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

class UnionFindTree {
private:
  vector<int> per, rank;
public:
  void init(int n) {
    per.resize(n,0);
    rank.resize(n,0);
    for (int i=0; i<n; i++) {
      per[i]=i;
      rank[i]=0;
    }
  }
  int find(int x) {
    if (x==per[x]) {
      return x;
    } else {
      per[x]=find(per[x]);
      return per[x];
    }
  }
  void unite(int x,int y) {
    x=find(per[x]);
    y=find(per[y]);
    if (x==y) {
      return ;
    }
    if (rank[x]<rank[y]) {
      per[x]=y;
    } else {
      per[y]=x;
      if (rank[x]==rank[y]) {
        rank[x]++;
      }
    }
  }
  bool same(int x,int y) {
    x=find(x);
    y=find(y);
    return x==y;
  }
};
int main() {
  int n, q;
  cin >> n >> q;
  UnionFindTree S;
  S.init(n);
  while (q--) {
    int com, x, y;
    cin >> com >> x >> y;
    if (!com) {
      S.unite(x,y);
    } else {
      printf("%d\n",S.same(x,y));
    }
  }
  return 0;
}

Measured memory_bytes: 3256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;



//??\???
#define MAX_Y 1000
#define MAX_X 1000
#define MAX_K 100000

int M;  //???????????????
int N;  //??±?\??????????
int K;  //??????????±??????????????????°

int A[MAX_K], B[MAX_K], C[MAX_K], D[MAX_K];

int main() {
  ios::sync_with_stdio(false);

  cin >> M >> N >> K;

  char map[M][N];

  for(int i = 0; i < M; i++) {
    for(int j = 0; j < N; j++) {
      cin >> map[i][j];
    }
  }

  for(int k = 0; k < K; k++) {
    cin >> A[k] >> B[k] >> C[k] >> D[k];
  }


  // cumulative sum
  int csJ[M+1][N+1];
  int csO[M+1][N+1];
  int csI[M+1][N+1];
  memset(csJ, 0, sizeof(csJ));
  memset(csO, 0, sizeof(csO));
  memset(csI, 0, sizeof(csI));
  for(int i = 0; i < M; i++) {
    for(int j = 0; j < N; j++) {
      csJ[ i+1 ][ j+1 ] = csJ[ i ][ j+1 ] + csJ[ i+1 ][ j ] - csJ[ i ][ j ] + ( map[i][j] == 'J');
      csO[ i+1 ][ j+1 ] = csO[ i ][ j+1 ] + csO[ i+1 ][ j ] - csO[ i ][ j ] + ( map[i][j] == 'O');
      csI[ i+1 ][ j+1 ] = csI[ i ][ j+1 ] + csI[ i+1 ][ j ] - csI[ i ][ j ] + ( map[i][j] == 'I');
    }
  }


  int sumJ = 0, sumO = 0, sumI = 0;
  for(int i = 0; i < K; i++) {
    int a = A[i], b = B[i], c = C[i], d = D[i];
    sumJ = csJ[c][d] - csJ[a-1][d] - csJ[c][b-1] + csJ[a-1][b-1];
    sumO = csO[c][d] - csO[a-1][d] - csO[c][b-1] + csO[a-1][b-1];
    sumI = csI[c][d] - csI[a-1][d] - csI[c][b-1] + csI[a-1][b-1];
    cout << sumJ << " " << sumO << " " << sumI << endl;
  }


 return 0;
}

Measured memory_bytes: 17280
n = int(input())
li = list(map(int,input().split()))
o1 = (sum(li))//n
o2 = o1 + 1
li1 = []
li2 = []
for i in range(n):
    li1.append((int(li[i]-o1))**2)
for j in range(n):
    li2.append((int(li[j]-o2))**2)
if sum(li1) >= sum(li2):
    print(sum(li2))
else:
    print(sum(li1))  

Measured memory_bytes: 38256
#include <iostream>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>

using namespace std;

#define MOD 998244353
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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



class RmqTree {
private:
	ll _find(ll a, ll b, ll k, ll l, ll r) {
		//区間[l,r)の最小値を持つk番目のノードを探索
		if (r <= a || b <= l)return INF;    // 交差しない
		if (a <= l && r <= b)return dat[k];   // 完全に含む
		else {
			ll s1 = _find(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子
			ll s2 = _find(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子
			return min(s1, s2);
		}
	}
public:
	ll n, height;
	vector<ll> dat;

	// 初期化（_nは最大要素数）
	RmqTree(ll _n) {
		n = 1;
		height = 1;
		while (n < _n) {
			n *= 2;
			height++;
		}
		dat = vector<ll>(2 * n - 1, INF);
	}

	// i番目の値(0-indexed)をxに変更
	void update(ll i, ll x) {
		i += n - 1; // i番目の葉ノードへ
		dat[i] = x;
		while (i > 0) { // 登りながら更新
			i = (i - 1) / 2;//親ノードのインデックス
			dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]);
			//子ノードの小さい方の値を代入
		}
	}

	// 区間[a,b)の最小値の取得
	ll find(ll a, ll b) {
		return _find(a, b, 0, 0, n);
	}
};


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

	ll n, q;
	cin >> n >> q;

	RmqTree rmq(n);
	REP(i, n) {
		rmq.update(i, (1LL << 31) - 1);
	}

	REP(i, q) {
		ll com, x, y;
		cin >> com >> x >> y;
		if (com == 0) {
			rmq.update(x,y);
		}
		else {
			cout<<rmq.find(x, y + 1)<<endl;
		}
	}

	return 0;
}


