akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

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

int main() {
    int a,b;
    cin>>a>>b;
    if(a==b){
        cout<<0<<endl;
    }else{
        if((a+b)%2==0){
            cout<<(a+b)/2<<endl;
        }else{
            cout<<"IMPOSSIBLE"<<endl;
        }
    }



    return 0;
}


Measured memory_bytes: 256
/*
 * MatrixVectorMultiplication.c
 *
 *  Created on: 2015/02/12
 *      Author: Takanori Hasegawa
 */

#include  <stdio.h>

int main(void){
	int m,n,i,j;
	int a[100][100]={0};
	int b[100]={0};
	int c[100]={0};

	scanf("%d %d",&n,&m);

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

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

	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			c[i] += a[i][j]*b[j];
		}
	}

	for(i=0;i<n;i++){
		printf("%d\n",c[i]);
	}


	return 0;
}

Measured memory_bytes: 648
from math import gcd
from functools import reduce
def resolve():
    def lcm_base(x, y):
        return (x * y) // gcd(x, y)

    def lcm_list(arr):
        return reduce(lcm_base, arr, 1)

    MOD = 10**9+7
    N = int(input())
    A = list(map(int, input().split()))

    num = lcm_list(A) % MOD
    ans = 0
    for a in A:
        ans += (num * pow(a, MOD - 2, MOD)) % MOD
    ans %= MOD

    print(ans)
    
if __name__ == "__main__":
    resolve()


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

using namespace std;
using ll = long long;
using ii = pair<int, int>;

