akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 1000000007; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;

vector<vector<int>> graph;
vector<int> ans;
vector<bool> visited;

signed main() {
  int N, M;
  cin >> N >> M;

  int a, b;
  graph.resize(N);
  visited.resize(N, false);
  REP(i, M){
    cin >> a >> b;
    a--; b--;
    graph[a].emplace_back(b);
    graph[b].emplace_back(a);
  }

  ans.emplace_back(0);
  ans.emplace_back(graph[0][0]);
  visited[0] = true;
  visited[graph[0][0]] = true;

  bool flag = true;
  while(flag){
    int v = ans[0];
    for(int i : graph[v]){
      if(visited[i] == false){
        ans.insert(ans.begin(), i);
        visited[i] = true;
        break;
      }
      if(i == graph[v].back()) flag = false;
    }
  }

  flag = true;
  while(flag){
    int v = ans.back();
    for(int i : graph[v]){
      if(visited[i] == false){
        ans.emplace_back(i);
        visited[i] = true;
        break;
      }
      if(i == graph[v].back()) flag = false;
    }
  }

  cout << ans.size() << endl;
  REP(i, ans.size()){
    cout << ans[i]+1; SPBR(i, ans.size());
  }

  return 0;
}

Measured memory_bytes: 7156
#include <stdio.h>

int main(void) {
    int a,b,c,d,i,j,n;
    int f[4][30]={0};
    
    scanf("%d", &n);
    for(i=0;i<n;i++){
    scanf("%d %d %d %d",&a,&b,&c,&d);
    f[a-1][(b-1)*10+(c-1)]+=d;
    }
    for(i=0;i<4;i++){
        for(j=0;j<30;j++){
            printf(" %d",f[i][j]);
            if(j%10==9)printf("\n");
        }
        if(i<3)
        printf("####################\n");
    }
    return 0;
}

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

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

    string ans;
    rep(i, s.size())
    {
        ans += "x";
    }
    cout << ans << endl;
}


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

using namespace std;

bool compare(vector<int> &a, vector<int> &b){
  for(int i = 0; i < a.size(); i++)
    if( a[i] != b[i] )
      return false;
  return true;
}

int main(){
  int n;
  cin >> n;
  vector<int> p(n), q(n), a(n);
  int pa, pb;
  for(int i = 0; i < n; i++)
    cin >> p[i];
  for(int i = 0; i < n; i++)
    cin >> q[i];
  for(int i = 0; i < n; i++)
    a[i] = i+1;
  int tt = 1;
  do{
    if( compare(p, a) )
      pa = tt;
    if( compare(q, a) )
      pb = tt;
    tt++;
  }while(next_permutation(a.begin(), a.end()));
  
  cout << abs(pa - pb) << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int moji = s.length()-1;

        while(moji > 0){
            if(moji%2 == 0){
                String s1 = s.substring(0,moji/2-1);
                String s2 = s.substring(moji/2,moji-1);
                if(s1.equals(s2))
                    break;
            }
            moji--;
        }
        System.out.println(moji);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

int w,h;

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

bool field[100][100];
bool visited[100][100];

int startfrom(int x, int y, int depth){
	int ret=depth;
	
	visited[x][y] = true;
	for(int i=0;i<4;i++){
		if(0 <= x+dx[i] && x+dx[i] < h &&
		0 <= y+dy[i] && y+dy[i] < w){
			if(field[x+dx[i]][y+dy[i]] == true &&
			visited[x+dx[i]][y+dy[i]] == false){
				ret = max(ret,startfrom(x+dx[i], y+dy[i], depth + 1));
			}
		}
	}
	visited[x][y] = false;
	
 	return ret;
}

int main(void){

	while(cin >> w >> h){
		if((w|h) == 0) break;
		
		int tmp,ret=0;
		
		memset(field, 0, sizeof(field));
		
		//read data
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				cin >> tmp;
				if(tmp == 1){
					field[i][j] = true;
				}else{
					field[i][j] = false;
				}
			}
		}
		
		//begin from all cells
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(field[i][j] == true){
					memset(visited, 0, sizeof(visited));
					ret = max(ret, startfrom(i,j,1));
				}
			}
		}
		cout << ret << endl;
	}
}

Measured memory_bytes: 0
N = int(input())
p = list(map(int, input().split()))

ans = False
for i in range(N):
    for j in range(i, N):
        p[i], p[j] = p[j], p[i]
        for k in range(N):
            if p[k] != k+1:
                p[i], p[j] = p[j], p[i]
                break;
            if k == N-1: ans = True
if ans: print('YES')
else: print('NO')

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

int main() {
  char grid[10][10];
  int H, W, K;
  cin >> H >> W >> K;
  
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> grid[i][j];
    }
  }
  
  int ans = 0;
  for (int i = 0; i < (1 << H); i++) {
    for (int j = 0; j < (1 << W); j++) {
      int count = 0;
      for (int k = 0; k < H; k++) {
        for (int l = 0; l < W; l++) {
          if (grid[k][l] == '#' && (i & (1 << k)) && (j & (1 << l))) {
            count++;
          }
          
        }
      }
      
      if (count == K) ans++;
    }
  }
  
  cout << ans << endl;
  
  
}

