akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void anss(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}

int main(){
  ll i,j,o;
  ll res=0,res1=0,res2=INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ll> a(n);
  for(i=0;i<n;i++){
    cin>>buf;
    res+=buf;
    if(buf%10!=0){
      chmin(res2,buf);
    }
  }
  if(res%10==0){
    if(res2==INF)cout<<0<<endl;
    else cout<<res-res2<<endl;
  }
  else cout<<res<<endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	//static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
	
	
	
	
	//for(int i=0;i<N;i++) {}
	public static void main(String[] args) {
		//int N=sc.nextInt();for(int i=0;i<N;i++) {}
		
		int N=sc.nextInt();
		int K=sc.nextInt()	;
		
		
		
		int v[]=new int[N];
		for(int i=0;i<K;i++) {
			int d=sc.nextInt();
			
			for(int a=0;a<d;a++) {
				v[sc.nextInt()-1]++;
			}
		}int ans=0;
		for(int i=0;i<N;i++) {
			if(v[i]==0) {
				ans++;
			}
			
			
		}
		p(ans);
		
		
		
	}
	

	
	
	
	

	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 46560
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    if (n % k == 0) {
      System.out.println(0);
    } else {
      System.out.println(1);
    }
  }
}

Measured memory_bytes: 21588
k,n = map(int, input().split())
a = list(map(int, input().split()))


d = 0
for i in range(1,n):
    if a[i]-a[i-1] >= d:
        d = a[i]-a[i-1]
    else:
        d = d

e = k + a[0] - a[-1]
if e >= d:
    d = e




print(k-d)

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

using namespace std;

typedef long long ll;

