akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#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(){
    ll n,k;
    cin >> n >> k;
    vector <ll> p(n),c(n);
    rep(i,n){
        cin >> p[i];
        --p[i];
    }
    rep(i,n){
        cin >> c[i];
    }

    ll ans=-1000100100100100;
    ll s;
    vector <ll> kai(n),score(n,ans);
    queue <int> q,q2,q3;
    ll qq,l,qq2,ka;
    int time=0;
    //q.push(0);
    rep(i,n){
        //cout << i << endl;
        if(score[i]!=ans){
            continue;
        }
        else{
            
            ka=0;
            q.push(i);
            q2=q3;
            s=0;
            time=0;
            while(1){
                qq=q.front();
                q.pop();
                //cout << qq << endl;
                if(i==qq and ka!=0){
                    l=q2.size();
                    rep(i,l){
                        qq2=q2.front();
                        q2.pop();
                        kai[qq2]=ka;
                        score[qq2]=s;
                    }
                    break;
                }
                else{
                    ++ka;
                    s+=c[p[qq]];
                    q.push(p[qq]);
                    q2.push(qq);
                }
            }
        }
    }
    ll no;


    /*rep(i,n){
        cout << kai[i] << " " << score[i] << endl;
    }*/

    ll ans2,ans3,ans4,ans5;
    ans5=-1001001001001001001;
    int ba;
    rep(i,n){
        ans2=0;
        ans3=0;
        ba=i;
        ans4=-1001001001001001001;
        if(score[i]>0){
            if(k>2*kai[i]){
                ans2+=(k/kai[i]-1)*score[i];
                no=k%kai[i]+kai[i];
            }
            else{
                no=k;
            }
            rep(i,no){
                ans2+=c[p[ba]];
                ba=p[ba];
                ans4=max(ans2,ans4);
            }
        }
        else{
            ll kk;
            kk=min(k,kai[i]);
            rep(i,kk){
                ans2+=c[p[ba]];
                ba=p[ba];
                ans4=max(ans2,ans4);
            }
        }
        ans5=max(ans5,ans4);
    }

    cout << ans5 << endl;



    

    return 0;
}

Measured memory_bytes: 3808
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

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

    map<string, int> mp;

    rep(i, n) {
        string s;
        cin >> s;
        mp[s]++;
    }
    int mx = 0;
    for ( auto p : mp ) mx = max(mx, p.second);
    for ( auto p : mp ) {
        if ( p.second != mx ) continue;
        cout << p.first << endl;
    }

    return 0;
}


Measured memory_bytes: 25216
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "YES" : "NO"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
template <class T, class U>ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T>ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "{";
	rep(i, v.size()) {
		if (i) os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}
template <class T, class U>istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >>p.second ;
	return is;
}
template <class T>istream& operator>>(istream& is,  vector<T>& v) {
	rep(i, v.size()) {
		is >> v[i];
	}
	return is;
}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	string s;
	int ans=0;
	cin >>s;
	int left, right;
	string ter = "keyence";
	for (left = 0; left < ter.size() and s[left] == ter[left];left++) {
	}
	if(s[left] != ter[left] and left!=0){
		//left--;
	}

	for (right = 0; right < ter.size() and
	                s[s.size() - right - 1] == ter[ter.size() - 1 - right];
	    right++){
		clog << s[s.size() - right - 1] << " " << ter[ter.size() - 1 - right]
		     << endl;
	    }
	    if (s[s.size() - right - 1] != ter[ter.size() - 1 - right] and right!=0){// right--;
		}
	    clog << right << " "<<left << endl;
	    cout << solve(ter.size() <= left + right) << endl;
}

Measured memory_bytes: 3628
#include<stdio.h>
#define MAX 100001
#define max2(a,b) a<b?b:a
#define max3(a,b,c) max2((max2(a,b)),c)
#define max4(a,b,c,d) max3((max2(a,b)),c,d)

int main(){
	int i,a,b,c,q,w,e,r,t,y;
	int n;
	char s[17];
	char ss[17]="CODEFESTIVAL2016";
	a = 0;
	scanf("%s",s);
	
	for(i = 0; i<16;i++){
		if(ss[i]!=s[i])a++;
	}
	
	printf("%d\n",a);
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {

  static long H;
  static long W;

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    H = sc.nextLong();
    W = sc.nextLong();

    sc.close();

    long result = Math.min(cal(H, W), cal(W, H));

    System.out.println(result);

  }

  public static long cal(long a, long b) {
    
    long min = Long.MAX_VALUE;

    for (int i = 1; i < a; i++) {

      long S1 = i * b;
      long H1 = a - i;

      // case 1 
      long H2 = H1 / 2;
      long H3 = H1 - H2;
      long S2 = H2 * b;
      long S3 = H3 * b;
      min = Math.min(min, compare(S1, S2, S3));
      
      // case 2
      long W2 = b / 2;
      long W3 = b - W2;
      S2 = W2 * H1;
      S3 = W3 * H1;
      min = Math.min(min, compare(S1, S2, S3));

    }
  
    return min;

  }

  public static long compare(long S1, long S2, long S3){

    return Math.max(Math.abs(S1 - S2), Math.max(Math.abs(S2 - S3), Math.abs(S3 - S1)));

  }

}