const int MAX { 200010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

ll solve(int N, const vector<int>& xs)
{
    vector<int> is(N + 1);

    for (int i = 0; i < N; ++i)
        is[xs[i]] = i + 1;

    multiset<int> S;

    S.insert(0);
    S.insert(0);
    S.insert(N + 1);
    S.insert(N + 1);

    ll ans = 0;

    for (int n = N; n > 0; --n)
    {
        ll i = is[n];
        auto it = S.upper_bound(i);

        ll x = *(--it);
        ll w = *(--it);

        auto jt = S.upper_bound(i);
        ll y = *jt;
        ll z = *(++jt);

#ifdef DEBUG
    cout << "n = " << n << " i = " << i << ", x = " << x << ", w = " << w << ", y = " << y << ", z = " << z << endl;
    cout << "--- inc = " << n*(x - w)*(y - i) + (i - x)*(z - y) << endl;
#endif
        // Ver editorial para melhor entendimento
        ans += n*((x - w)*(y - i) + (i - x)*(z - y));
        S.insert(i);
    }

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    vector<int> xs(N);

    for (int i = 0; i < N; ++i)
        cin >> xs[i];

    auto ans = solve(N, xs);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 5760
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

N = int(input())

cnt = 0
for i in range(1, N+1):
    if i%3==0 or i%5==0:
        pass
    else:
        cnt += i
print(cnt)

Measured memory_bytes: 68108
def main():
    A = [False]*5
    B = [int(i) for i in input().split()]
    for b in B:
        if b == 0:
            continue
        A[b-1] = True
    for i, a in enumerate(A):
        if not a:
            print(i+1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61648
#include<bits/stdc++.h>
#define ll long long int 
#define mod 1000000007
#define se second
#define fi first
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971
#define MAX 9223372036854775807
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
//	cout<<fixed<<setprecision(10);
	ll n,k;
	cin>>n>>k;
	ll arr[n+1];
	for(int a=1;a<=n;a++)
	cin>>arr[a];
	vector<ll> v;
	set<ll> s;
	ll x=1,y,z;
	set<ll>::iterator it;
	while(1)
	{
		it=s.find(x);
		if(it!=s.end())
		break;
		v.push_back(x);
		s.insert(x);
		x=arr[x];
	}
	vector<ll> v1;
	z=0;
	for(int a=0;a<v.size();a++)
	{
		if(v[a]==x)
		{
			z=1;
			y=a+1;
		}
		if(z==1)
		v1.push_back(v[a]);
	}
//	for(int a=0;a<v.size();a++)
//	cout<<v[a]<<" ";
//	cout<<endl;
//	for(int a=0;a<v1.size();a++)
//	cout<<v1[a]<<" ";
	//cout<<endl<<y<<endl;
	if(k<y)
	{
		cout<<v[k];
		return 0;
	}
	k-=(y-1);
	y=v1.size();
	y=k%y;
	cout<<v1[y];
	return 0;
}

Measured memory_bytes: 17736
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte(){
        if(ptr < buflen){
            return true;
        }else{
            ptr = 0;
            try{
                buflen = in.read(buffer);
            }catch(IOException e){
                e.printStackTrace();
            }
            if(buflen <=0){
                return false;
            }
        }
        return true;
    }

    private int readByte(){
        if(hasNextByte())return buffer[ptr++];
        else return -1;
    }

    private static boolean isPrintableChar(int c){
        return 33<=c && c<=126;
    }
    public boolean hasNext(){
        while(hasNextByte() && !isPrintableChar(buffer[ptr]))ptr++;
        return hasNextByte();
    }

    public String next(){
        if(!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)){
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong(){
        if(!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        if(b < '0' || '9' < b){
            throw new NumberFormatException();
        }
        while(true){
            if('0' <= b && b<='9'){
                n*=10;
                n+=b-'0';
            }else if(b==-1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt(){
        long nl = nextLong();
        if(nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDoutble(){return Double.parseDouble(next());}
}

public class Main {
    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int n = fs.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        int[] c = new int[n];
        for(int i=0;i<n;i++){
            a[i] = fs.nextInt();
            b[i] = fs.nextInt();
            c[i] = fs.nextInt();
        }

        int[][] dp = new int[n][3];
        dp[0][0] = a[0];
        dp[0][1] = b[0];
        dp[0][2] = c[0];
        for(int i=1;i<n;i++){
            dp[i][0] = Math.max(dp[i-1][1],dp[i-1][2])+a[i];
            dp[i][1] = Math.max(dp[i-1][0],dp[i-1][2])+b[i];
            dp[i][2] = Math.max(dp[i-1][0],dp[i-1][1])+c[i];
        }
        System.out.println(Math.max(Math.max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]));
    }
}

Measured memory_bytes: 26512
import collections

class WarshallFloyd():
    def __init__(self,N):  #Nは頂点の個数
        self.N = N
        self.d = [[float('inf')]*N for i in range(N)]  #d[i][j] = iからjへの最短距離,0-indexed
    def add(self,u,v,c,directed = False):
        if directed is False:  #無向グラフの場合
            self.d[u][v] = c
            self.d[v][u] = c
        else:  #有向グラフの場合
            self.d[u][v] = c
    def WarshallFloyd_search(self):
        for k in range(self.N):
            for i in range(self.N):
                for j in range(self.N):
                    self.d[i][j] = min(self.d[i][j],self.d[i][k] + self.d[k][j])
        for i in range(self.N):
            self.d[i][i] = 0
        return self.d

N,M,R = map(int,input().split())
r = list(map(int,input().split()))
data = [list(map(int,input().split())) for i in range(M)]

G = WarshallFloyd(N)

for u,v,c in data:
    G.add(u-1,v-1,c,directed=False)

d = G.WarshallFloyd_search()

A = [i for i in range(R)]

ans = float('inf')

from itertools import permutations

for i in permutations(A,R):
    a = 0
    for j in range(R-1):
        a += d[r[i[j]]-1][r[i[j+1]]-1]
    ans = min(ans,a)

print(ans)

Measured memory_bytes: 59736
//グリッド探索

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

int main(){
    int h,w;
    cin>>h>>w;
    string str[h];
    for(int i=0;i<h;i++){
        cin>>str[i];
    }
    int dx[8]={1,0,-1,0};
    int dy[8]={0,1,0,-1};
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            
            if(str[i][j]!='.'){
                int num=0;
                for(int d=0;d<4;d++){
                    int ni=i+dy[d];
                    int nj=j+dx[d];
                    if(ni>=0&&ni<h){
                        if(nj>=0&&nj<w){
                            if(str[ni][nj]=='#')
                            num++;
                        }
                    }
                    
                }
                if(num==0){
                        cout<<"No"<<endl;
                        return 0;
                    }
               
            }
        }
    }
    cout<<"Yes"<<endl;
    
    return 0;
}

Measured memory_bytes: 768
import math

n = int(input())
s = int(input())

ans = []

def f(b, n):
  if n < b:
    return n
  else:
    return f(b, n//b) + n % b

if n == s:
  ans.append(n+1) 
  
elif n < s:
  ans.append(-1)
  
else:
  rootn = int(math.sqrt(n))
  for b in range(2, rootn+2):
    if s == f(b, n):
      ans.append(b)
      break
      
  for p in range(1, rootn):
    b = (n-s)//p + 1
    if s == p + n%b:
      ans.append(b)
      
if not ans:
  ans.append(-1)

print(min(ans))

Measured memory_bytes: 3064
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<utility>
#include<bitset>
#include<cstdio>
#include<string>
#include<time.h>
#include<vector>
#include<cmath>
#include<queue>
#include<map>
#include<set>
using namespace std;
const int N=4e5+10,M=998244353;
long long c[N],l[N];
int main()
{
	int n;
	long long a,b,k,an=0;
	scanf("%d%lld%lld%lld",&n,&a,&b,&k);
	l[1]=1;
	c[0]=1;
	c[1]=n;
	for(int i=2;i<=n;i++)
	{
		l[i]=(M-M/i)*l[M%i]%M;
		c[i]=c[i-1]*(n-i+1)%M*l[i]%M;
	}
	for(int i=0;i<=n;i++)
	{
		if((k-a*i)/b<0)
			break;
		if((k-a*i)%b==0&&(k-a*i)/b<=n)
			an=(an+c[i]*c[(k-a*i)/b]%M)%M;
	}
	printf("%lld",an);
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n;

int main(){
	cin>>n;
	int a=0,b=0,c=0,t=0;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		if(s[0]=='B'&&s.back()=='A') c++;
		else if(s[0]=='B') a++;
		else if(s.back()=='A') b++;
		for(int j=1;j<s.size();j++) if(s[j-1]=='A'&&s[j]=='B') t++;
	}
	cout<<t+min(a,b)+c+(a+b==0&&c?-1:0)<<endl;
}

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

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define ANS(ans) cout << (ans) << endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (long long i = 0; i < (n); ++i)

int main() {
  int n;
  cin >> n;
  vector<string> v(n);
  REP(i, n) {
    cin >> v[i];
  }

  SORT(v);
  UNIQUE(v);

  ANS(v.size());
  return 0;
}


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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n;
  cin >> n;
  vl a(n),b(n),diff(n);
  ll sa = 0;
  ll sb = 0;
  REP(i,n){
    cin >> a[i];
    sa += a[i];
  }
  REP(i,n){
    cin >> b[i];
    sb += b[i];
  }
  if(sa<sb){
    cout << -1 << endl;
    return 0;
  }
  ll minus = 0;
  ll count = 0;
  REP(i,n){
    diff[i] = a[i] - b[i];
    if(diff[i]<0) {
      minus += abs(a[i] - b[i]);
      count ++;
    }
  }
  sort(diff.begin(),diff.end(),[](ll a,ll b){return a>b;});
  REP(i,n){
    if(minus <= 0) break;
    minus -= diff[i];
    count ++;
  }
  cout << count << endl;

  return 0;
}


Measured memory_bytes: 2560
-- https://github.com/minoki/my-atcoder-solutions
import Data.Char (isSpace)
import Data.List (unfoldr)
import qualified Data.ByteString.Char8 as BS

main = do
  [n,k] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  print $ if k == 1 then 0 else n - k


Measured memory_bytes: 380
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int dx[6]={1,-1,0,0,0,0},dy[6]={0,0,1,-1,0,0},dz[6]={0,0,0,0,1,-1};
  long long a, b, c;
  cin>>a>>b>>c;
  int n;
  cin>>n;
  int x,y,z;
  int usedx[1000],usedy[1000],usedz[1000];
 
  long long area=a*b*2+a*c*2+b*c*2;
  int cx,cy,cz;
 
  for(int i=0;i<n;i++){
    cin>>x>>y>>z;
      usedx[i]=x,usedy[i]=y,usedz[i]=z;
    for(int j=0;j<6;j++){
      int f=0;
      cx=x+dx[j],cy=y+dy[j],cz=z+dz[j];
      if(cx<a &&cy<b && cz<c && cx>=0 && cy>=0 && cz>=0 ){
    for(int k=0;k<i;k++)if(usedx[k]==cx && usedy[k]==cy && usedz[k]==cz)area--,f=1;
    if(!f)area++;
      }else area--;
    }
  }
 
  cout<<area<<endl;
 
  return 0;
}

Measured memory_bytes: 1176
N, x = map(int, input().split())
A = list(map(int, input().split()))

ans = 0
for i in range(N - 1):
    L = A[i]
    R = A[i + 1]
    eat = max(0, L + R - x)
    ans += eat
    A[i + 1] = max(0, R - eat)

print(ans)

Measured memory_bytes: 14540
#include <iostream>
#include <vector>
#include <math.h>
#include <map>

#define MAX_SAC 15
#define EPS 0.0000000001

using namespace std;

int main(int argc, char const *argv[])
{
	int s,a,c;
	int m=256;
	int n;
	int mins,mina,minc;
	double min;
	double h;

	while(1){
		cin>>n;
		if(n==0) break;

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


		min=100000000.0;
		mins = 0;
		mina = 0;
		minc = 0;
		for(s=0;s<=MAX_SAC;s++){
			for(a=0;a<=MAX_SAC;a++){
				for(c=0;c<=MAX_SAC;c++){
					
					int r=s;
					h = 0;
					map<int,int> mp;

					for(int i1=0;i1<n;i1++){
						r=(a*r+c)%m;
						mp[(l[i1]+r)%m]++;
					}

					for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++){
						h-=((double)(*it).second/m)*log((double)(*it).second/m);
					}

					if((min-EPS)>h) {		
						min = h;
						mins = s;
						mina = a;
						minc = c;	
					}
				}
			}
		}

		cout<<mins<<" "<<mina<<" "<<minc<<endl;
	}
	return 0;
}

Measured memory_bytes: 1252
#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
#from fractions import *
from bisect import *
from io import BytesIO, IOBase
def vsInput():
    sys.stdin = open('input.txt', 'r')
    sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]

#-------------------------code---------------------------#
#vsInput()

n=Int()
a=array()
ans=1
if(0 in a):
    print(0)
    exit()
for i in a:
    ans*=i
    #print(ans)
    if(ans>10**18):
        ans=-1
        break
print(ans)

Measured memory_bytes: 94616
#include <bits/stdc++.h>
using namespace std;
#define iinf 2000000000
#define linf 1000000000000000000LL
#define ulinf 10000000000000000000ull
#define MOD1 1000000007LL
#define mpr make_pair
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned long UL;
typedef unsigned short US;
typedef pair < int , int > pii;
clock_t __stt;
inline void TStart(){__stt=clock();}
inline void TReport(){printf("\nTaken Time : %.3lf sec\n",(double)(clock()-__stt)/CLOCKS_PER_SEC);}
template < typename T > T MIN(T a,T b){return a<b?a:b;}
template < typename T > T MAX(T a,T b){return a>b?a:b;}
template < typename T > T ABS(T a){return a>0?a:(-a);}
template < typename T > void UMIN(T &a,T b){if(b<a) a=b;}
template < typename T > void UMAX(T &a,T b){if(b>a) a=b;}
int n,a[200005],b[200005],bs,cnt[200005],res;
vector < int > son[200005];
int id(int v){
	return lower_bound(b,b+bs,v)-b;
}
void go(int v){
	int i,j;
	bool self=0;
	for(i=0;i<(int)son[v].size();++i){
		int u=son[v][i];
		if(u==v){
			self=1;
			continue;
		}
		go(u);
		int d=min(cnt[v],cnt[u]);
		res+=d;
		cnt[v]-=d;
		cnt[u]-=d;
	}
	if(self){
		res+=cnt[v]/2;
		cnt[v]%=2;
	}
}
int main(){
    // inputting start
    // 数据结构记得初始化！ n，m别写反！
    int i,j,k;
	scanf("%d",&n);
	for(i=0;i<n;++i) scanf("%d",a+i);
    #ifdef LOCAL
        TStart();
    #endif
    // calculation start
    // 数据结构记得初始化！ n，m别写反！
	sort(a,a+n);
	memcpy(b,a,sizeof(a));
	bs=unique(b,b+n)-b;
    for(i=0;i<n;++i){
		for(j=0;(1<<j)<=a[i];++j);
		int val=id((1<<j)-a[i]);
		if(val>=bs || b[val]!=(1<<j)-a[i]) continue;
		if(!i || a[i]>a[i-1]){
			son[val].push_back(id(a[i]));
		}
	}
	for(i=0;i<n;++i){
		++cnt[id(a[i])];
	}
	for(i=0;i<bs;++i){
		if(cnt[i]){
			go(i);
		}
	}
	printf("%d\n",res);
    #ifdef LOCAL
        TReport();
    #endif
    return 0;
}

Measured memory_bytes: 9856
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<stack>
using namespace std;

struct E{
  int to,cost;
};

int N,M,L,K;
int s,g;
vector<vector<E>> edge;
vector<int> B;
bool input(){
  edge.clear();
  B.clear();
  cin>>N>>M>>L>>K;
  if(!(N||M||L||K))return false;
  edge.resize(N+1);
  for(int i=0;i<M;i++){
    int a,b,c;
    cin>>a>>b>>c;
    edge[a].push_back(E{b,c});
    edge[b].push_back(E{a,c});
  }
  cin>>s>>g;
  for(int i=0;i<L;i++){
    int tmp;
    cin>>tmp;
    B.push_back(tmp);
  }
  return true;
}

struct S{
  int pos,cost,b;
}; 
bool operator<(S a,S b){
  return a.cost>b.cost;
}

vector<vector<int>> dp;
int solve(){
  priority_queue<S> que;
  que.push(S{s,0,0});
  
  dp.clear();
  dp.resize(N+1);
  for(int i=0;i<dp.size();i++){
    dp[i].resize(1<<L+1);
  }
  
  while(!que.empty()){
    S now = que.top();que.pop();
    for(int i=0;i<B.size();i++){
      if(now.pos == B[i]){
        now.b = now.b | (1<<i);
      }
    }
    if(!(dp[now.pos][now.b]<K+1))continue;
    dp[now.pos][now.b]++;
    if(now.pos == g && now.b==((1<<L)-1) ){
      if(dp[now.pos][now.b] == K){
        return now.cost;
      }
    }

    for(int i=0;i<edge[now.pos].size();i++){
      que.push(S{edge[now.pos][i].to ,now.cost + edge[now.pos][i].cost, now.b});
    }
  }
  return -1;
}

int main(){
  while(input()){
    int ans = solve();
    if(ans<0){
      cout<<"NA"<<endl;
    }else {
      cout<<ans<<endl;
    }
  }
}

Measured memory_bytes: 76996
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=5e5;
int a[N],w[N],n;
int judge(int x)
{
    for(int i=1;i<=2*n-1;i++)a[i]=w[i]>x;
    for(int i=n,j=n;i>1;i--,j++)
    {
        if(a[i]==a[i-1])return a[i]==0;
        if(a[j]==a[j+1])return a[j]==0;
    }
    return a[n]^(n&1);
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=2*n-1;i++)scanf("%d",w+i);
    int l=1,r=2*n-1,mid;
    while(l<r)
    {
        mid=(l+r)>>1;
        if(judge(mid))r=mid;
        else l=mid+1;
    }
    cout<<l<<endl;
}

