akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pr(num) cout << num << endl
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define mkp make_pair
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 150005
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;




int main(void) {
    ll N;
    ll a[MAX];
    cin >> N;
    ll i;
    ll cnt2=0, cnt4=0;
    
    for(i=0; i<N; i++) {
        cin >> a[i];
        if(a[i]%4==0) cnt4++;
        else if(a[i]%2==0) cnt2++;
    }
    
    if(cnt4*2+1>=N || cnt4*2+cnt2>=N) {
        puts("Yes");
    }else {
        puts("No");
    }
    
    
}




















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

int main(){
	string S;
	cin >> S;

	int N = S.size()*2-1;
	vector<char> ans(N);

	long long sum=0;
	long long sum2=0;
	for(int i=0; i < (1<<9); i++){
		bitset<9> ret(i);
		int cntS=0;
		sum2 += (int)S.at(cntS)-48;
		for(int j=0; j<(S.size()-1); j++){
			if(ret.test(j)){
				sum += sum2;
				cntS++;
				sum2 = (int)S.at(cntS)-48;
			}
			else{
				cntS++;
				sum2 *= 10;
				sum2 += (int)S.at(cntS)-48;
			}
		}
		sum += sum2;
		sum2 = 0;
		if( i == pow(2,S.size()-1)-1 ){
			cout << sum << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define inf 1000000000 //1E+9
using namespace std;	

int main(){
	int r;cin>>r;
	if(r<1200)cout<<"ABC"<<endl;
	else if(r<2800)cout<<"ARC"<<endl;
	else cout<<"AGC"<<endl;

	return 0;
}

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

int mod = 1000000007;

int main()
{
    int N;
    cin >> N;
    vector<int> list(N);
    for (int i = 0; i < N; i++)
        cin >> list[i];
    sort(list.begin(), list.end());
    bool x = true;
    for (int i = 0; i < N - 1;i++)
    {
        if (list[i] == list[i + 1])
            x = false;
    }
    cout << (x ? "YES" : "NO");
}

Measured memory_bytes: 1024
n,lw=map(int,input().split())
item=[]
for i in range(n):
    inp0,inp1=map(int,input().split())
    item.append((inp0,inp1))

dp=[10**13 for i in range(1002*n)]
dp[0]=0

for i in range(n):
    w=item[i][0]
    v=item[i][1]
    for q in range(1002*n-1,-1,-1):
        if q<=v:
            dp[q]=min(dp[q], w)
        else:
            dp[q]=min(dp[q], dp[q-v]+w)

for i in range(1002*n):
    if dp[i]>lw:
        print(i-1)
        break

Measured memory_bytes: 79332
#include <bits/stdc++.h>
using namespace std;
#define INT(a) scanf("%d",&a)
#define STR(a) scanf("%s",a)
#define DBL(a) scanf("%lf",&a)
#define LNG(a) scanf("%lld",&a)
#define PI acos(-1)

int main(){
	long long n,m;
	cin>>n>>m;

	long long ans = 0LL;
	if(n%2!=0){
		ans^=n;
		n++;
	}

	//cout<<ans<<endl;

	long long dis = m-n+1;
	dis = (dis/4)*4;

	n+=dis;
	
	for(long long i=n;i<=m;i++){
		ans^=i;
		//cout<<i<<endl;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n , x ,  a[110];
int main() {
	scanf("%d %d" , &n , &x);
	for(int i = 1 ; i <= n ; ++ i) scanf("%d" , & a[i]);
	sort(a + 1 , a + n + 1);
	int ans = 0;
	for(int i = 1 ; i <= n; ++ i) 
		if(x >= a[i]) {++ ans; x -= a[i];}
		else x = 0;
	if(x) -- ans;
	printf("%d\n" , ans);
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (n,m)= readLine()!!.split(" ").map { it.toInt() }
    val a = (1..n).map { readLine()!!.split(" ").map { it.toInt()-1 } }
    val p = (1..m).map { readLine()!!.split(" ").map { it.toInt()-1 } }


    val dist = Array(n){ IntArray(m) }
    for(ai in a.indices)for(pi in p.indices){
        dist[ai][pi]= Math.abs(a[ai][0]-p[pi][0]) + Math.abs(a[ai][1]-p[pi][1])
    }

    dist.forEach {
        val min = it.min()
        val ans = it.indexOfFirst { it==min }
        println(ans+1)
    }

}

Measured memory_bytes: 37744
for _ in range(5):
    a, b, c = [int(s) for s in input().strip().split(' ')]
    if  a | b | c == 0:
        break
    n = int(input().strip())
    rlist = [[int(s) for s in input().strip().split(' ')] for _ in range(n)]
    clist = [2,]*sum((a,b,c))
    for success in filter(lambda r: r[3] == 1, rlist):
        for i in success[:3]:
            clist[i-1] = 1

            for fail in filter(lambda r: r[3] == 0, rlist):
                plist = [clist[i-1] for i in fail[:3]]
                if sorted(plist) == [1,1,2]:
                    for i in fail[:3]:
                        if clist[i-1] == 2:
                            clist[i-1] = 0
                            break

    [print(r) for r in clist]



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



double dy[110][210][110];
bool chk[110][210][110];
int T[110];
int V[110];
int n;

double go(int idx, int t, int v) {
	if (idx == n && v == 0) {
		return 0;
	}
	if (idx == n) {
		return -1e9;
	}
	if (v > V[idx])return -1e9;
	auto& ret = dy[idx][t][v];
	if (chk[idx][t][v])return ret;
	chk[idx][t][v] = true;
	ret = -1e9;
	if (t == 0) {
		ret = go(idx + 1, T[idx+1], v);
		return ret;
	}
	if (v < V[idx]) {
		ret = std::max(ret, go(idx, t - 1, v + 1) + v + 0.5);
		ret = std::max(ret, go(idx, t - 1, v) + v + 0.25);
	}
	ret = std::max(ret, go(idx, t - 1, v) + v);
	if (v > 0) {
		ret = std::max(ret, go(idx, t - 1, v - 1) + v - 0.5);
	}
	return ret;
}
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &T[i]);
	}
	for (int i = 0; i < n; i++) {
		scanf("%d", &V[i]);
	}
	printf("%.10lf", go(0, T[0], 0));
}

Measured memory_bytes: 22272
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static int n;
        static int k;

        static void Main(string[] args)
        {
            int[] arr = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            n = arr[0];
            k = arr[1];

            int[] w = new int[n];
            int left = 0, right = 0;

            for (int i = 0; i < n; i++)
            {
                w[i] = int.Parse(Console.ReadLine());

                right += w[i];
            }

            int mid, v;

            while (right - left > 1)
            {
                mid = (left + right) / 2;
                v = Check(mid, w);

                if (v >= n) right = mid;
                else left = mid;
            }

            Console.WriteLine(right);
        }

        static int Check(int p, int[] w)
        {
            int Cnt = 0;

            for (int i = 0; i < k; i++)
            {
                int s = 0;

                while ((s + w[Cnt]) <= p)
                {
                    s += w[Cnt];
                    Cnt++;

                    if (Cnt == n) return Cnt;
                }
            }
            return Cnt;
        }
    }
}

