akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
 
#define Max 10000
#define NIL -1
 
struct tree{int parent,left,right;};
struct tree T[Max];
int n;
 
void pre(int u){
    if(u==NIL) return;
    printf(" %d",u);
    pre(T[u].left);
    pre(T[u].right);
}
 
void mid(int u){
    if(u==NIL) return ;
    mid(T[u].left);
    printf(" %d",u);
    mid(T[u].right);
}
 
void back(int u){
    if( u == NIL) return;
    back(T[u].left);
    back(T[u].right);
    printf(" %d",u);
}
 
int main(){
    scanf("%d",&n);
    int i;
    int id,l,r;
    int root;
    for(i=0;i<n;i++) T[i].parent = NIL;
    for(i=0;i<n;i++){
        scanf("%d",&id);
        scanf("%d%d",&l,&r);
        T[id].left = l;
        T[id].right = r;
        if(l != NIL) T[l].parent = id;
        if(r != NIL) T[r].parent = id;
    }
 
    for(i=0;i<n;i++)if(T[i].parent == NIL) root = i;
 
    printf("Preorder\n");
    pre(root);
    printf("\n");
    printf("Inorder\n");
    mid(root);
    printf("\n");
    printf("Postorder\n");
    back(root);
    printf("\n");
 
    return 0;
}

Measured memory_bytes: 1820
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cstdio>
using namespace std;
typedef long long int ll;
class RMQ{
	private:
		vector<ll> val;
		int n;
	public:
		RMQ(int size){
			n=1;
			while(n<size)n<<=1;
			val=vector<ll>(2*n,0);
		}
		//x 番目の要素を a に更新する
		void update(int x,ll a){
			x+=n-1;
			val[x]=a;
			while(x>0){
				x=(x-1)/2;
				val[x]=max(val[x*2+1],val[x*2+2]);
			}
		}
		//a<=x<b
		ll maximum(int a,int b,int k=0,int l=0,int r=-1){
			if(r==-1)r=n;
			if(r<=a||b<=l)return 0;
			if(a<=l&&r<=b){
				return val[k];
			}else{
				return max(maximum(a,b,k*2+1,l,(l+r)/2),maximum(a,b,k*2+2,(l+r)/2,r));
			}
		}
};
ll n;
main(){
	int i,j;
	while(cin >> n){
		RMQ dp(100010);
		for(i=0;i<n;i++){
			ll x;
			cin >> x;
			ll res = dp.maximum(0, x);
			dp.update(x, res + x);
		}
		cout << (ll)n*(n+1)/2 - dp.maximum(0, n+1) << endl;
	}
	return 0;
}

Measured memory_bytes: 5232
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
using graph = vector<vector<ll>>;

int main() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	while (a > 0 && c > 0) {
		c = c - b;
		a = a - d;
	}
	if (c <= 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3624
mod = 10 ** 9 + 7
def extGCD(a, b):
    if b == 0:
        return a, 1, 0
    g, y, x = extGCD(b, a%b)
    y -= a//b * x
    return g, x, y

def moddiv(a, b):
    _, inv, _ = extGCD(b, mod)
    return (a * inv) % mod

N = 2 * 10 ** 5 + 10
fact = [0] * (N)
fact[0] = 1
for i in range(1, N):
    fact[i] = (fact[i-1] * i) % mod

def comb(a, b):
    return moddiv(moddiv(fact[a], fact[a-b]), fact[b])

h, w, a, b = map(int, input().split())

ans = 0
for i in range(min(h-a, w-b)):
    x = h - 1 - a - i
    y = b + i
    plus = comb(x + y, x) * comb((h-1 - x) + (w-1 - y), (h-1 - x))
    ans += plus
    ans %= mod
print(ans)

Measured memory_bytes: 125144
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        if(s.length() == 2) System.out.println(s);
        else System.out.println(s.charAt(2) + "" + s.charAt(1)  + "" + s.charAt(0));
    }
}

Measured memory_bytes: 25044
n = int(input())
a = list(map(int, input().split()))
r = [0] * 9
for i in a:
    temp = i // 400
    if temp <= 8:
        r[temp] += 1
    else:
        r[8] += 1

c = sum([1 for i in r[:-1] if i != 0])
t = r[-1]

if c == 0:
    print(1, t)
else:
    print(c, c+t)

Measured memory_bytes: 3064
n=int(input())
dp=[i for i in range(100001)]
for i in range(100001):
    p=1
    while p<=i:
        dp[i]=min(dp[i],dp[i-p]+1)
        p*=6
    p=1
    while p<=i:
        dp[i]=min(dp[i],dp[i-p]+1)
        p*=9
else:
    print(dp[n])

Measured memory_bytes: 7064
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		while(true){
			int n = in.nextInt();
			if(n==0) return ;
			int aa=0, bb=0;
			for(int i=0; i<n; i++){
				int a = in.nextInt(), b = in.nextInt();
				if(a > b){
					aa += a+b;
				}
				else if(a==b){
					aa += a;
					bb += b;
				}
				else{
					bb += a+b;
				}
			}
			System.out.println(aa + " " + bb);
		}
		
	}
}

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

#define ll long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

int main(){
	fastio
	ll n;
	cin >> n;
	unordered_map<ll,ll> m;
	ll sum = 0;
	for(ll i = 0, tmp;i < n;i++) cin >> tmp, m[tmp]++, sum += tmp;
	ll q;
	cin >> q;
	while(q--){
		ll a,b;
		cin >> a >> b;
		m[b] += m[a];
		sum -= m[a]*a;
		sum += b*m[a];
		m[a] = 0;
		cout << sum << "\n";
	} 
}

Measured memory_bytes: 7112
from sys import exit
import math
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
x = li()

ave = sum(x) //n

ans1=0
for i in range(n):
    ans1 += (x[i]-ave) ** 2
ans2=0
for i in range(n):
    ans2 += (x[i]-(ave+1)) ** 2
print(min(ans1,ans2))

Measured memory_bytes: 9104
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]