Measured memory_bytes: 21972
import java.util.Scanner;

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

		String s = sc.next();

		int startA = 0;
		int endZ = 0;

		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == 'A') {
				startA = i;
				break;
			}
		}
		for (int i = s.length() - 1; i >= 0; i--) {
			if (s.charAt(i) == 'Z') {
				endZ = i;
				break;
			}
		}
		System.out.println(endZ - startA + 1);
		sc.close();
	}
}

Measured memory_bytes: 24624
#include<stdio.h>
#define N 8
  
int Q[N][N];

int putQueen(int *r,int *c,int k){
 
  int i;
  
  for(i = 0;i < k;i ++)
    {
      if(r[i] == r[k])return 0;
 
      if(c[i]==c[k])return 0;
     
      if(r[i] + c[i] == r[k] + c[k])return 0;
     
      if(r[i]-c[i] == r[k] - c[k])return 0;
    }
  return 1;
}

 
int main(){
  
  int i,j;
  int n,k;
  int r[N],c[N];
  
  for(i = 0;i < N;i ++)
    {
      r[i] = 0;
      c[i] = 0;
     
      for(j = 0;j < N;j ++)
    {
      Q[j][i] = 0;
    }
    }
  
  scanf("%d",&n);
 
  k = n;
  
  for(i = 0;i < n;i ++)
    {
      scanf("%d%d",&r[i],&c[i]);
    }
   
  while(k < N){
 
    if(c[k] == N-1)
      {
    r[k] ++;
    c[k] = 0;
      }
    else
      c[k] ++;
  
    if(r[k] > N-1)
      {
    r[k] = 0;
    c[k] = 0;
    k--;
      }
     
    else if(putQueen(r,c,k))
      k ++;
  }
  
  for(i = 0;i < N;i ++)
    {
      Q[c[i]][r[i]]=1;
    }
  
  for(i = 0;i < N;i ++)
    {
      for(j = 0;j < N;j ++)
    {
      if(Q[j][i] == 1)printf("Q");
      else{
        printf(".");
      }
    }
      printf("\n");
    }
  return 0;
}
 

Measured memory_bytes: 572
N = int(input().strip())
H = list(reversed(list(map(int, input().strip().split()))))

for i in range(1, N):
    h = H[i] - H[i-1]
    if h < 1:
        continue
    elif h == 1:
        H[i] -= 1
    else:
        print("No")
        break
else:
    print("Yes")


Measured memory_bytes: 14396
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <queue> 
#include <cctype> 
#include <climits> 
#include <stack> 
#include <map> 
#include <cstring> 

using namespace std; 

vector<int> res;
vector<vector<int> > to_v,to_w;

void dfs(int v, int c){
    res[v]=c;

    for(int i=0;i<to_v[v].size();i++){
        int to=to_v[v][i];
        int w=to_w[v][i];
        if(res[to]==-1) dfs(to,(c+w)%2);
    }
}

int main(){

    int n;
    cin>>n;

    res = vector<int>(n,-1);
    to_v = vector<vector<int> >(n);
    to_w = vector<vector<int> >(n);
    for(int i=0;i<n-1;i++){
        int u,v;
        long long w;
        cin>>u>>v>>w;
        
        u--,v--;
        to_v[u].push_back(v);
        to_w[u].push_back(w%2);
        to_v[v].push_back(u);
        to_w[v].push_back(w%2);
    }

    dfs(0,0);

    for(int i=0;i<n;i++){
        cout<<res[i]<<endl;
    }

    return 0;
}

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

