akhauriyash/Code-Regression huggingface dataset:
# include <cstdio>
# include <iostream>
# include <algorithm>
# include <queue>
# include <map>
# include <vector>
# include <cmath>
# include <cstring>
# define R register int
# define ll long long

using namespace std;

const int N=1000006;
int n,len,ch[N][27],a[N],cnt;
int t[N][27],cr[N],ep[N],f[N],b[N];
char s[N];
ll ans;

void ins()
{
	int no=0;
	for (R j=1;j<=26;++j) b[j]=0;
	for (R i=1;i<=len;++i)
	{
		int x=s[i]-'a'+1;
		if(!ch[no][x]) ch[no][x]=++cnt,cr[cnt]=x,f[cnt]=no;
		no=ch[no][x];
	}
	ep[no]=1;
	while(1)
	{	
		for (R i=1;i<=26;++i)
			t[no][i]+=b[i];		
		if(no==0) return;
		b[ cr[no] ]=1;
		no=f[no];
	}
}

int main()
{
	scanf("%d",&n);
	for (R i=1;i<=n;++i)
	{
		scanf("%s",s+1);
		len=strlen(s+1);
		for (R j=1;j<=len/2;++j)
			swap(s[j],s[len-j+1]);
		ins();
	}
	for (R i=0;i<=cnt;++i)
		for (R j=1;j<=26;++j)
		{
			int son=ch[i][j];
			if(!son) continue;
			if(ep[son]) 
				ans+=t[i][j]-1;
		}
	cout<<ans;
	return 0;
}

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

const int mod = 998244353;
class mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
    mint choose(int n, int a){
        mint x = 1 ,y = 1;
        for(int i = 0; i < a; ++i){
            x *= n-i;
            y *= i+1;
        }
        return x / y;
    }
    friend istream& operator>>(istream& is, mint& m){
        is >> m.x;
        return is;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

mint dp[3010][3010];

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  dp[a][b]=1;
  for(int i=a; i<=c; ++i){
    for(int j=b; j<=d; ++j){
      dp[i][j]+=dp[i-1][j]*j;
      dp[i][j]+=dp[i][j-1]*i;
      dp[i][j]-=dp[i-1][j-1]*(i-1)*(j-1);
    }
  }
  cout<<dp[c][d]<<endl;
}

Measured memory_bytes: 74380
#include <bits/stdc++.h>
const long long MOD = 1000000007;
const int INF = INT_MAX / 2;
const long double PI = 3.1415926;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
using namespace std;
vector<ll> v;
vector<string> vs;
vector<pair<ll, ll>> vp;
vector<vector<ll>> vv(110, vector<ll>(50, 0));
vector<tuple<ll, ll, ll>> vt;
map<ll, ll> mp;

