akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,cnt;
  int w[15],t[15];
  string s;
  while(1){
    cin>>n;
    if(n==0) break;
    cnt=0;
    for(int i=0;i<15;i++){
      w[i]=1;
      t[i]=0;
    }
    for(int i=0;i<n;i++){
      cin>>s;
      if(s[0]=='R'){
	t[0]=1;
	for(int j=1;j<8;j++){
	  w[j]=0;
	}
      }
      else if(s[0]=='F'){
	t[1]=1;
	for(int j=2;j<9;j++){
	  w[j]=0;
	}
      }
       else if(s[0]=='S'){
	 if(s[1]=='c'){
	   t[2]=1;
	   for(int j=3;j<10;j++){
	     w[j]=0;
	   }
	 }
	 else if(s[1]=='n'){
	   t[3]=1;
	   for(int j=4;j<11;j++){
	     w[j]=0;
	   }
	 }
	 else if(s[1]=='p'){
	   t[7]=1;
	   for(int j=8;j<15;j++){
	     w[j]=0;
	   }
	 }
       }
       else if(s[0]=='H'){
	 t[4]=1;
	 for(int j=5;j<12;j++){
	   w[j]=0;
	 }
       }
       else if(s[0]=='T'){
	 t[5]=1;
	 for(int j=6;j<13;j++){
	   w[j]=0;
	 }
       }
       else if(s[0]=='W'){
	 if(s[1]=='o'){
	   t[6]=1;
	   for(int j=7;j<14;j++){
	     w[j]=0;
	   }
	 }
	 else if(s[1]=='a'){
	   t[10]=1;
	   for(int j=11;j<15;j++){
	     w[j]=0;
	   }
	   for(int j=0;j<3;j++){
	     w[j]=0;
	   }
	 }
       }
       else if(s[0]=='P'){
	 t[8]=1;
	 w[0]=0;
	 for(int j=9;j<15;j++){
	   w[j]=0;
	 }
       }
      else if(s[0]=='A'){
	 t[9]=1;
	 w[0]=0;
	 w[1]=0;
	 for(int j=10;j<15;j++){
	   w[j]=0;
	 }
       }
      else if(s[0]=='D'){
	if(s[1]=='r'){
	  t[11]=1;
	  for(int j=12;j<15;j++){
	    w[j]=0;
	  }
	   for(int j=0;j<4;j++){
	    w[j]=0;
	  }
	}
	else if(s[1]=='e'){
	  t[12]=1;
	  for(int j=13;j<15;j++){
	    w[j]=0;
	  }
	   for(int j=0;j<5;j++){
	    w[j]=0;
	  }
	}
      }
      else if(s[0]=='L'){
	t[13]=1;
	w[14]=0;
	for(int j=0;j<6;j++){
	  w[j]=0;
	}
      }
      else if(s[0]=='G'){
	t[14]=1;
	for(int j=0;j<7;j++){
	  w[j]=0;
	}
      }
    }
    for(int i=0;i<15;i++){
      if(t[i]==1) cnt++;
    }
    if(cnt==1) cout<<"Draw"<<endl;
    else{
      for(int i=0;i<15;i++){
	if(t[i]==1){
	  if(w[i]==1){
	    if(i==0){
	      cout<<"Rock"<<endl;
	      break;
	    }
	    else if(i==1){
	      cout<<"Fire"<<endl;
	      break;
	    }
	    else if(i==2){
	      cout<<"Scissors"<<endl;
	      break;
	    }
	    else if(i==3){
	      cout<<"Snake"<<endl;
	      break;
	    }
	    else if(i==4){
	      cout<<"Human"<<endl;
	      break;
	    }
	    else if(i==5){
	      cout<<"Tree"<<endl;
	      break;
	    }
	    else if(i==6){
	      cout<<"Wolf"<<endl;
	      break;
	    }
	    else if(i==7){
	      cout<<"Sponge"<<endl;
	      break;
	    }
	    else if(i==8){
	      cout<<"Paper"<<endl;
	      break;
	    }
	    else if(i==9){
	      cout<<"Air"<<endl;
	      break;
	    }
	    else if(i==10){
	      cout<<"Water"<<endl;
	      break;
	    }
	    else if(i==11){
	      cout<<"Dragon"<<endl;
	      break;
	    }
	    else if(i==12){
	      cout<<"Devil"<<endl;
	      break;
	    }
	    else if(i==13){
	      cout<<"Lightning"<<endl;
	      break;
	    }
	    else if(i==14){
	      cout<<"Gun"<<endl;
	      break;
	    }
	  }
	}
	if(i==14) cout<<"Draw"<<endl;
      }
    }
  }
  return 0;
}



Measured memory_bytes: 3144
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        MyReader r = new MyReader();        
        int N = r.i();
        int[][] C = new int[N][2];
        for(int i = 0; i < N; i++)
            C[i] = r.ii();
        Arrays.sort(C, (x, y) -> {
            int z = x[1]-y[1];
            if(z == 0)
                return x[0]-y[0];
            else
                return z;
        });
        long t = 0;
        for(int[] c : C){
            t += c[0];
            if(t > c[1]){
                println("No");
                return;
            }
        }
        println("Yes");
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long.parseLong(ss[j]);            
            return ll;
        }
    }
}

