akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const int MAX=1e5+5;
const int MOD=1e9+7;

int extgcd(int a,int b,int& x, int& y){
	int d=a;
	if(b!=0){
		d = extgcd(b, a%b, y, x);
		y -= (a/b) * x;
	}
	else{
		x = 1; y = 0;
	}
	return d;
}
int mod_inv(int a,int m){
	int x,y;
	extgcd(a,m,x,y);
	return (m+x%m)%m;
}

//prime[i]はi番目の素数
//isp[j]はjが素数か判定
//エラトステネスの篩を用いる
int prime[MAX];
bool isp[MAX];
//int a[MAX]




int main(){
	//入力
	int N,m;
	cin>>N>>m;
  	int M=sqrt(m);
//  	cout<<M<<endl;
	
	int p = 0;
	//初期化
	for(int i=0;i<=M;i++)
		isp[i]=true;
	isp[0]=isp[1]=false;
	//2以上で素数ならふるい落とす
	for(int i=2;i<=M;i++){
		if(isp[i]){
			p++;
			prime[p]=i;
			for(int j=2*i;j<=M;j+=i) isp[j]=false;
		}
	}
	lli ans=1;
  	int n=1;
	rep1(i,p){
		int a=0;
      	int X=m;
		int pr=prime[i];
		while(X%pr==0){
			a++;
			X/=pr;
		}
      	n*=pow(pr,a);
		//(N+a-1)Caを掛ける
//      	cout<<a<<" ";
		rep1(k,a){
			ans=(ans*((lli)N+k-1))%MOD;
			lli inv=(lli)mod_inv(k,MOD);
			ans=(ans*inv)%MOD;
		}
//      	cout<<ans<<endl;
	}
//  	cout<<ans<<" "<<m<<endl;
  	if(m!=n){
		ans=(ans*N)%MOD;
    }
	cout<<ans;
}

Measured memory_bytes: 384
import java.util.Scanner;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        String ans = "";
        if (N == 0) {
            System.out.println("0");
        }
        while (true) {
            if (N == 0) {
                char[] a = ans.toCharArray();
                for (int i = ans.length() - 1; i >= 0; i--) {
                    System.out.print(a[i]);
                }
                return;
            }
            if (N % 2 == 1 || N % 2 == -1) {
                ans += "1";
                N = (N - 1) / -2;
            } else {
                ans += "0";
                N = N / -2;
            }
        }
    }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#include "string"

vector<int> z_function(string s) {
	int n = (int) s.length();
	vector<int> z(n);
	for (int i = 1, l = 0, r = 0; i < n; ++i) {
		if (i <= r)
			z[i] = min (r - i + 1, z[i - l]);
		while (i + z[i] < n && s[z[i]] == s[i + z[i]])
			++z[i];
		if (i + z[i] - 1 > r)
			l = i, r = i + z[i] - 1;
	}
	return z;
}

int32_t main() {
	boost;
	int n;
	cin >> n;
	string s;
	cin >> s;
	int ans = 0;
	for(int i = 0; i < n; i++) {
		string ns = s.substr(i);
		auto pi = z_function(ns);
		for(int j = 0; j < pi.size();j++) {
			int cur = min(j, pi[j]);
			ans = max(ans, cur);	
		}
	}
	cout << ans << endl;
}

	

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

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

using namespace std;

int main(){
	string s; cin>>s;
	int n=s.length()/2;
	for(int i=1;;i++) if(s.substr(0,n-i)==s.substr(n-i,n-i)) { cout<<2*(n-i)<<endl; break; }
	return 0;
}


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

typedef long long ll;

const int N = 305;

int n, K, mod, C[N][N], S[N][N], F[N][N];

int main()
{
	scanf("%d%d%d", &n, &K, &mod);
	for (int i = 0; i <= max(n, K); i++)
	{
		C[i][0] = 1;
		for (int j = 1; j <= i; j++)
			C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
	}
	F[0][0] = 1;
	for (int i = K; i >= 0; i--)
	{
		F[1][i] = 1;
		S[1][i] = (S[1][i + 1] + 1) % mod;
	}
	for (int i = 2; i <= n + 1; i++)
	{
		for (int j = 0; j <= K; j++)
			for (int a = 1; a < i; a++)
				F[i][j] = (F[i][j] + (ll)F[i - a][j] * S[a][j + 1] % mod * C[i - 2][a - 1] % mod) % mod;
		for (int j = K; j >= 0; j--)
			S[i][j] = (S[i][j + 1] + F[i][j]) % mod;
	}
	printf("%d\n", F[n + 1][0]);
	return 0;
}

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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

#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(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int n;
	cin >> n;
	cout << 800*n - 200*(n/15) << "\n";
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))
const int MOD = 1e9 + 7;

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	vi cnt(65, 0);
	rep(i, n) rep(j, 60) if(a[i] & (1LL << j)) cnt[j]++;
	ll ans = 0;
	rep(i, n) rep(j, 60) if(a[i] & (1LL << j)) (ans += ((ll)((1LL << j) % MOD) * (ll)(n - cnt[j]))) %= MOD;
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 2560
#import<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long LL;
LL i,j,k,m,n,a[200040];
string s;
main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	cout<<10-n/200;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 1000000007
#define MAX 100

