akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;

using ll=long long;

int main() {
  int M,D; cin >>M >>D;
  int ans=0;
  rep_eq(i,22,D) {
    int a=i%10;
    if (a<2) {a=0;}
    int b=i/10;
    if (b<2) {b=0;}
    if (1<=a*b and a*b<=M) {ans++;}
  }
  cout <<ans <<endl;
  return 0;
}


Measured memory_bytes: 3576
#include <iostream>
#include <algorithm>

main() {
  int a[12];
  for (int i = 0; i < 12; ++i) std::cin >> a[i];
  std::sort(a, a + 12);
  if (a[0] == a[1] && a[2] == a[3] && a[4] == a[5] && a[6] == a[7] && a[8] == a[9] && a[10] == a[11])
    std::cout << "yes" << std::endl;
  else 
    std::cout << "no" << std::endl;
}

Measured memory_bytes: 3128
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main(){
    string X; cin >> X;
    vector<char> V;
    for(char c:X){
        if(c=='S') V.push_back('S');
        else if(c=='T' && (V.empty() || V.back()!='S')) V.push_back('T');
        else if(c=='T' && !V.empty() && V.back()=='S') V.pop_back();
    }
    cout << V.size() << endl;
    return 0;
}


Measured memory_bytes: 772
#include <iostream>

using namespace std;

int main()
{
   int a, b, c;
   cin >> a >> b >> c;
   if( a == b && b == c ){
       cout << 1 << endl;
       return 0;
   }
    if( a == b || b == c || a == c ){
        cout << 2 << endl;
        return 0;
    }
    
    cout << 3 << endl;
   
   return 0;
}


Measured memory_bytes: 256
S = input()
ans = 'AC'
if S[0] != 'A' or S[2:-1].count('C') != 1:
    ans = 'WA'
else:
    for i in range(len(S)):
        if i == 0:
            continue
        elif (2 <= i <= len(S)-2) and S[i] == 'C':
            continue
        else:
            if not ('a' <= S[i] <= 'z'):
                ans = 'WA'
                break
print(ans)


Measured memory_bytes: 3064
n,m = map(int,input().split())
if n == 2 or m == 2:
  print(0)
elif n == 1:
  if m == 1:
    print(1)
  else:
    print(m-2)
elif m == 1:
  if n == 1:
    print(1)
  else:
    print(n-2)
else:
  print((n-2)*(m-2))

Measured memory_bytes: 3060
n, q = map(int, input().split())
tree = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)

cost = [0 for _ in range(n)]
for _ in range(q):
    pos, point = map(int, input().split())
    cost[pos-1] += point

memo = set([0])
stack = [0]

while len(stack) > 0:
    cur_node = stack.pop()
    cur_cost = cost[cur_node]

    for node in tree[cur_node]:
        if node not in memo:
            memo.add(node)
            cost[node] += cur_cost
            stack.append(node)

print(*cost)

Measured memory_bytes: 62456
#include <stdio.h>

int main()
{
    int n;
    scanf("%d", &n);
    int c[2] = {};
    for (int i = 0; i < n; ++ i) {
        int x;
        scanf("%d", &x); c[x & 1] ++;
    }
    while (c[0] > 1 || c[1] > 1) {
        c[0] += c[1] >> 1;
        c[1] &= 1;

        c[0] = c[0] / 2 + c[0] % 2;
    }
    puts(c[0] + c[1] == 1 ? "YES" : "NO");
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] iArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            long A = iArray[0];
            long B = iArray[1];
            long K = iArray[2];
            if (A == 0 && B == 0)
            {
                Console.WriteLine(A + " " + B);
            }
            else if (A > K)
            {
                Console.WriteLine((A - K) + " " + B);
            }
            else if (A - K <= 0)
            {
                if (B - (K - A) <= 0)
                {
                    Console.WriteLine("0" + " " + "0");
                }
                else
                {
                    Console.WriteLine("0" + " " + (B - (K - A)));
                }
            }
        }
    }
}
// 文字列の入力
//string s = Console.ReadLine();

// 整数の入力
//long n = long.Parse(Console.ReadLine());

// 文字列配列の入力
//string[] inputStrArray = Console.ReadLine().Split(' ');

// 整数配列の入力
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

Measured memory_bytes: 13396
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REPR(i,n)   FORR(i,n,0)
#define int long long

using namespace std;
typedef pair<int, int> pii;

int k,n,a[110]={0};
int dp[100010]={0};

