akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <stdio.h>
#include <cmath>

using namespace std;

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;

//階乗
int factorial(int k){
    int result=1;
    for (int i=1;i<=k;++i){
        result*=i;
    }
    return result;
}

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

    vector<int>D(10);
    rep(i,k){
        int d;
        cin>>d;

        D[d]++;
    }

    for(int i=n;i<=100000;i++){
        string s= to_string(i);
        bool jdg=true;

        rep(i,s.size()){
            if(D[s[i]-'0']==1){
                jdg=false;
                break;
            }
        }

        if(jdg){
            cout<<i<<endl;
            return 0;
        }
    }
}


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

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> A_List = new List<int>();

            string t_N = Console.ReadLine();
            string[] t_i = Console.ReadLine().Split(' ');

            int N = int.Parse(t_N);

            int A;
            for(int i = 0; N > i; i++)
            {
                A = int.Parse(t_i[i]);
                A_List.Add(A);
            }

            int max = 0;
            int min = 1001;
            for(int i = 0; i < A_List.Count; i++)
            {
                if (max < A_List[i]) max = A_List[i];
                if (min > A_List[i]) min = A_List[i];
            }

            int Length = max - min;
            Console.WriteLine(Length);
        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    ll ans=0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    int _min = 1e9+7;
    for (int i = 0; i < n-1; i++)
    {
        if(_min>abs(a[i])) _min = abs(a[i]);
        if(a[i]<0){
            a[i] *= -1;
            a[i+1] *= -1;
        }
    }
    for (int i = 0; i < n; i++)
    {
        ans += a[i];
        if(i==(n-1)){
            if(a[i]<0){
                ll b;
                b = ans + abs(a[i])*2 - _min*2;
                ans = max(b, ans);
            }
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 640
#include<stdio.h>
int main()
{
    int i,x,y,count=0,j=0;
    scanf("%d",&i);
    int ara[i],ara2[i];
    //scanf("%d",&i);
    for(int y=0;y<i;y++){
    scanf("%d",&ara[y]);
    }
    for( x=0;x<i-1;x++){
        if(ara[x]>=ara[x+1]){
            count++;
        }
        else{
            if(count>0){
                ara2[j]=count;
                j++;
                count=0;
            }
            else{
                count=0;
            }
        }
    }
    ara2[j]=count;
   // printf("%d\n",ara2[0]);
    for(int e=j+1;e<i+2;e++){
        ara2[e]=0;
    }
    int k=ara2[0];
    for(int u=1;u<i+2;u++){
        if(k<ara2[u]){
            k=ara2[u];
        }
    }
    printf("%d\n",k);

    return 0;
}


Measured memory_bytes: 896
#include "iostream"
#include "vector"
using namespace std;

int main(){
    int n;
    while(cin >> n){
        vector<int> a(n + 2, 0);
        for(int i = 1 ; i <= n ; ++i){
            cin >> a[i];
        }

        int base = 0;
        for(int i = 0 ; i <= n ; ++i){
            base += abs(a[i] - a[i + 1]);
        }

        for(int i = 1 ; i <= n ; ++i){
            cout << base - abs(a[i - 1] - a[i]) - abs(a[i] - a[i + 1]) + abs(a[i - 1] - a[i + 1]) << '\n';
        }
    }

    cout << flush;

    return 0;
}

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

int XOR(int a, int b) {
  if (a == 1 && b == 1 || a == 0 && b == 0) return 0;
  return 1;
}

int main(void) {
  
  int n;
  cin >> n;
  vector<int> a(2 * n + 5, 0), b(2 * n + 5, 0);
  rep (i, n) cin >> a[i + 1];

  //cout << endl;

  for (int i = n / 2 + 1; i <= n; i++) b[i] = a[i];

  //for (int i = 1; i <= n; i++) cout << b[i] << " ";
  //cout << endl;

  for (int i = n / 2; i >= 1; i--) {
    int now = i;
    int now_sum = 0;

    while (true) {
      now += i;
      if (now > n) break;
      now_sum += b[now];
    }
    //cout << now_sum << endl;
    now_sum %= 2;

    b[i] = XOR(a[i], now_sum);

  }
  //cout << endl;
  int cnt = 0;
  for (int i = 1; i <= n; i++) if (b[i]) cnt++;
  cout << cnt << endl;
  for (int i = 1; i <= n; i++) if (b[i]) cout << i << endl;

  return 0;
}

Measured memory_bytes: 3968
#include<stdio.h>

int main(){
        int i, j;
        for(i=1; i<10; i++) {
                for(j=1; j<10; j++) {
//                      if(i<=j) {

                                printf("%dx%d=%d\n", i, j, i*j);
//                      }
                }
        }
        return 0;
}


Measured memory_bytes: 2552
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n+5]={0};
	for(int i=1;i<=n;i++){
	    cin>>a[i];
	}
	long long ans=1000;
	for(int i=1;i<n;i++){
	    if(a[i]<a[i+1]){
	        ans+=(ans/a[i])*(a[i+1]-a[i]);
	    }
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define For(i, l, r) for (register int i = l, _r = r; i <= _r; ++i)
#define Ford(i, l, r) for (register int i = r, _l = l; i >= _l; --i)
using namespace std;
typedef long long ll;
const int maxn = 2e3 + 20;

int n,x,y,vis[maxn],ans[maxn];
struct Node{
	int num,dis;
	Node(int num,int dis):num(num),dis(dis){}
	Node(){}
};
queue<Node> q;

inline int read()
{
	int x = 0, f = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9'){if (ch == '-')f = -1;ch = getchar();}
	while (ch >= '0' && ch <= '9'){x = (x << 3) + (x << 1) + ch - '0';ch = getchar();}
	return x * f;
}

int main()
{
	n=read();
	x=read();
	y=read();
	For(i,1,n)
	{
		For(j,1,n) vis[j]=0;
		vis[i]=1;
		q.push(Node(i,0));
		while(!q.empty())
		{
			Node now=q.front();
			q.pop();
			++ans[now.dis];
			if(now.num==x&&!vis[y])
				vis[y]=1,q.push(Node(y,now.dis+1));
			if(now.num==y&&!vis[x])
				vis[x]=1,q.push(Node(x,now.dis+1));
			if(now.num>1&&!vis[now.num-1])
				vis[now.num-1]=1,q.push(Node(now.num-1,now.dis+1));
			if(now.num<n&&!vis[now.num+1])
				vis[now.num+1]=1,q.push(Node(now.num+1,now.dis+1));	
		}
	}
	For(i,1,n-1)
		printf("%d\n",ans[i]/2);
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int N = 82;
int A[N];
int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> A[i];
	long c = 1e3;
	for (int i = 1; i+1 <= n; i++) {
		if (A[i+1] <= A[i])
			continue;
		long s = c/A[i];
		c -= s*A[i];
		c += s*A[i+1];
	}
	cout << c;
	return 0;
}

Measured memory_bytes: 3580
N=int(input())
m={}
for _ in range(N):
    a=int(input())
    if a in m:
        if m[a] == 0:
            m[a] = 1
        else:
            m[a] = 0
    else:
        m[a]=1

ans=sum(m.values())

print(ans)


Measured memory_bytes: 15076
#include<iostream>
using namespace std;
using ll = long long;
const ll MOD = 998244353;
//Rを右端に固定したときのカウントを用意（今だけの増加量）
//それを累積するやつを用意
int main(){
  ll N,S; cin>>N>>S;
  ll A[N+100],DP[N+100][S+100][3];
  DP[0][0][0]=1;
  for(int i=0; i<N; i++){
    ll a;
    cin>>a;
    A[i]=a;
  }
  for(int i=0; i<N; i++){
    for(int j=0; j<=S; j++){
      DP[i+1][j][0]+=DP[i][j][0];//i00だけ1、それ以外０。ifの中のa[i]自身の場合が加算
      (DP[i+1][j][1]+=DP[i][j][0]+DP[i][j][1])%=MOD;
      (DP[i+1][j][2]+=DP[i][j][0]+DP[i][j][1]+DP[i][j][2])%=MOD;
      if(j+A[i]<=S){
        (DP[i+1][j+A[i]][1]=DP[i][j][0]+DP[i][j][1])%=MOD;
        (DP[i+1][j+A[i]][2]=DP[i][j][0]+DP[i][j][1])%=MOD;
      }
    }
  }
  cout<<DP[N][S][2]<<endl;
}

Measured memory_bytes: 219904
#include <stdio.h>
#define N 100000

int partition(int *,int ,int );
int A[N];

int main()
{
	int i,j;
	int n,q;
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&A[i]);
	}
	q = partition(A,0,n-1);
	for(i=0;i<n;i++){
		if(i==q){
			printf("[%d] ",A[i]);
		} 
		else if(i != n-1) {
			printf("%d ",A[i]);
		}
		else {
			printf("%d",A[i]);
		}
	}
	printf("\n");
	
	return 0;
}

