akhauriyash/Code-Regression huggingface dataset:
use std::vec::Vec;
use std::cmp;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
  let n: usize = read();
  let mut v: Vec<(String, usize, usize)> = Vec::new();

  for i in 0..n {
    let s: Vec<String> = read_vec();
    v.push((s[0].clone(), s[1].clone().parse().ok().unwrap(), i));
  }

  v.sort_by(|a, b| a.0.cmp(&b.0));

  let mut indx = 0;
  while indx < n {
    let mut i = indx;
    let mut t: Vec<(String, usize, usize)> = Vec::new();
    while  i < n && v[i].0 == v[indx].0 {
      t.push(v[i].clone());
      i += 1;
    }
    indx = i;
    t.sort_by(|a, b| b.1.cmp(&a.1));
    for elem in t {
      println!("{}", elem.2 + 1);
    }
  }



}


Measured memory_bytes: 4352
//AWTF2019-D
#include<stdio.h>
#include<stdbool.h>
#define prime 10000000019

void llswap(long long *a,long long *b){long long c;c=(*a);(*a)=(*b);(*b)=c;}
long long llsankaku(long long x){return ((1+x)*x)/2;}

long long calcul(long long p,long long q,long long z,long long *r,long long *b){
  long long f=0,cnt=0,w,i;
  (*r)=0;(*b)=0;
  if(p<q){f=1;llswap(&p,&q);}
  i=0;
  while(z>=0){
    w=z/q;
    cnt+=(w+1);
    (*r)+=i*(w+1);
    (*b)+=llsankaku(w);
    z-=p;
    i++;
  }
  if(f){llswap(r,b);}
  return cnt;
}

void calc(long long p,long long q,long long k,long long *r,long long *b){
  long long st,fi,te,c;
  st=0;fi=prime*2000;
  while(st<=fi){
    te=(st+fi)/2;
    c=calcul(p,q,te,r,b);
    if(c==k){break;}
    if(c<k){st=te+1;}
    if(c>k){fi=te-1;}
  }
}

typedef struct{
  long long xz;
  long long yz;
}point;

point vector_minus(point a,point b){
  point r;
  r.xz=a.xz-b.xz;
  r.yz=a.yz-b.yz;
  return r;
}

//gaiseki
long long crossproduct(point a,point b){
  return a.xz*b.yz-a.yz*b.xz;
}

bool ispossible(long long r,long long b,long long k){
  long long st,fi,te,zr,zb;
  long long fr,fb,sr,sb;
  st=1;fi=prime-1;
  while(st<=fi){
    te=(st+fi)/2;
    calc(te,prime-te,k,&zr,&zb);
    if(zr<=r && zb<=b){return true;}
    if(zr>r && zb>b){return false;}
    if(zr>r){st=te+1;sr=zr;sb=zb;}
    else{fi=te-1;fr=zr;fb=zb;}
  }
  //Is (r,b) on above the line{(fr,fb),(sr,sb)}(fr<sr)?
  point tg,l1,l2;
  tg.xz=r;tg.yz=b;
  l1.xz=fr;l1.yz=fb;
  l2.xz=sr;l2.yz=sb;
  if(crossproduct(vector_minus(l2,l1),vector_minus(tg,l1))>=0){return true;}
  return false;
}

long long solve(long long r,long long b){
  long long st=0,fi=2222222,te;
  while(st<=fi){
    te=(st+fi)/2;
    if(ispossible(r,b,te)){st=te+1;}
    else{fi=te-1;}
  }
  return fi;
}