int main(){
  string S;
  cin>>S;
  int N=S.size();
  int g_sum=0;
  int p_sum=0;
  int ans=0;
  for(int i=0;i<N;i++){
    if(g_sum==p_sum){
      if(S.at(i)=='p'){
        ans--;
      }
      g_sum++;
    }else{
      if(S.at(i)=='g'){
        ans++;
        p_sum++;
      }else{
        p_sum++;
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <set>
using namespace std;
int main()
{
    // 整数の入力
    int N;
    cin >> N;
    vector<int> numbersKeyIndexValue(N + 1, -1);
    multiset<int> workingSet;

    for (int i = 1; i <= N; ++i)
    {
        int num;
        cin >> num;
        numbersKeyIndexValue.at(num) = i;
    }
    workingSet.insert(0);
    workingSet.insert(0);
    workingSet.insert(N + 1);
    workingSet.insert(N + 1);

    long long result = 0;
    for (int num = N; num > 0; num--)
    {
        int index = numbersKeyIndexValue.at(num);
        if (index == -1)
        {
            continue;
        }
        auto ite = workingSet.lower_bound(index);
        int rightUpperIn = *ite;
        int rightUpperOut = *++ite;
        --ite;
        int leftUpperIn = *--ite;
        int leftUpperOut = *--ite;
        result += 1ll * num * (leftUpperIn - leftUpperOut) * (rightUpperIn - index);
        result += 1ll * num * (index - leftUpperIn) * (rightUpperOut - rightUpperIn);
        workingSet.insert(index);
    }
    cout << result;

    return 0;
}

Measured memory_bytes: 5376
from numpy import cumsum

N = int(input())
L = list(map(int, input().split()))

cum = list(cumsum(L))

ans = 10 ** 10
for c in range(N-1):
    l = cum[c]
    r = cum[-1] - l
    ans = min(ans, abs(r - l))

print(ans)


Measured memory_bytes: 32724
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long n,m;
inline long long gcd(long long x,long long y)
{
    if(y==0) return x;
    return gcd(y,x%y);
}
int main()
{
    scanf("%lld%lld",&n,&m);
    printf("%lld\n",3*(n-gcd(n,m)));
    return 0;
}


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


int main(){
    int n,x;
    cin >> n >> x;
    int s = 0;
    vector<int> m(n);
    rep(i,n){
        cin >> m[i];
        s += m[i];
    }
    sort(m.begin(),m.end());
    x -= s;
    int r = x/m[0];
    cout << n + r << endl;
}

Measured memory_bytes: 256
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int n,i;cin>>n>>i;
    cout<<n-i+1<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


Measured memory_bytes: 256
/*input
8
10 9 8 7 6 5 4 3
*/

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
#define chmax(x, y) x = max(x, y)

const int K = 43;

ll dp[K][2][2];

int main() {
    int n;
    cin >> n;
    vector<ll> _a(n);
    rep(i, n) cin >> _a[i];
    ll x = 0;
    rep(i, n) x ^= _a[i];
    ll a = _a[0], b = _a[1];
    x ^= a^b;
    ll s = a+b;

    vector<int> xs, ss, as;

    rep(i, K) rep(j, 2) rep(k, 2) dp[i][j][k] = -1;

    dp[0][0][0] = 0;
    ll v = 1; 
    rep(i, K-1) { // num of digits
        int cx = x&1;
        int cs = s&1;
        int ca = a&1;
        rep(j, 2) rep(k, 2) {
            if (dp[i][j][k] == -1) continue;
            rep(na, 2) rep(nb, 2) {
                int ni = i+1;
                int nj = 0, nk = k;
                if ((na^nb) != cx) continue;
                int ns = na+nb+j;
                if(ns%2 != cs) continue;
                if (ns >= 2) nj = 1;
                if (ca < na) {
                    nk = 1;
                }
                else if (ca == na) {
                    nk = k;
                }
                else {
                    nk = 0;
                }
                chmax(dp[ni][nj][nk], dp[i][j][k]|(v*na));
            }
        }
        x >>= 1;
        s >>= 1;
        a >>= 1;
        v <<= 1;
    }

    a = dp[K-1][0][0];
    if (a == -1 || a == 0) {
        puts("-1");
        return 0;
    }
    ll ans = _a[0]-a;
    cout << ans << endl;
}

Measured memory_bytes: 3576
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    int W, H, x, y;
    cin >> W >> H >> x >> y;
    
    double area = double(W) * double(H) / 2;
    
    bool flag = false; 
    if(x+x==W && y + y == H) flag = true;
    if(flag) printf("%.9f %c", area, '1');
    else printf("%.9f %c", area, '0');
}


Measured memory_bytes: 256
s=input();mod=10**9+7
dp = [[0]*13for _ in range(len(s)+1)]
dp[0][0]=1
for i in range(len(s)):
  if s[i]=='?':
    for j in range(13):
      for k in range(10):
        dp[i+1][(10*j+k)%13] += dp[i][j]
        dp[i+1][(10*j+k)%13] %= mod
  else:
    for j in range(13):
      dp[i+1][(10*j+int(s[i]))%13] += dp[i][j]
      dp[i+1][(10*j+int(s[i]))%13] %= mod
print(dp[len(s)][5])

Measured memory_bytes: 61788
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/











int N; double P[3010];
double dp[3030][3030];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) cin >> P[i];

    dp[0][0] = 1;
    rep(i, 0, N) rep(omote, 0, N + 1) {
        dp[i + 1][omote] += dp[i][omote] * (1 - P[i]);
        dp[i + 1][omote + 1] += dp[i][omote] * P[i];
    }

    double ans = 0;
    rep(omote, 0, N + 1) if (N - omote < omote) ans += dp[N][omote];
    printf("%.10f\n", ans);
}


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

int main()
{
	int a, b;
	cin >> a >> b;

	set<int> S;
	
	S.insert(1);
	S.insert(2);
	S.insert(3);

	S.erase(a);
	S.erase(b);

	auto itr = S.begin();
	cout << *itr << endl;

	return 0;
}

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

#define M 48828125
#define FOUND 1
char H[M];

int getChar( char ch )
{
	if( ch == 'A') {
		return 1;
	} else if( ch == 'C') {
		return 2;
	} else if( ch == 'G') {
		return 3;
	} else if( ch == 'T') {
		return 4;
	}
	return 0;
}

int getKey( char str[] )
{
	int i;
	int key = 0, base = 1;
	for ( i=0; '\0'!=str[i]; i++ ) {
		key += base*( getChar( str[i] ) );
		base *= 5;
	}
	return key;
}

int find( char str[] )
{
	if( FOUND == H[ getKey( str ) ] ) {
		return FOUND;
	} else {
		return 0;
	}
}

void insert( char str[] )
{
	H[ getKey( str ) ] = FOUND;
	return;
}

int main() 
{

	int i, n;
	char str[14], com[9];
	
	scanf( "%d", &n );
	for ( i=0; i<n; i++ ) {
		scanf( "%s %s", com, str );
		if ( com[0] == 'i' ){
			insert( str );
		} else {
			if( find( str ) ){
				printf("yes\n");
			} else {
				printf("no\n");
			}
		}
	}
    return 0;
}

Measured memory_bytes: 10080
S = input()
alpha = "abcdefghijklmnopqrstuvwxyz"

if len(S) != 26:
    for i in alpha:
        if i not in S:
            print(S+i)
            exit()

for i in range(24, -1, -1):
    for j in range(25, i, -1):
        if S[i] < S[j]:
            print(S[:i]+S[j])
            exit()
print(-1)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const long double PI = (acos(-1));
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define sc(x) scanf("%d",&x)
#define scll(x) scanf("%lld",&x)
int main(){
    int n, m, q, cnt;
    ll tmp, ans = 0;
    sc(n), sc(m), sc(q);
    vector<int> v, a(q), b(q), c(q), d(q);
    rep(i, 0, q) sc(a[i]), sc(b[i]), sc(c[i]), sc(d[i]);
    rep(i, 0, 1<<(n+m-1)){
        v.clear(); cnt = 1; tmp = 0;
        rep(j, 0, n+m-1){
            if (i & (1<<j)) v.push_back(cnt);
            else cnt++;
        }
        if (v.size() != n) continue;
        rep(j, 0, q){
            if (v[a[j]-1]+c[j] == v[b[j]-1]) tmp += d[j];
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3688
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int n,a,b;cin>>n>>a>>b;
	cout << min(a,b) << " " << max(a + b - n,0) << endl;
	
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
	const int mod=1000000007;
	const long o=1;
	static void Main(){
		Sc sc=new Sc();
		int n=sc.I,ans=0;
		int[][] a=new int[n][];
		for(int i = 0;i<n;i++) {
			a[i]=new int[]{sc.I,i};
		}
		Array.Sort(a,(u,v)=>u[0]-v[0]);
		for(int i = 0;i<n;i++) {
			if(i%2!=a[i][1]%2){ans++;}
		}
		Console.WriteLine("{0}",ans/2);
	}
}

class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
}

Measured memory_bytes: 22236
#include <iostream>
#include <cstdlib>

using namespace std;

struct pa{
  int s;
  int v;
};

int main(int argc, char **argv)
{
  int n, m, t;
  pa *a, p;
  while(1){
    cin >> n >> m;
    if(n == 0 && m == 0){
      break;
    }
    a = (pa *)calloc(m+1, sizeof(pa));

    for(int i = 1; i <= m; i++){
      a[i].s = i;
    }

    for(int i = 1; i <= n; i++){
      for(int j = 1; j <= m; j++){
	cin >> t;
	if(t){
	  a[j].v++;
	}
      }
    }

    for(int i = m; i >= 1; i--){
      for(int j = 2; j <= i; j++){
	if(a[j-1].v < a[j].v){
	  p = a[j-1];
	  a[j-1] = a[j];
	  a[j] = p;
	}
      }
    }

    cout << a[1].s;
    for(int i = 2; i <= m; i++){
      cout << " " << a[i].s;
    }
    cout << endl;

    free(a);
  }

  return 0;
}

Measured memory_bytes: 904
#include <stdio.h>
int main (){
	int a,b;
	scanf ("%d %d",&a,&b);
	int i,j;
	i=a%2;
	j=b%2;
	if ((i==0&&j==0)||(i==1&&j==0)||(i==0&&j==1)){
		printf ("Even");
	}
	else {
		printf ("Odd");
	}
	
	
	
	
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
const  int N=2e5+10;
const int mod = 998244353;
int arr[N];
ll num[N];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&arr[i]);
        num[arr[i]]++;
    }
    ll ans = 0;
    for(int i=1;i<=n;i++){
        ans += num[i]*(num[i]-1)/2;
    }
    for(int i=1;i<=n;i++){
        ll x = ans - (num[arr[i]] - 1);
        printf("%lld\n",x);
    }
    return 0;
}

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