Measured memory_bytes: 66976
// May this submission get accepted
#pragma GCC optimize ("O3")
#pragma GCC target("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) { if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(DUMPALL_ITR, (q).size()) { cerr << (q)[DUMPALL_ITR] << (DUMPALL_ITR == DUMPALL_ITR_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using  ld = long double;
using namespace std;

// 標準入出力
struct inp {
    size_t sz;
    inp(size_t _sz = 1) : sz(_sz) {}
    template <typename T> operator T () const { T a; cin >> a; return a; }
    template <typename T> operator vector<T> () const { vector<T> a(sz); for (size_t i = 0; i < sz; i++) cin >> a[i]; return a; }
    template <typename T, typename U> operator pair<T, U> () const { T f; U s; cin >> f >> s; return pair<T, U>(f, s); }
};
inp inp1; // input one
template <typename T> void say(T &x, char end = '\n') { cout << x << end; }
template <typename T> void say(vector<T> &x, char sep = ' ', char end = '\n') { for (size_t i = 0, sz = x.size(); i < sz; i++) { cout << x[i] << (i == sz-1 ? end : sep); } }

// モジュール


// 処理内容
int main() {
    
    ios::sync_with_stdio(false); // stdioを使うときはコメントアウトすること
    cin.tie(nullptr);            // インタラクティブ問題ではコメントアウトすること
    
    ll n = inp1;
    vector<ll> a = inp(n);

    bool ac = true;
    REP(i, n) {
        if (a[i] % 2 == 0 && (a[i] % 3 && a[i] % 5)) {
            ac = false;
            break;
        }
    }
    cout << (ac ? "APPROVED" : "DENIED") << endl;
    
}

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

int main() {
    int N;
    cin >> N;
    vector<string> S(N);
    rep(i, N) cin >> S[i];

    rep(i, N) sort(S[i].begin(), S[i].end());
    ll ans = 0;
    map<string, ll> mp;

    rep(i, N) mp[S[i]]++;

    for (auto p : mp)
        if (p.second != 1) {
            ll a = p.second - 1;
            ans += a * (a + 1) / 2;
        }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 18176
#include <cstdio>
#include <utility>
#include <vector>
#include <array>
#include <tuple>
#include <algorithm>

struct edge{ int dest, color, length; };
struct node_param{ int nstep, ncount, length; };
struct euler_param{ int ncount, clength, cnum; };
std::vector<std::vector<edge>> t_arr;
std::vector<std::array<int, 20>> parent_arr;
std::vector<node_param> node_arr;
std::vector<std::vector<euler_param>> color_path_arr;

void dfs(int current, int parent, int nstep, int& ncount, int length, std::vector<int>& current_clength, std::vector<int>& current_cnum){
  parent_arr[current][0] = parent;
  for(int k = 0; k < 20; k++){
    if(parent_arr[current][k] == -1) break;
    parent_arr[current][k+1] = parent_arr[parent_arr[current][k]][k];
  }
  node_arr[current].nstep = nstep;
  node_arr[current].ncount = ncount;
  node_arr[current].length = length;
  for(const auto& it: t_arr.at(current)){
    if(it.dest==parent) continue;
    ncount++;
    current_cnum[it.color]++;
    current_clength[it.color] += it.length;
    color_path_arr[it.color].push_back(euler_param{ncount, current_clength[it.color], current_cnum[it.color]});
    dfs(it.dest, current, nstep+1, ncount, length+it.length, current_clength, current_cnum);
    ncount++;
    current_cnum[it.color]--;
    current_clength[it.color] -= it.length;
    color_path_arr[it.color].push_back(euler_param{ncount, current_clength[it.color], current_cnum[it.color]});
  }
}

int lca(int node1, int node2){
  if(node_arr[node1].nstep > node_arr[node2].nstep) std::swap(node1, node2);
  int nstep_diff = node_arr[node2].nstep-node_arr[node1].nstep;
  int k = 0;
  while(nstep_diff > 0){
    if(nstep_diff & 1) node2 = parent_arr[node2][k];
    k++;
    nstep_diff >>= 1;
  }
  while(node1 != node2){
    int k2 = 0;
    while(parent_arr[node1][k2] != parent_arr[node2][k2]) k2++;
    k2 = std::max(0, k2-1);
    node1 = parent_arr[node1][k2];
    node2 = parent_arr[node2][k2];
  }
  return node1;
}

auto search_color_root(int color, int node){
  const auto& left = std::upper_bound(color_path_arr[color].begin(), color_path_arr[color].end(), node_arr[node].ncount, [](const int l, const euler_param& r){ return l < r.ncount;})-1;
  return *left;
}

int main(){
  int N,Q;
  scanf("%d%d", &N, &Q);
  t_arr.resize(N);
  for(int i = 0; i < N-1; i++){
    int a,b,c,d;
		scanf("%d%d%d%d", &a, &b, &c, &d);
    a--; b--; c--;
    t_arr[a].push_back(edge{b,c,d});
    t_arr[b].push_back(edge{a,c,d});
  }

  parent_arr.resize(N, {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1} );
  node_arr.resize(N);
  color_path_arr.resize(N, std::vector<euler_param>(1));
  std::vector<int> clength(N), cnum(N);
  int ncount;
  dfs(0, -1, 0, ncount, 0, clength, cnum);

  for(int i = 0; i < Q; i++){
    int x,y,u,v;
    scanf("%d%d%d%d", &x, &y, &u, &v);
    x--; u--; v--;
    int lcauv = lca(u,v);
    auto color_shift = [&](int node){
      auto cr = search_color_root(x, node);
      return node_arr[node].length + y*cr.cnum-cr.clength;
    };
    int ans = color_shift(u) + color_shift(v) - 2*color_shift(lcauv);
    printf("%d\n", ans);
  }

  return 0;
}




Measured memory_bytes: 32900
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <cstdlib>

using namespace std;

#define LL long long
#define INF 0x7fffffff
#define P 998244353

LL read(){
    LL x=0,f=1; char ch=getchar();
    while (ch<'0' || ch>'9') {if (ch=='-') f=-1; ch=getchar();}
    while (ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

int N,M,S,T;
#define MAXN 200100
struct EdgeNode{
    int next,to,dis,from;
}edge[MAXN<<1];
int head[MAXN],cnt;

void AddEdge(int u,int v,int w) {cnt++; edge[cnt].next=head[u]; head[u]=cnt; edge[cnt].to=v; edge[cnt].from=u; edge[cnt].dis=w;}
void InsertEdge(int u,int v,int w) {AddEdge(u,v,w); AddEdge(v,u,w);}

int deep[MAXN];
void dfs(int now,int last){
	for (int i=head[now]; i; i=edge[i].next)
		if (edge[i].to!=last){
			deep[edge[i].to]=deep[now]+1;
			dfs(edge[i].to,now);
		}
}

int f[MAXN];
int main(){
	N=read();
	for (int i=1; i<=N-1; i++){
		int u=read(),v=read();
		InsertEdge(u,v,1);
	}
	dfs(1,0);
	int mx = 0,mxk;
	for(int i=1; i<=N; i++){
		if (deep[i]>mx) mx=deep[i],mxk=i;
	}
	for (int i=1; i<=N; i++) deep[i]=0;
	dfs(mxk,0);
	for (int i=1; i<=N; i++){
		if (deep[i]>mx) mx = deep[i];
	}
	// printf("%d\n",mx);
	int len = mx+1;
	f[1]=1; f[2]=0;
	for (int i=3; i<=len; i++){
		if (f[i-2] && f[i-1]) f[i]=0;
		else f[i]=1;
	}
	if (f[len]) puts("First");
	else puts("Second");
	return 0;
}


Measured memory_bytes: 18176
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**6)
INF = float('inf')
MOD = 10 ** 9 + 7
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rf(): return float(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]
def rf_(): return [float(_) for _ in rs().split()]
def divisors(n, sortedresult=True):
    div = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            div.append(i)
            if i != n // i:
                div.append(n//i)
    if sortedresult:
        div.sort()
    return div
# endregion
N, W = ri_()
w, v = [0] * N, [0] * N
for i in range(N):
    w[i], v[i] = ri_()
dp = [[INF] * (N * (10 ** 3) + 1) for _ in range(N + 1)]
dp[0][0] = 0
for i in range(N):
    for j in range(N * (10 ** 3) + 1):
        if j - v[i] >= 0:
            dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i])
        else:
            dp[i + 1][j] = dp[i][j]
ans = 0
for j in range(N * (10 ** 3) + 1):
    if dp[N][j] <= W:
        ans = max(ans, j)
print(ans)

Measured memory_bytes: 309256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i = 0; i < (ll) n; i++)
#define xrep(i,x,n) for(ll i = (ll) x; i < (ll) n; i++)
#define vl vector<long long>
#define vs vector<string>
#define vvl vector<vector<long long>>
#define all(A) A.begin(), A.end()

