akhauriyash/Code-Regression huggingface dataset:
import os
import sys

from collections import Counter

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N = int(sys.stdin.buffer.readline())


def solve(N, group_cnt=2):
    s = sum(range(N + 1))

    while s * (group_cnt - 1) % group_cnt != 0:
        group_cnt += 1

    groups = [set() for _ in range(group_cnt)]
    sums = [[0, i] for i in range(group_cnt)]

    for n in reversed(range(1, N + 1)):
        for i, (_, v) in enumerate(sums[1:], start=1):
            sums[i][0] -= n
            groups[v].add(n)
        sums.sort()

    # わからない。グループ数増やしていけばどっかでうまくいくらしい。
    if len(Counter([s for s, _ in sums])) > 1:
        return solve(N, group_cnt + 1)

    ans = set()
    for group in groups:
        for v in set(range(1, N + 1)) - group:
            for u in group:
                ans.add((min(v, u), max(v, u)))
    return ans


ans = solve(N)
print(len(ans))
for r in ans:
    print(*r)
exit()

for n in range(3, 101):
    ans = solve(n)

    graph = [[] for _ in range(n + 1)]
    for v, u in ans:
        graph[v].append(u)
        graph[u].append(v)

    c = Counter([sum(vs) for vs in graph[1:]])
    if len(c) > 1:
        print(n, c)


Measured memory_bytes: 4332
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define all(cont) cont.begin(), cont.end()
#define unique(a)  sort(all(a)) , (a).erase(unique((a).begin(), (a).end()),(a).end())
#define rall(cont) cont.rbegin(), cont.rend()
#define sz(x) (int)(x).size()
#define fastio          ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define PB push_back
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
const int N = 2e5 + 5;
#define PI acos(-1.0)
typedef long long ll;
#define int long long
typedef long double ld;
typedef vector<int> VI;
inline ll add(ll x, ll y) { x += y; if (x >= mod) x -= mod; return x; }
inline ll sub(ll a, ll b) { if (a < b)swap(a, b); return (((a%mod) - (b%mod) + mod) % mod); }
inline ll mul(ll x, ll y) { return (x%mod * 1ll * y%mod) % mod; }
inline ll pwr(ll a, ll b) { ll x = 1 % mod; while (b) { if (b & 1) x = mul(x, a); a = mul(a, a); b >>= 1; }return x % mod; }
inline ll inv(ll a) { return pwr(a, mod - 2) % mod; }
ll gcd(ll a, ll b) { if (!a)return b % mod; return gcd(b%a, a) % mod; }
#define debug(x) cout << #x << " = " << x << endl;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#define in(container) for (auto &it : container) cin>>it;
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
signed main()
{
	fastio;
	int arr[32] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	int k;
	cin >> k;
	cout << arr[k-1] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    vector<int> v(n);
    for(int i=0;i<n;i++)
    cin>>v[i];
    int dp[n+10];
    memset(dp,0x3f,sizeof(dp));
    dp[0]=0;
    for(int i=1;i<n;i++)
    {
        for(int j=i-k;j<i;j++)
        {
        	if(j>=0)
            dp[i]=min(dp[i],abs(v[i]-v[j])+dp[j]);
        }
    }
    cout<<dp[n-1];
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,-1,0,1,1,-1,1,-1,0};
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;
}


vector<ll> sieve(int n) {
  vector<ll> res(n);
  iota(res.begin(), res.end(), 0);
  for (int i = 2; i*i < n; ++i) {
    if (res[i] < i) continue;
    for (int j = i*i; j < n; j += i)
      if (res[j] == j) res[j] = i;
  }
  return res;
}

vector<ll> factor(int n, const std::vector<ll>& min_factor) {
  // min_factor は sieve() で得られたものとする
  vector<ll> res;
  while (n > 1) {
    res.push_back(min_factor[n]);
    n /= min_factor[n];
    // 割った後の値についても素因数を知っているので順次求まる
  }
  return res;
}

int main(){
    ll n;cin >> n;
    vl v(n);rep(i,n)cin >> v[i];
    ll al=v[0];
    ll maxi=*max_element(all(v));
    rep(i,n){
        al=__gcd(al,v[i]);
    }
    if(al!=1){
        cout << "not coprime" <<endl;
    }
    else{
        vl ret(maxi+1);
        vl prime=sieve(maxi+1);
        bool ok=true;
        rep(i,n){
            vl fac=factor(v[i],prime);
            for(auto z:fac)if(ret[z])ok=false;
            for(auto z:fac)ret[z]++;
        }
        cout << (ok? "pairwise coprime":"setwise coprime") <<endl;
    }
} 

Measured memory_bytes: 26756
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define endl "\n"
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 2e+9 + 10;
typedef pair<ll, ll> P;

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

  vec d(26);
  string s; cin >> s;
  for(auto c:s) {
    d[c-'a']++;
  }
  rep(i,26) {
    if(!d[i]) {
      cout << (char)('a'+i) << endl;
      return 0;
    }
  }
  cout << "None" << endl;

  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int t,a,i,n,m,b,j;
    cin>>a>>t;
    vector< int >v[a];
    for(i=0;i<t;i++)
    {
        cin>>n>>m;
        if(n==0)
        {
            cin>>b;
            v[m].push_back(b);
        }
        else if(n==1)
        {
            for(j=0;j<v[m].size();j++)
            {
                if(j==v[m].size()-1)
                {
                    cout<<v[m][j];
                }
                else
                {
                    cout<<v[m][j]<<" ";
                }
            }
            cout<<endl;
        }
        else
            v[m].clear();

    }
}



