akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int rec( int a, int b, int c){
  if(!a & !b) return(0);
  if(c & 1) return( rec( a >> 1, b >> 1, c >> 1));
  if(b & 1) return( rec( c >> 1, b >> 1, a >> 1) + rec( ( a|b|c) >> 1, 0, 0) + 1);
  if(a & 1) return( rec( a >> 1, b >> 1, c >> 1) + 2 * rec( ( a|b|c) >> 1, 0, 0) + 2);
}


int main()
{
  int n, m, data[3];

  while( cin >> n >> m, m){
    for(int i = 0; i < 3; i++){
      int k;
      cin >> k;
      data[i] ^= data[i];
      for(int j = 0; j < k; j++){
        int num;
        cin >> num;
        data[i] |= 1 << --num;
      }
    }

    int ret = min( rec( data[0], data[1], data[2]), rec( data[2], data[1], data[0]));
    if(ret <= m) cout << ret << endl;
    else cout << -1 << endl;
  }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define int long long int
#define pb push_back
#define mod 1000000007
using namespace std;

void dfile(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int dp[100005][3];

int a[100005],b[100005],c[100005];
int n;

int32_t main()
{   
    //dfile();
    
    cin>>n;
     a[n],b[n],c[n];
     memset(dp,-1,sizeof(dp));
    for(int i=0;i<n;i++) {
        cin>>a[i]>>b[i]>>c[i];
    }
   
    dp[1][0]=a[0];
    dp[1][1]=b[0];
    dp[1][2]=c[0];
    for(int i=2;i<=n;i++){
        dp[i][0]=a[i-1]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=b[i-1]+max(dp[i-1][2],dp[i-1][0]);
        dp[i][2]=c[i-1]+max(dp[i-1][1],dp[i-1][0]);
    }
    cout<<max(dp[n][0],max(dp[n][1],dp[n][2]));



    return 0;   
}



Measured memory_bytes: 8240
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sn = new Scanner(System.in);
        int N = sn.nextInt();
        int result = 0;
        List<String> S = new ArrayList<String>();
        List<Integer> T = new ArrayList<Integer>();
        for(int i=0; i<N; i++){
            S.add(sn.next());
            T.add(sn.nextInt());
        }
        String X = sn.next();

        int index = S.indexOf(X);

        for(int j=index+1; j<N; j++){
            result = result + T.get(j);
        }

        System.out.println(result);
    }
}

