akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
const int MAXN = 100000;
char ret[20];
int Query(int ans){
    printf("%d\n", ans);
	fflush(stdout);
    scanf("%s", ret);
    if( ret[0] == 'V' ) return -1;
    return ret[0] == 'M' ? 1 : 0;
}
int guess[MAXN + 5];
int main() {
	int N;
	scanf("%d", &N);
	int p = Query(0);
	if( p == -1 )
		return 0;
	for(int i=0;i<N;i++)
		guess[i] = (i&1)^p;
	int le = 0, ri = N-1;
	while( true ) {
		int Mid = (le+ri) / 2;
		int res = Query(Mid);
		if( res == -1 )
			return 0;
		if( res == guess[Mid] )
			le = Mid+1;
		else ri = Mid-1;
	}
}

Measured memory_bytes: 1228
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_1_A&lang=ja
# union-find
# https://note.nkmk.me/python-union-find/


class UnionFind:
    def __init__(self, n):
        self.n = n
        # 各要素の親要素の番号を格納するリスト
        # 根がルートの時は、グループの要素数を格納　最初は全て根で要素数1
        self.parents = [-1] * n

    # 再帰 groupの根を返す
    # 経路圧縮あり
    def find(self, x):
        # 0より小さい場合は根
        if self.parents[x] < 0:
            # indexを返す
            return x
        else:
            # 根になるまで親を辿る
            # 経路圧縮 根のindexが全ての親に再帰的につく
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    # groupを併合
    def union(self, x, y):
        # 根を探す
        x = self.find(x)
        y = self.find(y)

        # 最初から統合されている
        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x
        # 根のグループ数を追加 xの方グループの要素数が多い前提なので多い方に寄せる
        self.parents[x] += self.parents[y]
        # 親(根)のindexを入れる
        self.parents[y] = x

    # xのgroupのサイズ
    def size(self, x):
        return - self.parents[self.find(x)]

    # 根が同じか判定
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # ルートが同じ要素を返す
    def members(self, x):
        root = self.find(x)
        # 根が同じ要素
        return [i for i, in range(self.n) if self.find(i) == root]

    # 全ての根の要素を返す
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    # グループの数を数える
    def group_count(self):
        return len(self.roots())

    # {root: [要素]}
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

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


n, q = map(int, input().split())

uft = UnionFind(n)

for _ in range(q):
    com, x, y = map(int, input().split())
    # unite
    if com == 0:
        uft.union(x, y)
    else:
        print('1' if uft.same(x, y) else '0')


Measured memory_bytes: 5736
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;
 
#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
int n;

int main() {
	cin >> n;
	int j,sum=0;
	rep(i,n){
		cin >> j;
		sum += j;
	}
	cout << sum - n << endl;
	return 0;
}


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

#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define sc(a) scahf("%c",&a);
#define ss(a) scanf("%s",a)
#define pi(a) printf("%d\n",a)
#define pl(a) printf("%lld\n",a)
#define pc(a) putchar(a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i, a, b) for(register int i=a;i<=b;++i)
#define repd(i, a, b) for(register int i=a;i>=b;--i)
#define reps(s) for(register int i=head[s];i;i=Next[i])
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define pii pair<int,int>
#define mii unordered_map<int,int>
#define msi unordered_map<string,int>
#define lowbit(x) ((x)&(-(x)))
#define ce(i, r) i==r?'\n':' '
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define INF 0x3f3f3f3f
#define pr(x) cout<<#x<<": "<<x<<endl
using namespace std;

inline int qr() {
    int f = 0, fu = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-')fu = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        f = (f << 3) + (f << 1) + c - 48;
        c = getchar();
    }
    return f * fu;
}