Measured memory_bytes: 5800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll V,E;
struct edge{
	ll to,cost,id;
};
const ll maxn = 100005;
const ll INF = 102120027425345LL;
vector<edge> G[maxn],rG[maxn],sG[maxn];
ll d[maxn], d2[maxn];
bool isBridge[maxn];
void dijkstra(ll s, vector<edge> G[maxn], ll d[maxn]) {
	priority_queue<P, vector<P>, greater<P> > que;
	fill(d, d+V, INF);
	d[s] = 0;
	que.push(P(0,s));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		ll v = p.second;
		if (d[v] < p.first) continue;
		for (auto e:G[v]){
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to],e.to));
			}			
		}
	}
}
	map<P,ll> M;
ll dfs_clock,pre[maxn],low[maxn];
ll dfs(ll u, ll edge_id) {
	ll lowu = pre[u] = ++dfs_clock;
	for (auto e: sG[u]) {
		ll v = e.to;
		if (!pre[v]) {
			ll lowv = dfs(v,e.id);
			lowu = min(lowu, lowv);
			if (lowv > pre[u]){
				if (M[P(u,v)]==1) isBridge[e.id] = true;
			}
		}
		else if (pre[v] <pre[u]&&e.id!=edge_id) lowu = min(lowu, pre[v]);
	}
	return low[u] = lowu;
}

ll ans[maxn];


int main() {
	scanf("%d%d", &V, &E);

	for (ll i = 0; i < E; i++) {
		ll x,y,cost;
		scanf("%lld%lld%lld",&x,&y,&cost);
		--x,--y;
		
		G[x].push_back(edge{y,cost,i});
		rG[y].push_back(edge{x,cost,i});	
	}
	dijkstra(0,G,d);
	dijkstra(1,rG,d2);
	for(ll i = 0; i < V; i++)
	for (auto e:G[i]) {
		//cerr << i << " "  <<e.to <<" " << d[i] << " " << e.cost << " " << d[e.to] << endl;
		if (d[i] + e.cost == d[e.to]&&d[e.to]+d2[e.to]==d[1]) 
		{
			sG[i].push_back(e),sG[e.to].push_back(edge{i,e.cost,e.id});//cerr << i << " "  <<e.to<<endl; 
			M[P(i,e.to)]++;
		}
	}
	//cerr << "------" << endl;
	dfs(0,-1);
	//for (ll i = 0; i < E; i++) cerr<< isBridge[i] << " " ;
	//cerr<<endl;
	for(ll i = 0; i < V; i++)
	for (auto e:G[i]) {
		if (isBridge[e.id]) ans[e.id] = -1;
		else {
			if (d[e.to] + e.cost + d2[i] < d[1]) ans[e.id] = 1;
			else ans[e.id] = 0;
		}
	}
	for (ll i = 0; i < E; i++) {
		if (ans[i] == -1) puts("SAD");
		else if (ans[i] == 0) puts("SOSO");
		else puts("HAPPY");
	}
	
	

}



Measured memory_bytes: 45796
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 11000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,int> P;

int C[110000];

int main(){
  ll a;
  int N,M;
  priority_queue<ll> pque;
  cin>>N>>M;
  for(int i=0;i<N;i++){
    cin>>a;
    pque.push(a);
  }
  for(int i=0;i<M;i++){
    a=pque.top(); pque.pop();
    pque.push(a/2);
  }
  a=0;
  for(int i=0;i<N;i++){
    a+=pque.top(); pque.pop();
  }
  cout<<a<<endl;

}




Measured memory_bytes: 1400
#include <stdio.h>
#include <string>
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;

int main(void){
    int a,b;
    cin >> a >> b;
    a+=b;
    string ans = a<=9?to_string(a):"error";
    cout << ans << endl;
    return 0;
}

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

int main() {
  char B;
  cin >> B;

  map<char, char> m;
  m['A'] = 'T';
  m['C'] = 'G';
  m['G'] = 'C';
  m['T'] = 'A';
  cout << m[B] << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>

inline void read(int &T) {
	int x=0;bool f=0;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=!f;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	T=f?-x:x;
}

int x,y;

int main() {
	read(x),read(y);
	for(int i=0;i<=x;++i) {
		int j=x-i;
		if(i*2+j*4==y) {
			puts("Yes");
			return 0;
		}
	}
	puts("No");
	return 0;
}

Measured memory_bytes: 3544
fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim_right().to_owned()
}

fn main() {
    let v: Vec<usize> = read_line().split_whitespace().map(|x| x.parse().unwrap()).collect();
    let (_, k) = (v[0], v[1] - 1);

    let mut chars: Vec<_> = read_line().chars().map(|c| c.to_string()).collect();
    chars[k] = chars[k].to_lowercase();
    
    println!("{}", chars.join(""));
}


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