int partition(int *A,int p ,int r){
	int tmp;
	int i,j,x;
	
	x = A[r];
	i = p-1;
	
	for(j=0;j<r;j++){
		if(A[j] <= x){
			i++;
			tmp = A[j];
			A[j] = A[i];
			A[i] = tmp;
		}
	}
	tmp = A[r];
	A[r] = A[i+1];
	A[i+1] = tmp;
	
	return i+1;
}

Measured memory_bytes: 992
#include <stdio.h>
#include <cmath>
#include <iostream>
#include <string>
#include <set>

using namespace std;
int main() {
	while (true)
	{
		int n;
		cin >> n;
		if (n == 0) { break; }
		string ary[50];
		string arycode[50];
		for (int i = 0; i < n; ++i) {
			cin >> ary[i];
			bool flag = true;
			for (int j = 0; j < ary[i].length(); ++j) {
				char c = ary[i][j];
				if (flag) {
					arycode[i] += c;
				}
				switch (c) {
				case 'a':
				case 'i':
				case 'u':
				case 'e':
				case 'o':
					flag = true;
					break;
				default:
					flag = false;
					break;
				}

			}
		}

		
		int k = 1;
		int max = 0;
		bool founded = false;
		for (; k <= 50; k++) {
			set<string> st;
			bool allunique = true;
			
			for (int i = 0; i < n; ++i) {
				string code;
				code = arycode[i].substr(0, k);

				auto itr = st.find(code);
				if (itr != st.end()) {
					allunique = false;
					break;
				}
				else {
					st.insert(code);
				}

			}

			if (allunique) {
				founded = true;
				break;
			}
		}

		if (founded) {
			cout << k << endl;
		}
		else
			cout << -1 << endl;
	}

}

Measured memory_bytes: 3180
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <iomanip>
typedef long long ll;

using namespace std;

