akhauriyash/Code-Regression huggingface dataset:
//1183F
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=1e9+7;
const int N=1e2+10;
char a[N][N];
int dp[N][N];
int32_t main()
{
    IOS;
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cin>>a[i][j];
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(i==1&&j==1)
            {
                dp[i][j]=(a[i][j]=='#');
            }
            else if(i==1)
            {
                if(a[i][j]=='#'&&a[i][j-1]=='.')
                {
                    dp[i][j]=dp[i][j-1]+1;
                }
                else 
                    dp[i][j]=dp[i][j-1];
            }
            else if(j==1)
            {
                if(a[i][j]=='#'&&a[i-1][j]=='.')
                {
                    dp[i][j]=dp[i-1][j]+1;
                }
                else 
                    dp[i][j]=dp[i-1][j];
            }
            else
            {
                int x=dp[i][j-1];
                int y=dp[i-1][j];
                if(a[i][j]=='#'&&a[i-1][j]=='.')
                    y++;
                if(a[i][j]=='#'&&a[i][j-1]=='.')
                    x++;
                dp[i][j]=min(x,y);
            }

        }
    }
    cout<<dp[n][m]<<endl;
    



      
}

Measured memory_bytes: 384
#pragma comment (linker, "/STACK:256000000")
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define sz(c) (int)(c.size())
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T, class U>using vp = vector<pair<T, U>>;
template<class T>using vv = vector<vector<T>>; template<class T, class U>using vvp = vv<pair<T, U>>;
template<class T>vv<T> vvec(const size_t n, const size_t m, const T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; }return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; }return 0; }
constexpr ll pow2(const int n) { return 1ll << n; }
constexpr int INF = 1 << 28; constexpr ll LINF = 1ll << 60;
constexpr int MAX = 1e5 + 5; constexpr int MOD = 1e9 + 7; constexpr double EPS = 1e-6;
constexpr int dy[4] = { 0,1,0,-1 }; constexpr int dx[4] = { 1,0,-1,0 };
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

string S;
vv<ll> dp;

int main() {
    cin >> S;
    int size = S.size();

    dp = vvec<ll>(size + 1, 4, 0);
    dp[0][0] = 1;

    rep(i, 1, size + 1) {
        if (S[i - 1] == 'A' || S[i - 1] == '?') {
            dp[i][0] += dp[i - 1][0];
            dp[i][1] += dp[i - 1][1] + dp[i - 1][0];
            dp[i][2] += dp[i - 1][2];
            dp[i][3] += dp[i - 1][3];
        }
        if (S[i - 1] == 'B' || S[i - 1] == '?') {
            dp[i][0] += dp[i - 1][0];
            dp[i][1] += dp[i - 1][1];
            dp[i][2] += dp[i - 1][2] + dp[i - 1][1];
            dp[i][3] += dp[i - 1][3];
        }
        if (S[i - 1] == 'C' || S[i - 1] == '?') {
            dp[i][0] += dp[i - 1][0];
            dp[i][1] += dp[i - 1][1];
            dp[i][2] += dp[i - 1][2];
            dp[i][3] += dp[i - 1][3] + dp[i - 1][2];
        }

        rep(j, 4) dp[i][j] %= MOD;
    }

    write(dp[size][3]);
}

Measured memory_bytes: 7376
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define INF 999999999
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl;
#define Vecpr vector<pair<lli,lli>>
int main() {
  lli A,B=0,C=0,D=0,F=INF;
  cin >> A;
  string S;
  cin >> S;
  B=S.size();
  vector<lli>P(B+1,0),Q(B+1,0);
  for(int i=1;i<B+1;i++){
    P[i]=P[i-1];
    if(S[i-1]=='W')P[i]++;
    Q[i]=Q[i-1];
    if(S[i-1]=='E')Q[i]++;
  }
  for(int i=1;i<B+1;i++)F=min(P[i]+Q[B]-Q[i-1],F);
  Out(F-1);
}

Measured memory_bytes: 5380
n=int(input())
a=list(map(int,input().split(' ')))
b=list(map(int,input().split(' ')))
c=list(map(int,input().split(' ')))
a=[0]+sorted(a)+[float('inf')]
c=[0]+sorted(c)+[float('inf')]


def bin_search_a(a,b):
    low=0
    high=len(a)-1
    while low<=high:
        mid=(low+high)//2
        if a[mid] < b <= a[mid+1]:
            return mid
        if a[mid] >= b:
            high=mid-1
        else:
            low=mid+1
    
def bin_search_c(c,b):
    low=0
    high=len(c)-1
    while low<=high:
        mid=(low+high)//2
        if c[mid] <= b < c[mid+1]:
            return mid
        if c[mid] > b:
            high=mid-1
        else:
            low=mid+1

altar=0

for bi in b:
    s=bin_search_a(a,bi)*(n-bin_search_c(c,bi))
    altar+=s
print(altar)

Measured memory_bytes: 23092
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <tuple>
#include <queue>

using namespace std;

