akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;


class UnionFind{
private:
    vector<int> p,s;
    int cnt;
public:
    UnionFind(){}
    UnionFind(int N):cnt(N),s(N,1),p(N){
        iota(p.begin(),p.end(),0);
    }
    int find(int x){
        if(p[x]==x) return x;
        else return p[x] = find(p[x]);
    }
    void unite(int x,int y){
        x = find(x); y = find(y);
        if(x==y) return;
        if(s[x]>s[y]) swap(x,y);
        p[x] = y;
        s[y] += s[x];
        cnt--;
    }
    bool is_same_set(int x,int y) {return find(x)==find(y);}
    int size(int x) {return s[find(x)];}
    int compnents_number(){return cnt;}
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M;
    cin >> N >> M;
    vec<int> A(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
        A[i]--;
    }
    UnionFind uf(N);
    for(int i=0;i<M;i++){
        int x,y;
        cin >> x >> y;
        x--; y--;
        uf.unite(x,y);
    }
    int ans = 0;
    for(int i=0;i<N;i++) if(uf.is_same_set(i,A[i])) ans++;
    cout << ans << "\n";
}

Measured memory_bytes: 1408
//I am so vegetable
//#define err
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define pb push_back
#define in insert
#define er erase
#define ct count
#define ep empty
#define _for(i,a,b) for(int i = (a);i<(b);++i)
#define _rfor(i,a,b) for(int i = (a);i>(b);--i)
#define _sfor(p,st) for(auto &p:st)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
const double pi = acos(-1.0);
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
ll qpow(ll x, ll y) { ll ans = 1; for (; y > 0; y >>= 1) { if (y & 1)ans *= x; x *= x; }return ans; }
ll qpow(ll x, ll y, ll MOD) { ll ans = 1; for (; y > 0; y >>= 1) { if (y & 1)ans = ans*x%MOD; x = x*x%MOD; }return ans; }
void exgcd(ll a,ll b,ll &x,ll &y){
    if(!b){x=1;y=0;return;}
    exgcd(b,a%b,x,y);
    ll X=x;
    x=y; y=X-a/b*y;
}
ll inv(ll x, ll MOD) { return qpow(x, MOD - 2) % MOD; }
ll m_m(ll a,ll MOD){ return (a%MOD+MOD)%MOD; }


signed main() {
	//ofstream cout("E:\\acm dream\\out.txt",ios::out);
	FIO;
    #ifdef err
	double be = clock();
    #endif
    int n;cin>>n;
    int ans = 0;
    _for(i,0,n){
        int x;cin>>x;
        if((i+1)%2&&x%2)++ans;
    }
    cout<<ans;
    #ifdef err
	double en = clock();
    cout<<"time: "<<fixed<<setprecision(8)<<en-be;
    #endif
	return 0;
}

Measured memory_bytes: 3604
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#define ll long long
#define mod 1000000007
#define MN 100005
using namespace std;
struct node
{
	ll val; int pos;
	friend bool operator<(const node& a,const node& b) {return a.val>b.val;}
};
struct edge{int nex,to,wt;}e[MN<<2];
struct bian{int x,y,z;}b[MN<<1];
priority_queue <node> q;
ll dis[2][MN];
int hr[MN],gs[2][MN];
int n,m,S,T,sm,ans,pin;

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

inline void ins(int x,int y,int z) {e[++pin]=(edge){hr[x],y,z}; hr[x]=pin;}
inline void rw(int& x,int y) {x+=y; if (x>=mod) x-=mod;}
inline void rd(int& x,int y) {x-=y; if (x< 0  ) x+=mod;}

void dijk(int SS,bool g)
{
	register int i,x;
	memset(dis[g],100,sizeof(dis[g]));
	dis[g][SS]=0; gs[g][SS]=1; q.push((node){dis[g][SS],SS});
	while (!q.empty())
	{
		while (!q.empty()&&dis[g][q.top().pos]!=q.top().val) q.pop();
		if (q.empty()) break;
		for (x=q.top().pos,q.pop(),i=hr[x];i;i=e[i].nex)
			if (dis[g][x]+e[i].wt<dis[g][e[i].to])
				dis[g][e[i].to]=dis[g][x]+e[i].wt,
				gs[g][e[i].to]=gs[g][x],q.push((node){dis[g][e[i].to],e[i].to});
			else if (dis[g][x]+e[i].wt==dis[g][e[i].to])
				rw(gs[g][e[i].to],gs[g][x]);
	}
}

int main()
{
//	freopen("data.in","r",stdin);
//	freopen("data.out","w",stdout);
	register int i,x,y,z;
	n=read(); m=read(); S=read(); T=read();
	for (i=1;i<=m;++i)
		b[i].x=x=read(),b[i].y=y=read(),b[i].z=z=read(),
		ins(x,y,z),ins(y,x,z);
	dijk(S,0); dijk(T,1);
	ans=1LL*(gs[0][T])*(gs[0][T]-1)%mod;
	for (i=1;i<=n;++i)
		if (dis[0][i]+dis[1][i]==dis[0][T]&&dis[0][i]==dis[1][i])
			sm=1LL*gs[0][i]*gs[1][i]%mod,
			rd(ans,1LL*sm*(sm-1)%mod);
	for (i=1;i<=m;++i)
		if (dis[0][b[i].x]+dis[1][b[i].y]+b[i].z==dis[0][T])
		{
			if (dis[0][b[i].x]*2<dis[0][T]&&dis[1][b[i].y]*2<dis[0][T])
				sm=1LL*gs[0][b[i].x]*gs[1][b[i].y]%mod,
				rd(ans,1LL*sm*(sm-1)%mod);
		}
		else if (dis[1][b[i].x]+dis[0][b[i].y]+b[i].z==dis[0][T])
		{
			if (dis[1][b[i].x]*2<dis[0][T]&&dis[0][b[i].y]*2<dis[0][T])
				sm=1LL*gs[1][b[i].x]*gs[0][b[i].y]%mod,
				rd(ans,1LL*sm*(sm-1)%mod);
		}
	printf("%d",ans);
}