int main()
{
	ll n;
	ll h[100001];

	cin>>n;
	for (size_t i = 0; i < n; i++) {
		cin >> h[i];
	}
	for (size_t i = n - 1; i >= 1; i--) {
		if (h[i - 1] - h[i] >= 2) {
			cout << "No";
			return 0;
		} else if (h[i - 1] - h[i] == 1) {
			h[i - 1] -= 1;
		} else {
			
		}
	}
	cout << "Yes";
	return 0;
}


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

int main(int argc, char const *argv[])
{
	string s;
	long long k;
	cin>>s>>k;
	if (s[0]!=s[s.size()-1])
	{
		long long ans=0LL;
		for (int i = 0; i < s.size()-1; ++i)
		{
			if (s[i]==s[i+1])
			{
				++ans;
				s[i+1]='.';
			}
		}
		ans*=k;
		cout<<ans<<endl;
	}
	else
	{
		long long cnt1=1LL,cnt2=0LL,cnt3=1LL;
		int now=0;
		while (now<s.size()-1&&s[now]==s[now+1])
		{
			s[now]='.';
			++now;
			++cnt1;
		}
		if (now==s.size()-1)
		{
			cout<<(long long)s.size()*k/2LL<<endl;
			return 0;
		}
		now=s.size()-1;
		while (now>0&&s[now]==s[now-1])
		{
			s[now]='.';
			--now;
			++cnt3;
		}
		for (int i = cnt1; i < s.size()-cnt3-1; ++i)
		{
			if (s[i]==s[i+1])
			{
				++cnt2;
				s[i+1]='.';
			}
		}
		long long ans=cnt1/2LL;
		ans+=cnt2*k;
		ans+=(cnt1+cnt3)/2LL*(k-1LL);
		ans+=cnt3/2LL;
		cout<<ans<<endl;
	}
	return 0;
}


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

#define pi 3.141592654
#define fix(n) cout << fixed << setprecision(n)

#define rep(i,a,b) for(int i=a;i<b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)

#define si(d)  scanf("%d",&d)
#define sll(d) scanf("%lld",&d)
#define pin(d) printf("%d\n",d)
#define pln(d) printf("%lld\n",d)
#define nl 	   printf("\n")

#define ll  long long
#define ull unsigned long long

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

#define vi      vector<int>
#define pii     pair<int,int>
#define piii    pair<pair<int,int>,int>
#define all(v)  v.begin(), v.end()

#define chalne_de continue
int mod = 1000000007;
const int N = 1000005;

// gcd
ll gcd(ll a , ll b)
{
    if ( b == 0)
    return a;
    return gcd( b, a % b);
}
ll lcm(ll a, ll b)
{
    ll x = gcd(a,b);
    a /= x;
    return a * b;
}
vector<pii> v[N];
ll inf = 1e18;
ll dist[N];
int bfs(int s)
{


    set<pii > st;
   st.insert({0,s});
    for (int i =0; i < N; i++)
        dist[i] = inf;
    dist[s] = 0;
    while ( !st.empty())
    {
        pii p = *st.begin();
        s = p.se;
        st.erase(st.begin());
        for ( int i = 0; i < v[s].size(); i++)
        {
                int w = v[s][i].se;
                if (dist[v[s][i].fi] > dist[s] + w)

                {
                    //visited[sx+ax[i]][sy+ay[i]] = 1;
                    if(dist[v[s][i].fi] != inf)
                    st.erase(st.find({dist[v[s][i].fi] ,i}));
                   dist[v[s][i].fi] = dist[s] + w;
                    st.insert({dist[v[s][i].fi],v[s][i].fi});
                }
            }
        }

}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	rep(i,0,n-1)
	{

	    int x, y , w;
	    cin >> x >> y >> w;
	    v[x].pb({y,w});
	    v[y].pb({x,w});
	}
	int q, k;
	cin >> q >> k;
	bfs(k);
	while ( q--)
    {

        int x ,y;
        cin >> x >> y;
       ll ans = dist[x] + dist[y] ;
       cout << ans << endl;
    }
	return 0;
}


Measured memory_bytes: 41204
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(long long i=s;i<n;i++)
#define mod 1000000007LL
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 1e18
#define five 100005;
#define six 1000005;
#define prllclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//___________________________________________________________________________________________________________________________________________________________

int main()
{
       speed;
       ll n,k;
       cin>>n>>k;
       ll xx = n%k;
       cout<<min(xx,(k-xx))<<endl;


}


Measured memory_bytes: 256
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long lng;
#define UP(i,a,b) for(int i=(a); i<=(b); ++i)
#define DOWN(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) UP(i,0,n-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //NOTE: <a> must be sorted in advance

