akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

int main(){
  int N;
  cin>>N;
  
  int L[N];
  for(int i=0;i<N;i++)cin>>L[i];
  
  int sum=0;
  int max=0;
  
  for(int i=0;i<N;i++){
    sum+=L[i];
    
    if(L[i]>max)max=L[i];
  }
  
  int ans=(sum-max)-max;
  
  if(ans>0){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
import fractions 
n,m = map(int,input().split())
gcd = int(fractions.gcd(n,m))
lcm = n * m // gcd
s = input()
t = input()

if gcd == 1:
  if s[0] == t[0]:
    print(lcm)
  else:
    print(-1)
else:
  if s[::n//gcd] == t[::m//gcd]:
    print(lcm)
  else:
    print(-1)    

Measured memory_bytes: 5432
#include <iostream>
#include <vector>

using namespace std;

vector<int> IsUsed;//空間使用済み調査用

void SleepCat(int W, int id, int cW){
	int cWbuf = 0;
	for (int i = 0; i < W; ++i){
		if (IsUsed[i] == -1)++cWbuf;
		else cWbuf = 0;
		if (cWbuf == cW){
			cout << (i - cW + 1) << endl;
			for (int j = i - cW + 1; j <= i; ++j){
				IsUsed[j] = id;
			}
			return;
		}
	}
	cout << "impossible" << endl;
	return;
}

void WakeCat(int id){
	for (vector<int>::iterator i = IsUsed.begin(); i != IsUsed.end(); ++i){
		if (*i == id)*i = -1;
	}
}

int main(){
	int W = 0, Q = 0;//塀幅,行数
	char loader;//ローダー
	int ID, cW;//猫id,猫幅

	while (1){
		cin >> W >> Q;//代入
		if (W == 0 && Q == 0)break;
		//初期化
		IsUsed.resize(W);
		for (int i = 0; i < W; ++i){
			IsUsed[i] = -1;
		}
		//メインループ
		for (int i = 0; i < Q; ++i){
			cin >> loader >> ID;
			if (loader == 's'){
				cin >> cW;
				SleepCat(W, ID, cW);
			} else if (loader == 'w'){
				WakeCat(ID);
			}
		}
		cout << "END" << endl;
	}


	return 0;
}

Measured memory_bytes: 1212
# coding: utf-8
import sys
from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import combinations, product
#import bisect# lower_bound etc
#import numpy as np
#import queue# queue,get(), queue.put()
def run():
    N = int(input())
    current = 0
    ways = []
    dic = {'(': 1, ')': -1}
    SS = read().split()

    for S in SS:
        path = [0]
        for s in S:
            path.append(path[-1]+ dic[s])
        ways.append((path[-1], min(path)))

    ways_pos = sorted([(a,b) for a,b in ways if a >= 0], key = lambda x:(x[1], x[0]), reverse=True)
    ways_neg = sorted([(a,b) for a,b in ways if a < 0], key = lambda x:(x[1] - x[0], -x[0]), reverse=True)[::-1]

    for i in range(len(ways_pos)):
        go, max_depth = ways_pos[i]
        if current + max_depth >= 0:
            current += go
        else:
            print("No")
            return None

    for i in range(len(ways_neg)):
        go, max_depth = ways_neg[i]
        if current + max_depth >= 0:
            current += go
        else:
            print("No")
            return None

    if current == 0:
        print('Yes')
    else:
        print('No')

if __name__ == "__main__":
    run()

Measured memory_bytes: 198992
#include <stdio.h>
#include <string.h>
int main(void){
	
	char a[3];
	scanf("%s",&a);

	if (strncmp(a,"AAA",3)==0 || strncmp(a,"BBB",3)==0){
		printf("No");
	}else{
		printf("Yes");
	}
	
	return 0;
	
}

Measured memory_bytes: 128
try:
    while True:
        l1 = list(map(int, input().split()))
        l2 = list(map(int, input().split()))
        hit = blow = 0
        for i in l1:
            for s in l2:
                if i == s:
                    if l1.index(i) == l2.index(s):
                        hit += 1
                    else:
                        blow += 1
        print(hit, blow)
except:
    pass

Measured memory_bytes: 7568
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
using namespace std;

#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)

#define FOR(i,a,b) for(ll i = (a);i<(b);i++)
#define REP(i,a) FOR(i,0,(a))
#define MP make_pair

int main() {
  int a, b, c;
  cin >> a >> b >> c;

  if ((b - a) == (c - b)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F(i,a,b) for(int i=a;i<=(b);++i)
#define F2(i,a,b) for(int i=a;i<(b);++i)
#define dF(i,a,b) for(int i=a;i>=(b);--i)
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define Debug debug("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define MN 1005
#define MK 25
#define ll long long
#define mod 1000000007
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
typedef pair<int,int> pii;
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
inline int qpow(int b,int e) {int a=1;for(;e;e>>=1,b=(ll)b*b%mod)if(e&1)a=(ll)a*b%mod;return a;}
int n,k;
int a[MN];
int fac[MN],ifac[MN];
int f[MK][MN];
int main(){
	scanf("%d%d",&n,&k);
	F(i,1,k)scanf("%d",a+i);
	fac[0]=1;
	F(i,1,n)fac[i]=(ll)fac[i-1]*i%mod;
	ifac[n]=qpow(fac[n],mod-2);
	dF(i,n,1)ifac[i-1]=(ll)ifac[i]*i%mod;
	f[0][0]=1;
	F(j,1,k){
		F(i,0,n){
			F(x,0,min(n-i,a[j])){
				f[j][i+x]=(f[j][i+x]+(ll)f[j-1][i]*ifac[x]%mod*fac[n-x]%mod*ifac[n-a[j]]%mod*ifac[a[j]-x])%mod;
			}
		}
//		F(i,0,n)printf("f[%d][%d]=%d\n",j,i,f[j][i]);
	}
	printf("%lld\n",(ll)fac[n]*f[k][n]%mod);
	return 0;
}

Measured memory_bytes: 384
import sys
from itertools import starmap
readline = sys.stdin.readline
class Segment(object):
    __slots__ = ('fi', 'se')
    def __init__(self, fi, se):
        self.fi = fi
        self.se = se
def cross(a, b):
    return a.real * b.imag - a.imag * b.real
def dot(a, b):
    return a.real * b.real + a.imag * b.imag
def norm(base):
    return abs(base) ** 2
def project(s, p2):
    base = s.fi - s.se
    r = dot(p2 - s.fi, base) / norm(base)
    return s.fi + base * r
def reflect(s, p):
    return p + (project(s, p) - p) * 2.0
s = Segment(*starmap(complex, zip(*[map(float, readline().split())] * 2)))
n = int(readline())
for _ in [0] * n:
    p1 = reflect(s, complex(*map(float, readline().split())))
    print("{0:.10f} {1:.10f}".format(p1.real, p1.imag))

Measured memory_bytes: 7904
#include<iostream>
#include <climits>
#include <cstdint>
#include<cmath>

using namespace std;

struct Activity{
  int A,B,C;
};

int getEnjoyment(Activity arr[],int n){
    int dp[n][3];
    dp[0][0] = arr[0].A;
    dp[0][1] = arr[0].B;
    dp[0][2] = arr[0].C;
    for(int i = 1;i<n;i++){
      dp[i][0] = arr[i].A + max(dp[i-1][1] ,dp[i-1][2]);
      dp[i][1] = arr[i].B + max(dp[i-1][0] ,dp[i-1][2]);
      dp[i][2] = arr[i].C + max(dp[i-1][1],dp[i-1][0]);
    }
    return max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}

int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  Activity arr[n];
  for(int i = 0;i<n;i++){
    cin >> arr[i].A >> arr[i].B >> arr[i].C;
  }
  cout << getEnjoyment(arr,n) << endl;
  return 0;
}


Measured memory_bytes: 2560
import collections
n=int(input())
data=[]
for i in range(n):
    num=input()
    data.append(num)
data=collections.Counter(data)
print("AC x {}".format(data["AC"]))
print("WA x {}".format(data["WA"]))
print("TLE x {}".format(data["TLE"]))
print("RE x {}".format(data["RE"]))

Measured memory_bytes: 16620
#include <bits/stdc++.h>
using namespace std;
 
#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << a << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair
 
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

vi perm(ll n) {
    if (n == 1) return vi();

    auto p = perm(n/2);
    p.push_back(si(p));
    if (n%2) {
        for (auto &x : p) x++;
        p.push_back(0);
    }
    return p;
}
 
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n; cin >> n;
    n++;
    auto p = perm(n);
    cout << 2*si(p) << endl;
    forn(i,si(p)) cout << i+1 << ' ';
    for (auto x : p) cout << x+1 << ' ';
    return 0;
}


Measured memory_bytes: 256
def cmb(n,r,mod):
    if r<0 or n<r:
        return 0
    r=min(r,n-r)
    return fact[n]*factinv[r]*factinv[n-r]%mod

mod=10**9+7
N,K=map(int,input().split())
fact=[1,1]
factinv=[1,1]
inv=[1,1]

for i in range(2,N+1):
    fact.append((fact[-1]*i)%mod)
    inv.append((-inv[mod%i]*(mod//i)%mod))
    factinv.append((factinv[-1]*inv[-1])%mod)

for i in range(1,K+1):
    ans=cmb(N-K+1,i,mod)*cmb(K-1,i-1,mod)%mod
    print(ans)

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

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

	int n; cin >> n;
	vector<int> l(n);
	REP(i, n) cin >> l[i];

	int cnt = 0;
	REP(i, n) for (int j = i+1; j < n; j++) for (int k = j+1; k < n; k++) {
		if (l[i] == l[j] || l[j] == l[k] || l[k] == l[i]) continue ;
		if (l[i] + l[j] == l[k] || l[i] + l[k] == l[j] || l[j] + l[k] == l[i]) continue ;
		if (!(l[i] + l[j] < l[k] || l[i] + l[k] < l[j] || l[j] + l[k] < l[i]))
			cnt++;
	}
	cout << cnt << '\n';
	return 0;
}

Measured memory_bytes: 3660
#include <stdio.h>
#include <stdlib.h>

int main(void) {
    int a[3] = {};
    int input1 = 0;
    char* input2 = 0;
    char* input3 = 0;
    scanf("%d", &input1);
    // printf("%d\n", input1);
    input2 = (char*)malloc(sizeof(char) * (input1+1));
    input3 = (char*)malloc(sizeof(char) * (input1+1));
    scanf("%s", input2);
    scanf("%s", input3);
    // printf("%s\n", input2);
    // printf("%s\n", input3);
    char* result = (char*)malloc(sizeof(char) * (input1*2+1));
    for(int i=0; i<input1*2; ++i) {
        if(i%2==0)
            result[i] = input2[i/2]; 
        else 
            result[i] = input3[i/2];
    }
    printf("%s\n", result);
    return 0;
}

Measured memory_bytes: 128
from operator import mul
from functools import reduce

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

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

ao = k
aka = n - k
sousa = aka + 1
kurikaesi = min(sousa, ao)
cnt = 0
for i in range(1, ao+1):
    if i <= sousa:
        basho = cmb(sousa, i)
        bunkatu = cmb(ao-i+i-1, i-1)
        print(basho * bunkatu % (10**9+7))
    else:
        print(0)

Measured memory_bytes: 3940
#Range Sum Query
n=int(input())
s=input()
q=int(input())
#1番から始まる数え方
#要素数　Seg_Len
Seg_Len=1<<19
seg=[0 for i in range(Seg_Len*2)]
#i番目の要素はi+Seg_Len-1
def add(ind,v):
    ind+=Seg_Len-1 #元々の配列のインデックスとセグメント木の長さを足すとセグメント木の配列内のインデックスになる。
    seg[ind]=v  #一番下の部分に値を追加する。
    while(1):
        ind//=2
        if(ind==0):
            break  #a[0]にアクセスさせない
        seg[ind]=seg[ind*2]|seg[ind*2+1]
        
def sum1(l,r):
    l+=Seg_Len-1
    r+=Seg_Len-1
    ans=0
    while(l<r):
        if(l%2==1):
            ans|=seg[l]
            l+=1
        l//=2
        if(r%2==1):
            ans|=seg[r-1]
            r-=1
        r//=2
    tmp=0
    while(ans):
        if(ans & 1):
            tmp+=1
        ans>>=1
    return tmp
#abc と　124の対応付け
alp='abcdefghijklmnopqrstuvwxyz'
d={}
for i in range(len(alp)):
    d[alp[i]]=2**i
    
for i in range(len(s)):
    add((i+1),d[s[i]])
for i in range(q):
    com,a,b=input().split()
    if(com=='1'):
        ind=int(a)
        v=d[b]
        add(ind,v)
    if(com=='2'):
        l=int(a)
        r=int(b)
        ##rは一つ増やしておく必要がある
        print(sum1(l,r+1))
        

Measured memory_bytes: 149616
D=int(input())
c = list(map(int,input().split()))

s=[None]*D
for i in range(D):
    s[i] = list(map(int,input().split()))
t=[0]*D
for i in range(D):
    t[i]=int(input())
    
m=int(input())
d=[None]*m
q=[None]*m
for i in range(m):
    d[i],q[i] = map(int,input().split())
sumc=sum(c)



def calc_score(t):
    last=[0]*26
    satis=0
    pena=0
    delta_pena=0
    for j in range(D):
        ss=s[j]
        tt=t[j]
        satis += ss[tt-1]
        delta_pena += sumc - c[tt-1]*(j+1-last[tt-1])

        last[tt-1]=j+1   
        pena += delta_pena
    return satis-pena

for i in range(m):
    t[d[i]-1] = q[i]
    print(calc_score(t))

Measured memory_bytes: 76196
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   string s;
   int ans = 0;
   cin >> s;
   for (int i = 0; i < 4; i++)
      if (s[i] == '+')
         ans++;
      else
         ans--;

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ll n,a,max,cal,yen,tui;
    cin>>n>>yen>>tui>>cal;
    vector<ll> v;
    for(int i=0;i<n;i++){
        cin>>a;
        v.push_back(a);
    }

    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());

    max=cal/yen;
    for(int i=0;i<n;i++){
        cal+=v[i];
        yen+=tui;
        if(max<cal/yen)max=cal/yen;
    }

    cout<<max<<endl;
}


Measured memory_bytes: 3160
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
    int H, W;
    string s[50];

    cin >> H >> W;
    for (int h = 0; h < H; h++) cin >> s[h];

    for (int h = 0; h < H; h++) {
        for (int w = 0; w < W; w++) {
            if (s[h][w] == '#') {
                bool flag = false;
                if (h > 0)     flag |= (s[h - 1][w] == '#');
                if (h < H - 1) flag |= (s[h + 1][w] == '#');
                if (w > 0)     flag |= (s[h][w - 1] == '#');
                if (w < W - 1) flag |= (s[h][w + 1] == '#');

                if (!flag) {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }

    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
/*
ABC095A - Something on It
*/

#include <bits/stdc++.h>
using namespace std;

int main() {
	string S;
	cin >> S;

	int ans = 700;

	if (S[0] == 'o') {
		ans += 100;
	}
	if (S[1] == 'o') {
		ans += 100;
	}
	if (S[2] == 'o') {
		ans += 100;
	}

	cout << ans << endl;

	return 0;
}


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

int n,m;
int q;
int a[50],b[50],c[50],d[50];
int ans = 0;

void dfs(vector<int> array){
    if(array.size()==n+1){
        int point = 0;
        for(int i=0;i<q;i++){
            if(array[b[i]]-array[a[i]]==c[i]) point += d[i];
        }
        if(point>ans) ans = point;
        return;
    }

    array.push_back(array.back());
    while(array.back()<=m){
        dfs(array);
        array.back()++;
    }
}

int main(void){
    cin >> n >> m >> q;
    for(int i=0;i<q;i++) cin >> a[i] >> b[i] >> c[i] >> d[i];

    vector<int> array(1,1);
    dfs(array);
    cout << ans << endl;
}

Measured memory_bytes: 3540
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
template <typename T> bool chmax(T &u, const T z) { if (u < z) {u = z; return true;} else return false; }
template <typename T> bool chmin(T &u, const T z) { if (u > z) {u = z; return true;} else return false; }
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
typedef pair<ll, ll> P;
const ll INF = 1LL << 60;
const int MOD = 1000000007;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

const int MAX = 1010101;
long long moto[MAX], gyaku[MAX], inv[MAX];
//inverse elsement 逆元
void ncr_shokika() {
    moto[0] = moto[1] = 1;
    gyaku[0] = gyaku[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        moto[i] = moto[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        gyaku[i] = gyaku[i - 1] * inv[i] % MOD;
    }
}
long long ncr(int n, int r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return moto[n] * (gyaku[r] * gyaku[n - r] % MOD) % MOD;
}
int main()
{
    int x, y;
    cin >> x >> y;
    if((x+y)%3!=0){
        cout<<0;
        return 0;
    }
    int a=(x+y)/3;
    int b=(2*y-x)/3;
    ncr_shokika();
    cout<<ncr(a,b)<<endl;
    return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vchar = vector<char>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;

int main(){
  ll n, a, b;
  cin >> n >> a >> b;
  ll ans = 0;
  rep(i, 1, n + 1){
    st str = to_string(i);
    ll sum = 0;
    vrep(j, str) sum += j - '0';
    if(sum >= a && sum <= b) ans += i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import Control.Monad
import Data.Maybe
import Data.List
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector as V
 
main = abc161b

abc161b = do
    [n, m] <- getIntList
    prods <- getIntList
    let prodsV = V.fromList prods
    let boolV = V.filter (== True) $ fmap (checkSelect m (V.sum prodsV)) prodsV
    putStrLn $ 
        if V.length boolV < fromIntegral m
            then "No"
            else "Yes"

checkSelect :: Integer -> Integer -> Integer -> Bool
checkSelect m sum prod
    | prod * 4 * m < sum  = False
    | otherwise = True


readInt = fst . fromJust . BS.readInteger
readIntList = map readInt . BS.words
getIntList = readIntList <$> BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine


Measured memory_bytes: 508
import java.util.Scanner;

public class Main{
    
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        while(true){
            int n,x;
            int sum=0,M=0;

            n=sc.nextInt();
            x=sc.nextInt();
            if(n==0&&x==0){
                break;
            }
            for(int i=1;i<=n;i++){
                for(int j=i+1;j<=n;j++){
                    for(int k=j+1;k<=n;k++){
                       sum= i+j+k;
                       if(sum==x){
                           M+=1;
                       }

                    }
                }
            }

            System.out.println(M);
        }

        sc.close();
    }
}


Measured memory_bytes: 26884
import sys
from collections import deque
from functools import reduce
import copy
import math


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    [N, K] = string_to_int(inputs[0])
    paint_range = K-1
    A = string_to_int(inputs[1])
    one_index = None

    for i, a in enumerate(A):
        one_index = i if a == 1 else one_index
    count = one_index // paint_range
    r = one_index % paint_range
    over = 0
    if r != 0:
        count += 1
        over = paint_range - r
    count += math.ceil(((N-1) - one_index - over) / paint_range)
    return count


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(2))
    print(ret)


Measured memory_bytes: 15020
#include <iostream>
#include <stack>
#include <queue>
using namespace std;

int main() {
	int g;
	stack<int> a;
	queue<int> b;
	while(cin >> g) if (g!=0) a.push(g); else { b.push(a.top()); a.pop();}
	while(!b.empty()) { cout << b.front() << endl; b.pop(); } 
	return 0;
}

Measured memory_bytes: 1200
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	const inputLines = input.split("\n");
	const line0 = inputLines[0];
	const line0vars = line0.split(" ");

	const d = parseInt(line0vars[0], 10);
	const t = parseInt(line0vars[1], 10);
	const s = parseInt(line0vars[2], 10);

	console.log((d <= t * s) ? "Yes" : "No");

	// tmp = input[1].split(" ");
	// //文字列から10進数に変換するときはparseIntを使います
	// var a = parseInt(input[0], 10);
	// var b = parseInt(tmp[0], 10);
	// var c = parseInt(tmp[1], 10);
	// var s = input[2];

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

// node index.js
// 1
// 2 3
// test
// (Ctrl + D)


Measured memory_bytes: 29640
#include <iostream>
#include <set>
using namespace std;
typedef long long ll;
ll C[32];
ll S[366][32];
ll T[366];
ll P[32];
ll L[32];
set<int> H[32];

ll calcSum(int D) {
  ll ret = 0;
  for (int i=1; i<=D; i++) {
    ret += S[i][T[i]];
  }
  return ret;
}
ll calcPenalty(int con, int D) {
  ll ret = 0;
  ll prev = 0;
  for (auto& it: H[con]) {
    ll dif = it - prev;
    ret += (dif - 1) * dif / 2;
    prev = it;
  }
  ll dif = D + 1 - prev;
  ret += (dif - 1) * dif / 2;
  ret *= C[con];
  return ret;
}

int main() {
  ios::sync_with_stdio(false);
  int D;
  cin >> D;
  for (int i=1; i<=26; i++) {
    cin >> C[i];
  }
  for (int i=1; i<=D; i++) {
    for (int j=1; j<=26; j++) {
      cin >> S[i][j];
    }
  }
  for (int day=1; day<=D; day++) {
    ll ocon = 1;
    ll oval = S[day][ocon] - (day - L[ocon]) * C[ocon];
    for (int con=2; con<=26; con++) {
      ll val = S[day][con] - (day - L[con]) * C[con];
      if (val > oval) {
        ocon = con;
        oval = val;
      }
    }
    T[day] = ocon;
    L[ocon] = day;
    H[ocon].insert(day);
  }
  for (int day=1; day<=D; day++) {
    cout << T[day] << endl;
  }
}

Measured memory_bytes: 3776
let rec solve l r =
  try
    let (a, b, c) = Scanf.scanf "%d,%d,%d " (fun a b c -> a, b, c) in
    if a = b then solve (l + 1) r
    else if a*a + b*b = c*c then solve l (r + 1)
    else assert false
  with _ -> (r, l)

let () =
  let (r, l) = solve 0 0 in
  Printf.printf "%d\n%d\n" r l

Measured memory_bytes: 2316
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[] s = sc.next().toCharArray();
        int needLeft = 0;
        int pointer = 0;
        for (int i = 0; i < n; i++) {
            if (s[i] == '(') {
                pointer++;
            } else {
                if (pointer == 0) {
                    needLeft++;
                } else {
                    pointer--;
                }
            }
        }
        int needRight = pointer;

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < needLeft; i++) {
            sb.append('(');
        }
        sb.append(s);
        for (int i = 0; i < needRight; i++) {
            sb.append(')');
        }
        System.out.println(sb);
    }

}


Measured memory_bytes: 22612
import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int n = Integer.parseInt(sc.next());
    int k = Integer.parseInt(sc.next());
    List<Integer> logs = new ArrayList<>();
    //PriorityQueue<Double> logs = new PriorityQueue<>(Comparator.reverseOrder());
    for (int i = 0; i < n; i++) {
      logs.add(Integer.parseInt(sc.next()));
    }
    Collections.sort(logs);
    if (k == 0) {
      pw.println(logs.get(logs.size() - 1));
      return;
    }
    int max = logs.get(logs.size() - 1);
    int l = 0;
    int r = max;
    while (r - l > 1) {
      int m = (l + r) / 2;
      int kCandidate = 0;
      for (int j = 0; j < n; j++) {
        int a = logs.get(j);
        kCandidate += Math.ceil((double) a / m) - 1;
      }
      if (k >= kCandidate) {
        r = m;
      } else {
        l = m;
      }
    }
    pw.println(r);
  }
}


Measured memory_bytes: 64156
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {

	public static class FastReader {
		BufferedReader br;
		StringTokenizer root;
		
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (root == null || !root.hasMoreTokens()) {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception addd) {
					addd.printStackTrace();
				}
			}
			return root.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception addd) {
				addd.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	
	public static FastReader sc = new FastReader();
 
	//static int mod = (int) (1e9+7),MAX=(int) (2e5+100);
    static List<Integer>[] edges;
    static long[][] dp;
    static int n,m;
    static Box[] box;
	public static void main(String[] args) {
	    n = sc.nextInt();
        box = new Box[n];
	    dp = new long[n][30001];
	    for(int i=0;i<n;++i) Arrays.fill(dp[i],-1);
	    for(int i=0;i<n;++i) {
	    	int w = sc.nextInt();
	    	int s = sc.nextInt();
	    	long v = sc.nextLong();
	    	box[i] = new Box(w,s,v);
	    }
	    Arrays.sort(box);
	    out.print(f(0,30000));
		out.close();
   }
	private static long f(int i,int wt) {
		if(i == n) return 0;
		if(dp[i][wt] != -1) return dp[i][wt];
		long o1=0,o2=0;
	    o1 = f(i+1,wt);
	    if(box[i].w <= wt)
	    o2 = box[i].v + f(i+1,Math.min(wt-box[i].w,box[i].s));
	   
		return dp[i][wt] = Math.max(o1, o2);
	}

	static class Box implements Comparable<Box>{
		int w;
		int s;
		long v;
		Box(int w,int s,long v){
			this.w = w;
			this.s = s;
			this.v = v;
		}
		@Override
		public int compareTo(Box o) {
			return -(this.w + this.s) + (o.w + o.s);
		}
		
	}
	
	

}



Measured memory_bytes: 323156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll M = 1000000007;
ll n, m;
ll fact(ll n) {
	ll cnt = 1;
	for (int i=1; i<=n; i++) {
		cnt *= i;
		cnt %= M;
	}
	return cnt;
}

ll pow(ll a, ll n) {
	if (n==0)
		return 1;
	else {
		ll b = pow(a, n/2);
		if (n%2==0)
			return (b*b)%M;
		else return (b*((a*b)%M))%M;
	}
}

int main() {
	cin >> n >> m;
	if ((n+m)%3) 
		cout << 0;
	else {
		ll c = (n+m)/3;
		m -= c;
		n -= c;
		if(m<0 || n<0) 
			cout << 0;
		else {
			c = fact(c);
			m = fact(m);
			n = fact(n);
			cout << (c*((pow(n, M-2)*pow(m, M-2))%M))%M;
		}
	}
}

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

char S[100000+1];
int sum[100000+1];
int main() {
  int N, Q;
  scanf("%d %d %s", &N, &Q, S);
  for(int i = 1; i < N; i++)
    sum[i+1] = sum[i] + (S[i-1] == 'A' && S[i] == 'C');
  while(Q--) {
    int l, r;
    scanf("%d %d", &l, &r);
    printf("%d\n", sum[r] - sum[l]);
  }
  return 0;
}

Measured memory_bytes: 1280
#include<cmath>
#include<cstdio>
#include<algorithm>

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

using namespace std;

const double EPS=1e-8;

struct point3{
	double x,y,z;
	point3():x(0),y(0),z(0){}
	point3(double x,double y,double z):x(x),y(y),z(z){}
	point3 operator+(const point3 &a)const{ return point3(x+a.x,y+a.y,z+a.z); }
	point3 operator-(const point3 &a)const{ return point3(x-a.x,y-a.y,z-a.z); }
};

point3 operator*(double c,const point3 &a){ return point3(c*a.x,c*a.y,c*a.z); }

struct line3{
	point3 a,b;
	line3(){}
	line3(const point3 &a,const point3 &b):a(a),b(b){}
};

double abs(const point3 &a){ return sqrt(a.x*a.x+a.y*a.y+a.z*a.z); }

double dot(const point3 &a,const point3 &b){ return a.x*b.x+a.y*b.y+a.z*b.z; }

point3 cross(const point3 &a,const point3 &b){
	return point3(a.y*b.z-a.z*b.y,a.z*b.x-a.x*b.z,a.x*b.y-a.y*b.x);
}

double dist(const line3 &L,const point3 &p){
	return abs(cross(L.b-L.a,p-L.a))/abs(L.a-L.b);
}

double dist(const line3 &L,const line3 &M){
	point3 u=L.b-L.a,v=M.b-M.a,w=L.a-M.a;
	if(abs(cross(u,v))<EPS){
		return dist(L,M.a);
	}
	else{
		// a*s+b*t=e
		// c*s+d*t=f
		double a= dot(u,u),b=-dot(u,v),c=-dot(u,v);
		double d= dot(v,v),e=-dot(u,w),f= dot(v,w);
		double det=a*d-b*c;
		double s=( d*e-b*f)/det;
		double t=(-c*e+a*f)/det;
		return abs((L.a+s*u)-(M.a+t*v));
	}
}

int main(){
	for(int n;scanf("%d",&n),n;){
		point3 s,g;
		scanf("%lf%lf%lf%lf%lf%lf",&s.x,&s.y,&s.z,&g.x,&g.y,&g.z);
		line3 L[100];
		rep(i,n) scanf("%lf%lf%lf%lf%lf%lf",&L[i].a.x,&L[i].a.y,&L[i].a.z,&L[i].b.x,&L[i].b.y,&L[i].b.z);

		static double d[102][102];
		rep(i,n){
			rep(j,i) d[i][j]=d[j][i]=dist(L[i],L[j]);
			d[i][ n ]=d[ n ][i]=dist(L[i],s);
			d[i][n+1]=d[n+1][i]=dist(L[i],g);
		}
		d[n][n+1]=d[n+1][n]=abs(s-g);

		rep(k,n+2) rep(i,n+2) rep(j,n+2) d[i][j]=min(d[i][j],d[i][k]+d[k][j]);

		printf("%.9f\n",d[n][n+1]);
	}

	return 0;
}

Measured memory_bytes: 1184
#include <iostream>
#include <vector>

int main(int argc, char** argv)
{
    int N;
    std::cin >> N;

    std::vector<long long> A(N+1);
    std::vector<long long> B(N);
    for (int i = 0; i <= N; i++) {
        std::cin >> A[i]; 
    }
    for (int i = 0; i < N; i++) {
        std::cin >> B[i]; 
    }

    long long ans = 0;
    for (int i = 0; i < N; i++) {
        long long b1 = std::min(A[i], B[i]);
        ans += b1;
        A[i] -= b1;
        B[i] -= b1;
        long long b2 = std::min(A[i+1], B[i]);
        ans += b2;
        A[i+1] -= b2;
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main(){
	int a[5];
	for(int i=0;i<5;i++) cin >> a[i];
	int k;
	cin >> k;
	bool flag=true;
	for(int i=0;i<4;i++)
		for(int j=i+1;j<5;j++){
			if(abs(a[i]-a[j])>k) flag=false;
		}

	if(flag) cout << "Yay!" << endl;
	else cout << ":(" << endl;
	return 0;
}


Measured memory_bytes: 764
N, W = gets.split.map(&:to_i)
items = (1..N).map { gets.split.map(&:to_i) }
upper_bound = items.map(&:first).inject(:+)
min_weight = [0] + (1..upper_bound).map { Float::INFINITY }
items.each do |v, w|
  new_min_weight = min_weight.dup
  (v..upper_bound).each do |value|
    new_min_weight[value] = min_weight[value - v] + w if min_weight[value - v] + w < new_min_weight[value]
  end
  min_weight = new_min_weight
end
upper_bound.downto(0) do |value|
  if min_weight[value] <= W
    p value
    break
  end
end


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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

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

    for (ll i = sqrt(n) + 10; ; i--) {
        if (i*i <= n) {
            cout << i*i << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 256
import numpy as np
N = int(input())

m = {}
for i in range(1, N + 1):
  x = str(i)
  if '0' in [x[0], x[-1]]:
    continue
  key = str([x[0], x[-1]])
  add = 1
  
  if key not in m:
    m[key] = add
  else:
    m[key] += add

ans = 0
for i in range(1, 10):
  for j in range(1, 10):
    key = str([str(i), str(j)])
    if key in m:
      d = m[key]
      if i == j:
        ans += d ** 2
      elif str([str(j),str(i)]) in m:
        ans += d * m[str([str(j),str(i)])]
    
print(ans)

Measured memory_bytes: 27132
#include<bits/stdc++.h>
#define ll long long
#define For(i,x,y) for(int i=x;i<=y;i++)
#define Rep(i,x,y) for(int i=x;i>=y;i--)
#define Forn(i,x,y) for(int i=x;i<y;i++)
#define oo 1000000
#define zyy 1000000007
#define N 100005
#define int ll
using namespace std;
inline int read(){int x=0,f=0;char ch=getchar();for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=1;for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-48;return f?-x:x;}
inline void write(int x){if(x<10) putchar(x+48);else write(x/10),putchar(x%10+48);}
inline void writeln(int x){if(x<0) putchar('-'),x=-x;write(x);putchar('\n');}
int n,a[N];
inline int work(){
	int sum=0,ans=0;
	For(i,1,n){
		sum+=a[i];
		if(i&1){
			if(sum<=0) ans+=abs(sum-1),sum=1;
		}else{
			if(sum>=0) ans+=abs(sum+1),sum=-1;
		}
	}
	return ans;
}
main(){
	n=read();int ans1,ans2;
	For(i,1,n) a[i]=read();ans1=work();
	For(i,1,n) a[i]=-a[i];ans2=work();
	writeln(min(ans1,ans2));
	return 0;
}

Measured memory_bytes: 1024
z=chomp(readline())
n=length(z)
x=zeros(Int,n)
x=[parse(Int,y) for y in z]
s0=zeros(Int,n)
s1=zeros(Int,n)
for i=1:n
d2=i%2
s0[i]=d2
s1[i]=1-d2
end
d0=s0-x
d1=s1-x
n0=sum(abs(d0))
n1=sum(abs(d1))
v=min(n0,n1)
print(v)

Measured memory_bytes: 123264
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 

using namespace std;

int main() {
	int i, j,n,m;
	map<int, int>mp1;
	map<int, int>mp2;
	int tmp = 0;

	cin >> n;

	for (i = 0; i < n; i++) {
		cin >> tmp;
		mp1[tmp]++;
	}

	cin >> m;

	for (i = 0; i < m; i++) {
		cin >> tmp;
		mp2[tmp]++;
	}
	

	for (auto itr = mp2.begin(); itr != mp2.end(); ++itr) {
		//std::cout << "key = " << itr->first           // キーを表示
	//		<< ", val = " << itr->second << "\n";    // 値を表示

		mp1[itr->first] = mp1[itr->first] - itr->second;
		if (mp1[itr->first] < 0) {
			cout << "NO" << endl;

			//getchar();
			//getchar();
			return 0;
		}

	}


	cout << "YES" << endl;






	return 0;
}

Measured memory_bytes: 18944
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define EPS 1e-10
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define first_more_idx(ve, num) upper_bound(all(ve), num)-ve.begin() // idx = first_more_idx(ve,num); if(idx = ve.size()) , then not exist
#define first_lessequal_idx(ve, num) lower_bound(all(ve), num)-ve.begin()
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > // only sort first param
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}
ll dx[]={0, 0, -1, 1};
ll dy[]={1, -1, 0, 0};// up,down,left right


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

    ll K;
    string S;
    cin >> K >> S;
    
    if(S.size() <= K){
        cout << S << endl;
    }else{
        rep(i, K){
            cout << S[i] ;
        }
        cout <<"..." << endl;
    }

    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 3656
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 1000000+5;
const int dx[] = {0,0,-1,1,-1,-1,1,1};
const int dy[] = {-1,1,0,0,-1,1,-1,1};
using namespace std;
LL bucket[10];
pair<int,int> node[N];
map<pair<int,int>,int> mp;
int main(){
    LL h,w,n;
    scanf("%lld%lld%lld",&h,&w,&n);
    for(int i=1;i<=n;i++){
        int x,y;
        scanf("%d%d",&node[i].first,&node[i].second);
        mp[node[i]]=1;//涂黑的格子贡献度为1
    }

    for(int i=1;i<=n;i++){
        for(int j=0;j<8;j++){
            int nx=node[i].first+dx[j];
            int ny=node[i].second+dy[j];
            if(nx>=1&&nx<=h&&ny>=1&ny<=w){
                pair<int,int> temp(nx,ny);
                mp[temp]++;
            }
        }
    }

    LL sum=0;
    LL tot=(h-2)*(w-2);
    map<pair<int,int>,int>::iterator it;
    for(it=mp.begin();it!=mp.end();it++){
        int x=it->first.first;
        int y=it->first.second;
        int val=it->second;
        if(x>=2&&x<=h-1&&y>=2&y<=w-1){
            bucket[val]++;
            sum++;
        }
    }
    bucket[0]=tot-sum;

    for(int i=0;i<=9;i++)
        printf("%lld\n",bucket[i]);

    return 0;
}

Measured memory_bytes: 57344
import java.util.Scanner;

public class Main {
  public static void main (String[] args) {
    Scanner in = new Scanner(System.in);

    while (in.hasNext()) {
      int R = in.nextInt();

      if (R < 1200) {
        System.out.println("ABC");
      } else if (R < 2800) {
        System.out.println("ARC");
      } else {
        System.out.println("AGC");
      }
    }
  }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define F first
#define S second
#define pb push_back
mt19937 rnd;


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    int x, y;
    cin >> x >> y;
    cout << (x + y - 1) / y << "\n";

#ifdef LOCAL
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
typedef long long ll;
const ll INF = 1LL<<60;
int main(){
	ll n;
	cin >> n;
	ll ans = INF;
	for (ll i = 1; i*i <= n ; ++i) {
		if(n%i==0){
			ans = min(ans, i + n/i -2);
		}
	}
	cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
#include "stdio.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)

using ll = long long;
using Pii = pair<int, int>;

const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9+7;

int dy[] = { 0, 0, 1, -1, 0 };
int dx[] = { 1, -1, 0, 0, 0 };

using MIte = multimap<ll, ll, greater<ll> >::iterator;



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

	// long long?
	int N;
	cin >> N;

	vector<int> d(N, 0);
	rep(i, N) cin >> d[i];

	int ans = 0;
	for (int i = 0; i != N - 1; ++i) {
		for (int j = i + 1; j != N; ++j) {
			ans += d[i] * d[j];
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
//ABC051-B(Sum of Three Integers)
#include<iostream>
using namespace std;

int k,s;

int main(){
    cin>>k>>s;
    int ans=0;
    //zは決まるので2重forループ
    for(int x=0; x<=k; x++){
        for(int y=0; y<=k; y++){
            int z=s-x-y;//x+y+z=s
            if(z>=0 && z<=k)ans++;
        }
    }
    cout<<ans<<endl;
}

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

pair<int, int> operator+(pair<int, int> a, pair<int, int> b) {
  pair<int, int> ret;
  ret.first = a.first + b.first;
  ret.second = a.second + b.second;
  return ret;
}
pair<int, int> operator-(pair<int, int> a, pair<int, int> b) {
  pair<int, int> ret;
  ret.first = a.first - b.first;
  ret.second = a.second - b.second;
  return ret;
}

int main() {
	
	const vector<pair<int,int>> d{ {-1,0},{0,-1},{1,0},{0,1} };
	
	while(1){
		int w,h;
		cin >> w >> h;
		if(w==0 && h==0) break;
		
		vector<vector<int>> ykabe(h+2,vector<int>(w+2)),xkabe(h+2,vector<int>(w+2));
		for(int i=1; i<=h; i++){
			for(int j=1; j<w; j++) cin >> ykabe.at(i).at(j);
			if (i==h) continue;
			for(int j=1; j<w+1; j++) cin >> xkabe.at(i).at(j);
		}
		vector<vector<int>> fld(h+2,vector<int>(w+2,-1));
		for(int i=1; i<h+1; i++) for(int j=1; j<w+1; j++) fld.at(i).at(j) = 1;
		queue<pair<int,int>> que;
		vector<vector<int>> dist(h+2,vector<int>(w+2,0));
		
		que.push({1,1});
		dist.at(1).at(1) = 1;
		while(!que.empty()){
			auto p = que.front();
			que.pop();
			for(int i=0; i<4; i++){
				auto a = p + d.at(i);
				if(fld.at(a.first).at(a.second)==-1) continue;
				if(i==0 && xkabe.at(p.first-1).at(p.second)==1) continue;
				if(i==1 && ykabe.at(p.first).at(p.second-1)==1) continue;
				if(i==2 && xkabe.at(p.first).at(p.second)==1) continue;
				if(i==3 && ykabe.at(p.first).at(p.second)==1) continue;
				if(dist.at(a.first).at(a.second)==0) {
					que.push(a);
					dist.at(a.first).at(a.second) = dist.at(p.first).at(p.second)+1;
				}
			}
		}
		cout << dist.at(h).at(w) << endl;
	}
}



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

/*alias*/
#define REP(i,n) for (int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
using ll=long long;

using namespace std;

/*input*/
int n;
string s;

/*funcs*/


/*main*/
int main(){
    cin>>n>>s;
    int r=0,l=0;
    for(int i=0;i<s.length();i++){
        if(s[i]=='('){
            r++;
        }else{
            if(r>0){
                r--;
            }else{
                l++;
            }
        }
    }
    for(int i=0;i<l;i++){
        cout<<'(';
    }
    cout<<s;
    for(int i=0;i<r;i++){
        cout<<')';
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define endl '\n';
typedef long long ll;
typedef long double ld;
using namespace std;

const int N = 2020;
int n, m;
char s[N][N];
int ans[N][N];

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s", s[i]);
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0, p = -1; j < m; j++) {
      if (s[i][j] == '#') p = j;
      ans[i][j] += j - p;
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = m - 1, p = m; j >= 0; j--) {
      if (s[i][j] == '#') p = j;
      ans[i][j] += p - j;
    }
  }

  for (int j = 0; j < m; j++) {
    for (int i = 0, p = -1; i < n; i++) {
      if (s[i][j] == '#') p = i;
      ans[i][j] += i - p;
    }
  }

  for (int j = 0; j < m; j++) {
    for (int i = n - 1, p = n; i >= 0; i--) {
      if (s[i][j] == '#') p = i;
      ans[i][j] += p - i;
    }
  }  

  int mx = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      mx = max(mx, ans[i][j] - 3);
    }
  }
  printf("%d\n", mx);

  return 0;
}

Measured memory_bytes: 20096
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    s = input()[::-1]

    res = 0
    dp = [[0] * n for _ in range(n)]
    for i in range(n):
        for j in range(i + 1, n):
            if s[i] == s[j]:
                dp[i][j] = dp[i - 1][j - 1] + 1
                res = max(res, min(j - i, dp[i][j]))

    print(res)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 270284
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		for(int i=0; i<N; i++)
			a[i] = sc.nextInt();
		
		if(firstWin(N, a))
			System.out.println("First");
		else
			System.out.println("Second");
		sc.close();
	}
	
	static boolean firstWin(int N, int[] a) {
		Arrays.sort(a);
		for(int i=0; i<N; i++) {
			if(N-i<=a[i]) {
				boolean win = (a[i]-(N-i))%2==1;
				int sameSize=0;
				for(int j=i-1; j>=0 && a[j]==N-i; j--)
					sameSize++;
				win |= sameSize%2==1;
				return win;
			}
		}
		//never reach
		return false;
	}
	
}

Measured memory_bytes: 23876
import java.util.*;
import java.lang.Math;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int n;
    int h[] = {0,0,0};
    int w[] = {0,0,0};
    int c[] = {0,0};
    int stack;
    int stack1;
    int stack2;
    int stack3;
    boolean nb = true;
    
    Map<Integer, Integer> board = new HashMap<Integer, Integer>();
	
    for(int i = 0; i < 3;i++){
    	for(int j = 0; j < 3;j++){
        	board.put(sc.nextInt(),i * 10 + j);
        }
    }
    
    n = sc.nextInt();
    
    for(int i = 0; i < n;i++){
    	stack = sc.nextInt();
      	if(board.containsKey(stack)){
          stack1 = board.get(stack);
          stack2 = stack1/10;
          stack3 = stack1%10;
          w[stack2]++;
          h[stack3]++;
          if(stack2 == stack3) c[0]++;
          if(2 - stack2 == stack3) c[1]++;
          if(w[stack2] == 3 || h[stack3] ==3 || c[0] == 3 || c[1] == 3) nb = false;
          board.remove(stack);
        }
    }
    
    if(nb) System.out.println("No");
    else System.out.println("Yes");

  }
}


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

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }

int find(char str[]){
  long long key, i, h;
  key = getKey(str);
  for ( i = 0;; i++){
    h = (h1(key)+i*h2(key))%M;
    if( strcmp(H[h],str) == 0 ) return 1;
    else if ( strlen(H[h]) == 0 ) return 0;
  }
  return 0;
}

int insert(char str[]){
  long long key, i, h;
  key = getKey(str);
  for ( i = 0; ; i++ ){
    h = (h1(key)+i*h2(key))%M;
    if( strcmp(H[h],str) == 0 ) return 1;
    else if ( strlen(H[h]) == 0 ){
      strcpy(H[h], str);
      return 0;
    }
  }
  return 0;
}

main(){
  int i, n, h;
  char str[L], com[9];
  for ( i = 0; i < M; i++ ) H[i][0] = '\0';
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ){
    scanf("%s %s", com, str);

    if ( com[0] == 'i' ){
      if (insert(str)){

      }
    } else {
      if (find(str) ){
	printf("yes\n");
      } else {
	printf("no\n");
      }
    }
  }
  return 0;
}



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

using namespace std;

int main(){
  int n; cin >> n;
  string ans = "No";

  for(int i = 1; i < 10; i++) {
    for(int j = 1; j < 10; j++) {
      if( n == ( i * j)) {
        ans = "Yes";
        break;
      }
    }
  }

  cout << ans << endl;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

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

    vector<int> d(N);
    rep(i, N) cin >> d.at(i);

    int sum = 0;
    rep(i, N - 1) {
        for(int j = i + 1; j < N; j++) {
            sum += d.at(i) * d.at(j);
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3632