akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;


int main(){
    long long n;
    cin >> n;
    vector<long long> a(n+1);
    for(long long i = 0; i < n; i++){
        cin >> a.at(i);
    }
    vector<long long> b(n+1);
    b[0] = a[0];

    long long ansa = 0,ansb = 0,sum = 0;
    //a[0]をマイナス(偶数がマイナス)
    for(long long i = 0; i < n; i++){
        if(i % 2 == 0){
            if(b[i] >= 0){
                ansa += 1 + b[i];
                b[i] = -1;
                b[i + 1] = b[i] + a[i + 1];
            }
            else b[i + 1] = b[i] + a[i + 1];
        }
        else{
            if(b[i] <= 0){
                ansa += 1 - b[i];
                b[i] = 1;
                b[i + 1] = b[i] + a[i + 1];
            }
            else b[i + 1] = b[i] + a[i + 1];
        }
    }

    b[0] = a[0];
    //a[0]をプラス(偶数がプラス)
    for(long long i = 0; i < n; i++){
        if(i % 2 == 1){
            if(b[i] >= 0){
                ansb += 1 + b[i];
                b[i] = -1;
                b[i + 1] = b[i] + a[i + 1];
            }
            else b[i + 1] = b[i] + a[i + 1];
        }
        else{
            if(b[i] <= 0){
                ansb += 1 - b[i];
                b[i] = 1;
                b[i + 1] = b[i] + a[i + 1];
            }
            else b[i + 1] = b[i] + a[i + 1];
        }
    }
    

    long long ans = min(ansa,ansb);
    cout << ans << endl;

}

Measured memory_bytes: 1792
#include<stdio.h>
#include<math.h>

int main(){

int N,D,ans=0;
scanf("%d%d",&N,&D);

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

for (int i = 0; i < N-1; i++){
  for (int j = i+1; j < N; j++){
    double sum = 0;
    for (int k = 0; k < D; k++){
      sum += (X[i][k]-X[j][k])*(X[i][k]-X[j][k]);
    }
    if (!(sqrt(sum)-(int)sqrt(sum))){ ans++;}
  }
}

printf("%d",ans);

return 0;

}

Measured memory_bytes: 2140
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N, A, B;
	cin >> N >> A >> B;

	cout << N / (A + B)*A + min(N % (A + B), A) << endl;

	return 0;
}

Measured memory_bytes: 256
import itertools
import math
from collections import defaultdict



def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

N = int(input())
ps = primes(10**5)

sim2017 = [0] * (10**5 + 1)
di =defaultdict(lambda :False)
for p in ps:
    di[p] = True
for p in ps:
    if di[(p+1)/2]:
        sim2017[p] +=1
l = len(sim2017)
for i in range(1,l):
    sim2017[i] = sim2017[i-1] + sim2017[i]
ins = []
for i in range(N):
    a,b = list(map(int,input().split(" ")))
    ins.append((a,b))
for a,b in ins:
    print(sim2017[b] - sim2017[a-1])



Measured memory_bytes: 23108
#include<bits/stdc++.h>
#define pub push_back
#define x first
#define all(a) a.begin(), a.end()
#define y second
#define mp make_pair
#define ll long long
using namespace std;

string s;
int len;
int cnt[55];

int main() {
    srand(time(NULL) + 'D' + 'E' + 'N' + 'I' + 'S' + 'S' + 'O' + 'N');
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);   
    cin >> s;
    len = s.size();
    ll ans = (ll)1 + (ll)len * (len + 1) / (ll)2;
    for (char x : s) cnt[x - 'a']++;
    for (int i = 0; i < 26; i++) ans -= cnt[i] * (ll)(cnt[i] + 1) / 2;
    cout << ans; 
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; i++)

int main()
{
  string str;
  int i;
  while(true){
    getline(cin, str);
    if(str[0] == '.') break;
    
    int len = 0;
    while(str[len] != '\0'){
      len++;
    }
        
    int d[101] = {0}, j;
    for(i = 0, j = 0 ; i < len ; i++){
      if(str[i] == '('){
	d[++j] = 1;
      }
      if(str[i] == '['){
	d[++j] = 2;
      }
      if(str[i] == ')'){
	if(d[j--]-1){
	  break;
	}
      }
      if(str[i] == ']'){
	if(d[j--]-2){
	  break;
	}
      }
    }
    if(str[i] || j){
      cout << "no" << '\n';
    }else{
      cout << "yes" << '\n';
    }
  }
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, K, H[int(1e5+5)];

int main(){
  cin >> N >> K;
  for (int i = 0; i < N; i++) cin >> H[i];
  sort(H, H + N);

  int ans = 1e9;
  for (int i = 0; i + K - 1 < N; i++){
    ans = min(ans, H[i + K - 1] - H[i]);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3992
#include <bits/stdc++.h>
 
using namespace std;
 
#define ALL(x) x.begin(), x.end()
 
typedef long long int lld;
typedef pair<int, int> pii;
 
const int maxn = 1e5 + 5;
bool dp[maxn];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(15);
	cout << fixed;
 
	int n, d;
	cin >> n >> d;

	int arr[10][10];

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

	auto dis = [&](int a, int b) {
		double res = 0;
		for (int i = 0; i < d; i++) {
			res += pow(arr[a][i] - arr[b][i], 2);
		}
		
		res = sqrt(res);

		if (res == floor(res))
			return true;
		return false;
	};

	int cnt = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (dis(i, j)) cnt++;
		}
	}

	cout << cnt << '\n';
 
 
	return 0;
}

