akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;

ll cnt2(ll x){
    ll res = 0;
    while(x % 2 == 0){
        res++;
        x /= 2;
    }
    return res;
}

int main(void){
    int n;
    cin >> n;
    vector<ll> a(n);
    ll ans = 0;
    for(int i=0; i<n; i++){
        cin >> a[i];
        ans += cnt2(a[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3652
str_in = input().split()
a = int(str_in[0])
b = int(str_in[1])
k = int(str_in[2])

if(a >= b):
  div = b
else:
  div = a

cnt = 0

for i in range(div):
  res_a = a % (div - i)
  res_b = b % (div - i)

  if ((res_a == 0) & (res_b == 0)):
    cnt += 1
    if(cnt == k):
      print (div - i)
      break

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

int main() {
  int n, k;
  cin >> n >> k;
  int s = k;
  int p = 1;
  while (n >= s) {
    s *= k;
    p++;
  }
  cout << p << endl;
}


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

using namespace std;

int main() {
    int n;
    string s;
    cin >> n >> s;
    string mod_s = s;
    stack<int> brackets;
    for (int i = 0; i < n; i++) {
        if (s[i] == '(') {
            brackets.push(0);
        } else {
            if (brackets.empty())
                mod_s = '(' + mod_s;
            else
                brackets.pop();
        }
    }
    while (!brackets.empty()) {
        brackets.pop();
        mod_s += ')';
    }
    cout << mod_s;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> table(H, vector<char>(W));
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      cin >> table.at(i).at(j);
    }
  }
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      if (table.at(i).at(j) == '#'){
        break;
      }
      else if (j == W-1){
        for (int k = i+1; k < H; k++){
          table.at(k-1) = table.at(k);
        }
        table.pop_back();
        H--;
        i--;
      }
    }
  }
  for (int j = 0; j < W; j++){
    for (int i = 0; i < H; i++){
      if (table.at(i).at(j) == '#'){
        break;
      }
      else if (i == H-1){
        for (int l = 0; l < H; l++){
		  for (int k = j+1; k < W; k++){
          table.at(l).at(k-1) = table.at(l).at(k);
          }
        }
        for (int k = 0; k < H; k++){
          table.at(k).pop_back();
        }
        W--;
        j--;
      }
    }
  }
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      cout << table.at(i).at(j);
      if (j == W-1){
        cout << endl;
      }
    }
  }
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			Scanner cin = new Scanner();
			int n = cin.Int();
			int m = cin.Int();
			List<int>[] to = new List<int>[n];
			for (int i = 0; i < n; i++) {
				to[i] = new List<int>();
			}

			for (int i = 0; i < m; i++) {
				int a = cin.Int() - 1;
				int b = cin.Int() - 1;
				to[a].Add(b);
			}

			int inf = n + 1;
			List<int> ans = null;
			for (int i = 0; i < n; i++) {
				var q = new Queue<int>();
				var dist = new int[n];
				var prev = new int[n];
				for (int j = 0; j < n; j++) {
					dist[j] = inf;
					prev[j] = -1;
				}
				dist[i] = 0;
				q.Enqueue(i);

				while (q.Count > 0) {
					var next = q.Dequeue();
					for (int j = 0; j < to[next].Count(); j++) {
						int toi = to[next][j];
						if (dist[toi] != inf) {
							continue;
						}

						dist[toi] = dist[next] + 1;
						prev[toi] = next;
						q.Enqueue(toi);
					}
				}

				var min = new Tuple<int, int>(inf, 0);
				for (int j = 0; j < n; j++) {
					foreach (int k in to[j]) {
						if (k == i) {
							if (dist[j] < min.Item1) {
								min = new Tuple<int, int>(dist[j], j);
							}
						}
					}
				}

				if (min.Item1 != inf) {
					int v = min.Item2;
					var temp = new List<int>();
					while (v != -1) {
						temp.Add(v);
						v = prev[v];
					}

					if (ans == null || temp.Count < ans.Count) {
						ans = temp;
					}
				}
			}

			if (ans == null) {
				Console.WriteLine(-1);
			} else {
				var sb = new StringBuilder();
				sb.AppendLine(ans.Count.ToString());
				for (int i = 0; i < ans.Count; ++i) {
					sb.AppendLine($"{ans[i] + 1}");
				}

				Console.WriteLine(sb.ToString());
			}
		}
	}

	public class Scanner
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private string[] buf_;
		private int index_;

		public Scanner()
		{
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = Console.ReadLine();
			while (st == "") {
				st = Console.ReadLine();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 19644
#include <stdio.h>
#include <iostream>
using namespace std ;

int main ( )
{
	long long  a , b ,x ;
    scanf("%lld%lld%lld" ,&a,&b,&x);


	if ( a%x ==0  )

		cout <<  ((b/x) - ((a)/x) ) +1 ;
		else
		cout << (b/x) - ((a)/x) ;
			return 0 ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int main(){
 int a;
 cin >> a;
 if(a==25){
   cout << "Christmas" << endl;
 }else if(a==24){
   cout << "Christmas" << " " << "Eve" << endl;
 }else if(a==23){
   cout << "Christmas" <<" " <<"Eve" <<" "<< "Eve" << endl;
 }else{
   cout << "Christmas" <<" "<< "Eve"<<" " << "Eve" <<" " << "Eve" << endl;
 }
 return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;

inline int read()
{
	int X=0; bool flag=1; char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') flag=0; ch=getchar();}
	while(ch>='0'&&ch<='9') {X=(X<<1)+(X<<3)+ch-'0'; ch=getchar();}
	if(flag) return X;
	return ~(X-1);
}

int n,k;
int h[N];
int dp[N];

int main() {
    //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	n=read();
	k=read();
	me(dp,INF,sizeof(dp));
	for(int i=1;i<=n;++i){
		h[i]=read();
	}
	dp[1]=0;
	for(int i=2;i<=k;++i){
		for(int j=1;j<i;++j){
			dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
		}
	}

	for(int i=k+1;i<=n;++i){
		for(int j=i-k;j<i;++j){
			dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
		}
	}

	printf("%d\n",dp[n]);

    return 0;
}

Measured memory_bytes: 8036
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<string>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<unordered_set>
#define PI acos(-1)
#define pb push_back
#define all(x) x.begin(),x.end()
#define INF 0x3f3f3f3f
#define dd(x) cout<<#x<<" = "<<x<<","
#define de(x) cout<<#x<<" = "<<x<<"\n"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=5e5+5;
const int mod=1e9+7; 
ll f[N],inv[N];
ll qpow(ll a,ll n){
	ll re=1;
	while(n>0){
		if(n&1){
			re*=a;
			re%=mod;
		}
		a*=a;
		a%=mod;
		n>>=1;
	}
	return re;
}
int main()
{
	f[0]=inv[0]=1;
	for(int i=1;i<N;i++){
		f[i]=1ll*f[i-1]*i%mod;
		inv[i]=qpow(f[i],mod-2);
	}
	int n,m;
	scanf("%d%d",&n,&m);
	int op=1;
	int ans=0;
	for(int i=0;i<=n;i++){
		ans+=1ll*op*f[i]%mod*f[n-i]%mod*f[n-i]%mod*f[n]%mod*inv[i]%mod*inv[n-i]%mod*f[m]%mod*inv[i]%mod*inv[m-i]%mod*f[m-i]%mod*inv[n-i]%mod*inv[m-n]%mod*f[m-i]%mod*inv[n-i]%mod*inv[m-n]%mod;
//		de(1ll*op*f[m]%mod*f[m-i]%mod*f[n]%mod*inv[i]%mod*inv[n-i]%mod);
		ans%=mod;
		ans+=mod;
		ans%=mod;
		op*=-1;
	}
	printf("%d",ans);
}

Measured memory_bytes: 11632
#include <cstdio>

typedef long long ll;

const int MaxN = 5005;
const int cIz = 1000000007;

inline void inc(int &a, ll b) {
	a = (a + b) % cIz;
}

int n;

int ne = 1, head[MaxN];
struct edge {
	int to, nxt;
} e[2 * MaxN];

inline void ins(int u, int v) {
	e[++ne] = {v, head[u]}; head[u] = ne;
}

int g[MaxN], sz[MaxN], f[MaxN][MaxN];

void dfs(int u, int fa) {
	int *F = f[u];
	sz[u] = 1;
	F[1] = 1;
	for (int i = head[u]; i; i = e[i].nxt) {
		int v = e[i].to;
		if (v == fa) continue;
		dfs(v, u);
		int *G = f[v];
		for (int j = sz[u]; j; --j) {
			int tmp = F[j];
			for (int k = sz[v]; k; --k) inc(F[j + k], (ll)tmp * G[k]);
			F[j] = (ll)tmp * G[0] % cIz;
		}
		sz[u] += sz[v];
	}
	int tmp = 0;
	for (int i = 2; i <= sz[u]; ++i) inc(tmp, (ll)F[i] * g[i]);
	F[0] = fa ? cIz - tmp : tmp;
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i < n; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		ins(a, b); ins(b, a);
	}
	g[0] = 1;
	for (int i = 2; i <= n; ++i) {
		g[i] = (ll)g[i - 2] * (i - 1) % cIz;
	}
	dfs(1, 0);
	printf("%d\n", f[1][0]);
	return 0;
}

Measured memory_bytes: 97152
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#include <atcoder/segtree>
using namespace std;
using namespace atcoder;

using ll = long long;
using P = pair<int,int>;


int op(int a, int b) { return max(a, b); }

int e() { return -1; }

int target;

bool f(int v) { return v < target; }

int main() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
	rep(i,n) cin >> a[i];

    segtree<int, op, e> seg(a);

    rep(i,q) {
        int t;
        cin >> t;
        if (t == 1) {
            int x, v;
			cin >> x >> v;
            x--;
            seg.set(x, v);
        } else if (t == 2) {
            int l, r;
			cin >> l >> r;
            l--;
            printf("%d\n", seg.prod(l, r));
        } else if (t == 3) {
            int p;
			cin >> p >> target;
            p--;
            printf("%d\n", seg.max_right<f>(p) + 1);
        }
    }
}


Measured memory_bytes: 6136
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d;
int main(){
	int n;
	cin>>n;
	while(n--){
		string s;
		cin>>s;
		if(s[0] == 'A') a++;
		else if(s[0] == 'W') b++;
		else if(s[0] == 'T') c++;
		else d++;
	}
	cout<<"AC x "<<a<<endl;
	cout<<"WA x "<<b<<endl;
	cout<<"TLE x "<<c<<endl;
	cout<<"RE x "<<d<<endl;
	return 0;
}

Measured memory_bytes: 3552
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,ans=0;
int a[100001];
int main()
{
 		cin>>n>>m;
 		for(int i=1;i<=n;i++)
 		{
 			cin>>a[i];
		 }
		 sort(a+1,a+1+n);
		 for(int i=n;i>n-m;i--)
		 {
		 	ans+=a[i];
		 }
		 cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
ks=[]
cnt=0
for _ in range(m):
    tmp=(list(map(int,input().split())))
    t=set([])
    for item in tmp[1:]:
        t.add(item-1)
    ks.append(t)
#print(ks)
p=list(map(int,input().split()))

for i in range(2**n):
    #print(bin(i))
    tmp=[0]*m
    for j in range(n):
        if i>>j&1==1:
            for index,item in enumerate(ks):
                if j in item:
                    tmp[index]+=1
    flag=0
    for index,item in enumerate(tmp):
        if item%2!=p[index]:
            flag=1
    if flag==0:
        cnt+=1

print(cnt)






Measured memory_bytes: 42736
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;

namespace AtCoder.ABC
{
    class QuestionB
    {
        public static void Main(string[] args)
        {
            var n = long.Parse(Console.ReadLine());

            if(n % 2 == 1) {
                Console.WriteLine(0);
                return;
            }

            var count = 0L;

            for(long i = 10; i <= n; i *= 5) {
                count += n / i;
            }

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 27476
n=int(input())
l=list(map(int,input().split()))
a=0
for i in range(n):
    a+=l[i]
a/=n
#print(a)
s=[]
for i in range(n):
    s.append(abs(l[i]-a))
b=min(s)
#print(b)
for i in range(n):
    if b==s[i]:
        print(i)
        break

Measured memory_bytes: 3064
def main():
    N = int(input())
    print(0, flush=True)
    s = input()
    if s == 'Vacant':
        exit()
    ans = [''] * N
    ans[0] = s
    pre = 0
    left = 0
    right = N
    while True:
        mid = (right + left) // 2
        print(mid, flush=True)
        s = input()
        ans[mid] = s
        if s == 'Vacant':
            exit()
        cnt = abs(mid - pre)
        if cnt % 2 == 0:
            if ans[pre] == ans[mid]:
                #間には存在しない
                if pre > mid:
                    right = mid
                else:
                    left = mid
            else:
                #間には存在する
                if pre > mid:
                    left = mid
                else:
                    right = mid
        else:
            if ans[pre] == ans[mid]:
                #間には存在する
                if pre > mid:
                    left = mid
                else:
                    right = mid
            else:
                #間には存在しない
                if pre > mid:
                    right = mid
                else:
                    left = mid
        pre = mid

        


if __name__ == "__main__":
    main()

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

#define ll long long
#define deb(x) cerr << #x << ":" << x << "\n"
#define all(x) x.begin(),x.end()
#define sz(x) x.size()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

void solve()
{
    ll n,d;
    cin>>n>>d;
    ll ans=0;
    for(int i=0;i<n;i++){
        ll x,y;
        cin>>x>>y;
        ans+=(x*x+y*y)<=(d*d);
    }
    cout<<ans<<"\n";
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>
int partition(int a[],int p,int r) {
	int x=a[r];
	int i=p-1,j,mid;
	for(j=p; j<r; j++) {
		if(a[j]<=x) {
			i++;
			mid=a[i];
			a[i]=a[j];
			a[j]=mid;
		}
	}
	mid=a[i+1];
	a[i+1]=a[r];
	a[r]=mid;
	return i+1;
}
int main() {
	int n,k,w;
	scanf("%d",&n);
	int a[n];
	for(k=0; k<n; k++)
		scanf("%d",&a[k]);
	w=partition(a,0,n-1);
	for(k=0; k<n; k++) {
		if(k>0)
			printf(" ");
		if(k==w)
			printf("[%d]",a[k]);
		else
			printf("%d",a[k]);
	}
	printf("\n");
	return 0;
}


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

int main(){
  int n, a;
  cin >> n;
  cin >> a;

  if ((n % 500) <= a){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3588
#include<stdio.h>

int main(){
        int max,min,swap;
        while(1){
                scanf("%d %d",&max,&min);
                if(max==0&&min==0)break;
                if(max<min){
                        swap=max;
                        max=min;
                        min=swap;
}
                printf("%d %d\n",min,max);
        }

}


Measured memory_bytes: 1968
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define _GLIBCXX_DEBUG

long long f(long long a,long long b,long long x){
    return a*x/b - a*(x/b);
}

int main() {
    using vi = vector<int>;
    
    long long a,b,n;
    cin >> a >> b >> n;
    long long x = 0;
    long long re = f(a,b,x);
    //int g = gcd(a,b);
    x+=b;
    if(x>n){
        x=n+1;
    }
    long long y = f(a,b,x-1);
    if(y > re){
        re = y;
    }
    cout << re << endl;
}

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

using namespace std;

//#define FILE_IO

int N;
int f[100005];
vector <int> edg[100005];

void first() { printf("First\n"); exit(0); }
void second() { printf("Second\n"); exit(0); }

void DFS(int nod, int fth)
{
    for(auto nxt: edg[nod])
        if(nxt != fth)
            DFS(nxt, nod);

    if(f[nod])  return;

    if(!f[nod] && f[fth])   first();

    f[nod] = fth; f[fth] = nod;
}

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    scanf("%d", &N);
    for(int i = 1; i <= N; i++)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        edg[x].push_back(y);
        edg[y].push_back(x);
    }

    f[0] = -1;
    DFS(1, 0);

    for(int i = 1; i <= N; i++)
        if(!f[i])   first();
    second();

    return 0;
}


Measured memory_bytes: 6144
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.Integer;
import java.lang.Math;
import java.lang.System;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));

        Walker walker = new Walker();
        String str;
        while ((str = r.readLine()) != null) {
            String input[] = str.split(",");
            int step = Integer.parseInt(input[0]);
            int angle = Integer.parseInt(input[1]);

            if (step == 0 && angle == 0) {
                break;
            }

            walker.walk(step);
            walker.turn(angle);
        }

        System.out.println(walker.getX());
        System.out.println(walker.getY());
    }
}

class Walker {
    static double x, y;
    static int angle;

    Walker() {
        x = 0;
        y = 0;
        angle = 0;
    }

    static void walk(int step) {
        double t = Math.PI*angle/180.0;
        x += step * Math.sin(t);
        y += step * Math.cos(t);
    }

    static void turn(int th) {
        angle += th;
    }

    static int getX() {
        return (int)x;
    }

    static int getY() {
        return (int)y;
    }
}

Measured memory_bytes: 17012
import sys

X=int(input())

coin=[500,5,100,50,10,1]
pleasure={500:1000, 5:5}

y=X
gain=0
for i in range(7):
    n = int(y/coin[i])
    if coin[i]==500 or coin[i]==5:
        gain+=n*pleasure[coin[i]]
    y = y % coin[i]
    if y==0:
        break

print(gain)

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

using namespace std;

void insertionSort(vector<int> x, int n){
    for(int i = 0; i < n; i++){
        int v = x[i];
        int j = i-1;
        while(j >= 0 && x[j] > v){
            x[j+1] = x[j];
            j--;
        }
        x[j+1] = v;
        for(int k = 0; k < n; k++){
            cout << x[k] << (k < n-1 ? " " : "");
        }
        cout << "\n";
    }
}

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }

    insertionSort(A, N);

    return 0;
}


Measured memory_bytes: 3064
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#define getchar getchar
#define putchar putchar
int32_t nextint(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); bool s=false; if(c=='-'){s=true;c=getchar();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); int s=0; if(c=='-'){s=1;c=getchar();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }

int p[1000][2];
int main(void){
	int n=nextint();
	for(int i=0; i<n; i++){
		p[i][0]=nextint();
		p[i][1]=nextint();
	}
	int P=(p[0][0]^p[0][1])&1;
	for(int i=1; i<n; i++){
		if((p[i][0]^p[i][1]^P)&1){
			puts("-1");
			return 0;
		}
	}
	if(P){
		puts("31");
		puts("1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912 1073741824");
		const long s = 2147483647;
		for(int i=0; i<n; i++){
			long u = (s + p[i][0] + p[i][1])/2;
			long v = (s + p[i][0] - p[i][1])/2;
			for(int j=0; j<31; j++){
				if(u&(1<<j)){
					if(v&(1<<j)){
						putchar('R');
					}else{
						putchar('U');
					}
				}else{
					if(v&(1<<j)){
						putchar('D');
					}else{
						putchar('L');
					}
				}
			}
			putchar(10);
		}
	}else{
		puts("32");
		puts("1 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912 1073741824");
		const long s = 2147483647;
		for(int i=0; i<n; i++){
			long u = (s + p[i][0] + p[i][1] - 1)/2;
			long v = (s + p[i][0] - p[i][1] - 1)/2;
			putchar('R');
			for(int j=0; j<31; j++){
				if(u&(1<<j)){
					if(v&(1<<j)){
						putchar('R');
					}else{
						putchar('U');
					}
				}else{
					if(v&(1<<j)){
						putchar('D');
					}else{
						putchar('L');
					}
				}
			}
			putchar(10);
		}
	}
}


Measured memory_bytes: 1500
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            double r, S, L;
            r = double.Parse(Console.ReadLine());

            S = (double)r * r * 3.141592653589;
            L = (double)2 * r * 3.141592653589;

            Console.WriteLine("{0} {1}", S, L);

        }
    }
}