numdot = 0
for i in s:
    numdot += i.count('.')

from collections import deque

#WFS(幅優先探索)
seen = [[0 for _ in range(w)] for __ in range(h)]
seen[0][0] = 1
todo = deque([(0, 0)])
d = [(1,0,0,h-1), (0,1,1,w-1), (-1,0,0,0), (0,-1,1,0)]

while todo != deque([]):
    a = todo.popleft()
    for i in d:
        if a[i[2]] != i[3]:
            x = a[0] + i[0]
            y = a[1] + i[1]
            if s[x][y] == '.' and seen[x][y] == 0:
                todo.append((x, y))
                seen[x][y] = seen[a[0]][a[1]] + 1

    if seen[h-1][w-1] != 0:
        print(numdot - seen[h-1][w-1])
        exit()

print(-1)

Measured memory_bytes: 3316
#include "bits/stdc++.h"

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, t; cin>>a>>b>>t;
    int ans = 0;
    int i = 0;
    while(1){
        i++;
        if(a*i<=t+0.5) ans+=b;
        else break;
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 256
def smaller(x, y):
	if x < y: return x
	else: return y

def larger(x, y):
	if x > y: return x
	else: return y

def gcd(x, y):
	if x < y: return gcd(y, x)
	else:
		if x % y == 0: return y
		else: return gcd(y, x%y)

def lcm(x, y):
	return (larger(x, y) / gcd(x, y)) * smaller(x, y)

N = int(raw_input())
ans = int(raw_input())
for i in range(1, N):
	ans = lcm(ans, int(raw_input()))
print ans

Measured memory_bytes: 2568
import random
import time
import copy

def down_score(d, c, last_d, score):
    sum = 0
    for i in range(26):
        sum = sum + c[i]*(d-last_d[i])
        
    return int(score - sum)


def main():
    D = int(input())

    c = list(map(int, input().split()))

    s = [list(map(int, input().split())) for i in range(D)]

    start = time.time()
    
    last_d = [0 for i in range(26)]
    ans = []    
    score1 = 0
    
    for i in range(D):
        max = 0
        idx = 0
        for j in range(26):
            if max < (s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2) and c[j] != 0:
                max = s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2
                idx = j
            elif max == (s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2) and c[j] * (i-last_d[j])*(i-last_d[j]+1)/2 > c[idx]* (i-last_d[idx])*(i-last_d[idx]+1)/2 and c[j] != 0:
                idx = j
            
        last_d[idx] = i+1
        score1 += s[i][idx]
        score1 = down_score(i+1,c,last_d,score1)
        
        ans.append(idx)
        
    random.seed(10)
    while time.time() - start < 1.9:
        cp = ans.copy()
        last_d = [0 for i in range(26)]
        score2 = 0  
        
        idx1 = random.randint(0,25)
        idx2 = random.randint(0,25)
        if random.randint(0,1):
            d1 = random.randint(0,D-1) 
            d2 = random.randint(0,D-1)
            if idx1 == idx2:
                continue
            if random.randint(0,1):
                ans[d1] = idx1
            else:
                ans[d1] = idx1
                ans[d2] = idx2
             
        #2値入れ替え
        elif random.randint(0,1):           
            d1 = random.randint(0,D-8) 
            d2 = random.randint(d1+1,d1+7)
            tmp1 = ans[d1]
            tmp2 = ans[d2]
            if random.randint(0,1):
                ans[d1] = tmp2
                ans[d2] = tmp1
            
        #3値入れ替え          
        else:
            d1 = random.randint(0,D-11) 
            d2 = random.randint(d1+1,d1+5)
            d3 = random.randint(d2+1,d2+5) 
            tmp1 = ans[d1]
            tmp2 = ans[d2]
            tmp3 = ans[d3]
            if random.randint(0,1):
                ans[d1] = tmp2
                ans[d2] = tmp3
                ans[d3] = tmp1
            else:
                ans[d1] = tmp3
                ans[d2] = tmp1
                ans[d3] = tmp2
            
        for i in range(D):
            score2 += s[i][ans[i]]
            last_d[ans[i]] = i+1
            score2 = down_score(i+1, c, last_d, score2)
        
        if score1 > score2:
            ans = cp.copy()
        else:
            score1 = score2
    
    for i in range(D):
        print(ans[i]+1)  

if __name__ == "__main__":
    main()


Measured memory_bytes: 10104
from collections import deque
from bisect import bisect_left

n = int(input())
l = sorted(map(int, input().split()))
ld = deque(l)
cnt = 0
for a in range(n - 2):
    l_a = ld.popleft()
    for b in range(a + 1, n - 1):
        cnt += bisect_left(l, l_a + l[b]) - b - 1
print(cnt)

Measured memory_bytes: 9632
#include <iostream>
using namespace std;
int cnt,w,h;
string s[21];
void check(int i,int j){
	if(s[i][j]=='#')return;
	cnt++;
	s[i][j]='#';
	if(i>0)check(i-1,j);
	if(i<h-1)check(i+1,j);
	if(j>0)check(i,j-1);
	if(j<w-1)check(i,j+1);
}


int main(){
	while(1){
		cin >>w >>h;
		if(!(w||h))break;
		for(int i=0;i<h;i++){
			cin >>s[i];
		}
		cnt=0;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(s[i][j]=='@')check(i,j);
			}
		}
	cout << cnt<<endl; 

	}
}

Measured memory_bytes: 3008
#include <stdio.h>

int main(){
int s = 700;
char a,b,c;
char o = 'o';
scanf("%c %c %c",&a,&b,&c);
if(a == o){
s += 100;
}

if(b == o){
s += 100;
}

if(c == o){
s += 100;
}

printf("%d",s);
}

Measured memory_bytes: 128
//A
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define MAX 100002

int n;
vector<long long int> A;

int dp[MAX][3];  //0 both OK 1 increase 2 decrease

