akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

char input[9010];
long long cnt[3][4010];

int main(void) {
	int n;
	scanf("%d", &n);
	getchar();

	for (int i = 1; i <= n; i++)
		scanf("%c", input + i);


	for (int i = n; i >= 1; i--) {
		cnt[0][i] = cnt[0][i + 1];
		cnt[1][i] = cnt[1][i + 1];
		cnt[2][i] = cnt[2][i + 1];

		if (input[i] == 'R')
			cnt[0][i]++;
		else if (input[i] == 'G')
			cnt[1][i]++;
		else
			cnt[2][i]++;
	}
	
	long long result = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = i + 1; j <= n; j++) {
			if (input[i] == input[j])
				continue;

			int k = j + (j - i);
			if (input[i] == 'R' && input[j] == 'G') {
				result = result + cnt[2][j + 1];
				if (input[k] == 'B')
					result = result - 1;
			}
			else if (input[i] == 'R' && input[j] == 'B') {
				result = result + cnt[1][j + 1];
				if (input[k] == 'G')
					result = result - 1;
			}
			else if (input[i] == 'G' && input[j] == 'R') {
				result = result + cnt[2][j + 1];
				if (input[k] == 'B')
					result = result - 1;
			}
			else if (input[i] == 'G' && input[j] == 'B') {
				result = result + cnt[0][j + 1];
				if (input[k] == 'R')
					result = result - 1;
			}
			else if (input[i] == 'B' && input[j] == 'R') {
				result = result + cnt[1][j + 1];
				if (input[k] == 'G')
					result = result - 1;
			}
			else if (input[i] == 'B' && input[j] == 'G') {
				result = result + cnt[0][j + 1];
				if (input[k] == 'R')
					result = result - 1;
			}
		}
	}

	printf("%lld\n", result);
}

Measured memory_bytes: 1776
#include <bits/stdc++.h>
#define LL long long
#define MEM(x,y) memset(x,y,sizeof(x))
#define MOD(x) ((x)%1000000007)

using namespace std;
const int maxn = 2e5 + 7;
char s[maxn];
int deg[maxn][2], now, del[maxn];
set<int>E[maxn];

