akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
typedef long long ll;

int main(void) {
  ll i, j, k, ans, cnt = 1, n;
  char a[110];
  scanf("%s%lld", a, &k);
  n = strlen(a);
  ll cmb[n + 1][k + 2], p[k + 1];
  for(i = 0; i <= n; ++i) for(j = 0; j <= k; ++j) cmb[i][j] = 0;
  cmb[0][0] = 1;
  for(i = 0; i < n; ++i) for(j = 0; j <= k; ++j) 
    cmb[i + 1][j] += cmb[i][j], cmb[i + 1][j + 1] += cmb[i][j];
  p[0] = 1;
  for(i = 0; i < k; ++i) p[i + 1] = p[i] * 9;
  ans = cmb[n - 1][k] * p[k];
  ans += cmb[n - 1][k - 1] * (a[0] - '1') * p[k - 1];
  for(i = 1; i < n; ++i) {
    if(cnt == k) break;
    if(a[i] != '0') {
      ans += cmb[n - 1 - i][k - cnt] * p[k - cnt];
      cnt++;
      ans += (a[i] - '1') * cmb[n - 1 - i][k - cnt] * p[k - cnt];
    }
  }
  printf("%lld", ans + (cnt == k ? 1 : 0));
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(){
	int a,b,c;
	int i,n=0;

	scanf("%d %d %d",&a,&b,&c);

	for(i=a;i<=b;i++){
		if(c%i == 0){
			n++;
		}
	}
	printf("%d\n",n);
	return 0;
}

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

int main() {
	int n;cin >> n;
	int x =0;
	int n2=n;
	while(n2>0){
		x += n2%10;
		n2/=10;
	}
	if(n%x==0) cout << "Yes" << endl;
	else cout << "No" << endl;
}



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

queue<int> S;// ??\???????????????????????¨???????????????
vector<int> in[MAX_N];// ??\??????
vector<int> out[MAX_N];// ?????????
vector<int> G[MAX_N];// ??\?????????????????????????????\???

void init(int V){// ?????°??????????????°
  for(int i=0;i<V;i++)in[i].clear();
  for(int i=0;i<V;i++){
    out[i]=G[i];
    for(int j=0;j<G[i].size();j++)
      in[G[i][j]].push_back(i);
  }
  for(int i=0;i<V;i++)
    if(!in[i].size())S.push(i);
}

vector<int> Topological_Sort(int V){
  vector<int> res;
  while(!S.empty()){
    int pos=S.front(); S.pop();
    res.push_back(pos);
    for(int i=0;i<out[pos].size();i++){
      int nx=out[pos][i];
      if(in[nx].size()==1)S.push(nx);
      for(int j=0;j<in[nx].size();j++)
	if(pos==in[nx][j]){
	  in[nx].erase(in[nx].begin()+j);
	  break;
	}
      out[pos].erase(out[pos].begin()+i);
      i--;
    }
  }
  for(int i=0;i<V;i++)
    if(in[i].size()||out[i].size())
      res.clear();
  return res;
}

int main(){
  int v,e,s,t;
  cin>>v>>e;
  for(int i=0;i<e;i++){
    cin>>s>>t;
    G[s].push_back(t);
  }
  init(v);
  vector<int> ans=Topological_Sort(v);
  for(int i=0;i<ans.size();i++)
    cout<<ans[i]<<endl;
  return 0;
}

Measured memory_bytes: 4884
#include <stdio.h>

int main(void)
{
  int m,f,r;

  while(1){
    
    scanf("%d %d %d",&m,&f,&r);
    
    if(m==-1 && f==-1 && r==-1){
      break;
    }

    if(m==-1 || f==-1 || m+f<30){
      printf("F\n");
    }
    else  if(m+f>=80){
      printf("A\n");
    }
    else if(m+f>=65 && m+f<80){
      printf("B\n");
    }
    else if(m+f>=50 && m+f<65){
      printf("C\n");
    }
    else if(m+f>=30 && m+f<50){
      if(r>=50){
	printf("C\n");
      }
      else{
      printf("D\n");
      }
    }
    
  }
  
    return 0;
  
}

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

int main() {
    string s;
    cin >> s;
    for (int n = s.size() - 1; n > 1; n--) {
        if (n & 1 == 1) continue;
        string t = s.substr(0, n);
        string t1 = t.substr(0, n / 2);
        string t2 = t.substr(n / 2);
        if (t1 == t2) {
            cout << n << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int[] A = nextIntArray(sc, N);
		sc.close();

		HashMap<Integer, Integer> m = new HashMap<>();
		for (int i = 0; i < N; i++) {
			int v = 0;
			if (m.containsKey(A[i])) {
				v = m.get(A[i]);
			}
			v++;
			m.put(A[i], v);
		}

		List<int[]> l = m.entrySet().stream()
				.filter(i -> (i.getValue() >= 2))
				.sorted((e1, e2) -> Integer.compare(e2.getKey(), e1.getKey()))
				.map(e -> new int[] { e.getKey(), e.getValue() })
				.collect(Collectors.toList());

		long ans;

		if (l.size() == 0) {
			ans = 0;
		} else if (l.get(0)[1] >= 4) {
			ans = (long)l.get(0)[0] * l.get(0)[0];
		} else if (l.size() == 1) {
			ans = 0;
		} else {
			ans = (long)l.get(0)[0] * l.get(1)[0];
		}

		out.println(ans);

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray1origin(Scanner sc, int n) {
		int[] result = new int[n + 1];
		for (int i = 1; i <= n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}

}


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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

vector<pair<long long, long long>> prime_factorize(long long N)
{
    vector<pair<long long, long long>> res;
    for (long long a = 2; a * a <= N; ++a)
    {
        if (N % a != 0)
            continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0)
        {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1)
        res.push_back({N, 1});
    return res;
}

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

    ll A,B;
    string S;
    cin >> A>>B;

    ll C = gcd(A, B);

    const auto &res = prime_factorize(C);

    cout << res.size() + 1 << endl;

}


Measured memory_bytes: 3648
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;
#define N 200000 + 5

int n, A[N], F[N];
LL k, l, r;

bool Check(LL x)
{
	LL t = 0;
	for (int i = 1; i <= n; i ++)
	{
		t += max(0LL, A[i] - x / F[i]);
		if (t > k)
			return false;
	}
	return true;
}

int main()
{
	scanf("%d%lld", &n, &k);
	for (int i = 1; i <= n; i ++)
		scanf("%d", A + i);
	for (int i = 1; i <= n; i ++)
		scanf("%d", F + i);
	sort(A + 1, A + n + 1);
	sort(F + 1, F + n + 1);
	reverse(F + 1, F + n + 1);
	for (int i = 1; i <= n; i ++)
		r = max(r, 1LL * A[i] * F[i]);
	while (l < r)
	{
		LL mid = l + r >> 1;
		if (Check(mid))
			r = mid;
		else l = mid + 1;
	}
	printf("%lld\n", l);
	return 0;
}

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    string s; cin >> s;
    if (s[2] == s[3] && s[4] == s[5]) cout << "Yes" << '\n';
    else cout << "No" << '\n';   
    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;
vector<int> w;
vector<int> seen;
int r1,r2;
void dfs(const Graph &G,int v,int co){

    seen[v]=co;
    co++;
    w.push_back(v);
    for(auto nv:G[v]){
        if(seen[nv]!=-1) {
            r1=seen[nv];
            r2=co;
            break;
            
        }
        dfs(G,nv,co);
    }
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int N,K;
    cin>>N>>K;
    int A[N];
    Graph G(N);
    rep(i,N) {
        cin>>A[i];
        A[i]--;
        G[i].push_back(A[i]);
    }
    seen.assign(N,-1);
    dfs(G,0,0);
    int ans;
    if(K<r2) {
        ans=w[K];
    }else{
        int r=r2-r1;
        int p=(K-r1)%r;
        ans=w[r1+p];
    }
    cout << ans+1 << endl;




}


Measured memory_bytes: 31136
//sieu nhan
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define inp "test.inp"
#define out "test.out"
#define oo 100005
#define inf 1e15
#define mod 1000000007
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define y1 hungdzno1
int n,m,res;
vector<vector<int> >ke;
vector<int> f;
void nhap(){
	cin>>n>>m;
	ke.resize(n);
	for(int i=0;i<m;++i){
		int a,b;
		cin>>a>>b;
		--a;
		--b;
		ke[a].pb(b);
	}
}
int dfs(int v){
	if(f[v]!=-1) return f[v];
	f[v]=0;
	for(int i=0;i<ke[v].size();++i){
		int u=ke[v][i];
		f[v]=max(f[v],dfs(u)+1);
	}
	return f[v];
}
void xuly(){
  for(int i=0;i<n;++i) f.push_back(-1);
	for(int i=0;i<n;i++) res=max(res,dfs(i));
	cout<<res;
}
main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  //freopen(inp,"r",stdin);
  //freopen(out,"w",stdout);
  nhap();
  xuly();
}


Measured memory_bytes: 8692
#include <iostream>
#include <cstring>

using namespace std;

int change(char a[10])
{
	int x = 0;
	
	for(int i = 0; i < strlen(a); i++){
		if(a[i] == 'm'){
			if(i == 0){
				x += 1000;
			}
			else{
				x += (a[i - 1] - '0') * 1000;
			}
		}
		
		if(a[i] == 'c'){
			if(i == 0 || a[i - 1] == 'm'){
				x += 100;
			}
			else{
				x += (a[i - 1] - '0') * 100;
			}
		}
		
		if(a[i] == 'x'){
			if(i == 0 || a[i - 1] == 'm' || a[i - 1] == 'c'){
				x += 10;
			}
			else{
				x += (a[i - 1] - '0') * 10;
			}
		}
		
		if(a[i] == 'i'){
			if(i == 0 || a[i - 1] == 'm' || a[i - 1] == 'c' || a[i - 1] == 'x'){
				x += 1;
			}
			else{
				x += a[i - 1] - '0';
			}
		}
	}
	return x;
}

void out(int ans)
{
	int m, c, x, i;
	m = ans / 1000;
	c = (ans - m * 1000) / 100;
	x = (ans - m * 1000 - c * 100) / 10;
	i = ans - m * 1000 - c * 100 - x * 10;
	
	if(m == 1) cout << "m";
	if(m - 1 > 0) cout << m << "m";
	
	if(c == 1) cout << "c";
	if(c - 1 > 0) cout << c << "c";
	
	if(x == 1) cout << "x";
	if(x - 1 > 0) cout << x << "x";
	
	if(i == 1) cout << "i";
	if(i - 1 > 0) cout << i << "i";
	
	cout << endl;
}

int main()
{
	int n;
	char a[10], b[10];
	
	cin >> n;
	while(n--){
		cin >> a;
		cin >> b;
		
		out(change(a) + change(b));
	}
	
	return 0;
}

Measured memory_bytes: 1168
#include<iostream>
using namespace std;
static const int MAX_N=10e2;
int a[MAX_N];
int main(void){
	int N;
		cin >> N;
	for(int i=0;i<N;i++)
		cin >> a[i];
	
	int ans=0;
	while(1){
		bool c=true;
		int cou=0;
		for(int i=0;i<N;i++){
			if(a[i]>0){
				a[i]--;
				if(c){
					ans++;
					c=false;
				}
			}
			else{
				c=true;
				cou++;
			}
		}
		if(cou==N)
			break;
	}
	cout << ans << endl;
}

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    vector<ll> as(n);
    for(int i=0; i<n; i++) cin >> as.at(i);

    ll sun = 0;
    for(auto a : as) sun += a;

    ll prea = 0;
    for(auto &a : as)
    {
        a += prea;
        prea = a;
    }

    ll nea = 0;
    for(auto a : as)
    {
        if(abs(2*a - sun) < abs(sun - nea)) nea = 2*a;
    }
    cout << abs(sun - nea) << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#define ll long long

using namespace std;

ll gcd(ll a, ll b) {
    ll  tmp, r;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  } else if (a==b) {
      return a;
  }
 
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }

  return b;
}

