akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;

int Tanni(string);

int main(){
  int i,j,n;
  string st,str,str2;
  cin >> n;
  for(int t=0;t<n;t++){
    int keta,a[1003],aa,dot;

    cin >> st >> str;

    dot = -1;
    bool f = false;
    for(i=0;i<st.size();i++){
      if(st[i] == '.'){
	a[i] = -1;
	dot = i;
	f = true;
      }
      else a[i] = st[i] - '0';
    }
    aa = i;

    if(dot == 0){
      for(i=aa-1;i>=0;i--) a[i+1] = a[i];
      a[0] = 0;
      dot = 1;
      aa++;
    }
    else if(dot == aa - 1) a[aa++] = 0;

    if(!f){
      a[aa] = -1;
      dot = aa;
      a[aa+1] = 0;
      aa += 2;
    }

    keta = Tanni(str);
    if(keta == 0) str2 = str;
    else cin >> str2;

    while(a[0] == 0 || dot != 1){
      if(a[0] != 0 && a[1] == -1) break;

      //for(dot=0;dot<aa;dot++) if(a[dot] == -1) break;
      
      if(a[0] == 0){
	keta--;
	int c;
	c = a[dot];
	a[dot] = a[dot+1];
	a[dot+1] = c;
	for(j=0;j<aa-1;j++) a[j] = a[j+1];
	a[aa-1] = 0;
	aa--;
      }

      else if(dot != 1){
	keta++;
	int c;
	c = a[dot];
	a[dot] = a[dot-1];
	a[dot-1] = c;
	dot--;
      }
    }
    
    if(!f) aa--;
    if(aa - 1 == dot) aa--;

    for(i=0;i<aa;i++){
      if(i == dot) cout << ".";
      else cout << a[i];
    }
    
    cout << " * 10^" << keta << " " << str2 << endl;
  }
  return 0;
}

int Tanni(string str){
  if(str == "yotta") return 24;
  else if(str == "zetta") return 21;
  else if(str == "exa") return 18;
  else if(str == "peta") return 15;
  else if(str == "tera") return 12;
  else if(str == "giga") return 9;
  else if(str == "mega") return 6;
  else if(str == "kilo") return 3;
  else if(str == "hecto") return 2;
  else if(str == "deca") return 1;
  else if(str == "deci") return -1;
  else if(str == "centi") return -2;
  else if(str == "milli") return -3;
  else if(str == "micro") return -6;
  else if(str == "nano") return -9;
  else if(str == "pico") return -12;
  else if(str == "femto") return -15;
  else if(str == "ato") return -18;
  else if(str == "zepto") return -21;
  else if(str == "yocto") return -24;
  else return 0;
};

Measured memory_bytes: 0
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n, m;
  while (cin >> n) {
    cin >> m;
    if (n == 0 && m == 0) return 0;
    vector<int> h(n), w(m);
    for (int i = 0; i < n; i++) {
      cin >> h[i];
    }
    for (int i = 0; i < m; i++) {
      cin >> w[i];
    }
    vector<int> cnt_h(2020200), cnt_w(2020200);
    for (int i = 0; i < n; i++) {
      int sum = 0;
      for (int j = i; j < n; j++) {
        sum += h[j];
        cnt_h[sum]++;
      }
    }
    for (int i = 0; i < m; i++) {
      int sum = 0;
      for (int j = i; j < m; j++) {
        sum += w[j];
        cnt_w[sum]++;
      }
    }
    long long ans = 0;
    for (int i = 0; i < 2020200; i++) {
      ans += cnt_h[i] * cnt_w[i];
    }
    cout << ans << '\n';
  }
  return 0;
}



Measured memory_bytes: 18652
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <climits>

