akhauriyash/Code-Regression huggingface dataset:
#include<bits/extc++.h>
#ifdef _debug 
#define dout(i) cout << #i << ' ' << i << ' '
#else 
#include<bits/stdc++.h>
#define dout(i) 0&&0
#endif
#pragma GCC optimize("unroll-loops,no-stack-protector,O3")
#define eout(i) {cout << (i) << '\n';exit(0);}
#define priority_queue __gnu_pbds::priority_queue
#define unordered_map __gnu_pbds::gp_hash_table
#define rep(a, b) {for(int _i = a;_i > 0;--_i){b;}}
#define multe int _T;for(cin >> _T;_T--;)
using namespace std;
using ll = long long;using ull = unsigned long long;using ul = unsigned;using db = double;
using __gnu_pbds::null_type;
template<typename T> void read(int n, T s){while(n--)cin >> *s, ++s;}
template<typename T> void write(int n, T s){while(n--)cout << *s << " \n"[n==0], ++s;}
template<typename T> using rbtree = __gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T> inline ostream& operator << (ostream &ou, const vector<T> &a){for(auto it = a.begin();it != a.end();++it)ou << (it != a.begin() ? " " : "") << *it;return ou;}
template<typename T1, typename T2>inline istream& operator >> (istream &in, pair<T1, T2> &a){return in >> a.first >> a.second;}
template<typename T1, typename T2>inline ostream& operator << (ostream &ou, const pair<T1, T2> &b){return ou << b.first << ' ' << b.second;}
template<typename T> inline long long pow(long long v, long long t, const T &p){long long res = 1;for(;t;t >>= 1, v = v * v % p)if(t & 1)res = res * v % p;return res;}
const int maxn = 18;
const int p = 1e9+7;
int n, m;
int lo[maxn];
ll dp[1 << maxn];
ll fa[1 << maxn], inv[1 << maxn], fainv[1 << maxn];
inline void init(){
	inv[1] = fa[1] = fainv[1] = fa[0] = inv[0] = fainv[0] = 1;
	for(int i = 2;i < (1 << maxn);++i){
		fa[i] = fa[i-1] * i % p;
		inv[i] = (p-p/i) * inv[p % i] % p;
		fainv[i] = inv[i] * fainv[i-1] % p;
	}
}
ll per(int a, int b){
	return (a < b ? 0 : fa[a] * fainv[a - b]) % p;
}
int count_bit(int v){
	int res = 0;
	for(;v;v -= (v & -v))++res;
	return res;
}
void out(int s){
	for(int i = n-1;i >= 0;--i)cout << !!(s & (1 << i));
	cout << '\n';
}
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	init();
	cin >> n >> m;
	read(m, lo+1);
	sort(lo+1, lo+1+m, greater<int>());
	dp[0] = 1;
#define lowbit(i) ((i) & (-i))
	for(int i = 1;i <= m;++i){
		for(int s = 1<<n;s > 0;--s){
			for(int j = s;j;j -= lowbit(j)){
				dp[s] = (dp[s] + (dp[s ^ lowbit(j)] * per((1<<n)-lo[i]-s+lowbit(j), lowbit(j)-1) % p * lowbit(j))) % p;				
			}
		}
	}
	ll res = 0;
	for(int s = 1;s < (1 << n);++s){
		dp[s] = dp[s] * fa[(1<<n)-1-s];
		if(count_bit(s)&1)res = (res + p - dp[s]) % p;
		else res = (res + dp[s]) % p;
	}
	cout << (fa[(1<<n)-1] + p + res) * (1 << n) % p;
}

Measured memory_bytes: 8576
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

H, W = map(int, input().split())
masu = []
for _ in range(H):
    masu.append(list(input()))

directions = [
    (-1, 1),(0, 1),(1, 1),
    (-1, 0),(1, 0),
    (-1, -1),(0, -1),(1, -1)
    ]

new_masu = []
for h in range(H):
    tmp = []
    for w in range(W):
        if masu[h][w] == "#":
            tmp.append("#")
            continue

        bombs = 0
        # is_debug = (h == 3 and w == 0)
        for direction in directions:
            x = w + direction[0]
            y = h + direction[1]
            if 0 <= x < W and 0 <= y < H:
                try:
                    if masu[y][x] == "#":
                        bombs += 1
                except Exception:
                    pass
        tmp.append(bombs)
    new_masu.append(tmp)

for line in new_masu:
    # この書き方重要
    print(*line, sep="")

Measured memory_bytes: 3572
eval"N,*A="+`dd`.split*?,
b=A[N,N].reverse
puts N.times{|i|$*[v=A[i]]||=i;v!=b[i]||(N=v;$.=i)}<A.count(N)?:No:[:Yes,(t=[N])*(k=[$*[N]||0,b[..$.].count(N)].min)+(b-t)+t*=b.count(N)-k]

Measured memory_bytes: 89424
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 

using ll = long long;
using ull = unsigned long long;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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 ctoi(char c){return c-'0';}


// TODO: write
int main() {
  int l,r,d;cin>>l>>r>>d;
  int ans = r/d - (l-1)/d;
  print(ans);

  return 0;
}

Measured memory_bytes: 3592
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
/*
桁dpの活用

A円払うとお釣りはB = A - N円です.
Nの1個先の桁まで考えることにする. それ以上は無駄
A 101
N 091
----------------------------
B 010

各桁の値をA[i], B[i], N[i]として参照することにします. すると最小化するのは
Σ(A[i] + B[i])
になります. さて桁iについて

if A[i] >= N[i]
    B[i] = A[i] - N[i]
else
    B[i] = A[i] - N[i] + 10
    A[i + 1]--;

後者は筆算で言うところの繰り下がりが起きています.
結局のところ繰り下がりがあるかないかに注意して目的関数を最適化すれば良いことになる.

dp[i][j] := 下からi桁目まで決めたとき
j = 1: 繰り下がりを起こす
j = 0: 繰り下がりを起こさない
ときの最小紙幣枚数
*/