typedef int Weight;
struct Edge
{
	int from, to; Weight cost;
	bool operator < (const Edge& e) const { return cost < e.cost; }
	bool operator > (const Edge& e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph &g, int from, int to, Weight cost)
{
	g[from].push_back(Edge{ from, to, cost });
}

int main()
{
	string s1, s2;
	cin >> s1 >> s2;
	if (s1.size() > s2.size()) cout << "GREATER" << endl;
	else if (s1.size() < s2.size()) cout << "LESS" << endl;
	else
	{
		REP(i, s1.size())
		{
			if (s1[i] > s2[i])
			{
				cout << "GREATER" << endl;
				return 0;
			}
			else if (s1[i] < s2[i])
			{
				cout << "LESS" << endl;
				return 0;
			}
		}
		cout << "EQUAL" << endl;
	}
}

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

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

int main() {
	int n;
	cin >> n;
	int d[100010];
	rep(i, n) cin >> d[i];
	sort(d, d+n);
	cout << d[n/2]-d[n/2-1] << endl;
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;

const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
const int dr[]={0,1,0,-1,0};


int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int d,g;
	cin >>d >>g;
	vector<ll> p(d), c(d);
	rep(i, d) cin >>p[i] >> c[i];
	rep(i, d) c[i] /=100; g /=100;
	
	int mn = 1<<28;
	rep(i, 1<<d){
		int ct =0, sm = 0;
		rep(j, d) if(i>>j &1){
			sm += p[j] *(j+1); sm += c[j];
			ct += p[j];
		}
		
		repr(j, d-1,0) if(!(i>>j &1)){
			if( sm >= g) break;
			if( sm + p[j] *(j+1) < g){
				continue;
			}else{
				int z= (g - sm +j) /(j+1);
				ct +=z;
				sm += z* (j+1);
				break;
			}
		}
		
		//dbg(i,mn,ct,sm, g);
		if(sm >= g) 		mn = min(ct, mn);
	}
	cout << mn <<"\n";
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main() {
  int a, b, c, d, l;
  int japanese = 0, math = 0, work = 0;
  scanf("%d\n", &l);
  scanf("%d\n", &a);
  scanf("%d\n", &b);
  scanf("%d\n", &c);
  scanf("%d\n", &d);
  if(a % c != 0) {
    japanese = a / c + 1;
  } else {
    japanese = a / c;
  }
  if(b % d != 0) {
    math = b / d + 1;
  } else {
    math = b / d;
  }
  if(japanese >= math) {
    work = japanese;
  } else {
    work = math;
  }
  printf("%d\n", l - work);
  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
    using namespace std;
     
    int main()
    {
        int x,d,b,c;
        while(cin>>d>>b>>c>>x){
            x/=50;
            int sum=0;
            for(int i=0;i<=d;i++){
                for(int j=0;j<=b;j++){
                    for(int k=0;k<=c;k++){
                        if(i*10+j*2+k==x) sum++;
                    }
                }
            }
            cout<<sum<<endl;
        }
        return 0;
    }

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    LL r,d,x;
    cin >> r >> d >> x;
    REP(i,0,10) {
        x = r * x - d;
        cout << x << endl;
    }
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
  int n,mini;
  cin >> n;
  vector <string> data1(n),data2(n);
  for(int i=0;i<n;i++){
    cin >> data1[i];
    data2[i] = data1[i];
  }
  for(int i=0;i<n-1;i++){
    for(int j=n-1;j>i;j--){
      if(data1[j][1]<data1[j-1][1]) swap(data1[j],data1[j-1]);
    }
  }
  for(int i=0;i<n;i++){
    mini = i;
    for(int j=i;j<n;j++){
      if(data2[j][1]<data2[mini][1]) mini = j;
    }
    if(mini != i) swap(data2[i],data2[mini]);
  }
  for(int i=0;i<n;i++) cout << (i!=0?" ":"") << data1[i];
  cout << endl << "Stable" << endl;
  for(int i=0;i<n;i++) cout << (i!=0?" ":"") << data2[i];
  if(data1==data2) cout << endl << "Stable" << endl;
  else cout << endl << "Not stable" << endl;
}



Measured memory_bytes: 3236
import sys
from itertools import product
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m = map(int, input().split())
    query = [list(map(int, input().split())) for _ in range(m)]

    for pattern in product(list(map(str, range(10))), repeat=n):
        num = str(int("".join(pattern)))
        if len(num) < n:
            continue
        for s, c in query:
            if len(num) >= s:
                if num[s - 1] != str(c):
                    break
            else:
                break
        else:
            print(num)
            exit()

    print(-1)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3064
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll N;
    string S,T;
    cin >> S >> T;
    N=S.size();
    ll cnt=0;
    rep(i,0,N){
        if(S[i]!=T[i])cnt++;
    }
    ll ans=cnt;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3916
import java.util.Scanner;

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

        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int C = scanner.nextInt();
        int D = scanner.nextInt();
        int cena_pociag = 0;
        int cena_bus = 0;
        if (A > B) {
            cena_pociag = B;
        } else {
            cena_pociag = A;
        }
        if (C > D) {
            cena_bus = D;
        } else {
            cena_bus = C;
        }

        System.out.println(cena_pociag+cena_bus);
    }
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////

struct edge{ ll to,cost,flag; };
bool used[500010];
ll V;
vector<edge> G[500010];
ll d[500010];

void dijkstra(ll s){
    fill(d,d+V+1,inf);
    d[s]=0;
    priority_queue<pair<ll,l_l>,vector<pair<ll,l_l>>,greater<pair<ll,l_l>>> que;
    que.push(make_pair(0,l_l(0,s)));
    
    while(!que.empty()){
        pair<ll,l_l> p=que.top();que.pop();
        ll v=p.second.second;
        if(d[v]<p.first)continue;
        used[p.second.first]=true;
        //cout<<p.second.first<<endl;
        rep(i,0,G[v].size()-1){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(make_pair(d[e.to],l_l(e.flag,e.to)));
            }
        }
    }
    
}


