akhauriyash/Code-Regression huggingface dataset:
def c_welcome_to_atcoder():
    N, M = [int(i) for i in input().split()]
    Results = []
    for _ in range(M):
        p, s = input().split()
        Results.append((int(p), s))

    count_wa = [0] * (N + 1)
    is_already_ac = [False] * (N + 1)

    for p, s in Results:
        if is_already_ac[p]:
            continue

        if s == 'AC':
            is_already_ac[p] = True
        elif s == 'WA':
            count_wa[p] += 1

    ans_ac = 0
    ans_wa = 0
    for ac, wa in zip(is_already_ac, count_wa):
        if ac:
            ans_ac += 1
            ans_wa += wa
    return '{} {}'.format(ans_ac, ans_wa)

print(c_welcome_to_atcoder())

Measured memory_bytes: 20500
N,T=gets.split.map(&:to_i)
a= N.times.map{
 gets.split.map(&:to_i)  
  }.select{|x|
    x[1] <= T
    }
if a.size > 0
  p a.min_by{|x|x[0]}[0]
else
  puts "TLE"
end

Measured memory_bytes: 1788
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

s=input()
t=input()
ans=0
for i in range(len(s)):
    if s[i]!=t[i]:
        ans+=1
print(ans)

Measured memory_bytes: 73560
#include<bits/stdc++.h>
#define endl "\n"
#define ll long long
#define eb emplace_back
#define sz(x) ((int)(x).size())
#define mo 100000000
using namespace std;
//Conditional Operator (condition?true part:false part) eg : cout<<(y<=3?"YES":"NO")<<endl;
ll getmul(ll n){ll int k{0};while(n>0){k+=n%10;n=n/10;}return k;}//Sum OF n DIGITS
int main(){
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     int t;
     cin>>t;
     map<string,int>mp;
     while(t--){
        string s;
        cin>>s;
        mp[s]++;
     }
     string arr[4]={"AC","WA","TLE","RE"};
     for(int i=0;i<4;i++){
         if(mp.find(arr[i])!=mp.end()){
             cout<<arr[i]<<" x "<<mp[arr[i]]<<endl;
         }
         else
             cout<<arr[i]<<" x 0"<<endl;
     }
 return 0;    
}

Measured memory_bytes: 3580
def parse(i):
    l = input().strip().split()
    return ((i, l[0]), int(l[1]) * int(l[2]))


n = int(input())

while n:
    ss, d = [parse(_) for _ in range(n)], {}

    for s in ss:
        k = s[0][1]
        d[k] = (d[k][0], d[k][1] + s[1]) if k in d else s

    d = [v[0] for v in d.values() if v[1] >= 1000000]

    if d:
        print('\n'.join(k[1] for k in sorted(d)))
    else:
        print('NA')

    n = int(input())

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

using namespace std;

vector<vector<int>> edges(200005, vector<int>());
vector<int> points(200005);
vector<bool> visited(200005);
vector<int> ans(200005);

