akhauriyash/Code-Regression huggingface dataset:
def main():
    n,m = tuple([int(t)for t in input().split()])

    keys = []

    dp = [10**9]*(1<<n)
    dp[0] = 0
    for _ in range(m):
        a,_ = tuple([int(t)for t in input().split()])
        c = tuple([int(t)for t in input().split()])
        key = 0
        for c_i in c:
            key |= 1<<(c_i-1)
        keys.append((a,key))
    

    for a,key in keys:
        for i in range(1<<n):
            dp[i|key] = min(dp[i|key],dp[i]+a)

    if dp[-1]==10**9:
        print(-1)
    else:
        print(dp[-1])
if __name__ == "__main__":
    main()

Measured memory_bytes: 9260
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n,k;
	cin>>n>>k;
	vector<int> p(n);
	rep(i,n) cin>>p[i];
	sort(begin(p),end(p));
	int ans=0;
	rep(i,k) ans+=p[i];
	cout<<ans<<endl;
}

Measured memory_bytes: 3668
use std::cmp::min;
use std::io::stdin;

fn main() {
    let mut is = String::new();
    stdin().read_line(&mut is).ok();
    let mut itr = is.split_whitespace().map(|e| e.parse::<usize>().unwrap());
    let n: usize = itr.next().unwrap();
    let k: usize = min(itr.next().unwrap(), 100);
    is.clear();
    stdin().read_line(&mut is).ok();
    let mut a = is
        .split_whitespace()
        .map(|e| e.parse::<usize>().unwrap())
        .collect::<Vec<usize>>();

    for _ in 0..k {
        let mut b = vec![0usize; n + 1];
        for i in 0..n {
            let l = i.saturating_sub(a[i]);
            let r = min(i + a[i] + 1, n);
            b[l] = b[l].wrapping_add(1);
            b[r] = b[r].wrapping_add(!0);
        }
        a = vec![0; n];
        for i in 0..n {
            a[i] = a[if i > 0 { i - 1 } else { 0 }].wrapping_add(b[i]);
        }
    }

    let mut flg = false;
    for e in a {
        if flg {
            print!(" ");
        }
        print!("{}", e);
        flg = true;
    }
    println!();
}


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

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long int d,t,s;
    cin>>d>>t>>s;
    if(d<=(t*s)){
    	cout<<"Yes";
	}
	else{
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <cmath>
#include <math.h>
using namespace std;

int main() {
	long double N; cin >> N;
	long double odd = 0;
	for (int i = 1; i <= N; i++) {
		if (i % 2 != 0) odd++;
	}
	long double ans = odd / N;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int A,B,C;
    scanf("%d %d %d\n",&A,&B,&C);
    
    if(A==B && B!= C)
    {
        printf("Yes\n");
    }
    else if(B==C && B!= A)
    {
        printf("Yes\n");
    }
    else if(A==C && B!= A)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
}


Measured memory_bytes: 256
use proconio::{fastout, input};
use std::collections::BTreeMap;

#[fastout]
fn main() {
    input! {
        n: usize,
        k: i64,
        q: usize,
        a: [i64; q]
    };

    let a: Vec<i64> = a.iter().map(|x| x - 1).collect();
    let mut v: Vec<i64> = vec![k; n];
    let mut map = BTreeMap::new();

    for i in a.iter() {
        let count = map.entry(i.to_string()).or_insert(0);
        *count += 1;
    }

    for i in 0..n {
        let x = map.get(&i.to_string());
        if x == None {
            if k - q as i64 > 0 {
                println!("Yes")
            } else {
                println!("No")
            }
        } else {
            let value = x.unwrap();
            if k - (q as i64 - value) > 0 {
                println!("Yes")
            } else {
                println!("No")
            }
        }
    }
}


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

int N;
int x[10], y[10];

double dist(int i, int j) {
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    return pow(dx * dx + dy * dy, 0.5);
}

void solve() {
    cin >> N;
    for(int i = 1; i <= N; i++) cin >> x[i] >> y[i];
    double sum = 0.0;
    vector<int> v(N);
    for(int i = 0; i < N; i++) v[i] = i + 1;
    do {
        for(int i = 0; i < N - 1; i++) sum += dist(v[i], v[i+1]);
    } while(next_permutation(v.begin(), v.end()));
    int Factorial = 1;
    for(int i = 2; i <= N; i++) Factorial *= i;
    cout << fixed << setprecision(10) << sum / Factorial << endl;
    return;
}

int main() {
    solve();
    return 0;
}


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

int n,m,q;
vector<int> a,b,c,d;
int ans;

void dfs(vector<int> A){
    if (A.size()==n+1){
        int now = 0;
        for (int i=0; i<q; i++){
            if(A[b[i]]-A[a[i]]==c[i]) now += d[i];
        }
        ans = max(ans, now);
        return;
    }
    A.push_back(A.back());
    while (A.back()<=m){
        dfs(A);
        A.back()++;
    }
    
}

int main(){
    cin >> n >> m >> q;
    a=b=c=d=vector<int>(q);
    for (int i=0; i< q; i++){
        cin>> a[i] >> b[i] >> c[i] >> d[i];
    }
    dfs(vector<int>(1,1));
    cout << ans << endl;
    return 0;
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 2;
//template end



int main(){
    string s; cin>>s;
    if(s=="Sunny")printf("Cloudy");
    if(s=="Cloudy")printf("Rainy");
    if(s=="Rainy")printf("Sunny");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
int main()
{
    IOS
     // freopen("input.txt","r",stdin);
     // freopen("output.txt","w",stdout);
     // freopen("error.txt","w",stderr);
    string s,t;
    cin>>s>>t;
    ll n=s.size();
    ll cnt=0;
    for(ll i=0;i<n;i++)
    {
        if(s[i]!=t[i])
        {
            ++cnt;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 3808
n=int(input())
a,b=[None]*100000,[None]*100000
for i in range(100000):
    a[i]=[None]*2
    a[i][0]=0
    a[i][1]=i
    b[i]=[None]*2
    b[i][0]=0
    b[i][1]=i
l=list(map(int,input().split()))
for i in range(n//2):
    a[l[2*i]-1][0]+=1
    b[l[2*i+1]-1][0]+=1
a.sort(reverse=True)
b.sort(reverse=True)
if a[0][1]==b[0][1]:
    print(n-max(a[0][0]+b[1][0],a[1][0]+b[0][0]))
else:
    print(n-a[0][0]-b[0][0])

Measured memory_bytes: 38004
#include <stdio.h>
  int main(){
   int x[101]={};
int y[101]={};
    int n,i,j;
while(scanf("%d",&n) != EOF){
x[n]++;
}
for(i=0;i<101;i++){
for(j=0;j<101;j++){
if(x[i]<x[j]){
y[i]++;
}
}
}
for(i=0;i<101;i++){
if(y[i]==0)
printf("%d\n",i);
}
return 0;
}

Measured memory_bytes: 596
if __name__ == '__main__':
    a = [int(i) for i in input().split()]
    count = 0
    for i in range(1,a[0]+1):
        s = str(i)
        sumN = 0
        for j in s:
            sumN += int(j)

        if a[1] <= sumN and a[2] >= sumN:
            count+=i
    print(count)

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

#define ld long double
#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define vl vector<ll>
#define vvi vector< vector<int> >
#define vvl vector< vector<ll> >
#define repd(i, a, b) for (int i=(a);i<(b);i++)
#define rep(i, n) repd(i,0,n)
#define ALL(v) v.begin(), v.end()
#define INF 1e9

using namespace std;

/**
 * calculate GCD(greatest common divisor)
 * @param a
 * @param b
 * @return
 */
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

/**
 * change minimum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T>
inline bool changeMinimum(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * change maximum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T>
inline bool changeMaximum(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * output answer
 * @tparam T
 * @param answer
 * @return
 */
template<typename T>
T output(T answer) {
    cout << answer << endl;
    return 0;
}

/** ----from here ---------------------------------------------------------- */

int main() {
    string S;
    cin >> S;
    int ans = 0;
    if (S == "SAT") { ans = 1; }
    if (S == "FRI") { ans = 2; }
    if (S == "THU") { ans = 3; }
    if (S == "WED") { ans = 4; }
    if (S == "TUE") { ans = 5; }
    if (S == "MON") { ans = 6; }
    if (S == "SUN") { ans = 7; }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys

def main():
    N, A, B = list(map(int, sys.stdin.readline().rstrip().split()))
    count = int(N / (A + B))
    mod = N % (A + B)
    if mod > A:
        print((count * A) + A)
    else:
        print((count * A) + mod)

if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
n,m,b;char s[9],c[9];
main()
{
    for(;scanf("%d%d",&m,&n)*m;){
        int q[1024]={0},i,t,p=m;
        for(t=i=1;i<=n;i++){
            scanf("%s",s,*c=0);
            i%3||strcat(c,"Fizz");
            i%5||strcat(c,"Buzz");
            *c||sprintf(c,"%d",i);
            for(strcmp(s,c)&&p>1&&(q[t]=p--);q[t=t%m+1];);
        }
        for(t=i=1;i<=m;i++)q[i]||(t=!printf(" %d"+t,i));
        puts("");
    }
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define ALL(n) n.begin(),n.end()

int main() {
	string a;
	cin >> a;
	REP(i, a.size() - 1) {
		if (a[i] == 'A' && a[i + 1] == 'C') {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
 
    long long k;
    cin>>k;
    if(k%2 == 0 || k%5 == 0){
        cout<<"-1\n";
    }
    else{
        long long p = 7%k;
        int cnt = 1;
        while(p != 0){
            p = (p*10+7)%k;
            ++cnt;
        }
 
        cout<<cnt<<"\n";
    }
 
}

Measured memory_bytes: 3556
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int w = sc.nextInt();
        int h = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int r = sc.nextInt();
        
         if(w >= x + r && 0 <= x -r && h >= y + r && 0 <= y - r){
             System.out.println("Yes");
         }else{
             System.out.println("No");
         }
    }
}


Measured memory_bytes: 26348
#include <iostream>
#include <string>

int main()
{
	int A, B, sum = 0;
	std::cin >> A;
	std::cin >> B;

	for (int i = A; i <= B;i++) {
		std::string str = std::to_string(i);
		if (str[0] == str[4] &&str[1] == str[3]) {
			sum++;
		}
		
	}

	std::cout << sum << std::endl;

	return 0;
}

Measured memory_bytes: 256
#define n '   '
L[n],p;F[n],X[n];i;long D[n*4],Z[n*4],A[n],x;long f(a,k,l,r,b){return(Z[k]+=(b=a>l|-r<~i)?0:x)+(D[k]=l<=i&a<r&b?fmax(f(a,2*k,l,b),f(a,2*k+1,b=l+r>>1,r)):D[k]);}main(j){for(gets(L);~scanf("%d%d%ld",L+j,&p,A+j);F[p]=j++)X[j]=F[p];for(;p?:(p=F[++i],f(i,1,0,n),n/i);p=X[p])x=A[p],x=f(L[p],1,0,n);printf("%ld",x);}

Measured memory_bytes: 133248
#include <bits/stdc++.h>
using namespace std;
#define int long long

int N, T, A[200005], L[200005], C[35];

bool valid() {
	for (int i = 0; i < 20; i++)
		if (C[i] >= 2) return 0;
	return 1;
}

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N;
	for (int i = 1; i <= N; i++) cin >> A[i];
	for (int i = 1, l = 1; i <= N; i++) {
		for (int j = 0; j < 20; j++)
			if (A[i] & (1<<j)) C[j]++;
		while (l < i && !valid()) {
			for (int j = 0; j < 20; j++)
				if (A[l] & (1<<j)) C[j]--;
			l++;
		}
		T += (i - l + 1);
	}
	cout << T << '\n';
}


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

typedef long long ll;
const ll MOD = 1e9+7;
const int N = 2005;

ll n,k,fac[N],inv[N];

ll bpow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1LL)res*=a;
        a*=a;
        b>>=1LL;

        if(a>=MOD)a%=MOD;
        if(res>=MOD)res%=MOD;
    }

    return res;
}

void calc(){
    fac[0]=1LL;
    for(int i=1;i<=2000;i++){
        fac[i]=fac[i-1]*1LL*i%MOD;
    }

    for(int i=0;i<=2000;i++){
        inv[i]=bpow(fac[i],MOD-2);
    }
}

ll nCr(ll a,ll b){
    if(a<b||b<0)return 0;
    return fac[a]*inv[b]%MOD*inv[a-b]%MOD;
}

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

    cin>>n>>k;

    for(int i=1;i<=k;i++){
        cout<<nCr(k-1,i-1)*nCr(n-k+1,i)%MOD<<"\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
     
#define pll pair <long long,long long>
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define vll vector <ll>
#define NFS ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl '\n'
#define M 1000000007   
using namespace std;

void solve()
{
	int a,b;
	cin>>a>>b;
	cout<<a*b;
}
 
int main()
{
    NFS
 	int t=1;
 	//cin>>t;
 	while(t--)
 	{
 		solve();
 	}
    return 0;
}

Measured memory_bytes: 3652
"""
dp[i] := 足場iまでにかかるコストの最小値
i-k >= 0
i >= k
"""
N, K = map(int, input().split())
*h, = map(int, input().split())
INF = 10**4
dp = [INF for _ in range(N)]
dp[0] = 0
dp[1] = abs(h[0] - h[1])  # initialize dp


import numpy as np
dp = np.zeros(N, dtype=int)
h = np.array(h)
for i in range(1, N):
    start = max(0, i-K)
    dp[i] = min(dp[start:i] + np.abs(h[start:i] - h[i]))
print(dp[-1])


Measured memory_bytes: 17212
#include<iostream>
using namespace std;
int main(){
	int X;
	cin>>X;
	int maxn=1;
	for(int i=2;i<100;i++){
		int p=i*i;
		while(p<=X){
			maxn=max(maxn,p);
			p*=i;
		}
	}
	cout<<maxn<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
def I(): return int(sys.stdin.readline().rstrip())

N = I()
if N < 105:
    print(0)
elif N < 135:
    print(1)
elif N < 165:
    print(2)
elif N < 189:
    print(3)
elif N < 195:
    print(4)
else:
    print(5)

Measured memory_bytes: 61800
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

int main() {
	int n,Q;
	cin>>n>>Q;
	vector<long long> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];

	rep(j,Q){
		ll x;
		cin>>x;
		ll res=0;
		int right=0;
		ll sum=0;
		rep(left,n){
			while(right<n && sum+a[right]<=x){
				sum+=a[right];
				right++;
			}
			res+=(right-left);
			if(right==left) right++;
			else sum-=a[left];
		}

		cout<<res<<endl;
	}
	
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<int, int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second

int n,m;
vll g[100005];
int visited[100005];
int dp[100005];

void dfs(int curr){
	visited[curr]=1;
	
	int len=0;

	for(auto x:g[curr]){
		if(!visited[x])
			dfs(x);
		len=max(len, dp[x]);
	}

	dp[curr] = max(dp[curr], 1+len);
	return;
}
void solve(){
	
	cin>>n>>m;	
	rep(i,0,m){
		int u,v;
		cin>>u>>v;
		g[u].pb(v);
	}
	rep(i,i,n+1){
		if(!visited[i])
			dfs(i);
	}
	int ans=0;
	rep(i,1,n+1){
		ans=max(ans,dp[i]);
	}
	cout<<ans-1<<endl;

}
signed main(){
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    srand (static_cast <unsigned> (time(0)));
    int t=1;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 9344
#include <bits/stdc++.h>
using namespace std;
string mp[20],str;
int dir[256],h,w,m;
char ch[4]={'^','>','v','<'};
int dx[]={0,1,0,-1},dy[]={-1,0,1,0};

int get_d(char a){
  if(a=='U') return 0;
  if(a=='R') return 1;
  if(a=='D') return 2;
  if(a=='L') return 3;
  return -1;
}

void shoot(int x,int y,int d){
  while(1){
    x+=dx[d],y+=dy[d];
    if(x<0||y<0||x>=w||y>=h||mp[y][x]=='#')return;
    if(mp[y][x]=='*'){
      mp[y][x]='.';
      return;
    }
  }

}

void update(int x,int y,int d){
  mp[y][x]='.';
  for(int i=0;i<m;i++){
    int pd=d,nx,ny;
    d=get_d(str[i]);
    if(d==-1){d=pd,shoot(x,y,d);continue;}

    nx=x+dx[d],ny=y+dy[d];
    if(nx<0||ny<0||nx>=w||ny>=h||mp[ny][nx]!='.')nx=x,ny=y;
    y=ny,x=nx;
  }
  mp[y][x]=ch[d];
}

int main(){
  memset(dir,-1,sizeof(dir));
  dir['^']=0,dir['>']=1,dir['v']=2,dir['<']=3;

  int q;
  cin>>q;
  while(q--){
    cin>>h>>w;
    for(int i=0;i<h;i++) cin>>mp[i];
    cin>>m>> str;

    for(int i=0;i<h;i++){
      int f=0;
      for(int j=0;j<w;j++) 
	if(dir[mp[i][j]]!=-1) {
	  update(j,i,dir[mp[i][j]]);
	  f=1;
	  break;
	}
      if(f)break;
    }

    for(int i=0;i<h;i++)cout <<mp[i]<<endl;
    if(q) cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1200
//テンプレ
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)

int main() {
  int A,B,C,D,E;
  cin>>A>>B>>C>>D>>E;
  if(A==0){
    cout<<1<<endl;
  }
  if(B==0){
    cout<<2<<endl;
  }
  if(C==0){
    cout<<3<<endl;
  }
  if(D==0){
    cout<<4<<endl;
  }
  if(E==0){
    cout<<5<<endl;
  }
}

Measured memory_bytes: 3632
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let mut n: u32 = read();
    let a: u32 = read();

    while n >= 500 {
        n -= 500;
    }

    let ans = if n <= a { "Yes" } else { "No" };
    println!("{}", ans);
}


Measured memory_bytes: 4352
n,k = map(int,input().split())
a = list(map(int,input().split()))

li = [-1] * n
li[0] = 0
town = [0]
now = 0
flag = False

for i in range(k):
    now = a[now] - 1
    if li[now] != -1:
        s = li[now]
        break
    else:
        li[now] = i + 1
        town.append(now)
    if i == k-1:
        flag = True

if flag:
    print(now+1)
    exit()

town2 = town[s:]
m = len(town2)
l = len(town) - len(town2)

print(town2[(k - l) % m]+1)


Measured memory_bytes: 32380
#include <bits/stdc++.h>
 
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
//const ll mod =  1000000007;
//const ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvll = vector<vll>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------

int main(){
 string s;
 cin>>s;
 if(s=="ABC")cout<<"ARC"<<endl;
 else cout<<"ABC"<<endl;
}
   



Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>
#include <map>


using namespace std;
typedef long long ll;
ll N;

ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}

int main(){

    ll N;
    cin >> N;

    map<string, ll> mp;

    string ans = "Yes";
    char back;
    for(ll i = 0; i < N; i++){
        string s;
        cin >> s;
        if(mp[s] == 0){
            mp[s]++;
            if(i != 0 && s[0] != back){
                ans = "No";
            }else{
                back = s[s.size()-1];
            }
        }else{
                ans = "No";
        }

    }

    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int k; string s;
	while(cin >> k) {
		cin.ignore(); cin >> s;
		if(s.size() > k) {
			for(int i = 0; i < k; i++) 
				cout << s[i];
			cout << "..." << endl;
		} else cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <climits>
#include <queue>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
template<typename T1, typename T2>
inline void chmin(T1& a, T2 b){if (a > b) a = b;}
template<typename T1, typename T2>
inline void chmax(T1& a, T2 b){if (a < b) a = b;}
const long long INF = 1LL << 60;

//品物0個の状態から始めるので(N+1)行必要, 価値は最大N*max(v_i)より10^5+1必要
ll  dp[110][100010] = { 0 };
int MAXV = 100010;

int main()
{
	int N, W;
	cin >> N >> W;
	vector<int> w(N), v(N);
	rep(i, N) cin >> w[i] >> v[i];

	// 初期化
	rep(i, N + 1) {
		for(int j = 0; j < 100010; ++j) dp[i][j] = INF;
	}
	// 初期条件
	dp[0][0] = 0;

	rep(i, N) {
		for (int sumv = 0; sumv < 100010; sumv++) {
			//i番目の品物を選ぶ
			if (sumv - v[i] >= 0) {
				chmin(dp[i + 1][sumv], dp[i][sumv - v[i]] + w[i]);
			}else {
				// v[i] > sumv
				chmin(dp[i + 1][sumv], w[i]);
			}

			//i番目の品物を選ばない
			chmin(dp[i + 1][sumv], dp[i][sumv]);

			//if(sumv % 10 == 0 && sumv <= 200)cout << dp[i+1][sumv] << " ";
		}
		//cout << endl;
	}



	long long res = 0;
	for (int sumv = 0; sumv < 100010; ++sumv) {
		if (dp[N][sumv] <= W) res = sumv;
	}
	cout << res << endl;

}

Measured memory_bytes: 80128
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
tot = sum(B)
for i in range(n-1):
  if A[i+1] == A[i]+1:
    tot += C[A[i]-1]
print(tot)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;

int const MOD=int(1e9)+7;
int const MAXN=220000;
int N;
int C[MAXN];
ll f[MAXN];

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	cin>>N;
	rep(i,0,N) cin>>C[i];

	int n=1;
	rep(i,1,N) if (C[i]!=C[i-1]) C[n++]=C[i];
	C[n]=0;
// rep(i,0,n) cerr<<C[i]<<" ";
// cerr<<endl;

	f[C[0]]=1;
	rep(i,0,n) f[C[i+1]]=(f[C[i+1]]+f[C[i]])%MOD;
	cout<<f[0]<<"\n";
}


Measured memory_bytes: 2560
#include <stdio.h>

int main(){
    int tmp[30], buf;
    int i, w, n, a, b;

    for (i = 1; i <= 30; i++) tmp[i] = i;
    
    scanf("%d %d", &w, &n);
  
    for (i = 0; i < n; i++) {
        scanf("%d,%d",&a,&b);
        buf = tmp[a];
        tmp[a] = tmp[b];
        tmp[b] = buf;
    }
  
    for (i = 1; i <= w; i++) printf("%d\n", tmp[i]);
    
    return 0;
}


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

using namespace std;

int main()
{
	int i, j, k, s;

	printf("32025\n");
	printf("< 2 0 100\n");

	for(i = 1; i <= 30; i ++){
		printf("+ %d %d %d\n", 100 + i - 1, 100 + i - 1, 100 + i);
	}

	printf("+ 2 2 11\n");

	for(i = 30; i >= 0; i --){
		printf("+ 11 %d 12\n", 100 + i);
		printf("< 0 12 13\n");
		printf("+ 13 %d %d\n", 200 + i, 200 + i);
		printf("< 13 100 13\n");
		for(j = 0; j < i; j ++){
			printf("+ 13 13 13\n");
		}
		printf("+ 11 13 11\n");
	}

	printf("+ 2 2 11\n");

	for(i = 30; i >= 0; i --){
		printf("+ 11 %d 12\n", 100 + i);
		printf("< 1 12 13\n");
		printf("< 13 100 13\n");
		printf("+ 13 %d %d\n", 300 + i, 300 + i);
		for(j = 0; j < i; j ++){
			printf("+ 13 13 13\n");
		}
		printf("+ 11 13 11\n");
	}

	for(i = 0; i <= 30; i ++){
		for(j = 0; j <= 30; j ++){
			printf("< %d %d 11\n", 200 + i, 300 + j);
			for(k = 0; k < i + j; k ++){
				printf("+ 11 11 11\n");
			}
			printf("+ 2 11 2\n");
		}
	}

	return 0;
}

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

int main()
{
  string S;cin>>S;
  vector<int> a(S.size());
  for(int i=0;i<S.size();i++)a[i]=S[i]-'0';
  int ans=0;
  for(int i=0;i<S.size();i++)
  {
    ans+=abs(a[i]-i%2);
  }
  int mans=0;
  for(int i=0;i<S.size();i++)
  {
    mans+=abs(a[i]-(i+1)%2);
  }
  printf("%d\n",min(ans,mans));
}

Measured memory_bytes: 3908
#include<iostream>
using namespace std;
int main()
{
	int arr[101010];
	int k,n;
	int cnt = 0;
	cin >> n >> k;

	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}
	for (int i = 0; i < n; i++)
	{
		if (arr[i] >= k)
			cnt++;
	}
	cout << cnt;
	return 0;
}

Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
long long rec(long long a, long long b) {
	if (a > b) swap(a, b);
	if (a == 0) return -b;
	return b / a * 2 * a + rec(a, b % a);
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	long long n, x;
	cin >> n >> x;
	cout << n + rec(n - x, x) << endl;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    dp = [float('inf') for _ in range(n + 100)]
    dp[0] = 0

    for i in range(1, n + 1):
        dp[i] = min(dp[i - 1] + 1, dp[i])

        six = 6

        while six <= i:
            dp[i] = min(dp[i - six] + 1, dp[i])
            six *= 6

        nine = 9

        while nine <= i:
            dp[i] = min(dp[i - nine] + 1, dp[i])
            nine *= 9

    print(dp[n])


if __name__ == '__main__':
    main()


Measured memory_bytes: 77820
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		ArrayList<PriorityQueue<Integer>> lists = new ArrayList<>();
		for (int i = 0; i < n; i++) {
		    lists.add(new PriorityQueue<>());
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < m; i++) {
		    int type = sc.nextInt();
		    if (type == 0) {
		        lists.get(sc.nextInt()).add(-sc.nextInt());
		    } else if (type == 1) {
		        int idx = sc.nextInt();
		        if (lists.get(idx).size() > 0) {
		            sb.append(-lists.get(idx).peek()).append("\n");
		        }
		    } else {
		        int idx = sc.nextInt();
		        if (lists.get(idx).size() > 0) {
		            lists.get(idx).poll();
		        }
		    }
		}
		System.out.print(sb);
	}
}



Measured memory_bytes: 169780
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
    int x;
    cin >> x;
    
    int n500 = x / 500;
    int d = x - n500 * 500;
    int n5 = d / 5;
    
    int ans = n500 * 1000 + n5 * 5;
    cout << ans << endl;
    
    return 0;
}


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

int main(void){
 char a, b;
cin >> a;
cin >> b;
 cout << (((a=='D' ? 1 : 0)^(b=='D' ? 1 : 0)) ? 'D' : 'H') << endl;
 return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#include<deque>
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
const ll MOD = 1e9 + 7;
using namespace std;

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int a, b, c;
	cin >> a >> b;
	if ((a*b * 1) % 2 == 1) {
		cout << "Yes" << endl;
		return 0;
	}
	if ((a*b * 2) % 2 == 1) {
		cout << "Yes" << endl;
		return 0;
	}
	if ((a*b * 3) % 2 == 1) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    string s,x="2019/04/30";
    cin>>s;
    if(s<=x)
        cout<<"Heisei"<<endl;
    else
        cout<<"TBD"<<endl;

    return 0;
}


Measured memory_bytes: 3652
#include<stdio.h>
int main(void)
{
	int t;
	int i,sum,ave;
	sum=0;
	
	for(i=0;i<5;i++){
		scanf("%d",&t);
		if(t<40){
			t=40;
		}
		sum+=t;
	}
	ave=sum/5;
	printf("%d\n",ave);
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = 2005;
const ll mod = 1000000007;

int ncr[N][N];

void pre(){
	memset(ncr, 0, sizeof(ncr));
	for(int n = 0; n < N; n++){
		ncr[n][0] = 1;
		for(int r = 1; r <= n; r++){
			ncr[n][r] = ncr[n - 1][r] + ncr[n - 1][r - 1];
			if(ncr[n][r] >= mod)ncr[n][r] -= mod;
		}
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	pre();
	int n, k;
	cin>>n>>k;
	for(int i = 1; i <= k; i++){
		ll ans = ncr[k - 1][i - 1];
		ans *= ncr[n - k + 1][i];
		ans %= mod;
		cout<<ans<<'\n';
	}

	return 0;
}

Measured memory_bytes: 16000
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define all(a)                      a.begin(), a.end()
#define F							first
#define S							second
#define pb                          push_back
#define ll							long long
#define index(a)            		order_of_key(a)
#define value(a)					find_by_order(a)
#define count_1 					__builtin_popcount
#define mod(x, m)					((((x) % (m)) + (m)) % (m))
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

ll dp[11111][111][2];
string s;int d;

ll solve(int pos,int m,int t){
	if(pos==s.size())return m==0;
	
	ll& res = dp[pos][m][t];
	
	if(res!=-1)return res;
	res=0;
	
	int mx= (t==1?s[pos]-'0':9);
	
	for(int i=0;i<=mx;i++){
		int nt= (t&&(s[pos]-'0'==i))?1:0;
		res=(res+solve(pos+1,(m+i)%d,nt))%(1000000007);
	}
	return res;
}
int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout<<setprecision(12);
	memset(dp,-1,sizeof(dp));
	cin>>s>>d;
	cout<<((solve(0,0,1)-1+1000000007LL)%1000000007);
	return 0;
}

Measured memory_bytes: 20352
#include <bits/stdc++.h>
#define i64 long long
#define ui64 unsigned long long
using namespace std;
ui64 computeXOR(ui64 n){
	ui64 rem = n&(ui64)3;
	if(rem == 0) return n;
	if(rem == 1) return 1;
	if(rem == 2) return n+1;
	if(rem == 3) return 0;
}
ui64 rangeXOR(ui64 l, ui64 r){
	ui64 ans = 0LL;
	for(ui64 i=l;i<=r;i++) ans^=i;
	return ans;
}
int main() {
	// your code goes here
	/*for(ui64 A=0;A<=20;A++){
		for(int B=A+1;B<=20;B++){
			printf("XOR[%d,%d] = %llu, output = %llu\n",A,B,rangeXOR(A,B), computeXOR(B)^computeXOR(A-1));
		}
	}*/
	
	ui64 A,B;cin>>A>>B;
	ui64 ans = computeXOR(B);
	if(A>0) ans^=computeXOR(A-1);
	printf("%llu\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main(void){
	int A, B, K, count = 0;
	std::cin >> A >> B >> K;
	int d = std::min(A, B);
	while(count < K){
		if((A % d == 0) && (B % d == 0)){
			count++;
		}
		d--;
	}
	d++;
	std::cout << d;
	
	return 0;
}

Measured memory_bytes: 256
const main = input => {
  const [X, Y] = input.trim().split(' ')
  if (X > Y) {
    console.log('>')
  } else if (X < Y) {
    console.log('<')
  } else {
    console.log('=')
  }
}
// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"))


Measured memory_bytes: 29524
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int gcd(int a ,int b){
  if(a==0){
    return b;
  }else if(b==0){
    return a;
  }else if(a > b){
    return gcd(a%b, b);
  }else{
    return gcd(a, b%a);
  }
}
int main(){
   int N;
   cin >> N;
   int A[N];

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

   for(int i=0;i<N-1;i++){
      A[i+1] = gcd(A[i],A[i+1]);
   }

   cout << A[N-1] <<endl;


  return 0;
}

Measured memory_bytes: 640
import Data.List
import Data.Array
getInts = do
    x <- getLine
    let y = map (read::String->Int) (words x) 
    return y


change [] n = []
change s n = 
    if isPrefixOf "AC" s then 
        [n] ++ change (tail s) (n + 1)
    else 
        [n] ++ change (tail s) n

solve' x q = do
    [a,b] <- getInts
    print $ (x ! (b-1)) - (x ! (a-1))
    if q > 1 then solve' x (q-1)
    else return ()

solve s n q = 
    solve' (listArray (0,n) (change s 0)) q

main::IO()
main=do
    [n,q] <- getInts
    s <- getLine
    solve s n q


Measured memory_bytes: 8060
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    A = [list(map(int,input().split())) for _ in range(3) ]
    N = int(input())
    b = [int(input()) for i in range(N)]

    res = 'No'

    C = [[0 for i in range(3)] for j in range(3)]

    for i in range(N):
        for j in range(3):
            for k in range(3):
                if A[j][k] == b[i]:
                    C[j][k] = 1

    for i in range(3):
        if C[i] == [1,1,1]:
            res = 'Yes'

    for i in range(3):
        temp = []
        for j in range(3):
            if C[j][i] == 1:
                temp.append(1)
            else:
                temp.append(0)
        # temp = [C[0][i],C[1][i],C[2][i]]
        if temp == [1,1,1]:
            res = 'Yes'
            break

    temp1 = [C[0][0],C[1][1],C[2][2]]
    temp2 = [C[0][2],C[1][1],C[2][0]]

    if temp1 == [1,1,1]:
        res = 'Yes'
    if temp2 == [1,1,1]:
        res = 'Yes'

    print(res)



main()


Measured memory_bytes: 3192
#include <cstdio>
    #include <cstdlib>
    #include <algorithm>
    #include <vector>
    #include <cstring>
    #include <set>
    #include <stack>
    #include <cassert>
    #define SIZE 500005
     
    using namespace std;
     
    int A[SIZE];
    int pos[SIZE];
    int back[SIZE];
    int n,K;
     
    int main()
    {
    	scanf("%d %d",&n,&K);
    	for(int i=0;i<n;i++)
    	{
    		scanf("%d",&A[i]);
    		A[i]--;
    		pos[A[i]]=i;
    	}
    	memset(back,-1,sizeof(back));
    	set <int> st;
    	st.insert(n);
    	set <int>::iterator it,its;
    	for(int i=n-1;i>=0;i--)
    	{
    		it=st.lower_bound(pos[i]-K+1);
    		int v=*it;
    		back[pos[i]]=back[v];
    		back[v]=pos[i];
    		while(it!=st.end())
    		{
    			int f=*it;
    			if(f>pos[i]) break;
    			its=it;it++;
    			st.erase(its);
    		}
    		st.insert(pos[i]);
    	}
    	stack <int> ans;
    	int now=n;
    	for(int i=n-1;i>=0;i--)
    	{
    		now=back[now];
    		pos[i]=now;
    	}
    	for(int i=0;i<n;i++) A[pos[i]]=i;
    	for(int i=0;i<n;i++) printf("%d\n",A[i]+1);
    	return 0;
    }

Measured memory_bytes: 32896
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int main(){
    int w,h,n,x,y,a;cin>>w>>h>>n;
    vector<vector<int>> vec(h,vector<int>(w,0));
    for(int i=0;i<n;i++){
        cin>>x>>y>>a;
        if(a==1){
            for(int j=0;j<h;j++){
                for(int k=0;k<x;k++){
                    vec[j][k]=1;
                }
            }
        }
        else if(a==2){
            for(int j=0;j<h;j++){
                for(int k=x;k<w;k++){
                    vec[j][k]=1;
                }
            }
        }
        else if(a==3){
            for(int j=0;j<y;j++){
                for(int k=0;k<w;k++){
                    vec[j][k]=1;
                }
            }
        }
        else{
            for(int j=y;j<h;j++){
                for(int k=0;k<w;k++){
                    vec[j][k]=i;
                }
            }
        }
    }
    int ans=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(vec[i][j]==0)ans++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <cctype>/////////////////////////////////////
#include <memory>
class Parser{

private:
    
    typedef std::string::const_iterator State;
public:
    Parser(){

    }
    ~Parser(){}

    long long int parse(std::string o_s){
        std::string::const_iterator s=o_s.begin();


        return expression(s);
    }
    long long int num_or_brackets(State &b){
        long long int result=-1;
        if(*b=='('){
            b++;
            result=expression(b);
            if(*b==')'){
                b++;
            }else{
                std::cout << "括弧の対応が正しくありません" << std::endl;
            }
        }else if(isdigit(*b)){
            result=number(b);
        }else if(*b==')'){
            std::cout << "括弧の対応が正しくありません" << std::endl;
        }else{
            std::cout << "数式に数字，記号以外のものが含まれています: "<<*b << std::endl;
            return -1;
        }
        return result;
    }
    long long int number(State &b){
        long long int result = 0;
        while(isdigit(*b)){
            result *= 10;
            result += (long long int)(*b - '0');
            b++;
        }
        return result;
    }
    long long int term(State &b){
        long long int result=num_or_brackets(b);
        while(1){
            if(*b=='*'){
                b++;
                result *= num_or_brackets(b);

            }else if(*b=='/'){
                b++;
                result /= num_or_brackets(b);
            }else{
                break;
            }
        }
        //std::cout << result << std::endl;
        return result;
    }
    long long int expression(State &b){
        long long int result;
        if(*b=='-'){
            result = -term(b);
        }else{
            result = term(b);


        }
        while(*b!='\0'){
            if(*b=='+'){
                b++;
                result += term(b);
            }else if(*b=='-'){
                b++;
                result -= term(b);
            }else if(*b==')'||*b=='='){
                return result;
            }else{
                std::cout << "数式に数字，記号以外のものが含まれています: "<<*b << std::endl;
                return -1;
            }
        }
        return result;
    }



};


int main(){
    std::unique_ptr<Parser> parser(new(Parser));
    long long int n;
    std::cin >> n;
    std::string s;

    for (long long int i=0; i < n; i++)
    {

        std::cin >> s;
        std::cout<<parser->parse(s)<<std::endl;
    }
    return 0;
}



Measured memory_bytes: 3196
S = input()
N = len(S)

if N % 2:
	A = '01'*(N//2)+'0'
	#B = '10'*(N//2)+'1'
else:
	A = '01'*(N//2)
	#B = '10'*(N//2)

c1 = 0
c2 = 0
for s,a in zip(S,A):
	if s!=a:
		c1+=1
	else:
		c2+=1

print(min(c1,c2))



Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    string s; cin >> s;
    ll c = 0;
    for (int i = 1; i < s.size(); i++) {
        if (s[i] != s[i-1]) c++;
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 512
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int K = sc.nextInt();
 
      if(K%2==0){
    System.out.println(K/2*K/2);
      }else{
	System.out.println(K/2*(K+1)/2);
      }
      }
}


Measured memory_bytes: 22740
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    string s; cin >> s; string pair = "2019/04/30";
    if(s > pair)cout << "TBD" << endl; 
    else cout << "Heisei" << endl;
}

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,x,t = inpl()
print((n+x-1)//x*t)


Measured memory_bytes: 10372
#include <iostream>

using namespace std;

int main()
{
    int H,N,sum=0;
    cin>>H>>N;
    int A[N];
    for(int i=0;i<N;i++)
        cin>>A[i];
    for(int i=0;i<N;i++)
        sum=sum+A[i];
    if(sum>=H)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


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

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;
using P = pair<int, int>;

int main() {
    int n, d, x, ans = 0;
    cin >> n >> d >> x;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        for (int j = 1;; j += a) {
            if (j > d)
                break;
            ans++;
        }
    }
    cout << ans + x << endl;
    return 0;
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int N;
    cin >> N;
    vector<ll> A(N+1);
    rep(i,N){
        cin >> A[i];
    }
    ll ans=0;
    for(int i=0;i<60;i++){
        ll count=0;
        for(int j=0;j<N;j++){
            ll asd = A[j]>>i;
            if((asd&1) != 0){
                count++;
            }
        }
        ll tmp = count*(N-count);
        tmp %= MOD;
        //ans+=pow(2,i)*tmp;
        ll p = pow(2,i);
        p %= MOD;
        ans += (p * tmp);
        ans %= MOD;
    }    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
import java.util.Scanner;
import java.lang.Math;

class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		double m = (1 + Math.sqrt(1 + 8 * n)) / 2;
		int k = (int)m;
		if (k == m) {
			System.out.println("Yes");
			System.out.println(k);
			int[][] a = new int[k][k];
			for (int b = 0; b < k; b++)
				a[b][b] = 0;
			int i = 1;
			for (int c = 0; c < k; c++) {
				for (int d = c + 1; d < k; d++) {
					a[c][d] = i;
					a[d][c] = i;
					i = i + 1;
				}
			}
					
			for (int j = 0; j < k; j++ ) {
				System.out.print(k - 1);
				for (int e = 0; e < k; e++) {
					if (j != e)
						System.out.print(" " + a[j][e]);
				}
				System.out.println();
			}
		}
		else
			System.out.println("No");
		
	}
}

Measured memory_bytes: 46728
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let a: usize = read();
    let b: usize = read();
    let maxb = n - a + 1;
    let minb = (n + a - 1) / a;
    if b < minb || maxb < b {
        println!("{}", -1);
        return;
    }
    let mut m = n;
    let mut restb = b;
    let mut seq = Vec::<usize>::new();
    for i in m-a..m {
        seq.push(i);
    }
    restb -= 1;
    m -= a;
    while m > 0 {
        assert!(restb != 0);
        let usable = std::cmp::min(a, m - (restb - 1));
        for i in m-usable..m {
            seq.push(i);
        }
        restb -= 1;
        m -= usable;
    }
    for i in 0..n {
        if i != 0 { print!(" "); }
        print!("{}", seq[i] + 1);
    }
    println!("");
}

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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;
const ll MOD = 1000000007;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	double w, h, x, y;
	cin >> w >> h >> x >> y;

	double area = h * w / 2;
	int ans = h / 2 == y && w / 2 == x;
	printf("%.6lf %d\n ", area, ans);
	return 0;
}


Measured memory_bytes: 256
/******************************************************************************

                         بسم الله الرحمن الرحيم
                     Author: Mst: Mhamuda Khatun
                               RUCSE27

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

#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define pi 2*acos(0.0)
#define f first
#define s second
#define pb push_back
#define gap ' '
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define mod 1000000007
#define MAX 1000000000000
#define N 305

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

    cout<<c<<gap<<a<<gap<<b;

    cout<<"\n";
    return 0;   //:D
}




Measured memory_bytes: 3556