int main(void) {
    ll n;
    ll a[200000];
    scanf("%lld", &n);
    for (ll i=0; i<n; i++) {
        scanf("%lld", &a[i]);
    }

    ll ans = 10000000000;
    ll dummy;

    for (ll i=0; i<n-1; i++) {
        dummy = gcd(a[i], a[i+1]);
        ans = min(ans, dummy);
    }
    if (n>=2) {
        printf("%lld\n", ans);
    }else {
        printf("%lld\n", a[0]);
    }

}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	char buf[4];

	scanf("%s",buf);

	int ans = 700;
	for(int i = 0; i < 3; i++){

		if(buf[i] == 'o'){

			ans += 100;
		}
	}

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

	return 0;
}


Measured memory_bytes: 3836
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

#define UTIL_SWAP(x, y)                                                                                                                    \
  do {                                                                                                                                     \
    typeof(x) _a = x;                                                                                                                      \
    x = y;                                                                                                                                 \
    y = _a;                                                                                                                                \
  } while (0)

#define UTIL_MAX(x, y) ((x) < (y) ? (y) : (x))

static int64_t left_node_value(int64_t arr[], int32_t index, size_t len)
{
  if ((index * 2) <= len) {
    return arr[index * 2 - 1];
  } else {
    return INT64_MIN;
  }
}