void visit(int n, int acc)
{
  if (visited[n]) return;
  visited[n] = true;
  ans[n] = acc + points[n];

  for (int i: edges[n]) {
    if (!visited[i]) {
      visit(i, ans[n]);
    }
  }
}

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

  for (int i = 0; i < N-1; i++) {
    int a, b;
    cin >> a >> b;
    edges[a - 1].push_back(b - 1);
    edges[b - 1].push_back(a - 1);
  }

  for (int i = 0; i < Q; i++) {
    int p, x;
    cin >> p >> x;
    points[p - 1] += x;
  }

  visit(0, 0);

  for (int i = 0; i < N; i++) {
    if (i < N - 1) {
      cout << ans[i] << " " << endl;
    } else {
      cout << ans[i] << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 24448
N = int(input())						# 5
A =        list( map(int, input().split()) )	# 1 2 3 4 5 ...

B=[]
i=0
for a in A:
	i+=1
	B.append([i,a])

C = sorted(B, key=lambda x:(x[1]))

for i,a in C:
	print(i, end=' ')

print()

Measured memory_bytes: 23384
#include <iostream>
#include <array>
#include <map>
#include <iomanip>
#include <vector>
#include <set>
#include <cctype>

#define repeat_range(i,a,b) for (int i=(a);i<(b);i++)
#define repeat(i,n) repeat_range(i,0,n)
typedef long long ll;

using namespace std;

template <typename T>
void puts(const T &v){
    cout << v << endl;
}

template <typename T>
void puts(const set<T> &v) {
    for(const auto &e: v) {
        puts(e);
    }
}

template <typename T>
void puts(const vector<T> &v) {
    for(const auto &e: v) {
        puts(e);
    }
}

// graph related algorithms


int main() {
    long N;
    cin >> N;
    vector<long> X;
    repeat(i, N) {
        int x;
        cin >> x;
        X.push_back(x);
    }
    
    vector<long> sorted = X;
    sort(sorted.begin(), sorted.end());
    
    // puts(X);
    
    long lesser_median = sorted[N/2 -1];
    long greater_median = sorted[N/2];
    
    if(lesser_median == greater_median) {
        repeat(i, N) {
            cout << lesser_median << endl;
        }
    } else {
        double the_median = (lesser_median + greater_median) / 2.0l;
        repeat(i, N) {
            if(X[i] < the_median) {
                cout << greater_median << endl;
            } else {
                cout << lesser_median << endl;
            }
        }
    }
}


Measured memory_bytes: 5488
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
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; }

// union by size + path having
class UnionFind {
public:

    //素集合の要素の親（木構造の根）を配列*3で保持している．初期状態では頂点間の辺は存在せず，孤立した状態のため，自分自身を根として初期化している（par: parent の略）．
    vector <ll> par;

    // 各集合（木）の大きさ．根をたどるとその木の大きさが返されるように実装されている．この配列を用意しておくとある頂点の連結成分の大きさを簡単に求められる
    vector <ll> siz;

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main(){
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    ll ans = 0;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        uf.merge(a, b);
    }
    rep2(i, 1, n) {
        if(!uf.issame(0, i)) {
            uf.merge(0, i);
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4780
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000007; 
int main()
{
  int N,M;
  cin >> N >> M;
  vector<int> oks(N+1,true);
  for(int i=0; i<M; i++){
    int a; cin >> a;
    oks.at(a)=false;
  }

  vector<long long int> dp(N+1);
  dp.at(0)=1;
  for(int now=0; now<N; now++){
    for(int next=now+1; next<=min(now+2,N); next++){
      if(oks.at(next)){
        dp.at(next)+=dp.at(now);
        dp.at(next)%=mod;
      }
    }
  }

  cout << dp.at(N) << endl;
}

Measured memory_bytes: 1408
def framod(n, mod, a=1):
    for i in range(1,n+1):
        a= (a * i) % mod
    return a

def power(n, r, mod):
    if r == 0: return 1
    if r%2 == 0:
        return power((n*n) % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod

def comb(n, k, mod):
  a=framod(n, mod)
  b=framod(k, mod)
  c=framod(n-k, mod)
  return (a * power(b, mod-2, mod) * power(c, mod-2, mod)) % mod


N,K = map(int, input().split())
mod = 10**9+7

for i in range(1,K+1):
  B = K
  R = (N-K)

  if ((B-1) < (i-1)):
    print(0)
  elif ((R+1) < i):
    print(0)
  else:
    print((comb(B-1, i-1, mod) * comb(R+1, i, mod)) % mod)


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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    vector<int> ans;
    int bar[1000][100];
    while(true){
        int N, M, a; cin >> N >> M >> a;
        if(N == 0) break;
        a--;
        for(int i = 0; i < 1000; i++){
            for(int j = 0; j < N; j++){
                bar[i][j] = j;
            }
        }
        rep(i, M){
            int h, p, q; cin >> h >> p >> q;
            p--; q--;
            bar[h][p] = q;
            bar[h][q] = p;        
        }
        for(int i = 999; i >= 1; i--){
            a = bar[i][a];
        }

        /*
        rep(i, M){
            rep(j, N){
                cout << bar[i][j] << " ";
            }
            cout << endl;
        }
        */
       ans.push_back(a+1);
    }
    rep(i, ans.size()) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 3468
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N; cin>>N;
    vector<int64_t> A(N);
    rep(n,0,N) cin>>A.at(n);

    sort(ToEnd(A));
    int64_t ansN=A.back(),ansM;
    auto itr=lower_bound(A.begin(),prev(A.end(),2), ansN/2.);
    ansM=*itr;

    itr--;
    if(ansM-ansN/2.>ansN/2.-*itr) ansM=*itr;

    cout<<ansN<<" "<<ansM<<endl;
}

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

int main(){
  int64_t n,a,b;
  cin >> n >> a >> b;
  int64_t result = 0;
  if((b-a)%2==0){
    cout << (b-a)/2<< endl;
  }else{
    if(n-b > a-1){
      int64_t k = a-1;
      b = b - (a-1);
      a = 1;
      result = k+1+(b-1-a)/2;
    }else{
      int64_t k = n-b;
      a = a + (n -b);
      b = n;
      result = k+1+(b-1-a)/2;
    }
      cout << result << endl;
  }

 
}

Measured memory_bytes: 256
def lcs(s,t):
    n=len(s)
    m=len(t)
    dp=[[0 for i in range(n+1)]for j in range(m+1)]
    st=""
    for i in range(m+1):
        for j in range(n+1):
            if(i==0 or j==0):
                dp[i][j]=0
            elif(t[i-1]==s[j-1]):
                dp[i][j]=max(1+dp[i-1][j-1],dp[i][j])
            elif(t[i-1]!=s[j-1]):
                dp[i][j]=max(dp[i-1][j],dp[i][j-1])
    # print(dp)
    x=dp[m][n]
    lcs=[""]*(x+1)
    lcs[x]=""
    i=m
    j=n
    tmp=x
    while(i>0 and j>0):
        if(t[i-1]==s[j-1]):
            lcs[x-1]=t[i-1]
            i-=1
            j-=1
            x-=1
        elif(dp[i-1][j]>=dp[i][j-1]):
            i-=1
        else:
            j-=1
    # print(lcs)
    for i in range(tmp+1):
        st=st+lcs[i]
    return st      


s=input()
t=input()
print(lcs(s,t))

Measured memory_bytes: 120028
#include<iostream>
#include<algorithm>
#include<vector>

int main()
{
    int n,x,mini=1000,ans=0;
    
    std::cin>>n>>x;

    int m[n];

    for(int i=0;i<n;i++){
        std::cin>>m[i];
        x-=m[i];
        if(m[i]<=mini)
            mini=m[i];
        ans++;
    }

    ans+=x/mini;

    std::cout<<ans<<'\n';

    return 0;

}


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

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;}
const long long INF=1LL << 60;

int main(){
    int N,Z,W;
    cin >> N >> Z >> W;
    vector<long long> V(N);
    for(int i=0;i<N;i++) cin >> V[i];

    vector<vector<long long> > DP(N+1,vector<long long>(2));//DP[i][j]:すでにi番目のカードまでを引いていて、if 先手 :j=0

    for(int i=N-1; i>=0;i--){
        //先手
        DP[i][0]= -INF;
        long long Y = (i ? V[i-1]: W);//後手の持っているカード i>0の時、i-1番目を取ったのは、後手だから
        chmax(DP[i][0],abs(Y- V[N-1]));//最大か
        
        for(int j=i+1;j<N;j++) chmax(DP[i][0],DP[j][1]);

        //後手番
        DP[i][1]= INF;
        long long X = (i ? V[i-1] :Z);
        chmin(DP[i][1], abs(X - V[N-1]));
        for(int j=i+1;j<N;j++) chmin(DP[i][1],DP[j][0]);
    }
    cout << DP[0][0] << endl;
}


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

int main() {
  int A,B;
  cin >> A >> B;
  int i=0;
  int t[5];
  while(A<=B){
    int tmp;
    tmp=A;
    t[4]=tmp%10;
    tmp/=10;
    t[3]=tmp%10;
    tmp/=10;
    t[2]=tmp%10;
    tmp/=10;
    t[1]=tmp%10;
    tmp/=10;
    t[0]=tmp%10;
    if(t[4]==t[0]&&t[3]==t[1]){
      i++;
    }
    A++;
  }
  cout << i <<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>

using namespace std;

int main(void){

	int H,W;

	while(1){
		cin>>H>>W;
		if(H==0&&W==0) break;
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				if((i+j)%2==0) cout<<"#";
				else cout<<".";
			}
			cout<<endl;
		}
		cout<<endl;
	}

	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using Graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

ll h,w,K;
void func(vector<int>& dst, vector<int>& src){
  for(int i = 0; i < w; ++i){
    dst[i] += src[i];
    if(dst[i]>K)dst[0]= -1;
  }
}
int main(){
  cin >> h >> w >> K;
  vector<string> a(h);
  for(int i = 0; i < h; ++i)cin >> a[i];
  Graph s(h,vector<int>(w) );
  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w; ++j){
      if(a[i][j]=='1')s[i][j]=1;
    }
  }
  ll ans = INF;
  for(int i = 0; i < (1LL<<(h-1)); ++i){
    bitset<10> bs (i);
    ll cnt = bs.count();
    if(cnt>ans)continue;
    ll sz = cnt +1;
    
    Graph vec(sz,vector<int>(w));
    ll now = 0;
    bool g = false;
    func(vec[now], s[0]);
    for(int j = 0; j < h-1; ++j){
      if(bs[j])++now;
      func(vec[now], s[j+1]);
      if(vec[now][0]==-1)g=true;
    }
    if(g)continue;
    vector<ll> tmp(sz);
    for(int j = 0; j < w; ++j){
      bool f = true;
      for(int k = 0; k < sz; ++k){
        tmp[k]+= vec[k][j];
        if(tmp[k]>K) f = false;
      }
      if(f)continue;
      ++cnt;
      for(int k = 0; k < sz; ++k){
        tmp[k]= vec[k][j];
      }
    }
    ans = min(ans,cnt);
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
#template
def inputlist(): return [int(j) for j in input().split()]
#template
#issueから始める
N = int(input())
def wa(N) : #kakuketanowa
    S = str(N)
    array = list(map(int,S))
    return sum(array)
ans = 10**9+7
for i in range(1,N):
    l = i
    r = N-i
    suma = wa(l) + wa(r)
    ans = min(ans,suma)
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
const int MAXN = 1005;
const int MAXV = MAXN*(MAXN-1)/2;
vector<int> E[MAXV];
int id[MAXN][MAXN];
 
int order[MAXN][MAXN - 1];

bool reached[MAXV];
bool finished[MAXV];
int dp[MAXV]; // max length of path from v
int dfs(int pos) {
	if (reached[pos]) {
		if (!finished[pos])return -1;
		return dp[pos];
	}
	dp[pos] = 0;
	reached[pos] = true;
	for (int i = 0; i < E[pos].size(); i++) {
		//cout <<"pos == " << pos <<  "to " << E[pos][i] << endl;
		int res = dfs(E[pos][i]);
		if (res == -1)return -1;
		dp[pos] = max(dp[pos], res + 1);
	}
	finished[pos] = true;
	return dp[pos];
}
 
int main() {
  int n;
  cin >> n;
  
  int V = 0;
  rep(i,n)rep(j,n) {
    if (i < j) {
      id[i][j] = V++;
    }else if(i > j){
      id[i][j] = id[j][i];
    }
  }
  rep(i,n) {
    rep(j,n-1) {
      cin >> order[i][j];
      order[i][j]--;
      order[i][j] = id[i][order[i][j]];
    }
  }
  
  rep(i,n) {
    
    rep(j,n-2) {
      E[order[i][j]].push_back(order[i][j + 1]);
    }
  }
  int ans = 0;
  rep(i,n) {
    rep(j,n){
      int res = dfs(order[i][j]);
      if (res == -1) {
        puts("-1");
        return 0;
      }
      ans = max(ans, res);
    }
  }
  cout << ans + 1 << endl;
  return 0;
}

Measured memory_bytes: 38528
import sys

lec=0
loz=0
while True:
  line = sys.stdin.readline()
  if not line: break
  l = line.rstrip().split(",")
  a = int(l[0])
  b = int(l[1])
  c = int(l[2])
  if a*a+b*b == c*c:
    lec += 1
  elif a == b:
    loz += 1

print lec
print loz

Measured memory_bytes: 6276
'use strict';
process.stdin.on('data', function(chunk) {
    var inputs = chunk.toString().trim().split(' ');
    var a = Number(inputs[0]);
    var b = Number(inputs[1]);
    if (a < b) {
        console.log('a < b');
    } else if (a > b) {
        console.log('a > b');
    } else {
        console.log('a == b');
    }
});
process.stdin.resume();
process.stdin.setEncoding('utf8');

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

const int N = 1005;

int n;
int a[N];
long long mx[2];
vector<int> vec[2];
vector<int> vres;

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

	cin >> n;

	for (int i = 1; i <= n; ++i) cin >> a[i];

	int maxpos = 1;
	for (int i = 1; i <= n; ++i) if (a[i] > a[maxpos]) maxpos = i;

	if (a[maxpos] < 0) {
		printf("%d\n", a[maxpos]);
		printf("%d\n", n - 1);
		for (int i = 1; i < maxpos; ++i) printf("1\n");
		for (int i = n - maxpos + 1; i >= 2; --i) printf("%d\n", i);
		return 0;
	}

	for (int i = 1; i <= n; ++i) {
		if (a[i] > 0) mx[i % 2] += a[i], vec[i % 2].push_back(i);
	}

	int maxmod = 0;
	if (mx[0] < mx[1]) maxmod = 1;

	printf("%lld\n", mx[maxmod]);

	vector<int> cur = vec[maxmod];

	while(cur.size() > 1) {
		if (cur[0] != 1) {
			vres.push_back(1);
			for (int &u : cur) --u;
			--n;
		}
		else {
			while(cur[1] - cur[0] != 2) {
				vres.push_back(3);
				for (int i = 1; i < cur.size(); ++i) cur[i] -= 2;
				n -= 2;
			}
			vres.push_back(2);
			cur.erase(cur.begin());
			for (int &u : cur) u -= 2;
			n -= 2;
		}
	}

	for (int i = n; i >= 2; --i) vres.push_back(i);

	printf("%d\n", vres.size());
	for (int &u : vres) printf("%d\n", u);
}

Measured memory_bytes: 256
/*
     Author:Raghav Bansal
     IIIT Una
                  */
#include <bits/stdc++.h>
#define int long long int
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define BOLT ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define X first
#define Y second
#define endl "\n"
using namespace std;
void solve() {
	string s;
	cin >> s;
	const int n = s.size();
	map<int, int> hash;
	const int p = 2019;
	hash[0]++;
	int ans = 0;
	int pwr = 1;
	int suffix = 0;
	for (int i = n - 1; ~i; i--) {
		suffix = suffix + (s[i] - '0') * pwr;
		if (suffix >= p )
			suffix %= p;
		ans += hash[suffix];
		hash[suffix]++;
		pwr = pwr * 10 % p;
	}
	cout << ans << endl;
}
int32_t main() {
	BOLT;
	solve();
}

Measured memory_bytes: 3652
import sys
sys.setrecursionlimit(100010)

n,u,v = [int(i)-1 for i in input().split()]
n+=1
AB = [[int(i)-1 for i in input().split()] for _ in range(n-1)]

nodes = [[] for _ in range(n)]
for ab in AB:
    nodes[ab[1]].append(ab[0])
    nodes[ab[0]].append(ab[1])

route = []
def search(p,before=-1):
    if len(nodes[p])==1 and p!=u:
        return False
    for node in nodes[p]:
        if node == before:
            continue
        if search(node,p) or node==v:
            route.append(p)
            return True
    return False
search(u)
route.reverse()
key = route[(len(route)-1)//2]
if len(route) == 1:
    nodes[key].remove(v)
else:
    nodes[key].remove(route[(len(route)-1)//2+1])

que = [key]
time = -1
while len(que)>0:
    time+=1
    newque = []
    while len(que)>0:
        p = que.pop()
        for q in nodes[p]:
            nodes[q].remove(p)
            newque.append(q)
    que=newque

tokey = len(route)//2+1
if time == 0:
    tokey -= 1

time = max(1,time)
print( tokey + time-1 )

Measured memory_bytes: 111868
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]

d = [(-1, 0), (1, 0), (0, -1), (0, 1)]

for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            continue

        flag = False
        for dx, dy in d:
            i2, j2 = i+dx, j+dy
            if not (0 <= i2 < H and 0 <= j2 < W):
                continue

            if S[i2][j2] == "#":
                flag = True

        if not flag:
            print("No")
            exit()
print("Yes")


Measured memory_bytes: 3064
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
a = li()

flag = True
for i in range(n):
    if (a[i] % 2) == 0:
        if (a[i]%3) != 0 and (a[i]%5) !=0:
            flag = False
if flag:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

ll n,a,b;
vector<ll> h(100010);

bool solve(ll x){
  ll cnt=0;
  rep(i,n){
    ll t=h[i]-b*x;
    if(t<=0) continue;
    if(t%(a-b)==0){
      cnt+=t/(a-b);
    }else{
      cnt+=t/(a-b)+1;
    }
  }
  return cnt<=x;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n>>a>>b;
  rep(i,n) cin>>h[i];
  ll high=1e10,low=0,mid;
  while(high-low>1){
    mid=(high+low)/2;
    if(solve(mid)) high=mid;
    else low=mid;
  }
  cout<<high<<endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  
  int W[10],K[10],score_sum1,score_sum2;
  
  for(int i=0 ; i < 10 ; i++)cin >>W[i];
  for(int i=0 ; i < 10 ; i++)cin >>K[i];
  
  sort(W,W+10);
  sort(K,K+10);
  
  score_sum1=W[9]+W[8]+W[7];
  score_sum2=K[9]+K[8]+K[7];
  
  cout <<score_sum1<<" "<<score_sum2<<endl;
  
  return 0;
}

Measured memory_bytes: 1180
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

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

#define REP(i, n) for(ll i = 0; i < n; i++)





int n;
vector<vector<vector<double>>> dp;

double f(int c1, int c2, int c3){
    if(c1 == 0 && c2 == 0 && c3 == 0) return 0.0;
    if(dp[c1][c2][c3]) return dp[c1][c2][c3];
    
    double res = 0.0, sum = c1 + c2 + c3;
    if(c1) res += f(c1 - 1, c2, c3) * (c1 / sum);
    if(c2) res += f(c1 + 1, c2 - 1, c3) * (c2 / sum);
    if(c3) res += f(c1, c2 + 1, c3 - 1) * (c3 / sum);
    res += (double)n / sum;
    return dp[c1][c2][c3] = res;
}

int main() {
    cin >> n;
    int c[3] = {};
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        c[a - 1]++;
    }
    dp.resize(n + 1, vector<vector<double>>(n + 1, vector<double>(n + 1)));
    printf("%.12lf\n", f(c[0], c[1], c[2]));
}

Measured memory_bytes: 216960
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use feature qw/say/;

my ($H, $W, $N) = split(/ /, <STDIN>);
my %counts;
for (1..$N) {
    my ($i, $j) = split(/ /, <STDIN>);
    --$i;
    --$j;
    for my $di (-1..1) {
        for my $dj (-1..1) {
            my ($ci, $cj) = ($i + $di, $j + $dj);
            next if $ci - 1 < 0 || $ci + 1 >= $H;
            next if $cj - 1 < 0 || $cj + 1 >= $W;
            ++$counts{"$ci:$cj"};
        }
    }
}


my @ret = (0) x 10;
++$ret[$_] for values %counts;
my $sum = 0;
$ret[0] = ($H - 2) * ($W - 2) - scalar(keys(%counts));
say $_ for @ret;

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define REPRl(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < (int)n; i++)
#define FORl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define ALL(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
ll fibonacci(ll n){
  if(n==0){
    return 0;
  }else if(n==1){
    return 1;
  }else{
    return fibonacci(n-1)+fibonacci(n-2);
  }
}

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

  REP(i,b.size()){
    if(b[i]=='A'){
      b[i]='T';
    }else if(b[i]=='T'){
      b[i]='A';
    }else if(b[i]=='C'){
      b[i]='G';
    }else{
      b[i]='C';
    }
  }
  cout << b << endl;
}

Measured memory_bytes: 256
d,g = map(int,input().split())
a = list(list(map(int, input().split())) for x in range(d))

minmin = 100000

for i in range(0,2**d):
    f = [True]
    min = 0
    sum = 0
    binary = format(i, 'b')
    binary = binary[::-1]
    # binary
    list2=[i for i, x in enumerate(binary) if x == '1']
    # print(list2)
    for i in range(len(list2)):
        sum+=a[list2[i]][0]*100*(list2[i]+1)+a[list2[i]][1]
        min += a[list2[i]][0]
    if (sum<g) and (len(list2)<d):
        # print("ぽうぽう")
        d2 = d-1
        while (1):
            # print("ぽうぽう1")
            if len(list2)==0:
                break
            if d2 in list2:
                d2 = d2-1
                continue
            else:
                break
        l = 0 
        while(sum<g):
            if l >= a[d2][0]:
                f[0]=False
                break
            # print("ぽうぽう2")
            min +=1
            sum += 100*(d2+1)
            l += 1
        if sum<g:
            f[0]=False
    if (f[0]==True)and(min < minmin):
        minmin = min
        # print(min,sum)
    


print(minmin)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;

namespace ABC158C
{
    class Program
    {
        static void Main(string[] args)
        {
            var A = RInt;
            var B = RInt;

            int ans = -1;
            for (int i = 1; i <= 10000; i++)
            {
                if ((int)(i * 0.08) == A && (int)(i * 0.1) == B) { ans = i; break; }
            }

            Console.WriteLine(ans);
        }


    }


}

namespace Assistant
{
    static class Input
    {
        static List<string> line = new List<string>();
        static int index = 0;
        static String RNext()
        {
            if (line.Count <= index) line.AddRange(Console.ReadLine().Split());
            return line[index++];
        }
        public static int RInt => int.Parse(RNext());
        public static long RLong => long.Parse(RNext());
        public static int[] RInts => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] RLongs => Console.ReadLine().Split().Select(long.Parse).ToArray();
        public static string RString => RNext();
        //以下未テスト
        public static int[] RIntsC(int c) => Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray();
        public static long[] RLongsC(int c) => Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray();
        public static char[][] RMap(int h) => Enumerable.Repeat(0, h).Select(x => Console.ReadLine().ToCharArray()).ToArray();
    }

    static class Debug
    {
        static public void Draw2D<T>(T[,] map, int mode = 1)
        {
#if DEBUG
            int W = map.GetLength(0);
            int H = map.GetLength(1);

            string[,] map2 = new string[W + 1, H + 1];
            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (i == 0 && j == 0) map2[i, j] = 0.ToString();
                    else if (i == 0) map2[i, j] = (j - 1).ToString();
                    else if (j == 0) map2[i, j] = (i - 1).ToString();
                    else map2[i, j] = map[i - 1, j - 1].ToString();
                }
            }

            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (mode == 0) Console.Write(map2[i, j].Last());
                    if (mode == 1) Console.Write(map2[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
#endif
        }

        public static void Draw1D<T>(T[] array, int mode = 0)
        {
#if DEBUG
            Console.WriteLine(string.Join(" ", array));
#endif
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<string>
#include<set>
#include<map>
#include<bitset>
#define UP(i,l,h) for(int i=l;i<h;i++)
#define DOWN(i,h,l) for(int i=h-1;i>=l;i--)
#define W(a) while(a)
#define INF 0x3f3f3f3f
#define LL long long
#define MAXN 8200
#define EPS 1e-10
#define MOD 100000000

using namespace std;

int main(){
    int n;
    scanf("%d",&n);
    int x=1;
    W(x<=n){
        x*=2;
    }
    printf("%d\n",x/2);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<ll> Size;
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1);
        for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        Size[x] += Size[y];
        return true;
    }

    ll size(int x){
        return Size[root(x)];
    }
};


string S[55];
int field[55][55];
int dh[4] = {-1, 1, 0, 0};
int dw[4] = {0, 0, 1, -1};
int H, W;
void dfs(int nowh, int noww, int bit) {
    for(int k = 0; k < 4; k++) {
        int newh = nowh + dh[k];
        int neww = noww + dw[k];
        if(newh < 1 || newh > H || neww < 1 || neww > W) continue;
        if(field[newh][neww] < 0) continue;
        if(field[newh][neww] & (1 << bit)) continue;
        field[newh][neww] |= (1 << bit);
        dfs(newh, neww, bit);
    }
}

int main() {
    //cout.precision(10);
    while(true) {
        cin >> W >> H;
        if(H == 0) break;
        //cerr << H << " " << W << endl;
        for(int h = 1; h <= H; h++) {
            cin >> S[h];
            S[h] = "#" + S[h];
            for(int w = 1; w <= W; w++) {
                if(S[h][w] == '.') field[h][w] = 0;
                if(S[h][w] == 'B') field[h][w] = -1;
                if(S[h][w] == 'W') field[h][w] = -2;
            }
        }
        for(int h = 1; h <= H; h++) {
            for(int w = 1; w <= W; w++) {
                if(S[h][w] == 'B') dfs(h, w, 0);
                if(S[h][w] == 'W') dfs(h, w, 1);
            }
        }
        int ansb = 0;
        int answ = 0;
        for(int h = 1; h <= H; h++) {
            for(int w = 1; w <= W; w++) {
                if(field[h][w] == 1) ansb++;
                if(field[h][w] == 2) answ++;
            }
        }
        cout << ansb << " " << answ << endl;
    }
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    if(N%1000!=0){
        cout << 1000-(N%1000) << "\n";
    }else{
        cout << 0 << "\n";
    }
}

Measured memory_bytes: 3620
// ! キュー

#include <stdio.h>
#define LEN 100005
typedef struct pp {
  char name[100];
  int t;
} P;
P Q[LEN];
int tail, head;
void enqueue(P u) {
  Q[head] = u;
  head = (head + 1) % LEN;
}

P dequeue() {
  P x = Q[tail];
  tail = (tail + 1) % LEN;
  return x;
}

int min(int a, int b) { return a < b ? a : b; }

int main() {
  int n, q, c;
  int time = 0;
  scanf("%d %d", &n, &q);
  for (int i = 1; i <= n; i++) {
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  tail = 1;
  head = n + 1;
  // whileの条件式が < だった場合，%
  // LENの計算でインデックスが1周してheadが小さくなったら抜けてしまうからwrong
  // answerになる
  while (tail != head) {
    P x = dequeue();
    c = min(x.t, q);  // x.t=50, q=100 c=50 x.t-c=0, x.t=100 q=50 c=50 x.t-c=50
                      // x.tが0より大きいかで判定
    x.t -= c;
    time += c;  // x.t <= q だった場合，cは処理が終えた時間, x.t > q
                // だった場合，cはq
    if (x.t > 0) {
      enqueue(x);
    } else {
      printf("%s %d\n", x.name, time);
    }
  }
  return 0;
}


Measured memory_bytes: 12756
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, m;
  cin >> n >> m;
  vector<P> p(n);
  rep(i, n) cin >> p[i].first >> p[i].second;
  sort(all(p));
  ll ans = 0;
  rep(i, n) {
    ll y = p[i].first;
    ll c = p[i].second;
    if(m <= c) {
      ans += y * m;
      break;
    } else {
      m -= c;
      ans += y * c;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const double PI=acos(-1);
int n;
pii p[110];
int main() {
	int i,j;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d%d",&p[i].fi,&p[i].se);
	for(i=1;i<=n;i++) {
		vector<pair<double,int> > v;
		for(j=1;j<=n;j++) {
			if(i==j) continue;
			int dx=p[j].se-p[i].se;
			int dy=-(p[j].fi-p[i].fi);
			if(dy<0) {
				v.push_back({0,1});
				v.push_back({PI+atan2(dy,dx),-1});
				v.push_back({2*PI+atan2(dy,dx),1});
				v.push_back({2*PI,-1});
			} else {
				v.push_back({atan2(dy,dx),1});
				v.push_back({PI+atan2(dy,dx),-1});
			}
		}
		sort(all(v));
		double sum=0; int cnt=0;
		for(j=0;j<sz(v);j++) {
			if(cnt) sum+=v[j].fi-v[j-1].fi;
			cnt+=v[j].se;
		}
		printf("%.10f\n",1-sum/(2*PI));
	}
	return 0;
}

Measured memory_bytes: 384
#!/usr/bin/env python3
import sys

sys.setrecursionlimit(300000)

def dfs(idx, visited, conn, d, cur):
    visited[idx] = True
    for nex in conn[idx]:
        if not visited[nex[0]]:
            d[nex[0]] = cur + nex[1]
            d = dfs(nex[0], visited, conn, d, cur + nex[1])
    return d


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]", Q: int, K: int, x: "List[int]", y: "List[int]"):

    conn = [[] for _ in range(N)]
    for j in range(N - 1):
        a = A[j] - 1
        b = B[j] - 1
        conn[a].append([b, C[j]])
        conn[b].append([a, C[j]])
    visited = [False] * N
    d = [0] * N
    d = dfs(K - 1, visited, conn, d, 0)
    for q in range(Q):
        s = x[q] - 1
        t = y[q] - 1
        ret = d[s] + d[t]
        print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int()] * (N-1)  # type: "List[int]" 
    b = [int()] * (N-1)  # type: "List[int]" 
    c = [int()] * (N-1)  # type: "List[int]" 
    for i in range(N-1):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
        c[i] = int(next(tokens))
    Q = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    x = [int()] * (Q)  # type: "List[int]" 
    y = [int()] * (Q)  # type: "List[int]" 
    for i in range(Q):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, a, b, c, Q, K, x, y)

if __name__ == '__main__':
    main()


Measured memory_bytes: 162240
/*"Everything in the universe is balanced. Every disappointment
   you face in life will be balanced by something good for you!
                Keep going, never give up."            */

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

#define ll long long
const ll N=1e6+9;
const ll mod=1e9+7;

ll a[N];

void solve()
{    
    ll n, m ;
    cin >> n >> m;
    vector<vector<long long int>>dp(n+1, vector<long long int>(100001,INT_MAX)) ;
    vector<pair<int,int>> items(n+1);
    for(int i=0; i<n; i++){
    	cin >> items[i].second >> items[i].first ;
    }
    dp[0][0] = 0;
    sort(items.begin(),items.end());
    for(int i=1; i<=n; i++){
    	dp[i][0] = 0 ;
    	for(int j = 1; j<=100000; j++) {
    		dp[i][j] = dp[i-1][j];
    		//cout<<dp[i][j]<<".";
    		 if(j>=items[i].first){
    		 	//cout<<dp[i-1][j-items[i].first]<<".";
    		 	dp[i][j] = min(dp[i][j], dp[i-1][j-items[i].first] + items[i].second ) ;
    		 }
    		 //cout<<dp[i][j]<<" ";
    	}
    	//cout<<"\n";
    }
    for(int i=100000; i>=0; i--){
    	if(dp[n][i]<=m){
    		cout<<i;
    		break;
    	}
    }

}

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll t=1;
    //pre();
    //cin>>t;
    while(t--)
    {
      solve();
    }  
}


// Xorawar

Measured memory_bytes: 83172
fun main(args: Array<String>) {
    val S = readInputLine()

    if (S.count { it == 'A' } == 3 || S.count { it == 'B'} == 3) {
        println("No")
    } else {
        println("Yes")
    }
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 33864
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a[5];
    for(int i=0;i<5;i++){
        cin>>a[i];
    }
    int k=0;
    for(int i=0;i<5;i++){
        if(a[i]==0){
            cout<<k+1;
        }
        k++;
    }
    return 0;
    
}


Measured memory_bytes: 3684
#include<bits/stdc++.h>
#define pb           push_back
#define pii          pair<int,int>
#define vi           vector<int>
#define vii         vector<pair<int,int>>
#define mp           make_pair
#define FOR(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD0(i, n) for (int i = (int)n; i >= 0; i--)
#define FORD1(i, n) for (int i = (int)n; i >= 1; i--)
#define debug(X) { cout << #X << " = " << (X) << endl; }
#define endl '\n'
#define int long long int
using namespace std;
vi adjList[(int)2e5];
vi val((int)2e5);
bool fail = false;
int dfs(int cur){
    bitset<5001> dp;
    dp[0] = 1;
    int sum = 0;
    int mn = 0;
    for(int child: adjList[cur]){
       int tot = dfs(child); 
       if(fail)return 0;
       int other = tot - val[child];
//       cout << tot << endl;
       dp = (dp << val[child]) | (dp << other);
       mn += min(other, val[child]);
       sum += tot;
    }
    if(mn > val[cur])fail = true;
    for(int i = val[cur]; i >= 0; i--){
       if(dp[i]){
           sum += (val[cur] - i); 
           break;
       }
    }
    return sum;
}
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    
    int n;cin >> n;
    int parent;
    FOR1(i, n-1){
        cin >> parent;
        parent--;
        adjList[parent].pb(i); 
    }
    FOR(i, n)cin >> val[i];
    dfs(0);

    if(fail)cout << "IM";
    cout << "POSSIBLE";
}




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

