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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)

#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define _repis(i,a,b,s) for(int i=a, i##_len(b); i<i##_len; i+=s)
#define REP(...) _overload3(__VA_ARGS__,_repis,_repi,_rep,)(__VA_ARGS__)

#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)

#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))

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

#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl
#define POSS(n) cout<<((n)?"POSSIBLE":"IMPOSSIBLE")<<endl



int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    if(!(a%2&&b%2&&c%2)){
        cout<<0<<endl;
    }else{
        ll mi=LINF;
        chmin(mi,a*b);
        chmin(mi,a*c);
        chmin(mi,c*b);
        cout<<mi<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
  int n, r;
  cin >> n;
  long long int a[n];
  for(int i = 0 ; i < n ; i++){
    cin >> a[i]; 
  }
  sort(a, a+n);
  long long int bi = (a[n-1] + 1)/2;
  long long int min = a[n-1];
  for(int i = 0 ; i < n ; i++){
    if(abs(a[i] - bi) < min){
      min = abs(a[i] - bi);
      r = a[i];
    }
  }
  cout << a[n-1] << " " << r << endl;
  return 0;
}

Measured memory_bytes: 1024
// ABC064A.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
using namespace std;
int main()
{
	int r, g, b;
	cin >> r >> g >> b;
	int num;
	num = 100 * r + 10 * g + b;
	if ((num % 4) == 0) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;

vi movex = {0,0,1,-1};
vi movey = {1,-1,0,0};
/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int _StartTime_ = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(15);

    int h,w, cnt = 0; cin >> h >> w;
    vii grid(h,vi(w));
    rep(i,h)rep(j,w) {
        char ch; cin >> ch;
        grid[i][j] = (ch=='#' ? 1 : 0);
        if(ch=='#') cnt++;
    }
    vii dist(h,vi(w, -1));
    queue<PII> que;
    que.emplace(0,0);
    dist[0][0] = 1;
    while(que.size()) {
        int x = que.front().first;
        int y = que.front().second;
        que.pop();
        rep(i,4) {
            int nx = x + movex[i];
            int ny = y + movey[i];
            if(!(0<=nx && nx<h && 0<=ny && ny<w)) continue;
            if(grid[nx][ny]) continue;
            if(dist[nx][ny]!=-1) continue;
            dist[nx][ny] = dist[x][y] + 1;
            que.emplace(nx,ny);
        }
    }
    if(dist[h-1][w-1]==-1) cout << -1 << '\n';
    else cout << h*w - dist[h-1][w-1] - cnt << '\n';

    // printf("ExcutionTime: %d /ms\n",1000*(int)((clock()-_StartTime_)/CLOCKS_PER_SEC));
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<map>
using namespace std;
map<int,int>mp;
int main(){
	int N,K,Q;
	scanf("%d %d %d",&N,&K,&Q);
	mp.clear();
	int a=Q+1-K;
	while(Q){
		int x;
		scanf("%d",&x);
		mp[x]++;
		Q--;
	}
	for(int i=1;i<=N;i++){
		if(mp[i]>=a){
			printf("Yes");
		}
		else printf("No");
		if(i!=N) printf("\n");
	}
	return 0;
} 

Measured memory_bytes: 5376
x, n= input().split()
x = int(x)
n = int(n)

array = [[0]]*200
if n == 0:
    print(x)
else:
    for i in range(200):
        array[i] = 0
    tmp = input().split(' ')
    for i in range(n):
        array[int(tmp[i])] = 1
    
    dif_tmp = 999
    ret = 999
    for i in range(200):
        if array[199-i] == 0:
            if abs(x-(199-i)) <= dif_tmp:
                ret = 199-i
                dif_tmp = abs(x-(199-i))
    for i in range(1,100):
        if abs(x+i) <= dif_tmp:
            ret = -i
            dif_tmp = abs(x+i)
    print(ret)

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

typedef pair<int, int> pii;

const int mod = 1e9 + 7;

int exp(int x, int n) {
    int ret = 1;
    while(n) {
        if(n & 1) ret = 1LL * ret * x % mod;
        x = 1LL * x * x % mod;
        n >>= 1;
    }
    return ret;
}
int inv(int x) {
    return exp(x, mod - 2);
}

int fact[200010], invf[200010];

int N, X, Y;
int lmn[200010], rmn[200010];
vector<int> C[200010];

int main() {
    fact[0] = 1;
    for(int i = 1; i < 200010; i++) {
        fact[i] = 1LL * fact[i - 1] * i % mod;
    }
    for(int i = 0; i < 200010; i++) {
        invf[i] = inv(fact[i]);
    }

    scanf("%d %d %d", &N, &X, &Y);

    for(int i = 0; i < N; i++) {
        int c, w; scanf("%d %d", &c, &w);
        C[--c].push_back(w);
    }

    for(int i = 0; i < N; i++) {
        sort(C[i].begin(), C[i].end());
    }
    for(int i = 0; i < N; i++) {
        lmn[i] = C[i].size()? C[i][0] : 1e9;
        if(i) lmn[i] = min(lmn[i], lmn[i - 1]);
    }
    for(int i = N - 1; i >= 0; i--) {
        rmn[i] = C[i].size()? C[i][0] : 1e9;
        if(i != N - 1) rmn[i] = min(rmn[i], rmn[i + 1]);
    }

    for(int i = 0; i < N; i++) {
        if(C[i].size() == 0) continue;

        int mn = 1e9;
        if(i) mn = min(mn, lmn[i - 1]);
        if(i != N - 1) mn = min(mn, rmn[i + 1]);

        while(C[i].size() > 1 && C[i].back() + mn > Y && C[i].back() + C[i][0] > X) {
            C[i].pop_back();
        }
    }

    int mn = 2e9, c = -1;
    for(int i = 0; i < N; i++) {
        if(C[i].size()) {
            if(mn > C[i][0]) {
                mn = C[i][0];
                c = i;
            }
        }
    }

    int ans = 1;
    int sum = 0;
    for(int i = 0; i < N; i++) {
        if(i == c) continue;
        if(C[i].size() && C[i][0] + mn <= Y) {
            ans = 1LL * ans * invf[ C[i].size() ] % mod;
            sum += C[i].size();
        }
    }
    if(sum) {
        ans = 1LL * ans * invf[ C[c].size() ] % mod;
        sum += C[c].size();
    }

    ans = 1LL * ans * fact[sum] % mod;
    printf("%d", ans);
}


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

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

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

        if x == y:
            return

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

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

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

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

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

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

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

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

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

n,m=map(int,input().split())
uf=UnionFind(n)
for i in range(m):
  a,b=map(int,input().split())
  a,b=a-1,b-1
  uf.union(a,b)
print(uf.group_count()-1)

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

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int INF = pow(2,29);
const int MOD = 1000000007;

int main() {
  ll N; cin >> N;
  ll L[1001] = {}; rep(i,N) {int tmp; cin >> tmp; L[tmp]++;}
  ll sum[1001] = {};
  for (int i=0; i<=1000; i++) {
    if (i==0) { sum[i] = L[i]; }
    else { sum[i] = sum[i-1] + L[i]; }
  }

  ll result = 0;
  for (int i=1; i<=1000; i++) {
    if (L[i]>=3) { result += L[i]*(L[i]-1)*(L[i]-2)/6; }
    if (L[i]>=2) {
      int pos = min(1000, i*2-1);
      result += ( sum[pos] - L[i] ) * (L[i]*(L[i]-1)/2); 
    } 
    for (int j=i+1; j<=1000; j++) {
      int pos = min(1000, i+j-1);
      result += L[i] * L[j] * ( sum[pos] - sum[j] );
    }
  }

  // rep(i,10) cout << sum[i] << " "; cout << endl;
  cout << result << endl;
  return 0;
}

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

#define int long long

using namespace std;



int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int A, B, C, D;
    cin >> A >> B >> C >> D;

    cout << max({A*C, A*D, B*C, B*D}) << '\n';

    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define ll long long;
#define dbg(x) cout<<#x<<"--------------"<<x<<endl;
#define dl cout<<"LINE"<<__LINE__<<endl;
using namespace std;
inline int gcd(int a,int b){return b==0?a:(gcd(b,a%b));}
inline int gcdt(int a,int b,int c){
	int ans=gcd(a,b);
	ans=gcd(ans,c);
	return ans;
}
int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int ans=0;
	int k;
	cin>>k;
	for(int i=1;i<=k;i++){
		for(int j=1;j<=k;j++){
			for(int l=1;l<=k;l++){
				ans+=gcdt(i,j,l);	
			}
		}
	}
	cout<<ans<<endl;
		
	return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

map<char,long long> mp;
int main(){
    string s; cin>>s;
    for(char c:s){
        mp[c]++;
    }
    long long n=s.size();
    long long ans=n*(n-1)/2+1;
    for(char c='a';c<='z';c++){
        ans-=mp[c]*(mp[c]-1)/2;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5,mod=998244353;
char s[N];
int n;
ll dp[N][3][3][2];
int main()
{
    scanf("%s",s+1);
    n=strlen(s+1);
    bool flag=false;
    for(int i=2;i<=n;i++)
        flag|=s[i]!=s[i-1];
    if(!flag){printf("1\n");return 0;}
    if(n<=3)
    {
        if(n==2) puts("2");
        if(n==3)
        {
            if(s[1]!=s[2]&&s[2]!=s[3]&&s[1]!=s[3]) puts("3");
            else if(s[1]==s[3]) puts("7");
            else puts("6");
        }
        return 0;
    }
    dp[1][0][0][0]=dp[1][1][1][0]=dp[1][2][2][0]=1;
    int sum=0;
    for(int i=1;i<n;i++)
        for(int j=0;j<=2;j++)
            for(int k=0;k<=2;k++)
            for(int h=0;h<2;h++)
            for(int f=0;f<=2;f++)
                (dp[i+1][(j+f)%3][f][(k==f)|h]+=dp[i][j][k][h])%=mod;
    for(int i=1;i<=n;i++) (sum+=s[i]-'a')%=3;
    ll ans=0;
    for(int i=0;i<=2;i++)
        (ans+=dp[n][sum][i][1])%=mod;
    flag=false;
    for(int i=2;i<=n;i++)
        flag|=s[i]==s[i-1];
    if(!flag) ans++;
    printf("%lld\n",ans);
}


Measured memory_bytes: 28544
N = int(input())
V_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))

ans = 0
for i in range(len(V_list)):
    if V_list[i] > C_list[i]:
        ans += V_list[i] - C_list[i]
        
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>

int main() {
  int n;
  scanf("%d",&n);
  int ans=-1000000000,M=1000000000,i;
  for(i=0; i<n; i++) {
    int x;
    scanf("%d",&x);
    if(i && x-M>ans) ans=x-M;
    if(M>x) M=x;
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 596
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n=int(input())
s=input()
x=0
r=0

for i in range(0,n):
  if s[i]=='I':
    x=x+1
  else:
    x=x-1
  r=max(r,x)
print(r)


Measured memory_bytes: 2940
/*
  AOJ 0133
  Title:Rotation of a Pattern
  @kankichi573
*/
#include <stdio.h>
#include <string.h>
char pat1[8][9];
char pat2[8][9];
void rot()
{
        int i,j;

        for(i=0;i<8;i++)
                for(j=0;j<8;j++)
                        pat2[i][j]=pat1[7-j][i];
}
void display()
{
        int i;

        for(i=0;i<8;i++)
                printf("%s\n",&pat2[i][0]);
}
int main()
{
        int i;
        for(i=0;i<8;i++)
                scanf("%s",&pat1[i][0]);

        for(i=1;i<=3;i++)
        {
                rot();
                printf("%d\n",i*90);
                display();
                memcpy(pat1,pat2,8*9);
        }

  return(0);
}

Measured memory_bytes: 548
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i,s,n) for(int i=s;i< (int)n; i++)
#define ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
// index が条件を満たすかどうか
bool isOK(int index, int key , vector<int>& a) {
    if (a[index] == key) return true;
    else return false;
}
// 二分探索
int binary_search(int key, vector<int>& a) {
    int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int right = (int)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
    /* どんな二分探索でもここの書き方を変えずにできる！ */
    while (right - left > 1) {
        int mid = left + (right - left) / 2;
        if (isOK(mid, key , a)) right = mid;
        else left = mid;
    }
    /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
    return right;
}

int main(){
  int n;cin >>n;
  vector<int> vec(n);
  vector<int> ans(n);
  rep(i,n) cin >>vec[i];
  rep(i,n) ans[vec[i]-1]=i+1;
  rep(i,n-1) cout <<ans[i]<<" ";
  cout  <<ans[n-1]<<endl;
}

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

int main(int argc, char *argv[]) {
    // freopen("input.txt","r",stdin);

    const long long INF = 1LL<<60;
    const int MAX_N = 100;
    const int MAX_V = 1000;

    // 入力
    int N;
    long long W, weight[MAX_N + 1], value[MAX_N + 1];
    long long dp[MAX_N + 1][MAX_V * MAX_N + 1];
  
    cin >> N >> W;
    for (int i = 0; i < N; ++i) {
      cin >> weight[i] >> value[i];
    }

    // 初期化
    for (int i = 0; i < MAX_N; i++) {
      for (int j = 0; j < MAX_V * MAX_N + 1; j++) {
        dp[i][j] = INF;
      }
    }

    // 初期条件
    dp[0][0] = 0;

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < MAX_V * MAX_N + 1; j++) {
            if (j < value[i]) {
                dp[i+1][j] = dp[i][j];
            } else {
                dp[i+1][j] = min(dp[i][j], dp[i][j - value[i]] + weight[i]);
            }
        }
    }

    long answer = 0;
    for (long i = 0; i < MAX_V * MAX_N + 1; i++) {
        if (dp[N][i] <= W) {
            answer = i;
        }
    }

    cout << answer << endl;

    return 0;
}


Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
int a[100010][4],dp[100010][4],n,ans=-1;
void solve(){
    cin>>n;
    for(int i=1;i<=n;i++)
      	for(int j=1;j<=3;j++)
          	cin>>a[i][j];
    for(int i=1;i<=n;i++)
      	for(int j=1;j<=3;j++)
          	for(int z=1;z<=3;z++)
            	if(j!=z)dp[i][j]=max(dp[i][j],dp[i-1][z]+a[i][j]);
    for(int i=1;i<=3;i++)ans=max(ans,dp[n][i]);
  	cout<<ans;
}
main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);

    //freopen("FORM MAU.inp","r",stdin);
    //freopen("FORM MAU.out","w",stdout);

    //srand(time(0));

    //int t;cin>>t;while(t--)
    //cout << setprecision(2) <<fixed;
    solve();
}