int main(){
	int n;
	while(1){
		cin >> n;
		if(!n) break;
		int sum = 0;
		vector<int> a(n);
		for(int i = 0; i < n; ++i){
			cin >> a[i]; 
			sum += a[i];
		}
		int ans = 0;
		for(int i = 0; i < n; ++i){
			if(a[i]*n<=sum){
				ans++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3136
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
ll modfac(ll a){
    ll ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
ll modinv(ll a,ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
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 n,w;cin >> n >>w;
    vvl dp(n+1,vl(w+1,0));
    vpl v(n);
    rep(i,n)cin >> v[i].fi >>v[i].se;
    rep(i,w+1)dp[0][i]=0;
    rep(i,n){
        rep(j,w+1){
            if(j<v[i].se)dp[i+1][j]=dp[i][j];
            else {
                dp[i+1][j]=max(dp[i][j-v[i].se]+v[i].fi,dp[i][j]);
                chmax(dp[i+1][j],dp[i+1][j-v[i].se]+v[i].fi);
            }
        }
    }
    cout << dp[n][w] <<endl;
}


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

int main(){
  int w, h, n;   cin >> w >> h >> n;
  int lx=0, rx=w, by=0, ty=h;
  int ans=-1;
  for(int i=0; i<n; i++){
    int x, y, a;  cin >> x >> y >> a;
    if(2<a){
      if(a==3) by = max(y, by);
      else ty = min(y, ty);
    }else{
      if(a==1) lx = max(x, lx);
      else rx = min(x, rx);
    }
    if((rx-lx)<0 || (ty-by)<0) ans = 0;
  }
  if(ans==-1) ans = (rx-lx)*(ty-by);
  cout << ans<< endl;


}


Measured memory_bytes: 256
n = gets.to_i
c = (n-1).times.map{gets.chomp.split(" ").map(&:to_i)}
for i in 0..n-3
  ans = c[i][0]+c[i][1]
  for j in i+1..n-2
    if ans <= c[j][1]
      ans = c[j][0]+c[j][1]
    else
      ans = ((ans+c[j][2]-1)/c[j][2])*c[j][2]+c[j][0]
    end
  end
  puts ans
end
puts c[-1][0]+c[-1][1],0

Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define mod 1000000007

const int sz=4e2+5;
ll inf=1e15;

ll dp[sz][sz],ar[sz],n,pre[sz];

ll f(int st,int en)
{
    if(st==en)
        return 0;
    if(en-st==1)
        return ar[st]+ar[en];
    ll &res=dp[st][en];
    if(res!=-1)
        return res;
    res=inf;
    for(int k=st;k<en;k++)
    {
        res=min(res,pre[k]-pre[st-1]+f(st,k)+pre[en]-pre[k]+f(k+1,en));
    }

    return res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        cin>>n;

        for(int i=1;i<=n;i++)
        {
            cin>>ar[i];
            pre[i]+=ar[i]+pre[i-1];
        }

        memset(dp,-1,sizeof(dp));

        cout<<f(1,n);

        
    }

    return 0;
}

Measured memory_bytes: 4888
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define xx first
#define yy second
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int inf=0x3f3f3f3f;
const LL INF=0x3f3f3f3f3f3f3f3f;
const int N=3e5+10;
const int M=1e6+10;

int main(){
	double n;
	scanf("%lf",&n);
	printf("%.7lf\n",n/3*n/3*n/3);
	return 0;
}

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

int main(){
  int k;
  scanf("%d",&k);
  int a,b;
  scanf("%d%d",&a,&b);

  if(a/k!=b/k || a%k==0){
    printf("OK\n");}
  else{
    printf("NG\n");}
  
  return 0;
}


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

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

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
string s[maxn];
int main()
{
	IOS;
	int n,m;
	cin>>n>>m;
	REP(i,n) cin>>s[i];
	REP(i,n+n)REP(j,m){
		cout<<s[i/2][j];
		if(j==m-1) cout<<'\n';
	}
	return 0;
}


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

using namespace std;

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

  string in, sl, sr;
  cout << 0 << endl << flush;
  cin >> in;
  if (in == "Vacant") return 0;
  sl = in;
  cout << N - 1 << endl << flush;

  cin >> in;
  if (in == "Vacant") return 0;
  sr = in;

  int left = 0, right = N - 1, mid;
  while (1) {
    mid = (left + right) / 2;
    cout << mid << endl << flush;

    cin >> in;
    if (in == "Vacant") break;
    {  // [left, mid]
      if ((mid - left) % 2) {
        if (sl == in) {
          sr = in;
          right = mid;
        }
      } else {
        if (sl != in) {
          sr = in;
          right = mid;
        }
      }
    }

    {  // [mid, r]
      if ((right - mid) % 2) {
        if (sr == in) {
          sl = in;
          left = mid;
        }
      } else {
        if (sr != in) {
          sl = in;
          left = mid;
        }
      }
    }
  }

  return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (int i = (int)a; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265359
#define EPS 1e-12

int main(void)
{
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if(a*b >= c*d) cout << a*b << endl;
  else cout << c*d << endl;
  
  return 0;
}


Measured memory_bytes: 892
#include <iostream>
#include <string>
#include <algorithm>
#define REP(i,n) for(int i = 0; i < (n);i++)
using namespace std;
pair<int, char> cct[28];
int main(){
  string s;
  cin >> s;
  cout << ((s.size() % 2) ^ (s[0] == s.back()) ? "First" : "Second") << endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h> 
#define ll long long
#define M 1000000007
using namespace std;
int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); 
    ll n,m,d,x,count=0;
    cin>>n>>m;int height[n+1]={ 0 };
    vector<int>adj[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>height[i];
    }
    for(int i=1;i<=m;i++)
    {
        cin>>d>>x;
        adj[d].push_back(height[x]);
        adj[x].push_back(height[d]);
    }
    for(int i=1;i<=n;i++)
    {
         if(adj[i].size()==0)
         {
             count++;continue;
         }else if(height[i]>*max_element(adj[i].begin(),adj[i].end()))
         {
             count++;
         }

    }
    cout<<count;

}

Measured memory_bytes: 9188
#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 priority_queue<int> PQ;
#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
#define mo 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;

int N, A, B, C;


ll comb(ll N_, ll C_) {
	const int NUM_ = 400001;
	static ll fact[400002], factr[400002], inv[400002];
	if (fact[0] == 0) {
		inv[1] = fact[0] = factr[0] = 1;
		for (int i = 2; i <= NUM_; ++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
		for (int i = 1; i <= NUM_; ++i) fact[i] = fact[i - 1] * i%mo, factr[i] = factr[i - 1] * inv[i] % mo;
	}
	if (C_<0 || C_>N_) return 0;
	return factr[C_] * fact[N_] % mo*factr[N_ - C_] % mo;
}
ll modpow(ll a, ll n = mo - 2) {
	ll r = 1;
	while (n) r = r * ((n % 2) ? a : 1) % mo, a = a * a%mo, n >>= 1;
	return r;
}

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

	cin >> N >> A >> B >> C;

	int ret = 0;
	int AW = A * modpow(A + B) % mod;
	int BW = B * modpow(A + B) % mod;
	int num=(A+B+C)* modpow(A + B) % mod;

	REP(i, N) {
		ret += comb(N - 1 + i, i)*modpow(AW, N) % mod*modpow(BW, i) % mod*(N + i) % mod;
		ret += comb(N - 1 + i, i)*modpow(BW, N) % mod*modpow(AW, i) % mod*(N + i) % mod;
	}

	cout << ret % mod*num%mod << endl;

	return 0;
}



Measured memory_bytes: 9600
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;
constexpr int kInf = 1e9;

int main() {
  int A, B, C, X, Y; cin >> A >> B >> C >> X >> Y;
  int vmin = kInf;
  for (int Z = 0; Z <= max(X, Y); ++Z) {
    int a = max(0, X - Z);
    int b = max(0, Y - Z);
    vmin = min(vmin, a * A + b * B + 2 * C * Z);
  }
  cout << vmin << endl;
}


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

int grid[11][11];

void solve(string s) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    a--, b--, c--, d--;
    int H = 1, W = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '/') H++;
    }
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '/') break;
        if (s[i] >= '0' && s[i] <= '9') {
            W += s[i] - '0';
        }
        else W++;
    }
    int now_h = 0, now_w = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '/') {
            now_w = 0;
            now_h++;
            continue;
        }
        if (s[i] >= '0' && s[i] <= '9') {
            for (int w = now_w; w < now_w + int(s[i] - '0'); w++) {
                grid[now_h][w] = 0;
            }
            now_w += s[i] - '0';
        }
        else {
            grid[now_h][now_w] = 1;
            now_w++;
        }
    }
    grid[a][b] = 0, grid[c][d] = 1;
    string ans;
    int zeros = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (grid[i][j]) {
                if (zeros) {
                    ans += char('0' + zeros);
                    zeros = 0;
                }
                ans += 'b';
            }
            else zeros++;
        }
        if (zeros) {
            ans += char('0' + zeros);
            zeros = 0;
        }
        if (i != H - 1) ans += '/';
    }
    cout << ans << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    while (true) {
        cin >> S;
        if (S == "#") break;
        solve(S);
    }
    return 0;
}


