akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
typedef pair<long long , long long> P;
typedef long long ll;
typedef long long lint;
#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)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
signed main(){
    ll L, R; cin>>L>>R;
    ll res = INF;
    if(R-L+1>=2019) res = 0;
    else{
        for(ll i=L; i<=R; i++){
            for(ll j=i+1; j<=R; j++){
                res = min(res, (i*j)%2019);
            }
        }
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;

int main(){
    int N; cin >> N;
    vector<int> B(N+1), C(N);

    B[0] = 1000000;
    B[N] = 1000000;

    for (int i=1; i<N; i++){
        cin >> B[i];
        C[i-1] = min(B[i-1], B[i]);
    }

//    C[0] = min(B[0], B[1]);
    C[N-1] = min(B[N-1], B[N]);

    int total = accumulate(C.begin(), C.end(), 0);
    cout << total;


}

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

	int A, B, C;
	cin >> A >> B >> C;

	int gdk = A + B;

	if (gdk >= C - 1)cout << B + C << endl;
	else cout << B + gdk + 1 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <stdlib.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#define SIZE 1001
#define gcode __gcd
#define bitcoin __builtin_popcount
#define check(n, pos) (n & (1<<pos))
#define set(n, pos) (n | (1<<pos))
using namespace std;

vector<int>ini;
vector<int>pb;
vector<int>name;
vector<int>life;
vector<char>who;
vector<char>love;
set<int>kshe;
set<int>namenai;
map<int,int>mp;
vector<pair<int,int> >mk;

int main(){
//	freopen("input","r",stdin);
	int a;
	scanf("%d",&a);
	int s[1001];
	for(int i=0;i<a;i++){
		scanf("%d",&s[i]);
	}
	vector<long> vec(s,s+a);
	sort(vec.begin(),vec.end());
	vec.erase(unique(vec.begin(),vec.end()),vec.end());
	printf("%ld\n",vec.size());
	//cerr<<"time elapsed:"<<clock()*1000.0/CLOCKS_PER_SEC<<"ms"<<"\n";
	return 0;
}

Measured memory_bytes: 256
n = int(input())
s = [input() for i in range(n)]
m = int(input())
t = [input() for i in range(m)]
candi = [0]
for i in s:
    tmp = 0
    for j in s:
        if i == j:
            tmp += 1
    for j in t:
        if i ==j:
            tmp -= 1
    candi.append(tmp)
print(max(candi))


Measured memory_bytes: 3060
N, X, Y = map(int, input().split())
res = [0]*(N-1)
for l in range(1, N):
    for r in range(l+1, N+1):
        i = min(r-l, abs(l-X)+abs(r-Y)+1)
        res[i-1] += 1
for r in res:
    print(r)

Measured memory_bytes: 3444
S = input()
SA  = S.replace('?','a')
T = input()

def test(i):
    #一文字目から初めてハマるかどうか確認
    S_sub = S[i:i+len(T)]
    for s,t in zip(S_sub,T):
        if s == '?':
            continue
        if s != t:
            return False
    return True

pw = []
for i in range(len(S)-len(T)+1):
    if test(i):
        x = SA[:i] + T + SA[i+len(T):]
        pw.append(x)
if pw:
    answer = sorted(pw)[0]
else:
    answer = 'UNRESTORABLE'
print(answer)


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);
    static int num = sc.nextInt();
    static int k = sc.nextInt();
    static int[] h = new int[num];
    static int[] dp = new int[num];
    public static void main(String[] args) {
        for (int i = 0; i < num; i++){
            h[i] = sc.nextInt();
            dp[i] = 2147483647;
        }
        dp[0] = 0;
        dp[1] = Math.abs(h[1] - h[0]);
        for (int i = 1; i < num; i++){
            for (int j = 1; j <= k && i - j >= 0; j++){
                chmin(dp[i],dp[i - j] + Math.abs(h[i] - h[i - j]), i);
//                if (dp[i] > dp[i - j] + Math.abs(h[i] - h[i - j]))
//                    dp[i] = dp[i - j] + Math.abs(h[i] - h[i - j]);
            }
        }
        System.out.println(dp[num - 1]);
    }
    public static void chmin(int a, int b, int i){
        if (a > b)
            dp[i] = b;
    }
}


Measured memory_bytes: 50676
using System;
		namespace Sample
		{
		  class Sample
		  {
		      static void Main()
		      {
		       string str = Console.ReadLine();
		       string[] arr =  str.Split(' ');
		       int x = int.Parse(arr[0]);
		       int y = int.Parse(arr[1]);
		       Console.WriteLine("{0}", (x*y)-(x+y-1));
		      }
		  }
		}


Measured memory_bytes: 13140
in1 = input().split()
in1num = [int(x) for x in in1]
a = input().split()
anum = [int(x) for x in a]
sum_a = sum(anum)
anum.sort(reverse=True)

N = in1num[0]
M = in1num[1]

#print(sum_a)
#print((sum_a)/(4*M))
#print(anum[M-1])

if anum[M-1] >= (sum_a)/(4*M):
  print("Yes")
else:
  print("No")

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

using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int max = 0;
    int res = 0;
    if(max < a){
        max = a;
    }
    if(max < b){
        max = b;
    }
    if(max < c){
        max = c;
    }
    res = 3 * max - a - b -c;
    if(res % 2 == 1){
        res += 3; 
    } 
    cout << res/2 << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, A: "List[int]"):
    d = [[a > 0, abs(a)] for i, a in enumerate(A)]
    d.sort(key=lambda x: x[1], reverse=True)
    AA = [dv[1] if dv[0] else -dv[1] for dv in d]
    # print(AA)
    s = 0
    for i in range(N-1):
        if AA[i] < 0:
            AA[i] *= -1
            AA[i+1] *= -1
        s += AA[i]
    # print(AA)
    print(s+AA[-1])
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()


