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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int t;cin>>t;

    cout<<t/30<<" "<<t%30*2<<endl;
    return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

vector<pair<ll,ll>> G[100005];
ll dist[100005];

void calc_dist(ll v, ll d){
  if(dist[v] != -1) return;
  dist[v] = d;
  rep(i,G[v].size()){
    calc_dist(G[v][i].first, d+G[v][i].second);
  }
}

int main(){
  int N;
  cin >> N;
  rep(i,N-1){
    ll a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    G[a].emplace_back(b,c);
    G[b].emplace_back(a,c);
  }

  rep(i,100005) dist[i] = -1;
  
  int Q, K;
  cin >> Q >> K;
  K--;

  calc_dist(K, 0);

  
  rep(i,Q){
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    cout << dist[x] + dist[y] << endl;
  }
  
  return 0;
}



Measured memory_bytes: 14336
#include<cstdio>
#include<iostream>
#include<cstring>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;

char s[105];
int ans[10000];
int h[10000],p[10000],k[10000],vis[10000];

int main(){
	scanf("%s",s + 1);
	int len = strlen(s + 1);
	for(int i = 1;i <= len;i++){
		h[i] = s[i] - '0';
		p[i] = h[i];
		vis[p[i]] = 1;
	}
	int all = 0;
	for(int i = 'a' - '0';i <= 'z' - '0';i++){
		if(vis[i] == 1){
			k[++all] = i;
		}
	}
	int ma = 10000000;
	for(int i = 1;i <= all;i++){
		int tot = 0,sum = 0;
		while(1){
			int flag = 0;
			for(int j = 2;j <= len - tot;j++){
				if(h[j] != h[j - 1]){
					flag = 1;
					break;
				}
			}
			if(flag == 0) break;
			tot++;
			for(int j = 1;j <= len - tot;j++){
				if(h[j] == k[i] || h[j + 1] == k[i]) h[j] = k[i];
				else h[j] = h[j];
			}
			sum++;
		}
		ma = min(sum,ma);
		for(int j = 1;j <= len;j++) h[j] = p[j];
	}
	printf("%d",ma);
}

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

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'
#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
#define int long long
// #define pow mypow

typedef pair<int,int> pii;
const int N = 2e5+5;
const int INF = 1e9+5;
const int MOD = 1e9+7;

int n, k, a[N];
int32_t main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >> n >> k;
	int neg = 0, zero = 0, pos = 0;
	for(int i=0; i<n; i++) {
		cin >> a[i];
		neg += (a[i] < 0);
		zero += (a[i] == 0);
		pos += (a[i] > 0);
	}
	sort(a, a+n);
	int l = -1e18, r = 1e18;

	while(l <= r){
		int mid = (l+r)/2;
		int cnt = 0; //cnt #products < mid
		if (mid == 0LL) cnt = neg * pos;
		if (mid < 0) {
			int j = neg + zero;
			for (int i=0; i<neg; i++){
				while(j<n && a[i]*a[j] >= mid) j++;
				cnt += n-j;
			}
		}
		if (mid > 0){
			cnt = neg * pos + zero * (n-zero) + zero*(zero-1)/2;
			// product of 2 negs
			int j = 0;
			for(int i=neg-1; i>j; i--){
				while(i>j && a[i]*a[j] >= mid) j++;
				cnt += i-j;
			}
			// product of 2 poss
			j = n-1;
			for(int i=neg+zero; i<j; i++){
				while(i<j && a[i]*a[j] >= mid) j--;
				cnt += j-i;
			}
		}
		if (cnt < k) l = mid + 1;
		else r = mid - 1;
	}
	int ans = l - 1;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
from collections import deque
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
edge = [[] for _ in range(N + 1)]
for _ in range(M):
    a, b = map(int, input().split())
    edge[a].append(b)
S, T = map(int, input().split())

path = [[-1] * 3 for _ in range(N + 1)]
path[S][0] = 0
node = deque([(S, 0)])
while node:
    s, d = node.popleft()
    dist = path[s][d]

    d = (d+1) % 3
    for t in edge[s]:
        if path[t][d] != -1:
            continue
        path[t][d] = dist + 1
        node.append((t, d))


ans = path[T][0]//3
print(ans)


Measured memory_bytes: 38112
//ex9_2
//TKC001

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define SIZE 100000

typedef struct stack{
    char num;
    struct stack *next;
}stack;

void push(stack **stk, char num){
    stack *new = calloc(1, sizeof(stack));
    if(new == NULL) exit(1);

    new->num = num;
    new->next =*stk;
    *stk = new;
}

char pop(stack **stk){
    char num;
    stack *tmp = *stk;
    if(tmp == NULL) exit(1);
    num = tmp->num;
    *stk = tmp->next;

    free(tmp);
    return num;
}


