akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define END getchar();getchar();return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define inf 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

signed main() {
	int a[10], ma = 0, ans = 0;
	rep(i, 5) {
		cin >> a[i];
		if (10 - (a[i] % 10) == 10) {
			ans += a[i];
		}
		else {
			ans += a[i] + 10 - (a[i] % 10);
			ma = max(ma, 10 - (a[i] % 10));
		}
	}
	cout << ans - ma << endl;
	

	END;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define cinf(x,n) for(int i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(int i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

int main(){
	int a,b;
	cin >> a >> b;
	cout << a*b << " " << 2*a+2*b << endl;
}


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

int main() {
    string s; cin >> s;
    int n = (int)s.size();

    // sでは同一の文字が隣合わず、両端は取れないので
    // abababacbab <- cとる
    // abababacabab <- cの両側どちらか　その後上と同じ
    // など。最終状態abababab...abababになるまで文字を減らせる。
    // 最初の文字と最後の文字が違うときは最終状態の長さは偶数、
    // 初期状態の長さが奇数なら奇数回、偶数なら偶数回減らせるかのどちらかしかない。
    // 最初と最後が違うときは逆

    if(s[0] == s[n-1]) {
        if(n & 1) cout << "Second";
        else cout << "First";
        cout << endl;
    } else {
        if(n & 1) cout << "First";
        else cout << "Second";
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define pb push_back
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define ll long long
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=a;i>b;i--)
#define mkp(a,b) make_pair(a,b)
#define all(v) v.begin(),v.end()
#define max3(a,b,c) max(a,(max(b,c))
#define min3(a,b,c) min(a,(min(b,c))
#define read(a) cin>>a
#define readt(a,b) read(a),read(b)
using namespace std;
bool compare(pair<int,int>& p1,pair<int,int>& p2)
{
    return p1.second<p2.second;
}
int main()
{
    fastio
    int n,x,t;
    cin>>n>>x>>t;
    int timeis=(n*t)/x;
    timeis=ceil((double)timeis/t)*t;
    cout<<timeis;
}

Measured memory_bytes: 3668
module M = Map.Make (struct type t = int let compare = compare end)

let () =
    let main () =
        let n, m = Scanf.sscanf (read_line ()) "%d %d" (fun n m -> n, m) in
        let arr = Array.init m (fun _ -> Scanf.sscanf (read_line ()) "%d %d %d" (fun x y _ -> x, y)) in
        let map =
            Array.fold_left (fun map (x, y) ->
                let map = M.add x (y :: try M.find x map with _ -> []) map in
                          M.add y (x :: try M.find y map with _ -> []) map) M.empty arr
        in
        let vertex = Array.make n 0 in

        let rec dfs cur group =
            if vertex.(cur - 1) = 0 then (
                vertex.(cur - 1) <- group;
                List.iter (fun x -> dfs x group) (try M.find cur map with _ -> [])
            )
        in

        let rec loop i group =
            if i > n then group - 1 else
                if vertex.(i - 1) > 0 then loop (i + 1) group else
                (dfs i group; loop (i + 1) (group + 1))
        in
        let ans = loop 1 1 in
        Printf.printf "%d\n" ans
    in
    main ()

Measured memory_bytes: 34304
import java.util.Scanner;
import java.util.InputMismatchException;

public class Main{
	public static void main(String[] args){
		try{
			Scanner scanner = new Scanner(System.in);
			String input = scanner.nextLine();
			
			String deleteMaru = input.replace("o", "");
			int maruNum = input.length() - deleteMaru.length();
			int finishedGames = input.length();
			
			if(15 - finishedGames + maruNum >= 8){
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
			
		} catch(IndexOutOfBoundsException e){
			e.printStackTrace();
		} catch(NumberFormatException e){
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 20948
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> Pi;
typedef long long ll;
#define pii Pi
#define pll PL
#define Fi first
#define Se second
#define pb(x) push_back(x)
//#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> pll;
typedef long double ldouble;
typedef pair<double, double> pdd;

const double PI = acos(-1);
const double EPS = 1e-9;

const int MX = 105;
const int MM = 1000000007;

int T[MX][MX][MX];
int D[MX];

int my_abs(int x){ return x < 0? -x : x; }

int main()
{
	int N;
	scanf("%d", &N);
	for(int i = 1; i <= N*2-1; i++) scanf("%d", D+i);
	sort(D+1, D+N*2);
	T[1][1][1] = 1;
	for(int i = 1; i < N; i++){
		int lt = D[N-i+1] != D[N-i];
		int rt = D[N+i-1] != D[N+i];

		for(int j = 1; j <= 2*i-1; j++){
			for(int k = 1; k <= j; k++){
				for(int l = 1; l <= k+lt; l++){
					int nxt = j+lt+rt - max(0, k+lt - l - 1);
					T[i+1][nxt][l] = (T[i+1][nxt][l] + T[i][j][k]) % MM;
				}
				for(int l = k+lt+1; l <= j+lt+rt; l++){
					int nxt = j+lt+rt - max(0, l - (k+lt) - 1);
					T[i+1][nxt][k+lt+1] = (T[i+1][nxt][k+lt+1] + T[i][j][k]) % MM;
				}
			}
		}
	}
	int ans = 0;
	for(int i = 1; i < MX; i++){
		for(int j = 1; j < MX; j++){
			ans = (ans + T[N][i][j]) % MM;
		}
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define F first
#define S second
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;


vector<int> g1[202020];
vector<int> g2[202020];
int p2[202020][20];
int d2[202020];

int up2(int x, int k){
	for (int i=19;i>=0;i--){
		if (k&(1<<i)){
			x=p2[x][i];
		}
	}
	return x;
}

void dfs02(int x, int p){
	p2[x][0]=p;
	for (int i=1;i<20;i++){
		p2[x][i]=p2[p2[x][i-1]][i-1];
	}
	for (int nx:g2[x]){
		if (nx!=p) {
			d2[nx]=d2[x]+1;
			dfs02(nx, x);
		}
	}
}

int lca2(int a, int b){
	if (d2[a]<d2[b]) swap(a, b);
	a=up2(a, d2[a]-d2[b]);
	if (a==b) return a;
	for (int i=19;i>=0;i--){
		if (p2[a][i]!=p2[b][i]){
			a=p2[a][i];
			b=p2[b][i];
		}
	}
	return p2[a][0];
}

int dist2(int a, int b){
	if (a==0||b==0) return 1e6;
	return d2[a]+d2[b]-2*d2[lca2(a, b)];
}

int v=2;

void dfs(int x, int p, int y, int t){
	v=max(v, t-1+2*dist2(y, x));
	for (int nx:g1[x]){
		if (nx!=p){
			if (dist2(nx, y)==0) continue;
			if (dist2(nx, y)==1){
				v=max(v, t+1);
			}
			else{
				if (dist2(x, nx)>2){
					cout<<-1<<endl;
					exit(0);
				}
				int dd=dist2(y, nx);
				int ny;
				if (up2(nx, dd)==y) ny=up2(nx, dd-1);
				else ny=up2(y, 1);
				dfs(nx, x, ny, t+2);
			}
		}
	}
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,x,y;
	cin>>n>>x>>y;
	for (int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		g1[a].push_back(b);
		g1[b].push_back(a);
	}
	for (int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		g2[a].push_back(b);
		g2[b].push_back(a);
	}
	dfs02(x, 0);
	dfs(x, 0, y, 1);
	cout<<v<<endl;
}

Measured memory_bytes: 48256
#include <stdio.h>

int main(){
    int x;
    scanf("%d", &x);
    int f00 = x / 500;
    int ans = f00 * 1000;
    x -= f00 * 500;

    int f = x / 5;
    ans += f * 5;
    
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
N, M = list(map(int, input().split()))
N_i = [1 for i in range(N)]
H = list(map(int, input().split()))


for i in range(M):
    #print("i+1=",i+1)
    A, B = map(int, input().split())
    if H[A-1] > H[B-1]:
        #print('Atakai')
        N_i[B-1] = 0
    elif H[A-1] < H[B-1]:
        #print('B')
        N_i[A-1] = 0
    else:
        N_i[A-1] = 0
        N_i[B-1] = 0



print(N_i.count(1))
#print(N_i)

Measured memory_bytes: 85100
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<vector>
#define inf 2147483647
#define rep(i,a,b) for(int i=a;i<b;i++)
#define  rr read()
#define ll long long
#define repb(i,a,b) for(int i=a;i<=b;i++)
#define CloseIo   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
int read()
{
    char ch = getchar();
	int x = 0, f = 1;
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while('0' <= ch && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    return x * f;
}
int main()
{
  int n=rr,m=rr;
  if(n>=6&&n<=12)
   printf("%d\n",m/2);
   else if(n<6)
   printf("0\n");
   else
   printf("%d\n",m);
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll INF=999999999999999;
ll cost[501][10002];
int main(){
    ll m,n,a,b,ans=0,now=0,sum=0;
    vector<ll> p;
    vector<ll> c;
    vector<ll> e;
    cin>>m>>n;

    for(int i=0;i<m;i++){
        cin>>a;
        p.push_back(a);
    }

    for(int i=0;i<n;i++){
        cin>>a>>b;
        c.push_back(a);
        e.push_back(b);
    }

    sort(p.rbegin(),p.rend());

    for(int j=0;j<n+1;j++){
    for(int i=0;i<10002;i++){
        cost[j][i]=INF;
    }
    }
      cost[0][0]=0;
    for(int i=1;i<n+1;i++){
        for(int j=0;j<c[i-1];j++){
            cost[i][j]=cost[i-1][j];
        }
        for(int j=c[i-1];j<10001;j++){
            cost[i][j]=min(cost[i-1][j],cost[i-1][j-c[i-1]]+e[i-1]);
        }
        for(int j=10001-c[i-1];j<10002;j++){
        cost[i][10001]=min({cost[i][10001],cost[i-1][10001],cost[i-1][j]+e[i-1]});
            
    }
    }
  



    for(int i=10001;i>0;i--){
        cost[n][i-1]=min(cost[n][i],cost[n][i-1]);
    }
  
    for(int i=0;i<m+1;i++){
        now=sum-cost[n][i];
        if(now>ans)ans=now;
      if(i!=m)sum+=p[i];
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 42384
#include <stdio.h>

int isPrime(int x)
{
	int i;
	if(x < 2) return 0;
	else if(x == 2) return 1;
	if(x%2 == 0) return 0;
	for(i=3; i*i<=x; i+=2){
		if(x%i == 0) return 0;
	}
	return 1;
}


int main(void)
{
	int n;
	scanf("%d", &n);
	
	int  x, j, count=0;
	for(j=0; j<n; j++){
		scanf("%d", &x);
		if(isPrime(x))
		{
			count++;
		}
	}
	printf("%d\n", count);
	
	return 0;
}


Measured memory_bytes: 2092
#include<iostream>
#include<set>
using namespace std;
int main()
{
  int n,x,y,max;
  set< pair<int,int> >point;
  set< pair<int,int> >::iterator it1,it2;
  while(cin>>n,n){
    point.clear();
    while(n-->0){
      cin>>x>>y;
      point.insert(make_pair(x,y));
    }
    max=0;
    for(it1=point.begin();it1!=point.end();it1++){
      for(it2=it1;it2!=point.end();it2++){
	x=it1->first-it2->first;
	y=it1->second-it2->second;
	if((max<x*x+y*y)
	   && point.count(make_pair(it1->first-y,it1->second+x))
	   && point.count(make_pair(it2->first-y,it2->second+x)))
	  max=x*x+y*y;
      }
    }
	cout<<max<<endl;
  }
}

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

int main() {
    char str[105];
	scanf("%s",str);
	int n=strlen(str);
	int ans=0;
	for(int i=0;i<n/2;i++){
		if(str[i]==str[n-i-1])continue;
		else ans++;
	}
	printf("%d",ans);
}

Measured memory_bytes: 256
# coding:utf-8

import sys
import heapq
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n = II()
M = [LI() for _ in range(n)]
for a in zip(* M):
    start = set(a)
    break
M.sort()
# print(start)

ans = 0
index = 0
hq = []
for i in range(31):
    if i + 1 in start:
        while i + 1 in start and M[index][0] == i + 1:
            heapq.heappush(hq, M[index][1])
            index += 1
            if index >= n:
                break

    while hq and hq[0] < i + 1:
        if hq:
            tmp = heapq.heappop(hq)
        else:
            break

    if hq:
        ans += 100
        tmp = heapq.heappop(hq)
    else:
        ans += 50

    # print(i+1, ans, hq)

print(ans)



Measured memory_bytes: 5680
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
	double ax,ay,bx,by,cx,cy,dx,dy,ex,ey,fx,fy; 
	while(cin >>ax >> ay >> bx >> by >> cx >> cy >> dx >> dy) {
		ex=ax-bx; ey=ay-by; fx=cx-dx; fy=cy-dy;
		if (ex*fx+ey*fy==0) cout << "YES" << endl; else cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 1216
n = int(input())
d = list(map(int, input().split()))
p = {}
for i in d:
  if i not in p:
    p[i] = 1
  else:
    p[i] += 1
m = int(input())
t = list(map(int, input().split()))
for i in t:
  if i not in p or p[i] == 0:
    print('NO')
    break
  else:
    p[i] -= 1
else:
  print('YES')


Measured memory_bytes: 47700
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const ll INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A, ll x = 10){cout << fixed << setprecision(x) << A << endl;}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){return x / gcd(x, y) * y;};

//コンビネーション
const int MAXcomb = 2000010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

void solve(){
  COMinit();
  ll X, Y;
  cin >> X >> Y;
  if((X+Y)%3){
    cout << 0 << endl;
    return;
  }
  ll turn = (X+Y)/3;
  if(turn > X || turn > Y){
    cout << 0 << endl;
    return;
  }
  cout << comb(X+Y-turn-turn, X-turn) << endl;

}

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


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

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
const int maxn=1e6+10;
const int mod=998244353;

int a[15][maxn];
int main()
{
    int n,m,k;
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1; i<=n; i++)
        for(int j=1; j<=m; j++)
            scanf("%1d",&a[i][j]);
    int ans=1e9;
    for(int i=0; i<1<<(n-1); i++)
    {
        vector<int>R;
        int now=0;
        R.pb(0);
        for(int j=1; j<n; j++)
            if(i&1<<j-1)
                R.pb(j);
        R.pb(n);
        now+=R.size()-2;
        vector<int>cnt(R.size()-1,0);
        int isok;
        for(int j=1; j<=m; j++)
        {
            isok=1;
            vector<int>cnt1(R.size()-1,0);
            for(int s=0; s<R.size()-1; s++)
            {
                for(int l=R[s]+1; l<=R[s+1]; l++)
                    if(a[l][j]&1)
                        cnt1[s]++;
                if(cnt1[s]>k)
                {
                    isok=-1;
                    break;
                }
                else if(cnt1[s]+cnt[s]>k)
                        isok=0;
            }
            if(isok==-1)
                break;
            else if(isok==1)
                for(int l=0; l<R.size()-1; l++)
                    cnt[l]+=cnt1[l];
            else
                now++,cnt=cnt1;
        }
        if(isok!=-1)
            ans=min(ans,now);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 20736
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define LINF 3e18+7
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const double PI = acos(-1.0);
const double EPS = 1e-10;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    map<string,int> mp;
    string sub1 = "",sub2 = "";
    int ans = 1;
    sub2 = S[0];
    for(int i=1;i<S.size();i++){
        sub1 += S[i];
        if(sub1 != sub2){
            sub2 = sub1;
            sub1 = "";
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
int main(){
int r, g, b, ans = 0;
cin>>r>>g>>b;

ans = (r * 100) + (g * 10)+ b;

if(ans % 4 == 0){
    cout<<"YES"<<endl;
}else{
    cout<<"NO"<<endl;
}

return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,a[200010],sta[200010],l[200010],r[200010];
long long ans=0;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	  scanf("%d",&a[i]);
	int top=0;
	for (int i=1;i<=n;i++) {
		while (top>0&&a[i]<a[sta[top]]) r[sta[top]]=i,top--;
		sta[++top]=i;
	}
	while (top) r[sta[top]]=n+1,top--;
	top=0;
	for (int i=n;i;i--) {
		while (top>0&&a[i]<a[sta[top]]) l[sta[top]]=i,top--;
		sta[++top]=i;
	}
	while (top) l[sta[top]]=0,top--;
	for (int i=1;i<=n;i++) {
		int ll=l[i]+1,rr=r[i]-1;
		ans+=1LL*a[i]*(i-ll+1)*(rr-i+1);
	}
	cout<<ans;
	return 0;
}

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

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

    int N;
    cin>>N;
    for(int i=1;i<10;i++){
        if(N%i==0){
            if(N/i<=9){
                cout<<"Yes"<<"\n";

                return 0;
            }
        }


    }
    cout<<"No"<<"\n";
    return 0;

}

Measured memory_bytes: 256
n = int(input())
a_inputs = list(map(int,input().split()))

min_num=float('inf')
minus_num=0

reverse_sum=0
for i in range(n):
    a = a_inputs[i]
    if a<0:
        minus_num+=1
        reverse_sum-=a
    else:
        reverse_sum+=a
    if min_num>abs(a):
        min_num=abs(a)
if minus_num%2==0:
    print(reverse_sum)
else:
    print(reverse_sum-2*min_num)

    


Measured memory_bytes: 14332
#include <bits/stdc++.h>
using namespace std;
int main() {
	int64_t n, a, b;
	cin >> n >> a >> b;
	int64_t ans = 0;
	int64_t set = n / (a + b);
	int64_t mod = n % (a + b);
	ans += a * set;
	if (mod >= a)ans += a;
	else ans += mod;
	cout << ans << endl;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "4", "WWRR" ].solve == 2 );
	assert( [ "2", "RR" ].solve == 0 );
	assert( [ "8", "WRWWRWRR" ].solve == 3 );
}



import std.conv;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	input.popFront;
	auto cs = input.front.to!( dchar[] );
	
	auto ans = 0L;
	auto l = 0L;
	auto r = cs.length.signed - 1;
	while( l < r )
	{
		while( l < r && cs[ l ] == 'R' ) l++;
		while( l < r && cs[ r ] == 'W' ) r--;
		if( l < r )
		{
			ans++;
			l++;
			r--;
		}
	}
	return ans;
}


Measured memory_bytes: 4200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  int n, k;
  cin >> n >> k;
  if (k > (n-1)*(n-2)/2) {
    puts("-1");
  } else {
    int cnt = (n-1)*(n-2)/2-k;
    cout << n-1 + cnt << endl;
    rep(i, n-1) {
      cout << "1 " << i+2 << endl;
    }
    for (int i = 2; i < n; i++) {
      for (int j = i+1; j <= n; j++) {
        if (cnt == 0) return 0;
        cout << i << " " << j << endl;
        cnt--;
      }
    }
  }
}


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

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for(int i=0; i<N; i++){
    cin >> A.at(i);
  }
  int left = 0;
  int right = 1e9;
  while(right-left>1){
    int x = (left+right)/2;
    int num = 0;
    for(int i=0; i<N; i++){
      num += A.at(i)/x - (A.at(i)%x==0);
    }
    if(num<=K){
      right = x;
    }else{
      left = x;
    }
  }
  cout << right;
  return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<string> S(N);
    for (int i = 0; i < N; ++i) cin >> S[i];
    
    set<string> T;
    for (int i = 0; i < N; ++i) T.insert(S[i]);
    if (T.size() == 3) cout << "Three" << endl;
    else cout << "Four" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		int n, m, l;
		long x, sum;
		int[][] matA, matB;
		String[] mats = in.readLine().split(" ");
		n = Integer.parseInt(mats[0]);
		m = Integer.parseInt(mats[1]);
		l = Integer.parseInt(mats[2]);
		matA = new int[n][m];
		matB = new int[m][l];
		for (int i = 0; i < n; i += 1) {
			String[] arrayA = in.readLine().split(" ");
			for (int j = 0; j < m; j += 1) {
				matA[i][j] = Integer.parseInt(arrayA[j]);
			}
		}
		for (int p = 0; p < m; p += 1) {
			String[] arrayB = in.readLine().split(" ");
			for (int q = 0; q < l; q += 1) {
				matB[p][q] = Integer.parseInt(arrayB[q]);
			}
		}
		in = null;
		for (int s = 0; s < n; s += 1) {
			x = 0;
			for (int t = 0; t < l; t += 1) {
				sum = 0;
				for (int u = 0; u < m; u += 1) {
					x = (matA[s][u] * matB[u][t]);
					sum += x;
				}
				sb.append(sum);
				if (t != (l - 1)) {
					sb.append(" ");
				}
			}
			sb.append(System.getProperty("line.separator"));
		}
		System.out.print(sb);
	}
}

Measured memory_bytes: 27108
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<pair<ll,ll> > vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
const int INF=1e9+7;

int main(){
  int n;cin>>n;
  cout<<n/3<<endl;
}


Measured memory_bytes: 256
x,y,z=[int(i) for i in input().split()]
tag_list=input().split()

tag_set=set(tag_list)

obj_list=[]
for i in range(0,x+1):
    obj_list.append(str(i))

result=[]

obj_set=set(obj_list[z+1:])
a=list(obj_set & tag_set)
result.append(len(a))

obj_set=set(obj_list[:z+1])
a=list(obj_set & tag_set)

result.append(len(a))

print(min(result))

Measured memory_bytes: 3064
#include<cstdio>
#include<memory.h>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<tuple>
#include<set>
#include<utility>
#include<map>
using namespace std;
typedef long long ll;
ll A[100004]; int N;
int main() {
	int i, j; ll total;
	cin >> N;
	for (i = 1; i <= N; i++) cin >> A[i];
	total = abs(A[1]);
	for (i = 2; i <= N; i++) {
		total += abs(A[i] - A[i - 1]);
	}
	total += abs(A[N]);

	ll a;
	a = total - abs(A[1]) - abs(A[2] - A[1]);
	a += abs(A[2]);
	cout << a << endl;
	for (i = 2; i < N; i++) {
		a = total - abs(A[i - 1] - A[i]) - abs(A[i] - A[i + 1]);
		a += abs(A[i + 1] - A[i - 1]);
		cout << a << endl;
	}
	a = total - abs(A[N - 1] - A[N]) - abs(A[N]);
	a += abs(A[N - 1]);
	cout << a << endl;
}

Measured memory_bytes: 2048
# -*- coding: utf-8 -*-
# モジュールのインポート
import math
import itertools


def get_input() -> int:
    """
    標準入力を取得する.

    Returns:\n
        int: 標準入力
    """
    N = int(input())

    return N

# メイン処理


def g(x: int, y: int, z: int) -> int:
    """
    関数.

    Args:\n
        x (int): 整数（1 <= x）
        y (int): 整数（1 <= y）
        z (int): 整数（1 <= z）

    Returns:\n
        int: 関数値
    """
    return x**2 + y**2 + z**2 + x*y + y*z + z*x


def main(N: int) -> None:
    """
    メイン処理.

    Args:\n
        N (int): 整数
    """
    # 求解処理
    l = [0 for n in range(N)]
    ub = int(math.sqrt(N))
    for x, y, z in itertools.product(range(1, ub + 1), repeat=3):
        v = g(x, y, z)
        if v <= N:
            l[v - 1] += 1

    # 結果出力
    for ans in l:
        print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    N = get_input()

    # メイン処理
    main(N)


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

int main() 
{
    int n, d, x;
    cin >> n >> d >> x;
    int sum=0;
    for (int i=0; i<n; i++)
    {
        int a;
        cin >> a;
        int j=0;
        int res=1;
        while (res<=d)
        {
            sum++;
            j++;
            res=j*a+1;
        }
    }
    cout << sum+x;
    return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<bool>> edges(N, vector<bool>(N, false));
  for (int i{}; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    edges[a][b] = edges[b][a] = true;
  }

  vector<int> route(N);
  iota(route.begin(), route.end(), 0);
  int ans{};
  do {
    if (route[0] != 0)
      continue;
    bool ok{true};
    for (int i{}; i < N - 1; ++i) {
      if (!edges[route[i]][route[i + 1]]) {
        ok = false;
        break;
      }
    }
    if (ok)
      ++ans;
  } while (next_permutation(route.begin(), route.end()));

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


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>

using namespace std;

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<double, int> d_i;
typedef pair<ll, int> ll_i;


/*
  let's try computer shogi!!!
 */

int main(){
  ll N,M;
  vector<ll> ts;
  vector<ll> ms;
  cin>>N;
  for(int i=0;i<N;++i){
    ll t;
    cin >> t;
    ts.push_back(t);
  }

  cin>>M;
  for(int i=0;i<M;++i){
    ll t;
    cin >> t;
    ms.push_back(t);
  }

  sort(ts.begin(),ts.end());
  sort(ms.begin(),ms.end());
  ll mcnt = 0;
  
  for(int i=0;i<N;++i){
    if(ts[i]==ms[mcnt]){
      mcnt++;
    }
  }
  if(mcnt == ms.size()){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 4848
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repp(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;

signed main(){
    int n, m;
    cin >> n >> m;
    int x, y;
    vector<int> f(n, 0), d(n, 1);
    f[0] = 1;
    rep(i, 0, m){
        cin >> x >> y;
        x--; y--;
        if(f[x]){
            f[y] = 1;
            if(d[x] == 1) f[x] = 0;
        }
        d[x]--;
        d[y]++;
    }
    int ans = 0;
    rep(i, 0, n) if(f[i]) ans++;
    cout << ans << endl;
}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  string s; cin >> s;
  if(s == "AAA" || s == "BBB") {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }

}


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

int main () {

    int N, H;
    scanf("%d %d", &N, &H);

    int a[N], b[N], max_a = INT_MIN;
    for (int i = 0; i < N; i++) {
        scanf("%d %d", &a[i], &b[i]);
        max_a = max(max_a, a[i]);
    }

    sort(b, b + N, greater<int>());

    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (b[i] < max_a) break;
        if (H <= 0) break;

        ans++;
        H -= b[i];
    }
    ans += max(0, (H + (max_a - 1)) / max_a);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define drep(i,cc,n) for(int i=(cc);i<=(n);++i)
#define rep(i,n) drep(i,0,n-1)
#define drrep(i,cc,n) for(int i=(cc);i>=(n);--i)
#define rrep(i,n) drrep(i,0,n-1)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,v.size())if(i==0)cout << v[i];else cout << " " << v[i]; cout << endl;
#define arrprint(v,n) rep(i,n)if(i==0)cout << v[i];else cout << " " << v[i]; cout << endl;
#define matprint(v,n,m) rep(i,n){rep(j,m){cout << v[i][j] << " ";}cout << endl;}
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
using ll = long long;
using P = pair<int,int>;
template<typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; //小さいものから取り出す

const int TL = 1970;
const double T0=2e3;
const double T1=6e2;

int d;
vector<int> c(26);
vector<vector<int>> s;
vector<int> t, now;
vector<int> last(26, -1);
ll best = 0;

ll score(){
    ll res = 0;
    rep(i,26)last[i] = -1;
    rep(i,d){
        res += s[i][t[i]];
        last[t[i]] = i;
        rep(j,26) res -= c[j] * (i - last[j]);
    }
    return res;
}

double prob(double delta, double temp){
    if(delta >= 0) return 1;
    return exp(delta/temp);
}

int main(){
    auto start = std::chrono::system_clock::now();      // 計測スタート時刻を保存
    random_device seed;
    mt19937_64 mt(seed());
    uniform_int_distribution<int> rnd1(0,25);
    uniform_int_distribution<int> rnd3(1,16);
    uniform_int_distribution<int> rnd4(0,1);
    uniform_real_distribution<double> rnd5(0,1);

    cin >> d;
    uniform_int_distribution<int> rnd2(0,d-1);

    rep(i,26) cin >> c[i];
    s.resize(d);
    rep(i,d)s[i].resize(26);
    rep(i,d)rep(j,26) cin >> s[i][j];
    t.resize(d);
    rep(i,d)t[i] = rnd1(mt);
    best = score();
    // vecprint(t);
    double T = T0;
    while(true){
        auto end = std::chrono::system_clock::now();       // 計測終了時刻を保存
        auto dur = end - start;        // 要した時間を計算
        auto msec = std::chrono::duration_cast<std::chrono::milliseconds>(dur).count();
        if(msec>=TL) break;
        T = pow(T0, 1-(double)msec/TL) * pow(T1, (double)msec/TL);

        if(rnd4(mt) == 0){
            int day = rnd2(mt);
            int con = rnd1(mt);
            int old = t[day];
            t[day] = con;
            ll now_s = score();
            if(rnd5(mt) < prob(now_s - best, T)) best = now_s;
            else t[day] = old;
        }else{
            int day1 = rnd2(mt);
            int day2 = day1 + rnd3(mt);
            if(day2 >= d)continue;
            swap(t[day1], t[day2]);

            ll now_s = score();
            if(rnd5(mt) < prob(now_s - best, T)) best = now_s;
            else swap(t[day1], t[day2]);
        }
    }

    // cout << score() << endl;
    rep(i,d)cout << t[i]+1 << endl;

    return 0;
}

Measured memory_bytes: 4292
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAX_N=100005;
LL a[MAX_N],n,k;
int main()
{
	cin>>n>>k;
	for(int i=0;i<n;i++)cin>>a[i];
	LL x=0;
	for(int i=62;i>=0;i--)
	{
		LL cnt=0;
		for(int j=0;j<n;j++)cnt+=(bool)(a[j]&(1LL<<i));
		if(2*cnt<n && (x|(1LL<<i))<=k)x|=1LL<<i;
	}
	LL res=0;
	for(int i=0;i<n;i++)res+=x^a[i];
	cout<<res<<endl;
}

Measured memory_bytes: 1024
n = int(input())
cou = 0
ans = False
for i in range(n):
	da, db = map(int, input().split())
	if da == db:
		cou += 1
	else:
		cou = 0
	if cou == 3:
		ans = True

if ans:
	print('Yes')
else:
	print('No')

Measured memory_bytes: 9080
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		
		if (a < b) {
			System.out.println("a < b");
		} else if (a > b) {
			System.out.println("a > b");
		} else {
			System.out.println("a == b");
		}

	}

}



Measured memory_bytes: 26384
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <stdio.h>
using namespace std;

//typedefリスト
typedef vector<int> vint;
typedef vector<string> vstr;

int main(void) {
	long long int K, A, B,ans,times;
	times=0;
	ans = 0;
	cin >> K >> A >> B;
	if (A >= K)cout << 1 + K << endl;
	else if (B - A <= 2)cout << 1 + K << endl;
	else {
	    times=K-(A+1);
		if (times%2 == 0) {
			ans = B + (B - A)*(times / 2);
		}
		else {
			ans = B + (B - A)*(times/ 2) + 1;
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>


using namespace std;

long long n, a, b, sol, ost;

int main(){
    cin >> n >> a >> b;
    
    sol = n - (n % (a + b));
    sol /= (a + b);
    sol *= a;
    
    ost = (n % (a + b));
    
    if(ost > a) ost = a;
    
    sol += ost;
    cout << sol;


	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include<map>
#include<vector>
#include<algorithm>
#include <stdio.h>
#include<set>
#include<string>
#include<math.h>
#include<cmath>
#include<iomanip>
#include<queue>
#include<stack>
#define ll long long
using namespace std;
long double pi = 3.14159265358979323846;
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);


int main() {
	string s;  cin >> s;
	
	int n = s.size();

	bool b = 1;
	for (int i =0; i < n; i++)
		if (s[i] != s[n - i - 1])
			b = 0;
	if (!b)
		cout << "No";
	else
		if (s[0] == s[n - 1] && s[n / 2 - 1] == s[(n + 3) / 2 - 1] && s[n / 2 - 1] == s[n - 1])
			cout << "Yes";
		else
			cout << "No";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

ll mod = 1000000007;
ll modsize;

ll modinv(ll a) {
	ll b = mod, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= mod;
	if (u < 0) u += mod;
	return u;
}

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

int dp[5010][5010];

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int n;
	string s;
	cin >> n >> s;
	int k = s.size();
	dp[0][0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= i; j++) {
			if (j == 0) {
				dp[i][j] = dp[i - 1][j] + dp[i - 1][j + 1];
				dp[i][j] %= mod;
			}
			else {
				dp[i][j] = dp[i - 1][j - 1] * 2 + dp[i - 1][j + 1];
				dp[i][j] %= mod;
			}
		}
	}
	cout << dp[n][k] * modinv(modpow(2, k)) % mod << endl;
}

Measured memory_bytes: 194176
//AtCoder ABC110 A - Maximize the Formula
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

int main() {
    vector<ll> t(3);
    cin>>t[0]>>t[1]>>t[2];
    sort(t.begin(),t.end());
    ll ans=t[2]*10+t[1]+t[0];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val n = in.readLine().toInt
    val as = in.readLine().split("\\s+").map(_.toInt)

    val map = Array.ofDim[Int](n + 1)
    for (a <- as) {
      map(a) += 1
    }

    val cns = Array.ofDim[Long](n + 1)
    val dcns = Array.ofDim[Long](n + 1)
    for (i <- as.indices) {
      val c = map(i + 1)
      cns(i + 1) = if (c > 1) {
        1L * c * (c - 1) / 2
      } else {
        0
      }
      dcns(i + 1) = if (c > 2) {
        1L * (c - 1) * (c - 2) / 2
      } else {
        0
      }
    }

    val sumOfCns = cns.foldLeft(BigInt(0)) {
      case (acc, cn) => acc + cn
    }

    for (a <- as) {
      out.println(sumOfCns - cns(a) + dcns(a))
    }

    out.flush()
  }
}


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

#define MAX 100000
typedef long long llong;

int n, k;
llong T[MAX];

int check(llong P){
    int i = 0;
    for(int j = 0; j < k; j++){
        llong s = 0;
        while(s + T[i] <= P){
            s += T[i];
            i++;
            if(i == n){
                return n;
            }
        }
    }
    return i;
}

int solve(){
    llong left = 0;
    llong right = 100000 * 10000;
    llong mid;
    while(right - left > 1){
        mid = (left + right) / 2;
        int v = check(mid);
        if(v >= n){
            right = mid;
        }else{
            left = mid;
        }
    }
    return right;
}

int main(){
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        cin >> T[i];

    }
            llong ans = solve();
        cout << ans << endl;
}


Measured memory_bytes: 3884
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	int H; int W;
	while(~scanf("%d%d", &H, &W)) {
		vector<string> a(H);
		rep(i, H) {
			char buf[501];
			scanf("%s", buf);
			a[i] = buf;
		}
		vector<string> ans1 = a, ans2 = a;
		rep(j, W) {
			ans1[0][j] = '#';
			ans2[H - 1][j] = '#';
			rer(i, 1, H - 2)
				(j % 2 == 0 ? ans1 : ans2)[i][j] = '#';
		}
		rep(i, H)
			puts(ans1[i].c_str());
		puts("");
		rep(i, H)
			puts(ans2[i].c_str());
	}
	return 0;
}


Measured memory_bytes: 1536
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;

#define lli long long int

vector<lli> *g;

void DFS(lli dp[],bool vis[],lli s)
{
	vis[s]=true;
	//dp[s]=k;
	for(lli i=0;i<g[s].size();i++)
	{
		if(!vis[g[s][i]])
		DFS(dp,vis,g[s][i]);
		dp[s]=max(dp[s],1+dp[g[s][i]]);
	}
}

int main()
{
	lli n,m;
	cin>>n>>m;
	g=new vector<lli>[n+1];
	for(lli i=0;i<m;i++)
	{
		lli x,y;
		cin>>x>>y;
		g[x].push_back(y);
	}
	lli dp[n+1];
	bool vis[n+1];
	memset(dp,0,sizeof(dp));
	memset(vis,false,sizeof(vis));
	for(lli i=1;i<=n;i++)
	{
		if(!vis[i])
		{
			DFS(dp,vis,i);
		}
	}
	cout<<*max_element(dp,dp+n+1)<<endl;
	//cout<<dp[5]<<endl;
	return 0;
}


Measured memory_bytes: 9344
#include <bits/stdc++.h>
using namespace std;
const int n = 1e5+5;
int N;

bool v(int a){
	return a >=1 && a <= 12;
}

int main(){
	cin >> N;
	int a = N /100;
	int b = N % 100;
	if(v(a) && v(b)){
		cout << "AMBIGUOUS" << endl;
	}else if(v(a)){
		cout << "MMYY" << endl;
	}else if(v(b)){
		cout << "YYMM" << endl;
	}else{
		cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(long long i=0;i<n;++i)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
using namespace std;
const int INF=1<<30;
int n,graph[101][101],v[101];
void bfs(int s){
    queue< int > q;
    fill(v,v+101,INF);
    q.push(s);
    v[s]=0;
    while(!q.empty()){
        int p=q.front();q.pop();
        FOR(i,1,n+1){
            if(!graph[p][i]) continue;
            if(v[i]==INF){
                v[i]=v[p]+1;
                q.push(i);
            }
        }
    }
    FOR(i,1,n+1){
        printf("%d ",i);
        printf("%d\n",v[i]!=INF?v[i]:-1);
    }
}
int main(){
    int u,k,e;
    scanf("%d",&n);
    REP(i,n){
        scanf("%d%d",&u,&k);
        REP(j,k){
            scanf("%d",&e);
            graph[u][e]=1;
        }
    }
    bfs(1);
    return 0;
}




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

using namespace std;

int l[2000];

int f;

int s;

void swap(int &a, int &b) {
	int t;
	t = a;
	a = b;
	b = t;
}

int find (int a, int b) {
	int c;
	while (a < b) {
		c = ((a + b + 1) / 2);
		if (l[c] < s) {
			a = c;
		}
		else {
			b = c - 1;
		}
	}
	return a;
}

int main() {
	int n, m;
	int ans = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> l[i];
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n - i - 1; j++) {
			if (l[j] > l[j + 1]) {
				swap(l[j], l[j + 1]);
			}
		}
	}
	for (int i = 0; i < n - 2; i++) {
		for (int j = i + 1; j < n - 1; j++) {
			s = l[i] + l[j];
			f = find(j + 1, n - 1);
//			cout << f << ' ';
			if (f == j + 1 && l[f] >= s) {
			}
			else {
				ans += (f - j);
			}
		}
	}
	cout << ans;
	return 0;
}

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

int main(){
	int n,k;
  	cin>>n>>k;
  int arr[n];
  for(int i=0;i<n;i++){
   cin>>arr[i]; 
  }
  int dp[n];
  dp[0]=0;
  for(int i=1;(i<=k)&&(i<n);i++){
   int x=INT_MAX;
    for(int j=i-1;j>=0;j--){
     int y=dp[j] + abs(arr[i] - arr[j]);
      if(y<x){
        x=y;
      }
    }
    dp[i]=x;
  }
  for(int i=k+1;i<n;i++){
    int M= INT_MAX;
    for(int j=i-1;j>=i-k;j--){
      int y=dp[j] + abs(arr[i] - arr[j]);
      if(y<M){
        M=y;
      }
      dp[i]=M;
    }
  }
  cout<<dp[n-1];
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
          using namespace std;
          #define tani_nachi_ke  ios_base::sync_with_stdio(false); cin.tie(NULL);
          #define M_PI 3.14159265358979323846
          #define data data_
          #define ff first
          #define ss second
          #define pb push_back
          #define ll long long
          #define ld long double

          int main()
          {
               tani_nachi_ke  

               long long a,b;
               cin >> a >> b;
               if(a == b)
               {
                    for(int i = 0; i < a; i++)
                         cout << b;
                    cout << endl;
               }
               else if(b > a)
               {
                    for(int i = 0; i < b; i++)
                         cout << a;
                    cout << endl;
               }
               else
               {
                    for(int i = 0; i < a; i++)
                         cout << b;
                    cout << endl;
               }
               





         
               return 0;
          }

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

int n,m,r,x,y,z,ans=0x3f3f3f3f;
int dis[210][210];
int ri[10];bool b[10];

inline void dfs(int dep,int lst,int now)
{
	if(dep==r){
		ans=min(ans,now);
	}
	for(int i=1;i<=r;i++){
		if(b[i]==0){
			b[i]=1;
			dfs(dep+1,i,now+dis[ri[lst]][ri[i]]);
			b[i]=0;
		}
	}
}

int main()
{
	memset(dis,1,sizeof(dis));
	scanf("%d %d %d",&n,&m,&r);
	for(int i=1;i<=r;i++){
		scanf("%d",&ri[i]);
	}
	for(int i=1;i<=m;i++){
		scanf("%d %d %d",&x,&y,&z);
		dis[x][y]=min(dis[x][y],z);
		dis[y][x]=min(dis[y][x],z);
	}
	for(int k=1;k<=n;k++){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
			}
		}
	}
	for(int i=1;i<=r;i++){
		b[i]=1;
		dfs(1,i,0);
		b[i]=0;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<climits>
using namespace std;
vector<long> p;
vector<long> c;

int main(){
    long n,k;
    cin >> n >> k;

    p.resize(n);
    c.resize(n);
    for(int i = 0;i < n;i++){
        cin >> p[i];
        p[i]--;
    }
    for(int i = 0;i < n;i++){
        cin >> c[i];
    }
    long ans = LONG_MIN;

    vector<long> round(n);//何回回れば元の位置に戻るか
    for(int i = 0;i < n;i++){
        long cycle = 0;
        long sum = 0;
        int v = i;
        //i始まりで何回回れば1周できるかと1周回った際の合計
        while(true){
            cycle++;
            sum += c[v];
            v = p[v];
            if(v == i){
                break;
            }
        }
        long path = 0;
        long cnt = 0;

        while(true){
            cnt++;
            path += c[v];

            if(cnt > k)break;
            long num = (k - cnt) / cycle;
            long score = path + max(0l,sum) * num;
            ans = max(ans,score);
            v = p[v];
            if(v == i)break;
        }

        
    }
    cout << ans << endl;
    


    return 0;
}

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

using namespace std;

int n, k, m;

int main() {
	while (cin >> n >> k >> m, n) {
		vector<int> v;
		for (int i = 0; i < n; i++) v.push_back(i + 1);
		
		int p = m - 1;
		v.erase(v.begin() + p);
		
		while ((int)v.size() > 1) {
			int size = (int)v.size();
			p = (p + k - 1) % size;
			v.erase(v.begin() + p);
		}
		
		cout << (*v.begin()) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1324
#include <stdio.h>
#include <cstdio>
#include <string>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>


std::string str;

long long int N[30] = { 0 };
char Alphabet[26] = {
	'a', 'b', 'c', 'd',
	'e', 'f', 'g', 'h',
	'i', 'j', 'k', 'l',
	'm', 'n', 'o', 'p',
	'q', 'r', 's', 't',
	'u', 'v', 'w', 'x',
	'y', 'z'
};

int main()
{
	long long int ans = 0;
	std::cin >> str;

	for (int a = 0; a < str.length(); ++a)
	{
		for (int b = 0; b < 26; ++b)
		{
			if (str[a] == Alphabet[b])
			{
				N[b]++;
				break;
			}
		}
	}


	ans = (str.length() * (long long int)(str.length() - 1)) / 2LL + 1;

	for (int a = 0; a < 26; ++a)
	{
		ans -= (N[a] * (N[a] - 1)) / 2LL;
	}

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

	return 0;
}

Measured memory_bytes: 640