int main() {
    ll n, k;
    cin >> n >> k;
    vl p(n);
    rep(i,n) cin >> p[i];

    sort(all(p));

    ll ans = 0;
    rep(i,k){
        ans += p[i];
    }

    cout << ans << endl;

}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repc(i, b, e) for(auto i = (b); i != (e); i++)

int main() {
    ll A, B, C;
    cin >> A >> B >> C;
    A = A - C;
    B = C - B;
    if(A * B < 0) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys,math,copy,queue,itertools,bisect
sys.setrecursionlimit(10**7)
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
INF = 10**18
MOD = 10**9 + 7
DD = ((1,0),(0,1),(-1,0),(0,-1))
m = [0,1,3,3,7,7,7,14,22,22,22,33,33,46,60]
x = [0,1,2,2,3,3,3,4,5,5,5,6,6,7,8]
N = NI()

a = N // 15
b = (a)*(a-1) * 60 + a*60
c = N % 15
d = (a) * 15 * x[c]  + m[c]
ans = b + d
print (ans)

Measured memory_bytes: 68692
fun main(args: Array<String>){
    val (n,k) = nextIntList()

    val sunukeS = arrayOfNulls<Boolean>(n)

    fun checkO(){
        val d = next().toInt()
        val aS = nextIntList()
        aS.forEach {
            sunukeS[it - 1] = true
        }
    }

    for(i in 1..k){
        checkO()
    }

    println(sunukeS.count{it == null })

}
fun next() = readLine()!!
fun nextIntList() = next().split(" ").map{ it.toInt() }

Measured memory_bytes: 39052
#include<iostream>
#include<iomanip>
#include<vector>
#include<set>
using namespace std;

class Square {
public:
    Square(double x, double y, double r) :x_(x), y_(y), r_(r) {}

    double left() const {return x_ - r_;}
    double right() const {return x_ + r_;}
    double bottom() const {return y_ - r_;}
    double top() const {return y_ + r_;}

private:
    double x_, y_, r_;
};

int main() {
    int step = 0;
    int n;
    while(cin >> n, n) {
        vector<Square> square;
        set<double> line;
        for(int i = 0; i < n; ++i) {
            double x, y, r;
            cin >> x >> y >> r;
            square.push_back(Square(x, y, r));
            line.insert(x - r);
            line.insert(x + r);
        }

        double answer = 0.0;
        double previous_x = 0.0;
        double previous_distance = 0.0;

        for(const auto& l: line) {
            const bool IN = true;
            const bool OUT = false;
            struct Node {
                double y;
                bool in;
                Node(double y, bool b) :y(y), in(b) {}
                bool operator<(const Node& n) const {return y != n.y ? y < n.y : in > n.in;}
            };

            answer += previous_distance * (l - previous_x);
            previous_x = l;
            previous_distance = 0.0;

            multiset<Node> node;
            for(const auto& s: square) {
                if(s.right() <= l || l < s.left()) continue;
                node.insert(Node(s.bottom(), IN));
                node.insert(Node(s.top(), OUT));
            }
            double y;
            int in = 0;
            for(const auto& n: node) {
                if(in == 0) y = n.y;
                previous_distance += n.y - y;
                y = n.y;
                in += n.in ? 1 : -1;
            }
        }

        cout << setprecision(2) << fixed << ++step << " " << answer << endl;
    }
}

Measured memory_bytes: 1308
n,m = map(int,input().split())
if n == 1:
    if m == 1:
        print(1)
    elif m == 2:
        print(0)
    elif m >= 3:
        print(m-2)
elif n == 2:
    print(0)
elif n >= 3:
    if m == 1:
        print(n-2)
    elif m == 2:
        print(0)
    elif m >= 3:
        print((n-2)*(m-2))
        

Measured memory_bytes: 3060
def read_tokens():
    return input().strip().split(' ')

def read_ints():
    return [int(token) for token in read_tokens()]

def solve(b, n):
    ret = []
    while len(b) > 0:
        # print(b)
        c = None
        for i in reversed(range(len(b))):
            if b[i] > i + 1:
                return [-1]
            if b[i] == i + 1:
                c = b[:i] + b[i+1:]
                ret.append(b[i])
                break
        if c is None:
            return [-1]
        b = c
    return list(reversed(ret))

n, = read_ints()
b = read_ints()

ans = solve(b, n)
print('\n'.join(str(x) for x in ans))

Measured memory_bytes: 3316
n=int(input())
lo=2
li=1
cou=0
import sys
if n==1:
    print(1)
    sys.exit()
if n==2:
    print(3)
    sys.exit()

for  i in range(n-1):

    cou=lo+li
    lo=li
    li=cou
   

print(cou)





Measured memory_bytes: 2940
class Dice:	
	def __init__( self, nums ):
		self.face = nums
	
	def rolltoTop( self, dicenum ):	
		num = 0
		for i,val in enumerate( self.face ):
			if dicenum == val:
				num = i
				break
		if num == 1:
			self.roll( "N" )
		elif num == 2:
			self.roll( "W" )
		elif num == 3:
			self.roll( "E" )
		elif num == 4:
			self.roll( "S" )
		elif num == 5:
			self.roll( "NN" )
	
	def roll( self, actions ):
		for act in actions:
			t = 0
			if act == "E":
				t =   self.face[0]
				self.face[0] =   self.face[3]
				self.face[3] =   self.face[5]
				self.face[5] =   self.face[2]
				self.face[2] = t
			elif  act == "N":
				t =   self.face[0]
				self.face[0] =   self.face[1]
				self.face[1] =   self.face[5]
				self.face[5] =   self.face[4]
				self.face[4] = t
			elif  act == "S":
				t =  self.face[ 0]
				self.face[0] =  self.face[4]
				self.face[4] =  self.face[5]
				self.face[5] =  self.face[1]
				self.face[1] = t	
			elif  act == "W":
				t =  self.face[0]
				self.face[0] =  self.face[2]
				self.face[2] =  self.face[5]
				self.face[5] =  self.face[3]
				self.face[3] = t	
			elif  act == "M":
				t =  self.face[1]
				self.face[1] =  self.face[2]
				self.face[2] =  self.face[4]
				self.face[4] =  self.face[3]
				self.face[3] = t

diceface = [ int( val ) for val in input( ).split( " " ) ]
dice = Dice( diceface )
q = int( input( ) )
for i in range( q ):
	topnum, frontnum = [ int( val ) for val in input( ).split( " " ) ]
	dice.rolltoTop( topnum )
	while dice.face[1] != frontnum:
		dice.roll( "M" )
		
	print( dice.face[2] )

Measured memory_bytes: 6824
#include<iostream>
using namespace std;
int N;
int A[2<<17];
long mod=998244353;
long X[1<<20],Y[1<<20];
void func(int id,int a)
{
	(X[id]+=Y[id]*a)%=mod;
	(Y[id]+=a)%=mod;
}
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
main()
{
	cin>>N;
	for(int i=0;i<N;i++)
	{
		cin>>A[i];
		for(int j=1;j*j<=A[i];j++)
		{
			if(A[i]%j==0)
			{
				func(j,A[i]);
				if(A[i]/j>j)func(A[i]/j,A[i]);
			}
		}
	}
	long ans=0;
	for(int i=1000000;i>0;i--)
	{
		for(int j=i+i;j<=1000000;j+=i)
		{
			X[i]-=X[j];
		}
		X[i]=(X[i]%mod+mod)%mod;
		(ans+=X[i]*power(i,mod-2))%=mod;
	}
	cout<<ans<<endl;
}


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

int main() {
    string s; cin >> s;
    int a, b, c, d;
    a = (int)(s[0] - '0');
    b = (int)(s[1] - '0');
    c = (int)(s[2] - '0');
    d = (int)(s[3] - '0');
    if (a-b-c-d == 7) {
        cout << a << "-" << b << "-" << c << "-" << d << "=7" << endl;
    } else if (a-b-c+d == 7) {
        cout << a << "-" << b << "-" << c << "+" << d << "=7" << endl;
    } else if (a-b+c-d == 7) {
        cout << a << "-" << b << "+" << c << "-" << d << "=7" << endl;
    } else if (a-b+c+d == 7) {
        cout << a << "-" << b << "+" << c << "+" << d << "=7" << endl;
    } else if (a+b-c-d == 7) {
        cout << a << "+" << b << "-" << c << "-" << d << "=7" << endl;
    } else if (a+b-c+d == 7) {
        cout << a << "+" << b << "-" << c << "+" << d << "=7" << endl;
    } else if (a+b+c-d == 7) {
        cout << a << "+" << b << "+" << c << "-" << d << "=7" << endl;
    } else if (a+b+c+d == 7) {
        cout << a << "+" << b << "+" << c << "+" << d << "=7" << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>

#define INF (1<<21)

int main(){
  int i,j,k,l,n;
  int a[101],b[101][101];

  scanf("%d",&n);
  for(i=1;i<=n;i++)
    scanf("%d %d",&a[i-1],&a[i]);

  for(i=1;i<=n;i++)
    b[i][i] = 0;

  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j = i + l -1;
      b[i][j] = INF;
      for(k=i;k<j;k++)
	if(b[i][j] > b[i][k] + b[k+1][j] + a[i-1] * a[k] * a[j])
	  b[i][j] = b[i][k] + b[k+1][j] + a[i-1] * a[k] * a[j];
    }
  }

  printf("%d\n",b[1][n]);

  return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 998244353
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 200010
using namespace std;
ll n,a[N],sum=0,ans=0;
int main(){
	ll i;
	scanf("%lld",&n);
	for(i=0;i<n;i++)
	{
		scanf("%lld",&a[i]);
		sum=(sum+a[i])%MOD;
	}
	for(i=0;i<n;i++)
	{
		sum=(sum+MOD-a[i])%MOD;
		ans=(ans+((a[i]*sum)%MOD))%MOD;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 5356
N, K = map(int, input().split())
h = list(map(int, input().split()))

# DP
inf = float("inf")
dp = [inf for _ in range(N)]
dp[0] = 0
for i in range(1, N):
    for k in range(1, K+1):
        if i - k < 0:
            break
        dp[i] = min(dp[i], dp[i-k] + abs(h[i] - h[i-k]))
print(dp[-1])

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

int main(){
	int x,y;
	cin >> x >> y;
	if (x > y){
		cout << "a > b" << endl;
	}else if (x < y){
		cout << "a < b" << endl;
	}else{
		cout << "a == b" << endl;
	}
}

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

int main() {
	int a, b, c; cin >> a >> b >> c;
	
	int count = 1000;
	int sum = 0;
	for (int i = a; count--; i *= a) {
		sum += a;
		if (sum % b == c) {
			cout << "YES" << endl;
			return 0;
		}
	}

	cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>

using namespace std;

int main(){

    int n;
    cin>>n;
    string c;
    cin>>c;
    vector<char> s;

    for(int i=0;i<c.size();i++){
        s.push_back(c[i]);
    }

    for(int i=0;i<s.size();i++){
         char a=s[i]+n;
        if(a>'Z'){
            s[i]=a-'Z'+'A'-1;
        }
        else{
            s[i]=a;
        }
    }

    for(int i=0;i<s.size();i++){
        cout<<s[i];
    }
    cout<<endl;
    
   
    return 0;
}


Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))
l_sum=sum(l)
ans=l_sum
c1=0
c2=0

for i in range(len(l)):
    c1=l_sum-sum(l[:i+1])
    c2=abs(c1-sum(l[:i+1]))

    if ans> c2:
        ans=c2
  
print(ans)

Measured memory_bytes: 9040
from collections import Counter

n = int(input())
a = [int(i) for i in input().split()]
q = int(input())
bc = [[int(i) for i in input().split()] for _ in range(q)]

cnt = Counter(a)
s = sum(a)
for b, c in bc:
    s += (c - b) * cnt[b]
    cnt[c] += cnt[b]
    cnt[b] = 0
    print(s)


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int64_t rll() {
	long long n;
	scanf("%lld", &n);
	return n;
}

int main() {
	int n = ri();
	std::cout << n * n * 3 << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> s(m), c(m);
    for (int i = 0; i < m; ++i) {
        cin >> s[i] >> c[i];
    }
    for (int i = 0; i <= 1000; ++i) {
        string A = to_string(i);
        if(A.size() != n) continue;
        int ok = 1;
        for (int j = 0; j < m; ++j) {
            if(A[s[j]-1]-'0' != c[j]) ok = 0;
        }
        if(ok){
            cout << A << "\n";
            return 0;
        }
    }
    puts("-1");
    return 0;
}

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

struct UnionFind {
  vector<int> r;
  
  UnionFind(int n) {
    r = vector<int>(n, -1);
  }
  
  int root(int x) {
    if (r[x] < 0) return x;
    return r[x] = root(r[x]);
  }
  
  int unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (r[x] > r[y]) swap(x, y);
    r[x] += r[y];
    r[y] = x;
    return true;
  }
  
  int size(int x) {
    return -r[root(x)];
  }
};

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> friends(n, 0);
  vector<int> blocks(n, 0);
  UnionFind UF(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a -= 1; b -= 1;
    UF.unite(a, b);
    friends[a]++; friends[b]++;
  }
  for (int i = 0; i < k; i++) {
    int c, d;
    cin >> c >> d;
    c -= 1; d -= 1;
    if (UF.root(c) == UF.root(d)) {
      blocks[c]++; blocks[d]++;
    }
  }
  for (int i = 0; i < n; i++) {
    int ans = UF.size(i) - (1 + friends[i] + blocks[i]);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 4256
import sys
import queue
input = sys.stdin.readline

h,w = map(int,input().split())
maze = [input() for _ in range(h)]
black = sum(x.count('#') for x in maze)
count = [[0 for _ in range(w)] for _ in range(h)]

count[0][0] = 1
q = queue.Queue()
q.put((0,0))

while not q.empty():
    y, x = q.get()
    for dy, dx in ((1,0),(0,1),(-1,0),(0,-1)):
        ny = y + dy
        nx = x + dx
        if 0 <= ny < h and 0 <= nx < w:
            if maze[ny][nx] == '.' and count[ny][nx] == 0:
                count[ny][nx] = count[y][x] + 1
                q.put((ny,nx))
if count[h-1][w-1] == 0:
    print (-1)
else:
    print (h*w - black - count[h-1][w-1])

Measured memory_bytes: 45032
using System;
using System.Collections.Generic;
using System.Linq;

class Program {
	static void Main(string[] args) {
		new Calc().calc();
	}
	public class Calc {
		public Calc() { }
		public void calc() {
			int n = ReadLine<int>();
			int m = n;
			if (IsKaibun(n)) { n.WriteLine(); return; }
			while (true) {
				if (IsKaibun(--m)) {
					m.WriteLine();
					return;
				}
				if (IsKaibun(++n)) {
					n.WriteLine();
					return;
				}
			}
		}
		private bool IsKaibun(int x) {
			char[] str = x.ToString().ToCharArray();
			int length = str.Length;
			for (int i = 0; i < length / 2; i++) {
				if (str[i] != str[length - 1 - i]) return false;
			}
			return true;
		}
	}

	public static T ReadLine<T>() {
		return (T)Convert.ChangeType(Console.ReadLine(), typeof(T));
	}
}
	//public static T[] ReadLine<T>(params char[] separators) {
	//	return Console.ReadLine()
	//		.Split(separators)
	//		.Select(_ => (T)Convert.ChangeType(_, typeof(T)))
	//		.ToArray();
	//}
//}
//	public static List<T> ReadLines<T>(int readCount) {
//		List<T> rt = new List<T>();
//		for (int i = 0; i < readCount; i++) {
//			rt.Add(ReadLine<T>());
//		}
//		return rt;
//	}
//}
public static class Utils {
	public static string Docking<T>(this IEnumerable<T> s, int sequenceRange, Func<T, string> filter = null) {
		string str = "";
		int c = 0;
		foreach (var item in s) {
			str += filter == null ? item.ToString() : filter(item);
			c++;
			if (c == sequenceRange) break;
		}
		return str;
	}

	public static string Docking<T>(this IEnumerable<T> s, Func<T, string> filter = null) {
		return s.Docking(s.Count(), filter);
	}

	public static string RangeDocking<T>(this IEnumerable<T> s,int start,int end,Func<T,string> filter = null) {
		string str = "";
		end = end < s.Count() ? end : s.Count();
		var items = s.ToArray();
		for (int i = start; i < end; i++) {
			str+= filter == null ? items[i].ToString() : filter(items[i]);
		}
		return str;
	}
	public static int IntParse(this string n) {
		return int.Parse(n);
	}
	public static void WriteLine(this object obj) {
		Console.WriteLine(obj);
	}
}

Measured memory_bytes: 10160
#include<bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back

using namespace std;

typedef long long ll;
typedef pair<int , int> pii;

const int N = 2010;

vector <int> adj[N];
deque <int> q;

int h[N] , n , k , ans = N , cnt;
bool mark[N];

void BFS(){

	while(!q.empty()){
	   int u = q.front();
	   q.pop_front();
	   
	   if(h[u] > k/2)
		  cnt++;

	   for(int v : adj[u]){
		  if(!mark[v]){
			 mark[v] = 1;
			 h[v] = h[u] + 1;
			 q.pb(v);
		  }
	   }
	}
	
	return;

}

void solve(){

	fill(mark , mark+n , 0);
	fill(h , h+n , 0);

	for(int u : q)
	   mark[u] = 1;

	cnt = 0;
	BFS();

	ans = min(ans , cnt);
}

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

	int u , v;
	cin >> n >> k;

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

	for(int i = 0 ; i < n ; i++){
	   q.pb(i);
	   if(k%2){
		  for(int u : adj[i]){
			 q.pb(u);
			 solve();
		  }			
	   }
	   else
		  solve();
	}

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


Measured memory_bytes: 892
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  string a,b;
  cin >> a >> b;
  
  if(a.size() != b.size()){
    if(a.size() > b.size()){
      cout << "GREATER";
      return 0;
    }else{
      cout << "LESS";
      return 0;
    }
  }
  
  rep(i,a.size()){
    if(a[i] > b[i]){
      cout << "GREATER";
      return 0;
    }
    if(a[i] < b[i]){
      cout << "LESS";
      return 0;
    }
  }
  
  cout << "EQUAL";
  return 0;
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector <int> a(n), b(n), c(n);
    for (int i = 0; i < n; ++i) cin >> a[i] >> b[i] >> c[i];
    vector <vector <int>> dp(n);
    for (int i = 0; i < n; ++i) dp[i].resize(3);
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    for (int i = 1; i < n; ++i)
    {
        dp[i][0] = a[i] + max(dp[i-1][1], dp[i-1][2]);
        dp[i][1] = b[i] + max(dp[i-1][0], dp[i-1][2]);
        dp[i][2] = c[i] + max(dp[i-1][0], dp[i-1][1]);
    }
    cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])) << '\n';
}