Measured memory_bytes: 11764
// https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/7/ITP1_7_B

#include <iostream>

int main()
{
    int n, x;
    int cnt = 0;

    while (1)
    {
        std::cin >> n >> x;
        if (n == 0 && x == 0)
            break;

        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= n; j++)
            {
                for (int k = 1; k <= n; k++)
                {
                    if (i + j + k == x && i!=j&&j!=k&&i!=k)
                    {
                        cnt++;
                    }
                }
            }
        }

        std::cout << cnt/6 << std::endl;
        cnt = 0;
    }
}


Measured memory_bytes: 3100
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int A[200010];
int n; 
int score(int b) {
    int ret = 0;
    rep(i, n) ret += abs(A[i] - (b + i + 1));
    return ret;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    
    rep(i, n) cin >> A[i];
    int left = -INF;
    int right = INF;
    while(left < right - 3) {
        int mid1 = (left * 2 + right) / 3;
        int mid2 = (left + right * 2) / 3;
        if(score(mid1) < score(mid2)) right = mid2;
        else left = mid1;
        //cout << left << " " << right << endl;
    }
    int ans = INF2;
    REP(i, left, right) ans = min(ans, score(i));
    cout << ans << endl;




    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef vector<bool> vb;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sq(x) ((x)*(x))
#define fo(i,n) for(int i=0;i<n;i++)
#define fp(i,k,n) for(int i=k;i<n;i++)
#define Fo(i,n) for(int i=1;i<=n;i++)
#define all(x) x.begin(),x.end()
#define deb(x) cout<<#x<<"="<<x<<"\n"
#define deb2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<"\n"
#define fi first
#define se second
const double pi = 3.14159265358979323846;
#define uni(c) (c).resize(unique(all(c))-(c).begin())
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL)
//pair <int, int> w[4] = {mp(-1, 0), mp(0, -1), mp(1, 0), mp(0, 1)};   // for matrix movement:
void cp()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}
void solve()
{
	ll n, m, k; cin >> n >> m >> k;
	vi a(n + 1, 0), b(m + 1, 0);
	ll x;
	a[0] = 0;
	b[0] = 0;
	Fo(i, n)
	{
		cin >> x;
		a[i] = x;
		if (i > 1)
			a[i] += a[i - 1];
	}
	Fo(i, m)
	{
		cin >> x;
		b[i] = x;
		if (i > 1)
			b[i] += b[i - 1];
	}
	ll j = m, ans = 0;
	if (a[1] <= k)ans = 1;
	if (b[1] <= k)ans = 1;
	for (int i = 0; i <= n; i++)
	{
		if (a[i] > k)
			break;
		while (b[j] + a[i] > k and j >= 0)
			j--;
		ans = max(ans, i + j);
	}
	cout << ans;

}
int main()
{
	fast;
	//cp();
	ll t = 1;
	//cin >> t;
	while (t--)
		solve();


	return 0;
}

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

int main() {
	int a,b,i,j,n,cur=1;
	cin >> a >> b;
	string s;
	cin >> s;
	for(i=0; i<a+b+1; i++){
		if((i!=a && s[i]=='-')||(i==a && s[i]!='-')){
			cout << "No"; return 0;
		}
	}
	
	cout << "Yes";
}