Measured memory_bytes: 7108
#include<stdio.h>
#include<iostream>

#define MAX_N 25
#define MAX_SUM 2005

using namespace std;

int value[MAX_N];
bool dp[MAX_N][MAX_SUM];

int main()
{
    int N;
    scanf("%d", &N);
    for(int i=1; i<=N; i++)
        scanf("%d", value+i);
    int Q;
    scanf("%d", &Q);
    for(int q=0; q<Q; q++){
        int sum;
        scanf("%d", &sum);
        //初始化table
        for(int i=0; i<=N; i++)
            dp[i][0]=true;
        for(int i=1; i<=N; i++){
            for(int j=1; j<=sum; j++){
                dp[i][j]=dp[i-1][j];
                if(j>=value[i])
                    dp[i][j]=dp[i][j]||dp[i-1][j-value[i]];
            }
        }
        if(dp[N][sum])
            printf("yes\n");
        else
            printf("no\n");
    }
    return 0;
}



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

int main(){
    int n,a[100];

    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int j = n-1; j >= 0; j--){
        if(j != n-1) cout << " ";
        cout << a[j];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3088
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

#define dprint(Exp,...) if(Exp){fprintf(stderr, __VA_ARGS__);}
#define printe(...) fprintf(stderr, __VA_ARGS__);
#define PrtExp(_Exp)  cerr<< #_Exp <<" = "<< (_Exp)
#define PrtExpN(_Exp)  cerr<< #_Exp <<" = "<< (_Exp) <<"\n"

#define SINT(n) scanf("%d",&n)
#define SINT2(n,m) scanf("%d %d",&n,&m)
#define SINT3(n,m,o) scanf("%d %d %d",&n,&m,&o)
#define SINT4(n,m,o,p) scanf("%d %d %d %d",&n,&m,&o,&p)
#define SINT5(n,m,o,p,q) scanf("%d %d %d %d %d",&n,&m,&o,&p,&q)
#define SLL(n) scanf("%lld",&n)
#define SLL2(n,m) scanf("%lld %lld",&n,&m)
#define SLL3(n,m,o) scanf("%lld %lld %lld",&n,&m,&o)
#define SST(s) scanf("%s",s)
#define SCH(c) scanf("%c",&c)

#define GC() getchar()

#define PINT(n) printf("%d",(int)(n))
#define PINT2(n,m) printf("%d %d",(int)(n),(int)(m))
#define PINT3(n,m,l) printf("%d %d %d",(int)(n),(int)(m),(int)(l))
#define PLL(n) printf("%lld",(long long)(n))
#define PST(s) printf("%s",(s))
#define PCH(s) printf("%c",(s))

#define PINTN(n) printf("%d\n",(int)(n))
#define PINT2N(n,m) printf("%d %d\n",(int)(n),(int)(m))
#define PINT3N(n,m,l) printf("%d %d %d\n",(int)(n),(int)(m),(int)(l))
#define PLLN(n) printf("%lld\n",(long long)(n))
#define PSTN(s) printf("%s\n",(s))
#define PCHN(s) printf("%c\n",(s))

#define PSP() printf(" ")
#define PN() printf("\n")

#define PC(c) putchar(c)
#define CSP (' ')
#define SN ("\n")

#define rep(i,a) for(ll i=0;i<a;i++)
#define reP(i,a) for(int i=0;i<=a;i++)
#define Rep(i,a) for(int i=a-1;i>=0;i--)
#define ReP(i,a) for(int i=a;i>=0;i--)

#define rEp(i,a) for(i=0;i<a;i++)
#define rEP(i,a) for(i=0;i<=a;i++)
#define REp(i,a) for(i=a-1;i>=0;i--)
#define REP(i,a) for(i=a;i>=0;i--)

#define repft(i,a,b) for(int i=a;i<b;i++)
#define repfT(i,a,b) for(int i=a;i<=b;i++)
#define Repft(i,a,b) for(int i=a-1;i>=b;i--)
#define RepfT(i,a,b) for(int i=a;i>=b;i--)

#define foreach(a,it) for(auto it = a.begin(); it != a.end(); ++it)

#define FILL(a,v) fill(begin(a),end(a), v)
#define FILL0(a) memset(a,0,sizeof(a))
#define FILL1(a) memset(a,-1,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll>   Pll;


const int INF = 0x2aaaaaaa; // 715,827,882
const ll INFLL = 0x1f1f1f1f1f1f1f1fLL;//2,242,545,357,980,376,863

template <class A, class B> inline ostream& operator<<(ostream& st, const pair<A, B>& P) { return st << "(" << P.first << "," << P.second << ")"; };
template <class A, class B> inline pair<A, B> operator+(const pair<A, B>& P, const pair<A, B>& Q) { return pair<A, B>(P.first + Q.first, P.second + Q.second); };
template <class A, class B> inline pair<A, B> operator-(const pair<A, B>& P, const pair<A, B>& Q) { return pair<A, B>(P.first - Q.first, P.second - Q.second); };


#define fs first
#define sc second



int main() {

	string s;
	cin >> s;

	s[s.length() - 8] = 0;
	cout << &s[0] << endl;


	return 0;
}

Measured memory_bytes: 768
S = list(input())
if 'L' in S[::2] or 'R' in S[1::2]:
    print('No')
    exit()
for i in S:
    if i != 'L' and i != 'R' and i != 'U' and i != 'D':
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 2940
N = int(input())
As = input().split()
As = [int(A) for A in As]
Ai = max(As)
x = float('inf')
for a in As:
    if abs((Ai - a) - a) <= x:
        x = abs((Ai - a) - a)
        Aj = a
print(Ai, Aj)

Measured memory_bytes: 14052
#include<stdio.h>
 int main(void)
 {
     int N;
     int i,j,k=0,l=0;

     scanf("%d",&N);

     for(i=1;i<=N;i++){
       for(j=1;j<=N;j++){
         if(i<j) break;
         else if((i%j==0)&&(i%2!=0)) k++;
       }
       if(k==8) { l++; k=0; }
       else k=0;
     }

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

     return 0;
 }


Measured memory_bytes: 1712
#include <math.h>
double x[99],y[99],X,Y;
n,i;main(){
	for(gets(x);~scanf("%lf %lf",x+n,y+n);n++);
	if(!(n&1))for(X=(x[0]+x[n/2])/2,Y=(y[0]+y[n/2])/2,i=1;i<n/2;i++){
		if(fabs((x[i]+x[n/2+i])/2-X)>0.0000001||fabs((y[i]+y[n/2+i])/2-Y)>0.0000001)break;}
	printf(i==n/2?"%f %f\n":"NA\n",X,Y);exit(0);
}

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

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

  vector<pair<long, long>> tasks(N);

  for (int i = 0; i < N; i++) {
    long A, B;
    cin >> A >> B;

    tasks[i] = make_pair(B, A);
  }

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

  long t = 0;

  for (int i = 0; i < N; i++) {
    pair<long, long> task = tasks[i];
    t += task.second;

    if (t > task.first) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
}

Measured memory_bytes: 3328
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            // 出現する頭文字の回数
            int[] ins = new int[5];
            for (int i = 0; i < n; i++) {
                String tmp = in.next();
                if (tmp.startsWith("M")) ins[0]++;
                if (tmp.startsWith("A")) ins[1]++;
                if (tmp.startsWith("R")) ins[2]++;
                if (tmp.startsWith("C")) ins[3]++;
                if (tmp.startsWith("H")) ins[4]++;
            }
            long ans = 0;
            // ありうるMARCHの組合せ
            int[] c1 = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
            int[] c2 = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
            int[] c3 = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};

            for (int i = 0; i < 10; i++) {
                ans += (long) ins[c1[i]] * (long) ins[c2[i]] * (long) ins[c3[i]];
            }

            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 57440
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	static Scanner stdIn= new Scanner(System.in);
	static ArrayList<Integer> smPrime = new ArrayList<Integer>();

	public static void main(String args[]){
		while(true){
			int input = stdIn.nextInt();
			if(input==1)
				break;
			func(input);
		}
	}
	static public void func(int in){
		ArrayList<Integer> ans = new ArrayList<Integer>();
		if(isPrime(in)){
			ans.add(in);
		}
		else{
			int tmp = in;
			if(in % 7 == 1){
				tmp=in-2;
				if(in % tmp == 0 ){
					if(isPrime(in/tmp)){
						ans.add(in/tmp);
					}
				}
			}
			while(tmp>6){
				tmp-=5;
				if(in % tmp == 0 ){
					if(isPrime(in/tmp)){
						ans.add(in/tmp);
					}
				}
				tmp-=2;
				if(in % tmp == 0 ){
					if(isPrime(in/tmp)){
						ans.add(in/tmp);
					}
				}
			}
		}
		System.out.print(in+":");
		for(int i=0;i<ans.size();i++){
			System.out.print(" "+ans.get(i));
		}
		System.out.println();
	}
	private static boolean isPrime(int i) {
		for(int j=0;j<smPrime.size();j++){
			if(i==smPrime.get(j)){
//				System.out.println("222");

				return true;
			}
		}
		int tmp=i;
		if(i % 7 == 1){
			tmp=i-2;
			if(i % tmp == 0 ){
	//			System.out.println("001");

				return false;
				}
		}
		while(tmp>6){
			tmp-=5;
			if(i % tmp == 0 )
			{
		//		System.out.println("002");

				return false;
				}
			tmp-=2;
			if(i % tmp == 0 )
			{
			//	System.out.println("003");

				return false;
				}

		}
		smPrime.add(i);
		//System.out.println("!!!!");
		return true;
	}
}

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