class Solver {
};
signed main() {
	int n, m, k, p;
	cin >> n >> m >> k >> p;
	p--;

	vector<vector<tuple<int, int>>> graph(n,
		vector<tuple<int, int>>(0));
	for (int i = 0; i < m; i++) {
		int x, y, w;
		cin >> x >> y >> w;
		x--;
		y--;
		graph[x].emplace_back(y, w);
		graph[y].emplace_back(x, w);
	}

	map<int, tuple<int, int>> posts;
	int pows = 1;
	for (int i = 0; i < k; i++) {
		int s, t;
		cin >> s >> t;
		s--;
		t--;
		posts[s] = make_tuple(pows, 0);
		posts[t] = make_tuple(pows, 1);
		pows *= 3;
	}

	int state_cnt = pow(3, k);
	vector<vector<int>> dp(n,
		vector<int>(state_cnt, 1e9));

	priority_queue<tuple<int, int, int>,
		vector<tuple<int, int, int>>,
		greater<tuple<int, int, int>>>que;
	que.emplace(make_tuple(0, 0, p));
	while (que.size() > 0) {
		int dist, c_bit, now;
		tie(dist, c_bit, now) = que.top();
		que.pop();
		if (dp[now][c_bit] <= dist)continue;
		dp[now][c_bit] = dist;
		for (int i = 0; i < graph[now].size(); i++) {
			int to = get<0>(graph[now][i]);
			int next_dist = get<1>(graph[now][i]) + dist;
			if (dp[to][c_bit] <= next_dist)continue;

			que.emplace(next_dist, c_bit, to);
		}

		int next_bit = c_bit;
		if (posts.find(now) != posts.end()) {
			int div = get<0>(posts[now]);
			int mode = get<1>(posts[now]);
			int bit_tmp = (c_bit / div) % 3;
			if (bit_tmp == mode)next_bit += div;
		}
		if (c_bit == next_bit || dp[now][next_bit] <= dist)continue;
		que.emplace(dist, next_bit, now);
	}

	int res = 1e9;
	for (int i = 0; i < n; i++) {
		res = min(res, dp[i][state_cnt - 1]);
	}
	if (res == 1e9)cout << "Cannot deliver" << endl;
	else cout << res << endl;
}


Measured memory_bytes: 8476
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n; cin >> n;
  	bool b = n % 10 == 7 || n/10 % 10 == 7 || n/100 % 10 == 7;
  	cout << (b ? "Yes" : "No") << endl;
}


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

#define rep(x, y) for (int i = (x); i < (y); i++)

typedef long long ll;

using namespace std;

void solve() {
    int n;
    cin >> n;

    int w[n];
    rep(0, n) cin >> w[i];

    int s1, s2, s_abs, min_abs = 1e9;
    for (int t = 0; t < n; t++) {
        s1 = 0;
        for (int i = 0; i < t; i++) {
            s1 += w[i];
        }

        s2 = 0;
        for (int i = t; i < n; i++) {
            s2 += w[i];
        }

        s_abs = abs(s1 - s2);
        min_abs = min(min_abs, s_abs);
    }

    cout << min_abs << endl;
}

int main() {
    solve();

    return 0;
}

Measured memory_bytes: 256
n = int(input())
a_li = list(set(int(x) for x in input().split()))

while 1:
    res = a_li[-1]
    a_li.sort(reverse = True)
    cou = 0
    for i in a_li[:-1]:
        a_li[cou] = i % a_li[-1]
        cou += 1
    a_li = list(set(a_li))
    try:
        a_li.remove(0)
    except:
        pass
    if len(a_li) == 0:
        print(res)
        break
    if len(a_li) == 1:
        print(a_li[0])
        break


Measured memory_bytes: 19728
N = int(input())
X = []
Y = []
for i in range(N):
    x, y = map(int, input().split())
    X.append((x, y, i))
    Y.append((y, x, i))
X.sort()
Y.sort()
Edges = list([] for _ in range(N))
for k in range(N-1):
    xk, yk, ik = X[k]
    xk_, yk_, ik_ = X[k+1]
    Edges[ik].append((ik_, min(abs(xk-xk_), abs(yk-yk_))))
    Edges[ik_].append((ik, min(abs(xk-xk_), abs(yk-yk_))))
    yk, xk, ik = Y[k]
    yk_, xk_, ik_ = Y[k+1]
    Edges[ik].append((ik_, min(abs(xk-xk_), abs(yk-yk_))))
    Edges[ik_].append((ik, min(abs(xk-xk_), abs(yk-yk_))))
    
import heapq
def prim(Edges, V):
    mst = []
    included = [False]*V
    heap = []
    included[0] = True
    for v, d in Edges[0]:
        heapq.heappush(heap, (d, 0, v)) #(dist, pre_v, cur_v)
    while heap:
        d, pre_v, cur_v = heapq.heappop(heap)
        if included[cur_v]:
            continue
        included[cur_v] = True
        mst.append((pre_v, cur_v, d))
        for next_v, dist in Edges[cur_v]:
            if not included[next_v]:
                heapq.heappush(heap, (dist, cur_v, next_v))
    return mst

mst = prim(Edges, N)
ans = 0
for v1, v2, d in mst:
    ans += d
    
print(ans)

Measured memory_bytes: 94620
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<string>

using namespace std;

typedef long long ll;

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

  string S;
  cin >> S;

  //basic_string<char>[S.size()];

  int i;
  for(i = 0; i < S.size(); i++)
    {
      if(int(char(S[i])+N) <=int('Z') )
	cout << char(int(S[i]) + N) ;
      else
	cout << char(int(S[i]) + N-int('Z')+int('A')-1) ;
    }



  cout << endl;



  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
main(){
int x[5];
for(int i=0;i<5;i++) cin>>x[i];
//sort(x,x+5);
for(int i=0;i<5;i++)
    if(x[i]==0) cout<<i+1;
}


Measured memory_bytes: 3628
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m,k,l;
int mx(int x,int y)
{
	return x>y?x:y;
}
int main()
{
	scanf("%d%d",&n,&m);
	printf("%d\n",mx(n+m,mx(n-m,n*m)));
	return 0;
}

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