int main() {
	UL N, K; cin >> N >> K;
	UL A[1000]; rep(i, N) cin >> A[i];
	sort(A, A + N);
	UL ans = 0;
	rep(i, K)ans += A[i];
	cout << ans;

	return 0;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define sanyes ios_base::sync_with_stdio(0), cout.tie(0); cin.tie(0);
#define llong long long
#define pb push_back
#define bpc __builtin_popcount

const llong mxn = 1e5 + 7;
const llong mod = 998244353;
const llong inf = 1e18 + 9;

using namespace std;

string s;
llong P[1001][1001];

llong n, l, dp[mxn], h[mxn];

int main (){
    cin >> n;
    for (int i = 1; i <= n; i ++){
        cin >> h[i];
    }dp[1] = dp[0] = 0;
    dp[2] = abs(h[1] - h[2]);
    for (int i = 3; i <= n; i ++){
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
    }cout << dp[n];
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,int> pdi;
typedef pair<double,double> pdd;
typedef pair<double,ll> pdl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<pdd> vdd;
typedef vector<pdi> vdi;
typedef vector<pdl> vdl;
#define fi first
#define se second
const ll INFLL=LLONG_MAX;
const int INF=INT_MAX;
const ll MAXLL=0x3f3f3f3f3f3f3f3f;
const int MAX=0x3f3f3f3f;
#define eb emplace_back
#define emp emplace
#define mp(a,b) make_pair(a,b)
template<class T> using min_heap=priority_queue<T,vector<T>,greater<T> >;
template<class T>
void sort(vector<T>& v){
	sort(v.begin(),v.end());
}
template <class T, class U>
void sort(vector<T>& v,U func){
	sort(v.begin(),v.end(),func);
}
template<class T>
void rsort(vector<T>& v){
	sort(v.rbegin(),v.rend());
}
template <class T>
int lb_index(vector<T>& v,T k){
	return lower_bound(v.begin(),v.end(),k)-v.begin();
}
template <class T>
int ub_index(vector<T>& v,T k){
	return upper_bound(v.begin(),v.end(),k)-v.begin();
}
template<class T>
bool is_sorted(vector<T>& v){
	return is_sorted(v.begin(),v.end());
}
template<class T>
bool sorted(vector<T>& v){
	return is_sorted(v);
}
int n;
map<pii,ll>mp;
ll bm(ll b,ll p,ll m){
	if(p==0)return 1%m;
	if(p&1){
		return (b%m*bm(b,p-1,m))%m;
	}
	ll i=bm(b,p>>1,m);
	return i*i%m;
}
int st[200000];
int f(int x){
	if(x==0)return 0;
	if(st[x])return st[x];
	int cnt=0;
	for(int i=0;(1<<i)<=x;i++){
		if(x&(1<<i))cnt++;
	}
	return st[x]=1+f(x%cnt);
}
void solve(){
	string s;
	cin>>n>>s;
	int mod=0;
	for(int i=0;i<n;i++){
		mod+=(s[i]=='1');
	}
	for(int i=0;i<=n;i++){
		mp[{i,mod+1}]=bm(2,i,mod+1);
		if(mod>1)mp[{i,mod-1}]=bm(2,i,mod-1);
	}
	int add=0,minus=0;
	for(int i=0;i<n;i++){
		if(s[i]=='1'){
			add=(add+mp[{n-i-1,mod+1}])%(mod+1);
			if(mod>1)minus=(minus+mp[{n-i-1,mod-1}])%(mod-1);
		}
	}
	for(int i=0;i<n;i++){
		if(s[i]=='1'){
			if(mod==1){
				cout<<0<<'\n';
				continue;
			}
			s[i]='0';
			cout<<1+f(((minus-mp[{n-i-1,mod-1}])%(mod-1)+(mod-1))%(mod-1))<<'\n';
			s[i]='1';
		}
		else{
			s[i]='1';
			cout<<1+f(((add+mp[{n-i-1,mod+1}])%(mod+1)+(mod+1))%(mod+1))<<'\n';
			s[i]='0';
		}
	}
}

int main(){
	ios::sync_with_stdio(0);
	int numberofsubtestcases=1;
//	cin>>numberofsubtestcases;
	while(numberofsubtestcases--){
		solve();
	}
}

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

int main() {
  int N, Nb,  x = 0, y = 0;
  cin >> N;
  Nb = N;
  for (int i = 8; i >= 0; i--) {
   x = N / pow(10, i);
   N -= x * pow(10, i);
   y += x;
  	}
  
  if(Nb % y == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main() {
  double D[80]; int d=0;
  char inbuf[99];
  while (gets(inbuf)) {
    char *tp = strtok(inbuf, " \n");
    while (tp!=NULL){
      if(!strcmp(tp, "+"))D[d-2]+=D[--d];
      else if(*tp=='*')D[d-2]*=D[--d];
      else if(!strcmp(tp, "-"))D[d-2]-=D[--d];
      else if(*tp=='/')D[d-2]/=D[--d];
      else D[d++]=atof(tp);
      tp = strtok(NULL, " \n");
    }
    printf("%.6lf\n",D[--d]);
  }
  return 0;
}

Measured memory_bytes: 580
n = int(input())
values = list(map(int, input().split()))

kabu = 0
money = 1000
for i in range(n-1):
    if values[i] < values[i+1]:
        kabu = money // values[i] 
        money += (values[i+1] - values[i]) * kabu
        
print(money)

Measured memory_bytes: 9144
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
char s[20005],t[20005];
int a[20005],b[20005],ta[20005],tb[20005];
int c1,c2,n;
int read()
{
	char c=getchar();
	int res=0;
	while(c<'0'||c>'9') c=getchar();
	while(c>='0'&&c<='9') res=(res<<1)+(res<<3)+(c^48),c=getchar();
	return res;
}
int main()
{
	n=read();
	scanf("%s",s+1);scanf("%s",t+1);
	if(s[1]=='1') ta[++c1]=0;
	for(int i=1;i<n;i++) if(s[i]!=s[i+1]) ta[++c1]=i;
	if(s[n]=='1') ta[++c1]=n;
	if(t[1]=='1') tb[++c2]=0;
	for(int i=1;i<n;i++) if(t[i]!=t[i+1]) tb[++c2]=i;
	if(t[n]=='1') tb[++c2]=n;
	for(int i=1;i<=c1;i++) a[i+c2]=ta[i];
	for(int i=c1+c2+1;i<=c1+c2+c2;i++) a[i]=n;
	int ans=0x3f3f3f3f;
	for(int i=0;i<=c1+c2;i+=2)
	{
		for(int j=0;j<=i;j++) b[j]=0;
		for(int j=1;j<=c2;j++) b[i+j]=tb[j];
		for(int j=i+c2+1;j<=c1+c2+c2;j++) b[j]=n;
		int sum=0;
		for(int j=0;j<=c1+c2+c2;j++) sum+=abs(a[j]-b[j]);
		ans=min(ans,sum);
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 3980
# frozen_string_literal: true

n, k = gets.split.map(&:to_i)
p = gets.split.map(&:to_i).unshift(0)
c = gets.split.map(&:to_i).unshift(0)
d = []
(1..n).each do |i|
  g = {}
  ni = i
  loop do
    break if g[ni] || d.select { |e| e[ni] }.size.positive?

    g[ni] = true
    ni = p[ni]
  end
  d.push g.dup if g.size.positive?
end

cs = []
d.each do |dg|
  css = []
  dg.each_key do |i|
    css.push c[i]
  end
  cs.push css
end

def findmax(ary, k)
  k = ary.size if k > ary.size || k.zero?
  max = -1 * 10**14
  a = ary + ary[0..(k - 1)]
  (0..(ary.size - 1)).each do |i|
    s = 0
    (0..(k - 1)).each do |j|
      s += a[i + j]
      max = s if max < s
    end
  end
  max
end
m = []
cs.each do |cc|
  if cc.sum <= 0
    m.push findmax(cc, k)
  else
    m.push [cc.sum * (k / cc.size) + ((k % cc.size).zero? ? 0 : findmax(cc, k % cc.size)), cc.sum * (k / cc.size - 1) + findmax(cc, k)].max
  end
end
puts m.max


Measured memory_bytes: 38456
#include <iostream>

using namespace std;

int main(){
    int N;
    cin >> N;
    long long a;
    int num = 0;
    for(int i = 0; i < N; i++){
        cin >> a;
        while(a % 2 == 0){
            a /= 2;
            num++;
        }
    }
    cout << num << endl;
    return 0;
}


Measured memory_bytes: 256
/* You lost the game. */
 
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cfloat>
#include <numeric>
#include <cassert>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <vector>
//#include <pthread.h>
 
#define fin(i,n) for (int i = (L) 0; i < n; i++)
#define fin2(i,a,b) for (int i = a; i < b; i++)
 
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define mod 1000000007
#define PI 3.1415926535897932384626
#define EXP1 2.718281828459045
 
#define si(n) scanf("%d", &n)
#define sii(n,m) scanf("%d %d", &n, &m)
#define siii(n,m,k) scanf("%d %d %d", &n, &m, &k)
#define sl(n) scanf("%lld", &n)
#define sll(n,m) scanf("%lld %lld", &n, &m)
#define slll(n,m,k) scanf("%lld %lld %lld", &n, &m, &k)
#define sd(n) scanf("%lf", &n)
#define sdd(n,m) scanf("%lf %lf", &n, &m)
#define sddd(n,m,k) scanf("%lf %lf %lf", &n, &m, &k)
#define sc(c) scanf("%c", &c)
#define ss(s) scanf("%s", s)
#define sai(t,n) fin(i,n) { scanf("%d", &t[i]); }
#define sal(t,n) fin(i,n) { scanf("%lld", &t[i]); }
#define sad(t,n) fin(i,n) { scanf("%lf", &t[i]); }
 
#define pc(n) printf("%c\n", n)
#define ps(s) printf("%s\n", s)
#define pi(n) printf("%d\n", n)
#define pii(n,m) printf("%d %d\n", n, m)
#define pl(n) printf("%lld\n", n)
#define pll(n,m) printf("%lld %lld\n", n, m)
#define plll(n,m,k) printf("%lld %lld %lld\n", n, m, k)
#define pd(n) printf("%lf\n", n)
#define pdd(n,m) printf("%lf %lf\n", n, m)
#define pai(t,n) fin(i,n) { printf("%d ", t[i]); } printf("\n")
#define pal(t,n) fin(i,n) { printf("%lld ", t[i]); } printf("\n")
#define pad(t,n) fin(i,n) { printf("%lf ", t[i]); } printf("\n")

#define OK ps("OK")
#define OK1 ps("OK1")
#define OK2 ps("OK2")
 
#define L long long int
#define D double
#define C char
#define PII pair<int, int>
#define VPII vector<PII>
#define VL vector<L>
#define VI vector<int>
#define VVI vector<VI>
#define VD vector<D>
#define VVD vector<VD>
#define VVPII vector<VPII>
#define VC vector<C>
 
using namespace std;

PII test(VI a, int n) {
    //pai(a, n);
    //pii(n, a[n]);
    if (n+1 == a.size()) { return mp(1+(a[n]%2), 3); }
    int t = a[n];
    int r1, r2;
    tie(r1, r2) = test(a, n+1);
    int s1 = 0, s2 = 0;
    if (a[n] % 2 == 0) { s1 += r2; } else { s1 += r1; }
    if ((a[n]+1) % 2 == 0) { s1 += r2; } else { s1 += r1; }
    if ((a[n]-1) % 2 == 0) { s1 += r2; } else { s1 += r1; }
    s2 = 3*r2;
    return mp(s1, s2);
}

int main() {
    int n, a[100];
    si(n);
    sai(a, n);
    vector<int> b(n);
    fin(i, n) { b[i] = a[i]; }
    pi(test(b, 0).first);
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  long long int x=1;
  long long int y=pow(10, 9)+7;
  for(int i=1; i<N+1;++i){
    x = (x*i)%y;
  }

  cout <<x <<endl;
  }

Measured memory_bytes: 256
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#define NUM 4

int main(void){
	long long int n, i, pro, cnt, sum;
	while(1){
		scanf("%lld", &n);
		if(n==-1) break;
		pro = 1;
		cnt = 0;
		while(pro<=n){
			pro *= NUM;
			cnt++;
		}
		pro /= NUM;
		sum = 0;
		while(n){
			sum += (int)pow(10,(double)cnt-1) * (n / pro);
			n %= pro;
			pro /= NUM;
			cnt--;
		}
		printf("%lld\n", sum);
	}
	return 0;
}

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

a_sum = [0]*N
x = 0

for i in range(N):
    x += a[i]
    a_sum[i] = x
    
ans = 10**18+1
sum_a = sum(a)

for i in range(N-1):
    ans = min(ans,abs(sum_a-2*a_sum[i]))
    
print(ans)

Measured memory_bytes: 24952
#include<stdio.h>
int main()
{
    int N;
    scanf("%d",&N);
        if(100>N>999)
            printf("\n");
        else if(N>=100&&N<=111)
            printf("111");
        else if(N>111&&N<=222)
            printf("222");
        else if(N>222&&N<=333)
            printf("333");
        else if(N>333&&N<=444)
            printf("444");
        else if(N>444&&N<=555)
            printf("555");
        else if(N>555&&N<=666)
            printf("666");
        else if(N>666&&N<=777)
            printf("777");
        else if(N>777&&N<=888)
            printf("888");
        else if(N>888&&N<=999)
            printf("999");

        return 0;
}


Measured memory_bytes: 1732
#include<iostream>
using namespace std;
int main(){
int n;
  cin>>n;
  string s,t;
  cin>>s;
  cin>>t;
  string k="";
  for(int i=0;i<n;i++){
  	k+=s[i];
    k+=t[i];
  }
  cout<<k;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll r, g, b; cin >> r >> g >> b;
    ((r*100 + g*10 + b)%4 == 0) ? YES() : NO();
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

vector<pair<ll, int>> factorize(ll n){
    vector<pair<ll, int>> ans;
    if(n == 1) return ans;
    for(ll i = 2; i*i <= n; i++){
        int cnt = 0;
        while(n%i == 0){
            cnt++;
            n /= i;
        }
        if(cnt) ans.eb(i, cnt);
    }
    if(n != 1) ans.eb(n, 1);
    return ans;
}

void Main(){
    int n; cin >> n;
    map<int, ll> cnt;
    rep(i, n) {
        int a; cin >> a;
        for(auto [p, e] : factorize(a)){
            cnt[p]++;
        }
    }
    ll mx = 0;
    for(auto [k, v] : cnt){
        mx = max(mx, v);
    }
    if(mx == n) cout << "not coprime" << endl;
    else if(mx <= 1) cout << "pairwise coprime" << endl;
    else cout << "setwise coprime" << endl;
    return;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 8484
#include <stdio.h>
int main(void){
  int i,n = 0;
  char w[11], t[1001];
  scanf("%s", w);
  do{
    scanf("%s",t);
    if(!strcmp(t,"END_OF_TEXT")) break;
      for(i=0;t[i]!='\0';i++)
        if(t[i]<91) t[i] += 32;
    if( !strcmp(w,t) ) n++;
  }while(1);
  printf("%d\n",n);
  return 0;
}


Measured memory_bytes: 2056
import java.util.Scanner;

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

        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0;i < a.length;i++){
            a[i] = sc.nextInt();
        }
        
        for(int i = n-1;i >= 0;i--){
            System.out.print(a[i]);

            if(i != 0){
                System.out.print(" ");
            }
        }

        System.out.print("\n");
    
        sc.close();
   }
}


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

int main() {
    int n, m;
    cin >> n;
    vector<int> t(n);
    rep(i, n) cin >> t.at(i);
    cin >> m;
    
    int sum = 0;
    rep(i, n) sum += t.at(i);

    vector<int> ans(m);
    rep(i, m) {
        int p, x;
        cin >> p >> x;
        p--;
        ans.at(i) = sum - t.at(p) + x;
    }
    rep(i, m) cout << ans.at(i) << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.*;
class Main
{
    public static void main(String args[])throws IOException
    {
BufferedReader input=new BufferedReader (new InputStreamReader (System.in));
    while(true)
        {
         
        int sum=0;
        String str=input.readLine();
        if(str.equals("0"))break;
        for(int i=0;i<str.length();i++)
            {
             
            sum+=str.charAt(i)-'0';
            }
        System.out.println(sum);
        }
    }
}

Measured memory_bytes: 16924
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        long y = sc.nextLong();
        if (x % y == 0) {
            System.out.println(-1);
        } else {
            System.out.println(x);
        }
    }

}


Measured memory_bytes: 35716
n = int(input())
a0, b0, c0 = map(int, input().split())
dp = [[0] * 3 for _ in range(n)]

dp[0][0] = a0
dp[0][1] = b0
dp[0][2] = c0
for i in range(n - 1):
    a, b, c = map(int, input().split())
    dp[i + 1][0] = max(dp[i][1] + a, dp[i][2] + a)
    dp[i + 1][1] = max(dp[i][0] + b, dp[i][2] + b)
    dp[i + 1][2] = max(dp[i][0] + c, dp[i][1] + c)
print(max(dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]))

Measured memory_bytes: 22780
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007;
int step(int n,int m,char a[][1001] )
{
    int dp[n][m]{};
    for(int i=1;i<m;i++)
    { if(a[0][i]=='#')
    break;
        dp[0][i]=1;
    }
    for(int i=1;i<n;i++)
    { if(a[i][0]=='#')
      break;
        dp[i][0]=1;
    }
    for(int i=1;i<n;i++)
    {
        for(int j=1;j<m;j++)
        {
            if(a[i][j]=='#')
            continue;
            dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
        }
    }
   
    return dp[n-1][m-1];
}
int main()
{
    int n,m;
    cin>>n>>m;
    char a[1001][1001];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin>>a[i][j];
        }
    }
    cout<<step(n,m,a);
}

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

using namespace std;

char c[2];
int main()
{
  c[0] = '-';
  c[1] = '+';
  string s;
  cin >> s;
  int a = s[0] - '0' , b = s[1] -'0', c = s[2]-'0', d = s[3]-'0';
  if (a+b+c+d == 7) cout << a << "+" << b << "+" << c << "+" << d << "=" << 7 << "\n";
  else if (a+b+c-d == 7) cout << a << "+" << b << "+" << c << "-" << d << "=" << 7 << "\n";
  else if (a+b-c+d == 7) cout << a << "+" << b << "-" << c << "+" << d << "=" << 7 << "\n";
  else if (a+b-c-d == 7) cout << a << "+" << b << "-" << c << "-" << d << "=" << 7 << "\n";
  else if (a-b+c+d == 7) cout << a << "-" << b << "+" << c << "+" << d << "=" << 7 << "\n";
  else if (a-b+c-d == 7) cout << a << "-" << b << "+" << c << "-" << d << "=" << 7 << "\n";
  else if (a-b-c+d == 7) cout << a << "-" << b << "-" << c << "+" << d << "=" << 7 << "\n";
  else if (a-b-c-d == 7) cout << a << "-" << b << "-" << c << "-" << d << "=" << 7 << "\n";
}


Measured memory_bytes: 256
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
// ----

fn main() {
    input!{
        a: i32,
        b: i32,
        c: i32,
    }
    if b-a == c-b {
        println!("YES")
    }
    else {
        println!("NO")
    }
}


Measured memory_bytes: 4352
var lines = [];

var readline = require('readline');
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
})