Measured memory_bytes: 5328
def main():
    import sys
    input = sys.stdin.readline
    import numpy as np

    N, K = [int(item) for item in input().split()]
    h =np.array([int(item) for item in input().split()])
    dp = np.full(N+K, 10**10+1, dtype='int64')
    dp[0] = 0

    for i in range(1, N):
        max1 = min(N, i+K)
        cost = abs(h[i:max1] - h[i-1])
        dp[i:max1] = np.minimum(dp[i:max1], dp[i-1] + cost)

    print(dp[N-1])

main()


Measured memory_bytes: 23184
#include <cstdio>
#include <string>
#include <iostream>

using namespace std;

int toInt(char c1, char c2) {
  return (c1 - '0') * 10 + c2 - '0';
}

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

  bool isYYMM = true;
  bool isMMYY = true;
  if (toInt(str[0], str[1]) > 12 || toInt(str[0], str[1]) == 0) {
    isMMYY = false;
  }
  if (toInt(str[2], str[3]) > 12 || toInt(str[2], str[3]) == 0) {
    isYYMM = false;
  }
  if (isYYMM && isMMYY) {
    cout << "AMBIGUOUS" << endl;
  } else if (isYYMM) {
    cout << "YYMM" << endl;
  } else if (isMMYY) {
    cout << "MMYY" << endl;
  } else {
    cout << "NA" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<limits>
#include<string.h>
#include<vector>
#include<stack>
#include<queue>
using namespace std;

int main()
{
    int n;
    cin>>n;
    int c0,c1,c2,c3;
    string s;
    c0=0;
    c1=0;
    c2=0;
    c3=0;
    for (int i = 0; i < n; i++)
    {
        cin>>s;
        if (s=="AC")
        {
            c0++;
        }else if (s=="WA")
        {
            c1++;
        }else if (s=="TLE")
        {
            c2++;
        }else
        {
            c3++;
        }
        
        
        
        
    }
    cout<<"AC"<<" "<<"x"<<" "<<c0<<endl;
    cout<<"WA"<<" "<<"x"<<" "<<c1<<endl;
    cout<<"TLE"<<" "<<"x"<<" "<<c2<<endl;
    cout<<"RE"<<" "<<"x"<<" "<<c3<<endl;
   
    
    



    

    return 0;
}

Measured memory_bytes: 3628
N = int(input())
X, Y = [], []
even, odd = 0, 0
for i in range(N):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)
    if (x + y) % 2 == 0:
        even += 1
    else:
        odd += 1