const int INF = 1e8; // これくらいあれば十分だろう

int main(){
    std::string N;
    std::cin >> N;
    std::reverse(N.begin(), N.end());
    N += '0'; // 次の桁まで考えるため最上位に0追加
    int n = N.size(); // 桁数
    std::vector<std::vector<int>> dp(int(2e6), std::vector<int>(2, INF));
    dp[0][0] = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 2; j++){
            // i, jからの遷移先
            int x = N[i] - '0'; // i + 1桁目を取って来る
            x += j; // Aのi+1桁目を1減らす代わりに引く数であるNのi+1桁目を1足す
            for(int a = 0; a < 10; a++){
                int next_i = i + 1;
                int next_j = 0;
                int b = a - x;
                if(b < 0){
                    //繰り下がりする場合
                    next_j = 1;
                    b += 10;
                }
                dp[next_i][next_j] = std::min(dp[next_i][next_j], dp[i][j] + a + b);
            }
        }
    }

    std::cout << dp[n][0] << std::endl;

    return 0;
}

Measured memory_bytes: 110596
S=input()
N=len(S)

a=[0]*(N+1)
for i in range(N):
    if S[i] =='<':
        a[i+1]=a[i]+1
for i in range(N-1,-1,-1):
    if S[i] == '>':
        a[i]=max(a[i+1]+1,a[i])
print(sum(a))

Measured memory_bytes: 23336
import sys
from collections import deque
inputs = sys.stdin.readlines()

n = int(inputs[0])
edges = [tuple(map(int, x.split())) for x in inputs[1:]]
B = [e[1] for e in edges] 

E = [[] for _ in range(n + 1)]
for a, b in edges:
    E[a].append(b)

Q = deque([1])
C = [0] * (n + 1)
while Q:
    v = Q.popleft()
    c = 0
    for u in E[v]:
        c += 1 + (c + 1 == C[v])
        C[u] = c
        Q.append(u)

print(max(C))
for b in B:
    print(C[b])

