akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <cmath>
#include <vector>
using namespace std;
typedef long long ll;
struct
{
    int p,x;
} dr[123];;
int main()
{
#ifdef LOCAL
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
#endif // LOCAL

    int n;
    scanf("%d",&n);
    int t[123];
    for(int i=1;i<=n;i++)
        scanf("%d",&t[i]);
    int m;
    scanf("%d",&m);
    memset(dr,0,sizeof dr);
    for(int i=1;i<=m;i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        dr[i].p=a;
        dr[i].x=b;
    }
    int all=0;
    for(int i=1;i<=n;i++)
        all+=t[i];
//    printf("all=%d\n",all);
    int sum[123];
    for(int i=1;i<=n;i++)
    {
        sum[i]=all-t[i];
//        printf("sum[%d]=%d\n",i,sum[i]);
    }
    for(int i=1;i<=m;i++)
    {
        printf("%d\n",sum[dr[i].p]+dr[i].x);
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	double a[n];
	for(int i=0;i<n;i++)
	{
		double x;
		cin>>x;
		a[i]=1/x;
	}
	long double sum=0;
	long double ans;
	for(int i=0;i<n;i++)
	{
		sum+=a[i];
	}
	ans=1/sum;
	cout<<ans<<"\n";

	/*for(int i=0;i<n;i++)
	{
		cout<<a[i]<<"\n";
	}*/
}



Measured memory_bytes: 256
N,K=list(map(int,input().split()))
l=list(map(int,input().split()))
roop=[1]
s=set([1])
now=l[0]
while now not in s:
   roop.append(now)
   s.add(now)
   now=l[now-1]
start=roop.index(now)
if len(roop) <= K:
   K-=start
   K=K%(len(roop)-start)
   print(roop[start+K])
else:
   print(roop[K])

Measured memory_bytes: 32328
//The Doc

#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
typedef long long int ll;
typedef unsigned long long int ull;
#define fi first
#define se second
#define pb push_back
ll mod1=pow(10,9)+7;
int mod2=998244353;
ll inf=1e9;
ll maxxy=1e6+9;
typedef long double ld;
const double PI =  3.141592653589793238;

ll power(ll x, ll y, ll pp)
{
    ll res = 1;
    x = x % pp;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % pp;
        y = y>>1;
        x = (x*x) % pp;
    }
    return res;
}

ll modInverse(ll n, ll pp)
{
    return power(n, pp-2, pp);
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    string t;
    cin>>s>>t;
    ll n=s.size();
    ll m=t.size();
    ll ans=1e9+7;
    for (int i = 0; i <=n-m ; ++i) {
        ll cur=0;
        for (int j = i; j <i+m ; ++j) {
            if(s[j]!=t[j-i]){
                cur++;
            }
        }
        ans=min(ans,cur);
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;

int imos[100010];
vector<ll> ans(100010, 0);

template <class T> class Single_vector_csv {
private:
    vector<T> single_v;
public:
    Single_vector_csv(const vector<T> &v);
    void write(int n);
};

template <class T> Single_vector_csv<T>::Single_vector_csv(const vector<T> &v) {
    copy(v.begin(), v.end(), back_inserter(single_v));
}

template <class T> void Single_vector_csv<T>::write(int n) {
    ofstream wFile;
    wFile.open("test.csv", ios::trunc);
    int m = single_v.size();
    n = min(m, n);
    wFile << "index" << ",";
    for (int i = 0; i < n; ++i) wFile << i << ",";
    wFile << endl;
    wFile << "value" << ",";
    for (int i = 0; i < n; ++i) wFile << single_v[i] << ",";
    wFile << endl;
}

int main(int argc, char const *argv[]) {
    int n, C;
    cin >> n >> C;
    vector<int> s(n);
    vector<int> t(n);
    vector<int> c(n);
    REP(i,n) cin >> s[i] >> t[i] >> c[i];
    for (int i = 1; i <= C; ++i) {
        REP(j,100010) imos[j] = 0;
        REP(j,n) if(c[j] == i) imos[s[j]-1]++, imos[t[j]]--;
        for (int j = 1; j < 100010; ++j) imos[j] += imos[j-1];
        REP(j,100010) if (imos[j] > 0) ans[j]++;
    }
    //Single_vector_csv<ll> csv(ans);
    //csv.write(*max_element(t.begin(), t.end()));
    cout << *max_element(ans.begin(), ans.end()) << endl;
    return 0;
}

Measured memory_bytes: 2560
import java.util.Scanner;
import java.util.TreeMap;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        TreeMap<String,TreeMap<Integer,Integer>> tree = new TreeMap<>();
        for (int i=0;i<n;i++){
            String s = sc.next();
            int p = sc.nextInt();
            if (!tree.containsKey(s)){
                tree.put(s,new TreeMap<>());
            }
            tree.get(s).put(p,i+1);
        }
        while (!tree.isEmpty()){
            TreeMap<Integer,Integer> t = tree.pollFirstEntry().getValue();
            while (!t.isEmpty()){
                System.out.println(t.pollLastEntry().getValue());
            }
        }
    }
}

Measured memory_bytes: 36168
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
using namespace std;
#define int long long

const int N = 55;
const int MAXV = 105;
int dp[N][N * MAXV];

signed main() {
  int n, p;
  cin >> n >> p;

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

  dp[0][0] = 1LL;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < N * MAXV; j++) {
      if(j - a[i] >= 0) {
        dp[i][j] += dp[i - 1][j - a[i]];
      }
      dp[i][j] += dp[i - 1][j];
    }
  }

  int ans = 0;
  for (int i = 0; i < N * MAXV; i++) {
    if(i % 2 == p % 2) ans += dp[n][i];
  }

  cout << ans << '\n';
}