static int64_t right_node_value(int64_t arr[], int32_t index, size_t len)
{
  if (((index * 2) + 1) <= len) {
    return arr[(index * 2) + 1 - 1];
  } else {
    return INT64_MIN;
  }
}

static void max_heapfy(int64_t arr[], size_t len, int32_t index)
{
  int64_t current = arr[index - 1];
  int64_t left = left_node_value(arr, index, len);
  int64_t right = right_node_value(arr, index, len);

  int32_t max = UTIL_MAX(current, UTIL_MAX(left, right));
  int32_t not_heapfy_index = index;
  if (max == current) {
    return;
  } else if (max == left) {
    not_heapfy_index = index * 2;
    UTIL_SWAP(arr[index - 1], arr[not_heapfy_index - 1]);
  } else {
    not_heapfy_index = index * 2 + 1;
    UTIL_SWAP(arr[index - 1], arr[not_heapfy_index - 1]);
  }
  max_heapfy(arr, len, not_heapfy_index);
}

void maximum_heap_build(int64_t arr[], size_t len)
{
  int32_t i;
  for (i = (len + 1) / 2; 0 < i; i--) {
    max_heapfy(arr, len, i);
  }
}

#if !defined(TEST)
#include <stdio.h>
int64_t buf[2 ^ 500000];

int32_t main(void)
{
  int32_t num;
  scanf("%d", &num);

  uint32_t i;
  for (i = 0; i < num; i++) {
    scanf("%ld", &buf[i]);
  }

  maximum_heap_build(buf, num);

  for (i = 0; i < num; i++) {
    printf(" %ld", buf[i]);
  }
  printf("\n");

  return 0;
}
#endif

Measured memory_bytes: 4504
#include <bits/stdc++.h>
#define ll long long
#define REP(i, n) for (ll (i) = 0; (i) < (n); (i)++)
#define REPI(i, a, b) for (ll (i) = (a); (i) < (b); (i)++)
#define int long long
using namespace std;
using P = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;

signed main() {
  string s;
  cin >> s;
  cout << s[0] << s.size() - 2 << s[s.size() -1] << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int rows, cols, i, j;
    while(1){
    scanf("%d %d",&rows,&cols);
     if(rows==0 && cols==0){
                break;
    }
    for(i=1; i<=rows; i++){
        for(j=1; j<=cols; j++){
            if((i+j) % 2==0){
                printf("#");
            }
            else{
                printf(".");
            }
        }
        printf("\n");
    }
    printf("\n");
}
    return 0;
}


Measured memory_bytes: 2036
X, N = map(int, input().split())
P = list(map(int, input().split()))
ans = 1000
ans_abs = 10000
for i in reversed(range(0, 102)):
    inP = False
    for p in P:
        if p == i:
            inP = True
            break
    if not inP:
        i_abs = abs(i - X)
        if ans_abs >= i_abs:
            ans = i
            ans_abs = i_abs

print(ans)

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

typedef long long ll;

typedef pair<int, pair<int, int> > p;

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

    int N, M;
    cin >> N >> M;

    vector<vector<int> > s(N);

    for(int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        s[a].push_back(b);
        s[b].push_back(a);
    }

    bool checker = false;

    for(int i = 0; i < s[0].size(); i++) {
        for(int j = 0; j < s[s[0][i]].size(); j++) {
            if(s[s[0][i]][j] == N - 1) {
                checker = true;
                break;
            }
        }
        if(checker) break;
    }

    if(checker) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 12016
n,k = list(map(int,input().split()))
d = []
res = []
c = 0

for i in range(k):
    a = []
    d = int(input())
    a = list(map(int,input().split()))
    
    for j in a:
        if (j in res) == False:
            res.append(j)

for i in range(n):
    if ((i+1) in res) == False:
        c += 1

print(c)
            
        



Measured memory_bytes: 9136
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
using namespace std;
int main()
{
ll x;
cin>>x;
if(x==0)
{
cout<<0<<" "<<0<<endl;
}
else
{
map<int,int> mp;
ll k=1;
ll mxn=10000000000000;
ll fn,sn;
while(k*k*k*k*k<=mxn)
{
mp[abs(k*k*k*k*k)]=k;
if(k*k*k*k*k==x)
{
fn=k;
sn=0;
break;
}
if(mp[abs(x-k*k*k*k*k)]>0)
{
fn=k;
sn=mp[abs(x-k*k*k*k*k)];
if(x-k*k*k*k*k>=0)
{
sn*=-1;
}
break;
}
k++;
}
cout<<fn<<" "<<sn<<endl;
}
}