int main(){
	long int i,j,N,K,A[200200];
	long int max_len=-1,max_index,ans;
	scanf("%ld%ld",&K,&N);
	
	for(i=0;i<N;i++){
		scanf("%ld",A+i);
		if(i>0){
			if (max_len<A[i]-A[i-1]){
				max_len = A[i]-A[i-1];
				max_index = i;
			}
		}
	}
	
	if(max_len < A[0]+K-A[N-1]){
		max_len = A[0]+K-A[N-1];
		max_index = 0;
	}
	
	printf("%ld\n",K-max_len);
 return 0;
 }

Measured memory_bytes: 1664
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7

n = ir()
ans = []
def solve(i,s,top):
    if i == n:
        ans.append(s)
    else:
        for k in range(top+1):
            solve(i+1,''.join([s,chr(ord('a')+k)]), max(k+1,top))

solve(1,'a',1)

ans.sort()
for num in ans:
    print(num)

Measured memory_bytes: 88804
a=1
b=1
l=[]
while(a!=0 or b!=0):
    a,b=map(int,input().split())
    l.append([a,b])
for i in range(len(l)):
    if l[i][0]>l[i][1]:
        print(l[i][1],l[i][0])
    elif l[i][0]==0 and l[i][1]==0:
        break
    else:
        print(l[i][0],l[i][1])


Measured memory_bytes: 6128
#include <iostream>
#include <vector>
#include <unordered_map>


using namespace std;
int main(void){
	
	int N,A,B;

	cin >> N >> A >> B;

	if (abs(B-A)%2==0){
		cout << "Alice" << endl;
	}else{
		cout << "Borys" << endl;
	}


	return 0;
}

Measured memory_bytes: 256
n = int(input())

a = input().split()

for i in range(n):
    a[i] = int(a[i])

s = 0
ans = 0
for i in range(n):
	s+=a[i]
for i in range(n):
	s -= a[i]
	ans += a[i]*s

print(ans % (1000000007))

Measured memory_bytes: 25036
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

lint N, cnt[10000001];
int main() {
	cin >> N;
	FOR(i, 1, N + 1) {
		lint curr = i;
		lint idx = 1;
		while (curr * idx <= N) {
			cnt[curr * idx]++;
			idx++;
		}
	}
	lint ans = 0;
	REP(i, N + 1) {
		ans += cnt[i] * i;
	}
	cout << ans;
}


Measured memory_bytes: 81652
#include <iostream>
#include <queue>

const int N = (1 << 21) * 21 + 7;

int hghbit[N];
int endbit(int x, int b) {
	return x ^ x >> b << b;
}
int dethghbit(int x) {
	return x ^ 1 << hghbit[x];
}

int n, k;
int cnt[N];
void addedge(int u, int v) {
	cnt[v] += cnt[u];
}

int main() {
	hghbit[0] = -1;
	for (int i = 1; i < 1 << 22; ++i)
		hghbit[i] = std::max(hghbit[i >> 1] + 1, i & 1 ? 0 : -1);

	scanf("%d%d", &n, &k);
	static char s[1 << 22 | 7];
	scanf("%s", s);
	for (int i = 1; i <= n; ++i) {
		scanf("%s", s);
		for (int j = 0; j < 1 << i; ++j)
			cnt[(1 << i | j) * (n + 1) + i] += s[j] ^ 48;
	}

	for (int i = n; ~i; --i)
		for (int j = 1 << i, k, l; j < 1 << n + 1; ++j) {
			int x = dethghbit(j) >> i, y = endbit(j, i), u, v;
			if (y)
				k = hghbit[y],
				u = x << 1 | 1, v = endbit(y, k),
				l = 1 << hghbit[j] - (i - k) + 1 | u << k | v,
				addedge(j * (n + 1) + i, l * (n + 1) + k);
			if (y ^ (1 << i) - 1)
				k = hghbit[y ^ (1 << i) - 1],
				u = x << 1, v = endbit(y, k),
				l = 1 << hghbit[j] - (i - k) + 1 | u << k | v,
				addedge(j * (n + 1) + i, l * (n + 1) + k);
			if (i)
				l = j >> i, k = 0,
				addedge(j * (n + 1) + i, l * (n + 1) + k);
		}

	int ans = 0, bit = 0;
	for (int i = 2, j; i < 1 << n + 1; ++i)
		if (cnt[i * (n + 1)] >= k && (j = hghbit[i]) > bit) ans = i, bit = j;
	if (ans)
		for (ans ^= 1 << bit; bit; --bit)
			if (ans >> bit - 1) printf("1"), ans ^= 1 << bit - 1;
			else printf("0");
	return 0;
}

Measured memory_bytes: 192896
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define N 100000000
#define pi M_PI

char H[N];

int getChar(char ch){
    if(ch=='A'){
        return 1;
    }else if(ch=='C'){
        return 2;
    } else if( ch == 'G') {
        return 3;
    } else if( ch == 'T') {
        return 4;
    }
    return 0;
}
int getKey( char str[] )
{
    int i;
    int key = 0, base = 1;
    for (i = 0 ; '\0' != str[i] ; i++ ) {
        key += base*( getChar( str[i] ) );
        base *= 5;
    }
    return key;
}

int find( char str[] )
{
    if( 1 == H[ getKey( str ) ] ) {
        return 1;
    } else {
        return 0;
    }
}

void insert( char str[] )
{
    H[ getKey( str ) ] = 1;
    return;
}

int main(){
  int i, n;
    char str[14], judge[9];

    scanf( "%d", &n );
    for (i = 0 ; i < n ; i++ ) {
        scanf( "%s %s", judge, str );
        if ( judge[0] == 'i' ){
            insert( str );
        } else {
            if( find( str ) ){
                printf("yes\n");
            } else {
                printf("no\n");
            }
        }
    }
    return 0;
}



Measured memory_bytes: 6904
#include<cstdio>
#include<algorithm>
using namespace std;

#define MAXN 100
int N;
int f[5][MAXN+5];