Measured memory_bytes: 33292
import javax.swing.*;
import java.io.*;
import java.util.*;

import static java.lang.Math.*;

public class Main {


    public static void main(String[] args) {
        try (CustomReader in = new CustomReader()) {
            new Main().execute(in);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    public void execute(CustomReader in) throws IOException {
        final int N = in.readLineAsInt();
        int[] A = in.readLineAsIntArray();
        for (int i = 1; i <= N; i++) {
            A[i - 1] -= i;
        }
        Arrays.sort(A);
        int k = N / 2;
        int b = (N % 2 == 0) ? (A[k - 1] + A[k]) / 2 : A[k];
        long sad = 0L;
        for (int i = 0; i < N; i++) {
            sad += Math.abs(A[i] - b);
        }
        System.out.println(sad);
    }


    static class CustomReader extends BufferedReader {
        public CustomReader() throws IOException {
            super(new InputStreamReader(System.in));
        }

        public int readLineAsInt() throws IOException {
            return Integer.parseInt(readLine());
        }

        public int[] readLineAsIntArray() throws IOException {
            String[] strArray = this.readLine().split(" ");
            int[] intArray = new int[strArray.length];
            for (int i = 0, n = strArray.length; i < n; i++) {
                intArray[i] = Integer.parseInt(strArray[i]);
            }
            return intArray;
        }

        public int[][] readAsIntMatrix(int rows, int columns) throws IOException {
            int[][] matrix = new int[rows][columns];
            for (int i = 0; i < rows; i++) {
                String[] r = this.readLine().split(" ");
                for (int j = 0; j < columns; j++) {
                    matrix[i][j] = Integer.parseInt(r[j]);
                }
            }
            return matrix;
        }

        public char[][] readAsCharMatrix(int rows) throws IOException {
            char[][] matrix = new char[rows][];
            for (int i = 0; i < rows; i++) {
                matrix[i] = this.readLine().toCharArray();
            }
            return matrix;
        }

    }

}

Measured memory_bytes: 46364
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<string.h>
#include<math.h>
#include<ctype.h>

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

typedef long long ll;

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

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int asc(const void* a, const void* b) { return *(int*)a - *(int*)b; }

ll dsc(const void* a, const void* b) { return *(ll*)b - *(ll*)a; }

bool used[100];
ll perm[100];

void permutation(int pos, int n) {
    if (pos == n) return;
    for (int i = 0; i < n; ++i) {
        if (!used[i]) {
            perm[pos] = i;
            used[i] = true;
            permutation(pos + 1, n);
            used[i] = false;
        }
    }
}

int main() {
    ll n, l[100];
    scanf("%lld", &n);
    for (int i = 0; i < n; i++) {
        scanf("%lld", &l[i]);
    }
    qsort(l, n, sizeof(ll), asc);
    ll ans = 0;
    for (int i = 0; i < n-2; i++) {
        for (int j = i + 1; j < n-1; j++) {
            for (int k = j + 1; k < n; k++) {
                if (l[i] == l[j] || l[j] ==l[k] || l[k] == l[i]) continue;
                if (l[i] + l[j] > l[k] && l[k] > l[j] - l[i]) ans++;
            }
        }
    }
    printf("%lld", ans);

    return 0;
}

Measured memory_bytes: 2132
// AOJ 2502: VOCAL ANDROID
// 2017.10.13 bal4u@uu

#include <stdio.h>
#include <string.h>

#define MAX(a,b) ((a)>=(b)?(a):(b))

int s[400], l[400], p[400], w[400];
int dp[400];

int main()
{
	int n, m, i, j, k;

	scanf("%d", &n);
	for (i = 0; i < n; i++) scanf("%d%d%d", s+i, l+i, p+i);
	scanf("%d", &m);
	for (i = 0; i < m; i++) scanf("%d", w+i);

	memset(dp, -1, sizeof(dp));
	dp[0] = 0;
	for (i = 1; i <=393; i++) for (j = 0; j < n; j++)
		for (k = s[j]; k <= l[j]; k++)
			if (i >= k) dp[i] = MAX(dp[i], dp[i-k]+p[j]);
  
	for (i = 0; i < m; i++) if (dp[w[i]] < 0) { puts("-1"); return 0; }
    for (i = 0; i < m; i++) printf("%d\n", dp[w[i]]);
	return 0;
}

Measured memory_bytes: 1832
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
// #include <bits/stdc++.h> all

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

int main(void){
  int k,x; cin >> k >> x;
  int edge=1000000;

  if(x-k+1 < -1*edge){
    for(int i = x; i < x+k-1; i++){
      cout << i << ' ';
    }
    cout << x-k-1;
  } else if(x+k-1 > edge){
    for(int i = x-k+1; i < x; i++){
      cout << i << ' ';
    }
    cout << x;
  } else {
    for(int i = x-k+1; i < x+k-1; i++){
      cout << i << ' ';
    }
    cout << x+k-1;
  }
  
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

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

int main() {
	int N;
	cin>>N;
	std::map<ll, ll> map;
	rep(i,N){
		int a;
		cin>>a;
		if(a % 2 == 1){
			map[1]++;
		}
		else{
			if(a % 4 == 0){
				map[4]++;
			}else{
				map[2]++;
			}
		}
	}
	string ans = "Yes";
	if(N % 2== 0){
		if(map[1]>map[4]){
			ans = "No";
		}
	}else{
		if(map[1] == (N+1)/2){
			if(map[4]<map[1]-1){
				ans = "No";
			}
		}
		else if(map[1]<(N+1)/2){
			if(map[4]<map[1]){
				ans = "No";
			}
		}
		else{
			ans = "No";
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
l, r = map(int, input().split())
ans = 4070306
if l <= 2019 <= r:
    ans = 0
else:
    for i in range(l, min(r, l+2019)+1):
        for j in range(i+1, min(r, i+2019)+1):
            ans = min(ans, (i*j)%2019)
print(ans)

Measured memory_bytes: 65372
#include <cstdio>
#include <cstring>

#define MAX_N 100001
#define INF (0x7fffffff)

/* -----------------------------------------------------------------------------
	型とクラス定義
----------------------------------------------------------------------------- */

/* -----------------------------------------------------------------------------
	大域データ
----------------------------------------------------------------------------- */

int N;					// 数列のサイズ
int M;					// 上限
int A[MAX_N];			// 数列

int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a % b);
}

int lcm(int a, int b) {
	long long c;

	if(a == INF || b == INF) return INF;
	c = a;
	c = c * b / gcd(a, b);
	if(c > M) return INF;
	else return c;
}

int exp2(int n) {
	return n % 2 == 1 ? 0 : 1 + exp2(n/2);
}

int main () {

	int pow2 = 1, L;

	// 長さの読込み
	scanf("%d %d", &N, &M);

	// 配列の読込み
	for(int i = 0; i < N; i++) scanf("%d", A + i);

	// 各要素の2のべきが等しいか．そうでなければ答えは0
	for(int i = 1; i < N; i++) {
		if(exp2(A[i]) != exp2(A[0])) {
			printf("0\n");
			return 0;
		}
	}

	// 各要素の2のべきが等しい場合
	L = A[0]/2;
	for(int i = 1; i < N; i++) L = lcm(L, A[i]/2);

	if(L == INF) printf("0\n"); 
	else printf("%d\n", (M/L+1)/2);

	return 0;
}

Measured memory_bytes: 512
import logging
import math

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

def main():
    N = int(input())
    L_2 = [list(map(int, input().split())) for _ in range(N)]
    logging.info("Hello!")

    logging.info(L_2)

    sum = 0
    for i in range(N):
        for j in range(i + 1, N):
           sum += math.sqrt((L_2[i][0] - L_2[j][0]) ** 2 + (L_2[i][1] - L_2[j][1]) ** 2)

    print('{:.10f}'.format(sum * 2 / N))
    
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 4704
#include<bits/stdc++.h>
using namespace std;
int main()
{
   ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
   int n,m;
   cin>>n>>m;
   int a[n+1]={};
   bool z[n+1]={},flag=true;
   a[1]=1;
   if(n==1)
   {
       a[1]=0;
   }
   for(int i=0;i<m;i++)
   {
       int s,c;
       cin>>s>>c;
       if(z[s]==0)
       {
           z[s]=1;
           a[s]=c;
       }
       else if(c!=a[s])
       {
           flag=false;
           break;
       }
   }
   if(flag==false)
   {
       cout<<"-1";
   }
   else
   {
       if(n==1)
       {
           cout<<a[1];
       }
       else if(a[1]==0)
       {
           cout<<"-1";
       }
       else
       {
           for(int i=1;i<=n;i++)
           {
               cout<<a[i];
           }
       }
   }
   return 0;
}    

Measured memory_bytes: 380
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main()
{
    string s;
    cin >> s;
    if (s.length() < 4)
        cout << "No" << endl;
    else
    {
        if (s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I')
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import numpy as np
n, d = map(int, input().split())
xy = [list(map(int, input().split())) for i in range(n)]
#y = [map(int, input().split())[1] for j in range(n)]
#print(xy[0])
count = 0
for i in xy:
  x = i[0]
  y = i[1]
  #print(x, y)
  if np.sqrt(x*x + y*y) <= d:
    #print(d, np.sqrt(x^2 + y^2))
    count+=1
print(count)

Measured memory_bytes: 63336
#if 1
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;

#define LOADVECTOR(type,name,N) std::vector<type>name(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
	cin >> name[nnn]; \
}

#define LOAD(type,name) type name; \
cin >> name;

int main() {
	ios::sync_with_stdio(false);
	LOAD(i32, A);
	LOAD(i32, B);
	LOAD(i32, C);
	int res = B / A;
	cout << std::min({ C,res });
	return 0;
}
#endif


Measured memory_bytes: 256
#include <stdio.h>
int min(int a, int b){return a > b ? b : a;}
int ans = 0;
int chk[202];
int node;
int d[202][202];//最初のhは縦方向，次のwは横方向
int dfs(int a, int f){
    int i, j;
    chk[a] = 0;
    for(i = node-1; i >= 0; i--){
        if(chk[i] != -1 || d[a][i] == 0){
            continue;
        }
        if(i == node-1){
            int flow = min(f, d[a][i]);
            ans += flow;
            d[i][a] += flow;
            d[a][i] -= flow;
            return flow;
        }
        int tmp = dfs(i, min(f, d[a][i]));
        if(tmp != 0){
            d[i][a] += tmp;
            d[a][i] -= tmp;
            return tmp;
        }
    }
    return 0;
}
int main(void){
    int i, j, k;
    int h, w;
    int a[100][100];
    char tmp[100];
    int s_x, s_y, t_x, t_y;
    scanf("%d%d", &h, &w);
    for(i = 0; i < h; i++){
        scanf("%s", tmp);
        for(j = 0; j < w; j++){
            switch(tmp[j]){
            case '.':
                a[i][j] = 0;
                break;
            case 'o':
                a[i][j] = 1;
                break;
            case 'S':
                a[i][j] = 2;
                s_x = i;
                s_y = j;
                break;
            case 'T':
                a[i][j] = 3;
                t_x = i;
                t_y = j;
                break;
            default:
                printf("error!\n");
            }
        }
    }
    if(s_x == t_x || s_y == t_y){
        printf("-1\n");
        return 0;
    }
    node = h + w + 2;//0はs，1~hは縦，h+1~h+wは横，h+w+1はt
    
    for(i = 0; i < node; i++){
        for(j = 0; j < node; j++){
            d[i][j] = 0;
        }
    }
    //縦方向
    d[0][s_x+1] = 100000;//sをセット
    d[0][s_y+h+1] = 100000;
    d[t_x+1][node-1] = 100000;//tをセット
    d[t_y+h+1][node-1] = 100000;
    for(i = 0; i < h; i++){
        for(j = 0; j < w; j++){
            if(a[i][j] != 0){
                d[i+1][h+1+j] = 1;
                d[h+1+j][i+1] = 1;
            }
        }
    }

    // for(i = 0; i < node; i++){
    //     for(j = 0; j < node; j++){
    //         printf("%4d ", d[i][j]);
    //     }
    //     printf("\n");
    // }

    while(1){
        for(i = 0; i < node; i++){
            chk[i] = -1;
        }
        int ans_before = ans;
        dfs(0, 1000000000);
        if(ans == ans_before){
            break;
        }
    }

    printf("%d\n", ans);
    return 0;
    
}

Measured memory_bytes: 1900
N = int(input())
S = input()

ans = 0
str_list = list(S)

for i in range (len(str_list)-2):
  if(str_list[i] == "A"):
    if(str_list[i+1] == "B"):
      if(str_list[i+2] == "C"):
        ans += 1

print(ans)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 9223372036854775806ll;
const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
/*メモ 
*/
int main(){
    ll n;
    std::cin >> n;
    std::vector<ll> s(32);
    s[0]=1;
    rrep(i,1,32){
        s[i]=s[i-1]*-2ll;
    }
    
    if(n==0){
        std::cout << 0 << std::endl;
        exit(0);
    }
    string ans;
    rep(i,32){
        //std::cout << n << std::endl;
        if(n==0)break;
        if(abs(n)%abs(s[i]*2)!=0){
           // std::cout << s[i] << std::endl;
            ans.pb('1');
            n-=s[i];
        }
        else{
            ans.pb('0');
            
        }
        
    }
    reverse(all(ans));
    std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
 int n,k=0;
 cin>>n;
 string s;
 cin>>s;
 for(int i=0;i<n;i++)
 {
     if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
     {
        k++;
     }
 }
 cout<<k<<endl;

    return 0;

}


Measured memory_bytes: 3604
#include <stdio.h>
 
int main() {
	int x, a, b;
	scanf("%d %d %d\n",&x,&a,&b);
	
	if (b <= a) printf("delicious\n");
	else if (b <= a + x) printf("safe\n");
	else printf("dangerous\n");
	
	return 0;
}

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

def main():
    n, m = map(int, input().split())

    if n >= 2 and m >= 2:
        cards = n * m - (n * 2 + (m - 2) * 2)
        print(cards)
    elif n == 1 and m >= 2:
        print(m - 2)
    elif n >= 2 and m == 1:
        print(n - 2)
    else:
        print('1')
    

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

ll dp[100005];

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

    int n, m;
    cin >> n >> m;

    vector <bool> broken(n+1, false);
    for (int i = 0; i < m; i++) {
        int a;
        cin >> a;
        broken[a] = true;
    }

    dp[0] = 1;
    for (int i = 1; i <= n; i++) {
        if (broken[i]) continue;

        if (i == 1) {
            dp[i] = dp[i-1];
        }
        else {
            dp[i] = (dp[i-1] + dp[i-2]) % MOD;
        }
    }

    cout << dp[n] << "\n";
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
typedef long long ll;
const int MAXN = 52;
const int MOD = 2019;
int qpow(int base, int exp){
	int res = 1;
	while(exp>0){
		if(exp&1)res = res*base%MOD;
		base = base*base%MOD;
		exp>>=1;
	}
	return res;
}
string S;
int N, tmp, psa[2019], cnt;
int main(){
	cin.tie(0);
	cin.sync_with_stdio(0);
	cin >> S; N = S.size();
	int cur = 1, pre = 0;
	for(int i = N-1;i>=0;i--){
		int digit = S[i]-'0';
		tmp=tmp+digit*qpow(10, N-i-1)%MOD;
		tmp%=MOD;
		if(tmp==0)cnt++;
		cnt+=psa[tmp]; psa[tmp]++;
	}
	cout << cnt << nl;
	return 0;
}


Measured memory_bytes: 3756
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
long long int gcd(long long int a,long long int b)
{
    while(a % b != 0)
    {
        long long int r = a % b;
        a = b;
        b = r;
    }
    return b;
}
int main()
{
    long long int n,m;
    cin >> n >> m;
    long long int a[n];
    for(int i = 0;i < n;i++)
    {
        cin >> a[i];
    }
    int count[n] = {};
    for(int i = 0;i < n;i++)
    {
        int x = a[i];
        while(x % 2 == 0)
        {
            x /= 2;
            count[i]++;
        }
    }
    bool flag = true;
    sort(count,count + n);
    for(int i = 0;i + 1 < n;i++)
    {
        if(count[i] != count[i + 1])
        {
            flag = false;
            break;
        }
    }
    if(!flag)
    {
        cout << "0\n";
        return 0;
    }
    if(n == 1)
    {
        cout << m / (a[0] / 2) - m / a[0] << "\n";
        return 0;
    }
    long long int LCM = a[0] * a[1] / gcd(a[0],a[1]);
    for(int i = 2;i < n;i++)
    {
        LCM = LCM * a[i] / gcd(LCM,a[i]);
    }
    cout << m / (LCM / 2) - m / LCM << "\n";

    return 0;
}

Measured memory_bytes: 1408
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections

def judge(li):
    algo = [0]*(m)
    cost = 0
    for i in range(len(li)):
        if li[i] == False:
            continue
        cost += C[i]
        for j in range(len(A[i])):
            algo[j] += A[i][j]
    for i in range(len(algo)):
        if algo[i]<x:
            return False
    return cost
n,m,x = map(int,input().split())
C = []
A = []
for i in range(n):
    d = list(map(int,input().split()))
    C.append(d[0])
    b = []
    for j in range(1,len(d)):
        b.append(d[j])
    A.append(b)
ans = 10000000000000
for i in range(2**n):
    li = [False]*n
    for j in range(n):
        if (i>>j)&1:
            li[n-j-1] = True
    a = judge(li)
    if a != False:
        ans = min(ans,a)
if ans == 10000000000000:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9488
#include <iostream>
#include <cstring>
#include <cstdio>

#define Maxn 200010

using namespace std;

inline int read() {
    int x = 0, f = 1;
    char c = getchar();
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while('0' <= c && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * f;
}

int n, f[Maxn], val[Maxn], low[Maxn];

struct Edge {
    int next, to;
}
edge[Maxn * 2];
int head[Maxn], edge_num = 1;

void add_edge(int from, int to) {
    edge[++edge_num].next = head[from];
    edge[edge_num].to = to;
    head[from] = edge_num;
}

pair <int, int> update(int l, int r, int v) {
    while(l < r) {
        int mid = (l + r) >> 1;
        if(low[mid] < v) l = mid + 1;
        else r = mid;
    }
    int temp = low[l];
    low[l] = v;
    return make_pair(l, temp);
}

void dfs(int u, int fa, int len) {
    bool flag; pair <int, int> info;
    // cout << "before:" << u << " " << len << " " << low[len] << endl;
    if(val[u] > low[len]) low[++len] = val[u], flag = 1;
    else info = update(0, len, val[u]), flag = 0;
    f[u] = len;
    // cout << "after:" << u << " " << len << " " << low[len] << " " << low[1] << " " << modpos << endl;
    for(int i = head[u]; i; i = edge[i].next) {
        int v = edge[i].to;
        if(v == fa) continue;
        dfs(v, u, len);
    }
    if(flag) low[len] = 0;
    else low[info.first] = info.second;
}

int main() {
    n = read();
    for(int i = 1; i <= n; ++i) val[i] = read();
    int u, v;
    for(int i = 1; i < n; ++i) {
        u = read(); v = read();
        add_edge(u, v);
        add_edge(v, u);
    }
    dfs(1, 0, 0);
    for(int i = 1; i <= n; ++i) printf("%d\n", f[i]);
    return 0;
}

Measured memory_bytes: 26484
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstddef>
#include<queue>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
    int n, t, a, ans = -1;
    cin >> n >> t >> a;
    vector<int> h(n);
    for(int i = 0; i < n; ++i) cin >> h.at(i);
    double cand, anst = 5000.0;
    for(int i = 0; i < n; ++i){
        cand = t - h.at(i) * 0.006;
        if(abs(anst - a) > abs(cand - a)){
            anst = cand;
            ans = i;
        }
    }
    cout << ans + 1 << endl;
    return 0;
}

Measured memory_bytes: 3592
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,K=map(int,input().split())
    A=tuple(map(int1,input().split()))
    used=[False]*N
    v=0
    while True:
        if used[v]==True:
            loopstart=v
            break
        else:
            used[v]=True
        v=A[v]
    v=0
    d0=-1
    for i in range(10**7):
        if v==loopstart and d0==-1:
            d0=i
        elif v==loopstart and d0!=-1:
            d1=i-d0
            break
        v=A[v]
    K-=d0
    if K>0:
        K-=K//d1*d1
    K+=d0
    v=0
    for _ in range(K):
        v=A[v]
    print(v+1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 91724
N = int(input())
arr = [int(i) for i in input().split()]
tot = sum(arr)
mem = [[0]* N for i in range(N)]
# updating bottom 2 rows
# mem[N-2][j] 
# mem[N-1][N-1]
if N == 1:
  print("%s" % arr[0])
else:
  mem[N-1][N-1] = arr[N-1]
  mem[N-2][N-2] = arr[N-2]
  mem[N-2][N-1] = max(arr[N-2], arr[N-2])

  # updating leftmost cols
  mem[0][0] = arr[0]
  mem[0][1] = max(arr[0], arr[1])
  mem[1][1] = arr[1]

  for i in range(N-3, -1, -1):
    for j in range(i, N):
      if i == 0 and j<=1 or i == 1 and j == 1:
        continue
      val1 = arr[i] + min(mem[i+1][j-1], mem[i+2][j])
      val2 = arr[j] + min(mem[i+1][j-1], mem[i][j-2])
      mem[i][j] = max(val1, val2)
  #print(mem)
  tmp = tot - mem[0][N-1]
  ans = mem[0][N-1] - tmp
  print("%s" % ans)


Measured memory_bytes: 118876
n,k = map(int,input().split())
V = list(map(int,input().split()))
rV = V[::-1]
m = min(n,k)
res = []
for i in range(m+1):
    for j in range(m-i+1):
        Q = []
        Q.extend(V[:i])
        Q.extend(rV[:j])
        if not Q:
            continue
        s = sum(Q)
        Q.sort()
        for p in range(min(len(Q),k-len(Q))):
            if Q[p] < 0:
                s -= Q[p]   
        res.append(s)
print(max(res))


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

int32_t main()
{
   int n,d;
   cin >> n >> d;
   int ans=0;
   for(int i=0; i<n; i++)
   { int x,y;
   cin >> x >> y;
   int a=(x*x) + (y*y);
   double res=sqrt(a);
   if(ceil(res)<=d)
   {ans++;
   }

   }
   cout << ans << endl;
}


Measured memory_bytes: 3676
N, K = gets.split.map(&:to_i)
arr = gets.split.map(&:to_i)
dp = Array.new(K + 1)
dp[0] = false
(1..K).each do |i|
  dp[i] = arr.any? do |j|
    next false if i - j < 0
    dp[i - j] == false
  end
end

if dp.last
  puts 'First'
else
  puts 'Second'
end

Measured memory_bytes: 2556
import java.util.*;
 
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[]a = new int[N];
        int sum = 0; 
        for(int i=0; i<N; i++) {
        	a[i] = sc.nextInt();
        	sum += a[i];
        }
        sc.close();
         
        double ave = (double)sum/N;
        double minGap = Math.abs(ave-a[0]);
        int minIndex = 0;
        for(int i=0; i<N; i++) {
        	if (minGap > Math.abs(ave-a[i])) {
        		minGap = Math.abs(ave-a[i]);
        		minIndex = i;
        	}
        } 
        System.out.println(minIndex);
    }
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
						
#define fast_cin() ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'
// #define int long long

const int K = 1e5 + 5, N = 105;

int dp[K][2];
int n, a[N], k;

int solve(int cur_stones, int cur_player) {
	int &ans = dp[cur_stones][cur_player];
	if (ans != -1) return ans;
	ans = cur_player ^ 1;
	for (int i = 1; i <= n; i++) {
		if (cur_stones - a[i] >= 0) {
			if ((solve(cur_stones - a[i], cur_player ^ 1) == cur_player)) {
				ans = cur_player;
			}
		}
	}
	return ans;
}
				
int32_t main() {
	fast_cin();  
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	memset(dp, -1, sizeof dp);
	int ans = solve(k, 0);
	if (ans == 0) {
		cout << "First";
	} else {
		cout << "Second";
	}
	cout << endl;
	// for (int cur_stones = 0; cur_stones <= k; cur_stones++) {
	// 	for (int cur_player = 0; cur_player < 2; cur_player++) {
	// 		int &ans = dp[cur_stones][cur_player];
	// 		ans = cur_player ^ 1;
	// 		bool ok = false;
	// 		for (int i = 1; i <= n; i++) {
	// 			if (cur_stones - a[i] >= 0) {
	// 				ok |= (dp[cur_stones - a[i]][cur_player ^ 1] == cur_player);
	// 			}
	// 		}
	// 		if (ok) ans = cur_player;
	// 	}
	// }
	// int ans = dp[k][0];
	// if (ans == 0) {
	// 	cout << "First";
	// } else {
	// 	cout << "Second";
	// }
	// for (int i = 0; i <= k; i++, cout << endl)
	// 	for (int j = 0; j < 2; j++)
	// 		cout << dp[i][j] << " ";
	return 0;
}

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

int main(){
    int n,k,a=0;
    cin>>n>>k;
    int h[n];
    for(int i=0;i<n;i++){
        cin>>h[i];
        if(h[i]>=k)
        a++;
    }
    cout<<a<<endl;
}

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const ll MOD=1e9+7;

template<typename T> bool chmax(T &a,const T b){if(a < b){a=b; return true;} return false;}
template<typename T> bool chmin(T &a,const T b){if(a > b){a=b; return true;} return false;}

int main(){
    int d, t, s;
    cin >> d >> t >> s;
    if(s*t >= d) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, C;  cin >> A >> B >> C;
  
  if (((A > C) && (C > B)) || ((A < C) && (C < B))) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
 
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using Tup = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<(v)<<"\n";
#define fl cout<<flush;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl '\n'
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld pi=3.141592653589793238;



signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> T(N+2,0);
    vector<ll> A(N+2,0);
    for(ll i=0;i<N;++i)cin>>T[i+1];
    for(ll i=0;i<N;++i)cin>>A[i+1];
    T[N+1]=T[N];
    A[0]=A[1];
    ll ans=1;
    //T[i]T[i+1]A[i+1]A[i+2]を比較
    for(ll i=0;i<N;++i){
        if(T[i]==T[i+1]){
            if(A[i+1]==A[i+2]){
                ans*=min(T[i+1],A[i+1]);
            }
            else{
                if(A[i+1]>T[i+1])ans*=0;
                else ans*=1;
            }
        }
        else{
            if(A[i+1]==A[i+2]){
                if(T[i+1]>A[i+1])ans*=0;
                else ans*=1;
            }
            else{
                if(T[i+1]==A[i+1])ans*=1;
                else ans*=0;
            }
        }
        ans%=MOD;
    }
    prt(ans)fl



    return 0;
}


Measured memory_bytes: 1792
# 入力値を受け取る
s = input()

# 入力値の3文字目を受け取る
a = s[2]

# 入力値の4文字目を受け取る
b = s[3]

# 入力値の3文字目と4文字目が同じでないなら'No'を表示する
if a != b:
    print('No')
    exit()
    
# 入力値の5文字目を受け取る
c = s[4]

# 入力値の6文字目を受け取る
d = s[5]

# 入力値の5文字目と6文字目が同じでないなら'No'を表示する
if c != d:
    print('No')
    exit()

# 上記以外なら'Yes'を表示する
print("Yes")

Measured memory_bytes: 3060
from collections import defaultdict

K = int(input())

d = [0]*(K+1)

r = 0
ten = 1
while 1:
    r = (r+ten*7)%K
    ten *= 10
    ten %= K
    if r == 0:
        print(sum(d)+1)
        break
    if d[r] != 0:
        print(-1)
        break
    elif d[r] == 0:
        d[r] = 1





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

int main(){
  int h, w;
  cin >> h >> w;
  
  vector<vector<char>> fig(h, vector<char>(w));
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cin >> fig.at(i).at(j);
    }
  }
  
  for(int i = 0; i < 2 * h; i++){
    for(int j = 0; j < w; j++){
      cout << fig.at(i/2).at(j);
    }
    cout << endl;
  }
}
    
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int64_t>A(N);
  for(int i=0;i<N;i++)
  cin>>A.at(i);
  int64_t a=0;int64_t b=0;
  for(int i=0;i<N;i++)
    if(a<abs(A.at(i))){a=abs(A.at(i)); b=i;}
  cout<<2*N-1<<endl;
  for(int i=0;i<N;i++)
    cout<<b+1<<" "<<i+1<<endl;
  if(0<=A.at(b)){
  for(int i=1;i<=N-1;i++)
    cout<<i<<" "<<i+1<<endl;
  }else{
  for(int i=N;2<=i;i--)
    cout<<i<<" "<<i-1<<endl;
  }
  return 0;
}

Measured memory_bytes: 3612
#!/usr/bin/env python3
import sys


def solve(N: int, S: str):
    ws = 0
    es = 0
    for s in S:
        ws += int(s == 'W')
        es += int(s == 'E')

    ce = 0
    cw = 0
    ret = N
    for s in S:
        ce += int(s == 'E')
        ret = min(ret, cw + (es - ce), )
        cw += int(s == 'W')
    print(ret)




# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()


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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

signed main() {
    ll N,ans=0;
    cin>>N;
    vector<ll> A(N),B(N);
    rep(i,0,N) cin>>A[i];
    rep(i,0,N) cin>>B[i];

    rep(k,0,32){
        auto a = A, b = B;
        rep(i,0,N) a[i] %= 1ll << (k+1);
        rep(i,0,N) b[i] %= 1ll << (k+1);
        sort(begin(b), end(b));

        ll T = 1ll << k, q=0;

        rep(i,0,N) {
            // ai + bj は高々4T
            // ai + bj が [T 2T) [3T 4T) の個数を数える
            auto it = lower_bound(begin(b),end(b),T-a[i]);
            auto jt = lower_bound(begin(b),end(b),2*T-a[i]);
            q += distance(it, jt);
            it = lower_bound(begin(b),end(b),3*T-a[i]);
            jt = lower_bound(begin(b),end(b),4*T-a[i]);
            q += distance(it, jt);
        }

        if (q%2==1){
            ans |= 1ll << k;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 7008
import sys
from collections import defaultdict
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
edge = [[] for _ in range(N + 1)]
for i in range(2, N + 1):
    a = int(input())
    edge[a].append(i)

child = defaultdict(list)


def DFS(s):
    if not edge[s]:
        return 0

    for t in edge[s]:
        child[s].append(DFS(t))

    child[s].sort(reverse=True)
    res = max(c + i for i, c in enumerate(child[s], start=1))
    return res


print(DFS(1))

Measured memory_bytes: 130144
#include<bits/stdc++.h>
using namespace std;
void fast(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
}

int main(){
	fast();	
	int h , n;
	cin >> h >> n;
	vector<int>a(n);
	int sum = 0;
	for(int i = 0; i < n; ++i){
		cin >> a[i];
		sum += a[i];
	}
	if(sum >= h){
		cout << "Yes\n";
	}
	else{
		cout << "No\n";
	}
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

class Solution {
public:
	/* time: O(1), space: O(1) */
	int password(int n) {
		return n * n * n;
	}
};

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

	Solution sol;
	int ans = sol.password(n);
	cout << ans << endl;
	return 0;
}


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

int main() {
  int A, B, maximum = 0, a = 0, b = 0, c = 0;
  cin >> A >> B;
  
  a = A + B;
  b = A - B;
  c = A * B;
  
  maximum = max(max(a, b), c);
  
  cout << maximum << endl;
}

Measured memory_bytes: 256
//Atcoder Grand Contest 003
//A-Wanna go back home 

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

//NとSのみだったらOK
//EとWのみだったらOK
//NEWS少なくとすべて一つずつあればOK

int main(void){
	string trip;
	int num_N,num_E,num_W,num_S;
	num_N=0;num_E=0;num_W=0;num_S=0;
	
	cin >> trip;

	for(int i=0;i<trip.size();++i){
		char c = trip[i];

		//for debug
		//cout << c << endl;

		switch(c){
			case 'N':
				++num_N;
				break;
			case 'E':
				++num_E;
				break;
			case 'W':
				++num_W;
				break;
			case 'S':
				++num_S;
				break;
			default:
			break;
			//NOP
		}
	}

	if((num_N!=0) && (num_S!=0) && (num_E==0) && (num_W==0)){
		cout << "Yes" << endl;
	}
	else if((num_N==0) && (num_S==0) && (num_E!=0) && (num_W!=0)){
		cout << "Yes" << endl;
	}
	else if((num_N!=0) && (num_S!=0) && (num_E!=0) && (num_W!=0)){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}

	return 0;	
}

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

int main(){
    long long n;
    cin>>n;
    long long a[5];
    long long m=1e18;
    for(int i=0;i<5;i++){
        cin>>a[i];
        m=min(a[i],m);
    }

    long long ans=0;

    ans+=5;

    if(n%m==0){
        cout<<ans+n/m-1;
        return 0;
    }

    cout<<ans+n/m;

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int N = 2000000 + 10;

int n,a[N],b[N];
int M(int x,int y,int z){
    if((x-y)*(x-z)<=0) return x;
    if((y-x)*(y-z)<=0) return y;
    return z;
}
int cac() {
    int dp[102][102];
    for(int i=1;i<=2*n-1;i++) dp[1][i]=a[i];
    for(int i=2;i<=n;i++){
        for(int j=i;j<=2*n-i;j++){
            dp[i][j] = M(dp[i-1][j],dp[i-1][j-1],dp[i-1][j+1]);
        }
    }
    printf("%d\n", dp[n][n]);
}
int chk(int x) {
    //printf("chk %d\n", x);
    for(int i=1;i<=2*n-1;i++) b[i]=a[i]<=x?0:1;
    int mid=n;
    int lb=mid-1,rb=mid+1;

    if(b[mid]==b[mid-1]) return b[mid]==0?1:0;
    if(b[mid]==b[mid+1]) return b[mid]==0?1:0; 
    
    while(lb>=2) {
        if(b[lb]!=b[lb+1] && b[lb]!=b[lb-1]) lb--;
        else break;
    }
    while(rb<2*n-1) {
        if(b[rb]!=b[rb-1] && b[rb]!=b[rb+1]) rb++;
        else break;
    }
    //printf("[%d, %d]\n", lb,rb);
    int R = min(mid-lb, rb-mid);
    if(lb==1 && rb==2*n-1) return (b[mid] ^ (R&1))==0?1:0;


    // [lb,mid,rb]

    if (mid-lb <= rb-mid) {
        int x1 = b[lb-1];    
        int x2 = b[mid] ^ (R&1);
        return x1 == 0 ? 1 : 0;
    } else {
        int x1 = b[rb+1];
        int x2 = b[mid] ^ (R&1);
        return x1 == 0 ? 1 : 0;
    }
}   

int main() {
    scanf("%d", &n);
    for(int i=1;i<=2*n-1;i++){
        scanf("%d",&a[i]);
        //a[i]=i;
    }
    //random_shuffle(a+1,a+1+n);
    int lef = 0, rig = n<<1|1;
    while(rig-lef>1) {
        int mid = (lef + rig) >> 1;
        if (chk(mid)) rig = mid;
        else lef = mid;
    }
    printf("%d\n", rig);
    //cac();
}





Measured memory_bytes: 5120
#include<iostream>
#include<cmath>
#include<string>
#include<fstream>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
    int n, m;
    cin>>n>>m;
    //vector <int> d;
    int ans;
    
    for(int i=m/2; i>=1; i--)
    {
        if(m%i==0 && m/i>=n)
        {
            ans=i;
            break;
        }
    }
    if(n==1) ans=m;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	int n,k; cin >> n >> k;
	vl a(n); rep(i,n) cin >> a[i];
	sort(all(a));
	int sum = 0;
	rep(i,k) sum += a[i];
	cout << sum << "\n";
}


Measured memory_bytes: 3632
#!/usr/bin/python3
# -*- coding: utf-8 -*-
def check(s):
    if dict_x[s[0]] == 0 and dict_x[s[1]] == 0:
        return "NOT"
    elif  dict_x[s[0]] > 0 and dict_x[s[1]] == 0:
        return s[1]
    elif  dict_x[s[0]] == 0 and dict_x[s[1]] > 0:
        return s[0]
    elif dict_x[s[0]] == 1 and dict_x[s[1]] == 1:
        return "EVEN"
    else:
        if dict_x[s[0]] > dict_x[s[1]]:
            return s[1]
        else:
            return s[0] 
def update(s, mozi):
    if s[1] == mozi:
        dict_x[s[0]] -= 1
        dict_x[s[1]] += 1
    else:
        dict_x[s[0]] += 1
        dict_x[s[1]] -= 1

n, a, b, c = map(int, input().split())
dict_x = {"A": a, "B": b, "C": c}
s_list = []
ans_list = []
flag = 1
for i in range(0, n):
    s = input()
    s_list.append(s)
if a + b + c == 0:
    flag = 0
elif a + b + c == 1:
    for s in s_list:
        x = check(s)
        if x == "NOT":
            flag = 0
            break
        else:
            ans_list.append(x)
            update(s, x)
elif a + b + c == 2:
    i = 0
    for s in s_list:
        x = check(s)
        if x == "NOT":
            flag = 0
            break
        elif x == "EVEN":
            if i == len(s_list) - 1:
                ans_list.append(s[0])
                update(s, x)
            elif s == s_list[i + 1]:
                ans_list.append(s[0])
                update(s, x)
            else:
                if s[0] in s_list[i + 1]:
                    ans_list.append(s[0])
                    update(s, s[0])
                else:
                    ans_list.append(s[1])
                    update(s, s[1])
        else:
            ans_list.append(x)
            update(s, x)
        i += 1
else:
    for s in s_list:
        x = check(s)
        if x == "NOT":
            flag = 0
            break
        elif x == "EVEN":
            ans_list.append(s[0])
            update(s, s[0])
        else:
            ans_list.append(x)
            update(s, x)

if flag == 1:
    print("Yes")
    for ans in ans_list:
        print(ans)
else:
    print("No")

Measured memory_bytes: 17124
N, T = map(int, raw_input().split())    
t = map(int, raw_input().split())   
ans = 0
cur = 0
for i in xrange(N - 1):
    if t[i + 1] - t[i] > T:
        ans += t[i] + T - cur
        cur = t[i + 1]
ans += t[N - 1] + T - cur
print ans



Measured memory_bytes: 20036