akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
const int M = 1000000007;

void WarshallFloyd(vector<vector<int>>& d) {
    int n = d.size();
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
            for (int k = 0; k < n; ++k)
                d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
}


int main() {
    while (1) {
        int n, m, l, k, a, h;
        cin >> n >> m >> l >> k >> a >> h;
        if (!n) return 0;

        l += 2;
        vector<int> f(l);
        f[0] = a;
        f[1] = h;
        for (int i = 2; i < l; ++i)
            cin >> f[i];

        vector<vector<int>> dist(n, vector<int>(n, M));
        for (int i = 0; i < n; ++i)
            dist[i][i] = 0;

        for (int i = 0; i < k; ++i) {
            int x, y, t;
            cin >> x >> y >> t;
            dist[x][y] = dist[y][x] = t;
        }
        WarshallFloyd(dist);

        vector<vector<int>> d(l, vector<int>(l, M));
        for (int i = 0; i < l; ++i)
            for (int j = 0; j < l; ++j)
                if (dist[f[i]][f[j]] <= m)
                    d[i][j] = dist[f[i]][f[j]];

        WarshallFloyd(d);
        if (d[0][1] < M)
            cout << (d[0][1] + max(0, d[0][1] - m)) << "\n";
        else
            puts("Help!");
    }
}

Measured memory_bytes: 3156
#include<iostream>	
#include<stdio.h>
#define ll long long
using namespace std;

ll sum,b,a;
ll c,d;

ll ged(ll a,ll b){
	return a==0?sum/b:ged(b%a,a);
}

