akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define N 2000010
#define INF 0x3f3f3f3f

using namespace std;

int n_road,n_rail;
int city;
int road_cont[2][N];
int road[2][N];
bool visit[N];
int cont[N];
int connected[N];

set <int> way_cont[2][N],temp_cont;
set <int>::iterator it;

int Find(bool way,int x)
{
    if(x==road_cont[way][x])return x;
    else
    {
        road_cont[way][x]=Find(way,road_cont[way][x]);
        return road_cont[way][x];
    }
}

void join(bool way,int a,int b)
{
    if(road[way][a]<road[way][b])
    {
        road_cont[way][a]=b;
        ++road[way][a];
    }
    else
    {
        road_cont[way][b]=a;
        ++road[way][b];
    }
}

void Create()
{
    int i;
    int x,y;
    for(i=1; i<=city; ++i)
    {
        road_cont[0][i]=road_cont[1][i]=i;
    }
    for(i=1; i<=n_road; ++i)
    {
        scanf("%d%d",&x,&y);

        int f1=Find(0,x);
        int f2=Find(0,y);
        if(f1!=f2) join(0,f1,f2);
    }
    for(i=1; i<=n_rail; ++i)
    {
        scanf("%d%d",&x,&y);

        int f1=Find(1,x);
        int f2=Find(1,y);
        if(f1!=f2) join(1,f1,f2);
    }
    //Create_tree
    for(int j=1; j<=city; ++j)
    {
        way_cont[0][Find(0,j)].insert(j);
        way_cont[1][Find(1,j)].insert(j);
    }

    memset(visit,0,sizeof(visit));
}

void Travel_Tree()
{
    for(int i=1; i<=city; i++)
    {
        if(visit[i])continue;
        int top=0;
        int Root1,Root2;
        Root1=Find(0,i);
        Root2=Find(1,i);

        bool road;
        if(way_cont[0][Root1].size() > way_cont[1][Root2].size())
        {
            temp_cont=way_cont[1][Root2];
            road=true;
        }
        else
        {
            temp_cont=way_cont[0][Root1];
            road=false;
            int t=Root1;
            Root1=Root2;
            Root2=t;
        }

        for(it=temp_cont.begin(); it!=temp_cont.end(); it++)
        {
            int p=*it;
            if(way_cont[!road][Root1].find(p)!=way_cont[!road][Root1].end())
            {
                top++;
                connected[top]=(p);
                visit[p]=1;
                /*cont[p]++;

                */

                way_cont[road][Root2].erase(p);
                way_cont[!road][Root1].erase(p);
            }
        }
        for(int j=1; j<=top; j++)
        {
            cont[connected[j]]=top;
        }
    }
}

int main()
{
    scanf("%d%d%d",&city,&n_road,&n_rail);
    Create();
    Travel_Tree();
    for(int i=1; i<=city; ++i)
    {
        if(i!=1)printf(" ");
        printf("%d",cont[i]);
    }
    printf("\n");
    return 0;
}


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

#define debug(x) (cerr << #x << " = " << x << endl;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F;
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;

inline int cmp(double x, double y = 0)
{
  if (fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

const int maxn = 5e6+ 2;

int main()
{
  ios::sync_with_stdio(false);
  int k;
  cin >> k;
  ll val = 0;
  for(int i = 1; i <= maxn ; i++)
  {
    val = (val * 10 + 7) % k;
    if(val == 0)
    {
      cout << i << endl;
      return 0;
    }
  }
  cout << "-1";
  return 0;
}

Measured memory_bytes: 3532
from fractions import Fraction
n,k=map(int,input().split())
times=[0]*n
for i in range(1,n+1):
    count=0
    j=1
    while True:
        if j*i<k:
            count+=1
            j=2*j
        else:
            break
    times[i-1]+=count
ans=0
for k in times:
    ans+=(Fraction(1,2))**k
print(ans.numerator/(ans.denominator*n))

Measured memory_bytes: 10816
import java.util.Scanner;

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

    	Scanner scanner=new Scanner(System.in);

    	int n =scanner.nextInt();
    	
    	int result=0;
    	
    	for(int i=0;i<n;i++) {
    		
    		int bufl=scanner.nextInt();
    		int bufr=scanner.nextInt();
    		
    		result+=(bufr-bufl)+1;
    		
    	}
    	
    	System.out.println(result);
    	
    	scanner.close();


    }

}

Measured memory_bytes: 26452
#include <iostream>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;

