akhauriyash/Code-Regression huggingface dataset:
IDENTIFICATION DIVISION.
       PROGRAM-ID. ABC047-B.
       DATA DIVISION.
       FILE SECTION.
       WORKING-STORAGE SECTION.
       77 STR PIC X(18).
       77 W PIC 9(3).
       77 H PIC 9(3).
       77 N PIC 9(3).
       77 I PIC 9(3).
       77 X PIC 9(3).
       77 Y PIC 9(3).
       77 XI PIC 9(3).
       77 YI PIC 9(3).
       77 A PIC 9(1).
       77 J PIC 9(3).
       77 K PIC 9(3).
       01 ARR.
           03 YA OCCURS 100 TIMES.
               05 XA OCCURS 100 TIMES PIC 9(1) VALUE ZERO.
       77 ANS PIC 9(5) VALUE ZERO.
       77 ANSS PIC Z(4)9.

       PROCEDURE DIVISION.
       MAIN-PROCEDURE.
            ACCEPT STR FROM SYSIN.
            UNSTRING STR DELIMITED " "
             INTO W H N.
            PERFORM VARYING I FROM 1 BY 1
             UNTIL N < I
               ACCEPT STR FROM SYSIN
               UNSTRING STR DELIMITED " "
                INTO X Y A
               EVALUATE A
                   WHEN 1
                       COMPUTE XI = X
                       PERFORM VARYING J FROM 1 BY 1
                        UNTIL H < J
                           PERFORM VARYING K FROM 1 BY 1
                            UNTIL XI < K
                               MOVE 1 TO XA (J K)
                           END-PERFORM
                       END-PERFORM
                   WHEN 2
                       COMPUTE XI = X + 1
                       PERFORM VARYING J FROM 1 BY 1
                        UNTIL H < J
                           PERFORM VARYING K FROM XI BY 1
                            UNTIL W < K
                               MOVE 1 TO XA (J K)
                           END-PERFORM
                       END-PERFORM
                   WHEN 3
                       COMPUTE YI = Y
                       PERFORM VARYING J FROM 1 BY 1
                        UNTIL YI < J
                           PERFORM VARYING K FROM 1 BY 1
                            UNTIL W < K
                               MOVE 1 TO XA (J K)
                           END-PERFORM
                       END-PERFORM
                   WHEN 4
                       COMPUTE YI = Y + 1
                       PERFORM VARYING J FROM YI BY 1
                        UNTIL H < J
                           PERFORM VARYING K FROM 1 BY 1
                            UNTIL W < K
                               MOVE 1 TO XA (J K)
                           END-PERFORM
                       END-PERFORM
               END-EVALUATE
            END-PERFORM.
            PERFORM VARYING J FROM 1 BY 1
             UNTIL H < J
               PERFORM VARYING K FROM 1 BY 1
                UNTIL W < K
                   IF XA (J K) = 0 THEN
                       ADD 1 TO ANS
                   END-IF
               END-PERFORM
            END-PERFORM.
            MOVE ANS TO ANSS.
            DISPLAY ANSS.
            STOP RUN.
       END PROGRAM ABC047-B.


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

string s;
int k;
ll dp[101][2][5];

int main() {
  cin >> s;
  int n = (int)s.size();
  cin >> k;
  for (int i = 0; i < 101; i++) for (int j = 0; j < 2; j++) for (int l = 0; l < 5; l++) dp[i][j][l] = 0;
  dp[0][0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 2; j++) {
      for (int l = 0; l <= k; l++) {
        int lim = j == 1 ? 9 : (s[i] - '0');
        for (int m = 0; m <= lim; m++) {
          dp[i + 1][j || (m < lim)][l + (m != 0)] += dp[i][j][l];
        }
      }
    }
  }
  cout << dp[n][0][k] + dp[n][1][k] << endl;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppiii;

void solve() {
  int n;
  cin >> n;
  int rhs = 0;
  int tot = 0;
  while(n--) {
    int a;
    cin >> a;
    rhs = max(rhs, a);
    tot += a;
  }
  if(rhs < tot-rhs) {
    cout << "Yes\n";
  }
  else {
    cout << "No\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
}


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

using namespace std ;
typedef long long ll;
typedef string str;
typedef pair<int, int> pii;
typedef vector<int> vint;
typedef vector<double> vdou ;
typedef vector<ll> vll;
typedef vector<vint> vvint;
typedef vector<str> vstr;
typedef pair<ll,ll> pll ;
typedef vector<pii> vpii ;
typedef vector<pll> vpll ;

#define REP(i, n) for (ll (i) = 0; (i) < (ll)(n); i++) 
#define FOR(i, a, b) for(ll (i) = a; (i) < (ll)b; i++)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define CHI 1000000000000000003
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (ll)x.size()
#define SP(x)  setprecision((ll)x)

const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -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);
  int n ;
  cin >> n ;
  vll a(n) ;
  vll sum(n,0) ;
  ll x1 = 0 ;
  ll x2 = 0 ;
  ll ans1 = 0 ;
  ll ans2 = 0 ;
  vector<char> ch1(n) ;
  vector<char> ch2(n) ;
  REP(i,n){
    cin >> a[i] ;
  }
  REP(i,n){
    if(i%2==0){
      ch1[i] = '+' ;
    }
    else{
      ch1[i] = '-' ;
    }
  }
  
  REP(i,n){
    if(i%2==1){
      ch2[i] = '+' ;
    }
    else{
      ch2[i] = '-' ;
    }
  }
  
  
  sum[0] = a[0] ;
  REP(i,n-1){
    sum[i+1] = sum[i] + a[i+1] ;
  }
  
  REP(i,n){
    int y = sum[i] ;
    y += x1 ;
    if(ch1[i]=='+'){
      if(y>0){
        continue ;
      }
      else if(y==0){
        x1++ ;
        ans1++ ;
      }
      else{
        x1 += abs(y) + 1 ;
        ans1 += abs(y) + 1 ;
      }
    }
    else{
      if(y<0){
        continue ;
      }
      else if(y==0){
        x1-- ;
        ans1++ ;
      }
      else{
        x1 -= abs(y) + 1 ;
        ans1 += abs(y) + 1 ;
      }
    }
  }



  REP(i,n){
    int y = sum[i] ;
    y += x2 ;
    if(ch2[i]=='+'){
      if(y>0){
        continue ;
      }
      else if(y==0){
        x2++ ;
        ans2++ ;
      }
      else{
        x2 += abs(y) + 1 ;
        ans2 += abs(y) + 1 ;
      }
    }
    else{
      if(y<0){
        continue ;
      }
      else if(y==0){
        x2-- ;
        ans2++ ;
      }
      else{
        x2 -= abs(y) + 1 ;
        ans2 += abs(y) + 1 ;
      }
    }
  }
  
  
  cout << min(ans1,ans2) <<endl ;
        
      
        
  
  
  
  return 0 ;
}

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

