akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
    	if(c == '-') f = -1;
    	c = getchar();
    }
    while(c >= '0' && c <= '9') {
    	res = res * 10 +c - '0';
    	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
    	out(x / 10);
    }
    putchar('0' + x % 10);
}
bool Query(int a,int b) {
    putchar('?');space;out(a);space;out(b);enter;
    fflush(stdout);
    char s[5];
    scanf("%s",s + 1);
    if(s[1] == 'Y') return 1;
    else return 0;
}
int sta[MAXN],top,A,B;
int ans[MAXN];
void Solve() {
    read(A);read(B);
    if(A <= B) {puts("Impossible");}
    else {
        for(int i = 0 ; i < A + B ; ++i) {
            if(!top) sta[++top] = i;
            else {
                if(!Query(sta[top],i)) --top;
                else sta[++top] = i;
            }
        }
        int h = sta[top];

        for(int i = 0 ; i < A + B ; ++i) {
            if(Query(h,i)) ans[i] = 1;
            else ans[i] = 0;
        }
        putchar('!');space;
        for(int i = 0 ; i < A + B ; ++i) {
            out(ans[i]);
        }
        enter;
    }
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}


Measured memory_bytes: 724
#include <bits/stdc++.h>
using namespace std;
short grd[5010][5010];
short func(short a,short b){
	return max(a,b);
}
int main(){
	int n,m;	cin>>n>>m;
	for(int i=0;i<m;i++){
		int a,b,x;	cin>>a>>b>>x;
		grd[a][b]=x+1;
	}
	for(int i=1;i<n;i++){
		for(int j=1;j<=n;j++){
			if(grd[i][j]){
				grd[i+1][j]=func(grd[i+1][j],grd[i][j]-1);
				if(j!=n){
					grd[i+1][j+1]=func(grd[i+1][j+1],grd[i][j]-1);
				}
			}
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(grd[i][j])	ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 48920
import java.util.*;

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

        int[] c = new int[n-1];
        int[] s = new int[n-1];
        int[] f = new int[n-1];
        for(int i = 0;i < n-1;i++) {
            String[] vals = sc.nextLine().split(" ");
            c[i] = Integer.parseInt(vals[0]);
            s[i] = Integer.parseInt(vals[1]);
            f[i] = Integer.parseInt(vals[2]);
        }

        for(int j = 0;j < n-1;j++){
            int t = 0;
            for(int k = j;k < n-1;k++){
                if(t <= s[k]){
                    t = s[k];
                }else{
                    t += (t-s[k]) % f[k] == 0?0:f[k] - (t-s[k]) % f[k];
                }
                t += c[k];
            }
            System.out.println(t);
        }
        System.out.println(0);
        sc.close();
    }

    static int getInt(String val) {
        return Integer.parseInt(val);
    }

}



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

#define lli long long int
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define INF 1000000007
#define endl "\n"

lli a;

int main(){
	cin>>a;
	cout<<(a/500)*1000+((a%500)/5)*5;

	//system("pause");
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node {
  int key;
  Node *right, *left, *parent;
};

Node *root, *NIL;

Node * find(Node *u, int k) {
  while(u != NIL && k != u->key) {
    if(k < u->key) u = u->left;
    else u = u->right;
  }

  return u;
}

void insert(int k) {
  Node *y = NIL;
  Node *x = root;
  Node *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while (x != NIL) {
    y = x;
    if(z->key < x->key) {
      x = x ->left;
    } else {
      x = x->right;
    }
  }
  z->parent = y;
  if(y == NIL) {
    root = z;
  } else {
    if(z->key < y->key) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

void inorder(Node*u) {
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}

void preorder(Node *u) {
  if(u == NIL) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

int main() {
  int n, i, x;
  string com;

  scanf("%d", &n);
  for(i = 0; i < n; i++) {
    cin >> com;
    if(com[0] == 'f') {
      scanf("%d", &x);
      Node *t = NIL;
      t = find(root, x);
      if(t != NIL) printf("yes\n");
      else printf("no\n");
    } else if(com == "insert") {
      scanf("%d",&x);
      insert(x);
    } else if(com == "print") {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}



Measured memory_bytes: 22012
#include <bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,m,b[100001],a[100001],c[100001],res,ans,x,y,z;
main(){
	cin>>n>>m;
	r(i,m)scanf("%d",&b[i]);
	r(i,m-1)a[min(b[i],b[i+1])]++,a[max(b[i],b[i+1])]--;
	r(i,n-1){
		res+=a[i+1];
		scanf("%d%d%d",&x,&y,&z);
		ans+=min(res*x,res*y+z);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4744
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <assert.h>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

ll mod;
const int N = 6000;
ll fact[N], invf[N], two[N];

ll add(ll x, ll y){
    return (x+y)%mod;
}

ll mul(ll x, ll y){
    return (x%mod)*(y%mod)%mod;
}

ll powll(ll x, ll y){
    ll res = 1LL;
    while(y){
        if (y & 1LL)
            res *= x;
        res %= mod;
        x = (x*x) % mod;
        y >>= 1LL;
    }
    return res;
}

ll divll(ll x, ll y){
    return (x * powll(y,mod-2)) % mod;
}

ll nPr(ll n, ll r){
    if (n < r || r < 0) return 0;
    return mul(fact[n], invf[n-r]);
}

ll nCr(ll n, ll r){
    if (n < r || r < 0) return 0;
    return mul(mul(fact[n], invf[r]), invf[n-r]);
}

int main() {
    string s;
    cin >> s;
    int ans = 700;
    for (char c : s) if (c == 'o') ans += 100;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; }
    mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { mint res(*this); return res+=a; }
    mint operator-(const mint a) const { mint res(*this); return res-=a; }
    mint operator*(const mint a) const { mint res(*this); return res*=a; }
    mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; }
    // for prime mod
    mint inv() const { return pow(mod-2); }
    mint& operator/=(const mint a) { return (*this) *= a.inv(); }
    mint operator/(const mint a) const { mint res(*this); return res/=a; }
};

vector<ll> inv,fact,invfact;
void mod_build(int n){  
  fact.resize(n+1); inv.resize(n+1); invfact.resize(n+1);
  fact[0]=inv[0]=invfact[0]=1; inv[1]=1;
  rep(i,n){
    fact[i+1]=fact[i]*(i+1)%mod;
    if(i>0)inv[i+1]=mod-inv[mod%(i+1)]*(mod/(i+1))%mod;
    invfact[i+1]=invfact[i]*inv[i+1]%mod;
  }
}
ll perm(int n,int k){ if(n<0||k<0||k>n){ return 0; } else { return fact[n]*invfact[n-k]%mod; } }
ll comb(int n,int k){ if(n<0||k<0||k>n){ return 0; } else { return (fact[n]*invfact[n-k]%mod)*invfact[k]%mod; }}
ll modpow(ll n,ll k){
  k%=mod-1; if(k<0)k+=mod-1;
  ll ret=1; while(k){ if(k&1)ret=ret*n%mod; n=n*n%mod; k>>=1; }
  return ret;
}
ll modinv(ll a){ return modpow(a, mod-2); }

int main(){
  ll n,k;
  cin >> n >> k;
  mint ans = 0;
  vector<mint> a(mx,0);
  for(ll i=k; i>=1; i--){
    if(k/i==1){
      ans += i;
      a[i] = 1;
      continue;
    }
    ll al = k/i;
    mint tmp = modpow(al,n);
    for(int j=2; j<=al; j++){
      tmp -= a[i*j];
    }
    a[i] = tmp;
    ans += tmp*i;
  }
  cout << ans.x << endl;
  return 0;
}


Measured memory_bytes: 4048
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Point{
	void set(double arg_x,double arg_y){
		x = arg_x;
		y = arg_y;
	}
	double x,y;
};

int X1,X2,X3,Y1,Y2,Y3;
Point A,B,C,center;
Point face_A,face_B,face_C;
double len_A,len_B,len_C;
double half_len_sum,S;
double inner_R;
double dist1,dist2,dist3;
double R1,R2,R3;


//交点を求める関数
Point calc_Cross_Point(double x1,double x2,double x3,double x4,double y1,double y2,double y3,double y4){
	Point ret;
	ret.x = ((x2-x1)*(y3*(x4-x3)+x3*(y3-y4))-(x4-x3)*(y1*(x2-x1)+x1*(y1-y2)))/((y2-y1)*(x4-x3)-(y4-y3)*(x2-x1));
	if(x1 != x2){
		ret.y = ((y2-y1)*ret.x+y1*(x2-x1)+x1*(y1-y2))/(x2-x1);
	}else{
		ret.y = ((y4-y3)*ret.x+y3*(x4-x3)+x3*(y3-y4))/(x4-x3);
	}
	return ret;
}

//インタフェース関数
Point calc_Cross_Point(Point a,Point b,Point c,Point d){
	return calc_Cross_Point(a.x,b.x,c.x,d.x,a.y,b.y,c.y,d.y);
}

double calc_dist(Point a,Point b){
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

void func(){

	A.set(X1,Y1);
	B.set(X2,Y2);
	C.set(X3,Y3);

	len_A = calc_dist(B,C);
	len_B = calc_dist(C,A);
	len_C = calc_dist(A,B);

	//総長の半分
	half_len_sum = (len_A+len_B+len_C)/2;
	S = sqrt(half_len_sum*(half_len_sum-len_A)*(half_len_sum-len_B)*(half_len_sum-len_C));

	//内接円の半径
	inner_R = (2.0*S)/(len_A+len_B+len_C);

	 //各頂点から角の二等分線を伸ばす
	 face_A.x = (len_B*B.x+len_C*C.x)/(len_B+len_C);
	 face_A.y = (len_B*B.y+len_C*C.y)/(len_B+len_C);

	 face_B.x = (len_C*C.x+len_A*A.x)/(len_A+len_C);
	 face_B.y = (len_C*C.y+len_A*A.y)/(len_A+len_C);

	 //内心円の座標は、角の二等分線の交点
	 center = calc_Cross_Point(A,face_A,B,face_B);

	 //内心と各頂点への距離
	 dist1 = calc_dist(center,A);
	 dist2 = calc_dist(center,B);
	 dist3 = calc_dist(center,C);

	 //公式
	 R1 = inner_R/(2.0*(half_len_sum-len_A))*(half_len_sum+dist1-inner_R-dist2-dist3);
	 R2 = inner_R/(2.0*(half_len_sum-len_B))*(half_len_sum+dist2-inner_R-dist1-dist3);
	 R3 = inner_R/(2.0*(half_len_sum-len_C))*(half_len_sum+dist3-inner_R-dist1-dist2);

	 printf("%.10lf %.10lf %.10lf\n",R1,R2,R3);
}

int main(){

	while(true){
		scanf("%d %d %d %d %d %d",&X1,&Y1,&X2,&Y2,&X3,&Y3);
		if(X1 == 0 && Y1 == 0 && X2 == 0 && Y2 == 0 && X3 == 0 && Y3 == 0)break;

		func();
	}

	return 0;
}



Measured memory_bytes: 3216
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll MOD=1e6+3;


int main(){
	int N;
	cin>>N;
	
	int A[2005];
	int s=0;
	rep(i,N){
		cin>>A[i];
		s+=A[i];
	}
	int h=(s+1)/2;
	
	bitset<4000005> b;
	b |= 1;
	rep(i,N){
		b |= (b<<A[i]);
	}
	int ans=h;
	while(true){
		if(b[ans]){
			break;
		}
		ans++;
	}
	cout<<ans<<endl;
}

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

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  int a[3], k;
  cin >> a[0] >> a[1] >> a[2] >> k;

  sort(a, a + 3);
  while (k--) a[2] *= 2;

  // 解答
  cout << a[0] + a[1] + a[2] << endl;

  return 0;
}


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

using namespace std;

vector<int> getDist(const vector<vector<int>>& g, int start){
    const int n = g.size();
    vector<int> res(n, -1);
    queue<int> qu; qu.push(start);
    res[start] = 0;
    while(!qu.empty()){
        int p = qu.front(); qu.pop();
        for(auto& t : g[p]){
            if(res[t] != -1) continue;
            res[t] = res[p] + 1;
            qu.push(t);
        }
    }
    return res;
}

long long check(const vector<vector<int>>& g, const vector<int>& start){
    auto cur = start;
    vector<int> check(g.size(), 0);
    for(auto& t : cur) check[t] = 1;
    long long res = 0;
    while(!cur.empty()){
        int maxDeg = 1;
        for(auto& t : cur) maxDeg = max<int>(maxDeg, g[t].size()-1);
        res *= maxDeg;
        vector<int> next;
        for(auto& t : cur){
            res += maxDeg - (g[t].size() - 1);
            for(auto& p : g[t]){
                if(check[p]) continue;
                check[p] = 1;
                next.push_back(p);
            }
        }
        cur = next;
    }
    return res;
}

int main(){
    int N;
    while(cin >> N){
        vector<vector<int>> g(N);
        for(int i=0;i<N-1;i++){
            int a, b; cin >> a >> b;
            g[a-1].push_back(b-1);
            g[b-1].push_back(a-1);
        }
        auto d = getDist(g, 0);
        int s = distance(d.begin(), max_element(d.begin(), d.end()));
        d = getDist(g, s);
        s = distance(d.begin(), max_element(d.begin(), d.end()));
        vector<int> cur;
        const int maxD = d[s];
        const int color = (maxD+2)/2;
        while(true){
            if(min(d[s], maxD - d[s]) == color-1){
                cur.push_back(s);
            }
            if(d[s] == 0) break;
            for(auto& t : g[s]){
                if(d[t] + 1 == d[s]){
                    s = t;
                    break;
                }
            }
        }
        long long res = check(g, cur);
        if(cur.size() == 1){
            for(auto& t : g[cur[0]]){
                vector<int> start = {cur[0], t};
                res = min(res, check(g, start));
            }
        }
        cout << color << " " << res << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)

//-----------------------------------------------
ll gcd(ll a,ll b){   //ユークリッドの互除法で最大公約数を求める再起関数
  if(b==0) return a;
  else return gcd(b,a%b);
}
//------------------------------------------------
//Bいかにc,dの約数が何個あるかを調べる　かぶりは最小公倍数を利用して求められる。
//c*d=最大公約数＊最大公倍数
int main(){
  ll a,b,c,d,l,g,count,ans;
  cin>>a>>b>>c>>d;
  g=gcd(c,d);//最大公約数
  l=c*d/g;//最小公倍数
  count=b/c+b/d-b/l-(a-1)/c-(a-1)/d+(a-1)/l;
  ans=b-a+1-count;
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
int gcd(int a,int b)
{
	return b==0?a:(gcd(b,a%b));
}
int main()
{
	int k,i,j,p,sum=0;
	scanf("%d",&k);
	for(i=1;i<=k;i++)
	for(j=1;j<=k;j++)
	for(p=1;p<=k;p++)
	sum+=gcd(gcd(i,j),p);
	printf("%d",sum);
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(int i=(int)(st),i##end=(int)(ed);i<=i##end;++i)
#define DREP(i,st,ed) for(int i=(int)(st),i##end=(int)(ed);i>=i##end;--i)
template<typename T>bool chkmin(T &x,const T &y){return x>y?x=y,1:0;}
template<typename T>bool chkmax(T &x,const T &y){return x<y?x=y,1:0;}
#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif
template<typename T>T read(){
	T 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^48),c=getchar();
	return x*f;
}
#define read() read<int>()
template<typename T>void write(T x,char c){
	static char t[25];
	static int tlen;
	t[tlen=1]=c;
	if(x<0)putchar('-'),x=-x;
	do t[++tlen]=(x%10)^48;
	while(x/=10);
	while(tlen)putchar(t[tlen--]);
}
#define pb push_back
typedef long long ll;
typedef double lf;
const lf pi=acos(-1.0);
const int maxn=305;
char s[maxn];
int n,m;
int dp[maxn][maxn][maxn];
int main(){
	scanf("%s",s+1);
	n=strlen(s+1),m=read();
	REP(i,0,n)
		REP(j,0,n-i+1)
			REP(k,0,m){
				if(i>=1)chkmax(dp[i][j][k],dp[i-1][j][k]);
				if(j>=1)chkmax(dp[i][j][k],dp[i][j-1][k]);
				if((i>=1)&&(j>=1)){
					if(s[i]==s[n-j+1])
						chkmax(dp[i][j][k],dp[i-1][j-1][k]+2-((i+j==n+1)&&(i==n-j+1)));
					else if(k>=1)
						chkmax(dp[i][j][k],dp[i-1][j-1][k-1]+2-((i+j!=n+1)&&(i==n-j+1)));
				}
			}
	int ans=0;
	REP(i,1,n)
		REP(j,0,m)
			chkmax(ans,dp[i][n-i+1][j]);
	write(ans,'\n');
	return 0;
}

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

int main()
{
    string s;
    cin >> s;
    vector<string> v = {"Sunny", "Cloudy", "Rainy"};
    for(int i=0; i<3; i++){
        if(v[i] == s){
            cout << v[(i+1)%3] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <deque>

int main(){
  std::deque<char > deque;
  std::string S;
  std::cin >> S;
  for (int i=0; i<S.length(); i++){
    deque.push_back(S[i]);
  }
  int Q;
  scanf("%d", &Q);
  bool flip = false;
  for (int i=0; i<Q; i++){
    //printf("i=%d\n", i);
    int T;
    scanf("%d", &T);
    //printf("T=%d\n", T);
    if (T==1){
      flip = !flip;
    } else {
      int F;
      char C;
      std::cin >> F >> C;
      if ((flip && F==1) || (!flip && F==2)){ // 末尾に追加
        deque.push_back(C);
      } else { // 銭湯に追加
        deque.push_front(C);
      }
    }
  }
  if (flip){
    std::reverse(deque.begin(), deque.end());
  }
  std::string ans;
  for (int i=0; i<deque.size(); i++){
    ans += deque[i];
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 1340
import sys
import numpy as np
from fractions import gcd
from functools import reduce
import io
import math

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()

N, M = rl()
A = np.array(rl())
B = A // 2

def merge(a, b):
    g = gcd(a, b)
    a //= g; b //= g
    if a%2 == 0 or b%2 == 0:
        return 0
    n = g * a * b
    if n > 10 ** 9:
        return 0
    return n

x = reduce(merge, B)
if x == 0:
    answer = 0
else:
    answer = M // x - M // (2*x)

print(answer)

Measured memory_bytes: 24944
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 2000001
//???????????£????????????
struct Node{
  int key;
  struct Node *next,*prev;
};

struct Node *nil;

struct Node* listSearch(int key){
  struct Node *cur=nil->next;
  while(cur!=nil&&cur->key!=key){
    cur=cur->next;
  }
  return cur;
}

void init(){
  nil=(struct Node *)malloc(sizeof(struct Node));
  nil->next=nil;
  nil->prev=nil;
}

void output(){
  struct Node *cur=nil->next;
  int i=0;
  while(1){
    if(cur==nil) break;
    if(i++>0) printf(" ");
    printf("%d",cur->key);
    cur=cur->next;
    }
  printf("\n");
}

void delNode(struct Node *t){
  if(t==nil) return;
  t->prev->next=t->next;
  t->next->prev=t->prev;
  free(t);
}

void delF(){
  delNode(nil->next);
}

void delL(){
  delNode(nil->prev);
}

void delKey(int key){
  delNode(listSearch(key));
}

void insert(int key){
  struct Node *a=(struct Node *)malloc(sizeof(struct Node));
  a->key=key;
  a->next=nil->next;
  nil->next->prev=a;
  nil->next=a;
  a->prev=nil;
}

int main(){
  int n,key,i,j,npoi=0,ndel=0,size=0;
  char c[12];

  scanf("%d",&n);

  init();
  for(i=0;i<n;i++){
    scanf("%s %d",c,&key);

    if(c[0]=='i'){
      insert(key);
      npoi++;
      size++;
    }
    else if(c[0]=='d'){
if(strlen(c)>6){
      if(c[6]=='F') delF();
      else if(c[6]=='L') delL();
    } else {
        delKey(key);
        ndel++;
      }
        size--;
      }
    }
    output();
  return 0;
}

Measured memory_bytes: 31788
import java.util.Scanner;

class Main{
	public static void main(String[] args) 	{
		Scanner sc = new Scanner(System.in);
		int youso = sc.nextInt();
		int hairetsu[] = new int[youso];
		for(int i = 0;i < youso;i++) {
			hairetsu[i] = sc.nextInt();
		}
		int count = 0;
		int k,j;
		for(k = 0;k< youso - 1;k++) {
			int min = k + 1;
			for(j = k + 1;j <= youso - 1;j++) {
				if(hairetsu[j] < hairetsu[min]) min = j;
			}
			if(hairetsu[k] > hairetsu[min]) {
					int swap = hairetsu[k];
					hairetsu[k] = hairetsu[min];
					hairetsu[min] = swap;
					count++;
			}
		}
		for(int i = 0;i < youso;i++) {
			System.out.printf("%d",hairetsu[i]);
			if(i != youso - 1) System.out.printf(" ");
		}
		System.out.printf("\n%d\n",count);
		sc.close();
	}	
}


Measured memory_bytes: 26568
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  string s,n;
  cin>>s>>n;
  if(s[0]==n[2] && s[2]==n[0] && s[1]==n[1]) cout<<"YES"<<'\n';
  else cout<<"NO"<<'\n';
  return 0;
}


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

int main() {
  vector<int> atAntenna(5);
  int k;
  for(int i = 0; i < 5; i++) {
    cin >> atAntenna.at(i);
  }
  cin >> k;
  
  bool ans = true;
  for(int i = 0; i < 5; i++) {
    for(int j = 0; j < 5; j++) {
      if(atAntenna.at(j) - atAntenna.at(i) > k) {
        ans = false;
        break;
      }
    }
  }
  if(ans) {
    cout << "Yay!" << endl;
  }
  else {
    cout << ":(" << endl;
  }
}  

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;



public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n =in.nextInt(),m=in.nextInt(),k=in.nextInt();
        if (k == 0){
            System.out.println("Yes");
            return;
        }
        for (int i = 0; i <= n ; i++) {
            for (int j = 0; j <=m ; j++) {
                if (i *(m-j) + j *(n-i) == k){
                    System.out.println("Yes");
                    return;
                }
            }
        }
        System.out.println("No");
    }
}















Measured memory_bytes: 21844
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] a = new int[m];
		int ans = 0;
		for(int i = 0; i<n; i++){
			int k = sc.nextInt();
			for(int j = 0; j<k; j++){
				int x = sc.nextInt()-1;
				a[x]++;
			}
		}
		for(int i = 0; i<m; i++){
			if(a[i]==n){
				ans++;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23764
d,g=map(int,input().split())
g//=100
A=[]
for i in range(d):
    p,c=map(int,input().split())
    c//=100
    A.append([i+1, p, c])
ans=float("inf")
# print(A)
for bit in range(1<<d):
    now=0 ; mon=0
    for i in range(d):
        if bit>>i &1:
            now+=A[i][0]*A[i][1]+A[i][2]
            mon+=A[i][1]
    # print(bit,now,mon)
    if now>=g:
        ans=min(ans,mon)
        continue
        
    for i in range(d-1,-1,-1):
        if bit>>i &1==0:
            for j in range(A[i][1]): #余りに何問とくか
                now+=A[i][0] ; mon+=1
                if now>=g:
                    ans=min(ans,mon)
                    continue
                else:
                    continue
print(ans)

Measured memory_bytes: 9184
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <locale>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

int main() {
    cin.tie(0);

    int n, k;
    string s;

    cin >> n;
    cin >> s;
    cin >> k;

    for (int i = 0; i < n; i++) {
        if (s[i] == s[k - 1])
            cout << s[i];
        else
            cout << "*";
    }
    cout << endl;
}

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

int main() {
    int n, m; cin >> n >> m;
    priority_queue<int> a;
    int v;
    for (int i = 0; i < n; i++) {
        cin >> v;
        a.push(v);
    }

    for (int i = 0; i < m; i++) {
        v = a.top();
        a.pop();
        a.push(v / 2);
    }
    long long int sum = 0;
    for (int i = 0; i < n; i++) {
        sum += a.top();
        a.pop();
    }

    cout << sum << endl;

    return 0;
}


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

using namespace std;
#define int long long
#define pb push_back
template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 & y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 & y) {if (x < y) x = y;}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	for (auto &i : a)
		cin >> i;
	auto b = a;
	sort(b.begin(), b.end());
	if (a == b) {
		cout << "YES";
		return 0;
	}
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			swap(a[i], a[j]);
			if (a == b) {
				cout << "YES";
				return 0;
			}
			swap(a[i], a[j]);
		}
	}
	cout << "NO";
	return 0;
}

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

const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x=0):x((x%mod+mod)%mod){}
	mint operator-() const { return mint(-x);}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res+=a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res-=a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res*=a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if (t&1) a *= *this;
		return a;
	}
	
	// for prime mod
	mint inv() const {
		return pow(mod-2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res/=a;
	}
};

int main() {
	int n;
	cin >> n;
	mint ans = 1;
	rep(i, n) ans *= (i+1);
	cout << ans.x << endl;
	return 0;
}

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

using namespace std;

long long P_is_not_2_5(long long N, long long P, const string& S) {
    map<long long, long long> residual;
    residual.insert(make_pair(0LL, 1LL));
    long long pow10 = 1;
    long long curr = 0LL;
    for (long long i = N - 1; i >= 0; --i) {
        //long long x = (curr + pow10 * (long long)atoi(S.substr(i, 1).c_str())) % P;
        curr += pow10 * (long long)atoi(S.substr(i, 1).c_str());
        curr %= P;
        if (residual.count(curr) == 0) {
            residual.insert(make_pair(curr, 1LL));
        }
        else {
            residual[curr] += 1;
        }
        //curr = x;
        pow10 *= 10;
        pow10 %= P;
    }
    long long ans = 0;
    for (auto it : residual) {
        long long n = it.second;
        if (n >= 2) {
            ans += n * (n - 1) / 2;
        }
    }
    return ans;
}

long long P_is_2_or_5(long long N, long long P, const string& S) {
    long long ans = 0LL;
    for (long long i = 0; i < N; ++i) {
        long long c = (long long)atoi(S.substr(i, 1).c_str());
        if (c % P == 0) {
            ans += i + 1;
        }
    }
    return ans;
}

void Main() {
    long long N, P;
    cin >> N >> P;
    string S;
    cin >> S;

    long long ans = 0LL;
    if (P == 2LL || P == 5LL) {
        ans = P_is_2_or_5(N, P, S);
    }
    else {
        ans = P_is_not_2_5(N, P, S);
    }
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  string s;
  cin >> s;
  ll k=s.size();
  ll ans=0,c=0;
  rep(i,k){
    if(s[i]=='A'||s[i]=='T'||s[i]=='G'||s[i]=='C'){
      c++;
      ans=max(ans,c);
    }
    else
      c=0;
  }
  cout << ans << endl;
}


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

int main() {
  long long x, k, d;
  cin >> x >> k >> d;
  if (x < 0) x *= -1;

  long long kk = min(x / d, k);
  x -= kk * d;
  k -= kk;

  long long res = x;
  if (k) {
    if (k%2 == 1) {
      res = abs(x-d);
    }
  }

  cout << res << endl;

  return 0;
}



Measured memory_bytes: 3628
package main

import (
	"fmt"
	"strings"
)

func main() {
	var h, w, cnt int
	fmt.Scan(&h, &w)
	m := make([]string, h)
	for i := range m {
		fmt.Scan(&m[i])
		cnt += strings.Count(m[i], "#")
	}
	if cnt == h+w-1 {
		fmt.Println("Possible")
	} else {
		fmt.Println("Impossible")
	}

}


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


/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace
#define mp make_pair


/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())


/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;


/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;


signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  int n, k; cin >> n >> k;
  vi a(n);

  rep(i, n) cin >> a[i];

  sort(all(a));
  cout << accumulate(a.begin(), a.begin()+k,0) << endl;
}


Measured memory_bytes: 3656
#include<iostream>
using namespace std;
const int N = 100;
typedef long long LL;
LL fibonacci(LL n) {
    if (n == 1) {
        return 0;
    }

    if (n == 2) {
        return 1;
    }

    LL a = 0;
    LL b = 1;
    LL c = 0;
    for (LL i = 3; i < n + 1; i++) {
        c = a + b;
        a = b;
        b = c;
    }
    return c;
}int main(){
	int n;
	LL m;
	cin>>n;
	m=2*fibonacci(n)+fibonacci(n+1);
	cout<<m<<endl;
	return 0;
}


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

using namespace std;

int main() {
	string s;
	int ans=1, a=0;
	cin >> s;
	for(int i=0; i<3; i++){
		if(s[i]=='R'){
			a=1;
			if(s[i]==s[i+1]) ans++;
		}
	}
	if(ans==1 && a==0){
		cout << 0;
	}else{
		cout << ans;
	}
	return 0;
}



Measured memory_bytes: 3624
s = input()
b = True

for i in range(int((len(s) - 1) / 2)):
    if s[i] != s[-1 - i] or s[i] != s[int((len(s) - 1) / 2) - i - 1] or s[int((len(s) + 3) / 2) + i - 1] != s[-1 - i]:
        b = False
        
if b:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
from collections import deque
from collections import defaultdict

n = int(input())

graph = defaultdict(list)

for i in range(n):
    u, k, *v = map(int, input().split())
    for v in v:
        graph[u].append(v)

ans = [-1] * (n + 1)

q = deque([1])
ans[1] = 0

while q:
    c = q.popleft()
    for v in graph[c]:
        if ans[v] == -1:
            ans[v] = ans[c] + 1
            q.append(v)

for i in range(1, n + 1):
    print(i, ans[i])


Measured memory_bytes: 6032
#include <bits/stdc++.h>
#define int long long
#define rank Asdfiasofsad
#define MAX_N N
#define N 12
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
int Max(int &a,int b){return a=max(a,b);}
int Min(int &a,int b){return a=min(a,b);}

class UF{
public:
  vector<int> par;
  UF(){par.resize(MAX_N);for(int i=0;i<MAX_N;i++)par[i]=i;}
  UF(int n){par.resize(n);for(int i=0;i<n;i++)par[i]=i;}

  int find(int x){
    if(par[x]==x)return x;
    return par[x]=find(par[x]);
  }
  
  void unite(int x,int y){
    x=find(x), y=find(y);
    if(x==y)return;
    if(x > y) swap(x,y);
    par[y]=x;
  }

  bool same(int x,int y){return find(x)==find(y);}
};

typedef unsigned long long ull;
ull VtoH(vector<int> &v){
  const int B = 1777771;
  int res = 0;
  for(int a:v) res = res*B + a;
  return res;
}

int h,w;
string mp[N];
int check(int y,int bit){
  int res = 1;
  for(int i=0;i<w;i++){
    if((bit>>i&1) && mp[y][i] != '?' && mp[y][i] != '#') res = 0;
    if(!(bit>>i&1)&& mp[y][i] != '?' && mp[y][i] != '.') res = 0;
    if(i<w-1 && !(bit>>i&1) && !(bit>>(i+1)&1)) res = 0;
  }
  return res;
}

bool check(int y,int ue,int bit){
  if(!check(y,bit)) return 0;
  for(int i=0;i<w;i++)if(!(bit>>i&1) && !(ue>>i&1)) return 0;
  return 1;
}

UF getNx(int y,int ue,UF &T,int bit){
  UF res(w);
  for(int i=0;i<w;i++)
    for(int j=i+1;j<w;j++)
      if((bit>>i&1) && (ue>>i&1) && (bit>>j&1) && (ue>>j&1) && T.same(i,j)) res.unite(i,j);
  
  for(int i=0;i<w;i++){
    if((bit>>i&1) || !(ue>>i&1))continue;
    int ok = 0;
    for(int j=0;j<w;j++)ok |= T.same(i,j) && (bit>>j&1);
    if(!ok) return UF(0); //NG
  }
  
  for(int i=0;i<w-1;i++){
    if(!(bit>>i&1) || !(bit>>(i+1)&1))continue;
    if(res.same(i,i+1)) return UF(0);//NG
    res.unite(i,i+1);
  }
  return res;
}

vector<int>Bit;
unordered_map<ull,int> mem[N][1<<N];
int dfs(int y,int ue,UF &T){
  int hash = VtoH(T.par);
  if(y == h) {
    for(int i=0;i<w;i++) 
      for(int j=i+1;j<w;j++) 
        if((ue>>i&1) && (ue>>j&1) && !T.same(i,j)) return -1e9;
    return 0;
  }

  if(mem[y][ue].count(hash)) return mem[y][ue][hash];  
  
  int res = -1e9;
  if(y == h-1 && w == 1 && mp[y][0] == '.') res = 0;
  for(int bit:Bit){
     int i = bit;
     if(!check(y,ue,i)) continue;
     UF nT = getNx(y,ue,T,i);
     if(!nT.par.empty()) Max(res,dfs(y+1,i,nT) + __builtin_popcount(i));
   }
   return mem[y][ue][hash] = res;
}

signed main(){
  cin>>h>>w;
  for(int i=0;i<h;i++)cin>>mp[i];

  for(int i=0;i<(1<<w);i++){
    int ok = 1;
    for(int j=0;j<w-1;j++) if(!(i>>j&1) && !(i>>(j+1)&1)) ok = 0;
    if(ok)Bit.push_back(i);
  }

  int ans = -1e9;
  for(int bit:Bit){
    if(!check(0,bit))continue;
    UF T(w);
    for(int i=0;i<w-1;i++)if((bit>>i&1) && (bit>>(i+1)&1)) T.unite(i,i+1);
    Max(ans, dfs(1,bit,T) + __builtin_popcount(bit));
  }
  
  cout<<Max(ans,-1)<<endl;
  return 0;
}

Measured memory_bytes: 7052
#include<iostream>
using namespace std;
long long gcd(long long x,long long y){return y?gcd(y,x%y):x;}
long long lcm(long long x,long long y){return x/gcd(x,y)*y;}
int main(){
    long long n,m,num=1LL,tmp;
    cin>>n>>m;
    long long a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        if((a[i]&-a[i])!=(a[0]&-a[0])){cout<<0<<endl;return 0;}
    }
    for(auto &x:a)x/=2;
    for(int i=0;i<n;i++){
        tmp=lcm(num,a[i]);
        if((tmp/a[i])%2LL==1LL)num=tmp;
    }
    if(m<num)cout<<0<<endl;
    else cout<<(m-num)/(num*2LL)+1LL<<endl;
    return 0;
}

Measured memory_bytes: 1024
import math
import sys

sys.setrecursionlimit(100000)

def solve():
    n = int(input())
    success_trip = True
    now_t, now_x, now_y = 0, 0, 0
    for i in range(n):
        next_t, next_x, next_y = map(int, input().split(' '))
        if success_trip:
            if not find_path(now_t, now_x, now_y, next_t, next_x, next_y):
                success_trip = False
            now_t, now_x, now_y = next_t, next_x, next_y
    
    if success_trip:
        print("Yes")
    else:
        print("No")

def find_path(now_t, now_x, now_y, next_t, next_x, next_y):
    time = next_t - now_t
    return recursion_find(time, now_x, now_y, next_x, next_y)
    
def recursion_find(time, now_x, now_y, target_x, target_y):
    # print("-----------")
    # print("time:", time)
    # print("now_x:", now_x)
    # print("now_y:", now_y)
    # print("target_x:", target_x)
    # print("target_y:", target_y)
    # print("-----------")

    if (abs(target_x - now_x) + abs(target_y - now_y) - time) % 2 == 1:
        # cant
        return False

    if time == 0:
        if now_x == target_x or now_y == target_y:
            return True
        else:
            return False
    else:
        # distant
        if time < abs(target_x - now_x) + abs(target_y - now_y):
            # cant
            return False
            
        if recursion_find(time-1, now_x-1, now_y, target_x, target_y):
            return True
        elif recursion_find(time-1, now_x, now_y-1, target_x, target_y):
            return True
        elif recursion_find(time-1, now_x+1, now_y, target_x, target_y):
            return True
        elif recursion_find(time-1, now_x, now_y+1, target_x, target_y):
            return True
        else: 
            return False

if __name__ == "__main__":
    solve()

Measured memory_bytes: 4316
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

int a[1000010],calc[1000010];

signed main()
{
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		int m=i,num=n;
		for(int j=19;j>=0;j--){
			if(n&(1<<j)){
				if(num==(1<<j)){
					calc[i]=1;break;
				}
				if(m>num/2) m=num+1-m;
				if(m>num-(1<<j)){
					calc[i]=0;break;
				}
				else num-=(1<<j);
			}
		}
	}
	bool flag0=0,flag1=0,flag2=0;
	for(int i=1;i<=n;i++){
		char c;
		cin>>c;
		a[i]=c-'1';
		if(a[i]==0) flag0=1;
		if(a[i]==1) flag1=1;
		if(a[i]==2) flag2=1;
	}
	if(flag0&&flag1&&flag2){
		for(int i=1;i<=n;i++) if(a[i]==2) a[i]=0;
		int ans=0;
		for(int i=1;i<=n;i++) if(calc[i]) ans^=a[i];
		cout<<ans<<endl;
		return 0;
	}
	if(!flag0){
		if(!flag1){
			for(int i=1;i<=n;i++) a[i]-=2;
		}
		else{
			for(int i=1;i<=n;i++) a[i]--;
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++) if(calc[i]) ans^=a[i];
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

inline int read()
{
    int x=0;char ch=getchar();
    while(ch<'0' || '9'<ch)ch=getchar();
    while('0'<=ch && ch<='9')x=x*10+(ch^48),ch=getchar();
    return x;
}

const int N=1e5+9;

int n,ans;
int a[N];

int main()
{
    if(fopen("vj.in","r"))
    {
        freopen("vj.in","r",stdin);
        freopen("vj.out","w",stdout);
    }

	n=read();
	for(int i=1;i<=n;i++)
		a[i]=read();

	for(int i=1,j,k;i<=n;i=j+1)
	{
		k=i;
		while(a[k]<=a[k+1])k++;
		j=k;
		k=i;
		while(a[k]>=a[k+1])k++;
		j=max(j,k);
		ans++;
	}

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

                    


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
const int N = 1e6+10;
typedef long long LL;
const LL mod = 1e9+7;
LL a[N];

int main()
{

    LL n, m;
    scanf("%lld %lld", &n, &m);
    m/=2;
    if(m<=n) cout<<m<<endl;
    else cout<<n+(m-n)/2<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();
		int l = scan.nextInt();
		int[][] A = new int[n][m];
		int[][] B = new int[m][l];
		long c = 0;
		
		for(int i = 0;i < n;i++)
		{
			for(int j = 0;j < m;j++)
			{
				A[i][j] = scan.nextInt();
			}
		}
		
		for(int i = 0;i < m;i++)
		{
			for(int j = 0;j < l;j++)
			{
				B[i][j] = scan.nextInt();
			}
		}
		
		for(int i = 0;i < n;i++)
		{
			for(int j = 0;j < l;j++)
			{
				c = 0;
				for(int k = 0;k < m;k++)
				{
					c += (A[i][k] * B[k][j]);
				}
				if(j != 0){System.out.print(" ");}
				System.out.print(c);
			}
			System.out.println("");
		}
	}
}

Measured memory_bytes: 44988
#[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! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[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! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input!{
      s: chars,
    }

    let n = s.len();
    let mut ans = 0;
    for st in 0..n {
        for e in st..n {
            let mut ok = true;
            for i in st..e+1 {
                if !(s[i] == 'A' || s[i] == 'C' || s[i]=='G'||s[i]=='T') {
                    ok = false;
                }
            }
            if ok {
                ans = max(ans, e-st+1);
            }
        }
    }
    puts!("{}\n", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vector<ll> > vvl;
typedef vector<vector<P> > vvp;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n;
  cin >> n;
  vector<pair<pair<string,int>,int>>vec;
  rep(i,n){
    string s;
    int p;
    cin >> s >> p;
    vec.push_back(make_pair(make_pair(s,-p),i+1));
  }
  sort(vec.begin(),vec.end());
  
  rep(i,n){
    cout << vec[i].second << endl;
  }
  
  
  return 0;     
}


Measured memory_bytes: 256
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    N = int(input())
    S = [input().rstrip() for _ in range(N)]

    dict = {S[0]:1}

    for i in range(1,N):
        temp = S[i]
        if temp in dict:
            dict[temp] = dict[temp] + 1
        else:
            dict[temp] = 1

    res = []

    most = max(dict.values())

    for i in dict:
        if dict[i] == most:
            res.append(i)

    res.sort()

    M = len(res)

    for i in range(M):
        print(res[i])



main()


Measured memory_bytes: 35344
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using static kyoupuro.Input;
using static kyoupuro.MyMath;

namespace kyoupuro {

    class MainClass {

        public static void Main() {
            var list = new List<int> { 1, 2, 3 };
            list.Remove(NextInt());
            list.Remove(NextInt());

            Console.WriteLine(list.First());
        }
    }

    class MyMath {
        public static long mod = 1000000007;

        public static long Gcd(long a, long b) {
            return b == 0 ? a : Gcd(b, a % b);
        }

        public static List<long> Factor(long n) {
            var list = new List<long>();
            n = DivideToLimit(n, 2, list);
            n = DivideToLimit(n, 3, list);
            long sqrt = Sqrt(n);
            for (int i = 5; i <= n && i <= sqrt; i += 4) {
                n = DivideToLimit(n, i, list);
                i += 2;
                n = DivideToLimit(n, i, list);
            }
            if(n > 1) list.Add(n);
            return list;
        }

        public static long Sqrt(long n) {
            if (n < 0) return 0;
            long a = 0, tmp = 0, b = 0;
            for (int i = 62; i >= 0; i -= 2) {
                tmp = (b << 1) + 1 <= (n >> i) ? 1 : 0;
                a = a << 1 | tmp;
                n -= (((b << 1) + 1) * tmp) << i;
                b = (b << 1) + tmp + tmp;
            }
            return a;
        }

        static long DivideToLimit(long divisor, long dividend, List<long> list) {
            while(divisor % dividend == 0) {
                list.Add(dividend);
                divisor /= dividend;
            }
            return divisor;
        }
    }

    class Input {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line() {
            return Console.ReadLine();
        }

        public static int NextInt() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return int.Parse(enumerator.Current);
        }

        public static long NextLong() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return long.Parse(enumerator.Current);
        }

        public static string[] StrArr() {
            return Line().Split(' ');
        }

        public static List<int> IntList() {
            return StrArr().Select(int.Parse).ToList();
        }

        public static List<long> LongList() {
            return StrArr().Select(long.Parse).ToList();
        }

        public static void Skip(int line = 1) {
            enumerator.Reset();
            for (int i = 0; i < line; i++) Console.ReadLine();
        }

        public static void Reset() {
            enumerator.Reset();
        }
    }
}

Measured memory_bytes: 13268