int main(){
    char a,b;	cin >> a >> b;
    if(a=='H' && b=='H')    cout << 'H' << endl;
    if(a=='H' && b=='D')    cout << 'D' << endl;
    if(a=='D' && b=='H')    cout << 'D' << endl;
    if(a=='D' && b=='D')    cout << 'H' << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int abcd;
  cin>>abcd;
  int flag[10];
  flag[3]=abcd%10; abcd/=10;
  flag[2]=abcd%10; abcd/=10;
  flag[1]=abcd%10; abcd/=10;
  flag[0]=abcd%10; abcd/=10;
  for(int bit=0;bit<(1<<4);bit++){
    int count=flag[0];
    string s;
    for(int i=1;i<4;i++){
      if(bit & (1<<i)){
	count+=flag[i];
	s+='+';
      }
      else{
	count-=flag[i];
	s+='-';
      }
    }
    if(count==7){
      rep(i,4){
	if(i!=3){
	  cout<<flag[i]<<s[i];
	}
	else{
	  cout<<flag[i];
	}
      }
      cout<<"=7"<<'\n';
      goto tmp;
    }
  }
 tmp:
  return(0);
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<ctype.h>

int main()
{
	char a[10000],b[10000];
	int n,i,j;
	scanf("%d %s %s",&n,&a,&b);
	for(i=0,j=0;i<n,j<n;i++,j++)
	{
		printf("%c%c",a[i],b[j]);
	}
return 0;
}

Measured memory_bytes: 128
import java.util.*;
import java.util.function.Predicate;

public class Main {

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {
        Scanner cin = new Scanner(System.in);
        N = cin.nextInt();
        A = new int[N];
        B = new int[N];
        C = new int[N];
        for (int i = 0; i < N; i ++){
            A[i] = cin.nextInt();
            B[i] = cin.nextInt();
            C[i] = cin.nextInt();
        }
        dp = new int[N][3];
        for (int i=0;i<N;i++){
            for (int j=0;j<3;j++){
                dp[i][j] = -1;
            }
        }

        System.out.println(Math.max(dfs(0,0), dfs(0, 1)));
    }

    int N;  //最大日数
    int[] A, B, C;  //それぞれの行動で得られる幸福度
    int[][] dp; // day, preChoiceの2引数に対する答えを記録する -1で初期化済み
    //何日目で最後に選んだのがどれの時に、これ以降最大どれだけの幸福度が得られるかを返す
    int dfs(int day, int preChoice) {
        //もし最終日であれば、もう幸福度は得られないので、0を返す
        if (day == N) return 0;
        //答えが計算済みであれば、dp配列から答えを返す
        if (dp[day][preChoice] != -1) return dp[day][preChoice];
        //最終日でなければ、3つの選択肢から選ぶ
        int chooseA, chooseB, chooseC;
        //選べない場合の最低値を入れておく。
        chooseA = chooseB = chooseC = Integer.MIN_VALUE;
        //A, B, Cをそれぞれ選んだ場合の幸福度を計算する
        if (preChoice != 0) chooseA = A[day] + dfs(day + 1, 0);
        if (preChoice != 1) chooseB = B[day] + dfs(day + 1, 1);
        if (preChoice != 2) chooseC = C[day] + dfs(day + 1, 2);
        //最も幸福度が高かったものを返す dp配列に記録する
        return dp[day][preChoice] = Math.max(chooseA, Math.max(chooseB, chooseC));
    }
}


Measured memory_bytes: 106396
#include<iostream>
#include<algorithm>
#include<map>
#include<cmath>
#include<vector>
#include<iomanip>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
ll a[114];
signed main() {
	ll n, ans = 0;
	cin >> n;
	rep(i, 2 * n)cin >> a[i];
	sort(a, a + 2 * n);
	reverse(a, a + 2 * n);
	for (int i = 1; i < 2 * n; i += 2)ans += a[i];
	cout << ans << endl;
	getchar(); getchar(); return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

h, w, k = map(int, input().split())
G = [[0]*w for _ in range(h)]
for _ in range(k):
  r, c, v = map(int, input().split())
  r -= 1
  c -= 1
  G[r][c] = v
dp = [[[0]*w for i in range(h)] for j in range(4)]
dp[0][0][0] = 0
dp[1][0][0] = G[0][0]
for i in range(h):
  for j in range(w):
    if j:
      dp[0][i][j] = dp[0][i][j-1]
      for k in range(1, 4):
        dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j-1]+G[i][j], dp[k][i][j-1])
    if i:
      dp[0][i][j] = max(dp[0][i][j], max(dp[0][i-1][j],dp[1][i-1][j],dp[2][i-1][j],dp[3][i-1][j]))
      dp[1][i][j] = max(dp[1][i][j], max(dp[0][i-1][j],dp[1][i-1][j],dp[2][i-1][j],dp[3][i-1][j])+G[i][j])
ans = max(dp[0][h-1][w-1],dp[1][h-1][w-1],dp[2][h-1][w-1],dp[3][h-1][w-1])
print(ans)

Measured memory_bytes: 429660
#include <iostream>

using namespace std;

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

  bool flag = true;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;

    if (a %2)
      continue;

    if (a % 5 == 0 || a %3 == 0)
      continue;


    flag = false;
    break;
  }

  if (flag)
    cout << "APPROVED" << endl;
  else
    cout << "DENIED" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>

using namespace std;

int SelectionSort(int A[],int N){
	int rs,minj;
	rs = 0;
	for(int i = 0 ;i<N;i++){
		minj = i;
		for (int j = i+1;j<N;j++)
		{
			if(A[j]<A[minj]) 
			{
				minj = j;
			}
		}
		swap(A[i],A[minj]);
		if(i != minj){
			rs++;	
		}
	}
	return rs;
} 

int main(){
	int A[100],N,rs;
	scanf("%d",&N);
	for (int i = 0;i<N;i++){
		scanf("%d",&A[i]);
	}
	rs = SelectionSort(A,N);
	for(int i = 0;i<N;i++){
		if(i) printf(" ");
		printf("%d",A[i]);
	}
	printf("\n%d\n",rs);
	return 0;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
template <typename T>
using V = std::vector<T>;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  V<i64> A(N), B(N);
  REP(i, N) cin >> A[i] >> B[i];
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  if (N % 2 == 1) {
    cout << B[N / 2] - A[N / 2] + 1 << endl;
  } else {
    int k = N / 2;
    cout << (B[k] + B[k - 1]) - (A[k] + A[k - 1]) + 1 << endl;
  }
}


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

char set1[5] = {'.',',','!','?',' '};
char set2[3] = {'a','b','c'};
char set3[3] = {'d','e','f'};
char set4[3] = {'g','h','i'};
char set5[3] = {'j','k','l'};
char set6[3] = {'m','n','o'};
char set7[4] = {'p','q','r','s'};
char set8[3] = {'t','u','v'};
char set9[4] = {'w','x','y','z'};