int main(){

    std::string S;
    std::cin >> S;
    if(S[0]<'a'){
        std::cout << "A" << std::endl;
    }else{
        std::cout << "a" << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3616
N, M = map(int, input().split())
H = list(map(int, input().split()))
A = []
B = []

no_good = []

for i in range(M):
    t = list(map(int, input().split()))
    A.append(t[0])
    B.append(t[1])

for i in range(M):
    if H[A[i]-1] > H[B[i]-1]:
        no_good.append(B[i])
    elif H[A[i]-1] < H[B[i]-1]:
        no_good.append(A[i])
    else:
        no_good.append(A[i])
        no_good.append(B[i])

result = N - len(set(no_good))
print(result)


Measured memory_bytes: 24832
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int k;
    cin >> k;
    string s;
    cin >> s;
    int n = sz(s);
    if (n <= k) {
        cout << s << endl;
    } else {
        rep(i, k) cout << s[i];
        cout << "..." << endl;
    }
}

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

const int MOD=998244353;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int n,s;
int a[5000];

ll ans=0;

void solve(int l,int r){
	if(r<=l)return;
	if(r-l==1){
		if(a[l]==s)ans++;
		return;
	}
	int md=(l+r)/2;
	vector<ll>dpl(3001),dpr(3001);
	vector<ll>L(3001),R(3001);
	dpl[0]=1;
	dpr[0]=1;
	assert(l<md&&md<r);
	for(int i=md-1;i>=l;i--){
		for(int j=3000-a[i];j>=0;j--){
			(dpl[j+a[i]]+=dpl[j])%=MOD;
		}
		rep(j,3001)(L[j]+=dpl[j])%=MOD;
	}
	for(int i=md;i<r;i++){
		for(int j=3000-a[i];j>=0;j--){
			(dpr[j+a[i]]+=dpr[j])%=MOD;
		}
		rep(j,3001)(R[j]+=dpr[j])%=MOD;
	}
	rep(j,s+1){
		(ans+=L[j]*R[s-j])%=MOD;
	}
	solve(l,md);
	solve(md,r);
}

int main(){
	cin>>n>>s;
	rep(i,n)scanf("%d",&a[i]);
	solve(0,n);
	cout<<ans<<endl;
}

Measured memory_bytes: 1444
fun main(args:Array<String>) {
    println(if(getAns()) "Yes" else "No")
}


fun getAns():Boolean {
    val (a,b) = readLine()!!.split(" ").map { it.toInt() }
    val s = readLine()!!
    val spl = s.split("-")
    if(spl.size != 2) {
        return false
    }
    if(spl[0].length != a || spl[1].length != b) {
        return false
    }
    return spl.all { a->a.all { it in ('0'..'9') } }
}


Measured memory_bytes: 37944
#include<bits/stdc++.h>
using namespace std;
int a[100005][4];
int dp[100005][4];
int Vacation(int i, int n, int flag){
    if(i == n)return 0;

    if(dp[i][flag] != -1)
        return dp[i][flag];

    int maxi = INT_MIN;
    if(flag == 0){
        maxi = max(maxi,a[i][1] + Vacation(i+1,n, 1));
        maxi = max(maxi,a[i][2] + Vacation(i+1, n, 2));
        maxi = max(maxi,a[i][3] + Vacation(i+1, n, 3));
    }
    else if(flag == 1){
        maxi = max(maxi, a[i][2] + Vacation(i+1, n, 2));
        maxi = max(maxi, a[i][3] + Vacation(i+1, n, 3));
    }
    else if(flag == 2){
        maxi = max(maxi, a[i][1] + Vacation(i+1, n, 1));
        maxi = max(maxi, a[i][3] + Vacation(i+1, n, 3));
    }
    else if(flag == 3){
        maxi = max(maxi, a[i][1] + Vacation(i+1, n, 1));
        maxi = max(maxi, a[i][2] + Vacation(i+1, n, 2));
    }
    dp[i][flag] = maxi;
    return maxi;
}
int main(){

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

    memset(dp, -1, sizeof(dp));
    cout << Vacation(0, n, 0) << endl;
    return 0;
}


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


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

    string S;

    cin >> S;
    
    if (S[S.length()-1] == 's')
    {
        S += "es";
    }
    else
    {
        S += "s";
    }

    cout << S << endl;
}


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

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

string solve(int N, const string& s) {
  vector<int> f(N);
  REP(i,N) f[i] = (s[i] == 'x') ? 1 : 0;
  REP(i,4) {
    vector<int> wolf(N);
    wolf[0] = i / 2;
    wolf[1] = i % 2;
    for(int j = 2; j < N; ++j) {
      if(wolf[j - 1] == f[j - 1]) wolf[j] = wolf[j - 2];
      else wolf[j] = 1 - wolf[j - 2];
    }
    if(((wolf[N - 2] == wolf[0]) == wolf[N - 1]) != f[N - 1]) continue;
    if(((wolf[N - 1] == wolf[1]) == wolf[0]) != f[0]) continue;
    string res;
    REP(j,N) res += (wolf[j] == 0) ? 'S' : 'W';
    return res;
  }
  return "-1";
}

int main(){
  int N;
  string s;
  cin >> N >> s;
  cout << solve(N, s) << endl;
  return 0;
}



Measured memory_bytes: 1400
// 再提出

#include <stdio.h>
#include <math.h>
 
int main(void) {
	int n;
	int hoge = 1;
 
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		int a;
		scanf("%d", &a);
		if (a % 2 == 0)
			hoge *= 2;
	}
 
	printf("%d\n", (int)pow(3, n) - hoge);
 
	return 0;
}

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

int main(void){
    long int x,year,m;
    m = 100;
    year = 0;

    cin >> x;

    while(m < x){
        m *= 1.01;
        year++;
    }

    cout << year << endl;

    return 0;
}

Measured memory_bytes: 3676
var body = '';
var readable = process.stdin;
readable.resume();
readable.setEncoding( 'utf-8' );
readable.on( 'data', function( chunk ) {
  body += chunk;
});

readable.on( 'end', function() {
  var data = body.split( '\n' );
  for( var i=0; i<data.length; i++ ) {
    if( 0 != data[i] ) {  
      console.log( 'Case '+(i+1)+': '+data[i]  );
    }
  }
});

Measured memory_bytes: 13552
#include <cmath>
#include <iostream>
#include <functional>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <iomanip>
#include <math.h>
#include <list>
#include <numeric>
using namespace std;

