akhauriyash/Code-Regression huggingface dataset:
def main():
    _ = input()
    lst_a = [int(a) for a in input().strip().split(' ')]

    # build hash table
    hash_tbl = {}
    for i, a_i in enumerate(lst_a):
        n_i = i + 1
        tmp = int(n_i - a_i)
        if tmp > 0:
            if tmp in hash_tbl.keys():
                hash_tbl[tmp].append(n_i)
            else:
                hash_tbl[tmp] = [n_i]

    ans = 0
    for j, a_j in enumerate(lst_a):
        n_j = j + 1
        tmp = int(n_j + a_j)
        if tmp in hash_tbl.keys():
            ans += len(hash_tbl[tmp])
    print(int(ans))


if __name__ == '__main__':
    main()


Measured memory_bytes: 98060
#include<stdio.h>
int main(void){
    int A[4][3][10],a,c,d,e,b,f,r,v,n;
    for(c=0;c<4;c++){
        for(d=0;d<3;d++){
            for(e=0;e<10;e++){
                A[c][d][e]=0;
            }
        }
    }
    scanf("%d",&n);
    for(a=0;a<n;a++){
        scanf("%d %d %d %d",&b,&f,&r,&v);
        A[b-1][f-1][r-1]=A[b-1][f-1][r-1]+v;
    }
    for(c=0;c<3;c++){
        for(d=0;d<3;d++){
            for(e=0;e<10;e++){
                printf(" %d",A[c][d][e]);
            }printf("\n");
        }printf("####################\n");
    }for(d=0;d<3;d++){
        for(e=0;e<10;e++){
            printf(" %d",A[3][d][e]);
        }printf("\n");
    }

return 0;
}

Measured memory_bytes: 612
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main(){
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> a(n);
  rep(i, n) cin >> a[i].first >> a[i].second;
  sort(a.begin(), a.end());
  int cur = 0;
  int ans = 0;

  priority_queue<int> q;
  for (int i = 1; i <= m; ++i) {
    while (cur < n && a[cur].first <= i) {
      q.push(a[cur].second);
      ++cur;
    }
    if(!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>

using namespace std ;

int memo [14][(int)1e5 + 1] ;
int MOD = (int)1e9 + 7 ;
string s ;
int n ;
int dp(int idx , int m)
{
    if(n == idx) return m == 5 ;
    if(memo[m][idx] != -1)return memo[m][idx] ;

    int ans = 0 ;
    if(s[idx] == '?')
        for(int j = 0 ; j <= 9 ; j ++)
            ans += dp(idx + 1,  (m * 10 + j) % 13) , ans %= MOD ;
    else
        ans += dp(idx + 1 , (m * 10 + s[idx] - '0') % 13) , ans %= MOD ;
    return memo[m][idx] = ans % MOD;
}
int main()
{
    ios_base :: sync_with_stdio(false) ;
    cin.tie(nullptr) ;
    cin >> s ;
    n = s.size() ;
    memset(memo , -1 ,sizeof memo) ;
    cout << dp(0 , 13) ;
    return 0 ;
}

Measured memory_bytes: 13776
#include<iostream>
using namespace std;

int main(){
    int N, K, h;
    int ans = 0;
    std::cin >> N >> K;

    for(int i = 0; i < N; i++){
        std::cin >> h;
        if(h >= K){
            ans++;
        }
    }

    std::cout << ans;

}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
ll mod = 998244353;
#include <bits/stdc++.h>
using namespace std;

ll mod_pow(int a, int b){
    ll res = 1;
    rep(i,b){
        res*=a;
        res%=mod;
    }
    return res%mod;
}
int dp[100100];
int main(){
    int n;
    cin >> n;
    int mx = 0;
    ll ans = 1;
    rep(i,n){
        int x;
        cin >> x;
        if(i==0){
            if(x!=0)
                ans = 0;
        }
        else{
            if(x==0){
                ans = 0;
            }
        }
        dp[x]++;
        mx = max(mx,x);
    }
    for(int i = mx;i>=0;i--){
        if(dp[i]==0){
            ans = 0;
        }
    }
    for(int i = 0;i<=n;i++){
        ans*=mod_pow(dp[i],dp[i+1]);
        ans%=mod;
    }
    cout << ans%mod << endl;
}

Measured memory_bytes: 640
get = list(map(int, input().split()))

N = get[0]
K = get[1]
Q = get[2]

list = [0]*N

for i in range(Q):
  list[int(input()) - 1] += 1 

for i in range(N):
  if K - (Q - list[i]) > 0:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 4680
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

string s;
int main() {
    cin>>s;

    bool flag=true;
    if(s[0]!='A') flag=false;

    int cntc=0;
    REP(i, 2, s.size()-1){
        if(s[i]=='C') cntc++;
    }
    if(cntc!=1) flag=false;

    REP(i, 1, s.size()){
        if(s[i]=='C') continue;
        if(s[i]<'a' || s[i]>'z') flag=false;
    }

    if(flag) cout<<"AC"<<endl;
    else cout<<"WA"<<endl;
    return 0;
}

Measured memory_bytes: 256
let n = read_int ()
let g, ds = Array.(make n [], make n 0)
let rec f v p d = ds.(v) <- d; List.iter (fun (u, c) -> if u <> p then f u v (d + c)) g.(v)
let _ = Scanf.(for _ = 1 to n - 1 do scanf " %d %d %d" @@ fun a b c -> g.(a - 1) <- (b - 1, c) :: g.(a - 1); g.(b - 1) <- (a - 1, c) :: g.(b - 1) done;
  scanf " %d %d" @@ fun q k -> f (k - 1) ~-1 0; for _ = 1 to q do scanf " %d %d" @@ fun x y -> Printf.printf "%d\n" @@ ds.(x - 1) + ds.(y - 1) done)

Measured memory_bytes: 24192
#include<bits/stdc++.h>

using namespace std;
#define EPS (1e-7)
#define INF (1e9)


typedef long long  ll;
#define endl '\n'




int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};



#define input_array(begin, N, M, A) A.resize((begin)+(N)); for (int i = 0; i < (begin)+(N); i++) { A[i].resize((begin)+(M)); } for (int i = begin; i < (begin)+(N); i++) { for (int j = begin; j < (begin)+(M); j++) { std::cin >> A[i][j]; }}

int  iabs(const int x) { return 0 <= x ? x : -x; }
const int MOD = 1000000007;
const long double PI = (acos(-1));
const int MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];

//////////////////////////////////////////


void COMinit() {
   fac[0] = fac[1] = 1;
   finv[0] = finv[1] = 1;
   inv[1] = 1;
   for (int i = 2; i < MAX; i++){
       fac[i] = fac[i - 1] * i % MOD;
       inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
       finv[i] = finv[i - 1] * inv[i] % MOD;
   }
}

int H, W;
bool dp[83][83][83*80*2] = {};

vector< vector<int> > a, b;
void Input() {

    cin >> H >> W;
}



void Solve() {



    input_array(1, H, W, a);
    input_array(1, H, W, b);



    dp[1][1][iabs(a[1][1] - b[1][1])] = true;

    for(int i = 1; i <= H; i++) {

        for(int j = 1; j <= W; j++) {

                for(int k = 0; k <= (H+W)*80; k++) {


                    if(dp[i][j][k]) {

                        if(i+1 <= H) {

                            int nd = iabs(k + (a[i+1][j] - b[i+1][j]));
                            dp[i+1][j][nd] = true;

                            nd = iabs(k - (a[i+1][j] - b[i+1][j]));

                            dp[i+1][j][nd] = true;
                        }
                        if(j+1 <= W) {

                            int nd = iabs(k + (a[i][j+1] - b[i][j+1]));
                            dp[i][j+1][nd] = true;

                            nd = iabs(k - (a[i][j+1] - b[i][j+1]));

                            dp[i][j+1][nd] = true;
                        }

                    }
                }
        }
    }

    int ans = INT_MAX;
    for(int k = 0; k <= (H+W)*80; k++) {

        if(dp[H][W][k]) {

            ans = min(ans, k);
        }
    }

    cout << ans << endl;
}



int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);
  Input();
  Solve();


  return 0;

}



