akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,(n))
using namespace std;

int N, A, C[3], MOD = 1e9 + 7;
int64_t ans = 1;

int main() {
    cin >> N;
    rep(i, N) {
        cin >> A;
        int cnt = 0, id = -1;
        rep(j, 3) {
            if (C[j] == A) {
                cnt++;
                id = j;
            }
        }
        //if (id == -1) ans = 0;
        ans *= cnt;
        ans %= MOD;
        C[id]++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pii pair<int,int>
#define pb push_back
#define r1 rt<<1
#define r2 rt<<1|1
#define fi first
#define se second
#define ri register int
#define rep(i,a,b) for(ri i=(a);i<=(b);++i)
#define rep2(i,a,b,c) for(ri i=(a);i<=(b);i+=(c))
#define REP(i,a,b) for(ri i=(a);i>=(b);--i)
#define REP2(i,a,b,c) for(ri i=(a);i>=(b);i-=(c))
using namespace std;

inline int read(){
	ri x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^'0'),c=getchar();
	return x*f;
}
inline ll readll(){
	ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^'0'),c=getchar();
	return x*f;
}
inline void write(ll x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10+'0');
}
const int p=1e9+7,N=1e6+5;
int n,m,fac[N],inv[N];
inline int C(ri x,ri y){
	if(x<y)return 0;
	return (ll)fac[x]*inv[y]%p*inv[x-y]%p;
}
inline int ksm(ri x,ri y){
	ri z=1;
	while(y){
		if(y&1)z=(ll)z*x%p;
		x=(ll)x*x%p;
		y>>=1;
	}
	return z;
}
int main()
{
	n=read();m=read();
	if((n+m)%3!=0){
		cout<<0;return 0;
	}
	ri xy=(n+m)/3;
	ri x=m-xy,y=n-xy;
	if(x<0||y<0){
		cout<<0;return 0;
	}
	fac[0]=1;rep(i,1,xy)fac[i]=(ll)fac[i-1]*i%p;
	inv[xy]=ksm(fac[xy],p-2);
	REP(i,xy,1)inv[i-1]=(ll)inv[i]*i%p;
	printf("%d\n",C(xy,x));
	return 0; 
}

Measured memory_bytes: 6784
import java.util.Scanner;

public class Main {
    
	public static void main(String[] args) {
		
        Scanner s = new Scanner (System.in);
        int n = s.nextInt();
        int[] a = new int[n];
        
        int max = 0;
        int max2 = 0;
        
        for (int i = 0; i < n; i ++) {
        	a[i] = s.nextInt();
        	if (a[i] > max) {
        		max2 = max;
        		max = a[i];
        	} else if (a[i] > max2 && a[i] <= max)
        		max2 = a[i];
        }
        
        for (int i : a) {
        	if (i == max)
        		System.out.println(max2);
        	else
        		System.out.println(max);
        }
        
	}
}

Measured memory_bytes: 91204
n, k = map(int, input().split())
s = input()

l = []
t = []
st = s[0]
for c in s[1:]:
    if not st or st[-1] == c:
        st += c
    else:
        l.append(len(st))
        t.append(st)
        st = c
l.append(len(st))
t.append(st)

print(len(''.join(t[:k*2])) + sum(map(lambda x: x-1, l[k*2:] if l[k*2:] else [0])))


Measured memory_bytes: 5764
w, h, n = gets.split.map(&:to_i)
arr1 = [0]
arr2 = [w]
arr3 = [0]
arr4 = [h]

n.times do |i|
  tmp_x, tmp_y, tmp_a = gets.split.map(&:to_i)
  if tmp_a == 1
    arr1.push(tmp_x)
  elsif tmp_a == 2
    arr2.push(tmp_x)
  elsif tmp_a == 3
    arr3.push(tmp_y)
  else
    arr4.push(tmp_y)
  end
end
width = arr2.min - arr1.max
height = arr4.min - arr3.max

if width > 0 && height > 0
  print width * height
else
  print 0
end

Measured memory_bytes: 1788
x, y = map(int, input().split())

#フェルマーの小定理を用いてcombの計算を行う
def comb(n, k, mod, frac):
    a=frac[n]
    b=frac[k]
    c=frac[n-k]
    return (a * pow(b, mod-2, mod) * pow(c, mod-2, mod)) % mod

if 2*y-x < 0 or 2*x-y < 0:
  print(0)
elif (2*y-x)%3 != 0 or (2*x -y) % 3 != 0:
  print(0)
else:
  a = int((2*y-x)//3)
  b = int((2*x-y)//3)
  mod = 10**9 + 7
  frac = [1]
  for i in range(a+b):
      frac.append(frac[i]*(i+1)%mod)
  print(comb(a + b, a, mod, frac))

Measured memory_bytes: 29484
import java.util.*;

 class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a=0;
        long b=0;
        long c=0;
        long d=0;
        
        long S = sc.nextLong();
        double aa = Math.sqrt(S);
        a = (long) Math.sqrt(S);
        if(aa!=a) {
        	a = a + 1;
        }
        d = a;
        if(S!=a*d) {
        long w = (a*d) - S;
        if (w<1000000000) {
        	b=w;
        	c=1;
        } else {
        	for (int i=1000; i>1; i--) {
        		if(w%i==0) {
        			b=w/i;
        			c=i;
        			break;
        		}
        	}
        }
        }
        System.out.println("0 0 " + a + " " + b + " " + c + " " + d);	
        
        
    }
}

Measured memory_bytes: 21844
#include <math.h>
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <iostream>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)

using namespace std;