int main() {
  int r, D, xs;
  vector<int> x(10);
  cin >> r >> D >> xs;
  
  x.at(0) = r*xs - D;
  cout << x.at(0) << endl;
  
  for (int i=0; i<9; i++) {
    x.at(i+1) = r*x.at(i) - D;
    cout << x.at(i+1) << endl;
  }
}



Measured memory_bytes: 256
N=int(input())
nodes=[]
plus=[]
minus=[]
for i in range(N):
  x,y=map(int,input().split())
  nodes.append((x,y))
  plus.append(x+y)
  minus.append(x-y)
print(max(max(plus)-min(plus),max(minus)-min(minus)))

Measured memory_bytes: 114488
#include <iostream>
#include <vector>
using namespace std;
vector<int> A;
vector<int> Q;
int n,q;
bool solve(int i,int m){
if(m==0) return true;
if(i>n) return false;
return solve(i+1,m)||solve(i+1,m-A[i]);
}

int main(){
cin>>n;
int tmp;
for(int i=0;i<n;i++){
cin>>tmp;
A.push_back(tmp);
}
cin>>q;
for(int i=0;i<q;i++){
cin>>tmp;
Q.push_back(tmp);
}
for(int i=0;i<q;i++){
if(solve(0,Q[i])){
cout<<"yes"<<endl;}
else{
cout<<"no"<<endl;}
}
return 0;
}