Measured memory_bytes: 3092
#include <stdio.h>
 
int main(void) {
 
	int input;

	scanf("%d", &input);

	int num = 1;
	
	while(input != 0) {

		printf("Case %d: %d\n", num, input);
		
		num++;
		
		scanf("%d", &input);
		
	}
	return 0;
}

Measured memory_bytes: 1720
a=int(input())
while a!=0:
    b=1000-a
    n=0
    if b>=500:
        n=n+1
        b=b-500
    if b>=100:
        n=n+b//100
        b=b%100
    if b>=50:
        n=n+1
        b=b-50
    if b>=10:
        n=n+b//10
        b=b%10
    if b>=5:
        n=n+1
        b=b-5
    n=n+b
    print(n)
    a=int(input())
    



    






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

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(abs(a-c) <=d || (abs(a-b) <= d && abs(b-c) <= d)) puts("Yes");
    else puts("No");



    return 0;
}


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

typedef long long ll;

int main() {
  int n; cin >> n;
  ll dp[101][21];
  int t[101];
  memset(dp,0,sizeof(dp));
  for ( int i = 1; i <= n; i++ ) cin >> t[i];

  dp[1][t[1]] = 1;

  for ( int i = 2; i < n; i++ ) {
    for ( int j = 0; j <= 20; j++ ) {
      if ( j + t[i] <= 20 ) dp[i][j+t[i]] += dp[i-1][j];
      if ( j - t[i] >= 0 ) dp[i][j-t[i]] += dp[i-1][j];
    }
  }

  cout << dp[n-1][t[n]] << endl;
  return 0;
}

