akhauriyash/Code-Regression huggingface dataset:
// C.

#include <iostream>
#include <sstream>

using namespace std;

int main(int argc, char *argv[])
{
	int c[3][3];
	for (int i = 0; i < 3; ++i) {
		for (int j = 0; j < 3; ++j) {
			cin >> c[i][j];
		}
	}
	bool ans = true;
	for (int i = 1; i < 3; ++i) {
		for (int j = 1; j < 3; ++j) {
			if ((c[i][0] - c[i-1][0]) != (c[i][j] - c[i-1][j])) {
				ans = false;
			}
			if ((c[0][j] - c[0][j-1]) != (c[i][j] - c[i][j-1])) {
				ans = false;
			}
		}
	}
	cout << (ans ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
import fractions
a,b,c,d=map(int,input().split())

lcm=(c*d)//fractions.gcd(c,d)
def q(n):
    sc=n//c
    sd=n//d
    s=n//lcm
    w=sc+sd-s
    return n-w

print(q(b)-q(a-1))

Measured memory_bytes: 63980
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;

int n, m;
vector<int> eds[220000];
int was[220000];

void dfs1(int v) {
	was[v] = 1;
	for (int u: eds[v])
		if (!was[u])
			dfs1(u);
}

int main() {
	cin >> n >> m;
	for (int i = 0; i < n; ++i) {
		int k;
		cin >> k;
		for (int j = 0; j < k; ++j) {
			int x;
			cin >> x;
			--x;
			eds[i].push_back(x + n);
			eds[x + n].push_back(i);
		}
	}
	dfs1(0);
	for (int i = 0; i < n; ++i)
		if (!was[i]) {
			cout << "NO\n";
			return 0;
		}
	cout << "YES\n";
	return 0;
}




Measured memory_bytes: 9472
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 7;
#define debug(a) cout<<#a<<": "<<a<<'\n'
struct E{
	int to,nx,val;
}e[maxn];
int head[maxn],tot;
ll dfn[maxn],num[maxn],fa[maxn],cnt,size[maxn],vis[maxn],pre[maxn],ans[maxn];
void dfs(int x){
	//cout << x << endl;
	vis[x]= 1;
	for(int i = head[x];i;i = e[i].nx){
		int y = e[i].to;
		if(vis[y])continue;
		ans[y]+=ans[x];
		dfs(y);
	}
}

void add(int x,int y){
	e[++tot].to = y;
	e[tot].nx = head[x];
	head[x] = tot;
}
int main() {
	ios::sync_with_stdio(false);
	int l,r,n,q,x,y,s,t;
	scanf("%d%d",&n,&q);
	for(int i = 1;i <= n;++i)size[i] = 1;
	for(int i = 1;i < n;++i){
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
	}
	
	for(int i = 1;i <= q;++i){
		scanf("%d%d",&s,&t);
		ans[s]+=t;
	}
	dfs(1);
	for(int i = 1;i<=n;++i)printf("%lld ",ans[i]);
	return 0;
}


Measured memory_bytes: 28672
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String S = scan.next();
        String K = scan.next();
        BigInteger remain = new BigInteger(K);
        char[] data = S.toCharArray();
        if (data.length == 1) {
            System.out.println(data[0]);
            return;
        }
        for (int i = 0; i < data.length; i++) {
            if (data[i] == '1') {
                if (remain.compareTo(BigInteger.ONE) == 0) {
                    System.out.println(data[i]);
                    return;
                }
                remain = remain.subtract(BigInteger.ONE);
            } else {
                System.out.println(data[i]);
                return;
            }
        }
    }
}


Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define sd(a) scanf("%d", &a)
#define sd2(a,b) scanf("%d%d", &a, &b)
#define sd3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define sld(a) scanf("%lld", &a)
#define sld2(a,b) scanf("%lld%lld", &a, &b)
#define sld3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define pd(a) printf("%d", a)
#define pld(a) printf("%lld", a)
#define sp printf(" ")
#define nl printf("\n")
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define clr(a, val) memset((a), (val), sizeof(a))
#define pb push_back
#define endl "\n"
#define mp(a, b) make_pair(a, b)
#define pii pair<int, int>
#define xx first
#define yy second
#define mx 100001
double f[mx];
double t[mx],v[mx];
double tim[mx];
void solve(int n)
{
	double ans=0;
	f[0]=0;
	v[n]=0;
	//cout<<f[0]<<" ";
	for(int i=1;i<=n;i++)
	{
		f[i]=min(v[i],f[i-1]+t[i-1]);
		f[i]=min(f[i],v[i-1]);
		for(int j=i+1;j<=n;j++)
			f[i]=min(f[i],v[j]+tim[j]-tim[i]);
		//cout<<f[i]<<" ";
	}
	//cout<<endl;
	for(int i=1;i<=n;i++)
	{
		if((f[i]+f[i-1]+t[i-1])*0.5<v[i-1])
		{
			double y=(f[i]+f[i-1]+t[i-1])*0.5;
			double x=(f[i]+t[i-1]-f[i-1])*0.5;
			ans+=(f[i-1]*x+f[i]*(t[i-1]-x)+0.5*x*x+0.5*(t[i-1]-x)*(t[i-1]-x));
		}
		else
		{
			double x=v[i-1]-f[i-1];
			double y=v[i-1]-f[i];
			ans+=(f[i-1]*x+f[i]*y+0.5*x*x+0.5*y*y+v[i-1]*(t[i-1]-x-y));
		}
	}
	cout<<fixed<<setprecision(6)<<ans<<endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	int n;cin>>(n);
	tim[0]=0;
	for(int i=0;i<n;i++)
	{
		cin>>(t[i]);
		tim[i+1]=tim[i]+t[i];
	}
	for(int i=0;i<n;i++)
		cin>>(v[i]);
	solve(n);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N, M;
  cin >> N >> M;
  vector<int> a(M);
  vector<int> b(M);
  
  for (int i = 0; i < M; i++) {
    cin >> a.at(i) >> b.at(i);
  }
  
  vector<int> c(N);
  
  for(int j = 0; j < M; j++) {
    
     c.at(a.at(j) - 1)++;
     c.at(b.at(j) - 1)++;
  }    
    
  for (int k = 0; k < N; k++) {
    cout << c.at(k) << endl;
  }
}
    


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