Measured memory_bytes: 3144
#!/usr/bin/env python3
import itertools

n = int(input())


data = [[] for i in range(5)]
# print(data)
for i in range(n):
    tmp = str(input())
    if tmp[0] == "M":
        data[0].append(tmp)
    elif tmp[0] == "A":
        data[1].append(tmp)
    elif tmp[0] == "R":
        data[2].append(tmp)
    elif tmp[0] == "C":
        data[3].append(tmp)
    elif tmp[0] == "H":
        data[4].append(tmp)

ans = 0
for i, j, k in itertools.combinations([0, 1, 2, 3, 4], 3):
    ans += len(data[i])*len(data[j])*len(data[k])
print(ans)


Measured memory_bytes: 16536
#include <iostream>

using namespace std;
typedef long long lint;

lint A, B, K;
lint ansA, ansB;

void resolve()
{
    cin >> A >> B >> K;

    if (A > K) {
        ansA = (A - K);
        ansB = B;
    } else {
        ansA = 0;
        ansB = (B > (K - A)) ? (B - (K - A)) : 0;
    }

    cout << ansA << " " << ansB << endl;
}

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


Measured memory_bytes: 256
#!/usr/bin/env python3


def main():
    n = int(input())
    b = list(map(int, input().split()))

    result = []
    for j in range(n):
        for i in range(n - j, 0, -1):
            if b[i-1] == i:
                result.append(i)
                del b[i-1]
                break
    if len(result) == n:
        result.reverse()
        for v in result:
            print(v)
    else:
        print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <map>

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