int main(void){
    int i, count = 0;
    stack *stk = NULL, *comp = NULL;
    char str[SIZE+1], last, prelast, fromcomp;
    //入力
    scanf("%s", str);
    //スタックに文字列を追加
    for(i = 0; i < strlen(str); i++){
        push(&stk, str[i]);
    }

    if(strlen(str) == 1){
        count = 0;
    }
    else{
        while (1){
            last = pop(&stk);
            prelast = pop(&stk);
            //lastとprelastが同じならcompに移動、違ったら消し、countを増やす。
            if(last == prelast){
                push(&comp, last);
                push(&stk, prelast);
            }
            else{
                count+=2;
                //compの最後の要素はstkの最後の要素と隣り合うのでstkに移動
                if(comp != NULL){
                    fromcomp = pop(&comp);
                    push(&stk, fromcomp);
                }
            }

            if(stk == NULL || stk->next == NULL) break;
        }
    }
    //出力
    printf("%d", count);
  
    return 0;
}

Measured memory_bytes: 4952
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.Globalization;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            int now = 0;
            int ans = -1;
            int N = int.Parse(Console.ReadLine());
            var a = new int[100000];

            for (int i = 0; i < N; i++)
            {
                a[i] = int.Parse(Console.ReadLine());
            }
                for (int i = 0; i < N; i++)
            {
                if (a[now] == 2)
                {
                    ans = i+1;
                    break;
                }
                else
                {
                    now = a[now]-1;
                }
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 15328
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	int N, K;
	Tuple[] p;
	long result = Long.MAX_VALUE - 1;

	static class Tuple {
		long x, y;

		Tuple(String line) {
			String[] tokens = line.split(" ");
			x = Long.parseLong(tokens[0]);
			y = Long.parseLong(tokens[1]);
		}
	}

	Main(BufferedReader in) throws IOException {
		String[] tokens = in.readLine().split(" ");
		N = Integer.parseInt(tokens[0]);
		K = Integer.parseInt(tokens[1]);
		p = new Tuple[N];
		for (int i = 0; i < N; ++i) {
			p[i] = new Tuple(in.readLine());
		}
		Arrays.parallelSort(p, new Comparator<Tuple>() {
			@Override
			public int compare(Tuple o1, Tuple o2) {
				int result = Long.compare(o1.x, o2.x);
				if (result != 0) {
					return result;
				} else {
					return Long.compare(o1.y, o2.y);
				}
			}
		});
	}

	int count(Tuple p1, Tuple p2, Tuple p3, Tuple p4) {
		Tuple[] array = new Tuple[3];
		array[0] = p2;
		array[1] = p3;
		array[2] = p4;
		long minX = p1.x;
		long minY = p1.y;
		long maxX = p1.x;
		long maxY = p1.y;
		for (int i = 0; i < 3; ++i) {
			minX = Math.min(minX, array[i].x);
			minY = Math.min(minY, array[i].y);
			maxX = Math.max(maxX, array[i].x);
			maxY = Math.max(maxY, array[i].y);
		}
		int c = 0;
		for (int i = 0; i < N; ++i) {
			Tuple point = p[i];
			if (point.x >= minX && point.x <= maxX) {
				if (point.y >= minY && point.y <= maxY) {
					++c;
				}
			}
		}
		return c;
	}

	void calc() {
		for (int i = 0; i < N; ++i) {
			Tuple p1 = p[i];
			for (int j = i; j < N; ++j) {
				Tuple p2 = p[j];
				for (int k = j; k < N; ++k) {
					Tuple p3 = p[k];
					for (int l = k; l < N; ++l) {
						Tuple p4 = p[l];
						int c = count(p1, p2, p3, p4);
						if (c >= K) {
							Tuple[] array = new Tuple[3];
							array[0] = p2;
							array[1] = p3;
							array[2] = p4;
							long minX = p1.x;
							long minY = p1.y;
							long maxX = p1.x;
							long maxY = p1.y;
							for (int m = 0; m < 3; ++m) {
								minX = Math.min(minX, array[m].x);
								minY = Math.min(minY, array[m].y);
								maxX = Math.max(maxX, array[m].x);
								maxY = Math.max(maxY, array[m].y);
							}
							long x = maxX - minX;
							long y = maxY - minY;
							long val = x * y;
							result = Math.min(result, val);
						}
					}
				}
			}
		}
	}

	void showResult() {
		System.out.println(result);
	}
}

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

using namespace std;
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
template<typename T> using vv = vector<vector<T>>;
template<typename T> using vvv = vector<vector<vector<T>>>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using pqg = priority_queue<T, vector<T>, greater<T>>;

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
const int DX[4] = {1, 0, -1, 0};
const int DY[4] = {0, 1, 0, -1};

#define _sel(_1, _2, x, ...) x
#define repn(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, ...) _sel(__VA_ARGS__, reps, repn)(i, __VA_ARGS__)
#define reppn(i, n) for (ll i = 1; i <= (n); i++)
#define repps(i, a, b) for (ll i = (a); i <= (b); i++)
#define repp(i, ...) _sel(__VA_ARGS__, repps, reppn)(i, __VA_ARGS__)
#define rrepn(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, a, b) for (ll i = (b) - 1; i >= (a); i--)
#define rrep(i, ...) _sel(__VA_ARGS__, rreps, rrepn)(i, __VA_ARGS__)
#define rreppn(i, n) for (ll i = (n); i >= 1; i--)
#define rrepps(i, a, b) for (ll i = (b); i >= (a); i--)
#define rrepp(i, ...) _sel(__VA_ARGS__, rrepps, rreppn)(i, __VA_ARGS__)

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define rng(v) (v).begin(), (v).end()
#define rrng(v) (v).rbegin(), (v).rend()
#define siz(x) int((x).size())
#define pow2(x) (1ll << (x))
#define bit(x, n) ((x) >> (n) & 1)
#define prt(x) cout << (x) << endl
#define dbg(x) dbgn(#x, x)

