akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl

const ll INF=1e9+7;
const ll N = 102;

vector<ll> r,b;
bool didr[N];
ll a,bc,n,ans=0;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	FOR(i,0,n){
		cin>>a>>bc;
		r.pb(a*1000+bc);
	}
	FOR(i,0,n){
		cin>>a>>bc;
		b.pb(a*1000+bc);
	}

	SORT(r);
	SORT(b);
	FILA(didr,N,false);
	FOR(i,0,n){
		ll bx=b[i]/1000;
		ll by=b[i]%1000;
		ll rx,ry,k=-1,my=-1;
		FOR(j,0,n){
			rx=r[j]/1000;
			ry=r[j]%1000;
			if((bx>rx)&&(by>ry)&&(didr[j]==false)&&(my<ry)){
				k=j;
				my=ry;
			}
		}
		if(k!=-1){
			didr[k]=true;
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int nsz = 1e5;
int n, p, ans;
num m, k, a[nsz + 5], b[nsz + 5];

bool inline cmp(int i, int j) {
    return b[i] - a[i] < b[j] - a[j];
}

bool inline chk(num md) {
    cont (i, n) {
        b[i] = a[i];
    }
    num mx = 0, sum = m * k;
    vector<int> rem;
    cont (i, n) {
        if (b[i] <= md) {
            num del = min(sum, m);
            sum -= del;
            b[i] += del;
            mx = max(mx, b[i]);
        }
    }
    cont (i, n) {
        if (a[i] == b[i] && b[i] <= mx) {
            num del = min(sum, mx - b[i]);
            sum -= del;
            b[i] += del;
            rem.push_back(i);
        } else if (a[i] == b[i]) {
            num del = min(sum, m);
            sum -= del;
            b[i] += del;
        }
    }
    sort(all(rem), cmp);
    loop (i, rem.size()) {
        int id = rem[i];
        num del = min(sum, m - (b[id] - a[id]));
        b[id] += del;
        sum -= del;
    }
    sort(b + 1, b + n + 1);
    reverse(b + 1, b + n + 1);
    cont (i, p) {
        if (b[i] == mx)  return 1;
    }
    return 0;
}

int main()  {
    ios::sync_with_stdio(0);
    cin >> n >> m >> k >> p;
    cont (i, n) {
        cin >> a[i];
    }
    sort(a + 1, a + n + 1);
    reverse(a + 1, a + n + 1);
    num l = -1, r = 1e16, md = (l + r) >> 1;
    for (; r - l > 1; md = (l + r) >> 1) {
        (chk(md) ? r : l) = md;
    }
    cont (i, n) {
        ans += a[i] >= r;
    }
    cout << ans << ln;
}

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

int main() {
  int n,m;long long ans = 0,honnsuu = 0;
  cin >> n >> m;
  vector<pair<long long,int>>p(n);
  for(int i = 0;i < n;i++){
    cin >> p[i].first >> p[i].second;
  }
  sort(p.begin(),p.end());
  for(int i = 0;i < n;i++){
    if(honnsuu+p[i].second < m){
      honnsuu += p[i].second;
      ans += p[i].second*p[i].first;
    }
    else{
      ans += (m-honnsuu)*p[i].first;
      cout << ans << endl;
      return 0;
    }
  }
}


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

#define REP(i, n) for(int i=0; i<n; i++)
#define REPA(i, a, n) for(int i=a; i<n; i++)
#define REPE(i, a, n) for(int i=a; i<=n; i++)
#define SetArray(a, n) for(int array_i=0; array_i<n; array_i++) cin >> a[array_i]
#define print(x) cout << x
#define printw(x) cout << x << " "
#define println(x) cout << x << endl
#define printl() cout << endl
#define sqr(x) (x)*(x)
#define cube(x) (x)*(x)*(x)
typedef long long ll;
typedef unsigned int uint;
typedef vector<int> vi;

int main(){
    int a, b;
    cin >> a >> b;
    println(a*b);

    return 0;
}




Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define ll long long int
#define F(i,j,k,in) for(int i=j;i<k;i+=in)
#define DF(i,j,k,in) for(int i=j;i>=k;i-=in)
#define feach(it,l) for (auto it = l.begin(); it != l.end(); ++it)
#define fall(a) a.begin(),a.end()
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define eq equal_range
#define fs first
#define ss second
#define ins insert
#define mkp make_pair
#define endl "\n"
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vin;
typedef vector<char> vch;
typedef vector<string> vst;
typedef vector<vector<ll>> vvll;
typedef vector<vector<int>> vvin;
typedef vector<pair<ll,ll>> vpll;
typedef vector<pair<int,int>> vpin;
typedef set<ll> sll;
typedef set<int> sint;
typedef set<char> sch;
typedef set<string> sst;
typedef queue<ll> qll;
typedef priority_queue<ll> pqll;
typedef queue<int> qin;
typedef priority_queue<int> pqin;
typedef map<ll,ll> mpll;
typedef map<int,int> mpin;
typedef pair<ll,ll> pll;
typedef pair<int,int> pin;
const ll MOD=1000000007;
const long double PI=3.1415926535897932384626433832795;
ll pwr(ll b,ll p){ll res=1;while(p){if(p&1) {res*=b; p--;}else{b*=b; p>>=1;}}return res;}
int main()
{
ios_base::sync_with_stdio(false) , cin.tie(NULL) , cout.tie(NULL);
int n , m ,x; cin>>n>>m>>x;
int A[13][13];
F (i,0,n,1) {
  F (j,0,m+1,1) cin>>A[i][j];
}
int mask = 1<<n;
int cost=1e9;
F (i,0,mask,1) {
  vin al (m+1,0);
  int sum=0;
  F (j,0,n,1) {
    if (i&(1<<j)) {
      F (k,1,m+1,1) al[k]+=A[j][k];
      sum += A[j][0];
    }
  }
  bool flag = true;
  F (p,1,m+1,1) if (al[p]<x) flag=false; 
  if (flag) cost=min(cost,sum);
}
if (cost==1e9) cout<<-1;
else cout<<cost;

return 0;
}


Measured memory_bytes: 3616
#define _USE_MATH_DEFINES
#define INF 100000000

#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

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

static const float EPS = 1e-8;

int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

int path[31][31];
float cost[31][1<<8];

class Data{
public:
	float cost;
	int now;
	int used;
	Data(int _n,float _c,int _u){		
		now = _n;
		cost = _c;
		used = _u;
	}

	bool operator>(const Data& d) const{
		return cost > d.cost;
	}
};

int main(){
	int n,m,p,a,b;
	while(~scanf("%d %d %d %d %d",&n,&m,&p,&a,&b)){
		if(n==0 && m==0 && p==0 && a==0 && b==0) break;
		//m : number of cities
		memset(path,-1,sizeof(path));
		fill((float*)cost,(float*)cost+(1<<8)*31,100000000.0);
		int *t = new int[n]();

		for(int i=0;i<n;i++){
			scanf("%d",t+i);
		}

		for(int i=0;i<p;i++){
			int x,y,z;
			scanf("%d %d %d",&x,&y,&z);
			path[x][y] = path[y][x] = z;
		}

		cost[a][0] = 0;

		priority_queue<Data,vector<Data>,greater<Data> > que;

		que.push(Data(a,0,0));

		while(!que.empty()){
			float c = que.top().cost;
			int now = que.top().now;
			int used = que.top().used;

			que.pop();
			for(int to=1;to<=m;to++){
				if(to==now) continue;
				if(path[now][to] == -1) continue;

				for(int j=0;j<n;j++){
					if(used & (1<<j)) continue;				
					if(cost[to][used | (1<<j)] <= c + (float)path[now][to]/(float)t[j]) continue;

					cost[to][used | (1<<j)] = c + (float)path[now][to]/(float)t[j];
					que.push(Data(to,c + (float)path[now][to]/(float)t[j],used | (1<<j)));
				}
			}
		}

		float res = numeric_limits<float>::max();

		for(int S=0;S<=(1<<n)-1;S++){
			res = min(cost[b][S],res);
		}

		if(100000000.0 <= res) printf("Impossible\n");
		else printf("%f\n",res);

		delete[] t;
	}
}

Measured memory_bytes: 7040
n, k, q = gets.chomp.split.map(&:to_i)
a = []
q.times do |i|
  a[i] = gets.chomp.to_i
end

count = Array.new(n, 0)
a.each do |aa|
  count[aa-1] += 1
end

min = q - k + 1
n.times do |i|
  if count[i] >= min
    puts 'Yes'
  else
    puts 'No'
  end
end


Measured memory_bytes: 3784
# 入力値を文字の配列で返す
def gets_s_list()
  gets.chomp.split("")
end

s_list = gets_s_list

count = 0
w_count = 0
s_list.each_with_index do |s, i|
  if s == "W"
    count += i - w_count
    w_count += 1
  end
end
puts count


Measured memory_bytes: 17020
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(a) (a).begin(),(a).end()
bool compare_by_b(pair<long, long> a, pair<long, long> b){
    return a.second < b.second;
}
#define LEN 100000
int main(){
    ll n;
    cin >> n;
    ll df[LEN+1];
    rep(i, LEN+1)df[i] = 0;
    rep(i, n){
        ll a;
        scanf("%lld", &a);
        df[a]++;
    }
 
    ll ans =0;
    for(int i = 1;  i < LEN; i++){
        ll res = df[i-1] + df[i] + df[i+1];
        if(ans <= res)ans = res;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define LL long long
#define rep(i,l,r) for(LL i=l;i<=r;i++)
#define dep(i,r,l) for(LL i=r;i>=l;i--)
#define fy 20021218020021218
#define N 100010
using namespace std;
struct node
{
	LL num,v;
}a[N];
LL ans[N];
LL n,m,i,j,k,l,r;
LL read()
{
	LL x=0,k=1; char c;
	while(!isdigit(c=getchar())) if(c=='-') k=-k;
	x=c^48;
	while(isdigit(c=getchar())) x=(x<<1)+(x<<3)+(c^48);
	return x*k;
}
bool cmp(node a,node b){return a.v>b.v;}
int main()
{
	n=read();
	rep(i,1,n) a[i].v=read(),a[i].num=i;
	sort(a+1,a+n+1,cmp);
	i=0; j=n+1;
	a[n+2].num=fy; a[n+2].v=fy; 
	while(i<=n)
	{
		j=min(j,a[++i].num);
		while(a[i].v==a[i+1].v) j=min(j,a[++i].num);
		ans[j]+=i*(a[i].v-a[i+1].v);
	}
	rep(i,1,n) printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 3456
#include<cstdio>
const int M=1e9+7;
inline int Mod(int a){return a<M?a:a-M;}
const int N=1003;
int n,m,f[N][N];char a[N];
signed main(){
	scanf("%d%d",&n,&m);
	f[0][1]=1;
	for(int i=1;i<=n;i++){
	  scanf("%s",a+1);
	  for(int j=1;j<=m;j++)if(a[j]=='.')
		f[i][j]=Mod(f[i-1][j]+f[i][j-1]);
	}
	printf("%d",f[n][m]);
	return 0;
}

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

int main(){
    int64_t H;
    cin >> H;
    
    int64_t num = 1;
    int64_t res = 0;
    
    for ( int64_t i = 0; i < 50; ++i){
        if ( H >= 2 ){
            H = H / 2;
            res += num;
            num *= 2;
        } else {
            res += num;
            break;
        }
    }
    
    cout << res << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<stack>
#include<sstream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=100+10;
int main() {
    int x,a,b,c;
    while(~scanf("%d%d%d%d",&a,&b,&c,&x)){
        int ans=0;
        for(int i=0;i*500<=x&&i<=a;i++)
            for(int j=0;j*100+i*500<=x&&j<=b;j++)
                if((x-(j*100+i*500))/50<=c)
                    ans++;
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static long bignum = 1000000000+7;

	public static int[] rudder = new int[200001];

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String[] ss = s.split("");
		if(ss[2].equals(ss[3])) {
			if(ss[4].equals(ss[5])) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}
			
		}else {
			System.out.println("No");
		}

	}





}
/*
class City{
	int order;
	int prefecture;
	int year;
	int number;
	City(int order,int prefecture, int year){
		this.order = order;
		this.prefecture = prefecture;
		this.year = year;
	}
}
*/


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;cin >> s;
	vector<bool> a(4);
	rep(i,s.size()){
		if(s.at(i)=='N') a.at(0)=true;
		else if(s.at(i)=='S') a.at(1)=true;
		else if(s.at(i)=='W') a.at(2)=true;
		else a.at(3)=true;
	}
	if(a.at(0)==a.at(1) && a.at(2)==a.at(3)) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

int main()
{
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;

    int kh, km = 0;

    int ansh, ansm;
    int ans;

    int ksh, ksm;

    kh = k / 60;
    km = k % 60;

    ksh = h2 - kh;
    ksm = m2 - km;

    ansh = ksh - h1;
    ansm = ksm - m1;
    ans = 60 * ansh + ansm;

    cout << ans << endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;

int main(){
    int N;
    cin >> N;

    int ans = 0;
    int a = 0, b = 0, c = 0;
    for(int i=0; i<N; i++){
        string s;
        cin >> s;
        for(int j=0; j<s.size()-1; j++)
            if(s[j] == 'A' && s[j+1] == 'B') ans++;
        if(s.front() == 'B' && s.back() == 'A') a++;
        else if(s.front() == 'B') b++;
        else if(s.back() == 'A') c++;
    }
    ans += max(0, a - 1);
    if(b >= 1 && a >= 1) ans++;
    else if(c >= 1 && a >= 1) ans++;
    ans += min(b, c);
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int n, m, x;
	cin >> n >> m >> x;
	int res = Inf;
	vector<int> c(n);
	vector<vector<int> > a(n, vector<int>(m));
	rep (i, n) {
	  cin >> c[i];
	  rep (j, m) cin >> a[i][j];
	}
	rep (bit, 1 << n) {
	  int tmp = 0;
	  vector<int> und(m);
	  rep (i, n) {
		if (bit & (1 << i)) {
		  tmp += c[i];
		  rep (j, m) und[j] += a[i][j];
		}
	  }
	  bool ok = true;
	  rep (i, m) if (und[i] < x) ok = false;
	  if (ok) res = min(res, tmp);
	}
	if (res == Inf) cout << -1 << endl;
	else cout << res << endl;
    
    return 0;
}


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

#define LL long long

#define FOR(INDEX, START, END) for (LL INDEX = (START); INDEX < (END); ++INDEX)
#define REP(INDEX, COUNT) for (LL INDEX = 0; INDEX < (COUNT); ++INDEX)

int main()
{
	LL N;
	cin >> N;

	vector<LL> a(N);
	REP(i, N) {
		cin >> a[i];
	}

	sort(a.begin(), a.end());

	cout << a[N / 2] - a[N / 2 - 1] << endl;


	return 0;
}


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

int main(){
    int N;
    cin >> N;
    if (N%10==2||N%10==4||N%10==5||N%10==7||N%10==9){
        cout << "hon" << endl;
    }
    else if(N%10==3){
        cout << "bon" << endl;
    }
    else{
        cout << "pon" << endl;
    }
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <inttypes.h>

static inline int_fast64_t max(int_fast64_t a, int_fast64_t b)
{
    return (a >= b) ? a : b;
}

int main(void)
{
    int_fast64_t n, t;
    scanf("%" SCNdFAST64" %" SCNdFAST64, &n, &t);
    int_fast64_t total = 0, tmp1 = 0, tmp2 = 0;
    for (int_fast64_t i = 0; i < n; ++i) {
        tmp1 = tmp2;
        scanf("%" SCNdFAST64, &tmp2);
        if (i > 0) {
            total += max(t - (tmp2 - tmp1), 0);
        }
    }
    printf("%" PRIdFAST64 "\n", n * t - total);
    return 0;
}


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

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

    int n, k;
    cin>>n>>k;

    int r=0, b;
    for(int i=0;i<n;i++){
        cin>>b;

        if(b>=k)r++;
    }

    cout<<r;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin >> s;
	int n = s.length();
	if(s[n-1] == 's')
		cout << s << "es\n";
	else
		cout << s << "s\n";
}


Measured memory_bytes: 3648
#include <cstdio>
#include <algorithm>

using namespace std;

const int N = 100010;

int n;
int h[N];

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", h + i);
    }
    h[0] = max(h[0] - 1, 1);
    for (int i = 1; i < n; i++) {
        if (h[i] >= h[i - 1] + 1) {
            h[i]--;
        } else if (h[i] < h[i - 1]) {
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}

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

using namespace std;
string s,t;
int n,x,y,u,v,co,can,sl,F[100005],T[100005],P[100005],vt,l,r,mid;
int main()
{
  
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>s>>t;
    cin>>n;
    s='.'+s;
    t='.'+t;
    for (int i=1;i<s.length();++i) F[i]=F[i-1]+1+(s[i]=='B');
    for (int i=1;i<t.length();++i)
    {
    P[i]=P[i-1]+(t[i]=='B');

    if (t[i]=='A') {sl=0;vt=i;T[i]=T[i-1]+1;}
    else
    {
        sl++;
        if (sl%2) T[i]=T[vt]+(sl+3)/2;
        else      T[i]=T[vt]+sl/2;
    }

    }
    while (n--)
    {
        cin>>x>>y>>u>>v;
        co=F[y]-F[x-1];
        can=0;
        vt=u-1;
        l=u;r=v;
        while (l<=r)
        {
            mid=(l+r)/2;
            if (P[mid]-P[u-1]==mid-u+1) {l=mid+1;vt=mid;}
            else r=mid-1;
        }
        sl=vt-u+1;
        if (sl%2) can=(sl+3)/2;
        else      can=sl/2;
        can+=T[v]-T[vt];
        if ((co-can)%3==0) cout<<"YES";else cout<<"NO";cout<<'\n';

    }

    return 0;
}


Measured memory_bytes: 2028
def main():
    a,b,k = list(map(int,input().split()))
    divisor = []
    cnt = 0
    for i in range(1,min(a,b) + 1):
        if min(a,b) % i == 0:
            divisor.append(i)
    for i in reversed(divisor):
        if max(a,b) % i == 0:
            cnt += 1
        if cnt == k:
            print(i)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
vector<ll> v;
set<int> s;
vector<int> to;
int solve(int n){
    if(s.find(n) != s.end()) return n;
    else{
        s.insert(n);
        to.push_back(n);
        solve(v[n]);
    }
}
int main(){
    cout << fixed << setprecision(10);
    ll n,k;
    cin >> n >> k;
    rep(i,n){
        int x;
        cin >> x;
        x--;
        v.push_back(x);
    }
    int num = solve(0);
    int len = 0;
    int beg = 0;
    rep(i,to.size()){
        if(to[i] == num){
            len = to.size() - i;
            beg = i;
        }
    }
    if(k < to.size()){
        cout << to[k] + 1 << endl;
        return 0;
    }
    vector<int> loop;
    for(int i = beg; i < int(to.size()); i++){
        loop.push_back(to[i]);
    }
    ll div = k - to.size();
    cout << loop[div%(loop.size())] + 1 << endl;
    return 0;
}

Measured memory_bytes: 21060
INT_MAX=10**18+7
MOD=10**9+7
def INPUT():return list(int(i) for i in input().split())
def LIST_1D_ARRAY(n):return [0 for _ in range(n)]
def LIST_2D_ARRAY(m,n):return [[0 for _ in range(n)]for _ in range(m)]
#################################################################################
n,k=INPUT()
print(min(n%k,abs(k-n%k)))


Measured memory_bytes: 38256
from collections import Counter
from operator import mul
from functools import reduce


def nCr(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


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

ac = dict(Counter(a))

ans = 0
for k, v in ac.items():
    if v < 2:
        ac[k] = (v, 0, 0)
    else:
        c = nCr(v, 2)
        ans += c
        if v - 1 < 2:
            ac[k] = (v, c, 0)
        else:
            ac[k] = (v, c, nCr(v - 1, 2))

for i in a:
    v = ac[i]
    if v[0] - 1 < 2:
        print(ans - v[1])
    else:
        print(ans - v[1] + v[2])

Measured memory_bytes: 29604
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

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...);
}
#ifdef LOCAL
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif

#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)

typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N;
    cin >> N;
    vector<ll> A(N);
    vector<ll> B(N);
    vector<ll> C(N - 1);

    REP(i, N) cin >> A[i];
    REP(i, N) cin >> B[i];
    REP(i, N - 1) cin >> C[i];
    ll ans = 0;
    ll previous = -1;

    REP(i, N) {
        ans += B[A[i] - 1];
        if (previous == A[i] - 1) ans += C[previous - 1];
        previous = A[i];
    }
    cout << ans << endl;

    return 0;
}


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


using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define all(n) n.begin(),n.end()
#define eb emplace_back
#define endl "\n"

const ll maxn=5e5;

const ll maxx=1e13;
const ll mod=1000000007;
const ll mod1=998244353;

vector<ll> adj[maxn];
ll h[maxn];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("test.txt","r",stdin);
    //   freopen("GREEDY.INP", "r", stdin);
    //  freopen("GREEDY.OUT", "w", stdout);
   ll n , k;
   cin>>n>>k ;
   for (int i=1;i<=n;i++)
   {
      cin>>h[i];
   }
    for (int i=1;i<=k;i++)
    {
        ll a, b;
        cin>>a>>b;
        adj[a] .pb(b);
        adj[b].pb(a);

    }
    ll ans=0;
    for (int i=1;i<=n;i++)
    {
        bool x=true;
        for (auto to:adj[i])
        {
            if (h[i ]<=h[to]) x=false ;
        }
        ans+=x;
    }
    cout <<ans;


}


Measured memory_bytes: 19660
#include <stdio.h>
int main(void){
    int a , b;
    scanf("%d %d",&a,&b);
    if(a < b){
        printf("a < b\n");
    }else if(a > b){
        printf("a > b\n");
    }else{
        printf("a == b\n");
    }
    return 0;
}



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

char map[10][10];

void check(int x, int y);

int main()
{
	int n;
	int x, y;

	cin >> n;

	for (int i = 0; i < n; i++){
		for (int j = 0; j < 8; j++){
			cin >> map[j];
		}
		cin >> x >> y;
		check(x - 1, y - 1); // (1,1) -> map[0][0]

		cout << "Data " << i + 1 << ":" << endl;
		for (int j = 0; j < 8; j++){
			cout << map[j] << endl;
		}
	}

	return (0);
}

void check(int x, int y)
{
	map[y][x] = '0';

	for (int i = 1; i <= 3; i++){
		if (y + i <= 7 && map[y + i][x] == '1'){
			check(x, y + i);
		}
		if (y - i >= 0 && map[y - i][x] == '1'){
			check(x, y - i);
		}
		if (x + i <= 7 && map[y][x + i] == '1'){
			check(x + i, y);
		}
		if (x - i >= 0 && map[y][x - i] == '1'){
			check(x - i, y);
		}
	}
}

Measured memory_bytes: 1168
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
#include "stdio.h"
using namespace std;

#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)

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

const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9+7;

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

using MIte = multimap<ll, ll, greater<ll> >::iterator;


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

	// long long?
	ll N, M;
	cin >> N >> M;

	vector<ll> vdp(pow(2, N), inf);
	rep(i, M) {
		ll a, b;
		cin >> a >> b;
		int key = 0;
		rep(j, b) {
			int c;
			cin >> c;
			c--;
			key = key | (1 << c);
		}

		vdp[key] = min(vdp[key], a);
		rep(k, vdp.size()) {
			int newk = k | key;
			vdp[newk] = min(vdp[newk], vdp[k] + a);
		}
	}

	if (vdp.back() == inf) {
		cout << "-1" << endl;
	}
	else {
		cout << vdp.back() << endl;
	}

	return 0;
}

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

using namespace std;

int main() {
int n, m = 0;
int a[1000];
int cnt = 0;
int sou = 0;
cin >> n >> m ;
for (int i =0; i < n; i++){
    cin >> a[i];
    sou = sou + a[i];
}
for (int i = 0; i < n; i++){
    if ((a[i] * 4 * m) >= sou){
        cnt = cnt + 1;
    }
}
if (cnt >= m){
    cout << "Yes" << endl;
}
else{
    cout << "No" << endl;
}
}



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

int main(){
	int n,a,Max=-1000000,Min=1000000;
	long long Sum=0;
	cin>>n;

	for(int i=0;i<n;i++){
		cin>>a;
		if(a>Max){
			Max=a;
		}
		if(a<Min){
			Min=a;
		}
		Sum=Sum+a;
	}

	cout<<Min<<" "<<Max<<" "<<Sum<<endl;	

	return 0;
}


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

int main() {
  ll N;
  cin >> N;
  if(N % 2 == 0) {
    cout << N << endl;
  } else {
    cout << N * 2 << endl;
  }
  return 0;
}


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

int main() {
  int a;
  string s, t, r;
  cin >> a >> s >> t;
  for(int i=0; i<a; i++) {
    r += s[i];
    for(int j=0; j<1; j++) {
      r += t[i];
    }
  }
  cout << r << endl;
  return 0;
}

Measured memory_bytes: 3636
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define D()
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 10000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(){

  long x,y=100;
  int c=0;
  cin >> x;
  while(y<x){
    y *= 1.01;
    c++;
  }
  cout << c <<endl;
}
  




Measured memory_bytes: 3632
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}
function PriorityQueue(n){
  this.heap=Array(n||1e5);
  this.size=0;
}
PriorityQueue.prototype = {
  push:function(x){
    var h=this.heap,i=this.size++,j;
    while(i){
      j=i-1>>1;
      if(h[j]<=x)break;
      h[i]=h[j],i=j;
    }
    h[i]=x;
  },
  pop:function(){
    var h=this.heap,s=this.size-1,x=h[s];h[s]=undefined;
    if(s<1)if(s)return;else return --this.size,x;
    var r=h[0],i=0,k=s>>1,j;--this.size;
    while(i<k){
      j=(i<<1)+1;
      if(h[j+1]<h[j])++j;
      if(x<=h[j])break;
      h[i]=h[j],i=j;
    }
    return h[i]=x,r;
  },
  top:function(){return this.heap[0];},
};

console.log(main());
function main(){
  var n = o.a();
  var m = o.a();
  var a = o.m(n);
  a.push([1e9,0]);
  a.sort((a,b)=>a[0]-b[0]);
  var ans = 0, j = 0;
  var pq = new PriorityQueue();
  for(var i = 1; i <= m; i++){
    while(a[j][0] <= i){
      pq.push(-a[j++][1]);
    }
    if(pq.size)ans -= pq.pop();
  }
  return ans;
}

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

using namespace std;

typedef long long ll;

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

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll a; cin >> a;
    ll ans = a-1;
    for(ll i = 1; i <= pow(a,0.5); i ++){
        if(a%i == 0){
            ans = min(ans,(i-1+a/i-1));
        }
    }
    cout << ans;
}



Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int a, b;
		
		while(scan.hasNextInt()){
			a = scan.nextInt();
			b = scan.nextInt();
			
			System.out.println((a + b));
		}
	}
}