using namespace std;
using P = pair<int,int>;


void init(int*,int*,int);
int find(int*,int);
bool same(int*,int,int);
void unite(int*,int*,int,int);


int main()
{
    int N,K,L,lpar[200010],lrank[200010],tpar[200010],trank[200010];
    cin>>N>>K>>L;
    init(lpar,lrank,N);
    init(tpar,trank,N);
    rep(i,K){
        int p,q;
        cin>>p>>q;
        unite(lpar,lrank,p-1,q-1);
    }
    rep(i,L){
        int r,s;
        cin>>r>>s;
        unite(tpar,trank,r-1,s-1);
    }

    map<P,int> m;
    rep(i,N){
        m[make_pair(find(lpar,i),find(tpar,i))]++;
    }
    rep(i,N){
        cout << m[make_pair(find(lpar,i),find(tpar,i))] <<" ";
    }
    cout << endl;

    return 0;
}

void init(int *par, int *rank, int n)
{
    rep(i,n){
        par[i]=i;
        rank[i]=0;
    }
    return;
}

int find(int *par, int x)
{
    if(par[x]==x){
        return x;
    }else{
        return find(par,par[x]);
    }
}

bool same(int *par, int x, int y)
{
    return find(par,x)==find(par,y);
}

void unite(int *par, int *rank, int x, int y)
{
    int par_x=find(par,x);
    int par_y=find(par,y);
    if(par_x==par_y){
        return;
    }else{
        if(rank[par_x]<rank[par_y]){
            par[par_x]=par_y;
        }else{
            par[par_y]=par_x;
            if(rank[par_x]==rank[par_y]){
                rank[par_x]++;
            }
        }
    }
}