Measured memory_bytes: 36048
import sys
import math as mt
input=sys.stdin.buffer.readline  
#t=int(input())
mod=10**9+7
t=1
for __ in range(t):
    
    x,y=map(int,input().split())
    
    #n=int(input())
    #a=[[0 for j in range(m)] for i in range(n)]
    ch=0
    for i in range(x+1):
        fo=(x-i)
        ans=i*2+fo*4
       # print(i,fo,ans)
        if ans==y:
            ch=1
            break
    if ch==1:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 61856
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define Fi first
#define Se second
signed main(){
    int n;
    string s[200000];
    cin>>n;
    map<char,int>mp;
    rep(i,n){
        cin>>s[i];
        mp[s[i][0]]++;
    }
    int a[]={mp['M'],mp['A'],mp['R'],mp['C'],mp['H']};
    int f=0;
    rep(i,5){
        if(a[i])f++;
    }
    if(f<3)cout<<0<<endl;
    else{
        int ans=0;
        rep(i,3){
            for(int j=i+1;j<4;j++){
                for(int k=j+1;k<5;k++){
                    ans+=a[i]*a[j]*a[k];
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;
const ll MOD = 1e9+7;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"[";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"]";return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&p)
{o<<"{"<<p.first<<", "<<p.second<<"}";return o;}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj)
{o<<"{";for(auto itr=obj.begin();itr!=obj.end();++itr)o<<(itr!=obj.begin()?", ":"")<<*itr;o<<"}";return o;}

int main(){
	cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n,k,a,b;
  cin >> n >> k;

  ll t = sqrt(n);
  ll m = n/(t+1);
  vector<vector<ll>> dps(k+1,vector<ll>(t+1,0));
  vector<vector<ll>> dpl(k+1,vector<ll>(m+1,0));

  for(ll i=1; i<=t; i++){
    dps[1][i] = 1;
  }
  a = n;
  dpl[1][0] = 0;
  for(ll i=0; i<m; i++){
    b = n/(i+2);
    dpl[1][i+1] = min(n,a)-b;
    a = b;
  }

  for(ll i=2; i<=k; i++){
    ll tmp = 0;
    for(ll j=1; j<=m; j++){
      tmp += dps[i-1][j];
      tmp %= MOD;
      dpl[i][j] = tmp * dpl[1][j];
      dpl[i][j] %= MOD;
    }
    if(t>m){
      tmp += dps[i-1][t];
      tmp %= MOD;
      dps[i][t] = tmp;
    }
    for(ll j=m; j>=1; j--){
      tmp += dpl[i-1][j];
      tmp %= MOD;
      dps[i][j] = tmp;
    }
  }
  //cout << dps << endl;
  //cout << dpl << endl;
  ll ans = 0;
  for(int i=0; i<=t; i++){
    ans += dps[k][i];
    ans %= MOD;
  }
  for(int i=0; i<=m; i++){
    ans += dpl[k][i];
    ans %= MOD;
  }
  cout << (ans+MOD) % MOD << endl;
  return 0;
}


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

typedef long long ll;
ll mod = 1000000007;

int main() {
    int n; cin >> n;
    vector<int> l(n,0);
    for (int i = 0; i < n; i++) cin >> l[i];
    sort(l.begin(),l.end());
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            int key = l[i] + l[j];
            auto itr = lower_bound(l.begin(), l.end(), key);
            int res = (int)(itr - l.begin()) - j - 1;
            ans += max(0, res);
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

using std::cin;
using std::cout;
using std::endl;
using std::vector;

struct data_t {
	int ind;
	int height;

	bool operator<( const data_t& right) const {
		return ( height == right.height ) || ( height < right.height );
	}
};

int main(void) {
	int n,m,a;
	cin >> n;
	cin >> m;
	cin >> a;
	
	while (n!=0||m!=0||a!=0) {
		vector<int> res(n);
		vector<int> p(m),q(m);
		vector<data_t> h(m);
		int ind;
		
		for (int i = 0; i < n; i++) {
			res[i] = i + 1;
		}

		for (int i = 0; i < m; i++) {
			cin >> h[i].height;
			h[i].ind = i;
			cin >> p[i];
			cin >> q[i];
		}

		std::sort(h.begin(),h.end());

		for (int i = 0; i < m; i++) {
			ind = h[i].ind;
			std::swap(res[p[ind]-1], res[q[ind]-1]);
		}
			
		cout << res[a-1] << endl;

		cin >> n;
		cin >> m;
		cin >> a;
	}

	return 0;
}

Measured memory_bytes: 3136
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long LL;
typedef vector<vector<LL> > mat;
const int maxn=100010;
const LL mod=1e9+7;
#define pb push_back

mat init,base;
LL dp[3];
int n,m;
int a[maxn];

mat mul(mat a,mat b)
{
	mat ans=init;
	for(int i=0;i<3;i++)
	    for(int j=0;j<3;j++)
	        for(int k=0;k<3;k++)
	            (ans[i][j]+=a[k][j]*b[i][k]%mod)%=mod;
	return ans;
}

mat pw(int k)
{
	if (k<1) return init;
	if (k==1) return base;
	
	mat temp=pw(k/2);
	if (k%2) return mul(mul(temp,temp),base);
	else return mul(temp,temp);
}

int main()
{
	vector<LL> temp;
	temp.clear();
	for(int i=0;i<3;i++)
	    temp.pb(0);
	init.clear();
	for(int i=0;i<3;i++)
	    init.pb(temp);
	base=init;
	
	base[0][0]=1;base[0][2]=1;
	base[1][0]=1;base[1][1]=1;base[1][2]=1;
	base[2][1]=2;base[2][2]=2;base[2][0]=1;
	
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	    scanf("%d",&a[i]);
	a[0]=0;
	m++;a[m]=n;
	
	for(int i=1;i<=m;i++)
	{
		if (i==1) {dp[0]=1;dp[1]=1;dp[2]=1;}
		else
		{
			int new_[3];
			new_[0]=dp[0];
			new_[1]=(dp[0]+dp[1])%mod;
			new_[2]=(dp[0]+dp[1]*2+dp[2])%mod;
			for(int j=0;j<3;j++) dp[j]=new_[j];
		}
		
		if (a[i]-a[i-1]>1)
		{
			mat temp=pw(a[i]-a[i-1]-1);
			int new_[3];
			for(int j=0;j<3;j++) new_[j]=0;
			for(int j=0;j<3;j++)
			    for(int k=0;k<3;k++)
			    	(new_[j]+=temp[j][k]*dp[k]%mod)%=mod;
			for(int j=0;j<3;j++) dp[j]=new_[j];
		}
	}
	
	printf("%lld\n",dp[2]);
	return 0;
}

Measured memory_bytes: 640
const double = Float64
const int = Int64
const vint = Vector{int}
const vdouble = Vector{double}

int(x) = parse(int,x)

parseint(x) = parse(int, x)
readint() = map(parseint, split(readline()))

function main()
  n = readint()[1]
  A = readint()
  
  Dplus = Dict{int,int}()
  Dminus = Dict{int,int}()

  for i in 1:n
    p = i + A[i]
    m = i - A[i]

    if get(Dplus, p, 0)==0
      Dplus[p]=1
    else
      Dplus[p]+=1
    end

    if get(Dminus, m, 0)==0
      Dminus[m]=1
    else
      Dminus[m]+=1
    end
  end

  sum = 0
  for (k,v) in Dplus
    sum += v*get(Dminus, k, 0)
  end
  println(sum)
end

main()

Measured memory_bytes: 242300
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstdio>
#include<queue>
using namespace std;
const int INF=1e9;
#define ll long long
int main(){
    int n;cin>>n;
    int a=n%10;
    if(a==2||a==4||a==5||a==7||a==9){
        cout<<"hon"<<endl;
    }else if(a==3){
        cout<<"bon"<<endl;
    }else{
        cout<<"pon"<<endl;
    }
} 

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define N 100005
#define ll long long
using namespace std;
int n,m;
int v[N],fa[N],fd[N];
int find(int x)
{
	if(x==fa[x])return x;
	return fa[x]=find(fa[x]);
}
int p[N];
bool cmp(int x,int y)
{
	return v[x]<v[y];
}
vector<int>vt[N];
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>v[i],fa[i]=i;
	int d=0;
	for(int i=1;i<=m;i++)
	{
		int t1,t2;
		cin>>t1>>t2;
		t1++;t2++;
		int a=find(t1),b=find(t2);
		if(a!=b)fa[a]=b,d++;
	} 
	if(d==n-1)return puts("0"),0;
	int nd=(n-1-d)*2;
	if(nd>n)
	{
		puts("Impossible");
	}
	else
	{
		ll ans=0;
		for(int i=1;i<=n;i++)p[i]=i;
		sort(p+1,p+n+1,cmp);
		for(int i=1;i<=n;i++)
		{
			vt[find(i)].push_back(i);
		}
		for(int i=1;i<=n;i++)
		{
			if(i==fa[i])
			{
				int mn=0x3f3f3f3f,id=0;
				for(int j=0;j<vt[i].size();j++)
				{
					if(v[vt[i][j]]<mn)
					{
						mn=v[vt[i][j]];id=vt[i][j];
					}
				}
				ans+=mn;fd[id]=1;nd--;
			}
		}
		for(int i=1;i<=n;i++)
		{
			if(nd&&!fd[p[i]])
			{
				ans+=v[p[i]];
				fd[p[i]]=1;
				nd--;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
    int N, Expensive, Sum = 0;
    long p;
    cin >> N;
    vector<int> v;

    for (int i = 0; i < N; i++)
    {
        cin >> p;
        v.push_back(p);
    }

    sort(v.begin(), v.end(), greater<>());

    Expensive = v[0] / 2;

    for (int i = 1; i < v.size(); i++)
    {
        Sum += v[i];
    }

    Sum += Expensive;

    cout << Sum;
}

Measured memory_bytes: 256
#author : dokueki

import sys


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


def main():
    n, m = map(int, sys.stdin.readline().split())
    print(n*(n-1)//2+m*(m-1)//2)


if __name__ == "__main__":
    #IOE()
    main()


Measured memory_bytes: 38256
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

ans = sum(B)
for i in range(N-1):
    if A[i]+1 == A[i+1]:
        ans += C[A[i]-1]
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        byte n = sc.nextByte();
        byte m = sc.nextByte();
        int[][] mat = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                mat[i][j] = sc.nextInt();
            }
        }
        int[] vector = new int[m];
        for (int i = 0; i < m; i++) {
            vector[i] = sc.nextInt();
        }

        for (int i = 0; i < n; i++) {
            int a = 0;
            for (int j = 0; j < m; j++) {
                a += mat[i][j] * vector[j];
            }
            System.out.println(a);
        }



    }

}


Measured memory_bytes: 40412
// Generated by CoffeeScript 1.12.7
(function() {
  var stdin;

  stdin = process.openStdin();

  stdin.setEncoding("utf-8");

  stdin.on('data', function(input) {
    var a, b, s;
    s = input.trim().split(" ");
    a = parseInt(s[0]);
    b = parseInt(s[1]);
    if ((a * b) % 2 === 0) {
      console.log("Even");
    } else {
      console.log("Odd");
    }
    return process.exit();
  });

}).call(this);

Measured memory_bytes: 11468
#include <iostream>

int main() {
  std::string S;
  std::cin >> S;

  uint32_t current = 0, max_count = 0;
  for (auto &&s : S) {
    if (s == 'A' || s == 'T' || s == 'C' || s == 'G') {
      current++;
    } else if (current > 0) {
      max_count = (current > max_count ? current : max_count);
      current = 0;
    }
  }

  max_count = (current > max_count ? current : max_count);
  std::cout << max_count << std::endl;

  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
abd = [list(map(int,input().split())) for i in range(m)]
graph = [[] for i in range(n+1)]
for a,b,d in abd:
  graph[a].append((b,d))
  graph[b].append((a,d))
def bipar(graph,n,m):
  ls = [0]*(n+1)
  stack = [1]
  ls[1] = 1
  while stack:
    x = stack.pop()
    for y,_ in graph[x]:
      if ls[y] == 0:
        ls[y] = 3-ls[x]
        stack.append(y)
      elif ls[y] == ls[x]:
        return False
  return ls
color = bipar(graph,n,m)
if color != False:
  num = [10**18]*(n+1)
  num[1] = 0
  stack = [1]
  mn1 = 10**18
  mn2 = 10**18
  while stack:
    x = stack.pop()
    if color[x] == 1:
      mn1 = min(mn1,num[x])
    else:
      mn2 = min(mn2,num[x])
    for y,d in graph[x]:
      if num[y] == 10**18:
        num[y] = d-num[x]
        stack.append(y)
      elif num[x]+num[y] != d:
        print(0)
        exit()
  print(max(0,mn1+mn2-1))
else:
  num = [10**18]*(n+1)
  num[1] = 1
  stack = [1]
  flg = 0
  while stack:
    x = stack.pop()
    for y,d in graph[x]:
      if num[y] == 10**18:
        num[y] = d-num[x]
        stack.append(y)
      elif num[x]+num[y] != d:
        if not flg:
          s = num[x]
          t = num[y]
          z = (s+t-d)//2
          num = [10**18]*(n+1)
          stack = [x,y]
          num[x] = s-z
          num[y] = t-z
          while stack:
            x = stack.pop()
            for y,d in graph[x]:
              if num[y] == 10**18:
                num[y] = d-num[x]
                stack.append(y)
              elif num[x]+num[y] != d:
                print(0)
                exit()
          if min(num) > 0:
            print(1)
            exit()
        else:
          print(0)
          exit()
  if min(num) > 0:
    print(1)
  else:
    print(0)

Measured memory_bytes: 83932
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define f first
#define s second
#define pb push_back
#define ipair pair<int,int>
#define INF INT_MAX
using namespace std;

set<string> items;

int main()
{
    fast;
    int t=1;
    //cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        string str;
        for(int i=0;i<n;i++)
        {
            cin>>str;
            items.insert(str);
        }
        cout<<items.size();
    }
    return 0;
}







Measured memory_bytes: 19184
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
typedef long long ll;
//写経したやつです　つべの解説動画見てください
int main(void){
    int n,k;cin>>n>>k;
    vector<int> a(n);
    rep(i,n)cin>>a[i];
    rep(i,n)a[i]--;
    vector<int> s(n+1);
    rep(i,n){
        s[i+1] = (s[i]+a[i])%k;
    }
    map<int,int> mp;
    ll ans = 0;
    queue<int> que;
    rep(j,n+1){
        ans+=mp[s[j]];
        mp[s[j]]++;
        que.push(s[j]);
        if(que.size() == k){
            mp[que.front()]--;
            que.pop();
        }
    }
    cout<<ans<<endl;
    return 0;
    
}


Measured memory_bytes: 12032
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var nk = Array.ConvertAll(ReadLine().Split(' '), long.Parse);
        var dic = new SortedDictionary<long,long>();
        for (var i = 0; i < nk[0]; i++)
        {
            var input = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
            if (dic.ContainsKey(input[0]))
                dic[input[0]] += input[1];
            else dic[input[0]] = input[1];
        }
        var sum = 0L;
        foreach(var pair in dic)
        {
            sum += pair.Value;
            if (sum >= nk[1]) { WriteLine(pair.Key); return; }
        }
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}


Measured memory_bytes: 20032
#include <stdio.h>
int main(void){
	double a, b;
	scanf("%lf%lf",&a,&b);
	double average = (a+b)/2;
	if(average-(int)average>=0.5){
		average += 1.0;
	}
	printf("%d\n",(int)average);
	return 0;
}

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

int main(){
    int a,b,c,x;
    cin >> a >> b >> c >> x;
    int res=0;
    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++){
                if(500*i+100*j+50*k==x)res++;
            }
        }
    }
    cout << res << endl;
}

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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