def calc(x, y):
    nowx, nowy = 0, 0
    t = ""
    for i in range(30, -1, -1):
        if nowx < x:
            nowx += 2 ** i
            p = 1
        else:
            nowx -= 2 ** i
            p = -1

        if nowy < y:
            nowy += 2 ** i
            q = 1
        else:
            nowy -= 2 ** i
            q = -1

        if p == 1 and q == 1:
            t += "R"
        elif p == 1 and q == -1:
            t += "U"
        elif p == -1 and q == 1:
            t += "D"
        else:
            t += "L"

    return t


if even >= 1 and odd >= 1:
    print(-1)
    exit()

else:
    d = [2 ** i for i in range(30, -1, -1)]
    if even == 0:
        print(31)
        print(" ".join(map(str, d)))
        for i in range(N):
            print(calc(X[i] + Y[i], X[i] - Y[i]))

    else:
        print(32)
        d.append(1)
        print(" ".join(map(str, d)))
        for i in range(N):
            print(calc(X[i] + Y[i] - 1, X[i] - Y[i] - 1) + "R")




Measured memory_bytes: 3188
#include<iostream>
using namespace std;
double dp[3005][3005];
double p[3005];
int n;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)cin>>p[i];
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n/2;j++){
			if(!i)dp[i][j]=1;
			else{
				dp[i][j]=p[i]*dp[i-1][j];
				if(j>0)dp[i][j]+=(1.0-p[i])*dp[i-1][j-1];
			}
		}
	}
	printf("%.12lf",dp[n][n/2]);
}

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