int main() {
  int K;
  string S;
  cin >> K >> S;
  int N = S.size();
  string STR;
  if (N <= K)
    cout << S << endl;
  else {
    for (int i = 0; i < K; i++)
      STR += S.at(i);
    cout << STR << "..." << endl;
  }
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <array>
#include <algorithm>
#include <set>

using namespace std;

#define int long long

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

    int n;

    cin >> n;

    string str;

    array<int, 26> ans;

    for (auto& x : ans)
    {
        x = 10000;
    }

    for (int i = 0; i < n; ++i)
    {
        cin >> str;

        array<int, 26> sum;

        for (auto& x : sum)
        {
            x = 0;
        }

        for (const char c : str)
        {
            sum[c - 'a']++;
        }

        for (int k = 0; k < sum.size(); ++k)
        {
            ans[k] = min(ans[k], sum[k]);
        }
    }

    for (int k = 0; k < ans.size(); ++k)
    {
        char c = 'a' + (char)k;

        for (int i = 0; i < ans[k]; ++i)
        {
            cout << c;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define degreeToRadian(deg) (((deg)/360)*2*M_PI)
#define radianTodegree(rad) (((rad)/2/M_PI)*360)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const int MOD = 1e9 + 7;

//cin.tie(0);ios::sync_with_stdio(false);
//cout << fixed << setprecision(15) << y << endl;
int main() {
  int h, w, k;
  cin >> h >> w >> k;
  vector<vector<char>> graph(h);
  int bcnt = 0;
  rep (i, h) {
    string s;
    cin >> s;
    for (auto v : s) {
      graph[i].push_back(v);
      if (v == '#') bcnt++;
    }
  }

  int ans = 0;
  rep (i, 1 << h) {
    rep (j, 1 << w) {
      int cnt = 0;
      vector<vector<char>> tmp = graph;
      
      rep (ii, h) {
	if (i & 1 << ii) {
	  rep (jjj, w) {
	    if (tmp[ii][jjj] == '#') cnt++;
	    tmp[ii][jjj] = 'x';
	  }
	}
      }

      rep (jj, w) {
	if (j & 1 << jj) {
	  rep (iii, h) {
	    if (tmp[iii][jj] == '#') cnt++;
	    tmp[iii][jj] = 'x';
	  }
	}
      }

      if (bcnt - cnt == k) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3568
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
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


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    string S; cin >> S;
    int ans = 1;
    rep(i, n - 1) {
        if(S[i] != S[i + 1]) ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H == 0 && W == 0){
                break;
            }else{
                for(int i = 0;i<H;i++){
                    for(int j = 0;j<W;j++){
                        System.out.printf("#");
                    }
                    System.out.printf("\n");
                }
                System.out.printf("\n");
            }

        }
    }
}



Measured memory_bytes: 64660
import java.util.*;

public class Main {

    static final int D = 365;
    static final int[] c = new int[27];
    static final int[][] s = new int[365][27];
    static final int[] ans = new int[365];
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int d = sc.nextInt();
        for (int i = 1; i <= 26; i++) {
            c[i] = sc.nextInt();
        }
        for (int i = 0; i < D; i++) {
            for (int j = 1; j <= 26; j++) {
                s[i][j] = sc.nextInt();
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < D; i++) {
            int max = 0;
            int idx = 0;
            for (int j = 1; j <= 26; j++) {
                if(max < s[i][j]){
                    max = s[i][j];
                    idx = j;
                }
            }
            ans[i] = idx;
            sb.append(idx + "\n");
        }
        System.out.print(sb.toString());
        sc.close();

    }

}


Measured memory_bytes: 47492
#include<stdio.h>

int main(void)
{
	unsigned long int a, b, c;
	int i = 0;

	b = 100;

	scanf("%ld", &a);

	do {
		b = (long int)(b * 1.01);
		i++;
	} while (b < a);

	printf("%ld", i);

	return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char S;
  cin >> S;
  if(S == 'a' || S == 'i' || S == 'u' || S == 'e' || S == 'o'){
    cout << "vowel" << endl;
  }
  else{
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cctype>
#include<queue>
#include<cstdio>
#include<cmath>
#include<sstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<ctime>
#include<cstdlib>
#include<map>
#include<utility>
#include<iomanip>
#include<set>
#include<stack>
//#include<Windows.h>
using namespace std;
typedef long long ll;typedef pair<int,int> pii;
typedef pair<ll,ll> pll;typedef vector<string> vss;
typedef vector<int> vii;typedef vector<pii> vpi;
typedef vector<ll> vll;typedef vector<pll> vpl;
typedef unsigned long long ul;typedef queue<int> qii;typedef queue<pii> qpi;
ll n,a[3][100005],ans;
int main()
{
	cin>>n;
	for(ll i=0;i<3;i++){
		for(ll j=0;j<n;j++)
			cin>>a[i][j];
		sort(a[i],a[i]+n);
	}
	for(ll j=0;j<n;j++){
		ll i=lower_bound(a[0],a[0]+n,a[1][j])-a[0];
		ll k=upper_bound(a[2],a[2]+n,a[1][j])-a[2];
		ans+=i*(n-k);
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 2688
// ABEY SAALE
// QUESTION KHUD KR SOLUTION KYU DEKH RHA H
 
 
 
 
 
 
 
 
//MAAF KIJIYEGA ME GUSSE ME IDHAR UDHAR NIKAL JATA HU
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define endl "\n"
#define ll long long
#define PI 3.1415926535 
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define senky_bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;

ll fac[2000005];
void pre(){ fac[0]=1; fac[1]=1; for(int i=2;i<200005;i++) fac[i]=(i*fac[i-1])%mod;}
ll power(ll a,ll b){ll res=1;while(b){if(b&1) res=(res*a)%mod;a=(a*a)%mod;b=b/2;}return res%mod;}
ll ncr(ll n,ll r){return ((fac[n]*power(fac[r],mod-2))%mod*power(fac[n-r],mod-2))%mod;}
// DEKHIYE JI  WALID JO THE ABBA HAMARE WO YEH function CHHOD KR GYE THE

signed main()
{   



      
      senky_bansal
      IIIT_ALLAHABAD
      
      // pre();
      ll t;
      // cin>>t;
      t=1;
      while(t--)
      { 
         
         ll k;
         cin>>k;
         ll ans = 0;
         for(ll i=1;i<=k;i++)
         {
            for(ll j=1;j<=k;j++)
            {
                for(ll l=1;l<=k;l++)
                {
                    ll p1 = __gcd(i,j);
                    ll p2 = __gcd(p1,l);
                    ans+=p2;
                }
            }
         } 
         cout<<ans<<endl;
         

      }
      






}



























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

/*------------------------------------------------------------------*/

#define ll long long int
#define mp make_pair
#define pb push_back
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); i++)



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


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

    //freopen("1.txt","rt",stdin);
    //freopen("output.txt","wwt",stdout);

    ll t;
    t=1;
    //cin>>t;
    //ll t1=0;
    while(t--)
    {
       ll h,w;
       cin>>h>>w;
       string s[h];
       for(ll i=0;i<h;i++)
        cin>>s[i];
       ll ans=0; 
       for(ll i=0;i<h;i++)
       {
           for(ll j=0;j<w;j++)
           {
               if(s[i][j]=='.')
               {
                   queue<pair<ll,pair<ll,ll>> >q;
                   vector<vector<ll> >visited(h,vector<ll>(w,0));
                   q.push({0,{i,j}});
                   ll mx=0;
                   while(!q.empty())
                   {
                     pair<ll,pair<ll,ll> >q1=q.front();
                     q.pop();  
                     ll d=q1.first;
                     ll x=q1.second.first;
                     ll y=q1.second.second;
                     if(visited[x][y] == 1) {
                         continue;
                     }

                     visited[x][y] = 1;


                     mx=max(mx,d);

                     rep(i,4) {
                         int n_x = x + dx[i];
                         int n_y = y + dy[i];

                         if(n_x < 0 || n_y < 0 || n_x >= h || n_y >=w || s[n_x][n_y] == '#') {
                             continue;
                         }

                         q.push({d+1, {n_x,n_y}});
                     }  
                   }
                   ans=max(ans,mx);   
               }
           }
       }
       cout<<ans;
    }
}


Measured memory_bytes: 3624
#include <stdio.h>
	#include <iostream>
	#include <vector>
	#include <algorithm>
	using namespace std;
	typedef long long ll;
	typedef std::vector<ll> lls;
	#define MIN(a, b) ( ((a)<(b)) ? (a) : (b) )
	#define MAX(a, b) ( ((a)>(b)) ? (a) : (b) )

	void cinv(lls& llVec, ll n) {
		ll val;
		llVec.reserve((size_t)(n));
		for (ll i = 0; i < n; i++) {
			cin >> val;
			llVec.push_back(val);
		}
	}


	int main()
	{
		ll K,X;

		cin >> K >> X;
		
		ll minVal = X - K + 1;
		ll maxVal = X + K - 1;
		for (int i = minVal; i <= maxVal; i++) {
			if (i != minVal) {
				cout << " ";
			}
			cout << i;
		}

		cout << '\n';

		return 0;
	}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string S; cin >> S;
    int Q; cin >> Q;

    bool reverse = false;
    for(int i=0; i<Q; i++){
        int T; cin >> T;
        if(T == 1){
            
            reverse = !reverse;

        } else{

            int F; cin >> F;
            string C; cin >> C;

            if((F==1 && reverse==false) || (F==2 && reverse==true)){

                S.insert(0,C);

            }else{

                S += C;

            }

        }

    }

    if(reverse){
        for(int i=0; i<S.size(); i++){
            cout << S.at(S.size()-1-i);
        }
        cout << endl;

    }else{
        cout << S << endl;
    }

}

Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 25, M = 1e6 + 25, oo = 1e9+7, mxmsk = 1 << 16;
const long long OO = 1e18+25;
    
#define f first
#define s second

int n;

int main() {
    scanf("%d",&n);
    printf("%d\n",3*n*n);
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

	    int n=gi();
	    int k=gi();
	    long[] A=new long[n];

        for(int i=0; i<n;i++) {
        	A[i]=gl();
        }

        Arrays.parallelSort(A);
        long m=A[0];
        for(int i=1; i<n;i++) {
        	m=uclid(m, A[i]);
        	if(m==1)break;
        }


        if(k%m==0 && k<=A[n-1]) {
		    System.out.println("POSSIBLE");
        } else {
        	System.out.println("IMPOSSIBLE");
        }
	}

	 // ユークリッドの互除法
    public static long uclid(long m, long n) {
    	if (m<n) {
			m^=n;
			n^=m;
			m^=n;
		}

		while(true) {
			long t=m%n;
			if (t==0) {
				return n;
			} else {
				m=n;
				n=t;
			}
		}
    }
	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

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

using namespace std;

typedef long long li;

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

    
    int n;
    cin >> n;
    
    vector<li> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    
    li sum = accumulate(a.begin(), a.end(), (li)0);
    li pref = 0;
    li answer = 1e18;
    for (int i = 0; i + 1 < n; i++)
    {
        pref += a[i];
        answer = min(answer, abs(sum - 2 * pref));
    }
    
    cout << answer << endl;
    
    return 0;
}

Measured memory_bytes: 1792
use std::cmp;

macro_rules! get {
      ($t:ty) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.trim().parse::<$t>().unwrap()
          }
      };
      ($($t:ty),*) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              let mut iter = line.split_whitespace();
              (
                  $(iter.next().unwrap().parse::<$t>().unwrap(),)*
              )
          }
      };
      ($t:ty; $n:expr) => {
          (0..$n).map(|_|
              get!($t)
          ).collect::<Vec<_>>()
      };
      ($($t:ty),*; $n:expr) => {
          (0..$n).map(|_|
              get!($($t),*)
          ).collect::<Vec<_>>()
      };
      ($t:ty ;;) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.split_whitespace()
                  .map(|t| t.parse::<$t>().unwrap())
                  .collect::<Vec<_>>()
          }
      };
      ($t:ty ;; $n:expr) => {
          (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
      };
}

