akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

class Main {
  public static void main (String[] args) {
    int[] ages = {10, 20, 30, 40, 50, 60, -1};
    Scanner scanner = new Scanner(System.in);
    while (scanner.hasNext()) {
      int n = scanner.nextInt();
      if (n == 0) {
        break;
      }
      int[] as = new int[7];
      for (int ii = 0; ii < n; ii++) {
        int a = scanner.nextInt();
        for (int jj = 0; jj < 7; jj++) {
          if (jj == 6) {
            as[6]++;
            break;
          }
          if (a < ages[jj]) {
            as[jj]++;
            break;
          }
        }
      }
      for (int ii = 0; ii < 7; ii++) {
        System.out.println(as[ii]);
      }
    }
  }
}

Measured memory_bytes: 206776
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <cstdio>
#include <math.h>
using namespace std;

#define ll long long
#define vecint vector<int>
#define listint list<int>
#define Pii pair<int, int>

#define REP(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define print(a) cout << a << endl

#define MOD 1000000007
#define NIL -1

int alph[26];

int main(){
  string w;
  cin>>w;
  string ans="Yes";
  rep(i,w.size()){
    alph[(int)(w[i]-'a')]++;
  }
  rep(i,26){
    if(alph[i]%2!=0) ans="No";
  }
  print(ans);
  return 0;
}


Measured memory_bytes: 256
#「ABピザを買う枚数」で全探索

A,B,C,X,Y = map(int,input().split())

ans = float("inf")

for i in range(0,2*max(X,Y)+1,1):#「ABピザを買う枚数」で全探索
    tmpans = i*C#ABピザの代金

    tmp_x = max(0,X-i//2)
    tmp_y = max(0,Y-i//2)
    tmpans += A*tmp_x
    tmpans += B*tmp_y

    ans = min(ans,tmpans)

print(ans)

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

using lint = long long;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    string str;
    cin >> str;
    int q;
    cin >> q;
    deque<char> result;
    for (char c : str) result.push_back(c);
    int start = 0;
    for (int t = 0; t < q; ++t) {
    	int type;
    	cin >> type;
    	if (type == 1) 
    		start ^= 1;
    	else {
    		int f; char c;
    		cin >> f >> c;
    		if (f == 1) {
    			if (start == 0) result.push_front(c);
    			else result.push_back(c);
    		} 
    		else {
    			if (start == 1) result.push_front(c);
    			else result.push_back(c);
    		}
    	}
    }
    if (start == 0) for (char u : result) cout << u;
    else for (int i = result.size()-1; i >= 0; --i) 
    	cout << result[i];
}

Measured memory_bytes: 976
import java.util.Scanner;

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

		if (D < 20) {
			System.out.println(0);
			return;
		}

		int cnt = 0;

		for (int i = 1; i <= M; i++) {
			for (int j = 20; j <= D; j++) {
				int d10 = j/10;
				int d2 = j%10;
				if (d2 < 2) {
					continue;
				}
				if (i == d10*d2) {
					cnt++;
				}
			}
		}
		System.out.println(cnt);
	}
}



Measured memory_bytes: 21844
#include <bits/stdc++.h>
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;

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

#define pb push_back
#define mp make_pair
#define st first
#define nd second

const int MOD = 1000000007;

int N;
char S[300005];

LL DP[300005][2][3];
LL go() {
  REP(i,N+5)REP(last,2)REP(state,3) DP[i][last][state] = 0;

  DP[0][0][S[0]] = 1;
  REP(i,N) {
    REP(k,2) {
      if (S[i] == 1-k) continue;

      // printf("!!%d %d\n", i, k);

      REP(last,2)REP(state,3) {
        int st = state;
        if (last == 1 && k == 1) {
          if (st == 0 && i%2 == 0) st = 1;
          else if (st == 1 && i%2 == 1) st = 2;
        }
        (DP[i+1][k][st] += DP[i][last][state]) %= MOD;
      }
    }
  }

  // REP(i,N+1)REP(last,2)REP(state,3) printf("%d %d %d %lld\n", i, last, state, DP[i][last][state]);

  LL result = 0;
  REP(last,2)FOR(state,1,3) {
    if (state == 1 && !S[N-1]) continue;
    result += DP[N][last][state];
  }

  return result % MOD;
}

int main() {
  // ios_base::sync_with_stdio(0);

  scanf("%s", S);
  N = strlen(S);
  REP(i,N) {
    if (S[i] == '?') S[i] = -1;
    else S[i] = S[i] - '0';
  }

  char A = S[0], B = S[N-1];
  LL result = 0;
  for (S[0] = (A == -1 ? 0 : A); S[0] <= (A == -1 ? 1 : A); ++S[0])
    for (S[N-1] = (B == -1 ? 0 : B); S[N-1] <= (B == -1 ? 1 : B); ++S[N-1]) {
      (result += go()) %= MOD;
    }

  printf("%lld\n", result);
}


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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
inline void dump(){cout<<endl;}
template<class Head,class... Tail>inline void dump(Head&& head, Tail&&... tail){cout<<head<<", ";dump(forward<Tail>(tail)...);}
template<typename T>inline istream &operator>>(istream&input,vector<T>&v){for(auto &elemnt:v)input>>elemnt;return input;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}

