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

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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;}

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  int n; cin >> n;
  string tmp = to_string(n);
  rep(i, 3) {
    if (tmp[i] == '1') tmp[i] = '9';
    else if (tmp[i] == '9') tmp[i] = '1';
  }
  cout << tmp << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
static inline void PUT(char c)
{
  static char buf[1<<15],*ptr=buf;
  if(ptr==buf+strlen(buf)||c==0){fwrite(buf,1,ptr-buf,stdout),ptr=buf;}*ptr++=c;
}
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(int a)
{
  if(a<0)PUT('-'),a=-a;
  int d[40],i=0;do{d[i++]=a%10;}while(a/=10);
  while(i--){PUT(d[i]+48);}PUT('\n');
}
static inline void Add(int *fwt,int i,int v,int len){while(i<len){fwt[i]+=v;i|=i+1;}}
static inline int Sum(int *fwt,int i){int v=0;while(i>=0){v+=fwt[i];i=(i&(i+1))-1;}return v;}
static inline int Diff(int *fwt,int x,int y,int len){if(x==-1){return Sum(fwt,y);}if(y==-1){y=len-1;}return Sum(fwt,y)-Sum(fwt,x-1);}
int main()
{
  int N=IN(),Q=IN(),after[500001],dat[500000],fenwick[500000],id[500001],left[500001],pos[500000],result[500000];
  rep(i,N){dat[i]=IN()-1;}
  rep(i,Q){left[i+1]=IN()-1;int r=IN()-1;after[i+1]=id[r];id[r]=i+1;}
  rep(r,N)
  {
    if(pos[dat[r]]){Add(fenwick,pos[dat[r]]-1,-1,N);}
    Add(fenwick,r,1,N);
    for(int i=id[r];i;i=after[i]){result[i-1]=Sum(fenwick,r)-Sum(fenwick,left[i]-1);}
    pos[dat[r]]=r+1;
  }
  rep(i,Q){OUT(result[i]);}
}

Measured memory_bytes: 17212
#include <bits/stdc++.h>
using namespace std;
 
#define ff first
#define ss second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define check(x) cout << #x << " : " << (x) << endl
#define all(v) v.begin(),v.end() 
#define show(a) for(auto i:a) cout<<i<<" ";cout<<endl
// #define endl '\n'  
typedef long long ll; 
typedef unsigned long long ull; 
typedef long double ld;
typedef pair< int , int > mypair;
typedef priority_queue <int> max_heap;
typedef priority_queue <mypair, vector<mypair>, greater<mypair> > min_heap;
const int mod=1000000007;
const int inf=1e9;
const int N=2e6+10;


int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin.exceptions(cin.failbit);
    string s,t;
    cin>>s>>t;
    int ans=0;
    int n=s.size();
    for(int i=0;i<n;i++) if(s[i]!=t[i]) ans++;
    cout<<ans;
    

    return 0;
} 

Measured memory_bytes: 3784
from math import gcd

from math import factorial as f

from math import ceil, floor, sqrt
import math

import bisect
import re
import heapq

from copy import deepcopy
import itertools
from itertools import permutations

from sys import exit

ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(map(int, input().split()))

yes = "Yes"
no = "No"