int N, c = -1, cnt; vector<int>X[10009];

int main() {
	cin >> N;
	for (int i = 1; i <= 1000; i++) {
		if (i*(i - 1) / 2 == N) { c = i; break; }
	}
	if (c == -1) {
		cout << "No" << endl;
		return 0;
	}
	for (int i = 0; i < c; i++) {
		for (int j = i + 1; j < c; j++) {
			X[i].push_back(cnt + 1);
			X[j].push_back(cnt + 1);
			cnt++;
		}
	}
	cout << "Yes" << endl;
	cout << c << endl;
	for (int i = 0; i < c; i++) {
		cout << X[i].size() << " ";
		for (int j = 0; j < X[i].size(); j++) { if (j) cout << " "; cout << X[i][j]; }
		cout << endl;
	}
	return 0;
}

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

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}


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

    vector<pair<int,int>> pairs(M+10);
    for(int i=0;i<M;i++){
        int a,b;
        cin >> a >> b;
        pairs[i]=make_pair(a,b);
    }
    sort(pairs.begin(),pairs.begin()+M,compare_by_b);
    int ct=0;
    int jg=0;
    for(int i=0;i<M;i++){
        if(i==0){
            ct++;
            jg=pairs[i].second-1;
        }
        else{
            if(pairs[i].first<=jg) continue;
            else{
                ct++;
                jg=pairs[i].second-1;
            }
        }
    }
    cout << ct << endl;
}

Measured memory_bytes: 1024
read a b c
read d e f
read g h i
read n
for((j=0;j<n;j++));do
	read x
	[ $a -eq $x ]&&a=0
	[ $b -eq $x ]&&b=0
	[ $c -eq $x ]&&c=0
	[ $d -eq $x ]&&d=0
	[ $e -eq $x ]&&e=0
	[ $f -eq $x ]&&f=0
	[ $g -eq $x ]&&g=0
	[ $h -eq $x ]&&h=0
	[ $i -eq $x ]&&i=0
done
if [ $[(a+b+c)*(d+e+f)*(g+h+i)*(a+d+g)*(b+e+h)*(c+f+i)*(a+e+i)*(c+e+g)] -eq 0 ];then
	echo Yes
else
	echo No
fi


Measured memory_bytes: 3780
N = gets.to_i
res = N

(0..N).each{|i|
    c, t = 0, i
    
    while t > 0 do
        c += t%6
        t /= 6
    end
    
    t = N-i
    
    while t > 0 do
        c += t%9
        t /= 9
    end
    
    res = c if res > c
}

p res

Measured memory_bytes: 1788
inputLine=input()
N=int(inputLine.split(" ")[0])
K=int(inputLine.split(" ")[1])

x=N%K
result=x
firstX=x

xNext=abs(x - K)
result=min(result, xNext)
x=xNext
while(x != firstX):
    xNext=abs(x - K)
    result = min(result, xNext)
    x=xNext

print(result)


Measured memory_bytes: 3060
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>

using namespace std;
typedef long long LL;
const int maxn = 100005;