lng power(lng b, int n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n in O(log(n)) time

const int MOD = 1000000007; //10^9+7
const double PI = 3.1415926535897932384626;

/*********** variables ************/
lng N;
vector<int> a;
bool ban[20];
/**********************************/

lng dfs(int now, int len) {
    if(now == len) {
        lng ans = a[len-1];
        lng d = 1;
        DOWN(i, len-1, 1) {
            d *= 10;
            if(ban[i]) d = 1;
            ans += d * a[i-1];
        }
        return ans;
    }
    ban[now] = true;
    lng sol1 = dfs(now+1, len);
    ban[now] = false;
    lng sol2 = dfs(now+1, len);
    return sol1 + sol2;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    lng n = N;
    while(n > 0) {
        a.push_back(n%10);
        n /= 10;
    }
    reverse(ALL(a));
    int len = (int)a.size();


    cout << dfs(1, len);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define mod 1000000007
#define size_f 100002
int main()
{
    int n,m;
    cin>>n>>m;

    vector<ll>v;
    for(int i=0;i<n;i++)
    {
        ll k;
        cin>>k;
        v.pb(k);
    }
    int a[size_f]={0};
    for(int i=0;i<m;i++)
    {
        int r,f;
        cin>>r>>f;

        if(v[r-1]<v[f-1]&&a[f]!=-1)
             a[f]=1;
        else
            a[f]=-1;

        if(v[r-1]>v[f-1]&&a[r]!=-1)
             a[r]=1;
        else
            a[r]=-1;

    }
    int c=0;
    for(int i=1;i<=n;i++)
    {
        if(a[i]==0||a[i]==1)
            c++;
    }
    cout<<c<<"\n";
    return 0;
}


Measured memory_bytes: 4588
#include<iostream>
#include<cstdio>
#include<ios>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<string>
#include<list>
#include<utility>
#include<tuple>
#include<map>
#include<unordered_map>
#include<complex>
using namespace std;
typedef long long llong;
llong gcd(llong a, llong b) {
	if (a < b) std::swap(a, b);
	if (a % b == 0) return b;
	else return gcd(b, a % b);
}
llong lcm(llong a, llong b) {
	llong g = gcd(a, b);
	return a * b / g;
}
//ここまで共通


int N;
double A[1000];
double B = 0;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		B += 1 / A[i];
	}
	B = 1 / B;
	printf("%.9lf", B);
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
#define db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'
const int inf = 1e9+7;
const int N = 1e6+9;

int main() {
    ios_base::sync_with_stdio(0);
    int a,b,n;
    cin>>n;
    map<string, int> mp;
    while(n--) {
        string s;
        cin>>s;
        mp[s]++;
    }
    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"]<<endl;
    return 0;
}

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

int main() {
  
  int x,a,b;
  cin >> x >> a >> b;
  
  if(abs(x-a) > abs(x-b)) cout << "B" << endl;
  else cout << "A" << endl;
  
  
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		char s[] = sc.next().toCharArray();
		char t[] = sc.next().toCharArray();
		StringBuilder sb =new StringBuilder();
		for(int i=0; i<n; i++) {
			sb.append(s[i]); sb.append(t[i]);
		}
		System.out.println(sb);
		sc.close();
	}
}


Measured memory_bytes: 23380
#include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define ll long long 
#define mod 1000000007

void fast(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);
}

int main() {
   fast();
   long long x,k,d;
   cin>>x>>k>>d;
   if(d>abs(x)){
      if(k%2==0){
        cout<<abs(x)<<"\n";
      }else{
        cout<<abs(abs(x)-d)<<"\n";
      }
   }else{
     if(abs(x)/d<k){
       x=abs(x);
       long long l=abs(x)/d;
       k=k-l;
       if(k%2==0){
        cout<<x-l*d;
        return 0;
       }else{
        cout<<(l+1)*d-x;
        return 0;
       }


     }else{
      cout<<abs(x)-k*d<<"\n";
      return 0;
     }


   }


}

Measured memory_bytes: 3656
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int count[4][3][10]={{{0}}};

int main(void){
   int n,i,j,k;
   int b,f,r,v;
   cin >>n;
   for(i=0;i<n;i++){
       cin >>b>>f>>r>>v;
       count[b-1][f-1][r-1] += v;
   }
   for(i=0;i<4;i++){   // n でなく4
       for(j=0;j<3;j++){
           for(k=0;k<10;k++){
               cout <<" "<<count[i][j][k];
           }
           cout <<endl;
       }
       if(i < 3) {
           cout <<"####################"<<endl;
       }
   }
//   for(j=0;j<3;j++){
//       for(k=0;k<10;k++){
//           cout <<" "<<count[i][j][k];
//       }
//       cout <<endl;
//   }
}


Measured memory_bytes: 3080
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N,K;
  long long S=0;
  cin>>N>>K;
  vector<long long>vec(N);
  for(long long X=0;X<N;X++){
    cin>>vec.at(X);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  if (N<=K){
    cout<<0<<endl;
  }
  else{
    for(long long X=K;X<N;X++){
      S+=vec.at(X);
    }
    cout<<S<<endl;
  }
}