rl.on('line', function (x) {
    lines.push(x);
});

rl.on("close", function () {
    var regexStart = "^A[a-z]"
    var regexMiddle = "[a-z]*C[a-z]*"
    var regexEnd = "[a-z]$"
    
    var regex = new RegExp(`${regexStart}${regexMiddle}${regexEnd}`)
    // var regex = new RegExp('^A[a-z][a-z]*C[a-z]*[a-z]$')

    var S = lines[0]
    console.log(regex.test(S) ? "AC" : "WA");
});

Measured memory_bytes: 7500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll N;
	cin >> N;
	vector<P> tree[N+1];
	FOR(i,0,N-1){
		ll a,b,c;
		cin >> a >> b >> c;
		tree[a].push_back({b,c});
		tree[b].push_back({a,c});
	}
	ll q,k;
	cin >> q >> k;
	ll d[N+1];
	bool did[N+1];
	FOR(i,0,N+1)did[i]=false;
	queue<P> Q;
	Q.push({k,0});
	did[k]=true;
	while(not Q.empty()){
		P x = Q.front();
		Q.pop();
		d[x.first] = x.second;
		FOR(i,0,tree[x.first].size()){
			if(not did[tree[x.first][i].first]){
				Q.push({tree[x.first][i].first,x.second+tree[x.first][i].second});
				did[tree[x.first][i].first] = true;
			}
		}
	}
	FOR(i,0,q){
		ll x , y ;
		cin >> x >> y;
		cout << d[x]+d[y] << endl;
	}
}