Measured memory_bytes: 256
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 2e5+5;

int n;
int ar[N];
int cnt[N];

int main(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        int x;
        cin >> x;
        ar[i] = x;
        cnt[x]++;
    }
    long long ans = 0;
    for(int i = 1; i < N; i++){
        ans += 1LL * cnt[i] * (cnt[i] - 1) / 2;
    }
    for(int i = 1; i <= n; i++){
        ans -= 1LL * cnt[ar[i]] * (cnt[ar[i]]-1) / 2;
        cnt[ar[i]]--;
        ans += 1LL * cnt[ar[i]] * (cnt[ar[i]] - 1) / 2;
        cout << ans << "\n";
        ans -= 1LL * cnt[ar[i]] * (cnt[ar[i]] - 1) / 2;
        cnt[ar[i]]++;
        ans += 1LL * cnt[ar[i]] * (cnt[ar[i]] - 1) / 2;
    }
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

int main(){
	cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
	ll L, R;cin >> L >> R;
	ll ans = 2019;
	for(ll i = L;i <= min(L + 2019, R);i++){
		for(ll j = L;j < i;j++){
			ans = min(ans, i * j % 2019);
		}
	}
	cout << ans << endl;
	return 0;
}


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

const int SIZE=200010;
vector<int> G[SIZE];
vector<int> ans;