template<typename T, typename U> inline bool umax(T& m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U> inline bool umin(T& m, U x) { if (m > x) { m = x; return true; } return false; }
template<typename T> inline void errv(T& v) { for (auto x: v) cerr << x << " "; cerr << endl; }
inline void errv(vb& v) { for (auto x: v) cerr << (x ? 1 : 0) << " "; cerr << endl; }
template<typename T> inline void dbgn(string n, T x) { cerr << n << ": " << x << endl; }
template<typename T> inline void dbgn(string n, vector<T>& v) { cerr << n << ": "; errv(v); }
template<typename T> inline void dbgn(string n, vv<T>& m) { cerr << n << ":" << endl; for (auto& v: m) errv(v); }


int main() {
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];

    int cnt = 0;
    rep(i, n) {
        if (i % 2 == 0) {
            if (a[i] % 2 == 1) {
                cnt++;
            }
        }
    }

    prt(cnt);

    return 0;
}


Measured memory_bytes: 3620
i = gets.chop
#keyence
flg = false
key = "keyence"
i.length.times do |hoge|
    if i[hoge] == key[hoge] then
        if i[-6 + hoge..-1] == key[-6 + hoge..-1]
        flg = true
        end
    end
end

if flg then
    puts "YES"
else
    puts "NO"
end

Measured memory_bytes: 1788
#include <stdio.h>
int main (void)
{
  char S[100001];
  int i,cnt_1,cnt_2,cnt=0;
  
  scanf("%s",S);
  
  for(i=0;S[i]!='\0';i++){
	if(i%2==0){
      if(S[i]=='0')
        cnt++;
    }else{
      if(S[i]=='1')
        cnt++;
    }
  }
  cnt_1=cnt;
  cnt=0;
  for(i=0;S[i]!='\0';i++){
	if(i%2==0){
      if(S[i]=='1')
        cnt++;
    }else{
      if(S[i]=='0')
        cnt++;
    }
  }
  cnt_2=cnt;
  if(cnt_1<cnt_2)
  printf("%d ",cnt_1);
  else
  printf("%d",cnt_2);
  return 0;
}

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

int main()
{
    int n, m;
    std::cin >> n >> m;
    int aSum = 0;
    for (int i = 0; i < m; ++i)
    {
        int a;
        std::cin >> a;
        aSum += a;
    }
    std::cout << std::max(n - aSum,-1) << std::endl;

    return 0;
}

Measured memory_bytes: 3636
a, b, c, d = map(int, input().split())

t = 0
while True:
    if t % 2 == 0:
        c -= b
        if c <= 0:
            print('Yes')
            exit()
    else:
        a -= d
        if a <= 0:
            print('No')
            exit()
    t += 1


Measured memory_bytes: 61692
/*author: hyperion_1724
  date: 
*/

//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required 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>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

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<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

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; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
    #ifndef ONLINE_JUDGE
        if (fopen("INPUT.txt", "r")) 
        {
            freopen ("INPUT.txt" , "r" , stdin);
            freopen ("OUTPUT.txt" , "w" , stdout);
        }
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    clock_t clk;
    clk = clock();
//-----------------------------------------------------------------------------------------------------------//

        READV(N);
    READV(D);
    READV(A);
    map<ll,ll> Z;
    set<ll> pos;
    FORI(i,0,N)
    {
        READV(X);
        READV(H);
        Z[X]=max(Z[X],H);
    }
    for(auto p:Z)
    {
        pos.insert(p.fi);
    }
    ll ans=0;
    map<ll,ll> V;
    ll sum=0;
    while(sz(pos)>0)
    {
        ll p=*pos.begin();
        sum+=V[p];
        ll H=Z[p]-sum;
        pos.erase(pos.begin());
        if (H>0)
        {
            ans+=(H+A-1)/A;
            V[p+2*D+1]-=((H+A-1)/A)*A;
            pos.insert(p+2*D+1);
            sum+=((H+A-1)/A)*A;
        }
    }
    cout<<ans<<endl;
 

//-----------------------------------------------------------------------------------------------------------//


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

    return 0;
}

Measured memory_bytes: 50304
#!/usr/bin/env python2
"""
This file is part of https://github.com/cheran-senthil/PyRival
Copyright 2019 Cheran Senthilkumar <hello@cheran.io>

"""
from __future__ import division, print_function

import itertools
import os
import sys
from atexit import register
from io import BytesIO


class dict(dict):
    """ dict() -> new empty dictionary """

    def items(self):
        """ D.items() -> a set-like object providing a view on D's items """
        return dict.iteritems(self)

    def keys(self):
        """ D.keys() -> a set-like object providing a view on D's keys """
        return dict.iterkeys(self)

    def values(self):
        """ D.values() -> an object providing a view on D's values """
        return dict.itervalues(self)