main(){

  string s;
  ll n,y,x;
  cin>>s>>x>>y;
  n = s.size();

  vector<ll> my,mx;
  bool dir = true;
  ll cnt = 0;
  rep(i,n){
    if(s[i]=='F'){
      cnt++;
    }else{
      if(dir)mx.emplace_back(cnt);
      else my.emplace_back(cnt);
      dir = !dir;
      cnt = 0;
    }
  }
  if(dir)mx.emplace_back(cnt);
  else my.emplace_back(cnt);

  ll xn = mx.size();
  ll yn = my.size();
  auto xdp = make_vector<bool>(xn+1,2e5);
  auto ydp = make_vector<bool>(yn+1,2e5);

  ll b = 10000;
  xdp[0][b] = ydp[0][b] = true;
  ll xi=0,yi=0;
  if(s[0]=='F'){
    xdp[1][b+mx[xi]] = true;
    xi = 1;
  }
  for(;xi<xn;++xi){
    rep(i,1e5){
      if(xdp[xi][i]){
        xdp[xi+1][i+mx[xi]]=true;
        xdp[xi+1][i-mx[xi]]=true;
      }
    }
  }
  for(;yi<yn;++yi){
    rep(i,1e5){
      if(ydp[yi][i]){
        ydp[yi+1][i+my[yi]]=true;
        ydp[yi+1][i-my[yi]]=true;
      }
    }
  }

  x += b;
  y += b;
  if( xdp[xn][x]&&ydp[yn][y] )puts("Yes");
  else puts("No");

}


Measured memory_bytes: 194560
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>

using namespace std;


class Puzzle
{
public:


	void input()
	{

	}


	void play()
	{
		int N;

		while (1) {
			cin >> N;
			if (N == 0) return;

			int a = 0;
			int b = 0;
			int A = 0;
			int B = 0;

			for (int li = 0; li < N; li++) {
				cin >> a >> b;
				if (a > b) A = A + a + b;
				if (a < b) B = B + a + b;
				if (a == b) {
					A += a;
					B += b;
				}
			}

			printf("%d %d\n", A, B);
		}
	}

};


int main()
{
	Puzzle puz;

	puz.input();
	puz.play();

    return 0;
}




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

