akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

class Main {

  public static void main(String[] args) {
  
  	try {
      long MODN = 1000000007;	
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      String strLine = br.readLine();
      String[] hwInput = strLine.split(" ");
      int H = Integer.parseInt(hwInput[0]);
      int W = Integer.parseInt(hwInput[1]);
      char[][] hw = new char[H][W];
      for(int i = 0 ; i < H ; i++) {
      	strLine = br.readLine();
        for(int j = 0 ; j < strLine.length(); j++) {
        	hw[i][j] = strLine.charAt(j);
            //System.out.print(hw[i][j] + " ");
        }
        //System.out.println();
      }
      long[][] dp = new long[H][W];
      
      for(int i = 0 ; i < H; i++) {
      	for(int j = 0 ; j < W; j++) {
        	if(i == 0 && j == 0) {
               dp[i][j] = 1;
            } else if(i == 0 || j == 0) {
              	if(j == 0) {
            		dp[i][j] = (hw[i][j] != '#' && dp[i-1][j] != 0) ? 1 : 0;
                } else {
                	dp[i][j] = (hw[i][j] != '#' && dp[i][j-1] != 0) ? 1 : 0;
                }
            } else {
            	if(hw[i][j] != '#') {
                	dp[i][j] = (dp[i][j-1] + dp[i-1][j]) % MODN;
                }
            }
          
          //System.out.print(dp[i][j] + " ");
        }
        
        //System.out.println();
      }
      System.out.println(dp[H-1][W-1]);
    } catch(Exception ex) {
    	System.out.println("exception is " + ex);
    }
  }
}

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

int main(void)
{
  int n, m;
  int list[512][512], inv[512];
  int i, j;
  int a, b;
  int cnt;

  while (scanf("%d%d", &n, &m), n || m){
    memset(list, 0, sizeof(list));
    memset(inv, 0, sizeof(inv));
    for (i = 0; i < m; i++){
      scanf("%d%d", &a, &b);
      list[a][b] = list[b][a] = 1;
    }
    for (i = 2; i <= n; i++){
      if (list[1][i]){
        inv[i] = 1;
        for (j = 2; j <= n; j++){
          if(list[i][j]){
            inv[j] = 1;
          }
        }
      }
    }
    cnt = 0;
    for (i = 2; i <= n; i++){
      if (inv[i]){
        cnt++;
      }
    }
    printf("%d\n", cnt);
  }

  return (0);
}

Measured memory_bytes: 1632
#include <stdio.h>
#include <string.h>
int main(void){
    char s[1001];
    scanf("%s",s);
    char t[1001];
    scanf("%s",t);
    
    int ans = 0;
    for(int i = 0;i<strlen(s)-strlen(t)+1;i++){
        int tmp = 0;
        for(int j = 0;j < strlen(t);j++){
            if(s[i+j] == t[j]){
                tmp++;
            }
        }
        if(ans < tmp)ans = tmp;
    }
    printf("%lu",strlen(t)-ans);
}


Measured memory_bytes: 1732
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#define MOD 1000000007
#define ll long long

int cmpfunc(const void *a, const void *b){
    return (*(int*)a - *(int*)b);
}

int max(int a,int b){
    return (a>b)?a:b;
}