Measured memory_bytes: 3652
class dice:
    def __init__(self,label):
        self.top, self.front, self.right, self.left, self.rear, self.bottom \
                = label
  
    def roll(self,op):
        if   op=='N': self.top, self.front, self.bottom, self.rear = \
                                self.front, self.bottom, self.rear , self.top
        elif op=='E': self.top, self.left , self.bottom, self.right = \
                                self.left , self.bottom, self.right, self.top
        elif op=='W': self.top, self.right, self.bottom, self.left = \
                                self.right, self.bottom, self.left , self.top
        elif op=='S': self.top, self.rear , self.bottom, self.front = \
                                self.rear , self.bottom, self.front, self.top
  
    def print_top(self): print(self.top)
    def print_right(self): print(self.right)
  
    def get_label(self):
        return [self.top, self.front, self.right, self.left, self.rear, self.bottom]

label = list(map(int,input().split()))
d = dice(label)
q = int(input())
for _ in range(q):
    top_front = [int(x) for x in input().split()]
    for op in 'EEENEEENEEESEEESEEENEEEN':
        if d.get_label()[:2] == top_front:
            d.print_right()
            break
        d.roll(op)


Measured memory_bytes: 5608
# AGC207A

def f(n, a, b):
    if (b - a) % 2:
        print('Borys')
    else:
        print('Alice')

n, a, b = map(int, input().split())
#f(5, 2, 4)
#f(2, 1, 2)
#f(58, 23, 42)
f(n, a, b)


Measured memory_bytes: 9080
#include <stdio.h>

int main(){
	int D, N;
	scanf("%d%d", &D, &N);
	
	if(D==0)
		if(N!=100) printf("%d", N);
		else printf("101");
	else if(D==1)
		if(N!=100) printf("%d", N*100);
		else printf("10100");
	else
		if(N!=100) printf("%d", N*10000);
		else printf("1010000");
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main() {
  int n;
  scanf("%d", &n);
  long long int arr[n], max = 1e18, prod = 1, flag = 0, zero = 0;
  
  for (int i = 0; i < n; i++) {
    scanf("%lld", &arr[i]);
    flag = (arr[i] > max) ? 1 : flag;
    prod *= arr[i];
    (arr[i]) ? max /= arr[i] : zero = 1;
  }

  (zero) ? puts("0") : ((flag) ? puts("-1") : printf("%lld\n", prod));
  return 0;
}

Measured memory_bytes: 2512
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define REPI(i, s, e) for (int i = (s); i <= (e); i++)
#define rep(i, n) REP(i, 0, n)
#define repi(i, n) REPI(i, 0, n)
#define ALL(v) (v).begin(), (v).end()

#define dump(x) (cout << #x << " = " << x << endl)
#define dump2(x, y) (cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl)
#define dump3(x, y, z) (cout << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", "<< z << ")" << endl)

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

int n;
vector<int> I, R, O;
const int M = 256;

#define EPS 1e-10
#define EQ(a, b) ((a)-EPS < b && b < (a)+EPS)

class node {
public:
	int s, a, c;
	double e;

	node() { e = 1e10; }
	node(int s, int a, int c, vector<int> &o):s(s), a(a), c(c), e(entropy(o)){}

	void print()
	{
		printf("%d %d %d\n", s, a, c);
	}

	double entropy(vector<int> &O)
	{
		int hist[M];

		memset(hist, 0, sizeof(hist));
		rep(i, O.size())
			hist[O[i]]++;

		int N = I.size();
		double h = 0;
		rep(i, M) {
			if (hist[i] != 0)
				h += hist[i] * log(1.0*hist[i]/N);
		}
		return -h/N;
	}

	bool operator<(const node &r) const {
		if (EQ(e, r.e)) {
			if (s == r.s) {
				if (a == r.a) return c < r.c;
				return a < r.a;
			}
			return s < r.s;
		}
		return e < r.e;
	}
};

int main(void)
{
	while (cin >> n, n) {
		I = vector<int>(n);
		rep(i, n)
			cin >> I[i];

		node ans = node();
		repi(s, 15) repi(a, 15) repi(c, 15) {
			R = vector<int>(n+1);
			O = vector<int>(n);

			R[0] = s;
			REPI(i, 1, n)
				R[i] = (a*R[i-1] + c) % M;
			rep(i, n)
				O[i] = (I[i]+R[i+1]) % M;

			node n = node(s, a, c, O);
			ans = min(ans, n);
		}
		ans.print();
	}
	return 0;
}

Measured memory_bytes: 1244
n,a,b=map(int,input().split())
h=[]
for _ in range(n):
    h.append(int(input()))

lo=0
hi=10**9
while lo<hi:
    md=(lo+hi)//2
    def chk(md):
        d=a-b
        cnt=0
        for i in h:
            i-=md*b
            if i>0:
                cnt+=i//d
                if i%d:
                    cnt+=1
        if cnt<=md:
            return True
        else:
            return False
    if chk(md):
        hi=md
    else:
        lo=md+1
print(lo)



Measured memory_bytes: 7192
// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll h, s = 0, c = 1;
    cin >> h;
    while (h)
    {
        s += c;
        c *= 2;
        h /= 2;
    }
    cout << s;
    return 0;
}

Measured memory_bytes: 256
def kai(a):
    if a == 1:
        return 1
    else:
        return a*kai(a-1)

def L(i, j, x, y):
    return ((x[i] - x[j])**2 + (y[i] - y[j])**2)**0.5

N  = int(input())
x = [0]*N
y = [0]*N
k = kai(N)
l = 0
for n in range(N):
    x[n], y[n] = map(int, input().split())