signed main() {
	cin>>n>>k;
    rep(i,n){
        cin>>a[i];
    }
	FOR(i,1,k+1){
        dp[i]=-1;
    }
    dp[0]=1;

    rep(i,k+1){
        if(dp[i]!=-1){
            continue;
        }
        rep(j,n){
            if(i-a[j]>=0){
                if(dp[i-a[j]]==1){
                    dp[i]=0;
                    break;
                }
            }
        }
        if(dp[i]==-1){
            dp[i]=1;
        }
    }
	
    if(dp[k]){
        cout<<"Second"<<endl;
    }
    else{
        cout<<"First"<<endl;
    }

	return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
int main(){
    int n,m,ans=0;
    while(1){
    scanf("%d %d",&n,&m);
    if(n==0&&m==0)
        break;
    int nowpoint=1;
    int fie[1001]={0},xi[1001]={0};
    for(int i=1;i<n+1;i++)
        scanf("%d",&fie[i]);
    for(int i=0;i<m;i++)
        scanf("%d",&xi[i]);

    /*
    for(int i=1;i<n+1;i++)
        printf("[%d]",fie[i]);
    puts("");
    for(int i=0;i<m;i++)
        printf("[%d]",xi[i]);
    puts("");
    */

    for(int i=0;i<m;i++){
        nowpoint+=xi[i];
        /*
        printf("[%d]",nowpoint);
        */
        nowpoint+=fie[nowpoint];
        /*
        printf("[%d]\n",nowpoint);
        */
        if(n<=nowpoint){
            ans=i;
            goto exit;
        }
    }
exit:
    printf("%d\n",ans+1);
    }
    return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
 
vector<vector<ll>>a(26);
int main() {
	string s,t;
	cin>>s>>t;
	for(int i=0;i<s.size();i++){
		ll now=s[i]-'a';
		a[now].push_back(i+1);
	}
	ll ans=0,now=0;
	bool out =false;
	for(int i=0;i<t.size();i++){
		ll sear=t[i]-'a';
		bool ch=false;
		auto Iter1 = upper_bound(a.at(sear).begin(),a.at(sear).end(), now);
		ll res =Iter1 -a[sear].begin();
		if(res!=a[sear].size()){
		    ll fi =a[sear][res];
				ans+=fi-now;
				now=fi;
				ch=true;
				out =false;
		}
		if(out){
			cout << -1;
			return 0;
		}
		if(ch!=true){
			i--;
			ans+=s.size()-now;
			now=0;
			out =true;
		}
	}
	cout << ans;
	return 0;
}

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

using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if(c + b - a > 0 ) {
        cout << c + b - a << endl;
    } else {
        cout << 0 << endl; 
    }
    return 0;
}


Measured memory_bytes: 256
n = int(input())
AB = []
for i in range(n):
    a, b = map(int, input().split())
    AB.append([a, b])
AB.sort(key=lambda x: x[1])
cumsum = 0
for a, b in AB:
    cumsum += a
    if cumsum > b:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 40668
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,ans=0;
  cin >> n;
  vector<int> da(n);
  vector<bool> ju(n,true);
  for (int i=0;i<n;i++){
    cin >> da[i];
  }
  sort(da.begin(),da.end());
  vector<int> df(31);
  df[0]=2;
  for(int i=0;i<30;i++){
    df[i+1]=df[i]*2;
  }
  for(int i=30;i>-1;i--){
    vector<int> go(n);
    for(int j=0;j<n;j++)
      go[j]=df[i]-da[n-j-1];
    int a=0,b=0;
    while(a<n&&b<n){
      if(da[a]==go[b]){
        if(ju[a]&&ju[n-b-1]&&a!=n-b-1){
          ju[a]=false;
          ju[n-b-1]=false;
          ans++;
        }
        else if(a==n-b-1)
          a++;
        else {
          if(!ju[a])
            a++;
          if(!ju[n-b-1])
            b++;
        }
      }
      else if(da[a]>go[b])
        b++;
      else
        a++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
int n,x,box[100010];

int main()
{
	int i,j;
	
	scanf("%d %d",&n,&x);
	for(i=0;i<n;i++)
	{
		scanf("%d",&box[i]);
	}
	
	int sum;
	long long ans=0;
	for(i=0;i<n-1;i++)
	{
		sum = box[i] + box[i+1];
		if(sum > x)
		{
			if(sum - box[i+1] <= x)
			{
				ans += sum-x;
				box[i+1] -= sum-x;
				sum = box[i] + box[i+1];
			}
			else if(sum - box[i+1] > x)
			{
				ans += box[i+1];
				box[i+1] = 0;
				sum = box[i];
				ans += sum-x;
				box[i] -= sum-x;
				
			}
		}
		
		
	}
	
	printf("%lld\n",ans);
	
}

Measured memory_bytes: 4196
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    lis = list(map(int, input().split()))
    val = [0] * n

    for i in range(n, 0, -1):
        if n // i == 1:
            val[i - 1] = lis[i - 1]
        else:
            a = sum(val[i - 1::i])
            if a % 2 != lis[i - 1]:
                val[i - 1] ^= 1

    print(sum(val))
    print(*[i + 1 for i in range(n) if val[i] == 1], sep=" ")
if __name__ == '__main__':
    main()
    

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

using namespace std;

int cnt = 0;
int MOD = 1000000007;

int main(){
    int A,B,C,X,Y;
    cin >> A >> B >> C >> X >> Y;
    
    int a=0,b=0,c=0;
    
    a = A*X+B*Y;
    b = C*2*max(X,Y);
    if(X>Y) c = (C*2*Y)+(X-Y)*A;
    else if(X<Y)  c = (C*2*X)+(Y-X)*B;
    else c = C*2*X;
    
    cout << min({a,b,c}) << endl;
    
    return 0;
}


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

char s[105];

void in()
{
    scanf("%s",s);
}

void work()
{
    int c=1;
    for(int i=0;i<strlen(s);++i)
    {
        if(s[i]=='C'&&c==1)
        {
            c=0;
        }
        if(s[i]=='F'&&c==0)
        {
            printf("Yes\n");
            exit(0);
        }
    }
    printf("No\n");
}

int main()
{
    in();
    work();
    return 0;
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first 
#define b second
int n;
vector<pair<int,string>> aa;
int pre[1000002][26];
int cot[1000002][26];

int co=0;
llo ans=0;
int cco[26];
void insert(string s){
	int cur=0;
	int st[26];
	for(int j=0;j<26;j++){
		st[j]=0;
	}
	
	if(s.size()==1){
		ans+=cco[s[0]-'a'];
	//	cout<<s<<":"<<ans<<endl;
	}
	for(int i=0;i<s.size();i++){
		st[s[i]-'a']+=1;
		if(st[s[i]-'a']==1){
			cco[s[i]-'a']+=1;
		}
	}
	for(int i=s.size()-1;i>=0;i--){
		if(pre[cur][s[i]-'a']==0){
			co+=1;
			pre[cur][s[i]-'a']=co;
		}

		cur=pre[cur][s[i]-'a'];
		if(i==1){
			ans+=cot[cur][s[0]-'a'];
		}
		st[s[i]-'a']-=1;
		for(int j=0;j<26;j++){
			if(st[j]>0){
				cot[cur][j]+=1;
			}
		}
	}

}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		aa.pb({s.size(),s});
	}
	sort(aa.begin(),aa.end());
	reverse(aa.begin(),aa.end());
	for(auto j:aa){
		insert(j.b);
	//	cout<<j.b<<","<<endl;
	}
	cout<<ans<<endl;






	return 0;
}

Measured memory_bytes: 207488
#include <iostream>
int main(){
    int a, b, c, d;
    d = 1;
    std::cin >> a >> b >> c;
    if(a < b){
        if(b < c){
            d = 0;
        }
    }
    if(d == 0){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }
}


Measured memory_bytes: 3080
#include <vector>
#include <algorithm>
#include <cstdio>

using namespace std;

int inputInt() {
    int i;
    scanf("%d", &i);
    return i;
}

int N;
vector<int> A;
long long ret;

int main() {
    N = inputInt();
    A.resize(max((int)A.size(), N)); for(int i=0; i<N; ++i) A[i] = inputInt();
    sort(A.rbegin(), A.rend());
    ret = 0;
    for(int i=1; i<N; ++i) ret += A[i>>1];
    printf("%lld\n", ret);
    return 0;
}


Measured memory_bytes: 3592
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<queue>
using namespace std;
int main()
{
    int n,m;
    priority_queue<int,vector<int>,less<int> >q;
    scanf("%d%d",&n,&m);
    int qt;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&qt);
        q.push(qt);
    }
    while(m--)
    {
        qt=q.top();
        qt/=2;
        q.pop();
        q.push(qt);
    }
    long long int sum=0;
    while(q.size())
    {
        sum+=q.top();
        q.pop();
    }
    printf("%lld\n",sum);
    return 0;
}


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