const int N = 105;
ll a[N];
int n;
int main(){
    n=qr();int cnt=0;
    repi(i,1,n)a[i]=qr();
    sort(a+1,a+1+n);
    repi(i,1,n-2)repi(j,i+1,n-1)repi(k,j+1,n)
    if(a[i]!=a[j]&&a[j]!=a[k]&&a[i]!=a[k]&&a[i]+a[j]>a[k])cnt++;
    pi(cnt);
    return 0;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
#define mp make_pair
#define endl "\n"
#define v vector
#define b begin()
#define e end()
using namespace std;
typedef long long ll;
typedef long l;
typedef long long unsigned ull;

int main(){

    /*int t;
    while(t--){

    }*/
    ll n;
    cin>>n;
    ll m = n/500;
    ll q = m*1000;
    n -= (m*500);
    ll p = (n/5)*5;
    cout<<q+p;

    return 0;

}

Measured memory_bytes: 3532
#include <stdio.h>
#include <string.h>

int main(){
	char s[1001];
	int len,i;
	scanf("%s",s);
	len = strlen(s);

	for (i = 0; i < len; i++)
	{
		switch (s[i])
		{
		case 'A':
			s[i]='X';
			break;

		case 'B':
			s[i]='Y';
			break;

		case 'C':
			s[i]='Z';
			break;

		default:
			s[i]-=3;
			break;
		} 
	}
	printf("%s\n",s);

	return 0;
}

Measured memory_bytes: 524
int main(void)
{
  int n,a=0,b=0,sum=0,i=0;
  scanf("%d",&n);
  while(i<n)
  {
    scanf("%d",&a);
    if(a>b)
    {
      sum+=b;
      b=a;
    }
    else sum+=a;
    i++;
  }
  sum+=b/2;
  printf("%d",sum);
  return 0;
}

Measured memory_bytes: 128
N = gets.to_i
S = gets.chomp

ans = 0
A = [*"0".."9"]
A.each do |x|
  next unless i = S.index(x)
  A.each do |y|
    if j = S.index(y, i+1)
      ans += A.count {|z| S.index(z, j+1) }
    end
  end
end
puts ans

Measured memory_bytes: 14360
import java.util.HashSet;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		var sc = new Scanner(System.in);
		var h = sc.nextInt();
		var w = sc.nextInt();
		var ch = sc.nextInt();
		var cw = sc.nextInt();
		var dh = sc.nextInt();
		var dw = sc.nextInt();
		var s = new int[h][w];
		for (var i = 0; i < h; i++) {
			var rs = sc.next();
			for (var j = 0; j < w; j++) {
				s[i][j] = rs.substring(j, j + 1).equals(".") ? 0 : -1;
			}
		}
		sc.close();

		var number = 1;
		var set = new HashSet<Integer>();
		set.add(getPosition(ch - 1, cw - 1));
		while (!set.isEmpty()) {
			var set2 = new HashSet<Integer>();
			for (var p : set) {
				s[getH(p)][getW(p)] = number;
			}
			for (var p : set) {
				check(s, p, number, set2);
			}
			number++;
			set = set2;
		}

		var result = s[dh - 1][dw - 1] < 0 ? -1 : s[dh - 1][dw - 1] - 1;
		System.out.println(result);
	}

	public static void check(int[][] s, int p, int number, HashSet<Integer> set) {
		var h = s.length;
		var w = s[0].length;
		var ph = getH(p);
		var pw = getW(p);
		for (var i = ph - 2; i <= ph + 2; i++) {
			for (var j = pw - 2; j <= pw + 2; j++) {
				if (i >= 0 && i < h && j >= 0 && j < w) {
					var d = Math.abs(i - ph) + Math.abs(j - pw);
					if (d == 1 && s[i][j] == 0) {
						s[i][j] = number;
						set.remove(getPosition(i, j));
						check(s, getPosition(i, j), number, set);
					} else if (d > 1 && s[i][j] == 0) {
						set.add(getPosition(i, j));
					}
				}
			}
		}
	}

	public static int getPosition(int h, int w) {
		return h * 1000 + w;
	}

	public static int getH(int p) {
		return p / 1000;
	}

	public static int getW(int p) {
		return p % 1000;
	}
}


Measured memory_bytes: 64312
#define REP(i,n) for (int i=0;i<(n);i++)
#include <iostream>
using namespace std;

int main(){
	int n;
	cin >> n;
	REP(i,n){
		int gx,gy,p,x1,x2,y1,y2;
		cin >> gx >> gy;
		int a[gx+1][gy+1],b[gx+1][gy+1];
		REP(j,gx+1){
		REP(k,gy+1){
			b[j][k] = 0;
		}
		}
		cin >> p;
		REP(j,p){
			cin >> x1 >> y1 >> x2 >> y2;
			if(x1 == x2){
				if(b[x2][max(y1,y2)] != 0)
					b[x2][max(y1,y2)] = 3;
				else
					b[x2][max(y1,y2)] = 1;
			}
			else if(y1 == y2){
				if(b[max(x1,x2)][y2] != 0)
					b[max(x1,x2)][y2] = 3;
				else
					b[max(x1,x2)][y2] = 2;
			}
		}
		a[0][0] = 1;
		for (int j=1;j<=gx;j++){ 
			if(b[j][0] == 0)
				a[j][0] = a[j-1][0];
			else
				a[j][0] = 0;
		}
		for (int k=1;k<=gy;k++){
			if(b[0][k] == 0)
				a[0][k] = a[0][k-1];
			else
				a[0][k] = 0;
		}

		for (int j=1;j<=gx;j++){
		for (int k=1;k<=gy;k++){
			switch(b[j][k]){
				case 0:
					a[j][k] = a[j-1][k] + a[j][k-1];
					break;
				case 1:
					a[j][k] = a[j-1][k];	
					break;
				case 2:
					a[j][k] = a[j][k-1];
					break;
				case 3:
					a[j][k] = 0;
					break;
			} 
		}
		}


		if(a[gx][gy] == 0)
			cout << "Miserable Hokusai!" << endl;
		else
			cout << a[gx][gy] << endl;
	}
}
	

Measured memory_bytes: 1160
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;


void main() {
    while (1) {
        auto s = readln.chomp;

        if (s == ".") return;

        writeln(isBalance(s) ? "yes" : "no");
    }
}

bool isBalance(string s) {
    auto st = Stack!(char)(200);

    foreach (ch ; s) {
        if (ch == '(' || ch == '[') st.push(ch);
        else if (ch == ')') {
            if (st.empty || st.top != '(') return false;
            else st.pop;
        }
        else if (ch == ']') {
            if (st.empty || st.top != '[') return false;
            else st.pop;
        }
    }

    return st.empty;
}

struct Stack(T) {
private:
    int N, peek;
    T[] data;

public:
    this(int size) 
    {
        N = size;
        data = new T[](N);
    }

    bool empty() @property
    {
        return peek == 0;
    }

    bool full() @property
    {
        return peek == N;
    }

    void push(T x) @property
    {
        assert(!full);
        data[peek++] = x;
    }

    void pop() @property
    {
        assert(!empty);
        --peek;
    }

    T top() @property
    {
        return data[peek - 1];
    }

    void clear() @property
    {
        peek = 0;
    }

    int length() @property
    {
        return peek;
    }

}