#[test]
fn test_1(){
   let expect = solve(600, 300, 220, 420);   
   assert_eq!(520, expect);
}

#[test]
fn test_2(){
   let expect = solve(555, 555, 400, 200);   
   assert_eq!(755, expect);
}

#[test]
fn test_3(){
   let expect = solve(549, 817, 715, 603);   
   assert_eq!(1152, expect);
}


fn solve(a: u32, b:u32, c:u32, d:u32) -> u32{
    let train = cmp::min(a, b);
    let bus = cmp::min(c, d);

    train + bus
}

fn main() {

    let a = get!(u32);
    let b = get!(u32);
    let c = get!(u32);
    let d = get!(u32);

    let ans = solve(a, b, c, d);

    println!("{}", ans);
}


Measured memory_bytes: 4352
N = int(input())
h = list(map(int, input().split()))
INF = 10**14
dp = [INF]*N

dp[0] = 0
dp[1] = abs(h[0] - h[1])

for i in range(2,N):
    dp[i] = min(dp[i-2] + abs(h[i-2]-h[i]),dp[i-1] + abs(h[i-1]-h[i]))

print(dp[N-1])

Measured memory_bytes: 13924
#include<iostream>
using namespace std;
int main(){
    long long x,y;
    cin >> x >> y;
    int i=1;
    int ans = 0;
    while(1){
        if(x <= y){
            ans ++ ;
            x = x*2;
        }
        else{
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
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():
    N, X = LI()
    L = LI()
    cur_x = 0
    cnt = 1
    for l in L:
        cur_x += l
        if cur_x > X:
            break
        cnt += 1
    print(cnt)
main()



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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n = 3;
  vector<string> s(n);
  REP(i, n)
    cin >> s[i];

  ll now = 0;
  ll a;
  vll cur(n, 0);
  while(true){
    if(cur[now] == s[now].size()){
      a = now;
      break;
    }

    ll next = s[now][cur[now]] - 'a';
    cur[now]++;
    now = next;
  }

  char ans = 'A' + a;
  cout << ans << endl;

}


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

#define rep(i, j, n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
#define Puts(x) puts(x? "Yes":"No")
const int mod = 1e9 + 7;

typedef long long i64;
typedef pair<int, int> pi;

template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;

i64 gcd(int n, int m) {return (m == 0? n : gcd(m, n % m));}
i64 lcm(int n, int m) {return (n / gcd(n, m) * m);}
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};

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

  int h, w;
  cin >> h >> w;
  vvt<int> c(10, vt<int>(10));
  rep(i, 0, 10) rep(j, 0, 10) cin >> c[i][j];

  rep(k, 0, 10) rep(i, 0, 10) rep(j, 0, 10)
    c[i][j] = min(c[i][j], c[i][k] + c[k][j]);

  int ans = 0;
  rep(i, 0, h) {
    rep(j, 0, w) {
      int a;
      cin >> a;
      if(a != -1) ans += c[a][1];
    }
  }
  cout << ans << endl;
} 


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