Measured memory_bytes: 3600
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>

using namespace std;

main(){
  int flag[3][200] = {{0},{0}};
  int p[3][200] = {{0},{0}};
  int n;
  scanf("%d", &n);
  for(int i = 0; i < n; i++){
    scanf("%d%d%d", &p[0][i], &p[1][i], &p[2][i]);
    flag[0][p[0][i]]++;
    flag[1][p[1][i]]++;
    flag[2][p[2][i]]++;
  }
  int ans = 0;
  for(int i = 0; i < n; i++){
    ans = 0;
    if(flag[0][p[0][i]] < 2)
      ans += p[0][i];
    if(flag[1][p[1][i]] < 2)
      ans += p[1][i];
    if(flag[2][p[2][i]] < 2)
      ans += p[2][i];
    printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 1192
#!/usr/bin/env python3
import sys 

# input
a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]

# calc
f = [[0 for _ in range(3)] for _ in range(3)]
for i in range(3):
    for j in range(3):
        if a[i][j] in b:
            f[i][j] = 1 

for i in range(3):
    s = 0 
    u = 0 
    for j in range(3):
        s += f[i][j]
        u += f[j][i]
    if s == 3 or u == 3:
        print('Yes')
        sys.exit()

if f[0][0] + f[1][1] + f[2][2] == 3 or f[0][2] + f[1][1] + f[2][0] == 3:
    print('Yes')
    sys.exit()

print('No')

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

string str;

int main(){
  while( getline(cin,str) ){
    if( str[0] == '.' ) break;

    stack<char> st;

    for(int i=0;i<(int)str.size();i++){
      if( str[i] == '(' || str[i] == '[' ){
	st.push( str[i] );
      } else if( str[i] == ')' ){
	if( st.empty() ) {
	  st.push(str[i]); break;
	}
	if( st.top() == '(' ) st.pop();
	else break;
      } else if( str[i] == ']' ){
	if( st.empty() ) {
	  st.push(str[i]); break;
	}
	if( st.top() == '[' ) st.pop();
	else break;
      }
    }

    if( st.empty() ) cout << "yes" << endl;
    else cout << "no" << endl;

  }
}

Measured memory_bytes: 1172
#include <cstdio>
#include <vector>

using namespace std;

int n,m;
vector<int> io;

main(){
  while(1){
    scanf("%d", &n);
    if(n == 0) break;

    scanf("%d", &m);
    char t;
    int b = 0;
    char x = 1;
    while(m--){
      scanf(" %c ", &t);
      if(t == 'I' && x == 1){
	x *= -1;
	b++;
      }else if(t == 'O' && x == -1){
	x *= -1;
	b++;
      }else if(t == 'I'){
	io.push_back((b-1)/2);
	b = 1;
	x = -1;
      }else {
	io.push_back((b-1)/2);
	b = 0;
	x = 1;
      }
    }
    io.push_back((b-1)/2);
    
    int r = 0;
    for(vector<int>::iterator it = io.begin(); it != io.end(); it++){
      int k = *it;
      if (k >= n) r += (k-n+1);
    }

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

    io.clear();
  }
}
    
	   

Measured memory_bytes: 872
use proconio::input;
use proconio::marker::Usize1;
use std::cmp::{max, min};
use im_rc::{vector, Vector};

type QT = (usize, usize, u64, u64);

fn main() {
    input! {
        n: usize,
        m: u64,
        q: usize,
        arr: [(Usize1, Usize1, u64, u64); q],
    }

    let mut solve = Solve {
        n,
        m,
        q,
        arr,
        ans: 0,
    };
    solve.solve();
}

struct Solve {
    n: usize,
    m: u64,
    q: usize,
    arr: Vec<QT>,
    ans: u64,
}

impl Solve {
    fn solve(&mut self) {
        self.dfs(vector![]);
        let ans = self.ans;
        println!("{}", ans);
    }

    fn dfs(&mut self, v: Vector<u64>) {
        if v.len() == self.n {
            let c = self.calc(&v);
            self.ans = max(self.ans, c);
            return;
        }

        let last = match v.last() {
            Some(x) => *x,
            None => 1,
        };

        for next in last..=self.m {
            let mut u = v.clone();
            u.push_back(next);
            self.dfs(u);
        }
    }

    fn calc(&self, v: &Vector<u64>) -> u64 {
        let mut ret = 0u64;
        for &(a, b, c, d) in &self.arr {
            if v[b] - v[a] == c {
                ret += d;
            }
        }

        ret
    }
}


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

int main()
{
  int  n = 0;
  cin >> n;
  bool flag = false;

  for(int i = 1;i <= 9;i++){
    for(int j = 0;j <= 9;j++){
      if(i * j == n){
        flag = true;
        break;
      }
    }
  }

  if(flag){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/02/27  Problem: ABC 114 D / Link: http://abc114.contest.atcoder.jp/tasks/abc114_d  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL ans = 0LL;

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

	LL N;
	cin >> N;
	map<int, int>Prime;
	FOR(i, 1, N + 1) {
		LL x = i;
		FOR(d, 2, i + 1) {
			while (x%d == 0) {
				Prime[d]++;
				x /= d;
			}
		}
	}
	VI pidx;
	for (auto it : Prime) {
		pidx.push_back(it.first);
	}

	map<LL, LL>dp;
	dp[1] = 1;
	for (auto it : Prime) {
		map<LL, LL>nx = dp;
		for (auto odp : dp) {
			FOR(k, 1, it.second + 1) {
				if (odp.first*(k + 1) <= 75)
					nx[odp.first*(k + 1)] += odp.second;
			}
		}
		nx.swap(dp);
	}
	LL ans = dp[75];
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
for e in iter(input,'0 0'):
 w,h=map(int,e.split())
 M=[[[1,0]*2 for _ in[0]*h]for _ in[0]*w]
 for i in range(1,w):
  for j in range(1,h):
   a,b=M[i-1][j][:2]
   c,d=M[i][j-1][2:]
   M[i][j]=[d,a+b,b,c+d]
 print((sum(M[w-2][h-1][:2])+sum(M[w-1][h-2][2:]))%10**5)


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

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define fcin ios::sync_with_stdio(false); cin.tie(nullptr);
#define INF 0x3f3f3f3f
#define all(x) x.begin(), x.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

template <typename A, typename B>
string to_string(pair<A, B> p){
    return "(" + to_string(p.fi) + ", " + to_string(p.se) + ")";
}

template <typename T>
string to_string(T v){
    string s = "{";
    bool first = true;
    for(const auto & x : v){
        if(!first) s += ", ";
        first = false;
        s += to_string(x);
    }
    return s + "}";
}

void debug_out(){ cerr << endl;}
template <typename First, typename... Next>
void debug_out(First F, Next... N){
    cerr << " " << to_string(F);
    debug_out(N...);
}

#ifdef LOCAL
    #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 1
#endif

int m[3][3], mark[3][3];

int main(){
    fcin;
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            cin >> m[i][j];
        }
    }
    int q;
    cin >> q;

    bool ok = false;
    while(q--){
        int x;  cin >> x;
        
        for(int i = 0; i < 3; i++){
            for(int j = 0; j < 3; j++){
                if(m[i][j] == x) mark[i][j] = 1;
            }
        }

        for(int i = 0; i < 3; i++){
            if(mark[i][0] and mark[i][1] and mark[i][2]) ok = true;
            if(mark[0][i] and mark[1][i] and mark[2][i]) ok = true;
        }

        if(mark[0][0] and mark[1][1] and mark[2][2]) ok = true;
        if(mark[0][2] and mark[1][1] and mark[2][0]) ok = true;
    }

    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}



Measured memory_bytes: 256
def main():
    n,k = map(int,input().split())
    ans = 0
    if k%2==0:
        kouho1 = []
        kouho2 = []
        for i in range(1,n+1):
            if i%k==0:
                kouho1.append(i)
            elif i%k == k/2:
                kouho2.append(i)
        ans += len(kouho1)**3
        ans+= len(kouho2)**3
    else:
        kouho = []
        for i in range(1,n+1):
            if i%k==0:
                kouho.append(i)
        ans += len(kouho)**3

    print(ans)
main()


Measured memory_bytes: 16708
#include<bits/stdc++.h>
#define ll long long
#define mx 1002
#define endl "\n"
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define fi first
#define se second
#define fr(i,a,b) for(int i=a;i<=b;i++  )
#define pii pair<int,int>
using namespace std;
int a[20][20];
int b[20];
int main()
{
    int n,m,c;
    cin>>n>>m>>c;
    fr(i,0,m-1)cin>>b[i];
    fr(i,0,n-1)
        fr(j,0,m-1)
            cin>>a[i][j];
    int tot=0;
    fr(i,0,n-1)
    {
        int x=c;
        fr(j,0,m-1)
            x+=(a[i][j]*b[j]);
        if(x>0)tot++;
    }
    cout<<tot<<endl;
}

Measured memory_bytes: 256
#include <iostream>
      #include <string>
      #include <vector>
      #include <algorithm>
      #include <set>
      using namespace std;
      typedef long long ll;
      #define rep(i,n) for (int i=0;i < (int)(n);i++)
      ll INF = 1LL  << 60;

      ll d[201][201];

      int main(){
        int n,m,r;
        cin >> n >> m >> r;
        vector<int> per(r);
        rep(i,r) cin >> per[i];
        rep(i,n) rep(j,n) { 
          if (i == j) d[i][j] = 0;
          else d[i][j] = INF;
         }
        rep(i,m){
          int x,y,c;
          cin >> x >> y >> c;
          x--;y--;
          d[x][y] = c;
          d[y][x] = c;
        }
        for (int i = 0;i < n;i++){
          for (int j = 0;j < n;j++){
            for (int k = 0;k < n;k++){
              d[j][k] = min(d[j][k],d[j][i]+d[i][k]);
            }
          }
        }
        //cout << endl;
        sort(per.begin(),per.end());
        ll ans = INF;
        do{
          //rep(i,r){
          //  cout << per[i] << " ";
          //}
          //cout << endl;
          ll cnt = 0;
          for (int i=0;i < r-1;i++){
            cnt+=d[per[i]-1][per[i+1]-1];
          }
          ans = min(ans,cnt);

        }while(next_permutation(per.begin(),per.end()));
        
        cout << ans << endl;
        
        return 0;

        
      }
        
        

Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
int a[100004];
int main()
{
	ll b=0,c=0,h=0;
	int n;
	int m[5]={0};
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a,a+n);
	for(int i=n-1;i>=0;i--)
	{
		if(a[i]==a[i-1])
		{
			i--;
				b=a[i];
				c++;
				if(c==1)
				h=b;
				
		}
		if(c==2)
		{
			printf("%lld\n",h*b);
				break;
		}
	
	}
if(c==0)
{
	printf("0\n");

}

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#define rep(i, n) repr((i), 0, (n))
#define repr(i, a, t) reps((i), (a), (t), 1)
#define reps(i, a, t, s) for (long long (i) = (a); (i) < (long long)(t); (i) += (s))
#define rrep(i, n) rrepr((i), (n) - 1, 0)
#define rrepr(i, a, t) rreps((i), (a), (t), 1)
#define rreps(i, a, t, s) for (long long (i) = (a); (i) >= (long long)(t); (i) -= (s))
#define each(v, c) for (auto &&(v) : (c))
using namespace std;
namespace mp = boost::multiprecision;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using ml = mp::cpp_int;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  if (v.empty()) return os << "vector{}";
  os << "vector{" << *v.begin();
  for (auto it = ++v.begin(); it != v.end(); ++it)
    os << ", " << *it;
  return os << "}";
}
template<typename T>
ostream &operator<<(ostream &os, const set<T> &s) {
  if (s.empty()) return os << "set{}";
  os << "set{" << *s.begin();
  for (auto it = ++s.begin(); it != s.end(); ++it)
    os << ", " << *it;
  return os << "}";
}
template<typename S, typename T>
ostream &operator<<(ostream &os, const map<S, T> &m) {
  if (m.empty()) return os << "map{}";
  os << "map{" << (*m.begin()).first << ": " << (*m.begin()).second;
  for (auto it = ++m.begin(); it != m.end(); ++it)
    os << ", " << (*it).first << ": " << (*it).second;
  return os << "}";
}
template<typename S, typename T>
ostream &operator<<(ostream &os, const pair<S, T> &p) {
  return os << "pair{" << p.first << ", " << p.second << "}";
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ifstream ifs;
  if (getenv("LOCAL") != nullptr) {
    ifs.open("src/_in.txt");
    cin.rdbuf(ifs.rdbuf());
  }

  ll N, M;
  cin >> N >> M;
  vector<ll> V(N), W(N);
  rep (i, N) {
    cin >> V[i] >> W[i];
  }
  // 配る
  vector<ll> dp(M + 1);
  rep (i, N) {
    rrep (j, M - W[i] + 1) {
      dp[j + W[i]] = max(dp[j + W[i]], dp[j] + V[i]);
    }
  }
  cout << *max_element(dp.begin(), dp.end()) << "\n";
}