int main()
{
    int H,W;
    cin>>H>>W;
    string s;
    vector<string> MAP(H + 2);
    MAP[0] = '#' * (W + 2);
    MAP[H + 1] = '#' * (W + 2);
    FOR(i,1,H+1){
        cin >> s;
        MAP[i] = '#' + s + '#';
    }
    vector<vector<int>> yoko(H + 2, vector<int>(W + 2, 0));
    vector<vector<int>> tate(W + 2, vector<int>(H + 2, 0));
    FOR(w,1,1+W){
        if (MAP[1][w]=='.'){
            tate[w][1] = 1;
        }
    }
    FOR(h,1,1+H){
        if (MAP[h][1]=='.'){
            yoko[h][1] = 1;
        }
        FOR(w,1,1+W){
            if (MAP[h][w+1]=='.'){
                yoko[h][w + 1] = yoko[h][w] + 1;
            }
            else{
                int x = yoko[h][w];
                FOR(i,w-x+1,w+1){
                    yoko[h][i] = x;
                }
            }
            if (MAP[h+1][w]=='.'){
                tate[w][h + 1] = tate[w][h] + 1;
            }
            else{
                int x = tate[w][h];
                FOR(i,h-x+1,h+1){
                    tate[w][i] = x;
                }
            }
        }
    }
    int ans = 0;
    FOR(h,1,1+H){
        FOR(w,1,1+W){
            ans=max(ans,yoko[h][w]+tate[w][h]-1);
        }
    }
    cout<<ans<<endl;
}


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

typedef long long ll;
typedef double lf;
typedef long double Lf;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;

#define TRACE(x) cerr << #x << "  " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

#define fi first
#define sec second
#define mp make_pair
#define pb push_back

int main() {
  ll x, y;
  cin >> x >> y;
  if (min(x, y) == 1) cout << 1 << endl;
  else cout << (x * y + 1) / 2 << endl;
  return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<set>
using namespace std;
#define ll long long
ll read()
{
	ll x;char c;
	while((c=getchar())<'0'||c>'9');
	for(x=c-'0';(c=getchar())>='0'&&c<='9';)x=x*10+c-'0';
	return x;
}
#define MN 100000
ll q[MN+5],ans[MN+5];
multiset< pair<ll,ll> > st;
int main()
{
	int n,i;ll s;
	set< pair<ll,ll> >::iterator it,tt;
	q[0]=read();n=read();
	for(i=1;i<=n;++i)q[i]=read();
	st.insert(make_pair(q[n],1));
	for(i=n;i--;)
	{
		for(s=0,it=st.end(),--it;it->first>q[i];)
		{
			s+=it->first/q[i]*it->second;
			st.insert(make_pair(it->first%q[i],it->second));
			tt=it;--it;st.erase(tt);
		}
		st.insert(make_pair(q[i],s));
	}
	for(it=st.begin();it!=st.end();++it)ans[it->first]+=it->second;
	for(i=q[0];--i;)ans[i]+=ans[i+1];
	for(i=1;i<=q[0];++i)printf("%lld\n",ans[i]);
}

Measured memory_bytes: 9472
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;

}

signed main() {
	ll a, p;

	cin >> a >> p;

	p += a * 3;

	cout << p / 2 << endl;
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a<c) {
    if (b>c) {
      if (b>d) cout << d-c;
      else cout << b-c;
    } else cout << 0;
  } else {
    if (d>a) {
      if (d>b) cout << b-a;
      else cout << d-a;
    } else cout << 0;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        int n = str.length();
        int rCount = 0;
        int lCount = 0;
        char nowChar = 'R';
        
        
        int val = 0;
        for (int z = 0; z < n; z++) {
            char c = str.charAt(z);
            if (nowChar == 'R') {
                if (c == 'R') {
                    rCount++;
                } else {
                    nowChar = 'L';
                    lCount++;
                }
            } else {
                if (c == 'R') {
                    for (int i = 0; i < rCount - 1; i++) {
                        System.out.print("0" + " ");
                    }
                    
                    val = (rCount + lCount) / 2;
                    if ((rCount + lCount) % 2 == 0) {
                        System.out.print(val + " " + val + " ");
                    } else {
                        if (rCount % 2 != 0) {
                            System.out.print((val+1) + " " + val + " ");
                        } else {
                            System.out.print(val + " " + (val+1) + " ");
                        }
                    }
                    
                    for (int i = 0; i < lCount - 1; i++) {
                        System.out.print("0" + " ");
                    }
                    
                    nowChar = 'R';
                    rCount = 1;
                    lCount = 0;
                } else {
                    lCount++;
                }
            }
        }
        
        
        for (int i = 0; i < rCount - 1; i++) {
            System.out.print("0" + " ");
        }
        
        val = (rCount + lCount) / 2;
        if ((rCount + lCount) % 2 == 0) {
            if (lCount >= 2) {
                System.out.print(val + " " + val + " ");
            } else {
                System.out.println(val + " " + val);
            }
        } else {
            if (rCount % 2 != 0) {
                if (lCount >= 2) {
                    System.out.print((val+1) + " " + val + " ");
                } else {
                    System.out.println((val+1) + " " + val);
                }
            } else {
                if (lCount >= 2) {
                    System.out.print(val + " " + (val+1) + " ");
                } else {
                    System.out.println(val + " " + (val+1));
                }
            }
        }
        
        if (lCount >= 2) {
            for (int i = 0; i < lCount - 2; i++) {
                System.out.print("0" + " ");
            }
            System.out.println("0");
        }
    }
}


Measured memory_bytes: 33776
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int64_t INF = 1LL << 60;

int main() {
 	int64_t A,V,B,W,T;
	 cin>>A>>V>>B>>W>>T;
   if(W>V){cout<<"NO"<<endl;}
   else{
     int dis=abs(A-B);
     if(dis<=(V-W)*T){cout<<"YES"<<endl;}
     else{cout<<"NO"<<endl;}
   }
	return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <math.h>

int main(){
	long N,A[100000],result=1,flag=1;
	scanf("%ld",&N);
	for(int i=0;i<N;i++){
		scanf("%ld",&A[i]);
		if(A[i]==0){
		printf("0");
		return 0;
		}
		if(1>(long)1e18/result/A[i]){
			flag=0;
		}
		else result=result*A[i];
	}
	if(flag==0)puts("-1");
	else printf("%ld\n",result);
  	return 0;
}


Measured memory_bytes: 2476
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define md 1000000007
#define ld long double
//typedef __int128_t i128;

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n, i = 0, j= 0, k = 0, l = 0, m = 0, a = 0, b = 0, sum = 0, x = 0, y = 0, z = 0, c, p;
    cin >> n >> m;
    cout << (n*(n-1))/2 + (m*(m-1))/2;

    return 0;
}


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