Measured memory_bytes: 6912
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize, k: usize,
        h: [i64; n],
    }

    let mut dp = vec![1 << 50; n + 1];
    dp[0] = 0;
    for i in 1..n {
        for j in 1..k + 1 {
            if i < j {
                break;
            }
            dp[i] = std::cmp::min(dp[i], dp[i - j] + (h[i] - h[i - j]).abs());
        }
    }
    println!("{}", dp[n - 1]);
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
using namespace std;
const int maxn = 10000 + 10;

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    if(n*a <= b){
        cout << n*a << "\n";
    }
    else {
        cout << b << "\n";\
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int i,dice[3] = {1,2,3},result = 1,tmp;
	char a[6];
	while(1){
		scanf("%d",&i);
		if(i == 0) return 0;
		for(;i > 0;i--){
			scanf("%s",a);
			if(strncmp(a,"North",5) == 0){
				tmp = dice[0];
				dice[0] = dice[1];
				dice[1] = 7 - tmp;
			}else if(strncmp(a,"South",5) == 0){
				tmp = dice[1];
				dice[1] = dice[0];
				dice[0] = 7 - tmp;
			}else if(strncmp(a,"Right",5) == 0){
				tmp = dice[1];
				dice[1] = dice[2];
				dice[2] = 7 - tmp;
			}else if(strncmp(a,"Left",4) == 0){
				tmp = dice[2];
				dice[2] = dice[1];
				dice[1] = 7 - tmp;
			}else if(strncmp(a,"West",4) == 0){
				tmp = dice[0];
				dice[0] = dice[2];
				dice[2] = 7 - tmp;
			}else if(strncmp(a,"East",4) == 0){
				tmp = dice[2];
				dice[2] = dice[0];
				dice[0] = 7 - tmp;
			}
		result += dice[0];
		}
		printf("%d\n",result);
		result = 1;
		dice[0] = 1;
		dice[1] = 2;
		dice[2] = 3;
	}
	return 0;
}

