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

int main() {
  int a,b,c,d,e,k;
  cin >> a >> b >>c >>d >> e >>k;
  if (b-a > k){
    cout << ":(";
  }
  else if(c-b > k){
 	cout << ":(";
  }
  else if(c-a > k){
 	cout << ":(";
  }
  else if(d-c > k){
 	cout << ":(";
  }
  else if(d-b> k){
 	cout << ":(";
  }
  else if(d-a> k){
 	cout << ":(";
  }
  else if(e-d> k){
 	cout << ":(";
  }
  else if(e-c> k){
 	cout << ":(";
  }
  else if(e-b> k){
 	cout << ":(";
  }
  else if(e-a> k){
 	cout << ":(";
  }
  else {
    cout << "Yay!";
  }

}

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

int main(){
	int n;
	while(scanf("%d",&n),n){
		vector < int > vi;
		for(int i = 0; i < n; i++){
			int tmp;
			scanf("%d",&tmp);
			vi.push_back(tmp);
		}
		sort(vi.begin(),vi.end());
		double ave = 0.0;
		for(int i = 1; i < n-1 ;i++){
			ave += vi[i];
		}
		printf("%.0lf\n",floor(ave/(n-2)));
	}
	return 0;
}

Measured memory_bytes: 1084
// Princess's Marriage
#include <iostream>
#include <utility>
#include <algorithm>
using namespace std;
int N, M;
pair<int,int> PD[10010];
pair<int,int> PD2[10010];
int main() {
  while (cin >> N >> M && N) { 
    int d, p;
    for (int i=0; i<N; ++i) {
      cin >> d >> p;
      PD[i] = make_pair(p, d); 
      // PD[i].first ??????i?????±?????? p
      // PD[i].second ??????i?????????  d
    }
    sort(PD,PD+N); // PD ?????§??????????????´????????????
    for (int i=0;i<N; ++i)
      PD2[N-i-1] = PD[i];
    int S = 0;
    for (int i=0; i<N; ++i)
      S += PD2[i].first * PD2[i].second;
    // ??????0?????????????????????,?????¨???S??????
    for (int i=0; i<N; ++i) {
      if (M <= 0) break;
      int guarded = min(M,PD2[i].second); // ????????????
      S -= PD2[i].first * guarded;
      M -= guarded;
    }
    cout << S << endl;
  }
}

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

int main() {
	int n;
	string s,t, ans;
	cin >> n;
	cin >> s >> t;
	int kiri = 0, kanan = 0;
	for(int i=0; i<n*2; i++) {
		if(i % 2 == 0) {
			ans += s[kiri];
			kiri++; 
		}else {
			ans += t[kanan];
			kanan++;
		}
	}
	cout << ans << '\n';
	return 0;
}

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

typedef long long ll;
bool query(ll x){cout<<"? "<<x<<endl;string s;cin>>s;return s[0]=='Y';}
void output(int x){cout<<"! "<<x<<endl;exit(0);}

int f[100];
int main(){
	f[0]=1;
	for(int i=1,j=10;i<=9;++i,j*=10)f[i]=query(j);
	if(!f[9]){
		for(int i=1,j=10;i<=9;++i,j*=10)
			if(!f[i]){
				ll l=j,r=j*10ll-1;
				while(l<r){
					ll mid=(l+r)/2;
					if(query(mid))r=mid;
					else l=mid+1;
				}
				output(l/10);
			}
	}else{
		int l=0,r=100000000;
		while(l<r){
			int mid=(l+r)/2;
			if(query(10*mid+2))r=mid;
			else l=mid+1;
		}
		output(max(1,l*10));
	}
	return 0;
}