int main() {
	// your code goes here
	vector<string>adj[100005];
	int n,m;
	cin>>n>>m;
	for(int i = 0; i <m; ++i){
	    int a;
	    string q;
	    cin>>a>>q;
	    adj[a].push_back(q);
	}
	int ans = 0, pen = 0;
	for(int i = 1;i<=n; ++i){
	    if(!adj[i].size())continue;
	    else {
	        for(int q = 0; q<adj[i].size(); ++q){
	            if(adj[i][q]=="AC"){ans++;pen+=q;break;}
	        }
	    }
	}
	cout<<ans<<" "<<pen;
}


Measured memory_bytes: 10368
import java.util.Scanner;

public class Main {
    public static void main(String[] args){

        Scanner sc =new Scanner(System.in);

        int N = sc.nextInt();
        int K = sc.nextInt();

          if (N % K == 0){
            System.out.println(0);
          }else {
            System.out.println(1);
          }
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;
class SegmentTree{
public:
    ll N, unit; 
    vector<ll> data, tree;
    SegmentTree(vector<ll> v, ll u){
        unit = u;
        data = v;
        ll n = data.size();
        N = 1;
        while(N<n)N*=2;
        tree = vector<ll>(N*2,u);
        build();
    }
    void build(){rep(i,N)update(i,data[i]);}
    void update(ll i, ll x){
        data[i]=x;
        i += N-1;
        tree[i]=x;
        while(i){
            i = (i-1)/2;
            tree[i]=merge(tree[i*2+1],tree[i*2+2]);
        }
    }
    ll query(ll start, ll end){return query(start, end, 0, 0, N);}
private:
    ll query(ll a, ll b, ll k, ll l, ll r){
        if(r<=a||b<=l)return unit;
        if(a<=l&&r<=b)return tree[k];
        else{
            ll lv = query(a,b,2*k+1,l,(l+r)/2);
            ll rb = query(a,b,2*k+2,(l+r)/2,r);
            return merge(lv,rb);
        }
    }
    ll merge(ll l, ll r){
        return l+r;
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,q;cin>>n>>q;
    vector<ll> c(n);rep(i,n){cin>>c[i];c[i]--;}
    vector<pair<P,ll>> rl(q);
    rep(i,q){
        ll l,r;cin>>l>>r;
        rl[i]={{r-1, l-1}, i};

    }
    sort(ALL(rl));
    vector<ll> lastApp(n, -1);
    rep(i,n){
        lastApp[c[i]]=i;
    }
    vector<ll> ans(q);
    SegmentTree st(vector<ll>(n,0),0);
    
    for(ll x:lastApp)if(x!=-1)st.update(x, st.data[x]+1);
    int nowr = -1;
    for(auto que:rl){
        ll l = que.first.second, r = que.first.first, idx = que.second;
        while(nowr<r){
            nowr++;
            st.update(lastApp[c[nowr]], st.data[lastApp[c[nowr]]]-1);
            lastApp[c[nowr]]=nowr;
            st.update(lastApp[c[nowr]], st.data[lastApp[c[nowr]]]+1);
        }
        ans[idx]=st.query(l, r+1);
    }
    for(ll A:ans)cout<<A<<endl;

    return 0;
}

Measured memory_bytes: 42636
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

int n,k,a[200010],b[200010];

int di(int x,int y){
	if(x < 0) return (x - y + 1) / y;
	else return x / y;
}

bool isOK(int x){
	int sum = 0;
	for(int i = 0;i < n;i++){
		if(a[i] < 0){
			sum += upper_bound(b,b + n,di(x,-a[i])) - b - (a[i] * a[i] <= x);
		}else if(a[i] > 0){
			sum += upper_bound(a,a + n,di(x,a[i])) - a - (a[i] * a[i] <= x);
		}else sum += (x >= 0) * (n - 1);
	}
	return sum / 2 >= k;
}

signed main(){
	cin >> n >> k;
	for(int i = 0;i < n;i++) cin >> a[i];
	sort(a,a + n);
	for(int i = 0;i < n;i++) b[i] = -a[n - i - 1];
	int ng = -INF,ok = INF;
	while(ok - ng > 1){
		int mid = (ok + ng) / 2;
		if(isOK(mid)) ok = mid;
		else ng = mid;
	}
	cout << ok << endl;
}

Measured memory_bytes: 3328
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	h, n := nextInt(), nextInt()
	sum := 0
	for i := 0; i < n; i++ {
		sum += nextInt()
	}

	if sum >= h {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 1152
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
class DIJ{
	public:
	struct edge{
		int to,cost;
	};
	vector<vector<edge> >G,rG;
	int n;
	vi d;//distance
	DIJ(int size){
		n=size;
		rG=G=vector<vector<edge> >(n);
	}
	void add_edge(int a,int b,int c){
		edge e={b,c},ee={a,c};
		G[a].pb(e);
		G[b].pb(ee);
	}
	void dij(int s){
		d=vi(n,inf);
		d[s]=0;
		priority_queue<pii>q;
		q.push(pii(0,s));
		while(!q.empty()){
			pii p=q.top();
			q.pop();
			int pos=p.second,cost=-p.first;
			if(cost>d[pos])continue;
			rep(i,G[pos].size()){
				edge e=G[pos][i];
				int to=e.to;
				int nowcost=cost+e.cost;
				if(nowcost<d[to]){
					d[to]=nowcost;
					q.push(pii(-d[to],to));
				}
			}
		}
	}
};
int main(){
	int n,m;
	char s,t;
	cin>>n>>m>>s>>t;
	vs in(n);
	rep(i,n)cin>>in[i];
	DIJ dij(26);
	rep(i,n){
		bool h=false;
		int w;
		rep(j,m){
			if(in[i][j]=='-'&&h==false){
				h=true;
				w=in[i][j-2]-'A';
			}else if(in[i][j]!='-'&&h){
				h=false;
				dij.add_edge(w,in[i][j+1]-'A',1);
			}
		}
	}
	rep(i,m){
		bool h=false;
		int w;
		rep(j,n){
			if(in[j][i]=='|'&&h==false){
				h=true;
				w=in[j-2][i]-'A';
			}else if(in[j][i]!='|'&&h){
				h=false;
				dij.add_edge(w,in[j+1][i]-'A',1);
			}
		}
	}
	dij.dij(s-'A');
	cout<<dij.d[t-'A']<<endl;
}






Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if ((a == 5 && b == 5 && c == 7) || (a == 5 && b == 7 && c == 5) || (a == 7 && b == 5 && c == 5)) printf("YES");
    else printf("NO");
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n, m, sum=0;
  cin >> n >> m;
  int arr[m];
  for(int i=0;i<m;i++)
  {
      cin >> arr[i];
      sum+=arr[i];
  }
  cout << ((n-sum)>=0 ? (n-sum): -1);
  return 0;
}

Measured memory_bytes: 3664
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(in);
    int a = Integer.parseInt(sc.next());
    int b = Integer.parseInt(sc.next());
    int c = Integer.parseInt(sc.next());
if(b-a==c-b){out.println("YES");
}else{
    out.println("NO");
}
}
}

Measured memory_bytes: 22868
A, B = map(int, input().split())

xor = [0, 1, 3]

def cal(n, flag=False):
    if n == 0:
        return 0
    else:
        if flag:
            n -= 1
        if n  < 3:
            return xor[n]
        else:
            amari = (n - 3) % 4
            if amari == 0:
                return 0
            elif amari == 1:
                return n
            elif amari == 2:
                return 1
            elif amari == 3:
                return n ^ 1
        
print(cal(A, flag=True) ^ cal(B))


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		//????????£?????????????????????
		Scanner sc = new Scanner(System.in);
		String str ="";
		//??°?????????
		while(true){
			//???????????????????????????
			str = sc.next(); 
			//"-"????????????????????????
			if(str.equals("-")){
				break;
			}
			//??°????????????
			int num = sc.nextInt();
			
			//??????????????°???????????£?????????
			for(int i = 0;i< num;i++){
				int h = sc.nextInt();
				//
				str = str.substring(h)+str.substring(0,h);
			}
			//??¨???
			System.out.println(str);
		}
	}
}

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