Measured memory_bytes: 604
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.jar.Attributes.Name;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;


public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(); 
        int m = sc.nextInt();
        int[] v = new int[n];
        Arrays.fill(v, -1);
        for(int i =0;i<m;i++){
            int s = sc.nextInt()-1;
            int c = sc.nextInt();
            if(v[s]<0){
                v[s] = c;
            }else if(v[s]!=c){
                sc.close();
                System.out.println(-1);
                return;
            }
        }
        if(n!=1 && v[0]==0){
            System.out.println(-1); 
            return;  
        }
        for(int i=0;i<n;i++){
            if(v[i] == -1){
                if(n>1 && i==0){
                    System.out.print(1);
                }else{
                    System.out.print(0);
                }
            }else{
                System.out.print(v[i]);
            }
        }

        
    }
}



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

int main() {
	int n, m, a, b, Sa=0, Sb=0, l, ra, rb;
	set<int> sa, sb;
	while(1) {
		cin >> n >> m;
		if(!n&&!m) break;
		ra = -1; rb = -1; sa.clear(); sb.clear();
		Sa = 0; Sb = 0;
		for(int i=0; i<n; ++i) {cin >> a; sa.insert(a); Sa += a;}
		for(int i=0; i<m; ++i) {cin >> b; sb.insert(b); Sb += b;}
		if((Sa+Sb)%2) {
			cout << "-1" << endl;
			continue;
		}
		if(Sa<Sb) {
			l = (Sb-Sa)/2;
			for(set<int>::iterator it=sa.begin(); it!=sa.end(); ++it) {
				if(sb.find((*it)+l)!=sb.end()) {
					ra = (*it); rb = (*it)+l;
					break;
				}
			}
		}else {
			l = (Sa-Sb)/2;
			for(set<int>::iterator it=sb.begin(); it!=sb.end(); ++it) {
				if(sa.find((*it)+l)!=sa.end()) {
					ra = (*it)+l; rb = (*it);
					break;
				}
			}
		}
		if(ra!=-1&&rb!=-1) cout << ra << " " << rb << endl;
		else cout << "-1" << endl;
	}
	return 0;
}

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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int n;
    cin >> n;
    set<string> s;
    string tmp;
    rep (i, n) {
        cin >> tmp;
        s.insert(tmp);
    }
    print(s.size());

    return 0;
}


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