long long int N, d[114], M;
char s[114];

int main(){
    scanf("%lld%s", &N, s);
    d[0] = 0;
    for(int i = 0; i <= N; ++i){
        d[i + 1] = d[i] + ((s[i] == ')') ? 1 : -1);
        M = max(M, d[i + 1]);
    }
    for(int i = M; --i >= 0;)cout << '(';
    cout << s;
    for(int i = M - d[N]; --i >= 0;)cout << ')';
    return 0;
}


Measured memory_bytes: 256
def main():
  n,h=map(int,input().split())
  ab=[list(map(int,input().split())) for _ in range(n)]
  amax=max([a for a,b in ab])
  b=[b for a,b in ab if b>amax]
  b.sort(reverse=True)
  ans=0
  sumb=sum(b)
  if h<sumb:
    d=0
    while d<h:
      d+=b[ans]
      ans+=1
    print(ans)
  else:
    d=h-sumb
    ans=len(b)+(d+amax-1)//amax 
    print(ans)
if __name__=='__main__':
  main()


Measured memory_bytes: 28380
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define p(s) cout<<(s)<<endl
#define REP(i,n,N) for(int i=n;i<N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=n;i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const int inf = 1e9;

int N;
int A[100010];
int sum;
int B[100010];
int main() {
    cin>>N;
    A[0]=0;
    A[N+1] = 0;
    REP(i,1,N+1) cin>>A[i];
    REP(i,0,N+1){
        sum+=abs(A[i] - A[i+1]);
        B[i] = - abs(A[i] - A[i+1]) - abs(A[i+1] - A[i+2]) + abs(A[i] - A[i+2]);
    }
    REP(i,0,N){
        p(sum+B[i]);
    }
    return 0;
}

Measured memory_bytes: 2048
N, M = list(map(int,input().split(' ')))
a = [list(map(int,input().split(' '))) for i in range(N)]
c = [list(map(int,input().split(' '))) for i in range(M)]
#print(a,c)
x = []
ans = []
for i in a:
  for j in c:
    x.append(abs(i[0]-j[0])+abs(i[1]-j[1]))