Measured memory_bytes: 26304
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)){
			int times = sc.nextInt();
			Map<String, Long> map = new HashMap<>();
			for (int i = 0; i<times; i++){
				int query = sc.nextInt();
				String key = sc.next();
				switch (query) {
				case 0:
					long x = sc.nextLong();
					map.put(key,x);
					break;
				case 1:
					if (map.get(key)!=null) {
						System.out.println(map.get(key));
					} else System.out.println(0);
					break;
				case 2:
					map.remove(key);
					break;
				}
			}
		}
	}
}


Measured memory_bytes: 195252
n = int(input())
ls = list(map(int, input().split()))

flg=0
for i in range(n-2):
  if (ls[i+1]<ls[i] and ls[i+1]>ls[i+2]) or (ls[i+1]>ls[i] and ls[i+1]<ls[i+2]):
    flg += 1
print(flg)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
using ll =long long;
using namespace std;



int main(){
    ll n,y;
    cin>>n>>y;
    rep(i,n+1){
        rep(j,n+1-i){
            ll diff=y-10000*i-5000*j;
            ll k=diff/1000;
            if(diff>=0&&i+j+k==n){
                cout<<i<<" "<<j<<" "<<k<<endl;
                return 0;
            }
        }
    }
    cout<<-1<<" "<<-1<<" "<<-1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)

