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

using ll = long long;

void solve(long long N){
    int cnt = 0;
    vector<int> v(N + 1);
    for(int i = 1;i <= 100;i++){
        for(int j = 1;j <= 100;j++){
            for(int k = 1;k <= 100;k++){
                if(i * i + j * j + k * k + i * j + j * k + i * k <= N){
                    v[i * i + j * j + k * k + i * j + j * k + i * k]++;
                }
            }
        }
    }
    for(int i = 1;i <= N;i++)
        cout<<v[i]<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 3652
l,r = map(int,input().split())
if l//2019 != r//2019:
    print(0)
else:
    
    lm = []
    for i in range(l,r+1):
        for j in range(i+1,r+1):
            lm.append(i*j%2019)
    print(min(lm))

Measured memory_bytes: 75428
#include <iostream>
#include <math.h>
#include <stdio.h>

using namespace std;

int main() {
  int N;
  cin >> N;
  int x = (int)(ceil(N / 1.08));
  if ((int)(x * 1.08) == N) {
    printf("%d\n", x);
  } else
    printf(":(\n");
}

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

public class Main{

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

	void run() {

		Scanner sc=new Scanner(System.in);

		int N=sc.nextInt();
		int Q=sc.nextInt();

		int[] A=new int[N];
		Arrays.fill(A,Integer.MAX_VALUE);

		SegmentTree seg=new SegmentTree(A);

		int min=0;
		for (int i = 0; i < Q; i++) {

			int query=sc.nextInt();
			int X=sc.nextInt();
			int Y=sc.nextInt();

			if(query==0) {
				seg.updata(X, Y);
			}else {
				min=seg.getmin(X,Y+1,0,0,-1);
				System.out.println(min);
			}

		}
	}
}




class SegmentTree {
	private int N;
	private int[] node;
	private static int INF=Integer.MAX_VALUE;

	SegmentTree(int[] v){

		int size=v.length;

		N=1;

		//NはNを超えるなかで最小の2のべき乗。
		while(N<size) {
			N*=2;
		}

		node=new int[2*N-1];

		Arrays.fill(node,INF);

		for (int i = 0; i < size; i++) {
			node[i+N-1]=v[i];
		}

		for (int i = N-2; i >= 0; i--) {
			node[i]=Math.min(node[2*i+1],node[2*i+2]);
		}

	}

	void updata(int index,int val) {
		//元の配列の要素番号から、セグ木の葉に変換する。
		index+=(N-1);

		//まず葉を更新。
		node[index]=val;

		//そこから順番に親をたどりながら更新していく
		while(index>0) {
			index=(index-1)/2;
			node[index]=Math.min(node[2*index+1],node[2*index+2]);
		}
	}

	int getmin(int a,int b,int k,int l,int r) {

		if(r<0) {r=N;};

		if(r<=a || b<=l) {
			return INF;
		}

		if(a<=l && r<=b) {
			return node[k];
		}

		int vl=getmin(a,b,2*k+1,l,(l+r)/2);
		int vr=getmin(a,b,2*k+2,(l+r)/2,r);

		return Math.min(vl,vr);
	}
}



Measured memory_bytes: 106700
from collections import deque
INF = 100001000100
n, m = [int(i) for i in input().split()]
room = [[] for _ in range(n)]
room_dis = [INF for _ in range(n)]
sign_post = [0 for _ in range(n)]


for i in range(m):
	a, b = [int(i) for i in input().split()]
	room[a-1].append(b-1)
	room[b-1].append(a-1)


d = deque([0])
dist = 1
room_dis[0] = 0

while len(d) != 0:
	tmp = d.popleft()
	for next in room[tmp]:
		if room_dis[next] > room_dis[tmp]+1:
			sign_post[next] = tmp
			room_dis[next] = room_dis[tmp]+1
			d.append(next)

print("Yes")
for i in range(1,n):
	print(sign_post[i]+1)






Measured memory_bytes: 35040
#include <iostream>
#include <string>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s = to_string(n);
  int sum = 0;
  for (int i = 0; i < s.size(); i++) {
    sum += s.at(i) - '0';
  }
  if (stoi(s) % sum == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    
	int H, W, N;
	int max, min;
    scanf("%d%d%d", &H, &W, &N);

    if(H>W){
    	max = H;
    	min = W;
	} else {
		max = W;
		min = H;
	}
	
	for(int i=1;i<=min;i++){
		if(i*max >= N){
			printf("%d", i);
			return 0;		
		} 
	}

}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

int a, b, c, d, e;
string s, t;

int main(){
  cin >> s;
  rep(i, s.size()){
    if(s.at(i) == 'P') cout<<'P';
    else cout <<'D';
  }
  cout <<endl;
  
}
 

Measured memory_bytes: 3724
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int k = sc.nextInt();
        int max = 0;
        
        for(int i=0; i<k; i++){
            if(a > 0){
                max++;
                a--;
            }
            else if(b > 0){
                b--;
            }
            else{
                max--;
                c--;
            }
        }
        System.out.println(max);
    }
}

Measured memory_bytes: 35784
#pragma GCC optimize("Ofast", "unroll-loops")

// #define TEST

#include <bits/stdc++.h>

using namespace std;

#define ll long long

int N;
string S;

void input(void){
    cin >> N >> S;
}

map<pair<string, string>, ll> cnt_r, cnt_l;