Measured memory_bytes: 1180
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define mp make_pair
#define ff first
#define ss second
#define MAXN  1000005
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,a,q,w,e;
    q=w=e=0;
    cin>>n;
    for(ll i=0;i<n;i++){
        cin>>a;
        if(a%4==0){
            q++;
        }
        else if(a%2==0){
            w++;
        }
        else e++;
    }
    if(q==e-1&&w==0){
        cout<<"Yes";
    }
    else if(q>=e){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }


    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
  {int X, Y, A, B, C; cin >> X >> Y >> A >> B >> C;
  vector<int> ps(A), qs(B), rs(C), as; for (auto xs : {&ps, &qs, &rs}) {for (auto &b: *xs) cin >> b; sort((*xs).rbegin(), (*xs).rend());}
  for (int i = 0; i < X; ++i) as.push_back(ps[i]);
  for (int i = 0; i < Y; ++i) as.push_back(qs[i]);
  for (auto r : rs) as.push_back(r);
  sort(as.rbegin(), as.rend());
  auto ans = 0LL; for (int i = 0; i < X + Y; ++i) ans += as[i];
  cout << ans << endl;}

Measured memory_bytes: 3572
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
counter = Counter(A)
value = sum(A)

q = int(input())
for i in range(q):
    b, c = map(int, input().split())
    value = value + counter[b] * (c - b)
    print(value)
    counter[c] += counter[b]
    counter[b] = 0


Measured memory_bytes: 87828
import sys

input=sys.stdin.readline

def main():
    N,M=map(int,input().split())
    s=input()
    dic={"A":[0 for i in range(N)],"B":[0 for i in range(N)]}
    edge=[[] for i in range(N)]

    for i in range(M):
        a,b=map(int,input().split())
        a-=1;b-=1
        edge[a].append(b)
        edge[b].append(a)
        dic[s[a]][b]+=1
        dic[s[b]][a]+=1

    que=set([])
    check=0
    for i in range(N):
        if dic["A"][i]==0 or dic["B"][i]==0:
            que.add(i)


    while que:
        v=que.pop()
        check+=v+1
        dic["A"][v]=float("inf")
        dic["B"][v]=float("inf")
        for nv in edge[v]:
            dic[s[v]][nv]-=1
            if dic["A"][nv]==0 or dic["B"][nv]==0:
                que.add(nv)

    if check==N*(N+1)//2:
        print("No")
    else:
        print("Yes")

if __name__=="__main__":
    main()