int ehead[maxn],ecnt;
struct edge {
	int u,v,next;
}edg[maxn];
void add(int u,int v) {
	edg[++ecnt]=(edge){u,v,ehead[u]};
	ehead[u]=ecnt;
}
int n,dep[maxn],a[maxn],stk[maxn],top;
bool comp(int u,int v) {
	return dep[u]>dep[v];
}
void dfs(int u) {
	for (int j=ehead[u];j;j=edg[j].next)
		dfs(edg[j].v);
	top=0;dep[u]=0;
	for (int j=ehead[u];j;j=edg[j].next)
		stk[++top]=edg[j].v;
	sort(stk+1,stk+top+1,comp);
	for (int i=1;i<=top;i++)
		dep[u]=max(dep[u],dep[stk[i]]+i);
}
int main()
{
	#ifdef Amberframe
		freopen("agc009b.in","r",stdin);
		freopen("agc009b.out","w",stdout);
	#endif
	scanf("%d",&n);
	for (int i=2;i<=n;i++)
		scanf("%d",&a[i]),add(a[i],i);
	dfs(1);printf("%d",dep[1]);
	return 0;
}

Measured memory_bytes: 5760
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<climits>
#include<cfloat>
#define pb push_back
#define curr(P, i) P[(i) % P.size()]
#define next(P, i) P[(i+1) % P.size()]

using namespace std;

double EPS = 1e-10;

double add(double a, double b){
  if(abs(a+b) < EPS * (abs(a)+abs(b)))return 0;
  return a+b;
}

struct point{
  double x, y;
  point(){}
  point(double x,double y) : x(x) , y(y){}

  point operator + (point p){
    return point(add(x,p.x), add(y,p.y));
  }

  point operator - (point p){
    return point(add(x,-p.x), add(y,-p.y));
  }

  point operator * (double d){
    return point(x*d,y*d);
  }
};

double dot(point a, point b) {
  return (a.x * b.x + a.y * b.y);
}

double cross(point a, point b) {
  return (a.x * b.y - a.y * b.x);
}

double norm(point a){
  return sqrt(a.x*a.x+a.y*a.y);
}

int ccw(point a, point b, point c) {
  b = b-a; c = c-a;
  if (cross(b, c) > 0)   return +1;
  if (cross(b, c) < 0)   return -1;   
  if (dot(b, c) < 0)     return +2;     
  if (norm(b) < norm(c)) return -2;      
  return 0;
}

point intersection_l(point a1, point a2, point b1, point b2) {
  return a1 + (a2 - a1) * (cross(b2 - b1,b1 - a1) / cross(b2 - b1,a2 - a1));
}

vector<point> covex_cut(vector<point>pol,point a,point b){
  vector<point>q;
  for (int i=0; i<pol.size();i++) {
    point A=curr(pol,i),B=next(pol, i);
    if (ccw(a,b,A)!=-1)q.push_back(A);
    if (ccw(a,b,A)*ccw(a,b,B)<0)
      q.push_back(intersection_l(A,B,a,b));
  }
  return q;
}

int main(void){
  int n;
  point in;
  vector<point>pol,ans;

  while(cin >> n,n){
    pol.clear();
    ans.clear();
    for(int i=0;i<n;i++){
      cin >> in.x >> in.y;
      pol.pb(in);
    }

    ans.pb(point(0,0));
    ans.pb(point(10001,0));
    ans.pb(point(10001,10001));
    ans.pb(point(0,10001));

    for(int i=0;i<n;i++)
      ans=covex_cut(ans,curr(pol,i),next(pol,i));
    
    if(ans.size())cout << 1 << endl;
    else cout << 0 << endl;

  }
  return 0;
}

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

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

    typedef long long ll;
    ll L[87];
    L[0] = 2;
    L[1] = 1;
    for (int i = 2; i <= n; i++)
    {
        L[i] = L[i - 2] + L[i - 1];
    }

    cout << L[n] << endl;
}

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

int main(){
	int ans=0;
	string a,b;
	cin>>a>>b;
	for(int i=0;i<3;++i){
		if(a[i]==b[i])ans++;
	} 
	cout<<ans<<endl;
	return 0;
}


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

int main()
{
    int arr[4][4];
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            cin>>arr[i][j];
        }
    }
    map<int,int>mp;
    int n;
    cin>>n;
    while(n--)
    {
        int a;
        cin>>a;
        mp[a]++;
    }
    for(int i=0;i<3;i++)
    {
        int flag=0;
        for(int j=0;j<3;j++)
        {
            if(mp[arr[i][j]]>0)flag++;
        }
        if(flag==3)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    for(int j=0;j<3;j++)
    {
        int flag=0;
        for(int i=0;i<3;i++)
        {
            if(mp[arr[i][j]]>0)flag++;
        }
        if(flag==3)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    if((mp[arr[0][0]]&&mp[arr[1][1]]&&mp[arr[2][2]])||(mp[arr[0][2]]&&mp[arr[1][1]]&&mp[arr[2][0]]))
    {
        cout<<"Yes"<<endl;
            return 0;
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e5+5;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    string s;cin>>s;
    for(ll i=0;i<s.size();i++)cout<<"x";
}




Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int x;
  vector<int>a;
  for(int i=0;i<10;i++){
    cin>>x;
    a.push_back(x);
  }
  sort(a.begin(),a.end()); 
  cout<<a[9]<<endl;
  cout<<a[8]<<endl;
  cout<<a[7]<<endl;
}



Measured memory_bytes: 3160
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private static class Node {
        int no;
        int color;
        public Node(int no) {
            this.no = no;
        }
        public String toString() {
            return "(" + no + ":" + color + ")";
        }
    }
    private void solve(Scanner sc) {
        int N = sc.nextInt();

        Map<Integer, Node> nodes = new HashMap<>();
        List<List<Node>> list = new ArrayList<>();
        for (int i = 0; i < N; ++i) {
            list.add(new ArrayList<>());

            nodes.put(i, new Node(i));
        }
        nodes.get(0).color = -1;
        nodes.get(N - 1).color = 1;

        for (int i = 1; i <= N - 1; ++i) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            list.get(a).add(nodes.get(b));
            list.get(b).add(nodes.get(a));
        }
        Deque<Node> q = new ArrayDeque<>();
        q.offer(nodes.get(0));
        q.offer(nodes.get(N - 1));
        int black = 0;
        int white = 0;
        Set<Integer> visited = new HashSet<>();
        while (!q.isEmpty()) {
            Node node = q.poll();
            if (visited.contains(node.no)) {
                continue;
            }
            visited.add(node.no);
            List<Node> l = list.get(node.no);
            for (Node n : l) {
                if (n.color == 0) {
                    n.color = node.color;
                    q.offer(n);
                }
            }
        }

        int color = 0;
        for (Node node : nodes.values()) {
            color += node.color;
        }

        if (color < 0) {
            _out.println("Fennec");
        } else {
            _out.println("Snuke");
        }
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 108088
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int H = in.nextInt();
            int W = in.nextInt();
            int N = in.nextInt();

            int a = Math.max(H, W);
            out.println((N + a - 1) / a);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

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

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

    }
}



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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> piipi;
typedef pair<pii, pii> piipii;