int main(){
    ll n;cin>>n;
    ll m;cin>>m;
    ll a[m],b[m],c[m];
    V=m;
    rep(i,1,m){
        cin>>a[i]>>b[i]>>c[i];
        edge e;
        e.to=b[i];e.cost=c[i];e.flag=i;
        G[a[i]].pb(e);
        e.to=a[i];e.cost=c[i];e.flag=i;
        G[b[i]].pb(e);
    }
    rep(i,1,n){
        dijkstra(i);
    }
    ll ans=0;
    rep(i,1,m){
        if(!used[i])ans++;
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 13952
n, k = map(int, input().split())
p = list(map(int, input().split()))
_c = list(map(int, input().split()))
c = [0]*n
for i in range(n):
    p[i] -= 1
    c[i] = _c[p[i]]
m = 31
MIN = - (1 << 63)
vertex = list()
score = list()
vertex.append(p)
score.append(c)
for a in range(1, m+1):
    p_ath = [0] * n
    c_ath = [0] * n
    for i in range(n):
        p_ath[i] = vertex[a-1][vertex[a-1][i]]
        c_ath[i] = score[a-1][i] + score[a-1][vertex[a-1][i]]
    vertex.append(p_ath)
    score.append(c_ath)
    
prv = [[MIN, 0] for _ in range(n)]
nxt = [[MIN, MIN] for _ in range(n)] 
for b in range(m, -1, -1):
    for i in range(n):
        if (k >> b) & 1:
            nxt[vertex[b][i]][0] = max(nxt[vertex[b][i]][0], prv[i][0] + score[b][i])
            nxt[vertex[b][i]][1] = max(nxt[vertex[b][i]][1], prv[i][1] + score[b][i])
            nxt[i][0] = max(nxt[i][0], prv[i][0], prv[i][1])
        else:
            nxt[vertex[b][i]][0] = max(nxt[vertex[b][i]][0], prv[i][0] + score[b][i])
            nxt[i][0] = max(nxt[i][0], prv[i][0])
            nxt[i][1] = max(nxt[i][1], prv[i][1])
    prv, nxt = nxt, prv
ans = max(max(x) for x in prv)
if ans == 0:
    ans = max(c)
print(ans)

Measured memory_bytes: 20572
n = int(input())


def factorization(n):
    retval = []
    tmp = n
    for p in range(2, int(n**.5)+1):
        if tmp % p == 0:
            cnt = 0
            while tmp % p == 0:
                cnt += 1
                tmp //= p
            retval.append([p, cnt])
    if tmp != 1:
        retval.append([tmp, 1])
    return retval


fact = factorization(n)
m = len(fact)
ans = 0
for i in range(1, 1000):
    for j in range(m):
        if i <= fact[j][1]:
            fact[j][1] -= i
            ans += 1
print(ans)


Measured memory_bytes: 9468
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
using namespace std;

const int N=1e6+5;
int n,d,x[N],y[N];

void solve()
{
    cin>>n;
    string s;
    cin>>s;
    int cnt=0;
    for(int i=0;i<n;i++) if(s[i]=='R') cnt++;
    int res=0;
    for(int i=0;i<cnt;i++) if(s[i]=='W') res++;
    cout<<res;
}

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //int t;
    //cin>>t;
    //while(t--)
        solve();
}


Measured memory_bytes: 3764
import math
N, D = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(N)]


def f(x, y):
    s = 0
    for i in range(len(x)):
        s += (x[i] - y[i])**2

    return math.sqrt(s)


count = 0
for i in range(len(L)):
    for j in range(i + 1, len(L)):
        fn = f(L[i], L[j])
        n = int(fn)
        if (n == fn):
            count += 1
        else:
            continue

print(count)


Measured memory_bytes: 3064
use proconio::input;