using namespace std;

int n, m, q;
vector<vector<int> > v;
int total = 0;

int a[10] = {-1};
void dfs(int idx, int value) {
  if(idx == n) {
    int x = 0;
    for(int i=0; i < v.size(); i++) {
      if(a[v[i][1]] - a[v[i][0]] == v[i][2]) x += v[i][3];
    }
    total = max(total, x);
    return;
  }
  for(int i = value; i <= m; i++) {
    a[idx+1] = i;
    dfs(idx+1, i);
  }
}

int main() {
  cin >> n >> m >> q;
  for(int i=0; i < q; i++) {
    vector<int> vv(4);
    cin >> vv[0] >> vv[1] >> vv[2] >> vv[3];
    v.push_back(vv);
  }
  sort(v.rbegin(), v.rend());

  for(int i=1; i <= m; i++) {
    a[0] = i;
    dfs(0, i);
  }
  cout << total << endl;
}


Measured memory_bytes: 3640
N = int(input())
S = input()
L = len(S)
adic ={"A":1,"B":2,"C":3,"D":4,"E":5,"F":6,"G":7,"H":8,"I":9,"J":10,"K":11,"L":12,"M":13,"N":14,"O":15,"P":16,"Q":17,"R":18,"S":19,"T":20,"U":21,"V":22,"W":23,"X":24,"Y":25,"Z":26}
alist = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
for i in range(L):
  s = S[i]
  val = adic[s]
  key = val + N
  if key>26:
    key -= 26
  else:
    key = key
  print(alist[key-1],end="")


Measured memory_bytes: 4468
using System;

class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		string[] sH = Console.ReadLine().Split(' ');

		int[] H = new int[100000];
		for (int i = 0; i < sH.Length; i++) {
			H[i] = int.Parse(sH[i]);
		}
		int j =0;
		int MAX = 0;
		for (int i = 0; i < N - 1; i++) {
		
			int cot = 0;
			for (j = i; j < N - 1; j++) {
				if (H[j] >= H[j + 1]) {
					cot++;
					i=j;
				} else {
					if (MAX < cot)
						MAX = cot;
					break;
				}
			}
			if (MAX < cot)
				MAX = cot;
		}
		Console.Write(MAX);
		Console.ReadLine();
	}
}


Measured memory_bytes: 25052
s = input()

count = 0

even = []
odd = []
for i in range(len(s)):
    if i % 2 == 1:
        if s[i] == "R":
            count += 1
    if i % 2 == 0:
        if s[i] == "L":
            count += 1
            

if count == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;

int main() {
    
    // ここから入力
    ll n,ans = 0;
    ll x,m,b = 0,cnt = 0;
    bool lp = false;
    cin >> n >> x >> m;
    vector<ll> aa;
    vector<int> checked(m+1,0);
    
  
    int i = 0;
    while(i < n){
      ans += x;
      checked.at(x)++;
      x = (x*x)%m;
      cnt++;
      if(x == 0) break;
      if(checked.at(x) == 2){
        aa.push_back(x);
        b += x;
        lp = true;
      }
      if(checked.at(x) == 3){
          break;
      }
        i++;
    }
 
    ans -= 3*b;
    if(lp){
      ll c = aa.size();
      n -= (cnt - 3*c);
      ll kakeru = n / c;
      ll amari = n % c;
      ans += b * kakeru;
      REP(i,amari) ans += aa[i];
    }
    
   cout << ans << endl;
   
}


Measured memory_bytes: 4264
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;bool b = true;
  cin >> s;
  for(int i=0;i<s.size() ;i++){
    if(i % 2 == 0 && s[i] != 'h'){
      b = false;
    }
    if(i % 2 == 1 && s[i] != 'i'){
      b = false;
    }
  }
  
  if(b && s.size() % 2 != 1)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

typedef vector<vector<int> > mat;

const int R = 4;
const int C = 4;
const int di[4] = {0,1,0,-1};
const int dj[4] = {1,0,-1,0};

int ans;

struct Water {
  int i, j, k;
};

bool finished(const mat &g) {
  for(int i = 0; i < R; ++i) {
    for(int j = 0; j < C; ++j) {
      if(g[i][j]) return false;
    }
  }
  return true;
}

mat click(int pi, int pj, mat g) {
  g[pi][pj] += 1;
  if(g[pi][pj] < 5) return g;
  g[pi][pj] = 0;
  vector<Water> ws;
  for(int k = 0; k < 4; ++k) {
    ws.push_back((Water){pi, pj, k});
  }
  while(ws.size()) {
    vector<Water> nws;
    map<pair<int, int>, int> m;
    for(int i = 0; i < ws.size(); ++i) {
      Water &w = ws[i];
      w.i += di[w.k];
      w.j += dj[w.k];
      if(w.i < 0 || w.i >= R) continue;
      if(w.j < 0 || w.j >= C) continue;
      if(g[w.i][w.j]) {
        m[make_pair(w.i, w.j)] += 1;
        continue;
      }
      nws.push_back(w);
    }
    for(map<pair<int, int>, int>::iterator it = m.begin();
        it != m.end(); ++it) {
      int i = it->first.first;
      int j = it->first.second;
      int c = it->second;
      if((g[i][j] += c) < 5) continue;
      g[i][j] = 0;
      for(int k = 0; k < 4; ++k) {
        nws.push_back((Water){i, j, k});
      }
    }
    ws = nws;
  }
  return g;
}

void rec(mat g, int c) {
  if(c >= ans) return;
  if(finished(g)) {
    ans = c;
    return;
  }
  for(int i = 0; i < R; ++i) {
    for(int j = 0; j < C; ++j) {
      if(c+1 >= ans) return;
      rec(click(i, j, g), c + 1);
    }
  }
}

