akhauriyash/Code-Regression huggingface dataset:
"use strict";
const main = input => {
    const a = Number(input[0].split(' ')[0]);
    const b = Number(input[0].split(' ')[1]);
    const k = Number(input[0].split(' ')[2]);
    let count=0;
    for(let i=Math.max(a,b); i>=0; i--) {
        if (a%i==0 && b%i==0) {
            count++
            if (count == k) {
                console.log(i);
                return;
            }
        }
    }
}
main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  vector<int> A(N);
  for(int i=0; i<N; i++){
   cin >> A.at(i);
  }
  
  vector<int> B(N);
  for(int i=0; i<N; i++){
   cin >> B.at(i);
  }
  
  vector<int> C(N-1);
  for(int i=0; i<N-1; i++){
   cin >> C.at(i);
  }
  
  int S=0;

  
  for(int i=0; i<N; i++){
    int T=A.at(i)-1;
    S+=B.at(T); 
  }
  
  for(int i=0; i<N-1; i++){
    int T=A.at(i)-1;
    if(A.at(i)+1==A.at(i+1)){
      S+=C.at(T); 
    }
  
  }
  cout << S << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int a[6] = {1, 5, 10, 50, 100, 500};
  int sum = 0;
  for (int i = 0; i < 6; i++) {
    int c;
    cin >> c;
    sum += a[i] * c;
  }
  cout << (sum >= 1000) << endl;

  return 0;
}


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

using namespace std;



int main(){
	int in;
	int prime[60001] = {};

	vector<int> p;
	int i, j;
	for (i = 2; i*i < 60000; i++){
		if (prime[i] == 0){
			for (j = 2; i*j <= 60000; j++){
				prime[i*j] = 1;
			}
		}
	}
	for (i = 1; i < 60001; i++){
		if (prime[i] == 0){
			p.push_back(i);
		}
	}



	while (cin >> in){
		if (in == 0){
			break;
		}
		for (i = in; i > 0; i--){
			if (prime[i] == 0 && prime[i - 2] == 0){
				cout << i - 2 << " " << i << endl;
				break;
			}
		}		

	}
}

Measured memory_bytes: 1512
#include <bits/stdc++.h>
using namespace std;
int ans = 0;
using ll = long long;
ll n;

vector<int> d = {3, 5, 7};
void dfs(ll a)
{
    if (a > n) return;
  
    bool flag3 = false;
    bool flag5 = false;
    bool flag7 = false;

    ll b = a;
    while(b % 10 != 0)
    {
        ll x = b % 10;
        b /= 10;
        if(x == 3) flag3 = true;
        else if(x == 5) flag5 = true;
        else if(x == 7) flag7 = true;
    }
    int y = b % 10;
    if(y == 3) flag3 = true;
    else if(y == 5) flag5 = true;
    else if(y == 7) flag7 = true;
    if(flag3 && flag5 && flag7) ans++;

    for(int i = 0; i < 3; i++)
    {
        ll k = a*10 + d[i];
        dfs(k);
    }
}

int main()
{
    cin >> n;

    dfs(0);
    cout << ans << endl;
}



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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int n,h,w;
	cin>>n>>h>>w;
  	int ans=(n-h+1)*(n-w+1);
  	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 256
n = int(input())
p = list(map(int,input().split()))
p.sort()

a1 = max(p)
a2 = min(p)
half = (a1+1) // 2
s = n // 2
graph = [0] * n

while True:
    if graph[s] != 0:
        break
    else:
        graph[s] += 1
    if p[s] < half:
        if abs(p[s] - half) < abs(a2 - half):
            a2 = p[s]
        s += 1
    elif p[s] > half:
        if abs(p[s] - half) < abs(a2 - half):
            a2 = p[s]
        s -= 1
    else:
        a2 = p[s]
        break
    if s == 0 or s == n:
        break
print(a1, a2)

Measured memory_bytes: 14428
#include <iostream>
#include <set>

using namespace std;

#define ALL(x) begin(x), end(x)

int main() {
  set<char> s;
  char c;
  while(cin >> c) {
    s.insert(c);
  }

  string ans = "None";
  for(c = 'a'; c <= 'z'; ++c) {
    if(!s.count(c)) {
      ans = c;
      break;
    }
  }

  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,p,w,g,y;
  string x;
  cin >> N;
  p = w = g = y = 0;
  
  for (int i =0; i < N; i++){
    cin >> x;
    if ( x == "P")
      p = 1;
    else if ( x == "W")
      w = 1;
    else if ( x == "G")
      g = 1;
    else if ( x == "Y")
      y = 1;
   }
int sum = p + w + g + y;
  if (sum == 3)
    cout << "Three" << endl;
  else if (sum == 4)
    cout << "Four" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > > 
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    
    ll a,b ; cin >> a >> b;
    ll inp = a * 100 + b ;
    cout << inp / 101 << endl;

    
    
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1ll<<60;
const double EPS = 1e-8;
const int MOD = 1000000007;

#define MAXSIZE 4001
int n;
ll a[MAXSIZE];
ll optimalBST(ll a[], int n) {
  static ll W[MAXSIZE];
  static ll X[MAXSIZE][MAXSIZE];
  static int K[MAXSIZE][MAXSIZE]; // +
  for (int i = 0; i < n; ++i) {
    W[i+1] = W[i] + a[i];
  }
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j <= n; ++j) {
      X[i][j] = (i+1==j) ? 0 : INF;
      if(i+1 == j) K[i][j] = j;
    }
    X[i][i] = 0;
  }
  for (int w = 2; w <= n; ++w) 
    for (int i = 0, j; (j = i+w) <= n; ++i){
      for (int r = K[i][j-1]; r <= K[i+1][j]; ++r) { // c
        ll c = X[i][r] + X[r][j] + W[j] - W[i];
        if (X[i][j] > c) { X[i][j] = c; K[i][j] = r; } // c
      }
    }
  return X[0][n];
}
main(){
	ios::sync_with_stdio(false);
	while(cin >> n){
		REP(i, n) cin >> a[i];
		cout << optimalBST(a, n) << endl;
	}
	return 0;
}