void _cnt_r(void){
    for (int f = 0; f < (1 << N); ++f){
        string sr1 = "", sr0 = "";
        for (int i = 0; i < N; ++i){
            if (f & (1 << i))
                sr1 = S[N + i] + sr1;
            else
                sr0 = sr0 + S[N + i];
        }
        ++cnt_r[{sr1, sr0}];
    }
}

void _cnt_l(void){
    for (int f = 0; f < (1 << N); ++f){
        string sl0 = "", sl1 = "";
        for (int i = 0; i < N; ++i){
            if (f & (1 << i))
                sl1 = S[i] + sl1;
            else
                sl0 = sl0 + S[i];
        }
        ++cnt_l[{sl0, sl1}];
    }
}

ll solve(void){
    _cnt_r(); _cnt_l();
    ll res = 0;
    for (auto& e : cnt_r){
        ll r = e.second;
        ll l = cnt_l[e.first];
        res += r * l;
    }
    return res;
}

int main(void){
    input();
    cout << solve() << endl;
    return 0;
}

Measured memory_bytes: 101376
from itertools import product
import re

N = int(input())
MOD = 10 ** 9 + 7

dp = [{''.join(last_3): 0 for last_3 in product('AGCT', repeat=3)} for i in range(N + 1)]
dp[0]['TTT'] = 1
NG_pattern = r'.*AGC|.*ACG|.*GAC|A.GC|AG.C|'

for i in range(N):
    for last_3 in product('AGCT', repeat=3):
        last_3 = ''.join(last_3)
        for next_s in 'AGCT':
            if re.match(NG_pattern, last_3 + next_s).group():
                continue
            else:
                dp[i + 1][last_3[1:] + next_s] += dp[i][last_3]
                dp[i + 1][last_3[1:] + next_s] %= MOD

print(sum(dp[-1].values()) % MOD)


Measured memory_bytes: 4084
import sys
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    r = i2n()
    print(3 * r * r)

main()


Measured memory_bytes: 38384
//In the name of Allah :)
#include <bits/stdc++.h>
#include <math.h>
using namespace std;

const int MAXN = 2e5 + 10;

long long pow(long long a){
        long long ans = 1;
        int n = 5;
        while(n--){
                ans *= a;
        }
        return ans;
}

int main(){
	ios_base::sync_with_stdio(NULL);cin.tie(nullptr);cout.tie(nullptr);
        long long x , a , b;
        cin >> x;
        for(long long i = -1000 ; i < 1000 ; i++){
                for(long long j = -1000 ; j < 1000 ; j++){
                        a = pow(i);
                        b = pow(j);
                        if(a - b == x){
                                cout << i << ' ' << j << '\n';
                                return 0;
                        }
                }
        }

}