int main(){
  ll n,a[10000];

  cin>>n;
  for(ll i=0;i<n;i++)cin>>a[i];

  sort(a,a+n);
  ll ans=1;
  for(ll i=0;i<n;i++)
    if(ans>=a[i])ans+=a[i];
    else break;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3240
# AOJ 0219: A Popular Ice-cream Shop
# Python3 2018.6.23 bal4u

while 1:
	n = int(input())
	if n == 0: break
	f = [0]*10
	for i in range(n): f[int(input())] += 1
	for i in range(10):
		if f[i] == 0: print('-')
		else: print('*'*f[i])



Measured memory_bytes: 5624
#include<iostream>
#include<string>
using namespace std;
int main(){
    int N;
    string a[100];
    cin>>N;
    for(int i=0;i<=N-1;i++)cin>>a[i];
    for(int i=1;i<=N-1;i++){
        if(a[i-1].substr(a[i-1].size()-1,1)!=a[i].substr(0,1)){
            cout<<"No"<<endl;
            return 0;
        }
        for(int k=0;k<=i-1;k++){
            if(a[i]==a[k]){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
Y = [list(map(int,input().split())) for _ in range(n)]
X = []
for y in Y:
    X.append([y[0]+y[1],y[0]-y[1]])
X.sort()
ans = n
right = X[0][0]
for i in range(1,n):
    left = X[i][1]
    if left < right:
        ans -= 1
    else:
        right = X[i][0]
print(ans)

Measured memory_bytes: 41440
// inputに入力データ全体が入る
function Main(input) {
  input = input.replace('\n', '');
  var N = parseInt(input);

  ans = 0;
  if(N >= 100 && N < 112){
    ans = 111;
  } else if(N >= 112 && N < 223){
    ans = 222;
  } else if(N >= 223 && N < 334){
    ans = 333;
  } else if(N >= 334 && N < 445){
    ans = 444;
  } else if(N >= 445 && N < 556){
    ans = 555;
  } else if(N >= 556 && N < 667){
    ans = 666;
  } else if(N >= 667 && N < 778){
    ans = 777;
  } else if(N >= 778 && N < 889){
    ans = 888;
  } else if(N >= 890 && N <= 999){
    ans = 999;
  }


  console.log('%d', ans);

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));



Measured memory_bytes: 21064
#include<bits/stdc++.h>
using namespace std;
const int maxN = 2e5 + 13;
int n, a[maxN], pos[maxN], arr[maxN];
bool cmp (int i, int j) {
    if (a[i] != a[j])
	return a[i] < a[j];
    return i < j;
}

int main () {
    ios::sync_with_stdio(false);
    cin.tie(0);;
    cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) 
	cin >> a[i];
    iota(arr, arr + n, 0);
    sort(arr, arr + n, cmp);
    int val1 = a[arr[(n - 1)/ 2]], val2 = a[arr[n / 2]];
    for (int i = 0; i < n; i++)
	pos[arr[i]] = i;
    for (int i = 0; i < n; i++) {
	if (pos[i] < n / 2)
	    cout << val2 << '\n';
	else
	    cout << val1 << '\n';
    }
}


Measured memory_bytes: 4608
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    x, y = map(int, input().split())
    for i in range(x + 1):
        num = ((2 * i) + (4 * (x - i)))
        if y == num:
            print('Yes')
            exit()
    print('No')

if __name__ == '__main__':
    main()


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

int main() {
	string s, t, u;
	int a, b;
	cin >> s >> t;
	cin >> a >> b;
	cin >> u;
	cout << (s == u ? a - 1 : a) << " " << (t == u ? b - 1 : b) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <utility>
#include <map>
#define maxn 100005
using namespace std;
const int inf = 0x3f3f3f3f;
const int neginf = 0xc0c0c0c0;
typedef long long ll;
typedef pair<int,int> P;
int n,m;
char s[maxn],t[maxn];
map <int,char> mp;
int gcd(int x,int y){
	if(x % y) return gcd(y,x % y);
	return y;
}
int main(){
	scanf("%d%d",&n,&m);
	scanf("%s",s);
	scanf("%s",t);
	ll len = (ll)n * m / gcd(n,m);
	for(int i=0;i<n;i++){
		mp[i * len / n + 1] = s[i];
	}
	for(int i=0;i<m;i++){
		if(mp.find(i * len / m + 1) != mp.end() && mp[i * len / m + 1] != t[i]){
			puts("-1");
			return 0;
		}
	}
	printf("%lld\n",len);
	return 0;
}
/*
6 3
abcdef
ace
*/

Measured memory_bytes: 4736
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

string S;
int ans = 0;

signed main(){
    cin >> S;
    rep(i, S.size()){
        if(S[i] == '1') ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include<iostream> 
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <sstream>
#include <vector>

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)



int main() {
	int a, b, c,ans=0,an,bn,cn;
	cin >> a >> b >> c;
	while (1) {
		
		if (a==b&&b==c&&(a!=1||b!=1||c!=1)) {
			cout << -1 << endl;
			return 0;
		}

		if (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
			an = b / 2 + c / 2;
			//cout << a << endl;
			bn = a / 2 + c / 2;
			//cout << b<< endl;
			cn = a / 2 + b / 2;
			//cout << c<< endl;
			ans++;
			a = an;
			b = bn;
			c = bn;
		}
		else break;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3632
#include <cstdio>
#include <algorithm>
#include <functional>

#define MAX 100000

int main()
{
	int N, M, X[MAX], dif[MAX], ans=0;
	scanf("%d %d", &N, &M);
	for(int i=0; i<M; i++){
		scanf("%d", &X[i]);
	}
	std::sort(X, X+M);
	for(int i=0; i<M-1; i++){
		dif[i] = X[i+1]-X[i];
	}
	std::sort(dif, dif+M-1, std::greater<int>());
	for(int i=N-1; i<M-1; i++){
		ans += dif[i];
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
  #include "dbgtoki.hpp"
  #define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
DbgTimer D_t;
  #define TSTART() D_t.start()
  #define TSTOP() D_t.stop()
#else
  #define DUMP(i) 
  #define TSTART()
  #define TSTOP()  
#endif
 
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());
using namespace std;
typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

const int EPS = 1e-9;



int main (){
  cin.tie(0);
  ios::sync_with_stdio(false);
  vi color(3);
  while(cin >> color[0] >> color[1] >> color[2]){
    TSTART();
    int ans;
    sort(ALL(color));//忘れないように!
    UNIQUE(color);
    ans = SZ(color);

    cout << ans << endl;
    TSTOP();
  }
    return 0;
}



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

int main(void){
	int W,H,x,y,r;
	cin >> W >> H >> x >> y >> r;
	
	if( x - r >= 0 && y - r >= 0 && x + r <= W && y + r <= H){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(), (c).end());
const long long MOD = 1e9 + 7;
typedef long long ll;

int main(){
	int N;
	cin >> N;
	string ans = "No";
	rep(i, N / 4 + 2){
		rep(j, N / 7 + 2){
			if(i * 4 + j * 7 == N){
				ans = "Yes";
				break;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** -10

def get_sum(a, d, n):
    """ 等差数列の和：(初項a, 公差d, 項数n) """
    return (2*a + (n-1)*d) * n // 2

N = INT()

ans = 0
for i in range(1, N+1):
    cnt = N // i
    ans += get_sum(i, i, cnt)
print(ans)


Measured memory_bytes: 64460
#include<stdio.h>
#include<stdbool.h>

#define N 8
#define FREE -1
#define NOT_FREE 1

int row[N],col[N],dpos[2*N-1],dneg[2*N-1];

bool X[N][N];

void initialize(){
  int i;
  for(i=0;i<N;i++){row[i] = FREE,col[i] = FREE;}
  for(i=0;i<2*N-1;i++){dpos[i] = FREE; dneg[i] = FREE;}
}

void printBoard(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(X[i][j]){
	if(row[i] != j)return;
      }
    }
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i] == j)printf("Q");
      else printf(".");
    }printf("\n");
  }
}

void recursive(int i){
  int j;
  if(i == N){
    printBoard();
    return;
  }
  for(j=0;j<N;j++){
    if(NOT_FREE == col[j] ||
       NOT_FREE == dpos[i + j] ||
       NOT_FREE == dneg[i - j + N - 1] )continue;
    row[i] = j;
    col[j] = dpos[i + j] = dneg[i - j + N - 1] = NOT_FREE;
    recursive(i + 1);
    row[i] = col[j] = dpos[i + j] = dneg[i - j + N - 1] = FREE;
  }
}

int main(){
  int i,j,k,r,c;
  initialize();
  for(i=0;i<N;i++)
    for(j=0;j<N;j++) X[i][j] = false;

  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d%d",&r,&c);
    X[r][c] = true;
  }

  recursive(0);

  return 0;
}



Measured memory_bytes: 2108
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
    ll a, b;
    cin >> a >> b;
    cout << a*b;
}

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

typedef long long int ll;
typedef long double ld;

#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define rev(i,a,b) for(ll i=a;i>=b;i--)
#define pll pair<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vpll vector<pll>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ln length()
#define M 1000000007

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

    string s;cin>>s;
    ll ct[27];
    rep(i,1,26) ct[i]=0;
    for(char c:s) ct[c-'a'+1]++;
    ll n=s.size();
    ll ans=n*(n-1)/2 + 1;
    rep(i,1,26) ans-= (ct[i]*(ct[i]-1))/2;
    cout<<ans<<'\n';
}


Measured memory_bytes: 720
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define INF 200001

//B
template<typename T>
struct BIT{//1_Indexed
  int n;
  vector<T> bit;
  BIT(int n_):n(200001),bit(n,INF){}
  T min(int a){
  int ret = INF;
  for(int i = a; i > 0; i -= i & -i) ret = (ret>bit[i]?bit[i]:ret);
  return ret;
  }

  void minadd(int a,int w){
    for(int i = a; i <= n; i += i & -i)bit[i] = (bit[i]>w?w:bit[i]);
  }
};
//E


int main(){//ARC075-E
  int n;cin>>n;
  BIT<int> b(n);
  vector<int> a(n);
  for(int i = 0; n > i; i++){
    cin>>a[i];
    b.minadd(i+1,a[i]);
  }
  int ans = 0;
  for(int i = 0; n > i; i++){
    if(b.min(i+1) == a[i])ans++;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

//vc alp(26) ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//cout<<""<<endl;
int main(){
  int X;cin>>X;
  int ma=1;
  for(int i=2;i*i<=X;i++){
    for(int j=2;pow(i,j)<=X;j++){
      ma = max(ma,(int)pow(i,j));
    }
  }
  cout<<ma<<endl;
}	





Measured memory_bytes: 256
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 1000000007;
int n,m,s,t;
#define MAX_V 100010
struct edge{int to,cost;};
typedef pair<int,int> pii;
int V;
vector<edge> G[2][MAX_V];
int d[2][MAX_V];
void dijkstra(int s,int x){
    priority_queue<pii,vector<pii>,greater<pii>> que;
    rep(i,V)d[x][i] = INF;
    //fill(d[x],d[x]+V,INF);
    d[x][s] = 0;
    que.push(pii(0,s));
    while(!que.empty()){
        pii p = que.top();que.pop();
        int v = p.se;
        if(d[x][v] < p.fi) continue;
        rep(i,G[x][v].size()){
            edge e = G[x][v][i];
            if(d[x][e.to] > d[x][v]+e.cost){
                d[x][e.to] = d[x][v] + e.cost;
                que.push(pii(d[x][e.to],e.to));
            }
        }
    }
}
vector<pair<int,int>> cst;

signed main(){
    cin >> n >> m >> s >> t;
    s--;
    t--;
    V = n;
    rep(i,m){//m は edge数
        int u,v,a,b;
        cin >> u >> v >> a >> b;
      	u--;
      	v--;
      	edge e1 = {u,a};
      	edge e2 = {v,a};
        G[0][v].pb(e1);
        G[0][u].pb(e2);
        edge e3 = {u,b};
      	edge e4 = {v,b};
        G[1][v].pb(e3);
        G[1][u].pb(e4);
    }
    dijkstra(s,0);//yen
    dijkstra(t,1);//snuke

    rep(i,n){
        cst.pb(MP(d[0][i]+d[1][i],i));
    }

    SORT(cst);
    int num = 0;
    rep(i,n){
        while(cst[num].se < i){
            num++;
        }
        cout << 1000000000000000-cst[num].fi << endl;
    }
    
    return 0; 
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://arc064.contest.atcoder.jp/tasks/arc064_c
// rm -r -f test;oj dl http://soundhound2018-summer-qual.contest.atcoder.jp/tasks/soundhound2018_summer_qual_d

Measured memory_bytes: 19900
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

typedef long long int lli;
typedef pair<int, int> ii;

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

#ifdef LOCAL
	#define eprintf(...) printf(__VA_ARGS__)
#else 
	#define eprintf(...) 1
#endif

#define ROUNDUP(a, b) 		( ((a) + ((b) - 1) ) / b)
#define SET_ZERO(a)	 		( memset((a), 0, sizeof(a)))
#define SET_NUM_ARRAY(a,b)	( memset((a), b, sizeof(a)))
//#define int long long int //dont forget to change int to signed

template<typename T>T gcd(T a, T b) {
	T c;
	if (a < b) {
		a += b;
		b = a - b;
		a -= b;
	}

	while (b != 0) {
		c = a % b;
		a = b;
		b = c;
	}
	return a;
}
int main() {
	int N;
	scanf("%d", &N);
	lli ans = 1;
	for (int i = 0; i < N; i++) {
		lli l;
		scanf("%lld", &l);
		ans = ans / gcd<lli>(ans, l) * l;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////

int N, M, R;
int d[310][310];
vector<int>r;
int res;
int main() {
	cin >> N >> M >> R;
	r.resize(R);
	for (int i = 0; i < R; ++i) {
		cin >> r[i];
		r[i]--;
	}
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			if (i != j)d[i][j] = INF;
			else d[i][j] = 0;
		}
	}
	for (int i = 0; i < M; ++i) {
		int a, b, t;
		cin >> a >> b >> t;
		a--, b--;
		d[a][b] = t;
		d[b][a] = t;
	}
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			for (int k = 0; k < N; ++k) {
				d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
			}
		}
	}
	res = INF;
	sort(r.begin(), r.end());
	do {
		int key = 0;
		for (int i = 0; i < R - 1; ++i) {
			key += d[r[i]][r[i + 1]];
		}
		res = min(res, key);
	} while (next_permutation(r.begin(), r.end()));
	cout << res << endl;
	return 0;

}

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

int main()
{
	int N,A[100010]={};
	int ans=0;
	
	cin >> N;
	for(int i=0;i<N;i++)
	{
		cin >> A[i];
	}
	
	sort(A,A+N);
	
	int cnt=0;
	for(int i=0;i<N;i++)
	{
		cnt++;
		if(A[i]!=A[i+1])
		{
			ans+=(cnt%2);
			cnt=0;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std ;
#define ll long long int
int main(){
	ll n , m , i , x , y;
	cin >> n >> m ;
	bool flag = false ;
	vector<int>v(n + 1 , -1) ;
	if(n == 1 && m == 0)
		cout << "0" ;
	else{
        for(i = 0 ; i < m ; i++){
		cin >> x >> y ;
        if(v[x] == -1){
        	if(x == 1 && y == 0 && n > 1)
        	   flag = true ;
        	else
        	   v[x] = y ;
        }
        else{
        	if(y != v[x]){
        		flag = true ;
        	}
        }
	}
	if(!flag){
		for(i = 1 ; i <= n ; i++){
			if(v[i] == -1){
				if(i == 1)
				  v[i] = 1 ;
				else{
					v[i] = 0;
				}
			}
		}
		for(i = 1 ; i <= n ; i++){
		   cout << v[i] ;
	    }
	}
	else{
		cout << "-1" ;
	}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

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

using namespace std;

int main() {
    int A, B, C, D, E, K;
    cin >> A >> B >> C >> D >> E >> K;
    bool f = true;
    f &= abs(A-B) <= K;
    f &= abs(A-C) <= K;
    f &= abs(A-D) <= K;
    f &= abs(A-E) <= K;
    f &= abs(B-C) <= K;
    f &= abs(B-D) <= K;
    f &= abs(B-E) <= K;
    f &= abs(C-D) <= K;
    f &= abs(C-E) <= K;
    f &= abs(D-E) <= K;
    if (f) cout << "Yay!" << endl;
    else cout << ":(" << endl;
}


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

int main(){
  int N;
  vector<int> a;
  cin >> N;
  int tmp = 0;
  for(int i=0;i<N;i++){
    cin >> tmp;
    a.push_back(tmp);
  }
  sort(a.begin(), a.end());
  cout << a[N-1] - a[0] << endl;
}


Measured memory_bytes: 256
#include <iostream>
int main(){
  int n, c[501], s[501], f[501], a[501]={}, i=0,j, t;
  std::cin>>n;
  while(std::cin>>c[i]>>s[i]>>f[i])i++;
  for(i=0;i<n-1;++i){
    t=0;
    j=i;
    while(j<n-1){
      if(t<s[j])t=s[j];
      else if(t>=s[j]&&t%f[j]==0){t+=c[j];++j;}
      else ++t;
    }
    a[i] = t;
  }
  for(i=0;i<n;++i)std::cout<<a[i]<<"\n";
}

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

int main(){
    
    int x, y;
    cin >> x >> y;

    for (int i=0; i<=x; i++){
        int aleg = i*2;
        int bleg = (x-i)*4;

        if (aleg+bleg == y){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int,V,greater<int>>

#define pb(a) push_back(a)
#define mp make_pair

#define dump(x)  cout << #x << " = " << (x) << "\n";
#define COUT(x) cout<<(x)<<"\n"

int main()
{
    int n = 0;
    cin >> n;
    int ans = 0;
    vector<int> num(2);
    REP(i, n)
    {
        cin >> num[0] >> num[1];
        if (num[0] == num[1])
        {
            ans += 1;
        }
        else
        {
            ans += num[1] - num[0] + 1;
        }
    }

    COUT(ans);


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    int h,w;
    cin>>h>>w;
    int masu[h][w];
    int sum = 0;
    rep(i,h){
        rep(j,w){
            char c;
            cin>>c;
            if(c=='#'){
               sum++;
            }else{
                masu[i][j]=0;
            }
        }
    }
   
    
    if(sum != h+w-1){
        cout<<"Impossible"<<endl;
    }else{
        cout<<"Possible"<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
const int Rmax = 10;
const int Cmax = 10000;
int A[Rmax][Cmax];
int R,C;

int main(){
  while(true){
    cin >> R >> C;
    if(R==0&&C==0) break;
    for(int i=0; i<R; i++){
      for(int j=0; j<C; j++){
        cin >> A[i][j];
      }
    }

    int ans = 0;
    for(int i=0; i<(1<<R); i++){
      int column[Cmax];
      for(int k=0; k<C; k++) column[k] = 0;
      for(int j=0; j<R; j++){
        for(int k=0; k<C; k++){
          column[k] += (i>>j)%2 ? A[j][k] : (1-A[j][k]);
        }
      }
      int sum = 0;
      for(int k=0; k<C; k++){
        //cout << column[k] << " ";
        sum += max(column[k], R-column[k]);
      }
      //cout << endl;
      ans = max(ans, sum);
    }

    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3416
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int W[105];
int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  for (int i=0; i<N; i++) {
    cin >> W[i+1];
    W[i+1] += W[i];
  }
  int ret = W[N];
  for (int i=0; i<N; i++) {
    ret = min(ret, abs((W[N]-W[i+1])-W[i+1]));
  }
  cout << ret << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream& operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream& operator<<(ostream &os, vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream& operator<<(ostream &os, set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream& operator<<(ostream &os, pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream& operator<<(ostream &os, map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

int N, M;
constexpr int Nmax = 100001;
bitset<Nmax> ok;
vector<int> to[Nmax];

int main()
{
    cin >> N >> M;
    REP(_, M)
    {
        int a, b;
        cin >> a >> b;
        to[a].push_back(b);
        to[b].push_back(a);
    }

    deque<int> ans;
    int now = 1;
    ans.push_back(now);
    ok.set(now);
    while (true)
    {
        bool flg = true;
        for (auto nxt : to[now]) if (!ok[nxt])
        {
            now = nxt;
            ans.push_back(now);
            ok.set(now);
            flg = false;
            break;
        }
        if (flg) break;
    }

    now = 1;
    while (true)
    {
        bool flg = true;
        for (auto nxt : to[now]) if (!ok[nxt])
        {
            now = nxt;
            ans.push_front(now);
            ok.set(now);
            flg = false;
            break;
        }
        if (flg) break;
    }

    cout << ans.size() << endl;
    for (auto v : ans) cout << v << " ";
    cout << endl;
}


Measured memory_bytes: 6784
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

#include <cmath>
#include <cstdlib>
#include <climits>

//#include <stdio.h>
//#include <stdlib.h>
//#include "show_vector.hh"


using namespace std;

#define debug false

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

  vector<pair<int, int> > cand;
  int N, T;
  cin >> N >> T;
  int n, t;
  //cout << "N * " << N << endl;
  for(int i = 0; i < N; i++){
    cin >> n >> t;
    if(t <= T){
      cand.push_back(make_pair(n, t));
    }
  }

  if(cand.size() == 0){
    cout << "TLE" << endl;
  }else{
    sort(cand.begin(), cand.end());
    cout << cand[0].first << endl;
  }

  return 0;
}
/*
3 70
7 60
1 80
4 50
*/

Measured memory_bytes: 256
def main():
    DIFF = 400

    N = int(input())

    ctr = [0] * 9
    for x in map(int, input().split()):
        ctr[min(x // DIFF, 8)] += 1

    le_red = sum(c > 0 for c in ctr[:8])
    gt_red = ctr[8]

    if gt_red:
        if le_red:
            print(le_red, le_red + gt_red)
        else:
            print(1, gt_red)
    else:
        print(le_red, le_red)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<cctype>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<ctime>

using std::cout;
using std::endl;
using std::cin;
using std::sort;
using std::queue;
using std::stack;
using std::set;
using std::vector;
using std::string;
using std::priority_queue;
using std::deque;
using std::pair;


int main(int argc, char** argv)
{
	if (argc == 2 && strcmp(argv[1], "-debug") == 0)
	{
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	}


	char s[100001];
	cin >> s;
	int len = strlen(s);
	int ans = len;
	for (int i = 0; i < len - 1; i++)
		if (s[i] != s[i + 1])
			ans = std::min(ans, std::max(i + 1, len - 1 - i));
	cout << ans;

	return 0;
}


Measured memory_bytes: 384
from bisect import bisect_left
import sys
sys.setrecursionlimit(10**7)

def input(): return sys.stdin.readline().strip()

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

INF = 999999999999999999999999

n = int(input())
A = [-INF] + get_nums_l()

# log(n)
# log(A)

edges = [ [] for _ in range(n+1) ]
for _ in range(n-1):
#for line in map(lambda s: s.strip(), sys.stdin.readlines()):
    line = input().strip()
    # log(line)
    u,v = map(int, line.split())
    edges[u].append(v)
    edges[v].append(u)

def dfs(dp, u, p=None):

    # log(u)
    # log(dp)

    # dpの中でA[u]以上の値が入っている最小のindex
    i = bisect_left(dp, A[u])

    old = dp[i]
    dp[i] = A[u]

    # 有効値(INF以外)が入っている最大のindex
    ans[u] = bisect_left(dp, INF) - 1

    for v in edges[u]:
        if v == p:
            continue
        dfs(dp, v, u)

    # 巻き戻し
    dp[i] = old

# ans[i] = ノード1からノードiへの経路中の最長増加部分列長
ans = [0] * (n+1)

# dp[i] = 最長増加部分列長がiの場合の末尾ノード値の最小
# dp[0]は使用しないので負の無限大を入れておく
dp = [INF] * (n+1)
dp[0] = -INF

dfs(dp, 1, None)

for i in range(1, n+1):
    print(ans[i])


Measured memory_bytes: 350892
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

bool isPalindrome(int x){
  string s = to_string(x);
  int n=s.length();
  bool ret=true;
  repeat(i,(n+1)/2){
    ret &= s[i]==s[n-1-i];
  }
  return ret;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b;cin>>a>>b;
  int n = b-a;
  cout << n*(n+1)/2-b << endl;
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)
	b := make([]int, n)
	a := make([]int, n)
	c := make([]int, n-1)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
	}
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &b[i])
	}
	for i := 0; i < n-1; i++ {
		fmt.Scanf("%d", &c[i])
	}
	sum := 0
	for i, v := range a {
		sum += b[v-1]
		if i > 0 {
			if v == a[i-1] + 1 {
				sum += c[a[i-1]-1]
			}
		}
	}
	fmt.Println(sum)
}

Measured memory_bytes: 512
import java.io.*;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
    //Solution by Sathvik Kuthuru
    public static void main(String[] args) {
        FastReader scan = new FastReader();
        PrintWriter out = new PrintWriter(System.out);
        Task solver = new Task();
        int t = 1;
        for(int tt = 1; tt <= t; tt++) solver.solve(tt, scan, out);
        out.close();
    }

    static class Task {

        public void solve(int testNumber, FastReader scan, PrintWriter out) {
            int n = scan.nextInt();
            int[] a = new int[n + 1];
            for(int i = 0; i < n - 1; i++) a[scan.nextInt()]++;
            for(int i = 1; i <= n; i++) out.println(a[i]);
        }
    }

    static void shuffle(int[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            int temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }

    static void shuffle(long[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            long temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(new File(s)));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}

Measured memory_bytes: 54532
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
//////////////////////////////////////////////////////////////////////////////////////////////////////////

bool f(string S, string T) {
    if (S.size() != T.size()) {
        return S.size() < T.size();
    }
    int N = S.size();
    rep(i,N) {
        if (S[i] != T[i]) {
            return S[i] - T[i] < 0;
        }
    }
    return true;
}
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    while (1) {
        int W,H; cin >> W >> H;
        if (W+H==0) break;
        vector<string> S(H);
        rep(i,H) cin >> S[i];

        vector<vector<string>> dp(H+1, vector<string>(W+1,""));
        rep(i,H) {
            rep(j,W) {
                if (S[i][j] - '0' < 0 || 9 < S[i][j] - '0') continue;
                if (dp[i+1][j] == "" && dp[i][j+1] == "" && S[i][j] == '0') continue;
                if (f(dp[i+1][j],dp[i][j+1])) dp[i+1][j+1] = dp[i][j+1] + S[i][j];
                else dp[i+1][j+1] = dp[i+1][j] + S[i][j];
            }
        }
        string ans = "";
        rep(i,H) {
            rep(j,W) {
                if (f(ans,dp[i+1][j+1])) ans = dp[i+1][j+1];
            }
        }

        cout << ans << endl;
    }
}


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

typedef long long ll;

string s;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> s;
    int res = 0;
    for (auto c : s) {
        if (c == 'A')
            res |= 1;
        else
            res |= 2;
    }

    if (res == 3)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}



Measured memory_bytes: 256
k = int(input())
a = list(map(int, input().split()))
if a[-1] != 2:
    print(-1)
    quit()
l, r = 2, 3
for i in range(k-2, -1, -1):
    s = ((l-1)//a[i]+1) * a[i]
    if s > r:
        print(-1)
        quit()
    t = ((r-1)//a[i]+1) * a[i]
    t = t-1 if t > r else t+a[i]-1
    l, r = s, t
print(l, r)

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

int main(){
    int n;cin>>n;
    int a[n];
    rep(i,n)cin>>a[i];
    bool inc=true;
    rep(i,n-1)if(a[i]>=a[i+1])inc=false;
    if(inc){
        cout<<1<<endl;
        return 0;
    }
    int ng=1,ok=n;
    while(ok-ng>1){
        int mid=(ok+ng)/2;
        vector<pair<int,int>> v;
        v.emplace_back(-1,-1);
        bool can=true;
        rep(i,n-1){
            if(a[i]<a[i+1])continue;
            int m=a[i+1];
            while(v.back().first>m)v.pop_back();
            while(v.back().first==m&&v.back().second==mid-1)v.pop_back(),--m;
            if(m==v.back().first)++v.back().second;
            else if(m)v.emplace_back(m,1);
            else {
                can=false;
                break;
            }
        }
        if(can)ok=mid;
        else ng=mid;
    }
    cout<<ok<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define P pair<int, int>
#define llong long long
int main(){
    int N;
    llong K;
    int a[100010], b[100010];
    cin >> N >> K;

    for(int i = 0; i < N; ++i){
        cin >> a[i] >> b[i];
    }

    vector<P> data;
    for(int i = 0; i < N; ++i){
        data.emplace_back(a[i], b[i]);
    }

    sort(data.begin(), data.end());
    
    int ans = 0;
    for(int i = 0; i < data.size(); ++i){
        if(data[i].second >= K){
            cout << data[i].first << endl;
            return 0;
        }
        K -= data[i].second;
    }

    return 0;
}

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

//Segment Tree for Range Maximum Query
class SegmentTree{
  int n;
  vl node;
public:
  SegmentTree(int n_){
    n=1;
    while(n<n_)n*=2;
    node = vl(2*n-1,-1e9);
  }

  void update(int k, ll v){
    int cur = k + n-1;
    node[cur] = v;
    while(cur>0){
      cur = (cur-1)/2;
      node[cur] = max(node[cur*2+1],node[cur*2+2]);
    }
  }

  //return maximum value in [a,b). ( [l,r) is interval in which k is.)
  ll RMQ(int a,int b,int k=0,int l=0,int r=0){
    if(l>=r)r = n;
    if(r<=a || b<=l)return -1e9;
    if(a<=l && r<=b)return node[k];
    ll vl = RMQ(a,b,2*k+1,l,(l+r)/2);
    ll vr = RMQ(a,b,2*k+2,(l+r)/2,r);
    return max(vl,vr);
  }
};

int main(){
  int n,m;
  while(scanf("%d%d",&n,&m), n){
    vl s(n+1,0);
    rep(i,n){
      scanf("%lld",&s[i+1]);
      (s[i+1] += s[i]) %= m;
    }
    
    vector<pll> ord(n);
    rep(i,n){
      ord[i] = pll(s[i+1],i);
    }
    sort(ord.begin(),ord.end());
    
    SegmentTree st(n);
    ll res = 0;
    rep(i,n){
      ll v = ord[i].first, p = ord[i].second;
      res = max(res, v);
      res = max(res, st.RMQ(p+1,n) + m-v);
      st.update(p,v);
    }
    printf("%lld\n",res);
  }
}

Measured memory_bytes: 2340
#include <stdio.h>


int main(void) {
	
	int a, b, c ;
	scanf( "%d %d %d", &a, &b, &c ) ;
	
	if ( a == 5 && b == 5 && c == 7) {
		printf( "YES\n" ) ;
	} else if ( a == 5 && b == 7 && c == 5) {
		printf( "YES\n" ) ;
	} else if ( a == 7 && b == 5 && c == 5) {
		printf( "YES\n" ) ;
	} else { 
		printf( "NO\n" ) ;
	}
	
	return 0 ;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define N 100005
#define Ms(a,b) memset(a,b,sizeof a);
#define db(x) cout<<#x<<"="<<x<<endl;
using namespace std;
int n,a[N],b[N];
int t[N],ans;
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),b[i]=a[i];
	sort(b+1,b+1+n);
	int len=unique(b+1,b+1+n)-b-1;
	for(int i=1;i<=n;i++){
		a[i]=lower_bound(b+1,b+1+len,a[i])-b;
		int l=1,r=i-1,res=0;
		while(l<=r){
			int mid=l+r>>1;
			if(t[mid]<a[i])r=mid-1;
			else l=mid+1,res=mid;
		}
		t[res+1]=a[i];
		ans=max(ans,res+1);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())

using namespace std;
typedef long long  ll;

int main(){
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for(int &x : a)
        cin >> x;

    int g = 0;
    for(int x : a)
        g = __gcd(x , g);


    cout << g << "\n";
}


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

using namespace std;

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

    int N;

    cin >> N;
    vector<long long> A(N);

    rep(i, N)
    {
        cin >> A[i];
    }

    unordered_map<long long, long long> hm;
    rep(i, N)
    {
        hm[A[i]]++;
    }

    long long all = 0;
    for (auto it : hm)
    {
        long long v = it.second;
        all += (v * (v - 1)) / 2;
    }

    rep(i, N)
    {
        long long t = hm[A[i]];
        long long m = (t * (t - 1)) / 2;
        long long n = ((t - 1) * (t - 2)) / 2;

        cout << all - m + n << endl;
    }
}


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

int main(){
  int n;
  int a[101];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int ct=0;
  int lc=0;
  while(1==1){
    while(a[lc]!=a[lc+1]&&lc<n){
      lc++;
    }
    int line=1;
    while(a[lc]==a[lc+line]){
      line++;
    }
    ct+=line/2;
    lc=lc+line;
    if(lc>n-2){break;}
  }
  cout<<ct<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

const lli MOD = 1000000007;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;

int main() {
	int N, A, B;
	cin >> N >> A >> B;

	cout << min(N * A, B) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
int main(){
  int u,k,C,V,D[1000][1000],n;
  std::cin >> n;
  for(int i=0;i<n;i++)for(int j=0;j<n;j++)D[i][j] = 200001;
  for(int i=0;i<n;i++){     std::cin >> u >> k;
    for(int j=0;j<k;j++){   std::cin >> V >> C;
      D[u][V] = C;}}
  for(int i=0;i<n;i++)D[i][i] = 0;
  for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)D[i][j]= std::min(D[i][j],D[i][k] + D[k][j]);
  for(int i=0;i<n;i++)std::cout << i << " " << D[0][i] << std::endl;
  return 0;
}

Measured memory_bytes: 0
/*
  The Island Was Silent before.
  .....
  And One day again it became Silent.
*/
#include<bits/stdc++.h>
using namespace std;
 
#define endl '\n'
#define ll  long long
#define modd(a,b) ((a+2*b)%b)
#define debug(a) cout << #a << ": " << (a) << "\n"
#define ioso ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define rtt cerr << "Time: " << clock()*1.0 / CLOCKS_PER_SEC << endl;
#define ffe freopen("input.txt","r",stdin), freopen("output.txt","w",stdout);
 
int main() {
  ioso
  #ifndef ONLINE_JUDGE
 // ffe
  #endif
  string s; cin >> s;

  if(isupper(s[0])) {
    cout << "A" << endl;
  }
  else {
    cout << "a" << endl;
  }
}

Measured memory_bytes: 3608
import java.lang.Math.ceil


fun main(args: Array<String>) {
    val input = readLine()!!.split(" ").map { it.toInt() }
    val a = input[0]
    val b = input[1]

    val x:Double = (a.toDouble() + b.toDouble()) / 2
    print(ceil(x).toInt())
}

Measured memory_bytes: 37732