Measured memory_bytes: 187900
n, m = map(int, input().split())
cnt = [0] * (n + 2)
cnt_sum = [0] * (n + 1)
for _ in range(m):
    l, r = map(int, input().split())
    cnt[l] += 1
    cnt[r + 1] -= 1
cnt_sum[0] = cnt[0]
for i in range(1, n + 1):
    cnt_sum[i] = cnt_sum[i - 1] + cnt[i]
print(cnt_sum.count(m))

Measured memory_bytes: 8048
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
  int n, k, x;
  while(cin>>n>>k){
    int tmp;
    for(int i=0; i<n; ++i){
      cin>>x;
      if(x==1)
        tmp=i;
    }
    int ans;
    ans=n;
    for(int i=max(0, tmp-k+1); i<min(n, tmp+k); ++i){
      ans=min(ans, (n-1-i+k-2)/(k-1) + (i+k-2)/(k-1));
    }
    cout<<ans<<endl;
  }
  return 0;
}




Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define M 200010
#define mmp make_pair
using namespace std;
int read() {
	int nm = 0, f = 1;
	char c = getchar();
	for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
	for(; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
	return nm * f;
}
ll a[M], b[M], n, ans, tm, now, tp, an[M], bn[M], sta[M], tot, now2;
multiset<ll> st;
multiset<ll>:: iterator it;
ll bude = 0;
map<ll, int> mp;
ll tmp;
int father[M];
int find(int x) {
	return father[x] == x ? x : father[x] = find(father[x]);
}
int main() {
//	freopen("replace.in", "r", stdin);
	//freopen("replace.out", "w", stdout);
	n = read();
	for(int i = 1; i <= n; i++) a[i] = read(), now ^= a[i];
	for(int i = 1; i <= n; i++) b[i] = read(), st.insert(b[i]), now2 ^= b[i];
	for(int i = 1; i <= n; i++) {
		it = st.find(a[i]);
		if(it == st.end()) tm++, bude = a[i];
		else st.erase(it);
		if(a[i] == b[i]) continue;
		ans++;
	}
	for(int i = 1; i <= n; i++) {
		if(a[i] != b[i]) break;
		if(i == n) {
			cout << "0\n";
			return 0;
		}
	}
	if(st.find(now) == st.end()) tm++;
	else st.erase(st.find(now));
	if(tm >= 2 || st.size()) {
		cout << "-1" << "\n";
		return 0;
	}
	tp = 0, tot = 0;
	for(int i = 1; i <= n; i++) {
		if(a[i] == b[i]) continue;
		sta[++tot] = a[i];
		an[++tp] = a[i];
		bn[tp] = b[i];
	}
	sta[0] = -1;
	sta[++tot] = now;
	sta[++tot] = now2;
	sort(sta + 1, sta + tot + 1);
	int cnt = 0;
	for(int i = 1; i <= tot; i++) {
		if(sta[i] == sta[i - 1]) continue;
		mp[sta[i]] = ++cnt;
	}
	for(int i = 1; i <= cnt; i++) father[i] = i;
	for(int i = 1; i <= tp; i++) {
		int vi = mp[an[i]], vj = mp[bn[i]];
		vi = find(vi), vj = find(vj);
		if(vi == vj) continue;
		father[vi] = vj;
	}
	int vi = mp[now], vj = mp[now2];
	vi = find(vi), vj = find(vj);
	if(vi != vj)
		father[vi] = vj;
	for(int i = 1; i <= cnt; i++) if(father[i] == i) ans++;
	cout << ans - 1<< "\n";
	return 0;
}
/*
5
1 2 3 0 5
1 2 3 5 5

1
2
2
*/

Measured memory_bytes: 15360
route = Array.new(100,0)
readlines.each do |line|
  frm,to = line.split.map(&:to_i)
  if frm == 0 && to == 0
    if route[1].odd? && route[2].odd? && route.drop(3).all?(&:even?)
      puts"OK" 
    else
      puts"NG"
    end
    route = Array.new(100){0}
  else
    route[frm] +=1 
    route[to] +=1 
  end
end

Measured memory_bytes: 6108
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n = int(input())
score = [0] * n
for i in range(n):
    s = input().split()
    score[i] = (s[0].strip(), int(s[1]), i + 1)

for s in sorted(score, key=lambda l: (l[0], -l[1])):
    print(s[2])


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

import numpy as np

n,k = map(int,input().split())
p_list = np.fromstring(input(),int,sep=' ')

Cumulative_sum = np.zeros(n+1, int)
Cumulative_sum[1:] = p_list.cumsum()

length_k_sum_list = Cumulative_sum[k:] - Cumulative_sum[0:-k]

print((length_k_sum_list.max()+k)/2)


Measured memory_bytes: 19920
#include <bits/stdc++.h>
#define ll long long
 
using namespace std;
 
int main(){
  int n,i,j,w;
  scanf("%d %d",&n,&w);
  vector<pair<int,int>>a(n);
  vector<vector<ll>>dp(n,vector<ll>(w+5,0));
  for(i=0;i<n;i++){
    scanf("%d %d",&a[i].first,&a[i].second);
  }
  for(i=0;i<=w;i++){
    if(a[n-1].first<=i){
      dp[n-1][i] = a[n-1].second;
    }
  }
  for(i=n-2;i>=0;i--){
    for(j=0;j<=w;j++){
      if(a[i].first<=j){
        dp[i][j] = dp[i+1][j]<(ll)a[i].second + dp[i+1][j-a[i].first]?a[i].second + dp[i+1][j-a[i].first]:dp[i+1][j];
      }
      else dp[i][j] = dp[i+1][j];
    }
  }
  printf("%lld",dp[0][w]);
}

Measured memory_bytes: 79488
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define in insert
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int n;
    scanf("%d", &n);
    vector<int> dp(3, 0);
    forn(i, n){
        vector<int> new_dp(3, 0);
        vector<int> c(3);
        for(int j = 0; j < 3; ++j) {
            scanf("%d", &c[j]);
        }
        for(int k = 0; k < 3; ++k){
        for(int j = 0; j < 3; ++j){
            if(k != j){
                    new_dp[j] = max(new_dp[j], dp[k] + c[j]);
                }
            }
        }
        dp = new_dp;
    }
    printf("%d", max({dp[0], dp[1], dp[2]}));
}