Measured memory_bytes: 15232
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		// Nの入力
		int N = sc.nextInt();
		
		// 結果の出力
		int result = (int) (N % 2 == 0 ? Math.floor(N/2) - 1 : Math.floor(N/2));
		System.out.println(result);
		
		sc.close();
	}

}


Measured memory_bytes: 23764
N,K = map(int,input().split())
p = list(map(int,input().split()))
s = sum(p[:K])
ans = s
for i in range(N-K):
    s -= p[i]
    s += p[i+K]
    ans = max(ans,s)
ans += K
ans /= 2
print(ans)

Measured memory_bytes: 71792
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

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

setA = set(prime_factorize(A))
setB = set(prime_factorize(B))
print(len(setA & setB)+1)

Measured memory_bytes: 62756
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <math.h>

int main(){
    int H, N;
    std::cin >> H >> N;
    std::vector<int> A,B;
    for (int i=0; i<N; i++) {
        int x,y;
        std::cin >> x >> y;
        A.push_back(x);
        B.push_back(y);
    }
    
    size_t array[N][H+1];
    for (int i=0; i<N; i++) {
        for (int j=0; j<H+1; j++) {
            if (j==0) {
                array[i][j] = 0;
            }
            else if (i==0) {
                array[i][j] = ((j-1)/A[i]+1)*B[i];
            }
            else if (j<A[i]) {
                const size_t v = B[i];
                array[i][j] = std::min(array[i-1][j], v);
            }
            else {
                array[i][j] = std::min(array[i-1][j], array[i][j-A[i]]+B[i]);
            }
        }
    }
    
    std::cout << array[N-1][H] << std::endl;
    return 0;
}