class Program
{
    static void Main()
    {
        Console.WriteLine(Solve());
        //Solve();
        return;
    }

    public static string Solve()
    {
        long[] input = ReadLongs();
        long N = input[0];
        long K = input[1];
        int[] A = ReadInts();
        bool[] L = new bool[A.Length];
        L[0] = true;
        int next = A[0];
        int[] path = new int[A.Length];
        path[0] = 1;
        int cnt = 1;
        int l = 0;
        for (int i = 0; i < N; i++)
        {
            if (L[next - 1])
            {
                for (int j = 0; j < N; j++)
                {
                    if (path[j] == next)
                    {
                        l = cnt - j;
                        cnt = j;
                        break;
                    }
                }
                break;
            }
            else
            {
                cnt++;
                path[i + 1] = next;
                L[next - 1] = true;
                next = A[next - 1];
            }
        }
        /*
        Console.WriteLine(string.Join(", ", path));
        Console.WriteLine(cnt);
        Console.WriteLine(l);
        */

        if (K < cnt)
        {
            return path[K].ToString();
        }
        else
        {
            return path[(K - cnt) % l + cnt].ToString();
        }

        return "1";
    }

    public static int Gcd(int a, int b)
    {
        if (a < b)
            return Gcd(b, a);
        while (b != 0)
        {
            var remainder = a % b;
            a = b;
            b = remainder;
        }
        return a;
    }

    private static string Read() { return Console.ReadLine(); }
    private static int ReadInt() { return int.Parse(Read()); }
    private static long ReadLong() { return long.Parse(Read()); }
    private static double ReadDouble() { return double.Parse(Read()); }
    private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
    private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
    private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
}


Measured memory_bytes: 43136
#include <iostream>
#include <cstring>

constexpr int MAX_N = 20;
constexpr int MAX_M = 20;
constexpr int MOD = 100000;
constexpr char JOI[] = "JOI";

int N, M;
char field[MAX_M][MAX_N];
int dp[2][1 << MAX_N][2];//dp[current or next][??´???N???????????????????????????"JO"????????????][??´???????????????"J"??????????????????]

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

	std::cin >> M >> N;

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

	dp[0][0][0] = 1;

	int crt = 0, nxt = 1;

	for(int i = 0; i < M; ++i){
		for(int j = 0; j < N; ++j){
			memset(dp[nxt], 0, sizeof(dp[nxt]));

			for(int bit = 0; bit < (1 << N); ++bit){
				for(int f = 0; f < 2; ++f){//??´???????????????'J'??????????????????
					if(dp[crt][bit][f] > 0){//????????????????????¨???????????´?????????????????????
						for(int k = 0; k < 3; ++k){//??????????????????????????????????????????'?'????????????????????¨??????????????????
							if(field[i][j] != '?' && field[i][j] != JOI[k]){
								continue;
							}//????????????????????????????????§????????¨???
							if(bit >> j & 1 && JOI[k] == 'I'){
								continue;
							}//????????????????????§??????????????£?????¨???

							int nbit = bit & ~(1 << j);//?????¨????????????JO???bit????¶??????????
							int nf = JOI[k] == 'J';//?¬????f????±???????

							if(JOI[k] == 'O' && f == 1){
								nbit |= 1 << (j - 1);
							}//JO?????§?????????????¬?????????????????????????????????????

							dp[nxt][nbit][nf] += dp[crt][bit][f];
							if(dp[nxt][nbit][nf] > MOD){
								dp[nxt][nbit][nf] -= MOD;
							}
						}
					}
				}
			}

			std::swap(crt, nxt);
		}
		for(int bit = 0; bit < (1 << N); ++bit){
			dp[crt][bit][0] += dp[crt][bit][1];
			if(dp[crt][bit][0] >= MOD){
				dp[crt][bit][0] -= MOD;
			}
 
			dp[crt][bit][1] = 0;
		}//?????????????????¨?????????????????????'J'??§???????????¨????????????????????§???????????????????????????
	}
	int ans = 1;
	for(int i = 0; i < M; ++i){
		for(int j = 0; j < N; ++j){
			if(field[i][j] == '?'){
				ans = (ans * 3) % MOD;
			}
		}
	}

	for(int bit = 0; bit < 1 << N; ++bit){
		ans = (ans + MOD - dp[crt][bit][0]) % MOD;
	}

	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 19536