int main() {
	int N; cin >> N;

	ll A[87] = {};
	A[0] = 2;
	A[1] = 1;

	rep(i, 2, N + 1) {
		A[i] = A[i - 1] + A[i - 2];
	}
	cout << A[N] << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define L(a,d) ((a)<<((d)*3))
#define R(a,d) (((a)>>((d)*3))&7)
int h,w,c,f[16][16],ofs[4][2]={{0,1},{1,0},{-1,0},{0,-1}};
void P(int d){
  int m=~L(7,d+1);
  rep(i,h)rep(j,w){
    f[i][j]&=m;
    f[i][j]|=L(R(f[i][j],d),d+1);
  }
}
int F(int x,int y, int d, int C){
  int n=1;
  int a=R(f[y][x],d);
  int m=~L(7,d+1);
  f[y][x]&=m;
  f[y][x]|=L(C,d+1);
  for(auto l:ofs){
    int s=x+l[0];
    int t=y+l[1];
    if(0<=s&&s<w&&0<=t&&t<h&&R(f[t][s],d)==a&&R(f[t][s],d+1)!=C)n+=F(s,t,d,C);
  }
  return n;
}
int D(int d){
  if(d&4){
    P(d);
    F(0,0,d,c);
    P(d+1);
    return F(0,0,d+1,7);
  }
  int x=0;
  for(int r=1;r<=6;++r){
    P(d);
    F(0,0,d,r);
    int v=D(d+1);
    x=x>v?x:v;
  }
  return x;
}
int main() {
  while(cin>>h>>w>>c,h){
    rep(i,h)rep(j,w)cin>>f[i][j];
    cout<<D(0)<<endl;
  }
  return 0;
}

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

int main()
{
	ll N, L, T;
	cin >> N >> L >> T;
	vector<ll> res(N), X(N), W(N), l(N), r(N);
	ll cnt = 0, sum1 = 0, sum2 = 0;
	for (int i = 0; i < N; i++) {
		cin >> X[i] >> W[i];
		sum1 += X[i];
		if (W[i] == 1) {
			res[i] = (X[i] + T % L) % L;
		}
		else {
			res[i] = (X[i] - T % L + L) % L;
			cnt++;
		}
		sum2 += res[i];
	}
	sort(res.begin(), res.end());
	ll K = (sum2 - sum1 - (N - cnt * 2) * T) / L;
	for (int i = 0; i < N; i++) {
		cout << res[(i - K % N + N) % N] << endl;
	}
	return 0;
}


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

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

            List<string> str = new List<string>();
            for (int i = 0; i < N; i++)
            {
                str.Add(Console.ReadLine()); 
            }
            List<string> resultStr = str.Distinct().ToList();
            int message = resultStr.Count;
            Console.WriteLine(message);
        }
    }
}