Measured memory_bytes: 256
#include<stdio.h>

int block[10][5];
int p[10000];
void trace(int h);

void del(int h,int c) {
	int P2;
	while (1) {
		P2 = p[c];
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < 3; j++) {
				if (block[i][j] == block[i][j + 1] && block[i][j + 1] == block[i][j + 2]) {
					p[c] += block[i][j] * 3;
					if (j < 2) {
						if (block[i][j + 2] == block[i][j + 3]) {
							p[c] += block[i][j];
							if (j < 1) {
								if (block[i][j + 3] == block[i][j + 4]) {
									p[c] += block[i][j];
									for (int k = j; k < 5; k++) block[i][k] = 0;
									break;
								}
							}
							for (int k = j; k < j + 4; k++) block[i][k] = 0;
							break;
						}
					}
					for (int k = j; k < j + 3; k++) block[i][k] = 0;
					break;
				}
			}
		}
		if (P2 == p[c]) break;
		trace(h);
	}

}

void trace(int h) {
	
	for (int s = 0; s < h; s++) {
		for (int i = h - 1; i >= 0; i--) {
			for (int j = 0; j < 5; j++) {
				if (block[i][j] == 0) {
					block[i][j] = block[i - 1][j];
					block[i - 1][j] = 0;
				}
			}
		}
	}
	
}

int main() {
	int h;

	int n;
	int i, j;
	int c = 0;
	while (1) {
		for (i = 0; i < 10; i++) {
			for (j = 0; j < 5; j++) {
				block[i][j] = 0;
			}
		}
		
		scanf("%d", &h);
		if (h == 0) break;

		for (i = 0; i < h; i++) {
			for (j = 0; j < 5; j++) {
				scanf("%d", &n);
				block[i][j] = n;
			}
		}

		del(h,c);

		c++;
	}
	for (i = 0; i < c; i++) {
		printf("%d\n", p[i]);
	}
	return 0;
}


Measured memory_bytes: 2724
/*input
100
*/

// Nihesh Anderson - knandy

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key
ll MOD=1000000007;

#define endl '\n'
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
ll INF = 2000000000000000001;
long double EPS = 1e-9;
ll power(ll a, ll n, ll md){if(n==0){return 1;}else{ll res=power(a,n/2,md);res=(res*res)%md;if(n%2!=0){res=(res*a)%md;}return res;}}
random_device rndm;
mt19937 grndm(rndm());
void mix(ll* a, ll* b){shuffle(a,b,grndm);}

const ll MX = 10000007;

ll fact[MX];

int main(){
	fast_cin();
	// freopen("input.in","r",stdin);
	// freopen("output.out","w",stdout);
	for(ll i = 0; i < MX; i++) {
		fact[i] = 1;
	}
	for(ll i = 2; i < MX; i++) {
		if(fact[i] > 1) {
			continue;
		}
		for(ll j = 1; i * j < MX; j++) {
			ll cur = i * j, cnt = 0;
			while(cur % i == 0) {
				cur /= i;
				cnt++;
			}
			fact[i * j] *= (cnt + 1);
		}
	}
	ll n, ans = 0; cin >> n;
	for(ll i = 1; i <= n; i++) {
		ans += i * fact[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 81740
#include <iostream>

using namespace std;

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

    bool ans = false;
    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++) {
            if (i * j == N) ans = true;
        }
    }

    cout << ((ans) ? "Yes" : "No") << endl;
}


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