#  ans.append(x)
#  ans.append(x.index(min(ans)))
  print(x.index(min(x))+1)
  x = []
  



Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<functional>
#define int long long
#define mod(int)(1000000007)
using namespace std;
const int INF = 1000000000000;
vector<int> prime_factor(int num) {
    vector<int>res;
    while (num % 2 == 0) { // 偶数の素数は2のみ
        res.push_back(2);
        num /= 2;
    }
    for (int i = 3; i <= num; i++) { // 他の素数で割っていく
        while (num % i == 0) {
			res.push_back(i);
            num /= i;
        }
    }
    return res;
}
int cnt[345678];
signed main() {
	int n, m, ans = 1; cin >> n;
	for (int i = 1; i <= n; i++) {
		for (int h = 0; h < prime_factor(i).size(); h++) {
			cnt[prime_factor(i)[h]]++;
			//cout << i << ' ' << prime_factor(i)[h] << endl;
		}
	}
	for (int h = 2; h <= n; h++) {
		ans *= (cnt[h] + 1); ans %= 1000000007;
		//cout << cnt[h] << endl;
	}
	cout << ans % 1000000007 << endl;
	return 0;
}

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

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

    if(n==0)
        cout<<x;
    else
    {
        int arr[n];
        bool visit[102];

        for(int i=0;i<102;i++)
            visit[i]=false;

        for(int i=0;i<n;i++)
        {
            cin>>arr[i];
            visit[arr[i]]=true;
        }

        int a=x-1,b=x+1;

        if(!visit[x])
            cout<<x;
        else
        {
            for(int i=0;i<10000;i++)
            {
                if(!visit[a--])
                {
                    cout<<a+1;
                    break;
                }

                if(!visit[b++])
                {
                    cout<<b-1;
                    break;
                }
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;

#define MAX_N 10001

bool is_prime[MAX_N];
vector<int> prime;
void init() {
    memset(is_prime, 1, sizeof(is_prime));
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i < MAX_N; i++) 
        if (is_prime[i]) {
            prime.push_back(i);
            for (int j = i+i; j < MAX_N; j+=i) 
                is_prime[j] = false;
        }
}

int main() {
    init();
    int n;
    while (cin >> n, n != 0) {
        int pat = 0;
        for (int i = 0; i < prime.size(); i++) {
            int m = 0;
            for (int j = i; j < prime.size(); j++) {
                m += prime[j];
                if (m == n) pat++;
            }
        }

        cout << pat << endl;
    }
    return 0;
}
 

Measured memory_bytes: 1240
// きさま！ 見ているなッ！

#include<iostream>
#include<queue>
#include<memory>
#include<map>
#include<set>
#include<unordered_map>
#include<array>
#include<vector>
#include<algorithm>
#include<list>
#include<limits>
#include<stdio.h>
#include<math.h>
#include<string>
#include<thread>

using namespace std;
using ll = long long;
using vec = vector<int>;
using mat = vector<vec>;
using lst = list<ll>;

const ll MOD = 1000000007;

ll N;
set<ll> ans;

void check(ll v)
{
	if (ans.count(v)||v==1) { return; }

	ll tmp = N / v;
	while (tmp%v == 0)
	{
		tmp /= v;
	}

	if ((tmp - 1) % v == 0)
	{
		ans.insert(v);
	}
}

int main()
{
	cin >> N;
	for (ll i = 1; i < sqrt(N - 1) + 1; ++i)
	{
		if ((N - 1) % i == 0)
		{
			ans.insert(i);
			ans.insert((N - 1) / i);
		}
	}

	for (ll i = 1; i < sqrt(N) + 1; ++i)
	{
		if (N%i == 0)
		{
			check(i);
			check(N / i);
		}
	}
	//check(6);
	//for (auto& i : ans) { cout << i << endl; }

	cout << ans.size()-1 << endl;



	return 0;
}


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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;
using Graph = vector<vector<int>>;

static long long INF = (1LL<<62);

class zeroblock{
	public:
		int l, r, len, lenex;
		int lpos, rpos;
		zeroblock(){
			l = 0;     // 左にある1の連続長さ
			r = 0;     // 右にある1の連続長さ
			len = 0;   // 自分の0の長さ
			lenex = 0; // l + r + len
			lpos  = -1; //lenexすべて1にしたときの左端の位置
			rpos  = -1; //lenexすべて1にしたときの右端の位置
		}
		int calc(){
			lenex = l + len + r;
			return lenex;
		}
};

long long N, K;
vector<zeroblock*> B;
string S;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N >> K;
	cin >> S;
	int al = 0, ar = 0, alen = 0;
	zeroblock* b = NULL;
	for(int i=0; i<S.size(); i++){
		if((i == 0 && S[i] == '0') || (i > 0 && S[i-1] == '1' && S[i] == '0')){
			if(B.size() > 0){
				b = B[B.size()-1];
				b->r = ar;
				b->lenex = b->l + b->len + b->r;
				ar = 0;
			}
			b = new zeroblock();
			b->l = al;
			al = 0;
			alen = 0;
		}
		else if(i > 0 && S[i-1] == '0' && S[i] == '1'){
			b->len = alen;
			B.push_back(b);
			alen = 0;
			al = 0;
			ar = 0;
		}

		if(S[i] == '1'){
			ar++;
			al++;
			if(i == S.size()-1 && B.size() > 0){
				zeroblock* p = B[B.size()-1];
				b->r = ar;
			}
		}
		if(S[i] == '0'){
			alen++;
			if(i == S.size()-1){
				b->len = alen;
				B.push_back(b);
			}
		}

	}
	for(int i=0; i<B.size(); i++){
		zeroblock* b = B[i];
		int v = b->calc();
		if(i == 0){
			b->lpos = 0;
			b->rpos = b->lenex - 1;
		}
		else{
			b->lpos = B[i-1]->lpos + B[i-1]->l + B[i-1]->len ;
			b->rpos = b->lpos + b->lenex - 1;
		}
	}

	if(B.size() == 0){
		printf("%lld\n", N);
		return 0;
	}
	if(B.size() == 1 && B[0]->len == N && K >= 1){
		printf("%lld\n", N);
		return 0;
	}

	LL ans = 0;
	for(int s=0; ; s++){
		int e = min(s + (int)K - 1, (int)B.size() - 1);
		int c = B[e]->rpos - B[s]->lpos + 1;
		if(ans < c){
			ans = (LL)c;
		}
		if(e == B.size()-1){
			break;
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 5364
#include <iostream>

using namespace std;

int main()
{
  int H, W; cin >> H >> W;
  int cost[10][10];
  for (int i = 0; i < 10; i++)
    for (int j = 0; j < 10; j++) cin >> cost[i][j];

  for (int k = 0; k < 10; k++) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++)
        cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
    }
  }

  int sum = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      int num; cin >> num;
      if (num != -1) sum += cost[num][1];
    }
  }
  cout << sum << endl;
}