char slove(char key, int count){
	switch(key){
		case '1':
			count%=5;
			return set1[count];
			break;
			
		case '2':
			count%=3;
			return set2[count];
			break;
			
		case '3':
			count%=3;
			return set3[count];
			break;
			
		case '4':
			count%=3;
			return set4[count];
			break;
			
		case '5':
			count%=3;
			return set5[count];
			break;
			
		case '6':
			count%=3;
			return set6[count];
			break;
			
		case '7':
			count%=4;
			return set7[count];
			break;
			
		case '8':
			count%=3;
			return set8[count];
			break;
			
		case '9':
			count%=4;
			return set9[count];
			break;
			
		default:
			cout << "test" << endl;
			return 0;
	}
}


int main(){
	int n;
	while(cin>>n){
		string s;
		for(int i=0; i<n; i++){
			cin >> s;
			string ans="";
			for(string::size_type j=0; j<s.size(); j++){
				int count=0;
				char c=s[j];
				while(c!='0'){
					count++;
					c=s[j+count];
				}
				if(count!=0)
					ans += slove(s[j+count-1], count-1);
				

				j+=count;
			}
			cout << ans << endl;
		}
		
	}
	return 0;
}

Measured memory_bytes: 0
n = input()
k = int(input())

# dp[digit][smaller][used # of non-0]
# dp[i][j][l]
dp = [[[0 for _ in range(k+2)] for _ in range(2)] for _ in range(len(n)+1)]
dp[0][0][0]=1

for i in range(len(n)):
    nd = int(n[i])
    for j in [0, 1]:
        for l in range(k+1):
            for d in range(10):
                ni=i+1
                nj=j
                nl=l

                if d!=0:
                    nl+=1
                if nl>k:
                    continue
                if j==0: # equal to n
                    if d > nd:
                        continue
                    if d < nd:
                        nj=1 # smaller
                dp[ni][nj][nl] += dp[i][j][l]

print(dp[len(n)][0][k]+dp[len(n)][1][k])

Measured memory_bytes: 41200
#include<bits/stdc++.h>
using namespace std;
 
#define       pb(a)             push_back((a))
#define       mp(a,b)           make_pair((a),(b))
#define       REP(a,b)          for(ll i=(a);i<(b);i++)
#define       REP2(a,b)         for(ll j=(a);j<(b);j++)
#define       REPE(a,b,c,d)     REP(a,b)for(ll j=(c);j<(d);j++)
#define       REPV(a,b,c)       for(ll (a)=b;(a)<(c);(a)++)
#define       IREP(a,b)         for(ll i=(a);i>=(b);i--)
#define       IREP2(a,b)        for(ll j=(a);j>=(b);j--)
#define       IREPV(a,b,c)      for(ll (a)=b;(a)>=(c);(a)--)
#define       all(v)            (v).begin(),(v).end()
#define       Trvs(c)           for (auto it = (c).begin(); it != (c).end(); it++)
#define       INF               INT_MAX
#define       sz(x)             x.size()
#define       flash             ios_base::sync_with_stdio(false);cin.tie(NULL);
#define       F                 first
#define       S                 second
#define       MOD               1000000007
 
using         ll     = long long;
using         vi     = vector<int>;
using         vvi    = vector<vi>;
using         vll    = vector<ll>;
using         vvll   = vector<vll>;
using         vb     = vector<bool>;
using         vd     = vector<double>;
using         vs     = vector<string>;
using         pii    = pair<int, int>;
using         pll    = pair<ll, ll>;
using         pdd    = pair<double, double>;
using         vpii   = vector<pii>;
using         vvpii  = vector<vpii>;
using         vpll   = vector<pll>;
using         vvpll  = vector<vpll>;
using         vpdd   = vector<pdd>;
using         vvpdd  = vector<vpdd>;
 
 
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}

void solve(){
	string s,t;
	cin>>s>>t;
	cout<<t<<s;
}
 
 
int main(){
 
	flash
	/*
    #ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("output.txt","w",stderr);
	#endif
 	*/
   
	//ll t;cin>>t;while(t--)
	solve();
 
 
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 100000000
#define N 400005
#define vi vector<int>
#define all(v) v.begin(),v.end()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int a,b,n;
   cin>>a>>b>>n;
   int x=min(b-1,n);
   cout<<(a*x)/b<<endl;

}



Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;

int main(void)
{
    IOS
    int n, k;
    cin >> n >> k;
    vector<vector<int>> v(n,vector<int>());
    deque<int> su;      // 種類別1個目
    deque<int> deq;     // 2個目以降
    REP(i,n) {
        int t, d; cin >> t >> d;
        t--;
        v[t].emplace_back(d);
    }
    REP(i,n) sort(RALL(v[i]));
    
    ll d1 = 0;
    REP(i,n) {
        if (!v[i].empty()) {
            d1 += v[i].front();
            su.emplace_back(v[i].front());
            FOR(j,1,v[i].size()) deq.emplace_back(v[i][j]);
        }
    }

    sort(ALL(deq));
    sort(RALL(su));

    ll d2 = 0;
    ll kind = su.size();
    if ( kind > k ) {
        while (kind > k) {
            d1 -= su.back();
            kind--;
            su.pop_back();
        }
    } else if (kind < k) {
        FOR(i,kind,k) {
            d2 += deq.back();
            deq.pop_back();
        }
    }

    ll ans = kind * kind + d1 + d2;
    while(!deq.empty()) {
        ll tmp = (kind-1) * (kind-1) + d1 + d2 - su.back() + deq.back();
        if (ans < tmp) {
            kind--;
            d1 -= su.back();
            su.pop_back();
            d2 += deq.back();
            deq.pop_back();
            ans = tmp;
        } else break;
    }
    //cerr << kind << " " << d1 << " " << d2 << endl;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  string str;
  cin>>str;
  for(ll i=0;i<(ll)str.size();i++){
    if(str.at(i)=='R'){
      ll x=0;
      ll y=0;
      while(str.at(i)=='R'){
        i++;
        x++;
      }
      while(str.at(i)=='L'){
        i++;
        y++;
        if(i==(ll)str.size()){break;}
      }
      for(ll i=0;i<x-1;i++){cout<<0<<" ";}
      cout<<x/2+x%2+y/2<<" "<<x/2+y%2+y/2<<" ";
      for(ll i=0;i<y-1;i++){cout<<0<<" ";}
    }
    if(i==(ll)str.size()){break;}
    i--;
  }
}

