akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,fo=0,ba=0;
  cin>>a>>b>>c;
  int k[b];
  for(int i=0;i<b;i++){
    cin>>k[i];
  }
  
  for(int i=c;i<a+1;i++){
    for(int m=0;m<b;m++){
      if(k[m]==i) fo+=1;
    }
  }
  for(int i=c;i>0;i--){
    for(int m=0;m<b;m++){
      if(k[m]==i) ba+=1;
    }
  }
  cout<<min(fo,ba)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#define INF 1000000007
using namespace std;

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


int main() {

	int a, b, c;
	cin >> a >> b >> c;
	int s[3] = { a,b,c };
	int oc = 0;
	int k = 0;

	if (a % 2 == 1) {
		oc += 1;
	}
	if (b % 2 == 1) {
		oc += 1;
	}
	if (c % 2 == 1) {
		oc += 1;
	}
	

	for (int i = 0; i < 3; i++) {
		for (int k = 0; k < 3; k++) {
			if (s[i] > s[k]) { swap(s[i], s[k]); }
		}
	}
	


	//s[0]が最大
	
	if (oc == 1) {
		for (int i = 0; i < 3; i++) {
			if (s[i] % 2 == 0) { s[i] += 1; }
		}
		k += 1;
	}
	else if (oc == 2) {
		for (int i = 0; i < 3; i++) {
			if (s[i] % 2 == 1) { s[i] += 1; }
		}
		k += 1;
	}
	
	
	cout << (s[0] - s[1]) / 2 + (s[0] - s[2]) / 2 + k << endl;


	return 0;
}




Measured memory_bytes: 256
N=int(input())
L=list(map(int, input().split()))
L.sort(reverse=True)
unique_vals=sorted(set(L), reverse=True)

count=0
#print(unique_vals)
for i, first in enumerate(unique_vals):
    for j, second in enumerate(unique_vals[i+1:]):
        for third in unique_vals[i+j+2:]:
            if third > first - second:
                count+=1*L.count(first)*L.count(second)*L.count(third)
                #print(first, second, third)
                #print(count)
            else:
                break
print(count)

Measured memory_bytes: 9172
import sys
import itertools
import queue
import numpy as np
input = sys.stdin.readline
sys.setrecursionlimit(100000)
# mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def main():
    X, Y ,Z = read_values()
    print(Z, X, Y)


if __name__ == "__main__":
    main()


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

signed main(){
  int X,ans=0;
  cin>>X;
  int Xnum=X/100;
  if(Xnum*100<=X&&X<=Xnum*105)ans=1;
  cout<<ans<<endl;
}

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

const int MAXN = 8;
bool graph[MAXN][MAXN];

int dfs(int v, int N, bool visited[]) {
	bool allV = true;
	for (int i = 0; i < N; i++)if (visited[i] == false)allV = false;
	if (allV)return 1;

	int ret = 0;
	for (int i = 0; i < N; i++) {
		if (graph[v][i] == false || visited[i])continue;
		visited[i] = true;
		ret += dfs(i, N, visited);
		visited[i] = false;
	}
	return ret;
}

int main() {
	int N, M; cin >> N >> M;
	for (int i = 0, a, b; i < M; i++) {
		cin >> a >> b;
		graph[a - 1][b - 1] = graph[b - 1][a - 1] = true;
	}

	bool visited[MAXN];
	for (int i = 0; i < N; i++) {
		visited[i] = false;
	}
	visited[0] = true;
	cout << dfs(0, N, visited) << endl;

	return 0;
}

Measured memory_bytes: 256
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll N;
ll arrA[200005];
ll arrB[200005];