for X in range(N):
    for Y in range(N):
        if X <= Y:
            continue
        else:
            l += L(X, Y, x, y)
           

bi = ((N - 1) * k)/((N * (N - 1))/2)



print((l * bi)/k)


Measured memory_bytes: 3064
/*----------------by syr----------------*/
/*

         iii                  ii
     rBQBBBBBBE       BBR iBBBBQBBL     XBBBBBBQBBBBB
   iBBQJ    7BBB      BBsSBBr   BBQ      i      cBBB
  rBBU       iBBw     BBBQi     HBBi           KBBi
  BBH         BB5    iBBB       isL          wBB5
 GBB         iBBi    6BB                   iBBB
 BBQ         BQB     BBD                  QBBi
 BBB        BQB     iQBi                1BBv
 sBBg     wBBB      QBB               iBBB
  7BBBBBBBBBi       BBR              wBBBBBBBBBBBBB
     irvi           ii               ii    i i iii
                i5U
               BBB
               BB7
              1BB
      iPBBBBBKBBR    JBR1       rQBO   BR  UBQP  iBBQi
    7BBBGs7sXBBBi     QBBr     gBBE   rBB BB2BB7HBZQBB
   QBBi      sBQ       BBB   iBBB     SQBBR  BBBB  cBQ
  gBQ        BBg        BBB KBBi      MBBH   BBB   BBs
 iBBv       iBBi         QBBBL        BBR   pBB   iBB
 pBB        BBB         iBBBB        iBB    BBL   KBB
 MBB       BBBR        BBB JBBi      DBR   iBQ    BBL
 GBB     7BBBB2      PBBH   BBBi     BQr   DBB   iBB
  BQBXwgBBP BB7    1BBB      BBQ7   1BB    BBc   BBB
   2BBBBw   BB    EBBS        QBBi  HBa   iBB    BB7
*/
#include<bits/stdc++.h>

using namespace std;

#define PH push
#define MP make_pair
#define PB push_back
#define fst first
#define snd second
#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define x0 x0123456789
#define y0 y0123456789
#define x1 x1234567890
#define y1 y1234567890
#define x2 x2345678901
#define y2 y2345678901
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9 + 7;

int main(){
	int a[3];
	scanf("%d%d%d", a + 0, a + 1, a + 2);
	sort(a, a + 3);
	printf("%d\n", a[0] + a[1]);
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,c,k,a[100010],ans=0,cnt=1,now=0;
    cin>>n>>c>>k;
    rep(i,n){
        cin>>a[i];
    }
    sort(a,a+n);
    now=a[0]+k;
    rep(i,n-1){
        if(cnt==0) now=a[i]+k;
        cnt++;
        if(now<a[i+1]){
            ans++;
            cnt=0;
            continue;
        }
        if(cnt==c){
            ans++;
            cnt=0;
            continue;
        }
    }
    cout<<ans+1<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#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 INF 1000000000000
#define NCK_MAX 510000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main(int argc, char const *argv[]) {
  int n; std::cin >> n;
  std::vector<ll> a(n,0); REP(i,n) std::cin >> a[i];
  ll ans=0;
  REP(i,60) {
    ll x = 0;
    REP(j,n) if (a[j] >> i&1) x++;
    ll now = x*(n-x)%MOD;
    REP(l,i) now = now*2%MOD;
    ans += now;
    ans %= MOD;
  }
  std::cout << ans << '\n';
  return 0;
}


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

int main()
{
	long long x; cin >> x;
	long long cnt = x / 11;
	cnt *= 2;
	x %= 11;
	if(x)cnt++;
	if (x > 6)cnt++;
	cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

#define M 1000000
#define NIL (-1)
#define L 12

char H[M][L];


int getInt(char c) {
    if (c == 'A') return 1;
    else if (c == 'C') return 2;
    else if (c == 'G') return 3;
    else if (c == 'T') return 4;
    else return -1;
}

long long getKey(char str[]) {
    long long sum = 0, p = 1;

    for (long long i = 0; i < strlen(str); i++) {
        sum += p * getInt(str[i]);
        p *= 5;
    }

    return sum;
}

int h1(int key) {
    return key % M;
}

int h2(int key) {
    return 1 + (key % (M - 1));
}

long long h(int key, int i) {
    return (h1(key) + i * h2(key)) % M;
}

int insert(char s[]) {
    long long key, hash, i = 0;

    key = getKey(s);

    while (true) {
        hash = h(key, i);
        if (strcmp(H[hash], s) == 0) {
            return 1;    
        } else if (strlen(H[hash]) == 0) {
            strcpy(H[hash], s);
            return 0;
        }
        i++;
    }
}

int find(char s[]) {
    long long key, hash, i = 0;

    key = getKey(s);

    while (true) {
        hash = h(key, i);
        if (strcmp(H[hash], s) == 0) {
            return 1;    
        } else if (strlen(H[hash]) == 0) {
            return 0;
        }
        i++;
    }
}

int main() {
    char order[L], str[L];
    int n;

    for (int i = 0; i < M; i++) {
        H[i][0] = '\0';
    }

    scanf("%d", &n);
    
    for (int i = 0; i < n; i++) {
        scanf("%s %s", order, str);

        if (order[0] == 'i') {
            insert(str);
        } else {
            if (find(str)) {
                printf("yes\n");
            } else {
                printf("no\n");
            }
        }
    }
    
    return 0;
}

Measured memory_bytes: 14448
n = int(input())
a_list = list(map(int,input().split()))
result = 1
if 0 in a_list:
  print(0)
else:
  for a in a_list:
    result = result *a
    if len(str(result)) >= 19:
      if result == 10**18:
        continue
      else:
        result = -1
        break
        
  print(result)

Measured memory_bytes: 87956
import sys

X,N = map(int,input().split())
if N != 0:
    P_LIST = list(map(int,input().split()))
else:
    print(X)
    sys.exit()

i = 0
for i in range(100):
    A = X - i
    if A not in P_LIST:
        X_min = A
        for j in range(100):
            B = X + j
            if B not in P_LIST:
                X_max = B
                if X_max - X < X - X_min:
                    print(X_max)
                    sys.exit()
                else:
                    print(X_min)
                    sys.exit()

Measured memory_bytes: 9144
#include <iostream>

typedef long long ll;

using namespace std;

int main()
{

    int A, B, C;
    ll X, Y;

    int ans_amount;

    cin >> A >> B >> C >> X >> Y;

    if((A + B) > (C * 2)){

        ans_amount = min(2 * C * min(X, Y) + A * (X - min(X, Y)) + B * (Y - min(X, Y)), 2 * C * max(X, Y));

    } else {
        ans_amount = (A * X) + (B * Y);
    }

    cout << ans_amount << endl;

    return 0;
}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, l;
	cin >> n >> l;
	l --;
	int ans = 1e9;
	for (int i = 1; i <= n; i++){
		if (abs(l + i) < abs(n * (n + 1) / 2 + l * n - ans)){
			ans = n * (n + 1) / 2 + l * n - (l + i);
		}
	}
	cout << ans;
}

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

