akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))
 
using namespace std;
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}
 
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
 
// Problem Specific Parameter:
 
// Description: ????????????
// Verifyed: various problem 
const R INF = 1E40L;
const R PI = acos(-1.0L);
using P=complex<R>;
const P O=0.0L;
using L=struct{P s,t;};
using VP=vector<P>;
using C=struct{P p;R c;};
 
inline R dot(P o,P a,P b){return real(conj(a-o)*(b-o));}
inline R det(P o,P a,P b){return imag(conj(a-o)*(b-o));}
inline int sdot(P o,P a,P b){return sgn(dot(o,a,b));}
inline int sdet(P o,P a,P b){return sgn(det(o,a,b));}
 
//projection verify AOJ CGL_1_A
P proj(L l,P p){ R u=real((p-l.s)/(l.t-l.s)); return (1-u)*l.s+u*l.t;}
 
// vertical parallel
// verified: AOJ CGL_2_A
bool vertical(L a,L b) {return sdot(O,a.t-a.s,b.t-b.s)==0;}
bool parallel(L a,L b) {return sdet(O,a.t-a.s,b.t-b.s)==0;}
bool eql(L a,L b){ return parallel(a,b) and sdet(a.s,a.t,b.s)==0;}
 
// crossing determination
// verified: AOJ CGL_2_B 
bool iss(L a,L b){
    int sa=sdet(a.s,a.t,b.s)*sdet(a.s,a.t,b.t);
    int sb=sdet(b.s,b.t,a.s)*sdet(b.s,b.t,a.t);
    return max(sa,sb)<0;
}
 
// crossing point 
// verified: AOJ CGL_2_C
P cross(L a,L b){
    R u=det(a.s,b.s,b.t)/det(O,a.t-a.s,b.t-b.s);
    return u*a.s+(1-u)*a.t;
}
     
// distance 
// verified: AOJ CGL_2_D
R dsp(L l,P p){
    P h=proj(l,p);
    if(sdot(l.s,l.t,p)<=0) h=l.s;
    if(sdot(l.t,l.s,p)<=0) h=l.t;
    return abs(p-h);
}
 
R dss(L a,L b){return iss(a,b)?0:min({dsp(a,b.s),dsp(a,b.t),dsp(b,a.s),dsp(b,a.t)});}
 
istream& operator >> (istream& is,P& p){ R x,y;is >> x >> y; p=P(x,y); return is;}
ostream& operator << (ostream& os,P& p){ os << real(p) << " " << imag(p); return os;}
 
int main(void){
    int n;
    cin >> n;
    rep(i,n){
        P a,b,c,d;
        cin >> a >> b >> c >> d;
        L s1={a,b},s2={c,d};
        cout << (sgn(dss(s1,s2))==0) << endl;
    }
    return 0;
}