int main() {
	scanf("%lld", &N);
	for(int i = 1; i <= N; i++) {
		scanf("%lld", &arrA[i]);
	}
	for(int i = N; i > N / 2; i--) {
		arrB[i] = arrA[i];
	}
	for(int i = N / 2; i >= 1; i--) {
		int x = 2;
		int tempAns = 0;
		for(int j = i * x; j <= N; j = i * x) {
			tempAns += arrB[j];
			x++;
		}
		if(tempAns % 2 == arrA[i]) {
			arrB[i] = 0;
		}
		else {
			arrB[i] = 1;
		}
	}
	ll cnt = 0;
	for(int i = 1; i <= N; i++) {
		// cout << arrB[i] << " ";
		if(arrB[i]) {
			cnt++;
		}
	}
	printf("%lld\n", cnt);
	for(int i = 1; i <= N; i++) {
		if(arrB[i]) {
			cout << i << " ";
		}
	}
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 3968
#include <stdio.h>
 

long long euclidGcd(long long inputNum1, long long inputNum2)
{
	long long minNumGcd = 0;
	long long maxNumGcd = 0;
	long long euclideanAlgorithmGcd = 1;	//ユークリッドの互除法によりGcd(greatest common divisor)最大公約数

	//--
	//数値の大小関係(--> if,else)
	//ユークリッドの互除法により最大公約数を求める。euclideanAlgrithimGcdを0にしないように、while実行されない(--> for(交換))
	//最大公約数を返す(--> return)
	if (inputNum1 > inputNum2)
	{
		maxNumGcd = inputNum1;	
		minNumGcd = inputNum2;
	}
	else
	{
		maxNumGcd = inputNum2;
		minNumGcd = inputNum1;
	}


	while (euclideanAlgorithmGcd != 0)
	{
		//見にくい
		euclideanAlgorithmGcd = maxNumGcd % minNumGcd;	// aaa = bbb % ccc;
		maxNumGcd = minNumGcd;							// bbb = ccc;
		minNumGcd = euclideanAlgorithmGcd;				// ccc = aaa;
	}

	
	euclideanAlgorithmGcd = maxNumGcd;
	return euclideanAlgorithmGcd;
	//--
}

long long euclidLcm(long long inputNum1, long long inputNum2, long long inputNumGcd)
{
	long long euclideanAlgorithmLcm = 0;	

	//--
	//最小公倍数の公式　＝ inputNum1 * inputNum2 /euclideanAlgorithmGcd(最大公約数);(--> 公式
	euclideanAlgorithmLcm = inputNum1 * (inputNum2 / inputNumGcd);
	//--
	return euclideanAlgorithmLcm;

}


int main(void)
{
	int input = 0;
	long long answer = 0;
	long long euclideanAlgorithmGcd = 0;

	long long t[100] = {};

	//数字を受け取る(--> scanf N個入力される予定)
	//数値の受け取り(--> for(scanf))
	//ユークリッドの互除法により、最小公倍数を計算(--> for(euclidGcd,euclidLcm))
	//答えの表示(--> printf)
	//-
	scanf("%d", &input);

	for (int i = 0; i < input;++i)
	{
		scanf("%lld",&t[i]);
	}

	answer = t[0];

	for (int i = 0; i < input - 1; i++) {
		euclideanAlgorithmGcd = euclidGcd(answer, t[i + 1]);
		answer = euclidLcm(answer, t[i + 1], euclideanAlgorithmGcd);
	}
	
	printf("%lld", answer);
	//--

	return 0;

}


Measured memory_bytes: 128
import java.util.*;


public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String A = sc.next();
        int[] cnt = new int[26];
        for (int i = 0; i < A.length(); i++) {
            cnt[A.charAt(i)-'a']++;
        }
        long ans = (long)(A.length())*(A.length()-1)/2+1;
        for (int i = 0; i < cnt.length; i++) {
            if (cnt[i] >= 2) ans -= (long)cnt[i]*(cnt[i]-1)/2;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 26788
/**
 * Martin Leshko (leshko.martin@gmail.com)
 */

#include <bits/stdc++.h>

using namespace std;

#define psb push_back

#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define for1n(i, n) for (int i = 1; i <= (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pii;
#define what_is(x) cerr << #x << " is " << x << endl;
#define remplir(a, z) memset(a, z, sizeof(a))
#define all(x) (x).begin(), (x).end()

void faststdio()
{
#ifndef abacaba
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
#endif
}

int main()
{
	faststdio();
	int n;
	cin >> n;
	cout << n * n * n << endl;
	return 0;	
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>

using namespace std;

int main() {
    bool sieve[1000001];
    fill_n((bool *)sieve, 1000001, true);
    sieve[0] = sieve[1] = false;
    for (int i = 2; i < 1000001; i++) {
        for (int j = i+i; j < 1000001; j += i) {
            sieve[j] = false;
        }
    }

    int a, b;
    while (cin >> a >> b, a|b) {
        int suma = 0, sumb = 0;
        for (int i = 2; i < 1000001; i++) {
            if (a == 1 && b == 1) break;
            if (sieve[i]) {
                if (a % i == 0) {
                    while (a % i == 0) a /= i;
                    if (a != 1) suma += i;
                    else suma = i - suma;
                }
                if (b % i == 0) {
                    while (b % i == 0) b /= i;
                    if (b != 1) sumb += i;
                    else sumb = i - sumb;
                }
            }
        }
        if (suma >= sumb) cout << "a" << endl;
        else cout << "b" << endl;
    }

    return 0;
}

Measured memory_bytes: 2124
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n ; ++i)
#define REP(i,a,b) for(int i=a; i<b; ++i)
typedef long long ll;
//プロトタイプ宣言
int gcd(int , int);


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








































//以下、ライブラリ
//ユークリッドの互除法

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



Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
	
	int a,b,c;
	int x, z=0;

	scanf("%d %d %d\n", &a, &b, &c);
	if (1<=a && a <= 10000 && 1<=b && b <= 10000 && 1<=c && c <=10000) {
		if (a <= b) {
			x = a;
			while (1) {
				if ((c%x) == 0) z++;
				x++;
				if (x==(b+1)) break;
			}
		}
	}
	
	printf("%d\n", z);
	
	return 0;
}

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

int main(){
    int y[7];
    int x[6][6]={{0,3,5,2,4,0},{4,0,1,6,0,3},{2,6,0,0,1,5},{5,1,0,0,6,2},{3,0,6,1,0,4},{0,4,2,5,3,0}};
    int a,b,c,d;
    int q;
    cin>>y[1]>>y[2]>>y[3]>>y[4]>>y[5]>>y[6];
    cin>>q;
    for(int i=0;i<q;i++){
        cin>>a>>b;
        for(int j=1;j<=6;j++){
            if(a==y[j]){
                c=j;
            }
            if(b==y[j]){
                d=j;
            }
        }
        cout<<y[x[c-1][d-1]]<<endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N; cin >> N;
	vector<int>dp(N + 1, INF);
	dp[0] = 0;
	int price[] = { 6,9 };
	rep(i, N) {
		chmin(dp[i + 1], dp[i] + 1);
		rep(j, 2) {
			int x = price[j];
			int y = x;
			while (i + x <= N) {
				dp[i + x] = min(dp[i + x], dp[i] + 1);
				x *= y;
			}
		}
	}
	cout << dp[N] << "\n";

	return 0;
}

Measured memory_bytes: 640
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class EWhoSaysAPun {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int N;
        in>>N;
        string S;
        in>>S;
        int left = 0, right = N / 2 + 1;
        unordered_map<string, int> M;
        while(1<right-left){
            int mid = (left+right) >> 1;
            bool ok = false;
            REP(i, N-mid+1){
                string cur = S.substr(i, mid);
                auto itr = M.find(cur);
                if(itr==M.end()){
                    M[cur] = i;
                }else{
                    if(i>itr->second+mid-1){
                        ok = true;
                        break;
                    }
                }
            }
            if(ok) left = mid;
            else right = mid;
            M.clear();
        }
        out<<left<<'\n';
    }
};


int main() {
	EWhoSaysAPun solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 9948
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007LL;

template <class _T> static _T tp_abs(const _T& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}

static void C_task();

int main()
{
	C_task();
	fflush(stdout);
	return 0;
}

static void C_task()
{
	int N, K, Q;
	get3int(N, K, Q);

	std::map<int, int> pt;
	for (int i = 0; i < Q; i++) {
		int ans;
		get1int(ans); ans--;
		pt[ans]++;
	}

	for (int i = 0; i < N; i++) {
		int ansCnt = 0;
		if (pt.find(i) != pt.end()) {
			ansCnt = pt[i];
		}
		if ((K - Q + ansCnt) > 0) {
			printf("Yes\n");
		}
		else {
			printf("No\n");
		}
	}
}


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


void fastIO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
}


int main()
{
    fastIO();

    vector<vector<int>> arr(3, vector<int> (3));

    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin >> arr[i][j];
        }
    }

    int n;
    cin >> n;
    unordered_set<int> st;
    for(int i=0;i<n;i++){
        int b;
        cin >> b;
        st.insert(b);
    }
    int cnt = 0;
    for(int i=0;i<3;i++){
        cnt = 0;
        for(int j=0;j<3;j++){
            if(st.find(arr[i][j]) != st.end())
                cnt++;
        }
        if(cnt == 3){
            cout << "Yes" << '\n';
            return 0;
        }
    }
    for(int i=0;i<3;i++){
        cnt = 0;
        for(int j=0;j<3;j++){
            if(st.find(arr[j][i]) != st.end())
                cnt++;
        }
        if(cnt == 3){
            cout << "Yes" << '\n';
            return 0;
        }
    }
    cnt = 0;
    for(int i=0,j=0;i<3&&j<3;i++,j++){
        if(st.find(arr[i][j]) != st.end())
            cnt++;
    }

    if(cnt == 3){
        cout << "Yes" << '\n';
        return 0;
    }
    cnt = 0;
    for(int i=0,j=2;i<3&&j>=0;i++,j--){
        if(st.find(arr[i][j]) != st.end())
            cnt++;
    }

    if(cnt == 3){
        cout << "Yes" << '\n';
        return 0;
    }
    cout << "No" << '\n';

    return 0;
}