Measured memory_bytes: 5896
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes                \
    cout << "Yes" << endl; \
    return 0;
#define No                \
    cout << "No" << endl; \
    return 0;
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template <typename T>
void print(const T &v);

int main()
{
    ll A, B;
    cin >> A >> B;
    if (A == B)
    {
        cout << A << endl;
        return 0;
    }
    ll a_after = ((A + 3) / 4) * 4;
    ll b_before = (B / 4) * 4;
    ll ans = 0;
    for (ll i = A; i < a_after; i++)
    {
        ans ^= i;
    }
    for (ll i = b_before; i <= B; i++)
    {
        ans ^= i;
    }

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

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


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

// 方針: (解いた問題数, 所要時間 + ペナルティ, チームのid)の配列もって降順ソート
// 所要時間は、(A問題を解いた時の時間) + (B問題を解いた時の時間) + .... と考えている
// 上から出力する

using pii = pair<int, int>;

int main()
{
    while (true)
    {
        int M, T, P, R;
        cin >> M >> T >> P >> R;
        if (M == 0)
            break;

        // List.first.first := 解いた問題数
        // List.first.second := 所用時間 + penalty
        // List.second := チームのid
        vector<pair<pii, int>> List(T);
        // 初期化
        for (int i = 0; i < T; ++i)
        {
            List[i] = make_pair(make_pair(0, 0), i);
        }

        // penalty[i][j] := チームiがj問題をWAした回数
        vector<vector<int>> penalty(T, vector<int>(P, 0));

        while (R--)
        {
            int m, t, p, j;
            cin >> m >> t >> p >> j;
            --t, --p;
            if (j == 0)
            { // ACなら
                List[t].first.first++;
                List[t].first.second += m;
                // 間違えた回数だけペナルティを加算
                List[t].first.second += penalty[t][p] * 20;
            }
            else
            { // WAなら
                // ペナルティを記録する
                penalty[t][p]++;
            }
        }

        auto cmp = [](pair<pii, int> &A, pair<pii, int> &B) -> bool {
            return (A.first.first > B.first.first) ||
                   (A.first.first == B.first.first && A.first.second < B.first.second) ||
                   (A.first.first == B.first.first && A.first.second == B.first.second && A.second > B.second);
        };
        sort(List.begin(), List.end(), cmp); // 降順ソート

        // デバッグ
        /*
        for (auto &p : List)
        {
            cout << p.first.first << " " << p.first.second << " " << p.second + 1 << endl;
        }
        cout << endl;
        */
        // 結果を出力
        int cnt = 0; // 出力したチームの数
        //stack<pair<pii, int>> Task; // 同順位を格納するためのスタック
        //vector<vector<int>> Rank; // Rank[i] := i位のチームの配列
        for (int i = 0; i < T; ++i)
        {
            if (i == 0)
            {
                cout << List[i].second + 1;
                continue;
            }
            if (List[i - 1].first != List[i].first)
            {
                // カンマを出力
                cout << "," << List[i].second + 1;
            }
            else
            {
                // 「=」を出力
                cout << "=" << List[i].second + 1;
            }
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3144
#include<iostream>
#include<string>
#include<vector>


using namespace std;

int main(){
  int N,Q; cin >> N >> Q;
  string S; cin >> S;
  vector<int> l(Q),r(Q);
  for(int i = 0; i < Q; i++){
    cin >> l[i] >> r[i]; l[i]--; r[i]--;} //0-indexed
   
  vector<int> Sum(N+1,0);
  
  for(int i = 1; i < N; i++){
    if(S[i-1] == 'A' && S[i] == 'C'){ Sum[i] = Sum[i-1] + 1;}
    else{ Sum[i] = Sum[i-1];}}
  
  for(int i = 0; i < Q; i++){
    cout << Sum[r[i]] - Sum[l[i]] << endl;
  }
  return 0;}

Measured memory_bytes: 2176
#include <stdio.h>
#define EMPTY -111//何もいない状態
#define HERE 100//Queenがいる状態
#define N 8//N×Nの盤面
#define KOSHIN 3180

void putQueen(int);
void printBoard(void);

int row[N];//横
int col[N];//縦
int dpos[N*2];//左斜め下 dpos = i + j (i -> 行、j -> 列)
int dneg[N*2];//右斜め下 dneg = i - j + (N - 1)
int judge[N][N];

int main(){

  int k = 0, r = 0, c = 0;
  int i = 0;

  //盤面の初期化
  for(i = 0; i < N; i++){

    row[i] = col[i] = EMPTY;
    
  }

  for(i = 0; i < N*2; i++){

    dneg[i] = dpos[i] = EMPTY;
    
  }

  //盤面に駒をおいていく
  scanf("%d",&k);

  for(i = 0; i < k; i++){

    scanf("%d%d",&r,&c);
    row[r] = c;
    col[c] = dpos[r+c] = dneg[r-c+N-1] = HERE;
    judge[r][c] = KOSHIN;
  }

  //ここで被らないようにQをおいていく
  putQueen(0);
  
  return 0;
  
}

void putQueen(int i){

  int j = 0;
  
  if(i == N){//終了条件
  
    printBoard();
    return;
    
  }
  
  for(j = 0; j < N; j++){

    if(judge[i][j] == KOSHIN){
    }
    else if(col[j] == HERE || dpos[i+j] == HERE || dneg[i-j+N-1] == HERE){
      continue;
    }
    
    //put a queen at(i, j)
    row[i] = j;
    col[j] = dpos[i+j] = dneg[i-j+N-1] = HERE;
  
    //try the next row
    putQueen(i+1);
    
    //remove the queen at (i, j)for backtracking
    if(judge[i][j] == KOSHIN);
    else col[j] = dpos[i+j] = dneg[i-j+N-1] = EMPTY;
    
  }
  
}

void printBoard(void){

  int i = 0, j = 0;
  
  for(i = 0; i < N; i++){

    for(j = 0; j < N; j++){

      if(col[j] == HERE && row[i] == j)printf("Q");
      else printf(".");

    }

    printf("\n");
    
  }
  
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define FIXED_FLOAT(x)  std::fixed <<std::setprecision(7)<<(x)
#define all(v) (v).begin(), (v).end()
using namespace  std;

using ll = long long;
const ll mod = 998244353;
typedef pair<int , int> pairs;
typedef complex<ll> G;
const int N = 1e6+5;

const int INF = 1e9+2;
void  done() {

}
void solve(){
    int red, green, blue;
    cin >> red >> green  >> blue;
    int k;cin >> k;
    while(green <= red) {
        green *= 2;
        k--;
    }
    while(blue <= green) {
        blue *= 2;
        k--;
    }
    cout << (k >= 0 ? "Yes" : "No");

}

void another() {



}
void test_case() {
    int t;
    cin >> t;
    while(t--)another();
}
int main() {

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

    solve();
}


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

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
 
  bool sunuke[N+1] = {false};
  
  for (int i = 0; i <K; i++) {
    int d;
    cin >> d;
    
    for ( int j = 0; j<d; j++) {
      int n;
      cin >> n;
      
      sunuke[n] = true;
    }
  }
  
  int ans = 0;
  for (int i = 1; i < N+1; i++) {
    if (sunuke[i]) {
      continue;
    } else {
      ans++;
    }
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#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++)
using ll = long long;


int main() {


string S;
ll ans=0;
cin >>S;
// cout<<S[0]<<endl;
rep(i,1<<3){
    ans=S[0] - '0';
    rep(j,3){
        if(i&(1<<j)){
            ans+= S[j+1]-'0';
        }
        else{
            ans-= S[j+1] - '0';

        }
    }
    if(ans==7){
        string eq;
        eq="";
        eq+= S[0];
        rep(j,3){
            if(i&(1<<j)){
                eq += '+';
                eq+= S[j+1];

            }
            else{
                eq+= '-';
                eq+= S[j+1];

            }
        }
        eq+= "=7";
        cout<<eq<<endl;
        break;


    }
}

}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Mon May 13 09:24:23 2019

@author: avina
"""

s = input().strip()

k = s[0]
cnt_1 = 0;cnt_2 = 1
for i in range(1,len(s)):
    if k == s[i] and i%2 !=0:
        cnt_1+=1
    
    if i%2 ==0 and k != s[i]:
        cnt_1+=1
if k == '1':
    e = '0'
else :
    e = '1'

for i in range(1,len(s)):
    
    if e != s[i] and i%2 ==0:
        cnt_2 +=1
    
    if e == s[i] and i%2 != 0:
        cnt_2+=1

print(min(cnt_1, cnt_2))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,a,x,y;
    cin>>n;
    std::multimap<int, pair<int,int>> map;
    for (int i=0;i<n;i++) {
        cin>>a;
        for (int j=0;j<a;j++) {
            cin>>x>>y;
            map.emplace(i+1,make_pair(x,y));
        }
    }
    int count=0,ans=0;
    for (int bit=0;bit<(1<<n);bit++) {
        count=0;
        std::deque<int> honest(n+1,0);
        int flag=0;
        for (int i=0;i<n;i++) {
            if (bit&(1<<i)) {
                honest[i+1]=1;
            }
        }
        for (int k=0;k<n+1;k++) {
            if (honest[k]==1) {
                auto p=map.equal_range(k);
                for (auto itr=p.first;itr!=p.second;itr++) {
                    int X=itr->second.first;
                    int Y=itr->second.second;
                    if (Y==1) {
                        if (honest[X]!=1) {
                            flag=1;
                            break;
                        }
                    } else if (Y==0) {
                        if (honest[X]==1) {
                            flag=1;
                            break;
                        }
                    }
                }
                if (flag==1) {
                    break;
                }
            }
        }
        if (flag==0) {
            for (int l=0;l<n+1;l++) {
                if (honest[l]==1) {
                    count++;
                }
            }
            ans=max(ans,count);
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#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 rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
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() {
  string S;
  cin>>S;
  int num = 0;
  for(int i=0;i<S.size();++i) {
    num += S[i]-'0';
    num %= 9;
  }
  if(num==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}



Measured memory_bytes: 3672
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define pb push_back
#define int long long
#define MEM(x) memset(x,0,sizeof(x))
#define vc vector<int>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define inf 0x3f3f3f3f
#define t_case int tt; cin>>tt; while (tt--)
#define lnginf 9223372036854775807
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define For(i,j,k) for (int i=(int)(j);i<(int)(k);i++)
#define rFor(i,j,k) for (int i=(int)(k-1);i>=(int)(j);i--)
#define ins insert
#define in(x); { for (auto &i : x) cin >> i; }
#define out(x); { for (auto i : x) cout<<i<<' ' ; }
#define pi  pair<int,int>
#define ti tuple<int,int,int>
#define PI 3.14159265359
#define des(x) setprecision(x)
const long long LL_INF = (long long) 2e18 + 5;
using namespace std;
//void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
const int N=3e5+10,mod=1e9+7;
int sum(int a,int b){
  int s=a+b;
  if(s>=mod)s-=mod;
  return s;
}
int mult(int a, int b) {
    return (1LL * a * b) % mod;
}
int sub(int a, int b) {
    int s = a - b;
    if (s < 0) s += mod;
    return s;
}

void solve(){
  int n; cin>>n;
  vector<int> v(n),pre(n);
  For(i,0,n){
    cin>>v[i];
    if(!i)pre[i]=v[i];
    else pre[i]=sum(pre[i-1],v[i]);
  }
  int s=0;
  For(i,0,n-1){
    s=sum(s,mult(v[i],sub(pre[n-1],pre[i])));
  }
  cout<<s<<'\n';
  
}
int32_t main() {

#ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
#endif
   fastio
   //t_case
    solve();



}

Measured memory_bytes: 6360
// a template for main.cpp
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k, a, d;
    cin >> n >> k;
    bool ok[101];
    memset(ok, false, sizeof(ok));
    for (int i = 0; i < k; i++) {
        cin >> d;
        while (d--) {
            cin >> a;
            ok[a] = true;
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (!ok[i]) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;    

#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))    
#define OUT(P) cout << (P) << endl    
#define OUT2(P1, P2) cout << (P1) << " " << (P2) << endl    
#define PRINT_ARRAY(P) for(int i=0; i<P.size(); i++) cout << P[i] << endl;    
#define PRINT_ARRAY_INLINE(P) do { for(int i=0; i<P.size(); i++) cout << P[i] << " "; cout << endl; } while(0)    
#define PRINT_ARRAY_WITH_LABEL(L, P) do { cout << L << ": "; PRINT_ARRAY_INLINE(P); cout << endl; } while(0)    
typedef long long ll;    
const long DIVIDE = 1e9+7;

int sum_digits(int num);    
template <class T>    
vector<T> copy_vector(vector<T> vec);    
long gcd(long a, long b);    
long lcm(long a, long b);
// ****** print functions ****** //
template <class T, class U>
void print_pairs(const vector<pair<T, U>> pairs);
template <class K, class V>
void print_map(const map<K, V> m);


int main() {    
    string s;
    cin >> s;
    vector<string> candidates{"dream", "dreamer", "erase", "eraser"};
    for(int i=0; i<candidates.size(); i++) {
        reverse(candidates[i].begin(), candidates[i].end());
    }
    reverse(s.begin(), s.end()); 
    int itr = 0;
    while(itr < s.size()) {
        bool changed = false;
        for(int i=0; i<candidates.size(); i++) {
            string cand = candidates[i];
            string tmp = s.substr(itr, cand.size());
            //cout << "cand: " << cand << endl;
            //cout << "tmp: " << tmp << endl;
            if(cand == tmp) {
                itr += cand.size();
                changed = true;
            }
        }
        if(!changed) break;
    }
    string ans = (itr == s.size())? "YES" : "NO";
    cout << ans << endl;
    return 0;    
}    

/******************************/    
/***** DECRARED FUNCTIONS *****/    
/******************************/    

int sum_digits(int num) {    
    int rtn = 0;    
    while(num != 0) {    
        int tmp = num % 10;    
        rtn += tmp;    
        num /= 10;    
    }    
    return rtn;    
}    

// vectorのコピー    
template <class T>    
vector<T> copy_vector(vector<T> vec) {    
    vector<T> rtn;    
    rtn.reserve(vec.size());    
    copy(vec.begin(), vec.end(), back_inserter(rtn));    
    return rtn;    
}    

long gcd(long a, long b) {    
    if(b==0) return a;    
    else return gcd(b, a % b);    
}

long lcm(long a, long b) {
    long gcd_ = gcd(a, b);
    return (a * b) / gcd_;
}

template <class T, class U>
void print_pairs(const vector<pair<T, U>> &pairs) {
    for(int i=0; i<pairs.size(); i++) { 
        cout << "(" << pairs[i].first << ", " << pairs[i].second << ")" << " "; 
    } 
    cout << endl;
}

template <class K, class V>
void print_map(const map<K, V> &m) {
    for(auto it=m.cbegin(); it!=m.cend(); it++) {
        cout << it->first << ": " << it->second << endl;
    }
}


Measured memory_bytes: 512
n = int(input())
num = dict()
for i in range(n):
    s = input()
    if s in num:
        num[s] += 1
    else:
        num[s] = 1
num_s = sorted(num.items(), key=lambda x:x[1],reverse=True)
max_num = max(num.values())
ans = []
for i in range(len(num_s)):
    if num_s[i][1] == max_num:
        ans.append(num_s[i][0])
ans.sort()
for i in range(len(ans)):
    print(ans[i])


Measured memory_bytes: 45788
#include<bits/stdc++.h>
#define int long long
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define INF (1ll<<60)
typedef pair<int, int> pii;
#define FI first
#define SE second
#define l_b lower_bound
#define u_b upper_bound
#define pb push_back
#define all(s) s.begin(),s.end()

signed main() {
	int X;
	cin >> X;
	int s = 0;
	int i = 0;
	for (; i < X; ++i) {
		s += i;
		if (s >= X)
			break;
	}
	cout << i << endl;
}


Measured memory_bytes: 256
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
int A,B;
int main() {
	cin>>A>>B;
	int S=A+B;
	S=max(S,max(A-B,A*B));

	cout<<S<<endl;


	return 0;
}


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

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")


#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
using namespace __gnu_pbds;

using ll = long long;

using namespace std;

signed main() {
    int N;cin >> N;
    vector<int> A;
    vector<vector<pair<int, int>>> v;
    for(int i = 0;i < N;i++){
        int a;cin >> a;
        A.push_back(a);
        vector<pair<int, int>> w;
        for(int i = 0; i < a;i++){
            int x,y;cin >> x >> y;
            w.push_back({x, y});
        }
        v.push_back(w);
    }
    vector<int> bits(N);
    auto a = [&](){
        for(int i = 0;i < N;i++){
            if(bits[i])
                for(int j = 0;j < A[i];j++){
                    if(bits[v[i][j].first - 1] != v[i][j].second){
                        return false;
                    }
                }            
        }
        return true;
    };
    ll ans = 0;
    function<void(int)> f = [&](int i){
        if(i == N){
            if(a()){
               ans = max(ans, ll(count(bits.begin(), bits.end(), 1))); 
            }
            return;
        }
        bits[i] = 1;f(i + 1);
        bits[i] = 0;f(i + 1);
    };
    f(0);
    cout<<ans<<endl;
}




Measured memory_bytes: 3584
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    def f(n,m,cap):
        cap *= 10
        s,t = LS()
        e = collections.defaultdict(list)
        for _ in range(n):
            a,b,c = LS()
            c = int(c)
            e[a].append((b,c))
            e[b].append((a,c))
        cs = set([S() for _ in range(m)])

        def search(s,t):
            d = collections.defaultdict(lambda: inf)
            d[(s,cap)] = 0
            q = []
            heapq.heappush(q, (0, (s,cap)))
            v = collections.defaultdict(bool)
            while len(q):
                k, u = heapq.heappop(q)
                if v[u]:
                    continue
                v[u] = True
                if u[0] == t:
                    return k

                for uv, ud in e[u[0]]:
                    uc = u[1] - ud
                    if uc < 0:
                        continue
                    if uv in cs:
                        uc = cap
                    uv = (uv, uc)
                    if v[uv]:
                        continue
                    vd = k + ud
                    if d[uv] > vd:
                        d[uv] = vd
                        heapq.heappush(q, (vd, uv))

            return None

        r = search(s,t)
        if r is None:
            return -1

        return r

    while 1:
        n,m,l = LI()
        if n == 0:
            break
        rr.append(f(n,m,l))
        # print('rr', rr[-1])

    return '\n'.join(map(str,rr))


print(main())



Measured memory_bytes: 869504
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007
flush = sys.stdin.flush()

def solve():
    x,y = LI()
    ans = 0
    f = [300000,200000,100000,0]
    if x == 1 and y == 1:
        print(1000000)
    else:
        ans = f[min(3,x-1)]+f[min(3,y-1)]
        print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 39664
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N int
	fmt.Scan(&N)
	a := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&a[i])
	}
	sort.Sort(sort.IntSlice(a))
	var w float64
	w = float64(a[0]+a[1]) / 2
	for i := 2; i < N; i++ {
		w = (w + float64(a[i])) / 2
	}
	fmt.Println(w)
}

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

using namespace std;
typedef long long ll;

int n, k;
int a[111];
int dp[100100];
int f(int rem)
{
    int &ret = dp[rem];
    if (~ret) return ret;
    set < int > st;
    for (int i = 0; i < n; ++i)
        if (a[i] <= rem)
            st.insert(f(rem-a[i]));
    int cnt = 0;
    while (st.find(cnt) != st.end())
    {
        ++cnt;
    }
    return ret = cnt;
}

int fIter()
{
    for (int i = 1; i <= k; ++i)
    {
        set <int> st;
        for (int j = 0; j < n; ++j)
        {
            if (a[j] <= i)
            {
                st.insert(dp[i-a[j]]);
            }
        }
        while (st.find(dp[i]) != st.end())
        {
            ++dp[i];
        }
    }
    return dp[k];
}

int fIterWinLose()
{
    for (int i = 1; i <= k; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            if (a[j] <= i)
            {
                dp[i] |= !dp[i-a[j]];
            }
        }
    }
    return dp[k];
}

int main()
{
//    memset(dp, -1, sizeof dp);

    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; ++i)
        scanf("%d", &a[i]);
    printf("%s\n", !fIterWinLose() ? "Second" : "First");

    return 0;
}


Measured memory_bytes: 640
/*
		Author : Kaustubh Gangwar
		||S||A||M||R||A||T||
*/
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ld long double
#define pb push_back
#define gcd __gcd
#define mp make_pair
#define vii vector<int>
#define vll vector<long long>
#define all(x) x.begin(),x.end()
#define f(i,a,b) for(int i=a;i<b;i++)
#define fe(i,a,b) for(int i=a;i<=b;i++)
typedef long long  ll;
typedef pair<int,int> pii;

ll bpow(ll a, ll b) {
	a=a;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

int main()
{	ios_base::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	
	ll n;
	cin>>n;
	cout<<n+bpow(n,2)+bpow(n,3);
		
		
	
return 0;
}


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

int main()
{
    int n, m;

    cin >> n >> m;

    int a[n+1], x[m], y[m], cnt = m;
    for( int i = 0; i < n + 1; i++ )
        a[i] = 0;

    for( int i = 0; i < m; i++ )
    {
        cin >> x[i] >> y[i];
        for( int j = x[i]; j <= y[i]; j++ )
            a[j]++;
    }

    for( int i = 1; i <= n; i++ )
        if( a[i] == 0 )
        {
            cout << "Impossible" << endl;
            return 0;
        }

    for( int i = 0; i < m; i++ )
        for( int j = m - 1; j > i; j-- )
            if( y[j] - x[j] < y[j-1] - x[j-1] )
            {
                int tx = x[j], ty = y[j];
                x[j] = x[j-1]; y[j] = y[j-1];
                x[j-1] = tx; y[j-1] = ty;
            }

    for( int i = 0; i < m; i++ )
    {
        bool judge = true;
        for( int j = x[i]; j <= y[i]; j++ )
            if( a[j] <= 1 )
            {
                judge = false;
                break;
            }
        if( judge )
        {
            for( int j = x[i]; j <= y[i]; j++ )  
                a[j]--;
            cnt--;
        }
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3096
require 'set'

loop do
  n, m, s = gets.split.map(&:to_i)
  break if n == 0

  points = (1..n).map { gets.split.map(&:to_i) }

  if m == 1
    puts 6 * s * s
    next
  end

  g = {}
  (0..n-1).to_a.combination(2) do |i, j|
    x1, y1, z1 = points[i]
    x2, y2, z2 = points[j]
    lx = [x1, x2].min + s - [x1, x2].max
    ly = [y1, y2].min + s - [y1, y2].max
    lz = [z1, z2].min + s - [z1, z2].max
    if lx > 0 && ly > 0 && lz > 0
      decrease = 2 * (lx * ly + ly * lz + lz * lx)
      g[i] ||= {}
      g[i][j] = decrease
      g[j] ||= {}
      g[j][i] = decrease
    end
  end

  connected_group = []
  reached = Set.new
  (0..n-1).each do |i|
    next if reached.include?(i)
    reached << i
    connected_group << [i]
    queue = [i]
    until queue.empty?
      j = queue.shift
      if g[j]
        g[j].each_key do |k|
          next if reached.include?(k)
          reached << k
          connected_group[-1] << k
          queue << k
        end
      end
    end
  end

  connected_group.select! {|group| group.size >= m }
  if connected_group.empty?
    puts -1
    next
  end

  max_dec = 0
  connected_group.each do |group|
    i = group.find {|i| g[i].size == 1 }
    decs = []
    dec = 0
    if i
      j = g[i].keys[0]
      (m - 1).times do
        decs << g[i][j]
        dec += g[i][j]
        i, j = j, g[j].keys.select {|k| k != i }[0]
      end
      max_dec = dec if dec > max_dec
      (group.size - m).times do
        dec -= decs.shift
        decs << g[i][j]
        dec += g[i][j]
        max_dec = dec if dec > max_dec
        i, j = j, g[j].keys.select {|k| k != i }[0]
      end
    else
      i = group[0]
      j = g[i].keys[0]
      (m - 1).times do
        decs << g[i][j]
        dec += g[i][j]
        i, j = j, g[j].keys.select {|k| k != i }[0]
      end
      if group.size == m
        dec += g[i][j]
        max_dec = dec if dec > max_dec
      else
        max_dec = dec if dec > max_dec
        (group.size - 1).times do
          dec -= decs.shift
          decs << g[i][j]
          dec += g[i][j]
          max_dec = dec if dec > max_dec
          i, j = j, g[j].keys.select {|k| k != i }[0]
        end
      end

    end
  end
  p m * 6 * s * s - max_dec
end



Measured memory_bytes: 7060
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)

int N, A[1 << 18];
int minx = (1 << 30), minid = 0;

int main() {
	scanf("%d", &N);
	for (int i = 1; i <= N; i++) {
		scanf("%d", &A[i]);
		if (minx > A[i]) { minx = A[i]; minid = i; }
	}
	cout << minid << endl;
	return 0;
}


Measured memory_bytes: 3544
#include<iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
	int a, b, c, d; cin >> a >> b >> c >> d;
	if (a + b > c + d) cout << "Left" << endl;
	else if (a + b == c + d) cout << "Balanced" << endl;
	else cout << "Right" << endl;
	return 0;
}

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

int main()
{
    int H, N;
    cin>>H>>N;
    vector<int> A(N), B(N);
    for (int i=0; i<N; i++)
        cin>>A[i]>>B[i];

    vector<int> T(H+1, 100000000);
    T[H] = 0;
    for (int h=H; h>0; h--)
        for (int i=0; i<N; i++)
        {
            int t = max(0, h-A[i]);
            T[t] = min(T[t], T[h]+B[i]);
        }
    cout<<T[0]<<endl;
}


Measured memory_bytes: 888
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#define mid ((l + r) / 2)
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
const double pi = acos(-1.0);

const int maxn = 200 + 5;
int n, l, value[maxn], sum;

ll a, b, c, d;

ll GCD(ll num1, ll num2) {
    if(num1 % num2 == 0) return num2;
    else return GCD(num2, num1 % num2);
}

ll LCM(ll x, ll y) {
    ll tem;
    tem = x * y / GCD(x, y);
    return tem;
}

int main() {
    ios_base :: sync_with_stdio(false);
    cin >> a >> b >> c >> d;
    ll Min1 = a / c, Min2 = a / d, Max1 = b / c, Max2 = b / d, Mli = b / LCM(c, d), Mili = a / LCM(c, d);
    ll cnt = Max1 + Max2 - Min1 - Min2 - Mli + Mili;
    if(a % c == 0 || a % d == 0) {
        cnt ++;
    }
    cout << b - a + 1 - cnt << endl;
    return 0;
}

Measured memory_bytes: 256
//https://discuss.codechef.com/t/robagain-editorial/20734
#pragma GCC optimize("O3")
#include<queue>
#include <cmath>
#include <complex>
#include<map>
#include <string>
#include<iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <string>
#include <iostream>
#include <stdio.h>
#include<bits/stdc++.h>


/*
#define x real()
#define y imag()
#define angle(a)                (atan2((a).imag(), (a).real()))
#define vec(a,b)                ((b)-(a))
#define same(p1,p2)             (dp(vec(p1,p2),vec(p1,p2)) < EPS)
#define dp(a,b)                 ( (conj(a)*(b)).real() )	// a*b cos(T), if zero -> prep
#define cp(a,b)                 ( (conj(a)*(b)).imag() )	// a*b sin(T), if zero -> parllel
#define length(a)               (hypot((a).imag(), (a).real()))
#define normalize(a)            (a)/length(a)
//#define polar(r,ang)            ((r)*exp(point(0,ang)))  ==> Already added in c++11
#define rotateO(p,ang)          ((p)*exp(point(0,ang)))
#define rotateA(p,ang,about)  (rotateO(vec(about,p),ang)+about)
#define reflectO(v,m)  (conj((v)/(m))*(m))
*/

//#define pi 3.141592654
#define forr(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define input ios_base::sync_with_stdio(0);cin.tie(0);
#define NOT(x) (1^x)

const double PI  = acos(-1.0);
using namespace std;
typedef pair<double,double>pdd;
typedef long long  ll;
typedef pair<ll, ll>pii;
typedef complex<double> point;

//int x[8]={1,0,0,-1,-1,-1,1,1};
//int y[8]={0,1,-1,0,-1,1,-1,1};
//const int N=500009,M=1000000;
const double EPS= 1e-9,eps=-1e9;
const int N =500005;

int n,a[100];
 int main()
{
//freopen("travel.in","r",stdin);
//freopen("travel.out","w",stdout);
//__builtin_popcount()
input;


      cin>>n;
      forr(i,1,n)cin>>a[i];
      ll ans=0;

      forr(i,1,n-1)
      forr(j,i+1,n)ans+=a[i]*a[j];

      cout<<ans;


return 0;
}


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

int main(){
    int n, m;
    cin >> n >> m;
    priority_queue<int> as;
    for(int i=0;i<n;++i){
        int a;
        cin >> a;
        as.push(a);
    }
    for(int i=0;i<m;++i){
        int a = as.top();
        as.pop();
        as.push(a/2);
    }
    int64_t ans = 0;
    while(!as.empty()){
        ans += as.top();
        as.pop();
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 892
#include <string>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <stdlib.h>
#include <algorithm>
#include <list>
#include <math.h>
#include<string.h>
#define reps(i,j,k) for(int i=(j);i<(k);i++)
#define rep(i,j) reps(i,0,j)

//	rep(i,10)cout << i << endl;
using namespace std;

int main(void){
	string s;
	cin >> s;
	rep(i,s.size()-8) cout<<s[i];
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	string a,b;
	cin>>a;
	cin>>b;
	for(int i=0;i<n;i++)
	{
		cout<<a.at(i)<<b.at(i);
	
	}




}

Measured memory_bytes: 256
"""
abc179_B
"""
n = int(input())
ans = 'No'

a = [input().split() for i in range(n)]

for i in range(0,n-2):
    if a[i][0]== a[i][1] and a[i+1][0] == a[i+1][1] and a[i+2][0] == a[i+2][1]:
        ans = 'Yes'
        break

print(ans)

Measured memory_bytes: 9192
import sys
import itertools


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, input().rstrip('\n').split()))
    ks = [list(map(int, input().rstrip('\n').split())) for _ in range(m)]
    p = list(map(int, input().rstrip('\n').split()))
    cnt = 0
    for v in itertools.product([True, False], repeat=n):
        b = True
        for i in range(m):
            t = 0
            for kv in ks[i][1:]:
                t += v[kv-1]
            if t % 2 != p[i]:
                b = False
                break
        if b:
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 39792
def solve():
    from sys import stdin
    f_i = stdin
    
    def f(bm_i, bw_i):
        if bm_i > bw_i:
            d = bm_i - bw_i
        else:
            d = bw_i - bm_i
        return d * (d - 30) ** 2
    
    while True:
        M, W = map(int, f_i.readline().split())
        if M == 0:
            break
        
        bm = list(map(int, f_i.readline().split()))
        bw = list(map(int, f_i.readline().split()))
        
        e_gen = [[f(m, w) for w in bw] for m in bm]
        
        bit_size = (1 << W)
        dp1 = [-1] * bit_size
        dp2 = [-1] * bit_size
        dp1[0] = 0
        dp2[0] = 0
        add_bit = [1 << i for i in range(W)]
        
        for i in range(M):
            for s1, e1 in enumerate(dp1):
                if e1 == -1:
                    continue
                for b, e in zip(add_bit, e_gen[i]):
                    if s1 & b:
                        continue
                    s2 = s1 | b
                    e2 = e1 + e
                    if e2 > dp2[s2]:
                        dp2[s2] = e2
            dp1 = dp2[:]
        print(max(dp2))

solve()


Measured memory_bytes: 5948
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;

int main(void){

    int n;
    cin >> n;

    int a[3000];

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

    int f=0;
    for(int i=0;i<n;i++){
        f += a[i]-1;
    }
    
    cout<<f<<endl;
}

Measured memory_bytes: 256
module Main (main) where

import Control.Monad
import Control.Monad.Trans.State
import Data.ByteString (ByteString)
import qualified Data.ByteString.Unsafe as B
import qualified Data.ByteString.Char8 as C8
import Data.Bool
import Data.Char
import Data.List
import Data.Maybe
import qualified Data.Array as Array

main :: IO ()
main = do
  (n,m) <- readPair
  xs <- replicateM m readInts
  mapM_ print $ solve n xs

solve :: Int -> [[Int]] -> [Int]
solve n = Array.elems . Array.accumArray f 0 (1,n) . flip zip [1..] . concat
  where
    f acc _ = acc + 1

-- utils
readInts :: IO [Int]
readInts = map (fst . fromJust . C8.readInt) . C8.words <$> C8.getLine

readPair :: IO (Int, Int)
readPair = head . unfoldr readT <$> C8.getLine
  where
    readT = runStateT $
      (,) <$> StateT (C8.readInt . C8.dropWhile isSpace)
          <*> StateT (C8.readInt . B.unsafeTail)

data Answer
  = YesNo Bool
  | YESNO Bool
  | AB Bool
  | Number Int
  | String String
  | ByteString ByteString
  | Compare Ordering
  | Compare2 Ordering

instance Show Answer where
  show (YesNo b)       = bool "No" "Yes"  b
  show (YESNO b)       = bool "NO" "YES"  b
  show (AB b)          = bool "B"  "A"    b
  show (Number i)      = show i
  show (String s)      = s
  show (ByteString bs) = C8.unpack bs
  show (Compare o)     = ordering "<" "=" ">" o
  show (Compare2 o)    = ordering "Right" "Balanced" "Left" o

ordering :: a -> a -> a -> Ordering -> a
ordering lt eq gt o = case o of
  LT -> lt
  EQ -> eq
  GT -> gt

-- | k 番目の文字に関数 f を適用する
indexMapBS :: Int -> (Char -> Char) -> ByteString -> ByteString
indexMapBS k f s = C8.concat [s1, C8.singleton (f c), s3]
  where
    (s1, s2) = C8.splitAt (k-1) s
    c = C8.head s2
    s3 = C8.tail s2

Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n;ll a[105];
ll dp[100005][3];
ll func(ll k,ll b)
{
	//cout<<k<<" "<<b<<endl;
	if(k==0)
		return !b;
	else if(k<0)
		return b;
	if(dp[k][b]!=-1)
		return dp[k][b];
	for(ll i=1;i<=n;i++)
	{
		if(func(k-a[i],!b)==b)
		{
			dp[k][b]=b;
			return dp[k][b];
		}
	}
	dp[k][b]=!b;
	return dp[k][b];
}
int main()
{
	ll k,i;
	cin>>n>>k;
	for(i=1;i<=n;i++)
		cin>>a[i];
	for(i=0;i<=k;i++)
		dp[i][0]=dp[i][1]=-1;
	if(func(k,1))
		cout<<"First"<<endl;
	else
		cout<<"Second"<<endl;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
int dist[220][220];
const int INF = 1001001001;
signed main(){
    int n,m,r;cin >> n >> m >> r;
    int rs[r];
    rep(i,r){
        cin >> rs[i];
        rs[i]--;
    }
    sort(rs,rs+r);
    rep(i,n)rep(j,n)dist[i][j] = INF;
    rep(i,m){
        int a,b,c;cin >> a >>b >>c;
        a--;b--;
        dist[a][b] = dist[b][a] = c;
    }
    rep(i,n)rep(j,n)rep(k,n)dist[j][k] = min(dist[j][k],dist[j][i] + dist[i][k]);
    int ans = 1001001001001ll;
    do{
        int ret = 0;
        
        rep(i,r-1){
            int from = rs[i],to = rs[i+1];
            ret += dist[from][to];
        }
        ans = min(ans,ret);
    }while(next_permutation(rs,rs+r));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string.h>
#include<queue>

using namespace std;

typedef pair<int,int> P;

bool wall[30][30][4];
int dis[30][30];
int dx[4] = {1,0,-1,0},dy[4] = {0,-1,0,1};

int main(){
	while(true){
		int n,m;
		cin >> n >> m;
		
		if(n == 0 && m == 0) break;
		
		memset(wall,0,sizeof(wall));
		memset(dis,0,sizeof(dis));
		
		for(int i = 0;i < (m * 2)-1;i++){
			if(i % 2 == 0){
				for(int j = 0;j < n-1;j++){
					int w;
					cin >> w;
					if(w == 1){
						wall[i/2][j][0] = 1;
						wall[i/2][j+1][2] = 1;
					}
				}
			}else{
				for(int j = 0;j < n;j++){
					int w;
					cin >> w;
					if(w == 1){
						wall[i/2][j][3] = 1;
						wall[(i/2)+1][j][1] = 1;
					}
				}
			}
		}
		
		queue<P> que;
		que.push(P(0,0));
		dis[0][0] = 1;
		
		while(que.size()){
			P p = que.front(); que.pop();
			if(p.first == (n-1) && p.second == (m-1)) break;
			for(int i = 0;i < 4;i++){
				int nx = p.first + dx[i],ny = p.second + dy[i];
				if(0 <= nx && nx < n && 0 <= ny && ny < m && dis[ny][nx] == 0 && wall[p.second][p.first][i] == 0){
					que.push(P(nx,ny));
					dis[ny][nx] = dis[p.second][p.first] + 1;
				}
			}
		}
		
		if(dis[m-1][n-1] == 0){
			cout << 0 << endl;
		}else{
			cout << dis[m-1][n-1] << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3104
def resolve():
    import copy
    s = list(input())
    t = list(map(int, s))
    for i in range(8):
        tmp = copy.deepcopy(s)
        d = 0
        ans = t[0]
        for j in range(3):
            if (i // 2**j)%2 == 1:
                tmp.insert(j+d+1, '+')
                ans += t[j+1]
            else:
                tmp.insert(j+d+1, '-')
                ans -= t[j+1]
            d += 1
        if ans == 7:
            print(''.join(tmp)+'=7')
            return
resolve()

Measured memory_bytes: 3700