int main(){
	cin >> n;
	for (int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		A.push_back(a);
	}
	for (int i = 0; i < MAX; i++){
		for (int j = 0; j < 3; j++){
			dp[i][j] = INT_MAX;
		}
	}
	dp[0][0] = dp[0][1] = dp[0][2] = 1;
	for (int i = 0; i+1 < n; i++){
		//if (A[i] == A[i + 1]){
			//cut
			dp[i + 1][0] = min(dp[i][0], min(dp[i][1], dp[i][2])) + 1;
		//}
		if (A[i] <= A[i + 1]){
			dp[i + 1][1] = min(dp[i][0], dp[i][1]);
		}
		if (A[i] >= A[i + 1]){
			dp[i + 1][2] = min(dp[i][0], dp[i][2]);
		}
	}
	int ans = min(dp[n - 1][0], min(dp[n - 1][1], dp[n - 1][2]));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2292
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll n;
    cin >> n;
    cout << n*800 - (n/15)*200 << endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int n;
long long int ans;
struct dish{int ta;int ao;};
struct dish a[100010];
bool cmp(dish a,dish b)
{
    if(a.ta+a.ao>b.ta+b.ao)
    {
        return true;
    }
    return false;
}
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d %d",&a[i].ta,&a[i].ao);
    }
    sort(a,a+n,cmp);
    for(int i=0;i<n;i++)
    {
        if(i%2==0)
        {
            ans+=a[i].ta;
        }
        else
        {
            ans-=a[i].ao;
        }
    }
    printf("%lld",ans);
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int N;
    cin >> N;
    map<int, int> m;
    REP(i, N){
        int a;
        cin >> a;
        m[a]++;
    }
    int ans = 0;
    for(auto&& i: m){
        if(i.se&1){
            ans++;
        }
    }
    pr(ans);
}

Measured memory_bytes: 4864
#include<iostream>
#include<cstdio>

using namespace std;

int main(int argc, char *argv[])
{
  int n,b,f,r,v;//b棟f階r番目の部屋にv人追加
  int Build[4][3][10]={0};
  scanf("%d",&n);
  for(int i = 0;i < n;i++){
    scanf("%d %d %d %d",&b,&f,&r,&v);
    getchar();
    Build[b-1][f-1][r-1] += v;
  }
  for(int i = 0;i < 4;i++){
    for(int j = 0;j < 3;j++){
      for(int k = 0;k < 10;k++){
    printf(" %d",Build[i][j][k]);
      }
        printf("\n");
    }
    if(i !=3)
    printf("####################\n");
  }
  return 0;
}

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

using namespace std;
typedef long long ll;

int main(){
    int N;cin >> N;
    vector<int> p(110,0);
    for (int i = 0; i < N; i++)
    {
        cin >> p[i];
    }
    
    for (int i = 0; i < N; i++)
    {
        cout << p[0];
        for (int j = 1; j < N; j++)
        {
            cout << " " << p[j];
        }
        cout << endl;

        int key = p[i+1];
        int k = i;
        while (k >= 0 && p[k] > key)
        {
            int tmp = p[k+1];
            p[k+1] = p[k];
            p[k] = tmp;
            k--;
        }
    }
    
}


Measured memory_bytes: 3080
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<cassert>
#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define FOREACH(i,c) for(__typeof((c).begin())i = (c).begin();i!=(c).end(); ++i)

//v4
int cond = 1;
string to_string(char c){return'\''+string(1,c)+'\'';}
string to_string(const string&s){return'"'+s+'"';}
string to_string(const char*s){return to_string((string)s);}
string to_string(bool b){return(b?"true":"false");}
string to_string(std::vector<bool>::reference&r){return to_string((bool)r);}
template<typename A,typename B>string to_string(const pair<A,B>&p){return"("+to_string(p.first)+", "+to_string(p.second)+")";}
template<typename A>string to_string(A v){int f=1;string r="{";for(auto x:v){if(!f){r+=", ";}f=0;r+=to_string(x);}r+="}";return r;}
template<typename A,typename B>string to_string(map<A,B>v){int f=1;string r="{";for(auto x:v){if(!f){r+=", ";}f=0;r+=to_string(x.first)+" -> "+to_string(x.second);}r+="}";return r;}
void __db(int i,const vector<string>&s){cerr<<endl;}
template<typename T,typename... A>void __db(int i,const vector<string>&s,T t,A... a){if(i)cerr<<", ";cerr<<s[i]<<" = "<<to_string(t);__db(i+1,s,a...);}

string __cl(string s){while(!s.empty()&&s[0]==' ')s.erase(0,1);while(!s.empty()&&s.back()==' ')s.pop_back();return s;}
vector<string>__vars(string s){vector<string>r;s+=",";string n="";int d=0;for(auto x:s)if(x==','&&d==0){if(!n.empty())r.push_back(__cl(n));n="";}else{n+=x;if(x=='('||x=='[')d++;else if(x==')'||x==']')d--;}return r;}
#define DB(...){if(cond){cerr<<"Line:"<<__LINE__<<" ";__db(0,__vars(#__VA_ARGS__),__VA_ARGS__);}}


int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  if (a == b) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }

    return 0;
}

Measured memory_bytes: 256
s=input()
s=s.replace('BC','.')
s=s.replace('B','/')
s=s.replace('C','/')
sl = s.split('/')
cnt =0
for si in sl:
    incre = 0
    for ci in si:
        if ci == 'A':
            incre +=1
        if ci == '.':
            cnt += incre
print(cnt)


Measured memory_bytes: 11288
//region #include <cp_helper>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <cmath>
#include <climits>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define io() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ii pair<int, int>
#define lll pair<ll, ll>
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vll vector<lll>
#define vvl vector<vl>
#define vii vector<ii>
#define all(a) a.begin(), a.end()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define pb(n) push_back(n)
#define eb(n) emplace_back(n)
#define pp(a, b) emplace_back(make_pair(a, b))
#define umap unordered_map
#define nl '\n'
#define fileio(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)
#define qmod %mod
#define pls int
#define give main()
#define AC io()
const int mod = 1000000007;
//endregion