Measured memory_bytes: 3648
#include <iostream>
using namespace std;
int main()
{
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  for (;;) {
    C -= B;
    if (C <= 0) {
      cout << "Yes" << endl;
      return 0;
    }
    A -= D;
    if (A <= 0) {
      cout << "No" << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 3628
n = int(input())
h = list(reversed(list(map(int, input().split()))))
for i in range(1, n):
    if h[i] > h[i - 1]:
        if h[i] - h[i - 1] > 1:
            print("No")
            exit()
        else:
            h[i] -= 1
print("Yes")

Measured memory_bytes: 14252
#include <iostream>
#include <string>
#define REP(i,k,n) for(int(i)=(k);(i)<(n);(i)++)
using namespace std;

const int MAX_N = (int)2e5 + 500;

int main()
{
  long N,T;
  long t[MAX_N];
  cin >> N >> T;
  REP(i,0,N) cin >> t[i];

  long res = 0;
  REP(i,0,N-1) {
    res += min(T, t[i+1] - t[i]);
  }
  // 最後の人は必ず T 秒出る
  res += T;
  cout << res << endl;

  return 0;
}


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

int main(){
	
	int a,b;cin>>a>>b;
	cout<<(a+b+1)/2<<endl;
	return 0;
}

//cout << ans?"Yes":"No" << endl;

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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

using ll=long long; 
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; 

#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (300006)
ll ans,n,m,k,A[MAXN],B[MAXN];
int main(){
	FAST
	cin>>n>>m>>k;
	FOR(i,1,n)cin>>A[i];
	FOR(i,1,m)cin>>B[i];
	FOR(i,1,m)B[i]+=B[i-1];
	FOR(i,1,n)A[i]+=A[i-1];
	FOR(i,0,n)if(A[i]<=k){
		ans = max(ans, i + (upper_bound(B+1, B+m+1, k - A[i]) - B - 1));
	}
	cout<<ans<<'\n';
}


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

int main()
{
  long long int N,A,B;
  cin>>N>>A>>B;
  long long int ans;
  if (N==1 && A==B) {
    ans=1;
  }else if(N==1 && A!=B){
    ans=0;
  }else if(A>B){
    ans=0;
  }else{
    ans = B*(N-1)+A-(A*(N-1)+B)+1;
  }
  cout<< ans <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

vector<int> a,b,bas,bbs;
int ans1,ans2,n;

signed main(){
	read(n);
	for(int i=1;i<=n;i++) bas.push_back(i);
	for(int i=1,x;i<=n;i++) a.push_back(read(x));
	for(int i=1,x;i<=n;i++) b.push_back(read(x));
	ans1=1,ans2=1;
	bbs=bas;
	while(bas!=a){
		ans1++;
		next_permutation(bas.begin(),bas.end());
	}
	while(bbs!=b){
		ans2++;
		next_permutation(bbs.begin(),bbs.end());
	}
	write(abs(ans2-ans1));
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] P = new int[N + 1];
		for (int i = 1; i <= N; i++)
			P[i] = sc.nextInt();
		int[] Q = new int[N + 1];
		for (int i = 1; i <= N; i++)
			Q[i] = sc.nextInt();
		int a = 0;
		for (int i = 1; i <= N; i++) {
			int count = 1;
			for (int j = 1; j < i; j++) {
				if (P[i] > P[j])
					count++;
			}
			a += fact(N - i) * (P[i] - count);
		}

		int b = 0;
		for (int i = 1; i <= N; i++) {
			int count = 1;
			for (int j = 1; j < i; j++) {
				if (Q[i] > Q[j])
					count++;
			}
			b += fact(N - i) * (Q[i] - count);
		}

		System.out.println(Math.abs(a - b));

	}

	public static int fact(int n) {
		if (n == 1 || n == 0)
			return 1;
		else
			return n * fact(n - 1);
	}
}


Measured memory_bytes: 22100
#include<stdio.h>
#include<string.h>
int main()
{
    long long int x;
    scanf("%lld",&x);
    if(x%10==2||x%10==4||x%10==5||x%10==7||x%10==9)
    {
        printf("hon");
    }else if(x%10==0||x%10==1||x%10==6||x%10==8)
    {
        printf("pon");
    }else{
    printf("bon");
    }
}

Measured memory_bytes: 1708
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <set>
#include <numeric>
#include <bitset>
#include <map>
#include <limits.h>
using namespace std;
typedef unsigned long ul;
typedef pair<ul, ul> P;
const int INF = 1e9;

long long gcd(long long x, long long y){
			if(x<y){
				long long temp = x;
			x = y;
				y = temp;
			}
			long long r = x % y;
				while(r!=0){
					x = y;
					y = r;
				r = x % y;
	    		}
			return y;
	    }

int main(){
int A,B,C,X,Y;
cin >> A >> B >> C >> X >> Y;
long long  ans = 0;
if(A+B>2*C){
	long long ans_1 = C*2*min(X,Y);
	if(X>Y){
		ans_1 += A*(X-Y);
	}
	else{
		ans_1 += B*(Y-X);
	}

	long long ans_2 = C*2*max(X,Y);
	ans = min(ans_1,ans_2);
}
else{
	ans += A*X + B*Y;
}
cout << ans << endl;
}

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

using namespace std;

int main()
{
    int t;
    
    scanf("%d", &t);
    
    while (t--){
        int n;
        int up = 0, down = 0;
        
        scanf("%d", &n);
        
        int p;
        for (int i = 0; i < n; i++){
            int x;
            scanf("%d", &x);
            
            if (!i) p = x;
            
            if (p < x) up = max(up, x - p);
            else down = max(down, p - x);
            
            p = x;
        }
        
        printf("%d %d\n", up, down);
    }
}

Measured memory_bytes: 1188
def func():
    tvs = []
    for i in range(num):
        tvs.append((-1, -1))
    for i in range(len(bans)):
        now = bans[i][0]
        can = bans[i][2]
        # tvs = [tv for tv in tvs if tv[1] == can] + [tv for tv in tvs if tv[1] != can]
        for j, tv in enumerate(tvs):
            if tv[1] == -1 or (tv[1] == can and tv[0] <= now) or tv[0] <= now - 1:
                del tvs[j]
                tvs.append((bans[i][1], can))
                break
        else:
            return False
    return True


n, C = map(int, input().split())

bans = []
for i in range(n):
    bans.append(tuple(map(int, input().split())))
bans.sort(key=lambda x: x[0])

for num in range(1, 1024):
    if func():
        print(num)
        break


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

int main() {
	int a, b, ans;
	cin >> a >> b;
	if (a >= 1 && a <= 9 && b >= 1 && b <= 9) {
		ans = a * b;
	}
	else {
		ans = -1;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

ll N, K;

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

  cin >> N >> K;

  if (K == 0) {
    cout << N * N << endl;
    return 0;
  }
  
  ll ans = 0ll;

  FOR(i, K, N + 1) {
    ll tmp = max((ll)i - K, 0ll);
    ans += tmp * (ll)((N + 1) / i);
    ll rest =  ((N + 1) % i);
    ans += max(rest - K, 0ll);
    // if (rest < K) continue;
    // ans += rest - K;
    // debug(i);
    // debug(ans);
  }

  cout << ans << endl;
  
  return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds; 
using namespace std;
using   ll=long long;
using   ld=long double;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ordered_set 	tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int             long long int

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007
#define hell            998244353 

ll mod_pow(ll a,ll b) 
{
    ll res = 1;
    while(b)	
    {
        if(b&1) 	
        {
        	res=(res*a)%mod;
        }
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a) 
{
	return mod_pow(a , mod-2);
}

void solve()
{
	int l , r , x;
	
	cin >> l >> r >> x;
	
	cout << r/x - (l-1)/x;
}

signed main() {
    fast;
    
    int t = 1;
    
    //cin >> t;
    
    while(t--) {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define fir first
#define sec second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int MAXN=105;
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc;
	for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny;
}
int n,m,k,Mod,F[2][MAXN][MAXN],C[MAXN][MAXN],Fpow[MAXN][MAXN];
inline void pre(int n=100){
	Rep(i,0,n){C[i][0]=1;Rep(j,1,i)C[i][j]=(C[i-1][j-1]+C[i-1][j])%Mod;}
	Rep(i,1,n){Fpow[i][0]=1;Rep(j,1,n)Fpow[i][j]=1ll*Fpow[i][j-1]*i%Mod;}
}
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read(),m=read(),k=read(),Mod=read(),pre();
	F[0][0][0]=1;int now=0;
	Rep(t,1,k){
		memset(F[now^1],0,sizeof(F[now^1]));
		Rep(i,0,n)Rep(j,0,m)if(F[now][i][j]){
			for(int a=0,x=F[now][i][j],y=1ll*Fpow[k-t+1][j]*Fpow[t][m-j]%Mod;i+a<=n;a++,x=1ll*x*y%Mod)
				F[now^1][i+a][j]=(F[now^1][i+a][j]+1ll*C[n-i][a]*x)%Mod;
		}now^=1,memset(F[now^1],0,sizeof(F[now^1]));
		Rep(i,0,n)Rep(j,0,m)if(F[now][i][j]){
			for(int b=0,x=F[now][i][j],y=1ll*Fpow[k-t+1][i]*Fpow[t][n-i]%Mod;j+b<=m;b++,x=1ll*x*y%Mod)
				F[now^1][i][j+b]=(F[now^1][i][j+b]+1ll*C[m-j][b]*x)%Mod;
		}now^=1,memset(F[now^1],0,sizeof(F[now^1]));
		Rep(i,0,n)Rep(j,0,m)if(F[now][i][j]){
			for(int c=0,x=F[now][i][j],y=1ll*(Mod-Fpow[k-t][j])*Fpow[t][m-j]%Mod;i+c<=n;c++,x=1ll*x*y%Mod)
				F[now^1][i+c][j]=(F[now^1][i+c][j]+1ll*C[n-i][c]*x)%Mod;
		}now^=1,memset(F[now^1],0,sizeof(F[now^1]));
		Rep(i,0,n)Rep(j,0,m)if(F[now][i][j]){
			for(int d=0,x=F[now][i][j],y=1ll*(Mod-Fpow[k-t][i])*Fpow[t][n-i]%Mod;j+d<=m;d++,x=1ll*x*y%Mod)
				F[now^1][i][j+d]=(F[now^1][i][j+d]+1ll*C[m-j][d]*x)%Mod;
		}now^=1;
	}cout<<F[now][n][m]<<"\n";
	return 0;
}




Measured memory_bytes: 3652
t = gets.chomp.to_i
w = gets.chomp.split(' ').map{|i| i.to_i }

df = []
t.times{|i|
  w1 = w[0 .. i]
  w2 = w[i + 1 .. -1]
  sum1 = 0
  sum2 = 0
  w1.each{|ii| sum1 += ii }
  w2.each{|ii| sum2 += ii }
  df[i] = (sum1 - sum2).abs
}
puts df.min


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

using namespace std;
const int N=2e5+5;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    int mn=n+1,ans=0;
    for(int i=0;i<n;i++)
    {
        int x;cin>>x;
        if(mn>x) ans++;
        mn=min(mn,x);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
from pprint import pprint


n = int(input())

points = [list(map(int,input().split())) for _ in range(n)]

dp_table = [[-float("inf")]*(n+1) for _ in range(3)]

#0日目は幸福度0
dp_table[0][0] = 0
dp_table[1][0] = 0
dp_table[2][0] = 0

for i in range(1,n+1):
    for abc in range(3):
        for before_abc in range(3):
            if abc != before_abc:
                dp_table[abc][i] = max(dp_table[abc][i],dp_table[before_abc][i-1] + points[i-1][abc])
            else:
                continue

pprint(max(dp_table[0][-1],dp_table[1][-1],dp_table[2][-1]))


Measured memory_bytes: 43004
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;

int N;
vector<LL>vec;
map<LL, int>cnt;

int main() {
	cin >> N;
	for (int i = 0; i < N; ++i) {
		LL tmp; cin >> tmp;
		vec.push_back(tmp);
		cnt[tmp]++;
	}
	if (N % 3 != 0) {
		for (LL elm : vec) {
			if (elm != 0) {
				cout << "No" << endl;
				return 0;
			}
		}
		cout << "Yes" << endl;
	}
	else {
		vector<int>cntv;
		vector<LL>xxo;
		for (auto p : cnt) {
			cntv.push_back(p.second);
			if (p.second % (N / 3)) {
				cout << "No" << endl;
				return 0;
			}
			for (int j = 0; j < (p.second / (N / 3)); ++j) {
				xxo.push_back(p.first);
			}
		}
		LL who = 0;
		for (LL elm : xxo) {
			who ^= elm;
		}
		if (who != 0) {
			cout << "No" << endl;
		}
		else {
			cout << "Yes" << endl;
		}
	}
	return 0;
}

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

const int N = 1e6 + 5;
typedef long long LL;

struct node {
	int val, low;
} a[N];
string s;
int tot, n, m, sum;

bool cmp1(node a, node b) {
	return a.val > b.val;
}

bool cmp2(node a, node b) {
	return a.low > b.low;
}

bool cmp3(node a, node b) {
	return -a.val + a.low < -b.val + b.low; 
}


int main() {
	cin>>n;
	for(int i = 1; i <= n; i++) {
		cin>>s;
		a[i].val = a[i].low = 0;
		for(int j = 0; j < (int) s.size(); j++) {
			if(s[j] == '(') tot++, a[i].val++;
			else tot--, a[i].val--;
			a[i].low = min(a[i].val, a[i].low);
		}
 	}
 	if(tot) {
 		cout<<"No"<<endl;
 		return 0;
 	} 
 	sort(a + 1, a + n + 1, cmp1);
 	for(int i = 1; i <= n; i++)
 		if(a[i].val <= 0) {
 			m = i - 1;
 			break;
 		}
 	sort(a + 1, a + m + 1, cmp2);
 	for(int i = 1; i <= m; i++) {
 		if(sum + a[i].low < 0) {
 			cout<<"No"<<endl;
 			return 0;
 		}
 		sum += a[i].val;
 	}
 	sort(a + m + 1, a + n + 1, cmp3);
 	 for(int i = m + 1; i <= n; i++) {
 		if(sum + a[i].low < 0) {
 			cout<<"No"<<endl;
 			return 0;
 		}
 		sum += a[i].val;
 	}
 	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 11416
#include<bits/stdc++.h>
using namespace std;
int n;
vector<int>adj[100005];
int lf[100005];
int dfs(int x,int p){
    int ret=0,cnt=0;
    for(auto y:adj[x]){
        if(y==p)continue;
        int z=dfs(y,x);
        ret+=z;
        if(z==0){++cnt;}
    }
    if(cnt>1)ret+=cnt-1;
    return ret;
}
int needed=-1;
void getnode(int x,int p){

    if(needed!=-1)return;
    lf[x]=-1;
    if(adj[x].size()==1&&p!=-1)lf[x]=x;
    int cnt=0,cnt1=0;
    for(auto y:adj[x]){
        if(y==p)continue;
        getnode(y,x);
        if(needed!=-1)return;
        if(lf[y]!=-1)cnt++,lf[x]=lf[y];
        cnt1++;
    }

    if(cnt1!=cnt)lf[x]=-1;
    else if(cnt>1)needed=lf[x];
}
int main()
{
    cin>>n;
    for(int i=1;i<n;++i){
        int u,v;
        scanf("%d%d",&u,&v);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    int x=0;
    for(int i=0;i<n;++i)if(adj[i].size()==1){x=i;break;}
    getnode(x,-1);
    if(needed!=-1)x=needed;
    cout<<dfs(x,-1)+1<<endl;
}


Measured memory_bytes: 13952
import java.util.*;
import java.math.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int _n = n;
        int x = 0;
        while(n != 0){
            x += n % 10;
            n /= 10;
        }
        boolean f = (_n % x == 0);
        io.YesNo(f);

        sc.close();
    }
}

class io{
    public static void br(){
        System.out.println("");
    }

    public static void YesNo(boolean f) {
        System.out.println(f?"Yes":"No");
    }
    public static void YESNO(boolean f) {
        System.out.println(f?"YES":"NO");
    }

}

class Algo{
    public static boolean isOdd(int n){
        return n % 2 == 1;
    }
    public static boolean isEven(int n){
        return n % 2 == 0;
    }


}



Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
int a[26]={0};
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		char c;
		cin>>c;
		a[c-65]=1;
	}
	int s=0;
	for(int i=0;i<26;i++)
	{
		s+=a[i];
	}
	if(s==3)
	{
		cout<<"Three";
	}
	else
	{
		cout<<"Four";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <fstream>
#include <cstdio>
using namespace std;
// vector<pair<int,int> > v;
// cin.ignore();//twice getline(cin,s);
// g++ iterator.cpp -std=c++17
// cout<<(A + B == C ? "YES" : "NO")<<endl;
// __gcd(a,b)
// string s=to_string(n);
// string p=s.substr(0,len);
// string q=s.insert(0,str);
// sort(arr, arr+n, greater<int>());
// cout<<fixed<<setprecision(9)<<pi<<endl
// const  double pi = acos(-1.0);
// sort(v.rbegin(),v.rend());
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define vll vector<ll>
#define mll map<ll,ll >
#define mlli map<ll,ll>::iterator
#define size size()
#define endl "\n"
#define ll long long int
#define ld long double
void fast(){ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);}


int main(void)
{
	fast();
	
	ll n;

	cin>>n;
	ll a[n];

	// ll maxi = INT_MIN;

	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
		
		// maxi = max(maxi,a[i]);
	}

	ll ans = 0;

	for(ll i=1;i<n;i++)
	{
		if(a[i-1]>a[i])
		{
			ans = ans + (a[i-1]-a[i]);

			a[i]=a[i]+(a[i-1]-a[i]);
		}
	}

	cout<<ans<<endl;
}

Measured memory_bytes: 5200
# -*- coding: utf-8 -*-

from collections import deque
import copy

class Puzzle(list):
    def __init__(self):
        list.__init__(self)
        self.space = None
        self.path = ""
    
    def __hash__(self):
        return hash(str(self[:]))

if __name__ == '__main__':
    
    N = 3
    N2 = 9
    dx = [-1, 0, 1, 0]
    dy = [0, -1, 0, 1]
    d = ["u", "l", "d", "r"]

    p = Puzzle()
    for i in range(N):
        p += [int(x) for x in input().split()]
    for i in range(N2):
        if p[i] == 0:
            p[i] = N2
            p.space = i
    target = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    def isTarget(p):
        return p[:] == target[:]

    def bfs(s):
        Q = deque()
        V = set()
        Q.append(s)
        V.add(s)
        while Q:
            u = Q.popleft()
            if isTarget(u):
                return u.path
            sx = u.space // N
            sy = u.space % N
            for r in range(4):
                tx = sx + dx[r]
                ty = sy + dy[r]
                if not (0<= tx < N and 0 <= ty < N):
                    continue
                v = Puzzle()
                v[:] = u[:]
                v.path = u.path
                change = tx * N + ty
                v[u.space], v[change] = v[change], v[u.space]
                v.space = change
                if not v in V:
                    V.add(v)
                    v.path += d[r]
                    Q.append(v)

        return "unsolvable"

    ans = bfs(p)
    print(len(ans))





Measured memory_bytes: 87500
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	z := getNextInt(scanner)
	w := getNextInt(scanner)

	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}

	ans := solve(n, z, w, aa)
	fmt.Fprintln(writer, ans)

	writer.Flush()
}

func solve(n, z, w int, aa []int) int {
	if n == 1 {
		return absint(aa[0] - w)
	}
	return maxint(absint(aa[n-1]-w), absint(aa[n-2]-aa[n-1]))
}

func absint(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func maxint(a int, b int) int {
	if a > b {
		return a
	}
	return b
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

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

    cout << (b - a == c - b ? "YES" : "NO") << '\n';

    return 0;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define LL long long

map <string, int> ha;
string s;
int cnt = 0;

int main () {
	int n; cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> s;
		if (ha[s] == 0) {
			cnt ++;
			ha[s] = 1;
		}
	}
	cout << cnt;
	
	return 0;
}


Measured memory_bytes: 19184
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define repr(i, n) for (ll i = n - 1; i >= 0; --i)
const int MOD = 1000000007;
const ll INF = 10000000000;
using namespace std;

void solve(void)
{
    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];
    ll ans = 0;
    repr(i, n)
    {
        ll x = ans + a[i];
        if (x % b[i] != 0)
            ans += b[i] - x % b[i];
    }
    cout << ans << endl;
}
int main(void)
{
    solve();
}

Measured memory_bytes: 4752
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define DEBUG
#define PI 3.141592653589793238462643383279

#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 1; i <= n; i++)
#define REPR(i, n) for(ll i = n; i >= 1; i--)
#define FOR(i, m, n) for(ll i = m; i <= n; i++)
#define INF 1e9+123
#define VEC(type,A,N) vector<type> A(N+10)
#define VECi(type,A,N,i) vector<type> A(N+10,i)
#define VEC2(type,A,N,M) vector<vector<type>> A(N+10,vector<type>(M+10))
#define VEC2i(type,A,N,M,i) vector<vector<type>> A(N+10,vector<type>(M+10,i))
#define ALL(v) v.begin()+1, v.end()-9
ll frac(ll k){
    int s = 1;
    for (ll i=1; i<=k; ++i)s *= i;
    return s;
}
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);
}
ll antidiv(ll N,ll C,ll D){
    return N-floor(N/C)-floor(N/D)+floor(N/lcm(C,D));
}
int main(){
    ll N;
    cin>>N;
    
    ll b;
    cin>>b;
    //s(b);
    ll sum=b,m=b;
    REP(i,N-2){
        cin>>b;
        //s(b);
        sum+=min(b,m);
        m=b;
    }
    cout<<sum+b;
    
    
    //sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
// "header" {{{
#pragma GCC optimize("Ofast")

#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <tuple>
#include <iomanip>
#include <climits>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int>
#define int int64_t
#define double long double
#define Fixed fixed << setprecision(10)
#define moke_pair make_pair

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int64_t mod1 = 1000000007;
constexpr int64_t mod2 = 998244353;

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

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class T,class U> using umap = unordered_map<T,U>;

inline int64_t updiv(int64_t n,int64_t d){ return ((n + d -1) / d); }
inline int square(int a){ return a * a; }
// }}}

signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int n,maxv = 0,sum = 0;
    cin >> n;

    rep(i,n){
        int a;
        cin >> a;
        sum += __builtin_ctz(a);
    }

    cout << sum << '\n';

    return 0;
}