void dfs(int x)
{
    if(del[x] || (deg[x][0] > 0 && deg[x][1] > 0)) return;
    now--; del[x] = 1;
    //cout << "del " << x << endl;
    for(int tmp : E[x])
    {
        deg[tmp][s[x - 1] - 'A']--;
        deg[x][s[tmp - 1] - 'A']--;
        dfs(tmp);
    }
    return;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n, m;
    cin >> n >> m;
    cin >> s;
    while(m--)
    {
        int u, v;
        cin >> u >> v;
        if(!E[u].count(v))
        {
            deg[u][s[v - 1] - 'A']++; E[u].insert(v);
        }
        if(!E[v].count(u))
        {
            deg[v][s[u - 1] - 'A']++; E[v].insert(u);
        }
    }
    now = n;
    for(int i = 1; i <= n; i++) dfs(i);
    if(now > 0) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 30976
s = list(input())

if "A" != s[0]:
    print("WA")
    exit()
s_extracted = s[2:-1]
if s_extracted.count("C") != 1:
    print("WA")
    exit()
# Get Upper characters without "A", "C"
s_upper = [
    chara for chara in s if chara != "C" and chara != "A" and chara.isupper()
]
if len(s_upper) > 0:
    print("WA")
    exit()

print("AC")

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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define ALL(obj)	(obj).begin(),(obj).end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define VEC vector

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;
typedef vector<int>				Vint;
typedef vector<Vint>			VV;

template<typename T>string join(const v(T)&v)
{stringstream s;REP(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define MAX 		100010


const ll LINF = (ll)9e18+7;		//
const int INF = 100100100;			//2,147,483,647 (Max int)
const ll MOD = 1e9+7;
// テンプレ終了
//====================================================================//

// int DP[MAX];




int main(){
	int H,W,K;cin >> H >> W >> K;
	v(string) A(H);
	REP(i,H)cin >> A[i];

	int ans = 0;

	REP(i,pow(2,H))REP(j,pow(2,W)){
		int cnt = 0;
		REP(r,H)REP(c,W){
			int re = pow(2,r);
			int ce = pow(2,c);
			if( i&re && ce&j){
				if(A[r][c] == '#'){
					cnt ++;
				}
			}
		}
		if(cnt == K){ ans++;}
	}

	cout << ans << endl;

	return 0;
}
 



Measured memory_bytes: 4040
def gcd_all(a):
    from math import gcd
    g = 0
    for x in a: g = gcd(g, x)
    return g

def is_pairwise():
    MAX_A = 10**6 + 1
    C = [0] * MAX_A
    for a in A: C[a] += 1
    for i in range(2, MAX_A):
        if sum(C[i::i]) > 1: return False
    return True

def solve():
    if is_pairwise(): return 'pairwise'
    if gcd_all(A) == 1: return 'setwise'
    return 'not'

n = int(input())
A = [*map(int, input().split())]
print(solve(), 'coprime')


Measured memory_bytes: 127280
'''
Created on 2020/08/26

@author: harurun
'''
def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

def main():
  import math
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  N,P=map(int,pin().split())
  l=factorize(P)
  d=list(set(l))
  ans=1
  for i in d:
    t=l.count(i)
    if t>=N:
      ans*=i**(int(t/N))
  print(ans)
  return

main()

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

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

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

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void) {
  int64 n;
  while (cin >> n && n) {
    vector<string> s(n);
    REP(i, s.size()) {
      cin >> s[i];
    }
    vector<int> rank(n, -1);
    REP(i, n) {
      REP(j, s[i].size()) {
        if (s[i][j] == '.' && s[i][j+1] != '.') {
          rank[i] = j;
          s[i][j] = '+';
          break;
        }
      }
    }

    REP(i, n) {
      if (rank[i] == -1) continue;
      int64 match = -1;
      FOR(j, i+1, n) {
        if (rank[j] < rank[i]) break;
        if (rank[j] == rank[i]) {
          match = j;
          break;
        }
      }
      if (match != -1) {
        FOR(j, i+1, match) {
          s[j][rank[i]] = '|';
        }
      }
    }
    REP(i, n) {
      REP(j, s[i].size()) {
        if (s[i][j] == '.') s[i][j] = ' ';
      }
      cout << s[i] << endl;
    }
  }
}



Measured memory_bytes: 3788
n = gets.chomp.to_i
l = []
n.times do |i|
  s, p = gets.chomp.split
  l[i] = [s, -p.to_i]
end
r = l.sort
n.times do |i|
  n.times do |j|
    if r[i] == l[j]
      puts j + 1
      break
    end
  end
end


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
const int INF= 1e9+5;

int main(){
 int n;
  cin>>n;
  vector<double>a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  double sum=0;
  for(int i=0;i<n;i++)sum+=1/a[i];
  cout << std::fixed << std::setprecision(10) << 1/sum << endl;
}

Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
using namespace std;

//https://github.com/atcoder-live/library/blob/master/mint.cpp
#define ll long long int
const ll mod = 1000000007ll;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  vector<mint> fact, ifact;//factに階乗を計算、ifactはその各々に対する逆元
  combination(ll n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (ll i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (ll i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(ll n, ll k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

void solve(long X,long Y,long* ans){
	if((X+Y)%3) return;
	long times_12 = (2*X-Y)/3;//(i+1,j+2)へ動く回数
	long times_21 = (2*Y-X)/3;//(i+2,j+1)へ動く回数
	//それぞれ何回必要かを調べたのち、場合の数をコンビネーションを用いて計算
	if(times_12<0||times_21<0) return;
	combination c(times_12+times_21);//struct combinationのコンストラクタを呼び出す
	mint output = c(times_12+times_21,times_21);//__call__ 的な 
	(*ans) = output.x;
}

int main(){
	long X,Y;
	long ans = 0;
	cin >> X >> Y;

	solve(X,Y,&ans);

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


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

using namespace std;


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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <numeric>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <sstream>

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define PI 3.14159265359 //πの値
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define C(x) cout << x << endl //テスト出力

//関数
//nCkの計算の関数(呼び出しは[cbn])
ll cbn(ll n, ll k) {
    ll r = 1;
    for (ll d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}
// a^n mod を計算する
ll powmod(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}
//２つの最大公約数
int gcb(int a, int b){
    if(a < b){
        int x = a;
        a = b;
        b = x;
    }
    int amari = a % b;
    if(amari == 0) return b;

    return gcb(b, amari);
}
//３つの最大公約数
int gcb_3(int a, int b, int c){
    return gcb(gcb(a, b), c);
}

/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;
vector<vector<要素の型>> 変数名(要素数1, vector<要素の型>(要素数2, 初期値))*/

/*-----------------------------ここから-----------------------------*/

int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n; cin>>n;
vector<ll> data(n);
REP(i,n) cin>>data[i];
ll cnt = 0;
ll max_height = 0;
REP(i,n) {
  max_height = max(max_height,data[i]);
  if(data[i]>=max_height) cnt++;
}
  cout<<cnt;
}

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

int main(){
    int N,count=1;
    cin >> N;
    int a[N];
    for (int i=0;i<N;i++){
        cin >> a[i];
    }
    sort(a,a+N);
    for (int i=0;i<N-1;i++){
        if (a[i] < a[i+1]){
            count = count+1;
        }
    }
    cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(11000)
def util(adj, curr, dp):
    res = 0
    if dp[curr] != -1:
        return dp[curr]
    for next in adj[curr]:
        res = max(res,1 + util(adj, next, dp))
    dp[curr] = res
    return res
 
n, m = map(int, input().strip().split())
adj = [[] for _ in range(n)]
for _ in range(m):
    x, y = map(int, input().strip().split())
    adj[x - 1].append(y - 1)
dp = [-1]*n
lp = 0
for i in range(n):
    lp = max(lp, util(adj, i, dp))
print(lp)

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  string s; std::cin >> s;
  int n = s.size();
  vi ans(n);
  rep(i, n) {
    int ni = i;
    while (ni+1 < n && s[i] == s[ni+1]) ni++;
    int cnt = ni - i + 1;
    if (s[i] == 'L') {
      ans[i] += (cnt + 1) / 2;
      if (i-1 >= 0) ans[i-1] += cnt / 2;
      else ans[i] += cnt / 2;
    } else {
      ans[ni] += (cnt + 1) / 2;
      if (ni+1 < n) ans[ni+1] += cnt / 2;
      else ans[ni] += cnt / 2;
    }
    i = ni;
  }
  rep(i, n) std::cout << ans[i] << (i+1 < n ? " " : "\n");
}


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

using namespace std;

int main() {
    while (true) {
        string s;
        cin >> s;
        if (s == "0") {
            break;
        }
        long long ans = 0;
        for (auto& c : s) {
            ans += c - '0';
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3156
h, w = gets.chomp.split(' ').map(&:to_i)
maze = []
h.times { maze << gets.chomp.split('') }
dirs = [[0, 1], [1, 0], [0, -1], [-1, 0]]
max = 0
(0...h).each do |si|
  (0...w).each do |sj|
    next if maze[si][sj] == '#'
    visited = Hash.new(false)
    queue = [[si, sj]]
    distance = 0
    until queue.empty?
      length = queue.length
      length.times do
        qi, qj = queue.shift
        next if visited["#{qi}-#{qj}"]
        visited["#{qi}-#{qj}"] = true
        max = [max, distance].max
        dirs.each do |d|
          ni, nj = qi + d[0], qj + d[1]
          next if ni < 0 ||
              nj < 0 ||
              ni >= h ||
              nj >= w ||
              visited["#{ni}-#{nj}"] ||
              maze[ni][nj] == '#'
          queue << [ni, nj]
        end
      end
      distance += 1
    end
  end
end
puts max

Measured memory_bytes: 2172
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
// using namespace atcoder;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000000000000ll
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
//#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
/* clang-format on */

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> c(n), v(n), a(n);
  REP(i, n) cin >> v[i];
  REP(i, n) cin >> c[i];
  REP(i, n) a[i] = v[i] - c[i];
  ll ans = 0;
  REP(i, n) if (a[i] > 0) ans += a[i];
  cout << ans << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;

int main()
{
  int n, q;
  fscanf(stdin, "%d", &n);
  vector<int> S(n);
  for (int i = 0; i < n; ++i) {
    fscanf(stdin, "%d", &S[i]);
  }
  set<int> s(S.begin(), S.end());
  fscanf(stdin, "%d", &q);
  int ans = 0, val = 0;
  for (int i = 0; i < q; ++i) {
    fscanf(stdin, "%d", &val);
    ans += s.count(val);
  }
  fprintf(stdout, "%d\n", ans);
  return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <queue>
#define rep(i, a, n) for(int i = int(a);i < int(n);++i)
#define repe(i, a, n) for(int i = int(a);i <= int(n);++i)
#define repr(i, a, n) for(int i = int(a);i > int(n);--i)
#define reper(i, a, n) for(int i = int(a);i >= int(n);--i)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define pb push_back
#define EPS (1e-20)
#define INF 2147483647
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using namespace std;


int H, W;
char s[60][60];


bool solve(){
	int dx[4] = { 1, 0, -1, 0 };
	int dy[4] = { 0, 1, 0, -1 };
	rep(i, 0, H){
		rep(j, 0, W){
			if(s[i][j] == '.') continue;
			rep(k, 0, 4){
				int X = j + dx[k];
				int Y = i + dy[k];
				if(0 <= X && X < W && 0 <= Y && Y < H && s[Y][X] == '#') break;
				if(k == 3) return false;
			}
		}
	}
	return true;
}


int main(){
	cin >> H >> W;
	rep(i, 0, H)
		rep(j, 0, W) cin >> s[i][j];
	if(solve()) Yes;
	else No;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
typedef long long ll;
using namespace std;
int main(void){
    int n;cin>>n;
    map<string,int> mp;
    rep(i,n){
        string s;cin>>s;
        mp[s]++;
    }
    int res=mp.size();
    cout<<res<<endl;
}


Measured memory_bytes: 19184
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll x,t{100},ans{};
    cin>>x;
    while(t<x){
        ++ans;
        t=t*1.01;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define ll long long
#define P pair<int ,int>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<vector<int>> vec(2 ,vector<int>(n));
    for(int i=0;i<n;i++) cin >> vec[0][i];
    for(int i=0;i<n;i++) cin >> vec[1][i];

    int ans = 0;
    for(int down = 0 ; down < n ; down++){
        int sum = 0;
        int tate = 0;
        for(int j=0;j<n;j++){
            if(j == down){
                sum += vec[tate][j];
                tate++;
                sum += vec[tate][j];
            }else {
                sum += vec[tate][j];
            }
        }ans = max (ans ,sum);
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
//------------------------------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//																				NEVER GIVE UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define mod 100000007
#define testcases() ll t; cin>>t; while(t--)
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define rep(i,start,end) for(ll i=start;i<end;i++)
 
//----------------------------------------------------------------------------------------------------------------------------------------------------

int main(){
  	int n,m;
  	cin>>n>>m;
  	if(n==m){
      cout<<"Yes";
    } else {
      cout<<"No";
    }
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <time.h>
#include <string>
#include <iomanip>
#include <algorithm>


using namespace std;

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  cout<<((a*b*c)/max({a,b,c}))/2<<endl;
  return 0;
}

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

int main(){
    int n; cin >> n;
    long long A[n];
    long long cons = 922337203685477580;
    for(int i = 0; i < n; i ++){
        cin >> A[i];
        //cout << A[i] << endl;
    }

    long long right_sum = A[n-1];
    long long left_sum = A[0];
    int right_ptr = n-2;
    int left_ptr = 1;
    //cout << right_ptr << endl;

    for(int i = 0; i < n-2; i++){
        if(left_sum < right_sum){
            left_sum += A[left_ptr];
            left_ptr++;
        }
        else{
            right_sum += A[right_ptr];
            right_ptr--;
        }
        if (left_sum > cons && right_sum > cons){
            left_sum -= cons;
            right_sum -= cons;
        }
        //cout << left_sum << " "<< right_sum << endl;
    }
    long long ans = 0;
  //cout << right_sum << " " << left_sum << endl; 
    if(left_sum < right_sum) ans = right_sum - left_sum;
    else ans = left_sum - right_sum;
    cout << ans << endl;

    return 0; 
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    set<int> s;
    rep(i,n){
        int a;
        cin >> a;
        s.insert(a);
    }
    int q;
    cin >> q;
    int ans = 0;
    rep(i,q){
        int b;
        cin >> b;
        if(s.find(b) != s.end()) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

const ll INF = 2e9;

ll dist[305][305], dist2[305][305];

void warchall_floyd(int N){
    rep(k,N)rep(i,N){
        if(dist[i][k] == INF) continue;
        rep(j,N){
            if(dist[k][j] == INF) continue;
	        chmin(dist[i][j], dist[i][k]+dist[k][j]);
        }
    }
}

void warchall_floyd2(int N){
    rep(k,N)rep(i,N){
        if(dist2[i][k] == INF) continue;
        rep(j,N){
            if(dist2[k][j] == INF) continue;
	        chmin(dist2[i][j], dist2[i][k]+dist2[k][j]);
        }
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int v, e;
	ll l;
    cin >> v >> e >> l;
    rep(i,v){
        rep(j,v) dist[i][j] = dist2[i][j] = INF;
        dist[i][i] = dist2[i][i] = 0;
    }
    rep(i,e){
        int s, t;
		ll d;
        cin >> s >> t >> d;
		--s; --t;
		if(d > l) continue;
        dist[s][t] = d;
		dist[t][s] = d;
    }
    warchall_floyd(v);
	rep(i,v)rep(j,v){
		if(dist[i][j] <= l) dist2[i][j] = 1;
	}
	warchall_floyd2(v);
	int q;
	cin >> q;
	rep(qi,q){
		int s, t;
		cin >> s >> t;
		--s; --t;
		cout << (dist2[s][t] == INF ? -1 : dist2[s][t]-1) << endl;
	}
    return 0;
}

Measured memory_bytes: 5044
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first

#if MYDEBUG
#define DBG(...) {string dst__=#__VA_ARGS__;dbgsplit(dst__);stringstream dss__; dss__<<dst__; debug(dss__,__VA_ARGS__);}
#else
#define DBG(...)
#endif
void debug(stringstream& ds){cerr<<endl;return;}
template<typename F, typename... R>void debug(stringstream& ds,const F& f, const R&... r){string n; ds>>n; cerr<< n <<'='<<f<<' '; debug(ds,r...);}
void dbgsplit(string &s){int l=s.length(),n=0;for(int i=0; i<l; ++i){if(s[i]=='(')++n;if(s[i]==')')--n;if(s[i]==','&&!n)s[i]=' ';}}
using LL = long long;
constexpr long long LINF=334ll<<53; constexpr int INF=15<<26; constexpr long long MOD=1E9+7;

struct Edge{
    int from,to;
};
using Graph = vector<vector<Edge>>;

//<f,s>
pair<int,int> dfs(int par, int cur, Graph &t){
    if((int)t[cur].size()==1 and t[cur][0].to==par){
        return{0,1};
    }
    int sum=0,prd=0,f=0;
    for(auto &e: t[cur]){
        if(e.to!= par){
            auto sub = dfs(cur,e.to,t);
            f=max(f,sub.first);
            prd |= sum&sub.second;
            sum |= sub.second;
        }
    }
    int res=(int)log2((int)t.size())+2;
    while(res>=0 && !(prd&(1<<res)))res--;
    res++;
    while(sum&(1<<res))res++;
    DBG(cur,res,max(f,res),(((sum>>res)|1)<<res))
    return {max(f,res),(((sum>>res)|1)<<res)};
}

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

    int n;
    cin >> n;
    Graph t(n);
    for(int i=0; i<n-1; ++i){
        int a,b;
        cin >> a >>b;
        --a;--b;
        t[a].push_back({a,b});
        t[b].push_back({b,a});
    }
    cout << dfs(-1,0,t).first<<"\n";

    return 0;
}



Measured memory_bytes: 11392
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int S = sc.nextInt();
        int h = S / 3600;
        int m = S % 3600 /60;
        int s = S % 3600 % 60;
        System.out.println(h + ":" + m +":" + s);
    }
}


Measured memory_bytes: 26408
#解説方針
import math
N = int(input())
A = list(map(int, input().split()))

all_xor = 0
for i in range(N):
  all_xor = all_xor ^ A[i]

fore = A[0] ^ A[1]#S
back = fore ^ all_xor #X
#a + b = (a xor b) + 2 * (a and b)
#a xor b = back, a + b = A[0] + A[1]

a_and_b = (A[0] + A[1] - back) / 2
#print(a_and_b, back)
#a_and_bは非負整数である必要がある
if (a_and_b % 1 != 0) or (a_and_b < 0):
  print(-1)
  quit()
a_and_b = int(a_and_b)

#print(a_and_b, back, a_and_b & back)
#a_and_bとbackには共通のbitがない
if (a_and_b & back) != 0:
  print(-1)
  quit()

ans = a_and_b
#print(math.log2(32))
if back == 0:
  if (ans == 0):
    print(-1)
  else:
    print(A[0] - ans)
  quit()
else:
  if ans > A[0]:
    print(-1)
    quit()
  nn = int(math.log2(back)) + 1
  #print(nn)
  #print(2 >> 1)
  #print(2 << 1)
  for i in range(nn + 1):
    #print(back, nn - i)
    if ((back >> (nn - i)) & 1):
      #print(ans, 2 << (nn - i))
      k = ans + (1 << (nn - i))
      #print("k", k, i)
      if k <= A[0]:
        ans = k 
  if (ans == 0):
    print(-1)
  else:
    print(A[0] - ans)
  
  

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

const int mod = 1000000007;
struct mint {
  ll x;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

vector<bool> prime_table(int n) {
  vector<bool> prime(n + 1, true);
  if (n >= 0) prime[0] = false;
  if (n >= 1) prime[1] = false;
  for (int i = 2; i * i <= n; i++) {
    if (!prime[i]) continue;
    for (int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}

ll mod_pow(ll x, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

int main() {
  ll n, k;
  cin >> n >> k;
  vector<set<ll>> d(k);
  FOR(i, 1, k + 1) {
    auto ad = divisor(i);
    for (auto x : ad) {
      d[i - 1].insert(x);
    }
  }

  mint ans = 0;

  map<ll, mint> sum;
  FORR(i, k, 2) {
    mint tmp = mod_pow(k / i, n, mod);
    mint cnt = tmp - sum[i];
    ans += cnt * i;
    ans -= cnt;
    for (auto x : d[i - 1]) {
      sum[x] += cnt;
    }
  }
  ans += mod_pow(k, n, mod);
  cout << ans.x << endl;
  return 0;
}

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

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

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

    int cnt = 0;
    for (int i = 0; i < N; ++i) {
        while (a[i] % 2 == 0) {
            cnt++;
            a[i] = a[i] / 2;
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x,y) make_pair(x,y)

int main(){
  ll N,K;
  cin>>N>>K;
  vector<ll> H(N);
  for(ll i=0;i<N;i++){
    cin>>H[i];
  }
sort(ALL(H));
reverse(ALL(H));
ll tmp=0;
for(ll i=K;i<N;i++){
tmp+= H[i];
}
cout<<tmp<<endl;


  
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
#define MOD 1000000007
#define MAX(a,b) (a>b?a:b)
#define MAX3(a,b,c) MAX(a,MAX(b,c))
#define MIN(a,b) (a<b?a:b)
#define MIN3(a,b,c) MIN(a, MIN(b,c))
typedef long long lli;
typedef struct {
    int tate;
    int yoko;
} lamp;

int main()
{
    int i,x,n,l[100],ans=1,now=0;
    scanf("%d%d",&n,&x);
    for(i=0; i<n; i++) {
        scanf("%d",l+i);
        if((now+=l[i])<=x) {
            ans++;
        } else {
            break;
        }
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using ll = long long;
using ld = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VI = vector<int>;
using VVI = vector<VI>;
using Vll = vector<ll>;
using VVll = vector<Vll>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  int N;
  cin >> N;
  string S;
  cin >> S;
  int cb = 0;
  REPR(i, S.size())
  {
    if (S[i] == ')') cb++;
    else if (cb > 0) cb--;
  }
  string add = "";
  REP(i, cb) add += '(';
  S = add + S;
  int ob = 0;
  REP(i, S.size())
  {
    if (S[i] == '(') ob++;
    else if (ob > 0) ob--;
  }
  add = "";
  REP(i, ob) add += ')';
  S = S + add;
  cout << S << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iomanip>

using namespace std;

int main() {
	int N, M; cin >> N >> M;
	vector<int> cities(N, 0);
	int from, to;

	for (int i = 0; i < M; i++) {
		cin >> from >> to;
		cities.at(from - 1)++;
		cities.at(to - 1)++;
	}

	for (int i = 0; i < N; i++) {
		cout << cities.at(i) << endl;
	}

}




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

int main() {
     
     long long n,h,i,j,t,m,l,r,q;
     long long p=0,k,w,z,x,y,d;
     q=1;
     for(l=0;l<q;l++)
     {
          string s,st;
          std::cin >> s ;
          std::cin >> st;
          n=s.length();
          x=0;
          for(i=0;i<n;i++)
          {
               if(s[i]!=st[i])
                    x++;
          }
          std::cout << x << std::endl;
     }
     return 0;
}

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

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n;
	double o;
	cin >> n;

	vector<double> dp(n + 3, 0);

	dp[0] = 1;

	for(int i = 1; i <= n; i++) {
		cin >> o;
		for(int j = i; j >= 0; j--) {
			dp[j] = (j == 0 ? 0 : dp[j - 1] * o) + dp[j] * (1-o);
		}
	}	
	double wy = 0;
	for(int i = 1; i <= n; i++) {
		int j = n - i;
		if(i > j) {
			wy += dp[i];
		}
	}
	cout << fixed << setprecision(10) << wy;
}

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

using namespace std;
typedef long long ll;
#define DBG(v) cerr << #v << " = " << (v) << endl;

const int MxN = 2009;

bool piece[MxN + 9];
vector<int> adj[MxN + 9];
int depth[MxN + 9];
int cnt[MxN + 9];

pair<ll, ll> dfs(const int u, const int parent) {
    vector<pair<ll, ll>> v;
    v.reserve(adj[u].size());

    cnt[u] = piece[u];
    for (const int x : adj[u]) {
        if (x == parent)
            continue;
        depth[x] = depth[u] + 1;
        v.push_back(dfs(x, u));
        v.back().first += cnt[x];
        v.back().second += cnt[x];
        cnt[u] += cnt[x];
    }

    if (v.empty())
        return {0, 0};
    if (v.size() == 1)
        return v[0];
    swap(v[0], *max_element(v.begin(), v.end()));


    pair<ll, ll> res = {0, 0};

    for (const pair<ll, ll> &p  : v)
        res.second += p.second;

    res.first = max(res.second & 1, v[0].first - (res.second - v[0].second));
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        char c;
        cin >> c;
        assert(c == '0' || c == '1');
        piece[i] = c == '1';
    }

    for (int i = 1; i < n; ++i) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    const ll Inf = 1LL << 60;
    ll ans = Inf;
    for (int root = 1; root <= n; ++root) {
        memset(depth, 0, sizeof depth);
        memset(cnt, 0, sizeof cnt);
        if (dfs(root, -1).first == 0) {
            ll res = 0;
            for (int i = 1; i <= n; ++i)
                if (piece[i])
                    res += depth[i];

            assert(res % 2 == 0);
            res /= 2;

            ans = min(ans, res);
        }
    }
    cout << (ans == Inf ? -1 : ans);
    return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int n, m;
int a[200000], b[200000];

int main() {
    scanf("%d%d", &n, &m);
    forn(i, m) {
        int from, to;
        scanf("%d%d", &from, &to), --from, --to;
        if (from == 0) {
            a[to] = 1;
        }
        if (to == n - 1) {
            b[from] = 1;
        }
    }
    for (int i = 1; i < n - 1; ++i) {
        if (a[i] && b[i]) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K;
  cin >> N >> K;
  vector<int> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  sort(H.begin(), H.end());
  int res = 1000000010;
  for (int i = 0; i < N - K + 1; i++) {
    res = min(res, H[i + K - 1] - H[i]);
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){

  while(x->left != NIL){
    x = x->left;
  }
  return x;

}

Node treeSearch(Node u, int k){
  if(u == NIL || k == u->key){
    return u;
  }
  if(k < u->key){
    return treeSearch(u->left,k);
  }
  else{
    return treeSearch(u->right,k);
  }

}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL){
    return treeMinimum(x->right);
  }

  y = x->parent;

  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left == NIL || z->right == NIL){
    y = z;
  }
  else{
    y = treeSuccessor(z);
  }
  if(y->left != NIL){
    x = y->left;
  }
  else{
    x = y->right;
  }

  if(x != NIL){
    x->parent = y->parent;
  }
  
  if(y->parent == NIL){
    root = x;
      }
  else if(y == y->parent->left){
    y->parent->left = x;
  }
  else{
    y->parent->right = x;
  }

  if(y != z){
    z->key = y->key;
  }
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }
    z->parent = y;

    if(y == NIL){
      root = z;
    }
    else if(z->key < y->key){
      y->left = z;
    }
    else{
      y->right = z;
    }

}

void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" ");
    printf("%d",u->key);

    inorder(u->right);
  }
}
void preorder(Node u){
  if(u != NIL){
  printf(" ");
  printf("%d",u->key);
  
  preorder(u->left);
  preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 24040
s=input()
l=len(s)
q=int(input())
cnt=1
l=str()
r=str()

for _ in range(q):
	a=list(input().split())
	if a[0]=="1":
		cnt*=(-1)
	else:
		if int(a[1])*cnt==1 or int(a[1])*cnt==-2:
			l+=a[2]
		else:
			r+=a[2]				

s=l[::-1]+s+r
if cnt==-1:
	s=s[::-1] 	

print(s)

Measured memory_bytes: 4468
from collections import Counter 
from collections import defaultdict
from collections import deque
from functools import reduce
import math
import itertools
import heapq
import numpy as np
import bisect
import sys
sys.setrecursionlimit(10**6)


def bfs(s,n,node):
    #頂点が探索済みかどうかのチェック配列
    check=[False for _ in range(n)]
    check[s]=True
    #次見る頂点を格納するキュー
    queue=deque([s])
    visited_num=1

    #問題固有の配列
    #color_check=[[True for _ in range(l)] for _ in range(n)]
    color=[-1 for _ in range(n)]
    color[s]=0
    
    while visited_num<n:
        #グラフが全連結ではない場合
        if len(queue)==0:
            #空配列を返す
            #現状までの計算済み配列を返してもいいと思う
            return color

        now_vertex=queue.popleft()
        #インデックスがない場合は
        for next_vertex in node[now_vertex]:


            if check[next_vertex]==True:
                continue

            queue.append(next_vertex)
            check[next_vertex]=True

            #問題固有の計算
            color[next_vertex]=color[now_vertex]+1
            visited_num+=1

    return color

#n=int(input())z
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
ceil=lambda x,y: (x+y-1)//y
input_list = lambda : list(map(int,input().split()))



#n=int(input())
n,m=input_list()
#a=input_list()
print(n*m)

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

#define lld long long
#define pii pair<int,int>
#define pb push_back
#define next nextt
#define Inf 1000000000
#define Linf 1000000000000000000LL
#define Mod 1000000007

using namespace std;

int N;
int cnt[100002];

void process(){puts("0");exit(0);}
int main(){
	scanf("%d",&N);
	for(int i=1; i<=N; i++){
		int x;
		scanf("%d",&x);
		if(N%2 == 1){
		if(x%2 == 1) process();
		cnt[x]++;
		if(cnt[x] == 3) process();
		if(cnt[0] == 2) process();
		}else{
			if(x%2 == 0) process();
			cnt[x]++;
			if(cnt[x] == 3) process();
		}
	}
	int ans = 1;
	for(int i=1; i<=N/2; i++){ans*=2;ans%=Mod;}
	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main() {
    int N, D, X;
    cin >> N >> D >> X;
    int ans = X;
    for (int i = 0, a; i < N; i++) {
        cin >> a;
        for (int j = 1; j <= D; j += a) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
//File Name: agc015_A.cpp
  //Created Time: 2017年06月12日 星期一 21时23分52秒
                                   
#include <bits/stdc++.h>
#define LL long long
using namespace std;
int main(){
	LL a,b,n,ans(0);
	cin >> n >> a >> b;
	if(a <= b && n >= 2)
		ans = (b - a) * (n - 2) + 1;
	else if(a == b && n <= 2)
		ans = 1;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <vector>

#define vi vector<int>

using namespace std;

int height, width;

vector<vi> cook_space;
array<bool, 10> check_reverse;


int count()
{
    int ret = 0;
    // 1?????°????????????

    for (int x = 0; x < width; ++x) {
        int not_reverse = 0;
        for (int y = 0; y < height; ++y) {
            // false && 1 or true && 0 ????????????????????¨??????
            if ( (!check_reverse.at(y) && cook_space.at(y).at(x)) ||
                    (check_reverse.at(y) && !cook_space.at(y).at(x)) ) {
                not_reverse++;
            }
        }
        int reversed = height - not_reverse;
        ret += max(reversed, not_reverse);
    }

    return ret;
}


int ans = 0;
void dfs(int depth) 
{
    // ???????????§???????????????????????????
    if (depth == height) {
        int temp = count();
        ans = max(temp, ans);
        return;
    }

    // depth???????????£??????????????????
    check_reverse.at(depth) = true;
    dfs(depth + 1);

    // depth???????????£????????????????????£??????
    check_reverse.at(depth) = false;
    dfs(depth + 1);
}


void solve()
{
    // ??¨??????
    dfs(0);
    cout << ans << endl;
}

int main()
{
    // input
    while (cin >> height >> width) {

        if (height == 0 && width == 0) break;

        cook_space.resize(height);

        for (auto& it: cook_space) {
            it.resize(width);
        }

        for (int y = 0; y < height; ++y) {
            for (int x = 0; x < width; ++x) {
                cin >> cook_space.at(y).at(x);
            }
        }

        solve();
    }

    return 0;
}

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

int main() {
    long long n, k, r,rr,d=0,ans, cnt;
    cin >> n >>k;
    vector<long long> a(n);
    for(int i=0; i<n; i++) {
        long long x;
        cin >> x;
        x--;
        a[i]=x;
    }
    map<long long, long long> m;
    for(int i=0; i<=200000; i++){
        if(m.count(d)) {
            r=i-m.at(d);
            rr=m.at(d);
            break;
        }
        else {
            m[d]=i;
            d=a[d];
        }
    }
    if(rr>k){
        d=0;
        for(int i=0; i<k; i++){
            d=a[d];
        }
    } 
    else {
        cnt=(k-rr)%r;
        for(int i=0; i<cnt; i++){
            d=a[d];
        }
        
    }
    ans=d+1;
    cout << ans;
}

Measured memory_bytes: 17172