akhauriyash/Code-Regression huggingface dataset:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 9e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){a=b; return true;} return false; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class AF {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    int a, b;
	    in >> a >> b;
	    if(a + b == 15) out << "+" << endl;
	    else if(a*b == 15) out << "*" << endl;
	    else out << "x" << endl;
	}
};


int main() {
	AF solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  if ((B - A - 1) % 2 == 1) {
    cout << "Alice\n";
  } else {
    cout << "Borys\n";
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 2e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int a, p;
    cin >> a >> p;
    cout << (a * 3 + p) / 2 << endl; 
    return 0;
}


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

using ll = long long;

#define for_(i,a,b) for(int i = (a);i < (b);i++)
#define rfor_(i,a,b) for(int i = (b)-1;i >= (a);i--)
#define rep(i,n) for_(i,0,(n))
#define rrep(i,n) rfor_(i,0,(n))

class Dice {
    public:
    int x, y, z;
    Dice() : x(3), y(1), z(2) {}
    ~Dice() {}
    void S() {
        int z_ = z;
        z = y;
        y = 7-z_;
    }
    void N() {
        int y_ = y;
        y = z;
        z = 7-y_;
    }
    void W() {
        int y_ = y;
        y = x;
        x = 7-y_;
    }
    void E() {
        int x_ = x;
        x = y;
        y = 7-x_;
    }
    void L() {
        int z_ = z;
        z = x;
        x = 7-z_;
    }
    void R() {
        int x_ = x;
        x = z;
        z = 7-x_;
    }
    void r(int u, int f) {
        if(y==u) {
        }else if(y==7-u) {
        	this->N();
        	this->N();
        }else if(x==u)this->W();
        else if(x==7-u)this->E();
        else if(z==u)this->N();
        else if(z==7-u)this->S();
        
        if(z==f) {
        }else if(z==7-f) {
        	this->L();
        	this->L();
        	
        }else if(x==f)this->L();
        else if(x==7-f)this->R();
    }
    void p() {
        cout<<x<<' '<<y<<' '<<z<<endl;
    }
};

int n;
int m[101][7];
Dice d;

bool same(int i, int j) {
    bool r = true;
    r = r && (m[i][1] == m[j][d.y] && m[i][2] == m[j][d.z]);
    r = r && (m[i][3] == m[j][d.x] && m[i][4] == m[j][7-d.x]);
    r = r && (m[i][5] == m[j][7-d.z] && m[i][6] == m[j][7-d.y]);
    return r;
}

bool check(int a, int b) {
    bool c = false;
    for_(i, 1, 7) {
        for_(j, 1, 7) {
        	if(j == i || j==7-i)continue;
            d.r(i, j);
            if(same(a, b)) {
                c = true;
                break;
            }
        }
    }
    return c;
}

int main(){
    cin.tie(0);
    
    cin>>n;
    rep(j, n)rep(i, 6)cin>>m[j][i+1];
    
    bool c = false;
    
    rep(i, n) {
        for_(j, i+1, n) {
            if(check(i, j)) {
                c = true;
                break;
            }
        }
    }
    
    cout<<(c?"No":"Yes")<<endl;
    
    return 0;
}



Measured memory_bytes: 3108
//***The night is the darkest just before the dawn***
 
#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main()
{
    ll h,w;
    cin>>h>>w;
    if((h<2)||(w<2)){
        cout<<"1";
        return 0;
    }
    cout<<(ll)ceil((((double)h*(double)w)/2.0));
}

Measured memory_bytes: 256
/*
Accepted 7/19
*/
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <fstream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>


using namespace std;


#define typeof(X) std::identity<decltype(X)>::type
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(a,b) make_pair((a),(b))

int main(){
	bool flag=true;
	multimap<string,int> dat;
	pair<string,int>  temp;
	vector<string>    memo;
	vector<int>       page;
	
	while(cin>>temp.first>>temp.second){
		dat.insert(temp);
	}
	for(auto i:dat){
		if(!(i.first.empty())){
			pair<multimap<string,int>::iterator,multimap<string,int>::iterator> tdat=dat.equal_range(i.first);
			auto find_it =find(begin(memo),end(memo),i.first);
			if( find_it == memo.end()){
				if(flag){
					cout<<i.first<<endl;
					flag=false;
				}else{
					cout<<"\n"<<i.first<<endl;
				}
				memo.push_back(i.first);
				page.clear();
			    for (auto it = tdat.first; it != tdat.second; ++it){
		        	page.push_back((*it).second);
		        }
		        sort(begin(page),end(page));
		        int j=0;
		        for(auto i:page){
		        	j++;
		        	if(j<page.size()){
						cout<<i<<" ";
					}else{
						cout<<i;
					}
		        }
		    }
		}
	}
	cout<<endl;
	
	return 0;
}

Measured memory_bytes: 1248
def L(cake1,cake2):
    return ((cake1+cake2)**2-abs(cake1-cake2)**2)**0.5
 
while 1:
    try:
        Cakes=map(int,raw_input().split())
        size_max=Cakes.pop(0)
        Cakes=sorted(Cakes)[::-1]
        size_min=999
        for j in range(len(Cakes)):
            cakes=Cakes[:]
            box=[cakes.pop(j)]
            while cakes:
                cos=[L(box[-1],i)/(box[-1]+i) for i in cakes]
                box.append(cakes.pop(cos.index(min(cos))))
            size=box[0]+box[-1]
            for i in range(len(box)-1):
                size+=L(box[i],box[i+1])
            size_min=min(size,size_min)
        print "OK" if size_min<=size_max else "NA"
    except:
        break

Measured memory_bytes: 4336
N = int(input())
obj = {}
for i in range(N):
  s = input()

  w = ''.join(sorted(list(s)))
  if not obj.get(w):
    obj[w] = 1
  else:
    obj[w] += 1

cnt = 0
for i in obj:
  v = obj[i]
  cnt += (v*(v-1))/2

print(int(cnt))
  

Measured memory_bytes: 17892
H=int(input())+1
A=[0]+list(map(int,input().split()))
def h(i):
 l=2*i;r=l+1
 g=l if l<H and A[i]<A[l]else i
 if r<H and A[g]<A[r]:g=r
 if g>i:A[i],A[g]=A[g],A[i];h(g)
for i in range(H//2,0,-1):h(i)
print(' '+' '.join(map(str,A[1:])))


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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) 
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (ll i=(ll)(a);i<(ll)(b);++i)
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)
#define YES(cond) cond ? OUT("YES") : OUT("NO")
#define Yes(cond) cond ? OUT("Yes") : OUT("No")