Measured memory_bytes: 78336
program problemC
  implicit none

integer :: NMAX,n
integer, allocatable :: A(:), man(:)

read(*,*) NMAX

allocate(A(NMAX-1), man(NMAX))

read(*,*) A

man(:)=0

do n=1, NMAX-1
  man(A(n))=man(A(n))+1
end do

do n=1,NMAX
  write(*,*) man(n)
end do








deallocate(A,man)

end program


Measured memory_bytes: 5116
import std.stdio;
import std.algorithm;
import std.array;
import std.conv;
import std.datetime;
import std.numeric;
import std.math;
import std.string;

string my_readln() { return chomp(readln()); }

void main()
{
	auto tokens = my_readln().split();
	auto N = tokens[0].to!uint;
	uint[] h;
	foreach (token; my_readln().split())
	{
		h ~= token.to!uint;
	}
	
	uint ans;
	while (true)
	{
		uint l = N, r = N;
		foreach (i; 0..N)
		{
			if (h[i] >= 1)
			{
				l = i;
				break;
			}
		}
		if (l == N) break;
		foreach (j; l+1..N)
		{
			if (h[j] == 0)
			{
				r = j;
				break;
			}
		}
		foreach (i; l..r)
		{
			--h[i];
		}
		++ans;
	}

	writeln(ans);
	stdout.flush();
}

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