int main()
{
    int N;
    cin >> N;
    int power = 0;
    int result = 0;
    while (N / (int)pow(10, power) != 0)
    {
        //cout << (N / (int)pow(10, power)) << endl;
        //cout << (int)pow(10, power) << endl;
        if ((N / (int)pow(10, power)) > 9)
        {
            if (power % 2 == 0)
            {
                result += (int)pow(10, power) * 9;
            }
        }
        else if ((N / (int)pow(10, power)) <= 9)
        {
            //cout << (N / (int)pow(10, N)) << endl;
            if (power % 2 == 0)
            {
                result += (N - (int)pow(10, power) + 1);
            }
            //cout << (N - (int)pow(10, power) + 1) << endl;
        }
        power++;
    }
    cout << result << endl;
}

Measured memory_bytes: 256
import sys
def input():
    return sys.stdin.readline()[:-1]


N, M = map(int, input().split())
A = list(map(int, input().split()))

BC_list = []

for i in range(M):
    B, C = map(int, input().split())

    BC_list.append({
        'B': B,
        'C': C
    })

BC_list.sort(reverse=True, key=lambda x: x['C'])

A_last = min(A)

limit_count = 0

for pair in BC_list:

    if pair['C'] < A_last:
        break

    for _ in range(pair['B']):
        A.append(pair['C'])

    limit_count += pair['B']
    if limit_count > N:
        break