Measured memory_bytes: 256
<?php
  
fscanf(STDIN,"%d",$n);
$arr = explode(" ",trim(fgets(STDIN)));

$count;
for($i=0; $i<$n; $i++){
	if($arr[$i] != $i+1){
    	$count ++;
    }
}

if ($count == 2||$count == 0){
	echo 'YES';
}else{
	echo 'NO';
}

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

int main()
{

  int64_t a, b, c, d;
  cin >> a >> b >> c >> d;
  int64_t Max = -1000000000000000000;
  
  
      if(a<0 && c<0){
        Max = max(Max, a*c);
      }
      if(b>0 && d>0){
        Max = max(Max, b*d);
      }
      Max = max(Max,max(a * d, b * c));

      cout << Max << endl;

      return 0;
}


Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Scanner;

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

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int M = scan.nextInt();
        int ans = 0;
        for (int i = 0; i < N + M; i++) {
            for (int j = 0; j < N + M; j++) {
                if (i == j) {
                    continue;
                }
                int t = 0;
                t += i < N ? 2 : 3;
                t += j < N ? 2 : 3;
                if (t % 2 == 0) {
                    ans += 1;
                }
            }
        }
        System.out.println(ans/2);
    }
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll N, M;
	cin >> N >> M;
	vector<ll> kosu(N, 1);
	vector<bool> flag(N, false);
	flag[0] = true;
	REP(i, M){
		ll a, b;
		cin >> a >> b;
		a--;b--;
		kosu[a]--;kosu[b]++;
		if(flag[a]==true) flag[b] = true;
		if(kosu[a]==0) flag[a] = false;
	} 
	ll res = 0;
	REP(i, N) res += flag[i];
	cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