Measured memory_bytes: 88832
#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
	ll n,h,w;
	cin >> n >> h >> w;
	ll y,x;
	ll count = 0;
	for(int i = 0; i < n; i++){
		cin >> y >> x;
		if(y >= h && x >= w)count++;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() 
{
 string s;
 cin>>s;
 int k=0;
 for(int i=0;i<s.length();i++)
 {
     k=k+s[i]-48;
     k=k%9;
 }
    if(k%9==0)
    cout<<"Yes"<<endl;
    else
    {
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll  pair <long long,long long>
#define ss second
#define ff first
#define inf 9223372036854775807
#define mod 1000000007
#define ld long double
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define bug(x) cout << #x <<": " << x << '\n';
const ll N=201 ;
int numPermsDISequence(string s) {

int n=s.length() ;
vector<int>dp(n+2,0),pre(n+2,0) ;
dp[1]=1 ;
pre[1]=1 ;
for(int i=2;i<=n+1;i++) pre[i]=1 ;


for(int i=2;i<=n+1;i++)
{
for(int j=1;j<=i;j++) // last
{
 dp[j]=0 ;
 if(s[i-2]=='>')
 {
   //for(int k=j;k<i;k++) dp[i][j]=(dp[i][j]+dp[i-1][k])%mod ;
   dp[j]=(pre[i-1]-pre[j-1]+mod)%mod ;
 }
else
 {
   //for(int k=1;k<j;k++)  dp[i][j]=(dp[i][j]+dp[i-1][k])%mod ;
   dp[j]=(pre[j-1]-pre[0]+mod)%mod ;
 }
}
pre[0]=dp[0] ;
for(int i=1;i<=n+1;i++)
{
    pre[i]=(pre[i-1]+dp[i])%mod ;
}

}

return pre[n+1]%mod ;

}
int main()
{
    fast ;
    ll n ; cin>>n ;
    string s ; cin>>s ;
    cout<<numPermsDISequence(s) ;



}



Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <complex>

using namespace std;

bool IsPrime(int num);

int main(){
	int n;
	while(cin >> n, n){
		int count = 0;
		for(int i = n+1; i <= 2*n; i++){
			if(IsPrime(i)){
				count++;
			}
		}
		
		cout << count << endl;
	}
	return 0;
}

bool IsPrime(int num){
	if(num < 2){
		return false;
	}else if(num == 2){
		return true;
	}else if(num % 2 == 0){
		return false;
	}
	
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2){
		if(num % i == 0){
			return false;
		}
	}
	
	return true;
}


Measured memory_bytes: 3100
# -*- coding: utf-8 -*-

R, G, B, N = map(int, input().split())

counter = 0
for r in range(int(N/R) + 1):
    for g in range(int((N - r)/G) + 1):
        t = R*r + G*g
        if t > N:
            break
        if (N - t) % B == 0:
            counter += 1

print(counter)

Measured memory_bytes: 3060
s = input()
t = input()
a = len(s) - len(t) + 1
c1= 0

for i in range(a):
    c2 = 0
    for j in range(len(t)):
        if s[i+j] == t[j]:
            c2 += 1
        else:
            continue
    c1 = max(c1,c2)


print(len(t)-c1)


Measured memory_bytes: 8904
program problemA
  implicit none

integer :: K,a,b
integer :: N



read(*,*) N

a=N/100
N=N-a*100
a=N/10
N=N-a*10


if (N==0) then
  write(*,*) 'pon'
else if (N==1) then
  write(*,*) 'pon'
else if (N==2) then
  write(*,*) 'hon'
else if (N==3) then
  write(*,*) 'bon'
else if (N==4) then
  write(*,*) 'hon'
else if (N==5) then
  write(*,*) 'hon'
else if (N==6) then
  write(*,*) 'pon'
else if (N==7) then
  write(*,*) 'hon'
else if (N==8) then
  write(*,*) 'pon'
else if (N==9) then
  write(*,*) 'hon'
end if





stop
end program


Measured memory_bytes: 2860
#include <bits/stdc++.h>
using namespace std ;

int main(){
  bool ans=true;
  string s;
  cin >> s;
  for(int i=0;i<s.length();i++){
    if((i%2==0&&s[i]=='L')||(i%2==1&&s[i]=='R'))ans=false;
  }
  if(ans)puts("Yes");
  else puts("No");
  return 0;
}


Measured memory_bytes: 256
S = str(input())

temp_0 = "0"
temp_1 = "1"
count_0 = 0
count_1 = 0
for x in S:
    if x == temp_0:
        count_0 += 1
        if temp_0 == "1":
            temp_0 = "0"
        else:
            temp_0 = "1"
    else:
        if temp_0 == "1":
            temp_0 = "0"
        else:
            temp_0 = "1"
            
for x in S:
    if x == temp_1:
        count_1 += 1
        if temp_1 == "1":
            temp_1 = "0"
        else:
            temp_1 = "1"
    else:
        if temp_1 == "1":
            temp_1 = "0"
        else:
            temp_1 = "1"

print(min(count_0,count_1))

Measured memory_bytes: 3188
/*

    author : s@if

*/

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define 		NIL 			-1
#define		 	fi	 		    first
#define 		sec 			second
#define 		MAX 			INT_MAX
#define			INF 			1e9
#define 		ll 			    long long
#define 		PI 			    acos(-1.0)
#define			MOD 			1000000007
#define 		PLL 			pair<ll,ll>
#define 		PII			    pair<int,int>
#define 		ull 			unsigned long long
#define 		For(i,a,b) 		for(int i=a;i<=(int)b;i++)
typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update> new_data_set;

//*find_by_order(k)  gives the kth element;
//order_of_key(item)   gives the index(number of element strictly less than item) of item;


inline int in() {int x; scanf("%d", &x); return x; }
bool Check(int N , int pos)	{	return (bool) (N & (1<<pos));}
int Set(int N, int pos) {	return N = N | (1<<pos);}

int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};    // King's move
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};
int hx[]={-2,-2,-1,+1,+2,+2,-1,+1};    // Knight's move
int hy[]={+1,-1,+2,+2,-1,+1,-2,-2};
int dx[]={+1,-1,+0,+0};
int dy[]={+0,+0,+1,-1};