Measured memory_bytes: 3456
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <bitset>
#include <string>
#include <cmath>
#include <set>
#include <map>
#define Rep(i, x, y) for (int i = x; i <= y; i ++)
#define Dwn(i, x, y) for (int i = x; i >= y; i --)
#define RepE(i, x) for (int i = pos[x]; i; i = g[i].nex)
#define ev g[i].y
using namespace std;
typedef long long ll;
typedef double db;
const int mod = 1000000007, N = 2005, D = N * N;
int n, m;
ll q[D + 5], p[D + 5], f[N][N];
ll C(int x, int y) {
	return q[x] * p[y] % mod * p[x - y] % mod;
}
ll mypow(ll x, int y) {
	ll z = 1;
	while (y) {
		if (y & 1) (z *= x) %= mod;
		y >>= 1; (x *= x) %= mod;
	}
	return z;
}
int main()
{
	scanf ("%d%d", &n, &m);
	if (m == 1) { puts("1"); return 0; }
	q[0] = 1;
	Rep(i, 1, D) q[i] = q[i - 1] * i % mod; 
	p[D] = mypow(q[D], mod - 2);
	Dwn(i, D, 1) p[i - 1] = p[i] * i % mod;
	Rep(i, 1, n) {
		f[i][0] = 1;
		Rep(j, 1, i) {
			f[i][j] = (f[i][j - 1] * C((n - j + 1) * m - (i - j + 1) - 1, m - 2) + f[i - 1][j]) % mod;
			// cout << i <<" "<<j<<" "<<f[i][j]<<endl;
		}
	}
	printf("%d\n", (int)(f[n][n] * q[n] % mod));

	return 0;
}

