akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int d;
   scanf("%d",&d);
   
        if(d==25) printf("Christmas\n");
        else if(d==24) printf("Christmas Eve\n");
        else if(d==23) printf("Christmas Eve Eve\n");
        else if(d==22) printf("Christmas Eve Eve Eve\n");
   
}


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

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

        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());
        sc.close();

        out.printf("%d\n", (A - 1) * (B - 1));
        out.flush();
    }
}


Measured memory_bytes: 23764
n = int(input())
h = [i for i in map(int, input().split())]
DP = [0, abs(h[0]-h[1])] 

for i in range(n-2):
    DP += [min(abs(h[i+2]-h[i+1])+DP[-1], abs(h[i+2]-h[i])+DP[-2])]

print(DP[-1])

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

int main() {

  std::string str;
  int temp;

  for(;;) {
    std::cin >> str;
    if( str == "0" ) {
      break;
    }

    temp = 0;
    for(int i = 0; i < str.size(); ++i) {
      temp += str[i] - '0';
    }
    std::cout << temp << std::endl;
  }
  
  return 0;
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
#include <random>
using namespace std;
using ll = long long;
using ldouble = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
const ll mod = ll(1e9) + 7;
const ldouble INF = 1e5;

const int MAX_N = 100;
double EPS = 1e-10;

double add(ldouble a, ldouble b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b)))return 0;
	return a + b;
}

//2dvector
struct P {
	ldouble x, y;
	P() {}
	P(ldouble x, ldouble y) :x(x), y(y) {}
	P operator + (P p) {
		return P(add(x, p.x), add(y, p.y));
	}
	P operator - (P p) {
		return P(add(x, -p.x), add(y, -p.y));
	}
	P operator * (ldouble d) {
		return P(x*d, y*d);
	}
	ldouble dot(P p) {
		return add(x*p.x, y*p.y);
	}
	ldouble det(P p) {
		return add(x*p.y, -y*p.x);
	}
};

//compare_dict
bool cmp_x(const P& p, const P& q) {
	if (p.x != q.x)return p.x < q.x;
	return p.y < q.y;
}

//find convex hull
vector<P> convex_hull(P* ps, int n) {
	sort(ps, ps + n, cmp_x);
	int k = 0;	//vertex_num_of_convex_hull
	vector<P>qs(n * 2);	//convex_hull

						//Lower_part
	for (int i = 0; i < n; i++) {
		while (k > 1 && (qs[k - 1] - qs[k - 2]).det(ps[i] - qs[k - 1]) <= 0)k--;
		qs[k++] = ps[i];
	}
	//Upper_part
	for (int i = n - 2, t = k; i >= 0; i--) {
		while (k > t && (qs[k - 1] - qs[k - 2]).det(ps[i] - qs[k - 1]) <= 0)k--;
		qs[k++] = ps[i];
	}
	qs.resize(k - 1);
	return qs;
}

//squared_dist
ldouble dist(P p, P q) {
	return (p - q).dot(p - q);
}

//inputs
int N;
P ps[MAX_N];

int main() {
	ldouble PI = 3.14159265;
	cin.sync_with_stdio(false);
	cin >> N;
	vector<pair<ldouble, ldouble>>ans;
	rep(i, N) {
		cin >> ps[i].x >> ps[i].y;
		ans.push_back({ ps[i].x,ps[i].y });
	}
	vector<P>qs = convex_hull(ps, N);
	map<pair<ldouble, ldouble>, ldouble>mp;
	rep(i, qs.size()) {
		if (i != qs.size() - 1 && i != 0) {
			ldouble x1 = qs[i - 1].x, x2 = qs[i + 1].x;
			ldouble y1 = qs[i - 1].y, y2 = qs[i + 1].y;
			x1 -= qs[i].x;
			x2 -= qs[i].x;
			y1 -= qs[i].y;
			y2 -= qs[i].y;
			mp[{qs[i].x, qs[i].y}] = (PI - acos(max(-1.0L,min((x1*x2 + y1*y2) / (sqrt(pow(x1, 2) + pow(y1, 2))*sqrt(pow(x2, 2) + pow(y2, 2))),1.0L)))) / (2 * PI);
		}
		else if (i == 0) {
			ldouble x1 = qs[qs.size() - 1].x, x2 = qs[i + 1].x;
			ldouble y1 = qs[qs.size() - 1].y, y2 = qs[i + 1].y;
			x1 -= qs[i].x;
			x2 -= qs[i].x;
			y1 -= qs[i].y;
			y2 -= qs[i].y;
			mp[{qs[i].x, qs[i].y}] = (PI - acos(max(-1.0L, min((x1*x2 + y1*y2) / (sqrt(pow(x1, 2) + pow(y1, 2))*sqrt(pow(x2, 2) + pow(y2, 2))), 1.0L)))) / (2 * PI);
		}
		else {
			ldouble x1 = qs[0].x, x2 = qs[i - 1].x;
			ldouble y1 = qs[0].y, y2 = qs[i - 1].y;
			x1 -= qs[i].x;
			x2 -= qs[i].x;
			y1 -= qs[i].y;
			y2 -= qs[i].y;
			mp[{qs[i].x, qs[i].y}] = (PI - acos(max(-1.0L, min((x1*x2 + y1*y2) / (sqrt(pow(x1, 2) + pow(y1, 2))*sqrt(pow(x2, 2) + pow(y2, 2))), 1.0L)))) / (2 * PI);
		}
	}
	rep(i, N) {
		cout << fixed << setprecision(16) << mp[{ans[i].first, ans[i].second}] << endl;
	}

	return 0;
}