Measured memory_bytes: 256
def resolve():
    from collections import deque
    n,m = map(int,input().split()) 
    edge = [[] for i in range(n+1)]
    visit=[-1]*(n+1)
    for i in range(m):
        a,b = map(int,input().split())
        edge[a].append(b)
        edge[b].append(a)
    chk=deque()
    chk.append([1,0])
    while chk:
        x,bx=chk.popleft()
        if visit[x]>-1:
            continue
        visit[x]=bx
        bx=x
        for i in edge[x]:
            if visit[i]>-1:
                continue
            chk.append([i,bx])
    print('Yes')
    for i in visit[2:]:print(i)

if __name__ == '__main__':
    resolve()

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

typedef vector<vector<int>> Graph;
Graph G;
int N, M;
vector<int> color;

bool dfs(int v, int c)
{
    color[v] = c;
    bool res = true;
    for (auto u : G[v]) {
        if (color[u] != -1 && color[u] == color[v]) return false;
        if (color[u] != -1) continue;
        res &= dfs(u, 1-c);
    }
    return res;
}

int main()
{
    ios::sync_with_stdio(false);
    cin >> N >> M;

    G.resize(N);
    color.resize(N);
    fill(ALL(color), -1);

    rep(i, M) {
        int A, B;
        cin >> A >> B;
        A--, B--;
        G[A].push_back(B);
        G[B].push_back(A);
    }

    if (dfs(0, 0)) {
        ll b = 0, w = 0;
        rep(i, N) (color[i] ? b : w)++;
        cout << b * w - M << endl;
    } else {
        cout << ((ll)N * (N - 1) / 2 - M) << endl;
    }
}