Measured memory_bytes: 21844
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {
    int h, w, n;
    int[] as, bs;

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

    void run() {
        FastReader sc = new FastReader();
        h = sc.nextInt();
        w = sc.nextInt();
        n = sc.nextInt();
        as = new int[n];
        bs = new int[n];
        for (int i = 0; i < n; i++) {
            as[i] = sc.nextInt() - 1;
            bs[i] = sc.nextInt() - 1;
        }
        solve();
    }

    void solve() {
        Set<Long> set = new HashSet<>();
        long[] counts = new long[10];
        counts[0] = ((long)h - 2) * (w - 2);
        for (int i = 0; i < n; i++) {
            long key = ((long)as[i] << 32) + bs[i];
            for (int j = -2; j <= 0; j++) {
                for (int k = -2; k <= 0; k++) {
                    if (as[i] + j < 0 || as[i] + j >= h - 2 || bs[i] + k < 0 || bs[i] + k >= w - 2) {
                        continue;
                    }
                    int count = 0;
                    for (int l = 0; l <= 2; l++) {
                        for (int m = 0; m <= 2; m++) {
                            long findKey = ((long) (as[i] + j + l) << 32) + bs[i] + k + m;
                            if (set.contains(findKey)) {
                                count++;
                            }
                        }
                    }
                    counts[count]--;
                    counts[count + 1]++;
                }
            }
            set.add(key);
        }
        for (int i = 0; i < 10; i++) {
            System.out.println(counts[i]);
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 168496
#include <bits/stdc++.h>
#include<math.h>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int , int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18 
int main (){
    ll a, b ,c ;
    cin >> a >> b >> c ;
    ll x, y ;
    cin >> x >> y ;
    if(2*c >= a+b){
        cout << a*x + b*y << endl ;
    }
    else {
        ll num = INF ; 
        if(x > y){
            rep(i, x + 1){
                if(y - i < 0){
                    b = 0 ;
                }
                if(num > a*(x - i) + b*(y - i) + 2*c*i){
                    num = a*(x - i) + b*(y - i) + 2*c*i ;
                }
            }
        }
        else {
            rep(i, y + 1){
                if(x - i < 0){
                    a = 0 ;
                }
                if(num > a*(x - i) + b*(y - i)+ 2*c*i){
                    num = a*(x - i) + b*(y - i) + 2*c*i ;
                }
            }
        }
        cout << num << endl ;
    }
}


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



int main(){
	int a, b=0;
	string s;
	cin >> a;
	cin >> s;
	for (int i = 0; i < a; i++) {
		if (s[i] == 'R')b++;
	}
	if (b > a / 2) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define f(x) memset(x,0x3f,sizeof(x))
using namespace std;
const int mxn=1024;
int T,n,m,ax[mxn],head[mxn],f[mxn],a[mxn],b[mxn],g[mxn][8192];
struct ed{int to,nxt;}edge[mxn<<1];
void addedge(int u,int v){edge[++m]=(ed){v,head[u]},head[u]=m;}
#define rep for (int i=head[u],v;i;i=edge[i].nxt) if ((v=edge[i].to)!=fa)
void dfs(int u,int fa){
	rep dfs(v,u); f(g[1]),m=g[1][0]=0; rep a[++m]=f[v],b[m]=ax[v];
	for (int i=1;i<=m&&(f(g[i+1]),1);++i)
		for (int j=0;j<=ax[u];++j){
			if (j+a[i]<=ax[u]) g[i+1][j+a[i]]=min(g[i+1][j+a[i]],g[i][j]+b[i]);
			if (j+b[i]<=ax[u]) g[i+1][j+b[i]]=min(g[i+1][j+b[i]],g[i][j]+a[i]);
		}
	for (int i=ax[u];i>=0;--i) f[u]=min(f[u],g[m+1][i]);
}
int main()
{
	for (int i=(scanf("%d",&n),f(f),2),x;i<=n;++i) scanf("%d",&x),addedge(i,x),addedge(x,i);
	for (int i=1;i<=n;++i) scanf("%d",&ax[i]);
	return dfs(1,0),puts(f[1]<0x3f3f3f3f?"POSSIBLE":"IMPOSSIBLE"),0;
}

Measured memory_bytes: 32896
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

// ユーグリッド互除法
ll GCD(ll a, ll b)
{
  if(b == 0) return a;
  else return GCD(b, a % b);
}

// 最小公倍数
ll LCM(ll a, ll b)
{
  ll g = GCD(a,b);
  return a / g * b;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,m; cin >> n >> m;
  string s,t; cin >> s >> t;
  ll l = LCM(n,m);
  ll g = GCD(n,m);
  ll gn = n/g;
  ll gm = m/g;
  REP(i,g){
    if(s[gn*i]!=t[gm*i]){
      cout << -1 << endl;
      return 0;
    }
  }
  cout << l << '\n';
  return 0;
}


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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int h, w;
    cin >> h >> w;
    vs s(h);
    rep(i, h) cin >> s[i];
    queue<pii> q;
    vector<vi> dist(h, vi(w, INF));
    q.emplace(0, 0);
    dist[0][0] = (s[0][0]=='.'?0:1);
    while (!q.empty()) {
        auto p = q.front(); q.pop();
        int y = p.first, x = p.second, d = dist[y][x];
        const vi dy = { 0, 1 }, dx = { 1, 0 };
        rep(i, 2) {
            int ny = y + dy[i], nx = x + dx[i];
            if (ny<0 || ny>=h || nx<0 || nx>=w) continue;
            int nd = d + (s[y][x]!=s[ny][nx]?1:0);
            if (dist[ny][nx] <= nd) continue;
            q.emplace(ny, nx);
            dist[ny][nx] = nd;
        }
    }
    int cnt = dist[h-1][w-1] + (s[h-1][w-1]=='.'?0:1);
    cout << (cnt / 2) << endl;
    return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <random>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;


std::random_device seed_gen;
std::mt19937_64 engine(seed_gen());
// ull a = engine();

int main(int argc, char const *argv[]) {
  ll D;std::cin >> D;
  vll c(26);re(i, 26) std::cin >> c[i];
  vvl s = VV(D, 26, 0, ll);
  re(i, D) re(j, 26) std::cin >> s[i][j];
  for(int i=0;i<D;i++){
    ll idx = -1, num = -1;
    for(int j=0;j<26;j++) if(num<s[i][j]) num = s[i][j], idx = j;
    std::cout << idx+1 << '\n';
  }
  return 0;
}


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

using namespace std;

int main(){
    int n;
	cin >> n;
	int sum = 0;
	int resa = 0,resb = 0;
	vector<int> a(n);
	for(int i=0;i<n;++i){
		cin >> a[i];
		sum += a[i];
	}
	sum /= n;
	for(int i=0;i<n;++i){
		resa += (sum - a[i]) * (sum - a[i]);
		resb += (sum - a[i] + 1) * (sum - a[i] + 1);
	}
	cout << min(resa,resb) << endl;
}

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

int main() {
  int A, B, C, D, L, R;
  cin >> A >> B >> C >> D;

  // ここにプログラムを追記
  L = A + B;
  R = C + D;
 
  if (L > R){
    cout << "Left" << endl;
  }
  else if (L == R){
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 3568
s=input()

ss=[0 for i in range(26)]
for i in range(len(s)):
    for j in range(26):
        if s[i]==chr(97+j):
            ss[j]=1

if len(s)!=26:
        for i in range(26):
            if ss[i]==0:
                s=s+chr(97+i)
                break
        print(s)





else:
    if s=="zyxwvutsrqponmlkjihgfedcba":
        print(-1)
    else:
        for i in range(25):
            if s[24-i] < s[25-i]:
                s=s[:25-i]
                break

        sss=[0 for i in range(26)]
        for i in range(len(s)):
            for j in range(26):
                if s[i]==chr(97+j):
                    sss[j]=1

        for i in range(26):
            if sss[i]==0 and chr(97+i)> s[len(s)-1]:
                s=s[:len(s)-1]+chr(97+i)
                break

        print(s)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e5+7;
int N;
const int MOD=1e9+7;
vector <int> adj[MAXN];
long long int dp[MAXN][2];
long long int solve(int u,int c,int p)
{
    if(dp[u][c]!=-1)
    return dp[u][c];
    long long int tot=1;
    for(int a:adj[u])
    {
        if(a==p)
        continue;
        if(c==0)
        tot=(tot*(solve(a,0,u)+solve(a,1,u)))%MOD;
        else
        tot=(tot*(solve(a,0,u)))%MOD;
    }
    return dp[u][c]=tot;
}
int main()
{
    cin>>N;
    memset(dp,-1,sizeof(dp));
    for(int i=1;i<N;i++)
    {
        int u,v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    cout<<(solve(1,0,-1)+solve(1,1,-1))%MOD<<"\n";
}

Measured memory_bytes: 15616
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
const int INF = 100000000;
const int MAX_N = 100;
typedef pair<int , int> P;
typedef long long ll;
 
int main () {
  double A, B, H, M;
  cin >> A >> B >> H >> M;
  double dL, dS, d;
  // dL = 30 * H + 0.5 * M;
  // dS = 6 * M;
  dL = (M_PI / 6) * H + (M_PI / 360) * M;
  dS = (M_PI / 30) * M;
  // printf("%lf\n", dL);
  // printf("%lf\n", dS);
  if (dL < dS) {
    d = dS - dL;
  } else {
    d = dL - dS;
  }
  // printf("%lf\n", d);
  double ans = A * A + B * B - 2 * A * B * cos(d);
  // printf("%lf\n", ans);
  ans = sqrt(ans);
  printf("%.9lf\n", ans);
  // cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4216
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll MOD=1e9+7;

void solve()
{
	ll k;
	cin>>k;
    ll s=7%k;
    for(ll i=1;i<=999982;i++)
    {
        if(s==0)
        {
            cout<<i;
            return;
        }
        else
            s=(s*10+7)%k;
            
    }
    cout<<"-1";
	return;
}
int main()
{
        fast;
        ll q;
        q=1;
        // cin>>q;
        while(q--)
        	solve();
        
        return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

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

	string ret;
	if(B <= A)
		ret = "delicious";
	else if(B-A <= X)
		ret = "safe";
	else
		ret = "dangerous";

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cmath>
#include <algorithm>
using namespace std;


int main() {

	int n;
	cin >> n;

	vector<int> a(n);
	vector<int> b(n);

	for (int i = 1; i < n; i++) {
		cin >> a.at(i);
		b.at(a.at(i)-1)++;
	}


	for (int i = 0; i < n; i++) {
		cout << b.at(i) << endl;
	}

}

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

long long A[100000], B[100000], C[100000];
long long l[100000];
long long r[100000];

int main(){
    long long i, j, k;
    long long X, Y, Z;
    cin >> X >> Y >> Z;
    long long S = X+Y+Z;
    vector<long long> order(S);
    for(i=0; i<S; i++){
        cin >> A[i] >> B[i] >> C[i];
        order[i] = i;
    }
    sort(
        order.begin(), order.end(),
        [](long long i, long long j){return B[i]-A[i] < B[j]-A[j];}
    );


    long long sum = 0;
    priority_queue<long long> que;
    for(i=0; i<X+Z; i++){
        long long index = order[i];
        sum += A[index];
        que.push(C[index]-A[index]);
        if(i>=X){
            sum += que.top();
            que.pop();
        }
        if(i>=X-1) l[i+1-X] = sum;
    }
    sum = 0;
    priority_queue<long long> que2;
    que = que2;
    for(i=0; i<Y+Z; i++){
        long long index = order[S-1-i];
        sum += B[index];
        que.push(C[index]-B[index]);
        if(i>=Y){
            sum += que.top();
            que.pop();
        }
        if(i>=Y-1) r[i+1-Y] = sum;
    }
    long long ans = 0;
    for(i=0; i<=Z; i++){
        ans = max(ans, l[i]+r[Z-i]);
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  long n,k;
  cin >> n >> k;
  long a[n];
  long maxa = 0;
  rep(i,n){
    cin >> a[i];
    if(maxa<a[i])maxa = a[i];
  }
  long li = 0, ri = maxa;
  long mid = (li+ri)/2;
  while(li+1<ri){
    long tmp=0;
    mid = (li+ri)/2;
    rep(i,n){
      //tmp += ceil((double)a[i]/(double)mid)-1;
      tmp += (a[i]-1)/mid;
    }
    if(tmp<=k)ri = mid;
    else if(tmp>k)li = mid;
  }
  cout << ri << endl;
  return 0;
}

Measured memory_bytes: 5172
#include<iostream>
#include<cmath>
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<string>
#include<string.h>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<iterator>
#include<queue>
#include<ctime>
#include<bitset>
#define eps 1e-6
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
//#define ll __int64
#define ll long long
#define lson l,m,(rt<<1)
#define rson m+1,r,(rt<<1)|1
#define M 1000000007
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
char mp[105][105];
int vis[105][105];
int dx[]={0,0,-1,1};
int dy[]={-1,1,0,0};
int n,m;
bool isok(int x,int y)
{
    return x>=0&&x<n&&y>=0&&y<m;
}
void dfs(int x,int y,char e)
{
    vis[x][y]=1;
    for(int d=0;d<4;d++)
    {
        int nx=x+dx[d];
        int ny=y+dy[d];
        if(isok(nx,ny)&&!vis[nx][ny]&&mp[nx][ny]==e)
        {
            dfs(nx,ny,e);
        }
    }
}
int main()
{
    while(scanf("%d%d",&n,&m))
    {
        if(n+m==0) break;
        memset(vis,0,sizeof(vis));
        int ans=0;
        for(int i=0;i<n;i++)
        {
            scanf("%s",&mp[i]);
        }
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                if(!vis[i][j])
                {
                    ans++;
                    dfs(i,j,mp[i][j]);
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 1720
#include <stdio.h>
#include <vector>
std::vector<long long int> V;
int check[100010];
int main()
{
	long long int a,b,c;
	scanf("%lld%lld%lld",&a,&b,&c);
	
	V.push_back(0);
	V.push_back(b);
	check[b] = 1;
	
	int start,end;
	for(int i=2;;i++)
	{
		b*=b;
		b%=c;
		if(check[b]!=0)
		{
			start = check[b];
			end = i-1;
			break;
		}
		V.push_back(b);
		check[b] = i;
	}
	
	if(a<start)
	{
		long long int ans = 0;
		for(int i=1;i<=a;i++) ans += V[i];
		printf("%lld",ans);
		return 0;
	}
	else
	{
		long long int ans = 0;
		for(int i=1;i<start;i++) ans += V[i];
		long long int S = 0;
		for(int i=start;i<=end;i++) S += V[i];
		ans += S * ((a-start+1)/(end-start+1));
		int k = (a-start+1)%(end-start+1);
		for(int i=start;i<start+k;i++) ans += V[i];
		printf("%lld",ans);
		return 0;
	}
}

Measured memory_bytes: 3732
#include <iostream>
#include "string.h"
using namespace std;
int main(){
int c,inc;
string x;
cin>>x;
int len=x.length();
for(int i=0;i<len;i++){
    if(x[i]=='A'){
                inc=i+1;
                break;
             }
    }
        for(int i=0;i<len;i++){
                if(x[i]=='Z'){
            c=i+1;
        }
        }
        cout<<c-inc+1<<"\n";
   }





Measured memory_bytes: 832
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>

#define REP(i, n) for(int i = 0; i < (n); i++)
#define ISIN(x, y, w, h) (x >= 0 && x < w && y >= 0 && y < h)

#define f first
#define s second

using namespace std;

pair<int, int> joint[70];
int h, w, c;
int p[8][8];
bool f[8][8];

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

int getInt(){ int r; scanf("%d", &r); return r; }

int solve(int now, int prev, int cnt){
  int ret = cnt;

  //printf("solve(%d, %d, %d)\n", now, prev, cnt);

  if(now == 6) return cnt;

  for(int col = 1; col <= 6; col++){
    int cc = cnt;
    queue<pair<int, int> > q;

    if(now == 5 && col != c) continue;
    if(now == 0 && col != prev) continue;

    REP(i, cnt) q.push(joint[i]);

    while(q.size()){
      int x = q.front().s;
      int y = q.front().f;

      q.pop();

      REP(i, 4){
	int xx = x + dx[i];
	int yy = y + dy[i];

	if(ISIN(xx, yy, w, h) && p[yy][xx] == col && !f[yy][xx]){
	  f[yy][xx] = true;
	  joint[cc].f = yy;
	  joint[cc].s = xx;
	  q.push(joint[cc++]);
	}
      }
    }

    if(now == 0 || cc != cnt){
      ret = max(ret, solve(now + 1, col, cc));
      
      for(int i = cnt; i < cc; i++){
	int x = joint[i].s;
	int y = joint[i].f;
	
	f[y][x] = false;
      }
    }
  }

  return ret;
}

int main(){
  while(true){
    h = getInt();
    w = getInt();
    c = getInt();

    if(h + w + c == 0) break;

    REP(i, h) REP(j, w) p[i][j] = getInt();
    f[0][0] = true;

    printf("%d\n", solve(0, p[0][0], 1));
  }
  return 0;
}

Measured memory_bytes: 920
#include <iostream>

using namespace std;

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

    int x,y,z;
    int ret=0;
    for (x=0;x<=k;x++){
	for (y=0;y<=k;y++){
	    z=s-(x+y);
	    if ((z >= 0) && (z <= k)) ret++;
	}
    }

    cout << ret << endl;

    return 0;
}

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

using namespace std;

map<int, int> dist;

int main() {
    int n;
    while (cin >> n) {
        dist.clear();
        if (n == 0) break;
        int p, d1, d2;
        for (int i = 0; i < n; i++) {
            cin >> p >> d1 >> d2;
            dist[p] = d1 + d2;
        }
        int max = 0, max_p;
        for (map<int, int>::iterator m = dist.begin(); m != dist.end(); m++) {
            if ((*m).second > max) {
                max = (*m).second;
                max_p = (*m).first;
            }
        }
        cout << max_p << ' ' << max << endl;
    }
    return 0;
}

Measured memory_bytes: 0
N,M = map(int,input().split())
A = list(map(int,input().split()))
weight = [0,2,5,5,4,5,6,3,7,6]
dp=[-1]*(N+1)
dp[0] = 0
for i in range(N+1):
    if dp[i] == -1:continue
    for a in A:
        if i+weight[a]<N+1:
            dp[i+weight[a]] = max(dp[i+weight[a]],dp[i]*10+a)
print(dp[-1])

Measured memory_bytes: 14692
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include<stack>
#include<set>
#include<queue>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll m = (1e+9) + 7;

int main() {
	int n;
	cin >> n;
	vector<int> a(n), l(n + 10), r(n + 10);
	l[0] = r[0] = 0;
	l[n + 1] = r[n + 1] = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		l[i + 1] = max(l[i], a[i]);
	}
	for (int i = n - 1; i >= 0; --i) {
		r[i + 1] = max(r[i + 2], a[i]);
	}
	for (int i = 1; i <= n; ++i)
		cout << max(l[i - 1], r[i + 1]) << endl;
	return 0;
}

Measured memory_bytes: 3968
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}


// ll memo[2020][2020];
// int pascal_triangle(){
//   for(int i = 0; i < 1000; i++){
//     for(int j = 0; j < i+1; j++){
//       if(j == 0 || j == i) memo[i][j] = 1;
//       else{
// 	memo[i][j] = (memo[i-1][j-1]+memo[i-1][j])%mod;
//       }
//     }
//   }
//   return 0;
// }


// int factorial(int n){
//   if(n == 0) return 1;
//   return n*factorial(n-1);
// }

// int divisor(int a){
//   int cnt = 0;
//   for(int i=1; i <= a; i++) if(a%i == 0) cnt++;
//   return cnt;
// }

// int comb(int n, int k){
//   pascal_triangle();
//   return memo[n][k];
// }

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}







//二項係数(mod剰余)----------------------------

// const int MAX = 3000010;
// const int M = 1000000007;

// vector<ll> fac(MAX); //n!(mod M)
// //a,bの範囲的にこれだけ配列を用意していけば十分
// vector<ll> ifac(MAX); //k!^{M-2} (mod M)

// ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
//     ll ans = 1;
//     while(n != 0){
//         if(n&1) ans = ans*x % M;
//         x = x*x % M;
//         n = n >> 1;
//     }
//     return ans;
// }

// ll COMinit(){
//   //大した量ではないので，先にfax[i]とifax[i]を全て計算しておく
//   fac[0] = 1;
//   ifac[0] = 1;
//   for(ll i = 0; i<MAX; i++){
//     fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
//     ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
//   }
//   return 0;
// }

// ll COM(ll a, ll b){ //aCbをmod計算
//   if(a == 0 && b == 0)return 1;
//   if(a < b || a < 0)return 0;
//   ll tmp = ifac[a-b]* ifac[b] % M;
//   return tmp * fac[a] % M;
// }

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



int main(){
  char c;
  cin >> c;
  char d = c+1;
  cout << d << endl;
  
  return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF (1LL<<60)
#define MOD7 1000000007LL
#define PREP(i, s, x) for(ll i = (s); i < (x); i ++)
#define MREP(i, s, x) for(ll i = (s); i >= (x); i --)
#define REP(i, x) PREP(i, 0, x)
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;
template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return 1;}return 0;}
ll llpow(ll a, ll n){ll res=1;REP(_,n){res*=a;}return res;}

ll llgcd(ll a, ll b){
    if(b == 0)
        return a;
    return llgcd(b, a % b);
}

int main(){
    ll n;
    cin >> n;
    string s;
    cin >> s;
    vector<ll> rgbcount(3,0);
    REP(i, n){
        if(s[i] == 'R'){
            rgbcount[0]++;
        }else if(s[i] == 'G'){
            rgbcount[1]++;
        }else if(s[i] == 'B'){
            rgbcount[2]++;
        }
    }
    ll ans = rgbcount[0] * rgbcount[1] * rgbcount[2];

    REP(t, n){
        REP(d, n){
            if(t + 2 * d < n){
                if(s[t] != s[t+d] && s[t+d] != s[t+2*d] && s[t+2*d] != s[t]){
                    ans--;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;


int main()
{
	int n,i,j,k;
	cin>>n>>k;
	int h[n+1];
	for(i=1;i<=n;i++)cin>>h[i];
	long long cost[n+1];cost[1]=0;cost[2]=abs(h[1]-h[2]);
	for(i=3;i<=n;i++)
	{
		cost[i]=cost[i-1]+abs(h[i]-h[i-1]);
		for(j=2;j<=k;j++)
		{
			if(i-j>=1)
			cost[i]=min(cost[i],(cost[i-j]+abs(h[i]-h[i-j])));
			else break;
		}
	}
	cout<<cost[n];
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
 
#define MOD 1000000007
 
int main() {
    ll n, m, ans;
    cin >> n >> m;
    if (abs(n - m) > 1) {
        cout << 0 << endl;
        return 0;
    }
 
    ll n1 = n;
    ll m1 = m;
    for (ll i = n-1; i >= 1; i--)
        n1 = (n1 * i) % MOD;
    for (ll i = m-1; i >= 1; i--)
        m1 = (m1 * i) % MOD;
 
    if (n == m) {
        ans = (n1 * m1 * 2) % MOD;
    } else {
        ans = (n1 * m1) % MOD;
    }
 
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define all(v) (v).begin(), (v).end()
#define pb push_back

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

    ll n,a[100001],ans=0,flag=0,tmp,num;
    cin >> n;
    map<ll,ll> mp;
    rep(i,n){
        cin >> a[i];
        mp[a[i]]++;
    }
    sort(a,a+n,greater<int>());
    rep(i,n){
        tmp = a[i];
        if(i>=1 && tmp==a[i-1]) continue;
        if(mp[a[i]]>=4){
            if(flag==1) ans = num * a[i];
            else ans = a[i] * a[i];
            break;
        }
        else if(mp[a[i]]>=2){
            flag++;
            if(flag==1) num = a[i];
            if(flag==2){
                ans = num * a[i];
                break;
            }
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 7296
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;

template <class T>
inline bool chmin(T &a, T b){
    if (a > b){
        a = b;
        return true;
    }
    return false;
}

template <class T>
inline bool chmax(T &a, T b){
    if (a < b){
        a = b;
        return true;
    }
    return false;
}

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    else return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

int INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    rep(i,n) cin >> a[i];
    rep(j,n) cin >> b[j];
    vector<ll> c;
    ll d = 0ll;
    ll ans = 0ll;
    Rep(i,n){
        if(a[i]-b[i]>=0) c.emplace_back(a[i]-b[i]);
        else{
            d += b[i]-a[i];
            ans++;
        }
    }
    sort(c.begin(),c.end());
    reverse(c.begin(),c.end());
    ll index = 0;
    while(d>0 && index < c.size()){
        d -= c[index];
        index++;
    }
    ans += index;
    if(d>0){
        cout << -1 << endl;
        return 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2936
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N;
    cin >>N;
    vector<ll>dp(N+1);
    dp[0]=2;
    dp[1]=1;
    rep(i,N-1){
        dp[i+2]=dp[i+1]+dp[i];
    }
    cout << dp[N] << endl;


    return 0;
    

}

Measured memory_bytes: 3644
def main():
    N = int(input())
    A = list(map(int,input().split()))
    flag = True
    count = 0
    while flag:
        flag = False
        for i in range(N-1,0,-1):
            if A[i] < A[i-1]:
                count += 1
                A[i], A[i-1] = A[i-1], A[i]
                flag = True
    print(" ".join(map(str,A)))
    print(count)


if __name__ == "__main__":
    import os
    import sys
    if len(sys.argv) > 1:
        if sys.argv[1] == "-d":
            fd = os.open("input.txt", os.O_RDONLY)
            os.dup2(fd, sys.stdin.fileno())
            main()
    else:
        main()

Measured memory_bytes: 7780
#include <bits/stdc++.h>
using namespace std;
int n;
long long h[100005];
long long dp[100005];

long long solve(int i){
	if(i >= n-1) return 0;
	if(dp[i] != -1) return dp[i];

	dp[i] = 1e17;
	if(i+1 <= n-1)
		dp[i] = min(dp[i], abs(h[i] - h[i+1]) + solve(i+1));
	if(i+2 <= n-1)
		dp[i] = min(dp[i], abs(h[i] - h[i+2]) + solve(i+2));

	return dp[i];
}

int main(){
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		scanf("%lld", &h[i]);
	memset(dp, -1, sizeof dp);
	cout<<solve(0)<<endl;
	return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define mod ((ull)1e9+7)
#define MAX ((ull)1e6)

ll pmod(ll n, ll p){
	ll m=n%mod;
	if(p==1) return m;
	ll ans=pmod((m*m)%mod, p/2)%mod;
	if(p%2==1) ans=(ans*m)%mod;
	return ans;
}

ll binom(ll n, ll k){
	ll a=1, b=1;
	for(ll i=0; i<k; i++){
		a=((a%mod)*((n-i)%mod))%mod;
		b=((b%mod)*((k-i)%mod))%mod;
	}
	return (a*pmod(b, mod-2))%mod;
}

int main(){
	int n;
	cin >> n;
	int c[n-1], s[n-1], f[n-1];
	for(int i=0; i<n-1; i++){
		cin >> c[i] >> s[i] >> f[i];
	}

	for(int i=0; i<n-1; i++){
		int t=0;
		for(int j=i; j<n-1; j++){
			if(t<s[j]) t=s[j];
			else if((t-s[j])%f[j]!=0) t+=f[j]-(t-s[j])%f[j];
			t+=c[j];
		}
		cout << t << endl;
	}
	cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var a, b, x int
	fmt.Scan(&a, &b, &x)

	aa := 0
	if a != 0 {
		aa = (a-1)/x + 1
	}

	bb := 0
	if b != -1 {
		bb = b/x + 1
	}

	cal := bb - aa
	fmt.Print(cal)

}


Measured memory_bytes: 512
fun main(args: Array<String>) {
    val k = readLine()!!.toInt()

    val memo = hashMapOf<Pair<Int, Int>, Int>()
    fun gcd(a: Int , b: Int): Int{
        val p = Pair(a,b)
        if (!memo.containsKey(p)){
            if (a == b){
                memo[p] = a
            } else if (a > b){
                memo[p] = gcd(b, a - b)
            } else {
                memo[p] = gcd(a, b - a)
            }
        }
        return memo[p]!!
    }

    var sum = 0
    for (a in 1..k){
        for (b in 1..k){
            for (c in 1..k){
                sum += gcd(a, gcd(b, c))
            }
        }
    }
    println(sum)
}

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

int main(){
  int x,ans=1;
  cin>>x;
  map<int,int> beki;
  for(int i=1; i*i<=1000; i++){
    for(int p=2; p<10; p++){
      beki[pow(i,p)]=1;
    }
  }
  rep(i,x+1){
    if(beki[i]==1){
      ans=i;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
	Scanner scanner = new Scanner(System.in);
	int r = scanner.nextInt();
	int g = scanner.nextInt();
	int b = scanner.nextInt();
	if (((g*10+b)%4) == 0) {
		System.out.println("YES");
	} else {
		System.out.println("NO");
	}
	scanner.close();
}
}


Measured memory_bytes: 19924
/**
     *    author:  tourist
     *    created: 26.11.2019 03:48:15       
    **/
    #include <bits/stdc++.h>
     
    using namespace std;
     
    int main() {
      ios::sync_with_stdio(false);
      cin.tie(0);
      int n, a, b;
      cin >> n >> a >> b;
      if (a * 1LL * b < n || a + b - 1 > n) {
        cout << -1 << '\n';
        return 0;
      }
      vector<int> c(a, 1);
      c[0] = b;
      int ptr = 1;
      for (int i = a + b - 1; i < n; i++) {
        if (c[ptr] == b) {
          ++ptr;
        }
        ++c[ptr];
      }
      ptr = 0;
      for (int x : c) {
        for (int i = 0; i < x; i++) cout << ptr + x - i << " ";
        ptr += x;
      }
      return 0;
    }

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

int N;
int ans[10];

int main() {
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		char S[5]; scanf(" %s", S);
		if (strcmp(S, "AC") == 0) ans[0]++;
		else if (strcmp(S, "WA") == 0) ans[1]++;
		else if (strcmp(S, "TLE") == 0) ans[2]++;
		else if (strcmp(S, "RE") == 0) ans[3]++;
	}
	printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n", ans[0], ans[1], ans[2], ans[3]);
	return 0;
}


Measured memory_bytes: 3828
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
using namespace std;
const int maxn=10000+5,maxm=40000+5;
int n,m,hd[maxn],to[maxm],nxt[maxm],w[maxm],val[maxm],cnt;
bool vis[maxn];
struct M{
	int cost,dis,to;
	M(int a,int b,int c){
		cost=a,dis=b,to=c;
	}
	friend bool operator < (M a,M b){
		if(a.dis==b.dis)
			return a.cost>b.cost;
		return a.dis>b.dis;
	}
};
inline void add(int x,int y,int s,int l){
	w[cnt]=s;
	to[cnt]=y;
	val[cnt]=l;
	nxt[cnt]=hd[x];
	hd[x]=cnt++;
}
inline int dijkstra(void){
	memset(vis,0,sizeof(vis));
	priority_queue<M> pq;
	pq.push(M(0,0,1));
	int ans=0;
	while(!pq.empty()){
		M top=pq.top();
		pq.pop();
		if(vis[top.to])
			continue;
		vis[top.to]=1,ans+=top.cost;
		for(int i=hd[top.to];i!=-1;i=nxt[i])
			pq.push(M(val[i],top.dis+w[i],to[i]));
	}
	return ans;
}
signed main(void){
	while(scanf("%d%d",&n,&m)&&n){
		cnt=0,memset(hd,-1,sizeof(hd));
		for(int i=1,x,y,s,l;i<=m;i++)
			scanf("%d%d%d%d",&x,&y,&s,&l),add(x,y,s,l),add(y,x,s,l);
		cout<<dijkstra()<<endl;
	}
	return 0;
} 

Measured memory_bytes: 2536
N = int(input())

def divisors(n):
    ret = set()
    m = 1
    while m*m <= n:
        if n%m==0:
            ret.add(m)
            ret.add(n//m)
        m += 1
    return ret

a = divisors(N)
b = divisors(N-1)

ans = len(b)-1
for k in a:
    if k==1: continue
    n = N
    while n%k==0:
        n //= k
    if n%k == 1:
        ans += 1

print(ans)


Measured memory_bytes: 39664
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
#define PI acos(-1)
ll A[5000001],bin[5000001];
vector<ll>v;
map<int,int>myMap;
set<int>mySet;
vector<pair<ll,ll> >vp;
/* Precode Start Here *\



     Sieve
void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}

     Power Function Modulo P

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}


   factorial

ll fact(ll n)
{
    ll ans=1;
    for(ll i=1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    return ans;
}
     Calculating nCr using Fermats law Theorem

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}


ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (ll i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (ll i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
     num of divisor and euler totient

ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
    for(int i=1;i<=n;i++)
        phi[i]=i;
    for(int i=2;i<=n;i++)
    {
        if(!mark[i])
        {
            for(int j=i;j<=n;j+=i)
            {
                mark[j]=1;
                phi[j]*=(1-1/(double)i);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
            divi[j]++;
    }
}




/* Precode Ends */
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
     ll m1,d1,m2,d2;
     cin>>m1>>d1>>m2>>d2;
     if((m1==1||m1==3||m1==5||m1==7||m1==8||m1==10||m1==12)&&d1==31)
     {
         cout<<1<<endl;
     }
     else if(m1==2&&d1==28)
     {
         cout<<1<<endl;
     }
     else if((m1==4||m1==6||m1==9||m1==11)&&d1==30)
     {
         cout<<1<<endl;
     }
     else
     cout<<0<<endl;

return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include <vector>
#include <string>
#include<algorithm>
#include<math.h>
using namespace std;
#define maxn 10000
int num[maxn];
int main()
{
	int n;
	int i = 0;
	cin >> n;
	do {
		num[i++] = abs(n %-2);
		n = ceil((double)n / -2);
	} while (n);
	while (i--)cout << num[i];
	return 0;
}


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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 100000000000000;
double PI = 3.1415926535;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main(){
    ll N;cin >> N;
    vector<ll> A(N);
    vector<vector<ll>> cnt(100,vector<ll>(2));
    for(int i = 0;i < N;i++){
        cin >> A[i];
        bitset<100> S(A[i]);
        for(int j = 0;j < 100;j++){
            if(S.test(j)){
                cnt[j][1]++;
            }else{
                cnt[j][0]++;
            }
        }
    }
    ll ans = 0;
    for(int i = 0;i < 62;i++){
        ll res = 0;
        res += cnt[i][0] * cnt[i][1];
        for(int j = 0;j < i;j++){
            res *= 2;
            res %= MOD;
        }
        ans += res;
        ans %= MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 2560
#include <iostream>

using namespace std;

int main(){
    long long A, B, C, X, Y;
    while(cin >> A >> B >> C >> X >> Y){
        const int m = max(X, Y);
        long long res = A * X + B * Y;
        for(int i=1;i<=m;i++){
            long long cur = 2*i*C;
            cur += A * max(0LL, X - i);
            cur += B * max(0LL, Y - i);
            res = min(res, cur);
        }
        cout << res << endl;
    }
}

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

int main() {
  int N,K;
  cin>>N>>K;
  vector<int> P(N);
  for(int i=0;i<N;i++){
    int p;
    cin>>p;
    P.at(i)=p;
  }
  sort(P.begin(),P.end());
  int ans=0;
  for(int j=0;j<K;j++){
    ans+=P.at(j);
  }
  cout<<ans<<endl;
}


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

using namespace std;

map<string, long> mp;

int main(){
    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        char s[10];
        for(int i = 0; i < 10; i++) cin >> s[i];
        sort(s, s+10);
        string S(10, 'a');
        for(int i = 0; i < 10; i++) S[i] = s[i];
        //cout << S << endl;
        if(mp.count(S) == 0){
            mp[S] = 1;
        }else{
            mp[S]++;
        }
    }
    long ans = 0;
    for(auto iter = mp.begin(); iter != mp.end(); iter++){
        long m = iter->second;
        ans += (m*(m-1))/2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 8064
import sys
sys.setrecursionlimit(10**7)

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

N = int(input())

X = [int(i) for i in input().split()]

x = X[0]

for i in range(1, N):
    x = gcd(x, X[i])
print(x)

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



int w,h,n;

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

    cin>>w>>h>>n;
    int dim = max(w,h);

    cout<<((n+dim-1)/dim)<<endl;
    
    
    return 0;
}


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

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        int n = sc.nextInt();
        int m = sc.nextInt();
        Vector<Integer>[] vectors = new Vector[n];
        for (int i = 0; i < n; i++) {
            vectors[i] = new Vector<>();
        }

        for (int i = 0; i < m; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;

            vectors[a].add(b);
            vectors[b].add(a);
        }

        int[] ans = new int[n];
        Queue<Integer> queue = new ArrayDeque<>();
        queue.add(0);
        while (!queue.isEmpty()) {
            int t = queue.poll();
            for (int v : vectors[t]) {
                if (ans[v] == 0) {
                    ans[v] = t + 1;
                    queue.add(v);
                }
            }
        }

        PrintWriter pw = new PrintWriter(System.out);
        pw.println("Yes");
        for (int i = 1; i < n; i++)
            pw.println(ans[i]);
        pw.flush();
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

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

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

Measured memory_bytes: 76304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long double pi = acos(-1);
void start(){
std::ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
}
int main(){
   start();
    int n;
    cin>>n;
    string s;
    cin>>s;
    if(n%2!=0)cout<<"No"<<endl;
    else {
        for(int i =  0 ,j = n/2; i < n/2 ;j++, i++){
            if(s[i]==s[j])continue;
            cout<<"No"<<endl;
            return 0;
        }
        cout<<"Yes"<<endl;
    }
    return 0 ;
}


Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.range, std.string, std.math, std.typecons;

void main()
{
    auto nk = readln.split.to!(int[]);
    auto N = nk[0];
    auto K = nk[1];

    long cnt;
    foreach (long i; 0..N) {
        if (i < K)
            continue;
        else {
            cnt += N / (i+1) * (i+1-K);
            if (N % (i+1) >= K) cnt += N % (i+1) - K + 1;
            if (!K) cnt -= 1;
        }
    }
    writeln(cnt);
}

Measured memory_bytes: 256
k, n = map(int, input().split())
a = list(map(int, input().split()))
d = [0] * n
d_max = 0

for i in range(n - 1):
    d[i] = a[i + 1] - a[i]
    d_max = max(d_max, d[i])

d[-1] = (k - a[-1]) + a[0]
d_max = max(d_max, d[-1])

print(k - d_max)


Measured memory_bytes: 26444