fn main() {
    input! {
        n: usize,
        t: [i64; n],
        a: [i64; n],
    };
    let mut f = vec![0_i64; n];
    f[0] = t[0];
    let mut p = t[0];
    for (i, &t_i) in t.iter().enumerate().skip(1) {
        if p < t_i {
            f[i] = t_i;
        }
        p = t_i;
    }
    if f[n - 1] > 0 && f[n - 1] != a[n - 1] {
        println!("0");
        return;
    }
    f[n - 1] = a[n - 1];
    p = a[n - 1];
    for (i, &a_i) in a.iter().enumerate().rev().skip(1) {
        if f[i] > 0 && f[i] > a_i {
            println!("0");
            return;
        }
        if p < a_i {
            if f[i] > 0 && f[i] != a_i {
                println!("0");
                return;
            }
            f[i] = a_i;
        }
        p = a_i;
    }

    let mut ans = 1_i64;
    for (&f_i, (&t_i, &a_i)) in f.iter().zip(t.iter().zip(a.iter())) {
        if f_i == 0 {
            ans *= std::cmp::min(t_i, a_i);
            ans %= 1_000_000_007;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 6368
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,k,col[200001],MOD=998244353,bik[200001],ans;
ll f(ll a,ll b){
    if(b==0)return 1;
    if(b%2==1)return f(a,b-1)*a%MOD;
    return f(a,b/2)*f(a,b/2)%MOD;
}
ll comb(ll n,ll k){
    return bik[n]*f(bik[n-k],MOD-2)%MOD*f(bik[k],MOD-2)%MOD;
}
int main(void){
    cin>>n>>m>>k;
    col[0]=m;
    bik[0]=1;
    for(ll i=1LL;i<=200000;i++){
        bik[i]=bik[i-1]*i;
        bik[i]%=MOD;
    }
    for(int i=1;i<n;i++){
        col[i]=(col[i-1]*(m-1))%MOD;
    }
    for(ll i=0LL;i<=k;i++){
        ans+=(comb(n-1,i)*col[n-i-1])%MOD;
        ans%=MOD;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 6756
// メモリ最小になりたい
#include <array>

constexpr int N = 1e5;
std::array<char, N+1> vS, vT;
constexpr short K = 'A' - 1;

int main(void){
    int i = 0;char c1, c2;
    vS[0] = 0; while((c1 = getchar()) != '\n'){ vS[i+1] = (vS[i] + c1 - K) % 3; i++;}
    i = 0;
    vT[0] = 0; while((c2 = getchar()) != '\n'){ vT[i+1] = (vT[i] + c2 - K) % 3; i++;}
    scanf("%d", &i);
    while(i--){
        int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d); a--; c--;
        c1 = (vS[b] - vS[a] + 3) % 3;
        c2 = (vT[d] - vT[c] + 3) % 3;
        puts(c1 == c2 ? "YES" : "NO");
    }
    return 0;
}


Measured memory_bytes: 640
H,W = map(int,input().split(" "))
a = [ [0]*W for _ in range(H)]
for i in range(H):
    a[i] = list(map(int,input().split(" ")))

cnt = 0
ans = []
for i in range(H-1):
    for j in range(W):
        if a[i][j] % 2 == 1:
            a[i+1][j] += 1
            a[i][j] -= 1
            cnt += 1
            ans.append((i+1,j+1,i+2,j+1))

for j in range(W-1):
    if a[-1][j] % 2 == 1:
        a[-1][j+1] += 1
        a[-1][j] -= 1
        cnt += 1
        ans.append((H,j+1,H,j+2))

print(cnt)
for i,j,k,l in ans:
    print("{0} {1} {2} {3}".format(i,j,k,l))

Measured memory_bytes: 72412
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    ll snuke=0;
    ll sum=0;
    rep(i,n){
        cin >> a[i];
        sum += a[i];
    }
    sum -= a[0];
    snuke = a[0];
    ll ans = abs(sum - snuke);
    for(int i=1; i<n-1; i++){
        ll sa;
        snuke += a[i];
        sum -= a[i];
        sa = abs(sum - snuke);
        ans = min(ans,sa);
    }
    cout << ans << endl;
   
    
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define ll long long
#define RE register
#define R read()
using namespace std;
inline ll read()
{
    ll x=0,k=1;char c=getchar();
    while (c<'0' || c>'9') {if (c=='-') k=-1;c=getchar();}
    while (c>='0' && c<='9') {x=(x<<1)+(x<<3)+(c^48);c=getchar();}
    return x*k;
}
bitset<2000010> f;ll a[2011],n,sum;
int main()
{
    n=R;for(RE int i=1;i<=n;++i) a[i]=R,sum+=a[i];
    f[0]=1;for(RE int i=n;i>=1;--i)f|=f<<a[i];
    for(RE int i=(sum+1)>>1;i<=sum;++i)if(f[i]){printf("%d\n",i);return 0;}
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

#define vec     vector<int>
#define vecll   vector<ll>
#define vec2    vector<vector<int>>
#define vec2ll  vector<vector<ll>>
#define vpair   vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define mpair(v1, v2)    make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << var << "\n"
#define scn(var)         cin >> var;
#define pYes()           prt("Yes")
#define pNo()            prt("No")
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(var)      rep(i,var.size()){cout << var[i] << " ";} cout << "\n"

#define bis(i, j)        i & (1<<j)
//----------------------------------------------------------------
ll mul[62];
int main(void) {
  int n;
  cin >> n;
  arrll(a,n);

  rep(k,62){
    if(k==0) mul[k] = 1;
    else mul[k] = (mul[k-1]*2) % MOD;
  }

  ll ans=0;
  rep(k,62){
    ll zero=0, one=0;
    rep(i,n){
      if(bis(a[i], 0)){
        one++; a[i]--;
      } else {
        zero++;
      }
      a[i]/=2;
    }
    //prt2(zero, one);
    //prt(mul[k] * (one * zero));
    ll tmp = (one*zero) % MOD;
    ans += tmp * mul[k] % MOD;
    ans %= MOD;
  }
  prt(ans);
}


Measured memory_bytes: 2560
#include <iostream>
using namespace std;
int main(){

 int r, g, b;
 cin >> r >> g >> b;
 
  int ans = (r * 100) + (g * 10) + b;
  
  if(ans % 4 == 0){
      cout << "YES" << endl;
  }
    
  else{
      cout << "NO" << endl;
  }
    
    
    
}

Measured memory_bytes: 3548
N = int(input())

max_4 = int(N / 4)
max_7 = int(N / 7)

cost_list = []
for i in range(max_7 + 1):
    for j in range(max_4 + 1):
        cost = 7 * i + 4 * j
        cost_list.append(cost)


if N in cost_list:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cassert>

using namespace std;
using ll = long long;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    int ans = 0;
    int mx = max(a, b);
    mx = max(mx, c);
    ans += (mx-a)/2;
    a += (mx-a)/2 * 2;
    ans += (mx-b)/2;
    b += (mx-b)/2 * 2;
    ans += (mx-c)/2;
    c += (mx-c)/2 * 2;

    if( (a < mx && b < mx) || (b < mx && c < mx) || (a < mx && c < mx) ){
        ans += 1;
    }else if(a == b && b == c){
    }else{
        ans += 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

vi w;

vector<vi> dp;

int calc(int l, int r) {
    if(dp[l][r] >= 0) return dp[l][r];
    auto& ret = dp[l][r];
    if(r - l == 1) return ret = 0;
    if(r - l == 2) {
        if(abs(w[l] - w[l+1]) <= 1) return ret = 2;
        else return ret = 0;
    }
    if(abs(w[l] - w[r-1]) <= 1) {
        int tmp = calc(l+1, r-1);
        if(tmp == r - l - 2) chmax(ret, tmp + 2);
    }
    for(int m = l + 1; m < r; ++m) {
        chmax(ret, calc(l, m) + calc(m, r));
    }
    return ret;
}

void solve() {
    int n;
    cin >> n;
    if(n == 0) exit(0);
    w.resize(n);
    rep(i, n) cin >> w[i];
    dp = vector<vi>(n+1, vi(n+1, -1));
    cout << calc(0, n) << endl;
}

int main(){
    while(1) solve();    
    return 0;
}


Measured memory_bytes: 3616
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
    char buffer[100010];
    int  cube_num = 0, value = 0;
    int  zero_num = 0, one_num = 0;
    if (fgets(buffer,100010,stdin) != NULL) {
        cube_num = strlen(buffer);
        for (int i = 0; i < cube_num-1; i++) {
            value = buffer[i]-'0';
            if (value) {
                one_num += 1;
            } else {
                zero_num += 1;
            }
        }
    } else {
            fprintf(stderr, "[x] fgets() error.\n");
        return 1;
    }
    if (zero_num <= one_num) {
        printf("%d",zero_num*2);
    } else {
        printf("%d",one_num*2);
    }
    return 0;
}

Measured memory_bytes: 256
N, L = map(int, input().split())
# 味：L + i - 1
aji_list = [L+i-1 for i in range(1, N+1)]

basic = abs(sum(aji_list))
min_diff = 9999999 
for i in aji_list:
    diff = abs(basic - abs(basic - abs(i)))
    min_diff = min(min_diff, diff)

for i in aji_list:
    if abs(basic - abs(basic - abs(i))) == min_diff:
        if basic == sum(aji_list):
            print(basic - abs(i))
        else:
            print(-1*(basic - abs(i)))
        break

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

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

  vector<regex> R(8);
  R.at(0) = (".*keyence");
  R.at(1) = ("k.*eyence");
  R.at(2) = ("ke.*yence");
  R.at(3) = ("key.*ence");
  R.at(4) = ("keye.*nce");
  R.at(5) = ("keyen.*ce");
  R.at(6) = ("keyenc.*e");
  R.at(7) = ("keyence.*");

  bool answer = false;
  for(auto r : R) answer |= regex_match(S, r);
  cout << (answer ? "YES" : "NO") << endl;
}


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

int main(){
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    h1=h2-h1;
    m1=m2-m1;
    h1=h1*60+m1;
    h1=h1-k;
    cout << h1 << endl;
}


Measured memory_bytes: 3632
#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)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  int a, b;
  vector <pair<int, int> > v;
  REP(i,m){
      cin >> a >>b;
      v.push_back(make_pair(b,a));
  }
  SORT(v);
  int ans = 0;
  int end = 0;
  for (auto p: v){
      if (p.second >= end){
          ans++;
          end = p.first;
      }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1400
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <math.h>
#include <deque>
#include <queue>
#include <map>
#include <iterator>
#include <set>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e) { std::cout << e << std::endl; }
template<typename T> void view(const std::vector<T>& v) { for (const auto& e : v) { std::cout << e << " "; } std::cout << std::endl; }
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v : vv) { view(v); } }
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 main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	string s;
	cin >> s;
	int n = s.size(); 
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		// i mozi
		int lim = n - i;
		for (int j = 0; j <= lim; j++) {
			//j start
			bool ok = true;
			for (int k = 0; k < i; k++) {
				// start = j
				// last = j + i - 1
				int now = j + k;
				if (s[now] != 'A' && s[now] != 'C' && s[now] != 'G' && s[now] != 'T') {
					ok = false;
				}
			}
			if (ok) chmax(ans, i);
		} 
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main (void)
{
	int num;
	int i = 1;
		
	while(1 ){
		scanf("%d", &num);
		if(num == 0) break;
		printf("Case %d: %d\n",i , num);
		i++ ;
	}
		
	return 0;
}	

Measured memory_bytes: 600
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

int INF = INT_MAX / 2;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

vector<int> bfs(int N, vector<vector<int> >& G, int s) {
	vector<int> d(N, INF); d[s] = 0;
	queue<int> q; q.push(s);
	while (q.size()) {
		int u = q.front(); q.pop();
		for (int v: G[u])
			if (d[v] > d[u] + 1) {
				d[v] = d[u] + 1;
				q.push(v);
			}
	}
	return d;
}

int main() {
	int N, K; cin >> N >> K;
	vector<vector<int> > G(N);
	for (int i = 0; i < N - 1; i++) {
		int u, v; cin >> u >> v;
		u--; v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	if (K % 2 == 0) {
		int mi = INF;
		for (int x = 0; x < N; x++) {
			vector<int> d = bfs(N, G, x);
			int cnt = 0;
			for (int u = 0; u < N; u++)
				if (d[u] > K / 2)
					cnt++;
			mi = min(mi, cnt);
		}
		cout << mi << endl;
	}
	else {
		int mi = INF;
		for (int x = 0; x < N; x++)
			for (int y: G[x]) {
				vector<int> d1 = bfs(N, G, x), d2 = bfs(N, G, y);
				int cnt = 0;
				for (int u = 0; u < N; u++)
					if (min(d1[u], d2[u]) > K / 2)
						cnt++;
				mi = min(mi, cnt);
			}
		cout << mi << endl;
	}
}


Measured memory_bytes: 384
using System;

namespace ITP1_7_B
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 0; ; i++)
            {
                string data = Console.ReadLine();
                int n = int.Parse(data.Split(' ')[0]);
                int x = int.Parse(data.Split(' ')[1]);
                int counter = 0;

                if (n == 0 && x == 0)
                    Environment.Exit(0);

                for (int j = 1; j <= n; j++)
                {
                    for (int k = j + 1; k <= n; k++)
                    {
                        for (int l = k + 1; l <= n; l++)
                        {
                            if (j + k + l == x)
                                counter++;
                        }
                    }
                }
                Console.WriteLine("{0}", counter);
            }
        }
    }
}