//24579 =  hon
//0168 = pon
//3 = bon
//long n = long.Parse(Console.ReadLine());
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

//Console.WriteLine(cnt);
//Console.ReadKey();



Measured memory_bytes: 49440
#include <bits/stdc++.h>
using  namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	int ar[n];
	int dp[n];
	for(int i=0;i<n;i++){
		cin>>ar[i];
		dp[i]=-1;
	}
	if(n<=1){
		cout<<abs(ar[n-1]-ar[0]);
		return 0;
	}
	dp[0]=0;
	dp[1]=abs(ar[1]-ar[0]);
	for(int i=2;i<n;i++)
		dp[i]=min(abs(ar[i]-ar[i-1])+dp[i-1],abs(ar[i]-ar[i-2])+dp[i-2]);
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.20f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;

int main() {
	int x;
	cin >> x;

	if (400 <= x && x <= 599) cout << 8 << endl;
	else if (x <= 799) cout << 7 << endl;
	else if (x <= 999) cout << 6 << endl;
	else if (x <= 1199) cout << 5 << endl;
	else if (x <= 1399) cout << 4 << endl;
	else if (x <= 1599) cout << 3 << endl;
	else if (x <= 1799) cout << 2 << endl;
	else if (x <= 1999) cout << 1 << endl;

	return 0;
}