const int SIZE=30;
int main(){
    int n;
    cin>>n;
    vector<vector<int>> mov(n+1,vector<int>(SIZE,0));
    vector<ll> x(n);
    map<ll,int> pos;
    for(int i=0;i<n;i++){
        cin>>x[i];
        pos[x[i]]=i;
    }
    pos[1e10l]=n;
    ll l;
    cin>>l;
    for(int i=0;i<n+1;i++) mov[i][0]=i;
    for(int i=0;i<n+1;i++){
        if(i!=n) mov[i][1]=(pos.upper_bound(x[i]+l)->second)-1;
        else mov[i][1]=n;
    }
    for(int i=1;i+1<SIZE;i++){
        for(int j=0;j<n+1;j++){
            if(j!=n) mov[j][i+1]=mov[mov[j][i]][i];
            else mov[j][i+1]=n;
        }
    }
    int q;
    cin>>q;
    for(int loop=0;loop<q;loop++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        if(a>b) swap(a,b);
        int res=0;
        while(true){
            int lb=0;
            int ub=SIZE;
            while(ub-lb>1){
                int mid=(lb+ub)/2;
                int to=mov[a][mid];
                if(b<=to) ub=mid;
                else lb=mid;
            }
            if(lb==0){
                res++;
                break;
            }
            res+=(1<<(lb-1));
            a=mov[a][lb];
        }
        cout<<res<<endl;
    }
    return 0;
}

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

int main() {
  int d,n;cin>>d>>n;
  int ans=1;
  rep(i,d)ans*=100;
  if(n==100)n++;
  ans*=n;
  cout<<ans<<endl;
}

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct UnionFind{
  ll N;
  llvec p;
  llvec cnt;
  UnionFind(ll n){
    N = n;
    p=llvec(N);
    cnt=llvec(N, 0);
    rep(i, N){
      p[i] = i;
      cnt[i] = 1;
    }
  }

  void con(ll a, ll b){
    P at = root(a);
    P bt = root(b);
    if(at.second!=bt.second){
      if(at.first>bt.first){
        swap(at, bt);
        swap(a, b);
      }
      p[at.second] = bt.second;
      cnt[bt.second]+=cnt[at.second];
      p[a]=bt.second;
    }
  }

  P root(ll a){
    ll atmp = a;
    ll c=0;
    while(atmp!=p[atmp]){
      atmp = p[atmp];
      c++;
    }
    p[a] = atmp;
    return {c, atmp};
  }

  bool is_con(ll a, ll b){
    P at=root(a);
    P bt=root(b);
    return at.second == bt.second;
  }
  
};

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }  
};


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll K;
  string S;
  cin >> K >> S;
  if(S.size()>K){
    cout << S.substr(0, K)+"...";
  }else{
    cout << S;
  }
  
  return 0;
}


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