Measured memory_bytes: 4780
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int main(){
	long long n, k;
	cin>>n>>k;
	vector<long long> vec(n, 0);
	for(int i = 0; i < n; ++i){
		cin>>vec[i];
	}
	vector<long long> t(n, 0), x(n, 0);
	for(int i = 0; i < n; ++i){
		long long r = vec[i];
		for(int j = i + 1; j < n; ++j){
			if(r > vec[j]){
				x[i]++;
			}
		}
		for(int j = 0; j < i; ++j){
			if(r > vec[j]){
				t[i]++;
			}
		}
	}
	long long kr = (k * (k + 1) / 2) % mod;
	long long br = (k * (k - 1) / 2) % mod;
	for(int i = 0; i < n; ++i){
		x[i] = (kr * x[i]) % mod;
		t[i] = (br * t[i]) % mod;
	}
	long long res = 0;
	for(int i = 0; i < n; ++i){
		res = (res + x[i]) % mod;
		res = (res + t[i]) % mod;
	}
	res %= mod;
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.math.*;

class Main {
    public static void main( String args[] ){
        String[] a = {"","Man","Oku","Cho","Kei","Gai","Jo","Jou","Ko","Kan","Sei","Sai","Gok","Ggs","Asg","Nyt","Fks","Mts"};

        Scanner in = new Scanner(System.in);
        while( true ) {
            BigInteger m = in.nextBigInteger();
            int n = in.nextInt();
            if( n == 0 ) break;
            BigInteger value = m.pow(n);
            StringBuffer s = new StringBuffer(value.toString());
            ArrayList<String> arr = new ArrayList<String>();
            int p = 0;
            for(int i=s.length();i>=0;i-=4){
                StringBuffer temp = new StringBuffer(s.substring(Math.max(i-4,0),i));
                int cnt = temp.length();
                for(int j=0;j<cnt;j++){
                    if( temp.charAt(0) != '0' ) break;
                    temp.deleteCharAt(0);
                }
                if( temp.length() != 0 ) arr.add(temp+a[p]);
                ++p;
            } 
            for(int i=arr.size()-1;i>=0;i--) {
                System.out.print(arr.get(i));
            }   System.out.println("");
        }
    }
}

Measured memory_bytes: 20308
#include <iostream>

int main() {
    for( int i = 1 ; i <= 10000 ; i++ ) {
        int x ;
        std::cin >> x ;
        
        if( x == 0 ) {
            break ;
        }
        
        std::cout << "Case " << i << ": " << x << std::endl ;
    }
}


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

using namespace std;

int main()
{
	int n, x, y;
	vector<int> X;
	vector<int> Y;
	
	scanf("%d", &n);
	
	for(int i = 0; i < n; i++)
	{
		scanf("%d", &x);
		X.push_back(x);
	}
	for(int i = 0; i < n; i++)
	{
		scanf("%d", &y);
		Y.push_back(y);
	}
	
	double sum1 = 0.0, sum2 = 0.0, sum3 = 0.0, sumMax = 0.0;
	
	for(int i = 0; i < n; i++)
	{
		sum1 += fabs(X[i] - Y[i]);
		sum2 += pow((X[i] - Y[i]), 2);
		sum3 += fabs(pow((X[i] - Y[i]), 3));
		sumMax = max(sumMax, fabs(X[i] - Y[i]));
	}
	
	printf("%.6lf\n", sum1);
	printf("%.6lf\n", sqrt(sum2));
	printf("%.6lf\n", pow(sum3, 1.0/3.0));
	printf("%.6lf\n", sumMax);
	
	return 0;
}


Measured memory_bytes: 3424
#B
N=int(input())
ac=0
wa=0
tle=0
re=0
for _ in range(N):
    c=input()
    if c=='AC':
        ac+=1
    elif c=='WA':
        wa+=1
    elif c=='TLE':
        tle+=1
    elif c=='RE':
        re+=1
            

print('AC'+" "+"x"+" "+str(ac))
print('WA'+" "+"x"+" "+str(wa))
print('TLE'+" "+"x"+" "+str(tle))
print('RE'+" "+"x"+" "+str(re))

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

using namespace std;
using ll = long long;

ll in(){
    ll res;
    (void)scanf("%lld",&res);
    return res;
}

template<class t>
t in(){
    t res;
    cin >> res;
    return res;
}

int main(){
    int n = in();
    vector<int> line(n);
    for(auto&i:line)i=in();
    int q = in();
    rep(query,q){
        int tmax = in()==1;
        int l = in();
        int r = in();
        int ans;
        if(tmax){
            ans = INT32_MIN;
            for(int i=l;i<r;++i){
                ans = max(ans,line[i]);
            }
        }else{
            ans = INT32_MAX;
            for(int i=l;i<r;++i){
                ans = min(ans,line[i]);
            }
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 3244
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
#define all(x) (x).rbegin(), (x).rend()
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,lgm=0;
    cin>>n;
    int arr[n];
    int  colour[9]={0};
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        if(arr[i]<=399){
            colour[0]=1;
        }else if(arr[i]>=400&&arr[i]<=799)
        {
            colour[1]=1;
        }else if(arr[i]>=800&&arr[i]<=1199)
        {
            colour[2]=1;
        }else if(arr[i]>=1200&&arr[i]<=1599)
        {
            colour[3]=1;
        }else if(arr[i]>=1600&&arr[i]<=1999)
        {
            colour[4]=1;
        }else if(arr[i]>=2000&&arr[i]<=2399)
        {
            colour[5]=1;
        }else if(arr[i]>=2400&&arr[i]<=2799)
        {
            colour[6]=1;
        }else if(arr[i]>=2800&&arr[i]<=3199)
        {
            colour[7]=1;
        }else{
        lgm++;
        }
    }
    int ans=0,m;
        for(int i=0;i<=7;i++)
        ans=ans+colour[i];
        if(ans==0)m=1;
        else m=ans;
    cout<<m<<" "<<ans+lgm<<endl;


}


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

int main(){
  string d;
  cin >> d;
  if(d == "SUN")
   cout << 7;
  if(d == "MON")
   cout << 6;
  if(d == "TUE")
   cout << 5;
  if(d == "WED")
   cout << 4;
  if(d == "THU")
   cout << 3;
  if(d == "FRI")
   cout << 2;
  if(d == "SAT")
   cout << 1;
}

Measured memory_bytes: 256
#include <stdio.h>
#define n 6

void swap(int *a,int *b){
	int t=*a;
	*a=*b;
	*b=t;
}

int main(void){
	int a[6],sum;
	int i,j;
	for(i=0;i<n;i++)scanf("%d",a+i);
	sum=0;
	for(i=0;i<4;i++){
		for(j=i+1;j<4;j++){
			if(a[i]<a[j]){
				swap(a+i,a+j);
			}
		}
	}
	sum+=a[0]+a[1]+a[2];
	for(i=4;i<6;i++){
		for(j=i+1;j<6;j++){
			if(a[i]<a[j]){
				swap(a+i,a+j);
			}
		}
	}
	sum+=a[4];
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 600
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const int mod=1e9+7;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-4;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>int LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>int UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
llint solve(vector<llint>&wa,int L,int R){
	if(L+1==R){return 0;}
	int M=(L+R)/2;
	llint ans=solve(wa,L,M)+solve(wa,M,R);
	//分割統治をおこなう
	vector<llint>ata;
	ata.reserve(R-L);
	int Lb=L,Rb=M;
	while(-1){
		if(Lb==M&&Rb==R){break;}
		else if(Lb==M){ata.pub(wa[Rb]);Rb++;ans+=M-Lb;}
		else if(Rb==R){ata.pub(wa[Lb]);Lb++;}
		else if(wa[Lb]<=wa[Rb]){ata.pub(wa[Rb]);Rb++;ans+=M-Lb;}
		else		  {ata.pub(wa[Lb]);Lb++;}
	}
	for(int i=L;i<R;i++){wa[i]=ata[i-L];}
	return ans;
}
int main(void){
	int i,n,K;cin>>n>>K;
	vector<llint>wa(n+1);
	for(i=0;i<n;i++){
		llint x;cin>>x;
		wa[i+1]=wa[i]+x-K;
	}
	cout<<solve(wa,0,n+1)<<endl;
	//2 0 3 -5 -4 -5
	//0 2 2 5 0 -4 -9
	//5 2 2 0 0 -4 -9
	return 0;
}



Measured memory_bytes: 4728
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int a, b;
  cin >> a >> b;
  string s, t;
  for (int i = 0; i < b; ++i) {
    s += to_string(a);
  }
  for (int i = 0; i < a; ++i) {
    t += to_string(b);
  }
  cout << min(s, t) << endl;
  return 0;
}

Measured memory_bytes: 256
/* Warshall-Floyd Algorithm */

#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
	int cost[101][101],time[101][101];

	for(int n,m;cin>>n>>m,n;){
		for(int i=1;i<=m;i++)
			for(int j=1;j<=m;j++)
				cost[i][j]=time[i][j]=1<<29;

		for(int i=0;i<n;i++){
			int a,b,c,t;	cin>>a>>b>>c>>t;
			cost[a][b]=cost[b][a]=c;
			time[a][b]=time[b][a]=t;
		}

		for(int l=1;l<=m;l++){
			for(int i=1;i<=m;i++){
				for(int j=1;j<=m;j++){
					cost[i][j]=min(cost[i][j],cost[i][l]+cost[l][j]);
					time[i][j]=min(time[i][j],time[i][l]+time[l][j]);
				}
			}
		}

		int k;	cin>>k;
		while(k--){
			int p,q,r;	cin>>p>>q>>r;
			cout<<(r?time[p][q]:cost[p][q])<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 944
n=int(input())
a=list(map(int, input().split()))
dp=[0]*n
dp[1]=abs(a[0]-a[1])
for i in range(2,n):
    dp[i]=min(abs(a[i]-a[i-2])+dp[i-2],abs(a[i]-a[i-1])+dp[i-1])
print(dp[-1])

Measured memory_bytes: 52592
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        if(a+b > c+d){
            System.out.println("Left");
        }else if(a+b == c+d){
            System.out.println("Balanced");
        }else{
            System.out.println("Right");
        }
    }
}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    std::vector<string> v;
    int n,l;
    cin >> n >> l;
    string tmp;
    for (int i = 0; i < n; i++) {
        cin >> tmp;
        v.push_back(tmp);
    }
    sort(v.begin(),v.end());
    tmp.clear();
    for(auto the:v){
        tmp.append(the);
    }
    cout << tmp;
}


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

namespace B
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var ab = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var sb = new StringBuilder();
            var array = new string[2];
            for (var i = 0; i < ab[1]; i++)
            {
                sb.Append(ab[0]);
            }
            array[0] = sb.ToString();
            sb.Clear();
            for (var i = 0; i < ab[0]; i++)
            {
                sb.Append(ab[1]);
            }
            array[1] = sb.ToString();
            Array.Sort(array);
            Console.WriteLine(array[0]);
        }
    }
}


