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

typedef struct {
  int value;              //数字(1~9)
  char shape;              //形(S,H,C,D)
} card;

void BubbleSort(card C[], int N)
{
  int i, j, flag;
  card tmp;

  for(i = 0; i < N; i++){
    flag = 0;
    for(j = N -1; j > i; j--){
      if(C[j].value < C[j-1].value){
        tmp = C[j];
        C[j] = C[j-1];
        C[j-1] = tmp;
        flag = 1;
      }
    }
  }
}

void SelectionSort(card C[], int N)
{
  int i, j, minj;
  card tmp;
  for(i = 0; i < N; i++){
    minj = i;
    for(j = i; j < N; j++){
      if(C[j].value < C[minj].value){
        minj = j;
      }
    }

    if(minj != i){      //iとminjが異なり実際に交換が行われた回数
      tmp = C[i];
      C[i] = C[minj];
      C[minj] = tmp;
    }
  }
}

int main(void)
{
  int n, i, flag = 0;
  card c1[36], c2[36];

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf(" %c%d", &c1[i].shape, &c1[i].value);
  	c2[i] = c1[i];
  }

  BubbleSort(c1 ,n);
  SelectionSort(c2, n);

  for(i = 0; i < n; i++){
      printf("%c%d", c1[i].shape, c1[i].value);
      if(i < n-1){
        printf(" ");
      }
      if(c1[i].shape != c2[i].shape){
        flag++;
      }
  }
  printf("\n");
  printf("Stable\n");

  for(i = 0; i < n; i++){
      printf("%c%d", c2[i].shape, c2[i].value);
      if(i < n-1){
        printf(" ");
      }
  }


  if(flag == 0){
    printf("\n");
    printf("Stable\n");
  }
  else{
    printf("\n");
    printf("Not stable\n");
  }

  return 0;

}