#define FOR(i,a,b) for(ll i=a; i<b; i++)
#define IN(a) cin>>a
#define OUT(a) cout<<a<<endl

template<typename T> void combSort(vector<T>& v){
  size_t h = (v.size()*10)/13;
  bool is_sorted = false;
  while(!is_sorted){
    if(h==1)is_sorted = true;
    for(size_t i=0; i<v.size()-h; ++i){
      if(v[i]>v[i+h]){
        swap(v[i],v[i+h]);
        if(is_sorted)is_sorted = false;
      }
    }
    if(h>1) h = (h*10)/13;
    if(h==0) h = 1;
  }
}

int main(){
  long long int n;
  IN(n);
  vector<long long int> a(n);
  for(long long int i=0; i<n; i++){
    IN(a.at(i));
  }
  combSort(a);
  reverse(a.begin(), a.end());
  long long int ans = 0;
  if(n%2==0){
    for(long long int i=0; i<n/2; i++){
      if(i==0){
        ans += a.at(i);
      }else{
        ans += a.at(i)*2;
      }
    }
  }else{
    for(long long int i=0; i<(n+1)/2; i++){
      if(i==0||i==(n-1)/2){
        ans += a.at(i);
      }else{
        ans += a.at(i)*2;
      }
    }
  }
  OUT(ans);
}

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