Measured memory_bytes: 256
// This template is based on Mr. tonymontaro's template (https://atcoder.jp/users/tonymontaro).
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    static PrintWriter out;
    static CF_Reader in;

    public static void main(String[] args) throws IOException {
        out = new PrintWriter(new OutputStreamWriter(System.out));
        in = new CF_Reader();
        StringBuilder result = new StringBuilder();

        // Start: int型の整数n mを取得する
        // // N M 形式
        int A = in.intNext();
        int B = in.intNext();
        int C = in.intNext();
        int X = in.intNext();
        // End: int型の整数n mを取得する

        int sum = 0;
        for (int a = 0; a <= A; a++) {
          for (int b = 0; b <= B; b++) {
            for (int c = 0; c <= C; c++) {
              if ((a * 500 + b * 100 + c * 50) == X) {
                sum++;
              }
            }
          }
        }
        result.append(sum);
        // Start: int型の整数Nと配列Aを取得する
        // // N
        // // A1 A2 A3... AN 形式
        // int n = in.intNext();
        // int[] A = in.nextIntArray(n);
        // End: int型の整数Nと配列Aを取得する

        // Start: Char型の文字をInt型に変換する
        // Integer.parseInt(String.valueOf(charText))
        // End: Char型の文字をInt型に変換する

        // Start: 文字列を1文字ずつ出力する
        // String text = in.next();
        // char[] work = new char[text.length()];
        // for(int i = 0; i < text.length(); i++){
        //   work[i] = text.charAt(i); // Char型の文字
        //   out.println(work[i]);
        // }
        // End: 文字列を1文字ずつ出力する

        out.println(result);

        out.close();
    }

    static class CF_Reader {
        BufferedReader br;
        StringTokenizer st;

        public CF_Reader() throws IOException {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine().trim());
            return st.nextToken();
        }

        long longNext() throws IOException {
            return Long.parseLong(next());
        }

        int intNext() throws IOException {
            return Integer.parseInt(next());
        }

        double doubleNext() throws IOException {
            return Double.parseDouble(next());
        }

        char charNext() throws IOException {
            return next().charAt(0);
        }

        public int[] nextIntArray(final int n) throws IOException {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = intNext();
            return a;
        }

        public long[] nextLongArray(final int n) throws IOException {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = longNext();
            return a;
        }

        String line() throws IOException {
            return br.readLine().trim();
        }
    }
}

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

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))
#define F first
#define S second
#define int ll

int patties[51];
int sz[51];
int calc(int n, int x){
    if(n == 0){
        if(x <= 0){
            return 0;
        }
        else{
            return 1;
        }
    }
    if(x <= sz[n - 1] + 1){
        return calc(n - 1, x - 1);
    }
    return patties[n - 1] + calc(n - 1, x - sz[n - 1] - 2) + 1;
}
int32_t main(){
    FAST
    int n, x; cin >> n >> x;
    patties[0] = 1;
    sz[0] = 1;
    for(int i = 1; i <= n; i++){
        sz[i] = sz[i - 1]*2 + 3;
        patties[i] = patties[i - 1]*2 + 1;
    }
    cout << calc(n, x);
    return 0;
}


Measured memory_bytes: 3704
import sys

def gcd(a, b):
    """
    最大公約数を求める
    """
    if a < b:
        a, b = b, a
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    """
    最小公倍数を求める
    """
    return a*b//(gcd(a, b))


input = sys.stdin.readline

a, b, c, d = map(int, input().split())

div_ac = (a-1) // c
div_bc = b // c


div_ad = (a-1) // d
div_bd = b // d

lcm_cd = lcm(c,d)

div_acd = (a-1) // lcm_cd
div_bcd = b // lcm_cd

a_1_result =  div_ac + div_ad - div_acd
b_result = div_bc + div_bd - div_bcd

print((b+1 - a) - (b_result - a_1_result))


Measured memory_bytes: 9200
import java.lang.Math;
import java.util.Scanner;

class Main{
  public static void main(String args[]){
    Scanner scanner = new Scanner(System.in);
    long n = scanner.nextInt();
    long m = scanner.nextInt();
    long N = (n == 1) ? 1 : n - 2;
    long M = (m == 1) ? 1 : m - 2;

    System.out.println(N * M);
  }
}

Measured memory_bytes: 21588
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
#include <bits/stdc++.h>
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<22,stdin),p1 == p2)?EOF:*p1++)
using namespace std ;
//char buf[(1 << 22)] , *p1 = buf , *p2 = buf ;
inline int read ()
{
    char c = getchar () ; int x = 0 , f = 1 ;
    while (c < '0' || c > '9') { if (c == '-') f = -1 ; c = getchar () ; }
    while (c >= '0' && c <= '9'){ x = x * 10 + c - '0' ; c = getchar () ; }
    return x * f ;
}
string s ;
int st[200005] , ans , top ;
int main ()
{
//	freopen (".in" , "r" , stdin) ; freopen (".out" , "w" , stdout) ;
	cin >> s ;
	ans = s.size () ;
	for (int i = 0 ; i < s.size () ; i ++)
	{
		if (s[i] == 'S') st[++ top] = 'S' ;
		else if (top) top -- , ans -= 2 ;
	}
	cout << ans ;
}


Measured memory_bytes: 900
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;
 
