akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

int main(){
    int x;
    int ans =0;
    

    cin >>  x ; 
    if (x >= 2000){
        ans =1;
    }else{
        for(int i= 0; i<20; i++){
            for(int j = 0; j<20;j++){
                for(int k=0;k<20;k++){
                    for(int l=0;l<20;l++){
                        for(int m=0;m<20;m++){
                            for(int n= 0;n<20;n++){
                                if(x == 100*i+101*j+102*k+103*l+104*m+105*n){
                                    ans =1;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if(ans == 0)putchar('0');
    else putchar('1');
    return 0;
}

Measured memory_bytes: 384
import sys
import math
from collections import defaultdict

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

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

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

#a!をmodしつつ求める
def fact(a,M=mod):
    ans = 1
    for i in range(2,a+1):
        ans = ans*i
        ans = ans%M
    return ans

#互いに素なa,bについて、a*x+b*y=1の一つの解[x,y]を出力
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]


#aの逆元(mod M)を求める（aとMは互いに素）
def mod_inv(a,M=mod):
    x = extgcd(a,M)[0]
    return (M+x%M)%M

N,M,K = II()
ans = 0
for i in range(N):
    x = i*(i+1)//2 + (N-1-i)*(N-i)//2
    for j in range(M):
        ans += M*x + N*(j*(j+1)+(M-1-j)*(M-j))//2
        ans %= mod

ans = ans*fact(N*M-2)*mod_inv(fact(K-2))*mod_inv(fact(N*M-K))*mod_inv(2)
ans %= mod
print(ans)

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

int main() {
    int N;
    cin >> N;
    vector<pair<pair<string, int>, int>> pairs;
    string s; int p;
    rep(i, N){
        cin >> s >> p;
        pairs.push_back(make_pair(make_pair(s, -p), i + 1));
    }
    sort(pairs.begin(), pairs.end());

    rep(i, N){
        cout << pairs.at(i).second << endl;
    }
}

Measured memory_bytes: 3648
#include <stdio.h>

#define EOL 40

int main(void)
{
    int n, i, j, max, maxk;
    int c[39][39];
    char str[60], kan[60];
    char *ps, *pk;
    char *k[] = {"?", "a", "b", "c", "d", "e", "f", "g", "h",
        "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
        "t", "u", "v", "w", "x", "y", "z", "ld", "mb", "mp",
        "nc", "nd", "ng", "nt", "nw", "ps", "qu", "cw", "ts"};

    for (i = 0; i < 39; ++i) {
        for (j = 0; j < 39; ++j) {
            c[i][j] = 0;
        }
    }

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

        ps = str;
        pk = kan;
        while (*ps != '\0') {
            switch (*ps) {
                case 'l':
                    if (*++ps == 'd')
                        *pk = 27;
                    else
                        *pk = *--ps - 'a' + 1;
                    break;
                case 'm':
                    if (*++ps == 'b')
                        *pk = 28;
                    else if (*ps == 'p')
                        *pk = 29;
                    else
                        *pk = *--ps - 'a' + 1;
                    break;
                case 'n':
                    if (*++ps == 'c')
                        *pk = 30;
                    else if (*ps == 'd')
                        *pk = 31;
                    else if (*ps == 'g')
                        *pk = 32;
                    else if (*ps == 't')
                        *pk = 33;
                    else if (*ps == 'w')
                        *pk = 34;
                    else
                        *pk = *--ps - 'a' + 1;
                    break;
                case 'p':
                    if (*++ps == 's')
                        *pk = 35;
                    else
                        *pk = *--ps - 'a' + 1;
                    break;
                case 'q':
                    if (*++ps == 'u')
                        *pk = 36;
                    else
                        *pk = *--ps - 'a' + 1;
                    break;
                case 'c':
                    if (*++ps == 'w')
                        *pk = 37;
                    else
                        *pk = *--ps - 'a' + 1;
                    break;
                case 't':
                    if (*++ps == 's')
                        *pk = 38;
                    else
                        *pk = *--ps - 'a' + 1;
                    break;
                case ' ':
                    *pk = 0;
                    break;
                default:
                    *pk = *ps - 'a' + 1;
                    break;
            }
            ++ps;
            ++pk;
        }
        *pk = EOL;

        for (pk = kan; *(pk + 1) != EOL; ++pk) {
            ++c[*pk][*(pk + 1)];
        }
    }

    for (i = 1; i <= 38; ++i) {
        max = 0;
        maxk = 1;
        for (j = 1; j <= 38; ++j) {
            if (c[i][j] > max) {
                max = c[i][j];
                maxk = j;
            }
        }
        printf("%s %s %d\n", k[i], k[maxk], c[i][maxk]);
    }

    return 0;
}

Measured memory_bytes: 600
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

MOD = 10**9+7

def main():
    n, k = rli()
    la = rli()
    rev1 = 0
    rev2 = 0
    for i in range(len(la)):
        for j in range(len(la)):
            if la[i] > la[j]:
                if i < j:
                    rev1 += 1
                else:
                    rev2 += 1
    ans = rev1 * k*(k+1)//2 + rev2 * (k-1)*k//2
    ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  int n; cin >> n;
  vector<string> s(n);
  rep(i,n) cin >> s[i];
  vector<int> a(n);
  vector<int> b(n);
  rep(i,n){
    int mx=0;
    rep(j,s[i].size()){
      if(s[i][j]==')') mx++;
      else mx--;
      chmax(a[i],mx);
    }
    mx=0;
    for(int j=s[i].size()-1;j>=0;j--){
      if(s[i][j]=='(') mx++;
      else mx--;
      chmax(b[i],mx);
    }
  }
  vector<pair<int,string> > v1(0);
  vector<pair<int,string> > v2(0);
  rep(i,n){
    if(b[i]-a[i]>=0) v1.emplace_back(a[i],s[i]);
    else v2.emplace_back(b[i],s[i]);
  }
  sort(all(v1));
  sort(all(v2));
  reverse(all(v2));
  string t;
  for(auto c:v1){
    t+=c.second;
  }
  for(auto c:v2){
    t+=c.second;
  }
  int check=0;
  rep(i,t.size()){
    if(t[i]=='(') check++;
    else check--;
    if(check<0){
      cout << "No" << endl;
      return 0;
    }
  }
  if(check!=0){
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 84432
def substring():
    a = input()
    K = int(input())
    atra = set()
    
    for i in range(len(a)):
        for j in range(i + K + 1):
            if i >= j:
                continue
            atra.add(a[i:j])
    atra = sorted(atra)
    print(atra[K - 1])
    
if __name__ == '__main__':
    substring()

Measured memory_bytes: 4464
n = int(input())
h = list(map(int,input().split()))
flag = 0

if n == 1:
  print("Yes")
elif n == 2:
  if h[1] - h[0] > -2:
    print("Yes")
  else:
    print("No")
else:
  for i in range(1,n):
    a = h[i-1]
    b = h[i]
    if b > a:
      if i == 1:
        h[i-1]  = h[i-1] - 1
        h[i]  = h[i] - 1
      else:
        h[i]  = h[i] - 1
    elif b == a:
      if i == 1:
        h[i-1]  = h[i-1] - 1
        h[i]  = h[i] - 1
      else:
        pass
    else:
      flag = 1
      break
  if flag:
    print("No")
  else:
    print("Yes")

Measured memory_bytes: 63984
#include<bits/stdc++.h>
using namespace std;
int MOD;
// #define MOD 998244353

class mint {
	public:
		int i;

		mint() : i(0) {}

		template<class T>
			mint(T x) {
				i = int(x % MOD);
				if (i < 0) i += MOD;
			}

		mint operator+(mint x) {
			return i + x.i;
		}

		mint operator-(mint x) {
			return i - x.i;
		}

		mint operator*(mint x) {
			return (long long)i * x.i;
		}

		mint operator/(mint x) {
			return (long long)i * x.pow(MOD - 2).i;
		}

		mint inv() {
			return pow(MOD - 2);
		}

		template<class T>
			mint pow(T p) {
				long long r = 1;
				long long t = i;
				for(; p > 0; p >>= 1) {
					if (p & 1) r = r * t % MOD;
					t = t * t % MOD;
				}
				return r;
			}

		template<class T1, class T2>
			static mint pow(T1 a, T2 b) {
				long long r = 1;
				long long t = (long long)(a % MOD);
				for(; b > 0; b >>= 1) {
					if (b & 1) r = r * t % MOD;
					t = t * t % MOD;
				}
				return r;
			}

		mint& operator+=(mint x) {
			i = (i + x.i) % MOD;
			return *this;
		}

		mint& operator-=(mint x) {
			i = i - x.i;
			if (i < 0) i += MOD;
			return *this;
		}

		mint& operator*=(mint x) {
			i = (int)((long long)i * x.i % MOD);
			return *this;
		}

		mint& operator/=(mint x) {
			i = (long long)i * x.pow(MOD - 2).i % MOD;
			return *this;
		}
};

std::ostream& operator<<(std::ostream& os, const mint& m) {
	return os << m.i;
}

mint dp[2002][6010];

void show(int n) {
	for(int i = 0; i <= n; i++) {
		for(int j = 0; j <= 3 * n; j++)
			cout << dp[i][j] << ' ';
		cout << endl;
	}
}

int main() {
	int n;
	cin >> n >> MOD;
	dp[0][0] = 1;
	for(int i = 0; i <= n; i++) {
		for(int j = 0; j <= 3 * n; j++) {
			if (j <= 3 * n - 1) dp[i][j+1] += dp[i][j];
			if (i <= n - 1 && j <= 3 * n - 2) dp[i+1][j+2] += dp[i][j] * (3*n-j-1);
			if (i <= n - 1 && j <= 3 * n - 3) dp[i+1][j+3] += dp[i][j] * (3*n-j-1) * (3*n-j-2);
		}
	}
	mint ans = 0;
	for(int i = 0; i <= n; i++) {
		ans += dp[i][3*n];
	}
	//show(n);
	cout << ans << endl;
}




Measured memory_bytes: 47232
#include <stdio.h>
/*
  整数i, j(0～9)に対して
  Cijを定義（1<=k<=N| kの先頭の桁の数はiに等しく末尾の桁の数はjに等しい）
  これをまず計算してから
  Cij × Cjiの結果を求める
*/
//プロトタイプ宣言
int lead(int n);
int end(int n);


int main (void){
  int n;
  int k;
  int i, j;
  int C[10][10]={};
  int count=0;
  scanf("%d", &n);

  for(k=1; k<=n; k++){
    i= lead(k);
    j= end(k);
    C[i][j] +=1;
  }

  for(i=0; i<=9 ; i++){
    for(j=0; j<=9; j++){
      count += C[i][j]*C[j][i];
    }
  }


  printf ("%d", count);
  return 0;
}

int lead(int n){
  while (n/10 !=0) {
    n /= 10;
  }
  return n;
}

int end(int n){
  return n%10;
}


Measured memory_bytes: 128
n, m = map(int, input().split())

ac = [0]*n
wa = [0]*n

for i in range(m):
    p, s = input().split()

    if s == 'WA' and ac[int(p)-1] == 0:
            wa[int(p)-1] += 1
    elif s == 'AC' and ac[int(p)-1] == 0:
            ac[int(p)-1] += 1

print('%d %d' % (sum(ac), sum([wa[k] for k in [i for i, j in enumerate(ac) if j != 0]])))

Measured memory_bytes: 9368
from fractions import gcd

n, m = [int(x) for x in input().split()]
a_list = [int(x) for x in input().split()]
a_h_list = [a // 2 for a in a_list]

count = set()
for a_h in a_h_list:
    temp = bin(a_h)
    count.add(len(temp) - temp.rfind("1"))

if len(count) == 1:
    temp = 1
    for a_h in a_h_list:
        temp *= a_h // gcd(a_h, temp)
    ans = (m // temp + 1) // 2
else:
    ans = 0

print(ans)

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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

#define	MOD 1000000007

struct	ITEM {
	long	wei;
	long	val;
};

int	main() {
	long N, W;
	cin >>N >>W;
	// Items = { Weight, Value }
	//vector<ITEM>	p = { {2, 3}, {1, 2}, {3, 6}, {2, 1}, {1, 3}, {5, 85} };
	vector<ITEM> p(N);
	for (long i=0; i<N; i++)
		cin >>p.at(i).wei >>p.at(i).val;
	long w1=p.at(0).wei;
	vector<vector<long>> WW(4);
	for (long i=0; i<N; i++)
		WW.at(p.at(i).wei-w1).push_back(p.at(i).val);
	for (int i=0; i<4; i++) {
		sort(WW.at(i).begin(), WW.at(i).end());
		reverse(WW.at(i).begin(), WW.at(i).end());
	}
	long S=0;
	for (int i0=0; i0<=WW.at(0).size(); i0++) {
		long WWW0=i0*w1;
		if (WWW0>W)
			break;
		for (int i1=0; i1<=WW.at(1).size(); i1++) {
			long WWW1=WWW0+i1*(w1+1);
			if (WWW1>W)
				break;
			for (int i2=0; i2<=WW.at(2).size(); i2++) {
				long WWW2=WWW1+i2*(w1+2);
				if (WWW2>W)
					break;
				long i3=WW.at(3).size();
				i3=min(i3, (W-WWW2)/(w1+3));
				long SS=0;
				for (int j=0; j<i0; j++)
					SS +=WW.at(0).at(j);
				for (int j=0; j<i1; j++)
					SS +=WW.at(1).at(j);
				for (int j=0; j<i2; j++)
					SS +=WW.at(2).at(j);
				for (int j=0; j<i3; j++)
					SS +=WW.at(3).at(j);
				S=max(S, SS);
			}
		}
	}
	cout <<S <<endl;
	return 0;
}


Measured memory_bytes: 256
sx, sy, tx, ty = map(int, input().split())

dx = tx - sx
dy = ty - sy

ans = []
ans += ["U"] * dy
ans += ["R"] * dx
ans += ["D"] * dy
ans += ["L"] * dx
ans += ["L"]
ans += ["U"] * (dy + 1)
ans += ["R"] * (dx + 1)
ans += ["D"]
ans += ["R"]
ans += ["D"] * (dy + 1)
ans += ["L"] * (dx + 1)
ans += ["U"]

print(*ans, sep="")


Measured memory_bytes: 4852
#include <stdio.h>
#include <math.h>
// #include <time.h>

int main(){
    long long int a;
    char bb[5];
    int i;
    scanf("%lld %s", &a, bb);
    long long int b=0;

    for(i=0;bb[i]!='\0';i++){
      if(bb[i]!='.'){
        b = 10*b + bb[i] - '0';
      }
    }
    printf("%lld\n", b*a/100);
    return 0;
}


Measured memory_bytes: 1736
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            Solve();
        }
        private const int MOD = 1000000007;
        private enum Color
        {
            B,
            W,
        }
        private struct Coordinate
        {
            public int x;
            public int y;
            public Coordinate(int x, int y)
            {
                this.x
                     = x;
                this.y = y;
            }
        }
        private static readonly int[] offsetX = { 0, -1, 1, 0 };// 2468方向
        private static readonly int[] offsetY = { 1, 0, 0, -1 };
        static void Solve()
        {
            var n = ReadAndParseIntArr();
            var dic = new HashSet<int>(n);
            string ans = dic.Contains(1) && dic.Contains(9) && dic.Contains(7) && dic.Contains(4) ? "YES" : "NO";
            Console.WriteLine(ans);
        }
        private static bool IsConnected(Coordinate src, Coordinate dst, int w, int h, Color[,] table)
        {
            if (dst.x < 0 || w <= dst.x) { return false; }
            if (dst.y < 0 || h <= dst.y) { return false; }
            if (table[src.y, src.x] == table[dst.y, dst.x]) { return false; }
            return true;
        }
        #region よく使う便利関数
        private static bool isPrime(long x)
        {
            if (x == 2) { return true; }
            if (x < 2 || x % 2 == 0) { return false; }
            long i = 3;
            while (i * i <= x)
            {
                if (x % i == 0) { return false; }
                i = i + 2;
            }
            return true;
        }
        private static long lcm(long x, long y)
        {
            return x / gcd(x, y) * y;
        }
        private static long gcd(long x, long y)
        {
            return y > 0 ? gcd(y, x % y) : x;
        }
        private static long pow(long x, long n)
        {
            if (n == 0) { return 1; }
            long res = pow(x * x % MOD, n / 2);
            if (n % 2 == 1)
            {
                res = res * x % MOD;
            }
            return res;
        }
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        #endregion
    }
}

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

int main()
{
    int N, Z, W;
    int A[2005];
    cin >> N >> Z >> W;

    for(int i = 0; i < N; i++) cin >> A[i];

    cout << max(abs(A[N - 1] - W), abs(A[max(N - 2, 0)] - A[N - 1])) << endl;

    return (0);
}

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

int main()
{
	while (1) {
		int H, W;
		cin >> H >> W;

		if (H == 0 && W == 0)break;

		for (int i = 1; i <= H; i++) {
			for (int j = 1; j <= W; j++) {
				int sum = i + j;
				if (sum % 2 == 0)cout << "#";
				else cout << ".";
			}
			cout << endl;
		}
		cout << endl;
	}
}

Measured memory_bytes: 3056
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define ll long long

int n;
ll a;

int main(){
  ll sum=1;
  int flag=1;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%lld",&a);
    if(a==0){
      sum*=0;
      break;}
    if(1.0*log(sum)+1.0*log(a)>18.0*log(10)){
    flag=0; continue;}
    sum *= a;
    if(sum>1000000000000000000){
    sum=-1; break;}
  }
  
  if(flag==0 && sum!=0){
    sum=-1;}
  printf("%lld\n",sum);
  
  return 0;
}


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

const int MAX_H = 99;
char grid[100][100];

void divide(int a){
    int c = min(a-1, MAX_H/4);
    for(int i=0;i<c;i++)
        for(int j=0;j<MAX_H;j++) grid[4*i+3][j] = '#';
    
    if (c==a-1) return;

    a -= c + 1;
    for(int i=0;i<MAX_H/4 && a;i++){
        if(c<a){
            for(int j=0;j<MAX_H;j++) grid[j][4*i+3] = '#';
            a -= c + 1;
        }else{
            for(int j=0;j<4*a;j++) grid[j][4*i+3] = '#';
            a = 0;
        }
    }
}

int main(){
    int a, b; cin >> a >> b;

    for(int i=0;i<MAX_H;i++){
        for(int j=0;j<=MAX_H;j++) grid[i][j] = '.';
    }
    divide(a);

    if(a!=1){
        b--;
        for(int i=0;i<MAX_H;i++) grid[i][99] = '#';
    }

    for(int i=1;i<MAX_H;i+=4){
        for(int j=1;j<MAX_H;j+=4)
            if(0<b--) grid[i][j] = '#';
    }

    cout << MAX_H << ' ' << MAX_H + 1 << endl;
    for(int i=0;i<MAX_H;i++){
        for(int j=0;j<=MAX_H;j++) cout << grid[i][j];
        cout << '\n';
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin>>N;
  int a=0,w=0,t=0,r=0;
  for(int i=0;i<N;i++){
    string S;
    cin>>S;
    if(S=="AC")a++;
    else if(S=="WA")w++;
    else if(S=="TLE")t++;
    else if(S=="RE")r++;
  }
    cout << "AC x "<<a<<endl;
    cout << "WA x "<<w<<endl;
    cout << "TLE x "<<t<<endl;
    cout << "RE x "<<r<< endl;
}

Measured memory_bytes: 3624
#include<stdio.h>
 
int main (void) {
int i,j,k;
int N,X;
int count;

while (1) {
scanf("%d %d", &N, &X);
if (N+X == 0) break;
 
count = 0;
for (i = 1; i <= N-2; i++)
for (j = i+1; j <= N-1; j++)
for (k = j+1; k <= N; k++)
if(i+j+k == X) count++;
 
printf("%d\n", count);
}
 
return (0);
}

Measured memory_bytes: 600
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	
	for i := 'a'; i <= 'z'; i++ {
		has := false
		for j := 0; j < len(s); j++ {
        	if string(i) == string(s[j]) {
				has = true
            	continue
			}
		
		}
		if !has {
        	fmt.Println(string(i))
        	return
		}
	}
	fmt.Println("None")
}

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

using namespace std;

char a[10];
int m,d;

int main()
{
    scanf("%s",&a);
    m = (a[0] - '0') * 10 + (a[1] - '0');
    d = (a[2] - '0') * 10 + (a[3] - '0');
    if(m <= 12 && m > 0)
    {
        if(d <= 12 && d > 0)
            printf("AMBIGUOUS\n");
        else
            printf("MMYY\n");
    }
    else
    {
        if(d <= 12 && d > 0)
            printf("YYMM\n");
        else
            printf("NA\n");
    }
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(pi c, pi d){
	return c.S < d.S;
}

int main() {
	ll w, h, x, y;
	
	cin >> w >> h >> x >> y;
	int ans = (2*x == w && 2*y == h?1:0);
	cout << double(w) * double(h) /2 << " " << ans;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define MOD (long long)1000000007
#define INF (long long)998244353
using namespace std;

int main(void){
    long long n,a,b;
    cin >> n >> a >> b;
    vector<long long> town(n,0);
    for(int i=0; i<n; i++)cin >> town[i];
    long long ans=0;
    for(int i=0; i+1<n; i++){
        ans+=min((town[i+1]-town[i])*a,b);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>   
#include<cstdio>  
using namespace std;
typedef long long LL;

LL mod_pow(LL n, LL m, LL mod) {
	LL res = 1;
	while (m > 0) {
		if (m & 1)
			res = res * n % mod;
		n = n * n % mod;
		m >>= 1;
	}
	return res;
}
int main()
{
	LL n, m;
	LL mod = 1000000007;
	scanf("%lld %lld", &n, &m);
	printf("%d\n", mod_pow(n, m , mod));
	return 0;
}


Measured memory_bytes: 3220
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        for (int i = 1; i <= 9; i++) {
            if (N % i == 0 && N / i >= 1 && N / i <= 9) {
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }
}


Measured memory_bytes: 23764
# 初案のアルゴリズムが違っていた。難しかった。

n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
b.append(0) #ダミー
z = 0
c = b[0]
for i in range(n+1):
    x = a[i] - c
    if i < n:
        if x <= 0:
            z += a[i]
            if -x >= a[i+1]:
                c = b[i+1] + a[i+1]
            elif -x < a[i+1]:
                c = b[i+1] - x
        elif x > 0:
            z += c
            c = b[i+1]
    elif i == n:
        if x <= 0:
            z += a[i]
        else:
            z += c
print(z)


Measured memory_bytes: 19004
import Control.Applicative( (<$>))
import Data.List( sort, group)
main = do
    n_ <- readLn::IO Int
    as_ <- map read . words <$> getLine
    let
	trans v i = let
			(q,r) = i `quotRem` 2
		in
		    case (r,v) of
			(0,0) -> trans 1 q
			(0,1) -> 2
			(1,0) -> 0
			(1,1) -> 1
	
	transformed = (trans 0) <$> as_
	zero_one_two = length' <$> (group $ sort transformed)
	    where
		length' (h:rest) = (h,1+length rest)

	[zero,one,two] = case zero_one_two of
	    [(0,zero),(1,one),(2,two)]	-> [zero,one,two]
	    [(0,zero),(1,one)]		-> [zero,one,0]
	    [(0,zero),(2,two)]		-> [zero,0,two]
	    [(1,one),(2,two)]		-> [0,one,two]
	    [(0,zero)]			-> [zero,0,0]
	    [(1,one)]			-> [0,one,0]
	    [(2,two)]			-> [0,0,two]

    putStr $ if even one
	    then if (zero+two) `quot` 2 <= two
		    then "Yes"
		    else "No"
	    else if (zero+two+1) `quot` 2 <= two
		    then "Yes"
		    else "No"

Measured memory_bytes: 35580
#include<stdio.h>

int main(){
    int n, m;
    scanf("%d %d", &n, &m);
    int buf = m/n;
    int ans = -1;
    for(int i=buf; i>=1; i--){
        if(m%i == 0){
            ans = i;
            break;
        }
    }
    printf("%d", ans);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<int, int>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

int n;

int main() {
    cin >> n;
    vector< vector<int> > graph(n, vector<int>());
    vector<int> fenvec(n, -1);
    vector<int> snuvec(n, -1);
    fenvec.at(0) = 0; snuvec.at(n-1) = 0;
    for(int i = 0; i < n-1; ++i) {
        int aa, bb; cin >> aa >> bb;
        aa--; bb--;
        graph.at(aa).emplace_back(bb);
        graph.at(bb).emplace_back(aa);
    }

    auto numberling = [&](vector<int> &chvec, int first) {
        queue<int> que;
        que.push(first);
        while(!que.empty()) {
            int now = que.front();
            que.pop();
            for(int i = 0; i < (int)graph.at(now).size(); ++i) {
                int next = graph.at(now).at(i);
                if(chvec.at(next) == -1) {
                    chvec.at(next) = chvec.at(now) + 1;
                    que.push(next);
                }
            }
        }
    };

    numberling(fenvec, 0);
    numberling(snuvec, n-1);

    int fennec = 0;
    int snuke = 0;
    for(int i = 0; i < n; ++i) {
        if(fenvec.at(i) <= snuvec.at(i)) fennec++;
        else snuke++;
    }

    if(fennec > snuke) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;
}

Measured memory_bytes: 6528
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String ans = (s.charAt(2) == s.charAt(3) && s.charAt(4) == s.charAt(5)) ? "Yes" : "No";
		System.out.println(ans);
	}

}


Measured memory_bytes: 21844
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100000;

int main(void){
    ll a,b,c,d;
    string s,t;

    cin >> a >> b;//>> c >> d;
    //cin >> s >> t;
    cout << 2 * b - a << endl;

    return 0;
}

Measured memory_bytes: 256
from itertools import accumulate

N, K, *PC = map(int, open(0).read().split())
P, C = [0] + PC[:N], [0] + PC[N:]

ans = float("-inf")
for start in range(1, N + 1):
    path = []

    cur = P[start]
    path = [C[start]]
    while cur != start:
        path.append(C[cur])
        cur = P[cur]

    A = list(accumulate(path))
    q, r = divmod(K, len(path))
    res = 0
    if A[-1] >= 0:
        if r == 0:
            q -= 1
            r += len(path)
        res += A[-1] * q
    elif q >= 1:
        r = len(path)

    ans = max(ans, res + max(A[:r]))

print(ans)

Measured memory_bytes: 108108
# -*- coding: utf-8 -*-
from collections import defaultdict
N=input()
s=raw_input()

str="abcdefghijklmnopqrstuvwxyz"
D={}
for i,str in enumerate(str):
	D[str]=i+1

base=27
mod=2**61-1
hash=[]

for i,x in enumerate(s):
	if i==0: hash.append(D[x]%mod)
	else: hash.append( (hash[-1]*base+D[x])%mod )

def get(l,r):
	if l==0: return hash[r-1]%mod
	else: return ( hash[r-1]-hash[l-1]*pow(base,(r-l),mod) )%mod

# 長さmを固定し、区間 [i, i + m) のハッシュ値を求めて、長さmの共通文字列があるかを判定
def check(m):
	C={}
	for i in range(N):
		if i+m<=N:
			hash_value=get(i,i+m)
			if hash_value in C:
				if m<=i-C[hash_value]:
					return True
			else:
				C[hash_value]=i
	else:
		return False

l=0
h=N

while 1<(h-l):
	m=(l+h)/2
	if check(m):
		l=m
	else:
		h=m

print l


Measured memory_bytes: 39196
from itertools import product
S = input()
n = len(S)
bit = list(product([0, 1], repeat = n - 1))
ans = 0
for state in bit:
    s = S[0]
    for i in range(len(state)):
        if state[i] == 1:
            s += '+' + S[i + 1]
        else:
            s += S[i + 1]
    ans_list = list(map(int,s.split('+')))
    for a in ans_list:
        ans += a
print(ans)


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

int main() {
	int n;
	cin >> n;
	vector<int> a(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		a[i] -= i;
	}
	sort(a.begin() + 1, a.end());
	int b;
	if (n % 2 == 0)
		b = (a[n / 2] + a[n / 2 + 1]) / 2;
	else
		b = a[n / 2 + 1];
	long long ans = 0;
	for (int i = 1; i <= n; i++)
		ans += abs(a[i] - b);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
#define MAX 100
static const int dx[4] = {1, 0, -1, 0};
static const int dy[4] = {0, -1, 0, 1};
int w, h, sx, sy, gx, gy, G[MAX+2][MAX+2];
bool dfs( int x, int y, int color ){
if ( color == 0 || G[x][y] != color ) return false;
if ( x == gx && y == gy ) return true;
G[x][y] = 0;
for ( int r = 0; r < 4; r++ ){
if ( dfs(x + dx[r], y + dy[r], color) ) return true;
}
return false;
}
main(){
int n, c, d, px, py, ww, hh;
while( cin >> w >> h && w ){
cin >> sx >> sy >> gx >> gy >> n;
for ( int y = 0; y < h+2; y++ )
for ( int x = 0; x < w+2; x++ ) G[x][y] = 0;
for ( int i = 1; i <=n; i++ ){
cin >> c >> d >> px >> py;
if ( d == 0 ) { ww = 4; hh = 2; }
else { ww = 2; hh = 4; }
for ( int y = 0; y <= hh-1; y++ )
for ( int x = 0; x <= ww-1; x++ ) G[px+x][py+y] = c;
}
if ( dfs(sx, sy, G[sx][sy]) ) cout << "OK" << endl;
else cout << "NG" << endl;
}
}

Measured memory_bytes: 0
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


# --------------------------------------------

dp = None


def is_even_str(s):
    return s[:len(s) // 2] == s[len(s) // 2:]


def main():
    S = input()

    for i in range(2, 99999, 2):
        if is_even_str(S[:len(S) - i]):
            print(len(S) - i)
            return


main()


Measured memory_bytes: 4828
import math
 
def prime(num):
  if num==1 or num==2 or num==3:
    return True
  for i in range(2,int(math.sqrt(num))+1):
    if num%i==0:
      return False
  else:
    return True
 
n=int(input())
ans=0
for i in range(n):
  tmp=int(input())
  if prime(tmp):
    ans+=1
print(ans)


Measured memory_bytes: 5672
use std::fmt::{Debug, Display};
use std::io::{self, Read};
use std::str::{self, FromStr};


fn solve(a: Vec<u32>) -> bool {
    let (x, y, z) = {
        let (mut x, mut y, mut z) = (0, 0, 0);
        for v in a {
            if v % 4 == 0 {
                z += 1;
            } else if v % 2 == 0 {
                y += 1;
            } else {
                x += 1;
            }
        }
        if y == 1 {
            x += 1;
        }
        (x, y >= 2, z)
    };
    if y { x <= z } else { x <= z + 1 }
}


fn main() {
    let stdin = io::stdin();
    let mut sc = Scanner::new(stdin.lock().bytes());
    let n = sc.next();
    if solve(sc.vec(n)) {
        println!("Yes");
    } else {
        println!("No");
    }
}


struct Scanner<R: Read> {
    buf: Vec<u8>,
    bytes: io::Bytes<R>,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(bytes: io::Bytes<R>) -> Self {
        Scanner {
            buf: Vec::with_capacity(256),
            bytes: bytes,
        }
    }

    fn next<T: FromStr>(&mut self) -> T
    where
        <T as FromStr>::Err: Debug,
    {
        self.buf.clear();
        for c in self.bytes
            .by_ref()
            .map(|c| c.unwrap())
            .skip_while(|&c| c == ' ' as u8 || c == '\n' as u8)
            .take_while(|&c| !(c == ' ' as u8 || c == '\n' as u8))
        {
            self.buf.push(c);
        }
        str::from_utf8(&self.buf).unwrap().parse().unwrap()
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        (0..n).map(|_| self.next()).collect()
    }

    fn pairs<A: FromStr, B: FromStr>(&mut self, n: usize) -> Vec<(A, B)>
    where
        <A as FromStr>::Err: Debug,
        <B as FromStr>::Err: Debug,
    {
        (0..n).map(|_| (self.next(), self.next())).collect()
    }

    fn trios<A: FromStr, B: FromStr, C: FromStr>(&mut self, n: usize) -> Vec<(A, B, C)>
    where
        <A as FromStr>::Err: Debug,
        <B as FromStr>::Err: Debug,
        <C as FromStr>::Err: Debug,
    {
        (0..n)
            .map(|_| (self.next(), self.next(), self.next()))
            .collect()
    }

    fn mat<T: FromStr>(&mut self, m: usize, n: usize) -> Vec<Vec<T>>
    where
        <T as FromStr>::Err: Debug,
    {
        (0..n).map(|_| self.vec(m)).collect()
    }
}


#[allow(dead_code)]
fn print_foreach<T: Display>(answer: &[T]) {
    for x in answer {
        println!("{}", x);
    }
}


#[allow(dead_code)]
fn print_yn(answer: bool, yes: &str, no: &str) {
    println!("{}", if answer { yes } else { no });
}


#[allow(dead_code)]
fn print_or<T: Display>(answer: &Option<T>, or: &T) {
    match *answer {
        Some(ref x) => println!("{}", x),
        None => println!("{}", or),
    }
}


Measured memory_bytes: 4352
al = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
c = input()
for i, a in enumerate(al):
    if a == c: print(al[i+1])

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <deque>
#include <climits>
using namespace std;
#define ll long long int
#define ld long long double
#define vi vector<long long int>
#define vc vector<char>
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(i = (a); i < (n); i++)
#define fi(i,a,n) for(i = (a); i <= (n); i++)
#define F first
#define S second

int main() {
    ll n;
    cin>>n;
    vi v(n);
    bool  c = false;
    ll count = 0;
    ll neg = 0;
    ll min = LLONG_MAX;
    for(ll i=0;i<n;i++){
        cin>>v[i];
        if(v[i]==0){
            c = true;
        }
        count += abs(v[i]);

        if(v[i]<0){
            neg++;
        }

        if(abs(v[i])<min){
            min = abs(v[i]);
        }

    }

    if(c || neg%2==0){
        cout<<count<<endl;
    }
    else{
        cout<<count - 2*min <<endl;
    }

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

const i64 INF = 1LL << 50;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M;
  cin >> N >> M;
  vector<i64> costs(M);
  vector<int> keys(M);
  REP(i, M) {
    int b;
    cin >> costs[i] >> b;
    REP(j, b) {
      int c;
      cin >> c;
      --c;
      keys[i] |= 1 << c;
    }
  }

  const int L = 1LL << N;
  vector<vector<i64>> dp(2, vector<i64>(L, INF));
  dp[0][0] = 0;
  REP(i, M) {
    i64 cost = costs[i];
    int key = keys[i];
    dp[1] = dp[0];
    REP(state, L) {
      if (dp[1][state] >= INF) continue;
      dp[0][state | key] = min(dp[0][state | key], dp[1][state] + cost);
    }
  }
  int keyall = 0;
  REP(i, N) { keyall |= 1 << i; }
  i64 ans = dp[0][keyall];
  cout << (ans == INF ? -1 : ans) << endl;
}


Measured memory_bytes: 3744
#include<stdio.h>
 
#define max(a,b) (a < b? b : a)
#define min(a,b) (a < b? a : b)
 
int main(void)
{
  int N;
  scanf("%d", &N);
  
  int p[20];
  for(int i = 0; i < N; i++)
  {
  	scanf("%d", &p[i]);  
  }
  
  int cnt = 0;
  for(int i = 1; i < N - 1; i++)
  {
    int ma = max( max( p[i - 1], p[i]), p[i + 1] );
    int mi = min( min( p[i - 1], p[i]), p[i + 1] );
    if( (ma != p[i]) && (mi != p[i]) )
    {
      cnt++;
    }
  }
  
  printf("%d", cnt);
  
}

Measured memory_bytes: 128
from itertools import combinations
n,m,x = map(int, input().split())
ca = [list(map(int, input().split())) for _ in range(n)]

ans = 10**9
for i in range(1, n+1):
  for j in combinations(ca, i):
    t = [0]*(m+1)
    for k in j:
      for l in range(m+1):
        t[l] += k[l]
    if all(t[q] >= x for q in range(1,m+1)):
      ans = min(ans, t[0])
if ans != 10**9: print(ans)
else: print(-1)

Measured memory_bytes: 9132
#include<stdio.h>
#include<iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>

using namespace std;

int main() {


	int n;
	cin >> n;
	
	int cnt = 0;
	int max = -1;

	long long int h[100000];

	cin >> h[0];

	for (int i = 1; i < n; i++) {
		cin >> h[i];
		if (h[i - 1] >= h[i]) {
			cnt++;
		}
		else {
			if (cnt >= max) {
				max = cnt;
			}
			cnt = 0;
		}
		
	}

	if (cnt >= max) {
		max = cnt;
		cnt = 0;
	}

	cout << max << endl;



	return 0;
}


Measured memory_bytes: 1024
/**
 *    author:  tourist
 *    created: 23.05.2020 15:53:29       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tt;
  cin >> tt;
  while (tt--) {
    long long n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    vector<pair<int, long long>> ops;
    ops.emplace_back(2, a);
    ops.emplace_back(3, b);
    ops.emplace_back(5, c);
    const long long inf = (long long) 4e18;
    map<long long, long long> mp;
    mp[0] = 0;
    mp[1] = d;
    function<long long(long long)> Dfs = [&](long long x) {
      if (mp.find(x) != mp.end()) {
        return mp[x];
      }
      long long ret = inf;
      if ((long double) d * (long double) x < ret) {
        ret = d * x;
      }
      for (auto& p : ops) {
        int num = p.first;
        long long cost = p.second;                      
        ret = min(ret, Dfs(x / num) + cost + d * (x % num));
        if (x % num != 0) {
          ret = min(ret, Dfs(x / num + 1) + cost + d * (num - x % num));
        }
      }
      return mp[x] = ret;
    };
    cout << Dfs(n) << '\n';
  }
  return 0;
}


Measured memory_bytes: 4428
#include<stdio.h>
#define N 100
#define White 0
#define Black 2
#define Gray 1


int GX[N][N],x,color[N],time,d[N],f[N];

void visit(int u){
  int v;
  color[u]=Gray;
  d[u]=++time;
  for(v=0;v<x;v++){
    if(GX[u][v]==0) continue;
    if(color[v]==White) visit(v);
  }
  color[u]=Black;
  f[u]=++time;
}

void dfs(){
  int u;
  for(u=0;u<x;u++) color[u]=White;
  time=0;
  for(u=0;u<x;u++){
    if(color[u]==White) visit(u);
  }
  for(u=0;u<x;u++) printf("%d %d %d\n",u+1,d[u],f[u]);
}

int main(){

  int i,j,a,b,c,v,g;

  scanf("%d",&x);

  for(i=0;i<x;i++){
    for(j=0;j<x;j++){
      GX[i][j]=0;
    }
  }

  for(i=0;i<x;i++){
    scanf("%d",&v);
    scanf("%d",&g);
    v--;
    for(j=0;j<g;j++){
      scanf("%d",&a);
      a--;
      GX[v][a]=1;
    }
  }

  dfs();
  return 0;
}



Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr int mod = 1e9+7;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.rbegin(), a.rend());
  int res = 0;
  rep(i,n) {
    if (i % 2 == 0) res += a[i];
    else res -= a[i];
  }
  cout << res << endl;
  return 0; 
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

int main() {
  int n;
  cin >> n;
  vector<ll> x(n), s(n);
  for (int i = 0; i < n; i++) cin >> x[i];
  for (int i = 0; i < n; i++) s[i] = x[i];
  sort(s.begin(), s.end());

  ll med1 = s[n / 2];
  ll med2 = s[n / 2 - 1];

  ll ans(0);
  for (int i = 0; i < n; i++) {
    if (x[i] < med1) {
      ans = med1;
    } else {
      ans = med2;
    }
    printf("%ld\n", ans);
  }
}


Measured memory_bytes: 6384
import java.util.*;

class Main {
  public static void main (String[] args) {
    Map<String, String> dec1 = new HashMap<String, String>();
    dec1.put("A", "00000");
    dec1.put("B", "00001");
    dec1.put("C", "00010");
    dec1.put("D", "00011");
    dec1.put("E", "00100");
    dec1.put("F", "00101");
    dec1.put("G", "00110");
    dec1.put("H", "00111");
    dec1.put("I", "01000");
    dec1.put("J", "01001");
    dec1.put("K", "01010");
    dec1.put("L", "01011");
    dec1.put("M", "01100");
    dec1.put("N", "01101");
    dec1.put("O", "01110");
    dec1.put("P", "01111");
    dec1.put("Q", "10000");
    dec1.put("R", "10001");
    dec1.put("S", "10010");
    dec1.put("T", "10011");
    dec1.put("U", "10100");
    dec1.put("V", "10101");
    dec1.put("W", "10110");
    dec1.put("X", "10111");
    dec1.put("Y", "11000");
    dec1.put("Z", "11001");
    dec1.put(" ", "11010");
    dec1.put(".", "11011");
    dec1.put(",", "11100");
    dec1.put("-", "11101");
    dec1.put("'", "11110");
    dec1.put("?", "11111");
    Map <String, String> dec2 = new HashMap<String, String>();
    dec2.put("101", " ");
    dec2.put("000000", "'");
    dec2.put("000011", ",");
    dec2.put("10010001", "-");
    dec2.put("010001", ".");
    dec2.put("000001", "?");
    dec2.put("100101", "A");
    dec2.put("10011010", "B");
    dec2.put("0101", "C");
    dec2.put("0001", "D");
    dec2.put("110", "E");
    dec2.put("01001", "F");
    dec2.put("10011011", "G");
    dec2.put("010000", "H");
    dec2.put("0111", "I");
    dec2.put("10011000", "J");
    dec2.put("0110", "K");
    dec2.put("00100", "L");
    dec2.put("10011001", "M");
    dec2.put("10011110", "N");
    dec2.put("00101", "O");
    dec2.put("111", "P");
    dec2.put("10011111", "Q");
    dec2.put("1000", "R");
    dec2.put("00110", "S");
    dec2.put("00111", "T");
    dec2.put("10011100", "U");
    dec2.put("10011101", "V");
    dec2.put("000010", "W");
    dec2.put("10010010", "X");
    dec2.put("10010011", "Y");
    dec2.put("10010000", "Z");
    Scanner scanner = new Scanner(System.in);
    String  out = "";
    while (scanner.hasNext()) {
      String line = scanner.nextLine();
      String dec1Str = "";
      for (int ii = 0; ii < line.length(); ii++) {
        dec1Str += dec1.get(line.substring(ii, ii + 1));
      }
      for (;;) {
        boolean flag = false;
        for (int ii = 3; ii < 9; ii++) {
          if (dec1Str.length() < ii) {
            flag = false;
            break;
          }
          String key = dec1Str.substring(0, ii);
          if (dec2.containsKey(key)) {
            out += dec2.get(key);
            dec1Str = dec1Str.substring(ii);
            flag = true;
            break;
          }
        }
        if (!flag) {
          break;
        }
      }
      out += "\n";
    }
    System.out.print(out);
  }
}

Measured memory_bytes: 156316
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <assert.h>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main(){
  ll n;
  cin>>n;
  vector<ll> v;
  rep(i,0,n){
    ll a;
    cin>>a;
    v.pb(a);
  }
  ll a = v[0]+v[1];
  ll b = 0;
  rep(i,2,v.sz){
    b^=v[i];
  }
  ll c = 0;
  per(i,0,60){
    if(((b>>i)&1)==1){
      c += (1LL<<i);
    }
  }
  ll c1 = c;
  ll d = 0;
  per(i,0,60){
    if(((b>>i)&1)==0){
      if(c1+(1LL<<(i+1))>a){

      }
      else{
        d+=(1LL<<i);
        c1+=(1LL<<(i+1));
      }
    }    
  }
  if(c1!=a){
    cout << -1 << endl;
    return 0;
  }
  per(i,0,60){
    if(((c>>i)&1)==1){
      if(d+(1LL<<i)<=v[0]){
        d += (1LL<<i);
      }
    }
  }
  if(d!=0&&d<=v[0]){
    cout << v[0]-d << endl;
  }
  else{
    cout << -1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<vector>
using namespace std;
int main(){
	int r, D,x2000;
	vector<int> x(11);
	cin >> r >> D>>x[0];
	for (int i = 0; i < 10; i++){
		x[i + 1] = x[i] * r - D;
	}
	for (int i = 1; i < 11; i++){
		cout << x[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int N;
  cin >> N;
  
  for (int i = 1; i <= 10; ++i) {
    if (i * 1000 >= N) {
      cout << (i * 1000 - N) << endl;
      break;
    }
  }
  
  return 0;
}


Measured memory_bytes: 3632
// Create by JJL
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <set>
#include <queue>
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;

using namespace std;
int main(){
    IOS;
    /* START CODE */
    LL  x,k,d;
    cin>>x>>k>>d;
    if(x<0) x=-x;
    if(x/d>=k) cout<<x-k*d<<endl;
    else {
        LL tx=x%d;
        k-=(x-tx)/d;
        if(k%2==0) cout<<abs(tx)<<endl;
        else cout<<d-tx<<endl;
    }
    return 0;
}


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

int main() {
    int n;
	cin>>n;
	int A[n+1];
	for(int i=0;i<n+1;i++) A[i]=0;
	for(int i=0;i<n-1;i++){
	    int val;
	    cin>>val;
	    A[val]++;
	}
	for(int i=1;i<n+1;i++){
	    cout<<A[i]<<endl;
	}
    return 0;
}


Measured memory_bytes: 4404