def gcd(x, y):
    """ greatest common divisor of x and y """
    while y:
        x, y = y, x % y
    return x


range = xrange

filter = itertools.ifilter
map = itertools.imap
zip = itertools.izip

sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))

input = lambda: sys.stdin.readline().rstrip('\r\n')


def main():
    H, W = map(int, input().split())
    h, w = map(int, input().split())

    print(H * W - (h * W + H * w - h * w))


if __name__ == '__main__':
    main()


Measured memory_bytes: 28652
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;

int main(){
  int n;
  string s,ans = "Yes";
  cin >> n >> s;
  if(n%2 == 1) {
    cout <<  "No";
    return 0;}
  
  rep(i,n/2){
    if(s.at(i) != s.at(n/2+i)) ans = "No";
  }
  cout << ans;
}

Measured memory_bytes: 256
from sys import stdin
def main():
    n = int(input())
    s = input()
    ans = 1
    start = 0
    end = 0
    for i in range(1, len(s)):
        if s[i] != s[start]:
            ans += 1
            start = i
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String a = s.nextLine();
        int count = 0;

        for (int i = 0; i < a.length(); i++) {
            if (a.charAt(i) == '1') {
                count++;
            }
        }
        System.out.println(count);
        s.close();
    }
}

Measured memory_bytes: 35644
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}


//-------------------------------------------------
// メモ
/*






*/
//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a, b, c ;
  cin >> a >> b >> c ;
  int cnt = 0 ;
  
  while(1){
    if(a%2==1 ||b%2==1 || c%2==1){
      cout << cnt <<endl ;
      return 0 ;
    }
    else{
      cnt++ ;
      ll sum = a+b+c ;
      a = sum - a;
      b = sum - b;
      c = sum - c;
      a /= 2 ;
      b /= 2 ;
      c /= 2 ;
    }
    if(max({a,b,c})==min({a,b,c})){
      cout << -1 <<endl ;
      return 0 ;
    }
  }
  
  
  
  return 0 ;
}



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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

template<typename T>
void O(T t){
  cout << t << endl;
}

const ll mod = 1e9+7;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  string s;
  string ans,tmp2;
  cin >> s;
  vector<ll> v(n+1);
  ll u = 0;
  rep(i,n){
    if(s[i] == '(' && u < 0){
      string tmp ;
      rep(i,abs(u)){
        tmp += "(";
      }
      ans = tmp + ans + tmp2;
      tmp2 = "";
      u = 0;
    }
    if(s[i] == '('){
      ++u;
      tmp2 += s[i];
    }
    if(s[i] == ')'){
      --u;
      tmp2 += s[i];
    }
  }
  string tmp ;
  if(u < 0){
    rep(i,abs(u)){
      tmp += "(";
    }
    ans = tmp + ans + tmp2;
  }
  else{
    rep(i,abs(u)){
      tmp += ")";
    }
    ans = ans + tmp2 + tmp;
  }
  tmp2 = "";
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
  char s[3];
  std::cin >> s[0] >> s[1] >> s[2];
  
  int ans = 0;
  for(int i = 0; i < 3; ++i)
  {
    if(s[i] == '1') ++ ans;
  }
  
  std::cout << ans;
}


Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/agc039/tasks/agc039_b
//任意の辺が、連続する番号の2つの頂点集合をつなげている

//この問題で、まず考え付くべきなのは、
//頂点の振り分け、どの集合も前後の集合としか連結しない。
//この二つの特徴に当てはまる構造は二部グラフ
//(の条件を厳しくしたもの)である
//参考：
//https://tt-conpetitive.hatenablog.com/entry/2019/10/06/023446
//https://sen-comp.hatenablog.com/entry/2019/10/06/174227
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

int N;
LL adj[200][200];//隣接行列

LL ans = 0;

void solve(){
	//BFSで二部グラフ判定
	//2色で頂点に色を塗る　隣り合う頂点が同じ色になってしまうのを避けられないなら
	//それは二部グラフではないことがわかる
	//その時は-1を返して終了

	//与えられたグラフがまず2部グラフでないなら
	//そもそも条件を満たすような集合は作れない
	int used[200] = {0};//頂点iをもう見たならused[i]=1
	used[0] = 1;
	queue<int> q;
	q.push(0);
	while (!q.empty()) {
		int now = q.front(); q.pop();//頂点をqueueから取り出す
		for (int i=0;i<N;i++) {
			if (adj[now][i]==1){
				if (used[i] == 0) {
					used[i] = (used[now]==1)? 2 : 1;//2か1で塗り分ける
					q.push(i);
				}
				else if (used[i] == used[now]) {
					ans = -1;
					return;
				}
			}
		}
	}
	//2部グラフと分かったならば以下を実行
	//ワーシャルフロイド
	for (int k=0;k<N;k++){
		for (int i=0;i<N;i++){
			for (int j=0;j<N;j++){
				adj[i][j] = min(adj[i][j],adj[i][k]+adj[k][j]);
			}
		}
	}
	//この時点でiとjの最短距離がE[i][j]に格納される
	//E[i][j]のうち一番大きいものをansとする
	for (int i=0;i<N;i++) {
		for (int j=0;j<N;j++) {
			ans = max(ans,adj[i][j]);
		}
	}
	ans++;
}
 