Measured memory_bytes: 17948
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }

int main(){
    SS(string,s);
    int a,b,c,d,B,C,D;
    string ans;
	a = s[0] - '0';
	b = s[1] - '0';
	c = s[2] - '0';
	d = s[3] - '0';
		rep(j,2) {
			B = b - (j * 2 * b);
			rep(k,2) {
				C = c - (k * 2 * c);
				rep(l,2) {
					D = d - (l * 2 * d);
					if (a + B + C + D == 7) {
						ans += s[0];
						B < 0 ? ans += "-" : ans += "+";
						ans += s[1];
						C < 0 ? ans += "-" : ans += "+";
						ans += s[2];
						D < 0 ? ans += "-" : ans += "+";
						ans += s[3];
						ans += "=7";
						cout << ans << endl;
						return 0;
					}
				}
			}
		}    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repn(i,n) for(ll i=0;i<=(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
//cin.tie(0);
//ios::sync_with_stdio(false);



signed main(){
    ll n,ans=0;cin>>n;
    vector<ll> v(n+1,0);
    for(int i=0;i < n;i++)
    {
        ll x;cin>>x;
        v[x]=i+1;
    }

    ll cnt=1;
    for(int i=2;i < n+1;i++)
    {
       if(v[i-1]<v[i]){
           cnt++;
           ans=max(ans,cnt);
       } 
       else cnt=1;
    }
    ans=max(ans,cnt);
    cout<<n-ans<<endl;
}


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
template<class T, class S> inline pair<T, S> mp(T x, S y){ return make_pair(x, y); }
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-12;

int N, M;
bool flag[200][200];
int p;
int K;

int main()
{
  while(cin >> N, N){
    rep(i, 200) rep(j, 200) flag[i][j] = false;
    rep(i, N){
      cin >> M;
      rep(j, M){
        cin >> p;
        flag[i][p - 1] = true;
      }
    }
    cin >> K;
    vi l(K);
    rep(i, K){
      cin >> l[i];
      l[i] -= 1;
    }

    int cnt = 0;
    int res;
    rep(i, N){
      bool ok = true;
      vrep(v, l) ok &= flag[i][*v];
      if(ok){
        cnt += 1;
        res = i + 1;
      }
    }
    printf("%d\n", cnt == 1 ? res : -1);
  }

  return 0;
}

Measured memory_bytes: 1216
#include <stdio.h>

int main(void) {
   
   int N,K;
   
   scanf("%d",&N);
   
   char Moji[N+10];
   
   scanf("%s",Moji);
   scanf("%d",&K);
   
   int i;
   
   for(i = 0;i < N;i++){
      if(Moji[i] != Moji[K-1]) {
         Moji[i] = '*';
      }
   }
   
   printf("%s\n",Moji);
   
   return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
/*

*/
ll ans = 0, N, M;
vector<vector<ll>> G;

void dfs(ll now, vector<ll> seen){
  seen[now] = 1;
  for(ll i=1; i<=N; i++){
    if (seen[i] == 0)
      break;
    if (i == N){
      ans++;
      return;
    }
  }
  for(auto v: G[now]){
    if (seen[v])
      continue;
    dfs(v, seen);
  }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    cin >>N >>M;
    G.assign(N+1, vector<ll>(0,0));
    vector<ll> seen(N+1,0);
    rep(i,M){
    	ll a,b; cin>>a>>b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs(1, seen);
    cout<<ans<<endl;
}

Measured memory_bytes: 3652
a, b, c, x, y = (int(i) for i in input().split())

tmp1,tmp2,tmp3 = 0,0,0

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

tmp2 = a*x+b*y

print(min(tmp1,tmp2,tmp3))


Measured memory_bytes: 3060
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

arr = [a, b, c, d, e]
m = 0
ans = 0
for i in arr:
    ans += i
    if i % 10:
        ans += 10 - (i % 10)
        m = max(m, 10-(i%10))
print(ans - m)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    int n;
    string s;
    cin >> n;
    cin >> s;
    int counter = 1;
    rep(i,n-1) {
        if (s.at(i) != s.at(i+1)) counter++;
    }
    cout << counter << endl;
}

Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i32 = int32_t;
using i64 = int64_t;
constexpr char newl = '\n';

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
//#define F first
//#define S second
#define debug(x) cout << #x << ": " << x << '\n';
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1

constexpr int MOD = 1e9 + 7; // 1e9 + 7

template<typename F>
struct FixPoint : F {
  FixPoint(F&& f) :F(forward<F>(f)) {}
  template<typename... Args>
  decltype(auto) operator()(Args&&... args) const {
    return F::operator()(*this, forward<Args>(args)...);
  }
};
template<typename F>
inline decltype(auto) MFP(F&& f) {
  return FixPoint<F>{forward<F>(f)};
}

// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;

  string s;
  s.reserve(N);
  cin >> s;

  // 狭義単調増加/減少の数列の、両端が一致している、と考える。
  // 4 <>< たとえばこれは、 {1, 3} {3, 2} {2, 4} という3つの数列などが考えられる。
  // 5 <<<< これは {1, 2, 3, 4, 5} 全体で一つの数列。

  // dp[i][j] := i 番目まで決めた時、i 番目の数より大きい、残っている数値の数が j 個のとき

  vector<vector<int>> dp(N + 1, vector<int>(N+1, 0));

  dp[0][0] = 1;

  FOR(i, 0, N - 1) {
    if (s[i] == '<') {
      F0R(j, i + 1) {
        dp[i + 1][j + 1] = dp[i][j] + dp[i + 1][j];
        if (dp[i + 1][j + 1] >= MOD) dp[i + 1][j + 1] -= MOD;
      }
    }
    else {
      F0R(j, i + 1) {
        dp[i + 1][i - j] = dp[i][i - j] + dp[i + 1][i - j + 1];
        if (dp[i + 1][i - j] >= MOD) dp[i + 1][i - j] -= MOD;
      }
    }
  }

  int result = 0;
  F0R(i, N) {
    result += dp[N - 1][i];
    if (result >= MOD) result -= MOD;
  }
  cout << result;
}
#endif


Measured memory_bytes: 35584
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
#define vall(x) (x).begin(), (x).end()
using namespace std;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2> bool chmin(T1 &l, const T2 &r);
template <class T1, class T2> bool chmax(T1 &l, const T2 &r);
template <class T1, class T2> void vadd(vector<T1> &v, T2 x);

#define int long long int

void solve(long long x) {
  cout << (x==0?1:0)<<endl;
}

signed main() {
  long long x;
  scanf("%lld", &x);
  solve(x);
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2> bool chmin(T1 &l, const T2 &r) {
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2> bool chmax(T1 &l, const T2 &r) {
  return (l < r) ? (l = r, true) : false;
}

template <class T1, class T2> void vadd(vector<T1> &v, T2 x) {
  for (auto &s : v)
    s += T2(x);
}


Measured memory_bytes: 3684
#include<bits/stdc++.h>
using namespace std;
#pragma region Macros
#define ll long long
#define ld long double
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
using P = pair<ll, ll>;
#define ios\
    ios::sync_with_stdio(false);\
    cin.tie(nullptr);
#define VEC(type, name, size)\
    V<type> name(size);\
    IN(name)
#define VVEC(type, name, h, w)\
    VV<type> name(h, V<type>(w));\
    IN(name)
#define INT(...)\
    int __VA_ARGS__;\
    IN(__VA_ARGS__)
#define LL(...)\
    ll __VA_ARGS__;\
    IN(__VA_ARGS__)
#define STR(...)\
    string __VA_ARGS__;\
    IN(__VA_ARGS__)
#define CHAR(...)\
    char __VA_ARGS__;\
    IN(__VA_ARGS__)
#define DOUBLE(...)\
    DOUBLE __VA_ARGS__;\
    IN(__VA_ARGS__)
#define LD(...)\
    LD __VA_ARGS__;\
    IN(__VA_ARGS__)
template <class T> void scan(T a) { cin >> a; }
void scan(int &a) { cin >> a; }
void scan(long long &a) { cin >> a; }
void scan(char &a) { cin >> a; }
void scan(double &a) { cin >> a; }
void scan(long double &a) { cin >> a; }
void scan(char a[]) { scanf("%s", a); }
void scan(string &a) { cin >> a; }
template <class T> void scan(V<T> &);
template <class T, class L> void scan(pair<T, L> &);
template <class T> void scan(V<T> &a) { for(auto &i : a) scan(i); }
template <class T, class L> void scan(pair<T, L> &p){ scan(p.first); scan(p.second); }
template <class T> void scan(T &a) { cin >> a; }
void IN() {}
template <class Head, class... Tail> void IN(Head &head, Tail &... tail) { scan(head); IN(tail...); }
template <class T> inline void print(T x){ cout << x << '\n';}
template <class T> V<T> press(V<T> &x){ 
    V<T> res = x;
    sort(all(res));
    res.erase(unique(all(res)), res.end());
    REP(i, SZ(x)){
        x[i] = lower_bound(all(res), x[i]) - res.begin();
    }
    return res;
}
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; }
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void err(bool b = true) {if(b) {cout << -1 << '\n'; exit(0);}}
template<class T> inline void fin(bool b = true, T e = 0) {if(b) {cout << e << '\n'; exit(0);}}
template<class T> T Roundup_div(T x, T y) {return (x+(y-1))/y;}
template <typename T> T pow(T a, long long n, T e = 1) {T ret = e; while (n) {if (n & 1) ret *= a; a *= a; n >>= 1; } return ret; }
const ll INF = 1e18;
#pragma endregion

int main(){
    ios;
    INT(h, n);
    V<> a(n), b(n), dp(h + 1, INF);
    REP(i, n) cin >> a[i] >> b[i];
    dp[h] = 0;
    REP(i, n) RREPS(j, h) chmin(dp[max(j - a[i], 0ll)], dp[j] + b[i]);
    print(dp[0]);
}

Measured memory_bytes: 3748
def bomb(field,x,y):
    rfield = field[:][:]
    rfield[y][x] = 0
    for i in range(-3,4):
        if 0 <= x+i <= 7:
            if rfield[y][x+i] == 1:
                rfield = bomb(rfield,x+i,y)
        if 0 <= y+i <= 7:
            if rfield[y+i][x] == 1:
                rfield = bomb(rfield,x,y+i)
    return rfield


n = int(raw_input())
for data in range(1,n+1):
    field = []
    raw_input()
    for line in range(8):
        field.append(map(int, list(raw_input())))
    x = int(raw_input())-1
    y = int(raw_input())-1

    field = bomb(field,x,y)
    print "Data %d:"%(data)
    for i in range(8):
        print "".join(map(str, field[i]))

Measured memory_bytes: 4272
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define LLINF (1e18)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    int l = 0, r = 0;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == '(')
        {
            l++;
        }
        else
        {
            if (l > 0)
            {
                l--;
            }
            else
            {
                r++;
            }
        }
    }
    if (r > 0)
    {
        for (int i = 0; i < r; i++)
        {
            s = '(' + s;
        }
    }
    if (l > 0)
    {
        for (int i = 0; i < l; i++)
        {
            s = s + ')';
        }
    }
    cout << s << endl;
}

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

int maxVal = 1e5;
const int inf = 2*1e9;

int Knapsack_2(vector<int> &weight, vector<int> &profit, int maxCap)
{
	int n = weight.size();
	
	// It's very important to make DP as long long
	vector<vector<long long>> dp(n + 1, vector<long long>(maxVal + 1, 0));

	/* dp[n][val] represents the minimum capacity of knapsack needed to gain exactly 'val' profit
	 * from the first 'n' elements
	 */

	// No element. There is no way to make any profit
	for(int val = 1; val <= maxVal; val++)
		dp[0][val] = inf;
	
	// An empty knapsack is needed to create zero profit
	for(int i = 1; i <= n; i++)
		dp[i][0] = 0;
	
	// No element and No Profit ==> Empty knapsack would work
	dp[0][0] = 0;

	for(int i = 1; i <= n; i++)
	{
		for(int val = 1; val <= maxVal; val++)
		{
			long long take_it = inf, leave_it = inf;

			leave_it = dp[i-1][val];

			if(val >= profit[i-1])
				take_it = weight[i-1] + dp[i-1][val - profit[i-1]];
			
			dp[i][val] = min(take_it, leave_it);
		}
	}

	for(int ans = maxVal; ans >= 0; ans--)
		if(dp[n][ans] <= maxCap)
			return ans;

}
int main()
{
	int n, maxCap;
	cin >> n >> maxCap;

	vector<int> weight(n), val(n);

	for(int i = 0; i < n; i++)
		cin >> weight[i] >> val[i];

	cout <<	Knapsack_2(weight, val, maxCap);
	return 0;
}





Measured memory_bytes: 83216
//BISMILLAHIRRAHMANIRRAHIM....*/
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<cassert>
#include<sstream>
#include<queue>
#include<stack>
#include<iostream>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#define ll long long
#define pb push_back
#define MP make_pair
#define vsort(v) sort(v.begin(),v.end())
#define NL printf("\n")
#define mod 1000000009
#define P(n) printf("%d",n)
#define xx first
#define yy second
#define bit(n) __builtin_popcount(n)
#define sc(a) scanf("%d",&a)
#include <set>
#include<map>
using namespace std;

// freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
/*int fx[] = {1,-1,0,0};
int fy[] = {0,0,1,-1};

int month[]= {31,28,31,30,31,30,31,31,30,31,30,31};
string day[]= {"Monday", "Tuesday", "Wednesday","Thursday","Friday", "Saturday", "Sunday"};
*/
 int ans = 1;
 void solve(int i, int j,int n){
        cout << "X";
       if(i==1 && j==1) return ;
       if(i==n && j==1) return ;
       if(i==n && j==n) return ;
       if(i==1 && j==n) return ;

       solve(i-1,j-1,n);
       solve(i-1,j+1,n);
       solve(i+1,j-1,n);
       solve(i+1,j+1,n);

       cout << endl;

     return ;
 }
 int solve2(int n){
    int o=0;
    if(n==0) return 1;
    while(n>0){
        if(n%10==0) o++;
        n/=10;
    }
    return o;
 }
 void sol(char c){
     char d=c+1;
  cout << d << endl;
  return ;
 }
 int solve3(int *a, int n){

        int ans = 1e7;
        set<int> st,st2;
          for(int i = 1; i<=n; i++){
             st.insert(a[i]);
          }
          int sz = st.size();
          if(sz==1) return 1;
          int l = 1;
          for(int i  = 1; i<=n; i++){
               st2.insert(a[i]);
               if(st2.size()==sz){
                 st2.erase(a[l]);
                 while(a[l]==a[l+1] && l<n){
                    l++;
                 }
                ans = min(ans,i-l+1);
                 if(i<=l) i = l;
                 l++;
               }
          }
  return ans;

 }


 int main()
{
   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

  //   sieve();

        int w,h,n;
        cin >> w >> h >> n;
         ans = 0;
        int mx = max(w,h);
        for(int i = 1; i<=w*h; i++){
           ans +=mx;
           if(ans>=n){
            cout << i << endl;
            return 0;
           }
        }

return 0;
}


Measured memory_bytes: 256
/* Author - thiolhub */

#include <bits/stdc++.h>

using namespace std;

#define ll              long long int
#define ld              long double
#define db              double
#define pi              3.1415926535897932384626
#define PI              acos(-1.0)
#define endl            "\n"
#define mod             1000000007
#define mk              make_pair
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(t)            ll t; cin>>t; while(t--)
#define sc(a)	        scanf("%lld",&a);
#define pr(a)	        printf("%lld\n",a)
#define f(i,a,n)		for(ll i=a;i<n;i++)
#define m(a)		    memset(a,0,sizeof(a))
#define FastIO          ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)



int main(){ FastIO;

int i,j,n;cin>>n;
int a[n][3],dp[n][3];
for(i=0;i<n;i++)
{
	for(j=0;j<3;j++) cin>>a[i][j];
}
memset(dp,0,sizeof(dp));
for(i=0;i<3;i++) dp[0][i]=a[0][i];
for(i=1;i<n;i++)
{
	for(j=0;j<3;j++)
	{
		dp[i][j]=a[i][j]+max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3]);
	}
}
cout<<*max_element(dp[n-1],dp[n-1]+3);