Measured memory_bytes: 3252
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let s: String = read();
    let t: String = read();

    println!("{}{}", t, s);
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
import sys
s = list(input())
if list(set(s)) == ["x"]:
    print(0)
    sys.exit()
t = [i for i in s if i != "x"]
n = len(t)
if "".join(t) != "".join(t[::-1]):
    print(-1)
else:
    dic = {}
    cnt = 0
    if n % 2 == 0:
        for j in range(len(s)):
            if s[j] != "x":
                cnt += 1
                if cnt == n//2:
                    a = s[:j+1]
                    a = a[::-1]
                if cnt == n//2 + 1:
                    b = s[j:]
                    break
        c = 0
        fa = []
        fb = []
        for k in range(len(a)):
            if a[k] == "x":
                c += 1
            else:
                fa.append(c)
                c = 0
        fa.append(c)
        c = 0
        for p in range(len(b)):
            if b[p] == "x":
                c += 1
            else:
                fb.append(c)
                c = 0
        fb.append(c)
        ans = 0
        for q in range(len(fa)):
            ans += max(fa[q],fb[q]) - min(fa[q],fb[q])
        print(ans)
    else:
        for j in range(len(s)):
            if s[j] != "x":
                cnt += 1
                if cnt == int(n/2) + 1:
                    a = s[:j+1]
                    a = a[::-1]
                    b = s[j:]
                    break
        c = 0
        fa = []
        fb = []
        for k in range(len(a)):
            if a[k] == "x":
                c += 1
            else:
                fa.append(c)
                c = 0
        fa.append(c)
        c = 0
        for p in range(len(b)):
            if b[p] == "x":
                c += 1
            else:
                fb.append(c)
                c = 0
        fb.append(c)
        ans = 0
        for q in range(len(fa)):
            ans += max(fa[q],fb[q]) - min(fa[q],fb[q])
        print(ans)

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