int N;
int a[100010];

int main(){
	scanf("%d" , &N);
	for(int i = 1 ; i <= N ; ++i){
		scanf("%d" , a + i);
	}
	int x = 0;
	for(int i = 1 ; i <= N ; ++i) if(a[a[i]] == i) ++x;
	printf("%d\n" , x / 2);
	return 0;
}


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

int number[6];
int relative[55];

class Dice {
public:
    Dice(){
		relative[31] = relative[43] = relative[24] = relative[12] = 0;
		relative[3] = relative[20] = relative[52] = relative[35] = 1;
		relative[1] = relative[40] = relative[54] = relative[15] = 2;
		relative[4] = relative[10] = relative[51] = relative[45] = 3;
		relative[2] = relative[30] = relative[53] = relative[25] = 4;
		relative[21] = relative[42] = relative[34] = relative[13] = 5;
 	};
    void setLabel(int index, int num) {
        number[index] = num;
    }
    int returnRight(int top, int front) {
        int top_index, front_index;
        for (int i = 0; i < 6; i++) {
            if (top == number[i]) top_index = i;
            if (front == number[i]) front_index = i;
        }
        return number[relative[10 * top_index + front_index]];
    }
};

int main() {
    Dice dice;
    int label[6];
    for (int i = 0; i < 6; i++) {
        cin >> label[i];
        dice.setLabel(i, label[i]);
    }
    int label_ref[6];
    for (int i = 0; i < 6; i++) cin >> label_ref[i];
    if (dice.returnRight(label_ref[0], label_ref[1]) == label_ref[2]) {
        if (dice.returnRight(label_ref[0], label_ref[2]) == label_ref[4]) {
            if (dice.returnRight(label_ref[0], label_ref[4]) == label_ref[3]) cout << "Yes" << endl;
            else cout << "No" << endl;
        }
        else cout << "No" << endl;
    }
    else cout << "No" << endl;
}


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#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)

const int MC = 200010;
int N;
LL x[MC];
LL a[MC];
LL s[MC];

int main(){
	cin >> N;
	repp(i,1,N+1){
		cin >> x[i] >> a[i];
		s[i] = s[i-1] + a[i];
	}
	LL ans = 0;
	LL mx = -12345678912345678;
	repm(i,N,0){
		mx = max(mx,s[i]-x[i]);
		ans = max(ans , mx-s[i-1]+x[i]);
	}
	cout << ans << endl;
	return 0;
}


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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
#define PI 3.14159265358979
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}