return 0;
}


Measured memory_bytes: 2560
import java.util.*;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static int M = 5;
	public static void main(String[] args) {
		int i,j,k;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		char[] s = null; 
		long[] ma = new long[M]; 
		for (i = 0; i < n; i++) {
			s = sc.next().toCharArray();
			switch(s[0]) {
			case 'M':
				ma[0]++;
				break;
			case 'A':
				ma[1]++;
				break;
			case 'R':
				ma[2]++;
				break;
			case 'C':
				ma[3]++;
				break;
			case 'H':
				ma[4]++;
				break;
			}
		}
		sc.close();
		long ans = 0L;
		for (i = 0; i < M-2; i++) {
			for (j = i+1; j < M-1; j++) {
				for (k = j+1; k < M; k++) {
					ans += ma[i]*ma[j]*ma[k];
				}
			}
		}
		out.println(ans);
	}
}


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

using namespace std;

using ll = long long;

#define ALL(A) A.begin(),A.end()

void ALLIN1_NUMBER(vector<ll>& V)
{
    for(auto& x : V)
    {
        cin >> x;
    }
}

bool ans_bool(int M)
{
    map<int,int> counter;
    for(int i=0;i<M;i++)
    {
        int a,b;
        cin >> a >> b;

        counter[a]++;
        counter[b]++;
    }

    bool ans = true;

    for(auto x : counter)
    {
        if(x.second%2!=0) ans = false;
    }

    return ans;
}