Measured memory_bytes: 10864
n = int(raw_input())
a = map(int, raw_input().split()) # city
b = map(int, raw_input().split()) # attacker
m = 0
for i in xrange(n):
  p = min(a[i], b[i])
  a[i] = a[i] - p
  c = b[i] - p
  q = min(a[i+1], c) 
  a[i+1] = a[i+1] - q
  m += p + q
print m


Measured memory_bytes: 14520
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

int get_int3(int *a1, int *a2, int *a3) {
  scanf("%d %d %d", a1, a2, a3);
  return 0;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int64_t *arr, int size) {
    int i;
    for(i = 0; i < size; i++) {
        scanf("%lld", &arr[i]);
    }
    return 0;
}

#define NUM_MAX 1000
#define K_MAX 3000
#define INF (1e+15)

// sort
int desc(const void *a1, const void *a2) {
    int64_t aa1 = *(int64_t*)a1;
    int64_t aa2 = *(int64_t*)a2;
    if(aa1 > aa2) return -1;
    if(aa1 == aa2) return 0;
    return 1;
}

#define HEAP_MAX (K_MAX*10)
void swap(int64_t *a1, int64_t *a2) {
    int64_t tmp = *a1;
    *a1 = *a2;
    *a2 = tmp;
}
 
// min heap
static int64_t min_heap[HEAP_MAX];
static int hmin_idx = 1;