Measured memory_bytes: 94248
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long A,B;
  char s;
  cin >> A >> s >> B;
  if (s == '+'){
    cout << A + B << endl;
  }
  else if (s == '-'){
    cout << A - B << endl;
  }
  else{
    cout << "error" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;

using namespace std;

struct Info{
	int type;
	bool first_check;
};

int main(){

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

	int* table = new int[N];
	Info* info = (Info*)malloc(sizeof(Info)*(N));

	for(int i = 0; i< N; i++){
		scanf("%d",&table[i]);
		info[i].type = 0;
		info[i].first_check = false;
	}

	for(int i = 0; i < N; i++){
		if(info[i].type == 0){
			info[i].first_check = true;
			current = (i + table[i])%N;
			while(info[current].first_check == false && info[current].type == 0){
				info[current].first_check = true;
				current = (current + table[current])%N;
			}
			if(current == i){
				info[i].type = 1;
				current = (i + table[i])%N;
				while(current != i){
					info[current].type = 1;
					current = (current + table[current])%N;
				}
			}else{
				if(info[current].type != 0){
					 info[i].type = -1;
					current = (i + table[i])%N;
					while(info[current].type == 0){
						info[current].type = -1;
						current = (current + table[current])%N;
					}
				}else{ //current.type == 0
					info[current].type = 1;
					base = current;
					current = (current + table[current])%N;
					while(current != base){
						info[current].type = 1;
						current = (current + table[current])%N;
					}

					info[i].type = -1;
					current = (i + table[i])%N;
					while(info[current].type == 0){
						info[current].type = -1;
						current = (current + table[current])%N;
					}
				}
			}
		}
	}

	int count = 0;
	for(int i = 0; i < N; i++){
		if(info[i].type == 1)count++;
	}

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

    return 0;
}

Measured memory_bytes: 3844
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    int n, m; cin >> n >> m;
    int s[5]; INITA(s, 0, 4, -1);
    REP(i, m) {
        int tmp_s, tmp_c; cin >> tmp_s >> tmp_c;
        if (s[tmp_s] == -1) {
            s[tmp_s] = tmp_c;
        } else if (s[tmp_s] != tmp_c) {
            cout << -1 << endl;
            return 0;
        }
    }
    int beg, end;
    if (n == 1) { beg = 0; end = 9; }
    else if (n == 2) { beg = 10; end = 99; }
    else { beg = 100; end = 999; }

    FOR(i, beg, end) {
        string st = to_string(i);
        bool all = true;
        FOR(j, 1, n) {
            if ((s[j] != -1) && (s[j] != st[j-1] - '0')) {
                all = false;
            }
        }
        if (all) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(begin, end) for (i=begin;i<end;i++)
#define repj(begin, end) for (j=begin;j<end;j++)
#define init(arr, end, val) for (i=0;i<end;i++) arr[i] = val;
#define printint(i0, i1) printf("%d %d\n", i0, i1)

using namespace std;
typedef long long int ll;
const int inf = 1000000000;
const int mod = 1000000007;
const int nil = -1;
ll i, n, m;
ll x, k, d, ans;

int main() {
    scanf(" %lld %lld %lld", &x, &k, &d);
    if (x == 0) {
        if (k%2 == 0) ans = 0;
        else ans = d;
    } else  {
        x = abs(x);
        i = floor(x / d);
        if (x /d >= k) ans = abs(x - k * d);
        else {
            if ((k-i)%2 == 0) ans = abs(x - i*d);
            else ans = abs(x - (i+1)*d);
        }
    } 
    printf("%lld\n", ans);
}

Measured memory_bytes: 3812
#include <bits/stdc++.h>
typedef long long ll;
#define  rep(i,a,b)for(long long i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
const ll INF=100000000000000LL;
const ll r197=1000000007;
typedef pair<ll,ll>P;
typedef pair<int,P>Pa;
bool Inframe(int a,int b,int c,int d,int h,int w){
	if(a+b>=0&&a+b<h&&c+d>=0&&c+d<w)return true;
	return false;
}
vector<P> v[100001];
int n,m;
ll ans=1;
ll C[100005]={-1};
string s;
multiset<ll> lset,rset;
ll a[100005];
ll b[100005]={};

int main() {
	cin>>n>>m;
	ll l,r,c;
	rep(i,0,m){
		cin>>l>>r>>c;
		v[r-1].push_back(P(l-1,c));
	}
	rep(i,0,n+1)C[i]=INF;
	C[0]=0;
	rep(i,1,n){
		ll res=INF;
		rep(j,0,v[i].size()){
			res=min(res,C[v[i][j].first]+v[i][j].second);
		}
		C[i]=res;
		for(int j=i-1;j>=0;--j){
			if(C[j]<=res)break;
			C[j]=res;
		}
	}
	if(C[n-1]==INF)cout<<-1<<endl;
	else cout<<C[n-1]<<endl;
	return 0;
}


Measured memory_bytes: 6784
//31
#include<iostream>
#include<vector>

using namespace std;

int main(){
  bool cmp[100000]={};
  vector<int> prm;
  for(int i=2;i<100000;i++){
    if(!cmp[i]){
      prm.push_back(i);
      for(int j=2;j*i<100000;j++){
	cmp[i*j]=true;
      }
    }
  }
  for(int m,a,b;cin>>m>>a>>b,m|a|b;){
    int ca=0,cb=0;
    for(int i=0;i<prm.size();i++){
      for(int j=i;j<prm.size();j++){
	long long ar=(long long)prm[i]*prm[j];
	if(ar>m)break;
	if(ca*cb<=ar&&prm[j]*a<=prm[i]*b){
	  ca=prm[i];
	  cb=prm[j];
	}
      }
    }
    cout<<ca<<' '<<cb<<endl;
  }
  return 0;
}
  

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

int main()
{
    int n, d;
    unordered_set<int> m;

    cin >> n;

    for (int i = 0; i < n; ++i)
    {
        cin >> d;
        m.insert(d);
    }

    cout << m.size() << endl;
}

Measured memory_bytes: 256
/**
 * @jakestrj
 */

#pragma warning(disable:4996)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include "bits/stdc++.h"
using namespace std;
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define rep(i, j, k) for(int i=(j);i<(k);++i)
#define repi(i, j, k) for(int i=(j);i<=(k);++i)
#define per(i, j, k) for(int i=(j);i>(k);--i)
#define peri(i, j, k) for(int i=(j);i>=(k);--i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).begin(),(x).end(), greater<int>()
#define mem(a, b) memset(a, (b), sizeof(a))
#define mem2(a, b) memset(a, (b), sizeof(a[0][0])*len(a)*len(a[0]))
#define sz(x) ((int)(x).size())
#define len(x) (int)(sizeof(x)/sizeof(x[0]))
#define endl "\n"
//#define INF 1e18
#define EPS 1e-9
#define PI 2*acos(0)
#define MOD 1000000007
typedef long long ll;
typedef long double ld;
typedef tuple<int, int, int> trio;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef map<int,int> mpii;
typedef set<int> si;

const int INF = 1e9+10;
const int MN = 1e5+10;
int dp[MN];
struct B {
	void solve(std::istream& cin, std::ostream& cout) {
		fill(dp, dp+MN, INF);
		int n, k; cin >> n >> k;
		vi h(n);
		rep(i, 0, n) cin >> h[i];
		dp[0]=0; //dp(stone 0 to stone 0)
		rep(i, 0, n){
			for(int j=i+1; j<n && (j-i)<=k; ++j){
				if(j<n){
					dp[j] = min(dp[j], dp[i]+abs(h[j]-h[i]));
				}
			}
		}
		cout << dp[n-1] << endl;
	}
};


int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	B solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

int main() {
    int N,M; cin >> N >> M; 
    if(N>=M) {cout << 0 << endl;}
    else{
    int point[M+10]; rep(i,M) cin >> point[i];
    sort(point,point+M);
    int dis[M+10]; rep(i,M-1) dis[i] = point[M-i-1]-point[M-i-2];
    sort(dis,dis+M-1,greater<int>());
    if(N==1) cout << point[M-1]-point[0] << endl;
    else{
    int sum=0;    
    rep(i,N-1){
        sum += dis[i];
    } 
    cout << point[M-1]-point[0]-sum << endl;
    }
    }
    
}

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

int main() {
  int A, B, C, D, R, L;
  cin >> A >> B >> C >> D;
  L = A + B;
  R = C + D;
  
  if (R > L){
   cout << "Right" << endl;
  }
  else if (R == L){
   cout << "Balanced" << endl;
  }
  else {
   cout << "Left" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
using namespace std;
long long n,a;
map <long long,int> mp;
int main()
{
	cin>>n;
	mp[0]++;
	long long sum=0,ans=0;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		sum+=a;
		ans+=mp[sum];
		mp[sum]++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 12800
//package com.company;
import java.util.Scanner;
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static java.lang.Math.*;

public class Main {

    static class FastScanner {
        StringTokenizer tok = new StringTokenizer("");
        BufferedReader in;

        FastScanner()  {
            in = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() throws IOException {
            while (!tok.hasMoreElements())
                tok = new StringTokenizer(in.readLine());
            return tok.nextToken();
        }

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


    }

    public static void main(String[] args) throws IOException {

        FastScanner input = new FastScanner();
        Scanner in = new Scanner(System.in);

           int n = input.nextInt();
           int a[] = new int[n];
           long ans = 0 ;
           for( int i = 0 ; i < n ; i++ ){
               a[i] = input.nextInt();
               if( i > 0 ){
                   if( a[i] < a[i-1]){
                       ans += Math.abs(a[i]-a[i-1]);
                       a[i] = a[i-1];
                   }
               }
           }
           System.out.println(ans);




    }
}

Measured memory_bytes: 55956
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int A, B, C;
  cin >> A >> B >> C;
  int ctr = 0;
  rep(i, 1000000) {
    if (A%2!=0||B%2!=0||C%2!=0) break;
    int a = (B+C)/2,
        b = (A+C)/2,
        c = (A+B)/2;
    A = a, B = b, C = c;
    ctr++;
  }
  if (ctr==1000000)ctr=-1;
  cout << ctr << "\n";
  return 0;
}


Measured memory_bytes: 256
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors

a=make_divisors(n=int(input()))
if len(a)%2==0:
    ans=([sum(a[k:k+2]) for k in range(0,len(a),2)])
    print(min(ans)-2)
else:
    print(a[-1]*2-2)

Measured memory_bytes: 3296
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <unordered_set>
#include <queue>
#include <boost/math/constants/constants.hpp>
#include <boost/math/common_factor_rt.hpp>
 
using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define FOR(i, n, m) for(int i=n; i<m; ++i)
 
int main() {
  ll K;
  cin >> K;

  ll sum = 0;
  
  FOR(i, 1, K+1){
    FOR(j, 1, K+1){
      FOR(k, 1, K+1){
        sum += gcd(gcd(i, j), k);
      }
    }
  }
  
  cout << sum << endl;
  
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <algorithm>

int W, H, N, X[1123], Y[1123];
int ans = 0;

int dist(int i) {
	if (X[i + 1] == X[i] && Y[i + 1] == Y[i]) { return 0; }
	if (X[i + 1] - X[i] > 0) {
		if (Y[i + 1] - Y[i] > 0) {	// ?????±
			return std::max(abs(X[i + 1] - X[i]), abs(Y[i + 1] - Y[i]));
		}
		if (Y[i + 1] - Y[i] < 0) {	// ?????±
			return abs(X[i + 1] - X[i]) + abs(Y[i + 1] - Y[i]);
		}
		else {	// ??±
			return X[i + 1] - X[i];
		}
	}
	if (X[i + 1] - X[i] < 0) {
		if (Y[i + 1] - Y[i] > 0) {	// ????\?
			return abs(X[i + 1] - X[i]) + abs(Y[i + 1] - Y[i]);
		}
		if (Y[i + 1] - Y[i] < 0) {	// ????\?
			return std::max(abs(X[i + 1] - X[i]), abs(Y[i + 1] - Y[i]));
		}
		else {	// ?\?
			return abs(X[i + 1] - X[i]);
		}
	}
	else {
		if (Y[i + 1] - Y[i] > 0) {	// ???
			return Y[i + 1] - Y[i];
		}
		if (Y[i + 1] - Y[i] < 0) {	// ???
			return abs(Y[i + 1] - Y[i]);
		}
	}
}

int main(void) {
	scanf("%d%d%d", &W, &H, &N);
	for (int i = 0; i < N; ++i) { scanf("%d%d", &X[i], &Y[i]); }

	for (int i = 0; i < N - 1; ++i) {
		ans += dist(i);
	}

	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 2736
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

int main()
{
	string S, T;
	cin >> S >> T;
	int A, B;
	cin >> A >> B;
	string U;
	cin >> U;


	if (S == U) {
		A -= 1;
	}
	else if (T == U) {
		B -= 1;
	}

	cout << A << " " << B << endl;


}


Measured memory_bytes: 3556
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#define inf 10e8
using namespace std;



int main(){
    long n,m;
    cin >> n >> m;
    priority_queue<double> que;
    for (long i=0;i<n;i++){
        double d;
        cin >> d;
        que.push(d);
    }
   
    for(long i=0;i<m;i++){
        double c;
        c=que.top();
        que.pop();
        c=c/2;
        que.push(c);
    }
    
    long ans=0;
    while(!que.empty()){
        long e;
        e=que.top()/1;
        que.pop();
        ans+=e;
    }
    cout << ans << endl;
}



Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF (1<<29)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
#define fr first
#define sc second
const int dx[] = {-1,0,0,1},dy[] = {0,1,-1,0};

typedef long long int ll;

using namespace std;

vector<int> split(string s){
    int x = -1;
    vector<int> ret;
    s += ",";
    REP(i,s.size()){
	if(s[i] == ','){
	    ret.PB(stoi(s.substr(x+1,i-x-1)));
	    x = i;
	}
    }
    return ret;
}

int main(){
    vector< vector<int> > m;
    int count = 1;
    int dp[100][100];
    memset(dp,0,sizeof(dp));
    while(true){
	string s;
	cin >> s;
	if(cin.eof()){
	    break;
	}
	m.PB(split(s));
	if(s.size() == 1) count--;
	if(count == -1) break;
    }
    vector< vector<int> > h;
    vector< vector<int> > t;

    dp[0][0] = m[0][0];
    REP(i,m.size()/2){
	REP(j,m[i].size()){
	    dp[i+1][j] = max(dp[i+1][j] , dp[i][j] + m[i+1][j]);
	    dp[i+1][j+1] = max(dp[i+1][j+1] , dp[i][j] + m[i+1][j+1]);
	}
    }
    FOR(i,m.size()/2,m.size()-1){
	REP(j,m[i+1].size()){
	    dp[i+1][j] = max(dp[i+1][j] , dp[i][j] + m[i+1][j]);
	    dp[i+1][j] = max(dp[i+1][j] , dp[i][j+1] + m[i+1][j]);
	}
    }
    cout << dp[m.size()-1][0] << endl;

    return 0;
}

Measured memory_bytes: 3048
s = gets.chomp
q = gets.to_i
head = Array.new(200000, nil)
n_head = 0
tail = Array.new(200000, nil)
n_tail = 0
rev = 0
q.times do
  t, f, c = gets.chomp.split
  if t == "1"
    rev = 1 - rev
  else
    if f.to_i - rev == 1
      head[n_head] = c
      n_head += 1
    else
      tail[n_tail] = c
      n_tail += 1
    end
  end
end
head = head.slice(0, n_head).join("")
tail = tail.slice(0, n_tail).join("")
if rev == 0
  s = head.reverse + s + tail
else
  s = (s + tail).reverse + head
end
puts s


Measured memory_bytes: 18940
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define loops(i, s, n) for (int i = s; i < n; i++)
#define loop(i, n) for (int i = 0; i < n; i++)
#define eps 1e-9
#define loopitr(mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define init(arr, n, val)       \
    for (int i = 0; i < n; i++) \
        arr[i] = val;
#define even_set 0xAAAAAAAA ... 1010101010
#define odd_set 0x55555555 ... 01010101
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define vall(v) v.begin(), v.end()
#define mkp make_pair
#define ret return
#define cont continue
#define nl endl
#define ff first
#define ss second
#define cnt_bits __builtin_popcount
#define init(arr, n, val)       \
    for (int i = 0; i < n; i++) \
        arr[i] = val;
const int mod = 1000000007;

double dp[3000][3000];
int n;

int main()
{

    fastio;
    cin >> n;
    double arr[n];
    loop(i, n)
    {
        cin >> arr[i];
    }

    for(int i = 0; i<= n ; i++)
      for(int j = 0; j<=n; j++)
        dp[i][j] = 0;

    for(int i = n/2 + 1; i<=n;i++){
        dp[i][n-i] = 1;
    }

    for(int h = n; h>=0; h--){
        for(int t= n; t>=0; t--){
            if(h+t >= n)  cont;

            int i = h + t;
            if(dp[h+1][t] != 0)
              dp[h][t] = dp[h+1][t]*(arr[i]);

            if(dp[h][t+1] != 0)  
              dp[h][t] += dp[h][t+1]*(1-arr[i]);
        }
    }

    cout<<fixed<<setprecision(10)<<dp[0][0]<<endl;
}

Measured memory_bytes: 70656
#include <cassert>
#include <cctype>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <deque>
#include <functional>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <fstream>
#include <iostream>
#include <sstream>
#include <iomanip>

using namespace std;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef long long ll;
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define NEXTP(c) next_permutation(ALL(c))
#define SUM(c) accumulate(ALL(c),0)
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define ANS(x) cout << (x) << endl;
#define DUMP(x) cerr << #x << " = " << (x) << endl;
#define INF 1000000000 // 10^9
const double EPS = 1e-10;

int main(){
    string s;
    int K;
    cin >> s >> K;
    string ret ="";

    REP(i, s.length()-1) {
        if (s[i] == 'a') {
            ret += 'a';
            continue;
        }

        int diff = 26 - (s[i] - 'a');
        if (diff <= K) {
            K -= diff;
            ret += 'a';
        } else {
            ret += s[i];
        }
    }

    ret += 'a' + (s[s.length()-1] - 'a' + K%26) % 26;

    cout << ret <<endl;

    return 0;
}

Measured memory_bytes: 640