akhauriyash/Code-Regression huggingface dataset:
from itertools import groupby, accumulate, product, permutations, combinations
def compress(arr):
    *XS, = set(arr)
    XS.sort()
    return {e: i+1 for i, e in enumerate(XS)},{i+1: e for i, e in enumerate(XS)}

def solve():
  ans = float('inf')
  N, K = map(int, input().split())
  X,Y = [0]*N,[0]*N
  for i in range(N):
    X[i],Y[i] = map(int, input().split())
  x_c,x_r = compress(X)
  y_c,y_r = compress(Y)
  n_x = len(x_c)
  n_y = len(y_c)
  num = [[0]*(N+1) for _ in range(N+1)]
  for i in range(N):
    X[i] = x_c[X[i]]
    Y[i] = y_c[Y[i]]
    num[X[i]][Y[i]] += 1
  cum2 = [[0]*(N+1) for _ in range(N+1)]
  for i in range(1,N+1):
    for j in range(1,N+1):
      cum2[i][j] = cum2[i-1][j]+cum2[i][j-1]-cum2[i-1][j-1]+num[i][j]
  for x1,x2 in combinations(range(1,n_x+1),2):
    x_l = x_r[x2]-x_r[x1]
    for y1,y2 in combinations(range(1,n_y+1),2):
      k = cum2[x2][y2]+cum2[x1-1][y1-1]-cum2[x1-1][y2]-cum2[x2][y1-1]
      if k>=K:
        y_l = y_r[y2]-y_r[y1]
        ans = min(ans,x_l*y_l)
  return ans
print(solve())

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

using namespace std;

#define sqr(x) ((x) * (x))
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define fin(name) freopen(name, "r", stdin)
#define fout(name) freopen(name, "w", stdout)
#define I(x, a) for(auto x : a)
#define F(i, l, r) for(auto i = l; i < r; ++i)
#define E(i, l, r) for(auto i = l; i <= r; ++i)
#define DF(i, l, r) for(auto i = l; i >= r; --i)
#define clean(a) memset((a),0,sizeof (a))
#define sync ios_base::sync_with_stdio(0);cin.tie(0)
#define all(x) (x).begin(),(x).end()
#define ret return
#define cont continue
#define brk break
#define ins insert
#define sz(a) ((int)(a).size())

typedef long long ll;
typedef unsigned long long ull;
typedef long double dbl;
typedef pair <int, int> pii;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)1e9 + 7;
const dbl eps = (dbl)1e-8;
const int maxn = (int)1e5 + 5;
const dbl pi = acos(-1);

ll a[5], k;

int main() {
//	fin("t.in");
	sync;

	cin >> a[0] >> a[1] >> a[2] >> k;
	/*
	while (k--) {
		F(i, 0, 3) {
			b[i] = 0;
			F(j, 0, 3)
				if (i != j)
					b[i] += a[j];
		}
		F(i, 0, 3)
			a[i] = b[i];


	}
	*/
	if (k & 1)
		cout << a[1] - a[0] << endl;
	else
		cout << a[0] - a[1] << endl;
	return 0;
}

Measured memory_bytes: 384
using System;
using System.Linq;

class p{
  static void Main(){
    int n = int.Parse(Console.ReadLine());
    string[] w = new string[n];
    for(int i = 0; i < n; i++){
      w[i] = Console.ReadLine();
    }
    bool flag = true;
    for(int i = 1; i < n; i++){
      if(w[i][0] != w[i - 1][w[i - 1].Length - 1]) flag = false;
    }
    if(flag)
      for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
          if(w[i] == w[j]) flag = false;
        }
      }
    Console.WriteLine(flag ? "Yes" : "No");
  }
}

Measured memory_bytes: 13140
n = gets.to_i
sumt = 1
suma = 1

n.times do
  t, a = gets.split.map(&:to_i)

  x = if (suma / a) < (sumt / t)
        (sumt % t).zero? ? (sumt / t) : ((sumt / t) + 1)
      else
        (suma % a).zero? ? (suma / a) : (suma / a) + 1
      end

  sumt = t * x
  suma = a * x
end

p sumt + suma

Measured memory_bytes: 1788
from collections import deque

def main():
    s1 = deque()
    s2 = deque()
    total = 0

    string = input()

    for i in range(len(string)):
        if string[i] == '\\':
            s1.append(i)
        elif string[i] == '/' and len(s1) > 0:
            j = s1.pop()
            a = i - j
            total += a

            while (len(s2) > 0 and s2[-1][0] > j):
                a += s2[-1][1]
                s2.pop()

            s2.append((j, a))

    ans = []
    while (len(s2) > 0):
        ans.append(s2[-1][1])
        s2.pop()

    print(total)

    print(len(ans), *ans[::-1])

if __name__ == "__main__":
    main()

Measured memory_bytes: 8448
#include<bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define per(i,n) for(int i=n-1;i>=0;++i)
#define rep1(i,n) for(int i=1; i<=n; ++i)
#define per1(i,n) for(int i=n; i>=1; ++i)
#define debug cout << "line : " << __LINE__ << " debug" << endl
#define Dcout(N) cout << setprecision(20) << N << endl
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define INF 1e9
const int mod = 1000000007;
typedef long long ll;
//------------------------------------------------------------------------

ll gcd(ll a, ll b) {
  if(a<b) swap(a,b);
  return b ? gcd(b,a%b) : a;
}
 
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


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

  ll a,b; cin >> a >> b;
  
  ll ans = lcm(a,b);
  
  cout << ans << endl;
  
  
  return 0;
}





Measured memory_bytes: 256
N,X,Y = list(map(int,input().split(' ')))

ls = [0 for i in range(N-1)]

for i in range(1,N):
	for j in range(i+1,N+1):
		l = min(j-i,abs(i-X)+1+abs(j-Y))
		ls[l-1] = ls[l-1] + 1

for i in range(N-1):
	print(ls[i])