Measured memory_bytes: 9892
#include <stdio.h>
#include <string.h>
#define T 1000003
char Hash[T][12];

int getChar(char string){
  if(string=='A')return 1;
  else if(string=='C')return 2;
  else if(string=='G')return 3;
  else if(string=='T')return 4;
  else return 0;
}

int h1(int key){
  return key%T;
}

int h2(int key){
  return 1+key%T;
}

int generateKey(char str[]){
  int i,char_value=0,rate=1;
  for(i=0;i<strlen(str);i++){
    char_value+=rate*getChar(str[i]);
    rate*=5;
  }
  return char_value;
}

void insert(char str[],int key){
  int h_number,i=0;
  while(1){
    h_number=(h1(key)+i*h2(key))%T;
    //元からあったとき
    if(strcmp(Hash[h_number],str)==0)break;
    //添字の部分に何もなかったとき(代入コピー操作)
    if(strlen(Hash[h_number])==0){
      strcpy(Hash[h_number],str);
      break;
    }
    i++;
  }
}

int find(char str[],int key){
  int h_number,i=0;
  while(1){
    h_number=(h1(key)+i*h2(key))%T;
    if(strcmp(Hash[h_number],str)==0)return 1;//match
    else if(strlen(Hash[h_number])==0)break;
    i++;
  }
  return 0;//Not match
}

int main(void){
  int i,n,key;
  char str[12],command[6];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s%s",command,str);
    key=generateKey(str);
    if(command[0]=='i')insert(str,key);
    else{
      if(find(str,key)==1)printf("yes\n");
      else printf("no\n");
    }
  }
  return 0;
}



Measured memory_bytes: 13344
#include<stdio.h>
int main(){
  int a,b,s=0,d[300]={0,300000,200000,100000};
  scanf("%d %d",&a,&b);
  s+=d[a]+d[b];
  if(a==1&&b==1)s+=400000;
  printf("%d\n",s);
  return 0;
}


Measured memory_bytes: 128
// https://atcoder.jp/contests/abc061/tasks/abc061_b

#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 INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

int main()
{
  /* Magic word */
  // cin.tie(0);
  // ios::sync_with_stdio(false);
  /* ---------- */

  int n, m;
  vector<int> r;

  cin >> n >> m;

  REP(i, n)
  {
    r.push_back(0);
  }

  REP(i, m)
  {
    int ai, bi;
    cin >> ai >> bi;
    r[ai - 1]++;
    r[bi - 1]++;
  }

  REP(i, n)
  {
    cout << r[i] << '\n';
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include<cmath>
#include<string>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define deb(x) cerr<<#x<<" "<<x<<"\n"
#define debi cerr<<"hey sparky\n"
#define x first
#define y second
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define newline cout<<"\n"
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"
#define nax (int)1e6+3
#define eps (double)1e-9
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> pdbs;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
//void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

// look for  all edge cases
//search for a pattern
		



signed main(){
	int n;
	cin >> n;
	
	int num = n;
	//int val = 26;
	
	string ans = "";
	// z - >0 a - > 1
	while(num > 0){
		char c;
		int rem = num%26;
		//deb(rem);
		
		if(rem == 0){
			rem = 26;
		}
		
		num -= rem;
		
		num /= 26;
		c = ('a'+rem -1);
		
		ans = c + ans;
	}
	
	cout<<ans;
	
	
	return 0;
}

	



Measured memory_bytes: 3576
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        final Scanner input = new Scanner(System.in);

        char[] text = input.nextLine().trim().toCharArray();
        if(text.length >= 6){
            if(text[3-1]==text[4-1] && text[5-1] ==text[6-1]){
                System.out.println("Yes");
            }else{
                System.out.println("No");
            }
        }else{
            System.out.println("No");
        }
    }
}


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