int main()
{
  int n;
  string s;
  cin >> n >> s;
  int white_count(0);

  for (auto&& e : s) {
    if (e == '.') {
      white_count++;
    }
  }

  int w(0);
  int b(0);
  int ans(n);
  for (int i = 0; i < n; i++) {
    if (s[i] == '.') {
      w++;
      ans = min(ans, b + white_count - w);
    } else {
      ans = min(ans, b + white_count - w);
      b++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
import sys
sys.setrecursionlimit(1000000)
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル


n,k = map(int,input().split())
lis = list(map(int,input().split()))
lis.sort()
ans = 0
for i in range( 2, n + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
for i in range(n):
    if i >= k-1:
        ans += lis[i] * cmb(i,k-1,mod)
    if n-i-1 >= k-1:
        ans -= lis[i] * cmb(n-i-1,k-1,mod)
    ans %= 10 ** 9+7
print(ans)

Measured memory_bytes: 20180
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
#include <cmath>
using namespace std;
#define vsort(vec) sort(vec.begin(), vec.end())
#define vreverse(vec) reverse(vec.begin(), vec.end())
using ll =long long;
const ll INF =1001001001;

//最大公約数
ll gcd(ll a, ll b){
   if (a%b==0){
       return(b);
   }else{
       return(gcd(b,a%b));
   }
}
//最小公倍数
ll lcm(ll a, ll b){
   return a*b/gcd(a,b);
}

//素数判定
ll isprime(ll n){
  bool prime=true;
  for(int i=2;i<n;i++){
    if(n%i==0){
      prime=false; break;
    }
  }
if(prime){cout<<n<<" is prime"<<endl;
         }else{cout<<n<<" is not prime"<<endl;}

}
//階乗　20くらいが限界
ll factorial(ll n){
  ll a=1;ll b=n;
  for(int i=0;i<n;i++){
    a*=b;
    b--;
  }
  return a;
}

//組み合わせ　nCr
ll comb(ll a,ll b){
  ll c;
  c=factorial(a)/(factorial(a-b)*factorial(b));
  return c; 
}




/*10億7。　　　100000007
2*2行列 H*W
vector<vector<int>> vec(H,vector<int>(W));
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
cin>>vec[i][j];
  }
}

文字列→数列
string S;int A=atoi(S.c_str());
数列→文字列
int A;string S=to_string(A);
数字判定　isdigit(a)
pair宣言　pair<int,int> p(5,7);
ソート　sort(vec.begin(),vec.end());
キュー　queue<int> q;
   q.push(7);　//７が入る
   cout << q.front() << endl;  // 先頭の値を出力
   q.pop();  // 先頭の値を削除
   q.empty();
*/
//座標　corrdinateト深さヲ保持スルタメノ構造体
struct Coor{
  ll y;
  ll x;
  ll depth;
};
 ll N,M;  
 ll sy,sx,gy,gx;
 ll y,x,depth;//キューから取り出した座標
vector<string> vec;
queue<Coor> q;
vector<ll> y_vec={0,0,-1,+1};//technique
vector<ll> x_vec={-1,+1,0,0};

int BFS(){
  while(!q.empty()){
    Coor now=q.front();q.pop();//キューの先頭を取り出す
    y=now.y,x=now.x,depth=now.depth;
    
    //停止条件
    if(y==gy&&x==gx){return depth;}
    
    //上下左右４方向を探索、進むことができればキューに格納
    for(int i=0;i<4;i++){
      Coor next={y+y_vec[i],x+x_vec[i],depth+1};
      if(0<=next.y&&next.y<=N-1&&0<=next.x&&next.x<=M-1&&vec[next.y][next.x]=='.'){
        vec[next.y][next.x]='x';//同じ場所を探索しないようにする
        q.push(next);
      }
    }
  }
  return 0;
}
                   
  


int main(void){
cout<<fixed<<setprecision(14);
//cin.tie(0); ios::sync_with_stdio(false);

  
ll R,G;
  cin>>R>>G;
  cout<<2*G-R<<endl;
  
  
  
  
  
  
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//#define CHKR
#define ll long long
#define pb push_back
//#define mp make_pair
#define fr first
#define sc second
#define ARRS int(2e5+500)
#define BARRS int(6e4+600)
#define MAX ((long long)(1e9+1))
#define EP ((long double)(1e-9))
#define MMAX ((long long)(1e9+10))
#define HS1 ((long long)(1000001329))
#define HS2 ((long long)(1000001531))
#define MOD ((long long)1000000009ll)
#define SQ 31622780
#define PI 3.14159265358979323846264338327950288419716939937510
#define BG 4294967232ll
#define MH 200008


#ifndef CHKR
int main(){
#else
int doit(fstream &in,fstream &out){
    cin.rdbuf(in.rdbuf());
    cout.rdbuf(out.rdbuf());
#endif
    #ifdef KHOKHO
        #ifndef CHKR
        freopen("in.in","r",stdin);
        freopen("out.out","w+",stdout);
        #endif //CHKR
    #endif //KHOKHO
    ll d=MAX,c=0;
    string s;
    ll p=0;
    string k="";
    cin>>c;
    cin>>s;
    for(int i=0; i<s.size(); i++){
        if(s[i]==')'){
            if(p)p--,k+=')';
            else k="("+k+")";
        }
        else p++,k+='(';
    }
    while(p--)k+=')';
    cout<<k;
    return 0;
}


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

long long knapsackHelper(int* weights, int* values , int n , int maxWeight ,long long** output){
 
  if(n == 0)
    return 0;
  
  if(maxWeight == 0)
    return 0;

  if(output[n][maxWeight]>=0)
    return output[n][maxWeight];
  
  if(weights[n-1]>maxWeight){
     long long option2 = knapsackHelper(weights, values , n-1 , maxWeight,output);
    output[n][maxWeight] = option2 ;
     return option2; 
  }
  
  long long option1 = values[n-1] + knapsackHelper(weights, values , n-1 , maxWeight-weights[n-1],output);
  long long option2 = knapsackHelper(weights, values , n-1 , maxWeight,output);
  
  long long res = max(option1,option2);
  output[n][maxWeight] = res;
  return res;
  
}
long long knapsack(int* weights, int* values, int n, int maxWeight){

  long long**output = new long long*[n+1];
  for(int i =0;i<=n;i++){
    output[i] = new long long[maxWeight+1];
    for(int j=0;j<=maxWeight;j++)
      output[i][j] = -1;
  }
  
 	long long res =  knapsackHelper(weights, values , n , maxWeight , output);
  
  	return res;

}
int main(){
  int n, w;
  cin>>n>>w;
  int weight[n];
  int value[n];
  
  for(int i=0;i<n;i++){
    cin>>weight[i];
    cin>>value[i];
  }
  cout<<knapsack(weight, value, n, w)<<endl;
  return 0;
}

Measured memory_bytes: 79488
#include"iostream"

using namespace std;

int main()
{
	int n, m, c;
	int  a[20][20];
	int b[20];
	int ans = 0;
	cin >> n >> m >> c;
	for (int k = 0; k < m; k++) {
		cin >> b[k];
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> a[i][j];
		
		}
	}
	for (int i = 0; i < n; i++) {
		int num = 0;
		for (int j = 0; j < m; j++) {
			num += a[i][j] * b[j];
		}

		if (num + c > 0) { ans += 1; }

	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define ALL(n) n.begin(),n.end()
#define MP make_pair

int main() {
	int n,s[600],c[600],f[600];
	cin >> n;
	REP(i, n - 1) cin >> c[i] >> s[i] >> f[i];
	REP(i, n - 1) {
		int t = 0;
		FOR(j,i, n - 1) {
			if (t < s[j])t = s[j];
			else if(t % f[j] > 0)t += f[j] - t % f[j];
			t += c[j];
		}
		cout << t << endl;
	}
	cout << "0" << endl;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

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

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

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

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

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

fn main() {
    input!{
        n: usize, k: usize,
        a: [i32; n],
    }
    let ans = (n-1) / (k-1) + {
        if (n-1) % (k-1) == 0 {
            0
        } else {
            1
        }
    };
    println!("{}", ans);
}


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

using namespace std;


int main() {
	int a, b; scanf("%d%d", &a, &b);
	double ret = 0;
	for (int i = 1; i <= a; i++) {
		double tmp = 1.0 / a;
		int now = i;
		while (now < b) {
			now *= 2;
			tmp /= 2;
		}
		ret += tmp;
	}
	printf("%.12f\n", ret);
}


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

using ll = long long;
#define int ll

// [a -> b-1]
#define reps(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
// [0 -> a-1]
#define rep(i, a) reps(i, 0, (a))
// [a-1 -> b]
#define rreps(i, a, b) for (int i = (int)((a)-1); i >= (int)(b); i--)
// [a-1 -> 0]
#define rrep(i, a) rreps(i, a, 0)
#define all(v) (v).begin(), (v).end()
// next_permutation(all(v))
#define PERM(v) next_permutation(all(v))
/*sort(all(v));
 * (v).erase(unique(all(v)), v.end())*/
#define UNIQUE(v)\
	sort(all(v));\
	(v).erase(unique(all(v)), v.end())
// b is [a, c)
#define RANGE(a, b, c) ((a) <= (b) && (b) < (c))
// c is [a, e) && d is [b, f)
#define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f)))
#define chmin(a, b) a = min(a, (b))
#define chmax(a, b) a = max(a, (b))
#define fcout cout << fixed << setprecision(15)
#define YES(f) cout << ((f) ? YES_STR : NO_STR) << endl;


signed main(){
	deque<char> d;
	{
		string s; cin >> s;
		for (auto c : s) d.push_back(c);
	}
	int Q; cin >> Q;
	bool rev = false;
	rep(_,Q) {
		int q; cin >> q;
		if (q == 1) rev = !rev;
		else {
			int f; cin >> f;
			char c; cin >> c;
			if ((f == 1 && rev) || (f == 2 && !rev)) d.push_back(c);
			else d.push_front(c);
		}
	}
	if (rev) {
		reverse(d.begin(), d.end());
	}
	for (auto x : d) cout << x;
	cout << endl;
	return 0;
}


Measured memory_bytes: 892
import java.util.Scanner;
 
class Main {
	public static void main(String[] args) {
 
	    Scanner sc = new Scanner(System.in);
	    long A = sc.nextLong();
	    long B = sc.nextLong();
	    long C = sc.nextLong();
	    long K = sc.nextLong();
	    long max = 0;
	    
	    if (K > 0 && K >= A) {
	      max += (A * 1);
	      K -= A;
	    } else if (K > 0 && K < A) {
	      max += (K * 1);
	      K = 0;
	    }
	    
	    if (K > 0 && K >= B) {
	      K -= B;
	    } else if (K > 0 && K < B) {
	      K = 0;
	    }
	    
	    if(K > 0 && K >= C) {
	      max += (C * -1);
	      K -= C;
	    } else if (K > 0 && K < C) {
	      max += (K * -1);
	      K = 0;
	    }
	    
	    System.out.println(max);
	    
	  }
}

Measured memory_bytes: 27084
n = int(input())
s = list(input())
a = []
a.append(s[1:].count("E"))
for i in range(n-1):
    if s[i+1] == "E" and s[i] == "E":
        a.append(a[i]-1)
    elif s[i+1] == "W" and s[i] == "E":
        a.append(a[i])
    elif s[i+1] == "E" and s[i] == "W":
        a.append(a[i])
    elif s[i+1] == "W" and s[i] == "W":
        a.append(a[i]+1)
print(min(a))

Measured memory_bytes: 20816
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0; i < N; i++)
#define INF 1 << 28
#define S second
#define F first
typedef pair<int,int> Pi;

inline void chmax(int &a, int b) { a = max(a,b); }
inline void chmin(int &a, int b) { a = min(a,b); }


int N, K;
int data[105];
int memo[105][4][2];

int dfs(int it, int ch, int cnt)
{
  int ret = 0;
  if(it == N)return 1;
  if(~memo[it][ch][cnt])return memo[it][ch][cnt];
  Rep(i,3) {
    if(data[it + 1] != INF && i != data[it + 1])continue;
    int nc;
    if(ch == i) nc = cnt + 1;
    else nc = 0;
    if(nc < 2) (ret += dfs(it + 1,i,nc)) %= 10000;
  }
  return memo[it][ch][cnt] = ret;
}

int main()
{
  memset(memo,-1,sizeof(memo));
  cin >> N >> K;
  int A, B;
  fill(data,data + 105,INF);
  Rep(i,K) {
    cin >> A >> B; --B;
    data[A] = B;
  }
  cout << dfs(0,3,0) << endl;
  return(0);
}
  

Measured memory_bytes: 3048
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main( void )
{
	// n: ¶kl, m:ê
	int n, m;
	while ( cin >> n >> m && n && m )
	{
		vector <int> score(m,0);
		for ( int i = 0; i < n; i++ )
		{
			for ( int j = 0; j < m; j++ )
			{
				int answer;
				cin >> answer;
				score[j] += answer;
			}
		}

		vector <int> id(m);
		for ( int i = 0; i < m; i++ )
			id[i] = i + 1;

		for ( int i = 0; i < m-1; i++ )
		{
			for ( int j = i + 1; j < m; j++ )
			{
				if ( score[i] < score[j] )
				{
					swap( score[i], score[j] );
					swap( id[i], id[j] );
				}
				else if( score[i] == score[j] )
				{
					if ( id[i] > id[j] )
					{
						swap( score[i], score[j] );
						swap( id[i], id[j] );
					}
				}
			}
		}

		for ( int i = 0; i < m; i++ )
		{
			cout << id[i];
			if ( i < m - 1 )
				cout << " ";
		}
		cout << endl;

	}

	return 0;
}

Measured memory_bytes: 908
#include <iostream>
#include <string>
using namespace std;
int main() {
	int n, p[200000],count=1,min;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	min = p[0];
	for (int i = 1; i < n; i++) {
		if (p[i] < min) {
			min = p[i];
			count++;
		}
	}
	cout << count;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define For(i,j,k)	for(int i=j;i<=k;++i)
#define Dow(i,j,k)	for(int i=k;i>=j;--i)
#define ll long long
#define inf 1e8
using namespace std;
inline ll read()
{
	ll t=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')	c=getchar();}
	while(c>='0'&&c<='9')	t=t*10+c-48,c=getchar();
	return t*f;
}
int n,a[200001],mx,ans,cnt[200001];

int main()
{
	n=read();
	For(i,1,n)	a[i]=read(),cnt[a[i]]++,cnt[a[i]-1]++,cnt[a[i]+1]++,mx=max(mx,a[i]);
	For(i,0,mx+1)	ans=max(ans,cnt[i]);
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
package main

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

func main() {
	defer stdout.Flush()
	a := readLengthAndSlice()
	l := 0
	r := 0
	count := int64(0)
	accm := 0
	for r < len(a) {
		if (accm & a[r]) == 0 {
			count += int64(r - l + 1)
			accm += a[r]
			r++
		} else {
			accm -= a[l]
			l++
		}
	}
	println(count)
}

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	i, err := strconv.Atoi(readString())
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_abc152() {
	string a, b;
	ll va, vb;
	ll ans;

	cin >> a >> b;
	va = stoi(a);
	vb = stoi(b);

	vector<string> s;

	string tmp;

	tmp = "";
	rep(i, va) {
		tmp += b;
	}
	s.push_back(tmp);

	tmp = "";
	rep(i, vb) {
		tmp += a;
	}
	s.push_back(tmp);

	sort(ALL(s));

	cout << s[0] << "\n";
}

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

	solve_abc152();

	return 0;
}

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

#define  all(x)          (x).begin(), (x).end()
#define  rall(v)          v.rbegin() , v.rend()
#define  ones(x)          __builtin_popcount(x)
#define  sz(v)           ((int)((v).size())
#define  debug(x)        cout << '>' << #x << ':' << x << endl;
#define  clr(v, d)       memset(v, d, sizeof(v));
#define  rep(i,a,b)      for(ll i=a; i<=b;i++)
#define  fo(i,n)         for(ll i=0;i<n;i++)
#define  rfo(i,n)        for(ll i=n-1;i>=0;i--)
#define  unq(vec)        sort(all(vec)); vec.resize(unique(all(vec)) - vec.begin());
#define  era(v)          sort(v.begin(), v.end());v.erase(unique(v.begin(), v.end()), v.end());
#define  pb              push_back
#define  mp              make_pair
#define  endl            '\n'
#define  fi               first
#define  se               second

using namespace std;
typedef long long         ll;
typedef long double       ld;
typedef vector<int>       vi;
typedef vector<long long> vll;
typedef vector<double>    vd;
typedef vector<vi >       vvi;
typedef vector< vd >      vvd;
typedef vector<string>    vs;
typedef pair<int,int>     pii;
typedef vector<pii>       vii;
typedef map<int,int>      mii;

ll gcd(ll a, ll b){return !b ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return (a / gcd(a, b)) * b;}
//ll modpow(ll a, ll b, ll m = MOD){a %= m; ll res = 1; while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;}
//ll bpow(ll a, ll b){ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
//ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}

const ll MOD = 1e9 + 7;
const int dx4[4] = {0, 1, 0, -1};
const int dy4[4] = {-1, 0, 1, 0};
const int dx8[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
bool cmp(int X,int Y){return X>Y;}

int main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll k;cin>>k;
string s;cin>>s;
ll x = s.length();
if(x<=k){cout<<s;return 0;}
string ans = "";
ans+=s.substr(0,k);
ans+="...";
cout<<ans;
}















Measured memory_bytes: 3656
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if (a < b && b < c){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }

    }
}



Measured memory_bytes: 26116
#include <iostream>
#include <array>

using namespace std;

int main(int argc, const char *argv[])
{
  string dow;
  cin >> dow;
  array<string, 7> dows{"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
  for (int i = 0; i < dows.size(); i++) {
    if (dows[i] == dow) {
      cout << dows.size() - i << "\n";
      break;
    }
  }

  return 0;
}

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

sumB = sum(B)

sumC = 0
for i in range(1, N):
    if A[i] == A[i-1] + 1:
        sumC = sumC + C[A[i-1]-1]
    
print( sumB + sumC )


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

namespace D {
    class Program {
        static void Main (string[] args) {
            var AB = Console.ReadLine ().Split (' ').Select (c => long.Parse (c)).ToList ();
            var A = AB[0];
            var B = AB[1];

            /*
            どんな非負整数nについても
            n ⊕ n   = 0
            なので、
            F(A,B)  = A ⊕ (A + 1) ⊕ ... ⊕ B
            より
            F(A,B)  = A ⊕ (A + 1) ⊕ ... ⊕ B ⊕ (0 ⊕ 0) ⊕ (1 ⊕ 1) ⊕ ... ⊕ ((A - 1) ⊕ (A - 1)) 
                    = {0 ⊕ 1 ⊕ ... ⊕ B} ⊕ {0 ⊕ 1 ⊕ ... ⊕ (A - 1)} (ただしA > 0)
            ゆえに
            F(A,B) = F(0,B) ⊕ F(0,A-1) (A != 0)
            また、任意の偶数eについて、
            e ⊕ (e+1) = 1
            が成り立つことを考えると、偶数Eについて
            F(0,E)  = 0 ⊕ 1 ⊕ 2 ⊕ 3 ⊕ ... ⊕ (E - 2) ⊕ (E - 1) ⊕ E
                    = (0 ⊕ 1) ⊕ (2 ⊕ 3) ⊕ ... ⊕ {(E - 2) ⊕ (E - 1)} ⊕ E
                    = 1 ⊕ 1 ⊕ ... ⊕ 1 ⊕ E
            が成り立つ。
            このとき、1の数が偶数であれば、
            F(0,E) = E
            また、F(0,E)の1の数が奇数であれば、
            F(0,E) = 1 ⊕ E = (E + 1)

            同様に、奇数Oについても、
            F(0, O) = 1 ⊕ 1 ⊕ ... ⊕ 1 ⊕ 1
            が成り立つ。
            このとき、F(0,O)の1の数が偶数であれば、F(0, O) = 0
            また、1の数が奇数であれば、F(0,O) = 1
            が成り立つ
            
             */
            if (A == 0) {
                Console.WriteLine (F (B));
            } else {
                Console.WriteLine (F (A - 1) ^ F (B));
            }
        }

        static long F (long K) {
            if (K % 2 == 0) {
                if (K % 4 == 0) {
                    return K;
                } else {
                    return K + 1;
                }
            } else {
                if (K % 4 == 3) {
                    return 0;
                } else {
                    return 1;
                }
            }
        }
    }
}

Measured memory_bytes: 13268
#include <stdio.h>

int main(){
  int k,n,i,j,tmp;
  int p[1000];
  
  scanf("%d %d",&n,&k);
  for(i=0;i<n;i++){
    scanf("%d",&p[i]);
  }
  
  for(i=n-1;0<i;i--){
    for(j=0;j<i;j++){
      if(p[j]>p[j+1]){
        tmp=p[j];
        p[j]=p[j+1];
        p[j+1]=tmp;
      }
    }
  }
  
  tmp=0;
  for(i=0;i<k;i++){
    tmp+=p[i];
  }
  
  printf("%d",tmp);
}

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

int main(){
    string s;
    cin >> s;

    int ans = 0;
    for(int i=0; i<s.length(); i++){
        if(s[i] == '2') ans += 1;
    }
    cout << ans << endl;
    return 0;
}

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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define chmax(s, t) s=max(s,t);
#define chmin(s, t) s=min(s,t); 

#define deg2rad(deg) (((deg)/360)*2*M_PI)
#define rad2deg(rad) (((rad)/2/M_PI)*360)

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

/*素数判定*/
bool is_prime(ll n){
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

/*約数列挙*/
vll enum_divisors(ll n){
    vll l;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            l.push_back(i);
            if(n/i != i) l.push_back(n/i);
        }
    }
   sort(all(l));
   return l;
}

/*素因数分解*/
vector<P> prime_factorize(ll n){
    vector<P> l;
    for(ll i=2;i*i<=n;i++){
        if(n%i!=0) continue;
        ll e = 0;
        while(n%i==0){
            e++;
            n /= i;
        }
        l.push_back({i, e});
    }
    if(n!=1) l.push_back({n, 1});
    return l;
}

/*最小公倍数*/
ll lcm(ll a, ll b){
    return a*b/__gcd(a,b);
}

/*最大公約数*/
ll gcd(ll a, ll b){
    return __gcd(a,b);
}

/*組み合わせ(Combination)*/
const ll CMAX = 1010000;
const ll CMOD = 1e9+7;
ll fac[CMAX], finv[CMAX], inv[CMAX];
// テーブルを作る前処理
void combinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < CMAX; i++) {
		fac[i] = fac[i - 1] * i % CMOD;
		inv[i] = CMOD - inv[CMOD%i] * (CMOD / i) % CMOD;
		finv[i] = finv[i - 1] * inv[i] % CMOD;
	}
}
// 二項係数計算
ll comb(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % CMOD) % CMOD;
}

/*階乗*/
ll factorial(ll n){
    const ll FMOD = 1e9+7;
    ll ret = n;
    for(ll i=n-1;i>0;i--){
        ret*=i;
        ret%=FMOD;
    }
    return (ret?ret:1);
}


int main(){

    ll n; cin >> n;
    ll absmin = INF;
    ll ans = 0;
    ll minuscnt = 0;
    rep(i, n){
        ll in; cin >> in;
        chmin(absmin, abs(in));
        if(in<0) minuscnt++;
        ans += abs(in);
    }

    cout << (minuscnt%2==0?ans:ans-2*absmin) << endl;

    return 0;
}

Measured memory_bytes: 3608
/*input
3
3 5
2 7
9 4
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

ll a[maxn],b[maxn];

int main(){
	IOS;
	int n;
	cin>>n;
	REP(i,n) cin>>a[i]>>b[i];
	REP(i,n) a[i]%=b[i];
	REP(i,n) a[i]=(b[i]-a[i])%b[i];
	for(int i=n-2;i>=0;i--) if(a[i]<a[i+1]){
		ll tmp=a[i+1]-a[i];
		a[i]+=tmp/b[i]*b[i];
		if(a[i]<a[i+1]) a[i]+=b[i];
	}
	cout<<a[0]<<'\n';
	return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lowbit(a) ((a) & -(a))
#define clean(a, b) memset(a, b, sizeof(a))
#define eps (-1e8)
#define make_pair P
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int maxn = 3e5 + 9;

int _;

int fa[maxn],num[maxn];
int find(int x)
{
    return fa[x]==x?x:fa[x]=find(fa[x]);
}
void merge(int x,int y)
{
	int xx=find(x);
	int yy=find(y);
    if(xx!=yy) num[yy]+=num[xx];
    fa[xx]=yy;
}
int main()
{
    int n,m,x,y;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) fa[i]=i,num[i]=1;
    for(int i=1;i<=m;i++)
    {
    	scanf("%d%d",&x,&y);
    	merge(x,y);
	}
	int ans=0;
	for(int i=1;i<=n;i++) if(i==find(i)) ans=max(ans,num[i]);
	printf("%d\n",ans);
    return 0;
}
 

Measured memory_bytes: 11600
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    ll n, k, o = 0, z = 0, a[200005] = {};
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) {
        if (a[i] < 0) o++;
        if (a[i] == 0) z++;
    }
    vector<ll> b, c;
    for (int i = 0; i < n; i++) {
        if (a[i] < 0) b.push_back(-a[i]);
        else if (a[i] > 0) c.push_back(a[i]);
    }
    sort(b.begin(), b.end()); sort(c.begin(), c.end());
    if (o * (n - o - z) >= k) {
        k = o * (n - o - z) - k + 1;
        ll l = 0, r = 1e18 + 328;
        while (l + 1 < r) {
            ll m = (l + r) / 2, d = 0;
            for (ll i = 0; i < b.size(); i++) d += (ll)(upper_bound(c.begin(), c.end(), m / b[i]) - c.begin());
            if (d < k) l = m;
            else r = m;
        }
        cout << -r;
    } else if (o * (n - o - z) + z * (n - z) + z * (z - 1) / 2 >= k) {
        cout << 0;
    } else {
        k -= o * (n - o - z) + z * (n - z) + z * (z - 1) / 2;
        ll l = 0, r = 1e18 + 328;
        while (l + 1 < r) {
            ll m = (l + r) / 2, d = 0;
            for (ll i = 0; i < b.size(); i++) d += (ll)(upper_bound(b.begin(), b.begin() + i, m / b[i]) - b.begin());
            for (ll i = 0; i < c.size(); i++) d += (ll)(upper_bound(c.begin(), c.begin() + i, m / c[i]) - c.begin());
            if (d < k) l = m;
            else r = m;
        }
        cout << r;
    }
}


Measured memory_bytes: 6720
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
struct poi{ll sum,pos;}a[200010];
ll n,k,ans,cnt,tree[200010],lisan[200010];
void read(ll &k)
{
    k=0;int f=1;char c=getchar();
    while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
    while(c<='9'&&c>='0')k=k*10+c-'0',c=getchar();
    k*=f;
}
bool cmp(poi a,poi b){return a.sum<b.sum;}
int lowbit(int x){return x&-x;}
void add(int x,int delta)
{
    for(int i=x;i<=cnt;i+=lowbit(i))
    tree[i]+=delta;
}
int sum(int x)
{
    int s=0;
    for(int i=x;i>=1;i-=lowbit(i))
    s+=tree[i];
    return s;
}
int main()
{
    read(n);read(k);
    for(int i=1;i<=n;i++)read(a[i].sum),a[i].sum-=k;
    for(int i=1;i<=n;i++)a[i].sum+=a[i-1].sum,a[i].pos=i;
    sort(a,a+1+n,cmp);
    for(int i=0;i<=n;i++)
    {
        if(a[i].sum!=a[i-1].sum||i==0)cnt++;
        lisan[a[i].pos]=cnt;
    }
    for(int i=n;i>=0;i--)
    {
        ans+=sum(cnt)-sum(lisan[i]-1);
        add(lisan[i],1);
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

/*------------------------------------------------------------------*/
int main(){
    int n; cin >> n;
    vector<string> s(n);
    rep(i, n){
        cin >> s[i];
    }
    string ans;
    for(char c = 'a'; c <= 'z'; c++){

        int len = 50;
        for(int i = 0; i < n; i++){
            int count = 0;
            for(int j = 0; j < s[i].size(); j++){
                if(s[i][j] == c) count++;
            }
            len = min(len, count);
        }
        
        for(int i = 0; i < len; i++){
            ans += c;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256