Measured memory_bytes: 256
n,y = map(int,input().split())
for a in range(y//10000+1):
    for b in range((y-10000*a)//5000+1):
        c = n-a-b
        if c >=0 and 10000*a + 5000*b + 1000*c == y:
            print(a,b,c)
            exit()
print(-1,-1,-1)

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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

int main() {
  int n;
  cin >> n;
  vi a;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a.push_back(x);
  }
  int dp[n];
  dp[0] = 0;
  dp[1] = abs(a[0] - a[1]);
  for (int i = 2; i < n; i++) {
    dp[i] =
        min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
  }
  cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1144
//C++ おまじない
#include <bits/stdc++.h>
#include <cmath>
using namespace std;

int main()
{
    // input
    int N,K;
    cin >> N >> K;
  
  	//最低は 10^100+0 最高は 10^100+N
  	//数字の個数は K+1
  	long long i=0; //個数を調べる
    long long a=0; //答え
  	long long dekai = 1000000007;
  	long long hajime=0,owari=0;
  	for (long long i=K-1; i<=N; i++) {
      //hajime = i * ( i + 1 ) / 2;
      //owari = N * (i + 1) - i * ( i + 1 ) / 2;
      //a += owari - hajime+1;
      a += (N - i) * (i + 1) + 1;
      while (a < 0 ) {
        a += dekai;
      }
    }
	cout << a % dekai <<endl;      
  	return 0;
}



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

int main(int argc, const char * argv[]) {
    
    int x,y;
    while (true) {
        cin >> x >> y;
        if(x == 0 && y== 0){
            break;
        }
        
        if(x>y){
            int t = x;
            x = y;
            y = t;
        }
        
        cout << x << " " << y << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1160
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final int t = scanner.nextInt();

        final List<Food> list = IntStream.range(0, n)
                .mapToObj(i -> new Food(scanner.nextInt(), scanner.nextInt()))
                .sorted(Comparator.comparingInt(food -> food.time))
                .collect(Collectors.toList());

        final int[][] dp = new int[n][t + 1];
        for (final int[] array : dp) {
            Arrays.fill(array, -1);
        }
        if (list.get(0).time < t) {
            dp[0][list.get(0).time] = list.get(0).deliciousness;
        } else {
            dp[0][t] = list.get(0).deliciousness;
        }
        dp[0][0] = 0;
        for (int i = 1; i < n; i++) {
            System.arraycopy(dp[i - 1], 0, dp[i], 0, t + 1);
            final Food food = list.get(i);
            for (int j = 0; j < t; j++) {
                if (dp[i - 1][j] < 0) {
                    continue;
                }
                if (j + food.time < t) {
                    dp[i][j + food.time] = Math.max(dp[i][j + food.time], dp[i - 1][j] + food.deliciousness);
                } else {
                    dp[i][t] = Math.max(dp[i][t], dp[i - 1][j] + food.deliciousness);
                }
            }
        }

        int max = 0;
        for (final int value : dp[n - 1]) {
            max = Math.max(max, value);
        }

        System.out.println(max);
    }

    private static class Food {
        final int time;
        final int deliciousness;

        Food(final int time, final int deliciousness) {
            this.time = time;
            this.deliciousness = deliciousness;
        }
    }
}


Measured memory_bytes: 69236
#include <iostream>
#include <vector>

using namespace std;

#define pb push_back
#define mp make_pair
#define ld long double
#define li long long int
int main()
{
    li x, N; cin >> x >> N;
    vector<bool> A(110, true); li ans = 0;
    for (int i = 0; i < N; i++)
    {
        li y; cin >> y; A[y] = false;

    }
    for (int i = 1; i <= 105; i++)
    {
        if (A[i] && (abs(ans - x) > abs(i - x)))
            ans = i;
    }
    cout << ans;
}


Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <bitset>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <string>
#include <algorithm>
#include <cmath>
#include <limits>

using namespace std;
using ll=long long;
using vint=vector<int>;
using pint=pair<int,int>;

const double EPS = 1e-9;
const int inf = numeric_limits<int>::max();

#define rep(i,n) for(int i=0;i<int(n);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,i,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl

void solve(){
	int N, Y;
	cin >> N >> Y;
	for(int i = 0; i < N+1; i++){
		for(int j = 0; j < N+1; j++){
			int k = N - i - j;
			if(10000 * i + 5000 * j + 1000 * k == Y && k >= 0){
				printf("%d %d %d\n", i, j, k);
				return;
			}
			if(10000 * i + 5000 * j > Y)
				break;
		}
		if(10000 * i > Y)
			break;
	}
	printf("-1 -1 -1\n");
}

int main(){
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
     
    int main(void) {
        int i = 0;
        char s[100];
        scanf("%s", &s);

        while(s[i] != '\0'){
            if(s[i] < 120){
                s[i] = s[i] + (120 - s[i]);
            }else{
                s[i] = s[i] - (s[i] - 120);
            }
            i++;
        } 

        printf("%s",s);
        return 0;
     
    }

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

int main() {
	int q, query, x, L, R;
	cin >> q;
	multiset<int> S;
	for (int i = 0; i < q; ++i) {
		cin >> query;
		if (0 == query) {
			cin >> x;
			S.insert(x);
			cout << S.size() << endl;
		}
		else if (1 == query) {
			cin >> x;
			cout << S.count(x) << endl;
		}
		else if (2 == query) {
			cin >> x;
			S.erase(x);
		}
		else {
			cin >> L >> R;
			for (multiset<int>::iterator i = S.lower_bound(L); i != S.upper_bound(R); ++i) cout << *i << endl;
		}
	}
}


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

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

using namespace std;

int main(){
  int N,A,B;
  string s;
  cin >> N >> A >> B;
  cin >> s;
  int a=0,b=0;
  rep(i,N) {
    if( s[i] == 'a' ) {
      if( a + b < A + B ) {
      	puts("Yes");
	++a;
      } else {
	puts("No");
      }
    } else if( s[i] == 'b' ) {
      if( a + b < A + B ) {
	if( b < B ) {
	  puts("Yes");
	  ++b;
	} else {
	  puts("No");
	}
      } else {
	puts("No");
      }
    } else {
      puts("No");
    }
  }
  return 0;
}


Measured memory_bytes: 896
import numpy as np

A,B,H,M = map(int,input().split())
m = H * 60 + M
short_ang = m * 0.5
long_ang = m * 6.
Ang = abs(long_ang - short_ang)
C = np.sqrt(A ** 2 + B ** 2 - 2*A*B*np.cos(Ang*np.pi/180))
print(C)

Measured memory_bytes: 27188
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {
    int h,w;
    cin >> h >> w;
    vector<string> c(h);
    rep(i,h)cin >> c[i];
    rep(i,h){
        cout << c[i] << "\n" << c[i] << "\n";
    }
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lli;
 
const lli INF = 1LL<<60;
const lli MAXM = 13;
const lli MAXW = 13;
 
lli M, W;
lli bm[MAXM], bw[MAXW];
lli dp[MAXM][1<<MAXW];
 
lli f(lli bm, lli bw) {
  return llabs(bm - bw) * (llabs(bm - bw) - 30LL) * (llabs(bm - bw) - 30LL);
}
 
int main() {
  while(cin >> M >> W && (M|W)) {
    for(lli i = 0; i < M; ++i) cin >> bm[i];
    for(lli i = 0; i < W; ++i) cin >> bw[i];
    fill(dp[0], dp[MAXM], -INF);
    dp[0][0] = 0;
    for(lli i = 0; i < M; ++i) {
      for(lli j = (1<<W)-1; j >= 0; --j) {
        dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
        for(lli k = 0; k < W; ++k) {
          if(j >> k & 1) {
            dp[i+1][j] = max(dp[i+1][j], dp[i][j-(1<<k)] + f(bm[i], bw[k]));
          }
        }
      }
    }
    lli res = 0;
    for(lli j = (1<<W)-1; j >= 0; --j) {
      res = max(res, dp[M][j]);
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1988
package main

import (
    "bufio"
    "fmt"
    "os"
)

//大量のデータを標準入力から受け取る時はnextLineを使うようにすると高速
var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
    sc.Scan()
    return sc.Text()
}

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

	if (a*b%2) == 0 {
		fmt.Println("Even")
	}else{
		fmt.Println("Odd")
	}
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    ll minus = 0;
    ll min_val = 9999999999;
    ll sum = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(a[i]<0){minus++;}
        min_val = min(min_val, abs(a[i]));
        sum += abs(a[i]);
    }
    if(minus%2==0){
        cout << sum << endl;
    }else{
        cout << sum - 2*min_val << endl;
    }

    return 0;
}


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

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

    int N;
    cin >> N;
    ll ans = 1;
    for (int i = 0; i < N; ++i) {
        ll T;
        cin >> T;
        ans = ans / __gcd(ans, T) * T;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	char class[9][16];
	int morning[9];
	int after[9];
	int i;

	for (i = 0; i < 9; i++) {
		scanf("%s %d %d", class[i], &morning[i], &after[i]);
	}

	for (i = 0; i < 9; i++) {
		printf("%s %d %d\n", class[i], morning[i] + after[i]
							 , morning[i] * 200 + after[i] * 300);
	}

	return 0;
}

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


public class Main{

     public static void main(String []args){
        Scanner scanner = new Scanner(System.in);
        String s1 = scanner.next();
        
        char[] c= s1.toCharArray();
        List<Integer> list = new ArrayList<>();
        
        
        for(int i=0;i<s1.length();i++)
        {
            if(c[i]!='B')
            list.add((int)c[i]-'0');
            
            else{
                if(list.size()>0)
            list.remove(list.size()-1);
            }
            
            
            
        }
        
        
         for(int i=0;i<list.size();i++)
         System.out.print(list.get(i));
        
        
        
        
        
        
        //System.out.println()
        //for(int i=0;i<n;i++)
     }
}

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

int main() {
    string str;
    cin >> str;
    int n=114514;
    for(int i=0;i<str.size()-2;i++) n=min(n,abs(753-atoi(str.substr(i,3).c_str())));
    cout << n << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main(){
  int ans;
  string s;
  cin >> s;
  for(int i = 0; i < 3; i++){
    if(s[i] == '1'){
      ans += 1;
    }
  }
  cout << ans << endl;
  
  return 0;
}

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

#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define RS(x) rsort(x.begin(),x,end()))
#define REVE(x) reverse(x.begin(), x.end())
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
#define pob pop_back
#define vint(v,n) vector<int> v(n); REP(i,n) scanf("%d", &v[i]);
int INF = 1e9 + 1;
int MOD = 1e9+7;
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
unsigned GetDigit(unsigned num){
    return log10(num)+1;
}

signed main(){
    int k,x;
    cin >> k >> x;
    if(k*500>=x){
    cout << "Yes";
    }else{
        cout << "No";
    }
    
             }

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
    //static List<string> str = new List<string>();
    static void Main(string[] args)
    {
        // 入力
        string[] input = Console.ReadLine().Split(' ');
        int H = int.Parse(input[0]);
        int W = int.Parse(input[1]);

        // Xも含めて、座標をリスト化する
        List<List<int>> list = new List<List<int>>();
        for(int i=0; i<H; i++)
        {
            input = Console.ReadLine().Split(' ');
            List<int> row = new List<int>();
            for(int j=0; j<W; j++)
            {
                row.Add(int.Parse(input[j]));
            }
            list.Add(row);
        }

        // 右 or 下にコインを移動させる
        List<string> ret = new List<string>();
        string str = "";
        for (int i = 0; i < H; i++ )
        {
            for(int j=0; j<W; j++)
            {
                //Console.WriteLine(i + " " + j);
                if(list[i][j]%2 == 0)
                {
                    continue;
                }
                else
                {
                    // 右が奇数 or 下がもう無いなら移動する
                    if((j+1<W && list[i][j+1]%2 == 1) || (j+1<W && i+1 >= H))
                    {
                        str = (i+1) + " " + (j+1) + " " + (i+1) + " " + (j + 2);
                        list[i][j] -= 1;
                        list[i][j + 1] += 1;
                        ret.Add(str);
                    }
                    else if(i+1 < H)
                    {
                        // 下に移動する
                        str = (i+1) + " " + (j+1) + " " + (i + 2) + " " + (j+1);
                        list[i][j] -= 1;
                        list[i + 1][j] += 1;
                        ret.Add(str);
                    }
                }
            }
        }

        Console.WriteLine(ret.Count);
        foreach(var s in ret)
        {
            Console.WriteLine(s);
        }
        //if (ret)
        //    Console.WriteLine("Yes");
        //else
        //    Console.WriteLine("No");
    }

    static int calculationGCD(int a, int b)
    {
        if(a%b == 0)
        {
            return b;
        }
        else
        {
            return calculationGCD(b, a % b);
        }
    }

}

Measured memory_bytes: 28820
#include<iostream>
using namespace std;
#define MAX 100000
typedef long long llong;

int n, k;
llong T[MAX];

int check(llong p) {
	int i=0;
	for(int j = 0; j < k; j++ ) {
		llong sum = 0;
		while( sum + T[i] <= p) {
			sum += T[i];
			i++;
			if(i == n ) return n;
		}
	}
	return i;
}

int solve() {
	llong left = 0;
	llong right = 100000 * 10000;
	llong mid; 
	while(left <= right) {
		mid = left + (right - left) / 2;
		int v = check(mid);
		if(v >= n) right = mid -1;
		else left = mid + 1;
	}
	return left;
}

main() {
	cin >> n >> k;
	for( int i = 0; i < n; i++) cin >> T[i];
	llong ans = solve();
	cout << ans << endl;
}

 

Measured memory_bytes: 3852
N, M = map(int, input().split())
ab_list = []
for _ in range(M):
    a, b = map(int, input().split())
    ab_list.append((a, b))

ab_list.sort(key=lambda x: x[1])

ans = 0
pre_x = -1
for a, b in ab_list:
    # 直前の切断で条件が満たせる場合
    if pre_x >= a:
        continue
    # 新たに切断する必要がある場合
    else:
        pre_x = b - 1
        ans += 1
print(ans)


Measured memory_bytes: 87060
#include<stdio.h>
int abs(int);
int main(){
    int h,w;
    char ppp;
    scanf("%d %d\n",&h,&w);
    char c[h][w];
    int aaa[h*w][2];
    int a=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            scanf("%c",&c[i][j]);
            if(c[i][j]=='B'){
                aaa[a][0]=i;
                aaa[a][1]=j;
                a++;
            }
        }
        scanf("%c",&ppp);
    }
    int aa=0;
    for(int i=0;i<a-1;i++){
        for(int j=i+1;j<a;j++){
            int bb=0;
            bb+=abs(aaa[i][0]-aaa[j][0]);
            bb+=abs(aaa[i][1]-aaa[j][1]);
            if(aa<bb) aa=bb;
        }
    }
    printf("%d\n",aa);
    return 0;
}

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


Measured memory_bytes: 2104
#!/usr/bin/env python3

N, A, B, C = (int(_) for _ in input().split())
status = [A, B, C]
name = ['A', 'B', 'C']
sel_num = {'AB': (0, 1),
           'BC': (1, 2),
           'AC': (2, 0)}

S = []
for n in range(N):
    S.append(sel_num[input()])

if A + B + C > 2:
    difficult = False
else:
    difficult = True

ret = []
try:
    for i in range(len(S)):
        a1, a2 = S[i]
        if status[a2] < status[a1]:
            a1, a2 = a2, a1
        if (difficult and
            (status[a1] == 1) and
            (status[a2] == 1) and
            (i + 1 < len(S)) and
            S[i] != S[i + 1]):
            b1, b2 = S[i + 1]
            if a2 == b1:
                a1, a2 = a2, a1
        ret.append(name[a1])
        status[a1] += 1
        status[a2] -= 1
        assert status[a2] >= 0
except:
    print('No')
    exit(0)

print('Yes')
for r in ret:
    print(r)


Measured memory_bytes: 10836
#include<stdio.h>
int main(void){
	long n,a[10000],i,Max=-1000001,Min=1000001,Sum=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%ld",&a[i]);
		if(a[i]>Max){
			Max=a[i];
		}
		if(a[i]<Min){
			Min=a[i];
		}
		Sum+=a[i];
	}
	printf("%ld %ld %ld\n",Min,Max,Sum);
	return 0;
}

Measured memory_bytes: 680
#include<bits/stdc++.h>
using namespace std;
double dp[3001][3001];
double p[3001];
double probability(int index,int k,int n){
    if(index==n)
    return 1;
    
    if(dp[index][k]!=-1)
    return dp[index][k];

   double H,T;
   H=probability(index+1,k,n)*p[index];
   if(k!=0)
   T=probability(index+1,k-1,n)*(1.0-p[index]);
   else{
       T=0;
   }
   dp[index][k]=H+T;
  // cout<<index<<" "<<H<<" "<<T<<endl;
   return dp[index][k];

}
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>p[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++)
        dp[i][j]=-1;
    }
    double ans=probability(0,n/2,n);
    cout<<setprecision(12)<<ans<<endl;


}


Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
 
  vector<double> A, B;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    A.push_back(a);
    B.push_back(b);
  }
 
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
  int ans = 0;
  if (N%2!=0) {
    int l = A[N/2];
    int r = B[N/2];
    ans = r - l + 1;
  } else {
    double l = (A[N/2-1]+A[N/2])/2;
    double r = (B[N/2-1]+B[N/2])/2;
    ans = 2*(r - l) + 1;
  }
 
  cout << ans << endl;
 
  return 0;
}

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