long long gcd(long long a,long long b){
    long long temp;
    if(a<b){
        temp=a;
        a=b;
        b=temp;
    }
    while((temp=a%b)!=0){
        a=b;
        b=temp;
    }
    return b;
}
int main() {
    int N;
    cin >> N;

    vector<long long> time(110);
    for(int i=0;i<N;i++){
        cin >> time[i];
    }
    long long ans=time[0];
    for(int i=1;i<N;i++){
        ans=(ans/gcd(ans,time[i]))*time[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<queue>
 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
 
const ll INF = 1ll<<50;
 
// セグメント木(RMQ 対応)
// update: k 番目の値を a に変更
// query: [l, r) の区間の最大値を求める
template<typename T>
struct ST {
    vector<T> seg;
    int size;
    ST(int n) {
        size = 1;
        while (size < n) size *= 2;
        seg.resize(2*size-1, INF);
    }
    inline T merge(T x, T y) {
        return min(x, y);
    }
    void update(int k, T a) {
        k += size-1;
        seg[k] = a;
        while (k > 0) {
            k = (k-1)/2;
            seg[k] = merge(seg[k*2+1], seg[k*2+2]);
        }
    }
    T query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) return INF;
        if (a <= l && r <= b){
            return seg[k];
        }
        T vl = query(a, b, k*2+1, l, (l+r)/2);
        T vr = query(a, b, k*2+2, (l+r)/2, r);
        return merge(vl, vr);
    }
    T query(int a, int b) {
        return query(a, b, 0, 0, size);
    }
};
 
const int MAXN = 100100;
ll N, E, T;
ll X[MAXN];
ll dp[MAXN];
 
int main() {
    cin >> N >> E >> T;
    for (int i = 0; i < N; i++)
        cin >> X[i];
    const ll INF = 1ll<<60;
    ST<ll> seg(N+10);
    for (int i = 0; i <= N; i++) {
        dp[i] = INF;
    }
    X[N] = E;
    dp[N] = 0;
    seg.update(N, dp[N] + X[N] + 2*X[N-1]);
    for (int i = N-1; i >= 0; i--) {
        // まず T が支配的な部分を探索
        int low = i, high = N;
        while (high - low > 1) {
            const int med = (low + high) / 2;
            if (2*(X[med]-X[i]) <= T) {
                low = med;
            } else {
                high = med;
            }
        }
        // cout << low+1 << "a" << N << endl;
        dp[i] = dp[low+1] + X[low+1] - X[i] + T;
        dp[i] = min(dp[i], seg.query(low+1, N) - 3*X[i]);
        if (i) seg.update(i, dp[i+1] + 2*X[i] + X[i+1]);
        //cout << i << " " << dp[i] << endl;
    }
    cout << X[0] + dp[0] << endl;
    return 0;
}


Measured memory_bytes: 3840
#pragma once

#include <bits/stdc++.h>

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;

#define rep(a,n) for(int a = 0;a < n;a++)
#define repi(a,b,n) for(int a = b;a < n;a++)

const ll mod = 1000000007;

int main(void)
{
	ll h, a;
	cin >> h >> a;
	if (h % a == 0) {
		cout << h / a << endl;
	}
	else {
		cout << h / a + 1 << endl;
	}
	return 0;
}


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

namespace ConsoleApp1
{
	class Program
	{
		static void Main(string[] a_asArgs)
		{
			int l_iN = int.Parse(Console.ReadLine());

			List<Point> l_lpRed = new List<Point>();
			List<Point> l_lpBlue = new List<Point>();

			for (int l_iIndex = 0; l_iIndex < l_iN; l_iIndex++)
			{
				int[] l_aiXY = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
				l_lpRed.Add(new Point { X= l_aiXY[0], Y = l_aiXY[1] });
			}
			for (int l_iIndex = 0; l_iIndex < l_iN; l_iIndex++)
			{
				int[] l_aiXY = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
				l_lpBlue.Add(new Point { X = l_aiXY[0], Y = l_aiXY[1] });
			}

			l_lpBlue.Sort(new PointComparerX());

			int l_iCount = 0;
			foreach (Point l_pBlue in l_lpBlue)
			{
				List<Point> l_List = l_lpRed.Where(a => a.X < l_pBlue.X && a.Y < l_pBlue.Y).ToList();
				if (l_List.Count > 0)
				{
					l_List.Sort(new PointComparerDescY());
					l_lpRed.Remove(l_List[0]);
					l_iCount++;
				}
			}

			Console.WriteLine(l_iCount);
		}

		private class Point
		{
			public int X;
			public int Y;
		}

		private class PointComparerX : IComparer<Point>
		{
			public int Compare(Point a_Point1, Point a_Point2)
			{
				return a_Point1.X - a_Point2.X;
			}
		}

		private class PointComparerDescY : IComparer<Point>
		{
			public int Compare(Point a_Point1, Point a_Point2)
			{
				return a_Point2.Y - a_Point1.Y;
			}
		}
	}
}


Measured memory_bytes: 13524
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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;
}

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> s(H, vector<char>(W));
  rep(i, H) {
    rep(j, W) {
      cin >> s[i][j];
    }
  }

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

  vector<vector<int>> d = vector<vector<int>>(H, vector<int>(W, INF));

  typedef pair<int, int> P;
  queue<P> q;
  q.push(make_pair(0, 0));
  d[0][0] = 0;

  while (!q.empty()) {
    P now = q.front();
    q.pop();

    rep(i, 4) {
      int y = now.fi;
      int x = now.se;
      int ny = y + dy[i];
      int nx = x + dx[i];
      if (0 <= ny && ny < H && 0 <= nx && nx < W) {
        if (s[ny][nx] != '#' && d[ny][nx] == INF) {
          d[ny][nx] = d[y][x] + 1;
          P next = make_pair(ny, nx);
          q.push(next);
        }
      }
    }
  }

  if (d[H - 1][W - 1] == INF) {
    cout << -1 << endl;
    return 0;
  }

  int no_change = d[H - 1][W - 1] + 1;
  int cnt = 0;
  rep(i, H) {
    rep(j, W) {
      if (s[i][j] == '.')
        cnt++;
    }
  }
  int ans = cnt - no_change;
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;


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

        double sum = 0;
        int ans = 0;
        double[] list = new double[N];

        for (int i = 0; i < N; i++) {
            list[i] = sc.nextDouble();
            sum += list[i];
        }

        int mid = (int) Math.round(sum / N);

        for (int i = 0; i < N; i++) {
            ans += Math.pow(list[i]-mid,2);
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 24276
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	int N, M, X;
	int ans = 0;
	vector<int> A;
	vector<vector<int>> table;
	vector<vector<int>> tables;

	cin>>N>>X>>M;
	
	table.resize(40, vector<int>(M));
	tables.resize(40, vector<int>(M));
	
	for(int j = 0; j < M; j++){
		table[0][j] = (j * j)% M;
		tables[0][j] = ((j * j)%M);
	}
	
	for(int i = 1; i < table.size(); i++){
		for(int j = 0; j < M; j++){
			table[i][j] = table[i-1][table[i-1][j]];
			tables[i][j] = tables[i-1][table[i-1][j]] + tables[i-1][j];
			// if(i <= 3)cout<<"i = "<<i<<" j = "<<j<<" tab = "<<table[i][j]<<" tabs = "<<tables[i][j]<<endl; 
		}
	}
	
	
	// N++;
	N--;;
	int now = X;
	
	// cout<<table[0][X]<<" "<<tables[0][X]<<endl;
	// cout<<table[1][X]<<" "<<tables[1][X]<<endl;
	// cout<<table[2][X]<<" "<<tables[2][X]<<endl;
	// cout<<table[3][X]<<" "<<tables[3][X]<<endl;
	
	for(int i = 0; i < table.size(); i++){
		if((N>>i)&1) {
			// cout<<i<<" now = "<<now<<endl;
			ans += tables[i][now];
			now = table[i][now];
		}
	}
	// cout<<now<<endl;
	cout<<ans+X<<endl;
	
	return 0;
}