pls give {
    AC;
    string a;
    int ans=0;
    cin >> a;
    for (int i=0; i<a.size()/2; i++) {
        if (a[i] != a[a.size()-i-1]) ans++;
    }
    cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)
#define Graph vector<vecctor<ll>>
#define pairs vector<pair<ll,ll>>
#define pb push_back



using namespace std;
using ll = long long;
const ll INF = 1e18;
const double PI = acos(-1);

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const ll mod = 1e9 + 7;







int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    ll n,ans = 0;
    cin >> n;
    for(int i = 1;i < n; i ++){
        ans += (n-1)/i;
    }

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

Measured memory_bytes: 3640
/**
* Think twice, code once.
* 1.integer overflow(maybe even long long overflow : (a+b >= c) -> (a >= c-b)
* 2.runtime error
* 3.boundary condition
* ---------------------------------------------------------------------------------------
* Author : zzy
* Date : 2020-03-28-20.05.26 Saturday
*/
#include <bits/stdc++.h>

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))
#define SZ(x) ((int)(x).size())

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

i64 k, n;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif

    cin >> k >> n;
    vi64 a(n);
    forn(i, n) cin >> a[i];
    i64 ans = (a[n-1]-a[0]);
    for (int i = 0; i < n-1; ++i) {
        ans = min(ans, k-(a[i+1]-a[i]));
    }
    cout << ans << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 1792
N,K=map(int,input().split())
A=list(map(int,input().split()))
imos=[0 for i in range(N+1)]

for t in range(K):
  for i in range(N):
    l=max(0,i-A[i])
    r=min(N,i+A[i]+1)
    imos[l]+=1
    imos[r]-=1
  for i in range(0,N):
    imos[i+1]+=imos[i]
    A[i]=imos[i]
  imos=[0 for i in range(N+1)]
  if len(set(A))==1 and (N in set(A)):
    break
for i in range(N):
  A[i]=str(A[i])
ans=" ".join(A)
print(ans)  

Measured memory_bytes: 169632
#include<bits/stdc++.h>
using namespace std;
#define rkc ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
#define fl(i,a,b) for(ll i=a;i<b;i++)
#define rfl(i,a,b) for(ll i=a;i>b;i--)
#define pb push_back
#define mp make_pair
#define test ll t;cin>>t;while(t--)
#define lld long double
#define vpp vector<pair<ll,ll>>
#define ff first
#define ss second
const ll M = 1e9 + 7;
const double pi  =3.141592653589793238463;
int main()
{
    rkc;
    ll a[3];
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    cout<<a[0]+a[1];
}

Measured memory_bytes: 256
//#pragma GCC optimize "trapv"
//-D_GLIBCXX_DEBUG
#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;
#define pm(m) for(auto itr=(m).begin();itr!=(m).end();itr++){itr->first<<" "<<itr->second<<"\n";}
#define int long long int
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define ii pair<int,int>
#define Max 100000+5
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define f first
#define s second
#define pb push_back
#define bug(x) cout<<(x)<<" ";exit(0);
int mod = 1000000007;
int mod1 = 998244353;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


int32_t main(){
	IO
	//freopen("input.txt","r",stdin);
    	//freopen("output.txt","w",stdout);
// 	int t;
// 	cin>>t;
// 	while(t--){
// 		int n;
//         cin>>n;
// 	}
string s;
cin>>s;
if(s[s.length()-1]!='s')s+="s";
else s+="es";
cout<<s;
}

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

###
# main
if(__name__ == '__main__'):
    # input
    n = input()

    hon_list = ['2', '4', '5', '7', '9']
    pon_list = ['0', '1', '6', '8']
    bon_list = ['3']

    for num in hon_list:
        if num == n[-1]:
            ans = "hon"

    for num in pon_list:
        if num == n[-1]:
            ans = "pon"

    for num in bon_list:
        if num == n[-1]:
            ans = "bon"

    print(ans)

# else:
    # do nothing

Measured memory_bytes: 9072
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner (System.in);
		int num = sc.nextInt();
		List<Integer> intArray = new ArrayList<>();

		for(int i=0 ; i<num ; i++) {
			intArray.add(sc.nextInt());
		}

		HashSet<Integer> type = new HashSet<>(intArray);

		System.out.print(type.size() < intArray.size() ? "NO" : "YES");
	}
}

Measured memory_bytes: 93580
#include<iostream>