Measured memory_bytes: 256
def main():
    from math import cos, radians

    A, B, H, M = map(int, input().split())

    x = abs(H * 30 + 0.5 * M - 6 * M)
    x = radians(x)

    C = A * A + B * B - 2 * A * B * cos(x)
    C = pow(C, 0.5)

    print(C)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9564
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
	int x, a, b, c, d;
	scanf("%d", &x);
	a = x/1000;
	b = x%10;
	c = (x%100-b)/10;
	d = (x%1000-x%100)/100;
	if((a == d && d == c)|| (d == c && c == b)) printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vvi;
typedef std::vector<long long> vl;
typedef std::vector<std::vector<long long>> vvl;
#define out(x) cout<<x<<"\n";
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
 
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;
}


ll gcd(ll n, ll m) {
    ll tmp;
    while (m!=0) {
        tmp = n % m;
        n = m;
        m = tmp;
    }
    return n;
}
 
ll lcm(ll n, ll m) {
    return abs(n) / gcd(n, m)*abs(m);//gl=xy
}
 
using namespace std;

void solve()
{
  ll n;
  cin >> n;
  ll sum = 0;
  rep(i,n){
    if(((i+1)%3==0)||((i+1)%5==0))
      ;
    else
      sum += (ll)(i + 1);
  }
  cout << sum;
}

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


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include<bitset>
#include<iostream>
using namespace std;
#include<math.h>
#include<map>
#include<vector>
#include<string>
#include<algorithm>
#define ll long long
#define ld double
#include<stdio.h>
#define f first
#define s second
#include<stack>
#include<queue>
#define its set<int>::iterator
#define itmp map<int,int>::iterator
#include<stack>
#define lp for(int i=0;i<n;i++)
#define dlp for(int i=0;i<n;i++) for(int j=0;j<n;j++)
#define mod 1000000009
//#define N 101
//#include <boost/functional/hash.hpp>
//bitset<1000> b;
//b.set();   all bit have 1
//seive of Erat
//totient theorm for co-prime
/*ll int N=1000;
	int p[1001]={0};
	p[2]=1;
		vector<int>v;
        for(ll int i=3;i<=N;i+=2)
        p[i]=1;
        v.push_back(2);
        for(ll int i=3;i<=N;i+=2)
        {
            if(p[i])
            {
			v.push_back(i);
                for(ll int j=i*i;j<=N;j+=2*i)
                p[j]=0;
            }
        }  */
/*
int gcd(int a, int b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} */
/*
stringstream ss;  
ss<<c;  
string s1;
ss>>s1;
*/
/*
int power(int x, unsigned int y) 
{ 
    int temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2); 
    if (y%2 == 0) 
        return temp*temp; 
    else
        return x*temp*temp; 
}*/
int main()
{
	ios_base::sync_with_stdio(false); 
    	cin.tie(NULL); 
	 
      	ll int t=1;
	//cin>>t;
	while(t--)
	{
            string s;
            cin>>s;
            int n=s.length();
            if(s[n-1]!='s')
            s+='s';
            else
            {
                
                s+="es";
            }
            cout<<s<<endl;
	}
	return 0;
}

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

int main(){
  int n,a,b;
  cin >> n >> a >> b;
  int out=0;
  for(int i=1;i<=n;++i){
    string s = to_string(i);
    int sum=0;
    for(auto j:s) sum+=j-'0';
    if(a<=sum and sum<=b) out+=i; 
  }
  cout << out << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    //Kruskal's Algorithm
    private static final long MAX = (long) (2e10 + 1);
    private static int[] father;
    public static void main(String[] args) throws Exception {
        Scanner scanner = new Scanner(System.in);
        int V = scanner.nextInt();
        int E = scanner.nextInt();
        int[][] edges = new int[E][3];
        father = new int[V];
        for(int i = 0; i < V; ++i){
            father[i] = i;
        }

        for(int i = 0; i < E; ++i){
            edges[i] = new int[] {scanner.nextInt(), scanner.nextInt(), scanner.nextInt()};
        }

        Arrays.parallelSort(edges, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                return o1[2] - o2[2];
            }
        });

        long minCost = 0;
        int count = 0;
        for(int i = 0; i < E; ++i){
            int[] edge = edges[i];

            if(union(edge[0], edge[1])){
                minCost += edge[2];
                ++count;
                if(count == V - 1){
                    break;
                }
            }
        }

        System.out.println(minCost);
    }

    private static int compressFind(int x){
        int parent = father[x];
        while(parent != father[parent]){
            parent = father[parent];
        }

        int fa = x;
        int temp = -1;
        while(fa != father[fa]){
            temp = father[fa];
            father[fa] = parent;
            fa = temp;
        }

        return parent;
    }

    private static boolean union(int x, int y){
        int faX = compressFind(x);
        int faY = compressFind(y);

        if(faX == faY){
            return false;
        }

        father[faX] = faY;
        return true;
    }
}

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