int main(){
	cin>>a>>b>>c>>d;
	sum=c*d;
	ll e=ged(c,d);
	ll ans=b-a+1;
	ll ans1=b/c-a/c;
	if(a%c==0)ans1++;
	ll ans2=b/d-a/d;
	if(a%d==0)ans2++;
	ll ans3=b/e-a/e;
	if(a%e==0)ans3++;
//	cout<<ans1<<" "<<ans2<<" "<<ans3<<endl;
	ans=ans-ans1-ans2+ans3;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque

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

def main():
    H,W = map(int,input().split())
    A = [list(input()) for _ in range(H)]

    que = deque()
    for x in range(W):
        for y in range(H):
            if A[y][x] == '#':
                que.append((x,y,0))        
    ans = 0
    while que:
        x,y,c = que.popleft()
        for dx,dy in ((-1,0),(1,0),(0,-1),(0,1)):
            sx = x + dx
            sy = y + dy
            if sx < 0 or sx >= W or sy < 0 or sy >= H or A[sy][sx] == '#':
                continue
            if A[sy][sx] == '.':
                que.append((sx,sy,c+1))
                A[sy][sx] = c + 1
                ans = max(ans,c+1)
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 240000
n,x,y=map(int,input().split())
s=[[]for i in range(n+1)]
for i in range(n-1):
    a,b=map(int,input().split())
    s[a].append(b)
    s[b].append(a)
p=[float("INF")for i in range(n+1)]
q=[float("INF")for i in range(n+1)]
p[x]=0
q[y]=0
c=set([x])
while c:
    d=set()
    for i in c:
        for j in s[i]:
            if p[j]>p[i]+1:
                p[j]=p[i]+1
                d.add(j)
    c=d
c=set([y])
while c:
    d=set()
    for i in c:
        for j in s[i]:
            if q[j]>q[i]+1:
                q[j]=q[i]+1
                d.add(j)
    c=d
a=0
for i in range(1,n+1):
    if p[i]<q[i]:
        a=max(a,q[i]-1)
print(a)

Measured memory_bytes: 31844
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld  double
#define pii pair<int,int>
#define pb push_back
#define N 300003
#define inf (ll)1e9+11
#define warmup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int mod=1e9+7;
unordered_set<int> s;

signed main()
{
    warmup
    
    int n,x;
    cin>>n;
    while(n--)
    {
        cin>>x;
        if(s.count(x))
            return cout<<"NO", 0;
        s.insert(x);
    }   
    cout<<"YES";
    
    return 0;
}


Measured memory_bytes: 8520
# -*- coding: utf-8 -*-
A, B, C = map(int, input().split(' '))

if A % 2 == 1 or B % 2 == 1 or C % 2 == 1:
    print(0)
    exit()

ans = 0
while True:
    A, B, C = B // 2 + C // 2, A // 2 + C // 2, A // 2 + B // 2
    ans += 1

    if A % 2 == 1 or B % 2 == 1 or C % 2 == 1:
        break

    if ans > 50:
        ans = -1
        break
    # print(A, B, C)

print(ans)

Measured memory_bytes: 38384
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <cstdio>
#include <cstring>
#define LL long long
using namespace std;

LL h, w, n;
LL re[10];

set< pair<int ,int> > st;
void f(int a, int b) {
    int num[3][3];
    memset(num, -1, sizeof(num));

    for(int i = 0; i < 3; ++i)
    for(int j = 0; j < 3; ++j) {
        int x1 = a - 2 + i, y1 = b - 2 + j;
        int x2 = a + i, y2 = b + j;
        if(x1 < 0 || y1 < 0 || x2 >= h || y2 >= w) continue;
        num[i][j] = 0;
    }
    for(int i = max(a-2, 0); i <= min((LL)a+2, h-1); ++i) {
        for(int j = max(b-2, 0); j <= min((LL)b+2, w-1); ++j) {
            if(st.find( make_pair(i, j) ) != st.end() ) {
                for(int ii = 0; ii < 3; ++ii)
                for(int jj = 0; jj < 3; ++jj) {
                    int x1 = a-2+ii, y1 = b-2+jj;
                    int x2 = a + ii, y2 = b + jj;
                    if(x1 < 0 || y1 < 0 || x2 >= h || y2 >= w) continue;
                    if(i >= x1 && i <= x1+2 && j >= y1 && j <= y1+2) {
                        if(num[ii][jj] == -1) num[ii][jj] = 1;
                        else num[ii][jj] += 1;
                    }
                }
            }
        }
    }
    for(int i = 0; i < 3; ++i)
    for(int j = 0; j < 3; ++j) {
        //cout << a << " " << b << " " << i << " " << j << " " << num[i][j] << endl;
        if(num[i][j] == -1) continue;
        re[ num[i][j] ] --;
        re[ num[i][j] + 1] ++;
    }
}
int main(int argc, char* argv[]) {
    while(cin >> h >> w >> n) {
        st.clear();
        memset(re, 0, sizeof(re));
        re[0] = (h - 2) * (w - 2);
        for(LL i = 0; i < n; ++i) {
            int a, b;
            cin >> a >> b;
            --a, --b;
            f(a, b);
            st.insert( make_pair(a, b) );
        }
        for(int i = 0; i < 10; ++i) {
            cout << re[i] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef long long ll;
const int N = 1e6 + 10;
int add(int x,int y) {
	x += y;
	if (x >= mod) x -= mod;
	return x;
}

int sub(int x,int y) {
	x -= y;
	if (x < 0) x += mod;
	return x;
}

int qpow(int x,int y) {
	int res = 1;
	while (y) {
		if (y & 1) res = 1ll * x * res % mod;
		x = 1ll * x * x % mod;
		y >>= 1;
	}
	return res;
}



int n;
int fac[N] , ifac[N] , inv[N];
void init() {

	ifac[0] = fac[0] = 1;
	for (int i = 1; i < N; i++) {
		fac[i] = 1ll * i * fac[i-1] % mod ;
		inv[i] = qpow(i , mod - 2);
		ifac[i] = 1ll * ifac[i-1] * inv[i] % mod ;
	}
}

int bionm(int m,int n){
	if (m < n || n < 0) return 0;
	return 1ll * fac[m] * ifac[n] % mod * ifac[m - n] % mod;
}
int res , f[N];
int main() {
	scanf("%d",&n);
	init();
	f[1] = 1;
	for (int i = 2;i <= n;i++){
		f[i] = add( 2ll * f[i-1] % mod , i & 1 ? 1 : mod - 1);
	}
	
	for (int i = 1;i <= n;i++){
		res = add(res , 1ll * f[i] * bionm(n , i) % mod * qpow(3ll * n % mod * i % mod , mod - 2) % mod);
	}
	res = 1ll * res * qpow(qpow(3 , n - 1) , mod - 2) % mod;
	cout<<res;
	return 0;
}

Measured memory_bytes: 15872
N=int(input())

H=list(map(int,input().split()))

H[0]-=1

s=0

if N>1:
    if H[0]>H[1]:
        s=1
    
    for i in range(1,N-1):
        if H[i]>H[i-1]:
            H[i]-=1
        if H[i]>H[i+1]:
            s=1


if s==1:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 14396
while True:
    n = int(input())
    if n == 0:
        break
    s = []
    for i in range(n):
        s.append([int(i) for i in input().split()])
    
    p, q, r, c = [int(i) for i in input().split()]

    possible = []
    for i in range(n):
        if (s[i][1] <= p) & (s[i][2] <= q) & (s[i][3] <= r) & ((4 * (s[i][1] + s[i][3]) + 9 * s[i][2]) <= c):
            possible.append(s[i][0])

    if possible == []:
        print('NA')
    else:
        for i in possible:
            print(i)

Measured memory_bytes: 7860
#include <iostream>

using namespace std;

int main()
{
	unsigned long n, m, a = 0;
	cin >> n >> m;
	if ( n < ( m / 2 ) ) {
		a = n + ( m - n * 2 ) / 4;
	} else {
		a = m / 2;
	}

	cout << a << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	int n, m;
	while (cin >> n, n) {
		vector<pair<int,int> > v(200);
		for (int i=0; i<n; ++i) cin >> v[i].first >> v[i].second;
		cin >> m;
		for (int i=n; i<n+m; ++i) cin >> v[i].first >> v[i].second;
		sort(v.begin(), v.begin()+n+m);
		int mx = 0, dp[200];
		for (int i=0; i<n+m; ++i) {
			dp[i] = 1;
			for (int j=0; j<i; ++j) {
				if (v[j].first < v[i].first && v[j].second < v[i].second) {
					dp[i] = max(dp[i], dp[j] + 1);
				}
			}
			mx = max(mx, dp[i]);
		}
		cout << mx << endl;
	}
	return 0;
}

Measured memory_bytes: 1200
#include <stdio.h>
#include <iostream>
#define Re register int

int T,X;

template <typename T> inline void read(T &var)
{
	T x=0; int w=0; char ch=0;
	while (!isdigit(ch)) w|=ch=='-',ch=getchar();
	while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	var=w?-x:x;
}
int main(int argc, char const *argv[])
{
	//freopen("1.in","r",stdin);
	read(T),read(X);
	printf("%.10lf",double(T)/double(X));
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
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)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int x;cin>>x;
    if(x==3)cout<<"YES"<<endl;
    else if(x==5)cout<<"YES"<<endl;
    else if(x==7)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

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

int W,H,K;
int m[1001][1001];
int c[1001][1001];

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

int sim(){
	int x = 0 , y = 0;
	while(x < W && y < H){

		int d = c[y][x];
		x += dx[d];
		y += dy[d];
	}
	cout << y+1 << " " << x+1 << endl;
}

int main(){

	while(cin >> H >> W >> K && H){
		for(int i = 0 ; i < H ; i++){
			for(int j = 0 ; j < W ; j++){
				cin >> m[i][j];
				c[i][j] = 0;
			}
		}
		c[0][0] = K-1;
		for(int i = 0 ; i < H ; i++){
			for(int j = 0 ; j < W ; j++){
				int x = c[i][j];
				c[i+1][j] += x/2;
				c[i][j+1] += x/2;
				c[i+dy[m[i][j]]][j+dx[m[i][j]]] += x%2; 
			}
		}
		for(int i = 0 ; i < H ; i++){
			for(int j = 0 ; j < W ; j++){
				c[i][j] = (c[i][j]+m[i][j])%2;
			}
		}
		sim();
	}
}

Measured memory_bytes: 8696
#include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

// author:Swastik Banerjee

using namespace std;

typedef long long ll;
#define MOD 1000000007

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



  ll N, K;
  cin >> N >> K;

  ll h[N];
  for (ll i = 0; i < N; i++) {
    cin >> h[i];
  }

  ll dp[N];
  for (ll i = 0; i < N; i++) {
    dp[i] = LLONG_MAX;
  }
  dp[0] = 0;

  for (ll i = 1; i < N; i++) {
    ll curr;
    for (ll j = 1; j <= K; j++) {
      if (i - j < 0) break;
      curr = dp[i - j] + abs(h[i] - h[i - j]);
      if (curr < dp[i]) dp[i] = curr;
    }
  }

  cout << dp[N - 1];
}

Measured memory_bytes: 1792
#include <iostream>
#define endl '\n'
#define ll long long

using namespace std;

int main() {
    int n, x;

    cin >> n >> x;
    int l[n];

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

    int d[n];
    int sum = 0;

    d[0] = 0;
    
    if(x > 0) {
        sum += 1;
    }

    for(int i = 1; i < n + 1; i++) {
        d[i] = d[i - 1] + l[i - 1];

        if(d[i] > x) {
            break;
        }

        else {
            sum += 1;
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
# Coding is about expressing your feeling and there is always a better way to express your feeling _feelme
import sys,math,numpy as np
#sys.stdin,sys.stdout=open('input.txt','r'),open('output.txt','w')
from sys import stdin,stdout;mod=int(1e9 + 7);from statistics import mode
from collections import *;from math import ceil,floor,inf,factorial,gcd,log2,sqrt
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
# print('{:.3f}'.format(1),round(1.123456789,4))
# np.set_printoptions(sign=' ',legacy='1.13') # legacy add space at sign position
# sys.setrecursionlimit(500000)
def lcm(a,b): return (a*b)//gcd(a,b)
def setbits(n):return bin(n).count('1')
def resetbits(n):return bin(n).count('0')
def modinv(n,p):return pow(n,p-2,p)
def ncr(n,r):
    num,den=1,1;r=min(n,n-r)
    for i in range(r):num*=(n-i);den*=(i+1)
    return num//den
def ncr_p(n, r, p):
    num,den=1,1;r=min(r,n-r)
    for i in range(r):num = (num * (n - i)) % p ;den = (den * (i + 1)) % p
    return (num * modinv(den,p)) % p
def isPrime(num) :
    if num<=1:return False
    if num==2 or n==3:return True
    if (num % 2 == 0 or num % 3 == 0) :return False
    m = int(num**0.5)+1
    for i in range(5,m,6):
        if (num % i == 0 or num % (i + 2) == 0) :return False
    return True
def bin_search(arr, low, high, val):
    while low <= high:
        mid = low + (high - low) // 2;
        if arr[mid] == val:return mid
        elif arr[mid] < val:low = mid + 1
        else:high = mid - 1
    return -1
def sumofdigit(num):
    count=0;
    while num : count+=num % 10;num //= 10;
    return count;
def inputmatrix():
    r,c=iia();mat=[0]*r;
    for i in range(r):mat[i]=iia();
    return r,c,mat;
def prefix_sum(n,arr):
    for i in range(1,n):arr[i]+=arr[i-1]
    return arr;
def binomial(n, k):
    if 0 <= k <= n:
        ntok = 1;ktok = 1
        for t in range(1, min(k, n - k) + 1):ntok *= n;ktok *= t;n -= 1
        return ntok // ktok
    else:return 0
def divisors(n):
    res = [];
    for i in range(1,ceil(sqrt(n))+1):
        if n%i == 0:
            if i==n//i:res.append(i)
            else:res.append(i);res.append(n//i)
    return res;


def fun(k):
    current=7
    for i in range(1,10**6):
        if current%k==0:
            return i
        current*=10
        current+=7
        current=current%k
    return -1
k = ii1()
print(fun(k))


Measured memory_bytes: 27316
x, y = map(int, input().split())
a = {1, 3, 5, 7, 8, 10, 12}
b = {4, 6, 9, 11}
c = {2}

if x in a and y in a or x in b and y in b or x in c and y in c:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 2940
def is_palindrome(s):
    l = len(s)
    return s[:l // 2] == s[l // 2 + l % 2:][::-1]


S = input()
L = len(S)

if is_palindrome(S) and is_palindrome(S[:L // 2]) and is_palindrome(S[L // 2 + 1:]):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

int main() {
    int t=1;
    //cin >> t;
    while(t--){
        ll n,i,j,x;
        int a[3][3];
        for(i=0;i<3;i++){
            for(j=0;j<3;j++){
                cin >> a[i][j];
               // m[a[i][j]]++;
            }
        }
        cin >> n;
        vector<int>v;
        for(i=0;i<n;i++){
            cin >> x;
            v.push_back(x);
        }
        bool vis[3][3]={false};
        for(i=0;i<3;i++){
            for(j=0;j<3;j++){
                for(int k=0;k<v.size();k++){
                    if(v[k]==a[i][j]){
                        vis[i][j]=true;
                    }
                }
            }
        }
        bool f=1,g=1,h=1,m=1,l=1,c=1,q=1,u=1;
        for(i=0;i<3;i++){
            if(!vis[0][i]){
                f=0;
            }
        }
        for(i=0;i<3;i++){
            if(!vis[2][i]){
                g=0;
            }
        }
        for(i=0;i<3;i++){
            if(!vis[1][i]){
                q=0;
            }
        }
        for(i=0;i<3;i++){
            if(!vis[i][1]){
                u=0;
            }
        }
        for(i=0;i<3;i++){
            if(!vis[i][0]){
                h=0;
            }
        }
        for(i=0;i<3;i++){
            if(!vis[i][2]){
                m=0;
            }
        }
        for(i=0;i<3;i++){
            if(!vis[i][i]){
                l=0;
            }
        }
        j=2;
        for(i=0;i<3;i++){
            if(!vis[i][j]){
                c=0;
            }
            j--;
        }
        if(f||g||h||m||l||c||u||q){
            cout <<"Yes"<<endl;
        }else{
            cout << "No"<<endl;
        }
    }
}

Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<cstdlib>
#include<math.h>
using namespace std;
int main(void){
    long long a,b,an,bn;
    int t[1000],flag=0;
    cin >> a >> b;
    t[0]=1;
    for(int i=1;i<1000;i++){
        t[i]=t[i-1]+i;
    }
    for(int j=1;j<499500;j++){
        an=a+j;
        bn=b+j;
        for(int k=0;k<999;k++){
            if(an==t[k]&&bn==t[k+1]){
                printf("%d",j-1);
                flag=1;
            }
            if(flag)
                break;
        }
        if(flag)
            break;
    }
    return 0;
    
}

Measured memory_bytes: 384
h,w=map(int,input().split())
mat=[]
dp=[]
dp.append([0]*(w+1))

for i in range(h):
    l=input()
    mat.append(l)
    dp.append([0]*(w+1))

dp[0][1]=1
for i in range(h):
    for j in range(w):
        if mat[i][j]=='.':
            dp[i+1][j+1]=(dp[i][j+1]+dp[i+1][j])%1000000007
            

print(dp[h][w])

Measured memory_bytes: 43644
#入力
h, w = map(int, input().split())
a = [''] * h
for i in range(h):
	a[i] = input()
    
#リストを作っておく
row = [False] * h
col = [False] * w

# "#" となっているところをTrueに変える
for i in range(h):
	for j in range(w):
		if a[i][j] == '#':
			row[i] = True
			col[j] = True

for i in range(h):
	if row[i]:#iがTrueなら
		for j in range(w):
			if col[j]:#jがTrueなら
				print(a[i][j], end = '')#出力
		print()


Measured memory_bytes: 4468
from collections import deque
n,m = map(int, input().split())
rev = [list() for _ in range(n+1)]
tr = [0]*(n+1)
ans = [0]*(n+1)
for _ in range(m):
  x,y = map(int,input().split())
  rev[y].append(x)
  tr[x] += 1
q = deque()
for i in range(1,n+1):
  if tr[i] == 0:
    q.append(i)
while q:
  cur = q.popleft()
  for x in rev[cur]:
    tr[x] -= 1
    ans[x] = max(ans[x],ans[cur]+1)
    if tr[x] == 0:
      q.append(x)
print(max(ans))

Measured memory_bytes: 23036
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int n,q;
	std::cin >> n >> q;
	std::vector<int> a(n);
	rep(i,n) std::cin >> a[i];
	std::vector<int> alternate(n+1,0);
	std::vector<int> ac(n+1,0);
	rep(i,n) {
		ac[i+1] = ac[i] + a[i];
		alternate[i+1] = alternate[i] + ((i+n)%2?a[i]:0);
	}
	debug(ac,alternate);
	rep(xxx,q) {
		int x;
		std::cin >> x;
		int l=0;int r=n;
		while(r-l>1) {
			int mid = (l+r)/2;
			if(n-mid*2-1<0 || std::abs(x-a[n-mid-1])<std::abs(x-a[n-2*mid-1])) r=mid;
			else l=mid;
		}
		print(alternate[std::max(0ll,n-2*r)]+ac[n]-ac[n-r]);
	}

	return 0;
}


Measured memory_bytes: 4096
N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
next_town=1
_vt=[1]
visited_town={1:0}
for i in range(K):
  now_town=next_town
  next_town=A[now_town-1]
  if next_town in visited_town:
    i_town=_vt.index(next_town)
    K-=i_town
    _vt=_vt[i_town:]
    goal=K % len(_vt)
    print(_vt[goal])
    break
  else:
    _vt.append(next_town)
    visited_town[next_town]=0
else:
  print(next_town)

Measured memory_bytes: 32380
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int N;
    cin >> N;
    vector<ll> s[N];
    for (int i = 0; i < N; i++) {
        int M;
        cin >> M;
        for (int j = 0; j < M; j++) {
            int c;
            cin >> c;
            s[i].push_back(c);
        }
    }
    
    ll sum = 0;
    priority_queue<ll, vector<ll>> pq;
    for (int i = N - 1; i >= 0; i--) {
        for (int j = 0; j < s[i].size(); j++) {
            pq.push(s[i][j]);
        }
        sum += pq.top();
        pq.pop();
    }
    
    cout << sum << "\n";
    return 0;
}


Measured memory_bytes: 19496
#include <cstdio>
int a[50],b,N;
int main(){scanf("%d",&N);if(N==0) printf("0");for(b=0;N!=0;N>>=1,b++){a[b]=N&1;if(b%2) N+=2*a[b];}while(b>0) printf("%d",a[--b]);return 0;}

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

using ll = long long;

//constant
const ll MOD = 1e+9 + 7;
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// view vector
template<typename T> void view(T e) { std::cout << e << std::endl; }
template<typename T> void view(const std::vector<T>& v) { for (const auto& e : v) { std::cout << e << " "; } std::cout << std::endl; }
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v : vv) { view(v); } }


// ***************************************


int main(void){

    int N, K;
    cin >> N >> K;

    vector<double> vec(N);
    double x, v;
    queue<double> old;
    double ans = 0;
    double s = 0.0;
    REP(i, N) {
        cin >> v;
        x = (v + 1) / 2;

        s += x;
        old.push(x);
       
        if (i >= K) {
            double d = old.front(); old.pop();
            s -= d;
        }
		ans = max(ans, s);
    }

    printf("%.10f", ans);

    return 0;
}

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

const int MOD=(int)1e9+7;
const int MAX=110000;
long long fac[MAX],finv[MAX],inv[MAX];
//テーブルを作る前処理
void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2;i<MAX;i++){
    fac[i]=fac[i-1]*i%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}
//二項係数の計算
long long COM(int n,int k){
  if(n<k) return 0;
  if(n<0 || k<0)  return 0;
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

int main(){
  COMinit();

  int n;
  cin >> n;
  vector<int> a(n+1);
  for(int i=0;i<n+1;i++)  cin >> a.at(i);

  set<int> S;
  int x=-1;
  for(int i=0;i<n+1;i++){
    if(S.count(a.at(i))){
      x=a.at(i);
      break;
    }
    S.insert(a.at(i));
  }
  int l=-1,r=-1;
  for(int i=0;i<n+1;i++){
    if(a.at(i)==x){
      if(l==-1) l=i;
      else  r=i;
    }
  }

  for(int i=1;i<=n+1;i++){
    long long ans=0;
    //同じ数字をxとすると
    //xを0個含むとき
    ans+=COM(n+1-2,i);
    ans%=MOD;
    //xを1個含むとき
    long long res=2*COM(n+1-2,i-1);
    res%=MOD;
    res+=MOD - COM(n+1-2-(r-1-l),i-1);
    res%=MOD;
    ans+=res;
    ans%=MOD;
    //xを2個含むとき
    ans+=COM(n+1-2,i-2);
    ans%=MOD;
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 8832
//libraries
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//namespace
using namespace std;
using namespace __gnu_pbds;

//typedef
//typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<long long> vll;

//define
#define i(X) cin>>X;
#define ol(X) cout<<X<<endl;
#define os(X) cout<<X<<" ";
#define inpv(a,n) vector<ll> a(n); for(ll i=0;i<n;i++){cin>>a[i];}
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define line cout<<"\n";
#define pbp(a,b) push_back(make_pair(a,b));
#define iniv(A,n,p) vector<ll> A(n,p);
#define vst(A) sort(A.begin(),A.end());
#define rvst(A) sort(A.rbegin(),A.rend());
#define forin(i,a,b) for(ll i=a;i<=b;i++)
#define forde(i,a,b) for(ll i=a;i>=b;i--)
#define fio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const long long inf=(long long)1e18;
long long MOD=(long long)(1e9+7);
ll mod=MOD;

ll power(ll x,ll y)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2) % MOD;
    p = (p * p) % MOD;

    return (y%2 == 0)? p : (x * p) % MOD;
}

int main() 
{
	// #ifndef ONLINE_JUDGE
    //    freopen ("input.txt" , "r" , stdin);
	// 	// freopen ("OUTPUT.txt" , "w" , stdout);
	// #endif
	fio;
	ll testcase=1;
	//cin>>testcase;
	while(testcase--)
	{
		// string s,t;
		// cin>>s>>t;
		// ll len=0;
		// forde(j,t.length()-1,0)
		// {
		// 	if(s.find(t.substr(0,j))!=-1)
		// 	{
		// 		len=max(len,j);
		// 		//cout<<len<<" ";
		// 		break;
		// 	}
		// }
		// ll ans=t.length()-len;
		// cout<<ans<<endl;
		ll n;
		cin>>n;
		vector<ll> a(n);
		vector<ll> pre(n+1,0);
		ll s=0;
		forin(i,0,n-1)
		{
			cin>>a[i];
		}
		forde(i,n-1,0)
		{
			s=(a[i]+s)%mod;
			pre[i]=s;
		}
		ll ans=0;
		forin(i,0,n-2)
		{
			ans=(ans+(a[i]*pre[i+1])%mod)%mod;
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 6344
def input_from_console():
    n = int(input())
    return n



def solve(num):
    for i in range(1, 10):
        if int(num/i) <= 9 and int(num/i) == num/i:
            return 'Yes'
    return 'No'



def main():
    n = input_from_console()

    print(solve(n))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  # Check if the python interpreter is in debug mode or not.
        check_cases()
    else:
        main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

int n, m;

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n;
	map<int, int> mp1, mp2;
	FOR(i, n) {
		int x;
		cin >> x;
		mp1[x]++;
	}
	cin >> m;
	FOR(i, m) {
		int x;
		cin >> x;
		mp2[x]++;
	}
	bool ok = true;
	for (auto itr = mp2.begin(); itr != mp2.end(); itr++) {
		if (itr->second > mp1[itr->first]) ok = false;
	}
	cout << (ok ? "YES" : "NO") << endl;
	return 0;
}

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

typedef struct{
	int data;
}dice;

int main(void)
{
	int i;
	int da[5];
	char move[101];
	int length; 
	dice temp_a;
	dice temp_b;

	for(i=0; i<6; i++){
	scanf("%d",&da[i]);	/*?????¢?????°???*/
	}
	
	dice one[6] = {
	{da[0]},
	{da[1]},
	{da[2]},
	{da[3]},
	{da[4]},
	{da[5]},
	};

	scanf("%s",move);	/*??????*/
	length = (int)strlen(move);
	for(i=0; i<length; i++){	/*?????¢?????????????????°???????????????*/
	if(move[i] == 'E'){
		temp_a = one[2]; 
		one[2] = one[0]; 
		temp_b = one[5]; 
		one[5] = temp_a; 
		temp_a = one[3]; 
		one[3] = temp_b; 
	}
	else if(move[i] == 'N'){
		temp_a = one[4];
		one[4] = one[0];
		temp_b = one[5];
		one[5] = temp_a;
		temp_a = one[1];
		one[1] = temp_b;
	}
	else if(move[i] == 'S'){
		temp_a = one[1];
		one[1] = one[0];
		temp_b = one[5];
		one[5] = temp_a;
		temp_a = one[4];
		one[4] = temp_b;
	}
	else if(move[i] == 'W'){
		temp_a = one[3];
		one[3] = one[0];
		temp_b = one[5];
		one[5] = temp_a;
		temp_a = one[2];
		one[2] = temp_b;
	}
	one[0] = temp_a;
	}

	printf("%d\n",one[0].data);

return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#include <iostream>
#include <numeric>
#include <string>
#include <list>
#include <limits>
#include <type_traits>
#include <vector>

using namespace std;

int main(void) {

    int s ,w;

    cin >> s;
    cin >> w;
    
    if ( w >= s  ) {
        cout << "unsafe";
    }
    else {
        cout << "safe";

    }

    
}

Measured memory_bytes: 3636
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;

    auto r = long.max;
    foreach (x; 0..N+1) {
        long rr;

        auto a = x;
        while (a) rr += a%6, a /= 6;

        auto b = N-x;
        while (b) rr += b%9, b /= 9;

        r = min(r, rr);
    }
    writeln(r);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//#include<stdio.h>
//#include<string.h>
typedef long long ll;
int main()
{
	ll n,sum=0;
	double a;
	scanf("%lld",&n);
	if(n<=1)
	sum=0;
	else
	sum=(1+n)*(n/2);
	if((n/2)*2!=n)
	{
		sum=sum+((1+n)/2)-n;
	}
	else
	sum=sum-n;
	printf("%lld",sum);
}

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

int main()
{
  int n, p[20];
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> p[i];
  int ans = n - 2;
  for (int i = 1; i + 1 < n; i++)
    if (p[i] < min(p[i - 1], p[i + 1]) || p[i] > max(p[i - 1], p[i + 1]))
      ans--;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int x,ans = 1;
  scanf("%d",&x);
  for(int i = 2; i <= x; i++)
  {
    int now = i * i;
    while(now <= x)
    {
      ans = max(ans,now);
      now *= i;
    }
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 256
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int n,h,w;

int main()
{
	cin>>n>>h>>w;
	cout<<(n-h+1)*(n-w+1)<<endl;
	rt0;
}

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

int main(){
    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    if(abs(c-1) > 1e18){
        cout << "Unfair" << endl;
        return 0;
    }

    if(k % 2 == 1){
        cout << b-a << endl;
    }else{
        cout << a-b << endl;
    }
    return 0;
}

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

using ll=long long;
#define int ll

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

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

signed main(){
	int N;
	cin >> N;
	int A[N];
	REP(i,N){
		cin >> A[i];
	}
	sort(A,A+N);
	cout << A[N-1] - A[0] << endl;
}

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

int main()
{
   int n,k;
   cin >> n >> k;
   vector<int> h(n);
   rep(i,n) cin >> h[i];
   vector<int> dp(n,INF);
   dp[0] = 0;
   for(int i = 0; i < n-1;i++)
   {
      for(int j =1; j <=k; j++)
      {
         if(i+j >= n)continue;
         int c = abs(h[i+j] - h[i]);
         dp[i+j] = min(dp[i+j], dp[i] + c);
      }
   }
   cout << dp[n-1] << endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws java.io.IOException {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] k = new int[n];
		int[] p = new int[n];
		for(int i = 0 ; i<n ; i++){
			k[i] = scan.nextInt();
			p[i] = scan.nextInt();
		}
		for(int i = 0 ; i<n ; i++){
			if(k[i]%p[i] == 0){
				System.out.println(p[i]);
			}else{
				System.out.println(k[i]%p[i]);
			}
		}
	}
}

Measured memory_bytes: 20372
h, w = map(int, input().split())
grid = []
for i in range(h):
    grid.append(list(input().rstrip()))

lat = [[0] * w for _ in range(h)]
lng = [[0] * w for _ in range(h)]

for i in range(h):
    count = 0
    for j in range(w):
        if grid[i][j] == '#':
            for k in range(j-count, j):
                lat[i][k] = count
            count = 0
        else:
            count += 1
    for k in range(w-count, w):
        lat[i][k] = count

for j in range(w):
    count = 0
    for i in range(h):
        if grid[i][j] == '#':
            for k in range(i-count, i):
                lng[k][j] = count
            count = 0
        else:
            count += 1
    for k in range(h-count, h):
        lng[k][j] = count

ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, lat[i][j] + lng[i][j] - 1)

print(ans)


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

int main() {
  int N, K; cin >> N >> K;
  int H[N]; for (int i = 0; i < N; i++) cin >> H[i];
  sort(H, H + N);
  long res = 0; for (int i = 0; i < N - K; i++) res += H[i];
  cout << res << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
using namespace std;
#define ll long long
int main()
{
    ll ans = 1e18;
    ll x ;
    cin>>x;
    ll sqx = sqrt(x);
    for(int i = sqx;i>=1;i--)
    {
        if(x%i == 0)
        {
            ans = min(ans,(x/i)+i-2);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
def binary_search(list_sorted, x):
    low = 0
    high = len(list_sorted) - 1
    
    while low <= high:
        center = (low + high) // 2

        if   list_sorted[center] == x:
            return 1        
        elif list_sorted[center] <  x:
            low  = center + 1
        elif list_sorted[center] >  x:
            high = center - 1
        else:
            raise

    return 0


n = int(input())

A = tuple(map(int, input().split()))

q = int(input())


for _ in range(q):

    k = int(input())

    print(binary_search(A, k))



Measured memory_bytes: 17556
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  string s;
  vector<int> v;
  cin>>n>>k>>s;
  
  int idx=0,ans=0;
  v.push_back(0);
  while(idx<n){
    int cnt=1;
    while(idx+1<n&&s[idx]==s[idx+1]){
      cnt++;
      idx++;
    }
    idx++;
    v.push_back(cnt);
  }
  for(int i=0;i<(int)v.size()-1;i++){
    v[i+1]+=v[i];
  }
  if(s[0]=='1'){
    if((int)v.size()-1-(k*2+1)<=0){
      cout<<n<<endl;
    }else{
      for( int i=0;i<(int)v.size();i++){
        if(i%2==0&&i+k*2<(int)v.size()){
            ans=max(ans,v[i+k*2]-v[i]);
            if(i+k*2+1<(int)v.size()){
              ans=max(ans,v[i+k*2+1]-v[i]);
            }
        }else if(i%2==1&&i+k*2-1<(int)v.size()){
          ans=max(ans,v[i+k*2-1]-v[i]);
          if(i+k*2<(int)v.size()){
              ans=max(ans,v[i+k*2]-v[i]);
            }
        }
      }
      cout<<ans<<endl;
   }
}else{
      if((int)v.size()-1-(k*2)<=0){
        cout<<n<<endl;
      }else{
        for( int i=0;i<(int)v.size();i++){
          if(i%2==0&&i+k*2-1<(int)v.size()){
            ans=max(ans,v[i+k*2-1]-v[i]);
            if(i+k*2<(int)v.size()){
               ans=max(ans,v[i+k*2]-v[i]);
             }
          }else if(i%2==1&&i+k*2<(int)v.size()){
            ans=max(ans,v[i+k*2]-v[i]);
            if(i+k*2+1<(int)v.size()){
              ans=max(ans,v[i+k*2+1]-v[i]);
            }
          }
        }
        cout<<ans<<endl;
     }
  }
  return 0;
}


Measured memory_bytes: 1020
#include<iostream>
#include<string>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b+c){
		cout<<"Yes"<<endl;
	}
	else if(b==a+c){
		cout<<"Yes"<<endl;
	}
	else if(c==a+b){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
		
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

long long int INF = 3e18;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←


#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl


ll mod = 1000000007;
ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}

ll n,m,num,sum,a,b,c,d,e,f,g,h,i,j,k,w,ok,ng,l,q,ans;
ll x[500005],y[500005],z[500005];
ll dp[3005][3005];
char s[500005],t[500005];
bool flag,dame;

int main(){
    cin >> n >> m >> c;
	for(i=0;i<m;i++)cin >> x[i];
	for(i=0;i<n;i++){
		a = c;
		for(j=0;j<m;j++){
			cin >> b;
			a += b * x[j];
		}
		if(a > 0)ans++;
	}
	p(ans);

	return 0;
}

Measured memory_bytes: 27008
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int S=100;
  cin>>N;
  for(int i=0;i<N;i++){
    int A;
    int B=0;
    cin>>A;
    while(A%2==0){
      B++;
      A/=2;
    }
    if(S>B)
      S=B;
  }
  cout<<S<<endl;
}

Measured memory_bytes: 256
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define repr(i,a,b) for (int i = a; i > b; --i)
#define mm(lamb, tttt) memset(lamb, tttt, sizeof lamb)
 
#define null NULL
#define eps 0.000000001
#define mod 1000000007
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define sz(V) (int)V.size()
#define _ <<" "<<
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;
bool dp[200000];

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 	
//	freopen ("test.txt","r",stdin);
	//string a,b;
	//cin>>a>>b;
	int n,k;
	cin>>n>>k;
	int a[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	for (int i = 0; i < n+2; ++i)
	{
		dp[i] = 0;
	}

	for (int i = 1; i <= k ; ++i)
	{
		bool temp = 0;

		for(int j=0;j<n;j++)
		{
			if( i - a[j] >= 0)
			{
				temp = temp + ( !dp[i-a[j]] );
				//cout<<i _ a[j] _ dp[i - a[j]] _ temp;
				//cout<<endl;
			}

		}
		//cout<<temp<<endl;
		dp[i] = temp;

		//cout<<dp[0] _ i <<endl;
	}

	
	if(dp[k])cout<<"First";
	else cout<<"Second";

}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=1; i<=(n);i++)
typedef long long ll;

int main(){
    int n, m; cin >> n >> m;
    n--;m--;
    cout << ((n*(n+1))/2)  + ((m*(m+1))/2)<< endl;
    return 0;
}


Measured memory_bytes: 888
import bisect
def main():
    N = int(input())
    dx = {}
    dy = {}
    dxpy = {}
    dxmy = {}
    for _ in range(N):
        x, y, u = input().split()
        x = int(x)
        y = int(y)
        if u in dx:
            if x in dx[u]:
                dx[u][x].append(y)
            else:
                dx[u][x] = [y]
            if y in dy[u]:
                dy[u][y].append(x)
            else:
                dy[u][y] = [x]
            if x + y in dxpy[u]:
                dxpy[u][x+y].append(y)
            else:
                dxpy[u][x+y] = [y]
            if x - y in dxmy[u]:
                dxmy[u][x-y].append(y)
            else:
                dxmy[u][x-y] = [y]
        else:
            dx[u] = {}
            dx[u][x] = [y]
            dy[u] = {}
            dy[u][y] = [x]
            dxpy[u] = {}
            dxpy[u][x+y] = [y]
            dxmy[u] = {}
            dxmy[u][x-y] = [y]
    for d in [dx, dy, dxpy, dxmy]:
        for j in d:
            for k in d[j]:
                d[j][k].sort()
    M = 3 * (10**6)
    ###SHOUMEN SHOTOTSU
    # U and D
    if "U" in dx and "D" in dx:
        for x in dx["U"]:
            if x not in dx["D"]:
                continue
            for y in dx["U"][x]:
                yi = bisect.bisect_left(dx["D"][x], y)
                if yi < len(dx["D"][x]):
                    M = min((dx["D"][x][yi] - y)*5, M)
    # L and R
    if "L" in dy and "R" in dy:
        for y in dy["R"]:
            if y not in dy["L"]:
                continue
            for x in dy["R"][y]:
                xi = bisect.bisect_left(dy["L"][y], x)
                if xi < len(dy["L"][y]):
                    M = min((dy["L"][y][xi] - x)*5, M)
    ###KOUSA
    # D and R
    if "D" in dy and "R" in dy:
        for s in dxmy["R"]:
            if s not in dxmy["D"]:
                continue
            for p in dxmy["R"][s]:
                yi = bisect.bisect_left(dxmy["D"][s], p)
                if yi < len(dxmy["D"][s]):
                    M = min((dxmy["D"][s][yi] - p)*10, M)
    # L and U
    if "L" in dy and "U" in dy:
        for s in dxmy["U"]:
            if s not in dxmy["L"]:
                continue
            for p in dxmy["U"][s]:
                yi = bisect.bisect_left(dxmy["L"][s], p)
                if yi < len(dxmy["L"][s]):
                    M = min((dxmy["L"][s][yi] - p)*10, M)
    # U and R
    if "U" in dy and "R" in dy:
        for s in dxpy["U"]:
            if s not in dxpy["R"]:
                continue
            for p in dxpy["U"][s]:
                yi = bisect.bisect_left(dxpy["R"][s], p)
                if yi < len(dxpy["R"][s]):
                    M = min((dxpy["R"][s][yi] - p)*10, M)
    # L and D
    if "D" in dy and "L" in dy:
        for s in dxpy["L"]:
            if s not in dxpy["D"]:
                continue
            for p in dxpy["L"][s]:
                yi = bisect.bisect_left(dxpy["D"][s], p)
                if yi < len(dxpy["D"][s]):
                    M = min((dxpy["D"][s][yi] - p)*10, M)
    return M
x = main()
if x < 3 * (10**6):
    print(x)
else:
    print('SAFE')


Measured memory_bytes: 230844
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n, i, count[] = new int[26];
		String str = "", str1="", eng = "abcdefghijklmnopqrstuvwxyz";
		char c;
		
		while(scan.hasNext()){
			str1=scan.next();
			str+=str1;
		}
		str = str.toLowerCase();
		n = str.length();
		for (i = 0; i < 26; i++) {
			count[i] = 0;
		}
		for (i = 0; i < n; i++) {
			c = str.charAt(i);
			switch (c) {
			case 'a':
				count[0]++;
				break;
			case 'b':
				count[1]++;
				break;
			case 'c':
				count[2]++;
				break;
			case 'd':
				count[3]++;
				break;
			case 'e':
				count[4]++;
				break;
			case 'f':
				count[5]++;
				break;
			case 'g':
				count[6]++;
				break;
			case 'h':
				count[7]++;
				break;
			case 'i':
				count[8]++;
				break;
			case 'j':
				count[9]++;
				break;
			case 'k':
				count[10]++;
				break;
			case 'l':
				count[11]++;
				break;
			case 'm':
				count[12]++;
				break;
			case 'n':
				count[13]++;
				break;
			case 'o':
				count[14]++;
				break;
			case 'p':
				count[15]++;
				break;
			case 'q':
				count[16]++;
				break;
			case 'r':
				count[17]++;
				break;
			case 's':
				count[18]++;
				break;
			case 't':
				count[19]++;
				break;
			case 'u':
				count[20]++;
				break;
			case 'v':
				count[21]++;
				break;
			case 'w':
				count[22]++;
				break;
			case 'x':
				count[23]++;
				break;
			case 'y':
				count[24]++;
				break;
			case 'z':
				count[25]++;
				break;
			default:
				break;
			}
		}
		for (i = 0; i < 26; i++) {
			System.out.println(eng.charAt(i) + " : " + count[i]);
		}
	}
}


Measured memory_bytes: 26560
#include<stdio.h>

int binarySearch(int*,int*,int,int);

int main(){
  int n,q,i;
  int S[100000],T[50000];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }

  printf("%d\n",binarySearch(S,T,n,q));
  return 0;
}
       
int binarySearch(int *S,int *T,int n,int q){
  int left=0,right=n,mid;
  int i,cnt=0;

  for(i=0;i<q;i++){\
    left=0;
    right=n;
    while(left<right){
      mid=(left+right)/2;
      if(S[mid] == T[i]){
	cnt++;
	break;
      }else if(S[mid] >T[i]){
	right=mid;
      }else left=mid+1;
    }
    
  }
  return cnt;
}



Measured memory_bytes: 2368
import numpy as np

N,M,X = map(int,input().split())
book = [list(map(int,input().split())) for i in range(N)]
npbook = np.array(book)
flag = -1
minsum = 1000000000

for i in range(2**N):
    sumyenskill = np.zeros(M+1)
    for j in range(N):
        if (i>>j)&1 ==1:
            sumyenskill += book[j]

    if min(sumyenskill[1:M+2])>=X:
        flag = 1
        if sumyenskill[0]<minsum:
            minsum = sumyenskill[0]

if flag ==1:
    print(int(minsum))
else:
    print(-1)


Measured memory_bytes: 27164
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main implements Closeable {

  private InputReader in = new InputReader(System.in);
  private PrintWriter out = new PrintWriter(System.out);

  public void solve() {
    for (int i = 1; i <= 5; i++) {
      int next = in.ni();
      if (next == 0) {
        out.println(i);
        break;
      }
    }
  }

  @Override
  public void close() throws IOException {
    in.close();
    out.close();
  }

  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public int ni() {
      return Integer.parseInt(next());
    }

    public long nl() {
      return Long.parseLong(next());
    }

    public void close() throws IOException {
      reader.close();
    }
  }

  public static void main(String[] args) throws IOException {
    try (Main instance = new Main()) {
      instance.solve();
    }
  }
}


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

int main()
{
	string s,t;
	cin>>s>>t;
	long long int n1=s.length(),n2=t.length(),i,f=1;
	if(n1+1==n2)
	{
		for(i=0;i<n1;i++)
		{
			if(s[i]!=t[i])
			{
				cout<<"No";
				f=0;
				break;
			}
		}
		if(f)
			cout<<"Yes";
	}
	else
		cout<<"No";
	return 0;
}


Measured memory_bytes: 3568
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
// typedef long  l;
typedef pair<int,int> P;
const ll INF=100000000000000001;
const double PI=3.141592653589;

int main(){
  int n; cin>>n;
  vector<int> l(n);
  rep(i,n) cin>>l[i];
  sort(l.begin(),l.end());
  int sum=0;
  rep(i,n-1)
  sum+=l[i];
  if(sum>l[n-1])
  cout<<"Yes"<<endl;
  else
  cout<<"No"<<endl; 

  return 0;
}


Measured memory_bytes: 256