using namespace std;
int main()
{
	int a,b,c,d,ans=0;
	cin >> a >> b >> c >> d;
	if(min(b,d) - max(a,c) > 0)
		ans = min(b,d) - max(a,c);
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;
using llong = long long int;

class UnionFind
{
private:
	vector<int> _root;
	vector<llong> _count;

public:
	UnionFind(int n)
		: _root(n), _count(n)
	{
		for (int i = 0; i < n; ++i)
		{
			_root[i] = i;
			_count[i] = 1LL;
		}
	}
	
	int root(int i)
	{
		if (i == _root[i])
			return i;
		return _root[i] = root(_root[i]);
	}
	
	void unite(int i, int j)
	{
		int ri = root(i), rj = root(j);
		if (ri == rj) return;
		_count[ri] += _count[rj];
		_root[rj] = ri;
	}
	
	bool same(int i, int j)
	{
		return root(i) == root(j);
	}
	
	llong count(int i)
	{
		return _count[root(i)];
	}
};

int main()
{
	llong N;
	int M;
	cin >> N >> M;
	
	vector<int> a(M);
	vector<int> b(M);
	for (int i = 0; i < M; ++i)
	{
		cin >> a[i] >> b[i];
		--a[i];
		--b[i];
	}
	
	llong inconvenience = N * (N - 1) / 2;
	vector<llong> inconveniences;
	inconveniences.push_back(inconvenience);
	UnionFind uf(N);
	for (int i = M-1; i > 0; --i)
	{
		if (!uf.same(a[i], b[i]))
		{
			inconvenience -= uf.count(a[i]) * uf.count(b[i]);
			uf.unite(a[i], b[i]);
		}
		inconveniences.push_back(inconvenience);
	}
	
	for (int i = M-1; i >= 0; --i)
	{
		cout << inconveniences[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 4212
/**
 *
 * AtCoder Beginner Contest 107 - Problem A: Train (https://beta.atcoder.jp/contests/abc107/tasks/abc107_a)
 *
 * Find the index j of the element i, if the vector is read backwards.
 *
 * Math solution: j = N - i + 1.
 */
#include <iostream>

#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstring>
#include <algorithm>

using namespace std;

using ll = long long;
using ii = pair<ll, ll>;

#define LOG(var, sep) (cerr << #var << " = " << (var) << (sep))
#define LOGM(msg) (cerr << (msg))
#define LOGV(vec, sep) { cerr << #vec << " ="; for (const auto& v : (vec)) cerr << " " << v; cerr << (sep); }
#define LOGA(arr, N, sep) { cerr << #arr << " ="; for (int i = 0; i < N; ++i) cerr << " " << (arr)[i]; cerr << (sep); }
#define LOGA2(arr, N, M, sep) { cerr << #arr << " =\n"; for (int i = 0; i < N; ++i) { for (int j = 0; j < M; ++j) cerr << (arr)[i][j] << " "; cerr << endl; } cerr << (sep); }

#define REP(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)

ostream& operator<<(ostream& os, const ii& p)
{
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

const int MAX { 2000010 };

string as[MAX];

void solve(int H, int W)
{
    set<int> cs, rs;

    REP(i, 0, H - 1)
    {
        auto sum = 0;

        REP(j, 0, W - 1)
        {
            sum += (as[i][j] == '#' ? 1 : 0);
        }

        if (sum == 0)
        {
            rs.insert(i);
        }
    }

    REP(j, 0, W - 1)
    {
        auto sum = 0;

        REP(i, 0, H - 1)
            sum += (as[i][j] == '#' ? 1 : 0);

        if (sum == 0)
        {
            cs.insert(j);
        }
    }

    REP(i, 0, H - 1)
    {
        bool printed = false;
        REP(j, 0, W - 1)
            if (rs.count(i) == 0 and cs.count(j) == 0)
            {
                printed = true;
                cout << (char) as[i][j];
            }

        if (printed)
            cout << endl;
    }
}

int main()
{
    ios::sync_with_stdio(false);

    int H, W;
    cin >> H >> W;

    REP(i, 0, H - 1)
        cin >> as[i];

    solve(H, W);

    return 0;
}


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


int main() {
  int k;
  cin >> k;
  string s;
  cin >> s;
  int a;
  a = s.size();
  if(a <= k){
    cout << s;
  }
  else{
    cout << s.substr(0, k) << "...";
  }
    
  return 0;
}

Measured memory_bytes: 3624
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) throws FileNotFoundException {

//    Scanner cin = new Scanner(new FileReader("input.txt"));
    Scanner cin = new Scanner(System.in);
    int r = cin.nextInt();
    int D = cin.nextInt();
    long start = cin.nextLong();

    for (int i=0;i<10;i++) {
      start = r*start-D;
      System.out.println(start);
    }

  }

}


Measured memory_bytes: 21972
// Marcin Knapik
#include<bits/stdc++.h>

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;

//#include <ext/pb_ds/assoc_container.hpp> // order_of_key
//#include <ext/pb_ds/tree_policy.hpp> // find by order
//using namespace __gnu_pbds; 
//#define ordered_set tree< int , null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>  

// const ll MAX_LL = 0xFFFFFFFFFFFFFFFF;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define losuj(a, b) uniform_int_distribution<ull>(a, b)(rng)
#define losuj_real(a, b) uniform_real_distribution<long double>(a, b)(rng)

typedef long double             ld;
typedef long long               ll;
typedef unsigned long long      ull;
typedef pair<ll, ll>            pll;
typedef pair<int, int>          ii;
typedef vector<int>             vi;
typedef vector<ii>              vii;
typedef vector<vi>              vvi;
typedef vector<vector<ii>>      vvii;
typedef vector< ll >            vll;
typedef vector< pll >           vpll;
 
#define sz(a)                   (int)(a).size()
#define pb                      push_back
#define all(c)                  (c).begin(), (c).end()
#define rall(c)                 (c).rbegin(), (c).rend()
#define FOR(i, a)               for (int i = 0; i < (a); i++)
#define f                       first
#define s                       second
#define rr "\e[31m "
#define bb "\e[m "

template <class T> inline bool setmin(T &a, T b){if (a > b)return a = b, 1;return 0;}
template <class T> inline bool setmax(T &a, T b){if (a < b)return a = b, 1;return 0;}
 
template<class T> inline T fast(T a,T b,T mod) {ll res = 1; while(b){if(b&1) res = (res*a)%mod;a = (a*a)%mod;b >>= 1;}return res;}
template<class T> inline T russian(T a, T b, T mod) {ll res = 0; while(b){if(b&1) res = (res + a)%mod; a = (a+a)%mod; b>>=1;}return res;}
template <class T> istream &operator>>(istream &os, vector<T> &container){for (auto &u : container)os >> u;return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &container){for (auto &u : container)os << u << " ";return os;}
template<typename T> inline T gcd(T a, T b) { while (b)swap(a %= b, b); return a; }

const ll INF = 1e9 + 7;
const ll mod = 998244353;
const ll N = 1e6+7;
const ll T = 1<<20;
const ll BIG_INF = 1e18 + 7;

ll n, m;

ll tree[T*2];
ll H[N];
ll A[N];

void add(int poz, ll val){
	poz += T;

	tree[poz] = val;

	poz/=2;
	while(poz){
		tree[poz] = max(tree[poz*2], tree[poz*2+1]);
		poz/=2;
	}
}

ll ask(int pocz, int kon){
	pocz += T-1;
	kon += T+1;
	ll ret = 0;

	while(pocz/2 != kon/2){
		if(!(pocz&1))
			ret = max(ret, tree[pocz+1]);
		if(kon&1)
			ret = max(ret, tree[kon-1]);
		pocz/=2;
		kon/=2;
	}
	return ret;
}

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

	FOR(i, n)
		cin >> H[i];

	FOR(i, n)
		cin >> A[i];

	FOR(i, n){
		ll maxi = ask(1, H[i]) + A[i];
		add(H[i], maxi);
	}

	cout << ask(1, T-1) << '\n';
}	


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

#define ll long long

const ll M = 1e9 + 7;

ll Mod(ll a)
{
    return (a % M + M) % M;
}

ll MulMod(ll a, ll b)
{
    return Mod(Mod(a) * Mod(b));
}

ll AddMod(ll a, ll b)
{
    return Mod(Mod(a) + Mod(b));
}

ll SubMod(ll a, ll b)
{
    return Mod(Mod(a) - Mod(b));
}

void test()
{
    string s = "0";
    ll cnt = 0;

    while(s != "99999")
    {
        if(s.length() < 5)
        {
            for(ll i = 0; i < s.length(); i++)
            {
                if(s[i] == '9')
                {
                    cnt++;
                    break;
                }
            }
        }
        else
        {
            bool has9 = false;
            bool has0 = false;
            
            for(ll i = 0; i < s.length(); i++)
            {
                if(s[i] == '0')
                {
                    has0 = true;
                }

                if(s[i] == '9')
                {
                    has9 = true;
                }
            }

            if(has0 && has9)
            {
                cnt++;
            }
        }
        
        
        s = to_string(stoi(s) + 1);
    }

    cout << cnt << "\n";
}

int main()
{
    ll s;
    cin >> s;

    if(s < 3)
    {
        cout << 0 << "\n";
        return 0;
    }

    vector<ll> dp(s + 1);

    dp[0] = 0;
    dp[1] = 0;
    dp[2] = 0;

    for(ll i = 3; i <= s; i++)
    {
        dp[i] = 1;
        
        for(ll j = 3; j <= i; j++)
        {
            dp[i] = AddMod(dp[i], dp[i - j]);
        }
    }

    // for(ll i = 1; i <= s; i++)
    // {
    //     cout << dp[i] << " ";
    // }

    // cout << "\n";

    cout << dp[s];

    return 0;
}

Measured memory_bytes: 3648
H, W, K = map(int, input().split())
C = [list(input()) for i in range(H)]

count = 0

for row in range((1 << H) - 1):
    for col in range((1 << W) - 1):
        black = 0
        for i in range(H):
            for j in range(W):
                if ((row >> i) & 1) == 0 and ((col >> j) & 1) == 0:
                    if C[i][j] == '#':
                        black += 1
        if black == K:
            count += 1

print(count)


Measured memory_bytes: 9132
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <ctype.h>
#include <stdlib.h>
#include <map>
using namespace std;

int main()
{
	int S, W;
	cin >> S >> W;

	if (W >= S) {
		cout << "unsafe" << endl;
	}
	else {
		cout << "safe" << endl;
	}

}

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

//using namespace __gnu_pbds;
using namespace std;

typedef  long long ll;
typedef long double ld;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define endl "\n"
#define ioss ios::sync_with_stdio(0);cin.tie(0);
#define pb push_back
#define eb emplace_back



double startTime;
double gct()//get_current_time
{
    return ((double)clock()-startTime)/CLOCKS_PER_SEC;
}

void suraj();

int main()
{
    startTime=(double)clock();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt,"w",stdout);
    //ioss
    //int t;cin>>t;while(t--)
    suraj();
    //suraj2();
    //suraj3();
    //suraj4();
    return 0;
}





























int dp[100009][3];//dp[i][j] means max happiness gained till ith day if jth work is done on last day






void suraj(){
int n;cin>>n;

for(int i=1;i<=n;i++){
    int a,b,c;cin>>a>>b>>c;
    dp[i][0]=max(dp[i-1][1]+a,dp[i-1][2]+a);
    dp[i][1]=max(dp[i-1][0]+b,dp[i-1][2]+b);
    dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c;
}


cout<<max(max(dp[n][0],dp[n][1]),dp[n][2])<<endl;
}













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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



int k;
int a[100] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
void solve(){
	cin >> k;
	
	cout << a[k-1] << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<algorithm>/*{{{*/
#include<cctype>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<vector>
using namespace std;
typedef long long lld;
typedef long double lf;
typedef unsigned long long uld;
typedef pair<int,int> pii;
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define ROF(i,a,b) for(int i=(a);i>=(b);--i)
namespace RA{
    int r(int p){return 1ll*rand()*rand()%p;}
    int r(int L,int R){return r(R-L+1)+L;}
}/*}}}*/
/******************heading******************/
const int N=2e5+5;

long long n,k;    
long long a[N],f[N];

bool check(long long x){
    long long res=0;
    FOR(i,1,n){
        //a[i],f[n-i+1]
        res+=max(a[n-i+1]-x/f[i],0ll);
    }
    return res<=k;
}
int main(){
    scanf("%lld%lld",&n,&k);
    FOR(i,1,n)scanf("%lld",&a[i]);
    FOR(i,1,n)scanf("%lld",&f[i]);
    sort(a+1,a+n+1);
    sort(f+1,f+n+1);
    long long l=0,r=1e18;
    while(l<r){
        long long mid=(l+r)>>1;
        if(check(mid))r=mid;
        else l=mid+1;
    }
    printf("%lld\n",l);
    return 0;
}


Measured memory_bytes: 3456
//
// Created by moono on 2018/10/27.
//

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



int main() {
    //
    int K, S;
    cin >> K >> S;

    //
    int num = 0;
    for (int i = 0; i <= K; ++i) {
        for (int j = 0; j <= K; ++j) {
            int k = S - i - j;
            if(0 <= k && k <= K) num++;
        }
    }

    //
    cout << num << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#define Mod 998244353
using namespace std;
long long fpow(long long a,long long b)
{
	long long ans=1,t=a;
	while(b)
	{
		if(b&1)ans=ans*t%Mod;
		t=t*t%Mod;
		b>>=1;
	}
	return ans;
}
int rev[40010];
void getrev(int bit)
{
	for(int i=0;i<(1<<bit);i++)
		rev[i]=(rev[i>>1]>>1)|((i&1)<<(bit-1));
	return ;
}
void ntt(long long* a,int n,int dft)
{
	for(int i=0;i<n;i++)
		if(i<rev[i])swap(a[i],a[rev[i]]);
	for(int step=1;step<n;step<<=1)
	{
		long long wn=fpow(3,(Mod-1)/(step<<1));
		if(dft==-1)wn=fpow(wn,Mod-2);
		for(int i=0;i<n;i+=step<<1)
		{
			long long wnk=1;
			for(int j=i;j<i+step;j++)
			{
				long long x=a[j],y=a[j+step]*wnk%Mod;
				a[j]=x+y;if(a[j]>=Mod)a[j]-=Mod;
				a[j+step]=x-y;if(a[j+step]<0)a[j+step]+=Mod;
				wnk=wnk*wn%Mod;
			}
		}
	}
	if(dft==-1){
		long long invn=fpow(n,Mod-2);
		for(int i=0;i<n;i++)
			a[i]=a[i]*invn%Mod;
	}
	return ;
}
long long tmp[40010];
long long g[40010];
long long f[210][8010];
long long fac[8010],inv[8010];
int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	fac[0]=inv[0]=1;
	for(int i=1;i<=n+2;i++)
	{
		fac[i]=fac[i-1]*i%Mod;
		inv[i]=fpow(fac[i],Mod-2);
	}
	int s=1,bit=0;
	while(s<=(n<<1))s<<=1,bit++;
	getrev(bit);
	for(int i=1;i<=n;i++)
		g[i]=inv[i+2]%Mod;
	ntt(g,s,1);
	f[0][0]=1;
	for(int i=1;i<=m;i++)
	{
		for(int j=0;j<s;j++)
			if(j<=n)tmp[j]=f[i-1][j]*inv[j]%Mod;
			else tmp[j]=0;
		ntt(tmp,s,1);
		for(int j=0;j<s;j++)
			tmp[j]=tmp[j]*g[j]%Mod;
		ntt(tmp,s,-1);
		for(int j=0;j<=n;j++)
			f[i][j]=((j*(j+1)/2+1)*f[i-1][j]+tmp[j]*fac[j+2])%Mod;
	}
	long long ans=0;
	for(int i=0;i<=n;i++)
		ans=(ans+fac[n]*inv[i]%Mod*inv[n-i]%Mod*f[m][i])%Mod;
	printf("%lld\n",ans);
	return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int>skip(n+1);
  rep(i, m) {
    int a;
    cin >> a; 
    skip[a] = 1;
  }
  vector<int>dp(n+2);
  const int mod = 1000000007;
  dp[n] = 1;
  for(int i=n-1; i>=0; --i){
    if(skip[i]){
      dp[i] = 0;
      continue;
    }
    dp[i] = (dp[i+2] + dp[i+1]) % mod;
  }
  cout << dp[0] << endl;
  return 0;
}

Measured memory_bytes: 1024
a,b,c,d = map(int,input())

if a+b+c+d == 7:
    print('+'.join(map(str,[a,b,c,d])) + '=7')
elif a+b+c-d == 7:
    print(str(a) + '+' + str(b) + '+' + str(c) + '-' + str(d) + '=7')
elif a+b-c+d == 7:
    print(str(a) + '+' + str(b) + '-' + str(c) + '+' + str(d) + '=7')
elif a-b+c+d == 7:
    print(str(a) + '-' + str(b) + '+' + str(c) + '+' + str(d) + '=7')
elif a+b-c-d == 7:
    print(str(a) + '+' + str(b) + '-' + str(c) + '-' + str(d) + '=7')
elif a-b+c-d == 7:
    print(str(a) + '-' + str(b) + '+' + str(c) + '-' + str(d) + '=7')
elif a-b-c+d == 7:
    print(str(a) + '-' + str(b) + '-' + str(c) + '+' + str(d) + '=7')
elif a-b-c-d == 7:
    print(str(a) + '-' + str(b) + '-' + str(c) + '-' + str(d) + '=7')


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

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b, a % b);
}