template<class T>
void OUT0(T N)
{
    cout << N << endl;
}

static const double pi = acos(-1.0);

double Cos(double D)
{
    return cos(pi/180 * D);
}

int main()
{
    ll N,M;
    cin >> N >> M;

    bool ans = ans_bool(M);

    if(ans) OUT0("YES");
    else OUT0("NO");

    return 0;
}

Measured memory_bytes: 4352
let tap f x = f x; x

let n = Scanf.sscanf (read_line ()) "%d" @@ fun n  -> n
let e = Array.init (n - 1) @@ fun _ -> Scanf.sscanf (read_line ()) "%d %d %d" @@ fun u v w -> (u, v, w)

let e = tap
  (fun tbl -> Array.iter (fun (u, v, w) -> Hashtbl.add tbl (u - 1) ((v - 1), w); Hashtbl.add tbl (v - 1) ((u - 1), w)) e)
  (Hashtbl.create n)


let f d =
  let que = Queue.create () in
  Queue.add (0, 0) que;
  while not (Queue.is_empty que) do
    let (i, w) = Queue.pop que in
    d.(i) <- w;
    List.iter (fun (a, b) -> if d.(a) = -1 then Queue.add (a, w + b) que) @@ Hashtbl.find_all e i
  done

let () =
  let d = Array.make n (-1) in
  f d;
  d |> Array.map (fun i -> string_of_int (i mod 2)) |> Array.iter print_endline

