akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
using namespace std;
int N;

int main(){

while(cin >> N){
  if(N == 0) break;
  
  int A[N];
  for (int i = 0; i < N; ++i){
    A[i] = i+1; 
  }
  reverse(A,A+N);

  int r = 0; 
  cin >> r; 
  
  for (int i = 0; i < r; ++i){
    int p = 0;
    int c = 0;
    cin >> p; cin >> c;
    rotate(A,A+p-1,A+p-1+c);
  }

  cout << A[0] << endl;

}

return 0;

}

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

#define MOD (1000000000+7)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) x.begin(), x.end()
#define print(vec,l,r) for(int i = l; i <= r; i++) cout << vec[i] <<" "; cout << endl;
#define forf(i,a,b) for(int i = (a); i < (b); i++)
#define forr(i,a,b) for(int i = (a); i > (b); i--)
#define input(vec,N) for(int i = 0; i < (N); i++) cin >> vec[i];

// template starts
typedef long long int ll;
int ans = 0;
vector<int> nums;
int N, M, Q;
vector<vector<int>> vec;
int score(){
	int s = 0;
	for(int i = 0; i < Q; i++){
		int b = vec[i][1]-1, a = vec[i][0]-1, c = vec[i][2], d = vec[i][3];
		if(nums[b] -nums[a] == c) s+= d;
	}
	return s;
}

void f(int i, int prev){
	if(i == N){
//		cout << endl;
//		for(int j = 0; j <N; j++) cout<< nums[j] << " ";
//		cout << " = " << score();
//		cout << endl;
		
		ans = max(ans, score());
		return;
	}
	for(int j = prev; j <= M; j++){
		nums[i] = j;
		f(i+1,j);
	}
}
void solve(){
	// code starts from here
	
	cin >> N >> M >> Q;
	vec.resize(Q);
	for(int q = 0; q < Q; q++){
		vec[q].resize(4);
		for(int i = 0; i < 4; i++){
			cin >> vec[q][i];
		}
	}
	
	nums.resize(N);
	for(int i = 0; i < N; i++) nums[i] = 0;
	
	f(0,1);
	cout << ans << endl;
}

int main(){
 	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	int T;
	T = 1;
	while(T--){
		solve();
	}

	return 0;
}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
   //#ifndef ONLINE_JUDGE
      // for getting input from input.txt
     // freopen("input.txt", "r", stdin);
      // for writing output to output.txt
      //freopen("output.txt", "w", stdout);
  ///#endif
fast();
//ll  t;cin>>t;while(t--)
{
  string s;
  cin>>s;
  ll n=s.length();
  for(int i=0;i<n;i++)
  {
    if(s[i]=='B')
    {
      if(i>0)
      {
        s[i]='a';
        int j=1;
        if(s[i-j]=='a')
        {
          while(s[i-j]=='a'&&i-j>=0)
          {
            j++;
          }
        
        s[i-j]='a';
      }
      else
      {
        s[i-j]='a';
      }
      }
    
    else
    {
      s[i]='a';
    }
  }
  }
  for(int i=0;i<n;i++)
  {
    if(s[i]!='a')
    {
      cout<<s[i];
    }
  }
  cout<<endl;
  
  

}
return 0;
}

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

int main(){
  string N;
  cin>>N;
  if(N[0]==N[1]&&N[1]==N[2]){
    cout<<"Yes"<<endl;
  }
  else if(N[1]==N[2]&&N[2]==N[3]){
    cout<<"Yes"<<endl;
  }
  else{cout<<"No"<<endl;}
}

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

int main() {
 double W, H, x, y;
 double z;
 int t = 0;
   cin >> W >> H >> x >> y;
  z=W*H/2;
  if (x==W/2 && y==H/2) {
    t=1;
  }
    cout << z << " " << t << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <cstring> 
#include <set>
#include <string>
#include <valarray>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define maxe(v) *max_element(v.begin(), v.end())
#define mine(v) *min_element(v.begin(), v.end())
#define pb push_back
#define pf push_front
#define rem 1000000007
#define cont continue

ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b%a, a);
}
ll modulo(ll a, ll b)
{
    ll r = a % b;
    return r < 0 ? r + b : r;
}
ll longrem(string k,ll n)
{
    // k is taken into input as a string...
	int now=0;
    for(int i=0;i<k.size();i++)
    {
        now=(now*10)%n;
        now=(now+k[i]-'0')%n;
    }
    return now;    // O( log(k) )/log(10) )
}
ll ncr(ll n,ll k)  
{  
    ll res = 1;  
    if ( k > n - k )  
        k = n - k; 
    for (ll i = 0; i < k; ++i)  
    {  
        res *= (n - i);  
        res /= (i + 1);  
    }  
    return res;  
}