Measured memory_bytes: 3620
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<unordered_set>
#include<vector>

#define ll long long
#define P pair<int,int>
#define FOR(i,N) for(int i=0;i<(int)N;i++)
#define FORIN(i,a,b) for(int i=a;i<(int)b;i++)
#define ALL(x) (x).begin(),(x).end()
#define LAST(x) (x)[(x).size()-1]
#define GI(name) int (name);scanf("%d",&(name))
#define GI2(name1,name2) int (name1),(name2);scanf("%d %d",&(name1),&(name2))
#define GI3(name1,name2,name3) int (name1),(name2),(name3);scanf("%d %d %d",&(name1),&(name2),&(name3))
#define GVI(name,size) vector<int> (name)(size);FOR(i,(size))scanf("%d",&(name)[i])
#define MOD 1000000007

using namespace std;

string to_hex(int x){
    stringstream ss;
    ss<<hex<<x;
    return ss.str();
}

inline int get_int(){
    int ret;
    scanf("%d",&ret);
    return ret;
}

inline vector<int> get_ints(int n){
    vector<int> ret(n);
    FOR(i,n){
        scanf("%d",&ret[i]);
    }
    return ret;
}

inline string get_str(){
    string ret;
    cin>>ret;
    return ret;
}

bool is_prime(int n){
    int s=sqrt(n)+1;
    for(int i=2;i<=s;++i){
        if(n%i==0){
            return 0;
        }
    }
    return 1;
}