int main() {
    int n,k; cin >> n >> k;
    int ans = 0;
    for (int i=1;;i++) {
        if (n < pow(k,i)) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3960
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll ans = 0;
    vll a(n);
    vll b(n);
    REP(i,n){
        cin >> a[i] >> b[i];
    }
    for(int i=n-1;i>=0;i--){
        ll now = a[i]+ans;
        if(now%b[i]>0){
            ans+=b[i]-(now%b[i]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
/*
C++ ???????????????????????????????????¬??????
??????AOJ-ITP1??????????????????
*/
#define _USE_MATH_DEFINES

#include <iostream> // ?¨??????\??????
#include <fstream>  // ??????????????\??????
#include <string>   // ???????????¢???
#include <vector>   // ???????????????
#include <cmath>    // ??°??????
#include <iomanip>  // stream???????????¢???
#include <algorithm>// max??¢??°??????

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;        // ????´???°????????????????????????
using std::fixed;         // ???????????????????¨???????????????????????????????
using std::setprecision;  // ?????°????°???°?????\???????????°????????????????????¨????????\???

int main() {
	int a;
	int count;
	while (cin >> a)
	{
		count = 0;
		for (size_t i = 0; i < 10; i++)
		{
			for (size_t j = 0; j < 10; j++)
			{
				for (size_t k = 0; k < 10; k++)
				{
					for (size_t l = 0; l < 10; l++)
					{
						//cout << i << j << k << l << endl;
						if (i+j+k+l == a)
						{
							count++;
						}
					}
				}
			}
		}
		cout << count << endl;
	}

	return 0;
}

Measured memory_bytes: 3080
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int value[] = new int[n];
        for (int i = 0; i < n; i++) {
        	value[i] = scanner.nextInt();
        }
        for (int i = value.length-1; i >= 0; i--) {
        	if (i < value.length-1) System.out.print(" ");
        	System.out.print(value[i]);
        }
        System.out.println();
    }
}



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

int main()
{
    int n,a,b,ink=0,our=0;
    string s;
    cin>>n>>a>>b>>s;
    for(int i=0;i<n;i++){
        if(s[i]=='a' && ink<a+b){
            cout<<"Yes"<<endl;
            ink++;
        }
        else if(s[i]=='b'){
            our++;
            if(our<=b && ink<a+b){
                cout<<"Yes"<<endl;
                ink++;
            }
            else cout<<"No"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
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 (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

int main() {
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    // 元の数字のままで正負が逆転するなら、そのまま
    // 逆転しないなら、和が1か-1になるまで操作する
    // 正負正負正負.. と負正負正負.. の2パターン
    ll ans = LLONG_MAX;
    rep(i, 2) { //i = 0:正負, i=1:負正
        vector<int> s(n);
        ll tmp = 0;
        rep(j, n) {
            if (j==0) s[0]=a[0];
            else s[j] = s[j-1]+a[j];
            if ((i+j)%2==0) { // 正であってほしい
                if(s[j]>0) continue;
                else {
                    tmp += 1-(s[j]);
                    s[j] = 1;
                }
            } else {
                if (s[j]<0) continue;
                else {
                    tmp += s[j]-(-1);
                    s[j] = -1;
                }
            }
        }
        chmin(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1028
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound

int main(){
  int N,A,B;
  cin>>N>>A>>B;
  VL X(N);
  rep(i,N) cin>>X[i];
  ll ans=0;
  rep(i,N-1){
    if((X[i+1]-X[i])*A<B) ans+=(X[i+1]-X[i])*A;
    else ans+=B;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
S = input()

WA = "WA"

if S[0] != 'A':
    print(WA)
    exit()

if S[1].isupper():
    print(WA)
    exit()

C_cnt = 0
for i in range(2, len(S) - 1):
    if S[i] == 'C':
        if C_cnt == 0:
            C_cnt += 1
            continue
        else:
            print(WA)
            exit()
    else:
        if S[i].isupper():
            print(WA)
            exit()

if C_cnt == 0:
    print(WA)
    exit()

if S[len(S) - 1].isupper():
    print(WA)
    exit()

print("AC")

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
  
using namespace std;
const int inf = 1e9 + 7;




signed main() {
	/*freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/

 	cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);


    string s;
    cin >> s;
    if (s.size() != 6 || s[2] != s[3] || s[4] != s[5]) cout << "No";
    else cout << "Yes";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define yesno(flg) if(flg){cout<<'YES'<<endl;}else{cout<<'NO'<<endl;}
#define vi vector<int>
#define pb push_back
#define i197 1000000007
#define MAX_N 200002
using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<Pii,int> Piii;
typedef pair<int,ll> Pil;
typedef pair<ll,ll> Pll;
typedef pair<string,int> Psi;
typedef pair<Psi,int> Psii;

const int inf=1000000000;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

vi vec[200001];
int x[200001]={};
int dp[200001];
int main() {
	string str;
	cin>>str;
	if(str=="Sunny")cout<<"Cloudy"<<endl;
	if(str=="Cloudy")cout<<"Rainy"<<endl;
	if(str=="Rainy")cout<<"Sunny"<<endl;
	return 0;
}


Measured memory_bytes: 4992
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <cassert>

using namespace std;

const int N = 1e5 + 7;
const long long INF = 1LL << 60;
int n;
int a[N];
char sign[N];
long long base = 0;

int main() {
	scanf("%d", &n);
	cin >> base;
	long long all = 0;
	for (int i = 1; i < n; i++) {
		char buffer[10];
		scanf("%s %d", buffer, &a[i]);
		sign[i] = buffer[0];
		all += a[i];
	}
	long long ans = -INF;
	for (int i = 1; i < n; i++) {
		if (sign[i] == '-') {
			long long middle = 0;
			int j;
			for (j = i + 1; j < n; j++) {
				if (sign[j] == '-') {
					break;
				} else {
					middle += a[j];
				}
			}
			ans = max(ans, all - 2 * a[i] - 2 * middle + base);
			base -= a[i];
		} else {
			base += a[i];
		}
		all -= a[i];
	}
	cout << max(base, ans) << endl;
	return 0;
}


Measured memory_bytes: 768
import java.io.InputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.TreeMap;
import java.math.BigDecimal;
import java.math.BigInteger;
    
public class Main{
 
static final InputStream in=System.in;
static final PrintWriter out=new PrintWriter(System.out);
static final int INF=Integer.MAX_VALUE;
static final long LINF=Long.MAX_VALUE;
 
public static void main(String[] args) throws IOException{
InputReader ir=new InputReader(in);
int n=ir.nextInt();
int nn=n;
int ans=n;
for(int i=2;i<=Math.sqrt(nn);i++){
 if(n%i==0){
  ans=ans-ans/i;
  while(n%i==0) n/=i;
 }
}
if(n!=1) ans=ans-ans/n;
out.println(ans);
out.flush();
}

static class InputReader {
 private InputStream in;
 private byte[] buffer=new byte[1024];
 private int curbuf;
 private int lenbuf;
 
 public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}
  
 public boolean hasNextByte() {
  if(curbuf>=lenbuf){
   curbuf= 0;
   try{
    lenbuf=in.read(buffer);
   }catch(IOException e) {
    throw new InputMismatchException();
   }
   if(lenbuf<=0) return false;
  }
  return true;
 }
 
 private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}

 private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}
 
 private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}

 public boolean hasNext(){skip(); return hasNextByte();}
 
 public String next(){
  if(!hasNext()) throw new NoSuchElementException();
  StringBuilder sb=new StringBuilder();
  int b=readByte();
  while(!isSpaceChar(b)){
   sb.appendCodePoint(b);
   b=readByte();
  }
  return sb.toString();
 }
 
 public int nextInt() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  int res=0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }
 
 public long nextLong() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  long res = 0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }
 
 public double nextDouble(){return Double.parseDouble(next());}
 
 public BigInteger nextBigInteger(){return new BigInteger(next());}
 
 public int[] nextIntArray(int n){
  int[] a=new int[n];
  for(int i=0;i<n;i++) a[i]=nextInt();
  return a;
 }
 
 public char[][] nextCharMap(int n,int m){
  char[][] map=new char[n][m];
  for(int i=0;i<n;i++) map[i]=next().toCharArray();
  return map;
 }
}
}

Measured memory_bytes: 24504
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
	return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
	return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
	int t=*a;
	*a=*b;
	*b=t;
}
long long gcd(long long x,long long y){
	return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
	return x/gcd(x,y)*y;
}

// konoshita kara kaku

int main(void){
	int n=in(),i=0,m;
	long long ans=1;
	char s[2][60];
	chin(s[0]);
	chin(s[1]);
	if(s[0][0]==s[1][0]){
		ans=3;
		m=0;
		i=1;
	}
	else{
		ans=6;
		m=1;
		i=2;
	}
	for(;i<n;i++){
		if(m==0){
			ans=ans*2%mod;
			if(s[0][i]!=s[1][i]){
				m=1;
				i++;
			}
		}
		else if(s[0][i]!=s[1][i]){
			ans=ans*3%mod;
			i++;
		}
		else m=0;
	}
	llprint(ans);
	return 0;
}

Measured memory_bytes: 128
package main

import (
	"fmt"
)

func main() {
	// t >= x + y
	// t % 2 == (x + y) % 2
	var n int
	fmt.Scan(&n)
	var t, x, y int
	for i := 0; i < n; i++ {
		fmt.Scan(&t, &x, &y)

		if t < x+y || t%2 != (x+y)%2 {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}


Measured memory_bytes: 5504
#include<stdio.h>

int main(){
	
	int panjangkata, lowercase;
	scanf("%d %d", &panjangkata, &lowercase);
	char kata[panjangkata + 3];
	scanf("%s", &kata);
	kata[lowercase - 1] += 32;
	printf("%s", kata);

	
	return 0;
}

Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<ll, ll> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;
double PI = acos(-1);

void solve()
{	
	double a, b, C;
	cin >> a >> b >> C;
	C *= PI/180;
	double c = pow(a*a+b*b-2*a*b*cos(C),0.5);
	double S = a * b * sin(C)/2;
	cout << S << endl;
	cout << a + b + c << endl;
	cout << S*2/a << endl;
	return;
}

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



Measured memory_bytes: 3628
program example
	implicit none

	integer(8) N,A,B,amari
    
    read(*,*)N,A,B
    
    if(A==0) then
    	write(*,*)"0"
    else
    	if(N/(A+B)==0) then
        	if(N>=A) then
        		write(*,*) A
            else
            	write(*,*) N
            end if
        else
    		amari=mod(N,A+B)
            
        	if(amari<=A) then
        		write(*,*) (N/(A+B))*A+amari
        	else
        		write(*,*) (N/(A+B))*A+A
        	end if
    	end if
    end if
end program example

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int>> vvint;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<int, vector<int>, greater<int>> spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int>> bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;        //大きい順に取り出し

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)

int INF = 1e9;
int NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
double EPS = 1e-9;
double PI = M_PI;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}
//-----------------------------------------

//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::chrono::system_clock::time_point start,end;
    start = std::chrono::system_clock::now();
    int n ;
    cin >> n ;
    vector<int> dis(n+1,0) ;
    vector<int> seen(n+1,0) ;
    queue<int> que ;
    vector<int> next ;
    next.push_back(1) ;
    int i6 = 6 ;
    while(i6<=n){
        next.PB(i6) ;
        i6 *= 6 ;
    }
    int i9 = 9 ;
    while(i9<=n){
        next.PB(i9) ;
        i9 *= 9 ;
    }
    
    que.push(0) ;
    seen[0] = 1 ;
    dis[0] = 0 ;

    while(!que.empty()){
        int k = que.front() ;
        que.pop() ;
        for(int i=0;i<next.size();i++){
            if(k+next[i]<=n && seen[k+next[i]]==0){
                que.push(k+next[i]) ;
                seen[k+next[i]] = 1 ;
                dis[k+next[i]] = dis[k] + 1 ;
            }
        }
    }

    cout << dis[n] <<endl;


    end = std::chrono::system_clock::now();
    auto elapsed = std::chrono::duration_cast< std::chrono::milliseconds >(end - start).count();
    //std::cout << elapsed <<"ms"<< std::endl;

    

    return 0;
}



Measured memory_bytes: 1152
#include<iostream>
#include<algorithm>
using namespace std;
int N_MAX=100;
int main()
{
  int n,i,s=0,t=0;
  int a[N_MAX];
  cin >> n;
  for(i=0;i<n;i++)
    cin >> a[i];
  sort(a,a+n,greater<int>());
  for(i=0;i<n;i++){
    if(i%2==0)
      s+=a[i];
    else
      t+=a[i];
  }
  cout << s-t << endl;
  return 0;
}

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

int  main()
{
	int n; cin >> n;
	vector <int> a(n);
	rep(i, n)
	{
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	cout << a.back() - a.front() << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=105;

int n,t[N];

int main()
{
    scanf("%d",&n);int mx=0;
    for (int i=1;i<=n;i++)
    {
        int x;scanf("%d",&x);
        t[x]++;mx=max(mx,x);
    }
    if (!(mx&1)&&t[mx/2]!=1||(mx&1)&&t[(mx+1)/2]>2) {puts("Impossible");return 0;}
    for (int i=(mx+1)/2+1;i<=mx;i++) if (t[i]<2) {puts("Impossible");return 0;}
    for (int i=1;i<(mx+1)/2;i++) if (t[i]) {puts("Impossible");return 0;}
    puts("Possible");
    return 0;
}

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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        List<Integer> p = new ArrayList<>();
        int[] yaku = new int[1000005];
        Arrays.fill(yaku, 0);

        for (int i = 0; i < N; i++) {
            int pi = sc.nextInt();
            p.add(pi);

            if (yaku[pi] != 0) {
                yaku[pi] = 2;
                continue;
            }
            for (int j = pi; j < 1000005; j += pi) {
                yaku[j]++;
            }
        }
        sc.close();

        int count = 0;
        for (int i = 0; i < N; i++) {
            if (yaku[p.get(i)] == 1) {
                count++;
            }
        }

        System.out.println(count);
    }
}


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

#include <boost/range/irange.hpp>
using boost::irange;

int main() {
  string s;
  cin >> s;
  int n = s.size();
  for (int i : irange(0, n, 2))  {
    cout << s[i];
  }
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
  vector<pair<int,int>> v;
  int n;
  cin >> n;
  int i;
  for(i=0;i<n;i++){
    int a,b;
    cin >> a >> b;
    v.emplace_back(b,a);
  }
  sort(v.begin(),v.end());
  int sum = 0;
  for(auto x : v){
    sum += x.second;
    if(sum>x.first){
      cout << "No" << "\n";
      return 0;
    }
  }
  cout << "Yes" << "\n";
  return 0;
}

Measured memory_bytes: 5320
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
#include<set>
#define SF scanf
#define PF printf
#define MAXN 200010
using namespace std;
typedef long long ll;
int n,st;
ll d;
int fa[MAXN];
ll siz[MAXN];
ll cnt[MAXN];
int get_fa(int x){
	if(fa[x]==0)
		return x;
	fa[x]=get_fa(fa[x]);
	return fa[x];	
}
vector<pair<ll,int> >mp;
struct node{
	ll x,y;
	int id;
	bool operator < (const node &a)	const {
		if(x!=a.x)
			return x<a.x;
		return y<a.y;
	}
}p[MAXN];
ll dist(int x,int y){
	return abs(p[x].x-p[y].x)+abs(p[x].y-p[y].y);
}
void merge(int x,int y){
	//PF("{%d %d}\n",x,y);
	x=get_fa(x);
	y=get_fa(y);
	if(x!=y)
		fa[x]=y;
}
void solve(ll now){
	mp.clear();
	int las=1;
	vector<pair<ll,int> >::iterator  lasx;
	bool flag=0;
	for(int i=1;i<=n;i++){
		if(p[i].x!=p[i-1].x){
			mp.clear();
			flag=1;
		}
		while(p[i].x-p[las].x>d&&las<=n)
			las++;
		while(p[i].x-p[las].x==d&&las<=n){
			mp.push_back(make_pair(p[las].y,p[las].id));
			las++;
		}
		vector<pair<ll,int> >::iterator it=lower_bound(mp.begin(),mp.end(),make_pair(p[i].y-d+now,0));
		if(flag){
			flag=0;
			lasx=mp.begin();
		}
		lasx=max(lasx,it);
		if(it==mp.end()||it->first >p[i].y+d-now)
			continue;
		for(;lasx!=mp.end()&&lasx->first <= p[i].y+d-now;lasx++){
			int x=lasx->second;
			int y=p[i].id;
			if(x>y)
				swap(x,y);
			merge(x,y);
		}
		cnt[p[i].id]+=(lasx-it);
		//PF("[%d %d %d]\n",p[i].id,cnt[p[i].id],lasx-it);
		if(lasx!=it)
			lasx--;
	}
}
int a,b;
int main(){
	SF("%d%d%d",&n,&a,&b);
	for(int i=1;i<=n;i++){
		SF("%d%d",&p[i].x,&p[i].y);
		p[i].id=i;
	}
	d=dist(a,b);
	for(int i=1;i<=n;i++){
		ll x=p[i].x;
		ll y=p[i].y;
		p[i].x=x-y;
		p[i].y=x+y;
	}
	sort(p+1,p+1+n);
	solve(0);
	for(int i=1;i<=n;i++)
		swap(p[i].x,p[i].y);
	sort(p+1,p+1+n);
	//PF("----------\n");
	solve(1);
	for(int i=1;i<=n;i++)
		siz[get_fa(i)]+=cnt[i];
	PF("%lld",siz[get_fa(a)]);
}

Measured memory_bytes: 9972
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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;}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    ll n;
    cin >> n;
    ll ans = 0;
    REP1(i, n) {
        if (i % 3 != 0 && i % 5 != 0) ans += (ll)i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3652
const fs = require('fs');
const input: string[] = fs.readFileSync('/dev/stdin', 'utf-8').split('\n');
const n: number = parseInt(input[0]);
const S: string = input[1];

let result: string = '';
for (let i = 0; i < n; ++i) {
  if (!result) {
    result += S[i];
  } else if (result.slice(-1) !== S[i]) {
    result += S[i];
  }
} 

console.log(result.length);

Measured memory_bytes: 38840
#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>;

ll dp[105][100005];

int main() {
    int n, W;
    cin >> n >> W;
    vector<int> w(n), v(n);
    rep(i,n) cin >> w[i] >> v[i];
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= W; ++j) {
            if (j < w[i-1]) dp[i][j] = dp[i-1][j];
            else dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i-1]]+v[i-1]);
        }
    }
    cout << dp[n][W] << endl;
    return 0;
}

Measured memory_bytes: 79360
n,m = list(map(int,input().split()))
l=[]
r=[]
for j in range(m):
	a,b = list(map(int,input().split()))
	l.append(a)
	r.append(b)
low = max(l)
high = min(r)
if(low>high):
	count = 0
else:
	count = min(high - low + 1, n)
print(count)

Measured memory_bytes: 11076
#include <iostream>

using namespace std;

int main()
{  int a,b;
cin>>a;
cin>>b;
if (a<=5){
    cout<<"0";
}
else if (a>=6&&a<=12){
      cout<<b/2 <<endl;
 }
else{
    cout<<b<<endl;
}
    return 0;
}

Measured memory_bytes: 256
//
//  header_useful.h
//  c++_acm
//
//  Created by 李弘辰 on 2019/7/23.
//  Copyright © 2019 李弘辰. All rights reserved.
//

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <vector>
#include <list>
#include <set>
#include <utility> // pair
#include <map>
#include <iostream>
#include <sstream>
#include <algorithm> // sort
#include <string>
#include <stack>
#include <queue>
#include <fstream>
#include <bitset>

using namespace std;

#define ll long long
#define uchar unsigned char
#define ushort unsigned short
#define uint unsigned int
#define ulong unsigned long
#define ull unsigned long long

#define INT_INF 0x7fffffff

#define pi acos(-1)

#define mx(a,b) (a) > (b) ? (a) : (b)
#define mn(a,b) (a) < (b) ? (a) : (b)
#define mem(a,b) memset(a,b,sizeof(a))
#define fre(a) freopen(a,"r",stdin)

#define cio ios::sync_with_stdio(false); // Do not use it with "scanf" and other c input!
#define pb push_back
#define REP(i,a,b) for (int i = a;i <= b;i ++)
#define pre(i,a,b) for (int i = a;i >= b;i --)
#define rep(i,a,b) for (int i = a;i < b;i ++)

#define itn int
#define nit int
#define inr int
#define mian main
#define ednl endl
#define fro for
#define fir for
#define reutrn return
#define retunr return
#define reutnr return


/* header_useful_h */


int main()
{
    int k;
    string s;
    cin >> k >> s;
    if (s.size() <= k) cout << s << endl;
    else {
        rep(i,0,k) {
            printf("%c",s[i]);
        }
        printf("...\n");
    }
    return 0;
}


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

int main() {
  string N;
  cin >> N;
  int B = N.size() - 1;
  char A = N[B];
  if(A == '3'){
    cout << "bon" << endl;
  }
  if ( (A == '2') || (A == '4') || (A == '5') || (A == '7') || (A == '9') ){
    cout << "hon" << endl; 
  }
  if ( (A == '0') || (A == '1') || (A == '6') || (A == '8') ) {
    cout << "pon" << endl; 
  }
}


Measured memory_bytes: 3628
if int(input()) in [4,7,8,11,12,14,15,16,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100]:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 38384
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
C = Counter(A)

A = set(A)
MAX_A = 10 ** 6
X = [0] * (MAX_A + 1)
for a in A:
    for i in range(a, MAX_A + 1, a):
        X[i] += 1

ans = len([a for a in A if (X[a] == 1) and (C[a] == 1)])
print(ans)

Measured memory_bytes: 50844
S=input()

cnt=[]

def solve(s):
  pos = len(s)-sum(s)
  ct=0
  res=0
  for i in range(len(s)):
    if s[i]==1:
      res+=(pos+ct-i)
      ct+=1
  return res

n=0
while n < len(S):
  if S[n]=='A':
    cnt.append(1)
    n+=1
  elif (n < len(S)-1) and (S[n]=='B') and (S[n+1]=='C'):
    cnt.append(0)
    n+=2
  else:
    cnt.append(2)
    n+=1

r=0
l=0
ans=0
while l < len(cnt):
  if cnt[l] != 2:
    r=l
    while r<len(cnt) and cnt[r]!=2:
      r+=1
    ans+=solve(cnt[l:r])
    l=r
  else:
    l+=1

    
print(ans)

Measured memory_bytes: 6756
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

	int N;
	int[] a;

	public void solve() {
		N = nextInt();
		a = new int[N];
		for(int i = 0;i < N;i++){
			a[i] = nextInt();
		}

		int notTwo = 0;
		int two = 0;
		int four = 0;

		for(int i = 0;i < N;i++){
			if(a[i] % 2 != 0){
				notTwo++;
			}else if(a[i] % 4 == 0){
				four++;
			}else if(a[i] % 2 == 0){
				two++;
			}
		}

		if(notTwo + two % 2 > four + 1){
			out.println("No");
		}else {
			out.println("Yes");
		}
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 35208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

struct UnionFind {
    UnionFind() {}
    UnionFind(int n) {
        resize(n);
    }
    
    void resize(int n) {
        par.resize(n, -1);
    }
    
    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    
    bool merge(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return false;
        if (par[rx] > par[ry]) swap(rx, ry);
        par[rx] += par[ry];
        par[ry] = rx;
        return true;
    }
    
    bool is_same(int x, int y) {
        return (root(x) == root(y));
    }
    
    int size(int x) {
        return -par[root(x)];
    }
    
private:
    vector<int> par;
};

template<class T>
struct MinimumSpanningTree {
    MinimumSpanningTree() {}
    MinimumSpanningTree(int n) {
        vertex_count = n;
    }
    
    void resize(int n) {
        vertex_count = n;
    }
    
    void add_edge(int from, int to, T cost) {
        edges.emplace_back((Edge){from, to, cost});
    }
    
    T get_total_cost() {
        sort(edges.begin(), edges.end(), [&](const Edge &a, const Edge &b) {
            return a.cost < b.cost;
        });
        UnionFind uf(vertex_count);
        T ans = 0;
        for (int i = 0, lc = (int)edges.size(); i < lc; i++) {
            if (uf.is_same(edges[i].from, edges[i].to)) continue;
            uf.merge(edges[i].from, edges[i].to);
            ans = ans + edges[i].cost;
        }
        return ans;
    }
    
private:
    struct Edge {
        int from, to;
        T cost;
    };
    
    int vertex_count = 0;
    vector<Edge> edges;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll v, e;
    cin >> v >> e;
    MinimumSpanningTree<ll> mst(v);
    rep(i, e) {
        ll s, t, w;
        cin >> s >> t >> w;
        mst.add_edge(s, t, w);
        mst.add_edge(t, s, w);
    }
    ll ans = mst.get_total_cost();
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 7100
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

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



use std::cmp;
use std::ascii::AsciiExt;
use std::iter::Iterator;

fn main() {
    input! {
        k:i32,
        s:i32
    }

    let mut cnt = 0;
    for i in 0..s + 1 {
        for j in 0..s+1 {
            let l = s - i - j;
            if l <= k && l >= 0 && i <= k && j <= k{
                cnt +=1;
            }
        }
    }

    println!("{}", cnt);

}



Measured memory_bytes: 4352
/* -------------------------------- Template -------------------------------- */

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

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

template <typename T> T &chmin(T &a, const T &b) { return a = std::min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = std::max(a, b); }

// template<typename T> constexpr T inf = [](){ assert(false); };
// template<> constexpr int inf<int> = 1e9;
// template<> constexpr ll inf<ll> = 1e18;
// template<> constexpr ld inf<ld> = 1e30;

struct yes_no : std::numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

void solve();

int main() {
  std::locale loc(std::locale(), new yes_no);
  std::cout << std::boolalpha << std::setprecision(12) << std::fixed;
  std::cout.imbue(loc);
  solve();
  return 0;
}

using namespace std;

/* -------------------------------- Library -------------------------------- */

/* ---------------------------------- Main ---------------------------------- */

void solve() {
  ll a, b, x;
  cin >> a >> b >> x;
  cout << (b + x) / x - (a + x - 1) / x << endl;
  return;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,s=1,len,sum[10],ans;
int main(){
	cin>>n;
	int m=n;
	while(m){
		s*=10,len++;
		m/=10;
	}
	s/=10;
	if(len>1) ans+=9;
	if(len>3) ans+=900;
	if(len>5) ans+=90000;
	if(len%2==1) ans+=n-s+1;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void fast()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
}
int main()
{
    fast();
    int k ;
    int n , m ;
    cin >> k >> n >> m  ;
    int i ;
    for ( i = n ; i<=m ; i++)
    {
        if(i%k==0) break;
    }
    if(i<=m) cout << "OK";
    else cout << "NG";






}


Measured memory_bytes: 3648
n = int(input())
alpha_dict = {}
for i,c in enumerate(range(ord('A'),ord('Z')+1)):
  alpha_dict[i] = str(chr(c)).lower()


ans = []
def dfs(s, mx, ans):
  if len(s) == n:
    ans += [s]
    return 
  else:
    for i in range(mx+2):
      dfs(s+alpha_dict[i], max(i, mx), ans)

dfs("", -1, ans)
ans = sorted(ans)
for a in ans:
  print(a)

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

using namespace std;

#define eb emplace_back
#define ii pair<int, int>
#define OK (cerr << "OK" << endl)
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int>
#define all(x) x.begin(), x.end()
#define vvi vector<vector<int>>
#define vvii vector<vector<pair<int, int>>>
#define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v))
#define endl '\n'

constexpr int INF = 2e18;
constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 2e5 + 3;

// #define MULTIPLE_TEST_CASES
void solve() {
  int n;
  cin >> n;
  ++n;

  int m;
  cin >> m;

  string s;
  cin >> s;

  reverse(all(s));
  vector<int> ans;
  set<int, greater<int>> st;

  for (int i = 1; i <= n; ++i) {
    if (s[i - 1] == '0')
      st.emplace(i);
  }

  int i = 1;
  while (i < n) {
    int maxx = min(i + m, n);
    auto it = st.lower_bound(maxx);
    if (*it == i) {
      cout << -1 << endl;
      return;
    }
    ans.eb(*it - i);
    i = *it;
  }

  reverse(all(ans));
  for (int x : ans) {
    cout << x << ' ';
  }
  cout << endl;
}

signed main() {
  // freopen(".in", "r", stdin);
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);

  int t = 1;
#ifdef MULTIPLE_TEST_CASES
  cin >> t;
#endif
  while (t--)
    solve();
}

Measured memory_bytes: 9024
#include <iostream>

using namespace std;

int c[50][50],w,h;
int dx[8]={-1,-1,-1,0,0,1,1,1};
int dy[8]={-1,0,1,-1,1,-1,0,1};
void dfs(int y,int x){
  if(c[y][x]){
    c[y][x]=0;
    int i;
    for(i=0;i<8;i++){
      if(y+dy[i]>=0 && y+dy[i]<h && x+dx[i]>=0 && x+dx[i]<w && c[y+dy[i]][x+dx[i]])
      dfs(y+dy[i],x+dx[i]);
    }
  }
  return;
}

int main(){
  int i,j,ans;
  cin >> w >> h;
  while(1){
    ans=0;
    if(w+h==0)break;
    //for(i=0;i<50;i++)for(j=0;j<50;j++)c[i][j]=0;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++)cin >> c[i][j];
    }
    for(i=0;i<h;i++){
      for(j=0;j<w;j++)if(c[i][j]){
        dfs(i,j);
        ans++;
      }
    }
    cout << ans << endl;
    cin >> w >> h;
  }
  return 0;
}



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

int main(){
	int cnt;
	long long a, b, c, temp1, temp2;
	cin >> a >> b >> c;
	if (a == b && a == c && a % 2 == 0){
		cout << "-1" << '\n';
		return 0;
	}
	cnt = 0;
	while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0){
		cnt++;
		temp1 = a;
		temp2 = b;
		a = (b + c) / 2;
		b = (temp1 + c) / 2;
		c = (temp1 + temp2) / 2;
	}
	cout << cnt << '\n';
	return 0;
}

Measured memory_bytes: 256