A.sort(reverse=True)

print(sum(A[0:N]))


Measured memory_bytes: 101092
#include<stdio.h>

int main()
{
   int a,b;

   scanf("%d %d",&a,&b);
   if(-1000<=a&&b<=1000)
   {
         if(a<b)
   printf("a < b\n");

          if(a>b)
   printf("a > b\n");

          if(a==b)
   printf("a == b\n");

   }

   return 0;
}



Measured memory_bytes: 2064
#include "bits/stdc++.h"
using namespace std;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

using ll=long long; 
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; 

#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (300006)
int main(){
	char a,b,c;
	cin>>a>>b>>c;
	cout<<a<<b<<c;
}


Measured memory_bytes: 3596
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int n; cin >> n;
	vector<long long> a(n + 1), b(n);
	for (int i = 0; i < n + 1; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}

	long long ans = 0;

	for (int i = 0; i < n; i++) {
		if (a[i] >= b[i]) {
			ans += b[i];
		}
		else {
			ans += a[i];
			b[i] = b[i] - a[i];
			if (a[i + 1] >= b[i]) {
				ans += b[i];
				a[i + 1] = a[i + 1] - b[i];;
			}
			else {
				ans += a[i + 1];
				a[i + 1] = 0;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;

  if (a == b && b == c && !(a & 1)) {
    cout << -1 << endl;
    return 0;
  }

  int ans = 0;
  while (!(a & 1) && !(b & 1) && !(c & 1)) {
    int A = b / 2 + c / 2;
    int B = a / 2 + c / 2;
    int C = a / 2 + b / 2;
    a = A;
    b = B;
    c = C;
    ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ldb = long double;
using pa = pair < ll, ll >;
using vec = vector < ll >;
#define pb push_back
#define po pop_back
#define mp make_pair
#define mt make_tuple
#define F  first
#define S  second
#define f(i,x,n) for(ll i=x;i<n;i++) 
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))
#define all(c) c.begin(),c.end()
#define str string
#define edl "\n"
#define add insert
#define cot continue
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;
const double PI = acos(-1);
const ll LINF = LLONG_MAX;




int main() 
{

 fast();
  
  // #ifndef ONLINE_JUDGE
  //   freopen("input.txt", "r", stdin);
  //   freopen("output.txt","w",stdout);
  // #endif
  
  ll a,k;
  cin>>a>>k;
  if(k==1)
  {
    cout<<0;
    return 0;
  }
  cout<<(a-(k));  


  


    




   
    return 0;
}
 

Measured memory_bytes: 256
using System;
using System.Text;


namespace aoj0506
{
    class Program
    {
        public void Proc()
        {
            while (true)
            {
                string Num = Console.ReadLine();
                if (string.IsNullOrEmpty(Num)) continue;
                int N = int.Parse(Num);
                if (N == 0) break;
                string current = Console.ReadLine();
                int count = 1;
                StringBuilder next = new StringBuilder();

                for (int i = 0; i < N; i++)
                {
                    char[] cs = current.ToCharArray();
                    for (int j = 0; j < cs.Length - 1; j++)
                    {
                        if (cs[j] == cs[j + 1])
                        {
                            count++;
                        }
                        else {
                            next.Append(count);
                            next.Append(cs[j]);              
                            count = 1;
                        }
                    }

                    next.Append(count);
                    next.Append(cs[cs.Length - 1]);
                    count = 1;
                    current = next.ToString();
                    next.Length = 0;
                }
                Console.WriteLine(current);
            }

        }
        static void Main(string[] args)
        {
            Program prg = new Program();
            prg.Proc();
        }
    }
}

Measured memory_bytes: 9760
n,k = map(int,input().split())
v = [int(x) for x in input().split()]

ans = 0
for l in range(n+1):
    for r in range(l,max(n,l+1)):
        m = v[:l]+v[r+1:]
        if len(m) > k:
            continue
        m.sort()
        i=0
        while i < len(m) and i < k - len(m) and m[i] < 0:
            i+=1
        ans = max(ans,sum(m[i:]))
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int N;
	cin >> N;
	if (N % 10 == 3) {
		cout << "bon" << endl;
	} else if (N % 10 == 0 || N % 10 == 1 || N % 10 == 6 || N % 10 == 8) {
		cout << "pon" << endl;
	} else {
		cout << "hon" << endl;
	}
}


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

using namespace std;

#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1){std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}

#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define endl '\n'
#define int long long

const int MX = 1e5 + 5;
int n;
int a[MX];

signed main()
{
	IOS;
	cin >> n;
	for (int i = 0; i < n+1; i++) {
		cin >> a[i];
	}
	int x, ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> x;
		int mn = min(a[i], x);
		ans += mn;
		x -= mn;
		mn = min(a[i+1], x);
		a[i+1] -= mn;
		ans += mn;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    vector<int> sign(n+1,-1);
    vector<vector<int>> edges(n+1);
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    vector<bool> visited(n+1);
    queue<int> q;
    q.push(1);
    visited[1] = true;
    while(!q.empty())
    {
        int curr = q.front();
        q.pop();
        for(int i=0;i<edges[curr].size();i++)
        {
            int child = edges[curr][i];
            if(!visited[child])
            {
                q.push(child);
                visited[child]=true;
                sign[child] = curr;
            }
        }
    }
    for(int i=2;i<=n;i++)
    {
        if(sign[i]==-1)
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    for(int i=2;i<=n;i++)
    {
        cout<<sign[i]<<endl;
    }
}


Measured memory_bytes: 10192
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;cin>>S;
  int cnt=0;
  char rc=S[0];
  for(int i=1;i<S.size();i++){
    if(rc!=S[i])cnt++;
    rc=S[i];
  }
  cout<<cnt<<endl;
}


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

int main(){
	long n;
	cin >> n;
	int max_a = 1;
	for(int i=2; i<=sqrt(n); i++){
		if (n % i == 0) max_a = i;
	}
	int max_b = n / max_a;
	int digit=0;
	while(max_b){
		max_b /= 10;
		digit++;
	}
	cout << digit;
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
int n,a[6005],b[6005],c[6005],n1,n2;
char s[6005];
bool dp[3005][3005];
string ask(bool dp[])
{
	string ans="";
	for(int i=1;i<=2*n;i++) if(dp[c[i]]) ans+=s[i];
	return ans;
}
int main()
{
	scanf("%d",&n);
	scanf("%s",s+1);
	for(int i=1;i<=2*n;i++)
	{
		if(s[i]=='a') a[++n1]=i,c[i]=n1;
		else b[++n2]=i,c[i]=n2;
	}
	dp[n][n]=1;
	for(int i=n-1;i>=1;i--)
	{
		dp[i][i]=1;
		if(a[i]<b[i])
		{
			int maxx=0;
			for(int j=a[i];j<=b[i];j++) if(c[j]>=i) maxx=max(maxx,c[j]);
			for(int j=b[i]+1;j<=2*n;j++) if(c[j]>maxx) dp[i][c[j]]=dp[i+1][c[j]];
		}
		else
		{
			int maxx=i,num=0;
			for(int j=b[i];j<=a[i];j++)
			{
				if(c[j]<i) continue;
				if(c[j]!=i) num++;
				maxx=max(maxx,c[j]);dp[i][c[j]]=1;
			}
			for(int j=a[i]+1;j<=2*n;j++)
			{
				if(c[j]<i) continue;
				if(s[j]=='b')
				{
					if(!num) dp[i][c[j]]=dp[maxx+1][c[j]];
					else
					{
						dp[i][c[j]]=1;maxx=max(maxx,c[j]);
						num++;
					}
				}
				else
				{
					if(!num) dp[i][c[j]]=dp[maxx+1][c[j]];
					else
					{
						dp[i][c[j]]=1;maxx=max(maxx,c[j]);
						num--;
					}
				}
			}
		}
		if(ask(dp[i])<=ask(dp[i+1])) memcpy(dp[i],dp[i+1],sizeof(dp[i+1]));
	}
	cout<<ask(dp[1]);
}

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

int isBomb(char x){
  if(x=='#'){
    return 1;
  }else{
    return 0;
  }
}

int main(){
  int H,W;
  cin >> H >> W;
  vector<vector<char>> M(H+2,vector<char>(W+2,'.'));
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      cin >> M[i][j];
    }
  }
  vector<vector<int>> A(H,vector<int>(W,0));
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      int sum=0;
      for(int k=i-1;k<=i+1;k++){
        for(int l=j-1;l<=j+1;l++){
          sum += isBomb(M[k][l]);
          A[i-1][j-1] = sum - isBomb(M[i][j]);
        }
      }
    }
  }
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      if(M[i][j]=='#'){
        cout << '#';
      }else{
        cout << A[i-1][j-1];
      }
    }
    cout << endl;
  }
}

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

