akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int debug = 0;

#define pos(i,j) (3*(i-1)+j-1)

int main()
{
    int a[10];
    bool open[10];
    int n;
    cin >> a[0] >> a[1] >> a[2];
    cin >> a[3] >> a[4] >> a[5];
    cin >> a[6] >> a[7] >> a[8];

    cin >> n;
    int b;
    rep(i, 9) open[i] = false;

    rep(i,n){
        cin >> b;
        rep(j,9){
            if(a[j]==b)
                open[j] = true;
        }
    }
    bool ans = false;
    if(open[0]&&open[3]&&open[6])
        ans = true;
    if (open[1] && open[4] && open[7])
        ans = true;
    if (open[2] && open[5] && open[8])
        ans = true;
    if (open[0] && open[1] && open[2])
        ans = true;
    if (open[3] && open[4] && open[5])
        ans = true;
    if (open[6] && open[7] && open[8])
        ans = true;
    if (open[0] && open[4] && open[8])
        ans = true;
    if (open[2] && open[4] && open[6])
        ans = true;

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

    return 0;
}

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

// 入力
long long N;

// cur: 現在の値、use: 7, 5, 3 のうちどれを使ったか, counter: 答え
void func(long long cur, int use, long long& counter) {
	if (cur > N) return; // ベースケース
	if (use == 0b111) ++counter; // 答えを増やす

	// 7 を付け加える
	func(cur * 10 + 7, use | 0b001, counter);

	// 5 を付け加える
	func(cur * 10 + 5, use | 0b010, counter);

	// 3 を付け加える
	func(cur * 10 + 3, use | 0b100, counter);
}

int main() {
	cin >> N;
	long long res = 0;
	func(0, 0, res);
	cout << res << endl;
}

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

string tbl = ">v<^";

struct P{
	int id;
	int p[4];
	P(){
		id = -1;
		memset(p,-1,sizeof(p));
	}
};
P ps[3010];



int dfs(int id){
	if( id == -1 ) return 0;
	int tmp[4];
	memcpy(tmp,ps[id].p,sizeof(tmp));
	for(int i = 0 ; i < 4 ; i++){
		if(ps[id].p[i] != -1 ){
	
			assert( ps[ps[id].p[i]].p[(i+2)%4] == id );
			ps[ps[id].p[i]].p[(i+2)%4] = tmp[(i+2)%4];
		}
	}
	
	int ans = dfs(ps[id].p[ps[id].id]);
	for(int i = 0 ; i < 4 ; i++){
		if( tmp[i] != -1 ){
			assert( ps[tmp[i]].p[(i+2)%4] != id );
			ps[tmp[i]].p[(i+2)%4] = id;
		}
	}
	return ans + 1;
	
}
int main(){
	int n;
	cin >> n;
	map<int, vector< pair<int,int> > > col,row;
	for(int i = 0 ; i < n ; i++){
		int x,y;
		char c;
		cin >> x >> y >> c;
		y*= -1;
		int id = tbl.find(c);
		ps[i].id = id;
		col[x].push_back({y,i});
		row[y].push_back({x,i});
	}		
	for( auto &i : col ) sort(i.second.begin(),i.second.end());
	for( auto &i : row ) sort(i.second.begin(),i.second.end());
	
	for( auto &i : col ){
		
		auto& seq = i.second;
		{
			int prv = -1;
			for(int j = 0 ; j < seq.size() ; j++){
				ps[seq[j].second].p[1] = prv;
				prv = seq[j].second;
			}
		}
		{
			int prv = -1;
			for(int j = seq.size() - 1 ; j >= 0 ; j--){
				ps[seq[j].second].p[3] = prv;
				prv = seq[j].second;
			}
		}
	}
	
	for( auto &i : row ){
		auto& seq = i.second;
		{
			int prv = -1;
			for(int j = 0 ; j < seq.size() ; j++){
				ps[seq[j].second].p[2] = prv;
				prv = seq[j].second;
			}
		}
		{
			int prv = -1;
			for(int j = seq.size() - 1 ; j >= 0 ; j--){
				ps[seq[j].second].p[0] = prv;
				prv = seq[j].second;
			}
		}
	}
	int answer = 0;
	for(int i = 0 ; i < n ; i++){
		answer = max(answer,dfs(i));
		//cout << i << " " << dfs(i) << endl;
	}
	cout << answer << endl;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const ll INF=1e18;
const int MOD=1e9+7;
const double pi=acos(-1);
int n;
int vec[100010];
void solve(){
  int l=0,r=n;
  cout << 0 << endl;
  string s;
  cin >> s;
  if(s[0]=='V')return;
  if(s[0]=='M')vec[0]=1;
  if(s[0]=='F')vec[0]=2;
  
  while(true){
    int c=(r+l)/2;
    cout << c << endl;
    string t;
    cin >> t;
    if(t[0]=='V')return;
    if(t[0]=='M')vec[c]=1;
    if(t[0]=='F')vec[c]=2;
    
    if((c-l)%2^vec[c]==vec[l])l=c;
    else r=c;
  }
}
  
int main(){
  cin >> n;
  int t=1;
  while(t--){
    solve();
  }
  return 0;
  
}


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N, K;
    cin >> N >> K;
    vec A(N+1, 0);
    ll s;
    REP(i,1,N+1) {
        cin >> A[i];
        if(A[i] == 1) s = i;
    }
    PR((N+K-3)/(K-1));
    
    return 0;
}

/*

7 3 1 8 4 6 2 5
1 1 1
    1 1 1
        1 1 1
            1 1
*/

Measured memory_bytes: 3944
n=int(input())
dp=[[0]*(n) for _ in range(3)]
l=[]
for i in range(n):
    a,b,c=map(int,input().split())
    l.append([a,b,c])