int main(){
  int A[3][3];
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
    cin >> A[i][j];
    }
  }
  int N;
  cin >> N;
  int B[N];
  for(int i=0;i<N;i++){
    cin >> B[i];
  }

  int k=0;
  while(k<N){
    for(int i=0;i<3;i++){
      for(int j=0;j<3;j++){
	if(A[i][j]==B[k]){
	  A[i][j]=0;
	  break;
	}
      }
    }
    k++;
  }
  for(int i=0;i<3;i++){
    if(A[i][0]==0 && A[i][1]==0 && A[i][2]==0){
      cout << "Yes" << endl;
      return 0;
    }
  }
  for(int i=0;i<3;i++){
    if(A[0][i]==0 && A[1][i]==0 && A[2][i]==0){
      cout << "Yes" << endl;
      return 0;
    }
  }
 
  if(A[0][0]==0 && A[1][1]==0 && A[2][2]==0){
    cout << "Yes" << endl;
    return 0;
  }
  if(A[2][0]==0 && A[1][1]==0 && A[0][2]==0){
    cout << "Yes" << endl;
    return 0;
  }  
  cout << "No" << endl; 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<lint>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
 
constexpr int MOD = 1000000007;
const int INF = 1 << 30;
 
template<typename T> T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }



 int main(){
    string a,b;
    cin>>a>>b;
    int length = a.size();
   int c=0;
      for(int i=0;i<length;i++){
        if(a.at(i)!=b.at(i)){
          c++;
        }
      }
        cout<<c;
    
 }

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

using namespace std;

int count_divisor(int N){
  int count=0;
  for(int i=1; i*i<N; i++){
  	if(N%i==0) count+=2;
  }

  return count;
}



int main(){
  int N, count, res;
  cin >> N;
  res = 0;
  count = 0;
  for(int i=1; i<=N; i+=2){
    if(count_divisor(i)==8) res++;
    
  }
  
  cout << res << endl;


  return 0;
}

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

#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

#define debug(x) cout << "> " << #x << " = " << x << endl;
#define debug_at(arr, at) cout << "> " << #arr << "[" << at << "] = " << arr[at] << endl;
#define debug_pair(p) cout << "> " << #p << " = (" << p.first << ", " << p.second << ")" << endl;

using namespace std;

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

    map<int, int> mp;
    fori(i, 0, 3) {
        int val;
        cin >> val;
        mp[val]++;
    }
    for(auto p : mp) {
        if(p.second == 1) {
            cout << p.first << '\n';
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,q;
char s[300001],c[300001][5],d[300001][5];
int sim(int x)
{
	for(int i=1;i<=q;i++)
		if(s[x]==c[i][0])
		{
			if(d[i][0]=='L')x--;
			else x++;
			if(!x||x>n)return x;
		}
	return x;
}
int main()
{
	cin>>n>>q>>s+1;
	for(int i=1;i<=q;i++)cin>>c[i]>>d[i];
	int l=1,r=n,ansL=0,ansR=n+1;
	while(l<=r)
	{
		int m=(l+r)/2;
		if(!sim(m))ansL=m,l=m+1;
		else r=m-1;
	}
	l=1;r=n;
	while(l<=r)
	{
		int m=(l+r)/2;
		if(sim(m)>n)ansR=m,r=m-1;
		else l=m+1;
	}
	cout<<n-(ansL+n+1-ansR)<<'\n';
}


Measured memory_bytes: 2432
N=int(input())
A=list(map(int,input().split()))
def xor(x,y):
    return x^y
S=xor(A[0],A[1])
for i in range(len(A)-2):
    S=xor(S,A[i+2])
ans=[]
for a in A:
    ans.append(xor(S,a))
print(*ans)
    

Measured memory_bytes: 31692
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,m,k;
    cin.tie(0);
    cout.tie(0);
    cin>>n>>k;
    vector<int>v;
    v.push_back(0);
    for(int i=0;i<n;i++)
    {
        cin>>m;
        v.push_back(m);
    }
    long long int dp[n+1];
  
    for(int i=1;i<=n;i++)
    dp[i]=1000000000;
    dp[1]=0;
    for(int i=2;i<=n;i++)
    {
        // cout<<"i"<<i<<"\n";
        for(int j=i-1 ;j>0 and j>=i-k;j--){
        
        
            dp[i]=min(dp[i],dp[j]+abs(v[i]-v[j]));
        }
        // cout<<dp[i]<<"\n";
       
    }
    
      
          
        
    
      
    cout<<dp[n];
        
    
}

Measured memory_bytes: 4516
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long n,k;
  cin>>k>>n;
  long long a[n];
  long long dif[n];
  for(int i=0; i<n; i++){
    cin>>a[i];
    if(i) dif[i-1]=a[i]-a[i-1];
  }
  dif[n-1]=k-a[n-1]+a[0];
  sort(dif, dif+n);
  long long sum=0;
  for(int i=0; i<n-1; i++)
    sum+=dif[i];
  cout<<sum<<endl;
}