N,M,C = map(int,input().split())
Bs = list(map(int,input().split()))
As = []
ans = 0
for i in range(N):
    a = list(map(int,input().split()))
    As.append(a)
for i in range(N):
    sikinoatai = 0
    for j in range(M):
        sikinoatai +=  As[i][j] * Bs[j]
    sikinoatai += C
    if sikinoatai > 0:
        ans += 1
print(ans)
        



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

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t =rep_jijo(n,x/2);
        return t*t%mod;
  }
  return n*rep_jijo(n,x-1)%mod;
}

int main() {
   ll N,K;
   cin>>N>>K;
   ll sum=0;
for(ll x=K;x<=N+1;x++){
     sum+=N*x-x*x+x+1;
     sum%=mod;
}
cout<<sum<<endl;
return 0;
}



Measured memory_bytes: 3616
#include <iostream>
#include<cmath>
#include<vector>
#include<numeric>
int main()
{
    int n = 0;
    int k = 0;
    std::cin >> n >> k;
    std::vector<double> tmp;
    const double v = 1.0 / n;
    for (int i = 1; i <= n;++i) {
        double target = static_cast<double>(k) / i;
        target = std::ceil(target);
        double count = std::log2(target);
        count = std::ceil(count);
        tmp.push_back(std::pow(0.5, count));
    }
    const auto ret = v*std::accumulate(std::begin(tmp), std::end(tmp), 0.0);
    printf("%.9lf",ret);
    return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include<vector>
using namespace std;
#define int long long
#define V vector
#define vel V<int>
#define rep(i,n) for(int i=0;i<n;i++)
#define mkp make_pair
#define pin pair<int,int>
pin solve(V<pin>& ab, int ex) {
	if (!ex) { return mkp(0, 0); }
	V<V<pin>> qab(2);
	int sz = ab.size();
	qab[0].reserve(sz);
	qab[1].reserve(sz);
	for (pin& x : ab) {
		qab[x.second & 1].push_back(mkp(x.first / 2, x.second / 2));
		if (x.first & 1) { qab[(x.second + 1) & 1].push_back(mkp(x.first / 2, (x.second + 1) / 2)); }
	}
	int c = 0;
	for (pin& x : qab[0]) {
		int qc = (2 * x.first + x.second) % 3;
		c ^= (qc + 1);
	}
	if (!c) {
		pin ans = solve(qab[1], ex - 1);
		ans.first *= 2; ans.second *= 2; ans.second++;
		return ans;
	}
	pin ans = solve(qab[0], ex - 1);
  	c=0;
  	for (pin& x : qab[1]) {
		int qc = (2 * x.first + x.second) % 3;
		c ^= (qc + 1);
	}
  	if (!c) {
		ans.first *= 2; ans.second *= 2;
		return ans;
	}
	c = 0;
	for (pin& x : qab[1]) {
		int w = ans.second - x.second-1;
		if ((w & x.first) == w) { c ^= 1; }
	}
	ans.first *= 2; ans.first++; ans.second *= 2; ans.second -= c;
	return ans;
}
signed main() {
	cin.tie(0); ios::sync_with_stdio(false);
	long long inf = 1e17;
	int n; cin >> n;
	V<pin> ab(n);
	rep(i, n) {
		long long a, b; cin >> a >> b;
		ab[i] = { a + inf,b + inf };
	}
	pin ret = solve(ab, 59);
	cout << ret.first - inf << " " << ret.second - inf << "\n";
}


Measured memory_bytes: 10572
#include<iostream>
#include<vector>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);++i)

const int NMAX = 250000;
bool ISPRIME[NMAX];
int ANSWER[NMAX];

int main() {
  REP(i,NMAX) ISPRIME[i]=true;
  ISPRIME[0] = ISPRIME[1] = false;
  for (int n = 2; n * n < NMAX; ++n) {
    if (!ISPRIME[n]) continue;
    for (int kn = 2 * n; kn < NMAX; kn += n) ISPRIME[kn] = false;
  }
  for (int n = 1; n < NMAX; ++n)
    ANSWER[n] = ANSWER[n-1] + (ISPRIME[n]?1:0);

  int n;
  while (cin >> n and n)
    cout << ANSWER[2 * n] - ANSWER[n] << endl;

  return 0;
}

Measured memory_bytes: 2384
#include<stdio.h>

int f[45];

int fibo(int n){
  if(n==0||n==1) return f[n]=1;
  if(f[n]!=-1) return f[n];
  return f[n]=fibo(n-1)+fibo(n-2);
}

int main(){
  int i,n;
  for(i=0;i<45;i++){
    f[i]=-1;
  }
  scanf("%d",&n);
  printf("%d\n",fibo(n));
  return 0;
}

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

using namespace std;

typedef long long ull;

ull gcd(ull x, ull y)
{
    if (y == 0)
        return x;
    return gcd(y, x % y);
}

vector<pair<ull, int>> factorize(ull n)
{
    vector<pair<ull, int>> res;
    for (ull i = 2; i * i <= n; ++i)
    {
        if(n % i) continue;
        res.emplace_back(i, 0);
        while(n % i == 0){
            n /= i;
            res.back().second++;
        }
    }
    if(n != 1) res.emplace_back(n, 1);
    return res;
}

int main()
{
    ull a, b;
    cin >> a >> b;
    ull g = gcd(a, b);
    auto f = factorize(g);
    int ans = f.size() + 1;
    cout << ans << endl;
}

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

void enqueue(int index);
int dequeue(void);

int Q[1001];
int lastQ;

char name[1001][11];
int time[1001];

main(){

  int i, index;
  char inName[11];
  int inTime;
  int elapsedTime = 0;
  int n,q;

  lastQ = 0;

  scanf("%d %d",&n,&q);

  for(i=0; i<n; i++){
    scanf("%s %d",inName,&inTime);

    // storage
    strcpy(name[i],inName);
    time[i] = inTime;

    enqueue(i);
  }

  while(n!=0){

    index = dequeue();

    time[index] -= q;
    elapsedTime += q;

    if(time[index] <= 0){

      elapsedTime += time[index];
      printf("%s %d\n",name[index],elapsedTime);
      n--;

    }else{

      enqueue(index);

    }

  }

  return 0;

}

void enqueue(int index){

  Q[lastQ++] = index;

}

int dequeue(void){

  int i,tmp = Q[0];

  lastQ--;

  for(i=0; i<lastQ; i++){
    Q[i] = Q[i+1];
  }

  return tmp;

}

Measured memory_bytes: 0
#include <iostream>
#include <string.h>
#include <math.h>
using namespace std;

int main(){
    string s;
    cin>>s;
    int n = s.size();
    int min = 700;
    int num = 0;
    for(int i=0; i<n-2; i++){
        
        if(abs((s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0')-753)<min){
            min = abs((s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0')-753);
        }
    }
    cout<<min<<endl;

    return 0;
}

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

typedef long long ll;
const int N = 2000006;

int a[N];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	string s,t;
	cin>>s>>t;
	
	int n = (int)s.size();
	for(int i=0;i<n;i++){
		if(s == t){
			cout<<"Yes";
			return 0;
		}
		t = t[n-1]+t;
		t.pop_back();
	}
	cout<<"No";
	
	return 0;
}


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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define forn(i , n) for(int i=0;i<n;i++)



int main(){
    int a;
    int b;
    int c;
    
    cin >> a >> b >> c;
    
    int counter = 0;
    for(int i = a; i <= b; i++){
        if(c % i == 0){
            counter++;
        }
    }
    
    cout << counter << endl;
    return 0;   
}

Measured memory_bytes: 3092
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
#define ll long long
#define _for(i,a,b) for(int i = (a); i < (b); i++)
#define _rep(i,a,b) for(int i = (a); i <= (b); i++)
const int N = 2e5+100;
int a[N], f[N],n;
int main(){     
    ll k; cin >> n >> k; 
    _for(i,0,n) cin >> a[i];
    _for(i,0,n) cin >> f[i];
    sort(a,a+n); sort(f,f+n, greater<int>());
    ll l = 0 , r = 1e12;
    while(l < r) {
        ll sum = 0; ll x = (l+r) >> 1;
        _for(i,0,n) sum += max(0ll, a[i]-x/f[i]);
        if(sum <= k) r = x;
        else l = x+1;
    }
    cout << l << endl;  
    return 0;
}


Measured memory_bytes: 1792
// 

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <stack>

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

using namespace std;

int main(){
  string s;
  cin >> s;
  int len = s.length();
  int sum = 0;
  for(int i = 0; i < len; i++){
    sum += s[i] - '0';
  }
  // cout << sum << endl;
  int n = stoi(s);
  if(n % sum == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

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

    int a[60], b[60];

    for (int i = 0; i < M; i++)
        cin >> a[i] >> b[i];

    int num[60] = {0};

    for (int i = 0; i < M; i++)
    {
        num[a[i]]++;
        num[b[i]]++;
    }

    for (int i = 1; i <= N; i++)
    {
        cout << num[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;
int num[4][3][10];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int x,y,z,m;
		scanf("%d%d%d%d",&z,&x,&y,&m);
		num[z-1][x-1][y-1]+=m;
	}
	for(int i=0;i<4;i++)
	{
		for(int j=0;j<3;j++)
		{
			for(int k=0;k<10;k++)
			printf(" %d",num[i][j][k]);
			printf("\n");
		}
		if(i<3)	
		{
		for(int k=0;k<20;k++)
		printf("#");
		printf("\n");
		}
				
	}
	return 0;
}


Measured memory_bytes: 2652
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iterator>
#include <set>
#include <map>
using namespace std;

const double PI=acos(-1);

int main(){
    string s;
    cin >> s;
    if(s == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
    return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

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

#define INF INT_MAX/3

int main(){
    cin.sync_with_stdio(false);
    string s;
    cin >> s;
    bool ok = true;
    set<char> ss;
    rep(i, s.size()) {
        if (ss.count(s[i])) ok = false;
        ss.insert(s[i]);
    }
    if (ok) cout << "yes" << endl;
    else cout << "no" << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
S = [input() for i in range(n)] 
alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
num = [[0 for _ in range(n)] for _ in range(26)]
ans = []
for fig in alphabet:
  for i in range(n):
    num[alphabet.index(fig)][i] = S[i].count(fig)
  for j in range(min(num[alphabet.index(fig)])):
    ans.append(fig)
print(("").join(ans))

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
bool chmin(T &a,T b){if(a>b){a=b;return true;}else return false;}
template<typename T>
bool chmax(T &a,T b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll k,n;cin>>k>>n;
  vector<ll>a(n);
  rep(i,0,n)cin>>a[i];
  rep(i,0,n-1)chmax(res,a[i+1]-a[i]);
  chmax(res,k+a[0]-a[n-1]);
  cout<<k-res<<endl;
  return 0;
}

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

int main(){
  int N,M;
  cin>>N>>M;
  vector<int> A(N,0);
  for(int i=0;i<M;i++){
    int s,c;
    cin>>s>>c;
    s--;
    if((A[s]!=0 && A[s]!=c) || (s==0 && c==0 && N!=1)){
      cout<<-1<<endl;
      return 0;
    }
    A[s]=c;
  }
  if(A[0]==0 && N!=1)
    A[0]=1;
  for(int i:A)
    cout<<i;
  cout<<endl;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))

ans = [[0 for j in range(W)] for h in range(H)]
flg = True
h = 0
w = 0
for i, a in enumerate(A):
    for _ in range(a):
        ans[h][w] = i + 1
        if flg:
            if w < W - 1:
                w += 1
            else:
                h += 1
                flg = False
        else:
            if w > 0:
                w -= 1
            else:
                h += 1
                flg = True
for l in ans:
    print(" ".join(map(str, l)))


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

constexpr ll MOD = 1e9+7;

using namespace __gnu_pbds;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

ll fact[100001];

int main() {

  fact[0] = 1;
  REP(i, 1, 100001) {
    fact[i] = fact[i-1] * i % MOD;
  }

  for(int N, R; cin >> N && N;) {
    cin >> R;
    vector<int> vs(N);
    ordered_set ost;
    rep(i, N) vs[i] = i;
    auto vs_rand = vs;
    random_shuffle(all(vs_rand));
    rep(i, N) ost.insert(vs_rand[i]);

    rep(i, R) {
      int s, t; cin >> s >> t; s--, t--;
      swap(vs[s], vs[t]);
    }

    ll ans = 0;

    rep(i, N) {
      ans += (ll)ost.order_of_key(vs[i]) * fact[N - i - 1] % MOD;
      ost.erase(vs[i]);
      ans %= MOD;
    }

    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 9096
def f s,ans,n
  n.times{|i|
    if (s[(i+1)%n])^(!ans[i])^(!ans[(i+1)%n])
      ans << true
    else
      ans << false
    end
  }
  
  return -1 if ans[-2]!=ans[0] || ans[-1]!=ans[1]
  
  return ans[0..-3]
end

n = gets.to_i
s = gets.chomp.chars.map{|c|c==?o}

ans = f(s,[true,true],n)

if ans==-1
  ans = f(s,[true,false],n)
end

if ans==-1
  ans = f(s,[false,true],n)
end

if ans==-1
  ans = f(s,[false,false],n)
end

if ans == -1
  puts ans
else
  puts ans.map{|t| t ? ?S : ?W}*''
end

Measured memory_bytes: 14228
import math
a, b, C = list(map(float, input().split()))
S = 1/2*a*b*math.sin(math.radians(C))
c = pow(pow(a,2)+pow(b,2)-2*a*b*math.cos(math.radians(C)),1/2)
L = a + b + c
h = b*math.sin(math.radians(C))

print(S)
print(L)
print(h)


Measured memory_bytes: 5696
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

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


const int MAX = 1000000;
int sum[MAX + 10];
int last[MAX + 10];
int key(int n)
{
	return 2 * last[n] - sum[n];
}
int main()
{
	fill_n(sum, MAX + 3, 0);
	for (int i = 2; i <= MAX; ++i)
	{
		if (!sum[i])
		{
			for (int j = i; j <= MAX; j += i)
			{
				sum[j] += i;
				last[j] = i;
			}
		}
	}

	int a, b;
	while (scanf("%d%d", &a, &b), a | b)
		puts(key(a) > key(b) ? "a" : "b");
}

Measured memory_bytes: 8560
a, b = map(int, input().split())
if a % 2 == 0:
    if b % 2 == 0:
        print(int((a+b)/2))
    else:
        print("IMPOSSIBLE")
else:
    if b % 2 == 0:
        print("IMPOSSIBLE")
    else:
        print(int((a+b)/2))

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

int main(int argc, char **argv)
{
	char a[100];
	char b[100];
	char c[100];
	scanf("%s",a);
	scanf("%s",b);
	scanf("%s",c);
	printf("%c%c%c\n",a[0],b[1],c[2]);
	return 0;
}

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

int main(){
    int a,b,n;
    cin>>a>>b>>n;
    for(int i = 0;i<n;i++){
        int x,y;
        cin>>x>>y;
        
        if(x<b && a<y){
            cout<<1<<endl;
            return 0;
        }
    }
    cout<<0<<endl;
    return 0;
}


Measured memory_bytes: 3100
n,k=map(int,input().split())
r=[0]*(n+1)
for i in range(k):
    for x in list(map(int,input().split()))[1:]:r[x]=i
a= [0] * (n + 1)
for _ in range(int(input())):
    p,q=map(int,input().split())
    if r[p]==r[q]:a[q]=a[p]=1
print(sum(a))

Measured memory_bytes: 7624
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<unordered_map>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep2(i,n) for(int i = (n - 1); i >= 0; i--)
#define PI 3.141592653589793

using namespace std;
using ll = long long;

int to[200000];

int main() {

	ll n, ans = 0;
	cin >> n;
	vector<ll> re;

	rep(i, n) {
		ll x;
		cin >> x;
		to[x]++;
		ans += x;
		if (to[x] == 1) {
			re.push_back(x);
		}
	}

	ll q;
	cin >> q;
	rep(i, q) {
		ll b, c;
		cin >> b >> c;
		ans -= to[b] * b;
		ans += to[b] * c;
		to[c] += to[b];
		to[b] = 0;
		cout << ans << endl;
	}



	return 0;
}

Measured memory_bytes: 4272
#include <stdio.h>

int i, j, k, n, A[100];

void pr(){ for(j=0;j<n;j++)printf("%d%s",A[j],j==n-1?"\n":" ");}
int main(){
	scanf("%d", &n);
	while(i < n) scanf("%d", &A[i++]);
	for(i = 0; i < n; i++){
		for(j = i, k = A[i]; j > 0 && k < A[j-1]; j--) A[j] = A[j-1];
		A[j] = k;
		pr();
	}
	return 0;
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    string s;
    int y,m,d;
    cin >> s;
    if(s=="#") return 0;
    cin >> y >> m >> d;
    if(y>31||(y==31&&m>=5)){
      cout << "?" SP y-30 SP m SP d << endl;
    }else{
      cout << "HEISEI" SP y SP m SP d << endl;
    }
  }
  return 0;
}



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

#define SENTINEL 1000000000

int count=0;

void merge(int A[],int left,int mid,int right){
  int n1,n2,i,j,k;
  int *L,*R;
  n1=mid-left;
  n2=right-mid;
  L=(int *)malloc(sizeof(int)*(n1+1));
  R=(int *)malloc(sizeof(int)*(n2+1));
  for(i=0;i<=n1-1;i++){
    L[i]=A[left+i];
  }
  for(j=0;j<=n2-1;j++){
    R[j]=A[mid+j];
  }
  L[n1]=SENTINEL;
  R[n2]=SENTINEL;
  i=0;
  j=0;
  for(k=left;k<=right-1;k++){
   if(L[i]<=R[j]){
      A[k]=L[i];
      i++;
      count++;
    }
    else{
      A[k]=R[j];
      j++;
      count++;
    }
  }
  free(L);
  free(R);
}

void mergeSort(int A[],int left,int right){
  int i,mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}

int main(){

    int N;
    scanf("%d", &N);

    int A[N];
    for (int i = 0; i < N; i++){
        scanf("%d", &A[i]);
    }

    mergeSort(A, 0, N);

    int judge = 0;

    for (int i = 0; i < N-1; i++){
        if(A[i] == A[i+1]){
            judge += 1;
        }
    }

    if (judge == 0){
        printf("YES");
    }else{
        printf("NO");
    }

    return 0;
}

Measured memory_bytes: 1908
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

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

int n, a[N];
string s, t;

int32_t main(){_
   
   vector<int>  a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
};

   int k;
   cin >> k;

   cout << a[k-1];

   return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn._

object Main extends App {


  val Array(n,w) = readLine().split(" ").map(_.toInt)
  val wv = Array.fill(n)(readLine().split(" ").map(_.toInt))

  val MaxV = 1e5.toInt + 10
  val MaxW = 1e9.toInt + 10
  val dp = Array.fill(n+1)(Array.fill(MaxV)(1e17.toLong))
  dp(0)(0) = 0
  def solve() = {
    for {
      i    <- 0 until n
      sumV <- 0 until MaxV
    } {
      if(sumV - wv(i)(1) >= 0) {
        dp(i+1)(sumV) = Math.min(dp(i)(sumV), dp(i)(sumV - wv(i)(1)) + wv(i)(0))
      } else dp(i+1)(sumV) = dp(i)(sumV)
    }

    var ans = 0L
    for(i <- 0 until MaxV) {
      if(dp(n)(i) <= w) ans = i
    }
    ans
  }





  println(solve())

}



Measured memory_bytes: 134376
S = input()

def check(S):
    N = len(S)
    for i in range(N):
        if S[i] != S[N - i - 1]:
            return False
    return True

if check(S) and check(S[0:int(len(S) / 2)]):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
/*
 * a.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

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

  if (a < b) cout << "a < b" << endl;
  else if (a > b) cout << "a > b" << endl;
  else cout << "a == b" << endl;
  return 0;
}

Measured memory_bytes: 1156
//
// B - Contest with Drinks Easy
//

#include <iostream>

using namespace std;

int main() {
    int N;
    cin >> N;
    int T[N + 1], sum = 0;
    for (int i = 1; i <= N; i++) {
        int t;
        cin >> t;
        T[i] = t;
        sum += t;
    }
    int M;
    cin >> M;
    for (int i = 0; i < M; i++) {
        int P, X;
        cin >> P >> X;
        cout << sum - T[P] + X << endl;
    }
}

Measured memory_bytes: 256
A = int(input()) # num of 500 coins
B = int(input()) # num of 100 coins
C = int(input()) # num of  50 coins
X = int(input()) # amount of payment

ans = 0

Bmax = B * 100
Cmax = C * 50

for a in range(A+1):
    b = 0
    rest = X - 500 * a
    if rest < 0:
        break
    if rest > Bmax + Cmax:
        continue
    if rest == 0:
        ans += 1
        # print(a,b,rest)
        continue
    else: # 0 < rest <= Bmax + Cmax
        for b in range(B+1):
            rest = X - 500 * a - 100 * b
            if rest < 0:
                break
            if rest > Cmax:
                continue
            else: # 0 <= rest <= Cmax
                ans += 1
                # print(a,b,rest)

print(ans)


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

int main(){
  int n, mini=0, maxi=0;
  cin>>n;
  vector<int> a(n), b(8,0);
  for(int i=0;i<n;i++){
    cin>>a[i];
    if(a[i]>=3200){
      maxi++;
    }else if(a[i]>=2800){
      b[0]++;
    }else if(a[i]>=2400){
      b[1]++;
    }else if(a[i]>=2000){
      b[2]++;
    }else if(a[i]>=1600){
      b[3]++;
    }else if(a[i]>=1200){
      b[4]++;
    }else if(a[i]>=800){
      b[5]++;
    }else if(a[i]>=400){
      b[6]++;
    }else{
      b[7]++;
    }
  }
  
  for(int i=0;i<8;i++){
    if(b[i]>0){
      mini++;
    }
  }
  cout<<(mini == 0 ? 1 : mini)<<" "<<mini+maxi<<endl;
  return 0;
}
  

Measured memory_bytes: 256
import itertools

user_input = input()
S = list(user_input)
N = int(user_input)
l = len(S)
bit_max = l-1

A = ["","+"]

if l == 1:
    print(N)

else:
    bit_max = l-1
    A = ["","+"]
    ans = 0

    for i in itertools.product(A,repeat=bit_max): 
        tmp = []
        for j,v in enumerate(S):
            tmp.append(v)
            if i[j] == "+":
                tmp.append("+")
            if j == bit_max -1:
                tmp.append(S[j+1])
                break
        
        values = "".join(tmp)
        values2 = values.split("+")

        tmp3 = 0
        for k in values2:
            tmp3 += int(k)
        
        ans += tmp3

    print(ans)

Measured memory_bytes: 3064
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int input = sc.nextInt();
		int count = 0;
		for (int i = 0; i < 4; i++) {
		    int number = input % 10;
		    if (number == 2) {
		        count++;
		    }
		    input /= 10;
		}
        System.out.println(count);
	}
}

Measured memory_bytes: 22868
#include<bits/stdc++.h>
#define faster  ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define pb push_back
const double PI = acos(-1.0);
using namespace std;

int main()
{
    faster

    int n;
    cin>>n;

    ll s=0,a[n];

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

        if(i!=0)
        {
            if(a[i-1]>a[i])
            {
                s=s+(a[i-1]-a[i]);

                a[i]=a[i-1];
            }
        }

    }

    cout<<s<<endl;




    return 0;
}




Measured memory_bytes: 5196
A,B,C = map(int, input().split())
a = [A]
b = [B]
c = [C]
count = 0
sum = A + B + C
for i in range(10 ** 9):

    if a[i] == b[i] == c[i]:
        if a[i] % 2 == 0 and b[i] % 2 == 0 and c[i] % 2 == 0:
            count = -1
            break
        else:
            count = 0
            break
    elif a[i] % 2 == 0 and b[i] % 2 == 0 and c[i] % 2 == 0:
        a.append(b[i] / 2 + c[i] / 2)
        b.append(a[i] / 2 + c[i] / 2)
        c.append(a[i] / 2 + b[i] / 2)
        count += 1
    else:
        break


print(count)


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

using tlll = tuple<ll,ll,ll>;



struct UnionF {
    vector<ll> S;
    
    UnionF(ll a){
        S=vector<ll>(a);
        for(ll i=0;i<a;i++)S[i]=i;
    }

    ll FFi(ll i){
        if(S[i]==i)return i;
        S[i]=FFi(S[i]);
        return S[i];
    }

    void marge(ll a,ll b){
        ll aa=FFi(a),bb=FFi(b);
        if(aa==bb)return;
        ll mms = (aa<bb)?aa:bb;
        S[aa]=mms;S[bb]=mms;
    }
    
    bool equalU(ll a,ll b){return (FFi(S[a])==FFi(S[b]));}
    
};

int main() {

    ll N,M;
    cin >> N >> M;
    UnionF U(N);
    for(ll i=0;i<M;i++){
        ll s1,s2;
        cin >> s1 >> s2;
        U.marge(s1, s2);
    }
    
    set<ll> road;
    for(ll i=0;i<N;i++){
        
        ll s1 = U.FFi(i);
        if(s1!=0)road.insert(s1);
        
    }
    
    cout << road.size() << endl;
    
}

Measured memory_bytes: 7760
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    int N;
    cin >> N;
    vector<P> table, table2;
    for(int i = 0; i < N; ++i){
        string s;
        cin >> s;
        int left = 0, right = 0;
        for(int j = 0; j < (int)s.length(); ++j){
            if(s[j] == '(') ++left;
            else{
                if(left)    --left;
                else    ++right;
            }
        }
        if(left == 0 && right == 0) continue;
        if(left - right < 0)    table2.emplace_back(left, left - right);
        else    table.emplace_back(right, left - right);
    }
    sort(table.begin(), table.end());
    sort(table2.rbegin(), table2.rend());
    int total = 0;
    for(auto& p : table){
        if(total - p.first < 0){
            cout << "No\n";
            return 0;
        }
        total += p.second;
    }
    for(auto& p : table2){
        if(total + p.second - p.first < 0){
            cout << "No\n";
            return 0;
        }
        total += p.second;
    }
    if(total == 0)  cout << "Yes\n";
    else    cout << "No\n";
}


Measured memory_bytes: 11244
def isPalindrome(words ,start, end):
  i = start - 1
  j = end - 1
  while i < j :
    if words[i] != words[j]:
      return False
    i+=1
    j-=1

  return True

S = list(input())
N = len(S) #words length

if isPalindrome(S ,1, N) and isPalindrome(S, 1, int((N-1)/2)) and isPalindrome(S, int((N+3)/2), N) :
  print('Yes')
else:
  print('No')


Measured memory_bytes: 38512
#include<bits/stdc++.h>
using namespace std;
string s;
int main(){
	cin>>s;
	for (int i=0;i<s.size();i++)
		if ((i%2==0&&s[i]=='L')||(i%2==1&&s[i]=='R')){
			cout<<"No"<<endl;
			return 0;
		}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] card= new int[n];
		for(int i = 0; i < n; i++){
			card[i] = sc.nextInt();
		}
		Arrays.sort(card);
		int alice = 0;
		int bob = 0;
		for(int i = card.length - 1; i >= 0; i--){
			alice += card[i];
			i--;
			if(i >= 0){
				bob += card[i];
			}
		}
		System.out.println(alice - bob);
 	}
}




Measured memory_bytes: 35916
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i = 0; i< (n);i++)
#define SORT(a) sort((a).begin(),(a).end());
#define che(a,string) cout<<string<<":"<<(a)<<endl;
#define ch(a,string) cout<<string<<":"<<(a)<<" ";
using namespace std;
typedef pair<int,int> p;
int main(){
	int n,m;
	cin >> n>>m;//n個のコマとM個の目的地。
	vector<long long> A(m);
	rep(i,m){
		cin>>A[i];
	  }
	  SORT(A);
	  vector<long long> B(m-1);
   rep(i,m-1){
	   B[i]=A[i+1]-A[i];
	   }
	   SORT(B);
	   int ans = 0;
	   rep(i,m-n){
		 ans +=B[i];
		 }
		 cout << ans <<endl;
	 }
 



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main() {
  map<char, char> mp =
      { { 'A', 'T' }, { 'T', 'A' }, { 'G', 'C' }, { 'C', 'G' } };
  char c;
  cin >> c;
  cout << mp[c];
  return 0;
}

Measured memory_bytes: 256
#pragma warning (disable:4996)
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
long long a[2000005] = { 0 };
long long c[2000005] = { 0 };
int main()
{
	long long n;
	cin >> n;
	for (long long i = 0; i < n; i++)
	{
		cin >> a[i];
		c[i] = a[i] - (i+1);
	}
	sort(c, c + n);
	long long b = c[n / 2];
	long long sadness=0;

	for (long long i = 0; i < n; i++)
	{
		sadness = sadness + abs(c[i] - b);
	}

	cout << sadness << endl;
	return 0;
}

Measured memory_bytes: 5888
#include <iostream>
#include <string>
#include <algorithm>
#include <cassert>
#include <set>
#include <vector>
#include <cmath>
#include <bitset>
#include <functional>
#include <limits>
#include <map>
using namespace std;

typedef long long ll;
#define rep1(i, n) for(ll i = 1; i <=(ll)(n); i++)
#define rep0(i, n) for(ll i = 0; i <=(ll)(n); i++)

ll pow(ll a, ll n) { //compute a^n with o(logn)
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}

ll pow(ll a, ll n, ll mod) { //compute a^n (mod mod) with o(logn)
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

const int MAX = 199;
const int MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//順列計算
ll PER(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[n - k] % MOD) % MOD;
}

int main(){
    ll n;
    cin >> n;
    ll a[n+1];
    rep1(i,n) cin >> a[i];
    ll money = 1000;
    ll num = 0;
    if(n == 2){
        ll k = floor((int)money/a[1]);
        money = max(money, money + k*(a[2] - a[1]));
        cout << money << endl;
        return 0;
    }

    for(int i = 2; i <= n;i++){
        if(a[i-1]< a[i]){
            //buy and sell
            num = money/a[i-1];
            money += num*(a[i]-a[i-1]);
            num = 0;
        }
    }
    cout << money << endl;
    return 0;
}

Measured memory_bytes: 3140
//
// Created on 2019-02-09.
//
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
template<class T> bool INRANGE(T x,T a,T b) { return a<=x&&x<=b; }

#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

#define PB push_back
#define INF 1e9
#define MOD 1e9+7
#define EPS 1e-9

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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


    string s;
    cin >> s;

    ll ans = 0;
    char w = '0';
    char b = '1';
    char befo;
    REP(i, s.length()){
        if (i == 0){
            if (s[i] == w) befo = w;
            else befo = b;
            continue;
        } else {
            if (s[i] == befo) {
                ans++;
                if (s[i] == w) befo = b;
                else befo = w;
            } else {
                if (s[i] == w) befo = w;
                else befo = b;
            }
        }
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 512
n, x = map(int, input().split())
 
P = [0] * (n + 1)
P[0] = 1
for i in range(1, n + 1):
    P[i] = P[i - 1] * 2 + 1

A = [0] * (n + 1)
A[0] = 1
for i in range(1, n + 1):
    A[i] = A[i - 1] * 2 + 3

#print(P)
#print(A)
 
def dfs(n, x):
    if n == 0:
        return 1
    if x == 1:
        return 0
    elif x <= 1 + A[n - 1]:
        return dfs(n - 1, x - 1)
    elif x == 1 + A[n - 1] + 1:
        return P[n - 1] + 1
    elif 1 + A[n - 1] + 1 < x < 1 + A[n - 1] + 1 + A[n - 1] + 1:
        return P[n - 1] + 1 + dfs(n - 1, x - 1 - A[n - 1] - 1)
    elif x >= 1 + A[n - 1] + 1 + A[n - 1] + 1:
        return P[n - 1] + 1 + P[n - 1]
    
print(dfs(n, x))    

Measured memory_bytes: 3064