Measured memory_bytes: 13536
#include<bits/stdc++.h>
using namespace std;
#define INS(x) x.begin(),x.end()
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int a,b;
    cin>>a>>b;
    if (a<=5) cout<<0<<'\n';
    else if (a<=12) cout<<b/2<<'\n';
    else cout<<b<<'\n';
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		while(true) {
			
			int x = sc.nextInt();
			int y = sc.nextInt();
			
			if(x==0 && y==0) {
				break;
			}
			
			if(x>y) {
				int tmp;
				tmp=x;
				x=y;
				y=tmp;
			}
			
			System.out.println(x+" "+y);
			
		}
		
		
	}

}


Measured memory_bytes: 36200
from collections import defaultdict


def main():
    n = int(input())
    a = list(map(int, input().split()))

    memo = defaultdict(int)
    ans = 0
    for i, x in enumerate(a, 1):
        ans += memo[i-x]
        memo[x+i] += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 61560
import java.util.Scanner;

public class Main {
  public static void main(String args[]) {
    Scanner acd = new Scanner(System.in);
    int n,a,b,c;
    a=acd.nextInt();
    b=acd.nextInt();
    if(b/100>0)
      n = a * 1000 + b;
    else if(b/10>0)
      n = a * 100 + b;
    else 
      n = a * 10 + b;
    for(c = 1;c < 317 && c * c != n; c++);
    if(c==317)
      System.out.println("No");
    else 
      System.out.println("Yes");
}   
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const long long INF = 1LL << 60; 
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; }