int main(){
	cin >> N;
	for(int i=0;i<N;i++){
		string S;
		cin >> S;
		for(int j=0;j<N;j++){
			if(S[j]=='0' && i!=j) adj[i][j] = INF;
			else if(i!=j) adj[i][j] = 1;
			else adj[i][j] = 0;
		}
	}
 
	solve();

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

Measured memory_bytes: 512
#include <stdio.h>
#include <iostream>
using namespace std;

int main()
{
    int n, m, result;
    int max = 1;
    int min = 100000;
    cin >> n >> m;
    int ini, fin;
    for (int i = 0; i < m; i++) {
        cin >> ini >> fin;
        if(max < ini) max = ini;
        if(min > fin) min = fin;
    }
    result = min - max + 1;
    if (result < 0) result = 0;
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int  sx, sy, tx, ty, i;

  scanf("%d %d %d %d", &sx, &sy, &tx, &ty);

  putchar('L');
  for(i=0; i<(ty-sy)+1; i++)  putchar('U');
  for(i=0; i<(tx-sx)+1; i++)  putchar('R');
  putchar('D');
  for(i=0; i<(tx-sx); i++)  putchar('L');
  for(i=0; i<(ty-sy); i++)  putchar('D');
  for(i=0; i<(tx-sx); i++)  putchar('R');
  for(i=0; i<(ty-sy); i++)  putchar('U');
  putchar('R');
  for(i=0; i<(ty-sy)+1; i++)  putchar('D');
  for(i=0; i<(tx-sx)+1; i++)  putchar('L');
  putchar('U');

  putchar('\n');
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = numeric_limits<ll>::max() / 4;
namespace utils{
    template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>;
    template<class T> using min_queue = p_queue<T, greater<T>>;
    template<class T> using max_queue = p_queue<T, less<T>>;

    template<class T> bool min_update(T& X, const T& A){ if(X > A) {X = A; return true;} return false; }
    template<class T> bool max_update(T& X, const T& A){ if(X < A) {X = A; return true;} return false; }
    using V_Set = unordered_set<int>;
    using E_Set = unordered_map<int, V_Set>;

#define ALL(x) begin(x), end(x)
#define rALL(x) rbegin(x), rend(x)
}
using namespace utils;


void sub_main(istream &is) {
    ll N;
    is >> N;
    if(!is) return;
    ll mx, sm;
    int p;
    mx = -1; sm = -1;
    for (int i = 0; i < N; ++i) {
        ll t;
        is >> t;
        if(t >= mx){
            sm = mx;
            mx = t;
            p = i;
        }
        else if(t >= sm){
            sm = t;
        }
    } // end i

    for (int i = 0; i < N; ++i) {
        cout << (p == i ? sm : mx) << endl;
    } // end i


}

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    string test_cases = "test_C.txt";
    cerr << "DEBUG MODE" <<  endl;
    cerr << test_cases << " -->" << endl;
    auto fs = fstream(test_cases, fstream::in);
    int lp = 0;
    while(fs) {
        lp++;
        cout << lp <<  "#------\n";
        sub_main(fs);
    }
    cout << "------#" << endl;
    if(lp <= 1) sub_main(cin);
#else
    sub_main(cin);
#endif
    return 0;
}


Measured memory_bytes: 1664
n,m=map(int, input().split())
a=[0]*(n+1)
b=[list(map(int, input().split()))+[i]+[0] for i in range(m)]
b.sort(key=lambda x:x[1])
for i,(x,y,l,z) in enumerate(b):
    a[x-1]+=1
    b[i][3]=a[x-1]
b.sort(key=lambda x:x[2])
for x,y,l,z in b:
    print('{0:06d}{1:06d}'.format(x,z))

Measured memory_bytes: 35960
def main():
    N,M,K=map(int,input().split())
    MOD=998244353
    E=0

    n_=1
    for i in range(1,N):
        n_=(n_*i)%MOD

    nr_ = 1
    nr_array=[]
    for i in range(1,N-1):
        nr_ = (nr_ * i) % MOD
        nr_array.append(nr_)
    m=1
    Mk_array=[1]
    for i in range(1,N):
        m=(m*(M-1))%MOD
        Mk_array.append(m)
    r_=1
    for i in range(0,K+1):
        if i!=0 and i!=N-1:
            r_ = (r_ * i) % MOD
            nr_=nr_array.pop()
            power_r=pow(r_,MOD-2,MOD)
            power_nr=pow(nr_,MOD-2,MOD)
        Mk=Mk_array.pop()

        if i!=0 and i!=N-1:
            E+=(n_*power_r*power_nr*Mk)%MOD
        else:
            E+=Mk%MOD

    res=(M*E)%MOD
    print(res)

if __name__=="__main__":
    main()



Measured memory_bytes: 24824
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
	auto pow2 = [](ll n) {ll ans = 1; REP(i, n)ans *= 2; return ans; };
	ll n = in(), p = in();
	ll odd = 0; REP(i, n) if (in() % 2 == 1) ++odd;
	cout << (
		p == 0 && odd == 0 ? pow2(n)
		: p == 1 && odd == 0 ? 0
		: pow2(n - 1)
		) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
bool mus(char c){
	return c=='k'||c=='s'||c=='t'||c=='p'||c=='h';
}
bool bo(char c){
	return c=='a'||c=='i'||c=='u'||c=='e'||c=='o';
}
int main(){
	while(true){
		string s;
		cin>>s;
		if(s[0]=='#') break;
		int N=s.size();
		string t;
		bool ins[200]={};
		rep(i,N-1){
			if(mus(s[i])&&s[i+1]=='y') t+=s[i],i++,ins[t.size()]=1;
			else t+=s[i];
		}
		t+=s[N-1];
		s=t;
		N=s.size();
		bool er[100]={};
		rep(i,N){
			if(i==0) continue;
			if(s[i]=='i'||s[i]=='u'){
				if(mus(s[i-1])&&(i==N-1||mus(s[i+1]))){
					er[i]=1;
				}
			}
			if(s[i]=='a'||s[i]=='o'){
				if(i+2<N&&mus(s[i-1])&&mus(s[i+1])&&s[i]==s[i+2]){
					er[i]=1;
				}
			}
		}
		rep(i,N) if(er[i]){
			for(int j=i-1;j>=0;j--){
				if(bo(s[j])){
					if(er[j]) er[i]=0;
					break;
				}
			}
		}
		rep(i,N){
			if(ins[i]) cout<<"y";
			if(er[i]) cout<<"("<<s[i]<<")";
			else cout<<s[i];
		}
		puts("");
	}
}

Measured memory_bytes: 1172
import sys
sys.setrecursionlimit(10 ** 6)


def solve():
    N, K = map(int, input().split())
    AB = [[] for _ in range(N + 1)]
    for _ in range(N - 1):
        a, b = map(int, input().split())
        AB[a].append(b)
        AB[b].append(a)

    # AB = [sorted([int(i) for i in input().split()]) for _ in range(N - 1)]
    # AB.sort()
    print(dfs(AB, 1, 0, 0, 1, K, 0) % (10 ** 9 + 7))


def dfs(hen, cho, kai, ko, tag, K, oya):
    tag *= K - (ko - 1 if ko > 0 else 0) - (2 if kai >= 2 else kai)
    next_ko = hen[cho].copy()
    if oya != 0:
        next_ko.remove(oya)
    for i in range(len(next_ko)):
        tag = dfs(hen, next_ko[i], kai + 1, i + 1, tag, K, cho)
    return tag % (10 ** 9 + 7)


if __name__ == '__main__':
    solve()


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

int main()
{
	int k, a, b, temp = 0, i = 1;
	cin >> k;
	cin >> a >> b;
	while (temp <= b) {
		temp = k * i;
		i++;
		if (temp >= a && temp <= b) {
			cout << "OK" << endl;
			return 0;
		}
	}
	cout << "NG" << endl;
	return 0;
}

Measured memory_bytes: 3624
// AOJ Volume 0 Problem 0036

#include <stdio.h>
#include <string.h>


int check_4card(int card[])
{
    int i;
    
    for (i = 1; i <= 13; i++){
        if (card[i] == 4){
            return (1);
        }
    }
    
    return (0);
}

int check_fullhouse(int card[])
{
    int i;
    
    for (i = 1; i <= 13; i++){
        if (card[i] == 1){
            return (0);
        }
    }
    
    return (1);
}

int check_3card(int card[])
{
    int i;
    
    for (i = 1; i <= 13; i++){
        if (card[i] == 3){
            return (1);
        }
    }
    
    return (0);
}

int check_2pair(int card[])
{
    int i;
    int cnt;

    cnt = 0;
    for (i = 1; i <= 13; i++){
        if (card[i] == 2){
            cnt++;
        }
    }
    
    if (cnt == 2){
        return (1);
    }
    return (0);
}

int check_1pair(int card[])
{
    int i;
    int cnt;

    cnt = 0;
    for (i = 1; i <= 13; i++){
        if (card[i] == 2){
            cnt++;
        }
    }
    
    if (cnt == 1){
        return (1);
    }
    return (0);
}

int check_straight(int card[])
{
    int i, j;

    for (i = 1; i <= 13; i++){
        if (card[i] != 0){
            break;
        }
    }
    
    if (i == 1 && card[2] == 0){
        i = 10;
    }
    
    for (j = i; j < i + 5; j++){
        if (card[j] != 1){
            return (0);
        }
    }
    return (1);
}

int main(void)
{
    int card[15];
	int c1, c2, c3, c4, c5;
    int i, j;

	while (scanf("%d,%d,%d,%d,%d", &c1, &c2, &c3, &c4, &c5) != EOF){
        memset(card, 0, sizeof(card));
        
        card[c1]++;
        card[c2]++;
        card[c3]++;
        card[c4]++;
        card[c5]++;
        card[14] = card[1];
        
        if (check_4card(card) == 1){
            printf("four card\n");
        }
        else if (check_fullhouse(card) == 1){
            printf("full house\n");
        }
        else if (check_straight(card) == 1){
            printf("straight\n");
        }
        else if (check_3card(card) == 1){
            printf("three card\n");
        }
        else if (check_2pair(card) == 1){
            printf("two pair\n");
        }
        else if (check_1pair(card) == 1){
            printf("one pair\n");
        }
        else {
            printf("null\n");
        }
	}
    
    return (0);
}

Measured memory_bytes: 0
if __name__ == "__main__":
    num = list(map(int, input().split()))

    if (num[3] == 0):
        print(0)
    elif (num[0] == 0 and num[1] == 0 and num[2] == 0):
        print(0)
    elif (num[3] <= num[0]):
        print(num[3])
    else:
        print(num[0] - num[3] + num[0] + num[1])


Measured memory_bytes: 9176
#include<stdio.h>

int main(void) {
	int N, i;
	int a, b, c, max;
	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%d %d %d", &a, &b, &c);
		if(a*a==b*b+c*c || b*b==c*c+a*a || c*c==a*a+b*b){
			printf("YES\n");
		} else {
			printf("NO\n");
		}
	}
	
	return 0;
}