int main(){
    int N;
    cin >> N;
    int left = 0; int right = 0;
    int count = 0;
    char S[N-1];
    char temp = '0';
    cin >> S;
    for(int i=0; i<N; ++i){
        if(S[i] == '('){ ++left; ++count; }
        else if(S[i] == ')'){
            if(count > 0){ --left; --count;}
            else{ ++right; }
        }
        temp = S[i];
    }

    for(int i=0; i<right; ++i){ cout << '('; }
    for(int i=0; i<N; ++i){ cout << S[i]; }
    for(int i=0; i<left; ++i){ cout << ')'; }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(), (x).end()
#define pb push_back
int main()
{
    int x, a, b;
    cin >> x >> a >> b;
    if (abs(x - a) < abs(b - x))
    {
        cout << "A" << endl;
    }
    else{
        cout << "B" << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    set<int>st;
    for(int i=0;i<k;++i)
    {
        int m;
        cin>>m;
        for(int j=0;j<m;++j)
        {
            int num;
            cin>>num;
            st.insert(num);
        }
    }
    cout<<n-st.size()<<endl;
    return 0;
}


Measured memory_bytes: 3536
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const long long INF=1LL << 60;
long long a,b;
long long dp[100200][110];
long long w[110],v[110];


int main(){
  double a;
  cin>>a;
  cout<<2*a*M_PI<<endl;
}



Measured memory_bytes: 3788
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        char c = 'C';

        String answer = "AB" + String.valueOf(new Character((char) (c + (int)Math.floor(n / 1000.0))));

        System.out.println(answer);
    }

}