int main(void){
    int n;
    scanf("%d",&n);
    int s[n+1];
    int i;
    for(i=1;i<=n;i++) scanf("%d",&s[i]);
    int ans=0;
    for(i=1;i<=n;i++) ans+=s[i];
    if(ans%10!=0){
        printf("%d\n",ans);
        return 0;
    }

    qsort(s+1,n,sizeof(int),cmpfunc);
    for(i=1;i<=n;i++){
        if(s[i]%10!=0){
            printf("%d\n",ans-s[i]);
            return 0;
        }
    }
    if(i>n) printf("0\n");

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1012345678;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

int gcd(int a, int b){
  if (a%b==0){
    return(b);
  }
  else{
    return(gcd(b,a%b));
  }
}


int ans[1000000];
int sum[1000000];

int main(){
  string s;
  cin >> s;
  int ans = inf;
  rep(i,int(s.size())){
    int r = stoi(s.substr(i,3));
    ans = min(abs(r-753),ans);
  }
  cout << ans << endl;


  
  return 0;
}




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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll BASE = 200000LL;

int n;
ll threshold;
vector<ll> a;

class BIT{
    public:
    int n;
    vector<ll> bit;

    BIT(int n): n(n){
        bit.resize(n);
        fill(all(bit), 0LL);
    }

    void add(int idx, ll x){
        for(int i=idx;i<=n;i+=i&-i) bit[i] += x;
    }

    ll sum(int end){
        ll ret = 0LL;
        for(int i=end;i>=1;i-=i&-i) ret += bit[i];
        return ret;
    }
};

bool judge(ll median){
    vector<ll> b(n+1);
    b[0] = BASE;
    reppp(i, 1, n+1){
        b[i] = b[i-1] + (a[i-1]>=median ? 1LL : -1LL);
    }

    ll cnt = 0LL;
    BIT bit = BIT(BASE+n);
    bit.add(b[0], 1LL);
    reppp(i, 1, n+1){
        cnt += bit.sum(b[i]);
        bit.add(b[i], 1LL);
    }
    return cnt >= threshold;
}

int main(){
    cin >> n;
    a.resize(n);
    rep(n) cin >> a[i];

    threshold = ll(n) * ll(n+1) / 2LL;
    threshold = (threshold+1LL) / 2LL;

    vector<ll> aa(a);
    sort(all(aa));
    int ok = 0; // 中央値はok以上
    int ng = n; // 中央値はng未満
    while(ng-ok > 1){
        int mid = (ng+ok)/2;
        
        if(judge(aa[mid])){
            ok = mid;
        }else{
            ng = mid;
        }
    }

    cout << aa[ok] << endl;
}

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

int main()
{
  int64_t h,ans,t;
  cin>>h;
  ans=0;
  t=1;
  while (h>0)
  {
    ans+=t;
    t*=2;
    h/=2;
  }
  cout<<ans;
}

Measured memory_bytes: 3596
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;
long long int mod = 1e9 + 7;
int main() {
  int n, h, w; cin >> n >> h >> w;
  int cnt = 0;
  for(int i=0; i<n; i++) {
    int a, b; cin >> a >> b;
    if(a >= h && b >= w) cnt++;
  }
  cout << cnt << endl;

  return 0;
}



//EOF


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
#define inf 0x3f3f3f3f
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 3e5+5;
const ll mod =   1e9+7;

int main()
{  fast
int a,b,c,d;
cin>>a>>b>>c>>d;
int cnt=0;
while(b<=a){
	cnt++;b*=2;
}
while(c<=b) {
	cnt++;c*=2;
}
if(d>=cnt){
	cout<<"Yes\n";
}
else{
	cout<<"No\n";
}
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false


int main(void){
    ll A,B,C,K;
    cin >> A >> B >> C >> K;
    
    ll Ans=0;
    while(A>=B){
        Ans++;
        B*=2;
    }
    while(B>=C){
        Ans++;
        C*=2;
    }
    
    if(Ans<=K){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}



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

using namespace std;

int main() {
  int n;
  cin >> n;

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

    int first = 0;
    int second = 0;
    int third = 0;

    while(1) {
      string str;
      cin >> str;
      if(str == "HIT") {
	score += third;
	third = second;
	second = first;
	first = 1;
      } else if(str == "HOMERUN") {
	score += first + second + third + 1;
	first = second = third = 0;
      } else if(str == "OUT") {
	out++;
      }

      if(out == 3) {
	cout << score << endl;
	break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int x[100005];
int main() {
	int n, a, b;
	long long ans = 0;
	scanf("%d%d%d", &n, &a, &b);
	scanf("%d", &x[1]);
	for (int i = 2; i <= n; ++ i) {
		scanf("%d", &x[i]);
		ans += min(1LL * a * (x[i] - x[i - 1]), 1LL * b);
	}
	printf("%lld\n", ans);
}



Measured memory_bytes: 640
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner((os.Stdin))

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	l := nextLine()
	i, e := strconv.Atoi(l)
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	a := []int{}
	for i := 0; i < n; i++ {
		a = append(a, nextInt())
	}

	fmt.Printf("%d\n", ABC081B(a))
}

// ABC081B ...
func ABC081B(a []int) int {
	res := math.MaxInt8

	for _, n := range a {
		tmp := 0
		for n%2 == 0 {
			n = n >> 1
			tmp++
		}

		if tmp < res {
			res = tmp
		}
	}

	return res
}


Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define REP(i, n) for(int i=0; i<n; i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}


ll N;
int main() {
    cin >> N;
    int ans = 0;
    if(N>=1800) ans = 1;
    else if(N>=1600) ans = 2;
    else if(N>=1400) ans = 3;
    else if(N>=1200) ans = 4;
    else if(N>=1000) ans = 5;
    else if(N>=800) ans = 6;
    else if(N>=600) ans = 7;
    else if(N>=400) ans = 8;
    cout << ans << endl;
}

Measured memory_bytes: 3620
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
	int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt();
	if (a == b) { System.out.println(c); }
  	if (b == c) { System.out.println(a); }
	if (c == a) { System.out.println(b); }
  }
}

Measured memory_bytes: 22868
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String[] a = sc.nextLine().split("");
        String[] b = sc.nextLine().split("");
        String[] c = sc.nextLine().split("");
        String top =a[0];
        String middle = b[1];
        String bottom = c[2];
        System.out.println(top +""+ middle + "" + bottom);
    }
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

bool check(int a, int ia)
{
	if ((a & ia) == ia)
	{
		return true;
	}
	return false;
}

void solve()
{
	map<int, int> mp;
	for(int i = 0; i < 9; ++i)
	{
		int a;
		cin >> a;
		mp[a] = i;
	}

	int n;
	cin >> n;
	int ia = 0b000000000;
	for(int i = 0; i < n; ++i)
	{
		int b;
		cin >> b;
		if (mp.find(b) != mp.end())
		{
			ia |= (1 << mp[b]);
		}
	}

	bool ans = false;
	ans |= check(ia, 0b111000000);
	ans |= check(ia, 0b000111000);
	ans |= check(ia, 0b000000111);
	ans |= check(ia, 0b100100100);
	ans |= check(ia, 0b010010010);
	ans |= check(ia, 0b001001001);
	ans |= check(ia, 0b100010001);
	ans |= check(ia, 0b001010100);

	cout << (ans ? "Yes" : "No");
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 256
main :: IO ()
main = do
    n <- read <$> getLine
    s <- getLine
    putStrLn $ show $ solve n s


solve :: Int -> String -> Int
solve n s = maximum $ map sameCount $ cutStr n s


sameCount :: (String, String) -> Int
-- aとbに共に含まれる文字の数をカウント
-- ("aab", "bca") -> 2 ('a', 'b'が該当)

sameCount (a, b) =
    length [x | x <- ['a'..'z'], x `elem` a && x `elem` b]


cutStr :: Int -> String -> [(String, String)]
-- 切断した文字列のペアを作成
-- "abc" -> [("", "abc"), ("a", "bc"), ("ab", "c"), ("abc", "")]

cutStr 0 s = [splitAt 0 s]
cutStr n s = (splitAt n s) : cutStr (n - 1) s

Measured memory_bytes: 1020
K,S = map(int,input().split())

result = 0
for X in range(K + 1):
  YZ = S - X
  if 0 <= YZ <= K:
    result += YZ + 1
  elif K < YZ <= 2 * K:
    result += 2 * K + 1 - YZ
  
print(result)

Measured memory_bytes: 2940
#include <cstdio>
#include <vector>
#include <set>
int N, K, O, J[17][100001], *fa = J[0], dep[100001], q[100001], LOG;
std::vector < int > E[100001];
struct compare
{
	inline bool operator () (int x, int y)
	{
		return dep[x] > dep[y] || dep[x] == dep[y] && x < y;
	}
};
std::set < int, compare > S;
void BFS()
{
	int H = 0, T = 1;
	q[1] = 1;
	while (H < T)
	{
		int u = q[++H];
		for (int v : E[u])
			dep[q[++T] = v] = dep[u] + 1;
	}
}
int main()
{
	scanf("%d%d", &N, &K);
	for (int i = 1, u; i <= N; i++)
	{
		scanf("%d", &u);
		if (i == 1)
			O += u != 1;
		else
		{
			E[u].push_back(i);
			fa[i] = u;
		}
	}
	while (2 << LOG < N)
		LOG++;
	for (int i = 1; i <= LOG; i++)
		for (int j = 1; j <= N; j++)
			J[i][j] = J[i - 1][J[i - 1][j]];
	BFS();
	for (int i = 1; i <= N; i++)
		S.insert(i);
	while (!S.empty() && dep[*S.begin()] > K)
	{
		int u = *S.begin();
		for (int i = LOG; ~i; i--)
			if (K - 1 >> i & 1)
				u = J[i][u];
		int H = 0, T = 1;
		q[1] = u;
		while (H < T)
		{
			int u = q[++H];
			for (int v : E[u])
				if (~dep[v])
					q[++T] = v;
		}
		for (int i = 1; i <= T; i++)
		{
			S.erase(q[i]);
			dep[q[i]] = -1;
		}
		O++;
	}
	printf("%d\n", O);
	return 0;
}


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

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

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void initialize();
int pop();
void push(int);
int top;
int stack[10000];

int main()
{
    char array[100];
    int x,y;

    initialize();

    while(scanf("%s",array)!=EOF){
        if(array[0]=='+')
        {
            x=pop();
            y=pop();
            push(x+y);
        }
        else if(array[0]=='-')
        {
            y=pop();
            x=pop();
            push(x-y);
        }
        else if(array[0]=='*')
        {
            x=pop();
            y=pop();
            push(x*y);
        }
        else 
        {
            push(atoi(array));
        }
    }
    printf("%d\n",pop());
    return 0;
}

void initialize()
{
    top=0;
}

void push(x)
{
    stack[++top] = x;
}

int pop()
{
    top--;
   return stack[top+1];
}



Measured memory_bytes: 2144
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>

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

using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
    int a, b;
    cin >> a >> b;
    int ans = 0;
    int i = 0;
    while((b-1) > (i*(a-1)))  {
        ans++;
        i++;
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
	int s;
	cin >> s;
	vector<bool> num(1000000, false);
	int a;
	for (int i = 0; i < 1000000; i++)
	{
		if (i==0)
		{
			a = s;
		}
		else if (a%2==0)
		{
			a /= 2;
		}
		else
		{
			a *= 3;
			a += 1;
		}

		if (!num[a])
		{
			num[a] = true;
		}
		else
		{
			cout << i + 1 << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 384
Mod = 10**9+7
N,M = map(int, input().split())
a = [int(input()) for _ in range(M)]
b = [1]*(N+1)
for j in a:
    b[j] = 0
for i in range(1,N+1):
    if b[i] == 0:
        continue
    if i == 1:
        b[1] = 1
        continue
    b[i] = b[i-1]+b[i-2]
    if b[i] >= Mod:
        b[i] %= Mod
print(b[N])

Measured memory_bytes: 50008
N = int(input())

F = [tuple(map(int, input().split())) for _ in range(N)]

P = [tuple(map(int, input().split())) for _ in range(N)]

ans = -10 ** 18
for i in range(1, 2 ** 10):
    tmp = 0
    lst = [0] * N
    for j in range(10): #時間帯
        if (i >> j) & 1: #開けるとした時
            for k in range(N):
                lst[k] += F[k][j]
    for k in range(N):
        tmp += P[k][lst[k]]
    ans = max(ans, tmp)


print (ans)

Measured memory_bytes: 3064
n, w = map(int, input().split())
goods = [list(map(int, input().split())) for _ in range(n)]
dp = [[float("INF")] * (10 ** 5 + 1) for _ in range(n + 1)]
dp[0][0] = 0

for i in range(n):
    for j in range(10 ** 5 + 1):
        if 0 <= j - goods[i][1]:
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - goods[i][1]] + goods[i][0])
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])


M = 0
for i in range(10 ** 5 + 1):
    if dp[n][i] <= w:
        M = i
print(M)


Measured memory_bytes: 312632
n = gets.to_i
v = gets.split.map(&:to_i)

e = Hash.new(0)
o = Hash.new(0)

(n/2).times do |k|
  e[v[2*k]] += 1
  o[v[2*k+1]] += 1
end

es = e.to_a.sort_by {|k,v| -v}
os = o.to_a.sort_by {|k,v| -v}

if es[0][0] == os[0][0]
  if es.size == 1 && os.size == 1
    p n / 2
  elsif es.size == 1
    p n / 2 - os[0][1]
  elsif os.size == 1
    p n / 2 - es[0][1]
  else
    p [n - es[0][1] - os[1][1], n - es[1][1] - os[0][1]].min
  end
else
  p n - es[0][1] - os[0][1]
end


Measured memory_bytes: 20984
n = int(input())
s = []
for i in range(n):
    s.append(input())
out = 0
a=0
b=0
c=0
for i in range(len(s)):
    if s[i][0] == "B" and s[i][len(s[i])-1] == "A":
        a=a+1
    elif s[i][0] == "B" and s[i][len(s[i])-1] != "A":
        b=b+1
    elif s[i][0] != "B" and s[i][len(s[i])-1] == "A":
        c=c+1
    for j in range(len(s[i])-1):
        if s[i][j] == "A" and s[i][j+1] == "B":
            out = out+1
if a== 0 and b == 0 and c == 0:
    out = out
elif b == 0 and c == 0:
    out = out + a - 1
else :
    out = out +a+ min(b,c)
    
print(int(out))

Measured memory_bytes: 3700
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    HashMap<Integer, Integer> map1 = new HashMap<Integer, Integer>();
    HashMap<Integer, Integer> map2 = new HashMap<Integer, Integer>();
    for(int i = 0; i < n; i++) {
      int v = sc.nextInt();
      if((i % 2) == 0) {
        if(map1.containsKey(v)) {
          map1.put(v, map1.get(v) + 1);
        } else {
          map1.put(v, 1);
        }
      } else {
        if(map2.containsKey(v)) {
          map2.put(v, map2.get(v) + 1);
        } else {
          map2.put(v, 1);
        }
      }
    }
    int k1 = 0;
    int k2 = 0;
    int m1 = 0;
    int m2 = 0;
    
    int l1 = 0;
    int l2 = 0;
    int n1 = 0;
    int n2 = 0;

    int s = 0;
    int t = 0;
    int q1 = 0;
    int q2 = 0;

    int p1 = 0;
    int p2 = 0;

    int s1 = 0;
    int s2 = 0;

    ArrayList<Integer> list1 = new ArrayList<Integer>();
    ArrayList<Integer> list2 = new ArrayList<Integer>();

    for(int key : map1.keySet()) {
      s++;
      p1 = key;
      if(q1 < map1.get(key)) s1 = key;
      list1.add(map1.get(key));
      q1 = Math.max(q1, map1.get(key));
    }

    for(int key : map2.keySet()) {
      t++;
      p2 = key;
      if(q2 < map2.get(key)) s2 = key;
      list2.add(map2.get(key));
      q2 = Math.max(q2, map2.get(key));
    }

    Collections.sort(list1); 
    Collections.sort(list2); 

    int ans = 0;

    if(s == 1) {
      if(t == 1) {
        if(p1 == p2) ans = n / 2;
      } else {
        ans = (n / 2 - q2);
      }
    } else {
      if(t == 1) {
        ans = (n / 2 - q1);
      } else {
        if(s1 == s2) {
          ans = n - list1.get(list1.size() - 1) - list2.get(list2.size() - 2);
          ans = Math.min(ans, n - list1.get(list1.size() - 2) - list2.get(list2.size() - 1));
        } else {
          ans = (n - q1 - q2);
        }
      }      
    }
    
    System.out.println(ans);
  }
}