#ifdef DEBUG
#define debug(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__)
#else
#define debug(fmt, ...)
#endif

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<llll> vllll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define repC3(vari,varj,vark,n)  for(int vari=0;vari<(n)-2;++vari)for(int varj=vari+1;varj<(n)-1;++varj)for(int vark=varj+1;vark<(n);++vark)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

int solve(int N, int A,int B, vi& a) {
    int p=0,q=0,r=0;
    for (int ai: a){
        if (ai <= A) ++p;
        else if (ai <= B) ++q;
        else ++r;
    }
    return min(min(p,q),r);
}

int main() {
    int N;
    cin >> N;
    int A,B;
    cin >> A >> B;
    vi a(N);
    rep(i,N) cin>>a[i];
    cout << solve(N,A,B,a) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

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; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
        Int N;
        cin >> N;
        vector<Int> A(N);
        vector<Int> C(N + 1);
        for (int i = 0; i < N; ++i) {
            cin >> A[i];
            C[A[i]]++;
        }

        sort(all(C));

        Int sum = 0;
        int idx = 0;
        vector<Int> anss(N + 1);
        for (int k = 1; k <= N; ++k) {
            while (idx <= N && C[idx] < k) {
                sum += C[idx];
                idx++;
            }
            Int pre = sum;
            Int suf = (N - idx + 1) * k;
            Int val = pre + suf;
            Int K = val / k;
            anss[K] = k;
        }
        for (int K = N; K > 0; --K) {
            chmax(anss[K - 1], anss[K]);
        }

        for (int i = 1; i <= N; ++i) {
            cout << anss[i] << endl;
        }

    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 7936
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i= (a); i<(b); i++)
#define REP(i,n) for(int i=0;i < (n);i++)
#define ALL(obj) (obj).begin(),(obj).end()
using namespace std;