Measured memory_bytes: 6784
import std;
import core.bitop;

// dfmt off
ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
void aryWrite(T = long)(T[] ary){ ary.map!(x => x.text()).join(' ').writeln(); }
alias Pair = Tuple!(long, "H", long, "W", long, "cost");
alias PQueue(T, alias less = "a>b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    auto n = lread();
    auto a = aryread();
    long[long] dic;
    a.each!(x => dic[x] = (x in dic) ? dic[x] + 1 : 1);
    auto rm = dic.byValue().filter!(x => x > 1)
        .map!(y => (y + 1) % 2)
        .sum();
    
    writeln(a.sort.uniq.array().length - (rm % 2));
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 12076
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>

int main() {
  int n, a, b;
  std::string s;
  int ax = 0;
  int bx = 0;
  std::cin >> n >> a >> b >> s;
  for (auto c : s) {
    bool ans = false;
    if (c == 'a') {
      if (ax + bx < a + b) {
        ans = true;
        ++ax;
      }
    } else if (c == 'b') {
      if (ax + bx < a + b and bx < b) {
        ans = true;
        ++bx;
      }
    }
    std::cout << (ans? "Yes": "No") << std::endl;
  }
  return 0;
}


Measured memory_bytes: 1336
#include <algorithm>
#include <iostream>
#include <cstdio>
#define int long long
using namespace std;
inline int read(){int tot=1;char c=getchar();while(c!='-'&&(c<'0'||c>'9'))c=getchar();if(c=='-')tot=-1,c=getchar();
int sum=0;while(c<='9'&&c>='0')sum=sum*10+c-'0',c=getchar();return sum*tot;}
void wr(int x){if(x<0){putchar('-');wr(-x);return;}if(x>=10)wr(x/10);putchar(x%10+'0');}
void wrn(int x){wr(x);putchar('\n');}
struct arr{
	int sum,id;
}a[200005];
bool cmp(arr a,arr b){
	if(a.sum==b.sum)return a.id<b.id;
	return a.sum>b.sum;
}
int ans[200005];
signed main()
{
	int n=read();
	for(int i=1;i<=n;i++)a[i].sum=read(),a[i].id=i;
	int f=1,s=2;
	sort(a+1,a+1+n,cmp);
	while(s<=n){
		while(a[s].sum==a[s-1].sum)s++;
		ans[a[f].id]+=(s-1)*(a[f].sum-a[s].sum);
		if(a[s].id<a[f].id)f=s;
		else a[f].sum=a[s].sum;
		s++;
	}
	ans[a[f].id]+=n*a[f].sum;
	for(int i=1;i<=n;i++)wrn(ans[i]);
}

Measured memory_bytes: 4352
N,M=map(int,input().split())
A=[input() for i in range(N)]
B=[input() for i in range(M)]
inc=0
for i in range(N-M+1):
    for j in range(N-M+1):
        if(B[0]==A[i][j:j+M]):
            t=1
            for k in range(1,M):
                if(B[k]!=A[i+k][j:j+M]):
                    t=0
            if(t==1):
                print("Yes")
                exit()
print("No")

Measured memory_bytes: 3064
n, m = map(int,input().split())
dp = [0 for _ in range(n+1)]
S = input()
a = [0 for _ in range(m)]
for i in range(1,n):
    if S[i-1:i+1] == "AC":
        dp[i] = dp[i-1]+1
    else:dp[i] = dp[i-1]
for i in range(m):
    x, y = map(int,input().split())
    a[i] = dp[y-1] - dp[x-1]
print(*a,sep="\n")

Measured memory_bytes: 11832
// atc.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <string>
#include    <algorithm>
using namespace std;

int main()
{
	int x;
	cin >> x;
	vector<int> A(x,0);

	for (int i = 0; i < x; i++) {
		cin >> A[i];
	}

	int sum = 0;

	for (int i = 0; i < x; i++) {
			sum +=  A[i];
	}
	sum -= x;

	cout << sum << endl;


	system("pause");

	return 0;

}


Measured memory_bytes: 504
/*
      author : nishi5451
      created: 11.08.2020 23:28:18
*/

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


int main(){
    int n;
    cin >> n;
    int ans;
    if(n%1000==0) ans = 0;
    else ans = (n/1000+1)*1000-n;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define sep                         ' '
#define endl                        '\n'
#define SZ(x)                       ll(x.size())

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const ll MAXN = 1e4 + 10;
const ll LOG = 22;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

ll n , ans , cnt[3] , A[MAXN] , C[MAXN][3][3];
string s;

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

    cin >> n >> s;
    for(ll i = 0 ; i < n ; i++){
        if(s[i] == 'R') A[i] = 0;
        if(s[i] == 'G') A[i] = 1;
        if(s[i] == 'B') A[i] = 2;
        cnt[A[i]]++;
    }

    ans = cnt[0] * cnt[1] * cnt[2];
    for(ll i = 0 ; i < n ; i++){
        for(ll j = i + 1 ; j < n ; j++){
            ll k = j + (j - i);
            if(k >= n)  continue;
            if(A[i] != A[j] && A[j] != A[k] && A[i] != A[k])    ans--;
        }
    }
    cout << ans << endl;

    return 0;
}
/*

*/


Measured memory_bytes: 3672
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
	int n,k;cin>>n>>k;
	int a[1005]={0};
	int sum=0;
	for(int i=1;i<=n;i++) cin>>a[i],sum+=a[i];
	sort(a+1,a+n+1);
	if(a[n-k+1]>=ceil(double(sum)/(4*k))) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int w,h,x,y,r;
    scanf("%d %d %d %d %d", &w,&h,&x,&y,&r);
    if(x - r < 0 || x + r > w || y - r < 0 || y + r >h){
        printf("No\n");
    }else{
        printf("Yes\n");
    }
    return 0;
}