Measured memory_bytes: 69576
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
	int x, y;
	cin >> x >> y;

	int a[7] = {1, 3, 5, 7, 8, 10, 12};
	int b[4] = {4, 6, 9, 11};

	if (x == y){
		cout << "Yes" << endl;
		return 0;
	}
	else {
		pair<bool, bool> c = make_pair(false, false);
		pair<bool, bool> d = make_pair(false, false);

		REP(i, 7){
			if (x == a[i]) c.first = true;
			if (y == a[i]) c.second = true;
		}
		REP(i, 4){
			if (x == b[i]) d.first = true;
			if (y == b[i]) d.second = true;
		}
		if (c.first == true && c.second == true || d.first == true && d.second == true){
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
#include<random>
#include<bitset>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++) //0から
#define REP(i,n) for(int j=i;j<n;j++) //iから

typedef long long ll;



//英字ならture、数字ならfalse
bool isalpha(char s){
    if(('A'<=s&&s<='Z')||('a'<=s&&s<='z')){
        return 1;
    }else{
        return 0;
    }
}
//全ての文字が英字ならture、数字ならfalse
bool Isalpha(string s){
    ll n;
    bool tmp = true;
    rep(i,n){
        if(isalpha(s[i])){
            tmp = false;
        }
    }
    return tmp;
}




using Graph = vector<vector<ll>>;



//cout<<fixed<<setprecision(10);

ll binary_search(vector<ll> a, ll n, ll key){
    ll right = n, left = -1;
    ll md = (right + left) / 2;

    while(right - left > 1){
        if(a[md] <= key){
            right = md;
        }else{
            left = md;
        }
        md = (right + left) / 2;
    }
    if(left == -1) return -1; //無い場合
    return right;
}

int main(){
    ll  a,b,w,v,t;
    cin>>a>>v;
    cin>>b>>w;
    cin>>t;
    string ans = "NO";

    ll x = b - a;
    if(x<0) x *= -1;
    ll s = v - w;

    if(x <= s * t){
        ans = "YES";
    }


    cout<<ans<<endl;

    return 0;
}



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

const string YES = "Yes";
const string NO = "No";

void solve(long long X)
{
    if (X < 30)
    {
        cout << NO << endl;
    }
    else
    {
        cout << YES << endl;
    }
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long X;
    scanf("%lld", &X);
    solve(X);
    return 0;
}


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

#define rep(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a);i>(b);i--)
#define all(a) (a).begin(),(a).end()
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef pair<int,int> pii;

main(){
  int n; cin >> n;

  long long ans = 1;

  rep(i,n){
    ans *= i+1;
    ans %= 1000000007;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;
//int divr[maxn];
/**/
/*void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}
 
 
 
 
 
 
 













int main()
{
     int n,m;
     cin>>n>>m;
     int a[n];
     for(int i=0;i<n;i++)cin>>a[i];
     vector<pair<int,int>> vec(m);
     for(int i=0;i<m;i++){
          int x,y;
          cin>>x>>y;
          vec.push_back({y,x});
     }
     sort(vec.rbegin(),vec.rend());
     sort(a,a+n);
     int j=0;
     for(int i=0;i<n&&j<m;i++){
          if(a[i]<vec[j].fi){
               int t=vec[j].se;
               while(i<n&&t--&&a[i]<vec[j].fi){
                    a[i]=vec[j].fi;i++;
               }
               j++;
               i--;
          }
     }
     ll res=0;
     for(int i=0;i<n;i++)res+=a[i];
     cout<<res;
}























Measured memory_bytes: 2176
use std::io::Read;
use std::cmp::max;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let s: Vec<char> = iterator.next().unwrap().chars().collect();

    let n: usize = s.len() + 1;
    let mut a: Vec<usize> = vec![0; n];

    for i in 0..s.len() {
        if s[i] == '<' {
            a[i + 1] = max(a[i + 1], a[i] + 1);
        }
    }

    for i in (0..s.len()).rev() {
        if s[i] == '>' {
            a[i] = max(a[i], a[i + 1] + 1);
        }
    }

    let ans: usize = a.iter().sum();
    return ans.to_string();
}


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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
}*/

signed main()
{
	int n;
	cin >> n;

	vi a(n), b(n);
	bool dif = false;
	rep(i, 0, n){
		 cin >> a[i] >> b[i];
		 if(a[i] != b[i]) dif = true;
	}

	if(!dif){
		cout << 0 << endl;
		return 0;
	}

	vi c;
	int ans = 0;
	rep(i, 0, n){
		if(a[i] <= b[i]) ans += b[i];
		else c.pb(b[i]);
	}

	sort(all(c));
	rep(i, 1, c.size()){
		ans += c[i];
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 768
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	int n,a;cin>>n>>a;
	cout << n*n-a << endl;
	return 0;
}

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



int main(){
	auto read_string 	=	[](){ string s; cin >> s; return s; };
	auto read_int       =   [](){ int tmp; cin >> tmp; return tmp; };
	auto read_char      =   [](){ char c; cin >> c; return c; };
	auto str_repeat	 	=	[](string a,int count){	string res = ""; for(size_t i = 0 ; i < count ; i++) res += a; return res;	};
	auto to_lower_case 	= 	[](string s){ string res=""; for(size_t i = 0 ; i < s.size() ; i++) res += tolower(s[i]); return res; };
	auto to_upper_case 	= 	[](string s){ string res=""; for(size_t i = 0 ; i < s.size() ; i++) res += toupper(s[i]); return res; };
	auto read_vec_int   =   [](int count){ vector<int> tmp(count); for(size_t i = 0 ; i < count ; i++) cin >> tmp[i]; return tmp; };
	auto title_case     =   [](string s) { string ret = ""; ret+=toupper(s[0]); ret += s.substr(1); return ret; };
	auto is_upper 		=   [](char c){ return (int)c >= (int)'A' && (int)c <= (int)'Z'; };
	auto is_lower		=   [](char c){ return (int)c >= (int)'a' && (int)c <= (int)'z'; };

	string s; cin >> s;
	int L = s.size();
	string ans = "AC";
	if(s[0]!='A'){
		ans = "WA";
	}

	int cnt = 0;
	for(size_t i = 1 ; i < L ; i++){
		if(isupper(s[i])){
			if(i == 1 || i == L - 1 || s[i] != 'C'){
				ans = "WA";
			}
			++cnt;
		}
	}
	if(cnt != 1){
		ans = "WA";
	}

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


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

int main() {

  int N;
  cin >> N;
  int SUM=0;
 
  for(int i=0;i<N;i++){
    int a;
    cin >> a;
    SUM+=(a-1);
  }
  cout << SUM <<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
const int MOD = 1000000007;
int main() {
    string s;
    cin>>s;
  int n=s.size();
    if (s[n-1]=='3')
    {
        /* code */
        cout<<"bon"<<endl;
    }
    else if (s[n-1]=='0'||s[n-1]=='1'||s[n-1]=='6'||s[n-1]=='8')
    {
        /* code */
        cout<<"pon"<<endl;
    }
    else
    {
        cout<<"hon"<<endl;
    }
    
    
    
    
}

Measured memory_bytes: 3624
n = int(input())
a = [(int(input()),0) for i in range(n)]
b = [(int(input()),1) for i in range(n)]
diff = 0
ans = 1
mod = 10 ** 9 + 7
ab = sorted(a+b)
prev = 0
for x,now in ab:
  if prev != now:
    diff = -diff
  if diff > 0:
    ans *= diff
    ans %= mod
  diff -= 1
  prev = now
print(ans)


Measured memory_bytes: 27664
//template code, C343, 2019
import java.util.*;

class Graph {
	private int totalVertex;
	private LinkedList<LinkedList<Integer>> adjList;

	public Graph() { totalVertex = 0; }
	
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjList = new LinkedList<LinkedList<Integer>>();
		for(int i = 0; i < totalVertex; i ++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1;
			int degree = in.nextInt();
			//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for(int j = 0; j < degree; j ++) {
				int idx2 = in.nextInt() - 1;
				tmp.add(idx2);
			}	
			adjList.add(tmp);
		}
		in.close();
	}
	
	public void printAdjMatrix() {
		Integer[][] adjMatrix = new Integer[totalVertex][totalVertex];
		for(int i = 0; i < adjList.size(); i++) {
			LinkedList<Integer> temp = adjList.get(i);
			Iterator iter = temp.iterator();
			for(int elem: temp) {
				adjMatrix[i][elem] = 1;;
			}
		}
		for(int i = 0; i < adjMatrix.length; i++) {
			for(int j = 0; j < adjMatrix[i].length; j++) {
				if(adjMatrix[i][j] == null) adjMatrix[i][j] = 0;
				if(j == adjMatrix[i].length - 1) System.out.print(adjMatrix[i][j]);
				else System.out.print(adjMatrix[i][j] + " ");
			}
			System.out.println();
		}
	}
}

//change class name GraphRepresentation to Main() for submission to AIZU
public class Main {
	public static void main(String argv[]) {
		Graph g = new Graph();
		g.loadAdjList();
		g.printAdjMatrix();
	}
}


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

int main() {
  int n;
  cin >> n;
  double ans = 0;
  rep(i,0,n) {
    double x; string u;
    cin >> x >> u;
    if (u == "JPY") ans += x;
    else {
      ans += x * 380000;
    }
  }
  printf("%.6lf", ans);
  return 0;
}


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

int main()
{
	ll a,v,b,w,t;
   cin >> a >> v >> b >> w >> t;
   if(a>b)swap(a,b);
   //if(a<b)
   {
   if(a+v*t<b+w*t)cout<<"NO"<<endl;
   else cout<<"YES"<<endl;
   }

}

Measured memory_bytes: 3632
#include <stdio.h>

int main() {
  int number_x, number_y;
  int group_name[12] = {0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0};
  scanf("%d %d", &number_x, &number_y);
  if(group_name[number_x-1] == group_name[number_y-1]) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0; i<(N); i++)
#define pb push_back
typedef long long ll;
const ll mod=1e9+7;

ll N;
ll a[200005];
ll b[200005];

int main(){ 

cin.tie(0);
ios::sync_with_stdio(false);

cin>>N;

rep(i,N+1){
	if(i==0) continue;
	cin>>a[i];
}

for(int i=N; i>=1; i--){
	ll s=0;
	ll mul=2;
	while(1){
		if(mul*i>N) break;
		s+=b[mul*i];
		mul++;
	}
	if(a[i]%2){
		if(s%2) b[i]=0;
		else b[i]=1;
	}else{
		if(s%2) b[i]=1;
		else b[i]=0;
	}
}

ll M=0;
rep(i,N+1){
	if(i==0) continue;
	if(b[i]==1) M++;
}
cout<<M<<endl;
rep(i,N+1){
	if(i==0) continue;
	if(b[i]==1) cout<<i<<" ";
}
cout<<endl;

}


Measured memory_bytes: 3968
def main():
    s = list(input())

    len_max = 0
    len_cur = 0
    for t in s:
        if t in {'A', 'C', 'G', 'T'}:
            len_cur += 1
        else:
            len_max = max(len_max, len_cur)
            len_cur = 0

    len_max = max(len_max, len_cur)
    print(len_max)


main()


Measured memory_bytes: 2940
import java.util.*;
class Main{
public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int i,j;
        int[] count=new int[26];
        String sentence=" ";
        char basic_c[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
        while(sc.hasNext()){
        sentence+=sc.nextLine();
        }
        sentence = sentence.toLowerCase();
        for(i=0; i < sentence.length(); i++){
            for (j = 0; j < basic_c.length; j++) {
                if (sentence.charAt(i)==basic_c[j])
                    count[j]++;
            }
        } 
        for(j = 0; j < basic_c.length; j++){
             System.out.println(basic_c[j]+" : "+count[j]);
        } 
    }
}


Measured memory_bytes: 26012
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
typedef vector<double> vec3;

int main() {
  
  int n;
  cin >> n;
  int ans = 0;
  for(int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    for(int j = l; j <= r; j++) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j,k;
  int a[101],b[101],c[101],n,p,q,r;
  short d[101][101][101];
  while(cin>>p>>q>>r&&p+q+r){
    cin>>n;
    memset(a,-1,sizeof(a));
    memset(b,-1,sizeof(b));
    memset(c,-1,sizeof(c));
    memset(d,-1,sizeof(d));
    for(i=0;i<n;i++){
      int t,u,v,w;
      cin>>t>>u>>v>>w;
      if(w){
	a[t]=1;
	b[u-p]=1;
	c[v-p-q]=1;
      }else
	d[t][u-p][v-p-q]=w;
    }
    for(i=1;i<p+1;i++){
      for(j=1;j<q+1;j++){
	for(k=1;k<r+1;k++){
	  if(d[i][j][k]==0){
	    if(a[i]==1&&b[j]==1)
	      c[k]=0;
	    if(b[j]==1&&c[k]==1)
	      a[i]=0;
	    if(c[k]==1&&a[i]==1)
	      b[j]=0;
	  }
	}
      }
    }
    for(i=1;i<p+1;i++)
      cout<<(a[i]==-1?2:a[i])<<endl;
    for(i=1;i<q+1;i++)
      cout<<(b[i]==-1?2:b[i])<<endl;
    for(i=1;i<r+1;i++)
      cout<<(c[i]==-1?2:c[i])<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
n,c=map(int,input().split())
d=[]
for i in range(c):
    d.append(list(map(int,input().split())))
l=[]
for i in range(n):
    l.append(list(map(int,input().split())))
p=[[0 for j in range(c)] for i in range(3)]
for i in range(n):
    for j in range(n):
        p[(i+1+j+1)%3][l[i][j]-1]+=1
ans=10**10
for i in range(c):
    for j in range(c):
        for k in range(c):
            if i!=j and i!=k and j!=k:
                t=0
                for x in range(c):
                    t+=d[x][i]*p[0][x]
                    t+=d[x][j]*p[1][x]
                    t+=d[x][k]*p[2][x]
                ans=min(ans,t)
print(ans)   

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

using ll = long long;
const ll INF = 1e18;

int main() {
    int N, ans = 0;
    cin >> N;
    vector<int> A(N);
    map<int, int> mp;
    rep(i, N) {
        cin >> A[i];
        mp[A[i]]++;
    }
    sort(A.begin(), A.end());
    for (int i = N - 1; i >= 0; i--) {
        if (mp[A[i]] == 0) continue;
        mp[A[i]]--;
        int b = 1;
        while (b <= A[i]) b += b;
        int j = lower_bound(A.begin(), A.end(), b - A[i]) - A.begin();
        if (A[j] != b - A[i]) continue;
        if (mp[A[j]] == 0) continue;
        mp[A[j]]--;
        ans++;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 10368
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in=new Scanner(System.in);
		String k=in.next();
		int z=0;
		int flag=0;
		char[] a=new char[k.length()];
		char[] b=new char[k.length()];
		for(int i=0;i<k.length();i++)
		{
			a=k.toCharArray();
		}
		for(int i=0;i<k.length();i++)
		{
			if(a[i]=='C'||a[i]=='F')
			{
				b[z]=a[i];
				z++;
			}
		}
		for(int i=0;i<z;i++)
		{
			for(int j=i+1;j<=z-1;j++)
			{
				if(b[i]=='C'&&b[j]=='F')
					flag=1;
			}
		}
		if(flag==1)
			System.out.println("Yes");
		else
			System.out.println("No");

		
		in.close();
	}

}


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

int main(){
  int x, a, b;
  cin >> x >> a >> b;
  
  int kyoria = x - a;
  if(kyoria < 0){
    kyoria = -1 * kyoria;
  }
  
  int kyorib = x - b;
  if(kyorib < 0){
    kyorib = -1 * kyorib;
  }
  
  char ans = 'A';
  
  if(kyoria > kyorib){
    ans = 'B';
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <array>
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <bitset>
#include <utility>
#include <assert.h>
using namespace std;

typedef unsigned long long ull;
typedef signed long long ll;
#define INF (1LL << 48)

struct PT { ll x; ll y; };
string to_s(ull x) { return to_string(x); }
string to_s(ll x) { return to_string(x); }
ll to_ll(const string& x) { return stoll(x); }
ull to_ull(const string& x) { return stoull(x); }



constexpr int MAX_N = 2000;
constexpr int MAX_Y = 20000;
short dp[MAX_N + 1][MAX_Y + 1];

int main(int argc, char* argv[])
{
	for (;;) {
		int N, a;
		cin >> N;
		if (cin.fail()) break;

		std::deque<int> q;
		if (N & 1) {
			for (int i = 0; i < N; i++) {
				cin >> a;
				if (i & 1) {
					q.push_back(a);
				} else {
					q.push_front(a);
				}
			}
		} else {
			for (int i = 0; i < N; i++) {
				cin >> a;
				if (i & 1) {
					q.push_front(a);
				} else {
					q.push_back(a);
				}
			}
		}
		for (auto b : q) {
			printf("%d ", b);
		}
		puts("");
	}

	return 0;
}


Measured memory_bytes: 2944
#include<stdio.h>
#define N 100

static const int W=0;
static const int G=1;
static const int B=2;

int n,M[N][N];
int color[N],d[N],f[N],tt=0;

void dfs_visit(int u){
  int v;
  color[u] = G;
  tt++;
  d[u] = tt;
  for (v=0;v<n;v++){
    if(M[u][v] == 0)continue;
    if(color[v] == W){
      dfs_visit(v);
    }
  }
  color[u] = B;
  tt++;
  f[u] = tt;
}

void dfs(){
  int i, u;
  for(i=0;i<n;i++)color[i] = W;
  tt = 0;
  for(u=0;u<n;u++){
    if(color[u] == W)dfs_visit(u);
  }
  for(i=0;i<n;i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }
}


int main(){
  int i,j;
  int u,k,v; 
  
  scanf("%d", &n);
  for (i=0;i<n;i++){
    for(j=0;j<n;j++)M[i][j] = 0;
  }
  
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }
  dfs();
}



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


int main(){
  int n;
  cin >> n;
  
  vector <int> a(n);
  vector <int> c(1000001,0);
  rep(i,n){
    cin >> a.at(i);
    if(c.at(a.at(i))!=0){
      c.at(a.at(i))++;
   		 continue;
    }else{
      
      for(int j=1;j*a.at(i)<=1000000;j++){
        c.at(j*a.at(i))++;
      }
    }
    
    
  }
  int co=0;
  rep(i,n){
    if(c.at(a.at(i))==1)
      co++;
  }
  
  cout << co << endl;
  
}

Measured memory_bytes: 7928
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool Finish_read;
template<class T>inline void read(T &x){Finish_read=0;x=0;int f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;Finish_read=1;}
template<class T>inline void print(T x){if(x/10!=0)print(x/10);putchar(x%10+'0');}
template<class T>inline void writeln(T x){if(x<0)putchar('-');x=abs(x);print(x);putchar('\n');}
template<class T>inline void write(T x){if(x<0)putchar('-');x=abs(x);print(x);}
/*================Header Template==============*/
char s[15];
int main() {
	scanf("%s",s+1);
	int n=strlen(s+1);
	if(s[1]!='A')
		return 0*puts("WA");
	int cnt=0,idx=0;
	for(int i=3;i<=n-1;++i)
		if(s[i]=='C')
			cnt++,idx=i;
	if(cnt!=1)
		return 0*puts("WA");
	for(int i=1;i<=n;++i)
		if(i!=1&&i!=idx&&isupper(s[i]))
			return 0*puts("WA");
	return 0*puts("AC");
}

Measured memory_bytes: 256
S = input()
N = len(S)
num = float('inf')
tmp = 0
for k in range(N):
    if k % 2 == 0 and S[k] == '0':
        tmp += 1
    if k % 2 != 0 and S[k] == '1':
        tmp += 1

num = min(tmp, num)

tmp = 0
for k in range(N):
    if k % 2 == 1 and S[k] == '0':
        tmp += 1
    if k % 2 != 1 and S[k] == '1':
        tmp += 1

num = min(tmp, num)

print(num)


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

int main()
{
	int n, l; cin >> n >> l; cin.ignore();
	vector<string> a;
	for (int i = 0; i < n; i++)
	{
		string tmp;
		getline(cin, tmp);
		a.push_back(tmp);
	}

	sort(a.begin(), a.end());
	for (int i = 0; i < n; i++)
	{
		cout << a[i];
	}
	cout << "\n";
	return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll=long long;
using vec=vector<ll>;
using vect=vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n;i>=0;i--)
#define Pool(i, m, n) for(ll i=n;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x,y) __gcd(x,y)
#define erase(s) s.erase(s.end()-1) //文字列sの末尾削除

ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*y/z;
}
ll primejudge(ll n){
  if(n<2)return 0;
  else if(n==2)return 1;
  else if(n%2==0)return 0;
  double sqrtn=sqrt(n);
  Loop(i,3,sqrtn+1){
     if(n%i==0){
        return 0;
     }
     i++;
  }
  return 1;
}
string RLE(string s){
  ll n=s.size();
  char now='.';
  ll count=1;
  string press;
  loop(i,n){
    if(s[i]!=now){
      if(i){
        press+=now;
        press+=to_string(count);
      }
      now=s[i];
      count=1;
      continue;
    }
    else count++;
  }
  press+=now;
  press+=to_string(count);
  return press;
}
int main() {
  cout << fixed << setprecision(30);
  ll n;
  cin>>n;
  vector<double> x(n);
  vector<double> y(n);
  loop(i,n)cin>>x[i]>>y[i];
  vec v(n);
  loop(i,n)v[i]=i;
  double way=0;
  do{
  loop(i,n-1){
    way+=sqrt(pow(x[v[i+1]]-x[v[i]],2)+pow(y[v[i+1]]-y[v[i]],2));
  }
}while(next_permutation(v.begin(), v.end()));
  loop(i,n)way/=(i+1);
  putout(way);
  return 0;
}

Measured memory_bytes: 256
import sys
def GcdLCM():
    for line in sys.stdin:
        x,y=map(int,line.split())
        if x==None:
            break
        
        gcd = Gcd(x,y)
        lcm = int(x*y/gcd)

        print("{} {}".format(gcd,lcm))
       
def Gcd(x,y):
    while x!=0:
        x,y=y%x,x
    return y
        
    
GcdLCM()

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

int main()
{
    ll n;
    cin>>n;
    ll a[n],c=0;
    for(ll i=0;i<n;i++)
       cin>>a[i];
    for(ll i=0;i<n;i=i+2)
    {
        if(a[i]%2!=0)
           c++;
    }
    cout<<c<<endl;
}

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

#define PI 3.14159265358979323846264338327950288419

using namespace std;

int gcd(int a, int b){
	if(b == 0){
		return a;
	}else{
		return gcd(b, a % b);
	}
}

int n, k, s[100005];

int main(){
	scanf("%d %d", &n, &k);
	bool bigger = false;
	int g = 0;
	for(int i = 1; i <= n; i++){
		scanf("%d", &s[i]);
		if(s[i] >= k){
			bigger = true;
		}
		g = gcd(g, s[i]);
	}
	
	if(bigger && k % g == 0){
		printf("POSSIBLE\n");
	}else{
		printf("IMPOSSIBLE\n");
	}
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,num;
    cin >> N;
    int f[N]={0};
    for(int x=1; x<=100; x++){
        for(int y=1; y<=x; y++){
            for(int z=1; z<=y; z++){
                num=x*x+y*y+z*z+x*y+y*z+z*x;
                if(num<=0 || num>N) continue;
                else if(x>y && y>z){
                    f[num-1]+=6;
                }else if(x==y && y==z){
                    f[num-1]++;
                }else{
                    f[num-1]+=3;
                }
            }
        }
    }
    for(int i=0; i<N; i++){
        cout << f[i] << endl;
    }
    return 0;
}

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

using namespace std;

int main() {
    int n, s, ans = 0;
    cin >> n >> s;

    for (int i = 0; i <= n; ++i) {
        if (i + n + n < s) {
            continue;
        }
        for (int j = i; j <= n; ++j) {
            if (i + j + n < s) {
                continue;
            }
            if (i + j > s) {
                break;
            }
            for (int k = j; k <= n; ++k) {
                if (i + j + k > s) {
                    break;
                }
                else if (i + j + k == s) {
                    if (i == j && j == k) {
                        ans++;
                    } else if (i == j || j == k || k == i) {
                        ans += 3;
                    } else {
                        ans += 6;
                    }
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String c = sc.next();

		String[] boin = {"a","e","i","o","u"};

		if(Arrays.asList(boin).contains(c) ) {
			System.out.println("vowel");
		}else{
			System.out.println("consonant");
		}

	}
}

Measured memory_bytes: 23764