vector<pair<int,ll>> vec[100000];
ll cost[100000];
void dfs(int now,ll COST){
    cost[now]=COST;
    int next;
    REP(i,vec[now].size()){
        next=vec[now][i].first;
        if(cost[next]<0){
            dfs(next,COST+vec[now][i].second);
        }
    }
}
int counter(int x){
    if(!x)return 0;
    return counter(x>>1)+(x&1);
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string S;cin>>S;
    REP(i,S.length()){
        if(i%2==0){
            if(S[i]=='L'){
                print("No");
                return 0;
            }
        }else{
            if(S[i]=='R'){
                print("No");
                return 0;
            }

        }

    }
    print("Yes");
    return 0;
}

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

int main() {
    int a,b,c,k;
    int ans = 0;
    cin >> a >> b >> c >> k;
    int xa = min(k,a);
    k -= xa;
    int xb = min(b,k);
    k -= xb;
    int xc = k;
    ans = xa-xc;
    cout << ans <<endl;
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N, Q;
	cin >> N >> Q;
	bool b = false;
	vector<long long>A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	vector<long long>Sum(N);//累積和
	vector<long long>SumSub(N);//奇数番目のみ
	for (int i = 0; i < N; ++i) {
		if (0 == i) {
			Sum[i] = A[i];
			SumSub[i] = A[i];
			continue;
		}
		Sum[i] = Sum[i - 1] + A[i];
		if (0 == i % 2) {
			SumSub[i] = SumSub[i - 2] + A[i];
		}
		else {
			SumSub[i] = 0;
		}
	}



	for (int i = 0; i < Q; ++i) {
		long long x;
		cin >> x;
		long long l = 0;//NG
		long long r = N;//OK
		while (l + 1 < r) {
			long long c = (l + r) / 2;
			//Tがcを取れるかどうかは
			//c は(N-c+1)枚目
			//Aがすでにcをとってないことが条件。
			// [2 * A[c] - x,A[c])の枚数がT-c以下なこと
			int count = lower_bound(A.begin(), A.end(), A[c]) - lower_bound(A.begin(), A.end(), 2 * x - A[c]);
			if (count >= (N - c - 1)) {
				r = c;
			}
			else {
				l = c;
			}
		}
		long long ans = Sum[N - 1] - Sum[r - 1];
		if ((2 * r - N) > 0) {
			if (0 == (2 * r - N)%2) {
				ans += Sum[2*r-N-1] - SumSub[2 * r - N - 2];
			}
			else {
				ans += SumSub[2 * r - N - 1];
			}
		}
		cout << ans <<endl;
	}
	return 0;
}


Measured memory_bytes: 5560
program main;
var
  n : LongInt;
  m, i, a : integer;
begin
  readln(n, m);
  for i := 1 to m do begin
    read(a);
    n := n - a;
  end;

  if n < 0 then
    writeln(-1)
  else
    writeln(n);
end.

Measured memory_bytes: 1324
#include<iostream>
#include<algorithm>
using namespace std;
using ll=long long;
int main(){

  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  ll ans1=a*c;
  ll ans2=a*d;
  ll ans3=b*c;
  ll ans4=b*d;
  cout<<max({ans1,ans2,ans3,ans4});
  return 0;
}

Measured memory_bytes: 3632
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	S := sc.nextStr()
	ans := ""
	for _, r := range S {
		if r == '0' {
			ans += "0"
		} else if r == '1' {
			ans += "1"
		} else {
			if len(ans) != 0 {
				ans = ans[:len(ans)-1]
			}
		}
	}

	fmt.Fprintln(wtr, ans)
	wtr.Flush()
}


Measured memory_bytes: 640
use std::collections::HashSet;
use std::io;

fn read_line() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s
}

macro_rules! from_line {
    ($($a:ident : $t:ty), +) => {
        $(let $a: $t;)+
        {
            let _line = read_line();
            let mut _it = _line.trim().split_whitespace();
            $($a = _it.next().unwrap().parse().unwrap();)+
                assert!(_it.next().is_none());
        }
    };
}

fn gen_key(mark: &str, val: u32) -> String {
    format!("{} {}", mark, val)
}

fn main() {
    from_line!(n: u32);
    let mut set = HashSet::new();
    for _row in 0..n {
        from_line!(mark: String, val: u32);
        set.insert(gen_key(&*mark, val));
    }
 
    let marks = vec!["S", "H", "C", "D"];
    for m in marks {
        for v in 1..13+1 {
            let card = gen_key(m, v);
            if !set.contains(&card) {
                println!("{}", card);
            }
        }
    }
}