int main() {
	int n;cin>>n;
	vector<int> h(n);
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	int ans=1;
	int maxh=h[0];
	for(int i=1;i<n;i++){
		if(h[i]>=maxh){
			maxh=h[i];
			ans++;
		}
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
S=input()
if S[0] != "A":
  print("WA")
elif len([i for i in S[2:-1] if i == "C"]) != 1:
  print("WA")
elif len([i for i in S if i.islower()]) != len(S)-2:
  print("WA")
else:
  print("AC")

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

int main(){
	string s;
	cin>>s;
	
	int ans=0;
	
	int l=0;
	int r=s.size()-1;
	
	while(l<=r){
		if(s[l]=='x'&&s[r]!='x'){
			ans++;
			l++;
		}else if(s[l]!='x'&&s[r]=='x'){
			ans++;
			r--;
		}else if(s[l]==s[r]){
			l++;
			r--;
		}else{
			cout<<-1<<endl;
			return 0;
		}
	}
	
	cout<<ans<<endl;
	
	
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>

int main(){
    while (true){
    int n;
    cin >> n;
    if (n==0) return 0;
    vector<pp> a(n+1);
    for (int i=1;i<n+1;i++){
        int h;
        cin >> h;
        cin >> a.at(h).first >> a.at(h).second;
    }
    vector<vector<pair<int,double>>> d(n+1,vector<pair<int,double>>(0));
    pair<int,double> v;
    for (int i=1;i<n+1;i++){
        for (int j=1;j<n+1;j++){
            if (i==j) continue;
            if ((a.at(i).first-a.at(j).first)*(a.at(i).first-a.at(j).first)+(a.at(i).second-a.at(j).second)*(a.at(i).second-a.at(j).second)>2500) continue;
            double yyyy=(a.at(i).first-a.at(j).first)*(a.at(i).first-a.at(j).first)+(a.at(i).second-a.at(j).second)*(a.at(i).second-a.at(j).second);
            v.second=sqrt(yyyy);v.first=j;
            d.at(i).push_back(v);
        }
    }
    int t;
    cin >> t;
    queue<int> q;
    
    
    for (int i=0;i<t;i++){
        vector<double> df(n+1);
        vector<vector<int>> r(n+1,vector<int>(0));
        for (int j=1;j<n+1;j++){
            df.at(j)=10000000;
        }
        int aa,bb;
        cin >> aa >> bb;
        q.push(aa);
        df.at(aa)=0;
        while(!q.empty()){
            int ii=q.front();
            q.pop();
            for (int j=0;j<d.at(ii).size();j++){
                int w=d.at(ii).at(j).first;
                double ww=d.at(ii).at(j).second;
                if (df.at(ii)+ww<df.at(w)) {
                    df.at(w)=df.at(ii)+ww;
                    q.push(w);
                    r.at(w)=r.at(ii);
                    r.at(w).push_back(ii);
                }
            }
        }
        if (r.at(bb).size()==0) cout << "NA" << endl;
        else {
            for (int j=0;j<r.at(bb).size();j++){
                cout << r.at(bb).at(j) << " ";
            }
            cout << bb << endl;
        }
    }
    }}


Measured memory_bytes: 3068
import java.io.*;
import java.util.*;

public class Main{
	static void main() throws Exception{
		int n=sc.nextInt();
		int[]in=sc.intArr(n);
		long sum=0;
		long ans=0;
		long mod=(long)1e9+7;
		for(int i=0;i<n;i++) {
			ans+=(sum*in[i])%mod;
			ans%=mod;
			sum+=in[i];
			sum%=mod;
		}
		pw.println(ans);
	}
	public static void main(String[] args) throws Exception{
		sc=new MScanner(System.in);
		pw = new PrintWriter(System.out);
		int tc=1;
//		tc=sc.nextInt();
		while(tc-->0)
			main();
		pw.flush();
	}
	static PrintWriter pw;
	static MScanner  sc;
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] intArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] longArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public int[] intSortedArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public long[] longSortedArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public Integer[] IntegerArr(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] LongArr(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
	static void shuffle(int[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			int tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
	static void shuffle(long[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			long tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
}

Measured memory_bytes: 54512
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
using namespace std;
int main(){
	int n;
	pair<string, int> p[100];
	cin >> n;
	string s;
	int p2;
	for(int i = 0;i < n;i++){
		cin >> s >> p2;
		p2 = (101 - p2) * 100 + i;
		p[i] = make_pair(s, p2);
	}
	sort(p, p + n);
	for(int i = 0;i < n;i++){
		cout << (p[i].second % 100 + 1) << endl;
	}
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

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

        int D = Integer.parseInt(sc.next());
        sc.close();

        String ans = "Christmas";
        for (int i  = 24; i >= D; i--) {
            ans += " Eve";
        }
        out.printf("%s\n", ans);
        out.flush();
    }
}


Measured memory_bytes: 21844
n, k = map(int, input().split())
ab = {}
for _ in range(n):
    a, b = map(int, input().split())
    ab.setdefault(a, 0)
    ab[a] += b
keys = list(ab.keys())
keys.sort()
i = 0
for key in keys:
    i += ab[key]
    if i >= k:
        print(key)
        break

Measured memory_bytes: 16236
import java.util.Scanner;
import java.util.stream.IntStream;


public class Main {
    public static void main(String[] args) {
        new Main().run();

    }

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        System.out.println(IntStream.rangeClosed(1,n).filter(i -> i%2 != 0).filter(i ->
            IntStream.rangeClosed(1,i).filter(i1 -> i % i1 == 0).count() == 8
        ).count());
    }

}

Measured memory_bytes: 26964
n, m = list(map(int, input().split(' ')))
ksm = [None] * m
for i in range(m):
    ksm[i] = list(map(int, input().split(' ')))[1:]


pm = list(map(int, input().split(' ')))

count = 0
for i in range(2 ** n):
    ok = True
    for j in range(m):
        val = 0
        for k in range(n):
            if (i >> k) & 1 and (k + 1) in ksm[j]:
                val += 1
        if val % 2 != pm[j]:
            ok = False
            break
    if ok:
        count += 1
        
print(count)




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

typedef long long ll;

ll A, B;

int main() {
  cin >> A >> B;
  if (abs(A - B) % 2 == 1) {
    cout << "IMPOSSIBLE" << endl;
  } else {
    cout << (A + B) / 2 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int month,day,day366;

	for(day366=0;; day366=0){
		scanf("%d %d",&month,&day);
		if(!month)
			break;
		switch(month){
			case 12:
				day366+=30;
			case 11:
				day366+=31;
			case 10:
				day366+=30;
			case 9:
				day366+=31;
			case 8:
				day366+=31;
			case 7:
				day366+=30;
			case 6:
				day366+=31;
			case 5:
				day366+=30;
			case 4:
				day366+=31;
			case 3:
				day366+=29;
			case 2:
				day366+=31;
		}
		switch((day366+day)%7){
			case 0:
				puts("Wednesday");
				break;
			case 1:
				puts("Thursday");
				break;
			case 2:
				puts("Friday");
				break;
			case 3:
				puts("Saturday");
				break;
			case 4:
				puts("Sunday");
				break;
			case 5:
				puts("Monday");
				break;
			case 6:
				puts("Tuesday");
				break;
		}
	}

	return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

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

const int MOD=1000000007;
int INF=100100100100100;

signed main(){
  int a,b,c;cin>>a>>b>>c;
  if(a==b && b==c)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    swap(a,b);
    swap(a,c);
    cout<<a<<" "<<b<<" "<<c;

}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;

#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define INF 1000000000000000000
#define all(vl) vl.begin(),vl.end()
#define m_p make_pair 
#define sz(a) sizeof(a)
#define forn(mp,it) for(it = mp.begin();it!=mp.end();it++)
#define FOR(i,a,n) for(int i=a;i<n;i++) 
#define FORE(i,a,n) FOR(i,a,n+1)
#define Endl endl
#define eNdl endl
#define enDl endl
#define endL endl

int main()
{
	ll a,b;
	cin>>a>>b;
	FOR(i,0,10000)
	{
		if(i*8/100 == a&&i*10/100 == b)
		{
			cout<<i<<Endl;
			return 0;
		}
	}
	cout<<-1<<endl;
	return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define INF 1<<28
#define MAX_V 105
#define ll int
struct edge{
  ll to,cap,rev;
  edge(ll to ,ll cap,ll rev):to(to),cap(cap),rev(rev){}
};
vector<edge> G[MAX_V];
vector<edge> G2[MAX_V];
bool used[MAX_V];
int level[MAX_V];
int iter[MAX_V];


void add_edge(ll from,ll to,ll cap){
  G[from].push_back(edge(to,cap,G[to].size()));
  G[to].push_back(edge(from,cap,G[from].size()-1));
}

void bfs(int s){
  memset(level,-1,sizeof(level));
  queue<int> que;
  level[s]=0;
  que.push(s);
  while(!que.empty()){
    int v=que.front();que.pop();
    for(int i=0;i<G[v].size();i++){
      edge &e = G[v][i];
      if(e.cap>0&&level[e.to]<0){
	level[e.to]=level[v]+1;
	que.push(e.to);
      }
    }
  }
}

int dfs(int v,int t,int f){
  if(v==t) return f;
  for(int &i=iter[v];i<G[v].size();i++){
    edge &e=G[v][i];
    if(e.cap>0&&level[v]<level[e.to]){
      int d = dfs(e.to,t,min(f,e.cap));
      if(d>0){
	e.cap-=d;
	G[e.to][e.rev].cap+=d;
	return d;
      }
    }
  }
  return 0;
}

void bfs2(int s){
  memset(level,-1,sizeof(level));
  queue<int> que;
  level[s]=0;
  que.push(s);
  while(!que.empty()){
    int v=que.front();que.pop();
    for(int i=0;i<G2[v].size();i++){
      edge &e = G2[v][i];
      if(e.cap>0&&level[e.to]<0){
	level[e.to]=level[v]+1;
	que.push(e.to);
      }
    }
  }
}

int dfs2(int v,int t,int f){
  if(v==t) return f;
  for(int &i=iter[v];i<G2[v].size();i++){
    edge &e=G2[v][i];
    if(e.cap>0&&level[v]<level[e.to]){
      int d = dfs2(e.to,t,min(f,e.cap));
      if(d>0){
	e.cap-=d;
	G2[e.to][e.rev].cap+=d;
	return d;
      }
    }
  }
  return 0;
}

int flow=0;
int max_flow(int s,int t){
  for(;;){
    bfs(s);
    if(level[t]<0) return flow;
    memset(iter,0,sizeof(iter));
    int f;
    while((f=dfs(s,t,INF))>0){
      flow+=f;
    }
  }
}

int max_flow2(int s,int t){
  int flow2=0;
  for(;;){
    bfs2(s);
    if(level[t]<0) return flow2;
    memset(iter,0,sizeof(iter));
    int f;
    while((f=dfs2(s,t,INF))>0){
      flow2+=f;
    }
  }
}

signed main(){
  ll k,n,m,i,j,a,b,c,x,y;
  cin >> k >> n >> m;
  ll s=MAX_V-1,t=0;
  for(i=0;i<m;i++){
    cin >> a >> b >> c;
    add_edge(a,b,c);
  }
  for(i=1;i<=k;i++){
    add_edge(s,i,INF);
  }
  ll ans=max_flow(s,t);
  for(i=1;i<MAX_V-1;i++){
    for(j=0;j<G[i].size();j++){
      if(G[i][j].cap!=0) continue;
      for(x=0;x<MAX_V;x++) G2[x]=G[x];
      G2[i][j].cap=INF;
      ans=max(ans,flow+max_flow2(s,t));
      if(ans>=INF) break;
    }
  } if(ans>=INF) cout << "overfuro" << endl;
  else cout << ans << endl;
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb push_back 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;
const ll INF=1000000000000000;

vector<ll> pw2(52,1); vector<ll> pw10(19,1);
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll mid(ll x,ll y,ll z){return x>y?y>=z?y:min(z,x):x>=z?x:min(y,z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll myceil(ll x,ll y){if(x<=y) return 1;else if(x%y==0) return x/y;else return x/y+1;}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> divisor(ll x){vector<ll> div;
	for(ll i=1;i*i<=x;i++){if(x%i==0){div.pb(i);if(i*i!=x)div.pb(x/i);}}
	sort(div.bg,div.ed);return div;}

int main(){
	rep1(i,51) pw2[i]=2*pw2[i-1];
    ll N; cin>>N;
	vector<ll>V(N);
	rep(i,N) cin>>V[i];
	sort(V.bg,V.ed);
	double tmp=0.0;
	rep(i,N){
		if(i==0) tmp+=V[i];
		else tmp+=pw2[i-1]*V[i];
	}
	printf("%.8f",tmp/pw2[N-1]);
}

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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define w(x)            int x; cin>>x; while(x--)
#define fr(i,a,b)       for(int i = a; i < b; i++)
#define inf 			1e9+1
void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

void knapsack(int n, int w, int *weights, int *values)
{
	int maxval = n * 1000;
	int dp[n + 1][maxval + 1];

	//base case
	for (int i = 0; i <= maxval; i++)
		dp[1][i] = inf;

	dp[1][0] = 0;
	dp[1][values[0]] = weights[0];

	for (int i = 2; i <= n; i++)
	{
		for (int v = 0; v <= maxval; v++)
		{
			if (values[i - 1] <= v)
				dp[i][v] = min(weights[i - 1] + dp[i - 1][v - values[i - 1]], dp[i - 1][v]);
			else
				dp[i][v] = dp[i - 1][v];
		}
	}

	int ans = 0;
	for (int x = 0; x <= maxval; x++)
	{
		if (dp[n][x] <= w)
			ans = x;
	}

	cout << ans << endl;
	return;

}

void solve()
{
	int n, w;
	cin >> n >> w;
	int weights[n], values[n];
	fr(i, 0, n)
	cin >> weights[i] >> values[i];
	knapsack(n, w, weights, values);
}

int32_t main()
{
	c_p_c();
	solve();
	return 0;
}

Measured memory_bytes: 81760
#include <bits/stdc++.h>
#include<chrono>
using namespace std;
using ll = long long;

int main() {
  int A, B;
  cin >> A >> B;
  if (A <= 5) {
    cout<< 0 << endl;
  }
  else if (A >= 13) {
    cout << B << endl;
  }
  else {
    cout << B / 2 << endl;
  }
}


Measured memory_bytes: 256
def f(v,t,now):
    res = now
    s = 0
    for i in range(len(t)-1):
        s+=t[i]
        if s-t[i]>=now:
            res = min(res,v[i]+s-t[i]-now)
        elif s>=now>=s-t[i]:
            res = min(res,v[i])
        else:
            res = min(res,v[i]+now-s)
    res = min(res, s-now)
    return max(res,0)
n = int(input())
t = list(map(int,input().split()))
v = list(map(int,input().split()))
t.append(0)
v.append(0)
ans = []
for i in range(sum(t)+1):
    ans.append(f(v,t,i))
    ans.append(f(v, t, i+0.5))
r = 0
for i in range(len(ans)-1):
    r+=(ans[i]+ans[i+1])/4
print(r)

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

int main(){
	int N;
	char* S;
	int x=0, max_x = 0;
	int i;
	scanf("%d", &N);

	S = (char*)malloc(sizeof(char) * (N + 1));

	scanf("%s", S);

	for(i=0; i<N; i++){
		if(S[i] == 'I'){
			x += 1;
			if(x > max_x){
				max_x = x;
			}
		}else{
			x -= 1;
		}
	}

	printf("%d\n", max_x);

	return 0;

}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

ll INF = 1000000000000;
vector<ll> ans(100001);
vvl G = vv(100001, 0, 0, ll);
vvl num = vv(100001, 2, INF, ll);
std::vector<int> oe(100001, 0);
int check(ll from, ll now){
  int ret = 0;
  for(int i=0;i<G[now].size();i++){
    if(from==G[now][i]) continue;
    int tmp = check(now, G[now][i]);
    if(ret==0) return oe[now] = -tmp;
    else if(ret==tmp) {
      std::cout << "No" << '\n';
      exit(0);
    }
  }
  return ret;
}
void back(ll from, ll now, ll l, ll r){
  num[now][0] = max(num[now][0], l);
  num[now][1] = min(num[now][1], r);
  if(num[now][0] > num[now][1]){
    std::cout << "No" << '\n';
    exit(0);
  }
  for(int i=0;i<G[now].size();i++){
    if(G[now][i]==from) continue;
    back(now, G[now][i], num[now][0]-1, num[now][1]+1);
  }
}
pair<ll, ll> dfs(ll from, ll now){
  ll l=-INF, r=INF;
  if(num[now][1]!=INF) l = num[now][0], r = num[now][1];
  for(int i=0;i<G[now].size();i++){
    if(from==G[now][i]) continue;
    pair<ll, ll> tmp = dfs(now, G[now][i]);
    l = max(l, tmp.first);
    r = min(r, tmp.second);
  }
  num[now][0] = l, num[now][1] = r;
  return make_pair(l-1, r+1);
}
void an(ll from, ll now){
  if(from==-1) ans[now] = num[now][0];
  else{
    ll p = ans[from];
    if(num[now][0] <= p+1 && p+1 <= num[now][1]) ans[now] = p+1;
    else if(num[now][0] <= p-1 && p-1 <= num[now][1]) ans[now] = p-1;
    else{
      std::cout << "No" << '\n';
      exit(0);
    }
  }
  for(int i=0;i<G[now].size();i++){
    if(from==G[now][i]) continue;
    an(now, G[now][i]);
  }
}
int main(int argc, char const *argv[]) {
  ll N, a, b, K;
  std::cin >> N;
  for(int i=0;i<N-1;i++){
    scanf("%lld %lld", &a, &b);
    G[a].push_back(b);
    G[b].push_back(a);
  }
  std::cin >> K;
  for(int i=0;i<K;i++){
    scanf("%lld %lld", &a, &b);
    num[a][0] = num[a][1] = b;
    oe[a] = (b%2==1?1:-1);
  }
  check(-1, 1);
  dfs(-1, 1);
  back(-1, 1, num[1][0], num[1][1]);
  for(int i=1;i<=N;i++){
    if(num[i][0]==num[i][1]){
      an(-1, i);
      break;
    }
  }
  //for(int i=1;i<=N;i++) std::cout << num[i][0] << " " << num[i][1] << '\n';
  std::cout << "Yes" << '\n';
  for(int i=1;i<=N;i++) std::cout << ans[i] << '\n';
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb push_back 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;
const ll INF=1000000000000000;

vector<ll> pw2(51,1); vector<ll> pw10(19,1);
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll mid(ll x,ll y,ll z){return x>y?y>=z?y:min(z,x):x>=z?x:min(y,z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll myceil(ll x,ll y){if(x<=y) return 1;else if(x%y==0) return x/y;else return x/y+1;}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> divisor(ll x){vector<ll> div;
	for(ll i=1;i*i<=x;i++){if(x%i==0){div.pb(i);if(i*i!=x)div.pb(x/i);}}
	sort(div.bg,div.ed);return div;}

//a,b x
int main(){
	ll W,H,N; cin>>W>>H>>N;
	ll U=H,D=0,L=0,R=W;
	rep(i,N){
		ll x,y,C; cin>>x>>y>>C;
		if(C==1 && x>=L) L=x;
		else if(C==2 && x<=R) R=x;
		else if(C==3 && y>=D) D=y;
		else if(C==4 && y<=U) U=y;
	}
	cout<<max(0ll,U-D)*max(0ll,R-L);
    
}

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

#define int long long 
#define MOD 1000000007



using namespace std;


signed main(){

	int N;
	cin>> N;
	
	int a[N];
	
	bool ans=false;
	
	for(int i=0;i<N;i++){
		cin >>a[i];
		if(a[i]%2==1){
			ans = true;
		}
	}

	

	if(ans){
		cout << "first" << endl;
 	}
 	else{
	 	cout << "second" << endl;
 	}
 	return 0;
	

}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(void) {
    int N;
    cin >> N;
    int MAX=0, MIN=1000;
    for(int i=0; i<N; i++) {
        int a;
        cin >> a;
        MAX = max(MAX, a);
        MIN = min(MIN, a);
    }

    cout << MAX-MIN << endl;
    return 0;
}


Measured memory_bytes: 256
n=int(input())
b=[]
for i in range(30):
    i+=2
    s=i*i
    while s <=1000:
        b.append(s)
        s=s*i
ans=1
for i in range(len(b)):
    if b[i] <= n and ans < b[i] :
        ans=b[i]
print(ans)






Measured memory_bytes: 3060
#include <stdio.h>

int main (void) {
	int n , i , buy;
	double sum = 0.0;
	
	scanf("%d",&n);
	
	for ( i = 0; i < n; i++ ) {
		scanf("%d",&buy);
		sum += (double)buy / n;
	}
	printf("%d\n",(int)sum);
	return 0;
}

Measured memory_bytes: 0
//author : Brijesh1in
#include <bits/stdc++.h>

using namespace std;
	
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define endl '\n'
#define boost ios::sync_with_stdio(false); cin.tie(NULL);
typedef long long li;


int main(){

	
	int n , k;
	cin>>n>>k;

	cout<<n-k+1<<endl;

}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
    if(a<b){
        int tmp=a;
        a=b;
        b=tmp;
    }
    int r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}
int main(){
    int n,X;
    cin>>n>>X;
    vector<int> x(n);
    for(int i=0;i<n;i++)cin>>x[i];
    if(n==1){
        cout<<abs(x[0]-X)<<endl;
        return 0;
    }
    vector<int> base(n);
    for(int i=0;i<n;i++){
        base[i]=abs(x[i]-X);
    }
    sort(base.begin(),base.end());
    int ans=gcd(base[0],base[1]);
    for(int i=2;i<n;i++){
        ans=gcd(ans,base[i]);
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
    ll w, h, x, y;

    cin >> w >> h >> x >> y;

    double half_area;
    half_area = (double)w * (double)h / 2;

    printf("%lf", half_area);

    if ( x + x == w & y + y == h ) {
        printf(" 1");
    }
    else {
        printf(" 0");
    }
//    if ( w % 2 != 0 | x % 2 != 0 ) {
//        printf(" 0\n");
//    }
//    else if ( w / 2 == x & h / 2 == y ) {
//        printf(" 1\n");
//    }
//    else {
//        printf(" 0\n");
//    }


    return 0;
}

Measured memory_bytes: 256
def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    S = input()
    K = len(S)-1
    s = 0
    for pattern in range(2**K):
        tmp = S[0]
        for i in range(K):
            if (pattern>>i)&1:
                tmp += ' '
            tmp += S[i+1]
        s += sum(map(int, tmp.split()))
    print(s)
if __name__ == '__main__':
    main()

Measured memory_bytes: 69912
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;

typedef  pair<int,int> P;
typedef long long LL;

const LL INF=300000000;
const LL MOD=1000000007;



int main(){
    string o,e;
    cin>>o>>e;
    string ans;
    for(int i=0;i<e.size();++i){
        ans.push_back(o[i]);
        ans.push_back(e[i]);
    }
    if(o.size()-e.size()==1)ans.push_back(o[o.size()-1]);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

#define rep(i, n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    string s;
    cin>>s;
    ll n = ll(s.size());

    vector<pair<ll,ll>> p;
    ll t=0;
    ll sum = 0;

    while(t<n){
        char a = s[t];
        sum=1;
        t++;
       while(t<n&&a==s[t]){t++;sum++;}
            if(a=='>'){
                p.push_back({1,sum});
                sum=0;
            }else{
                p.push_back({0,sum});
                sum=0;
            }
    }
     ll ans = 0;

    rep(i,p.size()){
       // cout<<p[i].first<<p[i].second<<endl;
        if(i+1<p.size()&&p[i].first==0&&p[i+1].first==1){
            ans+=max(p[i].second,p[i+1].second);
        }
        ans+=p[i].second*(p[i].second-1)/2;
    }


    if(s[0]=='>')ans+=p[0].second;
    if(s[s.size()-1]=='<')ans+=p[p.size()-1].second;

    cout<<ans<<endl;

    return 0;
}


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

void Main() {
    // input
    int K;
    int A, B;
    cin >> K;
    cin >> A >> B;

    // translate
    int num = K;
    while (num <= B) {
        if (num >= A) {
            cout << "OK" << endl;
            return;
        }
        num += K;
    }


    cout << "NG" << endl;


    // output

}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3596