template<class T> T gcd(const T x,const T y){if(!y){return x;}return gcd(y,x%y);}
template<class T> T lcm(const T x,const T y){return x/gcd(x,y)*y;};
template<class T> T modpow(const T x,const T n,const T mod) {
  T res=1;while(n>0){if(n%2)res=res*x%mod;x=x*x%mod;n/=2;};return res;
}
template<class T> bool alltrue(const T &a){return all_of(ALL(a),[](bool x){return x;});}
template<class T> bool anytrue(const T &a){return any_of(ALL(a),[](bool x){return x;});}
template<class T> bool contain(const T &a,const T &b){for(auto x:b){if (a.find(x)==a.end()){return false;}}return true;}
template<class T> bool mmax(T &m,const T q){ if (m < q) {m = q; return true;} else return false; }
template<class T> bool mmin(T &m,const T q){ if (m > q) {m = q; return true;} else return false; }
template<class T> int siz(const T &a) {return (int)a.size();}
template<class T> set<T> devisers(T n) {
  set<T> res;for(T i=1;i<(T)sqrt(n)+1;i++){if(n%i==0){res.insert(i);res.insert(n/i);}}return res;
}
template<class T> void concat(T &a, const T &b){a.insert(a.end(),b.begin(),b.end());}
template<class T> void getand(const T &a,const T &b,T &c) {
  set_intersection(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}
template<class T> void getor(const T &a,const T &b,T &c) {
  set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}

typedef long long ll;
typedef pair<ll, ll> P;

const int MOD=1e9+7;

int main() {
  ll T1,T2,A1,A2,B1,B2;cin>>T1>>T2>>A1>>A2>>B1>>B2;

  int first_winner = A1<B1 ? 1 : 0;
  int second_winner = A2<B2 ? 1 : 0;

  // 絶対追いつかない
  if (first_winner==second_winner) {
    OUT(0);
    return 0;
  }

  ll first_gap = abs(A1-B1)*T1;
  ll second_gap = abs(A2-B2)*T2;

  if (first_gap == second_gap) {
    OUT("infinity");
    return 0;
  }
  if (first_gap > second_gap) {
    OUT(0);
    return 0;
  }
  // 毎回この数だけ差がついていく
  ll total_gap = second_gap-first_gap;

  if (first_gap%total_gap==0) {
    OUT(first_gap/total_gap*2);
  } else {
    OUT(first_gap/total_gap*2+1);
  }

  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
struct bian{int nxt,to;}bi[200020];
int n,s,t,dis1[100010],dis2[100010],head[100010],num,ans;
inline void add(int from,int to){bi[++num]=bian{head[from],to};head[from]=num;}
void bfs(int v,int dis[])
{
	dis[v]=1;queue<int>q;
	q.push(v);
	int x,y;
	while(!q.empty())
	{
		x=q.front();q.pop();
		for(int i=head[x];i;i=bi[i].nxt)
		{
			y=bi[i].to;
			if(!dis[y])dis[y]=dis[x]+1,q.push(y);
		}
	}
}
int main()
{
	scanf("%d %d %d",&n,&s,&t);
	int x,y;
	for(int i=1;i<n;++i)
	{
		scanf("%d %d",&x,&y);
		add(x,y),add(y,x);
	}
	bfs(s,dis1);
	bfs(t,dis2);
	for(int i=1;i<=n;++i)
		if(dis1[i]<dis2[i])ans=max(ans,dis2[i]-2);
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 3072
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

S = str(input())
K = I()

p = -1
for i in range(len(S)):
    if S[i]!='1':
        p = i
        val = S[i]
        break

if p==-1:
    print(1)
elif p>=K:
    print(1)
else:
    print(val)

Measured memory_bytes: 38256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

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

const int N=10000;
int cnt[N+5];

int main()
{
    int n;
    for(int x=1;x*x<=N;x++){
        for(int y=1;(x*x+y*y+x*y)<=N;y++){
            for(int z=1;(x*x+y*y+z*z+x*y+y*z+z*x)<=N;z++){
                n=x*x+y*y+z*z+x*y+y*z+z*x;
                cnt[n]++;
            }
        }
    }
    cin>> n;
    for(int i=1;i<=n;i++) cout<< cnt[i] <<endl;
    return 0;
}

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

typedef long long ll;

int main() {
	int a,b,c,k;
	cin >> a >> b >> c >> k;
	if (b <= a) {
		while (b <= a) {
			b<<=1;
			k--;
		}
		if (k < 0) {
			cout << "No";
			return 0;
		}
	}
	
	if (c <= b) {
		while (c<=b) {
			c<<=1;
			k--;
		}
		if (k<0) {
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
	
	
	return 0;
}


Measured memory_bytes: 3596
# B - Template Matching
def main():
    n, m = map(int, input().split())

    a_l = [input() for i in range(n)]
    b_l = [input() for i in range(m)]

    for i in range(n-m+1):
        for j in range(n-m+1):
            ans = 'Yes'
            for k in range(m):
                for l in range(m):
                    if a_l[i+k][j+l] != b_l[k][l]:
                        ans = 'No'
            else:
                if ans == 'Yes':
                    print(ans)
                    exit()
    print(ans)

  
        
if __name__ == '__main__':
    main()

Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1ll<<30;
const ll longINF = 1ll<<60;
const ll MOD = 1000000007;
const bool debug = 0;
//---------------------------------//

ll dp[102][112345];
ll dp1[102][112345], dp2[102][112345]; // dp1:下から累積和 i以下, dp2: 上から*cnt累積和 i以上

ll solve(int N, int K) {
	ll X = 1;
	while (X * X <= N) X++;
	X--;
	
	dp[0][1] = 1;
	
	REP(i, K + 1) {
		FOR(j, 1, X + 1) dp1[i][j] = (dp1[i][j - 1] + dp[i][j]) % MOD;
		for (int j = X; j > 0; j--) dp2[i][j] = (dp2[i][j + 1] + dp[i][j] * (N / j - X) % MOD) % MOD;
		
		FOR(j, 1, X + 1) {
			if (i > 0) {
				(dp[i + 1][j] += dp1[i - 1][j - 1] * (N / j - X) % MOD) %= MOD; // k overX j (k < j)
				(dp[i + 1][j] += dp2[i - 1][j]) %= MOD; // k overX j (k >= j)
			}
			(dp[i + 1][j] += dp1[i][X]) %= MOD; // X以下, j
		}
		
	}
	
	return dp[K + 1][1];
}

int main() {
	int N, K;
	cin >> N >> K;
	
	cout << solve(N, K) << endl;
	return 0;
}


Measured memory_bytes: 267264
from collections import Counter, deque

def main():
    N, X, Y = map(int, input().split())
    X -= 1
    Y -= 1
    edge = [[i-1, i+1] for i in range(N)]
    edge[0] = [1]
    edge[N-1] = [N-2]
    edge[X].append(Y)
    edge[Y].append(X)

    def bfs(i):
        q = deque()
        q.append(i)
        while len(q):
            now = q.popleft()
            for j in edge[now]:
                if j == i:
                    continue

                if not cost[j]:
                    cost[j] = cost[now] + 1
                    q.append(j)
        
    ct = Counter()
    for i in range(N):
        cost = [0] * N
        bfs(i)
        ct += Counter(cost)

    for i in range(1, N):
        print(ct[i]//2)

if __name__ == "__main__":
    main()

Measured memory_bytes: 95580
n, m, c = map(int, input().split())
b = [int(i) for i in input().split()]
x = 0
for i in range(n):
    a = [int(i) for i in input().split()]
    d = 0
    for j in range(m):
        d += b[j] * a[j]
    if d + c > 0:
        x += 1
print(x)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include  <set>
#include <cmath>
using namespace std;
typedef long long ll;
#define rep(i,n) for(i=0;i<n;i++)

int main() {
	ll a, b, c, d, e, f, g, h, i, j, n, m, l, sum = 0;
	cin >> a >> b;
	c = 0;
	
	while (c <= a) {
		sum = 10000*c;
		for (i = c; i <= a; i++) {
			n = sum + (i - c) * 5000 + (a - i) * 1000;
			if (n == b) {
				cout << c << " " << i - c << " " << a - i<<"\n";
				goto end;
			}
			//cout << c << " " << i - c << " " << a - i << "\n";
		}

		c++;
	
	
	}
	if (c == a + 1)cout << "-1 -1 -1";
	end:

	return 0;
}

Measured memory_bytes: 256
import Control.Monad
import Data.List
main = do
  n <- readLn
  sp <- fmap (fmap (reverse.sortOn (snd.snd)).groupOn (fst.snd).sortOn (fst.snd).zip [1..n]) $ replicateM n $ do 
    [s,p] <- words <$> getLine
    return (s,read p :: Int)
  mapM_ (print.fst) $ concat sp


-- | A version of 'group' where the equality is done on some extracted value.
groupOn :: Eq b => (a -> b) -> [a] -> [[a]]
groupOn f = groupBy ((==) `on2` f)
    -- redefine on so we avoid duplicate computation for most values.
    where (.*.) `on2` f = \x -> let fx = f x in \y -> fx .*. f y

Measured memory_bytes: 1020
#include <bits/stdc++.h>  // include all standard C++ libraries

using namespace std;

// Loops
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define _rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a)-1;i>=int(b);--i)

#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(xi, x) for (auto&& xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)


// typedef
template <class T> using vec = vector<T>;
using ll = long long;
using vi   = vec<int>;
using vvi  = vec<vi>;
using vvvi = vec<vvi>;
using pii  = pair<int, int>;


// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second


// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase( unique(all(v)), v.end() )
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<class T> pair<T, size_t> max(vector<T> &x){ auto it = max_element(all(x)); return mp(*it, it-x.begin()); }
template<class T> pair<T, size_t> min(vector<T> &x){ auto it = min_element(all(x)); return mp(*it, it-x.begin()); }

template<class T> inline bool chmax(T &maxval, const T &newval) { if (maxval<newval) { maxval=newval; return 1; } return 0; }
template<class T> inline bool chmin(T &minval, const T &newval) { if (minval>newval) { minval=newval; return 1; } return 0; }

// Utilities
// Grid world utilities
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
#define inside(H,W,y,x) 0<=(x) && (x)<(W) && 0<=(y) && (y)<(H)

inline int in() {int x; cin >> x; return x;} // read int from cin
inline  ll IN() {ll x; cin >> x; return x;}  // read ll from cin



// Debug
#ifdef LOCAL
  #include "dump.hpp"
  #define debug(x) cerr << #x << ": " << x << '\n'
#else
  #define dump(...)
  #define debug(x)
#endif

// Paste snippets here!!

// 

int main(){
  cin.tie(0); ios::sync_with_stdio(false);    // Magic for faster cin
  int n; cin>>n;
  ll ret = 0;
  vi a(n); rep(i,n) { cin>>a[i]; ret += a[i]; }
  unordered_map<int,ll> hist;
  rep(i,n) hist[a[i]]++;
  int q; cin>>q;
  int b, c;
  rep(i,q){
    cin >> b >> c;
    if(hist.find(b)!=hist.end()){
      ret -= hist[b] * b;
      ret += hist[b] * c;
      hist[c] += hist[b];
      hist[b] = 0;
    }
    cout << ret << endl;
  }
  return 0;
}


Measured memory_bytes: 7256
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)
	ans := "Yes"
	for i, v := range s {
		if v == 'U' || v == 'D' {
			continue
		}
		if (i+1)%2 == 1 && v == 'R' {
			continue
		}
		if (i+1)%2 == 0 && v == 'L' {
			continue
		}
		ans = "No"
		break
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
S = input()
val = True
for i in range(1, len(S) + 1):
    if i % 2 and (S[i - 1] in ['R', 'U', 'D']):
        pass
    elif i % 2 == 0 and (S[i - 1] in ['L', 'U', 'D']):
        pass
    else:
        val = False
    if not val:
        print('No')
        break
else:
    print('Yes')

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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

    int N;
    cin >> N;

    vi vals(N);
    for (int i = 0; i < N; i++) {
        cin >> vals[i];
        vals[i] -= i - 1;
    }

    vi copy = vals;
    sort(all(copy));

    int median = copy[N / 2];
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        ans += abs(median - vals[i]);
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(10**6)

class BiCoeff(object):
    def __init__(self, MAX, m):
        super(BiCoeff, self).__init__()
        fac = [0]*MAX
        finv = [0]*MAX
        inv = [0]*MAX

        fac[0] = 1
        fac[1] = 1
        finv[0] = 1
        finv[1] = 1
        inv[1] = 1
        for i in range(2,MAX):
            fac[i] = (fac[i-1]*i)%m
            inv[i] = m - (inv[m%i] * (m//i))%m
            finv[i] = (finv[i-1] * inv[i])%m

        self.MAX = MAX
        self.m = m
        self.fac = fac
        self.finv = finv
        self.inv = inv

    def calc(self,n,k):
        if n<k:
            return 0
        if n<0 or k<0:
            return 0
        return (self.fac[n] * (self.finv[k]*self.finv[n-k])%self.m)%self.m


MOD = 10**9+7
n,k = map(int, input().split())

fact = [0]*(n+1)
fact[1] = 1
for i in range(2,n+1):
    fact[i] = fact[i-1]*i
    fact[i] %= MOD
bicoeff = BiCoeff(2*n+1,MOD)

res = 0
for i in range(1,n+1):
    if n-i<=k:
        res += bicoeff.calc(n-1,i-1)*bicoeff.calc(n,i)
        res %= MOD
print(res)


Measured memory_bytes: 53356
n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(m)]
if n == 1:
  start,end = 0,9
elif n == 2:
  start,end = 10,99
else:
  start,end = 100, 999

for i in range(start, end+1):
  flg = True
  for j in l:
    si = str(i)
    if si[j[0]-1] != str(j[1]):
      flg = False
      
  if flg == True:
    print(i)
    break
else:
  print(-1)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <queue>
/* Copy of Gainer's solution 
At first I went to BFS but I overthought it. */
using namespace std;

int n;

int main(){
  int n;
  cin >> n;
  vector<int> list (n);
  for (int i=0; i<n; i++){
    cin >> list[i];
  }
  // Since to swap a number means that the numbers never
  // need to be swapped again, you can ignore the next number.
  int swapped = 0;
  for (int i=0; i<n; i++){
    if (list[i] == i+1){
      swapped++;
      i++;
    }
  }
  cout << swapped;
  return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public final class Main {
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);

        int n = stdIn.nextInt();
        int l = stdIn.nextInt();

        if(l<=0 && 0<=l+n-1){
            System.out.println(n*l+(n*(n-1))/2);
        }else if(0<l){
            System.out.println((n-1)*l+(n*(n-1))/2);            
        }else{
            System.out.println((n-1)*l+(n*(n-1))/2-n+1);
        }
    }
}

Measured memory_bytes: 25172
#include <bits/stdc++.h>
using namespace std;
 int main() {
   int A,B,C,D;
   cin >>A>>B;
    if(A==B) cout << "Draw" << endl;   
   else if(A == 1) cout << "Alice" << endl;
   else if(B==1)cout << "Bob" << endl;
   else if(A > B) cout << "Alice" << endl;
   else if(A < B) cout << "Bob" << endl;
 }

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

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

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

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

bool solve() {
	ll b;
	cin >> b;
	if (b == 0) return (false);
	vll sum(1000005, 0);
	for (ll r = 1; r <= 1000000; r++) {
		sum[r] = sum[r-1] + r;
		if (sum[r] >= b) {
			int pos = lower_bound(begin(sum), begin(sum) + r + 1, sum[r]-b) - begin(sum);
			if (sum[pos] == sum[r]-b) {
				cout << pos + 1 << " " << r - pos << el;
				return (true);
			}
		}
	}
	
	for (ll k = 1000; k >= 1; k--) {
		ll ng = 1, ok = (1e9 + 1 / k) + 100;
		//cout << k << endl;
		while (abs(ng-ok)>1) {
			ll x = (ng+ok)/2;
			ll s = 0;
			for (ll i = 0; i < k; i++) s += x+i;
			//cout << x << " " << s << " " << k << el;
			if (s >= b) ok = x;
			else ng = x;
		}
		ll su = 0;
		for (ll i = 0; i < k; i++) su += ok+i;
		if (su == b) {
			cout << ok << " " << k << endl;
			return (true);
		}
	}

	return (true);
}

void Main() {
	while (solve());
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}



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

long gcd(long x, long y){
    if (x < y) {
        swap(x,y);
    }
    long r;
    while (x % y != 0) {
        r = x;
        x = y;
        y = r%y;
    }
    return y;
}
int main() {
    long a,b,c,d;
    cin >> a >> b >> c >> d;
    long divc = b/c - (a-1)/c;
    long divd = b/d - (a-1)/d;
    long lcm = (c*d)/gcd(c,d);
    long divcd = b/lcm - (a-1)/lcm;
    long range = b - a + 1;
    cout << range - divc - divd + divcd << endl;
}


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

using namespace std;
const int MAXN = 1.1E5;
int A[MAXN];

int main(void)
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	int n = 0;
	cin >> n;
	for (int i = 1;i <= n; ++i)
		cin >> A[i];
	sort(A + 1, A + 1 + n);
	reverse(A + 1, A + 1 + n);
	
	int pos = 0;
	for (int i = 1;i <= n; ++i)
		if (A[i] >= i)
			pos = i;
	int nxt = 0;
	while (A[pos + nxt + 1] == pos)
		++nxt;
	if (((A[pos] - pos)&1) || (nxt & 1))
		puts("First");
	else
		puts("Second");
	
	return 0;
}

Measured memory_bytes: 4008
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
  int n; cin>>n;
  string s; cin>>s;

  string walls = "";
  walls += 'L';
  reps(i,2*n-1){
    if(s[i-1]==s[i]){
      if(walls[i-1]=='L') walls+='R';
      else walls += 'L';
    }else{
      walls += walls[i-1];
    }
  }
  int wall[2*n][2];
  wall[0][0] = 1; wall[0][1] = 0;
  reps(i,2*n-1){
    wall[i][0] = wall[i-1][0];
    wall[i][1] = wall[i-1][1];
    if(walls[i]=='L') wall[i][0]++;
    else wall[i][1]++;
  }
  rep(i,2*n){
    cerr << s[i] SP walls[i] SP wall[i][0] SP wall[i][1] << endl;
  }
  // cerr << wall[2*n-1][0] SP wall[2*n-1][1] << endl;
  if(wall[2*n-1][0]!=wall[2*n-1][1]){
    cout << 0 << endl;
    return 0;
  }
  if(s[0]=='W' || s[2*n-1]=='W'){
    cout << 0 << endl;
    return 0;
  }
  ll ans = 1;
  reps(i,2*n-1){
    if(walls[i]=='R'){
      ans *= wall[i][0]-wall[i][1]+1;
      ans %= MOD;
    }
  }
  vector<ll> kaijo(n+1);
  kaijo[0] = kaijo[1] = 1;
  reps(i,n) kaijo[i] = (kaijo[i-1]*i)%MOD;
  cerr << ans SP kaijo[n] << endl;
  ans *= kaijo[n];
  ans %= MOD;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3220
from math import ceil
S=list(input())
num_x=S.count("x")
N=len(S)
num=N-num_x
cf,cr=0,0
F,R=[],[]

f,r=0,N-1
while len(F)<ceil(num/2):
  if S[f]=="x":
    cf+=1
  else:
    F.append((S[f],cf))
    cf=0
  f+=1
      
while len(R)<ceil(num/2):
  if S[r]=="x":
    cr+=1
  else:
    R.append((S[r],cr))
    cr=0
  r-=1
ans=0  
for i in range(ceil(num/2)):   
  if F[i][0]!=R[i][0]:
    print(-1)
    exit()
  else:
    ans+=abs(F[i][1]-R[i][1])
print(ans)


Measured memory_bytes: 53004
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    vector<pair<int, int>> red(n), blue(n);
    rep(i, n) {
        int a, b;
        cin >> a >> b;
        red[i] = make_pair(b, a);
    }
    rep(i, n) {
        int c, d;
        cin >> c >> d;
        blue[i] = make_pair(c, d);
    }
    sort(red.begin(), red.end());
    reverse(red.begin(), red.end());  // red(n)をy座標の降順にソート
    sort(blue.begin(), blue.end());  // blue(n)をx座標の昇順にソート

    vector<int> used(n);  // used[i] : 1のときred[i]はすでに選ばれている

    int ans = 0;
    rep(i, n) {
        rep(j, n) {
            if(used[j] == 0 && red[j].second < blue[i].first && red[j].first < blue[i].second) {
                used[j] = 1;
                ans++;
                break;
            }
        }
    }

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

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

int main(){

  int k;
  string s;
  cin >> k;
  cin >> s;

  if(s.size() > k){
    s = s.substr(0, k);
    s += "...";
  }
  cout << s << endl;

}


Measured memory_bytes: 3624
import std.stdio, std.array, std.conv, std.string, std.algorithm, std.math;

void main() {
  for (int i = 1; i <= 9; i++) {
    for (int j = 1; j <= 9; j++) {
      writefln("%dx%d=%d", i, j, i * j);
    }
  }
}

Measured memory_bytes: 1044
def main():
    N, M = (int(i) for i in input().split())
    S = input()
    from itertools import groupby
    for k, v in groupby(S):
        if k == '1' and len(list(v)) >= M:
            return print(-1)

    ans = []
    i = 0
    S = S[::-1]
    while i <= N:
        cur = M
        while N < i+cur or S[i+cur] == '1':
            cur -= 1
        i += cur
        if cur == 0:
            break
        ans.append(cur)

    ans = ans[::-1]
    print(*ans)


if __name__ == '__main__':
    main()


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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
#define PI 3.14159265358979
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}

vector<pair<int,ll>> vec[100000];
ll cost[100000];
void dfs(int now,ll COST){
    cost[now]=COST;
    int next;
    REP(i,vec[now].size()){
        next=vec[now][i].first;
        if(cost[next]<0){
            dfs(next,COST+vec[now][i].second);
        }
    }
}
int counter(int x){
    if(!x)return 0;
    return counter(x>>1)+(x&1);
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int A=in();
    int B=in();
    if(A<=B*2){
        cout<<"0"<<endl;
        return 0;
    }else{
        cout<<A-2*B<<endl;
        return 0;
    }
    return 0;
}


Measured memory_bytes: 3584
def selectionSort(array):
    n = len(array)
    cnt = 0
    for i in range(n):
        minj = i
        for j in range(i, n):
            if array[j] < array[minj]:
                minj = j
        array[i], array[minj] = array[minj], array[i]
        if i != minj and array[i] != array[minj]:
            cnt += 1

    return (array, cnt)

n = int(input())
array = [int(x) for x in input().split()]

resultArray, cnt = selectionSort(array)

print(*resultArray)
print(cnt)



Measured memory_bytes: 5608
N,M = map(int,input().split())
S = str(input())
tmp  = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
tmp2 = "abcdefghijklmnopqrstuvwxyz"
ans = ""
for i in range(N):
    if i==M-1:
        for j in range(26):
            if S[M-1]==tmp[j]:
                ans += tmp2[j]
                break
    else:
        ans += S[i]
print(ans)


Measured memory_bytes: 3060
from collections import deque
n,m = map(int,input().split())
g = [[] for _ in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)
q = deque([0])
d = [-1]*n
d[0] = 0
while q:
    v = q.popleft()
    for i in g[v]:
        if d[i] != -1:
            continue
        d[i] = v
        q.append(i)
if -1 in d:
    print("No")
else:
    print("Yes")
    for i in d[1:]:
        print(i+1)

Measured memory_bytes: 34912
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;
long long x[1010],y[1010],mx[4];
vector<long long> d;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,1,0,-1};
int main(){
    int i,j,k,n,cnt = 0;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> x[i] >>y[i];
        if((x[i]+y[i])%2){
            cnt++;
        }
    }
    if(cnt!=0 && cnt!=n){
        cout << -1 << endl;
        return 0;
    }
    long long z = pow(2,31);
    while(z>=1){
        d.push_back(z);
        z /= 2;
    }
    if(!cnt){
        d.push_back(1);
    }
    int m = d.size();
    cout << m << endl;
    for(i=0;i<m;i++){
        cout << d[i] << " ";
    }
    cout << endl;
    for(i=0;i<n;i++){
        long long s = 0,t = 0;
        for(j=0;j<m;j++){
            long long mn = 100000000000000;
            for(k=0;k<4;k++){
                mx[k] = abs(x[i] - (s + dx[k]*d[j])) + abs(y[i] - (t + dy[k]*d[j]));
                mn = min(mn,mx[k]);
            }
            for(k=0;k<4;k++){
                if(mn==mx[k]){
                    if(k==0){
                        cout << "L";
                    }
                    if(k==1){
                        cout << "U";
                    }
                    if(k==2){
                        cout << "R";
                    }
                    if(k==3){
                        cout << "D";
                    }
                    s += dx[k]*d[j]; t += dy[k]*d[j];
                    break;
                }
            }

        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <map>
#include <algorithm>
#include <stdio.h>
#include <set>
#include <cmath>

typedef long long ll;

using namespace std;

int main(){
    int n;
    cin >> n;
    if(n % 1000 == 0){
        cout << 0 << endl;
    } else {
        cout << 1000 - n % 1000 << endl;
    }
}

Measured memory_bytes: 3620
#include<stdio.h>
#define MAX 44

int fibonacci(int );

int F[MAX];

main()
{
  int n, i;

  scanf("%d", &n);
  for(i=0; i<n; i++) F[n] = 0;
  printf("%d\n", fibonacci(n));

  return 0;
}

int fibonacci(int n)
{
  if(n == 0 || n == 1)
    {
      F[n] = 1;
      return F[n];
    }
  if(F[n] != 0)
    {
      return F[n];
    }

  return F[n] = fibonacci(n-1) + fibonacci(n-2);
}

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

string str;
int tf[52];

bool update(string x){
  for(int i=0;i<52;i++)tf[i] = 0;
  for(int i=0;i<(int)x.size();i++){
    if(x[i]!='&'){
      int tmp;
      if(x[i] == '~'){
	if(x[i+1]>='a' && x[i+1]<='z')tmp = x[i+1]-'a';
	else tmp = x[i+1]-'A'+26;
	if(!tf[tmp])tf[tmp] = -1;
	else if(tf[tmp] == 1)return false;
	i++;
      }else{
	if(x[i]>='a' && x[i]<='z')tmp = x[i]-'a';
	else tmp = x[i]-'A'+26;
	if(!tf[tmp])tf[tmp] = 1;
	else if(tf[tmp] == -1)return false;
      }
    }
  }
  return true;
}

bool solve(void){
  string tmp;
  int pos = 0;
  while(pos < (int)str.size()){
    if(str[pos]=='|'){
      //cout << tmp << endl;
      if(update(tmp))return true;
      tmp.clear();
    }else if(str[pos]!='(' && str[pos]!=')')tmp.push_back(str[pos]);
    pos++;
  }
  if(update(tmp))return true;
  return false;
}
int main(){
  while(1){
    cin >> str;
    if(str == "#")break;

    if(solve())cout << "yes" << endl;
    else cout << "no" << endl;
  }
}

Measured memory_bytes: 900
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<char> s(n);
    string ans = "Three";
    for (int i = 0; i < n; ++i) {
        cin >> s[i];
        if (s[i] == 'Y') {
            ans = "Four";
            break;
        }
    }

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


Measured memory_bytes: 256
H, W = [int(_) for _ in input().split()]
A = [[_ for _ in input()] for _ in range(H)]


def parse(x, y):
    A[x][y] = '.'
    cand_OK = []
    cand_NG = []
    if x < H - 1:
        cand_OK += [[x + 1, y]]
    if y < W - 1:
        cand_OK += [[x, y + 1]]
    if x > 0:
        cand_NG += [[x - 1, y]]
    if y > 0:
        cand_NG += [[x, y - 1]]
    if any([A[i][j] == '#' for i, j in cand_NG]):
        return False
    if sum([A[i][j] == '#' for i, j in cand_OK]) == 2:
        return False
    if sum([A[i][j] == '.' for i, j in cand_OK]) == 2:
        return False
    if x == H - 1 and y == W - 1:
        return True
    for i, j in cand_OK:
        if A[i][j] == '#':
            return parse(i, j)


if parse(0, 0):
    print('Possible')
else:
    print('Impossible')


Measured memory_bytes: 3064
x,y=map(int,input().split())
mod=10**9+7

def nCk(n,k):
  MAX_N=n+5
  fac = [1,1] + [0]*MAX_N
  finv = [1,1] + [0]*MAX_N
  inv = [0,1] + [0]*MAX_N
  for i in range(2,MAX_N):
    fac[i] = fac[i-1] * i % mod
    inv[i] = mod - inv[mod % i] * (mod // i) % mod
    finv[i] = finv[i-1] * inv[i] % mod
  
  if n<k:
    return 0
  if n<0 or k<0:
    return 0
  return fac[n] * (finv[k] * finv[n-k] % mod) % mod

n=(y-0.5*x)/1.5
if int(n)!=n:
    print(0)
else:
    m=(y+x)//3
    l=int(n)
    print(nCk(m,l))

Measured memory_bytes: 87324
s = input()
t = input()

count = len(t)

for i in range(0, len(s) - len(t) + 1):
    x = s[i : i + len(t)]
    cnt = 0
    for i in range(len(t)):
        if t[i] != x[i]:
            cnt += 1
    if count >= cnt:
        count = cnt

print(count) 

Measured memory_bytes: 8988
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();

		while (true) {

			c -= b;

			if (c <= 0) {
				System.out.println("Yes");
				return;
			}

			a -= d;

			if (a <= 0) {
				System.out.println("No");
				return;
			}

		}

	}

}


Measured memory_bytes: 35768
#include "bits/stdc++.h"
using namespace std;
#define REP(i,a) for(int i = 0; i < (a);i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using Graph = vector < vector<int>>;
long int sum[200020] = {};
int main() {
	int n, d = 0;
	float a[20][20];
	float sum = 0;
	int count = 0;
	cin >> n >> d;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < d; j++) {
			cin >> a[i][j];
		}
	}

	for (int i = 0; i < n-1; i++) {
		for (int j = i+1; j < n; j++) {
			for (int k = 0; k < d; k++) {
				sum = sum +pow(a[i][k] - a[j][k],2);
			}
			sum = pow(sum, 0.5);
			sum = sum - int(sum / 1);
			if (!(sum)) {
				count++;
			}
			sum = 0;
		}
	}
	cout << count;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね

//ここから編集する


int main() {
    string s;
    cin >> s;
    if(s.find("AC") == -1){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    return 0;
}


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

void chmin(int &a, int b){
  if (a > b){
    a = b;
  }
}

int main(){
  int N;
  cin >> N;
  vector<int> h(N);
  vector<int> dp(N);
  for(int i = 0; i < N; i++){
    cin >> h.at(i);
    dp.at(i) = 1000000000;
  }
  dp.at(0) = 0;
  for(int i = 1; i < N; i++){
    chmin(dp.at(i), dp.at(i - 1) + abs(h.at(i) - h.at(i - 1)));
    if(i > 1){
      chmin(dp.at(i), dp.at(i - 2) + abs(h.at(i) - h.at(i - 2)));
    }
  }
  cout << dp.at(N - 1) << endl;
}

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

using i64 = int64_t;

int main(){
    int n, m, c;
    cin >> n >> m >> c;
    vector<int> b;
    for(int i=0;i<m;++i){
        int tmp;
        cin >> tmp;
        b.push_back(tmp);
    }

    int ans = 0;
    for(int i=0;i<n;++i){
        int sum = c;
        for(int j=0;j<m;++j){
            int tmp;
            cin >> tmp;
            sum += tmp * b[j];
        }
        if(sum > 0)ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=200005;
int a[M],b[M];
 main()

{
    fast
    int n;
    cin>>n;
    f(i,0,n-1)cin>>a[i];
    f(i,0,n-1)cin>>b[i];
    f(i,0,n-1)
    {
        if(b[i]<a[i])
        {
            cout<<"-1"<<endl;return 0;
        }
    }
    priority_queue<pi>pq;
    f(i,0,n-1)
    {
        if(a[i]!=b[i])pq.push(mp(b[i],i));
    }
    int ses=0;
    while(!pq.empty())
    {
        int y=pq.top().si;
        int x=(y-1+n)%n;
        int z=(y+1)%n;
        pq.pop();
        int cost=0;
        if(b[y]!=a[y] && b[y]>b[x] && b[y]>b[z])
        {
            cost=(b[y]-a[y])/(b[x]+b[z]);
            b[y]-=(cost*(b[x]+b[z]));
        }
        ses+=cost;
        if(b[y]!=a[y] && cost==0)
        {
            cout<<"-1"<<endl;
            return 0;
        }
        if(b[y]!=a[y])
        {
            pq.push(mp(b[y],y));
        }

    }
    f(i,0,n-1)
    {
        if(a[i]!=b[i])
        {
            cout<<"-1"<<endl;return 0;
        }
    }
    cout<<ses<<endl;
    return 0;

}



































Measured memory_bytes: 10468