dp[0][0],dp[1][0],dp[2][0]=l[0][0],l[0][1],l[0][2]
for i in range(0,n-1):
    dp[0][i+1]=max(dp[1][i]+l[i+1][0],dp[2][i]+l[i+1][0])
    dp[1][i+1]=max(dp[0][i]+l[i+1][1],dp[2][i]+l[i+1][1])
    dp[2][i+1]=max(dp[0][i]+l[i+1][2],dp[1][i]+l[i+1][2])
print(max([dp[0][n-1],dp[1][n-1],dp[2][n-1]]))


Measured memory_bytes: 65880
using System;

namespace HelloWorld
{
    class Program
    {
        static void Main()
        {
            while (true)
            {
                string alpha = Console.ReadLine();
                string[] beta = alpha.Split(' ');
                int a = int.Parse(beta[0]);
                int b = int.Parse(beta[2]);
                string op = beta[1];
                if (op == "+") Console.WriteLine(a + b);
                else if (op == "-") Console.WriteLine(a - b);
                else if (op == "*") Console.WriteLine(a * b);
                else if (op == "/") Console.WriteLine(a / b);
                else break;
            }
        }

    }
}




Measured memory_bytes: 15960
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define dup(x, y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using vp = vector<P>;
using vt = vector<T>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
  int n;
  cin >> n;
  vi a(n);
  REP(i, n-1) cin >> a[i];
  REP(i, n-1) a[i]--;
  vi c(n);
  REP(i, n-1) c[a[i]]++;
  REP(i, n) cout << c[i] << endl;

  return 0;
}

Measured memory_bytes: 4844
#include <bits/stdc++.h>
#define ll long long
#define REV(v) reverse(v.begin(), v.end());
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, start, stop) for (ll i = start; i < stop; i++)
#define FORR(i, start, stop) for (ll i = start; i > stop; i--)
#define SORT(v, n) sort(v, v + n);
#define SORTR(v, n) sort(v, v + n,greater<ll>());
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.begin(), v.end(),greater<ll>());
#define REMOVE(v,n) remove(vector<ll> v,v+v.size(),ll n)
#define ERASE(v,n) v.erase(v.begin()+n);
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
#define V(v,i,j) vector(v.begin() + i, v.begin() + j)
#define INSERT(va,vb) va.insert(va.end(), vb.begin(), vb.end())
using namespace std;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
const int MOD = 1000000007;
void chmin(int &a, int b) { if (a > b) a = b; }

//vector< vector<int> > v (size1, vector<int>(size2) );



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll K,S;
    cin>>K>>S;
    ll ans=0;
    ll z;


    FOR(x,0,K+1){
        FOR(y,0,K+1){
            z=S-x-y;
            if(z>=0 && z<=K){  
                ans++;
            }
        }
    }
    
    cout<<ans<<endl;

    return 0;
}

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

class Main {
	public static void main(String... args) {
		int N = IN.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = IN.nextInt();
		}

		int ans = 0;
		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				int tmp = Math.abs(A[i] - A[j]);
				if (tmp > ans) {
					ans = tmp;
				}
			}
		}
		puts(ans);
		flush();
	}
	static final Scanner IN = new Scanner(System.in);
	static final PrintWriter OUT = new PrintWriter(System.out);
	static <T> void puts(T arg) { OUT.println(arg); }
	static void flush() { OUT.flush(); }
}


Measured memory_bytes: 21716
use std::io::stdin;
use std::str::FromStr;

fn main(){
    let (n, k): (i64, i64) = get_pair();
    let mut ans = 0;

    ans += (n/k) * (n/k) * (n/k);

    if k%2 == 0 && n >= k/2 {
        let s = k/2;
        ans += ((n-s)/k+1) * ((n-s)/k+1) * ((n-s)/k+1);
    }

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

#[allow(dead_code)]
fn get_line() -> String {
    let mut s = String::new();
    match stdin().read_line(&mut s){
        Ok(_) => {s.trim().to_string()}
        Err(_) => String::new()
    }
}

#[allow(dead_code)]
fn get_vec<T: std::str::FromStr>() -> Vec<T> {
    let line = get_line();
    line.split_whitespace().filter_map(|x| x.parse().ok()).collect()
}

#[allow(dead_code)]
fn get_one<T: FromStr + Copy>() -> T {
    let v = get_vec();
    v[0]
}

#[allow(dead_code)]
fn get_pair<T: FromStr + Copy>() -> (T, T) {
    let v = get_vec();
    (v[0], v[1])
}

#[allow(dead_code)]
fn get_triple<T: FromStr + Copy>() -> (T, T, T) {
    let v = get_vec();
    (v[0], v[1], v[2])
}

#[allow(dead_code)]
fn get_chars() -> Vec<char> {
    get_line().chars().collect()
}


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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	string s;
	int w;
	cin>>s>>w;
	string t;
	int pos=0;
	while(pos<s.size()){
		t += s[pos];
		pos += w;
	}
	cout<<t<<endl;
	return 0;
}

Measured memory_bytes: 256
/*
link: 
tags: 
*/
#include<bits/stdc++.h>
#define to_l(a) ((a)<<1)
#define to_r(a) ((a)<<1|1)
#define lowbit(a) ((a)&(-a))
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
const int int_inf=0x3f3f3f3f;
const ll ll_inf=0x3f3f3f3f3f3f3f3f;
const int max_n=1e5+5;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int i,j;
	int a;
	cin>>a;
	cout<<!a<<endl;
	return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
 