int main()
{
	scanf("%d",&N);
	for(int i=1;i<=2;i++)
		for(int j=1;j<=N;j++)
			scanf("%d",&f[i][j]);
	for(int i=1;i<=2;i++)
		for(int j=1;j<=N;j++)
			f[i][j]+=max(f[i-1][j],f[i][j-1]);
	printf("%d",f[2][N]);
	//getchar();
	//getchar();
}

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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

string IntToString(int number) {
    stringstream ss;
    ss << number;
    return ss.str();
}

int main(){
    int n;
    cin >> n;
    for(int p=0; p < n; p++){
        string s;
        cin >> s;
        string t;
        vector<int> v;
        for(int i=0; i< s.size(); i++){
            if(s[i] == '[' && s[i+1] == '[') t += "[";
            if('0' <= s[i] && s[i] <= '9'){
                if('0' <= s[i] && s[i] <= '9'){
                    string num;
                    while('0' <= s[i] && s[i] <= '9'){num.push_back(s[i]); i++;}
                    v.push_back(stoi(num));
                }
            }
            if(s[i] == ']' && s[i+1] == ']'){
                sort(v.begin(), v.end());
                int sum = 0;
                for(int j=0; j< v.size()/2+1; j++) sum += v[j]/2+1;
                if(v.size() != 0) t += IntToString(sum);
                t += + "]";
                v.clear();
            }
        }
        v.clear();
        while(true){
            string q;
            for(int i=0; i< t.size(); i++){
                if(t[i] == '[' && t[i+1] == '[') q += "[";
                if('0' <= t[i] && t[i] <= '9'){
                    string num;
                    while('0' <= t[i] && t[i] <= '9'){num.push_back(t[i]); i++;}
                    v.push_back(stoi(num));
                }
                if(t[i] == ']' && t[i+1] == ']'){
                    sort(v.begin(), v.end());
                    int sum = 0;
                    for(int j=0; j< v.size()/2+1; j++) sum += v[j];
                    if(v.size() != 0) q += IntToString(sum);
                    q += + "]";
                    v.clear();
                }
            }
            if(q.size() == 0){cout << t.substr(1, t.size()-2) << endl; break;}
            t = q;
        }
    }
}

Measured memory_bytes: 1304
while true
    n = gets.to_i
    break if n == 0
    jiro = gets.chomp.split.map(&:to_i)
    nokori, turn = 32, true
    while nokori > 0
        if turn
            nokori -= (nokori - 1) % 5
        else
            nokori = [nokori - jiro[0], 0].max
            jiro.rotate!(1)
        end
        turn = !turn
        puts nokori
    end
end


Measured memory_bytes: 6852
# python 3.8.2用
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
from math import gcd
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def lcm(a,b):return (a*b) // gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def lprint(l): print(*l, sep='\n')
def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N = input()

print('Yes' if N.count('7') > 0 else 'No')

Measured memory_bytes: 10484
import sys

N, T = map(int, sys.stdin.readline().rstrip().split())

As = []
As = list(map(int, sys.stdin.readline().rstrip().split()))

mins = []
m = 1e10
vs = []
for A in As:
    m = min(m, A)
    vs.append(A - m)
max_v = max(vs)
res = 0
for v in vs:
    if v == max_v:
        res += 1
print(res)



Measured memory_bytes: 14804
n, m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

a.sort()
b.sort()

k = n - 1
l = m - 1
ans = 1
are = 10 ** 9 + 7

a_del = 0
b_del = 0

for i in range(n*m):
#    print(a)
    if k >= 0 and l>=0:
      if n * m - i == a[k] and n * m - i == b[l]:
        a.pop()
        b.pop()
        a_del += 1
        b_del += 1
        k -= 1
        l -= 1
        
      elif n * m - i == a[k]:
        ans = (ans * b_del) % are
        a.pop()
        a_del += 1
        k -= 1 

       
      elif n * m - i == b[l]:
        ans = (ans * a_del) % are      
        b.pop()
        b_del += 1       
        l -= 1    

      else:
        ans = ans * (a_del * b_del - (i*1) ) % are

    elif k >= 0:
      if n * m - i == a[k]:
        ans = (ans * b_del) % are
        a.pop()
        a_del += 1
        k -= 1 

      else:
        ans = ans * (a_del * b_del - (i*1) ) % are


    elif l >= 0:
      if n * m - i == b[l]:
        ans = (ans * a_del) % are      
        b.pop()
        b_del += 1       
        l -= 1    
      else:
        ans = ans * (a_del * b_del - (i*1) ) % are

    else:
        ans = ans * (a_del * b_del - (i*1) ) % are    
        
print(ans)

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
 
long long X, Y, Z, K, A[1009], B[1009], C[1009];
vector<long long>vec;
 
int main() {
	cin >> X >> Y >> Z >> K;
	for (int i = 0; i < X; i++) cin >> A[i]; sort(A, A + X, greater<long long>());
	for (int i = 0; i < Y; i++) cin >> B[i]; sort(B, B + Y, greater<long long>());
	for (int i = 0; i < Z; i++) cin >> C[i]; sort(C, C + Z, greater<long long>());
	//i did everything same ,the one condition that was not clear int the question and i did wromg was
	//that i didnt checked for i*j*k to be less than or equal to k
	//this makes less case and no  runtime error i guess
	for (int i = 0; i < X; i++) {
		for (int j = 0; j < Y; j++) {
			for (int k = 0; k < Z; k++) {
				if ((i + 1) * (j + 1) * (k + 1) <= K) vec.push_back(A[i] + B[j] + C[k]);
				else break;
			}
		}
	}
	sort(vec.begin(), vec.end(), greater<long long>());
	for (int i = 0; i < K; i++) cout << vec[i] << endl;
	return 0;
}