Measured memory_bytes: 3444
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        String s = sc.next();

        // 主処理
        int len = s.length();
        int countRed = len - s.replace("0", "").length();
        int countBlue = len - s.replace("1", "").length();
        int result = Math.min(countRed, countBlue) * 2;

        // 出力
        System.out.println(result);
        sc.close();
    }
}


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

int main(){
	int n;
	int a[102];
	scanf("%d",&n);
	for(int i = 0 ; i < n ; i ++){
		scanf("%d",&a[i]);
	}
	
	int ret = 1000000000;
	for(int x = -100 ; x <= 100 ; x ++){
		int sum = 0;
		for(int i = 0 ; i < n ; i ++){
			sum += (x-a[i])*(x-a[i]);
		}
		ret = min( ret , sum );
	}
	cout << ret << endl;
}
	

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

#define ll long long

const long double PI=acos(-1);

using namespace std;

ll gcd(ll a,ll b)

{

    if(b==0)

        return a;

    else

        return gcd(b,a%b);

}

bool prime(ll x)

{

    if(x==2)

    {

        return true;

    }

    else if(x<2||x%2==0)

    {

        return false;

    }

    else

    {

        for(int i=3;i*i<=x;i+=2) {

            if (x % i == 0) {

                return false;

            }

        }

        return true;

    }

}

int main()

{

  ll z;

  cin>>z;

  ll c=0,r=0,i=0;

  while(i<=1000000)

  {

      i++;

      c=(c*10+7)%z;

      if(c==0)

      {

          cout<<i;

          return 0;

      }

  }

      cout<<-1<<endl;

}

Measured memory_bytes: 3568
#include <stdio.h>

int main(){
    char ch[200];
    int m=0, h=0;
    int length=0, tmp=0;
    
    while(true){
        h=0, length=0;
        scanf("%s",ch);
        if(ch[0]=='-') break;
        scanf("%d",&m);
        for(int i=0;ch[i]!='\0';i++)length++;
        for(int i=0;i<m;i++){
            scanf("%d",&tmp);
            h+=tmp;
        }
        for(int i=h%length;i<length;i++) printf("%c",ch[i]);
        for(int i=0;i<h%length;i++) printf("%c",ch[i]);
        printf("\n");
    }
    return 0;
}


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

int main() {
    int N;
    cin >> N;
    
    vector<int> vec(N);
    
    for (int i = 0; i < N; i++) {
        cin >> vec.at(i);
    }
    
    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());
    
    int sum = 0;
    for (int i = 0; i < N; i++) {
        if (i % 2 == 0) sum += vec.at(i);
        if (i % 2 != 0) sum -= vec.at(i);
    }
    
    cout << sum << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main (void)
{
	int a,b,c;
	scanf("%d %d",&a,&b);
	c=a+b;
	if(c<a*b){
		c=a*b;
	}
	if(c<a-b){
		c=a-b;
	}
	printf("%d",c);
	return 0;
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10 ** 7)

N = int(input())

# s: 文字列
# n: これまでに使用した文字の種類数
def dfs(s:str, n:int):
    if len(s) == N:
        print(s)
        return
    
    maxc = ord("a") + n

    for c in range(ord("a"),  maxc + 1):
        dfs(s + chr(c), n+1 if (c == maxc) else n)

def main():
    dfs("", 0)

if __name__ == '__main__':
    main()

Measured memory_bytes: 4412
#include <iostream>
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) 
#define X first
#define Y second 
#define nl '\n'
#define AC return 0
#define mst(a,b) memset(a, b, sizeof a);
//#pragma GCC optimize(2)
using namespace std;
typedef long long ll;
typedef pair <int, int> PII;
const int N = 1e5+10, mod = 1e9+7, inf = 0x3f3f3f;
int a[N];

int main()
{
	int n;
	cin>>n;
	int ans = 0;
	for(int i = 1; i <= n; i++)
	{
		cin>>a[i];
		if((i&1)&&(a[i]&1))
			ans++;
	}
	cout<<ans<<nl;
	
	AC;
} 

Measured memory_bytes: 3192
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        aa: [usize1; n - 1],
    };

    let mut cc = vec![0; n];
    for a in aa {
        cc[a] += 1;
    }
    for c in cc {
        println!("{}", c);
    }
}