int main() {
	string s;
	cin >> s;
	sort(s.begin(), s.end());
	cout << (s == "abc" ? "Yes" : "No");
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

一度順番に並び替えておくと、単に"abc"との同値比較で良いので楽
*/

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define MAXN 20
string S,T;
int main()
{
    cin>>S>>T;
    int len=S.length();
    for(int i=0;i<len;i++)
    {
        bool flag=1;
        for(int j=0;j<len;j++)
        if(S[(i+j)%len]!=T[j]){flag=0;break;}
        if(flag){printf("Yes\n");return 0;}
    }
    printf("No\n");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
const ll mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

mint dp[105][100000];

int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> v;
    ll rn = 1;

    for (ll i=1; i*i<=n; i++) {
        rn = i;
        v.push_back(n/i);
    }
    if (v.back()==rn) v.pop_back();
    for (ll i=rn; i>=0; i--) {
        v.push_back(i);
    }
    reverse(v.begin(), v.end());
    //debug(rn);
    //debug(v.size());
    const ll ndp = v.size() - 1;
    rep(i, ndp) {
        dp[0][i] = v[i+1];
        //debug(dp[0][i].x);
    }
    

    for (ll i=1; i<k; i++) {
        rep(j, ndp) {
            dp[i][j] = mint(v[j+1]-v[j])*dp[i-1][ndp-1-j];
            if (j>0) {
                dp[i][j] += dp[i][j-1];
            }
            //debug(dp[i][j].x);
        }
    }

    

    mint ans = dp[k-1][ndp-1];
    
    cout << ans.x << endl;
    return 0;
}


Measured memory_bytes: 82940
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <iomanip>
#include <deque>
#include <queue>

#include <unordered_map>
#include <stack>
#include <bitset>
#include <cstdlib>
#include <sstream>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
ll pow(ll N, ll P){
    if(P==0) return 1;
    if(P%2==0){
        ll t = pow(N, P/2);
        return t*t;
    }
    return N * pow(N, P-1);
}
ll modpow(ll N, ll P,ll k){
    if(P==0) return 1;
    if(P%2==0){
        ll t = modpow(N, P/2,k)%k;
        return t*t%k;
    }
    return N * modpow(N, P-1,k)%k;
}
ll modkai(ll n,ll m,ll k){//n*(n-1)*(n-2)*...(m+1)%k
    if(n == m)return 1;
    return modkai(n-1,m,k)*n%k;
}
ll mod_cnb(ll n,ll m,ll k){//nCm%k,kは十分大きい素数
  int m_=modkai(m,0,k);
  return modkai(n,n-m,k)*modpow(m_,k-2,k)%k;
}
ll gcd(ll n,ll m){
    n=abs(n);
    m=abs(m);
    if(n*m==0)return max(n,m);
    ll n_ = max(n,m);
    ll m_ = min(n,m);
    if(n_%m_ == 0)return m_;
    return gcd(m_,n_%m_);
}
ll lcm(ll n,ll m){
    return n*m/gcd(n,m);
}
using Graph = vector<vector<int>>;

int main() {
    // 頂点数と辺数
    int N, M; cin >> N >> M;

    // グラフ入力受取 (ここでは無向グラフを想定)
    Graph G(N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    // BFS のためのデータ構造
    vector<int> dist(N, -1); // 全頂点を「未訪問」に初期化
    queue<int> que;

    // 初期条件 (頂点 0 を初期ノードとする)
    dist[0] = 0;
    que.push(0); // 0 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = v+1;
            que.push(nv);
        }
    }
    rep(i,N){
        if(dist[i]==-1){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    rep(i,N-1)cout<<dist[i+1]<<endl;
}

Measured memory_bytes: 10160
using System;
//ポイントは一つの山をxと置くこと
//すると2x=A1-A2+A3-A4+A5
namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] In = Console.ReadLine().Split(' ');
            int[] A = new int[n];
            for (int i = 0; i < n; i++)
            {
                A[i] = int.Parse(In[i]);
            }
            long x2 = 0;//とりあえず一つの山だけ計算する
            for (int i = 0; i < n; i++)
            {
                if (i % 2 == 1) x2 -= A[i];
                else x2 += A[i];
            }
            //一つ目の山を起点に他の山を考える
            int[] ans = new int[n];
            ans[0] = (int)(x2 / 2);
            for(int i=0; i < n - 1; i++)
            {
                ans[i + 1] = A[i] - ans[i];
            }
            for(int i=0; i < n; i++)
            {
                Console.WriteLine(ans[i] * 2);
            }
        }
    }
}