Measured memory_bytes: 640
n = gets.to_i
vs = gets.strip.split.map(&:to_i).sort

tmp = 0
n.times do |i|
    cur = vs[i]
    nex = vs[i + 1]
    break if nex.nil?
    tmp = (cur + nex) / 2.0
    vs[i + 1] = tmp
end

puts vs[n - 1]

Measured memory_bytes: 1788
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;
typedef string::const_iterator State;

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




int main(void) {

	int N, C;
	int d[31][31] = {};
	int c[501][501] = {};
	int point = 0;
	int result = INF;
	int total[3][31] = {};

	cin >> N >> C;
	FOR(i, 1, C) {
		FOR(j, 1, C) {
			cin >> d[i][j];
		}
	}
	FOR(i, 1, N) {
		FOR(j, 1, N) {
			cin >> c[i][j];
		}
	}

	FOR(k, 1, C) {
		FOR(i, 1, N) {
			FOR(j, 1, N) {
				total[(i + j) % 3][k] += d[c[i][j]][k];
			}
		}
	}

	FOR(i, 1, C) {
		FOR(j, 1, C) {
			FOR(k, 1, C) {
				if (i == j || j == k || k == i) {
					continue;
				}
				point = 0;
				point += total[0][i] + total[1][j] + total[2][k];
				if (point < result) {
					result = point;
				}
			}
		}
	}

	cout << result << endl;
	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
const int N = 1e3 + 11;
#define rg register
int head[N*N], to[N*N*2], nex[N*N*2], sz;
struct ddd{
    int x, y, du, stp;
}node[N*N], now;
int A[N][N], dl[N*N], n;
bool mark[N*N];
inline int read(){
    rg int x = 0;
    rg char ch = getchar();
    while(ch > '9' || ch < '0')ch = getchar();
    while(ch >= '0' && ch <= '9')x = 10 * x + ch - 48, ch = getchar();
    return x;
}
int deal(int x, int y){
    if(x < y) swap(x, y);//x >= y;
    if(!mark[n*x+y])
        node[n*x+y] = (ddd){x, y};
    return n * x + y;
}
void add(int x, int y){
    mark[x] = mark[y] = 1;
    to[++sz] = y;
    nex[sz] = head[x];
    head[x] = sz;
    node[y].du++;
    //printf("x=%d y=%d x1=%d y1=%d x2=%d y2=%d\n", x, y, node[x].x, node[x].y, node[y].x, node[y].y);
}

int main(){
    cin>>n;
    for(rg int i = 1;i <= n; i++){
        for(rg int j = 1;j < n; j++){
            A[i][j] = read();
        }
    }
    int hd = 0, tl = 0;
    for(int i = 1;i <= n; i++){
        for(int j = 1;j < n; j++){
            if(j > 1){
                add(deal(i, A[i][j-1]), deal(i, A[i][j]));
            }
        }
    }
    for(int i = 1;i <= (n + 1) * (n + 1); i++){
        if(!mark[i])continue;
        if(node[i].du == 0){
            dl[++tl] = i;
            //printf("x=%d y=%d\n", node[i].x, node[i].y);
        }
    }
    int ans = -1;
    while(hd < tl){
        now = node[dl[++hd]];
        ans = max(ans, now.stp);
        for(int i = head[deal(now.x, now.y)];i;i = nex[i]){
            ddd &v = node[to[i]];
            if(--v.du == 0){
                dl[++tl] = to[i];
                v.stp = now.stp + 1;
            }
        }
        //printf("hd=%d x=%d y=%d\n", hd, now.x, now.y);
    }
    bool flag = 0;
    for(int i = 1;i <= (n + 1) * (n + 1); i++){
        if(node[i].du != 0)flag = 1;
    }
    if(flag){
        puts("-1");
    }
    else printf("%d\n", ans + 1);
    return 0;
}

Measured memory_bytes: 40960
if __name__ == '__main__':
    N,M,Q=list(map(int,input().split()))
    C=[[0 for _ in range(N+1)] for _ in range(N+1)]
    for i in range(1,M+1):
        l,r=list(map(int,input().split()))
        C[l][r]+=1
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            C[i][j]+=C[i][j-1]
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            C[i][j]+=C[i-1][j]
    for q in range(Q):
        l, r = list(map(int, input().split()))
        ans=C[r][r]+C[l-1][l-1]-C[l-1][r]-C[r][l-1]
        print(ans)










Measured memory_bytes: 59900
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]


s = input()

temp = sorted(s)

if (temp[0] == temp[1] and temp[2] == temp[3] and temp[1] != temp[2]):
    print("Yes")
else:
    print("No")



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

using namespace std;

#define pb push_back
#define ll long long
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define bug cout << "ok" << endl

const ll INF = 1e9 + 5, N = 1e5 + 5, mod = 1e9 + 7;

int main(){
	ll n, x, t;
	cin >> n >> x >> t;
	ll k = (n / x) + (n % x > 0);
	cout << k * t << endl;
}

Measured memory_bytes: 3592
#include<stdio.h>

int main(){
    int X;
    scanf("%d",&X);
    X+=5;
    if(X%7==0){
        printf("sat\n");
    }else if(X%7==1){
        printf("sun\n");
    }else if(X%7==2){
        printf("mon\n");
    }else if(X%7==3){
        printf("tue\n");
    }else if(X%7==4){
        printf("wed\n");
    }else if(X%7==5){
        printf("thu\n");
    }else if(X%7==6){
        printf("fri\n");
    }
    return 0;
}


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