Measured memory_bytes: 1400
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

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

	ll n, m;
	cin >> n >> m;
	vector<vll> v(m, vll(0));
	for (ll i = 0; i < n; i++) {
		ll a, b;
		cin >> a >> b;
		if (a <= m) v[m - a].push_back(b);
	}
	priority_queue<ll> pq;
	ll ans = 0;
	for (ll i = 0; i < m; i++) {
		for (ll j = 0; j < v[m - 1 - i].size(); j++) pq.push(v[m - 1 - i][j]);
		if (pq.size()) {
			ans += pq.top();
			pq.pop();
		}
	}
	cout << ans << endl;
}


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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}





void _main() {
        int n; cin >> n;
        int dp[2][n];
        for (int i = 0; i < 2; i++) {
                for (int j = 0; j < n; j++) {
                        cin >> dp[i][j];
                        dp[i][j] += max(i ? dp[i - 1][j] : 0, j ? dp[i][j - 1] : 0);
                }
        }


        cout << dp[1][n - 1];
}




signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const ll INF = 1LL << 60;

ll N;
vector<ll> C, S, F;

int main() {
    cin >> N;
    C.resize(N - 1);
    S.resize(N - 1);
    F.resize(N - 1);

    rep(i, N - 1) cin >> C[i] >> S[i] >> F[i];

    // シュミレーション
    rep(i, N - 1) {
        ll time = 0;

        // スタート地点
        time += S[i];
        time += C[i];

        // 移動
        for (int j = i + 1; j < N - 1; j++) {
            // 達してない場合はまつ
            if (time < S[j]) {
                time += S[j] - time;
            } else if (time % F[j] == 0) {
                // 何もしない
            } else{
                // 待ち時間がる場合はたす
                time += F[j] - (time % F[j]);
            }

            time += C[j];
        }

        cout << time << endl;
    }
    cout << 0 << endl;
}

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

int main(){
    string s;
    int k;
    cin >> s >> k;
    vector<string> v;
    for(int i=0;i<s.size();i++){
        for(int j=1;j<=s.size()-i;j++){
            if(j>5) break;
            v.push_back(s.substr(i,j));
        }
    }
    sort(v.begin(),v.end());
    int count = 1;
    int i=0;
    while(1){
        if(count == k){
            cout << v[i] << endl;
            break;
        }else{
            if(v[i]!=v[i+1])    count++;
        }
        i++;
    }
    return 0;
}

Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
int n;
long double a[1010];
long double ans=0;
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
		ans+=1/a[i];
	cout<<fixed<<setprecision(7)<<(long double)1/ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep2(i,m,n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;
template <typename T>
T sq(T x){
  return x * x;
}

signed main (){
  vector<string> s(3);
    rep(i,3){
  cin >> s.at(i);
cout << (char)(s[i].at(0) - 'a' + 'A');

  }
   cout << endl;
    return 0;
}


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

typedef long long ll;
const int N = 1033;
int n;
ll x[N], y[N];
void solve(ll &x, ll &y, ll d) {
  ll man = 1ll << 55;
  int t = 0;
  if (abs(x - d) + abs(y) < man) man = abs(x - d) + abs(y), t = 1;
  if (abs(x + d) + abs(y) < man) man = abs(x + d) + abs(y), t = 2;
  if (abs(x) + abs(y - d) < man) man = abs(x) + abs(y - d), t = 3;
  if (abs(x) + abs(y + d) < man) man = abs(x) + abs(y + d), t = 4;
  if (t == 1) putchar('R'), x -= d;
  if (t == 2) putchar('L'), x += d;
  if (t == 3) putchar('U'), y -= d;
  if (t == 4) putchar('D'), y += d;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld%lld", &x[i], &y[i]);
    if (abs(x[1] + y[1] + x[i] + y[i]) & 1) return puts("-1"), 0;
  }
  int d = !(abs(x[1] + y[1]) & 1);
  printf("%d\n", 31 + d);
  for (int i = 30; ~i; i--) {
    printf("%lld ", 1ll << i);
  }
  if (d) printf("1 ");
  puts("");
  for (int i = 1; i <= n; i++) {
    for (int j = 30; ~j; j--) {
      solve(x[i], y[i], 1ll << j);
    }
    if (d) solve(x[i], y[i], 1);
    puts("");
  }
}


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

using namespace std;
#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