Measured memory_bytes: 41636
//
// Created by kashi on 17-05-2020.
//
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define Endl endl

int main(){
    int n;
    cin>>n;
   n=n%10;
    if(n==0 || n==1 || n==6 || n==8){
        cout<<"pon"<<endl;
    } else
    if(n==2 || n==4 || n==5 || n==7 ||n==9){
        cout<<"hon"<<endl;
    } else if(n==3){
        cout<<"bon"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3600
let id x = x
             
let make_sa s =
  let sl = String.length s in
  let sa = Array.init (sl+1) id in
  let rank = Array.init (sl+1) (fun i -> if i = sl then (-1) else Char.code s.[i]) in
  let ta = Array.make (sl+1) 0 in
  let cmp k i j =
    if rank.(i) = rank.(j) then
      let rik = if i + k <= sl then rank.(i+k) else (-1) in
      let rjk = if j + k <= sl then rank.(j+k) else (-1) in
      rik - rjk
    else rank.(i) - rank.(j) in
  let ra_rank k =
    let rec iter i =
      if i > sl then ()
      else begin
          ta.(sa.(i)) <- ta.(sa.(i-1)) + (if cmp k sa.(i) sa.(i-1) > 0 then 1 else 0);
          iter (i+1)
        end in
    let rec copy i =
      if i > sl then ()
      else begin
          rank.(i) <- ta.(i);
          copy (i+1)
        end in
    iter 1;
    copy 0 in
  let rec sort_sa k =
    if k > sl then ()
    else begin
        Array.fast_sort (cmp k) sa;
        ra_rank k;
        sort_sa (2 * k)
      end in
  sort_sa 1; sa

let string_search sa s p =
  let sl = String.length s in
  let pl = String.length p in
  let rec search l r =
    if r - l <= 1 then
      try String.sub s sa.(r) pl = p with _ -> false
    else
      let m = (l + r) / 2 in
      match compare (String.sub s sa.(m) (min pl (sl - sa.(m)))) p with
        0 -> true
      | x when x < 0 -> search m r
      | _ -> search l m
  in
  search 0 (sl+1)

let () =
  let t = read_line () in
  let q = read_int () in
  let sa = make_sa t in
  let rec loop x =
    if x = 0 then ()
    else let p = read_line () in
         (if string_search sa t p then "1" else "0") |> print_endline;
         loop (x-1)
  in loop q

Measured memory_bytes: 75356
#include<stdio.h>
#include<string.h>
#include<ctype.h>

int main(void)
{
    char W[10], T[1000];
    int i, count = 0;
    
    scanf("%s", &W);
    for(i=0;;i++){
        W[i] = toupper(W[i]);
        if(W[i] == '\0'){
            break;
        }
    }
    
    while(strcmp(T, "END_OF_TEXT") != 0){
        scanf("%s", &T);
        for(i=0;;i++){
            if(strcmp(T, "end_of_text") == 0){
                break;
            }
            T[i] = toupper(T[i]);
            if(T[i] == '\0'){
                break;
            }
        }
        if(strcmp(T, W) == 0){
            count++;
        }
    }
    printf("%d\n", count);
    
    return 0;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


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

  ll n;
  cin >> n;

  vll a(n);
  REP(i, n)
    cin >> a[i];
  
  long double bunbo, bunshi;
  bunshi = 1;
  bunbo = 0;

  REP(i, n)
    bunbo += 1.0 / a[i];

  cout << Decimal;
  cout << 1.0 / bunbo << endl;
  
}


Measured memory_bytes: 256
while True:
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        break
    for n in range(a):
        mark1 = "#"
        mark2 = "."
        outLen = ""
        if n % 2 == 0 :
            mark1 = "."
            mark2 = "#"
        for m in range(b):
            if m % 2 != 0:
                outLen = outLen + mark1
            else:
                outLen = outLen + mark2
        print(outLen)
    print("")


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

int main(){
	string s;
	cin >> s;
	int size=s.size();
	for(int i=0;i<size;i++){
		if(s[i]==s[i+1] && s[i+1]==s[i+2]){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 768
M = 998244353

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

table_a = [None] * (D - B + 1)
table_h = [None] * (D - B + 1)
table_v = [None] * (D - B + 1)

tmp_table_a = [None] * (D - B + 1)
tmp_table_h = [None] * (D - B + 1)
tmp_table_v = [None] * (D - B + 1)

table_a[0] = 1

c = 1
for x in range(1, D - B + 1):
	c = (c * A) % M
	table_a[x] = c
	table_v[x] = c

#c = 1
#for y in range(1, C - A + 1):
#	c = (c * B) % M
#	table_a[y][0] = c
#	table_h[y][0] = c

c = 1
for y in range(1, C - A + 1):
	c = (c * B) % M
	
	tmp_table_a[0] = c
	tmp_table_h[0] = c
	
	for x in range(1, D - B + 1):
#		print(x, y, table[y - 1][x] * (B + x - 1), table[y][x - 1] * (A + y - 1))
#		table[y][x] = table[y - 1][x] * (B + x - 1) + table[y - 1][x - 1] * (B + x - 1 + A + y - 1)
#		table[y][x] = max(table[y - 1][x] * (B + x - 1),  table[y][x - 1] * (A + y - 1)) + table[y - 1][x - 1] * (B + x - 1 + A + y - 1)
		
		tmp_table_v[x] = (tmp_table_a[x - 1] * (A + y)) % M
		tmp_table_h[x] = (table_a[x] * (B + x)) % M
		tmp_table_a[x] = (tmp_table_h[x] + (tmp_table_a[x - 1] - tmp_table_h[x - 1]) * (A + y) + tmp_table_h[x - 1]) % M
	
	table_a, tmp_table_a = (tmp_table_a, table_a)
	table_v, tmp_table_v = (tmp_table_v, table_v)
	table_h, tmp_table_h = (tmp_table_h, table_h)
	
#print(table_a)
#print(table_v)
#print(table_h)

print(table_a[D - B])


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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;

    int dp[n] = {0};

    for(int i = 1; i < s.length(); ++i){
        string subs = s.substr(i-1, 2);
        
        if(subs == "AC") dp[i] = dp[i-1] + 1;
        else dp[i] = dp[i-1];
    } 

    for (int i = 0; i < q; ++i){
        int l, r;
        cin >> l >> r;
        cout << dp[r-1] - dp[l-1] << endl;
    }
}

Measured memory_bytes: 1488
/*
ID: jerrywcy
LINK: https://atcoder.jp/contests/abc127/tasks/abc127_e
LANG: C++
STATUS:
*/
#include <bits/stdc++.h>

#define int long long
#define init(array,x) memset(array,x,sizeof(array))

using namespace std;

const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const int maxnm=2e5+10;

int n,m,k;
int fac[maxnm],inv_fac[maxnm];
int ans;

int p(int x,int y){
	long long ret=1,mul=x;
	while (y){
		if (y&1)ret=(ret*mul)%mod;
		mul=(mul*mul)%mod;
		y>>=1;
	}
	return ret;
}

void pre(){
	fac[0]=1;
	for (int i=1;i<=n*m;i++)fac[i]=(fac[i-1]*i)%mod;
	inv_fac[n*m]=p(fac[n*m],mod-2);
	for (int i=n*m-1;i>=0;i--)inv_fac[i]=(inv_fac[i+1]*(i+1))%mod;
	return ;
}

int C(int x,int y){
	if (y==0 || y==x)return 1;
//	cout<<fac[x]<<' '<<inv_fac[y]<<' '<<inv_fac[x-y]<<endl;
	return ((inv_fac[y]*inv_fac[x-y])%mod*fac[x])%mod;
}

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n>>m>>k;
	pre();
	for (int i=1;i<n;i++){
		long long tmp=1ll*i*(i+1)/2%mod;
		tmp=tmp*m*m%mod;
		ans=(ans+tmp)%mod;
	}
	for (int i=1;i<m;i++){
		long long tmp=1ll*i*(i+1)/2%mod;
		tmp=tmp*n*n%mod;
		ans=(ans+tmp)%mod;
	}
//	cout<<p(m,2*n-2)<<' '<<p(n,2*m-2)<<endl;
//	long long ans=m*m*((n-1)*n*(2*n-1)/6+n*(n-1)/2)/2+n*n*((m-1)*m*(2*m-1)/6+m*(m-1)/2)/2;
//	cout<<ans<<endl;
//	cout<<C(n*m-2,k-2)<<endl;
	ans=(ans*C(n*m-2,k-2))%mod;

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 3328
#include<cmath>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iomanip>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#define ll long long
#define inf 1000000000
#define mod 1000000007
#define N 1000000
using namespace std;
int n,i,sum;
int a[N];
int main()
{
	cin>>n;
	for (i = 1;i <= n; i++) cin>>a[i];
	for (i = 1;i <= n; i++)
		if (a[a[i]] == i) sum++;
	cout<<sum/2<<endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll a, b, c, d;
  cin>>a>>b>>c>>d;
  cout<<max(a*c, max(a*d, max(b*c, b*d)))<<endl;
}



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

int main(){
    int n;
    cin >> n;
    vector<int> ie(n);
    rep(i,n){
        cin >> ie[i];
    }
    int mi = 2005;
    int mx = 0;
    rep(j,n){
        mi = min(mi, ie[j]);
        mx = max(mx, ie[j]);
    }
    int ans;
    if ((mx - mi) % 2 == 0){
        ans = (mx - mi) / 2;
    }
    else{
        ans = (mx - mi + 1) / 2;
    }
    cout << ans << endl;
}


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

def main():
    N = int(input())
    d = list(map(int,input().split()))
    
    d.sort()
    now = 1
    time = [0]
    for num in d:
        if now == 1:
            time.append(num)
        else:
            time.append(24-num)
        now *= -1
    
    time.sort()
    ans = 24-time[-1]
    for i in range(N):
        ans = min(ans,time[i+1]-time[i])
    
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
const int B = 1<<20,w=4,h=5;
typedef pair<int,int>P;
vector<P> C;
 
int used[(B)+1],ans;
 void dfs(int bit){
  if(used[bit]++)return;
  ans=min(ans,(int)C.size());
 
  for(int i=0;i<C.size();i++){
    int x=i%w,y=i/w;
    for(int j=-1;j<=1;j++)
      for(int k=-1;k<=1;k++){
    if(j==0&&k==0)continue;
    int nx=x+j,ny=y+k,idx=ny*w+nx;
    if(nx<0||nx>=w||ny>=h||ny<0)continue;
    if(idx<=i||idx>=(int)C.size()||C[i].first!=C[idx].first)continue;
    int a=i,b=idx,nbit=bit|(1<<C[i].second)|(1<<C[idx].second);
    vector<P> tmp=C;
    if(a>b) swap(a,b);
    C.erase(C.begin()+b);
    C.erase(C.begin()+a);
    dfs(nbit);
    C=tmp;
      }
  }
}
 
int main(){
  int q;
  cin>>q;
  while(q--){
    C.resize(20);
    for(int i=0;i<20;i++) cin>>C[i].first,C[i].second=i;
    memset(used,0,sizeof(used));
    ans=1e9;
    dfs(0);
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 7108
l = [int(x) for x in input().split()]
X, N = l[0], l[1]
p = [int(x) for x in input().split()]

delta = 0
while True:
    if not X - delta in p:
        print(X-delta)
        break
    if not X + delta in p:
        print(X + delta)
        break
    delta += 1

Measured memory_bytes: 9096
#include <bits/stdc++.h>
#define re return
#define ull unsigned long long
#define ll long long
#define ld long double
#define mid (l+r)/2
#define f first
#define s second
#define oo 1e9
#define pi acos(-1)
#define OO 1e18
#define EPS 1e-12
#define FX(n) fixed<<setprecision(n)
#define mm(o,k) memset(o,k,sizeof o)
#define Hossam_Yehia ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
int main(){
    Hossam_Yehia;
    int a,b;
    cin >> a >> b;
    if(a>b)cout<<a-b;
    else cout<<0;
    re 0;
}


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

long long n,s,dp[11][1001];
int main(void){
  
  dp[0][0] = 1;
  
  for(int i=0;i<101;i++){
    for(int j=9;j>=0;j--){
      for(int k=0;i+k<1001;k++){
        dp[j+1][k+i]+=dp[j][k];
      }
    }
  }
  
  while(cin >> n >> s, n|s)
    cout << dp[n][s] << endl;
  return 0;
}

Measured memory_bytes: 1236
a = []
b = []
for i in range (4):
    n = int(input())
    a.append(n)
for j in range (2):
    m = int(input())
    b.append(m)
a.sort()
b.sort()    
y=int(a[1]+a[2]+a[3]+b[1])
print(y)
    


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  int n, k;
  string s;
  cin >> s >> k;
  n = s.size();

  set<string> st;
  REP(i, k) REP(j, n-i){
    st.insert(s.substr(j, i+1));
  }
  int i = 0;
  for(string c : st){
    i++;
    if(i == k) cout << c << endl;
  }
  
  return 0;
}

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	int ret;
	for (int i=0; i<5; i++) {
		int x; cin >>x;
		if (x==0) ret = i+1;
	}
	cout << ret << endl;
	return 0;
}

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


int main(){
    int A,B,C,D;
    int d[101];
    int ans = 0;
    int tmp;

    cin >> A;
    cin >> B;
    cin >> C;
    cin >> D;
    if(A <= C){
        if(B >= C){
            if(B <= D){
                ans = B - C;
            }else{
                ans = D - C;
            }
        }else{
            ans = 0;
        }
    }else{
        if(D >= A){
            if(D <= B){
                ans = D - A;
            }else{
                ans = B - A;
            }
        }else{
            ans = 0;
        }
    }
    cout << ans <<"\n";

    return 0;
}

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

const int MAX_N = 100000;
const int INF = LLONG_MAX/10;

int X, Y;

signed main()
{
	cin >> X >> Y;
	int ans = 0;
	if (abs(X) <= abs(Y))
	{
		if (Y < 0) Y = -Y, ans++;
		if (X < 0) X = -X, ans++;
	}
	else
	{
		if (X > 0) X = -X, ans++;
		if (Y > 0) Y = -Y, ans++;
	}
	printf("%lld\n", ans + Y - X);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main()
{
  int i,a,b,c;
  for(i=1; i<=3000; i++)
  {
    cin >> a >> b;
    if (a==0 && b==0)
    break;
     if ( a > b )
     {
     c=a;
     a=b;
     b=c;
      }

  cout << a << " " << b << endl;
  }
}


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

using ll = long long;

constexpr ll MOD = 1e9+7;
constexpr ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

int main(int argc, char **argv)
{
	ll N; cin >> N;
	vector<ll> A(N); REP(i, N) cin >> A[i];

	ll fac{1};
	ll res{0};
	REP(b, 60)
	{
		ll o{0}, e{0};
		REP(i, N)
		{
			if (A[i] & (1ll<<b)) ++o;
			else ++e;
		}

		(res += fac * o % MOD * e) %= MOD;
		(fac *= 2) %= MOD;
	}
	std::cout << res << std::endl;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
using namespace std;
typedef long long ll;
int main(){
   #ifndef ONLINE_JUDGE 
      FILE_READ_IN 
      FILE_READ_OUT 
   #endif
    int n; cin>>n;
    int a[n];
    ll avg=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        avg+=a[i];
    }
    avg=round(avg/(float)n);
    ll cost=0;
    for(int i=0;i<n;i++)
    {
        cost+=abs(avg-a[i])*abs(avg-a[i]);
    }
    cout<<cost<<"\n";
   return 0;
}

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

using namespace std;

using int64 = long long;
const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

template< typename T, typename Compare = greater< T > >
vector< T > knapsack_01(const vector< int > &w, const vector< T > &v, const int &W, const T &NG, const Compare &comp = Compare()) {
  const int N = (int) w.size();
  vector< T > dp(W + 1, NG);
  dp[0] = T();
  for(int i = 0; i < N; i++) {
    for(int j = W; j >= w[i]; j--) {
      if(dp[j - w[i]] != NG) {
        if(comp(dp[j - w[i]] + v[i], dp[j])) {
          dp[j] = dp[j - w[i]] + v[i];
        }
      }
    }
  }
  return dp;
}

int main() {
  int N, W;
  cin >> N >> W;
  vector< int > v(N), w(N);
  for(int i = 0; i < N; i++) cin >> v[i] >> w[i];
  auto ret = knapsack_01(w, v, W, -1);
  cout << *max_element(begin(ret), end(ret)) << endl;
}



Measured memory_bytes: 3228
#include<stdio.h>

#define N 102
#define MAX 100001

static const int INFTY = (1<<21);
 
main(){

  int n, i, j, u, k, v, c;
  int M[N][N], d[N], p[N], q[N];
 
  scanf("%d", &n);

  for ( i = 0; i< n; i++ ){
    for ( j = 0; j < n; j++ ){
      M[i][j] = INFTY;
    }

    d[i] = INFTY;
    q[i] = 0;

  }


  d[0] = 0;
  q[0] = 1;
  p[0] = 0;

  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &u, &k);
    for ( j = 0; j < k; j++ ){
      scanf("%d %d", &v, &c);
      M[u][v] = c;
    }
  }

u = 1;

  for(c = 0; c < n - 1; c++){
    k = MAX;
    for(i = 0; i < u; i++){
      for(j = 0; j < n; j++){
        if(q[j] == 0){
          if(M[p[i]][j] < MAX && d[j] >= M[p[i]][j] + d[p[i]]){
            d[j] = M[p[i]][j] + d[p[i]];
            if(d[j] <= k){
              k = d[j];
              v = j;
            }
          }
        }
      }
    }

    u++;
    q[v] = 1;
    p[i] = v;

  }

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

}

Measured memory_bytes: 644
#include<iostream>
#include<string>
#include<map>
#include<vector>
#define rep(i,a) for(int i=0;i<a;i++)
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
	int n,m;cin>>n;
	map<string,int>tmp;
	vi ne(n);
	rep(i,n){
		string s;cin>>s>>ne[i];
		tmp[s]=i;
	}
	cin>>m;
	vi p,q;
	rep(i,m){
		string a,b;cin>>a>>b;
		p.push_back(tmp[a]);q.push_back(tmp[b]);
	}
	rep(i,m)rep(j,m)ne[p[j]]=ne[q[j]]=min(ne[p[j]],ne[q[j]]);
	int sum=0;
	rep(i,n)sum+=ne[i];
	cout<<sum<<endl;
}

Measured memory_bytes: 1840
n = gets.to_i
a = 2.times.map{ gets.split.map(&:to_i) }

result = 0
(1..n).each do |i|
    baz = 0
    i.times{ |j| baz += a[0][j] }
    (i..n).each{ |k| baz += a[1][k-1] }
    result = baz if baz > result
end

puts result

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
vll g[MAX];
ll c[MAX];
bool vis[MAX];
map <pll, bool> pr;
vector <pll> ed;
void dfs(ll cur, ll par)
{
    vis[cur] = true;
    for(auto x : g[cur])
    {
        if(x == par)
            continue;
        if(!vis[x])
            dfs(x, cur);
        else
        {
            if(!pr[mp(x, cur)])
            {
                ed.pb(mp(cur, x));
                c[cur]++;
                pr[mp(x, cur)] = true;
                pr[mp(cur, x)] = true;
            }
        }
    }
    if(par != -1)
    {
        if(c[cur] % 2)
            ed.pb(mp(cur, par)), c[cur]++;
        else
            ed.pb(mp(par, cur)), c[par]++;
    }
}
int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    ll n, i, u, v, m;
    cin >> n >> m;
    for(i = 0; i < m; i++)
    {
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    if(m % 2 != 0)
    {
        cout << -1 << endl;
        return 0;
    }
    dfs(1, -1);
    for(auto x : ed)
        cout << x.F << ' ' << x.S << endl;
    return 0;
}

Measured memory_bytes: 43632
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(x,n) for(int i=x;i<n;i++)
#define REP(y,n) for(int j=y;j<n;j++)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
signed main(){
  string S,order,str;
  int q,a,b;
  char c;
  cin>>S>>q;
  rep(0,q){
    cin>>order;
    if(order=="print"){
      cin>>a>>b;
      rep(a,b+1){
        cout<<S[i];
      }
      cout<<endl;
    }
    else if(order=="reverse"){
      cin>>a>>b;
      rep(0,(b-a+1)/2){
        c=S[b-i];
        S[b-i]=S[i+a];
        S[i+a]=c;
      }
    }
    else if(order=="replace"){
      cin>>a>>b>>str;
      rep(a,b+1){
        S[i]=str[i-a];
      }
    }
  }
}



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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };


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

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

	int ans = 0;

	FOR(_, 0, 30) { // 2^30 = (1024)^3  
		bool dividable_two = 1;
		FOR(i, 0, N) {
			if (a[i] % 2 == 0) {
				a[i] /= 2;
			}
			else {
				dividable_two = 0;
			}

		}
		if (dividable_two) {
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}


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

int main() {
  bool p[50001];
  int n, c;

  memset(p, 0, sizeof(bool)*50001);
  for (int i=2; i*i<=50000; i++) {
    if (!p[i]) {
      for (int j=i*i; j<=50000; j+=i) {
        p[j] = true;
      }
    }
  }

  while ((cin >> n) && n) {
    c = 0;
    if (!p[n-2]) ++c;
    if (!(n%2)) {
      for (int i=3; (i<<1)<=n; i+=2) {
        if (!p[i] && !p[n-i]) ++c;
      }
    }
    cout << c << endl;
  }

  return 0;
}

Measured memory_bytes: 1216
import math
import os
import random
import re
import sys

def check_non_decreasing_squares(n: int, a: list):
    for i in range(1, n):
        if a[i] != a[i - 1]:
            if a[i] - 1 < a[i - 1]:
                print("No")
                sys.exit(0)
            a[i] -= 1
    print("Yes")

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().rstrip().split()))
    check_non_decreasing_squares(n, a)