Measured memory_bytes: 5040
#include<stdio.h>
#include<string.h>
int main()
{
	char str[4];
	char go[7][4]={{"SAT"},{"FRI"},{"THU"},{"WED"},{"TUE"},{"MON"},{"SUN"}};
	
	scanf("%s",str);
	for(int i=0;i<7;i++)
	{
		if(strcmp(go[i],str)==0)
		{
			printf("%d\n",i+1);
			break;
		}
	}
	return 0;
 } 

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define y1 zzz
#define fi first
#define se second
#define PII pair<int,int>
#define PII2 pair<int,PII >
#define PII3 pair<PII,int >
#define PII4 pair<PII,PII >
#define all(x) (x).begin(),(x).end()
#define pb push_back
void solve()
{
    string s;
    cin>>s;
    s='.'+s;
    if(s[3]==s[4]&&s[5]==s[6])cout<<"Yes";
    else cout<<"No";
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("STRWC.inp","r",stdin);
    //freopen("FORMMAU.out","w",stdout);
    //int t;cin>>t;while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 256
s = input()[:-1]
if len(s) == 0:
    print(0)
    quit()
for i in range(len(s) - 1, -1, -1):
    if i % 2 == 1:
        l = i // 2 + 1
        if s[: l] == s[l : i + 1]:
            print(2 * l)
            quit()
print(0)

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

namespace _0610
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            for (int i = 0; i < x[0]; i++)
            {
                string weather = Console.ReadLine();
                int a = 0;
                if (weather[0] != 'c')
                {
                    Console.Write(-1);
                    a = -1;
                }
                else
                {
                    Console.Write(0);
                    a = 0;
                }
                for (int j = 1; j < x[1]; j++)
                {
                    if (weather[j] == 'c')
                    {
                        Console.Write(" 0");
                        a = j;
                    }
                    else
                    {
                        if (a == -1)
                        {
                            Console.Write(" -1");
                        }
                        else
                        {
                            Console.Write(" " + (j - a));
                        }
                    }
                }
                Console.WriteLine();
            }
        }
    }
}