string S = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
    int n;
    while (cin >> n, n) {
        vector<int> t(n);
        rep(i, n) cin >> t[i];
        string s; cin >> s;

        string ans = s;

        int p = 0;
        rep(i, s.size()) {

            int idx=0;
            if ('a' <= s[i] && s[i] <= 'z') idx=s[i]-'a';
            if ('A' <= s[i] && s[i] <= 'Z') idx=s[i]-'A' + 26;

            int ttt = idx - t[p];
            if (ttt < 0) ttt += S.size();

            ans[i] = S[ ttt ];

            p = (p + 1) % n;
        }

        cout << ans << endl;
    }
}

Measured memory_bytes: 3180
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

long long chmax(long long a, long long b){
    if(a < b) return b;
    return a;
}

int main() {
    int i, j;
    int n, max_w;
    long long w[110] = {0};
    long long v[110] = {0};
    long long dp[110][100100] = {0};
    long long ans;
    
    scanf("%d%d", &n, &max_w);
    for(i = 0; i < n; i++){
        scanf("%lld%lld", &w[i], &v[i]);
    }
    for(i = 0; i < n; i++){
        for(j = 0; j <= max_w; j++){
            if(j >= w[i]){
                dp[i+1][j] = chmax(dp[i+1][j], dp[i][j-w[i]] + v[i]);
            }
            dp[i+1][j] = chmax(dp[i+1][j], dp[i][j]);
        }
    }
    
    printf("%lld\n", dp[n][max_w]);

    return 0;
}


Measured memory_bytes: 86144
import bisect
N = int(input())
Ls = list(map(int, input().split()))
Ls.sort()

# O(N^2 * logN)の全探索で解く
ans = 0
for a_i in range(N):
    for b_i in range(a_i+1, N):
        c_i = bisect.bisect_left(Ls, Ls[a_i]+Ls[b_i])
        if c_i > b_i:
            ans += c_i - b_i - 1
        else:
            pass
print(ans)

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

using namespace std;