inline void Input_Output () {
	//freopen(".in", "r", stdin);
   //freopen(".out", "w", stdout);
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n, m, v, p;
int a[N];
ll b[N];

bool check (int x) {
	if (a[p] > a[x] + m) return 0;
	ll now = m * (ll)v;
	now -= (p-1) * (ll)m;
	for (int i = 1; i <= n; i ++) {
		if (a[i] <= a[x])
			now -= m;
	}

   	for (int i = x; i >= p; i --) {
   		if (a[x] == a[i]) continue;
   		now -= a[x] + m - a[i];
   	}
     
	return now <= 0;
}

int main () {
   	SpeedForce;
   	cin >> n >> m >> v >> p;
	for (int i = 1; i <= n; i ++) {
		cin >> a[i];
	}
	sort(a + 1, a + n + 1, greater<int>());
	int l = p, r = n + 1;
	while(l < n && a[l] == a[l+1]) l++;

	//cout << check(5);
	//exit(0);

	while (r - l > 1) {
		int md = (l + r) >> 1;
		if (check(md)) l = md;
		else r = md;
	}

	cout << l << '\n';

    return Accepted;
}

// B...a

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...) 0
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    ll ans = 0;
    rep(i, 0, n) cin >> a[i];
    rep(i, 0, n) cin >> b[i];
    rep(i, 0, n) {
        if (a[i] != b[i] && a[i] <= 2 * b[i]) {
            cout << -1 << endl;
            return 0;
        }
    }
    set<int> tt;
    for (int x = 37; x > 0; x--) {
        vector<vector<ll>> cost(51, vector<ll>(51, -1));
        cost[0][0] = 0;
        rep(i, 1, 51) {
            cost[i][i] = 0;
            rep(j, 1, x) {
                if (cost[i][i % j] != -1) continue;
                cost[i][i % j] = 1LL << j;
            }
            for (int j : tt) {
                if (cost[i][i % j] != -1) continue;
                cost[i][i % j] = 1LL << j;
            }
        }
        rep(k, 0, 51) rep(i, 0, 51) rep(j, 0, 51) {
            if (cost[i][k] != -1 && cost[k][j] != -1) {
                if (cost[i][j] == -1) cost[i][j] = 1e18;
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
            }
        }
        ll tmp = 0;
        rep(i, 0, n) {
            if (cost[a[i]][b[i]] == -1) {
                tmp = 1LL << x;
            }
        }
        if (tmp) {
            ans += tmp;
            tt.insert(x);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>

using namespace std;

int main()
{
    int input[6];
    for (int ii=0; ii<6; ii++) {
        cin >> input[ii];
    }
    
    for (int ii = 0; ii <5; ii++) {
        for (int jj = ii+1; jj < 5; jj++) {
            if((input[jj] - input[ii]) > input[5]) { goto OVER_K;
            }
        }
    }
    
    printf("Yay!");
    return 0;

OVER_K:
    printf(":(");
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=1000000007;

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

Measured memory_bytes: 256
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());
    int ans = 1000000000;
    rep(i,n-k+1){
        ans = min(ans,(a[i+k-1]-a[i]));
    }
    cout << ans;


    return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M, K;
    cin >> N >> M >> K;
    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= M; j++) {
            int black = M * i + N * j - 2 * i * j;
            if (black == K) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import copy
n = int(input())
a = []
for i in range(n):
  s = int(input())
  a.append(s)
b = copy.copy(a)
a.sort(reverse=True)
c = b.index(a[0])
for j in b:
  if j == b[c]:
    print(a[1])
  else:
    print(a[0])

Measured memory_bytes: 19012
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define chmax(a, b) a = max(a, b);
#define chmin(a, b) a = min(a, b);
using namespace std;
using ll = long long;
using P = pair<int,int>;
using VI = vector<long long>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
using VVVVI = vector<VVVI>;

const ll INF = 1002003004005006007LL;

bool is_palin(string& s, int from, int to){
    for(; from < to; from++, to--) {
        if (s[from] != s[to]) return false;
    }
    return true;
}

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    vector<ll> c(n);
    rep(i, n) cin >> s[i] >> c[i];
    VVVI dp(n, VVI(22, VI(2, INF)));
    queue<tuple<int, int, bool, ll>> q;
    rep(si, n) {
        dp[si][0][0] = c[si];
        q.emplace(si, 0, 0, c[si]);
    }
    ll ans = INF;
    while(!q.empty()) {
        int si, i;
        bool t;
        ll cost;
        tie(si, i, t, cost) = q.front(); q.pop();
        if(dp[si][i][t] != cost) continue;
        if (t == 0) {
            if(is_palin(s[si], i, s[si].size()-1)) {
                chmin(ans, cost)
                continue;
            }
            rep(ri, n) {
                int i1 = i, i2 = s[ri].size()-1;
                bool ok = true;
                while(i1 < s[si].size() && i2 >= 0) {
                    if (s[si][i1] != s[ri][i2]) {
                        ok = false;
                        break;
                    }
                    i1++; i2--;
                }
                if (!ok) continue;
                ll nc = cost + c[ri];
                if (i1 < s[si].size()) {
                    if (nc < dp[si][i1][0]) {
                        dp[si][i1][0] = nc;
                        q.emplace(si, i1, 0, nc);
                    }
                } else if (i2 >= 0) {
                    if (nc < dp[ri][i2][1]) {
                        dp[ri][i2][1] = nc;
                        q.emplace(ri, i2, 1, nc);
                    }
                } else {
                    chmin(ans, nc);
                }
            }
        } else {
            if(is_palin(s[si], 0, i)) {
                chmin(ans, cost)
                continue;
            }
            rep(ri, n) {
                int i1 = i, i2 = 0;
                bool ok = true;
                while(i1 >= 0 && i2 < s[ri].size()) {
                    if (s[si][i1] != s[ri][i2]) {
                        ok = false;
                        break;
                    }
                    i1--; i2++;
                }
                if (!ok) continue;
                ll nc = cost + c[ri];
                if (i1 >= 0) {
                    if (nc < dp[si][i1][1]) {
                        dp[si][i1][1] = nc;
                        q.emplace(si, i1, 1, nc);
                    }
                } else if (i2 < s[ri].size()) {
                    if (nc < dp[ri][i2][0]) {
                        dp[ri][i2][0] = nc;
                        q.emplace(ri, i2, 0, nc);
                    }
                } else {
                    chmin(ans, nc);
                }
            }
        }
    }
    if (ans == INF) ans = -1;
    cout << ans << endl;
}


Measured memory_bytes: 3716
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

//ABC176C
int main(void) {
  long long n, k, i, cou=0, tmp;
  scanf("%lld", &n);
  long long a[n];
  for(i=0; i<n; i++)
    scanf("%lld", &a[i]);
  for(i=1; i<n; i++)
    if(a[i]<a[i-1]) cou+=a[i-1]-a[i], a[i]=a[i-1];

  printf("%lld", cou);
  return 0;
}

Measured memory_bytes: 3264
R,C,K=map(int,input().split())
rcv = [[0]*C for _ in range(R)]
for i in range(K):
    r,c,v = map(int,input().split())
    rcv[r-1][c-1]=v

dp = [[[0]*C for _ in range(R)] for _ in range(0,4)]

dp[1][0][0]=rcv[0][0]

#左端を縦に
j=0
for i in range(1,R):
    if rcv[i][j]==0:
        dp[0][i][j] = max(dp[r][i-1][j] for r in range(4))
    else:
        dp[0][i][j] = max(dp[r][i-1][j] for r in range(4))
        dp[1][i][j] = max(dp[r][i-1][j] for r in range(4))+rcv[i][j]

#上端を右に 
i=0
for j in range(1,C):
    if rcv[i][j]==0:
        for r in range(4):#左から引き継ぐだけ
            dp[r][i][j] = dp[r][i][j-1]
    else:
        dp[0][i][j] = dp[0][i][j-1]
        for r in range(1,4):
            dp[r][i][j] = max(dp[r][i][j-1] , dp[r-1][i][j-1]+rcv[i][j])

for i in range(1,R):
    for j in range(1,C):
        if rcv[i][j]==0:#左から引き継ぐか、上から引き継いでカウントキャンセル
            dp[0][i][j] = max(dp[0][i][j-1],
                              max(dp[r][i-1][j] for r in range(4) ) )
            for r in range(1,4):#左から引き継ぐだけ
                dp[r][i][j] = dp[r][i][j-1]
        else:
            dp[0][i][j] = max(dp[0][i][j-1],
                              max(dp[r][i-1][j] for r in range(4) ) )
            dp[1][i][j] = max(dp[1][i][j-1], dp[0][i][j-1]+rcv[i][j],
                              max(dp[r][i-1][j] for r in range(4) )+rcv[i][j] )
            for r in [2,3]:#左からのみ
                dp[r][i][j] = max(dp[r][i][j-1], dp[r-1][i][j-1]+rcv[i][j] )
print(max( dp[i][-1][-1] for i in range(4)) )

Measured memory_bytes: 430364
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define mp make_pair
#define all(v) v.begin(),v.end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

ll power(ll a, ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans*=a;
        a*=a;
        n>>=1;
    }
    return ans;
}