Measured memory_bytes: 3328
#include<iostream>
#include<stack>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
	stack<int> S1;
	stack<pair<int, int> > S2;
	char ch;
	int sum = 0;
	for (int i = 0; cin >> ch; i++) {
		if (ch == '\\') S1.push(i);
		else if (ch == '/' && S1.size() > 0) {
			int j = S1.top(); S1.pop();
			sum += i - j;
			int a = i - j;
			while (S2.size() > 0 && S2.top().first > j) {
				a += S2.top().second;
				S2.pop();
			}
			S2.push(make_pair(j, a));
		}
	}

	vector<int> ans;
	while (S2.size() > 0) { ans.push_back(S2.top().second); S2.pop(); }
	reverse(ans.begin(), ans.end());
	cout << sum << endl;
	cout << ans.size();
	for (int i = 0; i < ans.size(); i++) {
		cout << " ";
		cout << ans[i];
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 3160
#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>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
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, m;
    cin >> n >> m;
    vector<vector<int>> G(n, vector<int>(n, 0));
    vector<int> a(m), b(m);
    for(int i = 0; i < m; ++i){
        cin >> a[i] >> b[i];
        --a[i], --b[i];
        G[a[i]][b[i]] = G[b[i]][a[i]] = 1;
    }
    int ans = 0;
    for(int i = 0; i < m; ++i){
        G[a[i]][b[i]] = G[b[i]][a[i]] = 0;
        vector<bool> visited(n, false);
        queue<int> que;
        que.push(0);
        visited[0] = true;
        while(!que.empty()){
            int from = que.front();
            que.pop();
            for(int to = 0; to < n; ++to){
                if(G[from][to]){
                    if(!visited[to]){
                        visited[to] = true;
                        que.push(to);
                    }
                }
            }
        }
        for(int i = 0; i < n; ++i){
            if(!visited[i]){
                ++ans;
                break;
            }
        }
        G[a[i]][b[i]] = G[b[i]][a[i]] = 1;
    }
    cout << ans << endl;
}

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

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

int gcd(int _x, int _y){
    if(_y == 0){
        return _x;
    }

    return gcd(_y, _x % _y);
}