#endif


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

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

    string ans = "Yes";
    for(int i=N-1; i>0; i--) {
        if (H[i-1] -1 == H[i]) {
            H[i - 1]--;
        } else if (H[i-1] - 1 > H[i]) {
            ans = "No";
            break;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
typedef struct{
	int h,w,d;
}rect;
bool cmp(rect a,rect b){
	if(a.d==b.d)
		return a.h<b.h;
	return a.d<b.d;
}
int main(){
	vector<rect> v;
	REP(i,1,150){
		REP(j,i+1,150){
			rect t;
			t.h=i;
			t.w=j;
			t.d=i*i+j*j;
			v.push_back(t);
		}
	}
	sort(v.begin(),v.end(),cmp);
	while(1){
		int h,w;
		cin>>h>>w;
		if(!h)break;
		rep(i,v.size()){
			if(h==v[i].h&&w==v[i].w){
				cout<<v[i+1].h<<" "<<v[i+1].w<<endl;
				break;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3260
#include <bits/stdc++.h>
#define For(i, begin, end) for(int i=begin;i<end;i++)
#define Rep(i, n) For(i,0,n)
#define Sort(v) sort(v.begin(),v.end())
using namespace std;

int main(){
  string S;cin>>S;
  Rep(i,(S.size()+1)/2)cout<<S[2*i];
  
  return 0;
}

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

int main()
{
    int N;
    int K;
    int X;
    int Y;
    cin >> N;
    cin >> K;
    cin >> X;
    cin >> Y;

    int sum = 0;
    
    for (size_t i = 1; i <= N; i++)
    {
        if(i <= K) sum += X;
        else sum += Y;   
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
H, W = 82, 49
half_h = H // 2

WH = 0
BK = 1

nw, nb = map(int, input().split())
nw -= 1
nb -= 1

ret = []
for _ in range(half_h):
    ret.append([WH] * W)
for _ in range(half_h):
    ret.append([BK] * W)


def put(color, cnt, r1, r2):
    if cnt == 0:  # 追加
        return
    for r in range(r1 + 1, r2 - 1, 2):
        for c in range(0, W, 2):
            ret[r][c] = color
            cnt -= 1
            if cnt == 0:
                return


put(BK, nb, 0, half_h)
put(WH, nw, half_h, H)

print(H, W)  # 追加
for row in ret:
    print(*('#' if c == BK else '.' for c in row), sep='')


Measured memory_bytes: 3700
# 169 B

n = int(input())
l = list(map(int, input().split()))

def code(a):
    pro = 1
    if 0 in a:
        print(0)
    else:
        for i in a:
            pro *= i
            if pro > (10 ** 18):
                print(-1)
                return
        print(pro)

code(l)

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

int		main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int N, n;
	cin >> N;
	n = N;
	int x = 0;
	while (n)
	{
		x += n % 10;
		n /= 10;
	}
	if (N % x)
		cout << "No\n";
	else
		cout << "Yes\n";
}


Measured memory_bytes: 256
/*  
    |\_/|
    |* *|
    \_+_/
*/
#include<bits/stdc++.h>

#define endl '\n'

using namespace std;

int main(){

  cin.tie(0);     // cout と cin の同期を切る
  ios::sync_with_stdio(false);  /* cの stdioストリーム (printfとか)と*/


  int a[3];

  for(int i=0;i<3;i++){
    cin>>a[i];
  }

  sort(a,a+3);

  int cnt=0;
  
  for(int i=0;i<2;i++){
    if(a[i]!=a[i+1]){
      cnt++;
    }
  }

  cout<<cnt+1<<endl;
     
  return 0;

}


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

int main() {
	string s;
	cin >> s;
	double paa = 0;
	for (char c : s) if (c == 'p') paa++;
	int ans = floor(((double)s.length() - 2 * paa) / 2);
	cout << ans << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int x,n,a[101],mi=0x3f3f3f3f,pos;
bool find(int x)
{
	for(int i=1;i<=n;i++)
	{
		if(x==a[i])return false;
	}
	return true;
}
int main()
{
	cin>>x>>n;
	int f=1;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(a[i]==x)f=0;
	}
	if(f)cout<<x,exit(0);
	for(int i=0;i>=0;i++)
	{
		if(find(i))
		{
			if(abs(x-i)<mi)
			{
				mi=abs(x-i);
				pos=i;
			}
			else break;
		}
	}
	cout<<pos;
}


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

int p[3];
int s[2];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	for(int i = 0; i < 3; ++i){
		cin >> p[i];
	}
	
	for(int i = 0; i < 2; ++i){
		cin >> s[i];
	}
	
	int ans = 5000;
	for(int i = 0; i < 3; ++i){
		for(int j = 0; j < 2; ++j){
			ans = min (ans, p[i] + s[j] - 50);
		}
	}
	
	cout << ans << endl;
		
	return 0;
}

Measured memory_bytes: 1192
def main():
    from itertools import islice

    N = int(input())

    trains = []
    for _ in range(N - 1):
        c, s, f = map(int, input().split())
        trains.append((c, s, f))

    ans = []
    for i in range(N - 1):
        curr = 0
        for c, s, f in islice(trains, i, N - 1, 1):
            if curr < s: curr = s
            r = curr % f
            if r != 0: curr += f - r
            curr += c
        ans.append(curr)
    ans.append(0)

    print(*ans, sep='\n')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>

#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;

int N;
int A[100010];

signed main()
{
	cin >> N;
	REP(i, N) cin >> A[i + 1];
	A[0] = 0;
	A[N + 1] = 0;

	int all = 0;
	for (int i = 0; i <= N; i++)
	{
		all += abs(A[i + 1] - A[i]);
	}

	for (int i = 1; i <= N; i++)
	{
		int s = all;

		int a = abs(A[i - 1] - A[i]) + abs(A[i] - A[i + 1]);
		s -= a;

		int b = abs(A[i - 1] - A[i + 1]);
		s += b;

		cout << s << endl;
	}
}







Measured memory_bytes: 2048
#include<stdio.h>


int main( void ) 
{
	int a,b,d,r;
	double f;
	
	scanf( "%d%d", &a, &b );
	
	d=a/b;
	r=a%b;
	f=(double)a/b;
	
	printf( "%d %d %lf\n", d, r, f );


	return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using P = pair<int,int>;
using pq = priority_queue<int>;
typedef long long ll;
string yes = "Yes\n";
string no = "No\n";

int  main()
{
	string s; cin >> s;
	cout << (s[0] -48) + (s[1] - 48) + (s[2] -48) << endl;
	return (0);
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }

int main(){
  int N,M; cin>>N>>M;
  int a[N]; FILL(a,N,-1);
  
  bool ok = true;
  REP(count,M){
    int s,c; cin>>s>>c;
    --s;
    if(a[s]==-1){ a[s] = c; }
    else if(a[s] != c){ ok= false;}
  }
  if(ok){ ok = (N==1 || a[0]!=0); }
  if(ok){
    REP(i,N){
      if(a[i]==-1){
        if(i==0 && N>1){ a[i] = 1; }
        else{ a[i] = 0; }
      }
    }
    REP(i,N){
      printf("%d",a[i]);
    }
    printf("\n");
  }else{
    printf("-1\n");
  }
}



Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var s, t string
	fmt.Scan(&s, &t)

	fmt.Println(solve(s, t))
}

func solve(s, t string) string {
	src := make([]int, 26)
	dst := make([]int, 26)
	for i := 0; i < 26; i++ {
		src[i] = -1
		dst[i] = -1
	}

	for i := 0; i < len(s); i++ {
		si := int(s[i] - 'a')
		ti := int(t[i] - 'a')

		if src[si] != -1 || dst[ti] != -1 {
			if src[si] != ti || dst[ti] != si {
				return "No"
			}
		}
		src[si] = ti
		dst[ti] = si
	}
	return "Yes"
}

Measured memory_bytes: 2176
import math
while True:
  n=int(input())
  if n==0:
    break
  s=list(map(int,input().split()))
  m=sum(s)/len(s)
  bunsan2=0
  for i in range(n):
    bunsan2+=(s[i]-m)**2
  bunsan=bunsan2/n
  hensa=math.sqrt(bunsan)
  print(f"{hensa:.8f}")


Measured memory_bytes: 5712
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int aa[n];
    for(int i=0;i<n;i++)
    {
        cin>>aa[i];
    }
    sort(aa,aa+n);
    int sum=0;
    for(int i=0;i<n-2;i++)
    {
        for(int j=i+1;j<n-1;j++)
        {
            for(int k=j+1;k<n;k++)
            {
                if((aa[i]+aa[j])>aa[k])
                    sum++;
                else
                    break;
            }
        }
    }
    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
#define REP(i,to) for(i=0;i<(to);i++)

const int limit = 50;

int N, M;

int a[limit], b[limit];
bool graph[limit][limit];
bool visited[limit];

void dfs(int v) {
	int i;
	visited[v] = true;
	REP(i, N) {
		if (visited[i]) continue;
		if (graph[v][i] == false) continue;
		dfs(i);
	}
}

bool isConnected() {
	int i;
	REP(i, N)
		if (visited[i] == false) return false;
	return true;
}

int main() {
	int i, j, k, l;
	int ans = 0;
	 cin >> N >> M;
	
	REP(i, M) {
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
		graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
	}

	REP(i, M) {
		graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;
		REP(j, N)
			visited[j] = false;
		dfs(0);
		if (isConnected() == false) ans++;
		graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
def main():
    pocket = int(input())

    if(pocket<5):
        num_500 = 0
        num_005 = 0
    elif(pocket<500):
        num_500 = 0
        num_005 = int(pocket/5)
    else:
        num_500 = int(pocket/500)
        num_005 = int((pocket-(500*num_500))/5)

    val = 1000*num_500 + 5*num_005

    print(val)

main()


Measured memory_bytes: 3060
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int t0 = sc.nextInt();
		int mincost = 1001;
		
		for(int i = 0; i < n; i++) {
			int c = sc.nextInt();
			int t = sc.nextInt();
			
			if(t <= t0) {
				mincost = Math.min(mincost, c);
			}
		}
		
		if(mincost == 1001) {
			System.out.println("TLE");
		}else {
			System.out.println(mincost);
		}
	}
}

Measured memory_bytes: 22740
#include<stdio.h>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <math.h>

/*
	入力例：
	3
	1 1 3
*/

int main(){
	long N=0;
	long p,e,z;
	scanf("%ld", &N);
	long cnt=0;

	for(long i=0;i<1000;i++){
		if(1000*i>=N){
			printf("%d\n",1000*i-N);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

//解説参考.
int main(){
	llong a;
	double b;
	cin>>a>>b;
	
	llong bb=100*b+0.5;
	
	cout<<a*bb/100<<endl;
}

Measured memory_bytes: 3728
#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define fi first
#define se second
//#define pb push_back
#define mkp make_pair
//#define pa pair<int,int>
const int N=1e6+10; 
const int mod=998244353;
using namespace std;

//int dir[4][2]={0,1,1,0,0,-1,-1,0};
char a[N],b[N];
int pa[N][4],pb[N][4];
int main()
{
    int h,w,n; cin>>h>>w>>n;
    int sr,sc; cin>>sr>>sc;
    scanf("%s%s",a+1,b+1);
    bool ok=1;
    int pos=sc;
    for(int i=1;i<=n;++i) 
    {
        if(a[i]=='L') pos--;
        if(pos<1) ok=0;
        if(b[i]=='R') pos++;
        pos=min(pos,w);
    } 
    pos=sc;
    for(int i=1;i<=n;++i) 
    {
        if(a[i]=='R') pos++;
        if(pos>w) ok=0;
        if(b[i]=='L') pos--;
        pos=max(pos,1);
    }
    pos=sr;
    for(int i=1;i<=n;++i) 
    {
        if(a[i]=='U') pos--;
        if(pos<1) ok=0;
        if(b[i]=='D') pos++;
        pos=min(pos,h);
    }
    pos=sr;
    for(int i=1;i<=n;++i) 
    {
        if(a[i]=='D') pos++;
        if(pos>h) ok=0;
        if(b[i]=='U') pos--;
        pos=max(pos,1);
    }
    
    if(ok) puts("YES"); else puts("NO");
return 0;
}
/*
*/

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

typedef long long ll;
typedef pair<ll, ll> P;

int N;

int main(void){
    cin >> N;
    
    vector<int> num(N);
    for(int i=0;i<N;i++)    num[i] = i+1;
    
    map<int, int> m;
    for(int i=0;i<N-1;i++){
        if(num[i] == 1) continue;
        
        for(int j=i+1;j<N;j++){
            if(num[j] % num[i] == 0){
                num[j] /= num[i];
                m[num[i]]++;
            }
        }
        m[num[i]]++;
        num[i] = 1;
    }
    
    map<int, int> a;
    for(auto i : m){
        if(2 <= i.second)   a[2]++;
        if(4 <= i.second)   a[4]++;
        if(14 <= i.second)  a[14]++;
        if(24 <= i.second)  a[24]++;
        if(74 <= i.second)  a[74]++;
    }
    
    ll ans = a[74] + a[24] * max(0, a[2] - 1) + a[14] * max(0, a[4] - 1) + a[4] * (a[4]-1) / 2 * max(0, a[2] - 2);
    
    cout << ans << endl;
}

Measured memory_bytes: 256
import numpy as np
import sys
import math

#n = map(int,input().split())

data = [2246640
,2332104
,2379085
,2434833
,2490534
,2554600
,2609625
,2693919
,2742052
,2813988
,2875245
,2952085
,3003306
,3096024
,3157249
,3224511
,3306240
,3388576
,3444609
,3533637
,3591322
,3693924
,3767085
,3842623
,3912324
,4027884
,4102093
,4181949
,4270422
,4361548
,4427853
,4548003
,4616104
,4718640
,4812789
,4918561
,5003286
,5131848
,5205481
,5299011
,5392008
,5521384
,5610705
,5739009
,5818390
,5930196
,6052893
,6156139
,6239472
,6402720
,6493681
,6623853
,6741078
,6864016
,6953457
,7094451
,7215016
,7359936
,7475145
,7593865
,7689630
,7886244
,7984165
,8130747
,8253888
,8403448
,8523897
,8684853
,8802826
,8949612
,9105537
,9267595
,9376656
,9574704
,9686065
,9827097
,9997134
,10174780
,10290813
,10493367
,10611772
,10813692]


k = int(input())

if k >= 119:
    print(data[k-119])
    sys.exit()


def gcd(a,b):
    if a > b:
        a , b = b , a

    # q = b / a
    r = b % a

    if r == 0:
        return a
    else:
        return gcd(a,r)
    

sum = 0



for i in range(k):
    for j in range(k):
        for l in range(k):
            sum += gcd(i+1,gcd(j+1,l+1))


print(sum)

Measured memory_bytes: 27148
# coding: utf-8

def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = -1
    tmp = 1
    flg = False

    for a in A:
        if a == tmp:
            tmp += 1
            flg = True

    if flg:
        ans = N - tmp + 1

    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 32300
///not today

#include<bits/stdc++.h>
using namespace std;

#define SZ(x) (int)(x).size()
#define pb push_back
#define ll long long
#define xmax(x, y) (x) = max((x), (y))
#define xmin(x, y) (x) = min((x), (y))
#define F first
#define S second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define int long long
#define pipii pair< int, pair<int, int> >
#define plpll pair< ll, pair<ll, ll> >

using namespace std;

const int maxn = 1000* 100 + 5;
pll a[maxn];

int32_t main(){
      int n;
      cin >>n;
      for(int i = 0; i < n; i ++){
            cin >>a[i].F;
            a[i].S = i + 1;
      }
      sort(a, a + n);
      for(int i = 0; i < n; i ++)
            cout <<a[i].S <<' ';
      return false;
}


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

int main()
{
  int cnt = 0;
  string S;
  cin >> S;
  if (S[0] == '1')
    cnt++;
  if (S[1] == '1')
    cnt++;
  if (S[2] == '1')
    cnt++;
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int find(int n,vector<int>&root){
    if(root[n]==n)return n;
    else return find(root[n],root);
}
int main(){
    long long n,m;
    cin>>n>>m;
    int A[m],B[m];
    for(int i=0;i<m;i++)cin>>A[i]>>B[i];
    long long x=n*(n-1)/2;
    vector<int>root(n);
    vector<int>rank(n,0);
    vector<long long>size(n,1);
    vector<long long>ans(m);
    for(int i=0;i<n;i++)root[i]=i;
    for(int i=m-1;i>=0;i--){
        ans[i]=x;
        int a=find(A[i]-1,root);
        int b=find(B[i]-1,root);
        if(a==b)continue;
        x-=size[a]*size[b];
        if(rank[a]<rank[b]){
            root[a]=b;
            size[b]+=size[a];
        }
        else{
            root[b]=a;
            size[a]+=size[b];
            if(rank[a]==rank[b])rank[a]++;
        }
    }
    for(int i=0;i<m;i++)cout<<ans[i]<<endl;
    return 0;
}

Measured memory_bytes: 4480
#include<iostream>
#include<map>
#include<algorithm>
#include <iomanip>
#include <cmath>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <vector>
#include <bitset>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>

#define INF 1050000000
#define MOD 1000000007

using namespace std;


int main() {
	int n, a, b; cin >> n >> a >> b;
	string s; cin >> s;

	int t = 0;
	int abroad = 0;

	for (int i = 0; i < n; i++) {
		if (s[i] == 'c') { cout << "No" << endl; }
		else if (s[i] == 'a') {
			if (a + b > t) {
				t++;
				cout << "Yes" << endl;
			}
			else {
				cout << "No" << endl;
			}
		}
		else if (s[i] == 'b') {
			if (a + b > t&&b > abroad) {
				t++; abroad++;
				cout << "Yes" << endl;
			}
			else {
				cout << "No" << endl;
			}
		}
	}
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const long long INF = 1LL << 58;
struct Edge
{
    ll s, t, d;
};
typedef vector<vector<Edge>> Graph;
typedef vector<pii> vpii;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

ll L, N;
ll X[200001];
ll ans = 0;
ll sumR[200001];
ll sumL[200001];

signed main()
{
    cin >> L >> N;

    REP(i, N)
    cin >> X[i + 1];
    if (N == 1)
    {
        cout << max(L - X[1], X[1]) << endl;
        return 0;
    }

    sumL[0] = 0;
    REP(i, N)
    sumL[i + 1] = X[i + 1] * 2 + sumL[i];

    sumR[0] = 0;
    REP(i, N)
    sumR[i + 1] = (L - X[N - i]) * 2 + sumR[i];

    ll Le, Ri;
    ll tmp = 0;
    ll nl, nr;
    REP(i, N)
    {
        if (i == 0)
            continue;
        Le = i;
        Ri = N - i;
        REP(j, 2)
        { //start
            REP(k, 2)
            { //end
                if (j == 0 and k == 0)
                {
                    nl = min(Le, Ri + 1);
                    nr = nl - 1;
                }
                else if (j == 1 and k == 1)
                {
                    nr = min(Ri, Le + 1);
                    nl = nr - 1;
                }
                else
                {
                    nl = min(Ri, Le);
                    nr = nl;
                }
                tmp = 0;
                tmp = sumL[Le] - sumL[Le - nl];
                tmp = tmp + sumR[Ri] - sumR[Ri - nr];
                if (k == 0)
                    tmp = tmp - X[Le];
                else
                    tmp = tmp - (L - X[N - Ri + 1]);

                chmax(ans, tmp);
            }
        }
    }
    cout << ans << endl;

    //system("pause");
}

Measured memory_bytes: 4992
#include<stdio.h>
#include<iostream>
using namespace std;
int main(){

long long int a,b,A,B;

while(cin>>a>>b){
 A=a;B=b;
 while (b)
      {
	int tmp = a % b;
	a = b;
	b = tmp;
      }

b=A*B/a;
cout<<a<<" "<<b<<endl;
}
return 0;
}

    

Measured memory_bytes: 1156
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

int main(int argc, char *argv[]){
        int r;
		int dispose;
        double pi = 3.1415;
        double ans;
        dispose = scanf("%d",&r);
        ans = 2 * r * pi;
        printf("%lf",ans);
        return 0;
}

Measured memory_bytes: 1752
#![allow(clippy::needless_range_loop)]

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        #[allow(unused_mut)]
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        m: usize,
        k: usize,
        a: [usize; n],
        b: [usize; m],
    };

    let mut sum: usize = a.iter().sum();
    let mut ans: usize = 0;
    let mut b_index: usize = 0;
    for a_index in (0..=n).rev() {
        if a_index != n {
            sum -= a[a_index];
        }

        while b_index < m && sum + b[b_index] <= k {
            sum += b[b_index];
            b_index += 1;
        }

        if sum <= k && ans < a_index + b_index {
            ans = a_index + b_index;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 9272
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

int main() {
	vector<vector<int>>v(6);
	for (int i = 0; i < 6; i++) {
		int x, y;
		cin >> x >> y;
		if (x > y)swap(x, y);
		v[i] = { x,y };
	}
	sort(v.begin(), v.end());

	bool ret = true;
	if (v[0] != v[1] || v[2] != v[3] || v[4] != v[5])ret = false;
	if (v[0][0] != v[2][0] || v[0][1] != v[4][0] || v[2][1] != v[4][1])ret = false;

	cout << (ret ? "yes" : "no") << endl;
}

// START!!! (13:50)
// WA をしないように気を付けてください
// :(
// 大丈夫ですか？？？
// 問題 6 は分かりました、本当にやるだけです
// 問題 1 を AC したら実装します


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    int W, H;
    cin >> W >> H;
    vector<pair<int, bool>> roads(W + H);
    for(int i = 0; i < W; i++){
        int p;
        cin >> p;
        roads[i] = {p, 0};
    }
    for(int i = 0; i < H; i++){
        int p;
        cin >> p;
        roads[W + i] = {p, 1};
    }
    sort(all(roads));
    lint ans = 0, p_cnt = W + 1, q_cnt = H + 1;
    for(auto x: roads){
        if(x.second == 0){
            p_cnt--;
            ans += x.first * q_cnt;
        }else{
            q_cnt--;
            ans += x.first * p_cnt;
        }
    }
    cout << ans << endl;
}


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

using namespace std;

int main(){
    int n,m;
    cin >> n >> m;
    int d[m];
    for(int i = 0;i<m; i++){
        cin >> d[i];
    }
    int dp[50005];
    dp[0]=0;
    for(int i = 1;i<=n; i++){
        dp[i]=i;
        for(int j = 0;j<m;j++){
            if(d[j]<=i){
                dp[i]=min(dp[i],dp[i-d[j]]+1);
            }
        }
    }
    cout << dp[n] << '\n';
}


Measured memory_bytes: 3292
#include <iostream>
#include <algorithm>
#include <functional>
#include <math.h>
using namespace std;
int main(){
  int a,b;
  char op;
  while(1){
    cin>>a>>op>>b;
    if(op=='?') break;
    if(op=='+')cout<<a+b;
    if(op=='-')cout<<a-b;
    if(op=='*')cout<<a*b;
    if(op=='/')cout<<a/b;
    cout << '\n';
  }
  return 0;
}



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

int main()
{
	int x;
    cin>>x;
    
    if(x<600&&x>399)
    {
    	cout<<8<<endl;
     }
    else if(x<800&&x>599)
    {
    	cout<<7<<endl;
    }
    else if(x<1000&&x>799)
    {
    	cout<<6<<endl;
    }
    else if(x<1200&&x>999)
    {
    	cout<<5<<endl;
    }
    else if(x<1400&&x>1199)
    {
    	cout<<4<<endl;
    }
    else if(x<1600&&x>1399)
    {
    	cout<<3<<endl;
    }
    else if(x<1800&&x>1599)
    {
    	cout<<2<<endl;
    }
    else if(x<2000&&x>1799)
    {
    	cout<<1<<endl;
    }
    return 0;
    }

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

#define ll long long
#define endl "\n"
#define deb(x) cerr << #x << ":" << x << "\n"

void solve()
{
	ll n, k;
	cin >> n >> k;
	vector<ll> v(n + 1);
	for (int i = 1; i <= n;i++)
		cin >> v[i];
	if (k < n){
		int cur = 1;
		while (k--)
		{
			cur = v[cur];
		}
		cout << cur << endl;
		return;
	}
	set<ll> s;
	ll cur = 1;
	ll moves = 1;
	vector<int> d;
	vector<int> a;
	int cnt = 0;
	while (1)
	{
		if(s.count(cur)){
			for (int i = 0; i < d.size();i++){
				if(d[i]==cur){
					k -= i;
					for (int j = i; j < d.size();j++)
						a.emplace_back(d[j]);
				}
			}
			break;
		}
		s.insert(cur);
		d.emplace_back(cur);
		cur = v[cur];
	}
	cout << a[k % a.size()] << endl;
}

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


Measured memory_bytes: 12848
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;

const ll mod = 1e9 + 7;
int n;
vector<int> a;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<int> a(n);
    ll sum = 0;
    map<int, int> freq;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        freq[a[i]]++;
        sum += a[i];
    }
    int q;
    cin >> q;
    while (q--) {
        ll x, y;
        cin >> x >> y;
        ll cnt = freq[x];
        sum -= x * cnt;
        sum += y * cnt;
        cout << sum << endl;
        freq[y] += cnt;
        freq[x] -= cnt;
    }
    return 0;
}

Measured memory_bytes: 8000
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int64_t INF = 1LL << 60;

int main() {
  int N;
  cin>>N;
  vector<int>H(N);
  for(int i=0;i<N;i++){
    cin>>H[i];
  }
  int count=0;
  int ans=0;
  for(int i=0;i<N;i++){
    if(i+1<N&&H[i+1]<=H[i]){count++;}
    else {ans=max(ans,count);count=0;}
  }
  cout<<ans<<endl;
  return 0;}

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

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

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

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

const int MAX = 2005;
const int INF = 1001001001;
const int MOD = 1000000007;

int main(){
    int N, Z, W;
    cin >> N >> Z >> W;

    vector<int> a(N);
    rep(i, N) cin >> a[i];

    if (N == 1) {
        cout << abs(a[0] - W) << endl;
    } else {
        cout << max(abs(W - a[N-1]), abs(a[N-2] - a[N-1])) << endl;
    }
}

Measured memory_bytes: 3612
import math
import itertools

K = int(input())
K = [i for i in range(1, K+1)]
p = itertools.combinations_with_replacement(K, 3)
p = list(p)
g = 0

for i in p:
    a = math.gcd(i[0], i[1])
    b = math.gcd(a, i[2])
    if i[0] != i[1] != i[2]:
        g += b*6
    elif i[0] == i[1] == i[2]:
        g += b
    else:
        g += b*3

print(g)

Measured memory_bytes: 105376
//#define TIMER_
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define ALL(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using ll = long long;
using ull = unsigned long long;

inline ll pw(ll c) {
  return c*c*c*c*c;
}

inline ll f(ll a, ll b) {
  return pw(a) - pw(b);
}

int main() {
  fastio;
  int x; cin >> x;
  for (int a = -2000; a <= 2000; a++) {
    for (int b = -2000; b <= 2000; b++) {
      if (f(a,b) == x) {
        cout << a << " " << b << endl;
        return 0;
      }
    }
  }
  
  #ifdef TIMER_
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  #endif
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, X;
  X = 0;
  cin >> N;
  for (int i = 0; i<N ;i++){
  string C;
  cin >> C;
    if (C == "Y"){
    X = X + 1;
    }
  }
  if (X == 0){
  cout << "Three" << endl;
  }
  else if (X != 0){
  cout << "Four" << endl;
  }
}


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

using namespace std;
#define ll long long

#define rep(i, a) for (int (i) = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int (i) = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int (i) = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int (i) = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

void init();
void solve();

signed main()
{
	init();
	solve();
}

int N, Q;
string s;
vector<int> K;

void init()
{
	cin >> N >> s >> Q;
	K.resize(Q);
	rep(i, Q) cin >> K[i];
}

ll calc(int k)
{
	int d = 0, m = 0;
	ll dm = 0;
	int st = 0;
	int en = 1;
	ll res = 0;
	if (s[0] == 'D') d++;
	if (s[0] == 'M') m++;
	while (en < N) {
		if (s[en] == 'C') {
			res += dm;
		} else if (s[en] == 'D') {
			d++;
		} else if (s[en] == 'M') {
			m++;
			dm += d;
		}
		en++;
		st = max(0, en - k + 1);
		if (st) {
			if (s[st-1] == 'D') {
				d--;
				dm -= m;
			} else if (s[st-1] == 'M') {
				m--;
			}
		}
	}
	return res;
}

void solve()
{
	rep(i, Q) {
		cout << calc(K[i]) << endl;
	}
}


Measured memory_bytes: 1412
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999
#define rep(i,m,n) for(int i = m;i < n;i++)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl;
#define Vecpr vector<pair<lli,lli>>
#define mod 1000000007;
bool is_prime(lli x) {
  for(lli i = 2; i * i <= x; i++) {
    if(x % i == 0) return false;
  }
  return true;
}
int main() {
  lli A,B,C=1,D=0,E=0,F=0,G=0,H=0,N,M;
  cin >> N >> M>>A;
  N-=M;
  A-=N;
  if(A<0)A=0;
  Out(A);
}

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

char bord[52][52];

int main(){
	int h,w;
	cin>>h>>w;

	for (int i = 1; i <= h; ++i){
		for (int j = 1; j <= w; ++j){
			cin>>bord[i][j];
		}
	}

	int dx[8]={-1, 0, 1,1,1,0,-1,-1};
	int dy[8]={-1,-1,-1,0,1,1,1,0};
	
	for (int i = 1; i <= h; ++i){
		for (int j = 1; j <= w; ++j){
			if(bord[i][j]=='#')continue;
			char count='0';
			for (int k = 0; k < 8; ++k){
				if(bord[i+dy[k]][j+dx[k]]=='#')
					count++;
			}
			bord[i][j]=count;
		}
	}

	for (int i = 1; i <= h; ++i){
		for (int j = 1; j <= w; ++j){
			cout<<bord[i][j];
		}
		cout<<endl;
	}

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
const int maxn = 1e5 + 5;
#define INF 1000000000
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int a[maxn];
int cnt[maxn];

 int getSum(int n) 
    {  
    int sum = 0; 
    while (n != 0) 
    { 
     sum = sum + n % 10; 
     n = n/10; 
    }  
 return sum; 
 }

int countDigit(long long n) 
{ 
    int count = 0; 
    while (n != 0) { 
        n = n / 10; 
        ++count; 
    } 
    return count; 
} 
char S[110];
char T[110];

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio
	int a;
	cin >> a;
	cin >> S >> T;
	for(int i=0; i<a; i++){
		cout << S[i] << T[i]; 
	}
	cout << endl;
}






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

int N, M;
int A[105][105];
int memo[105][105];

int dp(int x, int y) {
  if(x == N && y == M) return 0;
  if(x > N || y > M) return 1000000;
  if(memo[x][y] != -1) return memo[x][y];
  int res = min(dp(x + 1, y) + (A[x][y] != A[x + 1][y] && A[x + 1][y] == '#'), dp(x, y + 1) + (A[x][y] != A[x][y + 1] && A[x][y + 1] == '#'));
  return memo[x][y] = res;
}

int main() {
//  freopen("inp", "r", stdin);
  memset(memo, -1, sizeof(memo));
  scanf("%d %d", &N, &M);
  getchar();
  for(int i = 1; i <= N; i++) {
    for(int j = 1; j <= M; j++) {
      A[i][j] = getchar();
    }
    getchar();
  }
  cout << dp(1, 1) + (A[1][1] == '#') << "\n"; 
}

Measured memory_bytes: 384