int main() {
  while(1) {
    mat g(R, vector<int>(C));
    for(int i = 0; i < R; ++i) {
      for(int j = 0; j < C; ++j) {
        if(cin >> g[i][j]); else return 0;
      }
    }
    ans = 6;
    rec(g, 0);
    if(ans == 6) ans = -1;
    cout << ans << endl;
  }
  return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define mem(a) memset(a, 0, sizeof(a))
#define sqr(x) ((x) * (x))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int mn = 305;
const int mod = 998244353;
#define P mod

int n,m;

int b[mn][mn];

ll powmod(ll a, ll b) {
    ll t = 1;
    for (; b; b >>= 1, a = a*a%P)
        if (b & 1) t = t*a%P;
    return t;
}

bitset<300> p[mn],a[mn];

int r=0;

void init() {
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < m; j++) {
            if (!a[i][j]) continue;//对线性基的这一位没有贡献
            if (!p[j].any()) {
                p[j] = a[i];
                r++;
                break;
            }//选入线性基中
            a[i] ^= p[j];
        }
    }
}

int main() {
#ifdef LOCAL
    freopen("../1.txt", "r", stdin);
#endif
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        for(int j=0;j<m;j++){
              scanf("%d",&b[i][j]);
              a[i][j]=b[i][j];
        }
    }
    init();
    printf("%lld\n",(powmod(2,n+m-1)-powmod(2,n+m-r-1)+mod)%mod);
    return 0;
}


Measured memory_bytes: 640
#pragma GCC optimize("O3") //コンパイラ最適化用

#define _GLIBCXX_DEBUG //配列に[]でアクセス時のエラー表示
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはメントされる
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--) //ループ変数は1ずつデクリ
#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--) //ループ変数は1ずつデクリ
// xにはvectorなどのコンテナ
#define ALL(x) x.begin(), x.end() // sortなどの引数を省略したい
#define SIZE(x) ll(x.size())      // sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 // 10^12:極めて大きい値,∞
#define MOD 1000000007    // 10^9+7:合同式の法
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back // vectorヘの挿入
#define MP make_pair // pairのコンストラクタ
#define F first      // pairの一つ目の要素
#define S second     // pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000

int main() {

    ll a, b, c, x;
    cin >> a >> b >> c >> x;

    ll cnt = 0;
    REP(i, a + 1) {
        REP(j, b + 1) {
            REP(k, c + 1) {
                if (i == 0 && j == 0 && k == 0) {
                    continue;
                }

                if (i * 500 + j * 100 + k * 50 == x) {
                    cnt++;
                }
            }
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3608
#include <stdio.h>
#include <string.h>

int main(void) {
	int i,n;
	int tp=0,hp=0;
	char taro[100],hana[100];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s",taro);
		scanf("%s",hana);
		if(strcmp(taro,hana)==0){
			tp++;
			hp++;
		}else if(strcmp(taro,hana)>0){
			tp += 3;
		}else hp += 3;
	}
	printf("%d %d\n",tp,hp);
	return 0;
}

Measured memory_bytes: 1796
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include<math.h>
using namespace std;

#define int long long
#define endl "\n"
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define all(v)  v.begin(),v.end()
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define all(v)  v.begin(),v.end()
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}

int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}



signed main() {
	int k, a = 0;
	queue<string>q;
	cin >> k;
	while (1) {
		if (a <= 8) {
			a++;
			q.push(to_string(a));
			if (a >= k) {
				cout << a << endl;
				break;
			}
		}
		else {
			if (q.front()[q.front().size() - 1]!='0') {
				q.push(q.front() + to_string((int)(q.front()[q.front().size() - 1]) - 1-'0'));
				a++;
			}
			if (a >= k) {
				cout << q.front() + to_string((int)(q.front()[q.front().size() - 1]) - 1-'0') << endl;
				break;
			}
			q.push(q.front() + q.front()[q.front().size() - 1]);
			a++;
			if (a >= k) {
				cout << q.front() + q.front()[q.front().size() - 1] << endl;
				break;
			}
			if (q.front()[q.front().size() - 1] != '9') {
				q.push(q.front() + to_string((int)(q.front()[q.front().size() - 1]) + 1-'0'));
				a++;
			}
			if (a >= k) {
				cout << q.front() + to_string((int)(q.front()[q.front().size() - 1]) + 1-'0') << endl;
				break;
			}
			q.pop();
		}
	}
}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    long long int a[100], b[100], tmp;
    cin >> a[0] >> a[1] >> b[0] >> b[1];
    tmp = a[0] * b[0];
    for(int i = 0; i < 2; i++) {
        for(int j = 0; j < 2; j++) {
            if(a[i] * b[j] > tmp) {
                tmp = a[i] * b[j];
            }
        }
    }
    cout << tmp;
}


Measured memory_bytes: 3636
<?php
fscanf(STDIN, "%d %d", $n, $t);
$ts = explode(' ', trim(fgets(STDIN)));
$x = $t;
$p = array_shift($ts) + $t;
foreach ($ts as $q) {
	if ($p > $q) {
		$x += $t - ($p - $q);
	} else {
		$x += $t;
	}
	$p = $q + $t;
}
echo $x;

Measured memory_bytes: 23028
import sys
sys.setrecursionlimit(10**7)
input=sys.stdin.readline

n, q = map(int, input().split())
t = [[] for i in range(n)]# 空の2次元配列を作る
for i in range(n-1):
    a, b = map(int, input().split())
    t[a - 1].append(b -1)
    t[b - 1].append(a -1)
# 配列は０から始まるから１、２、３、４の木を０、１、２、３として扱ってる
# 配列の０番目（つまり頂点０）が持つ値がその頂点が持つリンクとなる

v = [0] * (n) #空の配列を作る
for j in  range(q):# 0からqまで
    a, b = map(int, input().split())
    v[a-1] += b


def csum(now, bef):  # 累積和
    for nxt in t[now]:
        if nxt != bef:
            v[nxt] += v[now]
            csum(nxt, now)

csum(0, -1)
print(*v)


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

using namespace std;
typedef long long ll;