Measured memory_bytes: 66676
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll unsigned long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}

const int mod = 1'000'000'007;
const int N = 3e5, M = N;
//=======================

void solve() {
    int i,j,k,n;
    cin >> k >> n;
    vi a(n+1);
    fo(i,n) cin >> a[i];
    int d=INT_MIN;
    for(i=n-1; i>0; i--){
      d = max(d,a[i]-a[i-1]);
    }
    cout << min(k-d,k-(k-a[n-1]+a[0]));
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    int t = 1;
    // cin >> t;
    while(t--) {
      solve();
    }

    return 0;
}




Measured memory_bytes: 4012
program main
	implicit none
    integer n,i
    double precision,allocatable::a(:)
    double precision::s=0
    read *, n
    allocate(a(n))
    read *, (a(i), i=1,n)
    do i=1,n
    	s=s+1/(1.0*a(i))
    end do
    print '(f0.12)',1/s
end program main

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

#define inf 0x3f3f3f3f
#define pb push_back
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <vector <int>> vvi;
typedef pair <int, int> pi;
typedef vector <pair <int, int>> vpi;

int n;
vi v;

void read() {
  cin >> n;
  for(int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    v.pb(x);
  }
}

int abs(int x) {
  if (x > 0)
    return x;
  return -x;
}

void solve() {
  int lastDif = 99999999;

  for(int i = 1; i < n - 1; ++i) {
    int sum1 = 0, sum2 = 0;
    for(int j = 0; j <= i; ++j)
      sum1 += v[j];
    for(int j = i + 1; j < n; ++j)
        sum2 += v[j];
    int nr = abs(sum1 - sum2);
    if (nr < lastDif)
      lastDif = nr;
  }
  cout << lastDif;
}

int main() {
  ios :: sync_with_stdio(false);
  cin.tie(nullptr);
  read();
  solve();
  return 0;
}


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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
#define MOD 1e9 + 7

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

int N, K;
bool card[100010];