Measured memory_bytes: 2084
N, K, Q = map(int, input().split())
A = [int(input()) for i in range(Q)]

scores = [0] * N
for i in range(Q):
    scores[A[i]-1] += 1

for j in range(N):
    if K - Q + scores[j] > 0:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 8592
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)

void solve(int n) {
    int a[n];
    int sum = 0;
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }
    double ave = (double)sum / n;
    sum = 0;
    rep(i, n) {
        if (a[i] <= ave) sum++;
    }
    cout << sum << endl;
}
int main() {
    int n;
    while (cin >> n && n) {
        solve(n);
    }
}



Measured memory_bytes: 3124
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,pair<ll,ll> >
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 100009;
ll a,b;
string c,d;
stringstream ss;
long double f;
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>a>>b;
    ss<<a;
    ss>>c;
    ss.clear();
    ss<<b;
    ss>>d;
    c = c + d;
    ss.clear();
    ss<<c;
    ss>>a;
    f = sqrt(a);
    cout<<((f == (ll)f) ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 256
from collections import deque

K = int(input()) 
a = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])

for i in range(K-1):
    j = a.popleft()
    if j%10 != 0:
        a.append((10*j) + ((j%10) -1))
        
    a.append((10*j)+j%10)
    
    if j%10 != 9:
        a.append((10*j) +((j%10)+1))
    