int main() {
  int k;
  int a, b;
  cin >> k;
  cin >> a >> b;

  bool ok = false;
  for (int i = a; i <= b; ++i) {
    if (i % k == 0) {
      ok = true;
      break;
    }
  }

  cout << (ok ? "OK" : "NG");

  return 0;
}


Measured memory_bytes: 3596
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <iomanip>

#define int long long int

using namespace std;

typedef pair<int, int> P;

const int inf = 1e15;

signed main(){
    vector<vector<int>> c(3, vector<int>(3));
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            cin >> c[i][j];
        }
    }

    for(int i = 0; i < 2; i++){
        int x = c[0][i] - c[0][i+1];
        int y = c[1][i] - c[1][i+1];
        int z = c[2][i] - c[2][i+1];
        if(x != y || y != z){
            cout << "No" << endl;
            return 0;
        }
    }

    for(int i = 0; i < 2; i++){
        int x = c[i][0] - c[i+1][0];
        int y = c[i][1] - c[i+1][1];
        int z = c[i][2] - c[i+1][2];
        if(x != y || y != z){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb push_back;
#define sp " ";
void vout(vector<int> v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int par[200000];/*親*/
int Rank[200000];/*根の深さ*/
/*n要素で初期化*/
void init(int n){
    for(int i=0;i<n;i++){
        par[i]=i;
        Rank[i]=0;
    }
}
/*木の根を求める*/
int find(int x){
    if(par[x]==x){/*親が自分自身＝根*/
        return x;
    }
    else{
        return par[x]=find(par[x]);/*一つ上の階層へ*/
    }
}
/*ｘとｙの集合を併合*/
void unite(int x,int y){
    x=find(x);
    y=find(y);
    /*根を求める*/
    if(x==y) return;/*同じ集合に属していたら終了*/
    if(Rank[x]<Rank[y]){
        par[x]=y;
    }
    else{
        par[y]=x;
        if(Rank[x]==Rank[y]) Rank[x]++;
    }
}
/*同じ集合に属するか調べる*/
bool same(int x,int y){
    return find(x)==find(y);
}
/*利用方法はparのそれぞれの要素に対応させる形で別の配列を用意し、そこに入力する。*/
int main(){
    lli n,m;
    cin>>n>>m;
    init(n+10);
    vector<pii> edge;
    vector<lli> ans;
    map<lli,lli> node;
    rep(i,n){
        node[i+1]=1;
    }
    vector<lli> pole(n,1);
    rep(i,m){
        lli a,b;
        cin>>a>>b;
        edge.push_back(pii(a,b));
    }
    lli time=(node.size()*(node.size()-1))/2;
    ans.push_back(time);
    for(int i=m-1;i>=0;i--){
        lli ca,cb,num,mo;
        ca=find(edge.at(i).first);
        cb=find(edge.at(i).second);
        if(ca==cb) {ans.push_back(time);continue;}
        num=node.at(ca)+node.at(cb);
        time-=node.at(cb)*node.at(ca);
        unite(ca,cb);
        mo=find(ca);
        node.at(mo)=num;
        if(mo==ca){
            node.erase(cb);
        }
        else{
            node.erase(ca);
        }
        ans.push_back(time);
    }
    reverse(ans.begin(),ans.end());
    for(int i=1;i<ans.size();i++){
        cout<<ans.at(i)<<endl;
    }
}

Measured memory_bytes: 12532
#[allow(unused_macros)]
macro_rules ! read_value {($ next : expr , ($ ($ t : tt ) ,* ) ) => {($ (read_value ! ($ next , $ t ) ) ,* ) } ; ($ next : expr , [$ t : tt ; $ len : expr ] ) => {(0 ..$ len ) . map (| _ | read_value ! ($ next , $ t ) ) . collect ::< Vec < _ >> () } ; ($ next : expr , chars ) => {read_value ! ($ next , String ) . chars () . collect ::< Vec < char >> () } ; ($ next : expr , usize1 ) => {read_value ! ($ next , usize ) - 1 } ; ($ next : expr , $ t : ty ) => {$ next () . parse ::<$ t > () . expect ("Parse error" ) } ; }
#[allow(unused_macros)]
macro_rules ! input_inner {($ next : expr ) => {} ; ($ next : expr , ) => {} ; ($ next : expr , $ var : ident : $ t : tt $ ($ r : tt ) * ) => {let $ var = read_value ! ($ next , $ t ) ; input_inner ! {$ next $ ($ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input {(source = $ s : expr , $ ($ r : tt ) * ) => {let mut iter = $ s . split_whitespace () ; let mut next = || {iter . next () . unwrap () } ; input_inner ! {next , $ ($ r ) * } } ; ($ ($ r : tt ) * ) => {let stdin = std :: io :: stdin () ; let mut bytes = std :: io :: Read :: bytes (std :: io :: BufReader :: new (stdin . lock () ) ) ; let mut next = move || -> String {bytes . by_ref () . map (| r | r . unwrap () as char ) . skip_while (| c | c . is_whitespace () ) . take_while (| c |! c . is_whitespace () ) . collect () } ; input_inner ! {next , $ ($ r ) * } } ; }

#[allow(unused_macros)]
macro_rules ! max {($ a : expr $ (, ) * ) => {{$ a } } ; ($ a : expr , $ b : expr $ (, ) * ) => {{std :: cmp :: max ($ a , $ b ) } } ; ($ a : expr , $ ($ rest : expr ) ,+ $ (, ) * ) => {{std :: cmp :: max ($ a , max ! ($ ($ rest ) ,+ ) ) } } ; }
#[allow(unused_macros)]
macro_rules ! chmax {($ base : expr , $ ($ cmps : expr ) ,+ $ (, ) * ) => {{let cmp_max = max ! ($ ($ cmps ) ,+ ) ; if $ base < cmp_max {$ base = cmp_max ; true } else {false } } } ; }

fn main() {
    input! {
        n: usize,
        s: [String; n],
        m: usize,
        t: [String; m],
    }

    let mut ret = 0;
    for i in 0..n {
        let mut tmp = s.iter().filter(|&e| *e == s[i]).count() as isize;
        tmp -= t.iter().filter(|&e| *e == s[i]).count() as isize;
        chmax!(ret, tmp);
    }

    println!("{}", ret);
}


Measured memory_bytes: 2140
from collections import Counter

n = int(input())
l = list(map(int, input().split()))
cl = Counter(l)


cnt = 0
for v in cl.values():
    cnt += v * (v - 1) // 2 

for i in l:
    v = cl[i]
    ans = cnt - (v * (v - 1) // 2) + (v - 1) * (v - 2) // 2
    print(ans)


Measured memory_bytes: 26772
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
typedef long long int ll;
using namespace std;
using Graph = vector<vector<int> >;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll A,B,K;
cin>>A>>B>>K;
if(A-K>=0){
    A-=K;
}
else{
    B=B-(K-A);
    if(B<0)B=0;
    A=0;
}


cout<<A<<" "<<B<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 256
// È¥°É£¡Æ¤¿¨Çð! °ÑAC´ø»ØÀ´£¡
//      ¤Ø¡¡¡¡¡¡¡¡¡¡£¯|
// ¡¡¡¡/£Ü7¡¡¡¡¡¡ ¡Ï£ß/
// ¡¡ /¡¡©¦¡¡¡¡ £¯¡¡£¯								AC		AC		AC		AC
//    ©¦¡¡Z £ß,£¼¡¡£¯¡¡¡¡ /`©c						AC		AC		AC		AC
//    ©¦¡¡¡¡¡¡¡¡¡¡©c¡¡¡¡ /¡¡¡¡¡µ					AC		AC		AC		AC
// ¡¡Y¡¡¡¡¡¡¡¡¡¡`¡¡ /¡¡¡¡/  /						AC		AC		AC		AC
// ¡¡Øé¡ñ¡¡.¡¡¡ñ¡¡¡¡¡´¡¡/¡¡/						AC		AC		AC		AC
// ¡¡()¡¡ ¤Ø¡¡¡¡¡¡¡¡|¡¡£Ü¡´							AC		AC		AC		AC
// ¡¡¡¡>- ._¡¡ ¥£¡¡ ©¦ £¯£¯							AC		AC		AC		AC
// ¡¡ / ¤Ø¡¡¡¡ /¡¡/£¼| £Ü£Ü							AC		AC		AC		AC
// ¡¡ ©c_/¡¡¡¡(_£¯¡¡ ©¦£¯£¯							AC		AC		AC		AC
// ¡¡¡¡ 7¡¡¡¡¡¡¡¡¡¡¡¡¡¡|£¯							AC		AC		AC		AC
// ¡¡¡¡ £¾¨Dr£þ£þ`-¨D£ß/							AC		AC		AC		AC
//**************************************Accepted*****************************************//

#include<bits/stdc++.h>

#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define Unique(x) x.erase(unique(all(x)),x.end());

#define CIN_FILE "input.txt"
#define COUT_FILE "output.txt"

#define Pig (OO)

using namespace std;

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

inline int read()
{
	#define gc getchar
	int ans=0;
	bool f=1;
	char ch=gc();
	
	while(!isdigit(ch))f^=ch=='-',ch=gc();
	
	while(isdigit(ch))ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
	
	return f?ans:-ans;
	
	#undef gc
}

typedef long long ll;

int n;

vector<int> calc(vector<int> s)
{
	vector<int> ans(s.size()+1);
	
	ans[0]=-1;
	int j=-1;
	
	for(int i=0;i<s.size();i++)
	{
		while(j>-1&&s[j]!=s[i])j=ans[j];
		
		ans[i+1]=(++j);
	}
	
	return ans;
}

vector<int> matchIndex(vector<int> s,vector<int> t)
{
	vector<int> ret;
	vector<int> a=calc(t);
	
	for(int m=0,i=0;m<=s.size()-t.size();)
	{
		while(m+i<s.size()&&i<t.size()&&s[m+i]==t[i])i++;
		
		if(i==t.size())ret.pb(m);
		
		m+=max(i-a[i],1);
		
		i=max(a[i],0);
	}
	
	return ret;
}

int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	
	cin>>n;
	
	vector<int> a(n),b(n);
	
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++)cin>>b[i];
	
	a.pb(a[0]);
	b.pb(b[0]);
	
	vector<int> c(n),d(2*n);
	
	for(int i=0;i<n;i++)
	{
		c[i]=a[i]^a[i+1];
		d[i]=b[i]^b[i+1];
		
		d[n+i]=d[i];
	}
	
	d.pop_back();
	
	vector<int> ind=matchIndex(d,c);
	
	for(int i=0;i<ind.size();i++)ind[i]=(n-ind[i])%n;
	
	sort(all(ind));
	
	for(int i=0;i<ind.size();i++)cout<<ind[i]<<' '<<(a[ind[i]]^b[0])<<endl;
	
	//printf("Time used = %.12f",(double)(clock())/CLOCKS_PER_SEC);
	return 0;
}

/*  GOD BLESS  */


Measured memory_bytes: 9440
N, K, Q=map(int,input().split())
K -= Q
#print(K)
nP = [ K for i in range(N)]
 
for i in range(Q):
  Tmp = int(input())
  nP[Tmp - 1] += 1

#print(nP)
for i in range(N):
  if nP[i] > 0:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 6604
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x,y;
  cin >> x >> y;
  string ans;
  if (x==2 || y==2) {
    ans="No";
  }
  
  else if (x==4 || x==6 || x==9 || x==11) {
    if (y==4 || y==6 || y==9 || y==11) {
      ans="Yes";
    }
    else {
      ans="No";
    }
  }
  
  else {
    if (y==4 || y==6 || y==9 || y==11) {
      ans="No";
    }
    else {
      ans="Yes";
    }
  }
  
  cout << ans;
}
    
  

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys;
import string;
sys.setrecursionlimit(20000) # 再起呼び出しの最大数をセット

import copy
import math
import itertools

from functools import lru_cache
#@lru_cache(maxsize = None)

PPP = 1000000007

# 整数の入力
#n = int(input())

# スペース区切りの入力
#n, x = input().split()

# スペース区切りの整数の入力
a, b = map(int, input().split())
#n, x = map(int, input().split())
#print("sp", n, k, file=sys.stderr)
#a = [int(x) for x in input().split()]
#b = [int(x) for x in input().split()]
#print("a", a, file=sys.stderr)
#p, q, r = map(int, input().split())
#s = [int(x) for x in input().split()]
#t = [int(x) for x in input().split()]

# 改行区切りの整数の入力
#a = []
#for x in range(n):
#  a.append(int(input()))
#  a.append([int(x) for x in input().split()])
#b = []
#for x in range(m):
#  b.append([int(x) for x in input().split()])
#p = [int(x) for x in input().split()]
#a.sort()
#print(l, file=sys.stderr)

# 文字列の入力
#s = input()

# 出力
#print("{} {}".format(a+b+c, s))
#a.sort()
#print(set(a), file=sys.stderr)
#print(len(set(a)))

#cache = dict()

import re
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

def ton(n, k, x):
  s = ""
  while n > 0:
    s = str(n%k) + s
    n //= k
  return s


#print("a", a, file=sys.stderr)
#print("b", b, file=sys.stderr)

def getEnergy():
  for y in b:
    yield y

def doit():
  res = abs(a + b)
  if res % 2 == 1:
    print("IMPOSSIBLE")
  else:
    print(res // 2)

def yn():
  if doit():
    return "Yes"
  else:
    return "No"

#print(doit([0] * 4))
#doit(a)
#print(doit())
try:
  doit()
  #print(doit())
  #print(yn())
except Exception as e:
  print("e", e, file=sys.stderr)


Measured memory_bytes: 5784
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;


int main()
{
	long long int i, j, k, l, m,N,X,H,W, n,A,B, sum, flag, cc, cnt;
	sum = 0;
	flag = 1;
	cin >> H >> W;
	int a[501][501];
	int ans[260000][4];
	for (i = 1; i <=H; i++) {
		for (j = 1; j <= W; j++) {
			cin >> a[i][j];
			a[i][j] %= 2;
		}
	
	}
	sum = 0;
	for (i = 1; i <=H; i++) {
		for (j = 1; j <= W-1; j++) {
			if (a[i][j] == 1&&a[i][j+1]==1) {
				sum++;
				ans[sum][0]= i;
				ans[sum][1] = j;
				ans[sum][2] = i;
				ans[sum][3] = j + 1;
				a[i][j] = 0;
				a[i][j + 1] = 0;
			}
			else if (a[i][j] == 1 && a[i][j + 1] == 0) {
				sum++;
				ans[sum][0] = i;
				ans[sum][1] = j;
				ans[sum][2] = i;
				ans[sum][3] = j + 1;
				a[i][j] = 0;
				a[i][j + 1] = 1;
			}
		}

	}
	for (i = 1; i <= H-1; i++) {
		if (a[i][W] == 1 && a[i + 1][W] == 1) {
			sum++;
			ans[sum][0] = i;
			ans[sum][1] = W;
			ans[sum][2] = i+1;
			ans[sum][3] = W;
			a[i][W] = 0;
			a[i+1][W] = 0;
		}
		else if (a[i][W] == 1 && a[i+1][W] == 0) {
			sum++;
			ans[sum][0] = i;
			ans[sum][1] = W;
			ans[sum][2] = i+1;
			ans[sum][3] = W;
			a[i][W] = 0;
			a[i+1][W] = 1;
		}
		
	}
	cout << sum << endl;
	for (i = 1; i <= sum; i++) {
		cout << ans[i][0] << " " << ans[i][1] << " "<<ans[i][2] << " " << ans[i][3] << endl;;
	}





    return 0;
}



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

using namespace std;

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

    int N;
    cin >> N;
    vector<int> L(N);
    constexpr int MX = 1'001;
    vector<int> pre(MX + 1);
    for (int i = 0; i < N; ++i) {
        cin >> L[i];
        ++pre[L[i]];
    }
    for (int i = 1; i <= MX; ++i) {
        pre[i] += pre[i - 1];
    }
    long long res = 0;
    sort(begin(L), end(L));
    for (int i = 0; i < N; ++i) {
        for (int j = i + 1, k = i + 2; j < N; ++j) {
            while (k < N && L[k] < L[i] + L[j]) {
                ++k;
            }
            //cout << i << " " << j << " " << k << endl;
            res += k - j - 1;
        }
    }
    cout << res << "\n";


    return 0;
}

Measured memory_bytes: 256
#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){
  int a, b, c;
  cin >> a >> b >> c;
  if(a <= c && c <= b) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// 287644PV
#define FIXED_FLOAT(x) std::fixed <<std::setprecision(10)<<(x)
int mod = 1000000007;
int n;
int candies(int i, int k, vector<vector<int>> &memo, vector<int> &a) {
    if(k == 0 && i == n)
        return 1;
    if(k < 0 || i >= n)
        return 0;
    if(memo[i][k] != -1) {
        return memo[i][k];
    }
    else {
        int solution = 0;
        for (int j = 0; j <= a[i]; ++j) {
            solution = (solution+candies(i+1,k-j,memo,a))%mod;
        }
        memo[i][k] = 0;
        memo[i][k] += solution;
        return memo[i][k];
    }
}

void modAdd(int&x, int y)
{
    x += y;
    if(x >= mod)
        x -= mod;
}
void modSub(int&x, int y)
{
    x -= y;
    if(x < 0)
        x += mod;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k;
    cin >> n >>k;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<int> dp(k+1);
    dp[0] = 1;
    int solution = 0;
    for (int i = 0; i < n; ++i) {
        solution = 0;
        vector<int> interval(k+2);
        for (int j = k; j >= 0; --j) {
            int L = j+1;
            int R = j + min(a[i],k-j);
            if(L <= R) {
                modAdd(interval[L], dp[j]);
                modSub(interval[R + 1], dp[j]);
            }
        }
        for (int l = 0; l <= k; ++l) {
            modAdd(solution,interval[l]);
            modAdd(dp[l],solution);
        }
    }



    cout << dp[k];
    return 0;
}

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

int main() {
  long N;
  cin>>N;
  long ans=1,mod=1e9+7;
  vector<int> b(1001);
  for(int i=1;i<=N;i++){
    int tmp=i;
    for(int j=2;j<=1000;j++){
      int count=1;
      while(tmp%j==0){
        b[j]++;
        tmp /=j;
      }
    }
  }
  for(int i=2;i<1001;i++){
      ans*=b[i]+1;
      ans%=mod;
  }

  cout<<ans<<endl;
  }


Measured memory_bytes: 256
class dice:
    def __init__(self,label):
        self.top, self.front, self.right, self.left, self.rear, self.bottom \
                = label
  
    def roll(self,odr):
        if   odr=='N': self.top, self.front, self.bottom, self.rear = \
                                self.front, self.bottom, self.rear , self.top
        elif odr=='E': self.top, self.left , self.bottom, self.right = \
                                self.left , self.bottom, self.right, self.top
        elif odr=='W': self.top, self.right, self.bottom, self.left = \
                                self.right, self.bottom, self.left , self.top
        elif odr=='S': self.top, self.rear , self.bottom, self.front = \
                                self.rear , self.bottom, self.front, self.top
  
    def print_top(self): print(self.top)
    def print_right(self): print(self.right)
  
    def get_label(self):
        return [self.top, self.front, self.right, self.left, self.rear, self.bottom]
 
    def compare(self, label):
        for odr in 'EEENEEENEEESEEESEEENEEEN':
            if self.get_label() == label:
                return True
            self.roll(odr)
        else:
            return False
   
if __name__=='__main__':
    n = int(input())
    L = []
    for i in range(n):
        label = list(map(int,input().split()))
        for d in L:
            if d.compare(label): break
        else:
            L.append(dice(label))
            continue
        print('No')
        break
    else:
        print('Yes')
        


Measured memory_bytes: 5608
var map = {};

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(input) {
  input = input.split("\n");
  input.pop();
  for (var a in input) {
    var tmp = input[a].split(" ")
    var key = tmp[0];
    if(map[key] === undefined || map[key] == null) map[key] = [];
    map[key].push(tmp[1]);
  }
});
process.stdin.on('end', function() {
  var order = Object.keys(map).sort();
  var t;
  for (var k in order) {
    k = order[k];
    t = map[k].sort(function (a,b) {
      return a-b;
    });
    console.log(k);
    console.log(t.join(" "));
  }
});

Measured memory_bytes: 8700
#MLE注意！0や1のケースに注意

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    a = list(map(int, input().split()))
    res = 0
    l = [0]*(10**6)
    used = []
    for i in range(n):
        if 0<=i+1-a[i]<n:
            l[i+1-a[i]] += 1
            used.append(i+1-a[i])
    cnt = 0
    for i in range(n):
        if 0<=i+1-a[i]<n:
            l[used[cnt]] -= 1
            cnt += 1
        if 0<=i+1+a[i]<10**6:
            b = i+1+a[i]
            res += l[b]
    print(res)



if __name__ == '__main__':
    main()

Measured memory_bytes: 103676
import * as fs from 'fs';

const input = fs.readFileSync('/dev/stdin', 'utf8').split('\n');

const n = +input[0];

const s = input[1].split(' ');

let res = ''

for (let i = 0; i < n; i++) {
  res += s[0][i] + s[1][i];
}

console.log(res);

Measured memory_bytes: 9420
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;

int main() {
	int n,x;
	cin >> n >> x;
	vector<int> v(n);
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
	}
	int sum = 0;
	for (int i = 0; i < n; ++i) {
		if(sum + v[i] > x) {
			cout << i + 1;
			return 0;
		}
		sum += v[i];
	}
	cout << n + 1; 
}



















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

#define ll long long
#define MOD 1000000007

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n;
	cin>>n;
	string s;
	cin>>s;
	ll int res=0;
	map<char,int> pos;
	pos['R']=0;
	pos['G']=1;
	pos['B']=2;
	int index[3][4005];
	int count[]={0,0,0};
	for(int i=0;i<n;i++) {
		index[0][i]=count[0];
		index[1][i]=count[1];
		index[2][i]=count[2];
		index[pos[s[i]]][i]=count[pos[s[i]]]+1;
		count[pos[s[i]]]++;
	}
	for(int i=0;i<n;i++) {
		for(int j=i+1;j<n;j++) {
			if(s[i]==s[j] || i==j) continue;
			int k=2*j-i;
			char ch;
			char tmp[]={0,0,0};
			tmp[pos[s[i]]]=1;
			tmp[pos[s[j]]]=1;
			int ind=0;
			for(int x=0;x<3;x++) {
				if(tmp[x]==0) {
					ind=x;
					break;
				}
			}
			if(j==n-1) continue;
			res+=count[ind]-index[ind][j];
			if(k<n && index[ind][k]!=index[ind][k-1]) res--;
			
		}
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 3700
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

Int N,W;
Int dp[101][100001];
Int w[101],v[101];

int main(void) {
    cin>>N>>W;

    for(int i = 0;i < N;i++)
        cin>>w[i]>>v[i];

    for(int i = 0;i < N;i++) {
        for(int j = 1;j <= W;j++) {
            if(j - w[i] >= 0)
                dp[i+1][j] = max(dp[i][j],dp[i][j-w[i]]+v[i]);
            else
                dp[i+1][j] = dp[i][j];
        }
    }

    cout<<dp[N][W]<<endl;

    return 0;
}




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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  if (v.size() == 0) {
    os << "(empty)";
    return os;
  }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

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

int main() {

  int a[101] = {0};
  int ac = 0;

  for (int x; cin >> x, cin;) {
    a[x]++;
    ac = max(ac, a[x]);
  }

  for (int i = 1; i < 101; ++i)
    if (ac == a[i])
      cout << i << endl;

  return 0;
}

Measured memory_bytes: 1160