int main() {
	while(scanf("%d %d", &N, &K), N || K) {
		memset(card, false, sizeof(card));
		bool unknown = false;
		rep(i, K) {
			int c;
			scanf("%d", &c);
			if(c == 0) {
				unknown = true;
				continue;
			}
			card[c] = true;
		}
		bool flag = false;
		int cnt = 0, now, prev = 0, mini = 0;
		int ans = 0;
		FOR(i, 1, N + 1) {
			if(card[i]) {
				if(i == mini + 2) flag = true;
				++cnt;
			}
			else {
				now = cnt;
				if(unknown && flag) {
					ans = max(ans, prev + now + 1);
				}
				else ans = max(ans, now);
				cnt = 0;
				flag = false;
				prev = now;
				mini = i;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 3292
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<map>
#define For(i,a,b) for(int i=(a);i<(b);i++)
#define Rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;


int main() {
	string s;
	cin >> s;
	vector<string> S(4);
	Rep(i, 4) S[i].push_back(s[i]);
	for (int bit = 0;bit < (1 << 3);bit++) {
		int sum = stoi(S[0]);
		char c[3];
		For(i, 0, 3) {
			if (bit & (1 << i)) sum += stoi(S[i + 1]), c[i] = '+';
			else sum -= stoi(S[i + 1]), c[i] = '-';
		}
		if (sum == 7) {
			cout << s[0];
			Rep(i, 3) cout << c[i] << s[i + 1];
			cout << "=7" << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    vi h(n);
    rep(i,n)cin>>h[i];
    reverse(all(h));
    rep(i,n-1){
        if(h[i]>=h[i+1])continue;
        if(h[i]+1==h[i+1])h[i+1]--;
        else {
            cout<<"No"<<endl;
            return;
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;

class amida{
private:
	int wnum, w[30], n, a[30], b[30];
public:
	amida(int c, int d, int e[], int f[]);
	void set_w();
	void swap_amida();
	void disp();
};

amida::amida(int c, int d, int e[], int f[]){
	wnum = c;
	n = d;
	for(int i = 0; i < n; i++){
		a[i] = e[i];
		b[i] = f[i];
	}
}

void amida::set_w(){
	for(int i = 0; i < wnum; i++){
		w[i] = i;
	}
}

void amida::swap_amida(){
	for(int i = 0; i < n; i++){
		swap(w[(a[i] - 1)], w[(b[i] - 1)]);
	}
}

void amida::disp(){
	for(int i = 0; i < wnum; i++){
		cout <<(w[i] + 1)<<endl;
	}
}

int main(){
	int c, d, e[30], f[30];
	cin >>c;
	cin >>d;
	for(int i = 0; i < d; i++){
		scanf("%d,%d", &e[i], &f[i]);
	}
	
	amida hoge(c, d, e, f);
	hoge.set_w();
	hoge.swap_amida();
	hoge.disp();
	
	return 0;
}

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

using namespace std;

const int NMAX = 200000 + 5;

int N;
int A[NMAX];

int l[NMAX];

int ans;
int cnt[NMAX];

void addNr(int nr, int val) {
    if (val == 1) {
        l[nr] --;
        if (l[nr] > 0) {
            cnt[l[nr]] ++;
            if (cnt[l[nr]] == 1)
                ans --;
        }
    }
    else {
        if (l[nr] > 0) {
            cnt[l[nr]] --;
            if (cnt[l[nr]] == 0)
                ans ++;
        }
        l[nr] ++;
    }
}

int main() {
    int M = 0;
    cin >> N >> M;
    for (int i = 1; i <= N; ++ i)
        l[i] = i + 1;
    ans = N;
    for (int i = 1; i <= N; ++ i) {
        cin >> A[i];
        addNr(A[i], 1);
    }

    while (M --) {
        int X, Y;
        cin >> X >> Y;
        addNr(A[X], -1);
        A[X] = Y;
        addNr(A[X], 1);
        cout << ans << '\n';
    }

    return 0;    
}

Measured memory_bytes: 3840
use std::cmp::max;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("Failed to read bytes") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s: String = read();
    let mut cnt = 0;
    let mut tmp = 0;
    for i in s.chars() {
        if i == 'A' || i == 'C' || i == 'G' || i == 'T' {
            tmp += 1;
        } else {
            cnt = max(tmp, cnt);
            tmp = 0;
        }
    }
    println!("{}", max(cnt, tmp));
}


Measured memory_bytes: 4352
N, K = map(int, input().split())

mod = 10**9 + 7

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k]) % mod

    return result

for i in range(K):
    if i > N-K:
        ans = 0

    else:
        ao = cmb(K-1, i)
        aka = cmb(N-K+1,i+1)
        ans = ao * aka % mod

    print(ans)

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    string N;
    cin >> N;
    if (N.find('7') != string::npos) {
        cout << "Yes" << '\n';
    } else {
        cout << "No" << '\n';
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3652
#include<stdio.h>
#include<iostream>
#define VALUE 2147483647

using namespace std;
int main() {
	int n, q;
	cin >> n >> q;

	int a[100000];
	//初期値の設定
	for (int i = 0; i < n; i++) {
		a[i] = VALUE;
	}

	int com, x, y;
	for (int i = 0; i < q; i++) {
		cin >> com >> x >> y;

		if (com == 0) {
			a[x] = y;
		}
		else {
			int mini = VALUE;
			int j = x;
			while(1){
				
				if (a[j] < mini) {
					mini = a[j];
				}
				if (j == y) break;

				j++;
			}
			cout << mini << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 3484
using System;
using System.Collections.Generic;
using System.Linq;

public class Test
{
	public static void Main()
	{
		int n,m;
		List<int> list = new List<int>();
		
		n = int.Parse(Console.ReadLine());
		string[] b = new string[n];
		for(int i=0;i<n;i++)
		{
			b[i] = Console.ReadLine();
		}
		
		m = int.Parse(Console.ReadLine());
		string[] r = new string[m];
		for(int i=0;i<m;i++)
		{
			r[i] = Console.ReadLine();
		}
		list.Add(0);
		for(int i=0;i<n;i++)
		{
			int a=0, c=0;
			a = Plus(b[i], n, b);
			c = Minus(b[i], m, r);
			list.Add(a+c);
		}
		Console.WriteLine(list.Max());
	}
	public static int Plus(string s, int n, string[] b)
	{
		int a =0;
		for(int i=0;i<n;i++)
		{
			if(s.Length==b[i].Length&&0<=s.IndexOf(b[i]))
			{
				a++;
			}
		}
		return a;
	}
	public static int Minus(string s, int m, string[] r)
	{
		int c = 0;
		for(int i=0;i<m;i++)
		{
			if(s.Length==r[i].Length&&0<=s.IndexOf(r[i]))
			{
				c--;
			}
		}
		return c;
	}
}

Measured memory_bytes: 13524
/* ac */
/* gcc ac.c -o ac */

#include <stdio.h>


int main()
{
	int N;
	int n, k,r;
	int kaisuu,  max_kaisuu, max_n;

	scanf("%d",&N);
//printf("N=%d\n", N);

	max_kaisuu = 0;
	max_n =1;

	for(n=1; n<=N;  n++){
//printf("n=%d\n", n);
		kaisuu=0;
		k =n ;
		r = k%2;
//printf("kaisuu=%d   r=%d\n", kaisuu, r);
		k = n;
		while (r == 0){
			kaisuu= kaisuu +1;
			k = k/2;
			r = k%2;
			
//printf("kaisuu=%d   n=%d   k=%d   r=%d \n"  , kaisuu, n, k, r );
		}

		if(max_kaisuu < kaisuu){
			max_kaisuu = kaisuu;
			max_n = n;
//printf("max_kaisuu=%d   max_n=%d\n"  , max_kaisuu, max_n );
		}
//printf("n=%d \n\n"  , n );
	}



	printf("%d",max_n);

return 0;
}

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

using namespace std;

int main() {
	double w, h, x, y;
	int ver=0;
	
	scanf("%lf %lf %lf %lf", &w, &h, &x, &y);
	
	if (x == w/2 && y == h/2)
		ver=1;
	
	printf("%.6lf %d\n", (w*h)/2, ver);
	
	return 0;
}

Measured memory_bytes: 384
import math
import itertools
import fractions
import heapq
import collections
import bisect
import sys

sys.setrecursionlimit(10**9)
mod = 998244353
inf = 10**20

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

n,m = LI()

if n==m:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 5684
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  vector<vl> a(3, vl(3));
  rep(i, 3) {
    rep(j, 3) {
      cin >> a[i][j];
    }
  }

  ll n;
  cin >> n;
  ll s;
  rep(i, n) {
    cin >> s;
    rep(j, 3) {
      rep(k, 3) {
        if (a[j][k] == s) {
          a[j][k] = -1;
        }
      }
    }
  }

  rep(i, 3) {
    bool f = 1;
    rep(j, 3) {
      if (a[i][j] != -1) {
        f = 0;
      }
    }

    if (f) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  rep(i, 3) {
    bool f = 1;
    rep(j, 3) {
      if (a[j][i] != -1) {
        f = 0;
      }
    }

    if (f) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  if (a[0][0] == -1 and a[0][0] == a[1][1] and a[1][1] == a[2][2]) {
      cout << "Yes" << endl;
      return 0;
  }

  if (a[0][2] == -1 and a[0][2] == a[1][1] and a[1][1] == a[2][0]) {
      cout << "Yes" << endl;
      return 0;
  }

  cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};

ll MOD = 998244353;


int main() {
    ll n, a, b; cin >> n >> a >> b;
    if(a>b){cout << 0 << endl; return 0;}
    if(n==1&&a!=b){cout << 0 << endl; return 0;}
    if(n==1&&a==b){cout << 1 << endl; return 0;}
    
    ll A = a * (n - 2);
    ll B = b * (n - 2);
    cout << B - A + 1 << endl;
}


Measured memory_bytes: 3636
//@author :  |< U $ |-|
#include<cmath>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<algorithm>
#include<list>
#include<cstring>
#define ll long long
#define vi vector<long long>
#define pb push_back
#define pop pop_back
#define pi pair<long long ,long long>
#define vp vector<pair<long long,long long> >
#define mkp make_pair
#define in(i,n) for(i=0;i<n;i++)
#define fon(i,n,m) for(i=n;i<m;i++)
#define rfon(i,n,m) for(i=n;i>=m;i--)
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);
#define map map<long long,long long>
#define inm1(b)  memset(b,-1,sizeof(b))
#define in0(b) memset(b,0,sizeof(b))
#define ininf(b) memset(b,1000000001,sizeof(b))
#define MOD         1000000007
#define I 10000000001
#define TakeInput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout); 
using namespace std;
int gcd(int a, int b) {  if (a == 0)  return b; return gcd(b % a, a); }  
int main()
{
    jaldi
    #ifndef _DEBUG 
    //TakeInput
    #endif
    ll n,i,j,k;
    cin>>n;
    ll a[n][3];
    ll dp[n][3];
    //in0(dp);
    in(i,n){
        in(j,3){
            cin>>a[i][j];
        }
    }
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];
    fon(i,1,n){
        in(j,3){
            if(j==0){
                dp[i][j]=max(dp[i-1][1],dp[i-1][2])+a[i][j];
            }
            if(j==1){
                dp[i][j]=max(dp[i-1][0],dp[i-1][2])+a[i][j];
            }
            if(j==2){
                dp[i][j]=max(dp[i-1][1],dp[i-1][0])+a[i][j];
            }
            //cout<<dp[i][j]<<" ";
        }
        //cout<<endl;
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
    
}
 
 








 

Measured memory_bytes: 4992
#include<iostream>
#include<bits/stdc++.h>
#include<climits>

#define forn(x,n,s) for(int i = x; i < n; i += s )
#define forr(x,n,s) for(int i = x; i>=n; i -= s)

using namespace std;

void go(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  #ifndef ONLINE_JUDGE
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
  #endif
}

int main(){
    go();

    // code here
    double d,t,s;cin>>d>>t>>s;
    if((d/s)> t) cout<<"No";
    else cout<<"Yes";

}






Measured memory_bytes: 3736
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<iostream>
using namespace std;

int main()
{
	long long int N, M,A,B, i,D, j, k, l, m, n,  cnt, flag;
	cin >> N>>A>>B;
	vector<long long int>X(N);
	for (i = 0; i <= N-1; i++) {
		cin >> X[i];
	}
	long long int sum = 0;
	flag = 0;
	cnt = 0;
	for (i = 0; i < N - 1; i++) {
		if ((X[i + 1] - X[i])*A <= B) {
			sum += (X[i + 1] - X[i])*A;
		}
		else
			sum += B;
	}
	cout << sum << endl;
	return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define erep(i,a,b) for(int i=a;i<=(int)(b);i++)
#define per(i,a,b) for(int i=(b)-1;i>(a);i--)
#define eper(i,a,b) for(int i=((int)(a));i>=b;i--)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
using namespace std;
typedef long long ll;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n;
ll k, a[100005], m, g;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n >> k;
    rep(i, 0, n) {
        cin >> a[i];
        m = max(m, a[i]);
        g = gcd(g, a[i]);
    }
    if (m < k || k % g != 0) cout << "IMPOSSIBLE" << endl;
    else cout << "POSSIBLE" << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

#define MAX 100000

int list[MAX] = {0};

void init(){
    int i;
    for(i=0;i<MAX;i++){
        list[i]=i;
    }
}

int find(int n){
    if(n==list[n]) return n;
    return list[n]=find(list[n]);
}

int unit_friend(int a,int b){
    if(find(a)==find(b)) return 1;
    else return 0;
}

void unit(int a,int b){
    a=find(a);
    b=find(b);
    
    if(a==b)return;
    
    list[b]=a;
}

int main(void){
    int user_num,friend,i,s,t,q;
    init();
    scanf("%d%d",&user_num,&friend);
    for(i=0;i<friend;i++){
        scanf("%d%d",&s,&t);
        unit(s,t);
    }
    scanf("%d",&q);
    for(i=0;i<q;i++){
        scanf("%d%d",&s,&t);
        if(unit_friend(s,t)==1) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}

Measured memory_bytes: 972
N = int(input())
seed = "a"
alpha = "abcdefghij"


def dfs(string, mx_ind):
    if len(string) == N:
        print(string)
    else:
        for i in range(mx_ind + 1):
            dfs(string + alpha[i], mx_ind + 1 if i == mx_ind else mx_ind)


dfs("", 0)


Measured memory_bytes: 4404
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>

using namespace std;

int main()
{
	int a, b,ans;
	cin >> a >> b;
	if (a <= b) ans = a;
	else ans = a - 1;
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define vi vector<int>
#define ll long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define ii pair<int,int>
#define qu queue <int>
#define qmax priority_queue <int>
#define qmin priority_queue <int, vector<int>,greater<int>>

using namespace std;

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

    if(n%2 != 0)
        cout<<n*2<<endl;
    else
        cout<<n<<endl;

    return 0;
}

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

int f(int n){
    if(n<=0)return 0;
    int deno = 0;
    for(int nbuf = n; nbuf > 0; nbuf >>= 1){
        if(nbuf & 1)deno++;
    }
    return f(n%deno)+1;
}

int main(void){
    int N;
    string strX;
    cin >> N;
    cin >> strX;
    vector<int> res(N, 1);
    vector<int> curNum(N, 0);
    int defPop = 0;
    for(char C: strX){
        if(C == '1')defPop++;
    }
    vector<int> Power2ModPlus;
    vector<int> Power2ModMinus;
    int Power2ModPlusBuf = 1;
    int Power2ModMinusBuf = 1;
    for(int i=0; i<N; i++){
        Power2ModPlus.push_back(Power2ModPlusBuf);
        Power2ModPlusBuf = Power2ModPlusBuf * 2 % (defPop + 1);
        if(defPop > 1){
            Power2ModMinus.push_back(Power2ModMinusBuf);
            Power2ModMinusBuf = Power2ModMinusBuf * 2 % (defPop - 1);
        }
    }
    int fPlusBuf = 0;
    int fMinusBuf = 0;
    for(int i=0; i<N; i++){
        if(strX[N-i-1] == '1'){
            fPlusBuf += Power2ModPlus[i];
            fPlusBuf %= (defPop + 1);
            if(defPop > 1){
                fMinusBuf += Power2ModMinus[i];
                fMinusBuf %= (defPop - 1);
            }
        }
    }
    for(int i=0; i<N; i++){
        if(strX[N-i-1] == '1'){
            if(defPop > 1){
                curNum[i] = fMinusBuf + (defPop - 1) - Power2ModMinus[i];
                curNum[i] %= (defPop - 1);
            }else curNum[i] = -1;
        }else{
            curNum[i] = fPlusBuf + Power2ModPlus[i];
            curNum[i] %= (defPop + 1);
        }
    }
    for(int i=0; i<N; i++){
        if(curNum[i] >= 0){
            res[i] += f(curNum[i]);
        }else res[i] = 0;
    }
    for(int i=N-1; i>=0; i--){
        cout << res[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 6940
from sys import stdin
from heapq import heappush, heappop
solution = [i for i in range(1, 16)] + [0]
sol_idx = (15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14)
MAX_DEPTH = 45
count = 0
neighbor = (
    (1, 4),
    (0, 2, 5),
    (1, 6, 3),
    (2, 7),
    (0, 5, 8),
    (1, 4, 6, 9),
    (2, 5, 7, 10),
    (3, 6, 11),
    (4, 9, 12),
    (5, 8, 10, 13),
    (6, 9, 11, 14),
    (7, 10, 15),
    (8, 13),
    (9, 12, 14),
    (10, 13, 15),
    (11, 14)
)
distance = (
    (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
    (0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6),
    (1, 0, 1, 2, 2, 1, 2, 3, 3, 2, 3, 4, 4, 3, 4, 5),
    (2, 1, 0, 1, 3, 2, 1, 2, 4, 3, 2, 3, 5, 4, 3, 4),
    (3, 2, 1, 0, 4, 3, 2, 1, 5, 4, 3, 2, 6, 5, 4, 3),
    (1, 2, 3, 4, 0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5),
    (2, 1, 2, 3, 1, 0, 1, 2, 2, 1, 2, 3, 3, 2, 3, 4),
    (3, 2, 1, 2, 2, 1, 0, 1, 3, 2, 1, 2, 4, 3, 2, 3),
    (4, 3, 2, 1, 3, 2, 1, 0, 4, 3, 2, 1, 5, 4, 3, 2),
    (2, 3, 4, 5, 1, 2, 3, 4, 0, 1, 2, 3, 1, 2, 3, 4),
    (3, 2, 3, 4, 2, 1, 2, 3, 1, 0, 1, 2, 2, 1, 2, 3),
    (4, 3, 2, 3, 3, 2, 1, 2, 2, 1, 0, 1, 3, 2, 1, 2),
    (5, 4, 3, 2, 4, 3, 2, 1, 3, 2, 1, 0, 4, 3, 2, 1),
    (3, 4, 5, 6, 2, 3, 4, 5, 1, 2, 3, 4, 0, 1, 2, 3),
    (4, 3, 4, 5, 3, 2, 3, 4, 2, 1, 2, 3, 1, 0, 1, 2),
    (5, 4, 3, 4, 4, 3, 2, 3, 3, 2, 1, 2, 2, 1, 0, 1),
    (6, 5, 4, 3, 5, 4, 3, 2, 4, 3, 2, 1, 3, 2, 1, 0)
)
def get_diff(B):
    return sum(distance[v][i] for i, v in enumerate(B))
def get_next_board(board, space, prev):
    for nxt in neighbor[space]:
        if nxt == prev: continue
        b = board[:]
        b[space], b[nxt] = b[nxt], 0
        yield b, nxt
def answer_is_odd(board):
    return sum(divmod(board.index(0), 4)) % 2
def search(board):
    lower = get_diff(board)
    start_depth = lower
    if (lower % 2) ^ answer_is_odd(board): start_depth += 1
    for limit in range(start_depth, MAX_DEPTH + 1, 2):
        get_next(board, limit, 0, board.index(0), None, lower)
        if count > 0: return limit
def get_next(board, limit, move, space, prev, lower):
    if move == limit:
        if board == solution:
            global count
            count += 1
    else:
        for b, nxt in get_next_board(board, space, prev):
            p = board[nxt]
            new_lower = lower - distance[p][nxt] + distance[p][space]
            if new_lower + move <= limit:
                get_next(b, limit, move + 1, nxt, space, new_lower)
print(search([int(a) for _ in range(4) for a in stdin.readline().split()]))

Measured memory_bytes: 7968
N = int(input())
A = [[] for _ in range(N)]
for i in range(N):
    for _ in range(int(input())):
        A[i].append([int(s) for s in input().split()])

ret = 0
for i in range(2 ** N):#2**Nだけ正解の候補がある
    bits = [i >> j & 1 for j in range(N)]#　N桁の２進数iについて、逆順に並べた配列が生成
    #print(bits)
    for i, a in enumerate(A):#i→人、a→人iの証言のリスト
        if bits[i] == 0:#人iが正直者じゃない場合、continueして次の人の証言に移行
            continue
        for x, y in a:
            # print(bits, bits[x - 1], y)
            if bits[x - 1] == y:#正解の候補と証言が一致する場合、その人の次の証言を参照
                continue
            break#そうでない場合、その人の証言を聞くのをやめて次の人の証言を聞く
        else:#breakでループを抜けなかったときにのみ、elseが実行
            continue#このcontinueは２つ上のfor文のcontinueつまり、間違った証言がある場合、一つ下のbreakが評価されて、次の正解候補にうつる
        break
    else:#breakでループを抜けなかったときにのみ、elseが実行
        ret = max(ret, sum(bits))
print(ret)

Measured memory_bytes: 3064
function main(input) {
  const args = input.split('\n');
  const [A, B, C, K] = args[0].split(' ').map(n => parseInt(n, 10));

  console.log(
    K <= A + B
      ? Math.min(K, A)
      : A - (K - (A + B))
  );
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 29812