def main():
    n = ii()
    ans = [0 for i in range(n + 5)]
    for i in range(1,200):
        for j in range(1,200):
            for k in range(1,200):
                tmp = ((i + j)**2 + (j + k)**2 + (k + i)**2)
                if tmp <= 2 * n + 5 and tmp % 2 == 0:
                    ans[tmp // 2] += 1
    for i in range(1, n + 1):
        print(ans[i])


main()



Measured memory_bytes: 70092
#include <iostream>

typedef long long ll;

#define FOR(i,a,b) for(ll i = (a);i < (b);++i)
#define REP(i,n) FOR(i,0,n)

#define debug(x) cout << #x << "=" << x << endl;

using namespace std;

long long a[200000];

int main(void){

    int N;
    int T;
    cin >> N >> T;

    if(N == 1){
        cout << T << endl;
        return 0;
    }

    REP(i,N){
        cin >> a[i];
    }

    long long plus  = 0;
    long long minus = 0;
    REP(i,N-1){
        long long diff = a[i+1] - (a[i] + T);
        if(diff > 0){
            plus += T;
        }else{
            minus += T+diff;
        }
        if(i == N-2){
            plus += T;
        }
    }

    long long ans = plus+minus;

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


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

int main(){
	int H, W, M; cin>>H>>W>>M;
	set<pair<int,int>> HW;
	rep(i, M){
		int h, w; cin>>h>>w; h--,w--;
		HW.insert({h, w});
	}

	vector<int> sum_h(H, 0), sum_w(W, 0);
	for(auto hw:HW){
		sum_h[hw.first]++;
		sum_w[hw.second]++;
	}

	int max_h_num = 0;
	map<int, set<int>> h_num_ix;
	rep(i, H){
		if(sum_h[i] == 0) continue;
		h_num_ix[sum_h[i]].insert(i);
		max_h_num = max(max_h_num, sum_h[i]);
	}

	int max_w_num = 0;
	map<int, set<int>> w_num_ix;
	rep(i, W){
		if(sum_w[i] == 0) continue;
		w_num_ix[sum_w[i]].insert(i);
		max_w_num = max(max_w_num, sum_w[i]);
	}

	int max_num = max_h_num + max_w_num - 1;
	for(auto h_ix:h_num_ix[max_h_num]){
		for(auto w_ix:w_num_ix[max_w_num]){
			if(HW.find({h_ix, w_ix}) != HW.end()) continue;
			cout<< max_num + 1 <<endl;
			return 0;
		}
	}
	cout<< max_num <<endl;
}


Measured memory_bytes: 47804
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
using namespace std;

int main(){
    int x,a,b,c;
    cin >> x;
    a = x / 500;
    x = x % 500;
    b = x / 5;
    c = 1000 * a + 5 * b;
    cout << c << endl;
}

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

int main(){
    Int N; cin >> N;
    vector<Int>A(N);
    for(auto& e : A) cin >> e;
    Int ans = A.front() - 1;
    Int mini =  2;
    A.erase(A.begin());
    for(auto e : A){
        if(mini >  e) continue;
        if( mini == e ){
            mini = mini + 1;
            continue;
        }
        if(e % (mini) == 0){
            ans += e / (mini) - 1; //mini++;
        } else {
            ans += e / (mini);
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  while (1){
    char trump;
    cin >> trump;
    if (trump == '#'){
      break;
    }
    vector<vector<int>> rank(4, vector<int>(13));
    vector<vector<char>> suit(4, vector<char>(13));
    for (int i = 0; i < 4; i++){
      for (int j = 0; j < 13; j++){
        char r, s;
        cin >> r >> s;
        if (2 <= 'r' && r <= '9'){
          rank[i][j] = r - '1';
        }
        if (r == 'T'){
          rank[i][j] = 9;
        }
        if (r == 'J'){
          rank[i][j] = 10;
        }
        if (r == 'Q'){
          rank[i][j] = 11;
        }
        if (r == 'K'){
          rank[i][j] = 12;
        }
        if (r == 'A'){
          rank[i][j] = 13;
        }
        suit[i][j] = s;
      }
    }
    int NS = 0;
    int EW = 0;
    int lead_player = 0;
    for (int i = 0; i < 13; i++){
      char lead = suit[lead_player][i];
      vector<int> s(4);
      for (int j = 0; j < 4; j++){
        if (suit[j][i] == trump){
          s[j] = rank[j][i] + 13;
        } else if (suit[j][i] == lead){
          s[j] = rank[j][i];
        } else {
          s[j] = 0;
        }
      }
      int next = 0;
      for (int j = 0; j < 4; j++){
        if (s[j] > s[next]){
          next = j;
        }
      }
      if (next % 2 == 0){
        NS++;
      } else {
        EW++;
      }
      lead_player = next;
    }
    if (NS > 6){
      cout << "NS " << NS - 6 << endl;
    } else {
      cout << "EW " << EW - 6 << endl;
    }
  }
}


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

using namespace std;

typedef long long int ll;

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

  int n;
  cin >> n;
  vector < pair < ll, pair < ll, ll > > > vv;
  vector < pair < int, int > > a (n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = i + 1;
  }
  sort (a.begin(), a.end());
  for (int i = 0; i < n; i++) {
    if (vv.size() > 0 && vv.back().first == a[i].first) vv.back().second.first++;
    else {
      vv.push_back ({a[i].first, {1, a[i].second}});
    }
  }

  priority_queue < pair < ll, pair < ll, ll > > > q;
  for (auto i : vv) q.push (i);

  vector < ll > cnt (n + 1);
  pair < ll, pair < ll, ll > > u, v, w;
  while (!q.empty()) {
    u = q.top(); q.pop();
    if (q.size() > 0) {
      v = q.top(); q.pop();
    } else {
      v = {0, {0, n}};
    }

    cnt[u.second.second] += u.second.first * (u.first - v.first);
    w = {v.first, {v.second.first + u.second.first, min (u.second.second, v.second.second)}};
    if (w.first != 0) q.push (w);
  }

  for (int i = 1; i <= n; i++) cout << cnt[i] << '\n';
}


Measured memory_bytes: 11036
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main(void){
    char a[5];
    int b=0;
    cin>>a;
    for(int i=0;i<5;i++){
        if(a[i]=='A' && a[i+1]=='C'){
            b++;
        }
    }
    if(b==0){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

abcde = [ni() for _ in range(5)]
wait = []
ans = 0

for i in abcde:
    if i%10 == 0:
        ans += i
        wait.append(0)
    else:
        wait.append(10 - i%10)
        ans += 10 * (i//10 + 1)
    
wait.sort()
print(ans - wait[-1])

    

Measured memory_bytes: 3064
#include <stdio.h>

struct tree{
 int id,left,right;
};

struct tree a[10000];

void inparse(int m)
{
 if(m==-1) return;
 inparse(a[m].left);
 printf(" %d",m);
 inparse(a[m].right);
}

void preparse(int m)
{
 if(m==-1) return;
 printf(" %d",m);
 preparse(a[m].left);
 preparse(a[m].right);
}

void postparse(int m)
{
 if(m==-1) return;
 postparse(a[m].left);
 postparse(a[m].right);
 printf(" %d",m);
}

int main(int argc,char const *argv[])
{
 int i,n,m,left,right,root;

 scanf("%d",&n);
 for(i=0;i<n;i++){
  a[i].id=-1;
 }

 for(i=0;i<n;i++){
  scanf("%d %d %d",&m,&left,&right);
  a[m].left=left;
  a[m].right=right;
  if(left!=-1) a[left].id=m;
  if(right!=-1) a[right].id=m;
 }

 for(i=0;i<n;i++){
   if(a[i].id==-1) root=i;
 }

 printf("Preorder\n");
 preparse(root);
 printf("\nInorder\n");
 inparse(root);
 printf("\nPostorder\n");
 postparse(root);
 printf("\n");

 return 0;
}

Measured memory_bytes: 1820
#include <bits/stdc++.h>
#define pb push_back
#define forn(i, n) for (int i = 0; i < n; i++)
#define fornd(i, n) for (int i = n - 1; i >= 0; i--)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define for1d(i, n) for (int i = n; i >= 1; i--)
#define fi first
#define se second
#define all(x) x.begin(), x.end()

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef tuple<int, int, int> iii;

const int maxn = 100010;

int gcd(int a, int b) { return a % b == 0 ? b : gcd(b, a % b); }

int main() {
	int n, lst[maxn], ans;
	cin >> n;
	forn(i, n) scanf("%d", &lst[i]);
	ans = gcd(lst[0], lst[1]);
	for (int i = 2; i < n; i++) ans = gcd(ans, lst[i]);
	cout << ans;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(),x.end()
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const double PI=3.1415926535;

int main(){
    int N;
    cin>>N;
    int ans=999999999;
    vi W(N);
    int s1=0,s2=0;
    for(int i=0;i<N;i++){
        cin>>W[i];
        s2+=W[i];
    }
    for(int i=0;i<N-1;i++){
        s1+=W[i];
        s2-=W[i];
        ans=min(ans,abs(s1-s2));
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
typedef long long int ll;

string march = "MARCH";

#define INF (1e9)

int main() {
    ll N, count[5] = {};
    cin >> N;

    for (int i = 0; i < N; i++) {
        string S;
        cin >> S;
        for (int j = 0; j < 5; j++) {
            if (S[0] == march[j]) {
                count[j]++;
            }
        }
    }

    ll ans = 0;

    for (int i = 0; i < 5; i++) {
        for (int j = i + 1; j < 5; j++) {
            for (int k = j + 1; k < 5; k++) {
                ans += count[i] * count[j] * count[k];
            }
        }
    }

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


Measured memory_bytes: 256
#include<stdio.h>
int main ()
{
    int n,i,flag;
    scanf("%d",&n);
    int arr[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    for(i=0;i<n;i++)
    {
        if (arr[i]%2==0)
        {
            if(arr[i]%3==0 || arr [i]%5==0)
            {
                flag=0;
            }
            else
            {
                flag=1;
                break;
            }
        }
    }
    if (flag==0)
    printf("APPROVED\n");
    else if (flag==1)
    printf("DENIED\n");
    return 0;
}

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

int main() {
  int N, A, B;
  cin >> N;
  
  if (N % 1111 == 0) {
    cout << "Yes" << endl;
    }
  else if (N % 1110 <= 9) {
    cout << "Yes" << endl;
  }
  else if ((N % 1000) % 111 == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StackControler readDataArr = new StackControler(in.readLine()
				.split(" "));
		System.out.println(readDataArr.calcData());
	}
}

class Stack {
	private int[] stack;
	private static int pointer = 0, popData, remover = 0;

	Stack(int[] stack) {
		this.stack = stack;
	}

	public void push(int data) {
		stack[pointer] = data;
		pointer++;
	}

	public int pop() {
		pointer--;
		popData = stack[pointer];
		stack[pointer] = remover;// pop????????????data?????????
		return popData;
	}

}

class StackControler {
	private Stack stack;
	private String[] readData;
	private int operand2, operand1, result, strToIntData;

	StackControler(String[] readData) {
		this.readData = readData;
	}

	public int calcData() {
		String tempStrData;
		stack = new Stack(new int[readData.length / 2 + 1]);
		for (int i = 0; i < readData.length; i++) {
			tempStrData = readData[i];

			if (tempStrData.equals("+")) {
				operand1 = stack.pop();
				operand2 = stack.pop();
				result = operand2 + operand1;
				stack.push(result);
			} else if (tempStrData.equals("-")) {
				operand1 = stack.pop();
				operand2 = stack.pop();
				result = operand2 - operand1;
				stack.push(result);
			} else if (tempStrData.equals("*")) {
				operand1 = stack.pop();
				operand2 = stack.pop();
				result = operand2 * operand1;
				stack.push(result);
			} else {
				strToIntData = Integer.parseInt(readData[i]);
				stack.push(strToIntData);
			}
		}
		result = stack.pop();
		return result;
	}
}

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

#define BOARD_SIDE_LENGTH 4

const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};
 
int calculateHeuristic(int board[BOARD_SIDE_LENGTH][BOARD_SIDE_LENGTH]) {
    int res = 0;
    int a, i, j;
    
    for (i = 0; i < BOARD_SIDE_LENGTH; i++)
        for (j = 0; j < BOARD_SIDE_LENGTH; j++) {
            if (board[i][j] == 0) continue;
            a = board[i][j] - 1;
            res += abs(a / BOARD_SIDE_LENGTH - i) + abs(a % BOARD_SIDE_LENGTH - j);
        }
    
    return res;
}

void swap(int * a, int * b) {
    int t = *a;
    *a = *b;
    *b = t;
}

int check(int board[BOARD_SIDE_LENGTH][BOARD_SIDE_LENGTH], int limit, int depth, int prev, int py, int px) {
//    printf("cheking: i: %d, j: %d, depth: %d\n", py,px,depth);
    int heuriScore = calculateHeuristic(board);
    
    if (heuriScore + depth > limit) return 0;
    
    // same board!! success!
    if (heuriScore == 0) return 1;
    
    // loop through the 4 possible exchanges
    for (int i = 0; i < 4; i++) {
        if (abs(i - prev) == 2) 
            continue;
        
        // new position
        int ny = py + dy[i];
        int nx = px + dx[i];
        
        // skip if swapping is out of boundary
        if (ny <  0 || nx <  0 || ny >= BOARD_SIDE_LENGTH || nx >= BOARD_SIDE_LENGTH) 
            continue;
        
        // try swapping
        swap(&board[ny][nx], &board[py][px]);
        
        // return true if success
        if (check(board, limit, depth + 1, i, ny, nx))
            return 1;
        
        // not work, swap back
        swap(&board[ny][nx], &board[py][px]);
    }
    
    // not work even if all swaps are tried...
    return 0;
}
 
void solve(int board[BOARD_SIDE_LENGTH][BOARD_SIDE_LENGTH], int py, int px) {
    int limit = 0;
    
    while (1) {
        if (check(board, limit, 0, 99, py, px)) {
            printf("%d\n", limit);
            return;
        }
        // incremental limit.
        limit++;
    }
}
 
int main(int argc, char** argv) {
    int py, px, i, j;
    int board[BOARD_SIDE_LENGTH][BOARD_SIDE_LENGTH];
    
    for (i = 0; i < BOARD_SIDE_LENGTH; i++)
        for (j = 0; j < BOARD_SIDE_LENGTH; j++) {
            scanf("%d", &board[i][j]);
            
            if (board[i][j] == 0) {
                py = i;
                px = j;
            }
        }

    solve(board, py, px);
    
    return (EXIT_SUCCESS);
}





Measured memory_bytes: 2108
import math
N,Y = map(int, input().split())

breakRoop = False

for z in range(N+1):
  for y in range(N+1-z):
    x = N-z-y
    total = x*10000 + y*5000 + z*1000
    if total == Y:
      print(x, y, z)
      breakRoop = True
      break
  if breakRoop:
    break

if not breakRoop:
  print(-1, -1, -1)
      

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

int main() {
  ll a,b,c,ans;
  cin >> a >> b >> c;
  if(a%2 == 0 || b%2 == 0 || c%2 == 0) ans = 0;
  else{
    ans = min(b*c,a*c);
    ans = min(ans,a*b);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
a,b,c=gets.split.map &:to_i
j,r=0,[]
while true do
  break if [a,b,c].count(&:odd?)>0
  a,b,c=[b/2+c/2,c/2+a/2,a/2+b/2].sort
  j=-1 and break if r.include?([a,b,c])
  r.push([a,b,c])
  j+=1 
end
p j

Measured memory_bytes: 1788
import java.util.*;
public class Main
{
    public static void main(String [] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt(); int sum = 0;
        for (int i = 0; i < m; i++) {
            sum += sc.nextInt();
        }
        if (sum > n) System.out.println(-1);
        else System.out.println(n - sum);
    }


}

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

// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000000000000ll
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
//#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
/* clang-format on */

struct edge {
  ll from;
  ll to;
  ll cost;
};

// O(v^3) 負閉路にも使える
// vector<vector<ll>> dp(v, vector<ll>(v, INF)) dp[i][j]はiからjへのコスト
// https://qiita.com/ageprocpp/items/cdf67e828e1b09316f6e#%E3%83%80%E3%82%A4%E3%82%AF%E3%82%B9%E3%83%88%E3%83%A9%E6%B3%95
bool warshall_floyd(vector<vector<ll>> &dp, vector<edge> &edges, ll v) {
  ll e = edges.size();
  REP(i, e) { dp[edges[i].from][edges[i].to] = edges[i].cost; }
  REP(i, v) { dp[i][i] = 0; }

  REP(k, v) {
    REP(i, v) {
      REP(j, v) {
        if (dp[i][k] == INF || dp[k][j] == INF) continue;
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
      }
    }
  }

  REP(i, v) {
    //負閉路を持つ
    if (dp[i][i] < 0) return false;
  }
  return true;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // v=頂点数,e=辺の数
  ll v, e, h, w;
  cin >> h >> w;
  v = 10, e = 100;
  vector<edge> edges(e);
  REP(i, 10) {
    REP(j, 10) {
      ll c;
      cin >> c;
      edges[i*10+j] = {i, j, c};
    }
  }
  vector<ll> cnt(10, 0);
  REP(i, h * w) {
    ll a;
    cin >> a;
    if (a != -1) cnt[a]++;
  }
  vector<vector<ll>> dist(v, vector<ll>(v, INF));
  warshall_floyd(dist, edges, v);
  ll ans = 0;
  REP(i, 10) {
    ans += cnt[i] * dist[i][1];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3640
import math
N = int(input())
x = [0]*N
y = [0]*N
for i in range(N):
    x[i], y[i] = map(int, input().split())

def kyori(x1, y1, x2, y2):
    return math.sqrt((x1-x2)**2 + (y1-y2)**2)

total = 0
for i in range(N):
    for k in range(N):
        total += kyori(x[i], y[i], x[k], y[k])

total = total / N
print(total)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define mk make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N,M; cin >> N >> M;
    vc<pi> p;
    rep(i,M){
        int a,b; cin >> a >> b;
        p.pb(mk(b,a));
    }
    sort(all(p));
    int pos=0;
    int cnt=0;
    for(auto a:p){
        if(pos<=a.se){
            pos=a.fi;
            cnt++;
        }
    }
    cout << cnt << endl;
}

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

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

    int n, x;
    while(cin >> n >> x){
        if(n == 0 && x == 0) break;
        int ans = 0;
        for(int i = 1; i <= n; i++){
            for(int j = i + 1; j <= n; j++){
                for(int k = j + 1; k <= n; k++){
                    if(i + j + k == x){
                        ans++;
                    }
                }
            }
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3136
n,c = gets.split.map(&:to_i)
s = n.times.map{gets.split.map(&:to_i)}.sort_by{|i,j,k|i}
r = [[-1,0]]
n.times do |i|
  f = true
  for j in 0..r.size-1
    if r[j][0] < s[i][0] || r[j][1] == s[i][2]
      r[j] = s[i][1..2]
      f = false
      break
    end
  end
  r.push(s[i][1..2]) if f
  r = r.sort_by{|i,j|i}
end
puts r.size

Measured memory_bytes: 17360
import Control.Monad
import Control.Applicative

slice a b s = drop a $ take (b+1) s

print' a b s = putStrLn $ slice a b s
reverse' a b s = take a s ++ reverse (slice a b s) ++ drop (b+1) s
replace' a b p s = take a s ++ p ++ drop (b+1) s

exec [] _ = return ()
exec (all@(op:args):xs) s
	| op == "print"   = do 
						print' a b s
						exec xs s
	| op == "reverse" = exec xs (reverse' a b s)
	| op == "replace" = exec xs (replace' a b (last args) s)
		where [a,b] = map read $ take 2 args

main = do
	s <- getLine
	n <- readLn
	op <- replicateM n $ words <$> getLine
	exec op s

Measured memory_bytes: 5688
#include<iostream>
using namespace std;
void dfs(int,int);
int box[51][51];
int main(){
  int w,h,i,I,a;
  while(1){
    a=0;
    cin>>w>>h;
    if(w==0&&h==0) break;
    for(i=0;i<=h+1;i++){
      for(I=0;I<=w+1;I++){
	box[i][I]==0;
      }
    }
    for(i=1;i<=h;i++){
      for(I=1;I<=w;I++){
	cin>>box[i][I];
      }
    }
    for(i=1;i<=h;i++){
      for(I=1;I<=w;I++){
	if(box[i][I]==1){
	  dfs(i,I);
	  a++;
	}
      }
    }
    cout<<a<<endl;
  }
  return 0;
}
  void dfs(int i,int I){
  if(box[i][I]==0) return;
  box[i][I]=0;
  dfs(i,I+1);
  dfs(i+1,I+1);
  dfs(i+1,I);
  dfs(i+1,I-1);
  dfs(i,I-1);
  dfs(i-1,I-1);
  dfs(i-1,I);
  dfs(i-1,I+1);
  }

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

int main() {
int n,m;
cin >> n >>m;
vector<int>a(m*2);
vector<int>che(n,0);
for(int i=0;i<m*2;i++){
  cin >> a.at(i);
  che.at(a.at(i)-1)+=1;
}

for(int i=0;i<n;i++){
cout << che.at(i)<<endl;
}
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
    int n;
    cin >> n;
    vector<int> a(n),b(n),c(n);
    for(int i = 0;i < n;i ++){
        cin >> a.at(i) >> b.at(i) >> c.at(i);
    }

    vector<vector<int>> dp(n,vector<int>(3));

    dp.at(0).at(0) = a.at(0);
    dp.at(0).at(1) = b.at(0);
    dp.at(0).at(2) = c.at(0);

    for(int i = 1;i < n;i ++){
        dp.at(i).at(0) = max(dp.at(i-1).at(1), dp.at(i-1).at(2)) + a.at(i);
        dp.at(i).at(1) = max(dp.at(i-1).at(0), dp.at(i-1).at(2)) + b.at(i);
        dp.at(i).at(2) = max(dp.at(i-1).at(0), dp.at(i-1).at(1)) + c.at(i);

    }

    int m;
    m = max(dp.at(n-1).at(0), dp.at(n-1).at(1));
    m = max(m, dp.at(n-1).at(2));

    cout << m << endl;

}

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

#define rep(i,a,b)      for(int i=a;i<=b;i++)
#define revp(i,a,b)     for(int i=b;i>=a;i--)

string s;
int n,cnt=0;
int main()
{


    cin>>s;
    n=s.length();
    if(n&1)
    {
        rep(i,0,(n/2-1))
            if(s[i]!=s[n-1-i])
                cnt++;
    }
    else
    {
        rep(i,0,n/2-1)
            if(s[i]!=s[n-1-i])
                cnt++;
    }
    cout<<cnt;
}




Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
L = [0] * 8
cnt = 0
for i in a:
    if 1 <= i < 400:
        L[0] = 1
    elif 400 <= i < 800:
        L[1] = 1
    elif 800 <= i < 1200:
        L[2] = 1
    elif 1200 <= i < 1600:
        L[3] = 1
    elif 1600 <= i < 2000:
        L[4] = 1
    elif 2000 <= i < 2400:
        L[5] = 1
    elif 2400 <= i < 2800:
        L[6] = 1
    elif 2800 <= i < 3200:
        L[7] = 1
    else:
        cnt += 1
m = max(1, sum(L))
M = sum(L) + cnt
print(m, M)


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

m=[]
for i in range(1,n//2+2):
    a=0
    k=i
    l=n-i
    while k>0 or l>0:
        a=a+k%10+l%10
        k=k//10
        l=l//10

    m.append(a)

print(min(m))    
        

Measured memory_bytes: 9192
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

template<typename T>
class BIT {
    int n;
    vector<T> val;
public:
    BIT(int n):n(n),val(n+1,0) {}
    void add(int i,T x=1) {
        i++;
        while(i <= n) {
            val[i] += x;
            i += i&-i;
        }
    }
    T sum(int i) {
        T ret = 0;
        i++;
        while(i > 0) {
            ret += val[i];
            i -= i&-i;
        }
        return ret;
    }
    // [l,r)
    T sum(int l,int r) { return sum(r-1)-sum(l-1); }
};

void dfs(vi &in,vi &out,vi &ord,vvi &ls,vvi &G,vi &c,int v,int p) {
    in[v] = ord.size();
    ord.pb(v);
    ls[c[v]].pb(v);
    for(int u : G[v]) {
        if(u == p) continue;
        dfs(in,out,ord,ls,G,c,u,v);
    }
    out[v] = ord.size();
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    vi c(n);
    cin >> c;
    rep(i,n) c[i]--;
    vvi G(n);
    rep(_,n-1) {
        int a,b;
        cin >> a >> b;
        a--; b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    vvi ls(n);
    vi ord;
    vi in(n),out(n);
    dfs(in,out,ord,ls,G,c,0,-1);
    rep(i,n) reverse(all(ls[i]));
    BIT<int> bt(n);
    rep(i,n) bt.add(i);
    rep(k,n) {
        vp hist;
        ll ans = (ll)n*(n+1)/2;
        for(int i : ls[k]) {
            int sum = 1;
            for(int j : G[i]) {
                if(in[i] > in[j]) continue;
                int sz = bt.sum(in[j],out[j]);
                sum += sz;
                ans -= (ll)sz*(sz+1)/2;
            }
            bt.add(in[i],-sum);
            hist.eb(in[i],sum);
        }
        int sz = bt.sum(0,n);
        ans -= (ll)sz*(sz+1)/2;
        cout << ans << "\n";
        for(auto p : hist) bt.add(p.first,p.second);
    }
}

Measured memory_bytes: 45544
s = input()

n = len(s)

firsthalf = s[:(n - 1)//2]
secondhalf = s[(n + 3)//2 - 1:]
#
# print(firsthalf)
# print(secondhalf)

revfirst = firsthalf[::-1]
revsecond = secondhalf[::-1]
revitself = s[::-1]
#
# print(revfirst)
# print(revsecond)

if s == revitself and firsthalf == revfirst and secondhalf == revsecond:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <tuple>
#include <utility>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <map>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int INF = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};

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

    vector<int> h(n);
    rep(i,n)cin>>h[i];

    bool ans =true;
    for(int i=0;i<n-1;i++){
        if(h[i]<h[i+1]){
            h[i+1]--;
        }
        else if(h[i]>h[i+1]){
            ans =false;
        }

        
    }

    if(ans)cout << "Yes"<<endl;
    else cout << "No"<<endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back

using namespace std;

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

const int INF = 1e9 + 7;

int main()
{
	IO_OP;
	
	int x, a;
	cin >> x >> a;
	if(x < a) cout << 0 << endl;
	else cout << 10 << endl;
	
}



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

bool ok(int array[], int n, int k, long long P)
{
	int cnt = 0; //乗せた荷物の個数
	long long temp = 0; //荷物を載せようとしているトラックに今どのくらいの重さの荷物が乗っているか	
	for (int i = 0; i < k; ++i)
	{
		while ((P-temp) >= array[cnt]) //乗らなくなるまで乗せ続ける
		{
			temp += array[cnt];

			if (cnt == n-1)
			{
				return true;
			}

			cnt++;
		}

		temp = 0; 
	}

	return false;
}

int main()
{
	long long n,k;
	cin >> n >> k; //nは荷物の数、kはトラックの数
	int w[100000];
	for (int i = 0; i < n; ++i)
	{
		cin >> w[i];
	}

	long long l = 0, h = 1000000005;
	long long m;
	while(l+1 < h)
	{
		m = (l + h) / 2;
		if (ok(w,n,k,m))
		{
			h = m;
		}
		else
		{
			l = m;
		}

	}
	cout << h << endl;	
	return 0;
}


Measured memory_bytes: 3472
#include<bits/stdc++.h>
using namespace std;
long long read()
{
	char ch=getchar();long long x=0,ff=1;
	while(ch<'0'||ch>'9') {if(ch=='-') ff=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}
	return ff*x;
}
void write(long long z)
{
	if(z<0){putchar('-');z=-z;}
	if(z>=10){write(z/10);}
	putchar(z%10+'0');
}
const long long mod=1e9+7;
long long n,m,now;
long long f[2][305][305];
struct node
{
	long long l,r,x;
}a[305];
bool cmp(node aa,node bb)
{
	return aa.r<bb.r;
}
int main()
{
	n=read(),m=read();
	for(long long i=1;i<=m;++i) a[i].l=read(),a[i].r=read(),a[i].x=read();
	sort(a+1,a+m+1,cmp);
	f[now][0][0]=1;
	long long oo=1;
	for(long long i=1;i<=n;++i)
	{
		now^=1;
		for(long long j=0;j<i;++j)
		for(long long k=0;k<i;++k)
		{
			f[now][i-1][k]=(f[now][i-1][k]+f[now^1][j][k])%mod;
			f[now][j][i-1]=(f[now][j][i-1]+f[now^1][j][k])%mod;
			f[now][j][k]=(f[now][j][k]+f[now^1][j][k])%mod;
			f[now^1][j][k]=0;
		}
		while(a[oo].r==i) 
		{
			if(a[oo].x==3)
			{
				for(long long j=0;j<a[oo].l;++j)
				for(long long k=0;k<=i;++k) f[now][j][k]=0,f[now][k][j]=0;
			}
			else if(a[oo].x==2) 
			{
				for(long long j=a[oo].l;j<=i;++j)
				for(long long k=a[oo].l;k<=i;++k) f[now][j][k]=0;
				for(long long j=0;j<a[oo].l;++j)
				for(long long k=0;k<a[oo].l;++k) f[now][j][k]=0;
			}
			else if(a[oo].x==1)
			{
				for(long long j=a[oo].l;j<=i;++j)
				for(long long k=0;k<=i;++k) f[now][j][k]=0,f[now][k][j]=0;
			}
			oo++;
		}
	}
	long long ans=0;
	for(long long i=0;i<n;++i)
	for(long long j=0;j<n;++j) ans=(ans+f[now][i][j])%mod;//cout<<i<<" "<<j<<" "<<f[now][i][j]<<endl;
	write(ans);
	return 0;
}

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

int main(){
  int N;
  string S;
  cin >> N >> S;
  if(N%2==1){
    cout << "No" << endl;
  }
  else if(S.substr(0,N/2)==S.substr(N/2,N/2)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}
  

Measured memory_bytes: 3628
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Stack;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] tmpArray = br.readLine().split(" ");
		int n = Integer.parseInt(tmpArray[0]);
		int q = Integer.parseInt(tmpArray[1]);

		@SuppressWarnings("unchecked")
		ArrayList<Integer>[] queue = new ArrayList[n];
		for(int i = 0; i < n; i++){
			queue[i] = new ArrayList<Integer>();
		}

		for(int i = 0; i < q; i++){
			tmpArray = br.readLine().split(" ");

	
			if(tmpArray[0].equals("0")){
				int t = Integer.parseInt(tmpArray[1]);
				int x = Integer.parseInt(tmpArray[2]);

				queue[t].add(x);
			}
	
			else if(tmpArray[0].equals("1")){
				int t = Integer.parseInt(tmpArray[1]);

				if(!queue[t].isEmpty()){
					System.out.println(queue[t].get(0));
				}
			}
			
			else {
				int t = Integer.parseInt(tmpArray[1]);

				if(!queue[t].isEmpty()){
					queue[t].remove(0);
				}
			}
		}
	}
}



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

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

    bool can = true;
    sort(S.begin(), S.end());
    rep(i, S.size()-1) {
        if (S[i] == S[i+1]) can = false; 
    }
    if (can) cout << "yes" << endl;
    else cout << "no" << endl;
}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(N), B(N);
    rep(i, N) {
        cin >> A[i] >> B[i];
    }
    
    vector<pair<int, int>> AB(N);
    rep(i, N) {
        AB[i] = make_pair(A[i], B[i]);
    }

    sort(AB.begin(), AB.end());

    ll ans = 0;
    rep(i, N) {
        int buy = min(M, AB[i].second);

        ans += (long long)buy * AB[i].first;

        M -= buy;
    }

    cout << ans;

    cout << endl;
    return 0;
}

Measured memory_bytes: 1792
#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 maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
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;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N,M;
  cin >> N >> M;
  vi a(M);
  rep(i,M) {
    cin >> a[i];
  }
  vi dp(N+1,1);
  rep(i,M) {
    dp[a[i]] = 0;
  }
  for(int i = 2;i <N+1;i++) {
    if(dp[i] == 0) continue;
    dp[i] = (dp[i-1] + dp[i-2]) % MOD;
  }
  cout << dp[N] << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

class Cube{
    public:
        int f[6];
        Cube(){}
        void roll_z(){roll(1, 2, 4, 3);}
        void roll_y(){roll(0, 2, 5, 3);} // to W
        void roll_x(){roll(0, 1, 5, 4);} // to N
        void roll(int i, int j, int k, int l){
            int tmp = f[i]; f[i] = f[j]; f[j] = f[k]; f[k] = f[l]; f[l] = tmp;
        }
};

bool eq(Cube c1, Cube c2){
    for(int i = 0; i < 6; i++){
        if(c1.f[i] != c2.f[i]){
            return false;
        }
    }
    return true;
}

bool equal(Cube c1, Cube c2){
    for(int i = 0; i < 6; i++){
        for(int j = 0; j < 4; j++){
            if(eq(c1, c2)){
                return true;
            }
            c1.roll_z();
        }
        if(i%2 == 0){
            c1.roll_y();
        }else{
            c1.roll_x();
        }
    }
    return false;
}

int main(){
    
    Cube c1, c2;

    for(int i = 0; i < 6; i++){
        cin >> c1.f[i];
    }
    for(int i = 0; i < 6; i++){
        cin >> c2.f[i];
    }

    if(equal(c1, c2)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}




Measured memory_bytes: 3112
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007 //S(vector).size()
using namespace std;
typedef long long ll;

int main(void){
  ll n;
  cin >> n;
  ll a[n];
  rep(i, n) cin >> a[i];

  ll ans = 0;
  for(int i = 0; i < n; i++){
    while(a[i] % 2 == 0){
      ans++;
      a[i] /= 2;
    }
  }
  cout << ans << endl;

}


Measured memory_bytes: 384
N = int(input())
A = list(map(int, input().split()))

B = [0, 0, 0]
for a in A:
  if a % 4 == 0:
    B[2] += 1
  elif a % 2 == 0:
    B[1] += 1
  else:
    B[0] += 1
print ("Yes" if B[0] <= B[2] or B[1] == 0 and B[0] - B[2] == 1 else "No")

Measured memory_bytes: 62576
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str;
        int i, m, h;
        
        while(true) {
        	str = sc.next();
        	if(str.equals("-")) break;
        	m = sc.nextInt();
        	
        	for(i = 0; i < m; i++) {
        		h = sc.nextInt();
        		str = str.substring(h).concat(str.substring(0, h));
        	}
        	System.out.println(str);
        }
    }
}


Measured memory_bytes: 26228
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.numeric;


void main()
{
  immutable mod = 1_000_000_000 + 7;
  auto n = readln.chomp.to!int;
  auto a = readln.chomp.split.to!(int[]);

  auto r = new int[](n/2+1);
  auto t = n % 2;

  foreach (e; a) {
    if (t == e % 2) continue;

    r[(n/2) - (e/2) - ((n+1)%2)]++;
  }

  long res = 1;
  
  foreach (i; 0..n/2 + n%2) {
    res *= r[i];
    res %= mod;
    r[i]--;
  }
  foreach_reverse (i; 0..n/2) {
    res *= r[i];
    res %= mod;
  }

  res.writeln;
}


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

int main() {
	int a, b, c; scanf("%d%d%d", &a, &b, &c);
	set<int>se;
	for (int i = 0;; i++) {
		int j = (60 * i + c) % (a + b);
		if (j <= a) {
			printf("%d\n", 60 * i + c);
			break;
		}
		else {
			if (se.find(j) != se.end()) {
				puts("-1");
				break;
			}
			se.insert(j);
		}
	}
}

Measured memory_bytes: 3204
#include<stdio.h>
int main(){
	int a[10000],//ツ個ウツづ個青板療ア
		b[10000][2],//
		c[10000],j,
			i,k,n,g;//ツ篠淞づ個青板療ア
		while(scanf("%d",&n),n){
			for(i=0;i<n;i++)
				scanf("%d",&a[i]);
			g=0;
			
			
			
			while(1){
			
				k=0;
				
				for(i=0;i<n;i++){
			
					for(j=0;j<k;j++){
						if(a[i]==b[j][0]){
							b[j][1]++;
							break;
						}
					}
					
					if(j==k){
						b[k][1]=1;
						b[k][0]=a[i];
						k++;

					}
				}
				
				
				
			
				
				for(i=0;i<n;i++)
					for(j=0;j<k;j++)
						if(a[i]==b[j][0]){
							c[i]=b[j][1];
							break;
				}
				for(i=0;i<n;i++)
					if(a[i]!=c[i])
					break;
				
				if(i==n)//whileツ終ツ猟ケ
					break;
					else
						for(i=0;i<n;i++)
						a[i]=c[i];
					g++;
			}//whileツづ個終ツづュツづィ
			
			
			
			
			
			
			
			
			printf("%d\n",g);
			for(i=0;i<n-1;i++)
				printf("%d ",a[i]);
			printf("%d\n",a[n-1]);
			
		}
		return 0;
}

Measured memory_bytes: 0
n = int(input())
a = list()
xy = list()
for i in range(n):
  A = int(input())
  XY = [tuple(map(int, input().split())) for i in range(A)]
  a.append(A)
  xy.append(XY)
honest = [None] * n
ans = 0
for i in range(2 ** n-1,-1,-1):
  mini_ans = 0
  honest = []
  for j in range(n):
    honest.append(i % 2)
    i = i // 2
  for k,v in enumerate(honest):
    if v:
      mini_ans += 1
      for x,y in xy[k]:
        x -= 1
        if honest[x] != y:
          break
      else:
        continue
      break
  else:
    ans = max(ans,mini_ans)
    continue
print(ans)

Measured memory_bytes: 46700
s = input()
s1 = int(s[0])
s2 = int(s[1])
s3 = int(s[2])
s4 = int(s[3])
if(0 < (10 * s1 + s2) < 13 and 0 < (10 * s3 + s4) < 13):
  print('AMBIGUOUS')
elif(0 < (10 * s3 + s4) < 13):
  print('YYMM')
elif(0 < (10 * s1 + s2) < 13):
  print('MMYY')
else:
  print('NA')


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

int main() {
  int rx=0, r=0;
  string S;
  cin >> S;
  set<char> x;
  x.insert('A'); x.insert('C'); x.insert('G'); x.insert('T');
  
  for(char c : S)
    if(x.count(c))
      r++;
    else {
      if(r>rx)
        rx=r;
      r=0;
    }
  
  if(r>rx)
    rx=r;
  cout << rx << endl;
}

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

#define sorted(vector) sort(vector.begin(),vector.end())
#define vmin(vector) *min_element(vector.begin(),vector.end())
#define vmax(vector) *max_element(vector.begin(),vector.end())
#define vsum(vector) accumulate(vector.begin(),vector.end(),0)
#define append(a) push_back(a)
#define int(a) stoi(a)
#define str(a) to_string(a)
#define bisect_left(vector,a) lower_bound(vector.begin(),vector.end(),a)
#define bisect_right(vector,a) upper_bound(vector.begin(),vector.end(),a)

using namespace std;

int main(void){
    int n,m;
    cin>>n>>m;
    string s;
    vector<vector<string>> grid2(n,vector<string>(m,"."));
    for(int i=0  ;i<n  ;i++){
        cin>>s;
        for(int j=0  ;j<m  ;j++){
            grid2[i][j]=s[j];
        }
    }
    vector<vector<int>> grid(n,vector<int>(m,0));
    for(int i=0  ;i<n  ;i++){
        for(int j=0  ;j<m  ;j++){
            grid[i][j]=(grid2[i][j]==".");
//            cout<<grid[i][j]<<" ";
        }
//        cout<<endl;
    }
    
    vector<vector<int>> gridleft=grid;
    vector<vector<int>> gridright=grid;
    vector<vector<int>> gridup=grid;
    vector<vector<int>> griddown=grid;
    
    for(int i=0  ;i<n  ;i++){
        for(int j=1  ;j<m  ;j++){
            if (grid[i][j]){
                gridright[i][j]=gridright[i][j-1]+1;
            }else{
                gridright[i][j]=0;
            }
        }
    }

    for(int i=0  ;i<n  ;i++){
        for(int j=m-2  ;j>=0  ;j--){
            if (grid[i][j]){
                gridleft[i][j]=gridleft[i][j+1]+1;
            }else{
                gridleft[i][j]=0;
            }
        }
    }

    for(int j=0  ;j<m  ;j++){
        for(int i=1  ;i<n  ;i++){
            if (grid[i][j]){
                griddown[i][j]=griddown[i-1][j]+1;
            }else{
                griddown[i][j]=0;
            }
        }
    }

    for(int j=0  ;j<m  ;j++){
        for(int i=n-2  ;i>=0  ;i--){
            if (grid[i][j]){
                gridup[i][j]=gridup[i+1][j]+1;
            }else{
                gridup[i][j]=0;
            }
        }
    }
    
    vector<int> ans;
    for(int i=0  ;i<n  ;i++){
        for(int j=0  ;j<m  ;j++){
            ans.append(gridleft[i][j]+gridup[i][j]+gridright[i][j]+griddown[i][j]);
        }
    }
    cout<<vmax(ans)-3<<endl;
}


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

int main(){
  int n[3][3];
  rep(i,0,3){
    rep(j,0,3){cin>>n[i][j];}
  }

  vector<int> a(3,0);
  vector<int> b(3,0);
  
 rep(i,0,n[0][0]+1){
   a[0]=i;
   rep(j,0,3){
     b[j]=n[0][j]-a[0];
   }
   rep(j,1,3){
     a[j]=n[j][0]-b[0];
   }
   /*rep(j,0,3){
     cout<<a[j];
   }
   rep(j,0,3){
     cout<<b[j];
   }
   cout<<endl;*/
   bool empty=true;
   rep(j,0,3){
     rep(k,0,3){
       if(a[j]+b[k]!=n[j][k]){empty=false;}
     }
   }
   if(empty==true){cout<<"Yes"<<endl;return 0;}
 }
 
 cout<<"No"<<endl;
  
  return 0;
}


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

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

    ll H;
    cin >> H;
    ll ans = 0;
    ll res = 1;
    while (H) {
        H /= 2;
        ans += res;
        res *= 2;
    }
    cout << ans << endl;

    return 0;
}

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

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

    for(int i = 0; i < S.size(); i++){
        if(i % 2 == 1){
            if(S.at(i) == 'R'){
                cout << "No" << endl;
                return 0;
            }
        }
        else if(i % 2 == 0){
            if(S.at(i) == 'L'){
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;


}

Measured memory_bytes: 256