ll binaryToDecimal(ll n) 
{ 
    ll num = n; 
    ll dec_value = 0; 
  
    // Initializing base value to 1, i.e 2^0 
    ll base = 1; 
  
    ll temp = num; 
    while (temp) { 
        ll last_digit = temp % 10; 
        temp = temp / 10; 
  
        dec_value += last_digit * base; 
  
        base = base * 2; 
    } 
  
    return dec_value; 
} 

void decToBinary(int n) 
{ 
    
    int binaryNum[32]; 
  
    int i = 0; 
    while (n > 0) { 
  
         
        binaryNum[i] = n % 2; 
        n = n / 2; 
        i++; 
    } 
  
    // printing binary array in reverse order 
    for (int j = i - 1; j >= 0; j--) 
        cout << binaryNum[j]; 
} 
ll prime(ll n)
{
	ll flag=0;
	if(n==1 || n==2)
	{
		flag=0;
	}
	else 
	{
		if(n%2==0)
			flag=1;
		else
		{
			ll i=3;
			while(i<=sqrt(n) && flag==0)
			{
				if(n%i==0)
					flag=1;
				i=i+3;
			}
		}
	}
	return flag;
}
ll ispal(string str,string s)
{
	ll flag=0;
	reverse(str.begin(), str.end());
	if(str==s)
	{
		flag=1;
	}
	return flag;
}
ll ispalself(string str)
{
	ll flag=0;
	string s=str;
	reverse(str.begin(), str.end());
	if(str==s)
	{
		flag=1;
	}
	return flag;
}
/**************************************************************************************************************************************/
int main()
{
	
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	
	
	
	/*ll t;
	cin>>t;
	while(t--)
	{*/
	string str;
	ll i,n,cnt=0;
	cin>>str;
	n=3;
	
	
	for(i=0;i<n;i++)
	{
		if(str[i]=='A')
		{
			cnt++;
		}
	}
	
	if(cnt>0 && cnt<3)
	{
		cout<<"Yes\n";
	}
	else
	{
		cout<<"No\n";
	}

	
	
	
			
	//}
}

Measured memory_bytes: 256
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N,K = (int(_) for _ in input().split())
    l = list(int(_) for _ in input().split())
    l.sort()
    l=l[::-1]
    sum_l = 0
    for i in range(0,K):
        sum_l += l[i]
    print(sum_l)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

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

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

N = int(sys.stdin.buffer.readline())
A = list(map(int, sys.stdin.buffer.readline().split()))

A = np.array(A, dtype=int)
ans = 0

d = 1
while d < (1 << 60):
    cnt = np.count_nonzero(A & d)
    ans += (N - cnt) * cnt * d
    ans %= MOD
    d <<= 1
print(ans)


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

int lcs(string X, string Y) {
  int cs[1001][1001];
  int m = X.size();
  int n = Y.size();
  int answer = 0;
  for (int i = 1; i <= m; i++) cs[i][0] = 0;
  for (int j = 1; j <= n; j++) cs[0][j] = 0;

  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (X[i - 1] == Y[j - 1]) {
        cs[i][j] = cs[i - 1][j - 1] + 1;
      } else {
        cs[i][j] = max(cs[i - 1][j], cs[i][j - 1]);
      }
      answer = max(answer, cs[i][j]);
    }
  }

  return answer;
}

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

  int n;
  cin >> n;

  string X, Y;

  for (int i = 0; i < n; i++) {
    cin >> X >> Y;
    cout << lcs(X, Y) << endl;
  }

  return 0;
}

Measured memory_bytes: 7080
#include <iostream>
#include <algorithm>
#include <vector>
#include <climits>
#include <cfloat>
#include <string>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define INF INT_MAX
#define BINF DBL_MAX

int main(){
	double mx = 0;
	double mn = BINF;
	double h;
	while (cin >> h){
		if (h<mn) mn = h;
		if (h > mx) mx = h;
	}
	cout << mx - mn << endl;
	return 0;
}

Measured memory_bytes: 1284
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 = sc.nextInt();
        int B = sc.nextInt();
        int X = A * N;

        if(X >= B){
            System.out.println(B);
        }else{
            System.out.println(X);
        }
    }
}

Measured memory_bytes: 23764
S = []
H = []
C = []
D = []

a=int(input())
for _ in range(a) :
    i = input().split()
    suit = i[0]
    num = int(i[1])
    if suit== "S":
        S.append(num)
    elif suit== "H":
        H.append(num)
    elif suit== "C":
        C.append(num)
    elif suit== "D":
        D.append(num)

S_nasi=[]
H_nasi=[]
C_nasi=[]
D_nasi=[]
    
for i in range(13):
    if not i+1 in S:
        S_nasi.append(i+1)
    
for i in range(13):
    if not i+1 in H:
        H_nasi.append(i+1)

for i in range(13):
    if not i+1 in C:
        C_nasi.append(i+1)