Measured memory_bytes: 18024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;cin>>N;
  vector<long> L(N);
  for(int i=0;i<N;i++)cin>>L[i];
  int ans=0;
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      for(int k=j+1;k<N;k++){
        vector<long> l(3);
        l[0]=L[i];l[1]=L[j];l[2]=L[k];
        sort(l.begin(),l.end());
        if(l[0]+l[1]>l[2]&&l[0]!=l[1]&&l[1]!=l[2]&&l[2]!=l[0]){
          ans++;
        }
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3628
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())

yen = "JPY"
bi = 380000
ans = 0
for _ in range(N):
    a, b = input().split()
    if b == yen:
        ans += float(a)
    else:
        ans += float(a)*bi
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>


int main()
{
    long A,B;
    std::string S;
    std::cin >> A >> S >> B;
    if(S=="+"){
        std::cout << A+B << std::endl;
    }else{
        std::cout << A-B << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, 0, n) cin >> a[i];
    int ans = 0;
    rep(i, 0, n){
        rep(j, i + 1, n){
            if(a[i] > a[j]){
                (ans += k * (k + 1) / 2) %= mod;
            }
            if(a[i] < a[j]){
                (ans += k * (k - 1) / 2) %= mod;
            }
        }
    }
    cout << ans << endl;
}

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