Measured memory_bytes: 5500
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int r;
	while (cin >> r, r) {
		vi h(2), w(2), x(2), y(2);
		vector<vvi> v(2);
		REP(i, 2) {
			cin >> w[i] >> h[i] >> y[i] >> x[i];
			x[i]--; y[i]--;
			vvi tmp(h[i], vi(w[i]));
			REP(k, h[i])REP(j, w[i]) {
				cin >> tmp[k][j];
			}
			v[i] = tmp;
		}
		vvi c(2, vi(r + 1, INF));
		REP(a, 2) {
			auto tmp = [&](pii l, pii r) {
				return v[a][l.first][l.second] > v[a][r.first][r.second];
			};
			priority_queue<pii, vector<pii>, decltype(tmp)> q(tmp);
			q.push({ x[a],y[a] });
			vvi b(h[a], vi(w[a], 0));
			b[x[a]][y[a]] = 1;
			int cnt = 0;
			c[a][0] = 0;
			while (!q.empty()) {
				pii p = q.top(); q.pop();
				cnt++;
				chmin(c[a][min(r, cnt)], v[a][p.first][p.second]);
				REP(k, 4) {
					int ni = p.first + dx[2 * k], nj = p.second + dy[2 * k];
					if (ni < 0 || nj < 0 || ni >= h[a] || nj >= w[a] || b[ni][nj] == 1)continue;
					b[ni][nj] = 1;
					q.push({ ni,nj });
				}
			}
		}
		REP(a, 2)REP(i, r)chmax(c[a][i + 1], c[a][i]);
		int ans = INF;
		REP(i, r + 1) {
			chmin(ans, c[0][i] + c[1][r - i]);
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 6992
#include <iostream>
#include <map>
#include <vector>
#define	int long long
using namespace	std;
map <int,int> b;
signed main(){
  int n,a[100000],r=0;
  vector<int> c;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
    if(!b[a[i]]) c.push_back(a[i]);
    b[a[i]]++;
  }
  for(int i=0;i<(int)c.size();i++){
    if(b[c[i]]>=c[i]) r+=b[c[i]]-c[i];
    else r+=b[c[i]];
  }
  cout<<r<<endl;
  return 0;
}



Measured memory_bytes: 7796
#include <iostream>
#include <vector>

// 给卡牌排序，判断冒泡排序和选择排序是否是稳定的排序，通过对比冒泡的结果和选择的排序结果可以判断选择排序是否为稳定的排序算法

using namespace std;

struct Card { char suit, value; };

void bubble(vector<Card> &arr, int n) {
  for (int i = 0; i < n; i++) {
    int j=1;
    while(j<n-i){
      if(arr[j].value<arr[j-1].value){
        Card t = arr[j];
        arr[j] = arr[j - 1];
        arr[j - 1] = t;
      }
        j++;
    }
  }
  return;
}

void selectSort(vector<Card> &arr, int n) {
  for (int i = 0; i < n; i++) {
    int minIndex = i;
    for (int j = i; j < n; j++) {
      if (arr[j].value < arr[minIndex].value) {
        minIndex = j;
      }
    }
    Card t=arr[i];
    arr[i]=arr[minIndex];
    arr[minIndex]=t;
  }
  return;
}

void printArr(vector<Card> arr,int n){
  for(int i=0;i<n;i++){
    if(i) cout<<" ";
    cout<<arr[i].suit<<arr[i].value;
  }
  cout<<endl;
  return;
}

bool isStable(vector<Card> arr1,vector<Card> arr2,int n){
  for(int i=0;i<n;i++){
    if(arr1[i].suit!=arr2[i].suit){
      return false;
    }
  }
  return true;
}

int main(){
  int n;
  vector<Card> arr1,arr2;
  cin>>n;
  for(int i=0;i<n;i++){
    Card t;
    cin>>t.suit;
    cin>>t.value;
    arr1.push_back(t);
    arr2.push_back(t);
  }

  bubble(arr1,n);
  selectSort(arr2,n);
  printArr(arr1,n);
  cout<<"Stable"<<endl;
  printArr(arr2,n);
  if(isStable(arr1,arr2,n)){
    cout<<"Stable"<<endl;
  }else{
    cout<<"Not stable"<<endl;
  }

  return 0;
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;

ll f(ll n, ll k){
    ll ret = 1;
    for(int i=1;i<=k;i++){
        ret = ret * (n+1-i) / i;
    }
    return ret;
}

int main(){
    ll n , p ; cin >> n >> p;
    ll odd = 0, even = 0;
    rep(i,n){
        ll x; cin >> x;
        if(x%2) odd++; else even++;
    }
    ll ans = 0;
    if(p==0){
        for(int i=0;i*2<=odd;i++){
            ans += f(odd,i*2);
        }
    }else{
        for(int i=1;2*i-1<=odd;i++){
            ans+= f(odd,2*i-1);   
        }
    }
    ans *= pow(2,even);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

void insertionSort(int);

int main(){
  int N;
  scanf("%d",&N);
  
  insertionSort(N);
  
  return 0;
}

void insertionSort(int N){
  int i, j, v, A[N], k;

  for(k = 0; k <= N - 1; k++)
    scanf("%d", &A[k]);
  
  for(k = 0; k <= N - 1; k++)
    if(k == N - 1)
      printf("%d", A[k]);
    else
      printf("%d ", A[k]);
  
  printf("\n");
  
  for(i = 1; i <= N - 1; i++){
    v = A[i];
    j = i - 1;
    while(j >= 0 && A[j] > v){
      A[j + 1] = A[j];
      j--;
    }
    A[j + 1] = v;
    
    for(k = 0; k <= N - 1; k++)
      if(k == N - 1)
	printf("%d", A[k]);
      else
	printf("%d ", A[k]);
    printf("\n");
  }
}



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

int main() {
	ll h,w,ans=0;
	cin >> h >> w;
	string str;
	vector<vector<char>>s(h,vector<char>(w));
	vector<vector<ll>>wtbl(h,vector<ll>(w));
	vector<vector<ll>>htbl(h,vector<ll>(w));
	rep(i,h){
		cin >> str;
		rep(j,w) s.at(i).at(j)=str.at(j);
	}
	rep(i,h){
		ll tmp=0,ind=0;
		rep(j,w){
			if(s.at(i).at(j)=='#'){
        wtbl.at(i).at(j)=0;
				for(ll k=ind;k<j;k++) wtbl.at(i).at(k)=tmp;
				ind=j+1;
				tmp=0;
			}
			else if(s.at(i).at(j)=='.' && j==w-1){
				tmp++;
				for(ll k=ind;k<=j;k++) wtbl.at(i).at(k)=tmp;
			}
			else tmp++;
		}
	}	
	rep(i,w){
		ll tmp=0,ind=0;
		rep(j,h){
			if(s.at(j).at(i)=='#'){
        htbl.at(j).at(i)=0;
				for(ll k=ind;k<j;k++) htbl.at(k).at(i)=tmp;
				ind=j+1;
				tmp=0;
			}
			else if(s.at(j).at(i)=='.' && j==h-1){
				tmp++;
				for(ll k=ind;k<=j;k++) htbl.at(k).at(i)=tmp;
			}
			else tmp++;
		}
	}		
	rep(i,h){
		rep(j,w) ans=max(ans,htbl.at(i).at(j)+wtbl.at(i).at(j)-1);
	}
	cout << ans << endl;
}


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

const int MOD = (int)1e9+7;

void dfs(vector<vector<pair<int,int>>> &graph,vector<int> &ans,int now,int parent,int color){
	ans.at(now)=color;
	
	for(int i=0;i<graph.at(now).size();i++){
		int next=graph.at(now).at(i).first;
		if(next==parent)	continue;
		if(graph.at(now).at(i).second==0)	dfs(graph,ans,next,now,color);
		else	dfs(graph,ans,next,now,1-color);
	}
}

int main(){
	int N;
	cin  >> N;
	vector<vector<pair<int,int>>> graph(N);
	for(int i=0;i<N-1;i++){
		int u,v,w;
		cin >> u >> v >> w;
		u--;
		v--;
		w%=2;
		graph.at(u).push_back(make_pair(v,w));
		graph.at(v).push_back(make_pair(u,w));
	}

	vector<int> ans(N,-1);
	dfs(graph,ans,0,-1,0);
	for(int i=0;i<N;i++){
		cout << ans.at(i) << endl;
	}
	
	return 0;
}


Measured memory_bytes: 10496
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;
 
template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
 
const double PI = acos(-1.0);
const int INF = 1e9 + 47;
const LL LINF = 1LL * INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


const int N = 50;
int cnt[N][N];

LL read()
{
	LL res;
	cin >> res;
	int pw = 1000 * 1000 * 1000;
	res *= pw;
	string s;
	getline(cin, s);
	FOR(i, 1, SZ(s))
	{
		pw /= 10;
		res += pw * (LL) (s[i] - '0');
	}
	
	return res;
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	FOR(i, 0, n)
	{
		LL x = read();
		int cnt2 = 0, cnt5 = 0;
		while(x % 2 == 0)
			cnt2++, x/= 2;
			
		while(x % 5 == 0)
			cnt5++, x/= 5;
		cnt[cnt2][cnt5]++;
	}
	LL ans = 0;
	FOR(i1, 0, N)
	{
		FOR(j1, 0, N)
		{
			FOR(i2, 0, N)
			{
				FOR(j2, 0, N)
				{
					if(i1 + i2 >= 18 && j1 + j2 >= 18)
					{
						if(i1 != i2 || j1 != j2)
						{
							ans += cnt[i1][j1] * (LL) cnt[i2][j2];
						}
						else
						{
							ans += cnt[i1][j1] * (LL) (cnt[i1][j1] - 1);
						}
					}
				}
			}
		}
	}
	//cout << ans << endl;
	cout << ans / 2 << endl;
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}
 



Measured memory_bytes: 3796
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int R = in.nextInt();
            System.out.println(R < 1200 ? "ABC" : R < 2800 ? "ARC" : "AGC");
        }
    }
}