Measured memory_bytes: 21844
#include <cstdio>
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
using namespace std;

int main()
{
	int n, a, b;
	cin >> n >> a >> b;
	if (a <= b && a + b <= n) {
		cout << a << " " << 0 << endl;
	}
	else if (a > b && a + b <= n) {
		cout << b << " " << 0 << endl;
	}
	else if (a <= b && a + b > n) {
		cout << a << " " << a + b - n << endl;
	}
	else {
		cout << b << " " << a + b - n << endl;
	}
}

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

int main(){
    int N, num = 1, dest = 0, box;

    cin >> N;
    for(int i = 0; i<N; i++){
        cin >> box;
        if(box == num)num++;
        else dest++;
    }
    if(dest == N)cout << -1 << endl;
    else cout << dest << endl;
}

Measured memory_bytes: 256
# -*- coding:utf-8 -*-
array = []
while True:
    try:
        n = int(input())
        array.append(n)
    except EOFError:
        break
data = []
for i in range(len(array)):
    if array[i] == 0:
        elm = data.pop()
        print(elm)
    else:
        data.append(array[i])

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

#define INF 1000000000000000

using namespace std;

int main(){
    int N;
    cin >> N;
    long A[N];
    for(int i=0; i<N; i++) cin >> A[i];
    long dp[N][3][2];

    // initialize
    for(int j=0; j<3; j++){
        for(int s=0; s<2; s++) dp[0][j][s] = -INF;
    }
    dp[0][0][0] = 0;
    dp[0][1][1] = A[0];

    long base[N];
    base[0] = 0;

    for(int i=1; i<N; i++){

        base[i] = N / 2 - (N - i) / 2;
        for(int j=base[i]; j<=(i+2)/2; j++){
            if(j  <= (i+1)/2) dp[i][j - base[i]][0] = max(dp[i-1][j - base[i-1]][0], dp[i-1][j - base[i-1]][1]);
            else dp[i][j - base[i]][0] = -INF;
            if(j-1 <= (i+1)/2) dp[i][j - base[i]][1] = dp[i-1][j-1-base[i-1]][0] + A[i];
            else dp[i][j - base[i]][1] = -INF;
        }
    }
    cout << max(dp[N-1][N/2 - base[N-1]][0], dp[N-1][N/2 - base[N-1]][1]) << endl;
    return 0;
}

Measured memory_bytes: 16128