int main(){
  int a=0;
  string S,T;
  cin >> S >> T;
 
  for(int i = 0; i < S.size(); i++){
    if(S.at(i) != T.at(i)){
      a=1;
      cout << "No" << endl;
      break;
    }
  }
  if(a==0){
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<stdlib.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

//昇順
int asc(const void* a, const void* b){
    return *(int*)a-*(int*)b;
}

//降順
int desc(const void* a, const void* b){
    return *(int*)b-*(int*)a;
}

int main(void){
    int N,M;
    scanf("%d%d",&N,&M);

    for(int i=M/N;i>0;i--){
        if(M%i==0){
            printf("%d\n",i);
            return 0;
        }
    }
}

Measured memory_bytes: 128
#ifndef __cplusplus
    cat << EOF
#endif
#include <bits/stdc++.h>
using namespace std;

#define rep(...) overload_rep(__VA_ARGS__, rep_1, rep_0)(__VA_ARGS__)
#define rep_0(i, end) for(int i = 0; i < (end); ++i)
#define rep_1(i, fr, ba) for(int i = (fr); i <= (ba); ++i)
#define overload_rep(arg0, arg1, arg2, name, ...) name
#define all(box) box.begin(), box.end()

template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if(lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if(lhs > rhs) { lhs = rhs; return 1; } return 0; }

int main() {

    int N;
    cin >> N;
    map<int, int> mp;
    rep(i, N) {
        int a;
        cin >> a;
        mp[a]++;
    }

    cout << mp.size() << '\n';
    return 0;

}



Measured memory_bytes: 7728
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n;
    cin >> n;
    VI p(n);
    REP(i,n) cin >> p[i];

    VI ans;
    while (1){
        bool ok = true;
        REP(i,n) if (p[i] != i) ok = false;
        if (ok) break;

        if (p[0] != 0 && p[0] < p[n-1]){
            ans.push_back(n-1);
            swap(p[0], p[n-1]);
        }else{
            ans.push_back(1);
            VI tmp(p);
            REP(i,n-1) p[i] = tmp[i+1];
            p[n-1] = tmp[0];
        }
    }
    cout << ans.size() << endl;
    for (int x : ans) cout << x << endl;
    
    return 0;
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  char s[h][w];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> s[i][j];
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#' &&  s[i - 1][j] != '#' && s[i + 1][j] != '#' && s[i][j - 1] != '#' && s[i][j + 1] != '#') {
        cout << "No\n";
        return 0;
      }
    }
  }
  cout << "Yes\n";
  return 0;
}

Measured memory_bytes: 256
import java.io.*;

public class Main {

	//ツ　0003
	public static void main(String[] args) throws IOException {
		
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(reader.readLine());
		
		for(int i = 0; i < n; i++) {
			
			String s = reader.readLine();
//			if (s == null)
//				break;
			
			String[] sp = s.split(" ");
			int a = Integer.parseInt(sp[0]);
			int b = Integer.parseInt(sp[1]);
			int c = Integer.parseInt(sp[2]);
			if (a*a+b*b==c*c || a*a+c*c==b*b || b*b+c*c==a*a) {
				System.out.printf("YES\n");
			}
			else {
				System.out.printf("NO\n");
			}
		}
		reader.close();
	}
}

Measured memory_bytes: 12000
C=->n,r{k=1;r.times{|i|k=k*(n-i)/-~i};k};require'prime';N,M=gets.split.map &:to_i;r=1;M.prime_division.map{|n,k|r*=C[N+k-1,k]};p r%(10**9+7)

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

class Cube {
public:
  int face[6];
  Cube() {}
  void roll_z(){ roll(1, 2, 4, 3);}
  void roll_y(){ roll(0, 2, 5, 3);}
  void roll_x(){ roll(0, 1, 5, 4);}    
  
  void roll(int i, int j, int k, int l) {
    int t = face[i];
    face[i] = face[j];
    face[j] = face[k];
    face[k] = face[l];
    face[l] = t;
  }
  
  
  void move(char ch) {
    if(ch == 'E') {
      for(int i = 0; i < 3; i++) roll_y();
    } else if (ch == 'W') {
      roll_y();
    } else if (ch == 'N') {
      roll_x();
    } else if (ch == 'S') {
      for(int i = 0; i < 3; i++) roll_x();
    }
    
  }
  
};

int main() {
  Cube c;
  string ord;

  for(int i = 0; i < 6; i++) cin >> c.face[i];
  cin >> ord;

  for(int i= 0; i < ord.size(); i++) c.move(ord[i]);

  cout << c.face[0] << endl;

  return 0;
}



Measured memory_bytes: 3176