#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back

int main(){
    ll n, m;
    scanf("%lld%lld", &n, &m);
    printf("%lld\n", min(n, m/2) + (m-2*min(n, m/2))/4);
}

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

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

  string ans = "No";

  for (int i = 1; i <= 9; i++)
  {
    for (int j = 1; j <= 9; j++)
    {
      if (i * j == N)
        ans = "Yes";
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll i,j,k,n,m,s;
    cin>>n;s=0;
    ll a[n+5];
    for(i=0;i<n-1;i++) cin>>a[i];
    s=a[0];
    for(i=1;i<n-1;i++) s+=min(a[i],a[i-1]);
    cout<<s+a[n-2];
}


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

using namespace std;

int main()
{   
    
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int e=a*b;
    int y=c*d;
    int max=0;
    if(e>y)max=e;
    else max=y;
    cout<<max;

    return 0;
}

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

using namespace std;

#define rep(i, a, b)  for(int i = (a); i < (b); i++)
#define rrep(i, a, b) for(int i = (a); i > (b); i--)
#define sq(x) ((x) * (x))
#define bit(x) bitset<10>(x)
#define vsort(v)  sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<llint>())
#define debug(x) cout << #x << " " << (x) << endl
#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;


template<typename Tn> Tn __lcm(Tn a, Tn b)
{
    return a / __gcd(a, b) * b;
}

int n, m;
int havesw[11] = {};

int bit1cnt(int num)
{
    int rec = num & 1;
    while(num >>= 1) if(num & 1) rec++;
    
    return rec;
}


int main()
{
    ci >> n >> m;
    int k[11];
    
    rep(i, 0, m) {
	ci >> k[i];
	
	rep(j, 0, k[i]) {
	    int _sw;
	    ci >> _sw;
	    havesw[i] |= 1 << (_sw - 1);
	}
    }
    
    int p[11];
    int ans = 0;

    rep(i, 0, m) ci >> p[i];

    for(int i = 0; i < pow(2, n); i++) {
	bool flg = true;

	for(int j = 0; j < m; j++) {
	    int tmp = i & havesw[j];
	    if((bit1cnt(tmp) % 2) != p[j]) {
		flg = false;
		break;
	    }
	}
	
	if(flg) ans++;
    }
    
    co << ans << en;

    return 0;
}


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

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x)*(x))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

struct Thread {
    int id, children;
    string s;
};

int main() {
    int n;
    cin >> n;
    vector<Thread> th;
    vi indent(n+1);
    FOR(id, 1, n+1) {
        int k;
        string s;
        cin >> k >> s;

        bool inserted = false;
        REP(i, SZ(th)) {
            Thread& t = th[i];
            if (t.id == k) {
                int level = t.children;
                FOR(j, i+1, SZ(th)) {
                    if (indent[th[j].id] <= indent[t.id]) break;
                    level += th[j].children;
                }

                t.children++;
                th.insert(th.begin()+i+1+level, {id, 0, s});
                inserted = true;
                break;
            }
        }
        if (!inserted) {
            th.push_back({id, 0, s});
        }
        if (k == 0) {
            indent[id] = 0;
        } else {
            indent[id] = indent[k] + 1;
        }
//        for (auto t : th) {
//            REP(i, indent[t.id]) {
//                LOG(".");
//            }
//            LOG("%s (%d)\n", t.s.c_str(), t.children);
//        }
//        LOG("---------------\n");
    }

    for (auto t : th) {
        REP(i, indent[t.id]) {
            cout << ".";
        }
        cout << t.s << endl;
    }
}

Measured memory_bytes: 3324
#include <iostream>
#include <vector>
#include <queue>
#include <set>
using namespace std;