ld dp[301][301][301];
ll n;

ld f(ll a, ll b, ll c)
{
    if(a==0 && b==0 && c==0) return 0;
    if(dp[a][b][c]!=-1) return dp[a][b][c];
    ld x=a,y=b,z=c,ans=0;
    if(a>0) ans=ans+(x/(x+y+z))*f(a-1,b,c);
    if(b>0) ans=ans+(y/(x+y+z))*f(a+1,b-1,c);
    if(c>0) ans=ans+(z/(x+y+z))*f(a,b+1,c-1);
    ans=ans+n/(x+y+z);
    dp[a][b][c]=ans;
    return ans;
}

int main()
{
    IOS;
    repf(i,0,301) repf(j,0,301) repf(k,0,301) dp[i][j][k]=-1;
    cin>>n;
    ll a[3]={0};
    repf(i,0,n)
    {
        ll x;
        cin>>x;
        a[x-1]++;
    }
    cout<<fixed<<setprecision(10)<<f(a[0],a[1],a[2])<<endl;
    return 0;  
}

Measured memory_bytes: 426496
n, m, k = gets.split.map(&:to_i)
if k.zero? || n * m == k
  puts 'Yes'
  exit
end
(0..n).each do |i|
  (0..m).each do |j|
    num = m * i + n * j - i * j * 2
    if num == k
      puts 'Yes'
      exit
    end
  end
end
puts 'No'

Measured memory_bytes: 14392
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int x;
		int amari;
		x =N/10;
		amari=N-(10*x);
		if(amari==2||amari==4||amari==5||amari==7||amari==9) {
			System.out.println("hon");
		}else if(amari==3) {
			System.out.println("bon");
		}else {
			System.out.println("pon");
		}
	}

}


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

int main(void) {
	int i;
	char name[32];
	for(i = 0; i < 9; i++) {
		int am, pm;
		scanf(" %s %d %d", name, &am, &pm);
		printf("%s %d %d\n", name, am + pm, 200 * am + 300 * pm);
	}

	return 0;
}

Measured memory_bytes: 0
#include<iostream>

using namespace std;