int main(void){
    vector<pair<int,int>> food(5);
    for(int i = 0;i < 5;i++){
        cin >> food[i].second;
        food[i].first = food[i].second % 10;
        if(food[i].first == 0){
            food[i].first = 10;
        }
    }

    sort(food.begin(),food.end(),greater<pair<int,int>>());
    int sum = 0;
    for(int i = 0;i < 5;i++){
        if(i == 4){
            sum += food[i].second;
        } else {
            sum += 10*((food[i].second+10-1)/10); //(n+m-1)/m = 切り上げの公式
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);

using namespace std;

vector<vector<int>> child;

int dfs(int node){
    vector<int> v;

    for(int i=0;i<child[node].size();i++){
        v.push_back(dfs(child[node][i]));
    }
    sort(ALL(v));
    int tmp = 0;
    for(int i=0;i<v.size();i++){
        tmp = max(tmp,(int)( (v.size() - i) + v[i]));
    }
    return tmp;
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
    cin >> N;
    child.resize(N);
    rep(i,N-1){
        int a;
        cin >> a;
        a--;
        child[a].push_back(i+1);
    }
    cout << dfs(0) << endl;
}

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

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

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

	int ans=1;
	for(int i=0;i<N-1;i++){
		if(S.at(i)!=S.at(i+1))	ans++;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 512
def uf_find(n,p):

    ufl = []

    while p[n] != n:
        ufl.append(n)
        n = p[n]

    for i in ufl:
        p[i] = n

    return n


def uf_union(a,b,p,rank):

    ap = uf_find(a,p)
    bp = uf_find(b,p)

    if ap == bp:
        return True
    else:

        if rank[ap] > rank[bp]:
            p[bp] = ap
        elif rank[ap] < rank[bp]:
            p[ap] = bp
        else:
            p[bp] = ap
            rank[ap] += 1

        return False

N,M = map(int,input().split())

p = [i for i in range(N)]
rank = [0] * N

for i in range(M):

    A,B = map(int,input().split())
    A -= 1
    B -= 1
    uf_union(A,B,p,rank)

ans = 0
for i in range(N):
    if uf_find(i,p) == i:
        ans += 1
print (ans-1)


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

int a[3][3];
int d[3][3];

int main()
{
  rep(i, 3) rep(j, 3) cin >> a[i][j];
  int n;
  cin >> n;
  rep(ni, n)
  {
    int x;
    cin >> x;
    rep(i, 3)rep(j, 3) if (a[i][j] == x) d[i][j] = 1;
  }

  bool ans = false;

 // 横のビンゴを算出
  rep(i, 3){
    int cnt = 0;
    rep(j, 3) cnt += d[i][j];
    if (cnt ==3 ) ans = true;
  }
 // 縦のビンゴを算出
  rep(i, 3){
    int cnt = 0;
    rep(j, 3) cnt += d[j][i];
    if (cnt ==3 ) ans = true;
  }

  {
    int cnt = 0;
    rep(i, 3) cnt += d[i][i];
    if (cnt ==3 ) ans = true;
  }

  {
    int cnt = 0;
    rep(i, 3) cnt += d[i][2 - i];
    if (cnt ==3 ) ans = true;
  }

  puts(ans?"Yes":"No");
  return 0;
}


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

int main()
{
    int N;
    cin >> N;
    int di;
    vector<int> D;
    for(int i=0;i<N;i++){
        cin >> di;
        D.push_back(di);
    }
    sort(D.begin(), D.end());
    cout<<D[N/2]-D[N/2-1]<<endl;

    return 0;
}

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

int main(){
    long long x;
    cin >>x;
    
    /*rep(i,10){
        int a  = pow(i+1,5) - pow(i,5);
        cout << i+1 << "-"<<i <<" " <<a <<endl;
    }*/
    
    rep(i,1000){
        for(int j = -1000;j<1000;j++){
         long long a = pow(i,5) - pow(j,5);
            if(a == x){
                cout<<i<<" " <<j<<endl;
                return 0;
            }
        }
    }
    

}


Measured memory_bytes: 4036
#include <iostream>

int main() {
    char s[3];
    int count{0};
    for (int i = 0; i < 3; ++i) {
        std::cin >> s[i];
        if (s[i] == 'R') {
            count++;
        } else {
        }
    }

    if (s[0] == 'R' && s[1] == 'S' && s[2] == 'R') {
        count = 1;
    }
    std::cout << count << std::endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  string S;
  cin>>S;
  cout<<S.substr(0,3)<<endl;
  return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <iomanip>
#include <bits/stdc++.h>
#include <fstream>
#include <map>
using namespace std;
typedef long long ll;
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)


int main(){
  int n,A=0,W=0,T=0,R=0;
  string s;
  cin >> n;
  REP(i,n){
    cin >> s;
    if(s=="AC") A++;
    if(s=="WA") W++;
    if(s=="TLE") T++;
    if(s=="RE") R++;
  }
  cout << "AC" << " x " << A << endl;
  cout << "WA" << " x " << W << endl;
  cout << "TLE" << " x " << T << endl;
  cout << "RE" << " x " << R << endl;
  return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> edge;

ll edg[100005][3];
queue<ll> pedg[100005];
queue< pair<ll,ll> > searching;
ll n;

int main(){
    cin >> n;
    for(ll i=0; i<n-1; i++){
        cin >> edg[i][0] >> edg[i][1];
        edg[i][2] = 0;
        pedg[edg[i][0]].push(i);
        pedg[edg[i][1]].push(i);
    }

    ll mx = 0;
    for(ll i=1; i<n; i++){
        if( pedg[i].size() > mx ) mx = pedg[i].size();
    }

    searching.push(make_pair(1,0));
    ll cl_cnt = 1;
    while(!searching.empty()){
        pair<ll, ll> search_index = searching.front();
        searching.pop();
        ll pt = search_index.first;
        ll prnt_cl = search_index.second;
        while( !pedg[pt].empty() ){
            ll edge_num = pedg[pt].front(); pedg[pt].pop();
            ll pt_child;
            if( edg[edge_num][0] == pt) pt_child = edg[edge_num][1];
            else pt_child = edg[edge_num][0];
            if( cl_cnt == prnt_cl) {
                cl_cnt++;
                if( cl_cnt > mx ) cl_cnt=1;
            }
            if( edg[edge_num][2] == 0){
                edg[edge_num][2] = cl_cnt;
                searching.push(make_pair(pt_child, cl_cnt));
                cl_cnt++;
                if( cl_cnt == prnt_cl)  cl_cnt++;
                if( cl_cnt > mx ) cl_cnt=1;
            }

        }
    }

    cout << mx << endl;
    for( ll i=0; i<n-1; i++){
        cout << edg[i][2] << endl;
    }
    return 0;
}


Measured memory_bytes: 70272
#include <iostream>
#include <map>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
	int n, f, k = 0;
	map<pair<string, string>, int> db;

	cin >> n >> f;

	for (int i = 0; i < n; i++) {
		int m;
		string s1[10];
		cin >> m;

		for (int i = 0; i < m; i++)
			cin >> s1[i];

		sort(s1, s1 + m);

		for (int i = 0; i < m - 1; i++) {
			for (int j = i + 1; j < m; j++) {
				pair<string, string> p1 = make_pair(s1[i], s1[j]);

				if (db.find(p1) != db.end()) {
					db[p1]++;
					if (db[p1] == f)
						k++;
				}
				else {
					db[p1] = 1;
					if (f == 1)
						k++;
				}
			}
		}
	}

	cout << k << endl;
	for (map<pair<string, string>, int>::iterator itr = db.begin(); itr != db.end(); itr++)
		if(itr->second >= f)
			cout << itr->first.first << " " << itr->first.second << endl;

	return 0;
}



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

int main(){
  int N;
  cin >> N;
  int A,cnt,cntmin=10000000;
  for(int i = 0; i < N; ++i){
    cnt = 0;
    cin >> A;
    while((A%2) == 0){
      cnt++;
      A /= 2;
    }
    cntmin = min(cnt,cntmin);
  }
  cout << cntmin << endl;
  
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code
int main(int argc, char const* argv[])
{
	LL a,b,c,k;
	cin >> a >> b >> c >> k;
	if (k % 2 == 0) {
		cout << a-b << endl;
	}
	else {
		cout << b-a << endl;
	}
	return 0;
}



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

using Vertex = std::uint32_t;
using Weight = std::uint32_t;
using Graph = std::vector<std::vector<std::pair<Vertex, Weight>>>;

const auto Inf = std::numeric_limits<Weight>::max();
std::vector<Weight> Dijkstra(const Vertex s, const Graph& g)
{
    auto n = g.size();
    auto dist = std::vector<Weight>(n, Inf);
    dist[s] = 0;

    auto comp = [](auto x, auto y) { return x.second > y.second; };
    auto q =
        std::priority_queue<std::pair<Vertex, Weight>, std::vector<std::pair<Vertex, Weight>>, decltype(comp)>(comp);

    auto visited = std::vector<bool>(n, false);
    q.emplace(s, dist[s]);
    while (!q.empty())
    {
        auto v = q.top().first;
        q.pop();

        if (visited[v]) continue;

        visited[v] = true;

        for (const auto& node : g[v])
        {
            auto v_n = node.first;
            auto d_n = node.second;

            if (dist[v_n] > dist[v] + d_n)
            {
                dist[v_n] = dist[v] + d_n;
                q.emplace(v_n, dist[v_n]);
            }
        }
    }
    return dist;
}
int main()
{
    auto n = Vertex();
    auto m = Vertex();
    auto r = Weight();

    std::cin >> n >> m >> r;

    auto c = std::vector<Vertex>(r);
    for (Vertex i = 0; i < r; ++i)
    {
        std::cin >> c[i];
        --c[i];
    }
    std::sort(c.begin(), c.end());

    auto g = Graph(n);
    for (Vertex i = 0; i < m; ++i)
    {
        Vertex a;
        Vertex b;
        Vertex w;

        std::cin >> a >> b >> w;

        g[a - 1].emplace_back(b - 1, w);
        g[b - 1].emplace_back(a - 1, w);
    }

    auto dist_list = std::vector<std::vector<Weight>>();
    dist_list.reserve(r);
    for (Vertex s = 0; s < n; ++s)
    {
        dist_list.emplace_back(Dijkstra(s, g));
    }

    auto result = Weight(Inf);
    do
    {
        auto distance = Weight(0);
        for (Vertex i = 0; i < r - 1; ++i) distance += dist_list[c[i]][c[i + 1]];

        if (distance < result) result = distance;

    } while (std::next_permutation(c.begin(), c.end()));

    std::cout << result << std::endl;

    return 0;
}

Measured memory_bytes: 896
n,k = map(int,input().split())
S = input()
h = 'o'
if S[k-1] == 'A':
  h = 'a'
elif S[k-1] == 'B':
  h = 'b'
else:
  h = 'c'
print(S[:k-1]+h+S[k:])

Measured memory_bytes: 2940
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int n, i;
    int a[100];
    scanf("%d", &n);
    for(i=0; i<n; i++){
        scanf("%d", &a[i]);
    }
    for(i=n-1; i>=0; i--) {
        printf("%d", a[i]);
        if(i != 0){
            printf(" ");
        }
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2044
#include <iostream>
int main() {

    int a, b, c;

    std::cin >> a;
    std::cin >> b;
    std::cin >> c;

    if (a < b && b < c) {
        std::cout << "Yes\n";
    } else {
        std::cout << "No\n";
    }
      
    return 0; 
}    



Measured memory_bytes: 3088
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cassert>
#include<cstring>
using namespace std;

#define sz(x) (int)(x.size())
#define fi(a,b) for(int i=a;i<b;++i)
#define fj(a,b) for(int j=a;j<b;++j)
#define fo(a,b) for(int o=a;o<b;++o)
#define fdj(a,b) for(int j=a-1;j>=b;--j)
#define pb push_back
typedef long long ll;
/////////////////////

int const N = 5e5 + 41;

int l[N];

string str;
int n;

vector<int> getdivisors(int n){
	vector<int> res;
	res.pb(1);
	while(n > 1){
		int m = sz(res);
		fdj(m, 0) res.pb(res[j] * l[n]);
		n /= l[n];
	}
	return res;
}

void init(){
	for(int i=2;i<N;++i){
		if(!l[i]){
			for(int j=i;j<N;j+=i){
				if(l[j] == 0 || l[j] > i) l[j] = i;
			}
		}
	}
}

namespace Hash{
	static int const K = 3;
	int h[K][N], d[K][N];
	static int const P[K] = {63, 61, 59};
	static int const MOD[K] = {1000001531, 1000002187, 1000002193};//, 1000000007, 1000002277};

	int mul(int a, int b, int mod){
		return (ll) a * b % mod;
	}

	int sum(int a, int b, int mod){
		a %= mod;
		while(a < 0) a += mod;
		b %= mod;
		while(b < 0) b += mod;
		return (a + b) % mod;
	}

	void build(){
		fi(0, K) d[i][0] = 1;
		fi(1, N) fj(0, K){
			d[j][i] = mul(d[j][i-1], P[j], MOD[j]);
		}
		fi(0, sz(str)) fj(0, K){
			h[j][i] = mul( (i ? h[j][i-1] : 0), P[j], MOD[j]);
			h[j][i] = sum(h[j][i], (str[i] - 'a' + 1), MOD[j]);
		}
	}

	vector<int> gethash(int l, int r){
		vector<int> res;
		fi(0, K){
			int x = h[i][r];
			if(l) x = sum(x, -mul(h[i][l-1], d[i][r-l+1], MOD[i]), MOD[i]);
			res.pb(x);
		}
		return res;
	}
};

bool checkone(){
	fi(1, n){
		if(n % i == 0){
			vector<int> h = Hash::gethash(0, i-1);
			bool ok = true;
			for(int j=0;j<n;j+=i){
				vector<int> h0 = Hash::gethash(j, j+i-1);
				if(h0 != h){
					ok = false;
					break;
				}
			}
			if(ok) return false;
		}
	}	
	return true;
}

bool checkall(){
	fi(0, sz(str)) if(str[i] != str[0]) return false;
	return true;
}

int p[N], s[N];

void build(){
	fi(0, n+1) p[i] = s[i] = 1;
	fi(1, n+1){
		vector<int> h = Hash::gethash(0, i-1);
		for(int j=i+i;j<=n;j+=i){
			vector<int> h0 = Hash::gethash(j-i, j-1);
			if(h != h0) break;
			p[j-1] = 0;
		}
	}
	fi(1, n+1){
		vector<int> h = Hash::gethash(n-i, n-1);
		for(int j=i+i;j<=n;j+=i){
			vector<int> h0 = Hash::gethash(n-j, n-j+i-1);
			if(h != h0) break;
			s[n-j] = 0;
		}
	}
}

int checktwo(){
	int res = 0;
	fi(0, n-1){
		res += (p[i] && s[i+1]);
	}
	return res;
}

void solve(){
	n = sz(str);
	Hash::build();
	if(checkall()){
		cout << n << " " << 1 << endl;
		return;
	}
	if(checkone()){
		cout << 1 << " " << 1 << endl;
		return;
	}
	
	build();
	
	if(checktwo() > 0){
		cout << 2 << " " << checktwo() << endl;
		return;
	}

	cout << 3 << " " << 1 << endl;

	/*int ans = 0;

	fi(0, n) fj(i+1, n-1){
	if(!p[i]) continue;
	if(!s[j+1]) continue;
	string s = str.substr(i+1, j-i);
	if(!checkstring(s)) ++ans;
	}
	if(ans > 1){
	cerr << str << " " << ans << endl;
	exit(0);
	}*/
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	init();

	cin >> str;

	solve();


	return 0;
}

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

int main() {
  int A, B, C, D, E;
  cin >> A >> B >> C >> D >> E;
  int a = (A - 1) / 10 * 10 + 10;
  int b = (B - 1) / 10 * 10 + 10;
  int c = (C - 1) / 10 * 10 + 10;
  int d = (D - 1) / 10 * 10 + 10;
  int e = (E - 1) / 10 * 10 + 10;
  int Al = A + b + c + d + e;
  int Bl = a + B + c + d + e;
  int Cl = a + b + C + d + e;
  int Dl = a + b + c + D + e;
  int El = a + b + c + d + E;
  int ans = min(Al, Bl);
  ans = min(ans, Cl);
  ans = min(ans, Dl);
  ans = min(ans, El);
  cout << ans << endl;
}


Measured memory_bytes: 256
from collections import deque
import numpy as np

n, m = map(int, input().split())
path = [[] for i in range(n + 1)]
inbounds = [0] * (n + 1)

for i in range(m):
    x, y = map(int, input().split())
    path[x].append(y)
    inbounds[y] += 1

# Topological sort
topological = list(v for v in range(1, n + 1) if inbounds[v] == 0)
deq = deque(topological)

while deq:
    v = deq.popleft()
    for t in path[v]:
        inbounds[t] -= 1
        if inbounds[t] == 0:
            deq.append(t)
            topological.append(t)

# DP
dp = np.zeros(n + 1, dtype='int64')

for v in topological:
    for t in path[v]:
        dp[t] = max(dp[t], dp[v] + 1)

print(dp.max())


Measured memory_bytes: 30708
# coding: utf-8
import sys
sysread = sys.stdin.readline
def run():
    a,b,c,d = list(map(int, sysread().split()))
    A = [0,[a,b],[c,d]]
    turn = 1
    while True:
        att = A[turn]
        de = A[-turn]
        de[0] -= att[1]
        if de[0] <= 0:
            break
        turn *= -1
    ret = ['', 'Yes', 'No']
    print(ret[turn])

if __name__ == "__main__":
    run()

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

#define step(i, s, n, d) for(int i=s; i<n; i+=d)
#define FOR(i,s,n) step(i,s,n,1)
#define rep(i,n) FOR(i,0,n)
#define gets(x) x; cin >> x;
#define puts(x) x; cout << x << endl;
#define list_input(x, n) x[n]; rep(i,n){ gets(x[i]);}
#define ll long long

int main(){
  int n, result = 0;
  cin >> n;
  vector< pair<int, int> > ab;
  vector< pair<int, int> > cd;
  rep(i, n){
    int a, b;
    cin >> a >> b;
    ab.push_back( make_pair(a,b) );
  }
  rep(i, n){
    int c, d;
    cin >> c >> d;
    cd.push_back( make_pair(c,d) );
  }

  sort(ab.begin(), ab.end());
  sort(cd.begin(), cd.end());
  rep(i, n){
    int flag = -1, maxy = -1;
    rep(j, n){
      if (cd[i].first > ab[j].first) {
        if (ab[j].second >= maxy && cd[i].second > ab[j].second) {
          flag = j;
          maxy = ab[j].second;
        }
      }
    }
    if (flag != -1) {
      ab.erase(ab.begin()+flag);
      result += 1;
    }
  }
  puts(result)
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back()
#define ll long long
#define pi pair<int,int>
using namespace std;
ll dp[2005];
const int  mod = 1e9+7;

ll solve(int s)
{
  if(s==0)
  return 1;
  if(s<0)
  return 0;

  if(dp[s]!=-1)
  return dp[s];
  ll ans=0;
  for(int i=3;i<=s;i++)
  ans=(ans+solve(s-i))%mod;
  return dp[s]=ans;
}

int main()
{
  ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
  int s;
  cin>>s;
  memset(dp,-1,sizeof dp);
  // dp[0]=1;
  // for(int i=3;i<s;i++)
  // {
  //   for(int j=i;j<=s;j++)
  //   dp[j]=(dp[j]+dp[j-i])%mod;
  // }
  // ll ans = (dp[s]*2)%mod;
  // cout<<(ans+1)%mod<<endl;
  ll ans=solve(s);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF 1e9
#define dump(x) cerr<<#x<<"="<<x<<endl


using ll = long long;
const ll mod = LLONG_MAX;

ll T[110];


ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll m,ll n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;

	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}
int main(){
  ll n;
  ll me=-1;
  ll lc=-1;
  cin>>n;
  rep(i,n){
    cin>>T[i];
  }

  if(n==1){
    cout<<T[0]<<endl;
    return 0;
  }

  me=gcd(T[0],T[1]);
  lc=(T[0])*(T[1]/me);
  for(int i=2;i<n;i++){
    lc=lcm(lc,T[i]);
  }
  cout<<lc<<endl;


}


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

int main() {
    
    int N, A;
    long long ans = 0;
    vector<int> X;
    
    long long dp[51][5001];
    
    
    cin >> N;
    cin >> A;
    
    for ( int i = 0; i <= 50; i++ )
    for ( int j = 0; j < 5001; j++ ) {
        dp[i][j] = 0;
    }
    
    for ( int i = 0; i < N; i++ ) {
        int x;
        cin >> x;
        X.push_back( x - A );
    }
    
    
    for ( int i = N-1; i >= 0; i-- ) {
        
        int x = X[i];
        
        dp[i][x + 2500]++;
        
        for ( long long sum = 5000; sum >= 0 ; sum-- ) {
            if ( dp[i+1][sum] ) {
                dp[i][sum+x] += dp[i+1][sum];
                dp[i][sum] += dp[i+1][sum];
            }
        }
    }
    
    
    cout << dp[0][2500] << endl;
    
    return 0;
}

Measured memory_bytes: 2176
let rec upper_bound l r p =
  if r <= 1 + l
  then l
  else let m = (l + r) / 2 in
       if p m 
       then upper_bound m r p
       else upper_bound l m p

let () = Scanf.scanf "%d %d %d" @@ fun x k d ->
  let f i = Float.abs @@ float_of_int x +. float_of_int d *. float_of_int (2 * i - k) in
  let i = succ @@ upper_bound (-1) k @@ fun i -> f (i + 1) <= f i in
  Printf.printf "%d\n" @@ abs @@ x + d * (2 * i - k)


Measured memory_bytes: 3772
#include <bits/stdc++.h>
#include <string>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  string s01,s23;
  if(s.at(0) == '0'){
    s01 = s.at(1);
  }else{
  	s01 = s.at(0); //なぜかアルファベットになる,文字コードが一致するわけでもない
    s01 += s.at(1);
  }
  //cout << s01 << endl;
  if(s.at(2) == '0'){
    s23 = s.at(3);
  }else{
  	s23 = s.at(2);
    s23 += s.at(3);
  }
  //cout << s23 << endl;
  int i01,i23;
  i01 = stoi(s01);
  i23 = stoi(s23);
  if( (i01 > 12 || i01 == 0) && (i23 > 12 || i23 == 0)){
    cout << "NA" << endl;
  }else if( i01 <=12 && (i23 > 12 || i23 == 0)){
    cout << "MMYY" << endl;
  }else if( (i01 > 12 || i01 == 0) && i23 <= 12){
    cout << "YYMM" << endl;
  }else if( i01 <= 12 && i23 <= 12){
    cout << "AMBIGUOUS" << endl;
  }
  return 0;
  
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#define MOD 1000000007

using namespace std;

int main(void) {
	int i, j, num, buf;
	long long ans = 1;
	vector<int> pri = { 2 }, d = { 0 };
	cin >> num;
	for (i = 3; i <= num; i+=2) {;
		j = 0;
		while (j < pri.size() && i % pri[j] != 0)
			j++;
		if (j == pri.size()) {
			pri.push_back(i);
			d.push_back(0);
		}
	}
	for (i = 0; i < pri.size(); i++) {
		buf = 1;
		while (num / buf >= 1) {
			buf *= pri[i];
			d[i] += num / buf;
		}
	}
	for (i = 0; i < d.size(); i++) {
		ans *= d[i] + 1;
		ans %= MOD;
	}
	cout << ans << "\n";
	return 0;
}

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

//////全探索したいときに開けよ////////
/*
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}
*/

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}*/


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  string s;
  cin >> s;
  string wx;
  rep(i,s.size()){
    if(s.at(i) != 'x'){
      wx.push_back(s.at(i));
    }
  }
  //cout << wx;
  string wxr = wx;
  reverse(wx.begin(),wx.end());
  int result = 0;
  if(wxr != wx){
    cout << -1 << endl;
  }else{
    int l = 0;
    int r = s.size()-1;
    while(l < r){
      if(s.at(l) == s.at(r)){
        l++;
        r--;
      }else{
        if(s.at(l) == 'x'){
          l++;
          result++;
        }
        if(s.at(r) == 'x'){
          r--;
          result++;
        }
      }
    }
    cout << result << endl;
  }
}
        
        

Measured memory_bytes: 640
def main():
    H,W = map(int, input().split())
    S = [input() for _ in range(H)]


    U = [[0 for _ in range(W)] for _ in range(H)]
    D = [[0 for _ in range(W)] for _ in range(H)]
    L = [[0 for _ in range(W)] for _ in range(H)]
    R = [[0 for _ in range(W)] for _ in range(H)]

    #L,U
    for i in range(H):
        for j in range(W):
            if S[i][j] != "#":
                if j == 0:
                    L[i][j] = 1
                else:
                    L[i][j] = L[i][j-1] + 1
            
                if i == 0:
                    U[i][j] = 1
                else:
                    U[i][j] = U[i-1][j] + 1

    #R,D
    for i in reversed(range(H)):
        for j in reversed(range(W)):
            if S[i][j] != "#":
                if j == W-1:
                    R[i][j] = 1
                else:
                    R[i][j] = R[i][j+1] + 1
            
                if i == H-1:
                    D[i][j] = 1
                else:
                    D[i][j] = D[i+1][j] + 1

        
    ans = 0
    for i in range(H):
        for j in range(W):
            if S[i][j] == "#":
                continue

            tmp = L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3
            ans = max(ans, tmp)

    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 184964
#include<iostream>
#include<string>
#include<stdlib.h>
using namespace std;


int main() {
  //input
  int i;
  int  n; cin >> n;
  int  k; cin >> k;
  char a[n]; for(int i=0;i<n;i++) cin >> a[i];

  char ans=(int)a[k-1]+32;
  a[k-1] = ans;
  for(int i=0;i<n;i++){
    cout << a[i];
  } cout << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        HashSet<Integer> hs = new HashSet<Integer>();
        int a = sc.nextInt();
        int b = sc.nextInt();
        for(int i = 1; i <= 1250; i++){
            int t8 = (int)Math.floor(i*0.08);
            int t10 = (int)Math.floor(i*0.1);
            if(a == t8 && b == t10){
                System.out.println(i);
                return;
            }
        }
        System.out.println(-1);
    }
}

Measured memory_bytes: 23380
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define mt              make_tuple
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define range(a,b)		substr(a,b-a+1)
#define w(x)            int x; cin>>x; while(x--)
#define trace(x) 		cerr<<#x<<": "<<x<<" "<<endl;
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int pwmd(int a, int n, int m)
{
	if (!n)
		return 1;
	int pt = pwmd(a, n / 2, m);
	pt *= pt, pt %= m;
	if (n & 1)
		pt *= a, pt %= m;
	return pt;
}

int get_mod(string &s, int m)
{
	if (m <= 0)
		return 0;

	int n = s.length(), pw = n - 1, ans = 0;

	for (int i = 0; i < n; ++i)
	{
		if (s[i] == '1')
			ans += pwmd(2, pw, m), ans %= m;
		pw--;
	}

	return ans;
}

int get_cnt(int n)
{
	int ans = 0;

	while (n)
		n %= setbits(n), ans++;

	return ans;
}

int32_t main()
{
	FIO;
	int n; cin >> n;
	string s; cin >> s;

	int ones = 0;

	for (int i = 0; i < n; ++i)
		if (s[i] == '1')
			ones++;

	int mod_val[2] = {get_mod(s, ones - 1), get_mod(s, ones + 1)};

	for (int i = 0; i < n; ++i)
	{
		if (s[i] == '0')
		{
			int val = (mod_val[1] + pwmd(2, n - 1 - i, ones + 1)) % (ones + 1);
			cout << get_cnt(val) + 1 << '\n';
		}

		else if (ones == 1)
			cout << 0 << '\n';

		else
		{
			int val = (mod_val[0] - pwmd(2, n - 1 - i, ones - 1) + ones - 1) % (ones - 1);
			cout << get_cnt(val) + 1 << '\n';
		}
	}
	return 0;
}

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

void swap (int *, int *);
void print_a (int *, int);

int main (void) {
    int n, count=0;
    int *a;

    scanf ("%d", &n);
    a = (int *) malloc (sizeof(int) * n);
    for (int i=0; i<n; i++) scanf ("%d", a+i);

    for (int i=0; i<n; i++) {
        int mini=i;
        for (int j=i; j<n; j++) {
            if (a[j]<a[mini]) mini=j;
        }
        if (i!=mini) {
            swap (a+i, a+mini);
            count++;
        }
    }

    print_a (a, n);
    printf ("%d\n", count);

    free(a);
    return 0;
}

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

void print_a (int *a, int n) {
    for (int j=0; j<n; j++) {
        if (j==n-1) printf ("%d\n", a[j]);
        else printf ("%d ", a[j]);
    }
}


Measured memory_bytes: 2064
digit = [0, 1, 2, 3, 5, 7, 8, 9]
n = input()
while n != 0:
    new_num = []
    eight = 1
    
    while eight * 8 <= n:
        eight *= 8
    while eight > 0:
        new_num.append(n / eight)
        n %= eight
        eight /= 8
    
    nn_str = ''
    for i in range(0, len(new_num)):
        nn_str += str(digit[new_num[i]])
    print nn_str
    n = input()

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

template<typename T1,typename T2> void chmin(T1 &a,T2 b){if(a>b) a=b;};
template<typename T1,typename T2> void chmax(T1 &a,T2 b){if(a<b) a=b;};

const Int MAX = 114514;
Int dp[3][3][10][MAX];
signed main(){
  Int n;
  while(cin>>n,n){
    memset(dp,0,sizeof(dp));
    if(n&1){
      dp[1][1][1][1]=1;
      dp[0][0][0][1]=1;
      for(Int i=1;i<n;i++){
	for(Int j=0;j<2;j++){
	  for(Int k=0;k<2;k++){
	    for(Int l=0;l<=8;l++){
	      dp[j][0][l][i+1]+=dp[j][k][l][i];
	      if(!k) dp[j][1][l+1][i+1]+=dp[j][k][l][i];
	    }
	  }
	}
      }
      Int ans=0;
      for(Int j=0;j<2;j++)
	for(Int k=0;k<2;k++)
	  if(!j||!k) ans+=dp[j][k][8][n];
      for(Int i=1;i<=8;i++) ans*=i;
      cout<<ans<<endl;
    }else{      
      dp[1][1][1][1]=1;
      dp[2][2][1][1]=1;
      dp[0][0][0][1]=1;
      for(Int i=1;i<n/2;i++){
	for(Int j=0;j<3;j++){
	  for(Int k=0;k<3;k++){
	    for(Int l=0;l<=8;l++){
	      dp[j][0][l][i+1]+=dp[j][k][l][i];
	      for(Int nk=1;nk<3;nk++)
		if(k!=nk) dp[j][nk][l+1][i+1]+=dp[j][k][l][i];
	    }
	  }
	}
      }
      Int ans=0;
      for(Int j=0;j<3;j++)
	for(Int k=0;k<3;k++)
	  if(j+k!=3) ans+=dp[j][k][8][n/2];      
      for(Int i=1;i<=8;i++) ans*=i;
      cout<<ans<<endl;
    }
  }
  return 0;
}
 



Measured memory_bytes: 83600
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0);

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int a,b,c,d; cin >> a >> b >> c >> d;
    while(true){
        c -= b;
        if(c <= 0){
            cout << "Yes" << endl;
            return 0;
        }
        a -= d;
        if(a <= 0){
            cout << "No" << endl;
            return 0;
        }
    }
}



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

typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

int main() {
  ll n;
  cin >> n;
  vector<ll> l(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> l[i];
  }

  vector<ll> ans(n + 1, 0);
  for (int i = n; i >= 1; i--) {
    ll mon = 0;
    for (int j = 2 * i; j <= n; j+=i) {
      mon += ans[j];
    }
    if (mon % 2 != l[i]) {
      ans[i] = 1;
    }
  }

  vector<int> v;
	for (int i = 1; i <= n; ++i) {
		if (ans[i]) {
      v.push_back(i);
    }
	}
	cout << v.size() << endl;
	for (auto i : v) {
    cout << i << " "; 
  }
	cout << endl;

  return 0;
}


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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

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

  int n;
  cin >> n;
  cout << n / 3 << "\n";

  return 0;
}