for i in range(13):
    if not i+1 in D:
        D_nasi.append(i+1)

   



for i in S_nasi:
    print("S",i)

for i in H_nasi:
    print("H",i)

for i in C_nasi:
    print("C",i)

for i in D_nasi:
    print("D",i)


Measured memory_bytes: 5616
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const A = Number(input[0][0]);
  const B = Number(input[1][0]);
  const C = Number(input[2][0]);
  const X = Number(input[3][0]);

  let answer = 0;

  for (let a = 0; a <= A; a++) {
    for (let b = 0; b <= B; b++) {
      const c = (X - (a * 500 + b * 100)) / 50;

      if (c >= 0 && c <= C) {
        answer += 1;
      }
    }
  }

  return answer;
};

console.log(main(read()));


Measured memory_bytes: 29744
N = int(input())
H = list(map(int, input().split()))
result = 0
tmp_result = 0
if N == 1:
    print(0)
else:
    for k in range(1,N):
        if H[k] <= H[k-1]:
            tmp_result += 1
            if tmp_result > result:
                result = tmp_result
        else:
            tmp_result = 0
    print(result)

Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
 
#define FAST ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
 
#define MAXX 100005
 
#define PI 3.14159265358979323846264338327950
 
#define F first
#define S second
 
#define ll 	 long long int
 
#define mod  1000000007



int main()
{
	FAST;
	ll n;
	cin >> n;
	cout << ((n+1)/2) *(n/2);
	return 0;
}

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

unordered_map<int,int> mp;
int H,N,A[1010],B[1010];
#define INF (1<<30);

int rec(int h)
{
    if(h <= 0) {
        return 0;
    }
    if(mp.find(h) != mp.end()) {
        return mp[h];
    }
    int m = INF;
    for(int i = 0; i < N; i++) {
        if(rec(h-A[i]) + B[i] < m) {
            m = rec(h-A[i]) + B[i];

        }
    }
    mp[h] = m;
    return m;
}