#define ll long long
#define ld long double
#define ull unsigned long long
#define endl "\n"
#define MohamedMotaz ios::sync_with_stdio(0); cin.tie(0); ios_base::sync_with_stdio(0);
#define f(a, b, c) for(int a = b; a < c; a++)
using namespace std;
const ll mod = 1e9 + 7;



//ll fact[1000001]; ll inv[1000001];
//ll primes[100007];
//ll arr[1000007];
//ll modPower(ll b, ll p) {
//	if (p == 0)
//		return 1;
//
//	ll halfpow = modPower(b, p / 2);
//	ll toReturn = (halfpow * halfpow) % mod;
//	if (p % 2)
//		toReturn = (toReturn * b) % mod;
//
//	return toReturn;
//}
//
//ll fastPower(ll b, ll p) {
//	if (p == 0)
//		return 1;
//	ll ans = fastPower(b, p / 2);
//	ans = (ans * ans);
//	if (p % 2 != 0)
//		ans = (ans * b);
//	return ans;
//}
//ll GcdRecursive(ll a, ll b) {
//	if (b == 0) return a;
//	return GcdRecursive(b, a % b);
//}
//ll modLCM(ll a, ll b) {
//	ll val = GcdRecursive(a, b);
//	ll tmp = ((a % mod) * (b % mod)) % mod;
//	ll finalVal = ((tmp % mod) * (arr[val] % mod)) % mod;
//	return finalVal;
//
//}
//ll LCM(ll a, ll b) {
//	return (a * b) / GcdRecursive(a, b);
//}
//void move1step(ll& a, ll& b, ll q) { // a and b by reference
//	ll c = a - q * b;
//	a = b;
//	b = c;
//}
//ll GcdIterative(ll a, ll b) {
//	while (b) move1step(a, b, a / b);
//	return a;
//}
//
//void pre(ll n) {
//
//	fact[0] = 1;
//	inv[0] = 1;
//
//	for (ll i = 1; i <= n; i++) {
//		fact[i] = (i * fact[i - 1]) % mod;
//		inv[i] = modPower(fact[i], mod - 2);
//		arr[i] = modPower(i, mod - 2);
//	}
//}
//
//ll npr(ll n, ll r) {
//	return ((fact[n] * inv[n - r]) % mod);
//}
//
//ll ncr(ll n, ll r) {
//	return ((((fact[n] * inv[n - r]) % mod) * inv[r]) % mod);
//}
//
//void sieve(ll val) {
//	memset(primes, 1, sizeof primes);
//	primes[0] = primes[1] = false;
//	for (int i = 2; i <= val; i++) {
//		if (primes[i]) {
//			for (int j = i * i; j <= val; j += i) {
//				primes[j] = 0;
//			}
//		}
//	}
//
//}






int main()
{
    MohamedMotaz;

    ll x, y, a, b, c;

    cin >> x >> y >> a >> b >> c;

    vector<ll> aa(a), bb(b), ans;

    f(i, 0, a) cin >> aa[i];
    f(i, 0, b) cin >> bb[i];
    f(i, 0, c) { ll z; cin >> z; ans.push_back(z); }

    sort(aa.begin(), aa.end(), greater<ll>()), sort(bb.begin(), bb.end(), greater<ll>());

    f(i, 0, x) ans.push_back(aa[i]);
    f(i, 0, y) ans.push_back(bb[i]);

    sort(ans.begin(), ans.end(), greater<ll>());
    ll s = 0;
    f(i, 0, x + y) s += ans[i];
    cout << s;
}








Measured memory_bytes: 7792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
int n,k;
int s=0;
int main()
{
	cin >> n>>k;
	int h;
	for(int i=0;i<n;i++){
		cin >> h;
		if(h>=k) s++;
	}
	cout << s<<endl;
	return 0;
} 

Measured memory_bytes: 256
import java.util.Scanner;

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

        int n = sc.nextInt();
        int m = sc.nextInt();

        int maxL = 0;
        int minr = 100000;
        for (int i = 0; i < m; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();

            maxL = Math.max(maxL, l);
            minr = Math.min(minr, r);
        }
        
        int ans = 0;
        if (minr - maxL >= 0)
            ans = minr - maxL + 1;
        
        System.out.println(ans);
    }
}

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

int main() {
	int n,m;
	cin>>n>>m;
	vector<vector<int>> v(m);
	for (int i = 0; i < m; ++i) {
		int k; cin >> k;
		v[i].resize(k);
		for (int j = 0; j < k; ++j) {
			cin >> v[i][j];
			--v[i][j];
		}
	}
 
	vector<int> p(m);
	for (int i = 0; i < m; ++i) cin >> p[i];
 
	int ans = 0;
	for (int i = 0; i < (1 << n); ++i) {
		bool ok = true;
		for (int j = 0; j < m; ++j) {
			int c = 0;
			for (int id : v[j]) {
				if ((i >> id) & 1) {
					++c;
				}
			}
			c %= 2;
			if (c != p[j]) {
				ok = false;
			}
		}
		if (ok) {
			++ans;
		}
	}
 
	cout << ans << endl;
 
	return 0;
	
	


}

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