int main() {
  int N,K; cin >> N >> K;
  int sum=0;
  vector<int> vec(N);
  for(int i=0; i < N; ++i) {
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  for(int i=0; i < K; ++i) {
    sum += vec.at(i);
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

#ifdef DEBUG
    #define IFD if(true)
#else
    #define IFD if(false)
#endif

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


long long cnt(long long A, long long B, long long d)
{
    long long l, r;
    if(A % d == 0) {
        l = A;
    } else {
        l = (A / d + 1) * d;
    }
    if(B % d == 0) {
        r = B;
    } else {
        r = (B / d) * d;
    }
    return max((r - l) / d + 1, (long long)0);
}

int main()
{
    long long A, B, C, D, ans;
    cin >> A >> B >> C >> D;
    ans = B - A + 1;

    ans -= cnt(A, B, C) + cnt(A, B, D) - cnt(A, B, C * D / gcd(C, D));

    cout << ans << endl;

    return 0;
}


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

#define F first
#define S second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()

using namespace std;

typedef long long llong;

const int MXN = (int)1e6 + 7;
const int MOD = (int)1e9 + 7;
const int N = (int)1e3 + 7;

int n, a[MXN], k;
llong dp[MXN];

int main()
{
  cin >> n >> k;
  for(int i = 1; i <= n; i++){
    cin >> a[i];
    dp[i] = MOD;
  }
  dp[1] = 0;
  for(int i = 2; i <= n; i++){
    for(int j = i - 1; j >= max(1, i - k); j--){
      dp[i] = min(dp[i], abs(a[i] - a[j]) + dp[j]);
    }
  }
  /*for(int i = 1; i <= n; i++){
    cout << dp[i] << ' ';
  }*/
  cout << dp[n];
  return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int N, T;
  cin >> N;
  T=0;
  vector<int> A(N);
  for (int i=0; i<N; i++) {
    cin >> A[i];
  }
  for (int j=0; j<N; j++) {
    if (A[j]%2==1) {
      T=T+1;
    }
    else {
      if (A[j]%3==0||A[j]%5==0) {
        T=T+1;
      }
    }
  }
  if (T==N) {
    cout << "APPROVED" << endl;
  }
  else {
    cout << "DENIED" << endl;
  }
}

Measured memory_bytes: 3588
#include<stdlib.h>
#include<iostream>
using namespace std;

int main(){
  int a, b;
  cin >> a >> b;
  if(a % 2 == 0 || b % 2 == 0){
    cout << "Even" << endl;
  } else {
    cout << "Odd" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 31;
// clang-format on

char a, b, c, d;
int A, B, C, D;

const char opr[] = {'+', '-'};

int atoi(char cc) { return cc - '0'; }
void ops(int n, vector<char> &op)
{
  for (int i = 0; i < 3; i++) {
    op[i] = opr[n & 1];
    n = n >> 1;
  }
}

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> a >> b >> c >> d;
  A = atoi(a), B = atoi(b), C = atoi(c), D = atoi(d);
  vector<int> arr = {A, B, C, D};
  vector<char> op(3);

  for (int i = 0; i < (1 << 3); i++) {
    ops(i, op);
    int sum = arr[0];
    for (int i = 0; i < 3; i++) {
      if (op[i] == '+') {
        sum += arr[i + 1];
      }
      else {
        sum -= arr[i + 1];
      }
    }
    if (sum == 7) {
      REP(i, 3) printf("%d%c", arr[i], op[i]);
      printf("%d=7\n", arr[3]);
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n; cin>>n;
    vector <int> d(n);
    for(int i=0;i<n;i++){
        cin>>d[i];
    }
    sort(d.begin(),d.end());
    int x = (d.size() /2) -1;
    cout<<d[x+1] - d[x] <<endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int a,b;
	while((scanf("%d%d",&a,&b))!=EOF) 
	{
		long long int c,x,y;
		x=a;
		y=b;
		c=a%b;
		while(c!=0)
		{
			a=b;
			b=c;
			c=a%b;
		}
		long long int k;
		k=(x*y)/b;
		cout<<b<<" "<<k<<endl;
	}
	return 0;
}


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

using namespace std;

int main() {
    int n, m;

    cin >> n >> m;

    int x, y;
    vector<int> indeg(n + 1);
    vector<vector<int>> to(n + 1);

    for(int i = 0; i < m; ++i) {
        cin >> x >> y;
        ++indeg.at(y);
        to.at(x).push_back(y);
    }

    vector<int> dp(n + 1);
    queue<int> q;

    for(int i = 1; i <= n; ++i) {
        if(indeg.at(i) == 0) {
            q.push(i);
        }
    }

    int qf;

    while(!q.empty()) {
        qf = q.front();
        q.pop();
        for(int qft: to.at(qf)) {
            dp.at(qft) = max(dp.at(qft), dp.at(qf) + 1);
            if(--indeg.at(qft) == 0) q.push(qft);
        }
    }

    int ans = 0;

    for(int i = 1; i <= n; ++i) {
        ans = max(ans, dp.at(i));
    }

    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 6528
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int a[3];
	for(int i=0;i<3;i++){
		cin>>a[i];
	}
	sort(a,a+3);
	int m=a[2]*10+a[1]+a[0];
	cout<<m<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	
	int n,b,f,r,v;
	int h,c,i,j;
	int a[4][3][10]={0};
	scanf("%d",&n);
	
	for(h=0;h<n;h++){
		scanf("%d %d %d %d",&b,&f,&r,&v);
		a[b-1][f-1][r-1]+=v;
	}
	
	for(c=0;c<4;c++){
		for(i=0;i<3;i++){
			for(j=0;j<10;j++){
				printf(" %d",a[c][i][j]);
			}
			printf("\n");
		}
		if(c!=3){
			printf("####################\n");
		}
	}
	return 0;
}


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

int n, q, t, x, v, l, r;
int op(int a, int b) {
	return max(a, b);
}
int e() {
	return -1;
}
bool f(int i) {
	return i < v;
}

int main() {
	cin >> n >> q;
	vector<int> a(n);
	for (int& i : a) cin >> i;
	atcoder::segtree<int, op, e> seg(a);
	while (q--) {
		cin >> t;
		if (t == 1) {
			cin >> x >> v;
			seg.set(x - 1, v);
		} else if (t == 2) {
			cin >> l >> r;
			cout << seg.prod(l - 1, r) << endl;
		} else {
			cin >> x >> v;
			cout << seg.max_right<f>(x - 1) + 1 << endl;
		}
	}
}

Measured memory_bytes: 6152
n=int(input())
C=[]
S=[]
F=[]
for i in range(n-1):
    c,s,f=map(int,input().split())
    C.append(c)
    S.append(s)
    F.append(f)
for i in range(n):
    t=0
    for j in range(i,n-1):
        if t<S[j]:
            t=S[j]
        elif t%F[j]==0:
            t=t
        else:
            t=t+F[j]-t%F[j]
        t+=C[j]
    print(t)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()

void solve();

signed main () {
    clock_t beg = clock();
    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif
    int t = 1; 
    // cin >> t;    
    int tt = t;
    while (t--) { 
        solve();
    }
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
    return 0;
}
// C(i + j, i) where i and j have limits <= n and <= m
// C(i + m + 1, i + 1)
#define ll long long

const ll mod = 1e9 + 7; // change to something else

ll euclid(ll a, ll b, ll &x, ll &y) {
	if (b) { ll d = euclid(b, a % b, y, x);
		return y -= a/b * x, d; }
	return x = 1, y = 0, a;
}
struct Mod {
	ll x;
	Mod(ll xx = 0) : x(xx) {}
	Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
	Mod operator-(Mod b) { return Mod((x - b.x + mod) % mod); }
	Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
	Mod operator/(Mod b) { return *this * invert(b); }
	Mod invert(Mod a) {
		ll x, y, g = euclid(a.x, mod, x, y);
		assert(g == 1); return Mod((x + mod) % mod);
	}
	Mod operator^(ll e) {
		if (!e) return Mod(1);
		Mod r = *this ^ (e / 2); r = r * r;
		return e&1 ? *this * r : r;
	}
};

const int N = 2e6 + 55;
Mod fac[N], ifac[N]; 

Mod c (int n, int r) {
	if (r > n)
		return Mod(0);
	Mod ans = (fac[n] * ifac[r]) * ifac[n - r];
	return ans;
} 

Mod get (int n, int m) {
	Mod ans = 0;
	rep(i, 0, n + 1) {
		ans = ans + c(i + m + 1, i + 1);
	}
	return ans;
}
void solve() {
    fac[0] = 1;
    rep(i, 1, N)
    	fac[i] = fac[i - 1] * Mod(i);
    ifac[N - 1] = Mod(1)/Mod(fac[N - 1]);
    for (int i = N - 2; i >= 0; --i) {
    	ifac[i] = (ifac[i + 1] * Mod(i + 1));
    }
    int r1, r2, c1, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    Mod ans = get(r2, c2) - get(r1 - 1, c2) - get(r2, c1 - 1) + get(r1 - 1, c1 - 1);
    cout << ans.x;
}   

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

int main(int argc, char *argv[]){
  int N;
  cin>>N;
  vector<int> A(N+2,0);
  for(int i=1; i<=N; i++){
    int a;
    cin>>a;
    A[i]=a;
  }
  int sum=0;
  for(int i=1; i<=N+1; i++){
    sum+=abs(A[i]-A[i-1]);
  }
  for(int i=1; i<=N; i++){
    int res=(sum+abs(A[i+1]-A[i-1]))-abs(A[i]-A[i-1])-abs(A[i]-A[i+1]);
    cout<<res<<endl;
  }
}
  

Measured memory_bytes: 1664
N = int(input())
A = [[] for i in range(N)]
for n in range(N-1):
    a,b = map(int, input().split())
    A[a-1].append(b-1)
    A[b-1].append(a-1)
#print(A)


from collections import deque
def dfs(node):
    st = deque()
    push, pop = st.append, st.popleft
    push(node)
    cnt = [0]*N
    cnt[node] = 1
    while st:
        now = pop()
        for n in A[now]:
            if cnt[n] == 0:
                push(n)
            cnt[n] = 1
    return now

def dfs_L(node):
    st = deque()
    push, pop = st.append, st.popleft
    push([node,0])
    cnt = [0]*N
    cnt[node] = 1
    L_list = []
    while st:
        [now,L] = pop()
        L_list.append(L)
        for n in A[now]:
            if cnt[n] == 0:
                push([n,L+1])
            cnt[n] = 1
    return max(L_list)
            

step1 = dfs(0)
length = dfs_L(step1)
if length%3 == 1:
    print('Second')
else:
    print('First')

Measured memory_bytes: 116556
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static System.Array;

class Program
{
	public static void Main()
	{
		var n = ReadLine();
		var r = string.Concat(n.Reverse());
		if(n == r)
		{
			WriteLine("Yes");
		}
		else
		{
			WriteLine("No");
		}
	}
}


Measured memory_bytes: 18532
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

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

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    powers5 = dict()
    for i in range(-200, 200):
        powers5[i] = math.pow(i, 5)
    x = I()
    for i_key in powers5.keys():
        for j_key in powers5.keys():
            if powers5[i_key] - powers5[j_key] == x:
                print(i_key, j_key)
                return

main()


Measured memory_bytes: 10968
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    ll n,k;
    cin >> n >> k;
    vector<int>a(n);
    rep(i,n)cin >> a[i];
    rep(i,n)a[i]--;
    vector<int>ch(n);
    rep(i,n)ch[i] = 0;
    ch[0] = 1;
    int cntNow = 0;
    ll cnt = 0;
    while(1){
        if(ch[cntNow]==2)break;
        cntNow = a[cntNow];
        ch[cntNow]++;
        cnt++;
    }
    ll repcnt = 0;
    rep(i,cnt){
        if(ch[cntNow]==3)break;
        cntNow = a[cntNow];
        ch[cntNow]++;
        repcnt++;
    }

    cnt -= repcnt;
    if(k<cnt){
        int ans = 0;
        rep(i,k)ans = a[ans];
        cout << ans+1 << endl;
    }else{
        k-=cnt;
        k%=repcnt;
        rep(i,k){
            cntNow = a[cntNow];
        }
        cout << cntNow+1 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 4848
n=int(input())
A=list(map(int,input().split()))
dp=[0]*(10**6+1)
for i in A:
  dp[i]+=1
for i in range(1,10**6+1):
  if dp[i]>0:
    for j in range(2*i,10**6+1,i):
      dp[j]=0
print(dp.count(1))      

Measured memory_bytes: 32180
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>

using namespace std;

inline int gcd(int a, int b) {
    if (a == 0) return b;
    return gcd(b % a, a);
}

int gcd_arr(vector<int> arr) {
    int result = arr[0];
    for (int i = 1; i < arr.size(); ++i)
        result = gcd(arr[i], result);
    return result;
}

int main() {
    int N, X;
    cin >> N >> X;
    vector<int> diffs(N);
    int x;
    for (int i = 0; i < N; ++i) {
        cin >> x;
        diffs[i] = abs(X-x);
    }
    cout << gcd_arr(diffs) << endl;
    return 0;
}


Measured memory_bytes: 1024
'use strict'
const lines = require('fs').readFileSync(0, 'utf8').split('\n')
const str = lines[0]
const n = str.length - 1;
const dfs = (i, sum, order) => {
  if (i === n) return eval(order + str[n]);

  sum += dfs(i + 1, sum, order + str[i] + '+') + dfs(i + 1, sum, order + str[i]);

  return sum;
}

const ans = dfs(0, 0, '');
console.log(ans);

Measured memory_bytes: 7756
from numpy import array, int64, minimum

def main():
    N, K, *I = map(int, open(0).read().split())

    A, F = array(I[:N], int64), array(I[N:], int64)
    A.sort()
    F.sort()
    F = F[::-1]

    sum_A = A.sum()

    ng, ok = -1, 10 ** 12
    while ng + 1 < ok:
        mid = (ok + ng) // 2
        if (sum_A - minimum(A, mid // F).sum()) <= K:
            ok = mid
        else:
            ng = mid

    print(ok)


if __name__ == '__main__':
    main()


Measured memory_bytes: 53188
N = str(input())
listed_N = list(N)

list_map  = list(map(int, listed_N))
 
if list_map[0]<list_map[1]:
    print("{}{}{}".format(list_map[0]+1,list_map[0]+1,list_map[0]+1))
elif list_map[0] == list_map[1]:
    if list_map[1]<list_map[2]:
        print("{}{}{}".format(list_map[0]+1,list_map[0]+1,list_map[0]+1))
    else:
        print("{}{}{}".format(list_map[0],list_map[0],list_map[0]))
else:
    print("{}{}{}".format(list_map[0],list_map[0],list_map[0]))
    

Measured memory_bytes: 3064
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

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

int main()
{
  ll x, y, a, b, i;
  scanf("%lld%lld", &x, &y);
  a = x;
  b = a + a;
  for (i = 0; b <= y; i++)
  {
    ll tmp = a;
    a = b;
    b = b + b;
  }
  printf("%lld\n", i + 1);
  return 0;
}	

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=998244353;
ll s(ll n){
    ll res=0;
    while(n){
        res+=n%10;
        n/=10;
    }
    return res;
}
signed main(){
    ll k;cin>>k;
    ll now=1;
    ll ans=1;
    while(k){
        cout<<ans<<endl;
        ll c=ans+now;
        if(c-now*s(c)<=0){
            ans=c;
        }else{
            while(c-now*s(c)>0){
                now*=10;
            }
            ans+=now;
        }
        k--;
    }
}

Measured memory_bytes: 3568
#include <cstdlib>

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
	int N,K;
	ll ret;
	cin >> N >> K;

	
	ret = K;
	if (N > 2)
	{
		rep(i, (N - 1))
		{
			ret *= (K - 1);
		}
	}

	cout << ret << endl;
	return 0;
}

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

int main(int argc, const char * argv[])
{
    string str;
    getline(cin, str);
    for (int i = 0; i < str.size(); i++) {
        str[i] = toupper(str[i]);
    }
    cout << str << endl;
    return 0;
}

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

ans = N
for i in range(N+1):
    cc = 0
    num_6 = i
    num_9 = N - i
    while num_6 > 0:
        cc += (num_6 % 6)
        num_6 //= 6
    while num_9 > 0:
        cc += (num_9 % 9)
        num_9 //= 9
    if ans > cc:
        ans = cc

print(ans)


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

using namespace std;

#define pii pair<int,int>
#define ll long long
#define s second
#define f first

const int MAX_N=2*10e5+5;
ll n,k,a[MAX_N],s,mx=-1;

int main(){
  cin >> k >> n;
  for(int i=0;i<n;++i){
    cin >> a[i];
    if(i){s+=a[i]-a[i-1];mx=max(a[i]-a[i-1],mx);}
  }
  s+=a[0]+k-a[n-1];
  s-=max(mx,a[0]+k-a[n-1]);
  cout << s;
  return 0;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<vin> vvin;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())
const int INF=1e9+7;
int main(){
  int n,x,y;
  cin>>n>>x>>y;
  vin count(n);
  vvin d(n,vin(n));//iからjまでの距離
  REP(i,n){
    REP(j,i){
      if(i+1<=x||y<=j+1){d[i][j]=i-j;}
      else{d[i][j]=min(i-j,abs(y-i-1)+1+abs(x-j-1));}
      count[d[i][j]]++;
    }
  }
  
  REP(i,n-1){
    cout<<count[i+1]<<endl;
  }
}

Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
#define vll vector<ll>
constexpr ll INF = 1e9 + 7;
constexpr ll MOD = 1e9 + 7;

template<typename T>
void vecin(vector<T>& v, int n = 0){
    if (n == 0)
        n = v.size();
    for (int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
}
template <typename T>
void vecout(vector<T> &v, int n = 0)
{
    if (n == 0)
        n = v.size();
    for (int i = 0; i < n-1; ++i)
    {
        cout << v[i] << " ";
    }
    cout << v[n - 1] << endl;
}
void print(string s){
    cout << s << endl;
}

int main()
{
    ciosup;
    int n;
    cin >> n;
    vint a(n);
    vecin(a);
    double ans = 0;
    REP(i,n){
        ans += 1. / (a[i] * 1.);
    }
    ans = 1. / ans;
    cout.precision(8);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
#define llMAX 9223372036854775807
#define llMIN -9223372036854775808
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;

int main(){
  ll ans=0;
  cin >> n >> k>>x;

  cout<<x<<" "<<n<<" "<<k<<" "<<endl;
  return 0;
}




Measured memory_bytes: 256