print(a.popleft())

Measured memory_bytes: 12384
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {
    char s;
    cin >> s;
    if (s == 'A') {
        cout << "T" << endl;
    } else 
    if (s == 'T') {
        cout << "A" << endl;
    } else 
    if (s == 'G') {
        cout << "C" << endl;
    } else {
        cout << "G" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
/*#include <math.h> INFINITY*/

#define MAX 500000
#define INFINITY 1000000001

void mergeSort(int *, int, int);
void merge(int *, int, int, int);

int L[MAX / 2 + 2], R[MAX / 2 + 2];
int count = 0;

int main(){
  int *A, n, i;
  scanf("%d",&n);
  A = malloc(n * sizeof(int));
  for(i = 0; i < n; i++){
    scanf("%d",&A[i]);
  }
  mergeSort(A, 0, n);
  for(i = 0; i < n - 1; i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[n - 1]);
  printf("%d\n",count);
  
  return 0;
}

void mergeSort(int *A, int left, int right){
  int mid;
  if(left + 1 != right){
    mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}
void merge(int *A, int left, int mid, int right){
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  for(i = 0; i < n1; i++){
    L[i] = A[left + i];
  }
  for(i = 0; i < n2; i++){
    R[i] = A[mid + i];
  }
  L[n1] = INFINITY;
  R[n2] = INFINITY;
  i = 0;
  j = 0;
  for(k = left; k < right; k++){
    count++;
    if(L[i] <= R[j]){
      A[k] = L[i++];
    }
    else{
      A[k] = R[j++];
    }
  }
}



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

int main(){
	int m;
	cin>>m;
	for(int i=0;i<m;i++){
		int str,len,n,ctop=0;
		cin>>str>>len>>n;
		for(int j=0;j<n;j++){
			int typ,cst,crt=str;
			double rate;
			cin>>typ>>rate>>cst;
			if(typ==1){
				for(int k=0;k<len;k++){
					crt+=crt*rate-cst;
				}
			}else{
				int add=0;
				for(int k=0;k<len;k++){
					add+=crt*rate;
					crt-=cst;
				}
				crt+=add;
			}
			if(ctop<crt){
				ctop=crt;
			}
		}
		cout<<ctop<<endl;
	}
	return 0;
}

Measured memory_bytes: 1232
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>

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

using namespace std;
typedef long long int ll;
const int INF = 1000000000;
const double PI = 3.1415926535897932;
const ll MOD = 1000000007;

int main()
{
    int n, m;
    cin >> n >> m;

    priority_queue<int> pque;
    rep(i, n) {
        int a;
        cin >> a;
        pque.push(a);
    }
    rep(i, m) {
        int discount = pque.top() / 2;
        pque.pop();
        pque.push(discount);
    }
    ll ans = 0;
    while(!pque.empty()) {
        int price = pque.top();
        pque.pop();
        ans += ll(price);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 892