Measured memory_bytes: 256
var
	x:int64;
	n:longint;
function ans(x,y:longint):int64;
var 
	i:longint;
	s:int64;
begin
	s:=1;
	for i:=1 to x do s:=s shl 1+y;
	exit(s);
end;
function fac(a:longint; b:int64):int64;
var
	t1,t2:int64;
begin
	if b<=0 then exit(0);
	if (a>0) and (b=1) then exit(0);
	if a=0 then 
		if b>=1 then exit(1)
		else exit(0);
	t1:=ans(a-1,1);
	t2:=ans(a-1,3);
	if b<=t2+1 then exit(fac(a-1,b-1));
	exit(t1+1+fac(a-1,b-t2-2));
end;
begin
	read(n,x);
	writeln(fac(n,x));
end.

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

int m, f, r;

int main() {
  while(1){
    cin >> m >> f >> r;
    if(m == -1 && f == -1 && r == -1) break;

    if(m == -1 || f == -1)  cout << "F" << endl;
    else if(m + f >= 80)    cout << "A" << endl;
    else if(m + f >= 65)    cout << "B" << endl;
    else if(m + f >= 50)    cout << "C" << endl;
    else if(m + f >= 30)
      if(r >= 50)           cout << "C" << endl;
      else                  cout << "D" << endl;
    else                    cout << "F" << endl;
  }
}

Measured memory_bytes: 3096
def main():
    n = int(input())
    l = [int(v) for v in input().split()]
    ans = 0
    for i in range(n-2):
        for j in range(i+1, n-1):
            for k in range(j+1, n):
                l3 = sorted([l[i],l[j],l[k]])
                if l3[0]!=l3[1] and l3[1]!=l3[2] and l3[0]+l3[1]>l3[2]:
                    ans += 1
    print(ans)

main()

Measured memory_bytes: 9200
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i < (n);++i)
typedef long long ll;
using namespace std;
 
int main(){
  int x,y;
  cin >> x >> y;
  
  int ans = x + y/2;
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for (int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
typedef long long ll;

int main()
{
  string a, b, c;
  cin >> a >> b >> c;
  int bc = stoi(b + c);
  cout << ((bc % 4 == 0) ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256