int main () {
	int A, B, K;
	
	cin >> A >> B >> K;
	
	for(int i=0;i<K;i++){
		if(i%2 == 0){
			if(A % 2 == 0){
				B += A/2;
				A = A/2;
			}else{
				A = A - 1;
				B += A/2;
				A = A/2;
			}
		}else{
			if(B % 2 == 0){
				A += B/2;
				B = B/2;
			}else{
				B = B - 1;
				A += B/2;
				B = B/2;
			}
		}
	}
	
	cout << A << " " << B << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <set>
#include <math.h>
#define pai 3.14159265358979323846264338327950288;
#define keta(n) cout << fixed << setprecision((n));
using ll = long long;
int main()
{
  int n, x;
  cin >> n >> x;
  vector<int> m(n);
  int msum = 0, a = 1000;
  rep(i, n)
  {
    cin >> m[i];
    msum += m[i];
    a=min(a,m[i]);
  }
  cout << n + (x - msum) / a << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int X,A,B,C,s=0;cin>>A>>B>>C>>X;X/=50;
  for(int a=0;a<=A;a++)for(int b=0;b<=B;b++)for(int c=0;c<=C;c++){
    if(10*a+2*b+c==X)s++;
  }
  cout<<s<<endl;
}

Measured memory_bytes: 256
object Main{
  def main(args: Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val as = List.fill(n)(sc.nextInt)
    val s = as.sortBy(identity)

    val bit = new FenwichTree(n*2+2)

    def aux(x:Int): Boolean = {
      bit.init()
      val ys = as.map(a => if (a >= x) 1 else -1).scanLeft(0)(_+_).map(_+(n+1))
      var sum: Long = 0L
      ys.foreach({
        a => {
          sum += bit.get(a)
          bit.update(a)
        }
      })
      sum >= 1L*n*(n+1)/4
    }

    def solve(l:Int,r:Int): Int = {
      if (l == r) l
      else if (l+1 == r) {
        if (aux(s(r))) r
        else l
      }
      else {
        val m = (l+r)/2
        if (aux(s(m))) solve(m,r)
        else solve(l,m)
      }
    }
    println(s(solve(0,n-1)))
  }
}


class FenwichTree(val n: Int){
  private var tree: Array[Int] = Array.fill(n+1)(0) //1-index (1..n+1)

  def update(x: Int): Unit = {
    var i: Int = x
    while (i <= n){
      tree(i) = tree(i) + 1
      i += (i &  (-i))
    }
  }
  def get(x: Int): Int = {
    var i: Int = x
    var a: Int = 0
    while (i > 0){
      a += tree(i)
      i -= (i & (-i))
    }
    return a
  }
  def init(): Unit = {
    tree = Array.fill(n+1)(0)
  }
}


Measured memory_bytes: 129576
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int f[100010],w[101],v[101];
int main(){
	int n,W;
	scanf("%d%d",&n,&W);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&w[i],&v[i]);
	}
	memset(f,0x3f,sizeof(f));
	f[0]=0;
	for(int i=1;i<=n;i++){
		for(int j=100010;j>=v[i];j--){
			f[j]=min(f[j],f[j-v[i]]+w[i]);
		}
	}
	for(int j=100000;j>=0;j--)if(f[j]<=W){
		printf("%d",j);
		return 0;
	}
} 

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int nodes[2000][2000];
int vedges[2000][2000];
int hedges[2000][2000];

int main(){
	int N, M, Q;
	cin >> N >> M >> Q;
	int i, j;
	vector<string> S;
	for (i = 0; i < N; i++){
		string s;
		cin >> s;
		S.push_back(s);
	}
	//vector<vi> nodes;
	//vector<vi> vedges;
	//vector<vi> hedges;
	for (i = 0; i < N; i++){
		vi nodes_line;
		if (S[i][0] == '1'){
			nodes_line.push_back(1);
		}
		else{
			nodes_line.push_back(0);
		}
		for (j = 1; j < M; j++){
			if (S[i][j] == '1'){
				nodes_line.push_back(nodes_line[j - 1] + 1);
			}
			else{
				nodes_line.push_back(nodes_line[j - 1]);
			}
		}
		for (j = 0; j < M; j++){
			if (i == 0){
				nodes[i][j] = nodes_line[j];
			}
			else{
				nodes[i][j] = nodes[i - 1][j] + nodes_line[j];
			}
		}
	}

	for (i = 0; i < N; i++){
		vi vedges_line;
		vedges_line.push_back(0);
		for (j = 1; j < M; j++){
			if (S[i][j] == '1' && S[i][j - 1] == '1'){
				vedges_line.push_back(vedges_line[j - 1] + 1);
			}
			else{
				vedges_line.push_back(vedges_line[j - 1]);
			}
		}
		for (j = 0; j < M; j++){
			if (i == 0){
				vedges[i][j] = vedges_line[j];
			}
			else{
				vedges[i][j] = vedges[i - 1][j] + vedges_line[j];
			}
		}
	}

	for (j = 0; j < M; j++){
		vi hedges_line;
		hedges_line.push_back(0);
		for (i = 1; i < N; i++){
			if (S[i][j] == '1' && S[i - 1][j] == '1'){
				hedges_line.push_back(hedges_line[i - 1] + 1);
			}
			else{
				hedges_line.push_back(hedges_line[i - 1]);
			}
		}
		for (i = 0; i < N; i++){
			if (j == 0){
				hedges[i][j] = hedges_line[i];
			}
			else{
				hedges[i][j] = hedges[i][j - 1] + hedges_line[i];
			}
		}
	}

	for (i = 0; i < Q; i++){
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		x1--;
		y1--;
		x2--;
		y2--;
		int n_nodes;
		int n_vedges;
		int n_hedges;
		n_nodes = nodes[x2][y2];
		n_vedges = vedges[x2][y2];
		n_hedges = hedges[x2][y2];
		if (x1 >= 1){
			n_nodes -= nodes[x1 - 1][y2];
			n_vedges -= vedges[x1 - 1][y2];
			n_hedges -= hedges[x1][y2];
		}
		if (y1 >= 1){
			n_nodes -= nodes[x2][y1 - 1];
			n_vedges -= vedges[x2][y1];
			n_hedges -= hedges[x2][y1 - 1];
		}
		if (x1 >= 1 && y1 >= 1){
			n_nodes += nodes[x1 - 1][y1 - 1];
			n_vedges += vedges[x1 - 1][y1];
			n_hedges += hedges[x1][y1 - 1];
		}
		//cout << n_nodes << n_vedges << n_hedges << endl;
		cout << n_nodes - n_vedges - n_hedges << endl;
	}
	return 0;
}

Measured memory_bytes: 52864
A, B, N = map(int, input().split())
if B < A:
  B_t = A
  A = B
  B = B_t

divisors = []
divisors_A = []

for s in range(1, A+1):
  if A % s == 0:
    divisors_A.append(s)
    
for k in divisors_A:
  if B % k == 0:
    divisors.append(k)
    
divisors = divisors[::-1]
print(divisors[N-1])
    

Measured memory_bytes: 3060