const long long INF = 1LL << 60;
const int MOD = (int)1e9 + 7;
typedef long long ll;
//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    //sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
vector<bool> seen;
vector<int> start_time;vector<int> finish_time;
vector<vector<int> > g;
void dfs(int ind,int& cnt){
    start_time[ind]=++cnt;
    seen[ind]=true;
    for(int nextind : g[ind]){
        if(seen[nextind])continue;
        dfs(nextind,cnt);
    }
    finish_time[ind]=++cnt;
}
signed main () {
    int n;scanf("%d",&n);
    g.resize(n);
    REP(i,n){
        int ind,tmp;scanf("%d %d",&ind,&tmp);
        REP(j,tmp){
            int a;scanf("%d",&a);
            g[i].push_back(a-1);
        }
    }
    seen.assign(n,false);start_time.resize(n);finish_time.resize(n);
    int cnt =0;
    REP(i,n){
        if(seen[i])continue;
        dfs(i,cnt);
    }
    REP(i,n){
        printf("%d %d %d\n",i+1,start_time[i],finish_time[i]);
    }
    return 0;
}


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

ll dp[101][200010];

signed main(){
    //cout << setprecision(12) ;
    ios::sync_with_stdio(false);
	cin.tie(0);
 
    ll n,k;
    cin>>n>>k;
    
    ll mod=1e9+7;
    ll q=sqrt(n);
    if(n/q==q){
        q=2*q-1;
    }
    else q=2*q;
    ll cnt[q+1]={};
    cerr<<q<<endl;
    for(int i=1;i<=(q+1)/2;i++){
        cnt[q-i+1] = n/i - n/(i+1);
        cnt[i] = 1;
        //cerr<<i<<" "<<cnt[q-i+1]<<" "<<cnt[i]<<endl;
    }
    for(int i=0;i<k;i++){
        for(int j=1;j<=q;j++){
            dp[0][q-j+1]=1;
            dp[i+1][j] = dp[i][q-j+1] * cnt[j];
            dp[i+1][j]%=mod; 
            dp[i+1][j] += dp[i+1][j-1];
            dp[i+1][j]%=mod;
        }
    }
    ll ans=0;
    ans = dp[k][q];
    cout<<ans<<endl;

}