void dfs(int v,int p=-1)
{
    for(int u:G[v]){
        if(u==p) continue;
        ans[u]+=ans[v];
        dfs(u,v);
    }  
}
int main()
{
    int N,Q; cin>>N>>Q;
    for(int i=0;i<N-1;i++){
        int a,b; cin>>a>>b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    ans.resize(N);
    while(Q--){
        int p,x; cin>>p>>x;
        p--;
        ans[p]+=x;
    }
    dfs(0);
    for(int i=0;i<N;i++) cout<<ans[i]<<endl;
    
    return 0;
}

Measured memory_bytes: 23552
#include<iostream>
#include<cstring>
#include<vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
//using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<long long,int> P;

int main(){
    int x;
    cin >> x;
    cout << x * x * x << endl;
}


Measured memory_bytes: 3072
N = int(input())
y = int(N**0.5)
ans = 0
for A in range(1, y+1):
    if N%A == 0:
        x = N/A
        if x != A:
            ans += 1 + 2*(x-1-A)
    else:
        ans += 1 + 2*(N//A-A)
print(int(ans))

Measured memory_bytes: 9444
#include<cstdio>
#include<algorithm>
#include<cstdlib>
using namespace std;
int n, D[51][101][101], w[110], Mod = 1000000007;
int s;
int main(){
    int i, j, k, l;
    scanf("%d",&n);
    for(i=1;i<n+n;i++){
        scanf("%d",&w[i]);
    }
    sort(w+1,w+n+n);
    D[1][1][1] = 1; s = 1;
    for(i=1;i<n;i++){
        int ck1 = 0, ck2 = 0;
        if(w[n-i]!=w[n-i+1])ck1 = 1;
        if(w[n+i]!=w[n+i-1])ck2 = 1;
        for(j=1;j<=s;j++){
            for(k=1;k<=j;k++){
                if(!D[i][j][k])continue;
                int tp = D[i][j][k];
                for(l=1-ck1;l<=k;l++){
                    int t = j+ck1+ck2-max(0, k-l-1);
                    D[i+1][t][l+ck1] = (D[i+1][t][l+ck1] + tp)%Mod;
                }
                for(l=k+1;l<=j+ck2;l++){
                    int t = j+ck1+ck2-(l-k-1);
                    D[i+1][t][k+1+ck1] = (D[i+1][t][k+1+ck1] + tp)%Mod;
                }
            }
        }
        s += ck1+ck2;
    }
    int r = 0;
    for(i=1;i<=s;i++)for(j=1;j<=i;j++)r=(r+D[n][i][j])%Mod;
    printf("%d\n",r);
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int d[51];
int cop[51];
int main()
{
    int n, r;
    while (cin >> n >> r)
    {
        if (n == 0)
            break;
        for (int i = 0; i < n; i++)
            d[i] = n - i;
        for (int i = 0; i < r; i++)
        {
            int p, c;
            cin >> p >> c;
            for (int j = 0; j < c; j++)
                cop[j] = d[p - 1 + j];
            for (int j = p - 2; j >= 0; j--)
            {
                d[j + c] = d[j];
            }
            for (int j = 0; j < c; j++)
                d[j] = cop[j];
        }
        cout << d[0] << endl;
    }
}


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

typedef long long lli;

lli gcd(lli a, lli b) {
  return b == 0 ? a : gcd(b, a%b);
}

lli lcm(lli a, lli b) {
  return a*b/gcd(a,b);
}

int main() {
  lli a, b;

  while(cin >> a >> b) {
    cout << gcd(a, b) << " " << lcm(a, b) << endl;
  }
  return 0;
}

Measured memory_bytes: 1156
from itertools import accumulate
N=int(input())
A=list(input())
E=[1 if A[i] =="E" else 0 for i in range(N) ]
W=[1 if A[i] =="W" else 0 for i in range(N) ]
E=list(accumulate(E[::-1]))[::-1]
W=list(accumulate(W))
min_=N
for i in range(N):
    min_=min(min_,E[i]+W[i]-1)
print(min_)

Measured memory_bytes: 116416
a, b = list(map(int, input().split()))

def acc_xor(x):
  if x%4==0:
    return x
  elif x%4==1:
    return 1
  elif x%4==2:
    return x+1
  else:
    return 0

print(acc_xor(a-1)^acc_xor(b))

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

using namespace std;

typedef long long          ll;
typedef unsigned long long ull;
typedef vector<int>	       vi;
typedef vector<bool>       vb;
typedef map<int, int>      mii;
typedef pair<int, int>     ii;

#define INF                0x3f3f3f3f
#define INFLL              0x3f3f3f3f3f3f3f3f
#define each(x, s)         for(auto& x : s)
#define loop(x)	           for(int i = 0;i < x;i++)
#define vloop(v, x)        for(int v = 0;v < x;v++)
#define avg(l, r)          l + (r - l) / 2
#define iter(a)            a.begin(), a.end()
#define riter(a)           a.rbegin(), a.rend()
#define endl               "\n"

const ll mod = 1000000007;

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

	int n, k;
	cin >> n >> k;
	int ans = 0;
	while (n) n /= k, ans++;
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int n,m;
int i,j;
int req[100],no[100];
int d;

void sort(int a[], int n,int b[]){
	int x;
	for(i=n-1;i>0;i--){
		for(j=0;j<i;j++){
			if(a[j]>a[j+1]){
				x=a[j];
				a[j]=a[j+1];
				a[j+1]=x;
				x=b[j];
				b[j]=b[j+1];
				b[j+1]=x;
			}
			else if(a[j]==a[j+1])if(b[j]<b[j+1]){
				x=b[j];
				b[j]=b[j+1];
				b[j+1]=x;
			}
		}
	}
}

int main(){
	while(1){
		scanf("%d %d",&n,&m);
		if(n==0&&m==0)return 0;
		for(i=0;i<m;i++)req[i]=0;
		for(i=0;i<m;i++)no[i]=i+1;
		for(i=0;i<n;i++)for(j=0;j<m;j++){
			scanf("%d",&d);
			if(d==1)req[j]++;
		}
		sort(req,m,no);
		for(i=m-1;i>=0;i--){
			printf("%d",no[i]);
			if(i!=0)printf(" ");
		}
		printf("\n");
	}
}

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

using namespace std;

int a[1000];
int sum;

int main(){
	int n;

	scanf("%d", &n);

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

	for(int i = 0 ; i < n ; i++){
		for(int j = i + 1 ; j < n ; j++){
			sum += a[i] * a[j];
		}
	}

	printf("%d\n", sum);

	return 0;
}

Measured memory_bytes: 256
def sort(l):
    
    for i in range(len(l)) :
        key = l[i]
        j = i-1
        while j>=0 and l[j]>key:
            l[j+1] = l[j]
            j -= 1
            
        l[j+1] = key
        print(" ".join(map(str,l)))

n = int(input())
line = list(map(int,input().split(" ")))

sort(line)

Measured memory_bytes: 7604
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<unordered_map>
#include<bits/stdc++.h>
#define ll long long 
#define d double
using namespace std;
 
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  int r;
  cin>>r;
  int A=3*r*r;
  int a=3*1*1;
  cout<<A/a<<endl;
  
  return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
const double eps = 1e-8;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
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; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T> ostream& operator << (ostream& os, const set<T>& s) { for (auto si : s) os << si << " "; return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b % mod; if (a >= mod) a -= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12); // debuged
    int T;
    T = 1;
    while (T--) solve();
}

void solve() {
    ll x, k, d;
    cin >> x >> k >> d;
    if (x < 0) x = -x;
    
    ll cnt = min(x / d, k);
    x -= cnt * d;
    k -= cnt;
    // cerr << x << " " << k << endl;
    
    // 偶数回行ったり来たり
    if (k % 2) k = 1;
    else k = 0;
    
    if (k) x -= d;
    cout << abs(x) << endl;
}







Measured memory_bytes: 3684
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: usize = s.next().unwrap().parse().unwrap();
	let k: i64 = s.next().unwrap().parse().unwrap();
	let mut cnt = vec![0; 40];
	for a in s.take(n).map(|a| a.parse::<i64>().unwrap()) {
		for i in 0..40 {
			if a & (1 << i) != 0 {
				cnt[i] += 1;
			}
		}
	}
	let mut dp = vec![std::i64::MIN; 4];
	dp[0] = 0;
	for i in (0..40).rev() {
		let mut next = vec![std::i64::MIN; 4];
		let bit = 1 << i;

		for lastl in 0..2 {
			for lastm in 0..2 {
				if dp[lastl << 1 | lastm] == std::i64::MIN {
					continue;
				}
				let maxm = if lastl == 1 || k & bit != 0 { 1 } else { 0 };
				for m in 0..=maxm {
					let x = bit * if m == 0 { cnt[i] } else { n as i64 - cnt[i] };
					let nextl = if lastl == 1 || m < maxm { 1 } else { 0 };
					if next[nextl << 1 | m] < dp[lastl << 1 | lastm] + x {
						next[nextl << 1 | m] = dp[lastl << 1 | lastm] + x;
					}
				}
			}
		}

		dp = next;
	}
	println!("{}", dp.iter().max().unwrap());
}


Measured memory_bytes: 3400
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

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

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;


static const int MAXN=100005;
struct BIT{
  int val[MAXN*2+2];
  int n;
  void init(int n_){
    n=1;
    while(n<n_) n<<=1;
    REP(i,n+1) val[i]=0;
  }
  void add(int k,int a){
    ++k;
    while(k<=n){
      val[k]+=a;
      k+=k&-k;
    }
  }
  int query(int k){ //[0,k)
    int res=0;
    while(k>0){
      res+=val[k];
      k-=k&-k;
    }
    return res;
  }
};


int n;
int buf[3][100005];

int ar[100005],sign[100005];
void ng(){
  puts("No");
  exit(0);
}

BIT bit;

int main(){
  cin>>n;
  REP(i,3) REP(j,n) scanf("%d",&buf[i][j]),--buf[i][j];

  REP(i,n){
    int a=min({buf[0][i],buf[1][i],buf[2][i]}),b=max({buf[0][i],buf[1][i],buf[2][i]});
    if(b-a!=2 || a%3!=0) ng();
    if(buf[1][i]!=(a+b)/2) ng();
    int base=buf[0][i]/3;

    ar[i]=base;
    sign[base]=(buf[0][i]%3==2);
    if(abs(base-i)/2%2) sign[base]^=1;
    if((ar[i]&1)!=(i&1)) ng();
  }
  debug(ar,ar+n);

  bit.init(n);
  lint sum1=0,sum2=0;
  for(int i=0;i<n;i+=2){
    int dif=(i/2-bit.query(ar[i]+1));
    sum1+=dif;
    dump(sum1);
    bit.add(ar[i],1);
  }
  bit.init(n);
  for(int i=1;i<n;i+=2){
    int dif=(i/2-bit.query(ar[i]+1));
    sum2+=dif;
    bit.add(ar[i],1);
  }

  int cnt[2]={0};
  REP(i,n) if(sign[i]) cnt[i&1]++;
  dump(cnt[0]);dump(sum2);
  dump(cnt[1]);dump(sum1);
  if(cnt[0]%2==sum2%2 && cnt[1]%2==sum1%2) puts("Yes");
  else puts("No");
  return 0;
}





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

int main()
{
    vector<int> v(3);
    int n, cnt = 0;
    cin >> v[0] >> v[1] >> v[2] >> n;
    sort(v.begin(), v.end());
    for (int i = 0; v[0] * i <= n; i++)
    {
        for (int j = 0; v[0] * i + v[1] * j <= n; j++)
        {
            if ((n - (v[0] * i + v[1] * j)) % v[2] == 0)
                cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
#include <string.h>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

int x, y;

int main(){
  cin >> x >> y;
  int ans;
  if( 0 <= x && x < y) ans = y - x;
  else if(x < 0 && 0 < y) ans = abs(abs(y) - abs(x)) + 1;
  else if(x < y && y <= 0) ans = y - x;
  else if(0 < y && y < x) ans = x - y + 2;
  else if(y <= 0 && 0 <= x) ans = abs(abs(y) - abs(x)) + 1;
  else if(y < x && x < 0) ans = x - y + 2;

  cout << ans << endl;

  return 0;
}



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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;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--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N; cin >> N;
    vector<ll> p(N);
    ll cnt = 0;
    rep(i, N){cin >> p.at(i);}
    vector<ll> q(p);
    sort(q.begin(), q.end());

    rep(i, N){if (p.at(i) != q.at(i)){cnt++;}}
    string ans = (cnt <= 2) ? "YES" : "NO";
    cout << ans << endl;
}

int main() {

    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
# ABC 062 A - Grouping
x,y =map(int,input().split())
ga = [1,3,5,7,8,10,12]
gb = [4,6,9,11]
gc= [2]
if x in ga and y in ga:
    print("Yes")
elif x in gb and y in gb:
    print("Yes")
elif x in gc and y in gc:
    print("Yes")
else:
    print('No')
    

Measured memory_bytes: 3060
import sys

state = True
for s in sys.stdin:
    if state:
        state = not state
        a = list(map(int,s.split()))
    else:
        state = not state
        b = list(map(int,s.split()))
        hit = 0
        for i in range(len(a)):
            if a [i] == b [i]:
                hit += 1
        blow = -hit
        for i in range(10):
            blow += min(a.count(i),b.count(i))
        print(hit,blow)

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

int mat[100002][3], dp[100002][3];


int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) 
    for (int j = 0; j < 3; ++j) cin >> mat[i][j];

  for (int i = 0; i < 3; ++i) dp[0][i] = mat[0][i];

  vector<vector<int>> now {{1, 2}, {0, 2}, {0, 1}};

  for (int pos = 1; pos < n; ++pos) {
    for (int col = 0; col < 3; ++col) {
      for (auto el: now[col]) {
        dp[pos][col] = max(dp[pos][col], mat[pos][col] + dp[pos - 1][el]);
      }
    }
  }

  int res = 0;
  for (int i = 0; i < 3; ++i) res = max(res, dp[n - 1][i]);
  cout << res << endl;  
  return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

using namespace std;


long long n,a,b;
static const long long N = 100005;
long long h[N];

bool enough(long long t){
    long long ans=0;
    for (long long i=0;i<n;i++){
       if ((h[i] - b*t) > 0 and (h[i] - b*t) % (a-b) == 0){
            ans += (h[i] - b*t) / (a-b);
        }else if((h[i] - b*t) > 0){
            ans += (h[i] - b*t) / (a-b) + 1;
        }
    }
   if (ans <= t){
        return true;
    }else{
        return false;
    }
}
long long binary_search(long long vmin, long long vmax){
    if(vmin == vmax){
        return vmin;
    }
    long long vmid = (vmin + vmax) / 2;
    if (enough(vmid) == true){
        vmax = vmid;
    }else{
        vmin = vmid+1;
    }
    binary_search(vmin,vmax);

}


int main() {
    

    cin >> n >> a >> b;
    for (long long i = 0;i<n;i++){
        cin >> h[i];
    }
    long long vmax = 1000000000;
    long long vmin = 0;
    long long q = binary_search(vmin,vmax);
    cout << q << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{   int a, b, n, i;

    scanf("%d %d %d", &a, &b, &n);

    if (a == 5 && b == 5 && n == 7) {
        puts("YES");
    } else if (a == 5 && b == 7 && n == 5) {
        puts("YES");
    } else if (a == 7 && b == 5 && n == 5) {
        puts("YES");
    } else {
        puts("NO");
    }


    return 0;
}



Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    static Deque<String> list = new ArrayDeque<>();

    public static void main(String[] args) {
        StringBuilder ans = new StringBuilder();
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] sp = new String[2];
        try {
            int n = Integer.parseInt(br.readLine());
            for (int i = 0; i < n; i++) {
                sp = br.readLine().split(" ");
                if (sp[0].equals("insert")) {
                    list.addFirst(sp[1]);
                } else if (sp[0].equals("delete")) {
                    list.remove(sp[1]);
                } else if (sp[0].equals("deleteFirst")) {
                    list.removeFirst();
                } else if (sp[0].equals("deleteLast")) {
                    list.removeLast();
                }
            }
            if (!list.isEmpty()) {
                ans.append(list.getFirst());
                list.removeFirst();
            }
            while (!list.isEmpty()) {
                ans.append(" ").append(list.getFirst());
                list.removeFirst();
            }
            System.out.println(ans.toString());
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }catch (IOException e) {
            e.printStackTrace();
        }
    }
}



Measured memory_bytes: 228692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    ll a,b,c;cin>>a>>b>>c;
    ll ans = 0;
    if(a%2==0 || b%2==0 || c%2==0){
        ans = 0;
    }
    else{
        ans = min(min(a*b,b*c),c*a);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;


int main() {
    int N, M;
    int food[30];
    int num_food;
    int like;
    int res = 0;

    for (int k = 0; k < 30; k++) {
        food[k] = 0;
    }

    cin >> N;
    cin >> M;

    for (int i = 0; i < N; i++) {
        cin >> num_food;
        for (int j = 0; j < num_food; j++) {
            cin >> like;
            food[like-1]++;
        }
    }

    for (int k = 0; k < 30; k++) {
        if (food[k] == N) {
            res++;
        }
    }

    cout << res;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define reps(i,x) for(ll i=1;i<=(ll)(x);i++)
#define rrep(i,x) for(ll i=((ll)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(ll)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
int main() {
  int n, a;

  cin >> n;
  ll ans = 0;
  rep(i, n){
    cin >> a;
    ans += a - 1;
  }
  cout << ans << endl;

  
}



Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;
 
public class Main {

  public static class edge {
    int from;
    int to;
    edge (int _from, int _to) {
      from = _from;
      to   = _to;
    }
  }

  static final int V = 100;
  static int n, t;
  static int d[], f[];
//static ArrayList<ArrayList<edge>> es;
  static edge[][] es;

  public static void dfs(int v) {  
    int i;
    d[v] = ++t;
//    for (i=0; i<es.get(v).size(); i++) {
    for (i=0; i<es[v].length; i++) {
//      int to = es.get(v).get(i).to;
      int to = es[v][i].to;
      if (d[to] == -1) dfs(to);
    }
    f[v] = ++t;
  }

  public static void main(String[] args) {
    int i, j;

    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
//    es = new ArrayList<ArrayList<edge>>();
    es = new edge[n][];

    d = new int[n];
    f = new int[n];
    Arrays.fill(d, -1);
    Arrays.fill(f,  0);

    for (i=0; i<n; i++) {
      int u = Integer.parseInt(sc.next());
      int k = Integer.parseInt(sc.next());
//      ArrayList<edge> l = new ArrayList<edge>();
    es[i] = new edge[k];
      for (j=0; j<k; j++) {
        int v = Integer.parseInt(sc.next());
//        l.add(new edge(u-1, v-1));
        es[i][j] = new edge(u-1, v-1);
      }
//      es.add(new ArrayList<edge>(l));
    }

    t = 0;
    for (i=0; i<n; i++)
      if (d[i] == -1) dfs(i);

    for (i=0; i<n; i++) {
      System.out.print(String.valueOf(i+1) + ' ');
      System.out.print(String.valueOf(d[i]) + ' ');
      System.out.println(f[i]);
    }
  }
}

Measured memory_bytes: 20492
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
using namespace std;

int main(){
	int n, a, count = 1000;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		int temp = 0;
		while (a % 2 == 0) {
			++temp;
			a /= 2;
		}
		count = min(count, temp);
	}
	cout << count << endl;
}

Measured memory_bytes: 256
def nCr(n, r, mod):
    x, y = 1, 1
    for r_ in range(1, r+1):
        x = x*(n+1-r_)%mod
        y = y*r_%mod
    return x*pow(y, mod-2, mod)%mod

n, k = map(int, input().split())
mod = 10**9+7
for i in range(1, k+1): print(nCr(n-k+1, i, mod)*nCr(k-1, i-1, mod)%mod)

Measured memory_bytes: 3316
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

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

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


n, m = map(int, readline().split())
ab = [list(map(int, readline().split())) for _ in range(m)][::-1]
uf = UnionFind(n + 1)
ans = [0] * (m + 1)
ans[-1] = n * (n - 1) // 2
for i, (a, b) in enumerate(ab):
    ans[-(i + 2)] = ans[-(i + 1)]
    if not uf.same(a, b):
        ans[-(i + 2)] -= uf.size(a) * uf.size(b)
    uf.union(a, b)
print(*ans[1:])


Measured memory_bytes: 35732
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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 (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int K; cin >> K;
	int N; cin >> N;
	VI A;
	REP(i, N) {
		int a;
		cin >> a;
		A.push_back(a);
	}

	REP(i, N) A.push_back(A[i] + K);

	VI sum(N * 2 + 10, 0);
	REP(i, 2 * N) {
		sum[i + 1] = sum[i] + A[i];
	}
	int ans = INF;

	REP(i, N) {
		chmin(ans, A[i + N - 1] - A[i]);
		//cout << A[i + N - 1] << " " << A[i] << endl;
	}
	reverse(A.begin(), A.end());
	REP(i, 2 * N + 5)sum[i] = 0;
	REP(i, 2 * N) {
		sum[i + 1] = sum[i] + A[i];

	}
	REP(i, N) {
		chmin(ans, abs(A[i + N-1] - A[i]));
		//cout << A[i + N - 1] << " " << A[i] << endl;
	}
	cout << ans << endl;



	return 0;
}



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



int main(void){
	
	int n,m,a,b;

	scanf("%d %d",&n,&m);
	
	int h[n];

	int array[n];

	for(int i=0;i<n;i++)
{
	array[i]=1;
}



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

	int count=0;

	for(int i=0;i<m;i++)
	{
		scanf("%d %d",&a,&b);

		if(h[a-1]>h[b-1]){			
			array[b-1]=0;
		}
		else if(h[a-1]<h[b-1]){
			array[a-1]=0;			
		}
		else
		{
			array[a-1]=0;
			array[b-1]=0;
		}
	}

	for(int i=0;i<n;i++)
	{
		if(array[i]!=0){count++;}
	}

	printf("%d",count);

	return 0;
	}


Measured memory_bytes: 2508
#include<iostream>
#include <vector>
#include <cstdlib>
#include<algorithm>
#include<string>
#include<cmath>
#include<math.h>
#define ll long long int
using namespace std;
    vector <ll> a;
    vector <ll> b;
    vector <ll> c;


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

    for(ll i=0;i<n;i++)
    {
        ll temp1,temp2,temp3;
        cin>>temp1>>temp2>>temp3;
        a.push_back(temp1);
        b.push_back(temp2);
        c.push_back(temp3);
    }
    vector <vector<ll>> arr(n,vector <ll> (3,0));
    arr[0][0]=a[0];
    arr[0][1]=b[0];
    arr[0][2]=c[0];
    for(ll i=1;i<n;i++)
    {
        arr[i][0]=max(arr[i-1][1],arr[i-1][2])+a[i];
        arr[i][1]=max(arr[i-1][0],arr[i-1][2])+b[i];
        arr[i][2]=max(arr[i-1][0],arr[i-1][1])+c[i];

    }
    cout<<max(max(arr[n-1][0],arr[n-1][1]),arr[n-1][2]);
    return 0;

}

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

int main() {
  int n; cin>>n;
  vector<int> t(n+1),x(n+1),y(n+1);
  t[0] = 0; x[0] = 0; y[0] = 0;
  for(int i=1; i<=n; i++) cin>>t[i]>>x[i]>>y[i];
  for(int i=0; i<n; i++) {
    int d = abs(x[i+1]-x[i]) + abs(y[i+1]-y[i]);
    if(d > t[i+1]-t[i] || (t[i+1]-t[i])%2 != d%2) {
      cout<<"No";
      return 0;
    }
  }
  cout<<"Yes";
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <queue>

using namespace std;
using ll = long long;
using pint = pair<int, int>;

int main() {
	string S;
	vector<string> W = { "SUN","MON","TUE","WED","THU","FRI","SAT" };
	cin >> S;
	
	for (int i = 0; i < W.size(); ++i) {
		if (S == W[i]) {
			cout << 7 - i << endl;
			return 0;
		}
	}
	return 0;
}



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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n=in();
    string s;
    int ans[26];
    REP(i,26){
        ans[i]=100;
    }
    REP(i,n){
        cin>>s;
        vector<int> str;
        REP(j,s.size()){
            str.pb(s[j]-'a');
        }
        REP(j,26){
            ans[j]=min(ans[j],int(count(all(str),j)));
        }
    }
    REP(i,26){
        if(ans[i]==100)continue;
        REP(j,ans[i]){
            cout<<char('a'+i);
        }
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i++; i<N)
#define RVROOP(i, N) for(int i=N; i--; i>=0)
#define ALL(v) v.begin(), v.end()
const int INF = 1e9;
const int MAX = 510000;
const int MOD = 1000000007;
const double PI = acos(-1);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

/*C++になってるか確認したほうがよくない？WOWWOW*/
/*DP使ったほうがよくない？？WOWWOW*/

int main(){
    int N, K; cin>>N>>K;
    int a[N];
    for(int i=0; i<N; i++){
        a[i]=0;
    }
    int d, A;
    for(int i=0; i<K; i++){
        cin>>d;
        for(int j=0; j<d; j++){
            cin>>A;
            a[A-1]++;
        }
    }
    int ans=0;
    for(int i=0; i<N; i++){
        if(a[i]==0){
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3636
#include<stdio.h>

int main(){
	int a,b,krg,kali,out;
	scanf("%d %d",&a,&b);fflush(stdin);
	out = a+b;
	krg = a-b;
	kali = a*b;
	if(krg > out)
		out = krg;
	if(kali > out)
		out = kali;
	printf("%d",out);
	return 0;
}

Measured memory_bytes: 128
package main

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

var (
	s    = bufio.NewScanner(os.Stdin)
	w    = bufio.NewWriter(os.Stdout)
	a, n = []int{}, 0
)

func main() {
	n = nextInt(s)
	a = atoi(s)
	_ = nextInt(s)
	m := atoi(s)

	for _, v := range m {
		i := 0
		if solve(i, v) {
			fmt.Fprintln(w, "yes")
			continue
		}
		fmt.Fprintln(w, "no")
	}
	w.Flush()
}

func nextInt(s *bufio.Scanner) int {
	s.Scan()
	r, err := strconv.Atoi(s.Text())
	if err != nil {
		panic(err)
	}
	return r
}

func atoi(s *bufio.Scanner) []int {
	s.Scan()
	a := strings.Fields(s.Text())
	i := []int{}

	for _, v := range a {
		j, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		i = append(i, j)
	}
	return i
}

func solve(i, m int) bool {
	if m == 0 {
		return true
	} else if i >= n {
		return false
	}
	return solve(i+1, m) || solve(i+1, m-a[i])
}



Measured memory_bytes: 1136
#include<bits/stdc++.h>
#define fori(x,a,b) for (int x=a;x<=b;x++)
#define int long long
using namespace std;
const int K = 1e5+10;
const int mod = 1e9+7;
int n,k,a[K];
int f[110][K],fake[K];
int sum[K];
 main()
{
    cin>>n>>k;
    fori(i,1,n) cin>>a[i];
    fori(i,1,k) f[0][i] = 0;
    f[0][0] = 1;
    // f[i][j] : j vien keo cho doan tu 1 -> i;
   fori(i,1,n)
   {
       sum[0] = f[i-1][0];

       fori(j,1,k)
       {
           sum[j] = ( sum[j-1] + f[i-1][j] )%mod;
       }


       fori(j,0,k)
       {
           int tmp = sum[j]; // f[i-1][0...j]
           int unreachable = j-a[i]-1;//?
           if (unreachable>=0)
           {
               tmp = (tmp - sum[unreachable] + mod)%mod;
           }
           f[i][j] = tmp;
       }
   }
  cout<<f[n][k];

}


Measured memory_bytes: 83284
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s,t;
    cin>>s>>t;
    int mx=INT_MAX;
    for(int i=0;i<=s.size()-t.size();i++){
        int mn=0;
        for(int j=0;j<t.size();j++){
            if(s[i+j]!=t[j]){
                mn++;
            }
        }
        mx=min(mx,mn);
    }
    cout<<mx;
}

// int ans=0,mx=INT_MAX,flag=0;

//         ans=0;
//         for(int j=0;j<t.size();j++){
//             if(i+j>=s.size()){
//                 flag=1;
//                 break;
//             }
//             if(s[i+j]!=t[j]){
//                 ans++;
//             }
//         }
//         mx=min(mx,ans);
//     }
//     cout<<mx;

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
	int M, K; cin >> M >> K;
	int N = 1 << M;
	if (N <= K) {
		cout << -1 << endl;
		return 0;
	}

	if (M == 0) {
		if (K == 0) {
			cout << "0 0" << endl;
		}
		else {
			cout << -1 << endl;
		}
		return 0;
	}
	if (M == 1) {
		if (K == 0) {
			cout << "0 0 1 1" << endl;
		}
		else {
			cout << -1 << endl;
		}
		return 0;
	}
	
	cout << K << " ";
	for (int i = 0; i < N; i++) {
		if (i == K) {
			continue;
		}
		cout << i << " ";
	}
	cout << K << " ";
	for (int i = N - 1; i >= 0; i--) {
		if (i == K) {
			continue;
		}
		cout << i << " ";
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 1792
#pragma GCC optimize "03"
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;

pi a[N];
 
signed main() {
	IOS;
	#ifdef LOCAL
		freopen("input.txt","r", stdin);
		freopen("output.txt","w",stdout);
	#endif
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> a[i].se >> a[i].fi;
	sort(a + 1, a + n + 1);
	reverse(a + 1, a + n + 1);
	int cur = inf;
	for(int i = 1; i <= n; i++){
		cur = min(cur, a[i].fi);
		cur -= a[i].se;
	}
	if(cur < 0)
		cout << "No";
	else
		cout << "Yes";
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

const int MAX_TEMBODAI_NUMBER = 200010;

int main() {
  int tembodai_count, temboway_count;
  scanf("%d %d", &tembodai_count, &temboway_count);

  int height_array[tembodai_count];
  int max_height_array[tembodai_count];
  for (int i = 0; i < tembodai_count; i += 1) {
    scanf("%d", height_array + i);
    max_height_array[i] = 0;
  }

  int bad_tembodai[MAX_TEMBODAI_NUMBER];
  for (int i = 0; i < temboway_count; i += 1) {
    int tembodai_number_a, tembodai_number_b;
    scanf("%d %d", &tembodai_number_a, &tembodai_number_b);
    if (height_array[tembodai_number_a - 1] >= height_array[tembodai_number_b - 1]) {
      bad_tembodai[tembodai_number_b] += 1;
    }
    if (height_array[tembodai_number_a - 1] <= height_array[tembodai_number_b - 1]) {
      bad_tembodai[tembodai_number_a] += 1;
    }
  }

  int output = 0;
  for (int i = 1; i <= tembodai_count; i += 1) {
    if (bad_tembodai[i] == 0) {
      output += 1;
    }
  }
  printf("%d", output);

  return 0;
}


Measured memory_bytes: 2904
#coding: utf-8
import math
import heapq
import bisect

MOD = 10**9+7

def gcd(A,B):
    if B>A:
        A,B = B,A

    if(A%B==0):
        return B
    else:
        return gcd(B,A%B)

A,B = map(int, input().split())
G = gcd(A,B)

ans = 1
for i in range(2,math.ceil(math.sqrt(G))+1):
    if G%i==0:
        ans+=1
        while G%i==0:
            G/=i
if G!=1:
    ans+=1

print(ans)


Measured memory_bytes: 3064