Measured memory_bytes: 93056
#include <iostream>
#include <string>
#include <set>

using namespace std;

int f[501];

int main() {

  long long n, origin, ans = 1e12, k;
  cin >> origin >> n;
  for(int i = 1;i <= n;i++){
    cin >> k;
    f[k + 150] = true;
  }
  k = 0;
  while(true){
    if(f[origin - k + 150] == false){
      cout << origin - k;
      return 0;
    }
    if(f[origin + k + 150] == false){
      cout << origin + k;
      return 0;
    }
    k++;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n;
    cin >> n;
    vector<ll> cnt(n, 0), a(n);
    rep(i, 0, n) {
        cin >> a[i];
        a[i]--;
        cnt[a[i]]++;
    }

    ll all = 0;
    rep(i, 0, n) {
        if(cnt[i] >= 2) all += (cnt[i]-1) * cnt[i] / 2;
    }

    rep(i, 0, n) {
        if(cnt[a[i]] < 2) cout << all << endl;
        else {
            ll pre = (cnt[a[i]]-1) * cnt[a[i]] / 2;
            ll cur = (cnt[a[i]]-2) * (cnt[a[i]] - 1) / 2;
            ll ans = all - pre + cur;
            cout << ans << endl;
        } 
    }
}

Measured memory_bytes: 5760
# -*- coding: utf-8 -*-
# 整数の入力
import numpy as np
n,l  = map(int, input().split())
a = np.arange(l,l + n, 1)
amax = l + n -1
amin = l
if amax * amin >0:
    if abs(amax) - abs(amin)>0:
        print(sum(a) - (amin))
    else:
        print(sum(a) - (amax))
elif amax * amin <= 0:
    print(sum(a))
else:
    pass

Measured memory_bytes: 21656
import numpy as np
N = int(input())
a = [int(i) for i in input().split()]
oppai = np.array(a)

max = np.max(oppai)
min = np.min(oppai)
x = (max+min)//2
sum = [0] * 201

for i in range(-100,101):
    oppai = np.array(a) #oppaiの初期化
    oppai -= i
    oppai = oppai**2
    sum[i+100] = np.sum(oppai)
    #print('sum[{}]'.format(i+100),sum[i+100])

chinko = np.array(sum)
#print(np.argmin(chinko)+x-1)
print(np.min(chinko))


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

int main(){
	/*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    int r,d,x;
    cin>>r>>d>>x;
    long long a[10];
 long long   temp = x;
    for(int i = 0;i<10;i++){
    	a[i] = ((r*temp) - d);
    	temp = a[i];
    }
    for(int i = 0;i<10;i++){
    	cout<<a[i]<<endl;
    }
	return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::*;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    return ret;
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.is_err() || res.ok().unwrap() == 0 || u8b[0] <= ' ' as u8 {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = std::string::String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}
fn parse<T: std::str::FromStr>(s: &str) -> T { s.parse::<T>().ok().unwrap() }

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { parse(&get_word()) }

fn main() {
    let n: i64 = get();
    let x = n / 11;
    let r = n % 11;
    println!("{}", 2 * x + if r > 0 { if r <= 6 { 1 } else { 2 }} else { 0 });
}


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

using namespace std;

#define REP(var, n)  for (decltype(n) var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)

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

#define all(c) begin(c),end(c)

#define D(x) do { std::cerr << x << " "; } while (0)
#define D2(x) do { std::cerr << #x << ": " << x << std::endl; } while (0)


template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}


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

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


auto solve() {
    map<int, int> a;
    REP(i, 3) {
        int u, t;
        cin >> u >> t;
        a[u]++;
        a[t]++;
    }

    FOR(i, 1, 4 + 1) {
        FOR(j, 1, 4 + 1) {
            FOR(k, 1, 4 + 1) {
                FOR(l, 1, 4 + 1) {
                    if (a[i] == 1 && a[j] == 1 &&
                        a[k] == 2 && a[l] == 2) {
                        return true;
                    }
                }
            }
        }
    }

    return false;
}


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

//    cout << (solve() ? "even" : "odd") << endl;
    cout << (solve() ? "YES" : "NO") << endl;
//    cout << solve() << endl;
//    solve();

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
using namespace std;
int main(){
  string s;
  cin >> s;
  if(s.length()==2)cout << s <<endl;
  else cout << s.at(2) << s.at(1) << s.at(0)<<endl;
}

Measured memory_bytes: 256
def main():
    s = input()
    q = int(input())
    flag = 0
    cnt = 0
    front = []
    back = []

    for i in range(q):
        t = input()
        if len(t) == 1:
            cnt += 1
            if flag == 0:
                flag = 1
            elif flag == 1:
                flag = 0
        else:
            _, a, b = (str(i) for i in t.split())
            if a == "1":
                if flag == 0:
                    front.append(b)
                elif flag == 1:
                    back.append(b)
            elif a == "2":
                if flag == 0:
                    back.append(b)
                elif flag == 1:
                    front.append(b)

    if cnt % 2 == 0:
        front = front[::-1]
        s = ''.join(front) + s + ''.join(back)
    else:
        back = back[::-1]
        s = ''.join(back) + s[::-1] + ''.join(front)

    print(s)

if __name__ == '__main__':
    main()

Measured memory_bytes: 6080
import java.util.*;

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

        int r = sc.nextInt();
        int D = sc.nextInt();
        int x = sc.nextInt();
        
        for(int i = 2001; i <= 2010; i++){
            x = r * x - D;
            System.out.println(x);
        }
    }
}


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

using ll = long long;
// #define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
/***** MAIN *****/
signed main() {
    string s;
    cin >> s;
    if(s.size()%2) {
        cout << "No" << endl;
        return 0;
    }
    bool flag = true;
    REP(i,s.size()-1) {
        if(s[i] == 'h' && s[i +1] == 'i') {
            ++i;
        } else {
            flag = false;
            break;
        }
    }
    if(flag) {
        cout << "Yes";
    } else {
        cout << "No";
    }

    cout << "\n";
    return 0;
}
/***** MAIN *****/


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

def print_l(l):
    print(' '.join(map(str, l)))

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res

n,a,b = l_in()
p,q = divmod(n, a+b)
print(p*a + min(q, a))


Measured memory_bytes: 3064
import math


N,M=map(int,input().split())
s=[]
c=[]
for i in range(M):
    a, b = map(int,input().split())
    s.append(a)
    c.append(b)

found = False

start = pow(10,N-1)
stop = pow(10,N)
if N == 1:
    start = 0

for i in range(start, stop):
    
    i_str = str(i)

    passed = True
    for j in range(M):
        if not i_str[s[j]-1] == str(c[j]):
            passed = False
            break
    if passed:
        found = True
        print(i)
        break

if not found:
    print("-1")


Measured memory_bytes: 3064
n = int(input())

info = [[int(x) for x in input().split()] for _ in range(n)]

def height(point, info):
    cx, cy = point[0], point[1]
    ch = None
    theo_max = float('inf')
    for i,p in enumerate(info):
        x, y, h= p[0], p[1], p[2]
        tmp = abs(cx-x) + abs(cy-y) + h
        if h == 0:
            theo_max = min(theo_max, tmp)
            if ch:
                if theo_max < ch:
                    return None
                    break
        else:
            if not ch:
                ch = tmp
                if theo_max < ch:
                    return None
                    break
            else:
                if ch != tmp:
                    return None
                    break
                if theo_max < ch:
                    return None
                    break
    return ch

t = None
ans = None
for x in range(101):
    if t:
        break
    for y in range(101):
        if t:
            break
        point = (x,y)
        t = height(point, info)
        if t :
            ans = [x,y,t]

print(' '.join(map(str, ans)))


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

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> d(n+1);
	for (int i = 1; i <= n; i++) {
		cin >> d[i];
	}
	sort(d.begin(), d.end());
	bool ans = true;
	if (d[n / 2] == d[n / 2 + 1])ans = false;
	if (ans) {
		cout << abs(d[n / 2 + 1] - d[n / 2]) << endl;
	}
	else {
		cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<algorithm>
using namespace std;
void f(int);
int n,cnt;
int main()
{
	scanf("%d",&n);
	f(0);
	printf("%d\n",cnt);
	return 0;
}

void f(int x)
{
	int i;
	if(x==3) cnt++;
	else {
		for(i=0;i<n;i++){
			f(x+1);
		}
	}
}

Measured memory_bytes: 1708
fn main() {
    let k: usize = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().parse().unwrap()
    };

    let mut check = vec![false; k + 1];
    let mut x = 0;
    let mut count = 0;
    while !check[x] {
        check[x] = true;
        x = (x * 10 + 7) % k;
        count += 1;
        if x == 0 {
            println!("{}", count);
            return;
        }
    }
    println!("-1");
}

Measured memory_bytes: 2980
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
#include <list>
// #include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
typedef long long ll;
typedef double lf;
typedef short int si;


void Main(){
    ll N;
    sll(N);
    ll ans = 0;
    for(ll a=1;a<=N;++a){
        ans += (N-1) / a;
    }

    cout << ans <<endl;
}

int main(){
    Main();
}

Measured memory_bytes: 3260
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#define N 210000
using namespace std;
int n,m,a[N],b[N],ans,num;
struct node{int l,r,c;}A[N];
int solve(int lim)
{
    for(int i=1;i<=m;i++) b[i]=(a[i]>=lim);
    num=0;
    int i=1;
    while(i<m)
    {
        if(b[i]!=b[i+1]) {i++;continue;}
        A[++num].l=i;A[num].c=b[i];
        while(i<m && b[i+1]==b[i]) i++;
        A[num].r=i;i++;
    }
    if(num==0) return b[1];
    A[0].r=0;
    for(int i=1;i<=num;i++)
    {
        int l=A[i-1].r+1,r=A[i].l-1;
        if(l>r) continue;
        int mid=(l+r)/2;
        A[i-1].r=mid;A[i].l=mid+1;
    }
    int l=A[num].r+1,r=m,mid;
    if(l<=r) {mid=(l+r)/2;A[num].r=mid;}
    for(int i=1;i<=num;i++) if(A[i].l<=n && A[i].r>=n) return A[i].c;
}
int main()
{
    scanf("%d",&n);
    m=2*n-1;
    for(int i=1;i<=m;i++) scanf("%d",&a[i]);
    int l=1,r=m;
    while(l<=r)
    {
        int mid=(l+r)/2;
        if(solve(mid)) ans=mid,l=mid+1;
        else r=mid-1;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int a[101][3],b[101];
int main()
{
 	int n,m,i,j,k;
 	cin>>n>>m;
 	for(i=1;i<=m;i++)
 	{
 		for(j=1;j<=2;j++)
 		{
 			cin>>a[i][j];
		 }
	 }
	 for(i=1;i<=m;i++)
 	{
 		for(j=1;j<=2;j++)
 		{
 			//cout<<a[i][j]<<" ";
 			for(k=1;k<=n;k++)
 			{
 				if(a[i][j]==k) b[k]++;
			 }
		 }
		 cout<<endl;
	 }
	 for(i=1;i<=n;i++)
	 {
	 	cout<<b[i]<<endl;
	 }
}
/*
2 5
1 2
2 1
1 2
2 1
1 2
*/

Measured memory_bytes: 256
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
import queue
import copy
import bisect
import heapq


def dfs(s, prev, pre):
  val[s] += Ope[s] + prev
  for i in G[s]:
    if(i == pre):
      continue
    dfs(i, val[s], s)

def bfs(sx, sy, n):
  que = deque([[sy,sx]])
  while que:
    y,x = que.popleft()
    for i,j in D:
      if(x+i<0 or y+j<0 or x+i>W-1 or y+j>H-1):
        continue
      dist = G[y+j][x+i]
      if(G[y+j][x+i] != "X"):
        if(type(G[y+j][x+i]) is str):
          G[y+j][x+i] = G[y][x]+1
          que.append([y+j,x+i])
        elif(dist>G[y][x]+1):
          G[y+j][x+i] = G[y][x]+1
          que.append([y+j,x+i])
        

#X = str(input()).split()
#a = [int(x) for x in input().split()]
#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#V, E, r = map(int, input().split())
#INF = V * 10001

H, W = map(int, input().split())

ans = H*W

if(ans%2==0):
  ans = ans/2
else:
  ans = math.ceil(ans/2)

if(H==1 or W ==1):
  ans = 1

print(int(ans))


Measured memory_bytes: 38764
import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N = int(readline())
l = {readline().decode().rstrip() for _ in range(N)}


print(len(l))


Measured memory_bytes: 31140
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

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

int main() {
	IOS();
	ll a, p;
	cin >> a >> p;
	dump((a * 3 + p) / 2);
	return 0;
}

Measured memory_bytes: 256
# ABC160b


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    def dump(*args):
        sys.stderr.write(str(args))

    x = int(input())
    print(x//500*1000+(x-x//500*500)//5*5)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<iostream>
#include<string>
using namespace std;
 
class Proc{
public:
  string nam;
  int tim;
  Proc(){
    nam = "";
    tim = 0;
  }
};
 
Proc Q[100001];
 
class Queue{
private:
  int fp;
  int rp;
public:
  Queue(){
    fp = 0;
    rp = 0;
  }
  int next(int p) const{
    return (p+1)%100001;
  }
  bool isFull() const{
    return (next(rp) == fp);
  }
  bool isEmpty() const{
    return (rp == fp);
  }
  void push(Proc d){
    if(isFull()){
      return;
    }
    Q[rp] = d;
    rp = next(rp);
  }
  Proc front(){
    if(isEmpty()){
      Proc er;
      er.tim = -1;
      return er;
    }
 
    return Q[fp];
  }
  void pop(){
    if(isEmpty()){
      return;
    }
    fp = next(fp);
  }
};
 
int main(){
  Queue que;
 
  int n,q;
  cin >> n >> q;
 
  for(int i=0;i<n;i++){
    Proc p;
    cin >> p.nam >> p.tim;
 
    que.push(p);
  }
 
  int total_tim = 0;
 
  while(!que.isEmpty()){
    Proc p = que.front();
    que.pop();
 
    if(p.tim <= q){
      total_tim += p.tim;
 
      cout << p.nam << ' ' << total_tim << endl;
    }else{
      total_tim += q;
      p.tim -=q;
 
      que.push(p);
    }
  }
 
  return 0;
}


Measured memory_bytes: 7028
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);

int sh, sm, fh, fm, k;

void solv()
{
    scanf("%d%d%d%d%d", &sh, &sm, &fh, &fm, &k);
    int s = sh * 60 + sm;
    int f = fh * 60 + fm;
    int d = f - s;
    printf("%d\n", max(0, d - k));
}

int main()
{
    #ifdef SOMETHING
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif // SOMETHING
    //ios_base::sync_with_stdio(false);
    //cin.tie(0);
    solv();
    return 0;
}

//while ((double)clock() / CLOCKS_PER_SEC <= 0.9){}


Measured memory_bytes: 3820
#include <iostream>
#include <stdio.h>
#include <set>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
using namespace std;

int each_bits(lli x)
{
	int sum = 0;

	while (x > 0) {
		sum += x % 10;
		x /= 10;
	}

	return sum;
}

int main(void)
{
	lli N; cin >> N;
	int f = each_bits(N);
	if (N%f == 0)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;
#define int ll

void print() {
    cout << endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << ' ';
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

template<class T, class U>
void print(pair<T,U> &p){
    print(p.first, p.second);
}


signed main(){
    ll n; cin >> n;
    vector<ll> r(n);
    rep(i,n) {
        int p;cin >> p;
        p--;
        r[p] = i;
    }
    vector<ll> a(n), b(n);
    int base = 30000;
    rep(i,n){
        a[i] = base * (i + 1);
        b[i] = base * (n - i) + r[i];
    }

    print(a);
    print(b);
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
int main(){
    int A, B, ans = 0;
    cin >> A >> B;
    
    
        if(A > B){
                ans = 2*A -1;
                
    }
    if(A < B){
        ans = 2*B-1;
    }
    if(A == B){
        ans = A + B;
    }
    cout << ans << endl;
}

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

int main() {
  int N, M, K;
  cin >> N >> M >> K;
  vector<int> A(N), B(M);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  for (int i = 0; i < M; i++) cin >> B.at(i);
  vector<long> X(N + 1), Y(M + 1);
  for (int i = 1; i < N + 1; i++) X.at(i) = X.at(i - 1) + A.at(i - 1);
  for (int i = 1; i < M + 1; i++) Y.at(i) = Y.at(i - 1) + B.at(i - 1);
  int ans = 0;
  for (int a = 0; a < N + 1; a++) {
    if (X.at(a) > K) break;
    int tmp = K - X.at(a);
    int b = upper_bound(Y.begin(), Y.end(), tmp) - Y.begin() - 1;
    ans = max(ans, a + b);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 7948
#include <iostream>
#include <string.h>
using namespace std;
int main(void){
    int AliceCard,BobCard;
    string Winner;
    cin>>AliceCard>>BobCard;
    Winner="Alice";
    
    
    if(AliceCard==BobCard){
        Winner="Draw";
    }else if((BobCard>AliceCard&&AliceCard!=1)||BobCard==1){
        Winner="Bob";
    }
    cout<<Winner<<endl;
    
    
    
}


Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr = input.trim().split("\n");
var n= arr.shift()-0;
var xyz = [];
for(var i=0;i<=n;i++)xyz[i]=[0,0,0];
var x = arr.shift().split(" ").map(Number);
var y = arr.shift().split(" ").map(Number);
var z = arr.shift().split(" ").map(Number);
x.shift();
y.shift();
z.shift();
x.forEach(v=>{
   xyz[v][0]=1;
});
y.forEach(v=>{
   xyz[v][1]=1;
});
z.forEach(v=>{
   xyz[v][2]=1;
});
xyz.shift();
var cnt = 0;
xyz.forEach(v=>{
   if(v[0]==0 && v[2]==1)cnt++;
   else if(v[1]==1 && v[2]==1)cnt++;
});
console.log(cnt);


Measured memory_bytes: 17400
#include<iostream>
#include<vector>
#include<cinttypes>
#include<algorithm>
#include<numeric>
#include<iterator>
#include<tuple>
#include<functional>
#include<set>

using si32 = std::int32_t;
using ui32 = std::uint32_t;


int main() {

	si32 n;
	std::cin >> n;

	std::vector<std::vector<si32>> graph( n ), cost( n, std::vector<si32>( n, -1 ) );

	for( si32 i{}; i < n; ++i )
	{
		for( si32 j{}; j < n; ++j )
		{
			si32 t; std::cin >> t;

			if( t < 0 || i == j )
				continue;

			graph[i].emplace_back( j );
			graph[j].emplace_back( i );

			cost[i][j] = cost[j][i] = t;
		}
	}


	//	std::queue<>

		//edges
	std::vector<std::pair<si32, si32>> mst;
	mst.reserve( n - 1 );

	for( const auto&e : graph.front() )
		if( mst.empty() )
			mst.emplace_back( 0, e );
		else
			if( cost[0][e] < cost[ mst[0].first ][ mst[0].second ] )
				mst[0] = std::make_pair( 0, e );

	//std::cout << mst[0].first << " " << mst[0].second << "\n";


	std::set<si32> mst_vertices;
	for( const auto&v : { mst[0].first, mst[0].second } )
		mst_vertices.emplace( v );


	while( mst.size() < static_cast<decltype(mst.size())>(n - 1) )
	{
		
		si32 cost_t = 20000;
		std::pair<si32, si32> edge{ 0,0 };
		
		for( const auto& mv : mst_vertices )
		{
			for( const auto& gv : graph[mv] )
				if( mst_vertices.find( gv ) == mst_vertices.end() )
					if( cost[mv][gv] < cost_t )
					{
						edge = std::make_pair( mv, gv );
						cost_t = cost[mv][gv];
					}
		}

		mst_vertices.emplace( edge.second );
		mst.emplace_back( edge );
		/*
		std::cout << edge.first << " " << edge.second << "\n";
		std::cout<<"---\n"
			<< mst.size() << ":\n";
		for( const auto&e : mst )
			std::cout << e.first << " " << e.second << "\n";
		std::cout << "------\n";
		*/
		
	}
	
	ui32 ans{};
	for( const auto& e : mst )
	{
		ans += cost[e.first][e.second];
//		std::cout << e.first << " " << e.second << " " << cost[e.first][e.second] << " " << ans << "\n";
	}

	std::cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin>>n;
    cout<<n*n*n<<endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=2000010;
const ll mod=1e9+7;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; }
    mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { mint res(*this); return res+=a; }
    mint operator-(const mint a) const { mint res(*this); return res-=a; }
    mint operator*(const mint a) const { mint res(*this); return res*=a; }
    mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; }
    // for prime mod
    mint inv() const { return pow(mod-2); }
    mint& operator/=(const mint a) { return (*this) *= a.inv(); }
    mint operator/(const mint a) const { mint res(*this); return res/=a; }
};

vector<ll> inv,fact,invfact;
void mod_build(int n){  
  fact.resize(n+1); inv.resize(n+1); invfact.resize(n+1);
  fact[0]=inv[0]=invfact[0]=1; inv[1]=1;
  rep(i,n){
    fact[i+1]=fact[i]*(i+1)%mod;
    if(i>0)inv[i+1]=mod-inv[mod%(i+1)]*(mod/(i+1))%mod;
    invfact[i+1]=invfact[i]*inv[i+1]%mod;
  }
}
ll perm(int n,int k){ if(n<0||k<0||k>n){ return 0; } else { return fact[n]*invfact[n-k]%mod; } }
ll comb(int n,int k){ if(n<0||k<0||k>n){ return 0; } else { return (fact[n]*invfact[n-k]%mod)*invfact[k]%mod; }}
ll modpow(ll n,ll k){
  k%=mod-1; if(k<0)k+=mod-1;
  ll ret=1; while(k){ if(k&1)ret=ret*n%mod; n=n*n%mod; k>>=1; }
  return ret;
}
ll modinv(ll a){ return modpow(a, mod-2); }

int main(){
  mod_build(mx);
  ll a,b,c,d;
  cin >> a >> b >> c >> d;
  mint ans = 0;
  ans += comb(c+1+d+1,c+1); 
  ans -= comb(c+1+b,c+1);
  ans -= comb(a+d+1,d+1);
  ans += comb(a+b,a);
  cout << ans.x << endl;
  return 0;
}


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

using namespace std;

const int maxn=1e4+5;

typedef long long ll;

const ll mod=1e9+7;

char s[maxn];

int main(){
	int n;
	scanf("%d",&n);
	scanf("%s",s);
	int ans=0;
	for(int i=1;i<n-1;i++){
		if(s[i-1]=='A'&&s[i]=='B'&&s[i+1]=='C') ans++;
	}
	printf("%d",ans);
	return 0;
}

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

int n, k;
const long MAX = 100000;
long T[MAX];

int check(long p){
	int i = 0;
	for (int j = 0; j < k; j++){
		long s = 0;
		while (s + T[i] <= p){
			s += T[i];
			i++;
			if (i == n) return n;
		}
	}
	return i;
}

int solve(){
	long left = 0;
	long right = 100000 * 10000;
	long mid;
	while (right - left > 1){
		mid = (left + right) / 2;
		int v = check(mid);
		if (v >= n) right = mid;
		else left = mid;
	}
	return right;
}

main(){
	cin >> n >> k;
	for (int i = 0; i < n; i++) cin >> T[i];
	long ans = solve();
	cout << ans << endl;
}

Measured memory_bytes: 1940