int main()
{
    string s;
    int cnt;

    cin >> s;

    for(int i = 0;i < s.size();i++){
        if(s[i] == 'A') {
            cnt = i;
            break;
        }
    }

    for(int i = s.size();0 < i;i--){
        if(s[i] == 'Z'){
            cnt = i - cnt + 1;
            break;
        }
    }

    cout << cnt;
    return 0;

}

Measured memory_bytes: 640
import itertools
h,w,k=map(int,input().split())
c = [input() for i in range(h)]
row = []
column = []

for i in range(h):
    cnt = 0
    for g in range(w):
        if c[i][g] == "#":
            cnt+=1
    row.append(cnt)

for i in range(w):
    cnt = 0
    for g in range(h):
        if c[g][i] == "#":
            cnt+=1
    column.append(cnt)

ans=0
s = sum(row)

it = list(itertools.product([0,1], repeat=h+w))
for l in it:
    cnt = s
    cnth = []
    cntw = []
    for i in range(h):
        if l[i]==1:
            cnth.append(i)
            cnt -= row[i]
    for g in range(w):
        if l[h+g]==1:
            cntw.append(g)
            cnt -= column[g]
    for i in cnth:
        for g in cntw:
            if c[i][g]=="#":
                cnt += 1
    if cnt == k:
        ans+=1