Measured memory_bytes: 576
#include<bits/stdc++.h>
using namespace std;
int a[111];
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	reverse(a,a+n);
	int mn=1e9;
	const int cnt=a[0];
	int ans=1;
	for(int i=1;i<=cnt;i++){
		int cnt2=0;
		for(int j=0;j<n;j++)
			cnt2+=(a[j]-i)*(a[j]-i);
		if(cnt2<mn){
			mn=cnt2;
			ans=i;
		}
	}
	cout<<mn<<endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
if n%2==0:
    print(a[0]+2*sum(a[1:n//2]))
else:
    temp=n//2+1  
    print(a[0]+2*sum(a[1:temp-1])+a[temp-1])

Measured memory_bytes: 31620
def end():
    print("No")
    exit()

n, a, b, c = map(int, input().split())
s = [input() for i in range(n)]
log = []

for i in range(n):
    if s[i] == "AB":
        # コーナーケース
        if a == 1 and b == 1:
            # aが重複 最後はどっちでもいいので
            if i == n-1 or s[i+1] == "AB" or s[i+1] == 'AC':
                a += 1
                b -= 1
                log.append("A")
            # Bが重複
            else:# "BC"
                a -= 1
                b += 1
                log.append("B")
        elif a == 0 and b == 0:
            end()
        else:
            if a>=b:
                a -= 1
                b += 1
                log.append("B")
            else:
                a += 1
                b -= 1
                log.append("A")

    elif s[i] == "AC":
        # コーナーケース
        if a == 1 and c == 1:
            # aが重複
            if i == n-1 or s[i+1] == "AC" or s[i+1] == 'AB':
                a += 1
                c -= 1
                log.append("A")
            # Cが重複
            else:# "BC"
                c += 1
                a -= 1
                log.append("C")
        elif a == 0 and c == 0:
            end()
        else:
            if a>=c:
                a -= 1
                c += 1
                log.append("C")
            else:
                a += 1
                c -= 1
                log.append("A")
    else:#BC
        # コーナーケース
        if c == 1 and b == 1:
            # Bが重複
            if i == n-1 or  s[i+1] == "BC" or s[i+1] == 'AB':
                c -= 1
                b += 1
                log.append("B")
            # Cが重複
            else:# "AC"
                c += 1
                b -= 1
                log.append("C")
        elif b == 0 and c == 0:
            end()
        else:
            if b>=c:
                b -= 1
                c += 1
                log.append("C")
            else:
                b += 1
                c -= 1
                log.append("B")
else:
    print("Yes")
    print(*log, sep='\n')


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

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



    cin.tie(0);
    ios::sync_with_stdio(false);

    /////////////////////
    // Write code below /
    /////////////////////
    int N,K,d,A,n[100]={},cnt=0;

    cin>>N>>K;
    rep(i,K){
        cin>>d;
        rep(j,d){
            cin>>A;
            n[A-1]++;
        }
    }
    rep(i,N){
        if(n[i]==0){
            cnt++;
        }
    }
    cout<<cnt<<endl;

    return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>
#include <algorithm>
using namespace std;
const int MAX_N=100;
const int MAX_W=10000;
int n,W;
int v[MAX_N];
int w[MAX_N];
int dp[MAX_N+1][MAX_W+1];
void solve(){ 
   for(int i=0;i<n;i++){
       for(int j=0;j<=W;j++){
              if(j<w[i]){
            dp[i+1][j]=dp[i][j];
                        }
                else{
             dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
                   }
           }
   }

      }
int main(){
     scanf("%d%d",&n,&W);
     for(int i=0;i<n;i++){
         scanf("%d%d",&v[i],&w[i]);
         dp[i][0]=0;
         }
solve();
printf("%d\n",dp[n][W]);
return 0;
}

Measured memory_bytes: 4936
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
from bisect import bisect, bisect_left, bisect_right

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

sys.setrecursionlimit(10 ** 8)


def search(y, x, depth):
    global ans
    if s[y][x] == ".":
        if y == H and x == W:
            if depth < ans:
                ans = depth
        if s[y + 1][x] == ".":
            if check[y + 1][x] > depth:
                pos.append([y + 1, x, depth])
                check[y + 1][x] = depth
        elif s[y + 1][x] == "#":
            if check[y + 1][x] > depth:
                search(y + 1, x, depth)
                check[y + 1][x] = depth
        if s[y][x + 1] == ".":
            if check[y][x + 1] > depth:
                pos.append([y, x + 1, depth])
                check[y][x + 1] = depth
        elif s[y][x + 1] == "#":
            if check[y][x + 1] > depth:
                search(y, x + 1, depth)
                check[y][x + 1] = depth
    else:
        if y == H and x == W:
            if depth < ans:
                ans = depth + 1
        if s[y + 1][x] == ".":
            if check[y + 1][x] > depth + 1:
                pos.append([y + 1, x, depth + 1])
                check[y + 1][x] = depth + 1
        elif s[y + 1][x] == "#":
            if check[y + 1][x] > depth:
                search(y + 1, x, depth)
                check[y + 1][x] = depth
        if s[y][x + 1] == ".":
            if check[y][x + 1] > depth + 1:
                pos.append([y, x + 1, depth + 1])
                check[y][x + 1] = depth + 1
        elif s[y][x + 1] == "#":
            if check[y][x + 1] > depth:
                search(y, x + 1, depth)
                check[y][x + 1] = depth


H, W = map(int, input().split())
s = [["$" for _ in range(W + 2)]]
for i in range(H):
    s.append(["$"] + list(input()) + ["$"])
s.append(["$" for _ in range(W + 2)])
check = [[INF] * (W + 2) for _ in range(H + 2)]

ans = INF
pos = deque()
if s[1][1] == ".":
    pos.append([1, 1, 0])
else:
    search(1, 1, 0)
while len(pos) > 0:
    y, x, depth = pos.popleft()
    search(y, x, depth)
print(ans)

Measured memory_bytes: 6980
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
//一部doubleをllにしていて時間を犠牲にしたクソ
int main(){

    double A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
    double noud_limit = 100 * E / (100 + E);
    double noud = 0;
    ll sugar = 0;
    ll water = 0;

    for(ll a = 0; a <= 31; a++){
        //cout << a << endl;
        for(ll b = 0; b <= 31; b++){
            //cout << b << endl;
            for(ll c = 0; c <= 101; c++){
                //cout << c << endl;
                for(ll d = 0; d <= 101; d++){
                    //cout << d << endl;
                    double t_water = 100 * A * a + 100 * B * b;
                    if(t_water <= 0) continue;
                    double t_sugar =  C * c + D * d;
                    double t_noud = 100 * t_sugar / (t_water + t_sugar) ;
                    if(t_water + t_sugar > F){
                        continue;
                    }
                    if(t_noud > noud_limit ){
                        continue;
                    }
                    if(noud <= t_noud){
                        noud = t_noud;
                        sugar = t_sugar;
                        water = t_water;
                    }
                }         
            }          
        }    
    }

    cout << water + sugar << " " << sugar << endl;

}  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 922337203685477;
const ll mininf = -922337203685477;
const ll nax = 1e5 + 5;
ll x;

bool prima(ll x){
	if(x<=1) return false;
	if(x<=3) return true;
	for(int i=2;i*i<=x;i++){
		if(x%i==0){
			return false;
		}
	}
	return true;
}

int main(){
	IOS
	cin >> x;
	ll ans=0;
	while(1){
		if(prima(x)){
			break;
		}
		x++;
	}
	cout << x << '\n';
}


Measured memory_bytes: 3632
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                    as A
import qualified Data.Array.ST                 as ST
import qualified Data.Array.Unboxed            as AU
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import qualified Data.Foldable                 as DF
import           Data.Int
import qualified Data.IntMap                   as IM
import           Data.List
import qualified Data.Map                      as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Set                      as S
import qualified Data.Sequence                 as SQ
import           Data.Time
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
readInts n = replicateM n readInt
readString = map BS.unpack . BS.words <$> BS.getLine
readStrings n = replicateM n <$> readString
toPair [x, y] = (x, y)

main = do
  [n, m] <- readInt
  path   <- map toPair <$> readInts m
  let path' = sort $ path ++ map (\(a, b) -> (b, a)) path in print $ solve n m path'

solve n m path = length $ filter (\p -> g p path') pathes
 where
  pathes = map (\ss -> (1 : ss)) (permutations [2, 3 .. n])
  path'  = let (a, b) = head path in M.fromList $ f (tail path) [(a, [b])]

f ((a, b) : ss) ((c, d) : acc) | a == c    = f ss ((c, (b : d)) : acc)
                               | otherwise = f ss ((a, [b]) : (c, d) : acc)
f [] acc = acc

g [_] _ = True
g (a : b : ss) path | b `elem` (path M.! a) = g (b : ss) path
                    | otherwise             = False


Measured memory_bytes: 1020
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

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

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

      return tokenizer.nextToken("\n");
    }

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

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

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

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int k = sc.nextInt();
    int x = sc.nextInt();
    System.out.println(500 * k >= x ? "Yes" : "No");
  }
}

Measured memory_bytes: 22996
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var a = o.a();
  var b = o.a();
  var c = o.a();
  return Math.max(c-a+b,0);
}

Measured memory_bytes: 7372