using Graph = vector<vector<int>>;

ll kzyou(ll a,ll k){//aのk乗を返す
    ll zyou = 1;
    for(ll i = 1;i<=k;i++){
        zyou *= a;
    }
    return zyou;
}
typedef pair<int,int> P;

bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}

int main(){
  int N;
  cin >> N;
  string S,T;
  cin >> S >> T;
  string ans;
  rep(i,N){
    ans.push_back(S[i]);
    ans.push_back(T[i]);
  }
  cout << ans << endl;
 }

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
#include<stack>
using namespace std;
const int maxn=500000;
int n;
struct node{
	int pos,id1,id2;
	bool operator<(const node &t)const{
		return pos<t.pos;
	}
}a[maxn+10];
struct segnode{
	int l,r,down,up;
}b[(maxn<<2)+10];
int dis[(maxn<<2)+10];
int nodecnt;
vector<int> g[maxn+10];
void buildtree(int p,int l,int r){
	b[p].l=l; b[p].r=r;
	b[p].down=++nodecnt; g[nodecnt].clear();
	b[p].up=++nodecnt; g[nodecnt].clear();
	if(l==r){
		g[b[p].down].push_back(a[l].id2);
		g[a[l].id1].push_back(b[p].up);
	}else{
		int mid=l+r>>1;
		buildtree(p<<1,l,mid); buildtree(p<<1|1,mid+1,r);
		g[b[p].down].push_back(b[p<<1].down);
		g[b[p].down].push_back(b[p<<1|1].down);
		g[b[p<<1].up].push_back(b[p].up);
		g[b[p<<1|1].up].push_back(b[p].up);
	}
}
void addedge(int p,int l,int r,int ptoseg,int segtop){
	if(b[p].l==l&&b[p].r==r){
		g[ptoseg].push_back(b[p].down);
		g[b[p].up].push_back(segtop);
	}else{
		int mid=b[p].l+b[p].r>>1;
		if(r<=mid) addedge(p<<1,l,r,ptoseg,segtop);
		else if(l>mid) addedge(p<<1|1,l,r,ptoseg,segtop);
		else{
			addedge(p<<1,l,mid,ptoseg,segtop);
			addedge(p<<1|1,mid+1,r,ptoseg,segtop);
		}
	}
}
int dfn[maxn+10],low[maxn+10],scc[maxn+10],dfscnt,scccnt;
stack<int> stk;
void dfs(int x){
	dfn[x]=low[x]=++dfscnt; stk.push(x);
	for(int i=0;i<g[x].size();++i){
		int e=g[x][i];
		if(!dfn[e]){
			dfs(e); low[x]=min(low[x],low[e]);
		}else if(!scc[e]) low[x]=min(low[x],dfn[e]);
	}
	if(dfn[x]==low[x]){
		++scccnt;
		for(;;){
			int t=stk.top(); stk.pop();
			scc[t]=scccnt; if(t==x) break;
		}
	}
}
bool check(int v){
	for(int i=1;i<=n<<1;++i) g[i].clear(); nodecnt=n<<1;
	buildtree(1,1,n<<1);
	for(int i=1;i<=n<<1;++i){
		int l=upper_bound(dis+1,dis+(n<<1)+1,a[i].pos-v)-dis,
			r=lower_bound(dis+1,dis+(n<<1)+1,a[i].pos+v)-dis-1;
		if(l<i) addedge(1,l,i-1,a[i].id1,a[i].id2);
		if(i<r) addedge(1,i+1,r,a[i].id1,a[i].id2);
	}
	for(int i=1;i<=nodecnt;++i) dfn[i]=scc[i]=0;
	dfscnt=scccnt=0;
	for(int i=1;i<=nodecnt;++i) if(!dfn[i]) dfs(i);
	for(int i=1;i<=n;++i) if(scc[i<<1]==scc[(i<<1)-1]) return 0;
	return 1;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d%d",&a[i<<1].pos,&a[(i<<1)-1].pos);
		a[i<<1].id1=i<<1; a[(i<<1)-1].id1=(i<<1)-1;
		a[(i<<1)-1].id2=i<<1; a[i<<1].id2=(i<<1)-1;
	}
	sort(a+1,a+(n<<1)+1);
	for(int i=1;i<=(n<<1);++i) dis[i]=a[i].pos;
	int l=0,r=2e9;
	while(l!=r){
		int mid=(1ll+l+r)>>1;
		if(check(mid)) l=mid; else r=mid-1;
	}
	printf("%d",l);
	return 0;
}