print(ans)

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

int main() {
    int n;
    cin >> n;
    int ac = 0, wa = 0, tle = 0, re = 0;
    for(int i = 0; i < n; i++) {
        string s;
        cin >> s;
        if (s == "AC") {
            ac++;
        }
        else if (s == "WA") {
            wa++;
        }
        else if (s == "TLE") {
            tle++;
        }
        else if (s == "RE") {
            re++;
        }
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
    return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;

int main()
{
    long long n;
    scanf("%lld",&n);
    long long i,sum=1;
    for(i=1; i<=n; i++)
    {
        sum*=i;
        sum%=1000000007;
    }
    printf("%lld\n",sum);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 998244353
#define pi 3.141592653589793
const int N = 2000001;
using namespace std;



int main() {
//    cout << fixed << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


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

    int maxi = 0;
    for (int i = 0; i < n - 1; i++) {
        maxi = max(maxi, a[i + 1] - a[i]);
    }

    maxi = max(maxi, k - a[n - 1] + a[0]);


    cout << k - maxi;

}


Measured memory_bytes: 1024
import java.util.Scanner;
import java.util.List;
import java.util.Arrays;

public class Main {
    
    public static void main(String... args) {
        Scanner scanner = new Scanner(System.in);
        
        int count = Integer.parseInt(scanner.nextLine());
        String[] numbers = scanner.nextLine().split(" ");
        
        List<String> list = Arrays.asList(numbers);
        String result = list.stream().reduce((e1, e2) -> e2.concat(" " + e1)).get();
        System.out.println(result);
    }
}


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


void solve(std::vector<long long> H, std::vector<long long> M, long long K){
    cout << ((H[1] * 60 + M[1]) - (H[0] * 60 + M[0]) - K) << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::vector<long long> H(2);
    std::vector<long long> M(2);
    for(int i = 0 ; i < 2 ; i++){
        scanf("%lld",&H[i]);
        scanf("%lld",&M[i]);
    }
    long long K;
    scanf("%lld",&K);
    solve(std::move(H), std::move(M), K);
    return 0;
}


Measured memory_bytes: 3708
import java.util.*;

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

        int K = Integer.parseInt(scan.next());
        int N = Integer.parseInt(scan.next());
        int min = 0;

        List<Integer> A = new ArrayList<>();
        List<Integer> dist = new ArrayList<>();

        for(int i=0; i<N; i++)
        {
            A.add(Integer.parseInt(scan.next()));
        }

        scan.close();
        
        for(int i=0; i<N; i++)
        {
            if(i<N-1)
            {
                dist.add(A.get(i+1) - A.get(i));
            }else{
                dist.add(K-A.get(i) + A.get(0));
            }
        }

        Collections.sort(dist);
        //System.out.println(dist);

        for(int i=0; i<N-1; i++)
        {
            min += dist.get(i);
        }
        System.out.println(min);
    }
}

Measured memory_bytes: 64744
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        n: usize,
        x: usize,
        m: usize,
    }

    let mut ans = x;
    let mut sum = 0;
    let mut cnt = 0;
    let mut init = 0;
    let mut ok: bool = true;
    let mut dp: Vec<usize> = Vec::new();
    for i in 0..m {
        dp.push(ans);
        ans = (ans*ans)%m;
        for j in 0..dp.len() {
            if ans==dp[j] {
                cnt = dp.len() - j;
                init = j;
                ok = false;
                break;
            }
        }
        if ok==false {
            break;
        }
    }
    let mut init_sum = 0;
    for i in 0..init {
        init_sum += dp[i];
    }

    for i in init..dp.len() {
        sum += dp[i];
    }

    let d = (n-init) / cnt;
    let r = (n-init) % cnt;
    sum *= d;
    sum += init_sum;
    for i in 0..r {
        sum += ans;
        ans = (ans*ans)%m;
    }
    println!("{}", sum);
}