Measured memory_bytes: 27076
import java.io.BufferedReader;
import java.io.InputStreamReader;


public class Main {

	public static void main(String[] args) throws Exception {
		// TODO ?????????????????????????????????????????????
		BufferedReader breader = getReader();
		int[] ary = getAryMl(breader);
		int maxdf = ary[1] - ary[0] ;
		for( int i = 0 ; i < ary.length-1 ; i++ ) {
			int maxj = i+1;
			int mini = i;
			int minik = i;
			for( int j = i+1 ; j < ary.length ; j++ ) {
				if ( ary[maxj] <= ary[j]) {
					maxj = j;
					mini = minik;
				}
				if ( ary[j] < ary[minik]) {
					minik = j;
				}
			}
//			for( int k = i+1 ; k < maxj ; k++ ) {
//				if ( ary[k] < ary[mini]) {
//					mini = k;
//				}
//			}
			int maxdfw = ary[maxj]- ary[mini];
			if ( maxdf < maxdfw) {
				maxdf = maxdfw ;
			}
			i = maxj;
		}
		System.out.println(maxdf);
		
	}
	public static BufferedReader getReader() {
		return( new BufferedReader(new InputStreamReader(System.in)));
	}
	public static int getInt(BufferedReader br)throws Exception {
		String line = br.readLine();
		return Integer.valueOf(line);
	}
	public static int[] getAry(BufferedReader br)throws Exception {
		String line = br.readLine();
		String[] nstr = line.split(" ");
		int[] n = new int[nstr.length];
		for( int i=0 ; i < nstr.length ; i++ ) {
			n[i] = Integer.valueOf(nstr[i]);
		}
		return n;
	}
	public static int[] getAryMl(BufferedReader br)throws Exception {
		int n = getInt(br);
		int[] ary = new int[n];
		for( int i=0 ; i < n ; i++ ) {
			ary[i] = getInt(br);
		}
		return ary;
	}
	public static void putAry(int[] ary, int num) {
		for( int i = 0; i < num ; i++ ) {
			System.out.print(ary[i]);
			if ( i < num-1) {
				System.out.print(" ");
			}
		}
		System.out.println("");
	}
	public static void putAry(int[] ary) {
		putAry(ary, ary.length ) ;
	}
	public static boolean isPrime(int n) {
		int r = (int)Math.sqrt((double)n)+1;
		for( int j = 2 ; j < r ; j += 1) {
			if ( n%j == 0 ) {
				return false;
			}
		}
		return true;
	}

}

Measured memory_bytes: 37920
N,M = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(M)]

# 1からN
se1 = set()
se2 = set()

for a,b in AB:
  if a>b:
    a,b = b,a
  if a == 1:
    se1.add(b)
  if b == N:
    se2.add(a)
    
se = se1 & se2
answer = 'POSSIBLE' if se else 'IMPOSSIBLE'
print(answer)