Measured memory_bytes: 28800
n = int(input())
c = [int(input()) for _ in range(n)]
mod = 10 ** 9 + 7

# 解説AC
dp = [1] * n
color = [-1] * max(c)
for i, ci in enumerate(c):
    dp[i] = dp[i - 1]
    if 0 <= color[ci - 1] < i - 1:
        dp[i] += dp[color[ci - 1]]
        dp[i] %= mod
    color[ci - 1] = i
print(dp[-1] % mod)


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

using ll = long long;
static const ll MOD = 1e9 + 7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string k;
  int d;
  cin >> k >> d;
  
  ll dp[k.size() + 1][2][d];
  for (int i = 0; i < k.size() + 1; i++) {
    for (int j = 0; j < 2; j++) {
      for (int ii = 0; ii < d; ii++) {
        dp[i][j][ii] = 0;
      }
    }
  }
  dp[0][0][0] = 1;
  
  for (int i = 0; i < k.size(); i++) {
    for (int j = 0; j < 2; j++) {
      for (int ii = 0; ii < d; ii++) {
        for (int next = 0; next <= (j ? 9 : k[i] - '0'); next++) {
          dp[i + 1][j | (next < k[i] - '0')][(ii + next) % d] += dp[i][j][ii];
          dp[i + 1][j | (next < k[i] - '0')][(ii + next) % d] %= MOD;
        }
      }
    }
  }
  
  cout << (dp[k.size()][0][0] + dp[k.size()][1][0] - 1 + MOD) % MOD << '\n';
}

Measured memory_bytes: 15872
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif


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

    int N; cin >> N;
    vi A(N); REP(i, N) cin >> A[i];

    ll ans = 0;
    ll sum = 0;
    int r = 0;
    REP(l, N) {
        while(r < N && (sum & A[r]) == 0) {
            sum += A[r];
            r++;
        }
        ans += (r - 1) - l + 1;

        sum -= A[l];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024