int main(void) {
  ll N, M;
  string S, T;
  cin >> N >> M >> S >> T;

  ll lcm = N * M / __gcd(N, M);

  bool ok = true;
  REP(i, 0, N) {
    ll k = lcm / N * i;
    if (k % (lcm / M) == 0) {
      ll j = k / (lcm / M);
      ok = ok && S[i] == T[j];
    }
  }
  REP(i, 0, M) {
    ll k = lcm / M * i;
    if (k % (lcm / N) == 0) {
      ll j = k / (lcm / N);
      ok = ok && T[i] == S[j];
    }
  }

  if (ok) {
    cout << lcm << endl;
  } else {
    cout << -1 << endl;
  }
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int countSurroundingBomb(int h, int w, int lh, int lw, char** grid);
bool isSpace(int h, int w, char** grid);

int main() {
  int h, w;
  cin >> h >> w;
  char** grid = new char*[h];
  for(int i = 0; i < h; i++)
    grid[i] = new char[w];
  
  //input
  for(int i = 0; i < h; i++)
    for(int j = 0; j < w; j++)
      cin >> grid[i][j];
  
  for(int i = 0; i < h; i++)
    for(int j = 0; j < w; j++)
      if(isSpace(i, j, grid) != false)
        grid[i][j] = '0' + countSurroundingBomb(h, w, i, j, grid);
  
  //output
  for(int i = 0; i < h; i++) {
    for(int j = 0; j < w; j++)
      cout << grid[i][j];
    cout << endl;
  }
  
  //release  
  for(int i = 0; i < h; i++)
    delete[] grid[i];
  delete[] grid;
}
bool isSpace(int h, int w, char** grid) {
  if(grid[h][w] == '.')
    return true;
  else return false;
}
int countSurroundingBomb(int h, int w, int lh, int lw, char** grid) {
  int cnt = 0;
  for(int i = -1; i <= 1; i++)
    for(int j = -1; j <= 1; j++) {
      int llh = lh + i, llw = lw + j;
      if(llh < 0 || llh > h - 1 || llw < 0 || llw > w - 1)
        continue;
      else if(i == 0 && j == 0)
        continue;
      if(grid[llh][llw] == '#')
        ++cnt;
    }
  return cnt;
}

Measured memory_bytes: 256
def main():
    n = input()
    aa = map(int, raw_input().split())
    dic = {(0, 0, 0): 1}
    for a in aa:
        next_dic = {}
        for (x, y, z), c in dic.iteritems():
            if a == x:
                key = (x + 1, y, z)
                next_dic[key] = next_dic.get(key, 0) + c
            if a == y:
                key = (x, y + 1, z)
                next_dic[key] = next_dic.get(key, 0) + c
            if a == z:
                key = (x, y, z + 1)
                next_dic[key] = next_dic.get(key, 0) + c
        dic = next_dic
    count = 0
    for c in dic.itervalues():
        count = (count + c) % 1000000007
    print count


main()


Measured memory_bytes: 41708
import java.util.Scanner;

	class Main{
		public static void main(String[]args){
            
            
        Scanner sc=new Scanner(System.in);
            int x,y,i;
            for(i=0;i<3000;i++){
           		 x=sc.nextInt();
           		 y=sc.nextInt();
				 if(x==0&&y==0)break;
                System.out.println(Math.min(x,y)+" "+Math.max(x,y));
           }
        }
    }


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int A[1010101];
int N;

void solve() {
	int i,j,k,l,r,x,y; string s;
	cin>>N;
	ll ret=0;
	for(i=1;i<=N;i++) {
		for(j=i;j<=N;j+=i) ret+=j;
	}
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

#define ff first
#define ss second
#define PI acos(-1)
#define pb push_back
#define int long long
#define ld long double
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int M = (1e9)+7;
const int N = 1e6+5;

int mpower(int x, int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1){
            res = (res*x) % p;
        }
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

signed main()
{
    FAST
    int tc=1;
    //cin>>tc;
    for(int ti=1;ti<=tc;ti++)
    {
        int n;
        cin>>n;
        int s = 0;
        int a[n];
        for(int i=0;i<n;i++)cin>>a[i],s+=a[i],s%=M;
        int ans = 0;
        for(int i=0;i<n;i++)
        {
            int add = (a[i]*(s-a[i]+M)%M)%M;
            ans += add;
            ans %= M;
        }
        ans *=  mpower(2LL,M-2,M);
        ans %= M;
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 5228
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
#define MD 1000000007
#define INF 1ll<<60
const double PI=3.141592653589;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

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


Measured memory_bytes: 3632
n=int(input())
num=100
d={}
for i in range(1,n+1):
    d[i]=0
for i in range(1,num+1):
    for j in range(1,num+1):
        for k in range(1,num+1):
            val=(i*i)+(j*j)+(k*k)+(i*j)+(j*k)+(k*i)
            if val>n:
                continue
            # print(i,end=" ")
            # print(j,end=" ")
            # print(k)
            d[val]=d[val]+1
for i in range(1,n+1):
    print(d[i])

Measured memory_bytes: 9680
#include <bits/stdc++.h>
using namespace std;
long long m=1e9+7;
long long fact[1000001],inv[1000001];

long long modRecursive(long long a,long long b,long long c)
{
	if(b == 0) return 1;
	if(b%2 ==0) return modRecursive((a*a)%c,b/2,c);
	else return ((a%c)*(modRecursive((a*a)%c,b/2,c)))%c;
}

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


Measured memory_bytes: 256
<?php
  
  fscanf(STDIN,"%s",$N);


$count = 1;

for($i=0;$i<4;$i++){
  if($N[$i] == $N[$i+1]){
    $count++;
  }
}


  
  
if($count >= 3 && $N[1]==$N[2]){
  echo "Yes\n";
}else{
  echo "No\n";
}





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

int main(int argc, const char * argv[]) {



    cin.tie(0);
    ios::sync_with_stdio(false);

    /////////////////////
    // Write code below /
    /////////////////////
    int n,m,i;

    cin >>n>>m;

    int a[n];

    for(i = 0;i < m;i++){
        cin >>a[i];
        n = n - a[i];
    }
    if(n < 0)
        cout <<-1<<endl;
    else
        cout <<n<<endl;
        

    return 0;
}

Measured memory_bytes: 3692
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

int main() {
    int n; cin >> n;
    const int64_t mod = 1e9 + 7;
    int64_t power = 1;
    for (int i = 1; i <= n; i++) {
        power = (power * i) % mod;
    }
    cout << power % mod << endl;
}


Measured memory_bytes: 256
def dump(dp, max_w):
    for i in range(max_w + 1):
        print('%3d' % dp[i], end='')
    print()

inf = 1 << 60
max_n, max_w = map(int, input().split())
v = [0] * (max_n + 1)
w = [0] * (max_n + 1)
for i in range(1, max_n + 1):
    v[i], w[i] = map(int, input().split())

dp = [0] * (max_w + 1)

for n in range(1, max_n + 1):
    for i in range(max_w + 1 - w[n]):
        dp[i+w[n]] = max(dp[i+w[n]], dp[i] + v[n])
    #dump(dp, max_w)

print(dp[max_w])



Measured memory_bytes: 5920
# from pprint import pprint
# import math
# import collections

n = int(input())
# n, k = map(int, input().split(' '))
# a = list(map(int, input().split(' ')))
# a = []
# for i in range(n):
#     a.append(int(input()))

import math

ans = math.ceil(n / 1000) * 1000 - n

print(ans)


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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int tc; cin>>tc; while(tc--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    int n;
    ll x, y;
    cin>> n;

    ll sum[n], sub[n];

    for(int i=0; i<n; i++)
    {
        cin>> x>> y;

        sum[i]= x+y;
        sub[i]= x-y;

    }

    cout << max (  (*max_element( sum , sum +n) - * min_element ( sum , sum +n)),  (*max_element( sub, sub +n) - * min_element ( sub , sub +n)));

    return 0;
}




Measured memory_bytes: 6688
import java.util.*;
import java.math.*;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] tt=new int[n];
		int[] kk=new int[n];
		int[] cc=new int[n];
		for(int i=0; i<n; i++){
			kk[i]=i;
			cc[i]=i;
		}
		tt[n-1]=1;
		for(int i=n-2; i>=1; i--){
			tt[i]=tt[i+1]*(n-i);
		}
		int pp=1;
		for(int i=0; i<n; i++){
			int p=sc.nextInt();
			if(i==n-1){
				break;
			}
			for(int j=p; j<n; j++){
				kk[j]--;
			}
			pp+=kk[p-1]*tt[i+1];
		}
		int qq=1;
		for(int i=0; i<n; i++){
			int q=sc.nextInt();
			if(i==n-1){
				break;
			}
			for(int j=q; j<n; j++){
				cc[j]--;
			}
			qq+=cc[q-1]*tt[i+1];
		}
		System.out.println(Math.abs(qq-pp));
	}
}


Measured memory_bytes: 23252
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
 
int main() {
	int n, l;
	int ans = 0;
	cin >> n >> l;
	if (l <= 0 and l+n-1>=0) {
		for (int i = 1; i < n+1; i++) {
			ans += l+i-1;
		}
	}
	else if(l > 0) {
		for (int i = 2; i < n+1; i++) {
			ans += l+i-1;
		}
	}
	else {
		for (int i = 1; i < n; i++) {
			ans += l+i-1;
		}	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[200010],dp[550][550];

int movex[4] = {1,-1,0,0};
int movey[4] = {0,0,1,-1};

int main(){
  cin >> n >> m;
  char field[102][102];
  l = 0;
  lep(i,1,n){
    lep(j,1,m){
      cin >> field[i][j];
      if(field[i][j] == '.')l++;
    }
  }
  rep(i,0,102)rep(j,0,102)dp[i][j] = INF;
  dp[1][1] = 0;
  queue<P> q;
  q.push(P(1,1));
  while(!q.empty()){
    P p = q.front();
    q.pop();
    ll x,y;
    x = p.first,y = p.second;
    if((x == n && y == m)){
      print(l-min(dp[x][y],dp[x][y])-1);
      return 0;
    }
    rep(i,0,4){
      if(field[x + movex[i]][y + movey[i]] == '.' && dp[x + movex[i]][y + movey[i]] == INF){
        dp[x + movex[i]][y + movey[i]] = dp[x][y] + 1;
        q.push(P(x + movex[i],y + movey[i]));
      }
    }
  }
  print(-1);
  return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<list>
#include<algorithm>
using namespace std;

int main(){
  
  int q, command, x, d;
  list<int> L;
  list<int>::iterator it = L.end();
  
  cin >> q;
  for(int i = 0;i < q;i++){
    cin >> command;
    if(command == 0){
      cin >> x;
      it = L.insert(it, x);
    }else if(command == 1){
      cin >> d;
      if(d > 0) for(int i = 0;i < d;i++) ++it;
      else for(int i = 0;i < -d;i++) --it;
    }else if(command == 2){
      it = L.erase(it);
    }
  }
  
  for(it = L.begin();it != L.end();it++) cout << *it << endl;
  
  return 0;
}


Measured memory_bytes: 18552
#include"stdio.h"
#include"iostream"
#include"string.h"
#include"string"
#include"math.h"
using namespace std;
int a[200005];
int main(){
	int N,i=0;
	long long sum=0,b=0,c=0,min;
	scanf("%d",&N);
	for(i=0;i<N;i++)
	scanf("%d",&a[i]),sum=sum+a[i];
		for(i=0;i<N-1;i++)
		{	b=b+a[i];
			c=sum-b;
			if(i==0)
			min=labs(b-c);
			if(labs(b-c)<labs(min))	min=labs(b-c);
		}
		printf("%ld",min);
		
	
	
	
	
	
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;

int par[100000];
int ran[100000]; //rank

void init(int n){
	for(int i=0;i<n;i++){
		par[i] = i;
		ran[i] = 0;
	}
}

int find(int x){
	if(par[x] == x){
		return x;
	}else{
		return par[x] = find(par[x]);
	}
}

void unite(int x, int y){
	x = find(x);
	y = find(y);
	if(x == y) return;

	if(ran[x]<ran[y]){
		par[x] = y;
	}else{
		par[y] = x;
		if(ran[x]==ran[y]) ran[x]++;
	}
}

bool same(int x, int y){
	return find(x) == find(y);
}

int main(){
	int N,M;
	scanf("%d %d", &N, &M);

	int p[N];
	for(int i=0;i<N;i++){
		scanf("%d", &p[i]);
		// 1<=p[i]<=N -> 0<=p[i]<=N-1
		p[i]--;
	}

	// init union-find
	init(N);

	for(int i=0;i<M;i++){
		int x,y;
		scanf("%d %d", &x, &y);
		// 1<=x,y<=N -> 0<=x,y<=N-1
		x--;
		y--;
		unite(x,y);
	}

	int ans = 0;
	for(int i=0;i<N;i++){
		if(same(i,p[i])) ans++;
	}

	printf("%d\n", ans);

	return 0;
}


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

//temmplate------
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define INF 1e9
#define ZERO(a) memset(a, 0, sizeof(a))
typedef long long lint;
//------template

int main(){
    char C;
    cin >> C;
    cout << char((int)(C) + 1) << "\n";
}

Measured memory_bytes: 256