int main(){
  long long r,b;
  scanf("%lld%lld",&r,&b);
  printf("%lld\n",solve(r,b)-1);//-1 : empty box
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
string s,a,b;
int n,m;
main(){
    cin>>s;
    a+=s[0];
    a+=s[1];
    b+=s[2];
    b+=s[3];
    n=stoi(a);
    m=stoi(b);
    if(m==0){
        if(n<=12 && n>=1)
            cout<<"MMYY";
        else cout<<"NA";
        return 0;
    }
    if(n==0){
        if(m<=12 && m>=1)
            cout<<"YYMM";
        else cout<<"NA";
        return 0;
    }
    if(n>=1 && n<=12 && m<=12 && m>=1){
        cout<<"AMBIGUOUS";
        return 0;
    }
    if(n>12 && m<=12 && m>=1){
        cout<<"YYMM";
        return 0;
    }
    if(n<=12 && n>=1 && m>12){
        cout<<"MMYY";
        return 0;
    }
    if(n>12 && m>12){
        cout<<"NA";
        return 0;
    }
    return 0;
}


Measured memory_bytes: 256
A,B,Q = gets.split.map &:to_i
S = (0...A).map{ gets.to_i }
T = (0...B).map{ gets.to_i }

def rs(x)
  (0...A).bsearch{ |i| x <= S[i] }
end

def ls(x)
  i = rs(x)
  i ? (i>0 ? i-1 : nil) : A-1
end

def rt(x)
  (0...B).bsearch{ |i| x <= T[i] }
end

def lt(x)
  i = rt(x)
  i ? (i>0 ? i-1 : nil) : B-1
end

(0...Q).each{
  x = gets.to_i
  vs = []
  rsi = rs(x)
  lsi = ls(x)
  rti = rt(x)
  lti = lt(x)
  vs << S[rsi] + x  - 2*T[lti] if rsi && lti
  vs << 2*S[rsi] - x  - T[lti] if rsi && lti
  vs << T[rti] + x  - 2*S[lsi] if rti && lsi
  vs << 2*T[rti] - x  - S[lsi] if rti && lsi
  if rsi
    if rrti = rt(S[rsi])
      vs << T[rrti] - x
    end
  end
  if rti
    if rrsi = rs(T[rti])
      vs << S[rrsi] - x
    end
  end
  if lsi
    if llti = lt(S[lsi])
      vs << x - T[llti]
    end
  end
  if lti
    if llsi = ls(T[lti])
      vs << x - S[llsi]
    end
  end
  p vs.min
}


Measured memory_bytes: 5044
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n, x;
    cin >> n >> x;
    int ans = 1e9;
    REP(i,n){
        int p, q;
        cin >> p >> q;
        if (q <= x) ans = min(ans, p);
    }
    if (ans == 1e9){
        cout << "TLE" << endl;
    }else{
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};

int main(void){
    string S;
    cin >> S;
    int rev=0;
    deque<char> ans;
    rep(i,S.size()) ans.push_back(S[i]);
    int Q;
    cin >> Q;
    rep(i,Q){
        int T;
        cin >> T;
        if(T==1) rev++;
        else{
            int F;
            char C;
            cin >> F >> C;
            if((F==1)^(rev%2==1)) ans.push_front(C);
            else ans.push_back(C);
        }
    }
    if(rev%2==0){
        while(!ans.empty()){
            cout << *ans.begin();
            ans.pop_front();
        }
    }
    else{
        while(!ans.empty()){
            cout << *ans.rbegin();
            ans.pop_back();
        }
    }
    cout << endl;
}

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    string S; cin >> S;
    deque<char> dq;
    rep(i, S.length()) dq.push_back(S[i]);
    int Q; cin >> Q;
    bool st = false; //false -> 逆順にした回数が偶数回, true -> 奇数回
    rep(i, Q){
        int T; cin >> T;
        if(T == 1) st = !st;
        else{
            int f; char c; cin >> f >> c;
            if(st){
                if(f == 1) dq.push_back(c);
                else dq.push_front(c);
            }
            else{
                if(f == 1) dq.push_front(c);
                else dq.push_back(c);
            }
        }
    }
    if(st){
        while(!dq.empty()){
            cout << dq.back();
            dq.pop_back();
        }
    }
    else{
        while(!dq.empty()){
            cout << dq.front();
            dq.pop_front();
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 896
/*
    And I know I may end up failing too
*/




#include<bits/stdc++.h>
using namespace std;

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

#define dbg          cout<<"Freak"<<endl;
#define dbgg(i)      cout<<i<<endl;
#define N            1e9+7
#define pb           push_back
#define pf           push_front
#define pi           acos(-1)
#define all(x)       x.begin(),x.end()
#define fast         ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define INF          0x3f3f3f3f

struct hash_pair
{
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1> {}(p.first);
        auto hash2 = hash<T2> {}(p.second);
        return hash1 ^ hash2;
    }
};



ll t;
ll dp[100005][103];
pll p[105];



int main()
{
    fast;
    ll a,b,c,d,e,f,g,i,j;
    ll n,k;
    cin>>n>>a;
    for(i=1;i<=n;i++)
    {
        cin>>b>>c;
        p[i]={b,c};
    }
    ll ans=0;
    for(i=1;i<=a;i++)
    {
        for(j=1;j<=n;j++)
        {
            if(j==1&&i>=p[j].first)
            {
                dp[i][j]=p[j].second;
            }
            else if(j>1&&i>=p[j].first)
            {
                dp[i][j]=max(dp[i][j-1],p[j].second+dp[i-p[j].first][j-1]);
            }
            else if(j>1)
            {
                dp[i][j]=max(dp[i][j],dp[i][j-1]);
            }
            ans=max(ans,dp[i][j]);
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 80768
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair

using namespace std;
const int N=1e5+5;
int n,a,b;

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n>>a>>b;
    int t=n/(a+b);
    n-=(a+b)*t;
    cout<<t*a+min(n,a);
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    char a[6];
    gets(a);
    int i;
    if(a[2]==a[3]&&a[4]==a[5])
    {
        printf("Yes\n");
    }
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int f[100001];
int Find(int x){
	if(f[x]!=x)f[x]=Find(f[x]);
	return f[x];
}
void Union(int x,int y){
	f[Find(x)]=Find(y);
}
int main(){
	int n,m;
	cin>>n>>m;
	int p[n+1];
	for(int i=1;i<=n;i++){
		cin>>p[i];
		f[i]=i;
	}
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		Union(x,y);
	}
	int ans=0;
	for(int i=1;i<=n;i++)
		if(Find(p[i])==Find(i))ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
def main():
    l= [int(i) for i in input().split()]
    k = 0
    while(l.count(max(l)) < 3):
        l.sort()
        if max(l) - min(l) > 1:
            l[0] += 2
        else:
            l[1] += 1
            l[0] += 1
        k += 1
    print(k)
        

main()

Measured memory_bytes: 2940
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vll a(n);
    int t=0;
    int f=0;
    REP(i,n){
        cin >> a[i];
        if(a[i]%4==0){
            f++;
        }else if(a[i]%2==0){
            t++;
        }
    }
    if(t>0){
        if(f>=((n-t)+1)/2){
            puts("Yes");
        }else{
            puts("No");
        }
    }else{
        if(f>=(n-t)/2){
            puts("Yes");
        }else{
            puts("No");
        }
    }


    return 0;
}

Measured memory_bytes: 3988
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;

int main(void){
    int ans=0;
   char s[100001];
   cin>>s;
   int l=strlen(s);
   int i=0,t=l-1;
   for(;i<t;i++,t--){
       while(s[i]=='x'&&i<t){
           i++;
       }
       while(s[t]=='x'&&i<t){
           t--;
       }
       if(s[i]!=s[t]){
           cout<<-1<<endl;
           return 0;
       }
   }
   for(int j=0,k=l-1;j<k;){
       if(s[j]==s[k]){
           j++;
           k--;
           
       }else if(s[j]=='x'){
           j++;
           ans++;
       }else{
           k--;
           ans++;
       }
   }
  cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

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

int main() {
    int N;
    cin >> N;
    vector<int> v;
    REP(i,2 * N) {
        int l;
        cin >> l;
        v.push_back(l);
    }
    
    sort(v.begin(), v.end(), greater<int>());
    
    int ans = 0;
    for(int i = 0; i < 2 * N; i+=2) {
        ans += min(v[i], v[i+1]);
    }
    
    cout << ans << endl;
    return 0;
}

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

key=sum(a[0:N-1])+b[-1]
for i in range(0,N):
  Key=sum(a[0:i+1])+sum(b[i:N])
  key=max(key,Key)
print(key)

Measured memory_bytes: 9132
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(void){
  vector<long long int> input(3);
  cin >> input[0] >> input[1] >> input[2];
  sort(input.begin(), input.end());

  if(input[2] % 2 == 0){ cout << 0 << endl; }
  else{ cout << input[0] * input[1] << endl; } 

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int n; std::cin >> n;
    std::string s; std::cin >> s;

    auto func = [&](int len) {
        auto comp = [&](int i, int j) {
            return s.substr(i, len) < s.substr(j, len);
        };
        std::set<int, decltype(comp)> st(comp);
        for (int i = n - 2*len; i >= 0; i--) {
            st.insert(i + len);
            auto iter = st.lower_bound(i);
            if (iter != st.end() &&
                    s.substr(*iter, len) == s.substr(i, len)) {
                return true;
            }
        }
        return false;
    };

    int lo = 0, hi = n + 1;
    while (hi - lo > 1) {
        int mid = lo + (hi - lo) / 2;
        if (func(mid)) lo = mid;
        else hi = mid;
    }
    std::cout << lo << std::endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1012345678;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
const int N = 1e6 + 5;

int main(){
  string s;
  cin >> s;
  rep(i,3){
    if(s[i] == s[i+1]){
      cout << "Bad" << endl;
      return 0;
    } 
  }
  cout << "Good" << endl;
  return 0;
}


Measured memory_bytes: 256
function main(input) {
    const args = input.split(' ');
    const A = parseInt(args[0], 10),
          B = parseInt(args[1], 10);
    const left = A - B * 2;
    if (left < 0) {
      console.log(0);
    } else {
      console.log(left);
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

using namespace std;

#define endl '\n'

typedef long long ll;

const int maxn = 3000 + 3;

int n;
ll dp[maxn][maxn], a[maxn], sum[maxn];

ll solve(int lo, int hi){
	if(hi == lo)
		return a[lo];
	if(dp[lo][hi] != -1)
		return dp[lo][hi];
	
	ll s1 = a[lo] + (sum[hi] - sum[lo]) - solve(lo + 1, hi);
	ll s2 = a[hi] + (sum[hi - 1] - sum[lo - 1]) - solve(lo, hi - 1);
	
	return dp[lo][hi] = max(s1, s2);
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> a[i], sum[i] = sum[i - 1] + a[i];
	
	memset(dp, -1, sizeof(dp));
	ll x = solve(1, n);
	ll y = sum[n] - x;
	
	cout << x - y << endl;

	return 0;
}

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

int main() {
    int n;
    long double ddd,dd,d=0;
	cin>>n;
	vector<int> x(n),y(n);
    rep(i,n)cin>>x[i]>>y[i];
    for(int i=0; i<n-1; i++){
        for(int k=i+1;k<n;k++){
            ddd=(x[i]-x[k])*(x[i]-x[k])+(y[i]-y[k])*(y[i]-y[k]);
            dd=sqrt(ddd);
            d+=dd;
        }
    }
    d*=2; d/=n;
	cout<<setprecision(10)<<d;
	return 0;
}


Measured memory_bytes: 256
while True:
    n = int(input())
    if n == 0:
        break
    rows = [list(map(int, input().split())) for _ in range(n)]
    for row in rows:
        print("".join(map("{0:>5}".format, row)), end="")
        print("{:>5}".format(sum(row)))
    columns = list(zip(*rows))
    print("".join(map("{0:>5}".format, list(sum(column) for column in columns))), end="")
    print("{0:>5}".format(sum(sum(row) for row in rows)))

Measured memory_bytes: 7612
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
using namespace std;
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007


int main(int argc, char const *argv[]) {
  int n,k,d[20]={};
  std::cin >> n >> k;
  for(int i=0; i<k; i++){
    int m; std::cin >> m;
    d[m]=-1;
  }

  for(int i=n; i<100000; i++){
    bool f=true;
    int m=i;
    while(m>0){
      if(d[m%10]==-1){
        f=false;
        break;
      }
      m/=10;
    }
    if(f){
      std::cout << i << '\n';
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;


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

    int n;
    cin >> n;
    long long sum1, sum2, a, ans1, ans2;
    sum1 = sum2 = a = ans1 = ans2 = 0;
    for (int i = 0; i < n; ++i)
    {
        cin >> a;
        sum1 += a;
        sum2 += a;
        if (i&1)
        { 
            if (sum1 <= 0) ans1 += 1-sum1, sum1 = 1;
            if (sum2 >= 0) ans2 += sum2+1, sum2 = -1;
        } else {
            if (sum1 >= 0) ans1+=sum1+1,sum1=-1;
            if (sum2 <= 0) ans2+=1-sum2,sum2=1;
        }
    }
    cout << min(ans1, ans2) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string>
#include<iostream>
#include<math.h>
#include<vector>
#include<set>
using namespace std;

int main(void) {
	string a[3];
	int i, j;
	for (i = 0;i < 3;i++) {
		cin >> a[i];
	}
	cout << a[0][0] << a[1][1] << a[2][2] << endl;
        return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define reep(i,n) for(ll i = n; i >-1; i--)
#define deb(variable) cout<<#variable<<"="<<variable<<endl
#define MMOD(i) ((i%MOD)+MOD)%MOD;
#define vec(i,j) vector<vector<ll>>(i,vector<ll>(j,0))
const ll INF=99999999999999999;
const ll MOD=1000000007;
const ll MAX_N=500010;
ll a,b,c,d,e,x,y,z,k,m,n,l,q,ans=0;
vl v1,v2,v[200100],kaijo,gysku;
string s;
ll solve(void){
    rep(i,1<<n){
        v2=vl(m,0);
        rep(j,n){
            if((i&(1<<j))>0){
                rep(k,v[j].size()){
                    v2[v[j][k]]++;
                }
            }
        }
 
        rep(j,m){
        	//cout<<i<<" "<<j<<" "<<v1[j]<<" "<<v2[j]<<endl;
            if(v2[j]%2!=v1[j])goto next;
        }
        //cout<<i<<endl;
        ans++;
        next:
        d=0;
    }
 
    return ans;
}
int main(){
    cin>>n>>m;
    rep(i,m){
        cin>>a;
        rep(j,a){
            cin>>b;
            v[b-1].push_back(i);
        }
    }
 
    rep(i,m){
        cin>>a;
        v1.push_back(a);
    }
 
 
 
    cout<<solve()<<endl;
}

Measured memory_bytes: 4992
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int r = sc.nextInt(), D = sc.nextInt(), x2000 = sc.nextInt();

        for (int i=0; i<10; i++) {
            x2000 = r * x2000 - D;
            System.out.println(x2000);
        }
    }
}

Measured memory_bytes: 21972
import math
import itertools
import statistics

N = int(input())

# num = math.factorial(N)

cities_cord = []

for i in range(N):
    a = list(map(int,input().split()))
    cities_cord.append(a)
    
cities_no = list(range(N))

distance = []

for v in itertools.permutations(cities_no):
    all_dist = 0
    for i in range(len(v)-1):
        dist = math.sqrt((cities_cord[v[i]][0]-cities_cord[v[i+1]][0])**2 +
                         (cities_cord[v[i]][1]-cities_cord[v[i+1]][1])**2)
        all_dist += dist
        
    distance.append(all_dist)
    

print(statistics.mean(distance))
        

Measured memory_bytes: 6808
#include<bits/stdc++.h>   
#define ll long long
#define sz size
#define fr first
#define sc second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define int long long
using namespace std;

double n,t,a,h[1005];

signed main(){
    ios_base::sync_with_stdio(0);  cin.tie(); cout.tie();
    cin >> n >> t >> a;
    for(int i=1;i<=n;i++) cin >> h[i];
    double ans=1e19;
    double ans1=1e19;
    for(int i=1;i<=n;i++){
        double x;
        x=(t-0.006*h[i]);
        if(abs(x-a)<ans1){
        ans=i;
        ans1=abs(x-a);}
    }
    cout<<ans;
}

Measured memory_bytes: 256
s = input()
t = list(s)

if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()

r = []
for c in t:
    r.append(ord(c))

if len(t) < 26:
    r = sorted(r)

    temp = ord('a')

    for x in r:
        if x == temp:
            temp += 1
        else:
            break

    t.append(chr(temp))

    print(''.join(t))

else:
    temp = r[25]
    for i in range(24, -1, -1):
        if r[i] < temp:
            hoge = r[i]
            fuga = sorted(r[i + 1:])
            for x in fuga:
                if x > hoge:
                    hoge = x
                    break
            t[i] = chr(hoge)
            break
        else:
            temp = max(temp, r[i])
            t[i] = ''

    t[25] = ''
    print(''.join(t))



Measured memory_bytes: 3064
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <fstream>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  int k, s;
  cin >> k >> s;
  int answer = 0;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      if (0 <= s - i - j && s - i - j <= k) answer++;
    }
  }

  cout << answer << endl;
}


Measured memory_bytes: 256
from itertools import chain
import sys

def main():
    N = int(input())
    # TLEs were caused mostly by slow input (1s+)
    # S = list(input() for _ in range(N))
    S = sys.stdin.read().split('\n')
    print(solve(S))

def get_count(args):
    s, result = args # messy input to work with map.
    cum_sum = 0
    for c in s:
        if c == ')':
            cum_sum -= 1
        else:
            cum_sum += 1
        result[0] = max(result[0], -cum_sum)
    result[1] = result[0] + cum_sum
    return result

# Made-up name, don't remember what to call this. Radix-ish
def silly_sort(array, value_min, value_max, get_value):
    if len(array) == 0:
        return
    cache = [None for _ in range(value_max - value_min + 1)]
    for elem in array:
        # Assume elem[0] is the value
        value = get_value(elem) - value_min
        if cache[value] is None:
            cache[value] = []
        cache[value].append(elem)
    for values in cache:
        if values is None:
            continue
        for value in values:
            yield value

def solve(S):
    counts = [[0,0] for _ in range(len(S))]
    counts = list(map(get_count, zip(S,counts)))
    first_group = []
    second_group = []
    min_first_group = float('inf')
    max_first_group = 0
    min_second_group = float('inf')
    max_second_group = 0

    for c in counts:
        if c[0] - c[1] <= 0:
            first_group.append(c)
            max_first_group = max(max_first_group, c[0])
            min_first_group = min(min_first_group, c[0])
        else:
            second_group.append(c)
            max_second_group = max(max_second_group, c[1])
            min_second_group = min(min_first_group, c[1])
    first_group = silly_sort(first_group, min_first_group, max_first_group, lambda c: c[0])
    second_group = reversed(list(silly_sort(second_group, min_second_group, max_second_group, lambda c: c[1])))

    order = chain(first_group, second_group)

    cum_sum = 0
    for c in order:
        cum_sum -= c[0]
        if cum_sum < 0:
            return 'No'
        cum_sum += c[1]
    if cum_sum == 0:
        return 'Yes'
    return 'No'

if __name__ == '__main__':
    main()


Measured memory_bytes: 124036
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <bits/stdc++.h>
#include <iomanip>
#include <numeric>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)
#define P pair<ll, ll>
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

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

int main(void)
{
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, 0, h) cin >> s[i];

    vector<vector<int>> seen(h, vector<int>(w, -1));
    int cta = 0, ans = 0;
    rep(i, 0, h) rep(j, 0, w) if (s[i][j] == '.') cta++;
    queue<P> que;
    P a = {0, 0};
    que.push(a);
    seen[0][0] = 0;
    while (!que.empty())
    {
        P tmp = que.front();
        que.pop();
        rep(i, 0, 4)
        {
            int ny = tmp.first + dy[i], nx = tmp.second + dx[i];
            if (ny < 0 || h <= ny || nx < 0 || w <= nx)
                continue;
            if (s[ny][nx] == '#')
                continue;
            if (seen[ny][nx] == -1)
            {
                seen[ny][nx] = seen[tmp.first][tmp.second] + 1;
                P b = {ny, nx};
                que.push(b);
            }
        }
    }
    if (seen[h - 1][w - 1] == -1)
        ans = -1;
    else
        ans = cta - seen[h - 1][w - 1] - 1;
    cout << ans << endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    int n;
    cin >> n;
    bool ok = false;
    if (n % 10 == 7)
    {
        ok = true;
    }
    if ((n / 10) % 10 == 7)
    {
        ok = true;
    }
    if ((n / 100) % 10 == 7)
    {
        ok = true;
    }

    string ans = ok ? "Yes" : "No";
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>

using namespace std;
int main() {
  int h, n;
  cin >> h >> n;

  int sum = 0;
  for(int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    sum += a;
  }

  if(sum >= h) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	
	static BufferedReader reader;

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		reader = new BufferedReader(new InputStreamReader(System.in));
		
		int N = Integer.parseInt(readLine());
		int max_h = 0;
		int count = 0;
		String[] Hs = readLine().split(" ");
		for(int i=0;i<Hs.length;i++){
			if(max_h<=Integer.parseInt(Hs[i])) {
				count++;
				max_h = Integer.parseInt(Hs[i]);
			}
		}
		
		System.out.println(count);
	}

	private static String readLine(){
		try{
			return reader.readLine();
		}catch(Exception e){
			return e.getMessage();
		}
	}
}

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

#define all(v) v.begin(), v.end()
#define V vector
#define P pair
#define M map
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;

int n, m;
ll x;
V<ll> c;
V<V<ll> > a;

int main() {
    cin >> n >> m;
    cin >> x;
    c.resize(n);
    a.resize(n);
    for(int i = 0; i < n; i++){
        cin >> c[i];
        for(int j = 0; j < m; j++){
            ll t; cin >> t;
            a[i].push_back(t);
        }
    }

    ll res = INF;
    for(int bit = 0; bit < (1 << n); bit++){
        ll sum = 0;
        V<ll> ans(n);
        for(int i = 0; i < n; i++){
            if(bit & (1 << i)){
                sum += c[i];
                for(int j = 0; j < m; j++){
                    ans[j] += a[i][j];
                }
            }
        }
        bool flag = true;
        for(int i = 0; i < m; i++){
            if(ans[i] >= x){
                continue;
            }else{
                flag = false;
                break;
            }
        }
        if(flag) res = min(sum, res);
    }
    if(res == INF) cout << -1 << endl;
    else cout << res << endl;
}


Measured memory_bytes: 3648
N,C = map(int,input().split())
xv = [list(map(int,input().split())) for _ in range(N)]
x = [xv[i][0] for i in range(N)]
v = [xv[i][1] for i in range(N)]

C1 = [0]*N
C2 = [0]*N
for i in range(N):
    C1[i] = C1[i-1]+v[i]
    C2[i] = C2[i-1]+v[i]
for i in range(N):
    C1[i] -= x[i]
    C2[i] -= 2*x[i]
for i in range(1,N):
    C1[i] = max(C1[i],C1[i-1])
    C2[i] = max(C2[i],C2[i-1])

D1 = [0]*N
D2 = [0]*N
for i in range(N):
    D1[i] = D1[i-1]+v[N-1-i]
    D2[i] = D2[i-1]+v[N-1-i]
for i in range(N):
    D1[i] -= C-x[N-1-i]
    D2[i] -= 2*(C-x[N-1-i])
for i in range(1,N):
    D1[i] = max(D1[i],D1[i-1])
    D2[i] = max(D2[i],D2[i-1])

ans = 0
for i in range(N):
    ans = max(ans,C1[i],D1[i])

for i in range(N-1):
    ans = max(ans,C2[i]+D1[N-i-2],D2[i]+C1[N-i-2])

print(ans)

Measured memory_bytes: 46468
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define PI acos(-1)
typedef long long ll;
typedef pair<int, int> p_ii;
const ll INF = 1LL << 60;

class BIT {
public:
	BIT(ll N, ll v) :V_SIZE(N) {
		dat.resize(N);
		fill(dat.begin(), dat.end(), v);
	}

	ll query(ll i) {
		ll ret = 0;
		while (i > 0) {
			ret += dat[i];
			i -= (i & -i);
		}
		return ret;
	}

	void update(ll i, ll v) {
		while (i < V_SIZE) {
			dat[i] += v;
			i += (i & -i);
		}
	}

	ll V_SIZE;
	vector<ll> dat;
};

int main() {
	
	ll n, m, q;
	cin >> n >> m >> q;
	vector<BIT> b(n + 1, BIT(n + 1, 0));
	for (int i = 0; i < m; i++) {
		ll l, r; cin >> l >> r;
		for (ll j = 1; j <= l; j++) {
			b[j].update(r, 1);
		}
	}
	for (ll i = 0; i < q; i++) {
		ll p, q;
		cin >> p >> q;
		cout << b[p].query(q) << endl;
	}
	
	return 0;
}

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

int main() {
	char s[200], buf[200];
	int m, h;
	while (1) {
		scanf("%s", s);
		if (!strcmp(s,"-"))break;
		scanf("%d", &m);
		for (int i = 0; i < m; i++) {
			scanf("%d", &h);
			for (int j = 0; j < h; j++) {
				buf[j] = s[j];
			}
			for (unsigned int j = 0; j < strlen(s) - h; j++) {
				s[j] = s[j+h];
			}
			for (int j = 0; j < h; j++) {
				s[j+strlen(s)-h] = buf[j];
			}
		}
		printf("%s\n", s);
	}
	return 0;
}


Measured memory_bytes: 2672
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scanner =new Scanner(System.in);

		int N = scanner.nextInt();
		int K = scanner.nextInt();

		int[] Ni = new int[N];
		for (int i = 0; i < N; i++) {
			Ni[i] = scanner.nextInt();
		}

		int ans = (N-1)/(K-1);
		if((N-1)%(K-1)!=0)ans++;
		System.out.println(ans);

	}

}


Measured memory_bytes: 50016
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef pair<int, int>P;
 
struct st { int p, b, c; };
bool operator<(st a, st b) { return a.c>b.c; }
map<int, vector<int>>E[100000];
vector<int>G[100000];
map<int, int>d[100000];
int main() {
	int n, m; scanf("%d%d", &n, &m);
	rep(i, m) {
		int p, q, c; scanf("%d%d%d", &p, &q, &c); p--; q--;
		E[p][c].push_back(q); E[q][c].push_back(p);
		G[p].push_back(c); G[q].push_back(c);
	}
	priority_queue<st>que;
	d[0][0] = 0; que.push({ 0,0,0 });
	while (!que.empty()) {
		st p = que.top(); que.pop();
		if (d[p.p][p.b] != p.c)continue;
		if (d[p.p].find(0) == d[p.p].end() || d[p.p][0] > p.c) {
			d[p.p][0] = p.c;
			que.push({ p.p,0,p.c });
		}
		if (p.b == 0) {
			for (int v : G[p.p]) {
				if (d[p.p].find(v) == d[p.p].end() || d[p.p][v] > p.c + 1) {
					d[p.p][v] = p.c + 1;
					que.push({ p.p,v,p.c + 1 });
				}
			}
			continue;
		}
		for (int v : E[p.p][p.b]) {
			if (d[v].find(p.b) == d[v].end() || d[v][p.b] > p.c) {
				d[v][p.b] = p.c;
				que.push({ v,p.b,p.c });
			}
		}
	}
	int Min = INT_MAX;
	for (auto p : d[n - 1])Min = min(Min, p.second);
	if (Min == INT_MAX)puts("-1");
	else printf("%d\n", Min);
}


Measured memory_bytes: 85680
#include <stdio.h>

int main(void) {
  FILE* fp;
  fp = stdin;
  char line[64];
  if(!fgets(line, 64, fp)) return 0;
  int a, b;
  sscanf(line, "%d %d", &a, &b);
  printf("%d\n", (a + b + 1)/2);
  return 0;
}

Measured memory_bytes: 128
def main():
    import sys
    input = sys.stdin.readline
    
    n, k = map(int, input().split())
    s = input()
    
    islands = 0
    for i in range(1, n):
        if s[i] != s[i - 1]:
            islands += 1
    
    islands = max(0, islands - 2 * k)
    
    print(n - 1 - islands)
    
    return 0

main()


Measured memory_bytes: 3260
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/algorithm_ext.hpp>
#include <boost/math/common_factor_rt.hpp>
using namespace std;
using namespace boost::range;
using boost::irange;
using boost::math::gcd;
using boost::math::lcm;

using ll = int64_t;
constexpr char LN = '\n';
template<class T> bool chmax(T& a, const T& b) {if(a<b){a=b;return true;}else{return false;}}
template<class T> bool chmin(T& a, const T& b) {if(b<a){a=b;return true;}else{return false;}}

#ifdef LOCAL
template<class H> void dump_(const char* s, H h) {cout<<s<<"="<<h<<LN; }
template<class H, class... T> void dump_(const char* s, H h, T... t) {for(;*s!=',';++s){cout<<*s;}cout<<"="<<h<<",";dump_(++s,t...);}
#define dump(...) dump_(#__VA_ARGS__, __VA_ARGS__)
#else
#define dump(...)
#endif

struct init_ {init_(){cin.tie(nullptr);ios::sync_with_stdio(false);}} init_;

template<class C> C scan(size_t n) {C c(n);for(auto& v:c){cin>>v;}return c;}
template<class C> C scan(size_t n, size_t m) {C vss(n);for(auto& vs:vss){vs.resize(m);for(auto& v:vs){cin>>v;}}return vss;}

template<class R> struct Joined { const R& r; const char* s; };
template<class R> Joined<R> joined(const R& r, const char* s = " ") {return{r,s};}
template<class R> ostream& operator<<(ostream& out, Joined<R> j) {bool f=true;for(const auto& v:j.r){if(f){f=false;}else{out<<j.s;}out<<v;}return out;}

template<class T> using matrix = vector<vector<T>>;
template<class T> matrix<T> make_matrix(size_t n, size_t m, const T& init = T()) {matrix<T> vss(n);for(auto& vs:vss){vs.resize(m,init);}return vss;}
template<class T> ostream& operator<<(ostream& out, Joined<matrix<T>> j) {bool a=true;for(const auto& vs:j.r){if(a){a=false;}else{out<<LN;}bool f=true;for(const auto& v:vs){if(f){f=false;}else{out<<j.s;}out << v;}}return out;}

template<class T> void show(const T& t) {cout<<t<<LN;}
template<class T> void show(const vector<T>& v) {cout<<joined(v)<<LN;}
void show(bool b) {cout<<(b?"Yes":"No")<<LN;}
void show(double d) {cout<<fixed<<setprecision(12)<<d<<LN;}

char for_win_to(char h) {
    return (h == 'r') ? 'p' :
           (h == 'p') ? 's' : 'r';
}

char rest(char a, char b) {
    return (a == 'r') ?
                (b == 'p') ? 's' : 'p' :
           (a == 'p') ?
                (b == 's') ? 'r' : 's' :
           (a == 's') ?
                (b == 'r') ? 'p' : 'r' : 'r';
}

int main() {
    int N, K, R, S, P;
    string T;
    cin >> N >> K >> R >> S >> P >> T;
    string my_hand(N, ' ');
    ll point = 0;
    for (int i : irange(0, N)) {
        char hand = for_win_to(T[i]);
        if (K <= i && my_hand[i - K] == hand) {
            if (i + K < N) {
                hand = rest(hand, for_win_to(T[i + K]));
            } else {
                hand = rest(hand, hand);
            }
        } else {
            point += (hand == 'r') ? R :
                     (hand == 's') ? S : P;
        }
        my_hand[i] = hand;
    }
    dump(my_hand);
    show(point);
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int n,F[50];
void fibonacci(int n){
    for(int i=0;i<=n;i++){
        if(i<=1)
            F[i]=1;
        else
            F[i]=F[i-1]+F[i-2];
    }
}
int main(){
    cin>>n;
    fibonacci(n);
    cout<<F[n]<<endl;
    return 0;
}


Measured memory_bytes: 3104
def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a

k = int(input())
temp = [[xgcd(i, j) for i in range(1, k+1)] for j in range(1, k+1)]
ans = 0
for a in range(k):
    for b in range(k):
        t = temp[a][b]
        ans += sum([temp[t-1][c] for c in range(k)])
print(ans)

Measured memory_bytes: 9368
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
 
int main() {
    string s;
    int count = 0;
 
    cin >> s;
     for(int i = 0; i < (int)s.size(); ++i) {
        if (s[i] == '1') {
            count++;
        }
    }
     cout << count << endl;
}


Measured memory_bytes: 3596
/*
        _            _                  _            _       _     _         _   _          _          _             _        
       / /\         / /\               / /\         / /\    / /\  /\ \      /\_\/\_\ _     /\ \       /\ \     _    /\ \      
      / /  \       / /  \             / /  \       / / /   / / /  \ \ \    / / / / //\_\   \ \ \     /  \ \   /\_\ /  \ \     
     / / /\ \__   / / /\ \           / / /\ \__   / /_/   / / /   /\ \_\  /\ \/ \ \/ / /   /\ \_\   / /\ \ \_/ / // /\ \_\    
    / / /\ \___\ / / /\ \ \         / / /\ \___\ / /\ \__/ / /   / /\/_/ /  \____\__/ /   / /\/_/  / / /\ \___/ // / /\/_/    
    \ \ \ \/___// / /  \ \ \        \ \ \ \/___// /\ \___\/ /   / / /   / /\/________/   / / /    / / /  \/____// / / ______  
     \ \ \     / / /___/ /\ \        \ \ \     / / /\/___/ /   / / /   / / /\/_// / /   / / /    / / /    / / // / / /\_____\ 
 _    \ \ \   / / /_____/ /\ \   _    \ \ \   / / /   / / /   / / /   / / /    / / /   / / /    / / /    / / // / /  \/____ / 
/_/\__/ / /  / /_________/\ \ \ /_/\__/ / /  / / /   / / /___/ / /__ / / /    / / /___/ / /__  / / /    / / // / /_____/ / /  
\ \/___/ /  / / /_       __\ \_\\ \/___/ /  / / /   / / //\__\/_/___\\/_/    / / //\__\/_/___\/ / /    / / // / /______\/ /   
 \_____\/   \_\___\     /____/_/ \_____\/   \/_/    \/_/ \/_________/        \/_/ \/_________/\/_/     \/_/ \/___________/    
                                                                                                                              
*/
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)

#define endl '\n'
#define pb emplace_back
#define mkp make_pair
#define p_q priority_queue
#define INF 2000000000
#define PI 3.1415926
#define coutdb cout << fixed << setprecision(10)

const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int long long

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

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

  int N; cin >> N;
  int ans = 0;
  for(int i = 1; i <= 1000000; i++){
    if(N % i == 0 and N/i - 1 > i){
      ans += N/i - 1;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PI 3.1415926535897932384626433832795
typedef tree<pair<int,int>,null_type,less<pair<int,int> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
long long MOD = 1e9+7;
pair<int,int> dx[4] = {{1,0},{-1,0},{0,1},{0,-1}};
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct chash {int operator()(int x) const { return x ^ RANDOM; }};
string toString(long long x){stringstream ss;ss << x;string str = ss.str();return str;}
long long fastpow(long long x,long long k){if(!k)return 1;if(k & 1)return ((x * fastpow(x,k-1) % MOD) % MOD) % MOD;
long long ans = fastpow(x,k/2);ans %= MOD;ans *= ans;ans %= MOD;return ans;}
long long sumF(long long x){int s = 0;while(x)s += x%10,x /= 10;return s;}
bool isS(char c){return (c >= 'a' && c <= 'z');}
bool isB(char c){return (c >= 'A' && c <= 'Z');}
bool isD(char c){return (c >= '0' && c <= '9');}
bool isSqrt(long long x){ long long f = sqrt((long double)x + 0.5); return f*f == x;}
long long lcm(long long a,long long b){return a * (b / __gcd(a,b));}
int arr[100005];
int pGcd[100005];
int sGcd[100005];
int main()
{
    IO;
    int n;
    cin >> n;
    for(int i = 1;i <= n;i++)
        cin >> arr[i],pGcd[i] = __gcd(pGcd[i-1],arr[i]);
    for(int i = n;i >= 1;i--)
        sGcd[i] = __gcd(sGcd[i+1],arr[i]);
    int bestGcd = -1;
    for(int i = 1;i <= n;i++)
        bestGcd = max(bestGcd,__gcd(pGcd[i-1],sGcd[i+1]));
    cout << bestGcd;
    return 0;
}


Measured memory_bytes: 1408
//Æ­·Ö²»¹æ·¶£¬±¬ÁãÁ½ÐÐÀá
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
using namespace std;
const int mxn=2e5+5;
int n,a[mxn];
inline bool ok(int md){
	if(md==1){
		for(int i=1;i<n;++i)if(a[i]>=a[i+1])return 0;
		return 1;
	}
	map<int,int>m;m.clear();
	for(int i=2;i<=n;++i)if(a[i]<=a[i-1]){
		m.erase(m.upper_bound(a[i]),m.end());
		int k=a[i];++m[k];
		for(;k and m[k]==md;)m.erase(k),++m[--k];
		if(!k)return 0;
	}
	return 1;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",a+i);
	int l=1,r=n,md;
	for(;l<r;){
		md=l+r>>1;
		if(ok(md))r=md;
		else l=md+1;
	}
	printf("%d\n",l);
}

Measured memory_bytes: 1152
#include <stdio.h>


int main(void){
    int N,M;
    scanf("%d %d",&N,&M);
    double a[N];
    double ruiseki[N+1];
    ruiseki[0]=0;
    for(int i=0;i<N;i++){scanf("%lf",&a[i]);ruiseki[i+1]=ruiseki[i]+a[i];}
    double dp[2][N-M+1][N-M+1];
    for(int i=0;i<2;i++)for(int j=0;j<N-M+1;j++)for(int k=0;k<N-M+1;k++){dp[i][j][k]=-100000000000000;}
    dp[0][0][0]=(double)a[0];
    dp[1][0][0]=(double)a[0];
    for(int i=1;i<N;i++){
        for(int j=0;j<N-M+1&&j<i;j++){
            double max=0;
            for(int k=0;k<=j;k++)if(max<dp[0][j][k])max=dp[0][j][k];
        dp[1][j][0]=max+a[i];
        }
        for(int j=1;j<N-M+1&&j<=i;j++)for(int k=1;k<=j;k++){
            dp[1][j][k]=dp[0][j-1][k-1]+(double)(ruiseki[i+1]-ruiseki[i-k])/(k+1)-(double)(ruiseki[i]-ruiseki[i-k])/k;
        }
        for(int j=0;j<N-M+1;j++)for(int k=0;k<N-M+1;k++)dp[0][j][k]=dp[1][j][k];
    }
    double ans=0;
    for(int k=0;k<N-M+1;k++)if(ans<dp[1][N-M][k])ans=dp[1][N-M][k];
    if(M!=1)printf("%f",ans);
    else printf("%f",dp[1][N-M][N-M]);
    return 0;
}



Measured memory_bytes: 4972
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
using namespace std;
int main()
{
	string s;
	cin >> s;
	int k;
	cin >> k;
	string ans[k];
	int n, m, o,p;
	for (n = 0; n < k; n++){
		ans[n] = "zzzzz";
	}
	int leng = s.size();
	for (n = 1; n <= min(leng, 5); n++){
		for (m = 0; m <= leng - n; m++){
			for (o = 0; o <k; o++){
				if (ans[o] == s.substr(m, n)){
					break;
				}
				else if (ans[o]>s.substr(m, n)){
					for (p = k-1; p>o;p--){
						ans[p] = ans[p - 1];
					}
					ans[o] = s.substr(m, n);
                  break;
				}
			}
		}
	}
	cout << ans[k-1] << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()

ll lcm(ll a, ll b) { return (a / __gcd(a, b) * b); }

int main() {
  //
  int n;
  cin >> n;
  vl a(n);
  rep(i, n) cin >> a[i];
  if (n < 2) {
    cout << a[0] << endl;
    return 0;
  }
  ll ans = lcm(a[0], a[1]);
  REP(i, 2, n) {
    ans = lcm(ans, a[i]);
    // cout << ans << endl;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n, m = [int(x) for x in input().split()]
matrix = []
for num in range(n):
    matrix.append([int(y) for y in input().split()])
colum = []
for num in range(m):
    colum.append(int(input()))
for i in range(n):
    a = 0
    for j in range(m):
        product = matrix[i][j] * colum[j]
        a += product
    print(a)

Measured memory_bytes: 7976
import collections as cl
N = int(input())
A = [int(i) for i in input().split()]
Q = int(input())

res = sum(A)
c = cl.Counter(A)
for i in range(Q):
  BC = [int(j) for j in input().split()]
  B = BC[0]
  C = BC[1]
  if B in c:
    res += (C-B)*c[B]
    if C in c:
      c[C] += c[B]
    else:
      c[C] = c[B]
    del(c[B])
  print(res)
  

Measured memory_bytes: 21304