int main(){
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> vec;
  for(int i=0; i<h; i++){
    string str;
    cin >> str;
    vec.push_back(str);
  }
  vector<vector<int>> ans(h, vector<int>(w, 0));
  queue<int> berryExistsQue;
  set<int> berryExistsSet;
  int count = 1;
  for(int i=0; i<h; i++){
    bool berryExists = false;
    queue<int> que;
    for(int j=0; j<w; j++){
      if(vec[i][j] == '#'){
        berryExists = true;
        que.push(j);
        ans[i][j] = count;
        count++;
      }
    }
    while(!que.empty()){
      int num = que.front();
      que.pop();
      if(num-1 >= 0 && ans[i][num-1] == 0){
        ans[i][num-1] = ans[i][num];
        que.push(num-1);
      }
      if(num+1 < w && ans[i][num+1] == 0){
        ans[i][num+1] = ans[i][num];
        que.push(num+1);
      }
    }
    if(berryExists){
      berryExistsQue.push(i);
      berryExistsSet.insert(i);
    }
  }
  while(!berryExistsQue.empty()){
    int num = berryExistsQue.front();
    berryExistsQue.pop();
    if(num-1 >= 0 && berryExistsSet.find(num-1) == berryExistsSet.end()){
      for(int j=0; j<w; j++){
        ans[num-1][j] = ans[num][j];
      }
      berryExistsSet.insert(num-1);
      berryExistsQue.push(num-1);
    }
    if(num+1 < h && berryExistsSet.find(num+1) == berryExistsSet.end()){
      for(int j=0; j<w; j++){
        ans[num+1][j] = ans[num][j];
      }
      berryExistsSet.insert(num+1);
      berryExistsQue.push(num+1);
    }
  }
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      cout << ans[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}
  
  
  

Measured memory_bytes: 1280
#!/usr/bin python3
# -*- coding: utf-8 -*-

n = int(input())
ret = 0
cnt = 0
for i in range(n):
    a, b = map(int, input().split())
    if a == b:
        cnt += 1
    else:
        ret = max(ret, cnt)
        cnt = 0
ret = max(ret,cnt)
if ret >= 3:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9112
#include<stdio.h>
main(){
  int x[100],i=0,tmp;
  while(scanf("%d",&x[i])!=EOF){
    tmp=x[i];
    if(tmp!=0){
      i++;
    }else{
      printf("%d\n",x[i-1]);
      i--;
    }
  }
  return 0;
}

Measured memory_bytes: 600
kk=0
while kk==0:
	h,w=map(int,input().split())
	if h==0 and w==0:
		break
	else:
		for i in range(h):
			if i%2==0:
				s="#"
			else:
				s="."
			for k in range(w-1):
				if s[-1]=="#":
					s=s+"."
				else:
					s=s+"#"
			print(s)
		print("")




Measured memory_bytes: 5608
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
string bit(ll x){
    string s = "";
    int i = 0;
    for(int i = 0;i <= 40;i++){
        if(x % 2 == 1)s = '1'+s;
        else s = '0'+s;
        x /= 2;
    }
    return s;
}
int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    vector<string> A(n);
    for(int i = 0;i < n;i++){
        cin >> a[i];
        A[i] = bit(a[i]);
        //cout << A[i] << endl;
    }
    ll x = 0;
    ll ans = 0;
    for(int i = 0;i <= 40;i++){
        int count = 0;
        for(int j = 0;j < n;j++){
            if(A[j][i] == '0')count++;
        }
        ll add = pow(2,40-i);
        if(count >= (n+1)/2) x += add;
        else count = n - count;
        //cout << ans << endl;
        if(x > k){
            x -= add;
            count = n - count;
        }
        ans += count*add;
    }
    cout << ans << endl;
}


Measured memory_bytes: 9600
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int flag=0;
    char a[100];
    cin >>a;
    
    if(a[2]==a[3]){
        if(a[4]==a[5]){
            cout <<"Yes";
            flag++;
        }
    }
    
    if(flag==0){
        cout<<"No";
    }
    
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>

using namespace std;

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

int main(){
    int N;

    cin >> N;

    string s[N];
    int sums[N];

    REP(i,N){
        sums[i] = 0;
    }

    REP(i,N){
        cin >> s[i];
    }

    int M;

    cin >> M;

    string t[M];

    REP(i,M){
        cin >> t[i];
    }

    REP(i,N){
        REP(j,N){
            if(s[i] == s[j]){
                sums[i]++;
            }
        }
        REP(k,M){
            if(s[i] == t[k]){
                sums[i]--;
            }
        }
    }

    sort(sums,sums+N);

    cout << max(0,sums[N-1]);

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int N, i, j, k;
	cin >> N;
	int A[N];
	for(i = 0; i < N; i++){
		cin >> A[i];
	}

//	1  insertionSort(A, n, g)
//	2      for i = g to n-1
//	3          v = A[i]
//	4          j = i - g
//	5          while j >= 0 && A[j] > v
//	6              A[j+g] = A[j]
//	7              j = j - g
//	8              cnt++
//	9          A[j+g] = v
//	10
//	11 shellSort(A, n)
//	12     cnt = 0
//	13     m = ?
//	14     G[] = {?, ?,..., ?}
//	15     for i = 0 to m-1
//	16         insertionSort(A, n, G[i])
	int g, v, m = 1, cnt = 0;
	int G[13] = {0};
	G[0] = 1;
	while((g = 3*G[m-1]+1) < N){
		G[m] = g;
		m++;
	}
	for(k = m-1; k >= 0; k--){
		g = G[k];
		//insertionSort;
		for(i = g; i < N; i++){
			v = A[i];
			j = i - g;
			while(j >= 0 && A[j] > v){
				A[j+g] = A[j];
				j = j - g;
				cnt++;
			}
			A[j+g] = v;
		}
	}

	cout << m << endl << G[m-1];
	for(i = m-2; i >= 0; i--){
		cout << ' ' << G[i];
	}
	cout << endl << cnt << endl;
	for(i = 0; i < N; i++){
		cout << A[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 6964