Measured memory_bytes: 2448
#include<bits/stdc++.h>
using namespace std;
int main ()


{
long long   int a,b,c,x,y,z;

    cin>>a>>b>>c;

    x=a-b;
    if(x!=0&&c-x>=0)
    {
       cout<<(c-x)<<endl;
    }
    else if(x==0)
    {
        cout<<c<<endl;
    }
    else if((c-x)<0)
        cout<<"0"<<endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
S = [input() for _ in range(N)]

t = {}
ans = 0
for s in S:
    st = "".join(sorted(list(s)))
    if st in t.keys():
        t[st] += 1
        ans += t[st]
    else:
        t[st] = 0

print(ans)


Measured memory_bytes: 24976
import math
n,m=map(int,input().split())
dog = math.factorial(n)
monkey = math.factorial(m)
ans = dog*monkey%(10**9+7)
if abs(n-m)==0:
    print(ans*2%(10**9+7))
elif abs(n-m)==1:
    print(ans%(10**9+7))
else:
    print(0)

Measured memory_bytes: 5196
#include <iostream>

using namespace std;

int main() {
    int N; 
    cin >> N;
    int A[N], B[N], C[N]; 
    for (int i=0; i<N; i++) scanf("%d %d %d", A+i, B+i, C+i);
    
    int ansA[N], ansB[N], ansC[N];
    ansA[0] = A[0];
    ansB[0] = B[0];
    ansC[0] = C[0];

    for (int i=1; i<N; i++) {
        ansA[i] = max (ansB[i-1], ansC[i-1]) + A[i];
        ansB[i] = max (ansA[i-1], ansC[i-1]) + B[i];
        ansC[i] = max (ansA[i-1], ansB[i-1]) + C[i];
    }

    cout << max (max (ansA[N-1], ansB[N-1]), ansC[N-1]) << endl;

    return 0;
}

Measured memory_bytes: 2560
import java.util.*;

public class Main {

    public static void main(String[] args) {
//        long startTime = System.currentTimeMillis();
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        long[] nValue = new long[N + 1];
        nValue[0] = 1L;
        for (int i = 0; i < M; i++) {
            int a = scanner.nextInt();
            nValue[a] = -1;
        }
        scanner.close();

        long calcValue = 1000000007;

        for (int i = 0; i < N + 1; i++) {
            if (nValue[i] < 0) {
                continue;
            }
            // 1段上がる場合
            int one = i + 1;
            if (one <= N && nValue[one] >= 0) {
                nValue[one] = (nValue[i] + nValue[one]) % calcValue;
            }
            // 2段上がる場合
            int two = i + 2;
            if (two <= N && nValue[two] >= 0) {
                nValue[two] = (nValue[i] + nValue[two]) % calcValue;
            }
        }

        System.out.println(nValue[N]);
    }
}


Measured memory_bytes: 48320
#include<bits/stdc++.h>
#define ll long long
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
int main() 
{
	FAST
	ll n;
	cin>>n;
	string s;
	cin>>s;
	if(n>=3200)
		cout<<s;
	else
		cout<<"red";
	return 0;
}

Measured memory_bytes: 256
# Minimum Spanning Tree
p = []
rank = []
edge = []
cost = 0

def makeSet(x):
    global p, rank
    p.append(x)
    rank.append(0)

def findSet(x):
    global p
    if x != p[x]:
        p[x] = findSet(p[x])
    return p[x]

def link(x, y):
    global p, rank
    if rank[x] > rank[y]:
        p[y] = x
    else:
        p[x] = y
        if rank[x] == rank[y]:
            rank[y] += 1

def union(x, y):
    link(findSet(x), findSet(y))    

def same(x, y):
    if findSet(x) == findSet(y):
        return 1
    else:
        return 0   

[v, e] = list(map(int, input().split()))
for i in range(v):
    makeSet(i)

for i in range(e):
    [s, t, w] = list(map(int, input().split()))
    edge.append([w, s, t])

edge.sort()

while v > 1:
    min = edge.pop(0)
    if not same(min[1], min[2]):
        union(min[1], min[2])
        cost += min[0]
        v -= 1

print(cost)


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int v[5];
int k;

int main(){
  REP(i,5)cin>>v[i];
  cin>>k;
  bool ok = true;
  REP(i,5)REP(j,i){
    int d = v[i]-v[j];
    if(d>k)ok=false;
  }
  puts(ok ? "Yay!" : ":(");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> ba(M);
    int a, b;
    for (size_t i = 0; i < M; i++)
    {
        cin >> a >> b;
        a--;
        b--;
        ba[i] = {b, a};
    }
    sort(all(ba));
    int cnt = 0;
    for (size_t i = 0; i < M; i++)
    {
        cnt++;
        int cur = ba[i].first;
        while (ba[i + 1].second < cur and cur <= ba[i + 1].first and i + 1 < M)
        {

            i++;
        }
    }
    cout << cnt;

    return 0;
}

Measured memory_bytes: 1024