void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 3156
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define fi first
#define se second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int MAXN=2e3+5;
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc;
	for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny;
}
int n,Mod,F[MAXN*3][MAXN*4],ans;
inline void Add(int&x,int y){x+=y,x>=Mod?x-=Mod:0;}
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read(),Mod=read(),F[0][n+1]=1;int now=0;
	Rep(i,0,3*n)Rep(j,-n,n*3)if(F[i][j+(n+1)]){
		int d=j+(n+1),tmp=F[i][d];
		Add(F[i+1][d+1],tmp),Add(F[i+2][d-1],1ll*tmp*(i+1)%Mod),Add(F[i+3][d],1ll*tmp*(i+2)%Mod*(i+1)%Mod);
	}Rep(t,n+1,4*n+1)ans=(ans+F[3*n][t])%Mod;cout<<ans<<'\n';
	return 0;
}




Measured memory_bytes: 127200
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <cassert>
#include <utility>
#include <stack>
#include <queue>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int n;
int a[200100];
ll sum[200100];

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(i==0){
			sum[i]=a[i];
		}else{
			sum[i]=sum[i-1]+a[i];
		}
	}
	
	ll ans=INFl;
	
	for(int i=0;i<n-1;i++){
		ans=min(ans,abs(sum[i]-(sum[n-1]-sum[i])));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2560
import itertools
n=int(input())
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))
num=[i for i in range(1,n+1)]
l=list(itertools.permutations(num, r=None))
a=l.index(p)
b=l.index(q)
print(abs(a-b))


Measured memory_bytes: 8052
#include<bits/stdc++.h>
using namespace std; 
 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
 
typedef long long int ll; 
typedef long double ld; 
 
#define MAX 300005
#define endl '\n'
#define UPPER 1000000000