using namespace std;

int main()
{
    char b;
    scanf("%c", &b);
    if (b == 'A')
    {
        printf("T\n");
    }
    else if (b == 'C')
    {
        printf("G\n");
    }
    else if (b == 'G')
    {
        printf("C\n");
    }
    else
    {
        printf("A\n");
    }
    return 0;
}

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

typedef long long ll;
int main()
{
    map<char,int>mp;
    for(int i=0;i<4;i++)
    {
        char ch;
        cin>>ch;
        mp[ch]++;
    }
    cout<<(mp.size()==2 ? "Yes" : "No")<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    for(int i = 0; i < 3; ++i) {
        int h1,m1,s1,h2,m2,s2;
        cin >> h1 >> m1 >> s1 >> h2 >> m2 >> s2;
        if(s2 < s1) {
            --m2;
            s2 += 60;
        }
        s2 -= s1;
        if(m2 < m1) {
            --h2;
            m2 += 60;
        }
        m2 -= m1;
        h2 -= h1;
        cout << h2 << ' ' << m2 << ' ' << s2 << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main()
{
    char weather[3];
    int counter = 0;

    scanf("%s",weather);

    if(weather[0] == 'R'){
        counter++;
        if(weather[1] == 'R'){
            counter++;
            if(weather[2] == 'R'){
                counter++;
            }
        }
    }else if(weather[1] == 'R'){
        counter++;
        if(weather[2] == 'R'){
            counter++;
        }
    }else if(weather[2] == 'R'){
        counter++;
    }

    printf("%d",counter);

    return 0;

}

Measured memory_bytes: 1676