const int MAXN = (int)2e5+9;


int main()
{
/*	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);  */

    ll i,j,k,l,m,n,p,q,x,y,u,v,r,tc,t;

    cin>>n>>k;

    ll ans = 0;

    while(n)
    {
        ans++;
        n/=k;
    }

    cout<<ans<<endl;

  //  main();

    return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)


Measured memory_bytes: 256
#include <string>
#include <iostream>

using namespace std;

int main()
{
	long long ans = 0, i, j, k, H, W;
	string C[100];
	cin >> H>>W;

	for (i = 0; i < H; i++) {
		cin >> C[i];
	}

	for (i = 0; i < H; i++) {
		cout << C[i] << endl;
		cout << C[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 500010
#define ll long long
using namespace std;
struct data{int x; double y;}d[N];
int n, op, cl, sum, x, sx;
double y, sy;
inline char gc(){
	static char now[1<<16], *S, *T;
	if(S==T){T=(S=now)+fread(now, 1, 1<<16, stdin); if(S==T)return EOF;}
	return *S++;
}
inline int read(){
	int x=0, f=1; char ch=gc();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=gc();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=gc();}
	return x*f;
}
int main(){
	n=read(); sum=read();
	op=1; cl=0; sx=sy=0;
	for(int i=1; i<=n; i++){
		y=read(); x=read();
		sx+=x; sy+=x*y;
		while(sx>sum){
			if(sx-d[op].x<sum){sy-=(sx-sum)*d[op].y; d[op].x-=sx-sum; sx=sum;}
			else{sx-=d[op].x; sy-=d[op].x*d[op].y; op++;}
		}
		printf("%.10f\n", sy/sum);
		while(op<=cl&&y<d[cl].y){y=(x*y+d[cl].x*d[cl].y)/(x+d[cl].x); x+=d[cl].x; cl--;}
		d[++cl].x=x; d[cl].y=y;
	}
	return 0;
}

Measured memory_bytes: 18304
#include <bits/stdc++.h>
#define max		  1000000
#define pb		  push_back
#define pairs	  pair<int, int>
#define vi		  vector<int>
#define vb		  vector<bool>
#define vii		  vector<pairs>
#define lb		  lower_bound
#define ub		  upper_bound
#define lli		  long long int
#define endl	  '\n'
#define FastInput ios_base::sync_with_stdio(false), cin.tie(NULL);
#define Cases	  cout << "Case " << ++Case << ": ";
#define __test    \
	int tt;       \
	int Case = 0; \
	cin >> tt;    \
	while (tt--)
#define read(x)	 freopen(x, "r", stdin)
#define write(x) freopen(x, "w", stdout)
#define InputArray(a, n)        \
	for (int i = 0; i < n; i++) \
		cin >> a[i];
#define CopyArray(a, temp, n)   \
	for (int i = 0; i < n; i++) \
		temp[i] = a[i];
#define PrintArray(a, n)        \
	for (int i = 0; i < n; i++) \
		cout << a[i] << " ";    \
	cout << endl;
using namespace std;

int main() {
#ifdef Niloy
	read("input.txt");
	write("output.txt");
#endif

	int n;
	cin >> n;
	long long arr[100010];

	for (int i = 0; i < n; i++) {
		scanf("%lld", &arr[i]);
	}

	long long int mul = 1;

	for (int i = 0; i < n; i++) {
		if (arr[i] == 0) {
			printf("0\n");
			return 0;
		}
	}

	for (int i = 0; i < n; i++) {
		if (arr[i] <= 1000000000000000000 / mul) {
			mul *= arr[i];
		} else {
			printf("-1\n");
			return 0;
		}
	}

	printf("%lld\n", mul);
	cerr << "time = " << (clock() / CLOCKS_PER_SEC) << " sec" << '\n';
	return 0;
}

Measured memory_bytes: 4544
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

string dp[10100];

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n,m;
  vector<char> v(m);
  cin>>n>>m;
  for(int i=0;i<m;i++)cin>>v[i];

  int mp[] = {0,2,5,5,4,5,6,3,7,6};

  for(int i=0;i<=n;i++){
    if(i&&dp[i]=="")continue;
    for(int j=0;j<m;j++){
      char num = v[j];
      int nx = i + mp[num-'0'];
      string new_s = dp[i] + num;
      sort(new_s.rbegin(), new_s.rend());
      // 桁数が多い or 桁数が同じなら辞書順
      if(new_s.size()>dp[nx].size() || (new_s.size()==dp[nx].size() && new_s>dp[nx])){
        dp[nx] = new_s;
      }
    }
  }

  cout<<dp[n]<<endl;

  return 0;
}


Measured memory_bytes: 27008
a,b,c,x,y = map(int, input().split())

ans = 0

if a + b > 2 * c:
    if x > y:
        if a > 2 * c:
            ans += x * 2 * c
        else:
            ans += y * 2 * c + (x - y) * a
    else:
        if b > 2 * c:
            ans += y * 2 * c
        else:
            ans += x * 2 * c + (y - x) * b
else:
    ans += a * x + b * y

print(ans)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;


int calc_temp(int T, int H, int A) {
    return 1000*T-6*H-1000*A;
}

int abs(int a) {
    if(a>=0) {
        return a;
    } else {
        return -a;
    }
}

int main() {
    int N, T, A;
    cin >> N >> T >> A;

    int H[N], i, min, min_index;
    for(i=0; i<N; i++) {
        cin >> H[i];
        if(i==0) {
            min = abs(calc_temp(T, H[i], A));
        } else {
            if(abs(calc_temp(T, H[i], A)) < min) {
                min = abs(calc_temp(T, H[i], A));
                min_index = i;
            }
        }
    }

    cout << min_index+1 << endl;


    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

#if defined(DEBUG)

#include <unistd.h>
#include <sys/fcntl.h>
#define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#else  // defined(DEBUG)

#define DLOG(...)
#define DCALL(func, ...)

#endif // defined(DEBUG)

vector<int> zAlg(string s) {
  int n = s.size();
  vector<int> z(n);
  z.at(0) = n;
  int i = 1;
  int j = 0;
  while (i < n) {
    for ( ; i+j < n && s.at(j) == s.at(i+j); j++) {}
    z.at(i++) = j;
    if (j > 0) {
      for (int k = 1; i < n && z.at(k) < j-1; k++, j--, i++) z.at(i) = z.at(k);
      j--;
    }
  }
  return z;
}

// matches("abab", "xababab") --> [1,3]
vector<int> matches(string p, string s, char sepChar = '\xff') {
  auto v = zAlg(p + string(1, sepChar) + s);
  int n = p.size();
  vector<int> res;
  for (size_t i = 0; i < s.size() - (n-1); i++) {
    if (v.at(n+1 + i) == n) res.push_back(i);
  }
  return res;
}

int out(int x) {
  cout << x << endl;
  return 0;
}

int sch(int i, int stop, const string& s, const string& t, auto& vm) {
  int j = (i + t.size()) % s.size();
  if (j == stop) return -1;
  if (vm.at(j) < 0) {
    if (sch(j, stop, s, t, vm) < 0) return -1;
  }
  vm.at(i) = vm.at(j) + 1;
  return vm.at(i);
}

int main(int argc, char *argv[]) {
#if defined(DEBUG)
  // GDB on Cygwin ignores redirection at run command.
  if (argc == 2) dup2(open(argv[1], 0), 0);
#else
  // For performance.  We should not use C-style stdio functions
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  cout << setprecision(20);

  string s;
  string t;
  cin >> s >> t;
  int r = 1 + (s.size() - 1 + t.size()) / s.size();
  string reps = "";
  reps.reserve(r * s.size());
  for (int i = 0; i < r; i++) reps += s;
  auto vec = matches(t, reps);
  vector<int> vm(s.size());
  for (size_t i : vec) {
    if (i >= s.size()) break;
    vm.at(i) = -1;
  }
  int maxSize = 0;
  for (size_t i : vec) {
    if (i >= s.size()) break;
    int x = sch(i, i, s, t, vm);
    if (x == -1) return out(-1);
    maxSize = max(maxSize, x);
  }
  return out(maxSize);


}



Measured memory_bytes: 24300
import java.util.*;

class Main{
	static char[][] c;
	static int a,b;
	static void delete(int m,int n){
		c[m][n]='*';
		if(m>0){
			if(n>0){
				if(c[m-1][n-1]=='@')delete(m-1,n-1);
			}if(n<b-1){
				if(c[m-1][n+1]=='@')delete(m-1,n+1);
			}if(c[m-1][n]=='@')delete(m-1,n);
		}
		if(m<a-1){
			if(n>0){
				if(c[m+1][n-1]=='@')delete(m+1,n-1);
			}if(n<b-1){
				if(c[m+1][n+1]=='@')delete(m+1,n+1);
			}if(c[m+1][n]=='@')delete(m+1,n);
		}
		if(n>0)if(c[m][n-1]=='@')delete(m,n-1);
		if(n<b-1)if(c[m][n+1]=='@')delete(m,n+1);
		return;
	}
	public static void main(String args[]){
		Scanner s=new Scanner(System.in);
		
		while((b=s.nextInt())!=0&&(a=s.nextInt())!=0){
			c=new char[a][b];
			
			for(int i=0;i<a;i++)
				for(int j=0;j<b;j++){
					c[i][j]=s.nextInt()==1?'@':'*';
				}
			int ans=0;
			for(int i=0;i<a;i++)
				for(int j=0;j<b;j++)
					if(c[i][j]=='@'){
						ans++;
						delete(i,j);
					}
			
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;

int main() {
    int N;

    cin>>N;

    vector<int> B(N-1);

    vector<int> A(N);

    for(int i=0;i<N-1;i++){

        cin>>B.at(i);
    }


    int sum=0;

    for(int i=1;i<N-1;i++){

        A.at(i)=min(B.at(i-1),B.at(i));
        sum=sum+A.at(i);
    }

    A.at(0)=B.at(0);
    A.at(N-1)=B.at(N-2);

    cout << sum+A.at(0)+A.at(N-1)<<endl;
    
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n;
  int *d;
  cin>>n;
  d=new int[n];
  for(int i=0;i<n;i++){
    cin>>d[i];
  }
  int count[100];
  for(int i=0;i<100;i++){
    count[i]=0;
  }
  for(int i=0;i<n;i++){
    count[d[i]-1]++;
  }
  int ans=0;
  for(int i=0;i<100;i++){
    if(count[i]!=0)ans++;
  }
  cout <<ans;
  return 0;
}

Measured memory_bytes: 256
//2019.12.16
//s1270188 momoka murakami
//alds1_04d Allocation

#include<stdio.h>
#include<stdlib.h>

//prototype
int allocation(void);

//global
int w_n, *w, car_n, SUM=0;

int main(){
  int i;

  //input
  scanf("%d %d",&w_n,&car_n);
  w=(int *)malloc(sizeof(int)*w_n);
  for(i=0;i<w_n;i++){
    scanf("%d",&w[i]);
    SUM+=w[i];
  }
  
  //output
  printf("%d\n",allocation());
  
  free(w);
  return 0;
}

int allocation(void){
  int *car, allow;
  int i, j;
  
  car=(int *)malloc(sizeof(int)*car_n);

  allow=SUM/car_n;
  while(1){
    for(i=0;i<car_n;i++) car[i]=0;
    
    for(i=0,j=0;i<w_n;i++){

      if(car[j]+w[i]>allow){
	j++;
	if(j==car_n || car[j]+w[i]>allow) break;
      }
      
      car[j]+=w[i];
    }

    if(i==w_n) break;
    allow++;
  }


  // for(i=0;i<car_n;i++) printf("%d ",car[i]);
  free(car);
  return allow;
}



Measured memory_bytes: 2272
import sys
N, M = map(int, raw_input().split())
a = []
b=[]
res=1000
flag=0
for i in sys.stdin:
    b=i.split()
    b[0]=int(b[0])
    b[1]=int(b[1])
    if M >=b[1] and res >=b[0]:
        res=b[0]
        flag=1

if flag==1:
    print res
else:
    print "TLE"

Measured memory_bytes: 2568
#include<stdio.h>
#pragma warning(disable:4996)

int main() {
	int p[1001] = { 0 };
	int k = 0,n = 0,tmp = 0,sum =0;

	scanf("%d %d", &n, &k);

	for (int i = 0; i < n; i++) {
		scanf("%d", &p[i]);
	}

	for (int j = 0; j < n; j++) {
		for (int m = j+1; m < n; m++) {
			if (p[m] <= p[j]) {
				tmp = p[m];
				p[m] = p[j];
				p[j] = tmp;
			}
		}
	}

	for (int s = 0; s < k; s++) {
		sum += p[s];
	}
	printf("%d", sum);
}

Measured memory_bytes: 1728
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;


public class Main {

    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        int x = s.nextInt(),y=s.nextInt();
        while(x--!=0){
            String word = s.next();
            System.out.println(word);
            System.out.println(word);
        }
    }


}




class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {return Integer.parseInt(next());}

    public long nextLong() throws IOException {return Long.parseLong(next());}

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

Measured memory_bytes: 26444
n,m = map(int,input().split())
#a = list(map(int,(input().split())))
a = list(map(lambda x: int(x)*(-1), input().split()))

import heapq
#n 買う商品数
#m 割引券の数
#a 値段
heapq.heapify(a)
while True:
   # print(a)
    tmp = (-1) * heapq.heappop(a) //2
    heapq.heappush(a,-1 * tmp)
    m -= 1
    if m == 0:
        break
print(-1*sum(a))

    

Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
double r,area,peri;
const double b=M_PI;

int main(){

cin >> r;
area=b*r*r;
peri=2.0*b*r;
cout<<fixed<<setprecision(6);
cout<<area<<" "<<peri<<endl;
return 0;
}



Measured memory_bytes: 3276
#include <bits/stdc++.h>
using namespace std;

int main(){
  string s;
  cin>>s;
  map <string,int> week;
  week.insert(make_pair("SUN",7));
  week.insert(make_pair("MON",6));
  week.insert(make_pair("TUE",5));
  week.insert(make_pair("WED",4));
  week.insert(make_pair("THU",3));
  week.insert(make_pair("FRI",2));
  week.insert(make_pair("SAT",1));
  
  int value=week.at(s);
  cout<<value<<endl;
  
  return 0;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int H;
        int W;

        while (true) {
            H = sc.nextInt();
            W = sc.nextInt();
            if(H==0 && W==0){
                break;
            }
            int i;
            int j;
            for(i=0;i<H;i++){
                for(j=0;j<W;j++){
                    if(i%2==0){
                        if(j%2 == 0){
                            System.out.print("#");
                        }else{
                            System.out.print(".");
                        }        
                    }else{
                        if(j%2 == 0){
                            System.out.print(".");
                        }else{
                            System.out.print("#");
                        }
                    }
                }
                System.out.println("");
            }
            System.out.println("");
        
        }
        sc.close();
    }
}


Measured memory_bytes: 36528
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;


vector<int> sieve_of_eratosthenes(int n) {
  vector<int> primes(n);
  for (int i = 2; i < n; ++i)
    primes[i] = i;
  for (int i = 2; i*i < n; ++i)
    if (primes[i])
      for (int j = i*i; j < n; j+=i)
        primes[j] = 0;
  return primes;
}

int main()
{
	int n;
	while(cin>>n){
		vector<int> V=sieve_of_eratosthenes(n+1);
		V.erase(remove(V.begin(),V.end(),0),V.end());
		cout<<V.size()<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long deposit = 100;
		long result = 0;
		while(x > deposit) {
			deposit*=1.01;
			result++;
		}
		System.out.println(result);

	}

}


Measured memory_bytes: 35656
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long double pi = acos(-1.0); 
typedef long long ll;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n, k;
	cin >> n >> k;
	vector<int> p(n);
	for(int i = 0; i < n; i++) {
		cin >> p[i];
	}
	sort(p.begin(), p.end());
	int ans = 0;
	for(int i = 0; i < k; i++) {
		ans += p[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 3644
// #include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <numeric>
// #include <windows.h>
using namespace std;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = V<VV<T>>;
template<class T1, class T2> using P = pair<T1, T2>;
using I = int;
using D = double;
using B = bool;
using C = char;
using S = string;
using LL = long long;
using LD = long double;
using ULL = unsigned long long;
using PII = P<I, I>;
using VPII = V<PII>;
using PLL = P<LL, LL>;
using VPLL = V<PLL>;
using VI = V<I>;
using VVI = VV<I>;
using VLL = V<LL>;
using VVLL = VV<LL>;
using VC = V<C>;
using VVC = VV<C>;
using VS = V<S>;
using VVS = VV<S>;
using VB = V<B>;
using VVB = VV<B>;
#define REP(type, i, n) for (type i = 0; i < (type)(n); ++i)
#define REP2(type, i, m, n) for (type i = (m); i < (type)(n); ++i)
#define REPR(type, i, n) for (type i = (n)-1; i >= 0; --i)
#define REPR2(type, i, m, n) for (type i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a, type) sort(ALL(a), greater<type>())
#define SORTF(a, comp) sort(ALL(a), comp)
#define REVERSE(a) reverse(ALL(a))
#define SIZE(a, type) ((type)(a).size())
#define bit_search(bit, n) REP(LL, bit, 1LL<<(n))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) (lower_bound(ALL(a), (x)) - a.begin())
#define bisect_right(a, x) (upper_bound(ALL(a), (x)) - a.begin())
#define INPUT(a) REPx(&x, a) cin >> x;
#define INPUT2(a) REPx(&x, a) INPUT(x);
#define INPUTP(a) REPx(&x, a) cin >> x.first >> x.second;
#define ENDL cout << endl;

const int INF = 2e9;
// const LL INF = 9e18;
const LL MOD = 1e9+7;

template<class T> using PRIORITY_QUEUE = priority_queue< T, V<T>, greater<T> >;
template<class T> inline bool chmin(T &a, T b){if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){if (a < b) {a = b; return true;} return false;}
template<class T> inline void debug1(V<T> A){REP(int, i, SIZE(A, int)){if (A[i] == INF) cout << "I ";else cout << A[i] << " ";}ENDL}
template<class T> inline void debug2(VV<T> A){REP(int, i, SIZE(A, int)){REP(int, j, SIZE(A[i], int)){if (A[i][j] == INF) cout << "I "; else cout << A[i][j] << " ";}ENDL}}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k, s, x;
  cin >> n >> k >> s;
  x = s+1;
  for (int i = 2; i*i <= s; ++i)
  {
    if (s % i)
    {
      x = i;
      break;
    }
  }
  REP(int, i, n)
  {
    if (i < k) cout << s << " ";
    else cout << x << " ";
  }
  ENDL

  return 0;
}


Measured memory_bytes: 3656
#include<stdio.h>

int main(){
  int n;
  scanf("%d",&n);
  int ans;
  if(n%10==1){
  	ans = 9;
    n = n/10;
  }else{
  	ans = 1;
    n = n/10;
  }

  if(n%10==1){
  	ans = ans+(10*9);
    n = n/10;
  }else{
  	ans = ans+(10*1);
    n = n/10;
  }
   if(n%10==1){
  	ans = ans+(100*9);
    n = n/10;
  }else{
  	ans = ans+(100*1);;
    n = n/10;
  }

  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int tim;
  int c[1000];
  int t[1000];
  int ansc=0;
  cin >> n >> tim;
  for (int i = 0; i < n; i++) {
    cin >> c[i] >> t[i];
    if(i==0){
      ansc=c[0];
    } else {if(t[i]<=tim){
      if(ansc>=c[i]){
        ansc=c[i];
      }
    }
  }}

  if(ansc==c[0]&&t[0]>tim){
    cout << "TLE" << endl;
  } else {
    cout << ansc << endl;
  }
}


Measured memory_bytes: 256
N,x=map(int,input().split())
a=list(map(int,input().split()))
cnt=0
for i in range(N-1):
    l=a[i]+a[i+1]
    if(l>x):
        cnt+=l-x
        if(a[i+1]>=l-x):
            a[i+1]-=l-x
        else:
            a[i+1]=0
            
print(cnt)

Measured memory_bytes: 14540
#include<bits/stdc++.h>
using namespace std;
const int N=500100,mod=998244353;
typedef long long ll;
int jc[N],jc2[N],n,k;
int inv(int x){return x==1?1:mod-mod/x*(ll)inv(mod%x)%mod;}
void init(){
	jc[0]=1;
	for(int i=1;i<=k;++i)jc[i]=(ll)jc[i-1]*i%mod;
	jc2[k]=inv(jc[k]);
	for(int i=k;i;--i)jc2[i-1]=(ll)jc2[i]*i%mod;
}
int C(int n,int k){
	if(n<k||k<0)return 0;
	return (ll)jc[n]*jc2[k]%mod*jc2[n-k]%mod;
}
int ans;
int main(){
	cin>>n>>k;init();
	for(int i=0;i<=k-i;++i){
		int j=k-i,tmp=n-(j-i);
		if(tmp>i)continue;
		if(i!=j)ans=(ans+C(k,i)-C(k,tmp-1))%mod;
		else ans=(ans+C(k-1,i-1)-C(k-1,n-2))%mod;
	}
	cout<<(ans+mod)%mod<<'\n';
	return 0;
}

Measured memory_bytes: 4096
#include <iostream>
#include <string>
#include <cmath>
#define PI 3.14159265358979

using namespace std;

int main()
{
	string s;
	int d = 90;
	double x = 0;
	double y = 0;
	while (cin >> s){
		
		//入力
		if (s == "0,0"){
			break;
		}
		string left = "";
		string right = "";
		for (int i = 0;; i++){
			if (s[i] == ','){
				for (int j = i + 1; j < (signed)s.length(); j++){
					right += s[j];
				}
				break;
			}
			left += s[i];
		}
		int walk = stoi(left);
		int turn = stoi(right);

		//計算
		double rad = d * PI / 180.0;
		x += walk * cos(rad);
		y += walk * sin(rad);
		d = (d - turn + 360) % 360;
	}
	cout << (int)x << endl;
	cout << (int)y << endl;
	return 0;
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define x first
#define y second
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rof(i,a,b) for(ll i=a;i>b;i--)
ll mod=1e9+7;
//cf dont use unordered map. use simply map<... , ... > m;

//They are Iterator minus v.begin() krna //lower_bound(v.begin(),v.end(),x)-v.begin()  //upper_bound(v.begin(),v.end(),x)-v.begin()
// lower bound tells greater than or equal to // upper bound tells strictly greater than
//int a[1001][1001] //aise global me hi// ll lcm(ll a, ll b){ return a / __gcd(a, b) * b; }
//memset can initialize to 0 or -1 ONLY //memset(str, 't', sizeof(str)); // string //memset(a, 0, sizeof(a));  //1D array    // memset(a,0,sizeof(a[0][0])*n*n); //2D array
// set.insert(),find() //for(auto it=set.begin();....) cout<<*it;   // sort(v.begin(),v.end(),compare)

ll power_mod(ll x,ll n,ll m) // x^n %mod // O(Log Power n)
{ll ans=1;
while(n!=0)
{
    if(n&1==1)
    {
        ans=(ans%m * x%m)%m;
    }
    x=(x%m * x%m)%m;
    n=n>>1;
}
    return ans;
}
void solve()
{
    ll n,k;cin>>n>>k;

    ll ans[k+1];
    for(ll i=k;i>0;i--)
    {
        ans[i]=power_mod(k/i,n,mod);

        ll j=i*2;
        while(j<=k)
        {
            ans[i]=(ans[i]%mod-ans[j]%mod)%mod;
            j+=i;
        }
    }
   // cout<<"DAS";
     ll sum=0;
     f(i,1,1+k)
     sum=(sum+(ans[i]%mod * i%mod))%mod;
cout<<sum;
//f(i,1,1+k) cout<<ans[i]<<" ";
//cout<<"DC";
}

int main()
{

ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll t=1;
  //  cin>>t;
    while(t--)
    {
     solve();
    }
}

Measured memory_bytes: 4364
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <deque>
#include <cassert>
#define pb push_back
#define point pair <int, int>
#define files(FileName) read(FileName); write(FileName)
#define read(FileName) freopen((FileName + ".in").c_str(), "r", stdin)
#define write(FileName) freopen((FileName + ".out").c_str(), "w", stdout)
using namespace std;
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }

const string FILENAME = "input";
const int MAXN = 2e3 + 1;

int n, k, ans;
vector <int> edge[MAXN];

int dfs(int i, int d, int p = -1) {
	if (d < 0) return 0;
	int s = 1;
	for (int j : edge[i]) {
		if (j == p) continue;
		s += dfs(j, d - 1, i);
	}
	return s;
}


int main() {
	ios::sync_with_stdio(false);
	srand(time(0));
	//read(FILENAME); 
	cin >> n >> k;
	for (int i = n - 1; i--;) {
		int a, b;
		cin >> a >> b;
		edge[a].pb(b);
		edge[b].pb(a);
	}
	if (k & 1) {
		for (int i = 1; i <= n; ++i) {
			for (int j : edge[i]) {
				chkmax(ans, dfs(i, k / 2, j) + dfs(j, k / 2, i));
			}
		}
	} else {
		for (int i = 1; i <= n; ++i) {
			chkmax(ans, dfs(i, k / 2));
		}
	}
	cout << n - ans << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
	while(true){
		int N;
		int dist[10009];
		for(int i=0;i<10009;i++){
			dist[i]=-1;
		}
		scanf("%d",&N);
		if(N==0)break;
		for(int i=0;i<N;i++){
			int P,D1,D2;
			scanf("%d%d%d",&P,&D1,&D2);P--;
			dist[P]=D1+D2;
		}
		int ma=-1,mai;
		for(int i=0;i<10009;i++){
			if(ma<dist[i]){
				ma=dist[i];
				mai=i;
			}
		}
		printf("%d %d\n",mai+1,ma);
	}
	return 0;
}

Measured memory_bytes: 1224
h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))

ans=[[0 for i in range(w)] for _ in range(h)]

co=0
for i in range(n):
    for j in range(a[i]):
        if (co//w)%2==1:
            ans[co//w][w-1-co%w]=i+1
        else:
            ans[co//w][co%w]=i+1
        co+=1
for i in range(h):
    for j in range(w-1):     
        print(ans[i][j],end=" ")
    print(ans[i][w-1])

Measured memory_bytes: 3912
main(){
	int K,S,i,c;
	for(;scanf("%d",&K),K;){
		S=0;
		for(i=0;i<K*(K-1)/2;i++){
			scanf("%d",&c);
			S+=c;
		}
		printf("%d\n",S/(K-1));
	}
	exit(0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>

using namespace std;

const int maxn = 10;
int h, w, k;
char mp[maxn][maxn];
long long ans = 0;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif

    cin >> h >> w >> k;
    for (int i = 0; i < h; ++i) {
        cin >> mp[i];
    }
    for (int i = 0; i < (1 << h); ++i) {
        for (int j = 0; j < (1 << w); ++j) {
            int res = 0;
            for (int ii = 0; ii < h; ++ii) {
                if ((1 << ii) & i) continue;
                for (int jj = 0; jj < w; ++jj) {
                    if ((1 << jj) & j) continue;
                    if (mp[ii][jj] == '#') ++res;
                }
            }
            if (res == k) ++ans;
        }
    }
    cout << ans << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  char x, y;
  cin >> x >> y;
  if(x == y) cout << '=' << endl;
  if(x < y) cout << '<' << endl;
  if(x > y) cout << '>' << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define PI 3.14159265359 //πの値
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

 
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll A,B,C; cin >> A >> B >> C;
if(A+B+C<=21) cout << "win";
else cout << "bust";
}


Measured memory_bytes: 3612
while True:
    n,x = [ int(i) for i in input().split( )]
    if n == x == 0:
        break
    counter = 0
    for i in range(1,n-1):
        for j in range(i+1,n):
            for k in range(j+1,n+1):
                if i + j + k == x:
                    counter += 1
    print(counter)



Measured memory_bytes: 5604
while true do
  n, r = gets.split.map(&:to_i)
  break if n == 0 && r == 0
  t = []
  r.times do |i|
    t << gets.split.map(&:to_i)
  end
  res = (0...n).to_a
  # p n, r, t, res, res[0]
  # puts
  
  for i, j in t
    res << res[-i - j + 1..-i]
    res = res.flatten()
    res[-i - j + 1 - j..-i - j] = []
    res = res.flatten()
  end
  p res[-1] + 1

end

Measured memory_bytes: 10300
#include <bits/stdc++.h>

using namespace std;

const int P = 998244353;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n, k;
	cin >> n >> k;

	vector<int> l(k);
	vector<int> r(k);
	for(int i = 0; i < k; ++i) {
		cin >> l[i] >> r[i];
	}

	vector<long long> dp(n + 1);
	vector<long long> pre(n + 1);

	dp[1] = 1;
	for(int i = 1; i <= n; ++i) {
		for(int j = 0; j < k; ++j) {
			dp[i] += pre[max(0, i - l[j])] - pre[max(0, i - r[j] - 1)];
			dp[i] = (dp[i] % P + P) % P;
		}
		pre[i] = (pre[i - 1] + dp[i]) % P;
	}

	cout << dp[n] << '\n';

	return 0;
}


Measured memory_bytes: 6360
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin() , v.end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
const ll INF=99999999999999;
const ll MOD=1000000007;
 
int main() {
  ll n;
  cin >> n;
  vl l;
  inputv(l,n);
  ll ans = 0;
  ll mn = INF;
  rep(i,n){
    mn = min(mn, l[i]);
  }
  ans += mn;
  rep(i,n){
    l[i] -= mn;
  }
  l.push_back(0);
  
  rep(i,n){
    if(l[i+1] < l[i]){
      ans += (l[i] - l[i+1]);
    }
  }
  cout << ans;
 return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>

long long A[1010190], souwa[123456];

int main(int argc, char *argv[])
{
  int n;
  std::cin >> n;
  for(int i=0;i<n;i++)
    std::cin >> A[i];
  std::sort(A,A+n,std::greater<long long>());
  souwa[n-1] = A[n-1];
  for(int i=n-2;i>=0;--i)
    souwa[i] = souwa[i+1] + A[i];
  int kotae = 1;
  for(int i=1;i<n;i++)
    {
      if( A[i-1] > souwa[i] * 2LL )
	break;
      kotae++;
    }
  std::cout << kotae << std::endl;
  return 0;
}


Measured memory_bytes: 5120
import numpy as np
import heapq

N = int(input())
A =  np.sort([int(x) for x in input().split(" ")])[::-1]

q = [(-A[1], (0, 1)), (-A[1], (0, 1))]
confort = A[0]
heapq.heapify(q)

i = 2
while N > i:
    m = heapq.heappop(q)
    # print(f"{m[1][0]}と{m[1][1]}の間に割り込む. 気持ち良さ {-m[0]}")
    confort -= m[0]
    heapq.heappush(q, (-A[i], (i, m[1][0])))
    heapq.heappush(q, (-A[i], (i, m[1][1])))
    i += 1
print(confort)


Measured memory_bytes: 70788
#include<bits/stdc++.h>
using namespace std;
int main()
{
	vector<int> vi;
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int a;
		cin>>a;
		vi.push_back(a);
	}
	sort(vi.begin(),vi.end());
	cout<<vi[n/2]-vi[n/2-1]<<endl;
	return 0;
 } 

Measured memory_bytes: 892
#include <stdio.h>

#define MAX(x, y) ((x)>=(y) ? (x):(y))
#define MIN(x, y) ((x)<=(y) ? (x):(y))

int main(int argc, char **argv) {
    int n;
    scanf("%d", &n);
    int ans = -1 << 30;
    int minr;
    scanf("%d", &minr);
    for(int i = 1; i < n; ++i) {
        int r;
        scanf("%d", &r);
        ans = MAX(ans, r - minr);
        minr = MIN(minr, r);
    }
    printf("%d\n", ans);
    return 0;
}



Measured memory_bytes: 2140
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

long long  mod = 1000000007;

int main(){
    int n;
    cin >> n;
    vector<int>a(n);
    rep(i,n)cin >> a[i];
    sort(a.begin(),a.end());
    int x = a[n-1];
    int y;
    int t = -1;
    for(int i=0;i<n;i++){
        if(a[i]>(double)x/2.0){
            t=i;
            break;
        }
    }
    if(t==-1){
        y = a[n-2];
    }else if(t==0){
        y = a[0];
    }else{
        if(x-a[t]>a[t-1]){
            y = a[t];
        }else{
            y = a[t-1];
        }
    }
    cout << x << " " << y << endl;
    return 0;
}

Measured memory_bytes: 640
N,M=map(int,input().split())
L=[]

for i in range(M):
    m=list(map(int,input().split()))
    L.append(m[1:])

#print(L)

S=list(map(int,input().split()))

ans=0

for i in range(2**N):
    sw=[0 for i in range(M)]
    I=i+0
    for j in range(N):
        if I&1==True:
            for k in range(M):
                if j+1 in L[k]:
                    sw[k]+=1
        I=I>>1
    #print(sw)
    cnt=0
    for j in range(M):
        if sw[j]%2==S[j]:
            cnt+=1
    if cnt==M:
        ans+=1
print(ans)

Measured memory_bytes: 74292
#include <bits/stdc++.h>
using namespace std;

int main() {
    int64_t N;
    cin >> N;
    int64_t ans=0;

    for(int64_t i=1;i<=N;i++){
        if(i%3!=0&&i%5!=0)ans+=i;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3632
#include <algorithm>
#include <iostream>
#include <map>

using namespace std;

const int N = 300000, M = 300000, K = 300000;

int xx[K], yy[K];
int kkx[1 + N], kky[1 + M];
map<pair<int, int>, bool> mp;
int qux[N], quy[N];

int main() {
	int n, m, k; cin >> n >> m >> k;
	for (int h = 0; h < k; h++)
		cin >> xx[h] >> yy[h];
	for (int h = 0; h < k; h++) {
		kkx[xx[h]]++, kky[yy[h]]++;
		mp[make_pair(xx[h], yy[h])] = true;
	}
	int kx = 0;
	for (int x = 1; x <= n; x++)
		kx = max(kx, kkx[x]);
	int ky = 0;
	for (int y = 1; y <= m; y++)
		ky = max(ky, kky[y]);
	int cntx = 0;
	for (int x = 1; x <= n; x++)
		if (kkx[x] == kx)
			qux[cntx++] = x;
	int cnty = 0;
	for (int y = 1; y <= m; y++)
		if (kky[y] == ky)
			quy[cnty++] = y;
	for (int hx = 0; hx < cntx; hx++)
		for (int hy = 0; hy < cnty; hy++)
			if (!mp[make_pair(qux[hx], quy[hy])]) {
				cout << kx + ky << '\n';
				return 0;
			}
	cout << kx + ky - 1 << '\n';
	return 0;
}


Measured memory_bytes: 29368
#include <bits/stdc++.h>
using namespace std;

int main(){
    int A, B, C, X; cin >> A >> B >> C >> X;

    int sum=0;

    for (int a=0; a <= A ; a++){
        for (int b=0; b <= B ; b++) {
            for (int c=0; c <= C ; c++){
                if( 500*a + 100*b + 50*c == X) sum++;
            }
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 256