int main(){
	
	std::ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	ll n;
	cin>>n;
	
	ll arr[n];
	for(ll i=0;i<n;++i){
		cin>>arr[i];
	}
	
	ll ans = 0;
	ll cur = arr[0];
	for(ll i=1;i<n;++i){
		if(cur<arr[i]){
			cur = arr[i];
		}
		else{
			ans += cur-arr[i];
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 5216
#include<bits/stdc++.h>
using namespace std;
int n,a[100010][4],x[100010],f[2],g[2];
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j;
	scanf("%d",&n);
	for(i=1;i<=3;i++)
	  for(j=1;j<=n;j++)
	    scanf("%d",&a[j][i]);
	for(i=1;i<=n;i++)
	  {
	   x[i]=(a[i][1]-1)/3;
	   if(a[i][1]==3*x[i]+1 && a[i][2]==3*x[i]+2 && a[i][3]==3*x[i]+3)
	     x[i]++;
	   else if(a[i][1]==3*x[i]+3 && a[i][2]==3*x[i]+2 && a[i][3]==3*x[i]+1)
	     x[i]=-x[i]-1;
	   else
	     {
		  printf("No\n");
		  return 0;
		 }
	  }
	for(i=1;i<=n;i++)
	  if((x[i]^i)&1)
	    {
		 printf("No\n");
		 return 0;
		}
	for(i=1;i<=n;i++)
	  if(x[i]<0)
	    f[i&1]++;
	for(i=1;i<=n;i++)
	  while(abs(x[i])!=i)
	    {
	     swap(x[i],x[abs(x[i])]);
	     g[i&1]++;
		}
	if(!((f[0]^g[1])&1) && !((f[1]^g[0])&1))
	  printf("Yes\n");
	else
	  printf("No\n");
	return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
int main()
{
    string s;
    cin >> s;
	
  	string h = s.substr(5, 2);
	if(h == "04" || h == "03" || h == "02" || h == "01")
      cout << "Heisei" << endl;
  	else
      cout << "TBD" << endl;


    return 0;
}


Measured memory_bytes: 256
while 1:
	exps=raw_input().split("|")
	if exps[0]=="#":break
	for i in range(len(exps)):
		v=True
		lits=exps[i][1:-1].split("&")
		for lit1 in lits:
			for lit2 in lits:
				if (lit1=="~"+lit2) or ("~"+lit1==lit2):
					v=False
		if v:
			print "yes"
			break
	else:
		print "no"
		

Measured memory_bytes: 4216
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, U, V;
vector <int> Graph[int(1e5 + 5)];
int DistT[int(1e5 + 5)], DistA[int(1e5 + 5)];

int Prepare(){
  scanf("%d%d%d", &N, &U, &V);
  fill(DistT, DistT + N + 1, -1);
  fill(DistA, DistA + N + 1, -1);
  for (int i = 0; i < N - 1; i++){
    int A, B; scanf("%d%d", &A, &B);
    Graph[A].push_back(B);
    Graph[B].push_back(A);
  }
  return 0;
}

int BFS(){
  queue <int> que;
  que.push(U); DistT[U] = 0;
  while (!que.empty()){
    int Q = que.front(); que.pop();
    for (int i = 0; i < Graph[Q].size(); i++){
      int next = Graph[Q][i];
      if (DistT[next] != -1) continue;
      DistT[next] = DistT[Q] + 1;
      que.push(next);
    }
  }
  que.push(V); DistA[V] = 0;
  while (!que.empty()){
    int Q = que.front(); que.pop();
    for (int i = 0; i < Graph[Q].size(); i++){
      int next = Graph[Q][i];
      if (DistA[next] != -1) continue;
      DistA[next] = DistA[Q] + 1;
      que.push(next);
    }
  }
  return 0;
}

int main(){
  Prepare(); BFS();

  int ans = 0;
  for (int i = 1; i <= N; i++){
    if (DistA[i] >= DistA[U] && DistT[i] < DistA[i]){
      ans = max(ans, DistA[i] - 1);
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6656
#include <stdio.h>
#include <stdlib.h>
int count(int *a,int N);
int med3(int x, int y,int z);
void quicksort(int a[], int left, int right);
int main()
{
	int N,K,*a,i,j,var,sum=0;
	scanf("%d %d",&N,&K);
	a=(int *)malloc(sizeof(int)*N);
	if(a==NULL) {
		fprintf(stderr,"Cannot allocation\n");
		return 1;
	}
	for(i=0;i<N;i++) a[i]=0;
	for(i=0;i<N;i++) {
		scanf("%d",&j);
		a[j-1]++;
	}
	if((var=count(a,N))<=K) {
		printf("0\n");
		return 0;
	} else {
		quicksort(a,0,N-1);
 		for(i=N-1,j=0;j<K;i--,j++) {
			sum+=a[i];
		}
		printf("%d\n",N-sum);
	}
	free(a);
	return 0;
}
int count(int *a,int N)
{
	int i,j=0;
	for(i=0;i<N;i++) {
		if(a[i]!=0) j++;
	}
	return j;
}

int med3(int x, int y,int z) {
    if (x < y) {
        if (y < z) return y; else if (z < x) return x; else return z;
    } else {
        if (z < y) return y; else if (x < z) return x; else return z;
    }
}

void quicksort(int a[], int left, int right) {
    if (left<right) {
        int i=left,j=right;
        int tmp,pivot=med3(a[i], a[i + (j - i) / 2], a[j]); 
        while(1) { 
            while (a[i]<pivot) i++; 
            while (pivot<a[j]) j--; 
            if (i>=j) break;
            tmp=a[i];a[i]=a[j];a[j]=tmp; 
            i++;j--;
        }
        quicksort(a, left, i - 1);
        quicksort(a, j + 1, right);
    }
}

Measured memory_bytes: 896
//                                      KiSmAt
#include "bits/stdc++.h"
using namespace std;
 
using ll = long long;
 
const ll inf = 1e18;
const int N = 2 * 1e5 + 10;

ll res;
ll a[N];

void solve(){
    ll n, k;
    cin >> n >> k;
    if(k == 1)  k = n;
    cout << n - k;
}
 
int main(int argc, char const *argv[]){
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}
// nEro

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

int main()
{
    int n, cnt = 0;
    int *a;
    cin >> n;
    a = new int[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    while(true){
        for(int i = 0; i< n; i++){
            if(a[i] % 2 != 0) {
                cout << cnt;
                return 0;
            }
            else {
                a[i] = a[i] / 2;
            }
        }
        cnt++;
    }
}


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

int main(void){
	int n; cin >> n;
	int acnt = 0;

	rep(loop, n){
		string str; cin >> str;

		if(str == "A"){
			acnt++;
		}
		else {
			if(acnt <= 0){
				cout << "NO" << endl;
				return 0;
			}
			acnt--;
		}
	}

	if(acnt > 0){
		cout << "NO" << endl;
	}
	else {
		cout << "YES" << endl;
	}


	return 0;
}

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

int main() {
  char c;
  cin >> c;
  
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
  	cout << "vowel";
  }
  else {
  	cout << "consonant";
  }
  
}




Measured memory_bytes: 3632
N=parse(Int,readline())
A=map(x->parse(Int,x),split(readline()))
mi=Mi=1
for i=2:N
	if A[mi]>A[i]
		mi=i
	end
	if A[Mi]<A[i]
		Mi=i
	end
end
ans=Array{Pair{Int,Int}}(0)
if -A[mi]<=A[Mi]
	for i=1:N
		if i!=Mi
			push!(ans,Mi=>i)
			A[i]+=A[Mi]
		end
	end
else
	for i=1:N
		if i!=mi
			push!(ans,mi=>i)
			A[i]+=A[mi]
		end

	end
end
if A[1]>=0
	for i=1:N-1
		push!(ans,i=>i+1)
	end
else
	for i=N:-1:2
		push!(ans,i=>i-1)
	end
end
println(length(ans))
for (k,v)=ans
	println("$k $v")
end


Measured memory_bytes: 172268
from heapq import heapify, heappush, heappop
from heapq import _heapify_max, _heappop_max

def _heappush_max(heap, item):
    heap.append(item)
    heapq._siftdown_max(heap, 0, len(heap)-1)

"""
method:
    heapify(x): ヒープに変換
    heappush(heap, item): itemをheapにpush
    heappop(heap): heapから最小値を取得 空の場合はIndexError
note:
    max heapにする場合は、prefix: _ とsuffix: _maxをつければ良い
"""


def main():
    n, m, s = map(int, input().split())
    edge = [[] for i in range(n)]
    cl, dl = [None]*n, [None]*n
    sa = 0
    for i in range(m):
        u, v, a, b = map(int, input().split())
        u -= 1
        v -= 1
        edge[u].append((v, b, a))
        edge[v].append((u, b, a))
        sa += a
    for i in range(n):
        c, d = map(int, input().split())
        cl[i] = c
        dl[i] = d
    dijkstra(n, s, edge, cl, dl)
        
        
    
def dijkstra(n, coin, edges, cl, dl):
    coin_max = 5000
    start = 0
    coin = min(coin, coin_max)
    d = [[10**15]*(coin_max+1) for _ in range(n)]
    d[start][coin] = 0
    priority_queue = []
    heappush(priority_queue, (0, start, coin))
    while priority_queue:
        cost_i, i, coin_i = heappop(priority_queue)
        if d[i][coin_i] < cost_i:
            continue
        supplied_coin = coin_i + cl[i]
        if supplied_coin <= coin_max and cost_i + dl[i] < d[i][supplied_coin]:
            d[i][supplied_coin] = cost_i + dl[i]
            heappush(priority_queue, (cost_i + dl[i], i, supplied_coin))
        for _to, _cost, _coin in edges[i]:
            ci = coin_i-_coin
            if coin_i >= _coin and d[_to][ci] > cost_i + _cost:
                d[_to][ci] = cost_i + _cost
                heappush(priority_queue, (cost_i + _cost, _to, ci))
    for i in d[1:]:
        print(min(i))
    
        

if __name__ == "__main__":
    main()

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

const int inf = 1e9;
const ll linf = 1e18;

template <ll mod> class modint
{
private:
    ll x;

public:
    constexpr modint(ll x = 0) noexcept : x(x >= 0 ? x % mod : (x % mod) + mod) {}
    constexpr modint &operator+=(const modint rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    constexpr modint &operator-=(const modint rhs) {
        if ((x += mod - rhs.x) >= mod) x -= mod;
        return *this;
    }
    constexpr modint &operator*=(const modint rhs) {
        (x *= rhs.x) %= mod;
        return *this;
    }
    constexpr modint &operator/=(const modint rhs) {
        *this *= rhs.inv();
        return *this;
    }
    constexpr modint operator+(const modint &rhs) const { return modint(*this) += rhs; }
    constexpr modint operator-(const modint &rhs) const { return modint(*this) -= rhs; }
    constexpr modint operator*(const modint &rhs) const { return modint(*this) *= rhs; }
    constexpr modint operator/(const modint &rhs) const { return modint(*this) /= rhs; }

    constexpr modint operator-() const { return modint(-x); }

    modint pow(ll n) const {
        modint e = *this, ret = modint(1);
        while (n) {
            if (n & 1) ret *= e;
            e *= e, n >>= 1;
        }
        return ret;
    }

    modint inv() const { return pow(mod - 2); }

    friend ostream &operator<<(ostream &os, const modint &m) {
        os << m.x;
        return os;
    }

    friend istream &operator>>(istream &is, modint &m) {
        ll in;
        is >> in;
        m = modint(in);
        return is;
    }
};
using mint = modint<1000000007>;

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

    int n; cin >> n;
    vector<ll> x(n);
    for (int i = 0; i < n; i++) cin >> x[i];
 
    mint ans = 0;
    
    for (int i = 1; i <= n - 1; i++) {
        static mint prob = 1;
        ans += (mint)(x[i] - x[i-1]) * prob;
        prob += mint(i + 1).inv();
    }
 
    mint fact = 1;
    for (int i = 2; i <= n - 1; i++) fact *= mint(i);
 
    ans *= fact;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
n,x = map(int, input().split())
a = list(map(int, input().split()))

a = [0]+a

ans = 0

for i in range(n):
    if a[i]>x:
        ans += a[i]-x
        a[i]=x
    if a[i]+a[i+1]>x:
        ans += a[i]+a[i+1]-x
        a[i+1]=x-a[i]

print(ans)

Measured memory_bytes: 63984
# include <iostream>
# include <algorithm>
# include <functional>
# define MAX 102

using namespace std;

int N;
int d[MAX];
int ans = 0;

int main () {
    cin >> N;
    for ( int i = 0; i < N; i++) {
        cin >> d[i];
    }
    sort(d, d+N, std::greater<int>() );
    
    for ( int i = 0; i < N; i++){
        if ( d[i] != d[i-1] ) { ans ++; }
     }
    cout << ans;
    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 repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    string s;
    cin >> s;
    if (s == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
}

Measured memory_bytes: 3572
/*input
7 11
1 2 2
1 3 1
2 4 2
2 5 2
2 6 1
3 4 1
3 5 1
3 6 1
4 7 2
5 7 2
6 7 1
*/
#include <bits/stdc++.h>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define int long long
#define N 1505
#define bit(x,y) ((x>>y)&1LL)

int n, m;
vector<vector<pair<int, int> > > a(N);
int dis[N][N];

bool inqueue[N];
queue<int> q;
int mxans = 0;
int mx[N];

void SPFA(int root) {
	dis[root][root] = 0;
	q.push(root); inqueue[root] = true;
	while (!q.empty()) {
		int u = q.front(); q.pop(); inqueue[u] = false;
		for (auto v : a[u]) {
			if (dis[root][v.fi] > dis[root][u] + v.se) {
				dis[root][v.fi] = dis[root][u] + v.se;
				if (!inqueue[v.fi]) {
					inqueue[v.fi] = true;
					q.push(v.fi);
				}
			}
		}
	}
	for (int i = 1; i <= n; i++) mxans = max(mxans, dis[root][i]);
}

bool visited[N]; bool mark[N];
void dfs(int u, int root) {
	if (visited[u]) return;
	visited[u] = true;
	mx[u] = dis[root][u];
	for (auto v : a[u]) {
		if (dis[root][v.fi] == dis[root][u] + v.se) {
			dfs(v.fi, root); mx[u] = max(mx[u], mx[v.fi]);
		}
	}
	if (mx[u] == mxans)
		mark[u] = 1;
}

vector<int> order;
signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifdef in1code
	freopen("1test.inp", "r", stdin);
#endif
	memset(dis, 127, sizeof(dis));
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		int u, v, c;
		cin >> u >> v >> c;
		a[u].push_back(mp(v, c));
		a[v].push_back(mp(u, c));
	}
	for (int i = 1; i <= n; i++) SPFA(i);
	for (int i = 1; i <= n; i++) {
		memset(visited, 0, sizeof(visited)); dfs(i, i);
	}
	for (int i = 1; i <= n; i++) {
		if (!mark[i]) order.push_back(i);
	}
	cout << order.size() << endl;
	for (auto it : order) cout << it << endl;
}


Measured memory_bytes: 21088
n, w = map(int, input().split())
vw = [[int(i) for i in input().split()] for _ in range(n)]
dp = [[-1 for _ in range(w + 1)] for _ in range(n + 1)]
for i in range(w + 1):
    dp[0][i] = 0
for i in range(n):
    for j in range(w + 1):
        if j >= vw[i][1]:
            dp[i + 1][j] = max(dp[i][j], dp[i][j - vw[i][1]] + vw[i][0])
        else:
            dp[i + 1][j] = dp[i][j]
print(dp[n][w])


Measured memory_bytes: 25956
#include <stdio.h>

int main(void)
{
  int h1, m1, h2, m2, ken, han, man, fan;
  
  scanf("%d",&h1);
  scanf("%d",&m1);
  scanf("%d",&h2);
  scanf("%d",&m2);
  scanf("%d",&ken);

  while(m2-ken < 0){
    ken = ken-(m2+1);
  	m2 = 59;
    h2--;
  }
  m2 -= ken;
  
  han = (h2 - h1) * 60;
  man = m2 - m1;
  fan = han + man;
    
  printf("%d",fan);
  return 0;
}

Measured memory_bytes: 1728
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		var a=sc.Ia;
		long ans=0;
		for(int i = 0;i<n;i++) {
			for(int j = i+1;j<n;j++) {
				for(int k = j+1;k<n;k++) {
					if(a[i]!=a[j]&&a[i]!=a[k]&&a[k]!=a[j]&&a[i]+a[j]>a[k]&&a[i]+a[k]>a[j]&&a[k]+a[j]>a[i]){
						ans++;
					}
				}
			}
		}
		Console.WriteLine("{0}",ans);
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public int[] Ia3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public long[] La3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

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

#define __STDC_FORMAT_MACROS
#define p64 PRId64

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define ALL(f, x, ...)                                                         \
    ([&] (decltype ((x)) ALL) {                                                \
        return (f) (begin (ALL), end (ALL), ##__VA_ARGS__);                    \
    }) (x)

using namespace std;
using ll = int64_t;

int main() {
    int n;
    cin >> n;
    vector<int> p (n, 0);
    REP (i, n) cin >> p[i];
    int ans = 0;
    FOR (i, 1, n - 1) {
        if (p[i - 1] < p[i] && p[i] < p[i + 1])
            ans++;
        else if (p[i + 1] < p[i] && p[i] < p[i - 1])
            ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
var a,b,i,j,n,ans:longint;
var s:string;
begin
  readln(s);readln(n);
  for i:=1 to length(s) do 
  begin
    if (1+n*(i-1)>length(s))then break;
    write(s[1+n*(i-1)]);
  end;
  writeln;
end.

Measured memory_bytes: 128
package main

import "fmt"

func main() {
	var x, n int
	fmt.Scan(&x, &n)

	pl := make([]int, n)
	var p int
	for i := 0; i < n; i++ {
		fmt.Scan(&p)
		pl[i] = p
	}

	nu := x
	nd := x
	for {
		if contains(pl, nu) && contains(pl, nd) {
			/*
				if nu < 100 {
					nu++
				}
				if nd > 0 {
					nd--
				}
			*/
			nu++
			nd--
			continue
		} else {
			break
		}
	}

	if contains(pl, nu) {
		fmt.Println(nd)
		return
	}
	if contains(pl, nd) {
		fmt.Println(nu)
		return
	}
	u := abs(x - nu)
	d := abs(x - nd)
	if u >= d {
		fmt.Println(nd)
	} else {
		fmt.Println(nu)
	}
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func contains(s []int, e int) bool {
	for _, v := range s {
		if e == v {
			return true
		}
	}
	return false
}

Measured memory_bytes: 1824
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
using namespace std;
int main(){
    char s[11];
    cin>>s;
    char ans[11]={};
    for(int i = 0;i<10;i++){
        if(i == 3){
            ans[i]='8';
        }else{
            ans[i]=s[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (k, x) = readIntegerList()
    (if ((500 * k) >= x) "Yes" else "No").let(::println)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


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

using namespace std;

int main(void){
  int n;
  scanf("%d", &n);
  int dice[100][7];
  bool c = false;
  for(int k = 0;k < n;++k){
    for(int i = 1;i < 7;++i){
      scanf("%d", &dice[k][i]);
    }
  }

  bool flag = false;
  for(int x = 0;x < n;++x){
    for(int y = x + 1;y < n;++y){
      string commands = "EEENEEENEEESEEESEEENEEEN";
      int tmp;
      for(int i = 0;i < commands.length();++i){
        bool t = true;
        for(int j = 1;j < 7;++j){
          if(dice[x][j] != dice[y][j]){
            t = false;
          }
        }
        if(t){
          flag = true;
        }
        char command = commands[i];
        switch(command){
          case 'N':
            tmp = dice[x][1];
            dice[x][1] = dice[x][2];
            dice[x][2] = dice[x][6];
            dice[x][6] = dice[x][5];
            dice[x][5] = tmp;
            break;
          case 'E':
            tmp = dice[x][3];
            dice[x][3] = dice[x][1];
            dice[x][1] = dice[x][4];
            dice[x][4] = dice[x][6];
            dice[x][6] = tmp;
            break;
          case 'W':
            tmp = dice[x][4];
            dice[x][4] = dice[x][1];
            dice[x][1] = dice[x][3];
            dice[x][3] = dice[x][6];
            dice[x][6] = tmp;
            break;
          case 'S':
            tmp = dice[x][6];
            dice[x][6] = dice[x][2];
            dice[x][2] = dice[x][1];
            dice[x][1] = dice[x][5];
            dice[x][5] = tmp;
            break;
        }
      }
    }
  }
  printf(flag ? "No\n" : "Yes\n");
  return 0;
}



Measured memory_bytes: 3336
#include<stdio.h>
int main(){
  int n,m,i,b=0,bb=0,d=0,max=0,t;
  scanf("%d %d",&n,&m);
  for(i=0;i<n;i++){
    scanf("%d",&t);
    if(i)d+=m-b;
    if((bb<b&&b>t)||(bb>b&&b<t)){
      if(max<d)max=d;
      d=m-b;
    }
    bb=b;
    b=t;
  }
  d+=m-t;
  if(max<d)max=d;
  printf("%d\n",max);
  return 0;
}

Measured memory_bytes: 596
n = int(input())
a = list(map(int, input().split()))
a_index = []
for i in range(n):
    a_index.append((i, a[i]))
dic1 = {}
dic2 = {}
for i in range(n):
    one = a_index[i][0] + a_index[i][1]
    two = a_index[i][0] - a_index[i][1]
    if one not in dic1:
        dic1[one] = 1
    else:
        dic1[one] += 1
    if two not in dic2:
        dic2[two] = 1
    else:
        dic2[two] += 1
ans = 0
for i in dic1.keys():
    if i in dic2:
        ans += dic2[i] * dic1[i]
for i in dic2.keys():
    if i in dic1:
        ans += dic1[i] * dic2[i]
        #print(i)
print(ans // 2)


Measured memory_bytes: 73948
#include <iostream>
using namespace std;
#define MAX 100000

int parent(int i){
  return i/2;
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i+1;
}

int main(){
  int H,i,A[MAX+1];

  cin >> H;

  for(i=1;i<=H;i++){
    cin >> A[i];
  }

  for(i=1;i<=H;i++){
    cout << "node " << i << ": key = " << A[i] << ", ";
    if(parent(i) >= 1) cout << "parent key = " << A[parent(i)] << ", ";
    if(left(i) <= H) cout << "left key = " << A[left(i)] << ", ";
    if(right(i) <= H) cout << "right key = " << A[right(i)] << ", ";
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3104
//%std
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
	int out=0,fh=1;
	char jp=getchar();
	while ((jp>'9'||jp<'0')&&jp!='-')
		jp=getchar();
	if (jp=='-')
		fh=-1,jp=getchar();
	while (jp>='0'&&jp<='9')
		out=out*10+jp-'0',jp=getchar();
	return out*fh;
}
const int MAXN=5e3+10;
typedef unsigned long long ull;
const ull Base=37;
ull pw[MAXN],Hash[MAXN];
ull calc(int l,int r)
{
	return Hash[r]-Hash[l-1]*pw[r-l+1];
}
int n;
char s[MAXN];
int main()
{
	n=read();
	scanf("%s",s+1);
	pw[0]=1;
	for(int i=1;i<=n;++i)
	{
		Hash[i]=Hash[i-1]*Base+(ull)(s[i]-'a');
		pw[i]=pw[i-1]*Base;
	}
	int ans=0;
	for(int i=1;i<=n;++i)
		for(int j=i+1;j<=n;++j)
		{
			int L=1,R=min(j-i,n-j+1);
			while(L<=R)
			{
				int mid=(L+R)>>1;
				if(calc(i,i+mid-1)==calc(j,j+mid-1))
					L=mid+1,ans=max(ans,mid);
				else
					R=mid-1;
			}
		}
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;

#define mem(a,b) memset(a,b,sizeof(a))
#define FOR(i,j,k) for(int i=j;i<=k;i++)
#define REV(i,j,k) for(int i=j;i>=k;i--)
#define FORR(i,j,k,l) for(int i=j;i<=k;i+=l)
#define inf         freopen("in.txt", "r", stdin)
#define outf        freopen("out.txt", "w", stdout)
#define pf          printf
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c)    scanf("%d %d %d", &a, &b, &c)
#define clean(mat,n)   FOR(i,0,n) mat[i].clear()
#define minn          (long long)-1000000000000000000
#define maxx          (long long) 1000000000000000000
#define M          1000000007
#define M_PI           3.14159265358979323846  /* pi */
#define LL           long long
#define NL '\n'
#define cnd tree[idx]
#define lnd (idx<<1)
#define rnd ((idx<<1)+1)
#define PB push_back
#define F first
#define S second
#define MAX 410
#define MP make_pair
#define valid(nx,ny)  ((nx >= 0) && (nx < row) && (ny >= 0) && (ny < col))
#define LD long double
typedef pair<int,int> PR;

LL dp[MAX][MAX], n, sum[MAX], c, v;

LL rec(int l,int r)
{
    if(l == r) return 0;

    LL &re = dp[l][r];
    if(re != -1) return re;

    re = LLONG_MAX;
    FOR(i,l,r-1)
    {
        LL so = rec(l, i) + rec(i + 1, r);
        so += sum[r]; if(l) so -= sum[l - 1];
        re = min(re, so);
    }

    return re;
}

int main()
{
    ios::sync_with_stdio(false);
    //inf;
    //outf;

    cin >> n;
    FOR(i,0,n-1)
    {
        cin >> v;
        c += v; sum[i] = c;
    }

    mem(dp, -1);
    cout << rec(0, n-1) << endl;

    return 0;
}




Measured memory_bytes: 1664
import sys

stdin = sys.stdin

sn = lambda : stdin.readline().rstrip()
an = lambda : map(int, stdin.readline().split())
ni = lambda : int(sn())
def main():
  n, k, q = an()
  a = [ni() for _ in range(q)]

  point = [k] * n

  for aa in a:
    point[aa-1] += 1

  for p in point:
    p -= q
    if p <= 0:
      print("No")
    else:
      print("Yes")
main()


Measured memory_bytes: 10488
S=input()
N=len(S)
a=[]
b=[]
c=[]
d=[]

for i in range((N-1)//2):
    if((N-1)//2%2==1):
        if((N-1)//4>i ):
            a.append(S[i])

        elif((N-1)//4!=i):
            b.append(S[i])
    else:
        if((N-1)//4>i ):
            a.append(S[i])

        elif((N-1)//4==i):
            b.append(S[i])

        elif((N-1)//4!=i):
            b.append(S[i])

if(a==b[::-1]):
    if(S==S[::-1]):

        print('Yes')
    else:
        print('No')
    exit(0)

    for i in range((N+3)//2-1,N):
        if(((N+3)//2-1+N)//2>i ):
            c.append(S[i])
        elif(((N+3)//2-1+N)//2!=i):
            d.append(S[i])
    if(c==d):
        if(S==S[::-1]):

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


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

using namespace std;

int main() {
    string s;
    cin >> s;
    int arr[2] = {0};
    for(int i=0;i<3;i++)
        arr[s[i]-'A'] = 1;
    if(arr[0] == 1 && arr[1] == 1)
        cout << "Yes" << '\n';
    else
        cout << "No" << '\n';
}

Measured memory_bytes: 256
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	//static final PrintStream out = System.out; 多分大丈夫
	static Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] a = new int[M+2];
		for(int i=1;i<=M;i++) {   //0段目を配列a[0]に入れている
			a[i]=sc.nextInt();
		}
		sc.close();
		long[] dp = new long[N+1];
		int ta = 1;
		dp[0] = 1;
		if(a[ta]!=1)dp[1]=dp[0];
		else ta++;
		for(int i=2;i<=N;i++) {
			if(a[ta]!=i) {
				dp[i] = dp[i-2]+dp[i-1];
				dp[i]-=dp[i]>Mod?Mod:0;
			}else {
				ta++;
			}
		}
		//out.println(dp[N]);
		System.out.println(dp[N]);
	}
	/*private static int nextInt() {		プログラムを高速化するためのメソッドで無くても大丈夫
		return Integer.parseInt(next());
	}
	private static long nextLong() {
		return Long.parseLong(next());
	}
	private static String next() {
		return sc.next();
	}
	*/

}


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

int main(){
	cin.tie(0);	
	cout.tie(0);	
	ios_base::sync_with_stdio(0);
	bool val1[11] = {};
	bool val2[101] = {};
	bool val3[1001] = {};
	int n;
	string s;
	cin >> n >> s;
	for(int j = 0;j < n; ++j){
		int x = s[j] - '0';	
		for(int i = 0;i < 100; ++i){
			if(val2[i])val3[10 * i + x] = 1;
		}
		for(int i = 0;i < 10; ++i){
			if(val1[i])val2[10 * i + x] = 1;
		}
		val1[x] = 1;
	}
	cout << accumulate(val3, val3 + 1001, 0) << '\n';
}


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

using namespace std;

typedef long long ll;

struct pt
{
        ll x;
        ll y;
};

ll ar(pt a,pt b)
{
        return (a.x-b.x)*(a.y+b.y);
}

ll ar(pt a,pt b,pt c)
{
        return ar(a,b)+ar(b,c)+ar(c,a);
}


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

        ll s;
        cin>>s;

        ll val=(ll)1e9;

        pt a={0,0};
        pt b={val,1};
        ll x,y;

        if(s%val==0)
        {
                ll k=s/val;
                y=k;
                x=0;
        }
        else
        {
                ll a=s%val-val;
                x=-a;
                y=s/val+1;
        }

        pt c={x,y};

        if(ar(a,b,c)!=s)
        {
                cout<<"Big error\n";
        }

        cout<<a.x<<" "<<a.y<<" "<<b.x<<" "<<b.y<<" "<<c.x<<" "<<c.y<<"\n";

        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
    int N;
    cin >> N;
    int k = 0;
    for (int i = 0; i < N; i++) {
        int A;
        cin >> A;
        k += A&1;
    }
    if (k % 2 == 0) {
        puts("YES");
    }
    else {
        puts("NO");
    }
}

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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}


int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}
///////////////////////////
int main() {
  long long int a=0,b=0,c=0,d=0,n=0,count=0,ans=0;
  string s;
  cin>>a>>b;
  c=b+a*2;
  if(c/4<b/2) cout<<c/4<<endl;
  else cout<<b/2<<endl;
}
///////////////////////////

Measured memory_bytes: 256
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    A, B, C = map(int, input().split())
    K = int(input())

    k = 0
    while 1:
        if A >= B:
            B *= 2
            k += 1
        else:
            break
    while 1:
        if B >= C:
            C *= 2
            k += 1
        else:
            break
    if K >= k:
        print("Yes")
    else:
        print("No")


main()


Measured memory_bytes: 9172
fun main(args: Array<String>) {

    // input
    val (N, T) = readLine()!!.split(" ")
            .map { s -> s.toInt() }

    var minCost = Int.MAX_VALUE
    var minTime = T
    var isPathExist = false
    for (i in 1..N) {
        val (cost, time) = readLine()!!.split(" ")
                .map { s -> s.toInt() }
        if (time <= minTime && cost < minCost) {
            minCost = cost
            isPathExist = true
        }
    }
    if (isPathExist) {
        println(minCost)
    } else {
        println("TLE")
    }

}

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

int main() {
  vector<int> a(3),b(3),count(4);
  bool flag=1;
  for(int i=0;i<3;i++){
  	cin >> a.at(i) >> b.at(i);
  	count.at(a.at(i)-1)++;
  	count.at(b.at(i)-1)++;
  }
  for(int i=0;i<4;i++){
  	if(count.at(i)>=3) flag=0;
  }

  if(flag){
  	cout << "YES" << endl;
  }else{
  	cout << "NO" << endl;
  }
  return 0;
}


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



}

Measured memory_bytes: 580