Measured memory_bytes: 9692
#include<cstdio>
#include<iostream>
using namespace std;
int a,b,c,d;
int main(){
	cin>>a>>b>>c>>d;
	a+=b;c+=d;
	if(a>c)puts("Left");
	else if(a==c)puts("Balanced");
	else if(a<c)puts("Right");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define X first
#define Y second
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;


template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int mod =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

ll RS(ll N,ll P,ll M){
    if(P==0){
        return 1;
    }else{
        if(P%2==0){
            ll t=RS(N,P/2,M);
            return t*t%M;
        }else{
            return N*RS(N,P-1,M)%M;
        }
    }
}
int main() {
    ios::sync_with_stdio(false);
    int K=in();
    ll ans=0;
    REP1(i,K)REP1(j,K)REP1(l,K){
        ans+=gcd(gcd(i,j),l);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3640
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
#define N 2000
int solve(int, int,int, int []);

int main() {
	int n, q, A[N] = { 0 }, m, i;
	char str[2][4] = { "no","yes" };
	scanf("%d", &n);
	for (i = 0; i < n; i++) scanf("%d", &A[i]);
	scanf("%d", &q);
	for (i = 0; i < q; i++) {
		scanf("%d", &m);
		printf("%s\n", str[solve(0, m, n, A)]);
	}
	return 0;
}

int solve(int i, int m,int n,int A[]){
	int res;
	if (m == 0) return 1;
	if (i >= n) return 0;
	res = solve(i + 1, m,n,A) || solve(i + 1, m - A[i],n,A);
	return res;
}

Measured memory_bytes: 588
s = int(input())

a = [s]
for n in range(2, 1000001):
    if a[-1] % 2 == 0:
        a.append(int(a[-1]/2))
    else:
        a.append(3*a[-1]+1)

    try:
        a.index(a[-1], 0, -1)
        print(n)
        break
    except ValueError:
        continue


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb push_back
#define mp make_pair
#define nt _ll128
#define ld long double
long double PI =3.14159265358979323846;
using ll = long long;



const ll modo=1e9+7;
const ll inf=1e17;
const ll ms=(5e5)+5;

char ar[100][100];
int vis[100][100];

int r,c;

int check(int i,int j,int cc)
{
    if(i>=1&&j>=1&&i<=r&&j<=c&&ar[i][j]=='.'&&vis[i][j]>cc)return 1;
    return 0;
}

void go(int i,int j,int c)
{
    vis[i][j]=c;

    if(check(i-1,j,c+1))go(i-1,j,c+1);
    if(check(i+1,j,c+1))go(i+1,j,c+1);
    if(check(i,j-1,c+1))go(i,j-1,c+1);
    if(check(i,j+1,c+1))go(i,j+1,c+1);
}

int main()
{
    idfc;



  //  int r,c;
    cin>>r>>c;
    int i,j;
    int p=0;
    for(i=1;i<=r;i++)
    {
        for(j=1;j<=c;j++)
        {
            cin>>ar[i][j];
            if(ar[i][j]=='#')p++;
            vis[i][j]=INT_MAX;
        }
    }

    go(1,1,1);


    if(vis[r][c]==INT_MAX)
    {
        cout<<-1;
    }
    else{
      //cout<<vis[r][c]<<"\n";
     int ans=(r*c)-vis[r][c]-p;
      cout<<ans;
    }

    return 0;
}

Measured memory_bytes: 3700
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(s: str):
    ret = (-1, -1)
    def is_unbalance(t):
        if t[0] == t[1] or t[0] == t[2] or t[1] == t[2]:
            return True
        return False
    for i in range(len(s) - 2):
        if is_unbalance(s[i:i + 3]):
            ret = (i + 1, i + 3)
            break
    if len(s) == 2 and s[0] == s[1]:
        ret = (1, 2)
    print(ret[0], ret[1])
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    solve(s)

if __name__ == '__main__':
    main()


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

/* using */
using namespace std;

/* main constructor */
struct Fast
{
    Fast()
    {
        std::cin.tie(0);
        ios::sync_with_stdio(0);
        //cout << fixed << setprecision(12);
    }
} fast;

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

/* define */
#define REP(i, x, n) for (int i = x; i < (int)(n); ++i)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); --i)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) REP(i, 1, n + 1)
#define rrep(i, n) RREP(i, n, 0)
#define each(i, n) for (auto &i : n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define eunique(x) \
    sort(all(x));  \
    (x).erase(unique(all(x)), (x).end())
#define int long long

/* function */
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

/* const */
const int inf = 1e9 + 7;

/* main */
signed main(void)
{
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i += 2)
    {
        cout << s[i];
    }
    cout << endl;
    return 0;
}

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

int main(){
int A,s;
  cin>>A;
  s=A%1000;
  if(A%1110<10 || s%111==0 || s==0 ){
  cout<<"Yes"<<endl;
  }else {
  cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll n,i,j,x,sum=0,sum2=0,mul=1,maxi = INT_MIN;
    string s,ss;
    cin>>s>>ss;
    for(i = 0 ;i<ss.size() ;i++)
    {
        cout<<s[i]<<ss[i];
    }
    if(s.size()>ss.size())
        cout<<s[s.size()-1];
    cout<<endl;

}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int a,b;
	char c;
	while(cin>>a>>c>>b)
	{
		if(c=='+')
		{
	     	cout<<a+b<<endl;
		}
		else
		{
			cout<<a-b<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using static System.Math;
using static System.Console;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            Stdin io = new Stdin();
            Solve(io);
        }
        static void Solve(Stdin io)
        {
            int d, n;
            int[] l = io.Inputs();
            d = l[0]; n = l[1];
            if(n%100==0){
                n++;
            }
            WriteLine(n * (int)Math.Pow(10, 2 * d));
        }
    }
    class Stdin
    {
        public int Input()
        {
            return int.Parse(ReadLine());
        }
        public int[] Inputs()
        {
            string[] buf = ReadLine().Split(' ');
            return buf.Select(x => int.Parse(x)).ToArray();
        }
        public string Raw_Input()
        {
            return ReadLine();
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////
ll N;

ll calc(vll a) {
	ll x = a[N];
	ll r = N - 1;
	for (ll i = N; i <= 2 * N - 2; i++) {
		if (a[i] == a[i + 1]) { r = i - N; break; }
	}
	for (ll i = N; i >= 2; i--) {
		if (a[i] == a[i - 1]) { r = min(r, N - i); break; }
	}

	repn(i, r) { x = 1 - x; }

	return x;
}
int main() {
	cin >> N;

	vll a(2 * N);
	repn(i, 2 * N - 1)cin >> a[i];

	ll l = 1;
	ll r = 2 * N;

	while (r - l > 1) {
		ll m = (r + l) / 2;

		vll c(2 * N,0);
		repn(i, 2 * N - 1)if (a[i] >= m) { c[i] = 1; }

		//cout << l << r << endl;
		ll x = calc(c);
		//cout << l << r << m << x << endl;

		if (x == 1) { l = m; }
		else { r = m; }
	}

	cout << l << endl;

}

Measured memory_bytes: 7972
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>

#define nmax 8

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

int iin() {
    int i;
    scanf("%d", &i);
    return i;
}

long long llin() {
    long long i;
    scanf("%lld", &i);
    return i;
}

double din() {
    double i;
    scanf("%lf", &i);
    return i;
}

char cin() {
    char c;
    scanf("%c", &c);
    return c;
}

void stin(char *s) {
    scanf("%s", s);
}

void iout(int i) {
    printf("%d\n", i);
}

void llout(long long i) {
    printf("%lld\n", i);
}

void dout(double i) {
    printf("%lf\n", i);
}

void cout(char c) {
    printf("%c\n", c);
}

void stout(char *s) {
    printf("%s\n", s);
}


int table[nmax][nmax];

int dfs(int v, int n, int *visited) {
    int all_visited = 1, i;

    REP(i,n) {
        if (!visited[i]) {
            all_visited = 0;
            break;
        }
    }

    if (all_visited) {
        return 1;
    }

    int count = 0;

    REP(i,n) {
        if (!table[v][i]) continue;
        if (visited[i]) continue;

        visited[i] = 1;
        count += dfs(i, n, visited);
        visited[i] = 0;
    }

    return count;
}

int main() {
    int n = iin(), m = iin(), i, a, b;
    REP(i,m) {
        a = iin();
        b = iin();
        table[a - 1][b - 1] = 1;
        table[b - 1][a - 1] = 1;
    }
    int visited[n];
    memset(visited, 0, sizeof visited);
    visited[0] = 1;
    int count = dfs(0, n, visited);
    iout(count);
    return 0;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    i64 N, M; cin >> N >> M;

    i64 lb = 0;
    i64 ub = M / 2 + 1;
    auto check = [&](i64 x) {
        i64 reqc = x * 2;
        i64 affordable_s = N + (M - reqc) / 2;
        if (reqc > M) return false;
        if (affordable_s < x) return false;
        return true;
    };
    while (ub - lb > 1) {
        i64 mid = (lb + ub) / 2;
        if (check(mid)) lb = mid;
        else ub = mid;
    }
    cout << lb << endl;

    return 0;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a,b,flag=0,i;
	scanf("%d%d%d",&n,&a,&b);
	for(i=a;i<=b;i++)
	{
		if(i%n==0)
		{
			flag=1;
			break;
		}
	}
	if(flag)
	printf("OK\n");
	else
	printf("NG\n");
} 

Measured memory_bytes: 3680
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

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

int main(){
	int long long a;
	cin>>a;
	int long long b;
	rep(i, ceil(sqrt(a))){
		if(a % (i + 1) == 0)
			b = i + 1;
	}
	cout<<b + a / b - 2<<endl;
	return 0;
}

Measured memory_bytes: 256
//Link : https://atcoder.jp/contests/code-festival-2016-qualc/tasks/codefestival_2016_qualC_d

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 303

/*
int minH = min(x,y);
for(int i=minH;i;--i) {
  if(s[x-i][column]==s[y-i][column+1]) {
    ++curValue;
  }
}*/

char s[N][N];
int pre[N][N],dp[N][N];
int solveDp(int x,int y,int column) {
  if(x==0 || y==0) {
    return 0;
  }
  int &ret = dp[x][y];
  if(ret!=-1) {
    return ret;
  }
  ret = 1e9;
  ret = min(solveDp(x-1,y,column), solveDp(x,y-1,column));
  ret += pre[x][y];
  return ret;
}
int getValue(int column,int h) {
  memset(pre,0,sizeof(pre));
  for(int diff=0;diff<h;++diff) {
    //column 얘가 diff만큼 높다.

    int v = 0;
    for(int j=1;diff+j<=h;++j) {
      if(s[diff+j-1][column]==s[j-1][column+1]) {
        ++v;
      }
      pre[diff+j][j] = v;
    }
    //column+1
    if(diff!=0) {
      v = 0;
      for(int j=1;diff+j<=h;++j) {
        if(s[j-1][column]==s[diff+j-1][column+1]) {
          ++v;
        }
        pre[j][diff+j] = v;
      }
    }
  }
  memset(dp,-1,sizeof(dp));
  return solveDp(h,h,column);
}
void solve() {
  int h,w;scanf("%d %d ", &h,&w);
  for(int i=0;i<h;++i) {
    scanf(" %s ", s[i]);
  }
  long long ret = 0;
  for(int i=0;i<w-1;++i) {
    ret += getValue(i,h);
  }
  printf("%lld\n", ret);
}

int main() {
    //freopen("input.txt","r",stdin);
    solve();
    return 0;
}


Measured memory_bytes: 1024