int mincmp(int64_t a1, int64_t a2) {
    return a1 < a2;
}

int is_min_heap_empty(void) {
    return hmin_idx == 1;
}
 
void enqueue_min(int64_t val) {
    int node = hmin_idx;
    min_heap[hmin_idx++] = val;
    int parent;
    while((parent = node / 2)) {
        if(mincmp(min_heap[parent], min_heap[node])) break;
        swap(&min_heap[parent], &min_heap[node]);
        node = parent;
    }
    return;
}
 
int64_t dequeue_min(void) {
    int64_t ans = min_heap[1];
    min_heap[1] = min_heap[--hmin_idx];
    int node = 1;
    while(1) {
        int this = node;
        int left = node * 2;
        int right = node * 2 + 1;
        if(left < hmin_idx && !mincmp(min_heap[this], min_heap[left])) {
            this = left;
        }
        if(right < hmin_idx && !mincmp(min_heap[this], min_heap[right])) {
            this = right;
        }
        if(this == node) break;
        swap(&min_heap[this], &min_heap[node]);
        node = this;
    }
    return ans;
}

int size = 0;
int update(int64_t new, int k) {
#ifdef DEBUG
    printf("update(%lld)\n", new);
#endif
    if(k > size) {
        enqueue_min(new);
        size++;
        return 1;
    }
    int64_t mmin = min_heap[1];
    if(new <= mmin) return 0;
    enqueue_min(new);
    dequeue_min();
    return 1;
}