int main()
{
  int a,b;
  string s;
  cin>>s;
  a=((s.at(0)-'0')*10)+(s.at(1)-'0');
  b=((s.at(2)-'0')*10)+(s.at(3)-'0');
  if(a>=1&&a<=12)
  {
    if(b>=1&&b<=12)
      cout<<"AMBIGUOUS"<<endl;
    else
      cout<<"MMYY"<<endl;
  }
  else
  {
    if(b>=1&&b<=12)
      cout<<"YYMM"<<endl;
    else
      cout<<"NA"<<endl;
  }
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;

typedef long long lint;
int arr[100010];
vector<lint> V;

int contain(int N){
    int size=V.size();
    for(int i=0;i<size;i++)
        if(V[i]==N)return 1;
        return 0;
}

int main(void){
    int n;scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&arr[i]);
    sort(arr,arr+n);
    int A=-1,B=-1;
    for(int i=n-1;i>=1;i--)
        if(arr[i]==arr[i-1]){
            V.push_back(arr[i]);
            i--;
            if(V.size()>=2)break;
        }
    if(V.size()<2)printf("0\n");
    else printf("%lld\n",V[0]*V[1]);
    return 0;
}


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

#define NIL -2
#define INF 1000000001
#define EPS 1e-10
#define equals(a,b) (fabs((a) - (b)) < EPS)

using namespace std;
class Point{
    public:
    double x,y;

    Point(double x = 0,double y = 0): x(x), y(y) {}

    Point operator + (Point p){ return Point(x+p.x, y+p.y); }
    Point operator - (Point p){ return Point(x-p.x, y-p.y); }
    Point operator * (double k){ return Point(x*k,y*k);     }
    Point operator / (double k){ return Point(x/k,y/k);     }

    double norm(){ return x*x + y*y;}
    double abs(){ return sqrt(norm());}
    double dot(Point p){
        return x*p.x + y*p.y;
    }
    double prod(Point p){
        return x*p.y - y*p.x;
    }

    bool operator < (Point &p){
        return x != p.x ? x < p.x : y < p.y;
    }
    bool operator == (Point &p){
        return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
    }
  
};
typedef Point Vector;

int ccw(Point p0, Point p1,Point p2){
    Vector p10 = p1 - p0;
    Vector p20 = p2 - p0;
    double prod = p10.prod(p20);
    if(prod > EPS) return 1;
    if(prod < -EPS) return -1;
    if(p10.dot(p20) < -EPS) return 2;
    if(p10.abs() < p20.abs()) return -2;
    return 0; 
}

bool intersection(Point p0,Point p1,Point p2, Point p3){
    return ( ccw(p0,p1,p2) * ccw(p0,p1,p3) <= 0 ) && ( ccw(p2,p3,p0) * ccw(p2,p3,p1) <= 0 ) ;
}

int main(){
    double p0x,p0y,p1x,p1y;
    double p2x,p2y,p3x,p3y;
    int q;
    
    scanf("%d",&q);
    for(int i = 0;i < q;i++){
        scanf("%lf %lf %lf %lf",&p0x,&p0y,&p1x,&p1y);
        scanf("%lf %lf %lf %lf",&p2x,&p2y,&p3x,&p3y);
        Point p0(p0x,p0y);
        Point p1(p1x,p1y);
        Point p2(p2x,p2y);
        Point p3(p3x,p3y);
        int ans = (intersection(p0,p1,p2,p3))? 1 : 0;
        printf("%d\n",ans);
        
    }
    return 0;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int MOD=1000000007;
using namespace std;
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

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


Measured memory_bytes: 256
import std.functional,
       std.algorithm,
       std.container,
       std.typetuple,
       std.typecons,
       std.bigint,
       std.string,
       std.traits,
       std.array,
       std.range,
       std.stdio,
       std.conv;

N abs(N)(N a) {
  return a * (a < 0 ? -1 : 1);
}

void main() {
  long N = readln.chomp.to!long;
  long[] A = readln.chomp.split.to!(long[]);
  long[] B = new long[](N);
  long ans;

  foreach (long i, a; A) {
    B[i] = a - (i + 1);
  }
  B.sort!"a<b";
  long b = B[N/2];

  foreach (e; B) {
    ans += abs(e - b);
  }

  writeln(ans);
}


Measured memory_bytes: 11632
import sys
from itertools import groupby, accumulate

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K = map(int, readline().split())
    S = readline().strip()

    vec = [len(list(g)) for _, g in groupby(S)]
    keys = [k for k, _ in groupby(S)]
    csum = [0]
    csum.extend(accumulate(vec))

    ans = 0
    for i in range(len(vec)):
        if keys[i] == '0':
            if i == 0:
                n = 2 * K
            else:
                continue
        else:
            n = 2 * K + 1

        if ans < csum[min(i + n, len(csum) - 1)] - csum[i]:
            ans = csum[min(i + n, len(csum) - 1)] - csum[i]

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 14688
#include <bits/stdc++.h>
using namespace std;
const int N=109;
int n,m,x,c[N],a[N][N],p[N],ans=1000000000;
void dfs(int s,int price){
    if(s==n+1){
        for(int i=1;i<=m;i++){
            if(p[i]<x) return;
        }
        ans=min(ans,price);
        return;
    }
    dfs(s+1,price);
    for(int i=1;i<=m;i++) p[i]+=a[s][i];
    dfs(s+1,price+c[s]);
    for(int i=1;i<=m;i++) p[i]-=a[s][i];
}
int main(void){
    cin >> n>> m >>x;
    for(int i=1;i<=n;i++){
        cin >> c[i];
        for(int j=1;j<=m;j++){
            cin >> a[i][j];
        }
    }
    dfs(1,0);
    if(ans>=1000000000) cout<<"-1";
    else cout << ans;
}

Measured memory_bytes: 3580
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

const int INF = 1e9;
const int MAXK = 1e5+10;

int calc(int x){
	int ret = 0;
	while(x>0) {
		ret += x%10;
		x/=10;
	}
	return ret;
}

int dis[MAXK];
int main() {
	int K;
	scanf("%d", &K);
	// if(calc(K)%9==0) {
	// 	printf("%d", calc(K));
	// 	return 0;
	// }

	for(int i=0;i<K;i++)
		dis[i] = INF;

	int st = calc(K)%K;
	queue<int> q;
	q.push(1);
	dis[1] = 0;

	while(!q.empty()) {
		int cur = q.front();
		q.pop();

		int nxt = cur*10%K;
		if(dis[cur] < dis[nxt]) {
			dis[nxt] = dis[cur];
			q.push(nxt);
		}
		nxt = (cur+1)%K;
		if(dis[cur]+1 < dis[nxt]) {
			dis[nxt] = dis[cur]+1;
			q.push(nxt);
		}
	}

	// for(int i=0;i<K;i++)
	// 	printf("%d ", dis[i]);
	// puts("");

	printf("%d", dis[0]+1);	
	return 0;	
}

Measured memory_bytes: 768
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		ArrayList<Integer> a = new ArrayList<Integer>();
		ArrayList<String> op = new ArrayList<String>();
		ArrayList<Integer> b = new ArrayList<Integer>();
		ArrayList<Integer> ans = new ArrayList<Integer>();
		
		do {
			a.add(scan.nextInt());
			op.add(scan.next());
			b.add(scan.nextInt());
		} while (!op.contains("?"));
		for (int i = 0; i < op.size(); i++) {
			int _a = a.get(i);
			int _b = b.get(i);
			if (op.get(i).equals("+")) {
				ans.add(_a + _b);
			} else if (op.get(i).equals("-")) {
				ans.add(_a - _b);
			} else if (op.get(i).equals("*")) {
				ans.add(_a * _b);
			} else if (op.get(i).equals("/")) {
				ans.add(_a / _b);
			} else break;
			System.out.println(ans.get(i));
		}
	}
	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}
}