typedef long long ll;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int a, b;
    cin >> a >> b;
    if (a <= 0 && b >= 0) {
        cout << "Zero";
        return 0;
    }
    int l = a;
    int r = min(-1, b);
    if (l <= r && (r - l) % 2 == 0) {
        cout << "Negative";
    } else {
        cout << "Positive";
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static void solve() {
		String s = in.next();
		int n = s.length();
		int ans = 0;
		for (int i=0; i<n-1; i++) {
			if (s.charAt(i) != s.charAt(i+1)) {
				ans++;
			}
		}
		out.println(ans);
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		solve();
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 14244
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll n, k, s;
    cin >> n >> k >> s;

    vector<ll> ans;
    REP(i, k) ans.push_back(s);
    ll m = 1e9;
    REP(i, n-k) {
        if(s != m) ans.push_back(m);
        else ans.push_back(1);
    }

    REP(i, n) cout << ans[i] << (i==n-1?'\n':' ');

    return 0;
}

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

#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef tuple<ll,ll> Pll;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/10;
const ll MOD = 1e9+7;

ll dp[3010];
ll sum[3010];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;cin>>N;
  string s;cin>>s;
  fill(dp,dp+N,1);
  for(ll i=1;i<N;i++){
    sum[0]=0;
    for(ll j=0;j<N;j++){
      sum[j+1] = (sum[j]+dp[j])%MOD;
    }
    //debugArray(sum,N+1);
    //debugArray(dp,N);
    fill(dp,dp+N,0);
    if(s[i-1]=='<'){
      for(ll j=0;j<N-i;j++){
        dp[j] = (sum[N]-sum[j+1]+MOD)%MOD;
      }
    }else{
      for(ll j=0;j<N-i;j++){
        dp[j] = (sum[j+1]-sum[0]+MOD)%MOD;
      }
    }
  }
  cout<<dp[0]<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//using ll = long long;
using P = pair<int,int>;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n,mi = INF;
	cin >> n;
	for(int i = 1;i * i <= n;i++){
		if(n % i == 0){
			chmin(mi,i + n / i - 2);
		}
	}
	cout << mi << endl;
}

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

int N, col1, col2;
bool meow[100005];
vector<int> V[100005];

void dfs(int x, int p, int col) {
	if (col == 0) col1++;
	else col2++;
	for (int i = 0; i < V[x].size(); i++) if (p != V[x][i]) dfs(V[x][i], x, !col);
}

int main() {
	scanf("%d", &N);
	for (int i = 0; i < N - 1; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		a--;
		b--;
		V[a].push_back(b);
		V[b].push_back(a);
	}
	for (int i = 0; i < N; i++) {
		int leafs = 0;
		for (int j = 0; j < V[i].size(); j++) if (V[V[i][j]].size() == 1) leafs++;
		if (leafs > 1) {
			printf("First\n");
			return 0;
		} else if (leafs == 1) meow[i] = 1;
	}
	for (int i = 0; i < N; i++) {
		int sum = 0;
		for (int j = 0; j < V[i].size(); j++) sum += meow[V[i][j]];
		if (sum == V[i].size() && V[i].size() != 1) {
			printf("First\n");
			return 0;
		}
	}
	dfs(0, -1, 0);
	if (col1 == col2) printf("Second\n");
	else printf("First\n");
}


Measured memory_bytes: 5888
n = int(input())
a = list(map(int,input().split()))

if n % 2 == 0:
    x = n//2
    for i in range(x):print(a[(n-1)-(2*i)])
    for i in range(x):print(a[2*i])
else:
    x = n//2 + 1
    for i in range(x):print(a[(n-1)-(2*i)])
    for i in range(x-1):print(a[(2*i)+1])

Measured memory_bytes: 31020
import functools
import threading
import sys


def main():
    @functools.lru_cache(maxsize=None)
    def solve(n):
        if n == 1:
            return 0
        else:
            return min(
                solve(n - k) + abs(H[n] - H[n - k])
                for k in range(1, K + 1)
                if n - k >= 1
            )

    N, K = [int(x) for x in input().split(" ")]
    H = [None] + [int(x) for x in input().split(" ")]
    print(solve(N))


if __name__ == "__main__":

    sys.setrecursionlimit(1024 * 1024 * 2)
    threading.stack_size(128 * 1024 * 1024 * 2)
    threading.Thread(target=main).start()


Measured memory_bytes: 467944
<?php
$n=trim(fgets(STDIN));
$a=trim(fgets(STDIN));
$b=trim(fgets(STDIN));
$c=trim(fgets(STDIN));
$ans=0;
$i=0;
while($i<$n){
  $d=array($a[$i],$b[$i],$c[$i]);
  $d=array_count_values($d);
  $ans+=count($d)-1;
  ++$i;
}
echo $ans;

Measured memory_bytes: 4856
#include <iostream>

using namespace std;

int main(){

	int n = 0;
	int b[240] = { 0 };
	int f[240] = { 0 };
	int r[240] = { 0 };
	int v[240] = { 0 };
	int map[4][3][10] = { 0 };

	cin >> n;
	
	for (int i = 0; i < n; i++) {

		cin >> b[i] >> f[i] >> r[i] >> v[i];

	}

	for (int i = 0; i < n; i++) {

		map[b[i] - 1][f[i] - 1][r[i] - 1] += v[i];

	}

	for (int i = 0; i < 4; i++) {

		for (int u = 0; u < 3; u++) {

			for (int y = 0; y < 10; y++) {

				cout << " " << map[i][u][y];

			}

			cout << endl;

		}

		if (i != 3) {

			cout << "####################" << endl;

		}

	}

	return 0;

}



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

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;



int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	int n, m;
	cin >> n >> m;
	while (m--) {
		int a;
		cin >> a;
		n -= a;
	}

	if (n < 0) cout << -1 << endl;
	else cout << n << endl;

	return 0;
}


Measured memory_bytes: 3656
A , B = [int(i) for i in input().split()]

if B>A:    
    if (B-A)%2==0:
        print(int((B-A)/2+A))
    else:
        print("IMPOSSIBLE")