int main(void) {
    int xs, ys, zs;
    get_int3(&xs, &ys, &zs);
    int ord = get_int();

    int i, j, k;
    static int64_t xrr[NUM_MAX+1];
    static int64_t yrr[NUM_MAX+1];
    static int64_t zrr[NUM_MAX+1];
    fget_array(xrr, xs);
    fget_array(yrr, ys);
    fget_array(zrr, zs);
    xrr[xs] = yrr[ys] = zrr[zs] = -INF;
    qsort(xrr, xs, sizeof(int64_t), desc);
    qsort(yrr, ys, sizeof(int64_t), desc);
    qsort(zrr, zs, sizeof(int64_t), desc);

    for(i = 0; i < xs; i++) {
        for(j = 0; j < ys; j++) {
            int64_t sum = xrr[i] + yrr[j];
            for(k = 0; k < zs; k++) {
                int64_t sum3 = sum + zrr[k];
                if(!update(sum3, ord)) break;
            }
        }
    }

    qsort(&min_heap[1], ord, sizeof(int64_t), desc);
    for(i = 1; i <= ord; i++) {
        printf("%lld\n", min_heap[i]);
    }
    return 0;
}

Measured memory_bytes: 252
n, m = list(map(int, input().split()))
l = [200000 for i in range(0, n-1)]