int main(void) 
{
    cin >> H >> N;
    for(int i = 0; i < N; i++) {
        cin >> A[i] >> B[i];
    }
    cout << rec(H) << endl;;
    return 0;
}



Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define inf 1000000007
#define LINF 10000000000000007LL
#define ll long long
using namespace std;
int cnt[10];
signed main(){
	int h,w,n;
	map<pair<int,int>,int> nuri;
	set<pair<int,int> > ex;
	cin>>h>>w>>n;
	for(int i=0;i<n;i++){
		int x,y;
		cin>>x>>y;
		for(int j=-1;j<=1;j++){
			for(int k=-1;k<=1;k++){
				nuri[ mp(x+j,y+k) ] ++;
				ex.insert( mp(x+j,y+k) );
			}
		}
	}
	set< pair<int,int> >::iterator it = ex.begin();
	while(it != ex.end()){
		pair<int,int> P = *it;
		int cx = P.first;
		int cy = P.second;
		if( 1 < cx && cx < h && 1 < cy && cy < w){
			cnt [ nuri[P] ] ++;
		}
		it++;
	}
	cnt[0] = (h-2)*(w-2);
	for(int i=1;i<=9;i++){
		cnt[0] -= cnt[i];
	}
	for(int i=0;i<=9;i++){
		cout<<cnt[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 112768
#include <bits/stdc++.h>
#define maxn 5001
#define pb push_back
using namespace std;
typedef long long LL;

LL ans,tot;
int n,m,k;
int p[maxn];
int c[maxn];
bool mark[maxn];
vector<int> v;
vector<LL> sum;

void dfs(int u) {
	v.pb(u);
	tot += c[u];
	mark[u] = true;
	if(!mark[p[u]])
		dfs(p[u]);
}

LL f(int d) {
	LL best = INT_MIN;
	for( int i = m+1 ; i <= 2*m ; i++ )
		for( int j = i ; j > i-d ; j-- ) {
			LL temp = sum[i]-sum[j-1];
			best = max(best,temp);
		}
	return best;
}

void solve(int u) {
	tot = 0;
	v.clear();
	sum.clear();
	dfs(u);
	m = v.size();
	sum.pb(0);
	for( int i = 0 ; i < m ; i++ )
		sum.pb(sum.back()+c[v[i]]);
	for( int i = 0 ; i < m ; i++ )
		sum.pb(sum.back()+c[v[i]]);
	if(k <= m)
		ans = max( ans , f(k) );
	else {
		int times = k/m;
		tot = max(tot,0LL);
		ans = max( ans , f(k%m) + tot*times );
		ans = max( ans , f(m) + tot*(times-1) );
	}
}

int main() {
	scanf("%d%d",&n,&k);
	for( int i = 1 ; i <= n ; i++ )
		scanf("%d",&p[i]);
	for( int i = 1 ; i <= n ; i++ )
		scanf("%d",&c[i]);
	ans = INT_MIN;
	for( int i = 1 ; i <= n ; i++ )
		if(!mark[i])
			solve(i);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4116
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int ll;
typedef vector<int> vec;
typedef vector<vec> mat; 

int N,M,A,B,C,T;

mat mul(mat &A,mat &B){
	mat C( A.size(),vec(B[0].size() ));
	for(int i=0;i<A.size();i++)
		for(int k=0;k<B.size();k++)
			for(int j=0;j<B[0].size();j++)
				C[i][j]=(C[i][j]+A[i][k]*B[k][j])%M;
	return C;
}

mat pow(mat A,ll n){
	mat B(A.size(),vec(A[0].size()));
	for(int i=0;i<A.size();i++)
		B[i][i]=1;
	while(n>0){
		if(n&1) B=mul(B,A);
		A=mul(A,A);
		n >>=1;
	}
	return B;
}



int main(void){
	while(cin >> N >> M >> A >> B >> C >> T,N){;
		mat D(N,vec(N));
		for(int i=0;i<N;i++){
			if(i!=0)
				D[i-1][i]=C;
			if(i!=N-1)
				D[i+1][i]=A;
			D[i][i]=B;
		}
		mat E(N,vec(1));
		for(int i=0;i<N;i++)
			cin >> E[i][0];
		D=pow(D,T);
		E=mul(D,E);
		for(int i=0;i<N;i++)
			cout << (i?" ":"") << E[i][0];
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1288
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1400000;
char cn[CM], * ci = cn, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += (72 - dig >> 3);
	return tmp;
}
char* di = cn;
inline void putint(int X) {
	if (X < 10) {
		*di++ = '0' + X;
		*di++ = '\n';
		return;
	}
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

int A[200001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);

	fread(cn, 1, CM, stdin);
	int N = getint();
	rep(i, N - 1) A[getint()]++;

	rep1(i, N) putint(A[i]);

	fwrite(cn, 1, di - cn, stdout);


	Would you please return 0;
}

Measured memory_bytes: 3504
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
#define rep1(i,n) for(ll i=1; i<=n; ++i)
#define revrep(i,n) for(ll i=n-1; n>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define endl '\n'
template <class T> bool updmax(T& a, T b) { if (b > a) { a = b; return true;} return false;}
template <class T> bool updmin(T& a, T b) { if (b < a) { a = b; return true;} return false;}

int main() {
    fastio;
    ll ans=0;
    string s,t;
    cin >> s >> t;
    map<char, vector<int>> m;
    rep(i,(ll)s.size())
        m[s[i]].push_back(i);

    ll pos=0;
    for (size_t i=0; i<t.size();) {
        auto& v = m[t[i]];
        if (auto it = lower_bound(begin(v), end(v), pos); it == end(v)) {
            if (pos == 0) {
                ans = -1;
                break;
            }
            ans += s.size()-pos;
            pos = 0;
            continue;
        } else {
            ans += *it - pos + 1;
            pos = *it + 1;
            ++i;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 4156
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll N,X; cin>>N; 
    vector<ll> A(N);
    vector<ll> ans(N);
    ll sum=0;
    ll itido=0;
    rep(i,N) cin>>A[i],sum+=A[i],itido+=(i+1);
    if(sum%itido!=0){cout<< "NO"<<"\n"; return;}
    X=sum/itido;
    rep(i,N){
        ll sa=A[(i+1)%N]-A[i];
        if((X-sa)%N!=0 or X-sa<0){cout<< "NO"<<"\n"; return;}
        ans[i]=(X-sa)/N;
    }
    /*
    ll sum2=0;
    rep(i,N) sum2+=ans[i];
    if(sum2!=X) {cout<< "NO"<<"\n"; return;}
    */
    cout<< "YES" <<"\n";
}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


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

int arr[200001];


int main(){
    
    string S;
    cin >> S;
    
    int n = S.size();
    for(int i = 0; i < n; i++){
        if(S[i] == 'W'){
            arr[i] = 1;
        }else{
            arr[i] = 0;
        }
    }
    stack<int>s;
    for(int i = 0; i < n; i++){
        //cout << i << " " << arr[i] << endl;
        s.push(arr[i]);
    }
    
    long long res = 0;
    int total_ones = 0;
    while(!s.empty()){
        int value = s.top();
        s.pop();
        if(value == 0){
            res += total_ones;
        }else{
            total_ones += 1;
        }
        //cout << value << " " << res << endl;
    }
    
    cout << res << endl;
    
    
}


Measured memory_bytes: 5212
#include<cstdio>
#include<iostream>
#include<cmath>
#include<queue>
#include<vector>
#include<map>

using namespace std;
#define ROW 3
#define COL 3

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

struct Puzzle{
	int puzzle[ROW][COL];
	int space_x, space_y;

	bool operator < (const Puzzle &p) const {
		for(int i = 0; i < ROW; i++){
			for(int j = 0; j < COL; j++){
				if(puzzle[i][j] == p.puzzle[i][j]) continue;
				return puzzle[i][j] < p.puzzle[i][j];
			}
		}
		return false;
	}
};

struct Node{
	Puzzle state;
	int level;
	int cost;

	bool operator < (const Node &n) const {
		return cost > n.cost;
	}
};

int goal[ROW][COL] = {
		1, 2, 3,
		4, 5, 6,
		7, 8, 0
	};
map<int, pair<int, int>> heuristicMap;

int isGoal(Puzzle p){
	for(int i = 0; i < ROW; i++){
		for(int j = 0; j < COL; j++){
			if(goal[i][j] != p.puzzle[i][j]) return false;
		}
	}
	return true;
}

int Heuristuc0(Puzzle p){
	return 0;
}

int g(int level){
	return level;
}

int CaliculateCost(Node node){
	return Heuristuc0(node.state) + g(node.level);
}

int ASearch(Node start){
	priority_queue<Node> openList;
	map<Puzzle, pair<bool, int>> closedList;

	openList.push(start);

	while(!openList.empty()){
		Node now = openList.top(); openList.pop();
		
		if(isGoal(now.state)) return now.level;

		closedList[now.state] = make_pair(true, now.cost);
		
		for(int k = 0; k < 4; k++){
			int tx = now.state.space_x + dx[k];
			int ty = now.state.space_y + dy[k];
			if(tx < 0 || ty < 0 || tx >= ROW || ty >= COL) continue;

			Node child;
			child.state = now.state;
			swap(child.state.puzzle[now.state.space_x][now.state.space_y], child.state.puzzle[tx][ty]);
			child.state.space_x = tx;
			child.state.space_y = ty;
			child.level = now.level + 1;
			child.cost = CaliculateCost(child);

			if(!closedList[child.state].first){
				openList.push(child);
			}else if(child.cost < closedList[child.state].second){
				closedList.erase(child.state);
				openList.push(child);
			}
		}
	}

	return -1;
}

int main(){
	for(int i = 0; i < ROW; i++){
		for(int j = 0; j < COL; j++){
			heuristicMap[goal[i][j]] = make_pair(i, j);
		}
	}

	Node start;
	for(int i = 0; i < ROW; i++){
		for(int j = 0; j < COL; j++){
			cin >> start.state.puzzle[i][j];
			if(start.state.puzzle[i][j] == 0){
				start.state.space_x = i;
				start.state.space_y = j;
			}
		}
	}
	start.level = 0;
	start.cost = CaliculateCost(start);

	cout << ASearch(start) << endl;

	return 0;
}



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

int main() {
  int N, ans = 0;
  cin >> N;

  for (int i = 1; i <= N; i += 2) {
    int count = 0;
    // cout << "i : " << i << endl;
    for (int j = 1; j <= i; j++) {
      // cout << "j : " << j << endl;
      if (i % j == 0) {
        count++;
      }
    }
    // cout << "i : " << i << ", count : " << count << endl;
    if (count == 8) {
      ans++;
    }
  }
  cout << ans << endl;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll H, W, N;
    cin >> H >> W >> N;
    cout << N / max(H, W) + !!(N % max(H, W)) << endl;
    return 0;
}


Measured memory_bytes: 3552
#include<iostream>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  while(h!=0){
    int i,j;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	if(i==0||i==h-1||j==0||j==w-1)
	  cout << "#";
	else cout << ".";
      }
      cout << endl;
    }
    cout << endl;
    cin >> h >> w;
  }
  return 0;
}




Measured memory_bytes: 3084
#include <iostream>
#include <numeric>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)




int main() {
	int N, M;
	cin >> N >> M;
	vector<int> vec(M);
	int su = 0;
	for (int i = 0; i < M; i++) {
		cin >> vec.at(i);
		su += vec.at(i);
	}
	if (su > N) {
		cout << -1 << endl;
	}
	else {
		cout << N - su << endl;

	}
}



Measured memory_bytes: 3632
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll mod=(ll)1e9+7;
//}}}

int main(){
  int X, A;
  cin >> X >> A;
  int ans = (X < A) ? 0 : 10;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
m,n = map(int, raw_input().split())
MOD = 1000000007
lst = [m]
i = 0
while True:
  lst.append(lst[i]*lst[i]%MOD)
  i += 1
  if i > 30:
    break

ans = 1
i = 0
while True:
  if n % 2 == 1:
    ans = ans * lst[i] % MOD
    n -= 1
  i += 1
  n /= 2
  if n == 0:
    break

print ans

Measured memory_bytes: 6476
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
string s;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>s;
    int a=(s[0]-'0')*10+(s[1]-'0'), b=(s[2]-'0')*10+(s[3]-'0');
    if(a==0||a>12){
        if(b>0&&b<=12) cout <<"YYMM"<<"\n";
        else cout <<"NA"<<"\n";
    }
    else{
        if(b>0&&b<=12) cout <<"AMBIGUOUS"<<"\n";
        else cout <<"MMYY"<<"\n";
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<map>
#include<queue>
#include<set>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
int n,a[110000],ans,t;
int main(){
	scanf("%d",&n);
	fo(i,1,n) scanf("%d",&a[i]);
	t=0;ans=1;
	fo(i,2,n){
		if (a[i]<a[i-1]){
			t|=1;
		}
		if (a[i]>a[i-1]){
			t|=2;
		}
		if (t==3){
			t=0;
			ans++;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 512
// abc138_d
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;

    int cnt = 0;
    REP(i, N-1){
        if (S[i] == S[i+1]) cnt++;
    }

    print(min(N-1, cnt + 2 * K));

    return 0;
}


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

using namespace std;

const int N=1e5+5;

long long arr[N],ans[N];
int n;

int main()
{
	cin >> n;
	for(int i=0;i<n;i++)
	{
		cin >> arr[i];
		ans[0]+=(i%2?-1:1)*arr[i];
	}
	for(int i=1;i<n;i++)
	{
		ans[i]=2*arr[i-1]-ans[i-1];
	}
	for(int i=0;i<n;i++)
		cout << ans[i] << " \n"[i==n-1];
}

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

const int INF = 1e9;

//Segment Tree
class SegmentTree{
public:
  int n;
  vi node;
  vi ofset;
  SegmentTree(vi a){
    int n_ = a.size();
    n=1;
    while(n<n_)n*=2;

    node = vi(2*n-1, INF);
    for(int i=0;i<n_;i++)node[i+n-1] = a[i];
    for(int i=n-2;i>=0;i--)node[i] = min(node[2*i+1], node[2*i+2]);

    ofset = vi(2*n-1,0);
  }

  //return minimum value in [a,b). ( [l,r) is interval in which k is.)
  int rmq(int a,int b,int k=0,int l=0,int r=0){
    if(l>=r)r = n;
    if(r<=a || b<=l)return INF;
    if(a<=l && r<=b)return node[k]+ofset[k];
    int pl = rmq(a,b,2*k+1,l,(l+r)/2);
    int pr = rmq(a,b,2*k+2,(l+r)/2,r);
    return min(pl,pr) + ofset[k];
  }

  int search(int a,int b,int v,int k=0,int l=0,int r=0){
    if(l>=r)r = n;
    if(r<=a || b<=l)return INF;
    if(a<=l && r<=b && node[k]+ofset[k] >= v)return l;
    if(r-l<=1)return INF;
    int vr = rmq(a,b,2*k+2,(l+r)/2,r);
    if(vr + ofset[k] >= v){
      int res = search(a,b,v-ofset[k],2*k+1,l,(l+r)/2);
      return min(res, (l+r)/2);
    }else{
      int res = search(a,b,v-ofset[k],2*k+2,(l+r)/2,r);
      return res;
    }
  }
 
  int update_range(int a,int b,int v,int k=0,int l=0,int r=0){
    if(l>=r)r = n;
    if(r<=a || b<=l)return node[k];
    if(a<=l && r<=b){
      ofset[k] += v;
      return node[k]+ofset[k];
    }

    int vl = update_range(a,b,v,2*k+1,l,(l+r)/2);
    int vr = update_range(a,b,v,2*k+2,(l+r)/2,r);
    node[k] = min(vl,vr);
    return node[k]+ofset[k];
  }
};

int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int n,q;
  cin >> n >> q;
  string s;
  cin >> s;

  set<int> minus;
  vi h(n,1);
  rep(i,n-1){
    if(s[i+1] == '(')h[i+1] = h[i] + 1;
    else{
      h[i+1] = h[i] - 1;
      minus.insert(i+1);
    }
  }
  SegmentTree st(h);

  while(q--){
    int p;
    cin >> p; p--;
    if(s[p] == '('){
      s[p] = ')';
      minus.insert(p);
      st.update_range(p,n,-2);

      p = *minus.begin();
      s[p] = '(';
      minus.erase(p);
      st.update_range(p,n,2);
    }else{
      s[p] = '(';
      minus.erase(p);
      st.update_range(p,n,2);

      p = st.search(0,p+1,2);
      s[p] = ')';
      minus.insert(p);
      st.update_range(p,n,-2);
    }
    cout << p+1 << endl;
  }
}

Measured memory_bytes: 19036
from collections import Counter

n=int(input())
a=list(map(int,input().split()))
c=Counter(a)
s=0
for i in c:
    f=c[i]
    s+=(f*(f-1))//2
for i in a:
    ans=s 
    f=c[i]
    ans=ans-((f*(f-1))//2)
    ans+=((f-1)*(f-2))//2
    print(ans)

Measured memory_bytes: 26780
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    string s;
    int k;
    cin >> s >> k;
    rep(i,s.size()){
        int num = 26 - (s[i] - 'a');
        if (i == s.size()-1){
            if (k == num) s[i] = 'a';
            else if (k < num) s[i] += k;
            else if (k > num){
                k -= num;
                k %= 26;
                s[i] = 'a';
                s[i] += k;
            }
        }else{
            if (num == 26) continue;
            if (k - num < 0) continue;
            k -= num;
            s[i] = 'a';
        }
        if (k == 0) break;
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3720
import itertools, math

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
flag = True
if p == q:
    print(0)
else:
    for i, lst in enumerate(itertools.permutations(range(1, n + 1), n)):
        if lst == p or lst == q:
            if flag:
                ans = i
                flag = False
            else:
                print(i - ans)
                break
                

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

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

  vector<int> d(N);
  rep(i, N) cin >> d[i];

  sort(d.begin(), d.end());
  auto iter = unique(d.begin(), d.end());
  d.erase(iter, d.end());

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

Measured memory_bytes: 256
[n,t]=list(map(int,input().split()))
tlist=list(map(int,input().split()))
time=tlist[0]
ans=0
for i in range(0,n-1):
    time+=t
    if time>=tlist[i+1]:
        time=tlist[i+1]
        ans+=time-tlist[i]
    else:
        ans+=t
        time=tlist[i+1]
ans+=t
print(ans)

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

int main(){
    
    while(1)
    {
        int num;
        cin>>num;
        
        if(num == 0)
        {
            break;
        }
        
        vector< int > cardA(num);
        vector< int > cardB(num);
        
        for(int i=0;i<num;++i)
        {
            int pA, pB;
            cin>>pA>>pB;
            cardA[i] = pA;
            cardB[i] = pB;
        }
        
        int pointA = 0;
        int pointB = 0;
        
        for(int i=0;i<num;++i)
        {
            if(cardA[i] ==cardB[i])
            {
                pointA += cardA[i];
                pointB += cardA[i];
            }
            else if(cardA[i] > cardB[i])
            {
                pointA += cardA[i] + cardB[i];
            }
            else
            {
                pointB += cardA[i] + cardB[i];
            }
        }
        
        cout<<pointA<<" "<<pointB<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 0
s = gets.chomp.to_s

if s == "RRR"
  puts 3
end


if s == 'SRR' || s == 'RRS'
  puts 2
end

if s == 'RSS' || s == 'SRS'  
  puts 1
end

if s == 'SSR'  || s == 'RSR'
  puts 1
end

if s == 'SSS'
  puts 0
end



Measured memory_bytes: 14280
#include<bits/stdc++.h>
/*
CE 头文件 
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>

*/
using namespace std;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define mem(a,b) memset(a,b,sizeof (a))
#define ios std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0);
// ios和scanf,printf不能混用.即用ios必须全部cin,cout. 
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;

ll ksm(ll a,ll b){ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

map<string,int>m;
int main(){
	int n;
	scanf("%d",&n);
	rep(i,1,n){
		string s;
		cin>>s;
		m[s]++;
	}
	printf("AC x %d\n",m["AC"]);
	printf("WA x %d\n",m["WA"]);
	printf("TLE x %d\n",m["TLE"]);
	printf("RE x %d\n",m["RE"]);
    return 0;
}


Measured memory_bytes: 3768
input1 = gets
array = input1.split(" ")

num1 = array[0].to_i
num2 = array[1].to_i
num3 = array[2].to_i
num4 = num3 - (num1 - num2)
if num2 > num3 then
  num2 = num3
end
if num4 < 0 then
  num4 = 0
end
puts num2.to_s + " " + num4.to_s

Measured memory_bytes: 1788
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s string
	fmt.Scan(&s)
	
	afterRep := strings.Replace(s, "hi", "", -1)
  
	if len(afterRep) == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 640
import sys

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
#read = sys.stdin.buffer.read

def main():
    # input
    N, M = map(int, readline().split())
    H = list(map(int, readline().split()))
    paths = [[] for _ in range(N)]
    for _ in range(M):
        A, B = map(int, readline().split())
        A -= 1; B -= 1
        paths[A].append(H[B]); paths[B].append(H[A])

    ans = 0
    for i in range(N):
        Htmp = H[i]
        if len(paths[i]) > 0:
            Hmax = max(paths[i])
        else:
            Hmax = 0
        ans += (Htmp > Hmax)

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 89340
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int a,b,k; cin >> a >> b >> k;
    int gcd = GCD(a,b);
    VI d = divisor(gcd);
    out(d[d.size()-k]);

    return 0;
}

Measured memory_bytes: 256
N,M=list(map(int,input().split()))
A=[list(map(int,input().split())) for _ in range(M)]
ans=-1

x=1 if N==1 else 0
for i in range(10**(N-1)-x,10**N):
  tmp=[True if int(list(str(i))[A[m][0]-1])==A[m][1] else False for m in range(M)]
  if all(tmp)==True and (int(list(str(i))[0])!=0 or N==1):
    ans=i
    break
  
if M==0 and N==1:
  ans=0

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n,k;
ll a[101];
ll memo[100001][2];
ll findans(ll k,ll chance)
{
    if(k<a[0]&&k>=0)
    {
        if(chance==0)
        {
            return 0;
        }
        else
        {
            return 1;
        }
    }
    ll ans;
    if(chance==0)
    {
        ans=0;
    }
    else
    {
        ans=1;
    }
    if(memo[k][chance]!=-1)
    {
        return memo[k][chance];
    }
    for(ll i=0;i<n;i++)
    {
        if(k>=a[i])
        {
            if(chance==0)
            {
                ans=ans|findans(k-a[i],1-chance);
            }
            else if(chance==1)
            {
                ans=ans&findans(k-a[i],1-chance);
            }
        }
    }
    return memo[k][chance]=ans;
}
int main(){
    // Your code here!
    cin>>n>>k;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(ll i=0;i<=100000;i++)
    {
        for(ll j=0;j<2;j++)
        {
            memo[i][j]=-1;
        }
    }
    if(findans(k,0))
    {
        cout<<"First";
    }
    else
    {
        cout<<"Second";
    }
}


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

using ll = long long;

constexpr int MAX_L = 1e5;
constexpr int MOD = 1e9 + 7;

constexpr int N = 13;

ll dp[MAX_L+1][N];

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

  int mul = 1;
  bool flip{false};
  dp[S.length()][0] = 1;

  for (int i = S.length()-1; i >= 0; --i) {
    if (S[i] == '?') {
      for (int k{}; k < 10; ++k) {
        for (int j{}; j < N; ++j) {
          dp[i][(k * mul + j) % N] += dp[i+1][j];
          dp[i][(k * mul + j) % N] %= MOD;
        }
      }
    } else {
      int k = S[i] & 0xF;
      for (int j{}; j < N; ++j) {
        dp[i][(k * mul + j) % N] += dp[i+1][j];
        dp[i][(k * mul + j) % N] %= MOD;
      }
    }
    mul *= 10;
    mul %= N;
  }
  cout << dp[0][5] << endl;
  return 0;
}


Measured memory_bytes: 10624
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
    bool loop = true;
    int N, K, D[10], ans;
    cin >> N >> K;
    for (int i = 0; i < K; i++) cin >> D[i];
    for (int i = N; loop; i++) {
        loop = false;
        string tmp = to_string(i);
        for (int j = 0; j < K; j++) {
            int pos = tmp.find(to_string(D[j]));
            if (pos != string::npos) loop = true;
        }
        ans = i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext())
		{
			int w = stdIn.nextInt();
			if(w == -1)
			{
				break;
			}
			int sum = 1150;
			if(w >= 20)
			{
				sum += 1250;
				if(w >= 30)
				{
					sum += 1400 + 160 * (w - 30);
				}
				else
				{
					sum += 140 * (w - 20);
				}
			}
			else if(w >= 10)
			{
				sum += 125 * (w - 10);
			}
			System.out.println(4280 - sum);
		}
	}
}

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

using namespace std;

char s[5];

int main() {
    scanf("%s", &s);
    sort(s, s + 3);
    if(s[0] == 'a' && s[1] == 'b' && s[2] == 'c') puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {

    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;

        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }
}

class Task {


    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int h = in.nextInt();
        int n = in.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
            b[i] = in.nextInt();
        }
        int m = h + 10000;
        int[] dp = new int[m + 1];
        int inf = Integer.MAX_VALUE;
        Arrays.fill(dp, inf);
        dp[0] = 0;
        for (int i = 0; i <= m; i++) {
            if (dp[i] == inf) {
                continue;
            }
            for (int j = 0; j < n; j++) {
                if (i + a[j] <= m) {
                    dp[i + a[j]] = Math.min(dp[i + a[j]], dp[i] + b[j]);
                }
            }
        }
        int ans = inf;
        for (int i = h; i <= m; i++) {
            if (ans > dp[i]) {
                ans = dp[i];
            }
        }
        out.println(ans);
    }


}

class InputReader {

    private final BufferedReader reader;
    private StringTokenizer      tokenizer;

    public InputReader(InputStream stream){
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public String nextLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(nextLine());
        }
        return tokenizer.nextToken();
    }

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

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }

}


Measured memory_bytes: 23252