Measured memory_bytes: 596
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
inline ll lin() { ll x; scanf("%lld",&x); return x;}
inline char chin() { char x; scanf("%c",&x); return x;}
inline string stin() { string x; cin >> x; return x;}
inline double din() { double x; scanf("%lf",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
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; }
char itoa(int n) { return n + '0';}
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 main () {
  string s = stin();
  if (s == "ABC") puts("ARC");
  else puts("ABC");
  return 0;
}

Measured memory_bytes: 3592
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def inv(x):
    return pow(x, mod - 2, mod)

nm = {}
nm[0] = 1
def nCr_(n):
    b = n // 2 + 1
    r = 1
    d = 1
    for k in range(1,b+1):
        r = r * (n-k+1) % mod
        d = d * k % mod
        nm[k] = r * inv(d) % mod

def nCr(n, b):
    if b > n - b:
        b = n - b
    return nm[b]

def main():
    n,a,b,k = LI()
    r = 0
    nCr_(n)
    for i in range(n+1):
        ai = a * i
        bi = k - ai
        if bi < 0 or bi % b > 0 or bi // b > n:
            continue
        bb = bi // b
        r += nCr(n,i) * nCr(n,bb)
        r %= mod

    return r


print(main())



Measured memory_bytes: 80748
import itertools

n = int(input())

keta = 1
abc_list = 'abcdefghijklmnopqrstuvwxyz'
c = 0
while keta < 17:
    c += 26 ** keta
    # print(keta)
    if n <= c:
        # print('keta', keta)
        num = (26 ** keta) - (c-n)-1
        # print('num', num)
        # print('   ', 26 ** keta)
        # print(befor)
        i_t = 0
        # print(i_list)
        ans = ''
        for i in range(keta-1, -1, -1):
            # print('i', i, num, (num // (26**i)))
            idx = num // (26 ** (i))
            # print(idx, abc_list[idx])
            ans += abc_list[idx]
            num -= (num // (26 ** i)) * (26 ** i)
        print(ans)
        break

    keta += 1


Measured memory_bytes: 9196
#include <iostream>

using namespace std;

int main(){
  int n;
  while(true){
    cin >> n;
    if(n==0)
      break;
    int tsk = 0, ss=0;
    bool dd = true;
    for(int i=0; i<12; i++){
      int a, b;
      cin >> a >> b;
      tsk += (a-b);
      if(tsk >= n && dd){
	ss = i+1; dd = false;
      }
    }
    if(ss == 0)
      cout << "NA\n";
    else
      cout << ss << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;

/**
 * @author munkhbat
 * AOJ 0121
 * 7 puzzle
 * calculate from reverse. calculate all minimum move count from state "01234567" to every state.
 */
public class Main {
	private static int[] d = new int[]{1, -1, 4, -4};
	
	/**
	 * key : puzzle state, value : minimum move count of hand.
	 */
	private static Map<String, Integer> map;
	private static String state;

	public static void main(String[] a) {
		map = new HashMap<String, Integer>();
		bfs();
		Scanner sc = new Scanner(System.in);

		while (sc.hasNext()) {
			StringBuilder sb = new StringBuilder();
			for (int i = 0; i < 8; i++) {
				sb.append(sc.nextInt());
			}
			state = sb.toString();
			System.out.println(map.get(state));
		}
		sc.close();
	}
	
	private static int getInitialPos(String str) {
		return str.indexOf('0');
	}
	
	private static void bfs() {
		Queue<String> queue = new LinkedList<String>();
		queue.add("01234567");
		map.put("01234567", 0);
		int initialPos = 0;
		
		while (queue.size() > 0) {
			String p = queue.poll();
			
			initialPos = getInitialPos(p);
			
			for (int i = 0; i < 4; i++) {
				int pos = initialPos + d[i];
				if (pos < 0 || pos >= 8) {
					continue;
				}
				
				if (initialPos == 3 && pos == 4) {
					continue;
				}
				
				if (initialPos == 4 && pos == 3) {
					continue;
				}
				
				char[] tmp = p.toCharArray();
				tmp[initialPos] = p.charAt(pos);
				tmp[pos] = '0';
				String newStr = new String(tmp);
				if (map.get(newStr) == null) {
					queue.add(newStr);
					map.put(newStr, map.get(p) + 1);
				}
			}
		}
	}
}

Measured memory_bytes: 38612
dollar = int(input())

can = False
for cakes in range(int(dollar / 4) + 1):
  for donuts in range(int(dollar /7) + 1):
    price = 4 * cakes + 7 * donuts
    if price == dollar:
      can = True
      break
    elif price > dollar:
      break
  if can == True:
    break
    
print("Yes" if can == True else "No")

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

int main(){
    ll N;
    cin >> N;
    int n = pow(N,0.5);
    ll A,B;
    int Acnt,Bcnt;
    int Ans = 10000000;
    for (int i = 1; i <= n; i++)
    {
        if(N%i == 0){
            A = i;
            B = N/i;
            Acnt = 0;
            Bcnt = 0;
            while(A>0){
                Acnt++;
                A/=10;
            }
            while(B>0){
                Bcnt++;
                B/=10;
            }
            Ans = min(Ans, max(Acnt, Bcnt));
        }
    }
    cout << Ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n;
  list <char> s; 
  cin>>n;
  while(n){
    n--;
    s.push_front('a'+n%26);
    n/=26;
  }
  string ss(s.begin(), s.end());
  cout<<ss<<endl;
  return 0;
}

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

int main()
{ 
  string s;
  int n = 1000;

  cin >> s;
  for (int i = 0; i < s.size() - 2; i ++)
    n = min(n, abs(753 - stoi(s.substr(i, 3))));
  cout << n << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

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

	d := 1000000000
	if d == s {
		d = 1
	}

	for i := 0; i < n; i++ {
		if i < k {
			fmt.Printf("%d ", s)
		} else {
			fmt.Printf("%d ", d)
		}
	}
	fmt.Println()
}


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

int main(void){

    char S[11],T[11],U[11];
    int A,B,i;

    scanf("%s %s",S,T);
    scanf("%d %d",&A,&B);
    scanf("%s",U);

    if(strcmp(S,U) == 0){
        A--;
    }else{
        B--;
    }


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

Measured memory_bytes: 128
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n,m=INTM()
    road=[]
    for i in range(m):
        a,b=INTM()
        road.append(a)
        road.append(b)
    for i in range(n):
        ct=road.count(i+1)
        print(ct)
if __name__ == '__main__':
    do()

Measured memory_bytes: 3064
require 'matrix'


n, m= gets.split.map(&:to_i)

a = n.times.map do
      gets.split.map(&:to_i)
    end

b = m.times.map do
      gets.split.map(&:to_i)
    end

ma = Matrix.rows(a)
mb = Matrix.rows(b)
mc = ma * mb


mc.row_vectors.each {|row| puts row.to_a.join("\s")}


Measured memory_bytes: 7632
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,k;
    cin>>a>>b>>k;
    if(k<a){
        cout << a-k<<" "<<b<<endl;
    }else{
        k-=a;
        cout << 0<<" ";
        if(k<b){
            cout << b-k<<endl;
        }else{
            cout<< 0<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> bkt(N,0);
  
  for (int i=0; i<N; i++){
    int a;
    cin >> a;
    bkt.at(a-1)++;
  }
  for (int i=0; i<N; i++){
//    cout << bkt.at(i) << "-";
  }
  sort(bkt.begin(), bkt.end());
  int bcount =0;
  
  for (int i=0; i<N; i++){
//    cout << bkt.at(i) << "-";
    if(bkt.at(i) != 0) bcount++;
  }
//  cout << endl;
//  cout << bcount << endl;
  int ans = 0;
  if (bcount <= K){
    cout << ans <<endl;
    return 0;
  }
  
  for (int i=0; i<N; i++) {
    if(bkt.at(i) != 0){
      ans += bkt.at(i);
      bcount--;
    }
    if (bcount == K) break;
  }
  
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4052
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))

def main():
    n = II()
    aa = MII()
    aa = [0] + aa + [0]
    g = {i: abs(aa[i+1]-aa[i]) for i in range(n+1)}
    ng = {i: abs(aa[i+2]-aa[i]) for i in range(n)}
    sumv = sum(g.values())
    for i in range(n): print(sumv - (g[i] + g[i+1]) + ng[i])

if __name__ == '__main__':
    main()


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

int main()
{
    int K, A, B;
    cin >> K;
    cin >> A >> B;
    for(int i = A; i <= B; i++) {
        if(i%K == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;

int main(){
	 int a,b,c; cin >>a>>b>>c;
	 if(a<c&&c<b)cout<<"Yes"<<endl;
	 else if(a>c&&c>b)cout<<"Yes"<<endl;
     else cout <<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cfloat>

using namespace std;

long long a, b;

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

bool isprime(long long num)
{
	if (num == 2)
		return true;
	for (int i = 2; i <= sqrt(num) + 0.5; i++)
	{
		if (num % i == 0)
			return false;
	}
	return true;
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> a >> b;
	long long grd = gcd(a, b);
	int cnt = 1;
	if (grd == 1LL)
	{
		cout << "1" << endl;
		return 0;
	}
	if (isprime(grd))
	{
		cout << "2" << endl;
		return 0;
	}
	for (int i = 2; i <= sqrt(grd) + 0.5; i++)
	{
		if (grd % i == 0 && grd / i >= i)
		{
			if (isprime(i))
				cnt++;
			if (grd / i > i && isprime(grd / i))
				cnt++;
		}
	}

	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
S = str(input())
A = 'ACGT'
L = len(S)

cnt = 0
max_cnt = 0
for x in S:
    if x in A:
        cnt += 1
    else:
        if max_cnt < cnt:
            max_cnt = cnt
        cnt = 0
if max_cnt < cnt:
    max_cnt = cnt

print(max_cnt)


Measured memory_bytes: 2940
'use strict'

const main = arg => {
    const input = arg.trim().split("\n");
    var isBreak = false;
    const result = input.map(str => {
        const data = str.split(" ");
        const a = Number(data[0]);
        const b = Number(data[2]);
        if(isBreak){ return false; }
        switch(data[1]){
            case "+":
                return a + b;
            case "-":
                return a - b;
            case "*":
                return a * b;
            case "/":
                return Math.floor(a / b);
            case "?":
                isBreak = true;
                return false;
        }
    }).filter(obj => obj !== false);

    console.log(result.join("\n"));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 15384
#include <iostream>
#include <algorithm>
using namespace std;
#define MAX_N 200001

int N;
long int left_value, right_value;
long int X[MAX_N];
long int Y[MAX_N];
int main(){
    cin >> N;
    for (int i = 0; i < N; i++){
        cin >> X[i];
    }

    for (int i = 0; i < N; i++){
        Y[i] = X[i];
    }
    sort(Y, Y + N);
    left_value = Y[N/2 - 1];
    right_value = Y[N/2];
    // cout << left_value << right_value << endl;
    for (int i = 0; i < N; i++){
        if (X[i] <= left_value){
            cout << right_value << endl;
        }else{
            cout << left_value << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod_) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod_;
		}
		x = x * x % mod_;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}
/*--------Library Zone!--------*/

struct union_find {
	int par[214514], size_[214514];
	union_find(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};

int n, m;
int a[114514];
signed main() {
	cin >> n >> m;
	REP(i, n + 1)cin >> a[i];
	union_find uf(n + 1);
	rep(i, m) {
		int b, c; cin >> b >> c; uf.unite(b, c);
	}
	int ans = 0;
	REP(i, n + 1) {
		if (uf.find(i) == uf.find(a[i]))ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3712
/*

	Raghul
	
*/	
#include<bits/stdc++.h>
using namespace std;
#define ll long long
void solve(){
	  ll n,h,w;
	  cin>>n>>h>>w;
	  ll ans = (n-h+1) * (n-w+1);
	  cout<<ans;
}
int main(){
	int T;
	T = 1;
	while(T--){
		solve();
	}
	return 0;
}
/*}
int main(){
	int T;
	T = 1;
	while(T--){
		solve();
	}
	return 0;
}*/

Measured memory_bytes: 256
#include <iostream>
#include <map>
 
int main(){
	int n;
	std::cin >> n;
	std::map<int, int> mp;
	for(int i=0; i < n; i++){
		int a;
		std::cin >> a;
		auto itr = mp.find(a);
		if(itr != mp.end()){
			itr->second = 0;
			mp.erase(itr);
		}
		else{
			mp[a] = 1;
		}
	}
	int c = 0;
	for(auto x : mp){
		c += x.second;
	}
	std::cout << c;
	return 0;
}

Measured memory_bytes: 4992
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;

int ConvStrToInt(char c)
{
	if ('0' <= c && c <= '9') return (c - '0');
	return -1;
}
struct INFO
{
public:
	int belong;		// 0か1か
	int value;
	INFO()
	{
		belong = 0;
		value = 0;
	}
};


int checkStr(int startIndex, int changeValueNum, vector<INFO>& vInfo, vector<int>& vSum)
{
	int resultValue = 0;

	int counter = 0;
	for (int i = startIndex;i < vInfo.size(); ++i)
	{
		if (counter >= changeValueNum)
		{
			resultValue += vInfo[i].value;
			break;
		}

		if (vInfo[i].belong == 0)
		{
			++counter;
		}
		resultValue += vInfo[i].value;
	}

	return resultValue;
}


int main() {
	int N, K;
	string S;
	cin >> N >> K;
	cin >> S;

	// 先頭は1にしたい
	vector<INFO> vInfo;
	if (ConvStrToInt(S[0]) == 0)
	{
		INFO info;
		info.belong = 1;
		info.value = 0;
		vInfo.push_back(info);
	}

	for (int i = 0; i < N;)
	{
		INFO info;
		info.belong = ConvStrToInt(S[i]);
		for (int j = i;; ++j)
		{
			if (ConvStrToInt(S[j]) == info.belong)
			{
				++info.value;
			}
			else
			{
				i = j;
				break;
			}
		}
		vInfo.push_back(info);
	}

	// 最後は0にしたい
	if (vInfo.size() % 2 == 0)
	{
		INFO info;
		info.belong = 0;
		info.value = 0;
		vInfo.push_back(info);
	}

	int Add = 2 * K + 1;


	// 累積和
	vector<int> vSum(vInfo.size() + 1, 0);
	for (int i = 1; i < vSum.size(); ++i)
	{
		vSum[i] = vSum[i - 1] + vInfo[i - 1].value;
	}

	int ans = 0;
	//1-0-1...の1から始めるので、偶数番目だけ見る
	//for (int i = 0; i < vInfo.size(); i += 2)
	//{
	//	//次のleft, rightを計算する [left, right)
	//	int left = i;
	//	int right = min(i + Add, (int)vInfo.size());
	//	int tmp = vSum[right] - vSum[left];

	//	ans = max(tmp, ans);
	//}
	for (int i = 0;i< vInfo.size(); i += 2)
	{
		int left = i;
		int right = min(i+(K*2+1), (int)vInfo.size());
		int diff = vSum[right] - vSum[left];
		ans = max(ans, diff);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

int n, D[2];

vector<pp> d[2];

int iro[600][600][2];
char vis[600][600][2];

int cnt[4];

void dfs(int x, int y, int di){
	vis[x][y][di]=1;
	for(auto t:d[di]){
		int dx, dy; tie(dx, dy) = t;
		int nx=x+dx, ny=y+dy;
		if(0<=nx && 0<=ny && nx<2*n && ny<2*n){
			if(!vis[nx][ny][di]){
				iro[nx][ny][di] = iro[x][y][di] ^ 1;
				dfs(nx, ny, di);
			}
		}
	}
}

int main()
{
	read(n, D[0], D[1]);
	const int n2 = n*2;
	for(int di=0; di<2; ++di){
		for(int dx=0; dx<n2; ++dx) for(int dy=0; dy<n2; ++dy){
			if(dx*dx + dy*dy == D[di]){
				d[di].eb(dx, dy);
				d[di].eb(dx, -dy);
				d[di].eb(-dx, dy);
				d[di].eb(-dx, -dy);
			}
		}
	}
	
	for(int i=0; i<n2; ++i) for(int j=0; j<n2; ++j){
		for(int di=0; di<2; ++di) if(!vis[i][j][di]) dfs(i, j, di);
		++cnt[(iro[i][j][0]<<1)|iro[i][j][1]];
	}
	
	for(int i=0; i<4; ++i) if(cnt[i]>=n*n){
		int cc=0, tg=n*n;
		for(int x=0; x<n2; ++x){
			for(int y=0; y<n2; ++y){
				if(((iro[x][y][0]<<1)|iro[x][y][1]) == i){
					printf("%d %d\n", x, y);
					if(++cc == tg) return 0;
				}
			}
		}
	}
	return 0;
}


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

using namespace std;

int v[3];

int main() {
    //std::ifstream cin("A.in");
    //std::ofstream cout("A.out");
   // int ;
    std::ios::sync_with_stdio(false);
    cin >> v[0] >> v[1] >> v[2];
    sort(v, v + 3);
    if(v[0] == 5 && v[1] == 5 && v[2] == 7)
        cout << "YES" << std::endl;
    else
        cout << "NO" << std::endl;
    //cin.close();
    //cout.close();
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int H, W;
    while (true) {
      H = sc.nextInt();
      W = sc.nextInt();
      if (H == 0 && W == 0) break;
      for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
          System.out.print('#');
        }
        System.out.println();
      }
      System.out.println();
    }
  }
}


Measured memory_bytes: 39472
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N, M = list(map(int, sys.stdin.buffer.readline().split()))
A = list(map(int, sys.stdin.buffer.readline().split()))

A.sort()
A = np.array(A, dtype=int)
cs = A[::-1].cumsum()[::-1]


def test(k):
    # 幸福度が k 以上になる握手を採用する
    counts = N - np.searchsorted(A, k - A)
    return counts.sum() >= M


def count(k):
    counts = N - np.searchsorted(A, k - A)
    cnt = counts.sum()

    pos = np.searchsorted(A, k - A)
    ret = ((A * counts)[pos < N] + cs[pos[pos < N]]).sum()
    ret -= abs(M - cnt) * k
    return ret


ok = 0
ng = max(A) * 2 + 1
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if test(mid):
        ok = mid
    else:
        ng = mid

ans = count(ok)
print(ans)


Measured memory_bytes: 22680
#include<bits/stdc++.h>
using namespace std;
int n;
int main()
{
	cin>>n;
	int cnt=0,a=0,b=0,ba=0;
	for(int i=1;i<=n;i++)
	{
		string s;
		cin>>s;
		if(s[0]=='B')
			b++;
		if(s[s.size()-1]=='A')
			a++;
		if(s[0]=='B'&&s[s.size()-1]=='A')
			ba++;
		for(int j=0;j<s.size()-1;j++)
			if(s[j]=='A'&&s[j+1]=='B')
				cnt++;
	}
	cnt+=min(a,b);
	if(a==ba&&b==ba&&ba>0)
		cnt--;
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define IN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long ll;
//////////////////////////////////////////////////////
int intpow(int x,int y){
	if (y == 0) return 1;
	long long xx = x;
	long long xin = x;
	REP(i,y-1){
		xx = xx * xin;
	}
	return xx;
}

int main(){
	static int dp[100001] = {};
	dp[0] = 0;
	dp[1] = 1;
	dp[2] = 2;
	dp[3] = 3;
	int N; SCD(N);
	vector<int> v = {9,81,729,6561,59049,6,36,216,1296,7776,46656};
	
	FORq(i,4,N){
		int ncost = dp[i-1] + 1;
		
		REP(j,v.size()){
			int prev = v[j];
			if (prev > i) continue;
			ncost = min(ncost,dp[i-prev] + 1);
		}
		
		dp[i] = ncost;
	}
	
	PRINTD(dp[N]);
	
	
	return 0;
}



Measured memory_bytes: 640
// -*- coding:utf-8-unix -*-

#[macro_use]
extern crate lazy_static;
extern crate num_bigint; // 0.2.2
extern crate num_traits; // 0.2.8
use num_bigint::BigInt;
use num_traits::Pow;

// use proconio::derive_readable;
use proconio::fastout;
use proconio::input;
// use std::convert::TryInto;
// use ascii::Chars;
use libm::*;
use proconio::marker::{Bytes, Chars};
use std::cmp::*;
use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::*;
use std::ops::Range;
use std::str::FromStr;
use superslice::*;

use lazy_static::lazy_static;
use std::sync::Mutex;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

lazy_static! {
    static ref PARENTS: Mutex<Vec<usize>> = Mutex::default();
    static ref CHILDS: Mutex<Vec<Vec<usize>>> = Mutex::default();
}

const MOD: i64 = 1000_000_000 + 7;

//abc177-C
// #[fastout]
fn main() {
    input![n: i64, a: [i64; n]];

    let mut comsum = vec![0; n as usize];
    // comsum[0] = a[0];

    let mut old = 0;
    for i in 0..a.len() {
        comsum[i] = (a[i] + old) % MOD;
        old = comsum[i];
    }

    let mut ans = 0;
    for i in 0..a.len() - 1 {
        let m = a[i] * ((comsum[a.len() - 1] - comsum[i] + MOD) % MOD) % MOD;
        ans = (ans + m) % MOD;
    }

    println!("{}", ans);
}

// fn go2(start: usize, plus_val: usize, anss: &mut Vec<usize>, dcc: &Vec<usize>) {
//     let childrens = CHILDS.lock().unwrap()[start].clone();

//     // let mut ans = plus_val;
//     for c in childrens.iter() {
//         go2(*c, plus_val + dcc[start], anss, dcc);
//     }

//     anss[start] = plus_val + dcc[start];
// }

// let mut values = VALUES.lock().unwrap();
// values.extend_from_slice(&[1, 2, 3, 4]);
// assert_eq!(&*values, &[1, 2, 3, 4]);

// -100000000
//  1000000000


Measured memory_bytes: 7148
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(a) (a).begin(),(a).end()
#define PI 3.141592653589793238
#define INF 1050000000

using vi = vector<int>;


int main() {

	vi v(3);

	REP(i, 3) {
		cin >> v[i];
	}

	sort(ALL(v));
	
	
	cout << v[2]*10+v[1]+v[0] << endl;

	return 0;
}

Measured memory_bytes: 256
sx,sy,tx,ty = list(map(int, input().split()))

result = ""
dy = ty-sy
dx = tx-sx

for i in range(dy):
    result += "U"
for i in range(dx):
    result += "R"
for i in range(dy):
    result += "D"
for i in range(dx):
    result += "L"

result += "L"
for i in range(dy+1):
    result += "U"
for i in range(dx+1):
    result += "R"
result += "D"

result += "R"
for i in range(dy+1):
    result += "D"
for i in range(dx+1):
    result += "L"
result += "U"
print(result)


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int n,ans,i,j,cnt,flag;
string s;
char c;
int main(){
	cin>>n>>s;
	for(i=1;i<n-1;i++){
		cnt=0;
		for(c='a';c<='z';c++){
			flag=0;
			for(j=0;j<i;j++)if(s[j]==c)flag|=1;
			for(j=i;j<n;j++)if(s[j]==c)flag|=2;
			if(flag==3)cnt++;
		}
    ans=max(ans,cnt);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 384
N,M=map(int,input().split());C=[[0]*-~N for _ in range(N+1)];D=list(map(list,C));S=[input()for _ in range(N)];r=0
for t in range(M-1):
	for i in range(1,N+1):
		for j in range(1,N+1):C[i][j]=C[i-1][j-1]+int(S[i-1][t]==S[j-1][t+1]);D[i][j]=min(D[i-1][j],D[i][j-1])+C[i][j]
	r+=D[N][N]
print(r)

Measured memory_bytes: 46700
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			while(sc.hasNextInt()) {
				int m = sc.nextInt();
				int min = sc.nextInt();
				int max = sc.nextInt();
				if(m==0 && min==0 && max==0) break;
				
				int [] score = new int[m];
				for(int i=0;i<m;i++)
				{
					score[i] = sc.nextInt();
				}
				
				int d =0;
				int p =0;
				for(int i=max;i>=min;i--) {
					if(score[i-1]-score[i]>d) {
						d=score[i-1]-score[i];
						p=i;
					}
				}
				System.out.println(p);
			}
		}
	}
}




Measured memory_bytes: 57560
// B - Magic 2
#include <bits/stdc++.h>
using namespace std;

int main(){
	int r,g,b,k,t=0; cin>>r>>g>>b>>k;
	while(r >= g){ g *= 2; t++; }
	while(g >= b){ b *= 2; t++; }
	puts(t > k? "No":"Yes");
}


Measured memory_bytes: 3624
def main():
    from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    n = int(stdin.readline()[:-1])   
    r = stdin.readline()[:-1]
    #n = int(stdin.readline()[:-1])   
    #r = [stdin.readline() for i in range(n)]
    #t = [int(stdin.readline()) for i in range(n)]
    a = list(map(int, r.split()))
    #a, b = map(int, r.split())
    #a = [int(s[i]) for i in range(1, n+1)]
    #a = [list(map(int, r.split())) for i in range(1,n+1)]

    res = 1
    bk = a[0]
    for i in range(1,n):
        if bk >= a[i]:
            bk = a[i]
            res += 1
    print(res)


#    b = [0]*n
#    for i in range(n):
#        b[a[i]-1] = i

#    res = 0
#    mem = b[0]
#    for i in range(1,n):
#        if mem <= b[i]:
#            print(b[i])
##            mem = b[i]
#        else:
#            res += 1
#    print(res)

if __name__ == '__main__':
    main()


Measured memory_bytes: 70876
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;

#define ARRAY_MAX 55
#define MOD 1000000007


int main(){

    int n;
    cin >> n;
    string s;
    cin >> s;

    int a = 0,b = 0;//a:(の数、b:)の数

    for(int i = 0;i < s.length();i++){

        if(s[i] == ')'){
            b++;
            if(a > 0){
                a--;
                b--;
            }
        }else{
            a++;
        }
    }
    string ans;
    REP(i,b){
        ans.push_back('(');
    }
    ans += s;
    REP(i,a){
        ans.push_back(')');
    }
    cout << ans << endl;


    return 0;
}

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

int main() {
	char d='A'-'a';
	string a,b,c;cin>>a>>b>>c;
	cout<<(char)(a[0]+d)<<(char)(b[0]+d)<<(char)(c[0]+d)<<endl;
	return 0;
}


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

void solve(long long N, std::vector<long long> A){
    map<ll, ll> mp;
    for (ll i = 0; i < N; i++) mp[A[i]]++;
    vector<ll> useful;
    for(auto itr = mp.begin(); itr != mp.end(); ++itr){
        if(itr->second >= 2) useful.push_back(itr->first);
    }
    sort(useful.begin(), useful.end(), greater<ll>());
    ll ans = 0;
    if(useful.size() > 1){
        if(mp[useful[0]] >= 4) ans = useful[0] * useful[0];
        else ans = useful[0] * useful[1];
    }
    cout << ans << endl;
    return;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


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

int main(){
    int a, b;
    cin >> a >> b;
    if(a <= b){
        cout << a << endl;
    }else{
        cout << a-1 << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int n,m;
  cin >> n >> m;
  vector<int> a(n);
  for(int i=0;i<n;i++)cin >>a[i];
  vector<pair<int, int> > b(m);
  for(int i=0;i<m;i++){
    cin >> b[i].second >> b[i].first;
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  reverse(b.begin(),b.end());
  ll ans=0;
  int j=0,cnt=0;
  for(int i=0;i<n&&j<m;i++){
    if(a[i]<b[j].first){
      a[i]=b[j].first;
      cnt++;
    }else break;
    if(cnt==b[j].second){
      j++;
      cnt=0;
    }
  }
  for(int i=0;i<n;i++)ans+=a[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {
	static int[] subTreeSize;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String ans = "";
		while (n != 0) {
			if (n % -2 != 0) {
				ans = "1" + ans;
				n--;
			} else {
				ans = "0" + ans;
			}
			n /= -2;
		}
		
		if (ans.equals("")) {
			ans = "0";
		}
		
		System.out.println(ans);
		
		sc.close();
	}
}


Measured memory_bytes: 21844
import scala.io.StdIn

object Main extends App {
  val n = StdIn.readInt
  val ans = Iterator.continually(StdIn.readLine)
    .take(n)
    .map(_.split(" "))
    .map(e => 1 + e(1).toInt - e(0).toInt)
    .sum

  println(ans)
}

Measured memory_bytes: 26196
#include<bits/stdc++.h>
#define FIO "agc31B"
#define ll long long

const int N=2e5+5,MOD=1e9+7;

inline int add(int a,const int &b){a+=b;return a>=MOD?a-MOD:a;}
inline int sub(int a,const int &b){a-=b;return a<   0?a+MOD:a;}
inline int mul(const int &a,const int &b){return 1ll*a*b%MOD;}
inline int& inc(int &a,const int &b){return a=add(a,b);}
inline int& dec(int &a,const int &b){return a=sub(a,b);}
inline int& pro(int &a,const int &b){return a=mul(a,b);}
inline int qpow(int a,int b){int c=1;for(;b;b>>=1,pro(a,a))if(b&1)pro(c,a);return c;}

int n,a[N],f[N],lst[N];

int main(){
  scanf("%d",&n);
  for(int i=1;i<=n;i++)scanf("%d",&a[i]);
  for(int i=1;i<=n;i++)lst[a[i]]=n+1;
  f[0]=1;
  for(int i=1;i<=n;i++){
    f[i]=add(f[i-1],a[i]==a[i-1]?0:f[lst[a[i]]]);
    lst[a[i]]=i;
  }
  printf("%d\n",f[n]);
  return 0;
}


Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
int h,w,inf=1e9;
int main(){
  int ch,cw,dh,dw,i,j,k,l,y,x,cst=0;
  cin>>h>>w>>ch>>cw>>dh>>dw;
  ch--;cw--;dh--;dw--;
  vector<string> s(h);
  vector<vector<int>> cost(h,vector<int>(w));
  for(i=0;i<h;i++) cin>>s.at(i);
  for(i=0;i<h;i++) for(j=0;j<w;j++) cost.at(i).at(j)=inf;
  queue<pair<int,int>> q,qq;
  cost.at(ch).at(cw)=cst;
  q.push(make_pair(ch,cw));
  qq.push(make_pair(ch,cw));
  while(!q.empty()){
    while(!q.empty()){
      auto pr=q.front();
      y=pr.first;
      x=pr.second;
      q.pop();
      qq.push(make_pair(y,x));
      if(x-1>=0&&s.at(y).at(x-1)=='.'&&cost.at(y).at(x-1)==inf){
        cost.at(y).at(x-1)=cst;
        q.push(make_pair(y,x-1));
        qq.push(make_pair(y,x-1));
      }
      if(x+1<w&&s.at(y).at(x+1)=='.'&&cost.at(y).at(x+1)==inf){
        cost.at(y).at(x+1)=cst;
        q.push(make_pair(y,x+1));
        qq.push(make_pair(y,x+1));
      }
      if(y-1>=0&&s.at(y-1).at(x)=='.'&&cost.at(y-1).at(x)==inf){
        cost.at(y-1).at(x)=cst;
        q.push(make_pair(y-1,x));
        qq.push(make_pair(y-1,x));
      }
      if(y+1<h&&s.at(y+1).at(x)=='.'&&cost.at(y+1).at(x)==inf){
        cost.at(y+1).at(x)=cst;
        q.push(make_pair(y+1,x));
        qq.push(make_pair(y+1,x));
      }
    }
    if(cost.at(dh).at(dw)<inf){
      cout<<cost.at(dh).at(dw)<<endl;
      return 0;
    }
    while(!qq.empty()){
      auto pr=qq.front();
      y=pr.first;
      x=pr.second;
      qq.pop();
      for(k=-2;k<=2;k++){
        for(l=-2;l<=2;l++){
          if(0<=y+k&&y+k<h&&0<=x+l&&x+l<w&&s.at(y+k).at(x+l)=='.'&&cost.at(y+k).at(x+l)==inf){
            cost.at(y+k).at(x+l)=cst+1;
            q.push(make_pair(y+k,x+l));
          }
        }
      }
    }
    cst++;
  }
  cout<<-1<<endl;
}

Measured memory_bytes: 9540
import sys

input = lambda: sys.stdin.readline().rstrip()


def solve():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 1
    over = 10 ** 18

    for i in range(N):
        if A[i] == 0:
            print(0)
            exit()

    for i in range(N):
        ans = ans * A[i]
        if ans > over:
            print('-1')
            exit()

    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 21604
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int w = sc.nextInt();
		int w1 = sc.nextInt();
		int v1 = sc.nextInt();
		ArrayList<Integer> listA = new ArrayList<Integer>();
		ArrayList<Integer> listB = new ArrayList<Integer>();
		ArrayList<Integer> listC = new ArrayList<Integer>();
		ArrayList<Integer> listD = new ArrayList<Integer>();
		listA.add(v1);
		for(int i = 1; i < n; i++){
		    int wNow = sc.nextInt();
		    int vNow = sc.nextInt();
		    if(wNow == w1) listA.add(vNow);
		    if(wNow == w1 + 1) listB.add(vNow);
		    if(wNow == w1 + 2) listC.add(vNow);
		    if(wNow == w1 + 3) listD.add(vNow);
		}
		listA.sort(Comparator.reverseOrder());
		listB.sort(Comparator.reverseOrder());
		listC.sort(Comparator.reverseOrder());
		listD.sort(Comparator.reverseOrder());
		
		// 計算
		int result = 0;
		for(int i = 0; i <= listA.size(); i++){
		    int tempWA = 0;
		    int tempVA = 0;
		    int indexA = 0;
		    while(indexA < i){
		        if(tempWA + w1 > w) break;
		        tempWA += w1;
		        tempVA += listA.get(indexA);
		        indexA++;
		    }
		    for(int j = 0; j <= listB.size(); j++){
		        int tempWB = tempWA;
		        int tempVB = tempVA;
		        int indexB = 0;
		        while(indexB < j){
		            if(tempWB + w1 + 1 > w) break;
		            tempWB += w1 + 1;
		            tempVB += listB.get(indexB);
		            indexB++;
		        }
		        for(int k = 0; k <= listC.size(); k++){
		            int tempWC = tempWB;
		            int tempVC = tempVB;
		            int indexC = 0;
		            while(indexC < k){
		                if(tempWC + w1 + 2 > w) break;
		                tempWC += w1 + 2;
		                tempVC += listC.get(indexC);
		                indexC++;
		            }
		            for(int l = 0; l <= listD.size(); l++){
		                int tempWD = tempWC;
		                int tempVD = tempVC;
		                int indexD = 0;
		                while(indexD < l){
		                    if(tempWD + w1 + 3 > w) break;
		                    tempWD += w1 + 3;
		                    tempVD += listD.get(indexD);
		                    indexD++;
		                }
		                result = max(result, tempVD);
		            }
		        }
		    }
		}
		
		// 出力
		System.out.println(result);
	}
}


Measured memory_bytes: 23776
# -*- coding: utf-8 -*-
import sys
N,M,K=map(int, sys.stdin.readline().split())

par=[ i for i in range(N+1) ]
size=[ 1 for i in range(N+1) ]

def root(x):
    while par[x]!=x:
        x=par[x]
    return x

def same(x,y):
	return root(x)==root(y)

def unite(x,y):
    x=root(x)
    y=root(y)
    if x==y: return
    if size[y]<size[x]: x,y=y,x  #yの要素数を大きく
    size[y]+=size[x]
    par[x]=y

def getsize(x):
	return size[root(x)]

al_ok=[ 0 for i in range(N+1) ]	#隣接で友達関係のカウント

for _ in range(M):
    a,b=map(int, sys.stdin.readline().split())
    unite(a,b)
    al_ok[a]+=1
    al_ok[b]+=1

al_ng=[ 0 for i in range(N+1) ]	#隣接でブロックしている人のカウント
for _ in range(K):
    c,d=map(int, sys.stdin.readline().split())
    if same(c,d):
        al_ng[c]+=1
        al_ng[d]+=1

for i in range(1,N+1):
    print getsize(i)-1-al_ok[i]-al_ng[i],


Measured memory_bytes: 38428
//DMAX = 7;
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int fact[8];
int n;
int d[100];
int a[100];
int dp[101][5040];	//dp[i][j] = ?°???????i???N-1???????????????????§£. ??????????°???????i???i+DMAX-1????£??????????????±??????£????????? (j???0???DMAX-1???????????????????????????).

void init() {
	int i, j;
	
	fact[0] = 1;
	for (i = 1; i <= 7; i++) fact[i] = fact[i - 1] * i;
	cin >> n;
	for (i = 0; i < n; i++) cin >> d[i];
	for (i = 0; i < n; i++) cin >> a[i];
	for (i = 0; i < 101; i++) for (j = 0; j < 5040; j++) dp[i][j] = -1;
}

int encode(vector<int> perm) {
	int i, j;
	int jyo[7];
	int ret = 0, mul = fact[6];
	
	for (i = 0; i < 7; i++) jyo[i] = i;
	for (i = 0; i < 7; i++) {
		ret += mul * jyo[perm[i]];
		for (j = perm[i] + 1; j < 7; j++) {
			jyo[j]--;
		}
		mul /= max(1, 6 - i);
	}
	return ret;
}

vector<int> decode(int perm) {
	int i, j;
	int jyo[7];
	int div = fact[6];
	vector<int> ret;
	
	for (i = 0; i < 7; i++) jyo[i] = i;
	
	for (i = 0; i < 7; i++) {
		int id = (perm / div) % (7 - i);	//????????£?????????????????????, id(>=0)??????????°?????????? ??? jyo[j] = id??¨??????j
		for (j = 0; j < 7; j++) {
			if (jyo[j] == id) {
				break;
			}
		}
		int x = j;
		ret.push_back(x);
		
		jyo[x] = -1;
		for (j = x + 1; j < 7; j++) {
			jyo[j]--;
		}
		div /= max(1, 6 - i);
	}
	return ret;
}

vector<int> eraseNum(vector<int> perm, int num) {
	vector<int> ret;
	for (int i = 0; i < 8; i++) {
		if (perm[i] == num) continue;
		ret.push_back(perm[i]);
	}
	return ret;
}

vector<int> addNum(vector<int> perm, int num) {
	for (int i = 0; i < 7; i++) {
		perm[i] += num;
	}
	return perm;
}

int tameruHakidasu(int id, vector<int> nPerm) {
	int i;
	int tameru = 0, hakidasu = 0;
	int idPos = 0;
	
	for (i = 0; i < 8; i++) {
		if (nPerm[i] == 0) {
			idPos = i;
			break;
		}
	}
	
	//?????????
	for (i = 0; i < idPos; i++) {
		if (id + nPerm[i] < n && d[id + nPerm[i]] >= nPerm[i]) {
			tameru += a[id + nPerm[i]];
		}
	}
	
	//????????????
	for (i = idPos + 1; i < 8; i++) {
		if (id + nPerm[i] < n && d[id] >= nPerm[i]) {
			hakidasu += a[id];
		}
	}
	
	return tameru + hakidasu;
}


int dfs(int id, int perm) {
	int i;
	
	if (id == n) {
		return 0;
	}
	if (dp[id][perm] != -1) {
		return dp[id][perm];
	}
	
	int ret = 0;
	for (i = 0; i < 8; i++) {	//perm <- i(>=0)???????????´???????°???????id + DMAX????????\
		vector<int> p = decode(perm);
		vector<int>::iterator it = p.begin() + i;
		it = p.insert(it, 7);
		
		int plus = tameruHakidasu(id, p);
		
		p = eraseNum(p, 0);
		p = addNum(p, -1);
		
		int res = dfs(id + 1, encode(p));
		
		ret = max(ret, res + plus);
	}
	return (dp[id][perm] = ret);
}

int main() {
	init();
	
	int ans = 0;
	for (int perm = 0; perm < 5040; perm++) {
		ans = max(ans, dfs(0, perm));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5140
using System;
using System.Linq;

public class Test
{
	public static void Main()
	{
		// your code goes here
		
		string s = Console.ReadLine();
		int i = 0;
		int counter = 0;
		
		while(i < s.Length){
			
			if(i%2 == 0){
				if(s.Substring(i,1) == "L"){counter++;}
			}else{
				if(s.Substring(i,1) == "R"){counter++;}
			}
			
			i++;
			
		}
		
		if(counter==0){
			Console.WriteLine("Yes");
		}else{
			Console.WriteLine("No");
		}
		
	}
}

Measured memory_bytes: 13140
//Radhe Radhe
#include<bits/stdc++.h>
#define godspeed  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define limit 1000000000000000000 //1e18
#define mod 1000000007 //1e9+7
#define llu long long unsigned
#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i,n)    for(ll i=0; i<n; i++)
#define rep1(i,a,b)    for(ll i=a; i<b; i++)
#define repV(i,n)    for(ll i=0; i<v.size(); i++)
#define fixed cout.setf(ios::fixed);
#define Precise cout.precision(7);
#define yes cout<<"Yes"<<'\n';
#define no cout<<"No"<<'\n';
using namespace std;

int main()
{
    godspeed
    ll  i,j,n,m,k;
    string s,t;
    cin >> n >> m;
    if(n%m==0)
     return   cout << -1 << endl,0;
for(i=1;;i++)
{
    if((i*n)%m!=0)
       return cout << i*n << endl,0;

}
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi 3.1415926535898
int32_t main()
{
   int n;
   cin>>n;
   int x = n%10;
   if(x == 3)
    cout<<"bon";
   else if(x == 0 || x==1 || x==6 ||x ==8)
    cout<<"pon";
   else 
    cout<<"hon";

}

Measured memory_bytes: 3644
import java.util.Scanner;


public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner	stdin = new Scanner(System.in);
		int		nWeek = stdin.nextInt();
		int		nRent = 100000;
		int		nTmp  = 0;

		for(int nLoop = 0; nLoop < nWeek; nLoop++) {
			nRent *= 1.05;
			nTmp   = nRent % 1000;
			nRent /= 1000;
			nRent  = ((nTmp > 0) ? nRent + 1 : nRent) * 1000;
		}

		System.out.printf("%d\n", nRent);
	}

}

Measured memory_bytes: 17356