int main(){
    int K;
    cin >> K;
    long long ans = 0;
    for (int i = 1; i <= K;i++){
        for (int j = 1; j <= K; j++){
            for (int k = 1; k <= K;k++){
                ans += gcd(gcd(i, j), k);
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;

int main() {
    int n;
    cin >> n;
    vector<int> l(n);
    for (int i = 0; i < n; i++) {
        cin >> l.at(i);
    }
    sort(l.begin(), l.end());
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            for (int k = j + 1; k < n; k++) {
                if (l.at(i) != l.at(j) && l.at(j) != l.at(k) && l.at(k) != l.at(i) && l.at(i) + l.at(j) > l.at(k) && l.at(j) + l.at(k) > l.at(i) && l.at(k) + l.at(i) > l.at(j)) {
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3616
import sys
sys.setrecursionlimit(500000)

N = int(input())

tree = [[] for _ in range(N+1)]
for _ in range(N-1):
    a, b, c = map(int, input().split())
    tree[a].append((b, c))
    tree[b].append((a, c))

Q, K = map(int, input().split())

def dfs(start, dist, dists, f=None):
    for n, d in tree[start]:
        if n == f:
            continue
        dists[n] = dist + d
        dfs(n, dist+d, dists, start)

xy = [list(map(int, input().split())) for i in range(Q)]

dists = [0] * (N+1)
dfs(K, 0, dists)

for i in range(Q):
    x, y = xy[i]
    print(dists[x] + dists[y])


Measured memory_bytes: 226848
#include<stdio.h>
int main(){

int a,s;
scanf("%d%d",&a,&s);


if(a==1 && s==2 || a==2 && s==1){ printf("3\n");}
    else if(a==2 && s==3 || a==3 && s==2){printf("1\n");}
    else if(a==1 && s==3 || a==3 && s==1){printf("2\n");};

return 0;}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
using mapl = map < ll , ll >;
using mapc = map < char , ll >;
using vectorl = vector < ll >;
using vectors = vector < string >;
const int N = 2e5 + 10;
const ll inf = 1e15 + 42;
#define endl "\n"
const ll mod = 1000000007;

ll i=0,j=0,k=0,t=0,n=0;
const ll minn = 1e18;
const ll maxx = -1e18;
char x='a',y='a',z='a';
string s="",s1="";

vectorl pr;
void seive(int n){ 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++){ 
        if (prime[p] == true){ 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
    for (int p=2; p<=n; p++) 
      if (prime[p]) 
          pr.push_back(p);
} 

void solve(){
    ll n;
    cin>>n;
    map<string,ll> mp;
    ll co[n]={0};
    for(i=0;i<n;i++){
        string s;
        ll a;
        cin>>s>>a;
        mp[s]=i;
        if(i==0)
            co[i]=a;
        else
            co[i]=co[i-1]+a;
    }
    string s2;
    cin>>s2;
    cout<<co[n-1]-co[mp[s2]]<<endl;

}

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	public static void main(String[] args){
		Scanner s = new Scanner(System.in);
		int[] heights = new int[10];
		int hi = 0;
		int me = 0;
		int low = 0;
		for(int i = 0; i < heights.length; i++){
			int height = s.nextInt();
			if(height >= hi){
				low = me;
				me = hi;
				hi = height;
			}
			if(height >= me && height < hi){
				low = me;
				me = height;
			}
			if(height >= low && height < me){
				low = height;
			}
		}
		System.out.println(hi);
		System.out.println(me);
		System.out.println(low);
		
	}
}

Measured memory_bytes: 17180
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
int is_prime[200010],l2017[100010];
int main(){
    int q;cin>>q;
    REP(i,2,100001){
        bool f=1;
        REP(j,2,sqrt(i)+1)if(i%j==0&&i!=j)f=0;
        if(f){
            is_prime[i]=1,is_prime[2*i]=2;
        }
    }
    int count=0;
    REP(i,1,100001){
        if(is_prime[i]==1&&is_prime[i+1]==2)count++;
        l2017[i]=count;
    }
    rep(i,q){
        int l,r;cin>>l>>r;
        cout<<l2017[r]-l2017[l-1]<<endl;
    }
}

Measured memory_bytes: 1792
import fractions
n = int(input())
a = list(map(int, input().split()))
if n <= 2:
    print(max(a))
else:
    gcd_left = [a[0]]
    gcd_right = [a[-1]]
    for i in range(1, n):
        gcd_left.append(fractions.gcd(a[i], gcd_left[-1]))
        gcd_right.append(fractions.gcd(a[n-i-1], gcd_right[-1]))
    gcd_right = gcd_right[::-1]
    # print(gcd_left, gcd_right)
    ans = max(gcd_left[-2], gcd_right[1])
    for i in range(n-2):
        ans = max(ans, fractions.gcd(gcd_right[i+2], gcd_left[i]))
    print(ans)

Measured memory_bytes: 16128
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int n,mx_store,k; cin>>n>>mx_store>>k; 
    int a[n];
    for (int &i: a) cin>>i;
    sort(a,a+n);
    int ans=1,c=a[0],p=1;
    for (int i=1;i<n;i++){
        p++;
        if (a[i]-c>k or p>mx_store){
            ans++; p=1,c=a[i];
        } 
    }
    cout << ans << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


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

const int MOD = 1000000007;
const int INF = 1e9;

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

  long long ans = 0;
  ans = max(a*c, a*d);
  ans = max(ans, b*c);
  ans = max(ans, b*d);

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3628
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val m = sc.nextInt()
    val t = (1..n).map {
        val k = sc.nextInt()
        (1..k).map { sc.nextInt() - 1 }.fold(0, {acc, x -> acc or (1 shl x)})
    }.fold((1 shl m) - 1, {acc, x -> acc and x})
    println(Integer.bitCount(t))
}

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

using namespace std;

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

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

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

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

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

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

int main(){
  int x,y;
  cin>>x>>y;
  int g[] = {-1,1,3,1,2,1,2,1,1,2,1,2,1};
  cout<<(g[x]==g[y]?"Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 256
import math

n1 = int(input())

n3 = []
for i2 in range(n1):
    n3.append([int(i) for i in input().split()])

r4 = 0

for i5 in range(n1):
    for i6 in range(n1):
        if i5 != i6:
            r4 += math.sqrt(pow((n3[i5][0] - n3[i6][0]), 2) + pow((n3[i5][1] - n3[i6][1]), 2))

print(r4 / n1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes                \
    cout << "Yes" << endl; \
    return 0;
#define No                \
    cout << "No" << endl; \
    return 0;
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template <typename T>
void print(const T &v);

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

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 3564
import java.util.Scanner;
import java.awt.Point;
import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Point[] small=new Point[n];
		Point[] big=new Point[n];
		int ans=0;
		for(int i = 0; i<n; i++){
			int a = sc.nextInt();
			int b = sc.nextInt();
			small[i]=new Point(a,b);
		}
		for(int i = 0; i<n; i++){
			int c = sc.nextInt();
			int d = sc.nextInt();
			big[i]=new Point(c,d);
		}
		Arrays.sort(small, (pt1, pt2) -> (pt2.y - pt1.y));
		Arrays.sort(big, (pt1, pt2) -> (pt1.x - pt2.x));
		for(int i = 0; i<n; i++){
			for(int j = 0; j<n; j++){
				if(big[i].y>small[j].y && big[i].x>small[j].x){
					ans++;
					small[j].y=(2*n)+1;
					break;
				}
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 30668
n,t=map(int,input().split())
a=list(map(int,input().split()))
keep=0
ans=0
for i in range(n):
    if keep<=a[i]:
        ans+=t
        keep=a[i]+t
    else:
        ans=ans+t-(keep-a[i])
        keep=a[i]+t
print(ans)
        

Measured memory_bytes: 26832
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
// #include <ext/rope>
// using namespace __gnu_cxx;
typedef long long int ll;
typedef long double ld;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define ve vector
#define lb lower_bound
#define ub upper_bound
#define bb break
#define cc continue
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      // Initialize result 
    x = x % p;  // Update x if it is more than or 
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
ll modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
} 
struct point
{
    ll x,y;
};
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll s,w;
    cin>>s>>w;
    if(s>w)
    {
        cout<<"safe\n";
    }
    else
    {
        cout<<"unsafe\n";
    }
}



Measured memory_bytes: 3692
#include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#define pb(in,tmp) in.push_back(tmp)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) loop(i,0,b)
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
using namespace std;
int main(){
  int n;
  bool h=false;
  while(cin>>n,n){
    if(h)cout<<endl;
	h=true;
    vector<string>s(n);
	vector<int>t(n);
	rep(i,n){
	  int a,b,c;
	  cin>>s[i]>>a>>b>>c;
	  t[i]=3*a+c;
	}
	rep(i,n){
	  rep(j,n-i-1){
	    if(t[j]<t[j+1]){
		  swap(t[j],t[j+1]);
		  swap(s[j],s[j+1]);
		}
      }
	}
	rep(i,n)cout<<s[i]<<','<<t[i]<<endl;
	
  }
}

Measured memory_bytes: 1212
var
 i,j,k,x,y,s:longint;
begin
 readln(x,y);
 for i:=0 to x do
  for j:=0 to x do
   begin
    if (y-i-j>=0) and (y-i-j<=x) then
     inc(s);
   end;
 writeln(s);
end.

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  vl A(N, 0), B(N, 0);
  REP(i, N) cin >> A[i] >> B[i];

  bool ok = true;
  ll all = 0;
  REP(i, N) {
    all += A[i];
    if (A[i] != B[i])
      ok = false;
  }
  if (ok) {
    cout << 0 << endl;
    return 0;
  }
  ll ans = llINF;
  REP(i, N) {
    if (A[i] > B[i] && ans > B[i]) {
      ans = B[i];
    }
  }

  cout << all - ans << endl;

  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>

int g[102][102];
int d[102],f[102];
int t=0,n;

int dfs(int x){
  t++;
  int i;
  for(i=1;i<=n;i++){
    if(d[x]==0)
      d[x] = t;
    if(g[x][i]==1 && f[i]==0){
      g[x][i]=0;
      if(d[i]==0){
	dfs(i);
	t++;
      }
    }
    if(i==n && f[x]==0){
      f[x] = t+1;
    }
  }
  return 0;
}

int main(){
  scanf("%d", &n);
  int i,j;
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      g[i][j] = 0;
    }
    d[i]=0;
    f[i]=0;
  }

  int u,k;
  for(i=0;i<n;i++){
    scanf("%d %d", &u,&k);
    for(j=0;j<k;j++){
      int v;
      scanf("%d", &v);
      g[u][v] = 1;
    }
  }

  for(i=1;i<=n;i++){
    if(f[i]==0){
      dfs(i);
      t++;
    }
  }
  for(i=1;i<=n;i++){
    printf("%d %d %d\n", i, d[i], f[i]);
  }
  return 0;
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int h, n; std::cin >> h >> n;
  int sum = 0;
  rep(i, n) {
    int a; std::cin >> a;
    sum += a;
  }
  std::cout << (h <= sum ? "Yes" : "No") << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = pow(10, 9) + 7;
//const int mod = 998244353;
//const int mod = ;
const int INF = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}

signed main()
{
  int N;
  cin >> N;
  vector<tuple<string, int, int>> SPi(N);
  for (int i = 0; i < N; i++)
  {
    string s;
    int p;
    cin >> s >> p;
    SPi.at(i) = make_tuple(s, -p, i + 1);
  }

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

  for (int i = 0; i < N; i++)
  {
    cout << get<2>(SPi.at(i)) << endl;
  }
}

Measured memory_bytes: 256
class Union_Find():
    def __init__(self, num):
        self.par = [-1]*(num+1)
        self.siz = [1]*(num+1)

    def same_checker(self, x, y):
        return self.find(x) == self.find(y)

    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            x = self.par[x]
            return self.find(x)

    def union(self, x, y):
        rx = self.find(x)
        ry = self.find(y)
        if rx != ry:
            if self.par[rx] < self.par[ry]:
                self.par[ry] = rx
                self.siz[rx] += self.siz[ry]
            elif self.par[rx] > self.par[ry]:
                self.par[rx] = ry
                self.siz[ry] += self.siz[rx]
            else:
                self.par[rx] -= 1
                self.par[ry] = rx
                self.siz[rx] += self.siz[ry]
        return

    def size(self, x):
        return self.siz[self.find(x)]

n = int(input())
uf = Union_Find(n)

d = [list(map(int, input().split())) for i in range(n)]
x = [[] for i in range(100001)]
y = [[] for i in range(100001)]

for i in range(n):
    xi, yi = d[i]
    x[xi].append(i+1)
    y[yi].append(i+1)


for i in range(1, 100001):
    for j in range(len(x[i])-1):
        uf.union(x[i][j], x[i][j+1])

for i in range(1, 100001):
    for j in range(len(y[i])-1):
        uf.union(y[i][j], y[i][j+1])

par = [[] for i in range(n+1)]
for i in range(1, n+1):
    par[uf.find(i)].append(d[i-1])

ans = -n
for i in range(1, n+1):
    x = set()
    y = set()
    for xi, yi in par[i]:
        x.add(xi)
        y.add(yi)

    ans += len(x)*len(y)

print(ans)


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

//Made with <3 by MinumCoklatPanas
typedef long long ll;
const int INF = 1e9;
const ll INFF = 1e18;
const int MAXN = 510;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double INFD = 1E9;
const double EPS = 1e-9;

int par[100010];
int numset;

int finds(int x)
{
    return (par[x] == x ? x : par[x] = finds(par[x]));
}

void joins(int x,int y)
{
    int px = finds(x);
    int py = finds(y);
    if (px == py) return;
    par[px] = py;
    --numset;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,m;
    cin >> n >> m;
    for (int i = 1 ; i <= n ; i++) par[i] = i;
    numset = n;
    for (int i = 1 ; i <= m ; i++)
    {
        int a,b;
        cin >> a >> b;
        joins(a,b);
    }
    cout << numset - 1 << endl;
    return 0;
}

Measured memory_bytes: 4040
import math

x, k, d = map(int, input().split())


if abs(x) >= d * k:
    print(abs(abs(x)-d*k))
else:
    temp = math.ceil(abs(x)/d)
    if temp % 2 == 1:
        if k % 2 == 1:
            print(abs(abs(x)-temp*d))
        else:
            print(abs(abs(x)-temp*d+d))
    elif temp % 2 == 0:
        if k % 2 == 0:
            print(abs(abs(x)-temp*d))
        else:
            print(abs(abs(x)-temp*d+d))

Measured memory_bytes: 9088
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin
from itertools import product, permutations

EXPRESSIONS = [
    '({0[0]} {1[0]} ({0[1]} {1[1]} ({0[2]} {1[2]} {0[3]})))',
    '({0[0]} {1[0]} (({0[1]} {1[1]} {0[2]}) {1[2]} {0[3]}))',
    '(({0[0]} {1[0]} ({0[1]} {1[1]} {0[2]})) {1[2]} {0[3]})',
    '(({0[0]} {1[0]} {0[1]}) {1[1]} ({0[2]} {1[2]} {0[3]}))',
    '((({0[0]} {1[0]} {0[1]}) {1[1]} {0[2]}) {1[2]} {0[3]})'
   ]

def solve(datas):
    for nums in permutations(datas, 4):
        for ops in product('+-*', repeat=3):
            for template in EXPRESSIONS:
                exp = template.format(nums, ops)
                if eval(exp) == 10:
                    return exp
    return 0

def main():
    for line in stdin:
        if line.startswith('0 0 0 0'):
            break
        print(solve(line.split()))

if __name__ == '__main__':
    main()

Measured memory_bytes: 4448
#include <iostream>
 
int main(int argc, char *argv[]) {
  int x1, y1, x2, y2;
  std::cin >> x1 >> y1 >> x2 >> y2;
  int x = x2, y = y2, dx = x2 - x1, dy = y2 - y1;
  for (int i = 0; i < 2; ++i) {
    std::swap(dx, dy);
    dx = -dx;
    x += dx;
    y += dy;
    std::cout << x << " " << y << std::endl;
  }
}

Measured memory_bytes: 3640
#include <stdio.h>
int main(){
  int a,b;
  scanf("%d %d",&a, &b);
  if(b>a){
    a^=b;
    b^=a;
    a^=b;
  }
  printf("%d\n", gcd(a,b));
}
int gcd(int a, int b){
  if (!(a%b)) return b;
  return gcd(b,a%b);
}



Measured memory_bytes: 2108
#define _CRT_SECURE_NO_DEPRECATE
#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>  
#include<cstdio>  
#include<fstream>  
#include<iomanip>
#include<algorithm>  
#include<cmath>  
#include<deque>  
#include<vector>  
#include<assert.h>
#include<bitset>
#include<queue>  
#include<string>  
#include<cstring>  
#include<map>  
#include<stack>  
#include<set>
#include<functional>
#define pii pair<int, int>
#define mod 1000000007
#define mp make_pair
#define pi acos(-1)
#define eps 0.00000001
#define mst(a,i) memset(a,i,sizeof(a))
#define all(n) n.begin(),n.end()
#define lson(x) ((x<<1))  
#define rson(x) ((x<<1)|1) 
#define inf 0x3f3f3f3f
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

const int maxn = 1e5 + 150;
class node {
public:
	int u, v, w;
	node(int a, int b, int c) :u(a), v(b), w(c) {};
};
int fa[maxn];
int getf(int i) { return i == fa[i] ? i : fa[i] = getf(fa[i]); }
vector<node>edge;
bool cmp(const node&a, const node&b){return a.w < b.w;}
class T {
public:
	int value, id;
	bool operator<(const T &a)
	{
		return value < a.value;
	}
	T() {};
};
T sx[maxn], sy[maxn];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	int i, j, k, m, n, ta, tb;
	cin >> n;
	for (int i = 1; i <= n; ++i)
		fa[i] = i;
	for (int i = 1; i <= n; ++i)
	{
		cin >> sx[i].value >> sy[i].value;
		sx[i].id = sy[i].id = i;
	}
	sort(sx + 1, sx + n + 1);
	sort(sy + 1, sy + 1 + n);
	for (int i = 1; i < n; ++i)
	{
		edge.push_back(node(sx[i].id, sx[i + 1].id, sx[i+1].value - sx[i].value));
		edge.push_back(node(sy[i].id, sy[i + 1].id, sy[i+1].value - sy[i].value));
	}

	sort(all(edge), cmp);
	ll ans = 0;
	for (int i = 0; i <edge.size(); ++i)
	{
		if (getf(edge[i].u) != getf(edge[i].v))
		{
			ans += edge[i].w;
			fa[getf(edge[i].u)] = getf(edge[i].v);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6900
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;
 
int main(){
    int N; cin >> N;
    vvi kind(N, vi(0)); vvi unkind(N, vi(0));
    for(int i=0; i<N; i++){
        int a; cin >> a;
        for(int j=0; j<a; j++){
            int b, c; cin >> b >> c;
            if(c == 0){
                unkind[i].emplace_back(b-1);
            }
            else{
                kind[i].emplace_back(b-1);
            }
        }
    }
    ll max = 0;
    for(int i=0; i<pow(2,N); i++){
        vi res(N, -1);
        stringstream rr;
        rr << bitset<15>(i);
        string r = rr.str();

        ll k = 0;
        ll count = 0;
        for(int j=0; j<N; j++){
            if(r[14-j] == '1'){
                for(auto x: kind[j]){
                    if((res[x] == -1||res[x] == 1)&&(r[14-x] == '1')){
                        res[x] = 1;
                    }
                    else{
                        k++; break;
                    }
                }
                for(auto y: unkind[j]){
                    if((res[y] == -1||res[y] == 0)&&(r[14-y] == '0')){
                        res[y] = 0;
                    }
                    else{
                        k++; break;
                    }
                }
            }
        }

        if(k == 0){
            for(int h=0; h<N; h++){
                if(r[14-h] == '1'){count++;}
            }
        }
        if(count > max){max = count;}
    }
    cout << max;
}

Measured memory_bytes: 256
//Jai Shree Krishna
#include <vector>
#include <list>
#include <map>
#include <set>
#include "queue"
#include <deque>
#include <stack>
#include <numeric>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <complex>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include "fstream"
using namespace std;
#define PI acos(-1)
#define MOD (ll)1000000007
#define pii pair<long long ,long long >
#define ll  long long int
#define loop(i,n) for(ll i=0;i<n;i++)
#define loop2(i,n) for(ll i = 1;i<=n;i+=1)
#define pb push_back
#define mp make_pair
#define EPS 1e-8
void display(vector<int> v1){loop(i,v1.size()){cout<<v1[i]<<" ";}cout<<endl;}
ll dx[8] = {0,1,0,-1,1,1,-1,-1};
ll dy[8] = {1,0,-1,0,1,-1,1,-1};




const int MAXN  = (ll)1e5+100;

ll arr[MAXN];
ll pre[MAXN];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    //freopen("/Users/ashish/Desktop/B-large-practice.in.txt", "r", stdin);
    //freopen("/Users/ashish/Desktop/A-large-practice.out.txt", "w", stdout);
    ll n;
    cin>>n;
    loop2(i, n)
    {
        cin>>arr[i];
        
    }
    sort(arr+1,arr+n+1);
    loop2(i, n)
    {
        pre[i] = arr[i];
        pre[i]+=pre[i-1];
    }
    
    ll ans = 0 ;
    for(ll j  = n;j>=1;j-=1)
    {
        
        //cout<<j<<" "<<arr[j+1]<<" "<<pre[j]<<endl;
        if(arr[j+1]<=2*pre[j])
        {
            ans+=1;
        }
        else{
            break;
        }
    }
    cout<<ans<<endl;
    
    
    
    return 0;
}




Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <cstdio>
#include <new>
#include <vector>
#include <cstdlib>
#include <string>
#include <set>

using namespace std;

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

	int num;
	
	set<int> ss;

	for (int i = 0; i < N; ++i) {
		cin >> num;
		ss.insert(num);
	}

	for (int i = 0;; ++i) {
		if(ss.count(X-i)==0){
			cout << X - i << endl;
			break;
		}
		else if (ss.count(X + i) == 0) {
			cout << X + i << endl;
			break;
		}
	}

	/*if (N == 0) {
		cout << X << endl;
	}*/

}





Measured memory_bytes: 3620
#include<iostream>
using namespace std;
int d;
char c;

int main(){
	int n,x; cin >> n;
	d = x = 0;
	for(int i = 0; i < n; i++){
		cin >> c;
		if(c == 'I') x++;
		else x--;
		d = max(d,x);
	}
	cout << d << endl;
	return 0;
}

Measured memory_bytes: 256