//---main---------------------------------------------
int main(){
    //main
    int N;
    cin >> N;
    int A[N], B[N];
    rep(i,N) cin >> A[i] >> B[i];
    sort(A,A+N);
    sort(B,B+N);
 
 
    int ans;
    if(N%2==0) ans = (B[N/2-1] + B[N/2]) - (A[N/2-1]+A[N/2]) + 1;
    else ans = B[(N+1)/2-1] - A[(N+1)/2-1] + 1;
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 5184
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;

const int N=1000005;
const int mod=1000000007;

int n,ans;
int dp[N],s[N];

int main(){
	int i;
	scanf("%d",&n);
	if (n==1){
		printf("%d\n",n);
		return 0;
	}
	dp[0]=dp[1]=s[0]=1; s[1]=2;
	for (i=2;i<n;i++){
		dp[i]=(s[i-1]-dp[i-2])%mod;
		s[i]=(s[i-1]+dp[i])%mod;
	}
	ans=1ll*dp[n-1]*n%mod;
	(ans+=1ll*dp[n-2]*(n-1)%mod*n%mod)%=mod;
	for (i=0;i<n-2;i++){
		(ans+=1ll*dp[i]*(i+2)%mod*n%mod)%=mod;
		(ans+=1ll*dp[i]*(n-i-3)%mod*(n-1)%mod)%=mod;
	}
	printf("%d\n",(ans+mod)%mod);
	return 0;
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define MXN 300000
#define N 100005
int dp[305][305][305];
int mod=1e9+7;
int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    MEM(dp);
    vector<pii> v[305];
    for(int i =0;i<m;i++){
        int l,r,x;
        scanf("%d %d %d",&l,&r,&x);
        v[r].pb(mp(l,x));
    }
    dp[0][0][0]=1;
    LL ans=0;
    for(int i =0;i<=n;i++){
        for(int j=0;j<=n;j++){
            for(int k=0;k<=n;k++){
                int now=max(i,max(j,k));
                for(auto it:v[now]){
                    int cnt=0;
                    if(i>=it.x)cnt++;
                    if(j>=it.x)cnt++;
                    if(k>=it.x)cnt++;
                    if(cnt!=it.y)dp[i][j][k]=0;
                }
                if(now==n){
                    ans+=dp[i][j][k];
                }
                else{
                    dp[i][j][now+1]+=dp[i][j][k];
                    dp[i][j][now+1]%=mod;
                    dp[i][now+1][k]+=dp[i][j][k];
                    dp[i][now+1][k]%=mod;
                    dp[now+1][j][k]+=dp[i][j][k];
                    dp[now+1][j][k]%=mod;
                }
            }
        }
    }
    printf("%lld\n",ans%mod);
}

Measured memory_bytes: 111232
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

int main(){
  int n,m;
  while(cin>>n>>m,n){
    string s,p,g;
    cin>>s>>p>>g;
    int d[501][501];
    REP(i,n)REP(j,n)d[i][j] = (i!=j)?10000000:0;
    map<string,int> hash;
    int cnt = 0;
    hash[s] = cnt++;
    hash[p] = cnt++;
    hash[g] = cnt++;
    REP(i,m){
      string A,B;
      int ds,t;
      cin>>A>>B>>ds>>t;
      int dist = ds/40 + t;
      int na,nb;
      if(hash.find(A)!=hash.end())na = hash[A];
      else na = hash[A] = cnt++;
      if(hash.find(B)!=hash.end())nb = hash[B];
      else nb = hash[B] = cnt++;
      d[na][nb] = d[nb][na] = dist;
    }
    assert(cnt == n);
    REP(k,n)REP(i,n)REP(j,n)d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
    cout<<d[0][1]+d[1][2]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1940
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(ll i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

// 1_indexed
class BIT {
private:
    int n;
    vector<ll> a;
public:
    BIT(int _n);
    void add(int idx, ll v);
    ll sum(int i);
    ll sum(int i, int j);
    ~BIT();
};

BIT::BIT(int _n) {
    n = _n;
    a.assign(n+1, 0ll);
}

void BIT::add(int idx, ll x) {
    while (idx <= n) {
        a[idx] += x;
        idx += (idx & -idx);
    }
}

ll BIT::sum(int i) {
    ll ret = 0;
    while (i > 0) {
        ret += a[i];
        i -= (i & -i);
    }
    return ret;
}

ll BIT::sum(int i, int j) {
    ll l = sum(i-1);
    ll r = sum(j);
    return r-l;
}

BIT::~BIT() {
}


int main(int argc, char const *argv[]) {
    int n,q; cin>>n>>q;
    BIT ft = BIT(n);
    while (q--) {
        ll t,x,y; cin>>t>>x>>y;
        if (t) {
            cout << ft.sum(x,y) << '\n';
        }
        else {
            ft.add(x, y);
        }
    }
    return 0;
}


Measured memory_bytes: 3628
N, X = gets.split(" ").map(&:to_i)
L = gets.split(" ").map(&:to_i)
# S = gets.chomp
# N = gets.to_i

pos = 0
cnt = 0
while pos <= X
  if cnt >= L.size
    cnt += 1
    break
  end
  pos += L[cnt]
  cnt += 1
end
puts cnt


Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <algorithm>
#include <ios>
#include <iomanip>
#include <cmath>
#include <regex>
using namespace std;

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

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int D, N;
	cin>>D>>N;
	if((N==100)&&(D==0))
	{
		cout<<101;
	}
	else
	{
		if(D==0)
		{
			cout<<N;
		}
		else
		{
			if(D==1)
			{
				if(N==100)
				{
					cout<<101*100;
				}
				else
				{
				    cout<<N*100;
				}
			}
			else
			{
				if(N==100)
				{
				    cout<<101*100*100;
				}
				else
				{
					cout<<N*100*100;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
records = []

for i in range(M):
    pi, yi = map(int, input().split())
    records.append([i, pi, yi, "X"])

records.sort(key=lambda x:x[2])
records.sort(key=lambda x:x[1])

# for i in records:
#     print(i)
city = records[0][1]
city_num = 0

for i in range(M):
    if records[i][1] == city:
        city_num += 1
        records[i][3] = city_num
    else:
        city = records[i][1]
        records[i][3] = 1
        city_num = 1
records.sort()
for record in records:
    ans = "%06d" % record[1] + "%06d" % record[3]
    print(ans)


Measured memory_bytes: 29604
#!/usr/bin/python3
# Copyright (C) 2017 Sayutin Dmitry.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; version 3
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; If not, see <http://www.gnu.org/licenses/>.

def main():
    print("Yes" if input().strip().startswith("YAKI") else "No")

main()


Measured memory_bytes: 2940
# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define F first
# define S second
# define pb push_back
# define ub upper_bound
# define lb lower_bound
# define all(x) x.begin(), x.end()
# define pqueue priority_queue
# define mset multiset
# define umap unordered_map
# define Speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
# define rep(i,n) for(int i=0;i<n;++i)
# define forn(i,n) for(int i=1;i<=n;++i)
# define lr(i,l,r) for(int i=l;(l>r?i>=r:i<=r);(l>r?--i:++i))

using namespace std;

template<class T> void umin(T &a,T b){a=min(a,b);}
template<class T> void umax(T &a,T b){a=max(a,b);}

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int dx[]={1,0,-1,0,-1,-1,1,1},dy[]={0,1,0,-1,-1,1,-1,1}; 
const int mod = 1e9+7;
const ll N = 2e6+5;

//ll prime[N];

bool isprime(ll x){
	if(x<=2)return true;
	for(ll i=2;i*i<=x;++i){
		if(x%i==0){
			return 0;
		}
	}
	return 1;
}

void solve(){
	ll a,b;
	// rep(i,N+1)prime[i]=1;
	// for(int i=2;i<=N;++i){
	// 	for(int j=i+i;j<=N;j+=i){
	// 		prime[j]=0;
	// 	}
	// }
	cin>>a>>b;
	ll g=__gcd(a,b);
	vector<ll>v;
	for(ll i=1;i*i<=g;++i){
		if(g%i==0){
			v.pb(i);
			if(g/i!=i)v.pb(g/i);
		}
	}
	ll cnt=0;
	for(auto i:v){
		if(isprime(i))cnt++;
	}
	cout<<cnt;
}

int main(){
	Speed();
	int T=1; 
	//cin>>T;	
	while(T--)
		solve();
	return 0;
}

Measured memory_bytes: 3700
#include<stdio.h>

int main(void){

	int m,d;
	while(1){
	scanf("%d %d",&m,&d);
	if(m==0){break;}
	switch(m){
	case 12:d=d+30;
	case 11:d=d+31;
	case 10:d=d+30;
	case  9:d=d+31;
	case  8:d=d+31;
	case  7:d=d+30;
	case  6:d=d+31;
	case  5:d=d+30;
	case  4:d=d+31;
	case  3:d=d+29;
	case  2:d=d+31;
	}
	switch(d%7){
	case 1:printf("Thursday\n");break;
	case 2:printf("Friday\n");break;
	case 3:printf("Saturday\n");break;
	case 4:printf("Sunday\n");break;
	case 5:printf("Monday\n");break;
	case 6:printf("Tuesday\n");break;
	case 0:printf("Wednesday\n");break;
	}
	}
	return 0;
}

Measured memory_bytes: 584
import java.io.*;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(
				new InputStreamReader (System.in));
		String line=br.readLine();
		String[] str = line.split(" ");
		int W=Integer.parseInt(str[0]);
		int H=Integer.parseInt(str[1]);
		int x=Integer.parseInt(str[2]);
		int y=Integer.parseInt(str[3]);
		int r=Integer.parseInt(str[4]);
		if(0<=x-r && x+r<=W && 0<=y-r && y+r<=H) System.out.println("Yes");
		else System.out.println("No");
	}
}

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

int main(){
  int N, A, j, count_a=0, count_min=0;
  cin >> N;
  cin >> A;
  j = A;
  count_a = 0;
  while (j%2 == 0){
    count_a++;
    j /= 2;      
  }
  count_min = count_a;
  for (int i=0; i<N-1; i++){
    cin >> A;
    j = A;
    count_a = 0;
    while (j%2 == 0){
      count_a++;
      j /= 2;      
    }
    if (count_a <= count_min) count_min = count_a;
  }
  cout << count_min << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dimensional
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] NMXY = Console.ReadLine().Split(' ');

            int N = int.Parse(NMXY[0]);
            int M = int.Parse(NMXY[1]);
            int X = int.Parse(NMXY[2]);
            int Y = int.Parse(NMXY[3]);

            string[] x0 = Console.ReadLine().Split(' ');
            List<int> xNum = new List<int>();

            for(int i = 0; i < N; i++)
            {
                int x = int.Parse(x0[i]);
                xNum.Add(x);
            }

            xNum.Sort();

            string[] y0 = Console.ReadLine().Split(' ');
            List<int> yNum = new List<int>();

            for (int i = 0; i < M; i++)
            {
                int y = int.Parse(y0[i]);
                yNum.Add(y);
            }

            yNum.Sort();

            if (xNum[N - 1] < yNum[0] && X < yNum[0] && yNum[0] <= Y)  
            {
                Console.WriteLine("No War");
            }
            else
            {
                Console.WriteLine("War");
            }
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <iomanip>
#include <stack>
#include <array>
#include <deque>
#include <forward_list>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iterator>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <time.h>
#include <complex>
#include <cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n;i>0;i--)
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define SORT(v) sort((v).begin(),(v).end())
#define TEMP(type,x,y) do {temp temp=x,x=y,y=temp}while(0)
const ll INF = (1LL << 50);

int main() {

	int N, K;
	cin >> N >> K;

	int cnt = 0;
	REP(i, N) {
		int h;
		cin >> h;
		if (h >= K) cnt++;
	}

	cout << cnt << endl;

	return 0;

}

Measured memory_bytes: 256
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define fastAF ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define int ll
#define ull unsigned ll
#define ld long double
#define pb push_back
#define pf push_front
#define dll deque<ll>
#define vll vector<ll>
#define pll pair<ll,ll>
#define mapll map<ll,ll>
#define endl "\n"
#define all(v) v.begin(),v.end()
#define ms(a,x) memset(a,x,sizeof(a))
using namespace std;
void swap(auto*,auto*);
const ll N=2e5;
vll adj[N+1]; bool visited[N+1];
ll bfs(ll node)
{
	visited[node]=1;
	 ll start=node;
	queue<ll> q; ll c=0;
	q.push(node);
	while(!q.empty())
	{
		node=q.front(); q.pop(); c++;
		for(ll x:adj[node])
		{
			if(visited[x]) continue;
			visited[x]=1; q.push(x);
		}
	}
	return c;
}
int32_t main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fastAF
    ll n; cin>>n; ll m; cin>>m;
    for(ll i=1;i<=m;i++) {
    	ll u,v; cin>>u>>v; adj[u].pb(v); adj[v].pb(u);
    }
    ll maxLength=0; ms(visited,0);
    for(ll i=1;i<=n;i++)
    {
    	if(visited[i]) continue;
    	maxLength=max(maxLength,bfs(i));
    }
    cout<<maxLength<<endl;
    return 0;
}
void swap(auto &a,auto &b)
{
    auto temp=a; a=b; b=temp;
}

Measured memory_bytes: 17372
#include<stdio.h> 
#include<stdlib.h> 
struct node{ int key; struct node *p; struct node *l; struct node *r; }; 
typedef struct node *NodePointer; 
NodePointer r,NIL; 
NodePointer find(NodePointer x,int k){ 
while(x != NIL && k != x->key){ 
if(k < x->key){ 
x = x->l; 
}else{ x = x->r; 
} 
} 
return x; 
} 
void insert(int k){ 
NodePointer y = NIL; 
NodePointer x = r; 
NodePointer z = (NodePointer)malloc(sizeof(struct node)); 
z->key = k; 
z->l = NIL; 
z->r = NIL; 
while(x != NIL){ 
y = x; 
if(z->key < x->key){
x = x->l; 
}else{ x = x->r; 
} 
} 
z->p = y; 
if(y == NIL){ 
r = z; 
}
else if(z->key < y->key){ 
y->l = z; 
}
else{ y->r = z; 
} 
} 
void inorder(NodePointer u){ 
if(u == NIL){ 
return; 
} 
inorder(u->l); 
printf(" %d",u->key); 
inorder(u->r); 
} 
void preorder(NodePointer u){ 
if(u == NIL){ 
return; 
}
printf(" %d",u->key); 
preorder(u->l); 
preorder(u->r); 
} 
void print(){ 
inorder(r); 
puts(""); 
preorder(r); 
puts(""); 
} 
int main(){ 
int n,i,j,z,x; 
char s[10]; 
scanf("%d",&n); 
for(i=0;i<n;i++){ 
scanf("%s",s); 
if(s[0] == 'f'){ 
scanf("%d",&x); 
NodePointer t = find(r,x); 
if(t == NIL)printf("no\n"); 
else printf("yes\n"); 
}
else if(s[0] == 'i')
{ scanf("%d",&z); 
insert(z); 
}
else{ 
print(); 
} 
} 
return 0; 
} 


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

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

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int mod = 2019;

void Main() {
  int n;
  cin >> n;
  vector<int> A(n);
  rep(i, n) cin >> A[i];
  vector<int> B(n+1);
  rep(i, n) {
    if (i%2==0) {
      B[i+1] = B[i] + A[i];
    } else {
      B[i+1] = B[i] - A[i];
    }
  }
  rep(i, n) {
    int ans;
    if (i%2 == 0) ans = B[n] - 2 * B[i];
    else ans = - B[n] + 2 * B[i];
    cout << ans << " ";
  }
  cout << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 2176
s = input()

len_s = len(s)

current = 0
mod_dict = dict()
mod_dict[0] = 1
for i in range(len_s-1,-1,-1):
    c = s[i]
    current = (current+pow(10,len_s-i-1,2019)*int(c)) % 2019
    if current in mod_dict:
        mod_dict[current] += 1
    else:
        mod_dict[current] = 1

count = 0
for key in mod_dict:
    count+= (mod_dict[key]*(mod_dict[key]-1))//2

print(count)

Measured memory_bytes: 9184
N = int(input())
H = [int(x) for x in input().split()]
Count = 0
MAXC  = 0
for T in range(0,N-1):
    if H[T]>=H[T+1]:
        Count += 1
    else:
        Count = 0
    if Count > MAXC:
        MAXC = Count
print(MAXC)

Measured memory_bytes: 19984
def main() :
    n = int(input())

    if (n <= 599) :
        print(8)
        return
    
    if (n <= 799) :
        print(7)
        return
    
    if (n <= 999) :
        print(6)
        return

    if (n <= 1199) :
        print(5)
        return

    if (n <= 1399) :
        print(4)
        return

    if (n <= 1599) :
        print(3)
        return

    if (n <= 1799) :
        print(2)
        return

    if (n <= 1999) :
        print(1)
        return


main()



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

int main(){
	int n;
	cin >> n;
	int ans = 0;
	for(int a = 0; a <= n; ++a){
		for(int b = 0; b <= n-a; ++b){
			int total = 4*a+7*b;
			if(n==total) ++ans;
		}
	}
	if(ans) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f1 for(i=0; i<n; i++)
#define f2 for(j=0; j<n; j++)
int main()
{
   int x,y;
   cin>>x>>y;
   cout<<x+y/2<<endl;

}


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

#define pb push_back
#define vi vector < int >
#define ii pair < int, int >
#define vii vector < pair < int, int > >
#define vvi vector < vector < int > >
#define ll long long
#define X first
#define Y second
#define mp make_pair
#define FOR( i, lo, hi ) for( int i = (lo);i < (hi);i++ )
#define DFOR( i, hi, lo ) for( int i = (hi);i >= (lo);i-- )
#define pqueue priority_queue

using namespace std;

int n;

int digits( int x )
{
	int ret = 0;
	while ( x )
	{
		x /= 10;
		ret++;
	}
	return ret;
}

int main()
{
	cin >> n;
	int sol = 0;
	FOR( i, 1, n + 1 )
	{
		if ( digits( i ) % 2 == 1 )
			sol++;
	}
	cout << sol << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
using namespace std;
int main() {
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b+c>=22) cout<<"bust"<<endl;
    else cout<<"win"<<endl;
    return 0;
}

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

typedef long long ll;

int main(){
  string s;
  cin >> s;
  int pre;
  int after;
  pre = 10*(s[0]-'0') + s[1]-'0';
  after = 10*(s[2]-'0') + s[3]-'0';
  if(pre <= 12 && after <= 12 && pre > 0 && after > 0){
    cout << "AMBIGUOUS" <<endl;
  }
  else if(pre <= 12 && pre > 0){
    cout << "MMYY" <<endl;
  }
  else if(after <= 12 && after > 0){
    cout << "YYMM" <<endl;
  }
  else{
    cout << "NA" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//�]���؂�グ�� =>  (a + b - 1) / b 

signed main(){
	int n,m; cin>>n>>m;
	rep(i,0,n){
      string s; cin>>s;
      cout<<s<<endl;
      cout<<s<<endl;
    }
	return 0;
}

Measured memory_bytes: 256
n = int(input())
s = list(map(str,input()))
count = 0
for i in range(1,n):
  if s[i] == "E":
    count += 1
box = [0]*n
box[0] = count
for j in range(1,n):
  if s[j] == "E":
    count -= 1
  if s[j - 1] == "W":
    count += 1
  box[j] = count
print(min(box))

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

const int N = 2e5;
int T[N+100],F[N+100];
string c[N+100];

int main()
{
	string s,f = "",b = "";
	cin >> s;
	int q,total = 0,cur = 0;
	cin >> q;
	for(int i=1;i<=q;i++)
	{
		cin >> T[i];
		if(T[i]==1){
			total++;
		}
		else{
			cin >> F[i] >> c[i];
		}
	}
	for(int i=1;i<=q;i++)
	{
		if(T[i]==1){
			cur++;
		}
		else{
			if(F[i]==1){
				if((cur&1)==(total&1)){
					f += c[i];
				}
				else{
					b += c[i];
				}
			}
			else{
				if((cur&1)==(total&1)){
					b += c[i];
				}
				else{
					f += c[i];
				}
			}
		}
	}
	reverse(f.begin(),f.end());
	if(total&1){
		reverse(s.begin(),s.end());
	}
	cout << f << s << b << "\n";
}


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

using namespace std;

#define TEMP_T template<typename T>
TEMP_T void sort(T& v){ sort(v.begin(), v.end()); }
TEMP_T void revs(T& v){ reverse(v.begin(), v.end()); }
TEMP_T void uniq(T& v){ sort(v); v.erase(unique(v.begin(), v.end()), v.end()); }
TEMP_T T    cums(T& v){ T r(v.size()); partial_sum(v.begin(), v.end(), r); return r; }
TEMP_T void show(T& v, char delim=' ', char end='\n'){ for(int i=0; i<v.size()-1; i++) cout << v[i] << delim; cout << v[v.size()-1] << end; }
TEMP_T T    acum(vector<T>& v, T b=0){ return accumulate(v.begin(), v.end(), b); }
TEMP_T vector<T> inpt(int n){ vector<T> v(n); for (int i=0; i<n; i++) cin >> v[i]; return v; }

static inline int in(){ int x; scanf("%d", &x); return x; }
static const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
static const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};

struct Box {
  int cap;
  int val;
  Box(int cap, int val) : cap(cap), val(val) {}
};

int main()
{
  int n, m;
  m = in();
  n = in();
  vector<int> p = inpt<int>(m);
  sort(p);
  revs(p);
  vector<Box> bs;
  for (int i = 0; i < n; i++){
    int c, v;
    c = in();
    v = in();
    bs.push_back(Box(c, v));
  }
  int dp[10002]; // dp[cap] = min cost;
  const int inf = 100000000;
  fill(dp, dp + m + 2, inf);
  dp[0] = 0;
  for (int i = 0; i < n; i++){
    for (int j = m; j >= 0; j--){
      if (j + bs[i].cap > m) dp[m] = min(dp[m], dp[j] + bs[i].val);
      else dp[j + bs[i].cap] = min(dp[j + bs[i].cap], dp[j] + bs[i].val);
      dp[j] = min(dp[j], dp[j + 1]);
    }
  }
  vector<int> cum(m);
  cum[0] = p[0];
  for (int i = 1; i < m; i++){
    cum[i] = cum[i - 1] + p[i];
  }
  int maxi = 0;
  for (int i = 0; i < m; i++){
    maxi = max(maxi, cum[i] - dp[i + 1]);
  }
  printf("%d\n", maxi);
  return (0);
}

Measured memory_bytes: 1372
#include <iostream>
using namespace std;
main(){
	long long M,rD,rR,cD,cR;
	cin>>M>>rD>>rR>>cD>>cR;
	M -= (cD*100+rD-1)/rD + (cR*100+rR-1)/rR;
	cout << (M<0?-1:M) << endl;
	return 0;
}

Measured memory_bytes: 1160
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, M = mapint()

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

uf = UnionFind(N)
for _ in range(M):
    x, y, z = mapint()
    uf.union(x-1, y-1)
print(uf.group_count())

Measured memory_bytes: 81204
count=gets.to_i
array=[]
i=0
sum=0
count.times do
x=gets.to_i
array.push(x)
end
count.times do
  sum=sum+array[i]
  i=i+1
end
mini=array.reject { |e| e.modulo(10)==0 }
x=mini.min
if mini==[] then
  puts 0

elsif sum.modulo(10)==0 then
  puts(sum-x)
else
 puts(sum)
end


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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define int long long
typedef pair<int, int> ii;

const int N = 1e5 + 5;
int n, m, a[N], f[N], l[N], r[N], v[N], real[N];
vector<int> graph[N];
const int inf = 1e11;

void dfs(int u, int p){
    for(int i = 0; i < graph[u].size(); i++){
        int v = graph[u][i];
        if(v == p) continue;
        f[v] = f[u] + 1;
        dfs(v, u);
    }
}

void bye(){
    cout << "No\n";
    exit(0);
}
signed main() {
    cin.tie(0), ios::sync_with_stdio(0);
    cin >> n;
    for(int i =  1; i <= n - 1; i++){
        int u, v;
        cin >> u >> v;
        graph[u].pb(v); graph[v].pb(u);
    }
    dfs(1, 1);
    cin >> m;
    queue<int> q;
    for(int i = 1; i <= n; i++)
        l[i] = -inf, r[i] = inf;
    for(int i = 1; i <= m; i++){
        cin >> v[i];
        cin >> a[i];
        l[v[i]] = a[i];
        r[v[i]] = a[i];
        q.push(v[i]);
    }
    int prev = -1;
    for(int i = 1; i <= m; i++){//kiem tra tinh chan le
        int sum = (a[i] + f[v[i]]) % 2;
        if(prev == -1) prev = sum;
        if(sum != prev)
            bye();
        prev = sum;
    }
    while(!q.empty()){
        int u = q.front();
        q.pop();
        for(int i = 0; i < graph[u].size(); i++){
            int w = graph[u][i];
            int temp = l[u] - 1;
            if(temp > l[w]){
                l[w] = max(temp, l[w]);
                q.push(w);
            }
        }
    }
    for(int i = 1; i <= n; i++)
        q.push(v[i]);
    while(!q.empty()){
        int u = q.front();
        q.pop();
        for(int i = 0; i < graph[u].size(); i++){
            int w = graph[u][i];
            int temp = r[u] + 1;
            if(temp < r[w]){
                r[w] = min(temp, r[w]);
                q.push(w);
            }
        }
    }
    for(int i = 1; i <= n; i++){
        if(l[i] > r[i])
            bye();
    }
    cout << "Yes\n";
    for(int i = 1; i <= n; i++){
        cout << l[i] << "\n";
        for(int j = 0; j < graph[i].size(); j++){
            int w = graph[i][j];
            l[w] = max(l[w], l[i] - 1);
            r[w] = min(r[w], r[i] + 1);
        }
    }
}

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

int main(){
    int N,Y;
    cin >> N >> Y;
    int ansA=-1,ansB=-1,ansC=-1;
    for(int a=0;a<=N;a++){
        for(int b=0;b<=N-a;b++){
            int c=N-b-a;
            int total = 10000*a+5000*b+1000*c;
            if(total==Y){
                ansA=a;
                ansB=b;
                ansC=c;
            }
        }
    }
    cout << ansA << " " << ansB << " " << ansC << endl;
}

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


def main():
    n, m = map(int, input().split())
    ac_count = [0 for _ in range(n)]
    wa_count = [0 for _ in range(n)]

    for i in range(m):
        pi, si = input().split()
        pi = int(pi)
        pi -= 1

        if si == 'WA':
            if ac_count[pi] == 0:
                wa_count[pi] += 1
        else:
            if ac_count[pi] == 0:
                ac_count[pi] = 1

    total_ac = sum(ac_count)
    total_wa = 0

    for ac, wa in zip(ac_count, wa_count):
        if ac == 1:
            total_wa += wa

    print(total_ac, total_wa)


if __name__ == '__main__':
    main()


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

using namespace std;
using ll = long long;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll k;
    cin >> k;
    if (k % 7 == 0) k /= 7;
    k *= 9;
    ll v = 10;
    for (int i = 1; i < (int)2e6+11; ++i) {
        if (v % k == 1) {
            cout << i << '\n';
            return 0;
        }
        v = (v * 10) % k;
    }

    cout << -1 << '\n';
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	Int N;
	cin >> N;
	Int ans = 0;
	for (Int i = 1; i <= N; ++i) { ans += i * (N - i + 1); }
	for (int i = 0; i < N - 1; ++i) {
		Int u, v;
		cin >> u >> v;
		if (u > v) { swap(u, v); }
		ans -= u * (N - v + 1);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3580
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<bitset>

using namespace std;

/*

*/

char s[5];

int cal(int n, int m, int op){
  if(op == 0)
    return n + m;
  else
    return n - m;
}


int sum(int* op){
  int ret = s[0] - '0';
  for(int i = 0; i < 3; i++){
    ret = cal(ret, s[i + 1] - '0', op[i]);
  }
  return ret;
}

long long int pow(int x, int n){
  if(n == 0)
    return 1;

  return x * pow(x, n - 1);
}



char opt[2][2] = {"+", "-"};

int main(){
  scanf("%s\n", s);

  int op[3];
  for(int i = 0; i < 8; i++){
    for(int j = 0; j < 3; j++){
      op[j] = (i >> j) % 2;
    }

    if(sum(op) == 7){
      for(int i = 0; i < 3; i++)
        cout << s[i] << opt[op[i]];

      cout << s[3] << "=7" << endl;
      return 0;
    }

    
  }
  return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		string[] str = Console.ReadLine().Split();
		int[] A = new int[N];
		for(var i=0;i<N;i++){
			A[i] = int.Parse(str[i]);
		}
		int min = 1;
		int max = N;
		while(min<max){
			int na = (min+max)/2;
			bool flag = true;
			var listS = new List<int>();
			var listN = new List<int>();
			listS.Add(1);
			listN.Add(A[0]);
			for(var i=1;i<N;i++){
				if(A[i] > A[i-1]){
					int cta = listS.Count-1;
					if(listS[cta] == 1){
						listN[cta] += A[i]-A[i-1];
					} else {
						listS.Add(1);
						listN.Add(A[i]-A[i-1]);
					}
				} else {
					int cn = listS.Count-1;
					int ca = A[i-1]-A[i];
					while(ca > 0){
						if(listN[cn] <= ca){
							ca -= listN[cn];
							listN.RemoveAt(cn);
							listS.RemoveAt(cn);
							cn--;
						} else {
							listN[cn] -= ca;
							ca = 0;
						}
					}
					if(listS[cn] == na){
						if(listS.Count == 1){
							flag = false;
							break;
						} else {
							int n1 = listN[cn];
							if(listN[cn-1] == 1){
								listS[cn-1] += 1;
								listS[cn] = 1;
								if(cn-1 > 0 && listS[cn-2] == listS[cn-1]){
									listN[cn-2] += listN[cn-1];
									listS[cn-1] = listS[cn];
									listN[cn-1] = listN[cn];
									listS.RemoveAt(cn);
									listN.RemoveAt(cn);
								}
							} else {
								listN[cn-1] -= 1;
								listS[cn] = listS[cn-1]+1;
								listN[cn] = 1;
								listS.Add(1);
								listN.Add(n1);
							}
						}
					} else {
						if(listN[cn] == 1){
							listS[cn] += 1;
							if(cn > 0 && listS[cn-1] == listS[cn]){
								listN[cn-1] += listN[cn];
								listS.RemoveAt(cn);
								listN.RemoveAt(cn);
							}
						} else {
							listN[cn] -= 1;
							listS.Add(listS[cn]+1);
							listN.Add(1);
						}
					}
				}
			}
			if(flag){
				max = na;
			} else {
				min = na+1;
			}
		}
		Console.WriteLine(min);
	}
}

Measured memory_bytes: 29148
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()
    N = len(S)
    power = [0] * N
    power[0] = 1
    for i in range(N - 1):
        power[i + 1] = 10 * power[i] % 13

    S = S[::-1]

    Q = [i for i, c in enumerate(S) if c == '?']
    M = len(Q)

    const = 0
    for i, c in enumerate(S):
        if c != '?':
            const = (const + power[i] * int(c)) % 13

    dp = [0] * 13
    dp[const] = 1

    for i in range(M):
        dp, dp_prev = [0] * 13, dp
        p = power[Q[i]]
        for j in range(10):
            for k in range(13):
                idx = (p * j + k) % 13
                dp[idx] = (dp[idx] + dp_prev[k]) % MOD

    print(dp[5])
    return


if __name__ == '__main__':
    main()


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

public class Main {
	
	
	public static int dfs(int rest, int remain, int[][] memo){
		if(memo[rest][remain] != -1){
			return memo[rest][remain];
		}else if(rest == 0){
			return remain == 0 ? 1 : 0;
		}
		
		int ret = 0;
		
		final int limit = Math.min(1000, remain);
		for(int cur = 0; cur <= limit; cur++){
			ret += dfs(rest - 1, remain - cur, memo);
		}
		
		return memo[rest][remain] = ret;
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int[][] memo = new int[5][4001];
		for(int i = 0; i < 5; i++){
			if(i == 0){
				memo[0][0] = 1; 
			}else{
				Arrays.fill(memo[i], -1);
			}
		}
		
		while (sc.hasNextInt()) {
			final int n = sc.nextInt();
			
			System.out.println(dfs(4, n, memo));
		}
	}

}

Measured memory_bytes: 20200
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  string a, b, c;
  cin >> a >> b >> c;
  cout << (char)toupper(a[0]) << (char)toupper(b[0]) << (char)toupper(c[0])
       << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
const int mod = 1000000007;
const int max_n = 200005;
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;
}
int main(){
    ll n,k,s;cin >> n >>k >>s;
    if(s!=inf-10){
        rep(i,k)cout << s <<" ";
        rep(i,n-k)cout << inf-10 <<" ";
    }
    else{
        rep(i,k)cout << s <<" ";
        rep(i,n-k)cout << 1 <<" ";
    }
}

Measured memory_bytes: 1280
#include <iostream>
#define N 4005
using namespace std;
int n, a[N], d[N][N];

int abs(int p) {return p>0 ? p:-p;}

int f(int p, int q) {
	if(p==n+1 || q==n+1) return abs(a[p] - a[q]);
	if(d[p][q]) return d[p][q];
	if(p>q) return d[p][q] = max(f(p+1, q), f(p, p+1));
	else return d[p][q] = min(f(q+1, q), f(p, q+1));
}

int main() {
	cin>>n>>a[1]>>a[0];
	for(int i=2; i<n+2; i++) cin>>a[i];
	cout<<(n==1 ? abs(a[2]-a[0]) : f(1,0));
	return 0;
}

Measured memory_bytes: 32640