Measured memory_bytes: 15340
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxK = 1e5;
lli ans[maxK + 1];

int main()
{
  priority_queue<lli, vector<lli>, greater<lli>> q;
  for (int i = 1; i <= 9; i ++) q.push(i);
  int d = 0;
  while (!q.empty() && d <= maxK)
  {
    lli u = q.top(); q.pop();
    ans[d++] = u;
    int b = u % 10;
    if (q.size() <= maxK)
    {
      for (int j = -1; j <= 1; j++)
        if (b + j >= 0 && b + j <= 9)
          q.push(u * 10 + b + j);
    }
  }

  lli k;
  while (scanf("%lld", &k) != EOF)
    printf("%lld\n", ans[k - 1]);

  return 0;
}

Measured memory_bytes: 1908
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> B(N - 1);
    REP(i, N - 1) { cin >> B.at(i); }
    // cout << "ok" << endl;
    int ans = B[0] + B[N - 2];
    REP(i, N - 2) { ans += min(B[i], B[i + 1]); }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
using namespace std;
vector<string>v;
void permute(string a, int l, int r)  
{  
    // Base case  
    if (l == r)  
         v.push_back(a);
    else
    {  
        // Permutations made  
        for (int i = l; i <= r; i++)  
        {  
  
            // Swapping done  
            swap(a[l], a[i]);  
  
            // Recursion called  
            permute(a, l+1, r);  
  
            //backtrack  
            swap(a[l], a[i]);  
        }  
    }  
}  

int main(){

ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s,t;
    cin>>s>>t;
    t=t+s;
    cout<<t;
    
}

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

console.log(main());
function main(){
  var n = o.a();
  var m = o.a();
  var a = o.l().sort((a,b)=>a-b);
  var b = o.m(m);
  b.sort((a,b)=>b[1]-a[1]);
  var x = 0;
  for(var i = 0; i < m; i++){
    for(var j = 0; j < b[i][0] && x < n; x++, j++){
      if(a[x] < b[i][1])a[x] = b[i][1];
      else return a.reduce((a,b)=>a+b);
    }
  }
  return a.reduce((a,b)=>a+b);
}

Measured memory_bytes: 71844