vector<P> prime_division(int n){
    vector<P> ret;
    int s=sqrt(n)+1;
    int c=0;
    for(int i=2;i<=n;++i){
        if(n%i==0){
            c=0;
            do{
                ++c;
                n/=i;
            }while(n%i==0);
            ret.push_back(P(i,c));
        }
    }
    return ret;
}

string to_string(string s){
    return s;
}

template<class T>
string to_string(vector<T> v){
    string ret="{";
    FOR(i,v.size()-1){
        ret+=to_string(v[i])+",";
    }
    if(v.size()>0){
        ret+=to_string(LAST(v));
    }
    ret+="}";
    return ret;
}

void debug_print(){
    cerr<<endl;
}

template<class Head,class... Tail>
void debug_print(Head head,Tail... tail){
    cerr<<to_string(head)<<" ";
    debug_print(tail...);
}

template<class... T>
void debug(T... args){
    cerr<<"["<<__LINE__<<"]: ";
    debug_print(args...);
}

void print(){
    cout<<endl;
}

template<class Head,class... Tail>
void print(Head head,Tail... tail){
    cout<<to_string(head);
    print(tail...);
}

int main(){
    GI(s);
    unordered_set<int> list;
    list.insert(s);
    int i=1;
    while(1){
        i++;
        if(s%2==0){
            s/=2;
        }else{
            s=3*s+1;
        }
        if(list.count(s)>0){
            print(i);
            break;
        }else{
            list.insert(s);
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,n,t,p=0,a,b;
    string s;
    cin>>a>>b;
    while(b--){
        cin>>n;
        p+=n;
    }
    (p<a)?cout<<"No"<<endl :cout<<"Yes"<<endl;


    return EXIT_SUCCESS;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
inline char nc()
{
	return getchar();
	static char buf[100000], *l = buf, *r = buf;
	return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<class T> void read(T &x)
{
	x = 0; int f = 1, ch = nc();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=nc();}
	while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=nc();}
	x *= f;
} 
typedef long long ll;
const int maxn = 200000 + 5;
int n;
char s[maxn];
vector<int> r;
int main()
{
	scanf("%s", s + 1), n = strlen(s + 1);
	for(int i = 1, j = 0; i <= n; i += j)
	{
		if(i < n && s[i] == 'B' && s[i + 1] == 'C') r.push_back(0), j = 2;
		else
		{
			j = 1;
			r.push_back(s[i] == 'A' ? 1 : 2);
		}
	}
	ll an = 0;
	for(unsigned int i = r.size() - 1, k = 0; ~i; --i)
	{
		if(r[i] == 0) ++k;
		else if(r[i] == 1) an += k; 
		else k = 0;
	}
	printf("%lld\n", an);
	return 0;
}

Measured memory_bytes: 1528
d = int(input())
c = list(map(int, input().split()))
mtx = [list(map(int, input().split())) for _ in range(d)]

point = [c[i] for i in range(26)]

for i in range(d):
    pnt = [0] * 26
    for j in range(26):
        pnt[j] += point[j]
    for j in range(26):
        pnt[j] += mtx[i][j]
    m = max(pnt)
    a = [i for i, j in enumerate(pnt) if j == m]
    print(a[0]+1)
    for j in range(26):
        point[j] += c[j]
    point[a[0]] = c[a[0]]


Measured memory_bytes: 9504
N=int(input())
li = list(map(int,input().split()))	
cnt=0
for i in range(N):
  for j in range(N):
    Q=li[i]*li[j]
    cnt+=Q
lick=[li[i]*li[i] for i in range(N)]
w=sum(lick)
print(int((cnt-w)/2))

Measured memory_bytes: 3064
def main():
    n, a, b = map(int, input().split())
    
    if b - a < 0 or n == 1 and b - a > 0:
        print(0)
    elif n == 1:
        print(1)
    else:
        print((n-2)*(b-a)+1)
        
        
if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <iostream>

using namespace std;

int main(void)
{
    u_int m, n;
    cin >> m >> n;

    bool suspects[m+1][m+1];
    for (u_int i=0; i<=m; i++)
        for (u_int j=0; j<=m; j++)
            suspects[i][j] = false;

    for (u_int i=0; i<n; i++) {
        int x, y;
        cin >> x >> y;
        suspects[y][x] = true;
    }

    u_int i = 0;
    while (i < m) {
        for (u_int j=1; j<=m; j++) {
            u_int k=0;
            for (k=0; k<=m; k++) 
                if (suspects[j][k])
                    break;

            if (k > m) {
                cout << j << endl;
                i++;
                suspects[j][0] = true;
                for (u_int l=1; l<=m; l++)
                    suspects[l][j] = false;
                break;
            }
        }

    }

    return 0;
}

Measured memory_bytes: 1160
#include <iostream>

using namespace std;


int main(int argc, char *argv[])
{
	int N, X, Y, ans[2005] = {0};

	cin >> N >> X >> Y;

	for (int i = 1; i <= N; i++) {
		for (int j = i + 1; j <= N; j++) {
			int d = min(abs(j - i), min(abs(X - i) + 1 + abs(j - Y), abs(Y - i) + 1 + abs(j - X)));
			ans[d]++;
		}
	}
	for (int i = 1; i < N; i++) {
		printf("%d\n", ans[i]);
	}

	return 0;
}

Measured memory_bytes: 256
N = int(input())
c = ["FizzBuzz" if n % 15 == 0 else "Fizz" if n % 3 == 0 else "Buzz" if n % 5 == 0 else n for n in range(1,N+1)]
set_c = set(c)
r = 0
for x in range(len(c)):
  if type(c[x]) == type('string'):
    continue
  else:
    r += c[x]

print(r)

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

ll f[50][50][50];
int d[50][50],n;
char s[50];

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

int main()
{
	n=rd()*2;
	for (int i=1;i<=n;i++)
	{
		scanf("%s",s+1);
		for (int j=1;j<=n;j++) d[i][j]=s[j]-'0';
	}
	if (n==2) { printf("%d\n",d[1][2]);return 0; }
	for (int i=2;i<=n;i++) f[i][i][i]=1;
	for (int len=3;len<n;len++) for (int i=2,j=i+len-1;j<=n;i++,j++) for (int k=i+1;k<j;k++)
	{
		for (int l=i;l<k;l++) for (int r=k+1;r<=j;r++)
			for (int h1=i;h1<=l;h1++) for (int h2=r;h2<=j;h2++) if (d[h1][h2])
				f[i][j][k]+=f[l+1][r-1][k]*f[i][l][h1]*f[r][j][h2];
	}
	ll ans=0;
	for (int i=2;i<=n;i++) if (d[1][i]) ans+=f[2][n][i];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 640
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] A = Console.ReadLine().Split(' ').Select(gg => int.Parse(gg)).ToArray();
            int D = A[0];
            int N = A[1];

            int R = Convert.ToInt32(Math.Pow(100, D));
            if(N == 100)
            {
                N += 1;
            }
           if(D == 0)
            {
            Console.WriteLine(N);
                return;
            }

            Console.WriteLine(R * N);
            

        }
    }
}