Measured memory_bytes: 2032
#include <stdio.h>
int main()
{
    int num,temp,rem,count=0;
    scanf("%d",&num);
    temp = num;
    while(temp!=0)
    {
        rem = temp%10;
        if(rem==2)
            count++;
        temp/=10;
    }
    printf("%d\n",count);
    return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;
#define MAX_N 100010

ll N;
ll A[MAX_N] = {};
ll B[MAX_N] = {};

signed main()
{
    cin >> N;
    REP(i, N) { cin >> A[i] >> B[i]; }

    ll add = 0;
    for(int i = N-1; i >= 0; --i) {
        if((A[i] + add) % B[i] == 0) { continue; }
        ll tmp = ((A[i] + add) / B[i]) + 1;
        add += (tmp * B[i]) - (A[i] + add);
    }
    printf("%lld\n", add);
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a, b ,c ,d;
    cin >> a >> b >> c >> d;
    while(true){
        c -= b;
        if(c<=0) {
            cout << "Yes" << endl;
            break;
        }
        a -= d;
        if(a<=0){
            cout << "No"<< endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3592
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1e+9+7 //10^9+7
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>=(ll)(b);i--)

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

//グローバル変数

//ライブラリ挿入

int main(){
    //入力
    int N,M;
    cin >> N >> M;
    vector<vector<pair<int,ll>>> dist(N);
    vector<ll> x(N,INF);
    int l,r;
    ll d;
    REP(i,M){
        cin >> l >> r >> d;
        l--;
        r--;
        dist[l].push_back({r,d});
        dist[r].push_back({l,-d});
    }

    //処理
    bool flag=true;
    vector<bool> visited(N,false);
    int cur,next;
    ll x_next;
    queue<int> que;
    REP(i,N){
        if(visited[i]) continue;
        x[i]=0;
        que.push(i);
        while(!que.empty()){
            cur=que.front();
            que.pop();
            visited[cur]=true;
            REP(j,dist[cur].size()){
                next=dist[cur][j].first;
                x_next=x[cur]+dist[cur][j].second;
                if(x[next]==INF){
                    x[next]=x_next;              
                    que.push(next);
                }
                if(x[next]!=INF&&x[next]!=x_next) flag=false;
                if(!flag) break;
            }
            if(!flag) break;
        }
        if(!flag) break;

    }

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

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

public class Main{
    public static void main(String[] args)throws IOException{
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[][] ary=new int[3][n];
        for(int i=0;i<2;i++){
            for(int j=0;j<n;j++){
                ary[i][j]=sc.nextInt();
            }
        }
        sc.close();
        int gt=0;
        for(int i=0;i<n;i++){
            if(ary[0][i]-ary[1][i]>0){
                gt+=ary[0][i]-ary[1][i];
            }
        }
        System.out.println(gt+"\n");
    }
}

Measured memory_bytes: 23764
import java.util.ArrayList;
public class Main {
	public static void main(String args[]){
		ArrayList a=new ArrayList();
		for(int i=1;i<=9;i++){
			for(int j=1;j<=9;j++){
				System.out.printf("%dx%d=%d\n",i,j,i*j);
			}
		}
		
	}
}

Measured memory_bytes: 18068
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;



int main(){
  ll A, B, C, D;
  cin >> A;
  cin >> B;
  cin >> C;
  cin >> D;

  // can be divided by C
  ll hoge = (B/C) - ((A-1)/C);
  // can be divided by D
  ll fuga = (B/D) - ((A-1)/D);
  // can be divided by C&D
  ll kakeru = C*D;
  ll r = D % C;
  while(r!=0){
    D = C;
    C = r;
    r = D % C;
  }
  ll lcm = kakeru / C;
  ll bar = (B/lcm) - ((A-1)/lcm);

  // cout << hoge << endl;
  // cout << fuga << endl;
  // cout << bar << endl;
  cout << (B - A + 1) - (hoge + fuga - bar) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
main()
{
  int x[3]={0,0,0};
  int i,j,k;
  int dumy=0;
  int n=0;

  scanf("%d",&n);
  for(k = 0 ; k < n ; k++)
    {
      scanf("%d%d%d",&x[0],&x[1],&x[2]);
      x[0] = x[0] * x[0];
      x[1] = x[1] * x[1];
      x[2] = x[2] * x[2];
      
      for(i = 0 ; i < 3 ; i++)
	{
	  for(j = i + 1 ; j < 3 ; j++)
	    { 
	      if(x[i] < x[j])
		{
		  dumy = x[i];
		  x[i] = x[j];
		  x[j] = dumy;
		}
	    }
	}

      if(x[0] == x[1] + x[2])
	{
	  printf("YES\n");
	}
      else{
	printf("NO\n");
      }
    }
  return 0;
}

Measured memory_bytes: 0
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll fac(ll a) { return a > 1 ? fac(a - 1) * a : 1; }
int solve(){
  int n,a,b;
  cin >> n >> a >> b;
  vector<int>p(n);
  rep(i,n)cin >> p[i];
  sort(all(p));
  int A = 0,B = 0,C = 0;
  int i = 0;
  while(p[i] <= a){
    A++;
    i++;
  }
  while(p[i] <= b){
    B++;
    i++;
  }
  C = n - i;
  cout << max(min({A,B,C}),0) << endl;
  return 0;
}
int main(){
  ios::sync_with_stdio(false);cin.tie(nullptr);
  solve();
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int N;
main()
{
	cin>>N;
	vector<int>A;
	for(int a;cin>>a;)A.push_back(a);
	while(A.size()>1)
	{
		vector<int>B;
		for(int i=0;i<A.size();i+=2)
		{
			B.push_back(A[i]<A[i+1]?A[i+1]-A[i]:A[i]>A[i+1]?A[i]-A[i+1]:A[i]);
		}
		A=B;
	}
	cout<<A[0]<<endl;
}


Measured memory_bytes: 2292
n = int(input())

A = list(map(int, input().split()))

import collections

C = collections.Counter(A)

D = sorted(list(set(A)))[::-1]

t = 0
s = 0
for i in D:
    if C[i] >= 4 and t == 0:
        print(i ** 2)
        s = 1
        break
    elif C[i] >= 2 and t == 0:
        t = i
    elif C[i] >= 2 and t != 0:
        print(i * t)
        s = 1
        break

if s == 0:
    print(0)

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

int main(){
  int n, W;
  cin >> n >> W;
  int v[n], w[n];
  rep(i,n) cin >> v[i] >> w[i];
  vector<vector<int>> dp(n+1,vector<int>(W+1));
  rep(i,n) {
    rep(j,W+1) {
      if(j > 0) dp[i+1][j] = max({dp[i+1][j],dp[i][j],dp[i+1][j-1]});
      if(j >= w[i]) dp[i+1][j] = max(dp[i+1][j],dp[i][j-w[i]]+v[i]); 
    }
  }
  cout << dp[n][W] << endl;
  return 0;
}


Measured memory_bytes: 6800
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i < n; i ++)
#define rep1(i, n) for (int i=1; i <= n; i ++)
#define _min(x, y) x = min(x, y)
#define _max(x, y) x = max(x, y)
using namespace std;


int main() {
  int n; cin >> n;
  long long ans = 0;
  rep(i, n) {
    ans += i;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	int N;
	cin >> N;
	vector<int> num;
	for(int i=1;i<=9;i++){
		num.push_back(i + i * 10 + i * 100);
	}
	int ans =  *lower_bound(num.begin(), num.end(),N);
	cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
s = input()

curr_change_cnt = min_change_cnt = sum(c == 'E' for c in s[1:])
for i in range(1, n):
    if s[i - 1] == 'W':
        curr_change_cnt += 1

    if s[i] == 'E':
        curr_change_cnt -= 1

    min_change_cnt = min(curr_change_cnt, min_change_cnt)

print(min_change_cnt)


Measured memory_bytes: 3676
#include<bits/stdc++.h>
using namespace std;
int main(){
  int dp[1001][1001];
  for(int i=0;i<1001;i++)
    for(int j=0;j<1001;j++)
      dp[i][j]=2*1e9;
  dp[0][0]=0;
  int n;
  pair<int,int>a[1001];
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i].second>>a[i].first;
  sort(a,a+n);
  for(int i=0;i<n;i++)
    for(int j=0;j<=i;j++){
      int m=dp[i][j]+a[i].second;
      if(m<=a[i].first)dp[i+1][j+1]=min(dp[i+1][j+1],m);
      dp[i+1][j]=min(dp[i][j],dp[i+1][j]);
    }
  int ans;
  for(int i=0;i<=n;i++)
    if(dp[n][i]!=2*1e9)ans=i;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 6988
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define MP make_pair
#define PB push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	vector<vector<bool>> s(14, vector<bool>(14, false));
	int n; cin >> n;
	rep(i, n) {
		char x; int y, z;
		cin >> x >> y;
		switch (x) {
		case 'S':
			z = 0;
			break;
		case 'H':
			z = 1;
			break;
		case 'C':
			z = 2;
			break;
		case 'D':
			z = 3;
			break;
		}
		s[z][y] = true;
	}
	rep(i, 4) {
		for (int j = 1; j <= 13; j++) {
			if (!s[i][j]) {
				char c;
				switch (i) {
				case 0:
					c = 'S';
					break;
				case 1:
					c = 'H';
					break;
				case 2:
					c = 'C';
					break;
				case 3:
					c = 'D';
					break;
				}
				cout << c << " " << j << endl;
			}
		}
	}
}


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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define pll         pair<long,long>
#define vi          vector<int>
#define vll         vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)      (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define mod        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rem(i,a,b)  for(int i=a;i>b;i--)
#define mp(a,b)     make_pair(a,b)
#define vvi(a,b,name)    vector<vector<int>> name(a,vector<int>(b,-1))


void solve(){
    string s;
    cin>>s;
    ll l=s.length();
    rep(i,0,l){
        cout<<s[i];
        i++;
    }

}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 592
#include <string>
#include <iostream>

using namespace std;

int main()
{
	int M[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

	string D[7] = { "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday" };

	int MM = -1, DD = -1, DAYS = -1;

	while (true)
	{
		cin >> MM >> DD;

		if (MM == 0 && DD == 0)
		{
			goto Exit;
		}

		DAYS = 0;

		for (int i = 0; i < (MM - 1); i++)
		{
			DAYS += M[i];
		}

		DAYS += DD;

		cout << D[DAYS % 7] << endl;
	}

Exit:;

	return 0;
}

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

int main(){
  int H, W;
  cin >> H >> W;
  vector<vector<int>> A(H,vector<int>(W)), B = A;
  for(int i = 0; i < H; ++i)
    for(int j = 0; j < W; ++j)
      cin >> A[i][j];
  for(int i = 0; i < H; ++i)
    for(int j = 0; j < W; ++j)
      cin >> B[i][j];
  constexpr const int M = 80*80*2+1, m = 80*80+1;
  vector<bitset<M>> dp(W);
  dp[0][m] = 1;
  for(int i = 0; i < H; ++i){
    vector<bitset<M>> dp_(W);

    for(int j = 0; j < W; ++j){
      int d = abs(A[i][j]-B[i][j]);
      dp_[j] |= dp[j]<<d;
      dp_[j] |= dp[j]>>d;
      if(j > 0){
        dp_[j] |= dp_[j-1]<<d;
        dp_[j] |= dp_[j-1]>>d;
      }
    }
    swap(dp,dp_);
  }
  int ans = 1e9;
  for(int i = 0; i < M; ++i){
    if(dp[W-1][i]){
      ans = min(ans,abs(m-i));
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

typedef long long ll;

using namespace std;

int main(int argc , char *argv[]) {
    int a,b;
    cin >> a >> b;

    cout << (a >= 13 ? b : (a >= 6 ? b/2 : 0));
    return 0;
}

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

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

Measured memory_bytes: 256
#include<cstdio>
#include <utility>
#include <queue>
using P = std::pair<int, int>;
int H, W;
const static int MAX_H = 20, MAX_W = 20;
bool maze[MAX_H][MAX_W];
int ans = 0;
int depth[MAX_H][MAX_W];
int x[4] = {-1, 0, 1, 0};
int y[4] = {0, -1, 0, 1};
bool has_been_visited[MAX_H][MAX_W];

bool is_inside_the_maze(int x, int y){
	return x >= 0 && x < H && y >= 0 && y < W;
}

void Bfs(int start_x, int start_y) {
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j){
			has_been_visited[i][j] = false;
			depth[i][j] = 0;
		}
	}

	std::queue<P> next_vertex_to_visit;
	next_vertex_to_visit.push(std::make_pair(start_x, start_y));
	has_been_visited[start_x][start_y] = true;

	while( !next_vertex_to_visit.empty() ) {
		P u = next_vertex_to_visit.front();
		next_vertex_to_visit.pop();
		for (int i = 0; i < 4; ++i){
			int next_x = u.first + x[i], next_y = u.second + y[i];
			if(is_inside_the_maze(next_x, next_y) && maze[next_x][next_y] && !has_been_visited[next_x][next_y]){
				has_been_visited[next_x][next_y] = true;
				depth[next_x][next_y] = depth[u.first][u.second] + 1;
				if(depth[next_x][next_y] > ans) ans = depth[next_x][next_y];
				next_vertex_to_visit.push(std::make_pair(next_x, next_y));
			}
		}
	}
}


int main(){
	scanf("%d %d", &H, &W);
	for (int i = 0; i < H; ++i){
		scanf("\n");
		for (int j = 0; j < W; ++j){
			char tmp;
			scanf("%c", &tmp);
			maze[i][j] = tmp == '.';
		}
	}
	for (int k = 0; k < H; ++k){
		for (int l = 0; l < W; ++l){
			if(maze[k][l]) Bfs(k, l);
		}
	}
	printf("%d\n", ans);
	return 0;
}

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

#define int long long
const int mod = 1e9 + 7;
int n, dp[1000005], res[1000005], sum, ans;

signed main(){
    cin >> n;
    sum = 2;
    res[0] = res[1] = 1;
    for(int i = 2; i <= n; i++){
        res[i] = (sum - res[i - 2] + mod) % mod;
        sum = (sum + res[i]) % mod;
        dp[i] = ((res[i - 2] * (n - 1)) % mod * (n - 1)) % mod;
        dp[i] = (dp[i] + (res[i - 2] * (n - 1))) % mod;                             
        ans = (ans + dp[i]) % mod;
    }
    ans = (ans + (res[n - 1] * (n - 1))) % mod;
    cout << ans + 1;
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
int solve(int* a,int n,int k){
    int dp[n+1];
    dp[1]=0;
    for(int i=2;i<=n;i++){
        dp[i]=INT_MAX;
        for(int j=i-1;j>=1 && (i-j)<=k;j--){
            dp[i]=min(dp[i],abs(a[i]-a[j])+dp[j]);
        }
    }
    return dp[n];
}
int main(){
    int n,k;
    cin>>n>>k;
    int a[n+1];
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    cout<<solve(a,n,k);
}

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

int main() {
    long long int n, a[200000], b[200000], med, sum = 0;
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    for(int i=0; i<n; i++){
        b[i] = a[i] - (i+1);
    }
    // ソートして中央値を求める
    sort(b, b+n);
    med = b[n/2];

    for(int i=0; i<n; i++){
        sum += abs(b[i] - med);
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int main() {

 int S;
 cin >> S;
 
 int H = S / 3600;
 int M = (S % 3600) / 60 ;
 int s = S % 60;
 cout << H << ":" << M << ":" << s << endl;
}
 
                                    
                                           


  


 



Measured memory_bytes: 3100
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	a=a*pow(10,(int)(log10((double)b)+1))+b;
	for(int i=1;i<=1000;i++)
	{
		if(i*i==a) {
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
 } 

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int isSubset(int arr1[],int arr2[],int m,int n);
int main()
{
    int a[10],i;
    for(i=0;i<9;i++){
        scanf("%d",&a[i]);
    }
    int n;
    scanf("%d",&n);
    int b[n+1];
    for(i=0;i<n;i++){
        scanf("%d",&b[i]);
    }
    int r1[4],r2[4],r3[4];
    int c1[4],c2[4],c3[4];
    int d1[4],d2[4];
    r1[0]=a[0];r1[1]=a[1];r1[2]=a[2];
    r2[0]=a[3];r2[1]=a[4];r2[2]=a[5];
    r3[0]=a[6];r3[1]=a[7];r3[2]=a[8];
    c1[0]=a[0];c1[1]=a[3];c1[2]=a[6];
    c2[0]=a[1];c2[1]=a[4];c2[2]=a[7];
    c3[0]=a[2];c3[1]=a[5];c3[2]=a[8];
    d1[0]=a[0];d1[1]=a[4];d1[2]=a[8];
    d2[0]=a[2];d2[1]=a[4];d2[2]=a[6];



    if(isSubset(b,r1,n,3))printf("Yes");
    else if(isSubset(b,r2,n,3))printf("Yes");
    else if(isSubset(b,r3,n,3))printf("Yes");
    else if(isSubset(b,c1,n,3))printf("Yes");
    else if(isSubset(b,c2,n,3))printf("Yes");
    else if(isSubset(b,c3,n,3))printf("Yes");
    else if(isSubset(b,d1,n,3))printf("Yes");
    else if(isSubset(b,d2,n,3))printf("Yes");
    else printf("No");
    return 0;
}
int isSubset(int arr1[],int arr2[],int m,int n)
{
    int i = 0;
    int j = 0;
    for (i = 0; i < n; i++){
        for (j = 0; j < m; j++){
            if(arr2[i] == arr1[j])
            break;
        }
        if (j == m)return 0;
    }
    return 1;
}


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

int main (void){
    int N;
    cin >> N;
    ll sum = 0;
    for (int i = 1; i <= N; i++) {
        if (i % 3 == 0) continue;
        if (i % 5 == 0) continue;
        sum += i;
    }
    cout << sum << endl;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(long i=0;i<n;i++)
typedef vector<int> vec;
long modpow(long a,long n,long mod){
  long ans=1;
  while (n>0){
    if(n&1) ans=ans*a%mod;
    a=a*a%mod;
    n=n/2;
  }
  return ans; 
}
long modinv(long a,long mod){
  return modpow(a,mod-2,mod);
}

int main(){
  long mod=1000000007;
  long n,a,b,ans,ca,cb;
  cin>>n>>a>>b;
  
  ca=1;cb=1;
  rep(i,a){
    ca=ca*(n-i)%mod;
    ca=ca*modinv(i+1,mod)%mod;
  }
  rep(i,b){
    cb=cb*(n-i)%mod;
    cb=cb*modinv(i+1,mod)%mod;
  }
  ans=(modpow(2,n,mod)-1-ca-cb+3*mod)%mod;

  cout<<ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;
 

ll dpp[53];
ll dp[53];

ll rec(ll level,ll x){
    if(level == 0)return 1;
    if(x<=1)return 0;
    if(x<1+dp[level-1]+1)return rec(level-1,x-1);
    if(x==dp[level-1]+2)return 1+dpp[level-1];
    if(x==dp[level])return dpp[level];
    return dpp[level-1]+1+rec(level-1,x-(2+dp[level-1]));
}

int main(void){
    dp[0]=1;
    dpp[0]=1;
    for(ll i=1;i<=50;i++){
        dp[i]=2*dp[i-1]+3;
        dpp[i]=2*dpp[i-1]+1;
    }
    ll n,x;
    cin>>n>>x;
    cout<<rec(n,x)<<endl;
    return 0;
}

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

#define INF = 10000000;

int main() {
  int N, A, B, C, D, min1 = 0, min2 = 0;
  cin >> N >> A >> B >> C >> D;
  min1 += B*(N/A);
  if(N%A) {
    min1 += B;
  }
  min2 += D*(N/C);
  if(N%C) {
    min2 += D;
  }
  cout << min(min1, min2) << endl;

  return 0;
}


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

using namespace std;

int main(){
  	int A, B, C, X, Y;
  	cin >> A >> B >> C >> X >> Y;
  	long long ans=A*X+B*Y;
  	int many = max(X, Y);
  	
  	for(int i=0;i<=many;i++){
      	long long pay=A*(X-i)+B*(Y-i)+C*2*i;
      	if(X-i<0) pay=B*(Y-i)+C*2*i;
      	if(Y-i<0) pay=A*(X-i)+C*2*i;
      	ans=min(pay, ans);
    }
  	cout << ans << endl;
}

Measured memory_bytes: 3580
import java.util.*;
public class Main{
  	public static void main(String[] args){
      Scanner sc =new Scanner(System.in);
     
      int N=sc.nextInt();
      int a[];
      a=new int[101];
      for (int i=1;i<N+1;i++){
        a[i]=sc.nextInt();
      }
      
      int step=0;
      int m=(N+1)/2;
      int k=0;
      for (int i=1;i<m+1;i++){
        k=2*i-1;
        if(a[k]%2==1){
        step=step+1;
        }
      }
 
      System.out.println(step);
    }
}

Measured memory_bytes: 35944
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		
		int N = in.nextInt();
		int S = in.nextInt();
		
		int[] x = new int[N+1];
		int[] y = new int[N+1];
		
		int min = Integer.MAX_VALUE;
		int key = -1;
		
		for (int i=1;i<=N;i++)
		{
			x[i]= in.nextInt();
			y[i]= Math.abs(x[i] - S);
			
				if ( y[i] < min)
				{
					min = y[i];
					key = i;
				}
		}
		
		
		
		int D=min;
		boolean find = false;
		boolean right = true;
		
		while (D>=1&&!find) {
			right = true;
			for (int i=1;i<=N;i++) {
				if (y[i]%D!=0) {
					D--;
					right = false;
					break;
				}
			}
			if (right) 
				find = true;
		}
		System.out.println(D);
	}
}



Measured memory_bytes: 49468
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <set>
using namespace std;

int main()
{
	int32_t A, B;
	char op;
	cin >> A >> op >> B;

	cout << (op == '+' ? A + B : A - B) << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.awt.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(in);
        String s=sc.next();
        String t=sc.next();
        HashSet<Character> setS=new HashSet<>();
        HashSet<Character> setT=new HashSet<>();
        int loop=s.length();
        int[] x=new int[114514];
        for (int i = 0; i < loop; i++) {
            char p=s.charAt(i);
            char q=t.charAt(i);
            setS.add(p);
            setT.add(q);
            if(setT.size()!=setS.size()){
                out.println("No");
                exit(0);
            }
            if(x[p]==0){
                x[p]=q;
            }else if(x[p]!=q){
                out.println("No");
                exit(0);
            }
            
        }
        out.println("Yes");
    }
    //階乗
static long fact(long a){
    long b=1;
    for (long i = 1; i <= a; i++) {
        b*=i;
    }
    return b;
}
//最大公約数
static int gcd (int a, int b) {
    int temp;
    while((temp = a%b)!=0) {
        a = b;
        b = temp;
    }
    return b;
}
//※最小公倍数はa*b/gcd(a,b)である
//二項係数
static long combi (long a, long b) {
    b=min(a-b,b);
    return permu(a,b)/fact(b);
}
//順列
static long permu(long a,long b){
    long temp=1;
    for (long i =a ; i > a-b; i--) {
        temp*=i;
    }
    return temp;
}
}

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

"""
input:
0 0 2
2 0 2

output:
1.00000000 -1.73205080 1.00000000 1.73205080
"""

import sys
from math import sin, cos, atan2, acos


class Circle(object):
    __slots__ = ('centre', 'radius')

    def __init__(self, centre=float('inf'), radius=-1):
        self.centre = complex(centre)
        self.radius = float(radius)


def arg(p_vector):
    return atan2(p_vector.imag, p_vector.real)


def polar(a, r):
    return cos(r) * a + sin(r) * a * 1j


def get_circles_cross_points(c1, c2):
    centre_distance = abs(c1.centre - c2.centre)
    a = acos((pow(c1.radius, 2) + pow(centre_distance, 2) - pow(c2.radius, 2)) /
             (2 * c1.radius * centre_distance))
    t = arg(c2.centre - c1.centre)
    p1, p2 = c1.centre + polar(c1.radius, t + a), c1.centre + polar(c1.radius, t - a)

    if p1.real < p2.real:
        ans = (p1, p2)
    elif p1.real == p2.real:
        if p1.imag < p2.imag:
            ans = (p1, p2)
        else:
            ans = (p2, p1)
    else:
        ans = (p2, p1)
    return ans


def solve(_circle_info):
    for i, circle in enumerate(_circle_info):
        cx, cy, r = map(int, circle)
        circles[i].centre = cx + cy * 1j
        circles[i].radius = r

    cp1, cp2 = get_circles_cross_points(*circles)
    print('{0:.8f} {1:.8f} {2:.8f} {3:.8f}'.format(cp1.real, cp1.imag, cp2.real, cp2.imag))
    return None


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    circle_info = map(lambda x: x.split(), _input)

    circles = [Circle() for _ in range(2)]
    solve(circle_info)

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

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	string s, t;
	cin >> s >> t;
	mint ans = 1;
	rep(i,n){
		if(s[i] == t[i]){
			if(i == 0) ans *= 3;
			else if(s[i-1] == t[i-1]) ans *= 2;
		}
		else{
			if(i == 0) ans *= 6;
			else{
				if(s[i-1] == t[i-1]) ans *= 2;
				else ans *= 3;
			}
			i++;
		}
	}
	cout << ans.x << endl;
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    vector<int> b(n); for (int i = 0; i < n; i++) cin >> b[i];
    vector<int> ans;
    for (int i = 0; i < n; i++) {
        int k = -1;
        for (int j = 0; j < b.size(); j++) {
            if (j == b[j]-1) k = j;
        }
        if (k == -1) { cout << "-1\n"; return 0; }
        ans.push_back(k);
        b.erase(b.begin() + k);
    }
    for (auto it = ans.rbegin(); it != ans.rend(); it++) cout << 1 + *it << endl;
}


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

#define ll long long
#define ld long double
using namespace std;

vector<ll> a[500000];
vector<ll> res(500000,0);
vector<ll> used(500000,0);

ll dfsforres(ll v){
    used[v] = 1;
    ll answ = 1;
    for (auto i = a[v].begin(); i != a[v].end(); i++){
        if (used[*i] == 0){
            answ += dfsforres(*i);
        }
    }
    res[v] = answ;
    return answ;
}

ll timer = 0;
ll timer2 = 0;
bool r = false;
ll n;
ll verb = 0;

void dfs(ll v){
    used[v] = 1;
//    cout << v << " " << timer << endl;
    if (!r) timer++;
    if (v == n)
        r = true;
    for (auto i = a[v].begin(); i!= a[v].end(); i++){
        if (r) break;
        if (used[*i] == 0 && !r){
            dfs(*i);
        }
    }
    if (!r) timer--;
    else
    {
        timer2++;
        if (timer2 == timer/2){
            verb = v;
        }
    }
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (ll i = 1; i <=n-1 ;i++){
        ll x,y;
        cin >> x >> y;
        a[x].push_back(y);
        a[y].push_back(x);
    }
    dfsforres(1);
    for (ll i = 0; i <= n; i++)
        used[i] = 0;
    dfs(1);
    ll answw = res[verb];
    ll answb = n - answw;
//    cout << answw << " " << answb << endl;
//    cout << verb << endl;
    if (answw >= answb){
        cout << "Snuke" << endl;
    } else
        cout << "Fennec" << endl;
    return 0;
}

Measured memory_bytes: 27648
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
using ll = long long;
#define SENTINEL (1LL << 33)

ll Merge(vector<ll> &A, ll left, ll	mid, ll right) {
	ll n1 = mid - left;
	ll n2 = right - mid;
	vector<ll> L(n1+1,0), R(n2+1,0);
	// left, ..., mid-1
	for(ll i=0; i<n1; ++i){
		L[i] = A[left+i];
	}
	// mid, ..., right-1
	for(ll i=0; i<n2; ++i){
		R[i] = A[mid+i];
	}
	L[n1] = SENTINEL; 
	R[n2] = SENTINEL; 
	ll i, j;
	i = j = 0;
	for (ll k=left; k<right; k++) {
		if (L[i] <= R[j]) {
			A[k] = L[i];
			i++;
		} else {
			A[k] = R[j];
			j++;
		}
	}
	return (right - left);
}

ll MergeSort(vector<ll> &A, ll left, ll right) {
	ll count = 0;
	if (left+1 < right) {
		ll mid = (left + right)/2;
		count += MergeSort(A,left,mid);
		count += MergeSort(A,mid,right);
		count += Merge(A, left, mid, right);
	}
	return count;
}

void print(const vector<ll> &A) {
	for(ll i=0;i<A.size(); ++i){
		if(i!=0) cout << " ";
		cout << A[i];
	}
	cout << endl;
}

int main() {
	ll n;
	cin >> n;
	vector<ll> A(n,0);
	for (ll i=0;i<n;++i) scanf("%lld", &A[i]);
	ll count = MergeSort(A, 0, n);
	print(A);
	cout << count << endl;
	return 0;
}	



Measured memory_bytes: 10720
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647 -> 10桁
// MAX ll 9,223,372,036,854,775,807 -> 19桁
// MAX O(n) 10^18 -> 18回
// double pi = M_PI or acos(-1)
// printf("%.10f\n", ans);

int main() {
    int n, m;
    cin >> n >> m;
    vector<map<string, int>> score(n);
    rep(i, m) {
        int p;
        cin >> p;
        p--; // 0-index
        string word;
        cin >> word;
        if(word == "AC") {
            score[p]["AC"] = 1;
        } else {
            if (score[p]["AC"] != 1) score[p]["WA"]++;
        }
    }

    rep(i, n) {
        if (score[i]["AC"] == 0) score[i]["WA"] = 0;
    }

    map<string, int> ans;
    rep(i, n) {
        ans["AC"] += score[i]["AC"];
        ans["WA"] += score[i]["WA"];
    }

    cout << ans.at("AC") << " " << ans.at("WA") << endl;

    return 0;
}


Measured memory_bytes: 23580
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

//Summer of Phyonkichi
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[][] move = {{-2,-1},{-2,0},{-2,1},{-1,-2},{-1,2},{0,-2},{0,2},{1,-2},{1,2},{2,-1},{2,0},{2,1}};
		while(true){
			int sj = sc.nextInt();
			int si = sc.nextInt();
			if((sj|si)==0)break;
			int n = sc.nextInt();
			int[][] p = new int[n][2];
			for(int i=0;i<n;i++)for(int j=1;j>=0;j--)p[i][j]=sc.nextInt();
			boolean[][][] visited = new boolean[10][10][10];
			List<int[]> l = new ArrayList<int[]>();
			l.add(new int[]{si,sj});
			int step = 0;
			while(!l.isEmpty()&&step<n){
				List<int[]> next = new ArrayList<int[]>();
				for(int[]a:l){
					for(int k=0;k<12;k++){
						int i = a[0]+move[k][0];
						int j = a[1]+move[k][1];
						if(0<=i&&i<10&&0<=j&&j<10&&!visited[i][j][step]){
							boolean f = false;
							for(int c=-1;c<=1;c++){
								for(int b=-1;b<=1;b++){
									int ci = p[step][0]+c;
									int cj = p[step][1]+b;
									if(ci==i&&cj==j){
										f = true;
										break;
									}
								}
							}
							if(f){
								visited[i][j][step] = true;
								next.add(new int[]{i,j});
							}
						}
					}
				}
				step++;
				l = next;
			}
			System.out.println(step==n&&!l.isEmpty()?"OK":"NA");
		}
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>
using namespace std;
#define mod (long)(998244353)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
#define long long long
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr start, itr goal){ for(auto i = start; i != goal; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<long> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } long C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

vector<vector<int>> roads;

int dp[100010];

int move(int now){
    if(dp[now] != -1){
        return dp[now];
    }
    int ans = 0;
    for(int i: roads[now]){
        ans = max(ans, move(i) + 1);
    }
    return dp[now] = ans;
}

int main(){
    int N, M;
    cin >> N >> M;
    roads.resize(N);
    for(int i = 0; i < M; i++){
        int x, y;
        cin >> x >> y;
        roads[x - 1].push_back(y - 1);
    }
    memset(dp, -1, sizeof(dp));
    int ans = 0;
    for(int i = 0; i < N; i++){
        ans = max(ans, move(i));
    }
    cout << ans << endl;
}


Measured memory_bytes: 8192
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

s_a = [0] * (n + 1)
s_b = [0] * (m + 1)
#s_a[0] = a[0]
#s_b[0] = b[0]
for i in range(1, n + 1):
    s_a[i] = s_a[i - 1] + a[i - 1]
for i in range(1, m + 1):
    s_b[i] = s_b[i - 1] + b[i - 1]
    
import bisect
ans = 0
for i in range(n + 1):
    num = s_a[i]
    if k < num:
        continue
    cnt = i
    cnt += bisect.bisect_right(s_b, k - num) - 1
    if ans < cnt:
        ans = cnt
print(ans)

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M, Q;
  cin >> N >> M >> Q;
  int a[M];
  int q[Q];
  for (int i = 0; i < M; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < Q; i++) {
    cin >> q[i];
  }
  int prev[N], next[N];
  int flag[N];
  for (int i = 0; i < N; i++) {
    flag[i] = 1;
    prev[i] = (i - 1 + N) % N;
    next[i] = (i + 1) % N;
  }
  int p = 0;
  for (int i = 0; i < M; i++) {
    if (a[i] % 2 == 0) {
      for (int j = 0; j < a[i]; j++) {
        p = next[p];
      }
    } else {
      for (int j = 0; j < a[i]; j++) {
        p = prev[p];
      }
    }
    flag[p] = 0;
    prev[next[p]] = prev[p];
    next[prev[p]] = next[p];
    p = next[p];
  }
  for (int i = 0; i < Q; i++) {
    cout << flag[q[i]] << "\n";
  }
  return 0;
}


Measured memory_bytes: 6280
#include <stdio.h>
int main(){
int N,K;
  char s[55];
  
  scanf("%d",&N);
  if(N<=50)
  scanf("%d",&K);
  scanf("%s",s);
  
  if('A'==s[K-1]){s[K-1]='a';}else if('B'==s[K-1]){s[K-1]='b';}else{s[K-1]='c';}
  
  printf("%s",s);
  
  return 0;

}

Measured memory_bytes: 128
import bisect

X,N = (int(x) for x in input().split())
P = list(map(int, input().split()))
ALL = list(int(i) for i in range(-100,201))
P.sort()
Q = list(set(P)^set(ALL))
number = bisect.bisect(Q,X)

if number==0:
  print(Q[0])
elif number==len(Q):
  print(Q[len(Q)-1])
elif X-Q[number-1]<=Q[number]-X:
  print(Q[number-1])
elif X-Q[number-1]>Q[number]-X:
  print(Q[number])


Measured memory_bytes: 9100
S = input()
T = input()

SN = len(S)
TN = len(T)

SL = []
for i in range(SN - TN+1):
    SL.append(S[i : TN+i])

C = []
for s in SL:
    tmp = 0
    for t in range(TN):
        if s[t] != T[t]:
            tmp += 1
    C.append(tmp)

print(min(C))


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

void query_print(string &str, int start, int end)
{
  int len = end - start + 1;
  cout << str.substr(start, len) << endl;
}

void query_reverse(string &str, int start, int end)
{
  int len = end - start + 1;
  for (int i = 0; i < len / 2; i++)
  {
    char tmp = str.at(start + i);
    str.at(start + i) = str.at(end - i);
    str.at(end - i) = tmp;
  }
}

void query_replace(string &str, int start, string replace_str)
{
  for (int i = 0; i < replace_str.size(); i++)
  {
    str.at(start + i) = replace_str.at(i);
  }
}

void query(string &str)
{
  string order;
  int start, end;
  cin >> order >> start >> end;

  if (order == "print")
  {
    query_print(str, start, end);
  }
  else if (order == "reverse"s)
  {
    query_reverse(str, start, end);
  }
  else if (order == "replace"s)
  {
    string replace_str;
    cin >> replace_str;
    query_replace(str, start, replace_str);
  }
}

int main()
{
  string str;
  int query_num;
  cin >> str >> query_num;

  for (int i = 0; i < query_num; i++)
  {
    query(str);
  }
}



Measured memory_bytes: 3216
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int N = Integer.parseInt(line);
        for (int i=0; i<N; i++){
            String l = br.readLine();
            Scanner sc = new Scanner(l);
            
            int a[];
            a = new int[3];
            for (int j=0; j<3; j++){
                a[j] = sc.nextInt();
            }
            Arrays.sort(a);
            if ((a[0]*a[0] + a[1]*a[1]) == a[2]*a[2]){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }
        }
    }
}

Measured memory_bytes: 62644
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef pair<double,double> PD;
typedef pair<int,P> ed;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N,K;
  cin >> N >> K;
  vi l(N);
  rep(i,N) {
    cin >> l[i];
  }
  sort(rng(l));
  reverse(rng(l));
  int s = 0;
  rep(i,K) {
    s += l[i];
  }
  cout << s << endl;
  return 0;
}

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

struct Matrix {
	int r,c;
};

long f(vector<Matrix> &m, int begin, int end, vector<vector<long> > &memo) {
	if (m.size() < 2 || (end - begin) < 2) return 0;
	if (memo[begin][end] != -1) {
		return memo[begin][end];
	}
	if ((end - begin) == 2) {
		return memo[begin][end] = m[begin].r * m[begin].c * m[begin+1].c;
	}
	long common = m[begin].r * m[end-1].c;
	long res	= common * m[begin+1].r + f(m,begin+1,end,memo);
	for (int i=2;i<(end-begin);++i) {
		long t = f(m,begin, begin+i,memo) + f(m,begin+i,end,memo) + common * m[begin+i].r;
		res = min(res, t);
	}
	return memo[begin][end] = res;
}

int main() {
	int n;
	cin >> n;
	vector<Matrix> M(n);
	vector<vector<long> > memo(n);
	for (int i=0;i<n;++i) {
		int r,c;
		cin >> r >> c;
		M[i].r = r; M[i].c = c;
		memo[i].resize(n+1);
		for (int j=0;j<memo[i].size();++j) memo[i][j] = -1;
	}
	cout << f(M, 0, M.size(), memo) << endl;
	return 0;
}




Measured memory_bytes: 3192
n, h, w = [int(_) for _ in input().split()]

a = []
b = []
for i in range(n):
    ai, bi = [int(_) for _ in input().split()]
    a.append(ai)
    b.append(bi)

counter = 0
for i in range(n):
    if a[i] >= h and b[i] >= w:
        counter += 1
print(counter)

Measured memory_bytes: 3064
S=input()
Q=int(input())
p=0
u=0
l=""
r=""
for i in range(Q):
    q=list(input().split())
    if q[0]=="1":
        u+=1
    else:
        if q[1]=="1" and u%2==0 or q[1]=="2" and u%2==1:
            l=l+q[2]
        else:
            r=r+q[2]
if u%2==0:
    l=l[::-1]
    S=l+S+r
else:
    S=S[::-1]
    r=r[::-1]
    S=r+S+l
print(S)


Measured memory_bytes: 10112
// template version 1.6
// {{{ define basic macro
using namespace std;
#include <iostream>
#include <bits/stdc++.h>
// varibable settings
#define int long long
#define INF 1000000000000000000LL
// #define INF 2147483647
#define MOD 1000000007LL
// #define MOD 998244353LL
#define infile "../test/sample-1.in"

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)
template<class T, size_t N> size_t sza(const T (&array)[N]) { return N; }
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
template<class T=int> T in() {T x; cin>>x; return (x);}
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

// dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
#define fi first
#define se second

// }}}

int solve(){
  int a,b;cin>>a>>b;
  
  if ((a*b)%2==1) {
    cout << "Odd" << endl;
  }
  else{
    cout << "Even" << endl;
  }

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int furui[999984];

int main () {
	furui[0] = furui[1] = 1;
	for (int i = 2; i*i < 999984; i++) {
		if (furui[i] == 0) {
			for (int j = i; j <= 999983/i; j++) {
				furui[i*j] = 1;
			}
		}
	}
	int n;
	int a, b, p, m;
	int counter;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		counter = 0;
		for (int i = 0; i < n; i++) {
			cin >> p >> m;
			a = p-m;
			if (a <= 2) {
				a = 3;
				counter++;
			}
			if (a % 2 == 0) {
				a++;
			}
			b = p+m;
			if (b > 999983) {
				b = 999983;
			}
			for (int j = a; j <= b; j+= 2) {
				if (furui[j] == 0) {
					counter++;
				}
			}
			counter--;
		}
		cout << counter << endl;
	}
	return 0;
}

Measured memory_bytes: 5064