for i in range(0, m):
    a, b = list(map(int, input().split()))
    l[a-1] = min([l[a-1], b-2])

right = -1
count = 0

for i in range(0, n-1):
    if i > right and not l[i] == 200000:
        count += 1
        right = l[i]
    elif i <= right and not l[i] == 200000:
        right = min([l[i], right])

print(count)

Measured memory_bytes: 7088
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        if (n * a < b) {
            System.out.println(n * a);
        } else {
            System.out.println(b);
        }
    }
}


Measured memory_bytes: 21844
n = gets.to_i
as = gets.chomp.split(" ").map(&:to_i)
_as = as.tally
sum = _as.map{|k,v| k * v}.sum
q = gets.to_i
q.times do |i|
  b, c = gets.chomp.split(" ").map(&:to_i)
  num = _as.delete(b)
  if num
    sum += (c - b) * num
    _as[c] = (_as[c] || 0) + num
  end
  puts sum
end


Measured memory_bytes: 26712
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007


int N,M;
int A[100005];
int L=0;

int gcd(int a,int b){
    if(a==0||b==0)return max(a,b);
    int mi=min(a,b);int ma=max(a,b);
    int c=ma%mi;
    return gcd(mi,c);
}

signed main(){
    scanf("%lld %lld",&N,&M);
    //LCMを求める
    rep(i,N){
        scanf("%lld",&A[i]);
        A[i]/=2;
        if(i==0)L=A[i];
        else{
            int g=gcd(L,A[i]);
            L=g*(L/g)*(A[i]/g);
            if(L>M){printf("0\n");return 0;}
        }
    }
    rep(i,N){
        if( (L/A[i])%2==0 ){printf("0\n");return 0;}
    }
    printf("%lld\n",(M/L)/2+(M/L)%2);
    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include<math.h>
#include<algorithm>
typedef long long int ll;
using namespace std;

#define MAX 100005
 

int main(){
	int n,ans;
    ll mini=100000000000;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    int k=a[n-1];
    for(int i=0;i<n;i++){
        if(mini>labs(a[i]*2-a[n-1])){
            mini=labs(a[i]*2-a[n-1]);
            ans=i;
        }
    }

    cout<<k<<" "<<a[ans]<<endl;
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin >> n;
	vector<ll> a(3), b(3);
	rep(i,3) cin >> a[i];
	rep(i,3) cin >> b[i];
	rep(i,2){
		vector<ll> dp(n+1);
		rep(j,3)rep(k,n){
			if(k+a[j] <= n) chmax(dp[k+a[j]], dp[k] + b[j]);
		}
		ll score = 0;
		rep(j,n+1) chmax(score, n-j+dp[j]);
		n = score;
		swap(a, b);
	}
	cout << n << endl;
	return 0;
}

Measured memory_bytes: 198448