Measured memory_bytes: 46480
#include <bits/stdc++.h>
using namespace std;
int main (){
  int N,x;
  cin >> N >> x;
  vector<int> X(N);
  for (int i=0; i<N ; i++)
    cin >> X.at(i);
  sort(X.begin(),X.end()); //小さい順に下から引いていく
  
  int i ;
  for (i=0; i<N ; i++){
   if (x<0)
     break;
    else
      x -= X.at(i);//０より大きい限り引く
  }
  if (x != 0) 
    i--;
  cout << i <<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <random>
#include <iomanip>
#include <limits>
 
using namespace std;
 
typedef long long ll;
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
ll mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<int> G[100005];
std::vector<P> tree[100010];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define re(i,a,b) for(i=a;i<=b;i++)
 
ll i,j,k,l,ii,jj;
ll n,m,a,b,c,d,ans=INF,num,sum;
ll xx,yy,zz;
ll x[100005],y[100005],z[100005];
ll dp[500][500],cp[1500][1500];
 
int main(){
	cin>>n>>c;
	for(i=1;i<=c;i++){
		for(j=1;j<=c;j++){
			cin>>dp[i][j];
		}
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			cin>>cp[i][j];
			if((i+j)%3==0){
				x[cp[i][j]]++;
			}
			if((i+j)%3==1){
				y[cp[i][j]]++;
			}
			if((i+j)%3==2){
				z[cp[i][j]]++;
			}
		}
	}
	for(xx=1;xx<=c;xx++){
		for(yy=1;yy<=c;yy++){
			if(xx==yy)continue;
			for(zz=1;zz<=c;zz++){
				if(xx==zz || yy==zz)continue;
				sum = 0;
				for(i=1;i<=c;i++){
					sum += dp[i][xx]*x[i] + dp[i][yy]*y[i] + dp[i][zz]*z[i];
				}
				ans = min(ans,sum);
			}
		}
	}
	p(ans);

	return 0;

}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int H, W;
while(true){
cin >> H >> W;
if(H == 0 && W == 0){
break;
}

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



}
cout << endl;
}
cout <<endl;
}
}




Measured memory_bytes: 3088
import "dart:io";
import "dart:math";

main(){
  final int N = int.parse(stdin.readLineSync());
  List<int> A = stdin.readLineSync().split(" ").map((x) => int.parse(x)).toList();

  int ans = 0;
  var count = new List.generate(N, (i) => 0);
  for (int i = 0; i < N; i++){
    int tmp = 0;
    while (A[i] % 2 == 0){
      A[i] = A[i] ~/ 2;
      ++tmp;
    }
    count[i] = tmp;
  }
  ans = count.reduce(min);
  print(ans);
}


Measured memory_bytes: 13104
N,M = map(int,input().split())
A = []
B = []
for _ in range(M):
    L,R = map(int,input().split())
    A.append(L)
    B.append(R)
ans = min(B)-max(A)+1
if ans >= 0:
    print(ans)
else:
    print(0)

Measured memory_bytes: 55896
#!/usr/bin/ruby
# -*- coding: utf-8 -*-

def nwa(n, x)
  count = 0
  (1..n).each{|i|
    (1..(i-1)).each{|j|
      (1..(j-1)).each{|k|
#       printf("%d %d %d\n", i,j,k)
        if i+j+k == x then
          count += 1
#          printf("count=%d\n", count)
        else
        end
      }}}
  count
end

if __FILE__ == $0
  while gets
    fl=$_.chomp.split.map{|x| x.to_i}
    n = fl[0]
    x = fl[1]
    if n==0 and x==0 then break end
    puts nwa(n,x)
  end
end

Measured memory_bytes: 8788
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

const int MA_X = 1e-6;
const int MAxn = 2e5 + 5;

int main(){
    int n, a[MAxn];
    while(~scanf("%d", &n)){
        int y2 = 0, y4 = 0;
        memset(a, 0, sizeof(a));
        for(int i = 1; i <= n; i++){
            int x;
            cin >> x;
            while(x){
                if(x % 2 == 0){
                    a[i]++;
                    x /= 2;
                }
                else break;
            }
            if(a[i] >= 2) y4++;
            else if(a[i] == 1) y2++;
        }
        //printf("%d %d %d\n\n",n, y2, y4);
        if(y4 >= n/2) printf("Yes\n");
        else if(y2 == n-2*y4) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 1024
S = str(input())
a= [0,1,2,3]

judge = False

class E():
	def ex(self,S):
		m = S.replace('eraser' , '2')
		return m
		
class e():
	def ex(self,S):
		m = S.replace('erase' , '2')
		return m
		
class D():
	def ex(self,S):
		m = S.replace('dreamer','3')
		return m
		
class d():
	def ex(self,S):
		m = S.replace('dream','3')
		return m
		
		

a[0] = E()
a[1] = e()
a[2] = D()
a[3] = d()

for i in range(4):
	for j in range(4):
		for k in range(4):
			for l in range(4):
				m = a[i].ex(S)
				m = a[j].ex(m)
				m = a[k].ex(m)
				m = a[l].ex(m)
				
				try:
					int(m)
					print('YES')
					judge = True
				except:
					pass
				if judge == True:break
			if judge==True:break
		if judge==True:break
	if judge==True:break
	
if judge == False:
	print('NO')

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


bool water[31];
bool sugar[3001];


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

    //Available water gram
    for(int i = 0; 100*A*i <= F; i++) {
        for(int j = 0; 100*A*i + 100*B*j <= F; j++) {
            water[A*i + B*j] = true;
        }
    }

    //Available sugar gram
    for(int i = 0; C*i <= F; i++) {
        for(int j = 0; C*i + D*j <= F; j++) {
            sugar[C*i + D*j] = true;
        }
    }

    int sugarWater_amount = 100.0*A;
    int sugar_amount = 0;
    double percentage = 0.0;
    for(int i = A; i < 31; i++) {
        for(int j = 0; j < 3001; j++) {
            if(water[i] && sugar[j]) {
                if(100*i + j <= F && j <= i*E) {
                    double percentage_n = (100.0*j)/(100.0*i + j);
                    if(percentage_n > percentage) {
                        percentage = percentage_n;
                        sugarWater_amount = 100*i + j;
                        sugar_amount = j;
                    }
                }
            }
        }
    }
    cout << sugarWater_amount << " " << sugar_amount << endl;

    return 0;
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if ( A + B > C + D) {
    cout << " Left " << endl;
  }
  else if ( A + B < C + D) {
    cout << " Right " << endl;
  }
  else {
    cout << " Balanced " << endl;
  }
}


Measured memory_bytes: 3644
#include <stdio.h>
#include <stdlib.h>
#define sqr(x) ((x)*(x))

int main(void) {
	int n,x,y,i,j;
	int **magic;

	while (1) {
		scanf("%d",&n);
		if (n==0) break;
		magic = (int **)calloc(n,sizeof(int *));
		for (i=0;i<n;i++) magic[i] = (int *)calloc(n,sizeof(int));
		x = n/2;
		y = n/2+1;
		for (i=1;i<=sqr(n);i++) {
			if (magic[y][x]==0) magic[y][x] = i;
			else {
				while (magic[y][x]>0) {
					x = (x+n-1)%n;
					y = (y+1)%n;
				}
				magic[y][x] = i;
			}
			x = (x+1)%n;
			y = (y+1)%n;
		}
		for (i=0;i<n;i++) {
			for (j=0;j<n;j++) printf("%4d",magic[i][j]);
			putchar('\n');
			free(magic[i]);
		}
		free(magic);
	}

	return 0;
}

Measured memory_bytes: 624
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let s: String = scan(tokens);
    let ans = match s.as_str() {
        "SUN" => 7,
        "MON" => 6,
        "TUE" => 5,
        "WED" => 4,
        "THU" => 3,
        "FRI" => 2,
        "SAT" => 1,
        _ => unreachable!(),
    };
    println!("{}", ans);
}


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