Measured memory_bytes: 26248
using System;
using System.Collections.Generic;

class main
{
    public static int Main()
    {
        string x = Console.ReadLine();
        string[] str = x.Split(' ');
        List<int> list = new List<int>();
        list.Add(int.Parse(str[0]));
        list.Add(int.Parse(str[1]));
        list.Add(int.Parse(str[2]));

        list.Sort();

        Console.WriteLine("{0} {1} {2}", list[0], list[1], list[2]);

        return 0;
    }
}

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

int main(){
  int n;
  cin >> n;
  for(int i=1;i<10;i++){
    for(int j=1;j<10;j++){
      if(n==i*j){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}

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

list = [[0 for i in range(10)] for j in range(10)]

cnt = 0

for i in range(1, N+1):
    head = int(str(i)[0])
    tail = int(str(i)[len(str(i)) - 1])
    list[head][tail] += 1

for i in range(1, 10):
    for j in range(1, 10):
        cnt += list[i][j] * list[j][i]
print(cnt)

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

typedef long long ll;
const ll INF = 1e18;
const int BIG = 1e9 + 555;

ll m, k;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin >> m >> k;

	if(m == 0){
		if(k == 0){
			cout << "0 0\n";
		} else {
			cout << "-1\n";
		}
		return 0;
	}

	if(m == 1){
		if(k == 0){
			cout << "0 0 1 1\n";
		} else {
			cout << "-1\n";
		}
		return 0;
	}

	int n = (1LL << m) - 1;

	if(k > n){
		cout << "-1\n";
		return 0;
	}

	for(int i = 0; i < k; i++){
		cout << i << ' ';
	}
	cout << k << ' ';
	for(int i = k - 1; i >= 0; i--){
		cout << i << ' ';
	}
	
	for(int i = k + 1; i <= n; i++){
		cout << i << ' ';
	}
	cout << k << ' ';
	for(int i = n; i >= k + 1; i--){
		cout << i << ' ';
	}
	cout << '\n';
		
	//int x = 0;
	//for(int i = 0; i <= n; i++){
	//	if(k == i){
	//		continue;
	//	}
	//
	//	x ^= i;
	//}

	//cout << x << ' ' << k << '\n';

	return 0;
}

Measured memory_bytes: 1792
/* Includes */
#include <stdio.h>

/* Prototypes */
char evaluateStudent(int val1, int val2, int val3);

/* Values */
int m;              /* the midterm examination  (out of 50) */
int f;              /* the final examination    (out of 50) */
int r;              /* the makeup examination   (out of 50) */

char listStudents[50];

int cnt;

/* Main */
int main()
{
    for (int i = 0; i < 50; i++) {
        scanf("%d %d %d", &m, &f, &r);

        if ((m == -1) && (f == -1) && (r == -1)) {
            break;
        }
        else {
            /* NOP */
        }

        listStudents[i] = evaluateStudent(m, f, r);

        cnt = i;
    } 

    for (int i = 0; i <= cnt; i++) {
        printf("%c\n", listStudents[i]);
    }
}

/* Sub */
char evaluateStudent(int val1, int val2, int val3)
{
    if ((val1 == -1) || (val2 == -1)) {
        return 'F';
    }
    else {
        if ((val1 + val2) >= 80) {
            return 'A';
        }
        else if ((65 <= (val1 + val2)) && ((val1 + val2) < 80)) {
            return 'B';
        }
        else if ((50 <= (val1 + val2)) && ((val1 + val2) < 65)) {
            return 'C';
        }
        else if ((30 <= (val1 + val2)) && ((val1 + val2)< 50)) {
            if (val3 >= 50) {
                return 'C';
            }
            else {
                return 'D';
            }
        }
        else {
            return 'F';
        }
    }
}


Measured memory_bytes: 2120
N = int(input())
B = list(map(int,input().split()))
ans_rev = []

for i in range(N):
	rem = None
	for j in range(N-i):
		if B[j] == j+1:
			rem = j
	if rem == None:
		print("-1")
		exit()

	B.pop(rem)
	ans_rev.append(rem+1)

ans = [ans_rev[N-1-i] for i in range(N)]
for a in ans:
	print(a)


Measured memory_bytes: 3060
import java.util.Scanner;
import static java.lang.Math.abs;

public class Main {
  public static void main(String[] args) {
    int[] myArgs = new int[3];
    Scanner sc = new Scanner(System.in);
    myArgs[0] = sc.nextInt();
    myArgs[1] = sc.nextInt();
    myArgs[2] = sc.nextInt();

    Main logic = new Main();
    String output = logic.exec(myArgs);
    System.out.print(output);

  }

  private String exec(int[] myArgs) {
    long minCost = Long.MAX_VALUE;
    for (int i = 0;i < 3;i++) {
      for (int j = 0;j < 3;j++) {
        if (i != j) {
          long cost0 = abs(myArgs[i] - myArgs[j]);
          for (int k = 0;k < 3;k++) {
            if (i != k && j != k) {
              long cost1 = cost0 + abs(myArgs[j] - myArgs[k]);
              if (minCost > cost1) {
                minCost = cost1;
              }
              break;
            }
          }
        }
      }
    }
    return String.valueOf(minCost);
  }
}


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

int main() {
    int a, b, k;
    cin >> a >> b >> k;
    vector<int> ans;
    for (int i = 0; i < 100; i++){
        if (a % (i + 1) == 0 && b % (i + 1) == 0){
            ans.push_back(i + 1);
        }
    }
    
    /*for (int i = 0; i < ans.size(); i++){
        cout << ans.at(i) << endl;
    }*/
    reverse(ans.begin(), ans.end());
    
    cout << ans.at(k - 1) << endl;
    
    
    
}

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

int n;
int a[200050], num[200050];

int main() {
    cin >> n;
    for(int i = 0; i < n; i++) cin >> num[i], a[i] = num[i];
    sort(num, num+n);
    for(int i = 0; i < n; i++){
        if(a[i] < num[n/2]) cout << num[n/2] << endl;
        else cout << num[n/2-1] << endl;
    }
}

Measured memory_bytes: 3712
'use strict'

const INF = 900719925474099;


function Main(input){
    let temp = input.trim().split(' ');
    let a = parseInt(temp[0]);
    let b = parseInt(temp[1]);

    if(a>=13){
        console.log(b);
    }else if(a>=6){
        console.log(b/2);
    }else{
        console.log(0);
    }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21064
#include<bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,t;
    string x;
    cin>>n;
    string s;
    vector<string> m(n+1);
    vector<int> cs(n+1);
    cs[0]=0;
    for(int i=1;i<n+1;i++){
        cin>>m[i]>>t;
        cs[i]=cs[i-1]+t;
    }
    cin>>x;
    for(int i=1;i<=n;i++){
        if(x==m[i]){cout<<cs[n]-cs[i];return 0;}
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<string>
#include<algorithm>
#define REP(i,n) for(int i=0; i<int(n); i++)
using namespace std;
int main() {
	string S;
	cin >> S;
	if (S == "Sunny") {
		cout << "Cloudy" << endl;
	}
	else if (S == "Cloudy") {
		cout << "Rainy" << endl;
	}
	else if (S == "Rainy") {
		cout << "Sunny" << endl;
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e10;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int n;
  cin >> n;
  rep(i, 100) {
    rep(j, 100) {
      if (i * 4 + j * 7 == n) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define SORTG(v) sort(v.begin(),v.end(),greater<>())
#define SORT(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/3

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<string> Vs;

template<class T> void chmax(T& a, T b) {if(a<b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a>b){a=b;}}
void YesNo(int a) {if(a){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}}
void YESNO(int a) {if(a){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}}
void AorB(int a,string b,string c) {if(a){cout<<b<<endl;}else{cout<<c<<endl;}}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void start(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);}


signed main(){start();
    int n,m,k;
    cin>>n>>m>>k;
    REP(i,0,n+1){
        REP(j,0,m+1){
            int black=i*(m-j)+(n-i)*j;
            if(k==black){cout<<"Yes"<<endl;return 0;}
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    long k = sc.nextLong();

    if ((k % 2) != 0) {
      if (Math.abs(a - b) > (long) Math.pow(10, 18)) {
        System.out.println("Unfair");
      } else {
        System.out.println(b - a);
      }
    } else {
      if (Math.abs(a - b) > (long) Math.pow(10, 18)) {
        System.out.println("Unfair");
      } else {
        System.out.println(a - b);
      }
    }

  }
}

Measured memory_bytes: 35716
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  int j=0;
  cin >> S;
 
  for(int i=0;i<3;i++){
    if(S.at(i) == 'A'){
        j++;
    }else{
        j--;
    }
  }
  
  if(j==3||j==-3){
      cout << "No" << endl;
  }else{
      cout << "Yes" << endl;
  }
  
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        HashMap<Integer,Integer> odds = new HashMap<>();
        HashMap<Integer,Integer> evens = new HashMap<>();
        int a = sc.nextInt();
        String s = sc.next();
        System.out.println(a >= 3200 ? s : "red");
    }
}


class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 20692
#include<iostream>

using namespace std;

int main() {
    while(1){
      int n;
      cin >> n;
      if(n==0) break;
      int min = 1000000000;
      int fee;
      for(int a=0;a<=n/200+1;a++){
	for(int b=0;b<=n/300+1;b++){
	  for(int c=0;c<=n/500+1;c++){
	    if(a*200+b*300+c*500==n){
	      fee=a*380+b*550+c*850;
	      if(a>=5) fee+=((a/5)*5*380)*0.8-((a/5)*5*380);
	      if(b>=4) fee+=((b/4)*4*550)*0.85-((b/4)*4*550);
	      if(c>=3) fee+=((c/3)*3*850)*0.88-((c/3)*3*850);
      if(min>fee) min=fee;
	    }
	  }
	}
      }	
      cout << min <<endl;
     } 
   return 0;
    }



Measured memory_bytes: 2964