Measured memory_bytes: 40000
while True:
    n = int(input())#人数の受け取り
    if n == 0:#０人or何も入力しないなら終了
        break
    a = list(map(int, input().split()))#各人の成績の受け取り
    l = list()#出力の受け取り用
    for i in range(0, n):#成績の比較
        for j in range(0, n):
            if i == j:
                continue
            l.append(abs(a[i]-a[j]))#絶対値を受け取り用のlistに入力
    else:#listが完成したら
        print(min(l))#成績の一番近い生徒の差を出力



Measured memory_bytes: 51620
#include<iostream>
#include<cstdio>
#include<algorithm>
#define N 200001
using namespace std;
int g[N],a[N*2][2];
int n,m;
void ins(int x,int y){
	static int sum=1;
	a[++sum][0]=y,a[sum][1]=g[x],g[x]=sum;
}
int main(){
	scanf("%d %d",&n,&m);
	for (int i=1;i<=m;i++){
		int x,y;
		scanf("%d %d",&x,&y);
		ins(x,y),ins(y,x);
	}
	for (int i=g[1];i;i=a[i][1])
		for (int j=g[a[i][0]];j;j=a[j][1])
			if (a[j][0]==n){
				printf("POSSIBLE");
				return 0;
			}
	printf("IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 4096
while(True):
    ans = 0
    n,x = map(int,input().split())
    if n == 0 and x == 0:
        break
    for a in range(1,n+1):
        for b in range(a+1,n+1):
            c = x-a-b
            if c <= n and c > b:
                ans += 1
    print(ans)


Measured memory_bytes: 5592
#include<bits/stdc++.h>
     
using namespace std;
     
typedef long long ll;
typedef pair<int,int>P;
     
#define F first
#define S second
     
int main(){
  int n;
  int a,ans=0;
  int free=0;
  int color[8]={};
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&a);
    if(a>=3200) free++;
    else color[a/400]++;
  }

  for(int i=0;i<8;i++){
    if(color[i]>0) ans++;
  }
  
  printf("%d %d\n",max(1,ans),ans+free);
  
  return 0;
}


Measured memory_bytes: 256
/*
	Copyright: razouq (c)
	Author: Anass BENDARSI
	Date: 12/08/2017 13:02:38
	flamers will **** you
*/
#include<bits/stdc++.h>
//#include<flamers.h>
#define ll long long
#define ull unsigned long long
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define POB pop_back
#define dist(a, b) sqrt(a*a + b*b)
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pair<int, int>> vipi;
bool compare(pi p1, pi p2){
	 if(1) return true;
	 return false;
}


bool palin(string s){
	int d = 0, f = s.size(); f--;
	
	while(d < f){
		if(s[d] != s[f]) return false;
		d++; f--;
	}
	
	return true;
	
}

int main(){
//	freopen("input.in", "r", stdin);
//	freopen("output.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie();
	string s;
	cin>>s;
	if(palin(s)) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int a, b; cin >> a >> b;
  if (a + b >= 10) cout << "error" << '\n';
  else cout << a + b << '\n';
}

Measured memory_bytes: 256