Measured memory_bytes: 19052
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,avx2,fma,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(0),cin.tie(0), cout.tie(0)
typedef long long ll;


ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

//#######################################


int main(){
  boost;
  
//   cout<<"start";
  ll n,m,k;
  cin>>n>>m>>k;
  ll a[n+1],b[m+1];
  ll dpa[n+1]={},dpb[m+1]={};
  for(ll i=1;i<n+1;i++){
	  cin>>a[i];
	dpa[i]=dpa[i-1]+a[i];

  }


  for(ll i=1;i<m+1;i++){
	  cin>>b[i];
	 dpb[i]=dpb[i-1]+b[i];
  }
	ll ans=0;
	ll j=m;
	for(ll i=0;i<n+1;i++){
		if(dpa[i]>k)
		break;
		while(dpb[j]>k-dpa[i])
		j--;
		ans=max(ans,j+i);
	}
	cout<<ans;
}


Measured memory_bytes: 9808
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef long double ld;

int main() {
	int N, D;
	cin >> N >> D;
	vector<vector<double>>X;
	rep(i, N) {
		vector<double>d;
		rep(j, D) {
			double x;
			cin >> x;
			d.emplace_back(x);
		}
		X.emplace_back(d);
	}
	int count = 0;
	for (int i = N - 1; 0<=i; --i) {
		for (int j = i - 1; 0<=j; --j) {
			double ans = 0;
			for (int k = 0; k < D; ++k) {
				ans += pow(X[i][k] - X[j][k], 2);
			}
			if (ceil(pow(ans, 0.5)) == floor(pow(ans, 0.5)))
				count++;
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <stdbool.h>

int main()
{
  int year;
  int year1, year2;
  bool flag = true;

  while(scanf("%d %d", &year1, &year2)!=EOF){
    if(year1 == 0 && year2 == 0) break;
    if(!flag) printf("\n");

    flag = true;
    for(year = year1; year <= year2; ++year)
      if(year != 0 && ((year%4 == 0 && year%100 != 0) || year%400 == 0)){
	printf("%d\n", year);
	flag = false;
      }

    if(flag)
      printf("NA\n");
    flag = false;
  }

  return 0;
}

Measured memory_bytes: 616
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:" ; for(const auto &xxx : v) {std::cerr << xxx << " ";} std::cerr << "\n";}
#define SHOW_MAP(v) {std::cerr << #v << "\t:" ; for(const auto &xxx : v) {std::cerr << xxx.first << " " << xxx.second << "\n";} std::cerr << "\n";}



int main() {
    using namespace std;

    int n;
    string s;

    cin >> n;

    for (int i = 0; i < n; ++i)
    {
        char in;
        cin >> in;
        s += in;
    }

    set<int> se;

    for (int len = 1; len <= 4; ++len)
    {
        for (int i = 0; i + len <= n; ++i)
        {
            auto sub = s.substr(i, len);
            se.emplace(stoi(sub));
        }
    }

    for (int i = 0; i < 10000; ++i)
    {
        if (se.find(i) == se.end()) {
            cout << i << endl;
            break;
        }
    }



    return 0;
}


Measured memory_bytes: 3284