int main()
{
  int N; string S;
  cin >> N >> S;
  int count = 0;
  
  for(int i = 0; i < N-2 ; i++)
  {
    if(S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C')
      count++;
  }
  
  cout << count << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[18][2];
int c[19];
int dp[19][1 << 18][18];
int main() {
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i][0]);
	for(int i(0); i < n; i++) {
		scanf("%d", &a[i][1]);
		if(i % 2 == 1) swap(a[i][0], a[i][1]);
	}
	memset(dp, 0x7f, sizeof(dp));
	for(int i(0); i < n; i++) {
		dp[0][1 << i][i] = 0;
	}
	for(int i(0); i < n - 1; i++) {
		for(int j(0); j < (1 << n); j++) {
			if(__builtin_popcount(j) != i + 1) continue;
			c[n] = 0;
			for(int k = n - 1; k >= 0; k--) {
				c[k] = c[k + 1] + (j >> k & 1);
			}
			for(int k = 0; k < n; k++) {
				if(!(j >> k & 1)) continue;
				int lst = i % 2 == 0 ? a[k][0] : a[k][1];
				//cout << i << ' ' << j << ' ' << k << ' ' << lst << endl;
				for(int l = 0; l < n; l++) {
					if(j >> l & 1) continue;
					int cur = i % 2 == 0 ? a[l][1] : a[l][0];
					if(cur >= lst) {
						//cout << "->" << l << endl;
						dp[i + 1][j + (1 << l)][l] = min(dp[i + 1][j + (1 << l)][l], dp[i][j][k] + c[l]);
					}
				}
			}
		}
	}
	int ans = 0x7f7f7f7f;
	for(int i(0); i < n; i++) ans = min(ans, dp[n - 1][(1 << n) - 1][i]);
	if(ans == 0x7f7f7f7f) ans = -1;
	cout << ans << endl;
}


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

using namespace std;
using Graph = vector<vector<int>>;
using Grid= vector<vector<char>>;
using vin= vector<int>;
using ll=long long;
using vll= vector<ll>;
using vbl=vector<bool>;
using vch=vector<char>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define sort(x) sort(x.begin(), x.end());
#define rese(x) reverse(x.begin(), x.end());

int main() {
    int n,x,t;
    cin>>n>>x>>t;
    cout<<((n-1)/x+1)*t<<endl;

}


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

int main(){
  int n;
  cin >> n;
  double t = 0;
  for (int i = 0; i < n; i++) {
    int a = 0;
    cin >> a;
    t += 1.0 / a;
  }
  cout << 1 / t << endl;
}

Measured memory_bytes: 256
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <deque>
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
void print(vec v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(vecll v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}


#define INF 1e9+7
#define LLINF 1e18+7
const ll MOD=1e9+7;
const int N=500000;

main(){
    int a,b,c,d;cin>>a>>b>>c>>d;
    cout<<(a!=c);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int main() {
    int x,y;
    cin>>x>>y;
    cout<<gcd(x,y)<<endl;
    return 0;
}


Measured memory_bytes: 3124
#include<cstdio>
#include<algorithm>
using namespace std;
int mins(int a,int b)
{
	return (a<b)?a:b;
}
int a[200010];
int main()
{
	int n;
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	int N=a[n],m=0,ans=0;
	for (int i=n-1;i;i--)
	{
		if (mins(a[i],N-a[i])>m) m=mins(a[i],N-a[i]),ans=a[i];
	}
	printf("%d %d\n",N,ans);
	return 0; 
} 

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

#define I cin
#define O cout
#define EN endl
#define ln cout<<endl
#define pb(a) push_back(a)

typedef long long int llint;

llint n, m;
llint i, j;
llint cnt = 0;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

llint ogcd(llint a, llint b);

int main()
{
  string s, t;
  
  I >> n >> m;
  I >> s >> t;

  llint l = n * m / ogcd(n, m);;
  
  string x = "";

  bool flg = true;
  llint k = (l / n) * (l / m) / ogcd((l / n), (l / m));
  
  for(i = 0; i <= l; i += k) {
    if(s[i / (l / n)] != t[i / (l / m)]) flg = false;
  }
  
  O << (flg ? l : -1) << EN;
  
  return 0;
}

llint ogcd(llint a, llint b)
{
  if(a % b == 0) return b;
  
  return ogcd(b, a % b);
}


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

int main() {
	int Antenna[5];
	int k;

	for (int n = 0; n < 5; n++) {
		cin >> Antenna[n];
	}
	cin >> k;

	for (int n = 0; n < 5; n++) {
		for (int m = n; m < 5; m++) {
			if (n == m)continue;
			if (Antenna[m] - Antenna[n] > k)goto out;
		}
		if (n == 4) {
			cout << "Yay!";
			return 0;
		}
	}

out:
	cout << ":(";

	return 0;
}

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

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
template <typename T> constexpr T inf = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define COMP(key) [](const auto& a, const auto& b) { return a.key < b.key; }

template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& a) { return is >> a.first >> a.second; }
template<typename T> istream& operator>>(istream& is, vector<T>& a) { for (T& x : a) is >> x; return is; }

void LOG(const int& x) { cerr << x << "\n"; }
template<typename T> void LOG(const vector<T>& a) { for (const T& x : a) cerr << x << " "; cerr << "\n"; }
template<typename T, std::size_t S> void LOG(const T (&a)[S]) { REP(i, S) cerr << a[i] << " "; cerr << "\n"; }
template<typename T, std::size_t S, std::size_t R> void LOG(const T (&a)[S][R]) { REP(i, S) { REP(j, R) cerr << a[i][j] << " "; cerr << "\n"; } }

i64 ceil(i64 a, i64 b) { return (a - 1) / b + 1; }
i64 gcd(i64 a, i64 b) { while (b != 0) { i64 t = b; b = a % b; a = t; } return a; }
i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
i64 gcd(const vector<i64>& v) { return accumulate(ALL(v), 1LL, static_cast<i64(*)(i64, i64)>(gcd)); }
i64 lcm(const vector<i64>& v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<i64(*)(i64, i64)>(lcm)); }
i64 pow(i64 x, i64 y, i64 z) { i64 a = 1; while (y > 0) { if (y & 1) a = a * x % z; x = x * x % z; y /= 2; } return a; }
i64 inv(i64 x, i64 m) { return pow(x, m - 2, m); }

struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } initCpp;

using P = pair<i64, i64>;
const i64 M = 1000000007;
signed main() {
  i64 n, k;
  cin >> n >> k;
  vector<vector<i64>> G(n);
  REP(_, n - 1){
    i64 x, y;
    cin >> x >> y;
    x -= 1;
    y -= 1;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  i64 ans = k;
  vector<i64> C(n, k);
  queue<P> que;
  for (i64 x : G[0]) {
    que.push({0, x});
  }
  while (que.size()) {
    P p = que.front();
    que.pop();
    C[p.first] -= 1;
    C[p.second] -= 1;
    ans = ans * C[p.first] % M;
    for (i64 x : G[p.second]) {
      if (x == p.first) continue;
      que.push({p.second, x});
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 8948
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    S = input()
    N = len(S)
    sumv = 0
    for bit in range(1 << N-1):
        T = S[0]
        for i in range(N-1):
            if bit & (1 << i):
                T += "+"
            T += S[i + 1]
        sumv += eval(T)
    print(sumv)

if __name__ == '__main__':
    main()


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

int main(){
    int n,m,c;
    cin >> n >>m >> c;
    int lastans =0;
    vector<int>b(m);
    for(int i=0;i<m;i++)cin >> b[i];
    for(int i=0;i<n;i++){
        vector<int>data(m);
        int ans = 0;
        for(int j=0;j<m;j++){
            cin >> data[j];
            ans += data[j]*b[j];
        }
        ans += c;
        if(ans > 0)lastans ++;
    }
    cout << lastans << endl;
}

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

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

int main() {
    int N, K, ans = 0;
    cin >> N >> K;
    vector<int> P(N);
    vector<bool> Q(N - K + 1, false);
    int inc = 0, ans2 = 0;
    cin >> P[0];
    rep(i, N - 1) {
        cin >> P[i + 1];
        if (P[i + 1] > P[i]) {
            inc++;
            if (inc >= K - 1) {
                Q[i - K + 2] = true;
            }
        } else {
            //cout << i << inc << endl;
            if (inc >= K - 1) ans2 += inc + 2 - K;
            inc = 0;
        }
    }
    if (inc >= K - 1) {
        ans2 += inc + 2 - K;
        Q[N - K] = true;
    }
    //cout << ans2 << endl;
    set<int> st;
    rep(i, K) {
        st.insert(P[i]);
    }
    rep(i, N - K) {
        if (*st.begin() != P[i]) {
            st.erase(P[i]);
            st.insert(P[i + K]);
        } else {
            st.erase(P[i]);
            st.insert(P[i + K]);
            if (*st.rbegin() == P[i + K] && !Q[i + 1]) {
                ans++;
            }
        }
    }
    if (ans2 > 0) ans2--;
    cout << N - K + 1 - ans - ans2 << endl;
}

Measured memory_bytes: 10368
#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>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) REP(i,1,n+1)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> PII;
typedef vector<ll> Vl;
typedef vector<int> VI;
typedef tuple<int, int, int> TT;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
const int MAX = 510000;
const int inf = 1e9 + 7;
const int mod = 1e9 + 7;
const ll longinf = 1LL << 60;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;


int n, k, p, m, ans;
string s;

int main() {

	cin >> n >> k >> s;

	rep(i, n - 1){
		if (s[i] == s[i + 1])ans++;
	}

	ans += 2 * k;

	cout << min(n - 1, ans) << endl;

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int h,w;
int f[210][210];
signed main()
{
    h=read(), w=read();
    for(ri int i=0;i<10;i++)
    for(ri int j=0;j<10;j++)
    f[i][j]=read();

    for(ri int k=0;k<10;k++)
    for(ri int i=0;i<10;i++)
    for(ri int j=0;j<10;j++)
    f[i][j]=min(f[i][j],f[i][k]+f[k][j]);

    int res=0;
    for(ri int i=0;i<h;i++)
    for(ri int j=0;j<w;j++)
    {
        int x=read();
        if(x>=0) res+=f[x][1];
    }
    printf("%lld\n",res);
    return 0;
}

Measured memory_bytes: 3752