int main(void)
{
    int A[200000];
    int idx = 0;

    char line[15];
    fgets(line, 15, stdin);
    int q = atoi(line);

    int i = 0;
    for (i = 0; i < q; i++) {
        fgets(line, 15, stdin);
        if (line[0] == '0') A[idx++] = atoi(line + 2);
        else if (line[0] == '1') printf("%d\n", A[atoi(line + 2)]);
        else idx--;
    }
    return 0;
}



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

int main() {
    int x, i = 1;
    while (true) {
        if (i>10000) return 0;
        cin >> x;
        if (x == 0) return 0;
        cout << "Case " << i << ": " << x << endl;
        i++;
    }
    return 0;
}


Measured memory_bytes: 3080
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;

int main() {
    int a, b; cin >> a >> b;
    cout << (a-1)*(b-1) << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define repr(i,a,n) for(ll i = n-1;i >= a;i--)
#define LINF (ll)1e17
#define INF 1e9
#define MOD (ll)1e9+7
#define sMOD 1e5
#define fs first
#define sc second
#define setprecision(d) cout << fixed << setprecision(d);

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
	
}

ll lcm(ll a,ll b){
	return a * b / gcd(a,b);
}

signed main(){
	ll n,k,ans = 0;
	cin >> n >> k;
	ll h[n];

	rep(i,0,n) cin >> h[i];

	sort(h,h+n);

	rep(i,0,n-k){
		ans += h[i];
	}

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

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
long long a[1000001];
	long long d[1000001];
int main()
{
	long long n,k;
	cin>>n>>k;
	
	
	for(long long i=1;i<=n;i++){
		cin>>a[i];
	}
	d[1]=0;
	d[2]=abs(a[2]-a[1]);
	for(long long i=3;i<=n;i++){
		long long k1=k,g=i-1,mn=1000000000;
		while(g>=1 && k1>=1){
			if(d[g]+abs(a[i]-a[g])<=mn){
			mn=d[g]+abs(a[i]-a[g]);
			}
			g--;
			k1--;
		}
		d[i]=mn;
		
	}
	cout<<d[n];
	
	
	
	return 0;
}

Measured memory_bytes: 5120
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
	/*input*/
	vector<int>x(3);
	for(int i = 0; i < 3; i++){
		cin >> x[i];
	}
	/*calculation*/
	int ans = 0;
	sort(x.begin(), x.end());
	for(; x[2] - x[1] >= 2; ans++){
		sort(x.begin(), x.end());
		if(x[2] - x[1] >= 2){
			x[1] += 2;
		}
		//printf("x[0]:%3d x[1]:%3d x[2]:%3d\n", x[0], x[1], x[2]);
	}
	for(; x[1] - x[0] >= 2; ans++){
		sort(x.begin(), x.end());
		if(x[1] - x[0] >= 2){
			x[0] += 2;
		}
		//printf("x[0]:%3d x[1]:%3d x[2]:%3d\n", x[0], x[1], x[2]);
	}
	sort(x.begin(), x.end());
	if(x[0] == x[1] && x[1] == x[2]){		//a, a, a	
		ans += 0;
	}else if(x[0] == x[1]){					//a - 1, a - 1, a
		ans += 1;
	}else if(x[1] == x[2]){					//a - 1, a, a
		ans += 2;
	}else if(x[0] < x[1] && x[1] < x[2]){	//a - 2, a - 1, a
		ans += 3;
	}
	/*output*/
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

int main(){
  bool b[100010]={1,1};
  for(ll i=2;i*i<100010;i++) if(!b[i]) for(ll j=i*i;j<100010;j+=i) b[j]=1;
  ll q,l,r,d[100010]={};
  cin>>q;
  Fr(i,100000){
    if((!b[i])&&(!b[(i+1)/2])) d[i]=d[i-1]+1;
    else d[i]=d[i-1];
  }
  fr(i,q){
    cin>>l>>r;
    cout<<d[r]-d[l-1]<<endl;
  }
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1000000000
#define  pow(x) pow(10,(x)) 
typedef long long int LL;
const int MOD = 1000000007;
//sort(all(x))とするとソートできるよ

int main(){
    int N;cin >> N;
    vector<int> h(N);
    rep(i,N){
        cin >> h[i];
    }                       //ここまで入力

    vector<int> hcopy(N);   //ソート実験用配列
    bool endo = true;       //while鍵
    int res = 0;            //回数

    while(endo){
        hcopy = h;
        sort(all(hcopy));
        if(hcopy[N-1] == 0){  //全部0だったら終わり
            endo = false;
            break;   
        }
        bool ct = true;
        rep(i,N){                           //一周
            if(ct && h[i] == 0){            //初0遭遇
                continue;
            }
            else if(ct && h[i] != 0){       //初!=0遭遇
                ct = false;
            }
            if(h[i] == 0){                  //二回目0遭遇
                res++;
                break;
            }
            else{                           //水やり
                h[i]--;
                if(i == N-1)res++;
            }
        }
    }

    cout << res << endl;
}

Measured memory_bytes: 256
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 08/22/20 18:13:52
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  string n; cin>>n;
  int ans = 0;
  for (auto c:n) {
    ans += c-'0';
  }
  cout << (ans%9 == 0 ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 3784
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = (1e9)+7;
void fastIO(){
  ios_base::sync_with_stdio(0); cin.tie(0);
}


int main(){
  fastIO();
  int n;
  cin>>n;
  vector<int>seq(n);
  for(int i=0;i<n;i++){
  	cin>>seq[i];
  }
  seq.erase(unique(seq.begin(), seq.end()), seq.end());
  int tot = 1;
  for(int i=1;i<seq.size()-1;i++){
  	if(seq[i]<min(seq[i-1],seq[i+1])||seq[i]>max(seq[i-1],seq[i+1])){
  		tot++;
  		i++;
  	}
  }
  cout<<tot<<endl;
}  



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

int main(){
  long long n;
  
  cin >> n;
  long long m = sqrt(n);
  long long i;
  for(i = m;i>=1;i--){
    if(n%i==0) break;
  }
  cout << i+n/i-2;
}

Measured memory_bytes: 256
from functools import lru_cache


def popcnt(x):
    return bin(x).count("1")


@lru_cache(maxsize=None)
def rec(n):
    if n == 0:
        return 0
    else:
        return rec(n % popcnt(n)) + 1


ret = [rec(x) for x in range(2 * 10**5 + 1)]


n = int(input())
arr = input()

ALL_ARR = int(arr, 2)

cnt = popcnt(int(arr, 2))
init_big = ALL_ARR % (cnt + 1)
if cnt == 1:
    init_small = 0
else:
    init_small = ALL_ARR % (cnt - 1)


li = [0] * n
for i in range(n):
    if arr[i] == "0":
        li[i] = (init_big + pow(2, n - i - 1, cnt + 1)) % (cnt + 1)
    elif ALL_ARR - (1 << (n - i - 1)) == 0 or cnt - 1 == 0:
        li[i] = "flg"
    else:
        li[i] = (init_small - pow(2, n - i - 1, cnt - 1)) % (cnt - 1)


ans = []

for x in li:
    if x == "flg":
        ans.append(0)
    else:
        ans.append(ret[x] + 1)

print(*ans, sep="\n")

Measured memory_bytes: 40964
n = int(input())
d = {}
for i in range(n):
    s, p = input().split()
    if d.get(s) == None:
        d[s] = [[int(p), i]]
    else:
        d.get(s).append([int(p), i])
for key in sorted(d.keys()):
    for v, i in sorted(d.get(key), key=lambda x: x[0], reverse=True):
        print(i+1)


Measured memory_bytes: 38384
#include<stdio.h>
#include<math.h>

struct Point {double x,y;};

void koch(int n,Point a,Point b){
  if(n==0)return;
  Point s,t,u;
  double th=M_PI*60.0/180.0;

  s.x=(2.0*a.x+1.0*b.x)/3.0;
  s.y=(2.0*a.y+1.0*b.y)/3.0;
  t.x=(1.0*a.x+2.0*b.x)/3.0;
  t.y=(1.0*a.y+2.0*b.y)/3.0;
  u.x=(t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
  u.y=(t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;

  koch(n-1,a,s);
  printf("%.8f %.8f\n",s.x,s.y);
  koch(n-1,s,u);
  printf("%.8f %.8f\n",u.x,u.y);
  koch(n-1,u,t);
  printf("%.8f %.8f\n",t.x,t.y);
  koch(n-1,t,b);

}

int main(){
  Point a,b;
  int n;

  scanf("%d",&n);

  a.x=0;
  a.y=0;
  b.x=100;
  b.y=0;

  printf("%.8f %.8f\n",a.x,a.y);
  koch(n,a,b);
  printf("%.8f %.8f\n",b.x,b.y);

  return 0;

}


Measured memory_bytes: 2692
#include<iostream>
#include<vector>
#include<algorithm>

enum Role
{
	NoRole,
	Onepair,
	TwoPair,
	ThreeCard,
	Straight,
	FullHouse,
	FourCard
};

std::vector<int> CountSameCard(std::vector<int> card)
{
	std::vector<int> count(5);

	std::sort(card.begin(),card.end());

	int memory =card[0];

	int j=0;

	for(size_t i=1; i<5; ++i)
	{
		if(card[i]==memory)
		{
			count[j] += 1;
		}
		else
		{
			++j;
		}

		memory = card[i];
	}

	std::sort(count.begin(), count.end());

	return count;
}

bool JudgeStraight(std::vector<int> card)
{
	const int SpecialStraight[5]=
	{
		1,
		10,
		11,
		12,
		13,
	};

	std::sort(card.begin(),card.end());

	int memory = card[0];

	size_t i = 1;

	for(; i<5; ++i)
	{
		if(!(card[i]==memory+1))
		{
			break;
		}

		memory = card[i];
	}

	size_t j=0;

	for(; j<5; ++j)
	{
		if(card[j]!=SpecialStraight[j])
		{
			break;
		}
	} 

	return (i==5) || (j==5);
}

Role JudgeRole(std::vector<int> count, bool straight)
{
	std::sort(count.begin(),count.end());

	int max = *max_element(count.begin(),count.end());

	if(max==3)
	{
		return FourCard;
	}

	if(max==2)
	{
		if(count[3]==1)
		{
			return FullHouse;
		}
	}

	if(straight)
	{
		return Straight;
	}

	if(max==2)
	{
		return ThreeCard;
	}


	if(max==1)
	{
		if(count[3]==1)
		{
			return TwoPair;
		}

		return Onepair;
	}
	else
	{
		return NoRole;
	}
}


int main()
{
	std::vector<int> card(5);

	char c;

	while(std::cin >> card[0] >> c >> card[1] >> c >> card[2] >> c >> card[3] >> c >> card[4])
	{
		switch(JudgeRole(CountSameCard(card),JudgeStraight(card)))
		{
		case FourCard:
			std::cout << "four card\n";
			break;
		case FullHouse:
			std::cout << "full house\n";
			break;
		case Straight:
			std::cout << "straight\n";
			break;
		case ThreeCard:
			std::cout << "three card\n";
			break;
		case TwoPair:
			std::cout << "two pair\n";
			break;
		case Onepair:
			std::cout << "one pair\n";
			break;
		case NoRole:
			std::cout << "null\n";
			break;
		}
	}
}

Measured memory_bytes: 1172
#include <iostream>

using namespace std;
using ll = long long;

void FastIO ()
{
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
}

int main ()
{
  FastIO();
  
  ll n, k;
  cin >> n >> k;
  cout << min(n%k, abs(n%k - k));
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int n;cin >> n;
    string ss[3];cin >> ss[0] >> ss[1] >> ss[2];
    int ans = 0;
    for(int i=0;i<n;i++){
        set<char> st;
        for(int j=0;j<3;j++){
            st.insert(ss[j][i]);
        }
        ans += st.size()-1;
    }
    cout << ans << endl;
    return 0;
}


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int dn[61];
int isum[61];
int ksum[61];

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

	int N, K;
	int A;
	cin >> N >> K;

	rep(i, 0, N)
	{
		cin >> A;
		rep(j, 0, 61)
		{
			if ((A & (1LL << j)))
			{
				dn[j]++;
			}
		}
	}

	rep(i, 0, 61)
	{
		isum[i] = (1LL << i)*max(dn[i], N - dn[i]);
		ksum[i] = (1LL << i)*((K & (1LL << i)) ? N - dn[i] : dn[i]);
		if (0 < i)
		{
			isum[i] += isum[i - 1];
			ksum[i] += ksum[i - 1];
		}
	}

	int ans = ksum[60];
	rep(i, 0, 61)
	{
		if ((K & (1LL << i)))
		{
			int t = 0;
			t += ksum[60] - ksum[i];
			t += (1LL << i)*dn[i];
			if (0 <= i - 1)t += isum[i - 1];
			chmax(ans, t);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)


int main() {
    int a;
    string s;
    cin >> a;
    cin >> s;
    if (a >= 3200) cout << s << endl;
    else cout << "red" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
int main(){
  ll N;
  cin >> N;
  vector<int> digit;
  while(N!=0){
    if(N%2!=0){
      digit.push_back(1);
      N -= 1;
    }else{
      digit.push_back(0);
    }
    N /= (-2);
  }

  if(digit.empty()){
    cout << 0 <<endl;
  }else{
    int l = digit.size();

    for(int i=0;i<l;i++){
      cout << digit[l-i-1];
    }
    cout <<endl;
  }
   
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

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

int main(void) {
  int i,j;
  int n;
  string s1,s2;
  cin>>s1;
  cin>>s2;
  if(s1[0]==s2[2]&&s1[1]==s2[1]&&s1[2]==s2[0])cout<<"YES"<<endl;
  else cout<<"NO"<<endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	
	int n;
	cin>>n;
	vector<int> v(n),w(n);
	for(int i=0;i<n;i++)
		cin>>v[i];
	sort(v.begin(),v.end());
	w=v;
    v.erase(unique(v.begin(),v.end()),v.end());
    if(v.size()>3) return puts("No"),0;
    if(v.size()==1)
    	if(v[0]==0) return puts("Yes"),0;
    	       else return puts("No"),0;
    if(v.size()==2)
    {
    	int i;
    	for(i=0;i<w.size();i++)
    		if(w[i]) break;
    	if(i*3==w.size()) return puts("Yes"),0;
    	return puts("No"),0;
    }
    if(v.size()==3)
    {
    	int i,j;
    	if((v[0]^v[1])!=v[2] || (v[0]^v[2])!=v[1]) return puts("No"),0;
    	for(i=0;i<w.size();i++)
    		if(w[i]!=w[0]) break;
    	for(j=w.size()-1;j>=0;j--)
    		if(w[j]!=w[w.size()-1]) break;
    	if(3*i!=w.size() || 3*(w.size()-1-j)!=w.size()) return puts("No"),0;
    	return puts("Yes"),0;
    }
	
	return 0;
}

Measured memory_bytes: 1024
def main():
    s = input()
    q = int(input())
    left = ""
    right = ""
    hanten = False
    for i in range(q):
        query = input().split()
        if query[0] == "1":
            hanten = not hanten
        else:
            c = query[2]
            if query[1] == "1":
                if not hanten:
                    left += c
                else:
                    right += c
            else:
                if not hanten:
                    right += c
                else:
                    left += c
        #print(query)
        #print(s,left,right)
    left = left[::-1]
    answer = left + s + right

    if not hanten:
        print(answer)
    else:
        print(answer[::-1])


if __name__ == '__main__':
    main()


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

typedef long long ll;

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

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int>v(n);
	
	rep(i ,n){
		int tmp;
		cin >> tmp;
		
		v[tmp -1] = i + 1;
	}
	
	rep(i ,n){
		cout << v[i] << endl;
	}
	
	return 0;
}
		

Measured memory_bytes: 1152