Measured memory_bytes: 157312
N, M = map(int, input().split())
ac = [False] * N
wa = [0] * N
for _ in range(M):
    p, s = input().split()
    p = int(p) - 1
    if not ac[p]:
        if s == "AC":
            ac[p] = True
        else:
            wa[p] += 1
accnt = len([1 for x in ac if x])
wacnt = sum([wa[i] for i in range(N) if ac[i]])
print(accnt, wacnt)

Measured memory_bytes: 5528
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

int main() {
  int n,a,b;
  scanf("%d%d%d",&n,&a,&b);
  if((a - b) & 1) {
    printf("Borys\n");
  } else {
    printf("Alice\n");
  }
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<string>
#include<iostream>
using namespace std;
int main(){
   string str;
   int num;
   int counter[30] ={};
   char ch;

   while(getline(cin,str)){
       for(int i=0;i<str.size();i++){
           if(str[i]>='a' && str[i]<='z')counter[str[i]-'a']++;
           else if(str[i]>='A' && str[i]<='Z')counter[str[i]-'A']++;
       }
   }
       for(int i=0;i<26;i++){
           cout << (char)(i+'a') << " : " << counter[i] << endl;
       }
return 0;

}


Measured memory_bytes: 3204
def main():
    n = int(input())
    xs = list(map(int, input().split()))
    ys = list(map(int, input().split()))

    dist_ma = sum(abs(x - y) ** 1 for x, y in zip(xs, ys)) ** (1 / 1)
    dist_eu = sum(abs(x - y) ** 2 for x, y in zip(xs, ys)) ** (1 / 2)
    dist_p3 = sum(abs(x - y) ** 3 for x, y in zip(xs, ys)) ** (1 / 3)
    dist_inf = max(abs(x - y) for x, y in zip(xs, ys))

    print(dist_ma)
    print(dist_eu)
    print(dist_p3)
    print(dist_inf)

if __name__ == "__main__":
    main()

Measured memory_bytes: 5644
function Main(input) {
    input = input.split(" ");
    nums = input.map(input=>parseInt(input,10))

  　var AB = nums[0];
    var BC = nums[1];
    var CA = nums[2];
    var S = AB * BC/2;
    console.log(S);
}  

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <iostream>


#define N 200000


int main()
{
    int n, r[N], maxv, min, i;
   
    
    std::cin>>n;
    for(i=0; i<n; i++)
        std::cin>>r[i];

    min=r[0];
    maxv=-1000000000;
    for(i=1; i<n; i++)
    {
        if(maxv<r[i]-min)
            maxv=r[i]-min;
        if(min>r[i])
            min=r[i];
        

    }
    
    
    std::cout<<maxv<<std::endl;
    
}


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

int main(){
	int k; 
  	cin >> k;
	int count = 1, x = 7;
	
  	while(x % k){
		count++;
		x *= 10;
      	x += 7;
      
		if(count > k){
          break;
        }
		x %= k;
	}
  
	if(x % k){
      cout << -1;
    }
	else{
      cout << count;
    }
	return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define ll long long int


int main(){
	
	//ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll prod1 = b*c;
	ll prod2 = b*d;
	ll prod3 = a*c;
	ll prod4 = a*d;
	cout<<max(prod1,max(prod2,max(prod3,prod4)));
	return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
int main () {
    int n,k,ans = 1;
    
    scanf("%d",&n);
    scanf("%d",&k);
    for (int i=0;i < n;i++) {
        if (ans*2 < ans+k) {
            ans *= 2;
        } else {
            ans += k;
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 128
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n = k()
a = [0] + l() + [0]
sa = []

for i in range(len(a)-1):
    sa.append(abs(a[i+1]-a[i]))

asum = sum(sa)
for i in range(1,len(a)-1):
    print(asum-sa[i-1]-sa[i]+abs(a[i-1]-a[i+1]))


Measured memory_bytes: 21184
def main():
  n=int(input())
  l=0
  runrun=[str(x) for x in range(1,10)]
  while len(runrun)<n:
    l+=1
    def addrunrun(s,n,l):
      if l==0:
        runrun.append(s)
      elif n==0:
        addrunrun(s+"0",0,l-1)
        addrunrun(s+"1",1,l-1)
      elif n==9:
        addrunrun(s+"8",8,l-1)
        addrunrun(s+"9",9,l-1)
      else:
        addrunrun(s+str(n-1),n-1,l-1)
        addrunrun(s+str(n),n,l-1)
        addrunrun(s+str(n+1),n+1,l-1)
    for i in range(1,10):
      addrunrun(str(i),i,l)
  print(runrun[n-1])
main()

Measured memory_bytes: 17304
#include <bits/stdc++.h>
using namespace std;
const int maxn = 10005;
int n, a[maxn];
int main() {
	scanf("%d", &n);
	int cnt = 0;
	for (int i = 0; i < n; i ++) {
		scanf("%d", a + i);
		while (!(a[i] & 1)) {
			a[i] >>= 1;
			cnt ++;
		}
	}
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 256
n=int(input())
p=list(map(int,input().split()))
a=[0]*(n+1)
a[0]=n
ans=0
for ind,i in enumerate(p,1):
    a[ind]=min(i,a[ind-1])
for i in p:
    if p[i-1] <= a[i]:
        ans += 1
print(ans)

Measured memory_bytes: 26012
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
#include <set>
using namespace std;
using ll = long long;
#define rep(i,a,b) for(ll i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
 
int main() {
    int n;
    cin >> n;
    vector <string> a(n);
    set <string> b;
    rep(i,0,n) {
        cin >> a[i];
    }
    rep(i,0,n) {
        if (b.find(a[i]) != b.end()) {
            cout << "No" << endl;
            return 0;
        }
        b.insert(a[i]);
        if (i > 0) {
            if (a[i][0] != a[i-1][a[i-1].size()-1]) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3108
num = input()

#print(num)
flag = "loop"
op_list = ["+","-"]
for i in op_list:
  if flag == "break":
    break
  for j in op_list:
    if flag == "break":
      break
    for k in op_list:
      if i == "+":
        ans = int(num[0]) + int(num[1])
      else:
        ans = int(num[0]) - int(num[1])
        
      if j == "+":
        ans += int(num[2])
      else:
        ans -= int(num[2])
        
      if k == "+":
        ans += int(num[3])
      else:
        ans -= int(num[3])
      #print(ans)
      if ans == 7:
        print(num[0]+i+num[1]+j+num[2]+k+num[3]+"=7")
        flag = "break"
        break
      ans = 0
        




Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(S):
    for i, s in enumerate(S):
        if i % 2 == 1 and s == 'R':
            return 'No'
        if i % 2 == 0 and s == 'L':
            return 'No'
    return 'Yes'


def main():
    S = read_str()
    print(slv(S))


if __name__ == '__main__':
    main()


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

#define OUT_COUNT 0
#define POINT_COUNT 1

void initilaize(char array[]);
void process(int count[]); //処理関数

main()
{
	int i = 0, n = 0;
	int count[2];
	scanf("%d\n", &n);
	while(i < n)
	{
		count[0] = 0, count[1] = 0; //初期化
		process(count); //処理関数呼び出し
		printf("%d\n", count[POINT_COUNT]);
		i++;
	}
	return 0;
}
void initialize(char array[])
{
	short i = 0;
	for(i = 0; i < 8; i++)
	{
		array[i] = 0x00;
	}
}
void process(int count[]) //処理関数
{
	char event[8];
	short base = 0;
	int i = 0;
	int runner = 0;
	while(count[OUT_COUNT] < 3) //アウトカウントが3になるまで
	{
		initialize(event); //イベント代入配列の初期化
		gets(event); //イベントの取得
		if(strcmp(event, "OUT") == 0)
		{
			count[OUT_COUNT]++;
		}
		else if(strcmp(event, "HIT") == 0)
		{
			base++;
			if(base > 3)
			{
				count[POINT_COUNT]++;
				base--;
			}
		}
		else if(strcmp(event, "HOMERUN") == 0)
		{
			count[POINT_COUNT] += base + 1;
			base = 0;
		}
		//printf("count[OUT_COUNT] = %d base = %d\n", count[OUT_COUNT], base);
		//printf("count[POINT_COUNT] = %d\n", count[POINT_COUNT]);
	}
	return;
}

Measured memory_bytes: 596
#include<iostream>
#include<vector>
#include<numeric>
using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++)  cin >> a[i];
    ll sum = accumulate(a.begin(), a.end(), 0ll);
    if(sum%(n*(n+1)/2)){
        cout << "NO" << endl;
        return 0;
    }
    ll k = sum / (n*(n+1)/2);
    for(int i = 0; i < n; i++){
        ll diff = a[i]-a[(i+n-1)%n]-k;
        if(diff > 0 || abs(diff)%n > 0){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    ll n;cin>>n;
    vector<ll>c(n);
    vector<ll>a(n);
    vector<ll>b(n+1);
    b[0]=1;
    REP(i,1,n+1){
        b[i]=b[i-1]*2%inf;
    }
    rep(i,n)cin>>c[i];
    sort(all(c));
    a[0]=c[0];
    REP(i,1,n){
        a[i]=c[i]+a[i-1];
        a[i]%=inf;
    }
    ll ans=0;
    ans+=c[0];
    REP(i,1,n){
        ll k=ans;
        ans+=(b[i])*c[i];
        ans%=inf;
        ans+=(k+a[i-1]*(b[i-1]))%inf;
        ans%=inf;
    }
    ans*=b[n];
    ans%=inf;
    cout<<ans<<endl;
}

Measured memory_bytes: 4992
class queue:
  def __init__(self):
    self.my_list = []
  def enqueue(self,x):
    self.my_list.append(x)
    
  def dequeue(self):
    x = self.my_list[0]
    del self.my_list[0]
    return x
  def isEmpty(self):
    if len(self.my_list)==0:
      return True;
    else:
      return False;
    
# input接收一行输入，返回字符串
n,q = map(int,input().split())
my_queue = queue()
#for name,time in input().split():
#  my_queue.enqueue([name,int(time)])

for i in range(n):
  processes = input().split()
  my_queue.enqueue([processes[0],int(processes[1])])
  
cnt_time = 0

while not my_queue.isEmpty():
  p = my_queue.dequeue()
  if p[1]>q:
    cnt_time+=q
    p[1]-=q
    my_queue.enqueue(p)
    
  else:
    cnt_time+=p[1]
    print(p[0],cnt_time)


Measured memory_bytes: 13012
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long int
#define mod 1000000007
#define all(x) (x).begin(),(x).end()
 
#define REP(i, n) for(int i = 0; i < (n); i++)
#define NREP(i, n) for(int i = 1; i <= (n); i++)
#define SREP(i, s) for(int i = 0; i < (s.size()); i++)
#define SORT(v, n) sort(v, v+n);
#define GSORT(v, n) sort(v, v+n, greater<int>());
#define VSORT(v) sort(v.begin(),v.end());
#define VGSORT(v) sort(v.begin(),v.end(),greater<int>());
#define REV(a) reverse(begin(a),end(a));

int nums(int n){
	return to_string(n).length();
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	cout << fixed << setprecision(7);
////////////////////////////////////////////
	int n,k;
	cin >> n >> k;
	double p[n];
	REP(i,n){
		cin >> p[i];
		p[i]+=1.0;
	}
	double count=0;
	double maxp=0;
	REP(i,k){
		count+=p[i];
	}
	maxp=count;
	for(int i=0;i<n-k+1;i++){
		count-=p[i];
		count+=p[i+k];
		if(maxp<count) maxp=count;
	}

	cout << maxp/2 << endl;
///////////////////////////////////////////
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Test1 {

    


    class ClassMain {


        



        public static void Main(String[] args) {
            string line;
            while ((line = Console.ReadLine()) != null) {
                //int[] ints = line.Split(' ').Select(int.Parse).ToArray();
                int n = int.Parse(line);
                if (n == 0) { break; }
                int m = int.Parse(Console.ReadLine());

                int cnt = 0;
                int state = 0;
                int currentOI = 0;
                line = Console.ReadLine();
                for (int i = 0; i < m ; i++) {
                    if (state == 0) {//Nothing.
                        if (line[i] == 'I') { state = 1; continue; }
                    }else if(state==1){// prev_char = 'I'
                        if (line[i] == 'I') { continue; }
                        if (line[i] == 'O' && i != m - 1 && line[i + 1] == 'I') {
                            currentOI++;
                            i++;
                            state = 2;
                        }
                        else { state = 0; }
                    }
                    else if (state == 2) {// prev_ = "I[OI]*n"
                        if (currentOI >= n) { cnt++; }
                        if (line[i] == 'I') { state = 1; currentOI = 0; continue; }
                        if (line[i] == 'O' && i != m - 1 && line[i + 1] == 'I') {
                            currentOI++;
                            i++;
                        }
                        else { state = 0; currentOI = 0; }
                    }
                }
                Console.WriteLine(cnt);
            }
        }

        
    }

    

    
}

Measured memory_bytes: 11084
#include <iostream>

using namespace std;

int main(){
        int n,i,ans=1000000;
        int w[101];

        cin >>n;
        for(i=0; i<n; i++){
                int num;
                cin>>num;
                if(i==0) w[i]=num;
                else w[i]=w[i-1]+num;
        }

        for(i=0; i<n; i++){
                ans=min(ans,abs(w[i]-(w[n-1]-w[i])));
        }

        cout<<ans<<"\n";

        return 0;
}


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

int main() {

    int n;

    cin >> n;

    vector<int> a;

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

    sort(a.begin(),a.end(),greater<int>());

    int ans = a[n-1];

    for(int i=0; i<n; i++){
        if(a[0] != a[i] && abs(a[0]/2 - ans) > abs(a[0]/2 - a[i])){
            ans = a[i];
        }
    }

    cout << a[0] << " " << ans << endl;

    return 0;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const array<pair<int,int>,4> fd{make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 
//ll

int n,k;
int main(){
  cin>>n;
  string ans;
  if(n==25)ans = "Christmas";
  else if(n==24)ans = "Christmas Eve";
  else if(n==23)ans = "Christmas Eve Eve";
  else ans = "Christmas Eve Eve Eve";
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;

string S;
int K;

int main() {
    cin >> S >> K;
    long long cnt = 0;
    long long N = S.length();
    if (N == 1) {
        cout << K / 2 << endl;
        return 0;
    }
    bool change = false, one = true;
    for (int i = 0; i < N - 1; i++) {
        if (S[i] == S[i + 1] && !change) {
            cnt++;
            change = true;
        } else {
            change = false;
        }
        if (S[0] != S[i + 1]) {
            one = false;
        }
    }
    if (K == 1) {
        cout << cnt << endl;
        return 0;
    }
    if (one) {
        cout << N * K / 2 << endl;
        return 0;
    }
    long long ans = cnt;
    change = !change && S[0] == S[N - 1];
    cnt = change? 1 : 0;
    for (int i = 0; i < S.length() - 1; i++) {
        if (S[i] == S[i + 1] && !change) {
            cnt++;
            change = true;
        } else {
            change = false;
        }
    }
    ans += cnt * (K - 1);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <complex>
#include <cmath>

using namespace std;
const double eps = 1e-11;

typedef complex<double> xy_t;

double dotProduct(xy_t a, xy_t b){
	return (conj(a) * b).real();
}

double crossProduct(xy_t a, xy_t b){
	return (conj(a) * b).imag();
}

xy_t projection(xy_t p, xy_t b){
	return b*dotProduct(p,b)/norm(b);
}

bool cmpSign(double a, double b){
	if((a > 0 && b < 0) || (a < 0 && b > 0)) return false;
	return true;
}

int main (){
	int N;
	double X[4],Y[4];
	while(true){
		for(int i = 0; i < 4; i++) cin >> X[i] >> Y[i];
		if (!cin) break;
		xy_t a[4];
		for(int i = 0; i < 4; i++) a[i] = xy_t(X[i],Y[i]);
		double p = crossProduct(a[0]-a[3],a[1]-a[3]);
		double q = crossProduct(a[1]-a[3],a[2]-a[3]);
		double r = crossProduct(a[2]-a[3],a[0]-a[3]);
		bool ok = cmpSign(p,q) && cmpSign(q,r) && cmpSign(r,p);
		cout << (ok ? "YES" : "NO") << endl;
	}
	return 0;
}

Measured memory_bytes: 1220
import numpy as np
n=int(input())
A=list(map(int,input().split()))
cnt=0
x=0
while(A[x]%2==0):
    if(A[x]%2==0):
        A[x]/=2
        if(x==n-1):
            cnt+=1
            x=0
    else:
        break
    x+=1
        
print(cnt)

Measured memory_bytes: 12424