Measured memory_bytes: 3272
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
int main()
{
    int n, q;
    cin >> n;
    vector<int> s(n);
    rep(i,n) cin >> s[i];

    cin >> q;
    vector<int> t(q);
    rep(i,q) cin >> t[i];

    int ans = 0;
    rep(i,q){
        rep(j,n){
            if (s[j] == t[i]) {
                ans++;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3132
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <bitset>
#include <stdlib.h>


const int kN = 1000 + 5;
std::vector<int> edges[kN];
int x[kN], y[kN];
int n;

void dfs(int u, int fa)
{
    int sum = 0;
    for (int v : edges[u]) if (v != fa) {
        dfs(v, u);
        sum += x[v] + y[v];
    }
    std::bitset<5000 + 1> mask;
    mask[0] = 1;
    for (int v : edges[u]) if (v != fa) {
        mask = mask << x[v] | mask << y[v];
    }
    bool flag = false;
    for (int i = x[u]; i >= 0; -- i) if (mask[i]) {
        sum += x[u] - i;
        flag = true;
        break;
    }
    if (!flag) {
        puts("IMPOSSIBLE");
        exit(0);
    }
    y[u] = sum - x[u];
}

int main()
{
    scanf("%d", &n);
    for (int i = 2; i <= n; ++ i) {
        int p;
        scanf("%d", &p);
        edges[p].emplace_back(i);
    }
    for (int i = 1; i <= n; ++ i)
        scanf("%d", x + i);
    dfs(1, 0);
    puts("POSSIBLE");
}


Measured memory_bytes: 1664
# -*- coding: utf-8 -*-
"""
Created on Sun May 20 20:55:50 2018
AGC024A
@author: maezawa
"""

a, b, c, k = list(map(int, input().split()))
if a-b > 10**18 or b-a > 10**18:
    print('Unfair')
elif k%2 == 0:
    print(a-b)
else:
    print(b-a)
    

Measured memory_bytes: 3060
#include<stdio.h>
#define N 10000
#define q 500

int main(){
  int S[N];
  int T[q];
  int i,j,count=0,n,m;

  scanf("%d",&n);
  for(i=0; i<n; i++) scanf("%d",&S[i]);

  scanf("%d",&m);
  for(i=0; i<m; i++) scanf("%d",&T[i]);

  for(j=0;j<m;j++){
    for(i=0;i<n;i++){
      if(S[i]==T[j]) break;
    }
    if(i==n) count+=0;
    else count++;
  }
  

  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 2756
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class D
{
	public static void Main()
	{
		long H = GetLong();
		long W = GetLong();
		long N = GetLong();

		Dictionary<long, long> numBlack = new Dictionary<long, long>();
		for(long i = 0L; i < N; i++)
		{
			long a = GetLong();
			long b = GetLong();
			for(long dh = -1L; dh <= 1L; dh++)
			{
				long h = a + dh;
				if((h <= 1L) || (h >= H))
					continue;

				for(long dw = -1L; dw <= 1L; dw++)
				{				
					long w = b + dw;
					if((w <= 1L) || (w >= W))
						continue;

					long currentNum = 0L;
					numBlack.TryGetValue(h * W + w, out currentNum);
					numBlack[h * W + w] = currentNum + 1L;
				}
			}
		}

		long[] num = new long[10];
		foreach(long key in numBlack.Keys)
			num[numBlack[key]]++;
		num[0] = (long)(H - 2L) * (long)(W - 2L);
		for(int i = 1; i < 10; i++)
			num[0] -= num[i];

		for(int i = 0; i < 10; i++)
			Console.WriteLine(num[i]);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}





Measured memory_bytes: 58300
#include "bits/stdc++.h"
#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;

struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    vector<int> sum;
    int a = 1;
    for(int i = 1; i < N; i++){
        if(A[i] != A[i - 1]){
            sum.push_back(a);
            a = 1;
        }else{
            a++;
        }
    }
    if(A.back() == A[N - 1]) sum.push_back(a);
    int ans = 0;
    for(int s : sum){
        ans += s / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//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())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-12;
const LL INF = 1e18;


int main(){
	int a,b,c;
	char c1,c2;
	int cntr=0,cnth=0;
	while(cin>>a>>c1>>b>>c2>>c){
		if(a==b)cnth++;
		if(a*a+b*b==c*c)cntr++;
	}
	cout<<cntr<<endl;
	cout<<cnth<<endl;
	return 0;
}
/*

*/

Measured memory_bytes: 1164
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"n,*s=open(0).readlines();print(max(0,*[s.count(i)-s[int(n):].count(i)*2for i in s]))\n"
"\"";
  system(s);
  return 0;
}            

Measured memory_bytes: 3280
#![allow(unused_imports)]
use itertools::Itertools;
use proconio::{input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;

fn main() {
    input! {
        s:String,
        t:String,
    }

    if &s == &t[0..s.len()] {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2148
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#include <sstream>
#include <bitset>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
#define du3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c))
#define du2(a,b) scanf("%d %d",&(a),&(b))
#define du1(a) scanf("%d",&(a));
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) { if (a == 0ll) {return 0ll;} a %= MOD; ll ans = 1; while (b) {if (b & 1) {ans = ans * a % MOD;} a = a * a % MOD; b >>= 1;} return ans;}
ll poww(ll a, ll b) { if (a == 0ll) {return 0ll;} ll ans = 1; while (b) {if (b & 1) {ans = ans * a ;} a = a * a ; b >>= 1;} return ans;}
void Pv(const vector<int> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%d", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
void Pvl(const vector<ll> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%lld", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
inline long long readll() {long long tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
inline int readint() {int tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int n;
int vis[1000];
int a[maxn];
void dfs(int pos)
{
	if (pos == n + 1)
	{
		repd(i, 1, n)
		{
			printf("%c", (char)('a' + a[i] - 1));
		}
		printf("\n");
	} else
	{
		repd(i, 1, n)
		{
			if (vis[i] > 0 || vis[i - 1] > 0)
			{
				vis[i]++;
				a[pos] = i;
				dfs(pos + 1);
				vis[i]--;
			}
		}
	}
}
int main()
{
	//freopen("D:\\code\\text\\input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	n = readint();
	if (n == 1)
	{
		printf("a\n");
	} else
	{
		a[1] = 1;
		vis[1] = 1;
		dfs(2);
	}
	return 0;
}




Measured memory_bytes: 1536
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repv(t,it,v) for(vector<t>::iterator it = v.begin() ; it != v.end() ; ++it)

int N;
int A[3010];
vector<int> V[3010];
bool ans[3010];

bool dfs(int p , int q){
	repv(int,it,V[q]){
		if(*it == p || A[*it] >= A[q]) continue;
		if(!dfs(q,*it)) return 1;
	}
	return 0;
}

int main(){
	scanf("%d" , &N);
	repp(i,1,N+1){
		scanf("%d" , A + i);
	}
	repp(i,1,N){
		int x,y;
		scanf("%d%d" , &x , &y);
		V[x].PB(y);
		V[y].PB(x);
	}
	int z = 0;
	repp(i,1,N+1){
		ans[i] = dfs(-1,i);
		if(ans[i]) z = i;
	}
	repp(i,1,N+1){
		if(ans[i]) printf("%d%c" , i , z == i ? '\n' : ' ');
	}
	if(z == 0) printf("\n");
	return 0;
}


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

const int MAXN=110000;

typedef long long ll;

ll c,n,ans=0,sum=0;

struct data{
	ll dis,val;
}d[MAXN];

ll f[MAXN][21],g[MAXN][21],lg[MAXN];

void get_log(int n){
    int log=0;
    for(int i=1;i<=n;i++){
        lg[i]=(1<<log+1==i)?++log:log;
    }
}

ll querymaxf(int l,int r){
	if(l>r)return 0;
    int k=lg[r-l+1];
    return max(f[l][k],f[r-(1<<k)+1][k]);
}

ll querymaxg(int l,int r){
	if(l>r)return 0;
    int k=lg[r-l+1];
    return max(g[l][k],g[r-(1<<k)+1][k]);
}

void get1(){
	ll sum=0;
    for(int i=1;i<=n;i++){
    	sum+=d[i].val;
        f[i][0]=sum-d[i].dis;
    }
    for(int i=1;(1<<i)<=n;i++){
        for(int j=1;j+(1<<i)-1<=n;j++){
            f[j][i]=max(f[j][i-1],f[j+(1<<(i-1))][i-1]);
        }
    }
}

void get2(){
	ll sum=0;
    for(int i=n;i>=1;i--){
    	sum+=d[i].val;
        g[i][0]=sum-(c-d[i].dis);
    }
    for(int i=1;(1<<i)<=n;i++){
        for(int j=1;j+(1<<i)-1<=n;j++){
            g[j][i]=max(g[j][i-1],g[j+(1<<(i-1))][i-1]);
        }
    }
}

ll baoli(int limit){
	ll sum=0,M=0;
	for(int i=1;i<=limit;i++){
		sum+=d[i].val;
		M=max(M,sum-d[i].dis);
	}
	return M;
}

int main(){
	scanf("%lld%lld",&n,&c);
	get_log(n);
    for(int i=1;i<=n;i++){
		scanf("%lld%lld",&d[i].dis,&d[i].val);
	}
	for(int i=1;i<=n;i++){
		sum+=d[i].val;
		ans=max(ans,sum-d[i].dis);
	}
	sum=0;
	for(int i=n;i>=1;i--){
		sum+=d[i].val;
		ans=max(ans,sum-(c-d[i].dis));
	}
	get1();
	get2();
	//两个拼起来 
	ll prepos=0,premax=0,tmpsum=0;
	//先顺时针走 
	for(int i=1;i<=n;i++){
		tmpsum+=d[i].val;
		if(tmpsum-(2*d[i].dis)>0){
			premax=tmpsum-(2*d[i].dis);
		//	cout<<premax<<"a"<<endl;
			ans=max(ans,premax+querymaxg(i+1,n));
		}	
	}
	
	prepos=0,premax=0,tmpsum=0;
	//再走逆时针
	for(int i=n;i>=1;i--){
		tmpsum+=d[i].val;
		if(tmpsum-(2*(c-d[i].dis))>0){
			premax=tmpsum-(2*(c-d[i].dis));
			ans=max(ans,premax+querymaxf(1,i-1));
		//	ans=max(ans,premax+baoli(i-1));
		}
	}
	cout<<ans<<endl;
	return 0;
 }


Measured memory_bytes: 38656
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
	double x1, y1, x2, y2, x3, y3;
	int n;
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
		double x = ((y1-y3)*(y1*y1-y2*y2+x1*x1-x2*x2)-(y1-y2)*(y1*y1-y3*y3+x1*x1-x3*x3))/(2*(y1-y3)*(x1-x2)-2*(y1-y2)*(x1-x3));
		double y = ((x1-x3)*(x1*x1-x2*x2+y1*y1-y2*y2)-(x1-x2)*(x1*x1-x3*x3+y1*y1-y3*y3))/(2*(x1-x3)*(y1-y2)-2*(x1-x2)*(y1-y3));

		printf("%.3f %.3f %.3f\n", x, y, sqrt(pow((x1 - x), 2) + pow((y1 - y), 2)));
	}
	return 0;
}

Measured memory_bytes: 3112
import java.util.*;


public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        String s = scan.next();
        int out = s.length();
        for(int i = 0; i < s.length() - 1; i++){
            if(s.charAt(i) == s.charAt(i + 1)) out--;
        }
        System.out.println(out);
        scan.close();
    }
}

Measured memory_bytes: 30192
//============================================================================
// Name        : Test2.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

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

using namespace std;

int main() {
	int M;
	cin >> M;
	rep(_M,M){
		string s;
		set<string> all;
		cin >> s;
		all.clear();
		for(int i = 1;i<s.size();i++){
			string L = s;L.resize(i);
			string R = s.substr(i);
			string LI = L;reverse(L.begin(),L.end());
			string RI = R;reverse(R.begin(),R.end());
			all.insert(L+R);
			all.insert(R+L);
			all.insert(L+RI);
			all.insert(RI+L);
			all.insert(R+LI);
			all.insert(LI+R);
			all.insert(LI+RI);
			all.insert(RI+LI);
		}
		cout << all.size() << endl;
	}
	return 0;
}

Measured memory_bytes: 1292
S = input()
N = len(S)

cnt_1 = 0
cnt_2 = 0

for i in range(N):
  if i%2 == 0:
    if S[i] == "0":
      cnt_1 += 1
  else:
    if S[i] == "1":
      cnt_1 += 1

for j in range(N):
  if j%2 == 0:
    if S[j] == "1":
      cnt_2 += 1
  else:
    if S[j] == "0":
      cnt_2 += 1
      
print(min(cnt_1,cnt_2))

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

int main()
{
  int x, a, b;
  cin >> x >> a >> b;

  if(b - a <= 0) cout << "delicious" << endl;
  else if(b - a <= x) cout << "safe" << endl;
  else cout << "dangerous" << endl;

  return 0;

}


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

void solve() {
    int N, x;
    cin >> N >> x;
    if (x == 1 || x == 2 * N - 1) {
        cout << "No" << endl;
        return;
    }
    cout << "Yes" << endl;
    int i = 0;
    for (int j = 0; j < 2 * N - 1; j++) {
        if (j == N - 2) {
            cout << x - 1 << endl << x << endl << x + 1 << endl;
            j += 2;
            continue;
        }
        if (i == x - 2) i += 3;
        cout << i + 1 << endl;
        i++;
    }
    return;
}

int main() {
    solve();
}

Measured memory_bytes: 1536
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>
#include <utility>
#include <bitset>
using namespace std;
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[210][210];
int main()
{
    int m;
    cin>>m;
    for(int i=1;i<=2;i++)
        for(int j=1;j<=m;j++)
            scanf("%d",&a[i][j]);
    for(int i=1;i<=2;i++)
        for(int j=1;j<=m;j++)
            a[i][j]=a[i][j]+max(a[i-1][j],a[i][j-1]);
    printf("%d\n",a[2][m]);
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        
        int R = sc.nextInt();
        
        if( R < 1200 ){
            System.out.println("ABC");
        }else if( R < 2800 ){
            System.out.println("ARC");
        } else{
            System.out.println("AGC");
        }
    }
}


Measured memory_bytes: 25300
use std::ascii::AsciiExt;
use std::io::*;

// copy from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input! {
        _n: usize,
        k: usize,
        s: String,
    }
    let mut s = s.chars().collect::<Vec<char>>();
    s[k-1].make_ascii_lowercase();
    println!("{}", s.into_iter().collect::<String>());
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<string.h> 
int main()
{
	char s1[105],s2[105],t;
	scanf("%s%s",s1,s2);
	int n;
	n=strlen(s1);
	int i,j,k;
	int flag=1;
	for(i=0;i<n;i++){
		if(strcmp(s1,s2)==0){
			flag=0;
			break;
		}
		t=s1[0];
		for(j=0;j<n-1;j++){
			s1[j]=s1[j+1];	
		}
		s1[n-1]=t;
	} 
	if(flag==1)
	printf("No\n");
	else
	printf("Yes\n");
} 

Measured memory_bytes: 128
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			if(n==-1)break;
			double r = 1;
			double d = 0;
			
			for(int i=0;i<n-1;i++){
				d += Math.atan(1/r);
				r = Math.sqrt(1+r*r);
			}
				
			System.out.println(r*Math.cos(d));
			System.out.println(r*Math.sin(d));
		}
	
	}	
}

Measured memory_bytes: 17204
N,M = map(int,input().split())
PY = [list(map(int,input().split())) for _ in range(M)]
for i in range(M):
    PY[i].append(i)
PY.sort(key=lambda x:x[1])
ans = [0]*M
num = [0]*N
for p,y,i in PY:
    ans[i] = str(p).zfill(6) + str(num[p-1]+1).zfill(6)
    num[p-1] += 1
for s in ans:print(s)

Measured memory_bytes: 39884
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数 __builtin_popcount bitの個数

int main() {
  int N;
  ci(N);
  if(N == 1){
    co("Hello World");
  }
  else{
    int A, B;
    ci(A, B);
    co(A + B);
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(a) (a).begin(),(a).end()
 
using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
 
const ll MOD  = 1e9+7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;

int main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    bool turn = true;
    while(true){
        if(turn)c -= b;
        else a -= d;

        turn = !turn;

        if(a <= 0){
            cout << "No\n";
            return 0;
        }
        if(c <= 0){
            cout << "Yes\n";
            return 0;
        }
    }
}

Measured memory_bytes: 3632
#include <cstdio>
#include <iostream>
#include <vector>
#include <ctype.h>
#include <algorithm>
#define mp make_pair
#define fir first
#define sec second

using namespace std;

typedef long long LL;
typedef pair<LL, LL> pll;

const int MAXN = 2e5 + 7;
const int MOD = 1000000007 ; 

inline int read() {
	int res = 0, flag = 1; char in = getchar();
	while(!isdigit(in)) { if(in == '-') flag = -1; in = getchar(); }
	while(isdigit(in)) { res = (res << 1) + (res << 3) + in - '0'; in = getchar(); }
	return res * flag;
}

inline void chkmax(int &a, int b) { if(a < b) a = b; }
inline void chkmin(int &a, int b) { if(a > b) a = b; }

inline LL fpm(int x, int y) {
	LL res = 1;
	while(y) {
		if(y & 1) res = 1ll * res * x % MOD;
		x = 1ll * x * x % MOD;
		y >>= 1;
	}
	return res;
}

vector<int> G[MAXN];
vector<pll> dp[MAXN];

int n, fa[MAXN];
int lc[MAXN], id[MAXN], tot;
int dep[MAXN], cnt[MAXN];
LL zro[MAXN], all[MAXN], one[MAXN];
LL ans;

void dfs(int u) {
	int son = n + 1;
	int len = G[u].size();
	for(int i = 0; i < len; ++i) {
		int v = G[u][i];
		dfs(v);
		if(lc[v] > lc[son]) son = v;
	}
	if(son != n + 1) id[u] = id[son], lc[u] = lc[son] + 1;
	else id[u] = ++tot;

	dp[id[u]].push_back(mp(1ll, 1ll));
	if(G[u].size() == 1) return ;

	for(int i = 0; i <= lc[u]; ++i)
		all[i] = zro[i] = 1, one[i] = 0;
	
	for(int t = 0; t < len; ++t) {
		int v = G[u][t];
		for(int i = 0; i <= lc[v]; ++i) {
			int cur = lc[son] - lc[v] + i;
			pll st = dp[id[v]][i];
			(all[cur] *= (st.fir + st.sec) % MOD) %= MOD;
			(zro[cur] *= st.fir) %= MOD;
		}
	}

	for(int t = 0; t < len; ++t) {
		int v = G[u][t];
		for(int i = 0; i <= lc[v]; ++i) {
			int cur = lc[son] - lc[v] + i;
			pll st = dp[id[v]][i];
			(one[cur] += zro[cur] * fpm(st.fir, MOD - 2) % MOD 
				* st.sec % MOD) %= MOD;
		}
	}
	for(int i = 0; i < lc[u]; ++i) {
		dp[id[u]][i].fir = (all[i] - one[i] + MOD) % MOD;
		dp[id[u]][i].sec = one[i];
	}
}

inline void solve() {
	n = read();
	for(int i = 1; i <= n; ++i) {
		G[fa[i] = read()].push_back(i);
		dep[i] = dep[fa[i]] + 1;
		++cnt[dep[i]];
	}
	lc[n + 1] = -MAXN;
	++cnt[0];
	dfs(0);
	for(int i = 0; i <= lc[0]; ++i) {
		pll st = dp[id[0]][i];
		(ans += st.sec * fpm(2, n + 1 - cnt[lc[0] - i]) % MOD) %= MOD;
	}
	cout << ans << endl;
}

int main() {

	solve();
	return 0;
}


Measured memory_bytes: 53364
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
int main(void){
    int i,n;
    char az[27];
    int count[26] = {};
    char s;
    for(i=0;i<26;i++){
        az[i] = 'a' + i;
    }
    az[26] = '\0';
    while((scanf("%c",&s)) != EOF){
        s = tolower(s);
        n = s - 'a';
        count[n]++;
    }
    for(i = 0;i<26;i++){
        printf("%c : %d\n",az[i],count[i]);
    }
    return 0;
}

Measured memory_bytes: 544
X, N = map(int, input().split())
if N == 0:
    Ps = {}
    print(X)
    exit()
else:
    Ps = set(list(map(int, input().split())))

all_numbers = set(list(range(0, 102)))

search_numbers = list(all_numbers - Ps)

absolute_value = 1000
out = X
for i in search_numbers:
    if abs(i - X) < absolute_value:
        absolute_value = abs(i - X)
        out = i

print(out)

Measured memory_bytes: 9212
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
using namespace std;
const int maxn = 1e5 + 5;
vector<int>son[maxn];
queue<int>q;
int dis[maxn];
int ans[maxn];
bool vis[maxn];
int main()
{
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= m; i++)
	{
		int a, b;
		cin >> a >> b;
		son[a].push_back(b);
		son[b].push_back(a);
	}
	memset(dis, 0x3f, sizeof(dis));
	q.push(1);
	dis[1] = 0;
	while (!q.empty())
	{
		int u = q.front();
		q.pop();
		if (vis[u])
			continue;
		vis[u] = 1;
		for (int i = 0; i < son[u].size(); i++)
		{
			int v = son[u][i];
			if (dis[u] + 1 < dis[v])
			{
				dis[v] = dis[u] + 1;
				q.push(v);
				ans[v] = u;
			}
		}
	}
	for (int i = 2; i <= n; i++)
	{
		if (ans[i] == 0)
		{
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	for (int i = 2; i <= n; i++)
		cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 10824
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	int		l,r,a,b,c,i,j,k,n,m,x,y,ans = 0;
	cin >> n;

	int keta = -1;
	a = b = n;
	while(a>0) {
		keta++;
		b = a;			//最上位桁の数
		a /= 10;
	}
	int bb = b;
	for(i=0;i<keta;i++) bb *= 10;
//printf("keta %d b %d bb %d\n",keta,b,bb);

	for(i=1;i<=n;i++) {
		a = i;
		if (a%10 == 0 ) continue;
		if (a > 10) {
			r = a % 10;
			while(a>=10) {
				a /= 10;
			}
			l = a;
		} else {
			r = l = a;
		}
		
		if (l==r) ans++;	//1桁のケース
		//printf(">> l r i:%d %d %d\n",l,r,i);

		vector<int> cnt;
		cnt = { 1 , 10 , 100 , 1000 , 10000 };
		
		for(j=0;j<keta;j++) {
			x = r*10;
			if (j==keta-1 && r>b) break;
			for(k=0;k<j;k++) x = (x+9)*10;
			x += l;
			//printf("j x:%d %d\n",j,x);
			if (n>=x) {
				ans += cnt[j];
			} else if (j>0) {
				while(n<x) x -= 10;
				//printf("x bb : %d %d\n",x,bb);
				if ( x >= bb) ans += (x / 10) % cnt[j] + 1;
			}

		}
		//cout << i << ':' << ans << endl;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

final class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Iterator<String> sc) {
		int K = Integer.parseInt(sc.next());
		int S = Integer.parseInt(sc.next());
		int sum = 0;
		for (int x = 0; x <= K && x <= S; x++) {
			int remaining = S - x;
			sum += Math.max(Math.min(remaining, K) - Math.max(remaining - K, 0) + 1, 0);
		}
		System.out.println(sum);
	}
}

class Main {
	public static void main(String... args) {
		Solver.INSTANCE.solve(new Scanner(System.in));
	}
}

Measured memory_bytes: 21716
#pragma GCC optimize("O3")

#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz(x) (int)x.size()
#define f first
#define s second
const ll MOD=1e9+7;

ll modPow(ll first,ll second)
{
    first%=MOD;
    if(second==0)
        return 1;
    if(second==1)
        return first;
    ll res=modPow(first,second/2);
    if(second%2==0)
        return (res*res)%MOD;
    else
        return (((res*res)%MOD)*first)%MOD;
}

ll mul(ll first,ll second)
{
    first%=MOD;
    second%=MOD;
    return (first*second)%MOD;
}

ll sum(ll first,ll second)
{
    first%=MOD;
    second%=MOD;
    return (first+second)%MOD;
}

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    vector<ll> arr(n);
    F0R(i,n)
        cin >> arr[i];
    vector<vector<int>> cnt(60,vector<int>(n));
    vector<vector<int>> pref(60,vector<int>(n,0));
    F0R(i,60)
    {
        F0R(j,n)
        {
            int val=(arr[j] >> i) & 1;
            cnt[i][j]=val;
        }
    }
    F0R(i,60)
        pref[i][0]=cnt[i][0];
    F0R(i,60)
    {
        FOR(j,1,n)
        {
            pref[i][j]=pref[i][j-1]+cnt[i][j];
        }
    }
    ll tot=0;
    F0R(i,60)
    {
        ll powRes=modPow(2,i);
        FOR(j,1,n)
        {
            if(cnt[i][j]==0)
                tot=sum(tot,mul(powRes,pref[i][j-1]));
            else
                tot=sum(tot,mul(powRes,j-pref[i][j-1]));
        }
    }
    cout << tot;

    return 0;
}


Measured memory_bytes: 144364
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <stack>
#include <deque>
#include <memory.h>
using namespace std;

typedef struct _POINT
{
	int x, y;
	_POINT() {};
	_POINT(int _x, int _y) : x(_x), y(_y) {};
} POINT;

#define rep(idx, max)			for(int idx = 0, idx##Max = (max); idx < idx##Max; idx ++)
#define rrep(idx, min, max)	for(int idx = (min), idx##Max = max; idx < idx##Max; idx ++)
#define erep(idx, min, max)	for(int idx = (min), idx##Max = max; idx <= idx##Max; idx ++)

#define rev(idx, max)			for(int idx = (max) - 1; idx >= 0; idx --)
#define rrev(idx, min, max)	for(int idx = (max) - 1, idx##Min = (min); idx >= idx##Min; idx --)
#define erev(idx, min, max)	for(int idx = (max), idx##Min = (min); idx >= idx##Min; idx --)

#define foreach(it, obj)	for(auto it = obj.begin(), it##End = obj.end(); it >= it##End; it ++)

#define MAX_N	128

int g_width, g_height;	//! ??????????????????
char g_map[MAX_N][MAX_N];	//! ??????????????±
char g_mapVisited[MAX_N][MAX_N];	//! ?????????????¨?????????????

///
/// ???????????¨??? (for debugging)
///
void	PrintMap()
{
	erep(y, 0, g_height + 1)	{	erep(x, 0, g_width + 1)	{	::printf("%c", g_map[y][x]);	}	::puts("");	}	::puts("");
}

///
/// ??????????????±??\???
///
void	InitMap()
{
	::memset(g_map, 'x', sizeof(g_map));
	::memset(g_mapVisited, 0, sizeof(g_mapVisited));
	
	//erep(y, 1, g_height)	erep(x, 1, g_width)	{	std::cin >> g_map[y][x];	}
	erep(y, 1, g_height)
	{
		::scanf("%s", g_map[y] + 1);	g_map[y][g_width + 1] = 'x';
	}
	//PrintMap();
}

///
/// BFS??§?????????????????£?¶??????????????¨?????????°?????????????????°??§???????????¶???
///
void	BfsFill(POINT start)
{
	static int dx[]	= {0, +1, 0, -1};
	static int dy[]	= {+1, 0, -1, 0};
//	static POINT dr[] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
	deque<POINT>	que;
	
	int	field	= g_map[start.y][start.x];
	que.push_back(start);
	
	while(que.size())
	{
		rep(i, que.size())
		{
			POINT p = que.front();
			g_mapVisited[p.y][p.x]	= true;
			rep(n, 4)
			{
				POINT	pn(p.x + dx[n], p.y + dy[n]);
				if(g_map[pn.y][pn.x] == field && !g_mapVisited[pn.y][pn.x])
				{	que.push_back(pn);	}
			}
			que.pop_front();
		}
	}
}

///
/// DFS??§?????????????????£?¶??????????????¨?????????°?????????????????°??§???????????¶???
///
void	DfsFill(POINT start)
{
	static int dx[]	= {0, +1, 0, -1};
	static int dy[]	= {+1, 0, -1, 0};
//	static POINT dr[] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
	stack<POINT>	stk;
	
	int	field	= g_map[start.y][start.x];
	stk.push(start);
	
	while(stk.size())
	{
		POINT p = stk.top();
		stk.pop();
		g_mapVisited[p.y][p.x]	= true;
		rep(n, 4)
		{
			POINT	pn(p.x + dx[n], p.y + dy[n]);
			if(g_map[pn.y][pn.x] == field && !g_mapVisited[pn.y][pn.x])
			{	stk.push(pn);	}
		}
	}
}

///
/// ?§£???
///
int	Solve()
{
	int 	count = 0;
	erep(y, 1, g_height) erep(x, 1, g_width)
	{
		// ???????????¶?????????????????????
		if(g_mapVisited[y][x])	{	continue;	}
		// ??°?????????????????¶?????¨???????????????
		count ++;
		::DfsFill(POINT(x, y));
	}
	return(count);
}

int main()
{
	while(std::cin >> g_height >> g_width, g_width)
	{
		::InitMap();
		cout << ::Solve() << endl;
	}
}

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

int main() {
	int n,c=0;
	cin>>n;
	int a[n];
	for(int i=0; i<n; i++){
		cin>>a[i];
		if (a[i]!=(i+1))
			c++;     }
		if(c<=2)
		cout<<"YES";
		else 
		cout<<"NO";
	return 0;
}

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

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

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <string>
#define mem(i,a) memset(i,a,sizeof(i))
#define PI acos(-1.0)
#define DMAX 200000+5
#define MOD 20190823
#define eps 1e-8
#define mp make_pair
#define INF 1000000000+9
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
inline void read(int &f){
    f=0;
    ll x=1;
    char ch=getchar();
    while(ch<48 || ch>57) {
        if(ch=='-') {
            x=-1;
        }
        ch=getchar();
    }
    while(ch<=57 && ch>=48) {
        f=f*10+ch-'0';
        ch=getchar();
    }
    f*=x;
}
int n;
string s[DMAX];
map<string,int> ma;
int ans=0;
int main()
{   
    read(n);
    for(int i=1;i<=n;i++){
        cin>>s[i];
        ma[s[i]]++;
        ans=max(ans,ma[s[i]]);
    }
    sort(s+1,s+n+1);
    for(int i=1;i<=n;i++){
        if(s[i]==s[i-1]){
            continue;
        }
        else{
            if(ma[s[i]]==ans){
                cout<<s[i]<<endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 26752
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    M=[None]*n
    for i in range(n):
        M[i]=list(map(lambda x:int(x)-1,input().split()))[::-1]

    # i が誰かしらと対戦できるか
    def check(i):
        if(not M[i]): # 既に試合を終えている
            return False
        j=M[i][-1]
        if(not M[j]): # これは起こり得ない
            return False
        return i==M[j][-1]

    # 初日に対戦できる人をピックアップ
    # 重複が起こるが、後で unique を取る
    Q=[]
    for i in range(n):
        if(check(i)):
            j=M[i][-1]
            if(i>j): i,j=j,i # i<j
            Q.append((i,j))

    # 処理を行なっていく
    day=0
    nQ=[] # 次の試合相手
    while(Q):
        # Q には重複があるので unique
        Q=list(set(Q))
        # 先に全ての試合を終わらせる必要がある
        for i,j in Q:
            M[i].pop(); M[j].pop()
        # 試合を終えた人は次の試合を行える可能性がある
        for i,j in Q:
            if(check(i)):
                k=M[i][-1]
                nQ.append((min(i,k),max(i,k)))
            if(check(j)):
                k=M[j][-1]
                nQ.append((min(j,k),max(j,k)))
        Q,nQ=nQ,[]
        day+=1

    print(day if(all(M[i]==[] for i in range(n))) else "-1")
resolve()


Measured memory_bytes: 65500
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						(1000 * 1000 * 1000 * 2)
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
// メイン
int main()
{
	int M, K;
	cin >> M >> K;
	int valMax = 1 << M;

	vector<int> a;
	if (K == 0) {
		// K 0, 0, 1, 1, … N, N
		REP(i, valMax) {
			a.emplace_back(i);
			a.emplace_back(i);
		}
	} else {
		// K 0, 1, … N K N … 1, 0
		int xorRes = 0;
		REP(i, valMax) {
			if (i != K) {
				xorRes ^= i;
			}
		}
		if (xorRes != K) {
			cout << -1 << endl;
			return 0;
		}

		// 出力作成
		a.emplace_back(K);
		REP(i, valMax) {
			if (i != K) {
				a.emplace_back(i);
			}
		}
		a.emplace_back(K);
		for (int i = valMax - 1; 0 <= i; i--) {
			if (i != K) {
				a.emplace_back(i);
			}
		}
	}

	// 出力
	REP(i, a.size()) {
		cout << a[i] << " ";
	}
	cout << endl;
	return 0;
}


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

using namespace std;

using lint = long long;
using ldouble = long double;

const int INF = 1 << 30;

bool solve() {
    int T;
    cin >> T;
    if (T == 0) return false;

    vector<int> P(T);
    for (auto& p : P) cin >> p;

    int N;
    cin >> N;
    vector<int> M(100, 24);
    for (int i = 0; i < N; ++i) {
        int D;
        cin >> D;
        --D;

        int m;
        cin >> m;
        M[D] = min(M[D], m);
    }

    vector<int> dp(T, INF);
    dp[0] = 0;
    // dp[t] = t番目の周期にいるときのカフェインの最小値

    for (int d = 0; d < 100; ++d) {
        for (int t = 0; t < T; ++t) {
            if (P[t] > M[d]) dp[t] = INF;
        }

        rotate(dp.begin(), dp.end() - 1, dp.end());
        dp[0] = min(dp[0], *min_element(dp.begin(), dp.end()) + 1);
    }

    cout << *min_element(dp.begin(), dp.end()) << endl;
    return true;
}

int main() {
    while (solve()) {}
    return 0;
}



Measured memory_bytes: 3172
#include <cstddef>
#include <complex>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <limits>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>
#include <bitset>

using ll = long long;
using ull = unsigned long long;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

int main()
{
    using namespace std;

    ll n;
    cin >> n;

    vec<ll> v(5);
    for (auto& e : v)
    {
        cin >> e;
    }

    auto mi = *min_element(v.cbegin(), v.cend());

    auto t = n / mi;
    if (n % mi != 0)
    {
        ++t;
    }

    cout << t + 4ll << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int H, W;
bitset<160 * 160 + 1> dp[81][81];
int cost[81][81];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> H >> W;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> cost[i][j];
        }
    }
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            int tmp;
            cin >> tmp;
            cost[i][j] -= tmp;
        }
    }

    int s = H + W - 1;
    dp[0][0][80 + cost[0][0]] = true;
    dp[0][0][80 - cost[0][0]] = true;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            dp[i + 1][j] |= dp[i][j] << (80 + cost[i + 1][j]);
            dp[i + 1][j] |= dp[i][j] << (80 - cost[i + 1][j]);
            dp[i][j + 1] |= dp[i][j] << (80 + cost[i][j + 1]);
            dp[i][j + 1] |= dp[i][j] << (80 - cost[i][j + 1]);
        }
    }

    int ans = inf;
    for(int i = 0; i <= s * 160; i++){
        if(!dp[H - 1][W - 1][i]) continue;
        chmin(ans, abs(i - s * 80));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 20864
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
typedef long long int lint;
using namespace std;

//ただの辺
struct edge {
    using lint = long long int;
    int to;
    lint cost;
    //引数一つの時は距離1
    edge(int t, lint c = 1) : to(t), cost(c) {
    }
};

// nowスタートでまだ行ってないところを全部回る行き方
int dfs(int now, int arrived, vector<vector<edge>>& g) {
    if (arrived == (1 << g.size()) - 1) {
        return 1;
    } else {
        int res = 0;
        for (int i = 0; i < g[now].size(); i++) {
            int next = g[now][i].to;
            if ((arrived & (1 << next)) == 0) {
                res += dfs(next, arrived | (1 << next), g);
            }
        }
        return res;
    }
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<edge>> g(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(edge(b));
        g[b].push_back(edge(a));
    }
    cout << dfs(0, 1, g) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 5LL << 60;
const ll mod = 1e9 + 7;

int main() {
	ll N, K;
	cin >> N >> K;

	ll ans = 0;
	for(int i = K; i <= N + 1; i++) {
		ans += (((i * (N + 1 - i)) % mod) + 1) % mod;
		ans %= mod;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s; cin >> s;
  int v[3];
  int a = s[0] - '0';
  v[0] = s[1] - '0';
  v[1] = s[2] - '0';
  v[2] = s[3] - '0';
  for(int i = 0; i < 8; i++){
    int r = a;
  	for(int j = 0; j < 3; j++)
      if(i&(1<<j)) r -= v[j];
    	else r += v[j];
    if(r == 7){
      cout << a;
      for(int j = 0; j < 3; j++){
      	if(i&(1<<j)) cout << "-";
        else cout << "+";
        cout << v[j];
      }
      cout << "=7" << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); ++ i)
#define rrp(i,a,b) for (int i = (a); i >= (b); -- i)
#define gc() getchar()
#define fir first
#define sec second
typedef pair<int,int> pii;
typedef double db;
typedef long long ll;
template <typename tp>
inline void read(tp& x) {
  x = 0; char tmp; bool key = 0;
  for (tmp = gc(); !isdigit(tmp); tmp = gc())
    key = (tmp == '-');
  for (; isdigit(tmp); tmp = gc())
    x = (x << 3) + (x << 1) + (tmp ^ '0');
  if (key) x = -x;
}
template <typename tp>
inline void ckmn(tp& x,tp y) {
  x = x < y ? x : y;
}
template <typename tp>
inline void ckmx(tp& x,tp y) {
  x = x < y ? y : x;
}

const int N = 100010;
int n, m, a[N << 1];
bool check(int x) {
  int key = 1;
  for (int i = x+1, j = 2*n; i < j; ++ i, -- j) {
    if (a[i] + a[j] < m) key = 0;
  }
  return key;
}
int main() {
  read(n), read(m);
  rep (i, 1, 2*n) read(a[i]);
  sort(a+1, a+(2*n)+1);
  int l = 0, r = n, ans = n;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid * 2)) r = mid - 1, ans = mid;
    else l = mid + 1;
  }
  ans = ans * 2;
  int res = 0;
  for (int i = 1, j = ans; i < j; ++ i, -- j)
    res = max(res, a[i] + a[j]);
  for (int i = ans+1, j = 2*n; i < j; ++ i, -- j)
    res = max(res, a[i] + a[j] - m);
  printf("%d\n", res);
  return 0;
}


Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
d = list( map(int, input().split()))
m = int(input())
t = list( map(int, input().split()))

from collections import Counter

cd = Counter(d)
ct = Counter(t)

for k,v in ct.items():
    if v > cd[k]:
        print('NO')
        exit()
print('YES')


Measured memory_bytes: 56928
import java.util.Scanner;

public class Main {

    static int X;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        X = sc.nextInt();

        solve();
    }

    static void solve() {
        int MAX_ROOT = (int)Math.sqrt(X);

        int max = 1;
        for (int i = 2; i <= MAX_ROOT; i++) {
            for (int j = 1; j <= 9; j++) {
                if ((int)Math.pow(i, j) > X) {
                    break;
                }
                max = Math.max((int)Math.pow(i, j), max);
            }
        }
        System.out.println(max);
    }
}


Measured memory_bytes: 21844