else:
    if (A-B)%2==0:
        print(int((A-B)/2+B))
    else:
        print("IMPOSSIBLE")

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int n,q;
class Potentialized_UnionFind{
private:
	vector<int> p,r;
	vector<ll> diff_weight;
public:
	Potentialized_UnionFind(int N){
		p = r = vector<int>(N+1,0);
		diff_weight = vector<ll>(N+1,0);
		for(int i=1;i<=N;i++){
			p[i] = i;
			diff_weight[i] = 0;
			r[i] = 0;
		}
	}
	int root(int a){
		if(p[a] == a) return a;
		else{
			int r = root(p[a]);
			diff_weight[a] += diff_weight[p[a]];
			return (p[a] = r);
		}
	}
	bool is_same_set(int a,int b){
		return root(a) == root(b);
	}
	ll weight(int a){
		root(a);
		return diff_weight[a];
	}
	ll diff(int a, int b){
		return weight(b) - weight(a);
	}
	void unite(int a, int b, int w){
		w += weight(a);
		w -= weight(b);
		a = root(a);
		b = root(b);
		if(a==b) return;
		if(r[a]<r[b]){
			int t = a;
			a = b;
			b = t;
			w = -w;
		}
		if(r[a] == r[b]) r[a]++;
		p[b] = a;
		diff_weight[b] = w;
	}
};

int main(){
	while(cin >> n >> q && n>0){
		Potentialized_UnionFind uf(n);
		for(int i=0;i<q;i++){
			char c;
			ll w,a,b;
			cin >> c;
			if(c=='!'){
				cin >> a >> b >> w;
				uf.unite(a,b,w);
			}else{
				cin >> a >> b;
				if(uf.is_same_set(a,b)) cout << uf.diff(a,b) << endl;
				else cout << "UNKNOWN" << endl;
			}
		}
	}
}


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

int main()
{
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, N) cin >> a.at(i);
    sort(a.begin(), a.end(), greater<int>());
    int ans = 0;
    rep(i, N)
    {
        if (i%2==0) ans += a.at(i);
        else ans -= a.at(i);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
from fractions import gcd
N,X=map(int,input().split())
x=list(map(int,input().split()))
for i in range(N):
    if abs(x[i]-X)==0:
        continue
    x[i]=abs(x[i]-X)

ans=x[0]
for i in range(N):
    ans=gcd(ans,x[i])
print(ans)


Measured memory_bytes: 88172
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;
import java.lang.Math;

class Graph {
	private int totalVertex;
	//adjMatrix[u][v] = 1 if there is an edge from u to v, otherwise 0
	private int[][] adjMatrix;
	//adjWeight[u][v] -- the weight of the edge from u to v if there is one
	private int[][] adjWeight;
	//if a node is settled (e.g., processed in the Dijkstra's algorithm)
	private Boolean[] ifSettled;
	int[] distances;
	public Graph() { 
		totalVertex = 0;
	}
	public int getTotalVertex() { return totalVertex; }
	//load graph from standard input
	public void loadAdjMatrix() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjMatrix = new int[totalVertex][totalVertex];
		adjWeight = new int[totalVertex][totalVertex];
		ifSettled = new Boolean[totalVertex];
		distances = new int[totalVertex];
		distances[0] = 0;
		for(int i = 1; i < totalVertex; i++) {
			distances[i] = Integer.MAX_VALUE;
		}
		int i, j;
		for(i = 0; i < totalVertex; i ++) {
			ifSettled[i] = false;
			for(j = 0; j < totalVertex; j ++) {
				adjMatrix[i][j] = adjWeight[i][j] = 0;
			}
		}
		int u, v;
		for(i = 0; i < totalVertex; i ++) {
			u = in.nextInt();
			int degree = in.nextInt();
			for(j = 0; j < degree; j ++) {
				v = in.nextInt(); 
				adjMatrix[u][v] = 1;
				adjWeight[u][v] = in.nextInt();
			}	
		}
		in.close();
	}
	//return weight of the edge from u to v if there is one
	public int getWeight(int u, int v) {
		return adjWeight[u][v];
	}
	//return neighbors of u as a LinkedList
	public LinkedList<Integer> getNeighbors(int u) {
		LinkedList<Integer> tmp = new LinkedList<Integer>();
		for(int v = 0; v < totalVertex; v ++) {
			if(adjMatrix[u][v] == 1) tmp.add(v);
		}
		return tmp;
	}
	//return unsettled neighbors of u as a LinkedList
	public LinkedList<Integer> getUnsettledNeighbors(int u) {
		LinkedList<Integer> tmp = new LinkedList<Integer>();
		for(int v = 0; v < totalVertex; v ++) {
			if((adjMatrix[u][v] == 1) && (ifSettled[v] == false)) tmp.add(v);
		}
		return tmp;
	}
	//return the unsettled node that has the smallest dist
	public int getUnsettledNearest(int[] dist) {
		int md = Integer.MAX_VALUE;
		int mv = -1;
		int v;
		for(v = 0; v < totalVertex; v ++) {
			if((ifSettled[v] == false) && (dist[v] < md)) {
				md = dist[v];
				mv = v;
			}
		}
		return mv;
	}
	//implement the following	
	public int[] Dijkstra(int s) {
		LinkedList<Integer> unsettled = new LinkedList<Integer>();
		for(int i = 0; i < totalVertex; i++) {
			unsettled.add(i);
		}
		
		while(!unsettled.isEmpty()){
			int node = this.getUnsettledNearest(distances);
			for(Integer x : this.getUnsettledNeighbors(node)) {
				distances[x] = Math.min(distances[node] + this.getWeight(node, x), distances[x]);
			}
			ifSettled[node] = true;
			unsettled.remove((Integer)node);
		}
		return distances;
	}
}

public class Main {
	public static void main(String[] argv) {
		Graph g = new Graph();
		g.loadAdjMatrix();
		int[] dist = g.Dijkstra(0);
		for(int i = 0; i < g.getTotalVertex(); i ++) {
			System.out.println(i + " " + dist[i]);
		}
	}
}


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

int main() {
  // 入力を受け取る
  int N,A;
  cin >> N;

  A = 1000 - N % 1000;
  if(A == 1000){
    A = 0;
  }
  cout << A << endl;
  
}


Measured memory_bytes: 3644