akhauriyash/Code-Regression huggingface dataset:
unittest
{
	assert( [ "2 2", "3", "2 1 1" ].parse.expand.solve == "1 1\n3 2" );
	assert( [ "3 5", "5", "1 2 3 4 5" ].parse.expand.solve == "1 2 2 3 3\n4 4 4 4 3\n5 5 5 5 5" );
	assert( [ "1 1", "1", "1" ].parse.expand.solve == "1" );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto hw = input.front.split.to!( long[] );
	input.popFront;
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( hw[ 0 ], hw[ 1 ], as );
}

auto solve( long h, long w, long[] as )
{
	auto ansss = new long[][]( h, w );
	auto c = 1L;
	auto hi = 0L;
	auto wi = 0L;
	auto wd = 1L;
	while( !as.empty )
	{
		// 色を塗る
		ansss[ hi ][ wi ] = c;
		as.front--;
		if( as.front == 0 )
		{
			as.popFront;
			c++;
		}
		
		// 移動して、端まで来たら一つ下に降りて向きを変える
		wi += wd;
		if( w <= wi )
		{
			hi++;
			wi = w - 1;
			wd = -1;
		}
		else if( wi < 0 )
		{
			hi++;
			wi = 0;
			wd = 1;
		}
	}
	return ansss.map!( ( x ) => x.to!( string[] ).join( " " ) ).join( "\n" );
}


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

int main() {
	int N, a, two = 0, four = 0, other = 0;
	cin >> N;
	for (int i = 0;i < N;i ++) {
		cin >> a;
		if (a % 4) {
			if (a % 2) other ++;
			else two ++;
		} else four ++;
	}
	if (two) other ++;
	if (four + 1 >= other) cout << "Yes";
	else cout << "No";
	return 0;
}
// 4の倍数があった時…前の1か2の倍数を1個まで目標達成させる
// 2(かつnot4)の倍数があった時…最後に連続で置けば、1個で無い限り全て満たす

// 4の倍数にならない数(+2の倍数があるなら1個)を求め、それが4の倍数+1個以内か求める

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define pi 3.1415926535897932384
#define INF 2147483647
#define MOD 1000000007
#define MAX 200005
using namespace std;

typedef long long ll;

int Set(int mask, int pos){return mask = mask | (1<<pos);}
bool check(int mask, int pos){return (bool)(mask & (1<<pos));}

vector<int> v[26];

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    string s, t;

    cin>>s>>t;
    set<int> st;
    for(int i = 0; i < s.size(); i++){
        v[s[i]-'a'].pb(i);
        st.insert(s[i]-'a');
    }
    for(int i = 0; i < t.size(); i++){
        if(!st.count(t[i]-'a')){
            cout<<-1<<endl;
            return 0;
        }
    }

    ll ans = 0;
    int prev = -1;
    for(int i = 0; i < t.size(); i++){
        if(i == t.size())
            break;
        int idx = lower_bound(v[t[i]-'a'].begin(), v[t[i]-'a'].end(), prev) - v[t[i]-'a'].begin();
//        cout<<prev<<" "<<idx<<endl;
        if(idx == v[t[i]-'a'].size()){
            ans += (ll) s.size();
            prev = v[t[i]-'a'][0];
        }
        else if(v[t[i]-'a'][idx] == prev){
            if(idx + 1 >= v[t[i]-'a'].size()){
                ans += (ll) s.size();
                prev = v[t[i]-'a'][0];
            }
            else{
                prev = v[t[i]-'a'][idx+1];
            }
        }
        else if(v[t[i]-'a'][idx] < prev){
            ans += (ll) s.size();
            prev = v[t[i]-'a'][0];
        }
        else if(v[t[i]-'a'][idx] > prev){
            prev = v[t[i]-'a'][idx];
        }
    }

    cout<<ans + prev + 1<<endl;

    return 0;
}



Measured memory_bytes: 1228
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <math.h>
#include <functional>
#include <algorithm>
#include <utility>

typedef long long Int;
#define REP(i,n) for(int i = 0 ; i < n ; ++i)
#define REPS(a,i,n) for(int i = a ; i < n ; ++i)
using namespace std;




int main(){


	int n,m;
	while (cin >> n){
		stack<int> stack;
		m = 512;
		while (m){
			if (n >= m){
				stack.push(m);
				n -= m;
			}
			m /= 2;
		}
		int k(0);
		if (!stack.empty()){
			k += stack.top();
			cout << stack.top();
			stack.pop();
		}
		while (!stack.empty()){
			cout << " ";
			k += stack.top();
			cout << stack.top();
			stack.pop();
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#define ll long long 
using namespace std;

const ll MOD = 1e9+7;

ll factorial[200003];
ll revfac[200003];
// ll power[200003] = {0};

ll con(ll a, ll b){
	return factorial[a] * revfac[b] % MOD * revfac[a-b] % MOD; 
}

ll pow(ll a, ll e){
	ll tmp = 1;
	while(e > 0){
		if( e & 1ll){
			tmp = tmp * a % MOD ;
		}
		a = a * a % MOD;
		e >>= 1; 
	}
	return tmp;
	// if(e == 0){
	// 	return 1;
	// }
	// if(e%2 == 0){
	// 	return pow(a, e/2) * pow(a, e/2) % MOD;
	// }else{
	// 	return pow(a, e-1) * a % MOD;
	// }
}


void set_factorial(ll n){
	factorial[0] = 1;
	revfac[0] = 1; 
	for (int i = 1; i <= n; ++i)
	{
		factorial[i] = factorial[i-1] * i % MOD;
		revfac[i] = pow(factorial[i], MOD - 2) % MOD;
	}
}

int main(){
	ll h, w, a, b;
	cin >> h >> w >> a >> b;

	set_factorial(h+w);
	ll ans = 0;
	for (int i = 0; i <= h-a-1; ++i)
	{
		ans += con(b+i-1, i) * con(w-b+h-i-2, w-b-1) % MOD;
		// cout << con(b+i-1, i) <<  " " << con(w-b+h-i-2, w-b-1) << endl;
	}
	cout << ans % MOD << endl;

}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define f(i, q) for(int i = 0; i < q; i++)
using namespace std;

typedef long long ll;

int main() {
    vector<ll> time(5);
    ll n, count, bg, en, mn;

    cin >> n;
    f(i, time.size()) cin >> time.at(i);

    // 最小地（最大値）について
    mn = *std::min_element(time.begin(), time.end());
    // これもあるが
    sort(time.begin(), time.end());
    cout << (n - 1) / mn + 5 << endl;

    // 失敗例
    // vector< pair<ll, ll> > spot(6);
    // f(i, spot.size() - 1) cin >> spot.at(i).first;
    // f(i, spot.size()) spot.at(i).second = 0;
    // spot.at(0).second = n;

    // bg = en = count = 0;
    // while(spot.at(5).second != n) {
    //     count++;
    //     if(en < 5) en++;

    //     for(ll i = en - 1; i >= bg; i--) {
    //         if(spot.at(i).second > spot.at(i).first) {
    //             spot.at(i + 1).second += spot.at(i).first;
    //             spot.at(i).second -= spot.at(i).first;
    //         } else {
    //             spot.at(i + 1).second += spot.at(i).second;
    //             spot.at(i).second = 0;
    //         }
    //     }
    //     if(spot.at(bg).second <= 0) bg++;

    //     for(ll i = 0; i < 6; i++) {
    //         cout << spot.at(i).second << " ";
    //     }
    //     cout << endl;
    // }
    
    // cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int sum[3][1000][1000];

int main() {
  int h,w;
  cin >> h >> w;
  int q;
  cin >> q;
  memset(sum, 0, sizeof(sum));
  REP(i, h) {
    REP(j, w) {
      char c; cin >> c;
      int C = 0;
      if (c=='O') C=1;
      else if (c=='I') C=2;
      REP(k, 3) {
        int t = 0;
        if (i) t += sum[k][i-1][j];
        if (j) t += sum[k][i][j-1];
        if (i&&j) t -= sum[k][i-1][j-1];
        if (C == k) t++;
        sum[k][i][j] = t;
      }
    }
  }
  REP(i, q) {
    int x1,y1,x2,y2;
    cin >>y1>>x1>>y2>>x2;
    x1--;y1--;x2--;y2--;
    REP(k, 3) {
      int ans = sum[k][y2][x2];
      if (y1) ans -= sum[k][y1-1][x2];
      if (x1) ans -= sum[k][y2][x1-1];
      if (y1&&x1) ans += sum[k][y1-1][x1-1];
      if (k) cout << " ";
      cout << ans;
    }
    cout << endl;
  }
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
int cmp(const void *a, const void *b){
  return *(int*)a - *(int*)b;
}
int main(){
  int n,k,r=0;
  int l[50];
  scanf("%d%d",&n,&k);
  for(int i=0;i<n;i++)scanf("%d",&l[i]);
  qsort(l,n,sizeof(int),cmp);
  for(int i=1;i<=k;i++)r+=l[n-i];
  printf("%d",r);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
ll a[202020],n,ans;
int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>a[i];
        if(i){
            if(a[i] < a[i-1]){
                ans += a[i-1] - a[i];
                a[i] = a[i-1];
            }
        }
    }
    cout<<ans<<'\n';
}

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

int main() {
    string s;
    cin >> s;
    bool flag = false;
    for (int i = s.size()-1; i >= 0; i--)
    {
        s.erase(i);
        if (s.size() % 2 == 0) {
            for (int j = 0; j < s.size()/2; j++)
            {
                if (s[j] != s[j+(s.size()/2)]) {
                    break;
                }
                if (s[j] == s[j+(s.size()/2)] && j == s.size()/2-1) {
                    cout << s.size() << endl;
                 	return 0;
                }
            }
            
        }
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
typedef long long ll;
typedef pair<int,int> pii;

int main(){
    string s;
    int q;
    cin>>s>>q;
    int r=0;
    rep(i,q){
        int t;
        cin>>t;
        if(t==1){
            r=r^1;
        }else{
            int f;
            string c;
            cin>>f>>c;
            if(f!=1)f=0;
            f=(f^r);

            if(f==1){
                s.insert(0,c);
            }else{
                s.append(c);
            }
        }

    }
    if(r) reverse(s.begin(),s.end());
    cout<<s<<endl;
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF =0; 

int x[100050];
signed main(){
    int n;
    cin >> n;
    rep(i,n){
        cin >> x[i];
    }   
    int max = -100;
    for(int i=0;i<n;++i){
        if(max - x[i] > 1){ 
            cout << "No" <<'\n';
            return 0;
        }
        if(x[i] > max) max = x[i];
    }   
    cout << "Yes" << '\n';
    return 0;
}

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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if (a == b && b == c) {
    cout << 1 << endl;
  }
  else if (a != b && b != c && c != a) {
    cout << 3 << endl;
  }
  else {
    cout << 2 << endl;
  }
}

Measured memory_bytes: 256
A, B, C = map(int, input().split())
K = int(input())
cnt = 0
while cnt <= K:
  if A < B < C:
    print('Yes')
    break
  elif A < B:
    C = 2*C
    cnt += 1
    continue
  else:
    B = 2*B
    cnt += 1
    continue
if cnt > K:
  print('No')

Measured memory_bytes: 61840
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
      int N = nextInt();
      ArrayList<String> s = nextCharArray();
      int k = nextInt() - 1;
      String ok = s.get(k);
      for(int i = 0; i < N; i++){
        if(!s.get(i).equals(ok)){
          s.set(i, "*");
        }
      }
      myout(myconv(s, 0));
	}
	//Method addition frame start


  
	//Method addition frame end
}


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

int C(int x,int y){/*xCy,x≧y≧0*/if(y==0)return 1;return x*C(x-1,y-1)/y;}

int main() {
  int n,m;cin>>n>>m;
  cout<<C(n,2)+C(m,2)<<endl;
}


Measured memory_bytes: 3588
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}

function Main(input) {
  var counter = new Array(input.length+1).fill(0);
  input = myconv(input,6);
  for(var i = 0; i < input.length; i++){
    if(input[i] == "<"){
       counter[i+1] = counter[i]+1;
    }
  }
  
  //myout(counter);
  for(var i = input.length-1; 0 <= i; i--){
    if(input[i] == ">"){
       counter[i] = Math.max(counter[i+1]+1,counter[i]);
    }
  }
  var sum = 0;
  for(var i = 0; i < counter.length; i++){
    sum += counter[i];
  }
  //myout(counter);
  myout(sum);
}

Main(myin());


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

namespace ABC088_B
{
    class Program
    {
        static int Solve()
        {
            int num = int.Parse(Console.ReadLine());
            string[] card = Console.ReadLine().Split(' ');
            List<int> list = new List<int>(num);
            for (int i = 0; i < card.Length; i++)
            {
                list.Add(int.Parse(card[i]));
            }
            list.Sort();
            list.Reverse();
            int A = 0;
            int B = 0;
            for (int i = 0; i < list.Count; i++)
            {
                if (i%2 == 0)
                {
                    A += list[i];
                }
                else
                {
                    B += list[i];
                }
            }
            int ans = A - B;
            return ans;
        }
        static void Main(string[] args)
        {
            Console.WriteLine(Solve());
        }
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
	rep(i, v.size()) { os << v[i] << (i == v.size() - 1 ? "" : " "); }
	return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	for (T& x : v) { is >> x; }
	return is;
}

int n, m;
vector<vector<pair<int, int>>> g, rg;

int bfs() {
	queue<int> q;
	q.emplace(0);

	vector<int> coin(n, -1e9);
	coin[0] = 0;

	int cnt = 0;
	while (not q.empty()) {
		if (cnt > n * n + 10) { return -1e9; }
		int cur = q.front();
		q.pop();
		for (auto p : g[cur]) {
			if (coin[p.first] < coin[cur] + p.second) {
				coin[p.first] = coin[cur] + p.second;
				q.emplace(p.first);
			}
		}
		cnt++;
	}
	return coin[n - 1];
}

void dfs(int cur, vector<bool>& used) {
	used[cur] = true;
	for (auto p : rg[cur]) {
		if (used[p.first]) continue;
		dfs(p.first, used);
	}
}

signed main() {
	int p;
	cin >> n >> m >> p;
	rg = vector<vector<pair<int, int>>>(n);
	rep(i, m) {
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		rg[b].emplace_back(a, c - p);
	}
	vector<bool> used(n, false);
	dfs(n - 1, used);

	g = vector<vector<pair<int, int>>>(n);
	rep(to, n) {
		for (auto p : rg[to]) {
			int from, cost;
			tie(from, cost) = p;
			if (used[from] and used[to]) { g[from].emplace_back(to, cost); }
		}
	}

	auto ans = bfs();
	if (ans == -1e9)
		cout << -1 << endl;
	else
		cout << max(0LL, ans) << endl;
}


Measured memory_bytes: 13204
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define REP(i, n) for (size_t i = 0; i < (n); i++)
#define nvec(T, v, n) vector<T> v(n); REP(i, n) {cin>>(v)[i];}
#define npairs(T1, T2, v, n) vector<pair<T1, T2>> v(n); REP(i, n){cin>>v[i].first>>v[i].second;}
#define ntuples(T1, T2, T3, v, n) vector<tuple<T1, T2, T3>> v(n); REP(i, n){cin>>get<0>(v[i])>>get<1>(v[i])>>get<2>(v[i]);}
#define vec2d(T, v, m, n) vector<vector<T>> (v)(m, vector<T>(n))
#define nvec2d(T, v, m, n) vec2d(T, v, m, n); REP(j, m){REP(i, n) {cin>>(v[j])[i];}}

#define min_index(v) size_t( min_element(all(v)) - (v).begin() )
#define max_index(v) size_t( max_element(all(v)) - (v).begin() )
#define min_e(v) *min_element(ALL(v))
#define max_e(v) *max_element(ALL(v))

#define count_le(v, a) size_t( upper_bound(ALL(v), a) - (v).begin() )
#define count_lt(v, a) size_t( lower_bound(ALL(v), a) - (v).begin() )
#define count_ge(v, a) size_t( (v).end() - lower_bound(ALL(v), a) )
#define count_gt(v, a) size_t( (v).end() - upper_bound(ALL(v), a) )

#define order(neq_sl) [](const auto s, const auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}

#define acm accumulate
#define SUM(v) accumulate(ALL(v), 0l)
#define SORT(v) sort(ALL(v))

#define GCD(v) gcd(ALL(v), 0l)

/*template <typename T>
T gcd(T a, T b) {
    if (a > b) swap(a, b);
    if (a == 0) return b;
    return gcd(b%a, a);
}
template <typename InputItr, typename T>
T gcd(InputItr first, InputItr last, T init) {
    for (; first != last; ++first) init = gcd(init, *first);
    return init;
}*/

template <typename T>
using vec =vector<T>;

template <typename T>
using vvec =vector<vector<T>>;

int main(){
  int x,n;
  cin>>x>>n;
  nvec(int,p,n);
  vec<pair<int,int>> q;
  for (int i = 0; i < 102; i++) {
    bool a=1;
    for (int j = 0; j < n; j++) {
      if(i==p[j])a=0;
    }
    if(a==1)q.push_back(make_pair(abs(x-i),i));
  }
  SORT(q);
  cout<<q[0].second;
  
}


/* きょむ〜 */


Measured memory_bytes: 3632
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    int n, init;
    cin >> n >> init;
    vector<int> d(n);
    for(int i=0; i<n; ++i)
        cin >> d[i];

    vector<int> x(n);
    x[0] = init;
    for(int i=0; i<n-1; ++i)
        x[i+1] = min(x[i], abs(x[i] - d[i]));

    vector<bool> ans(n, true);
    long long tmp = 1;
    for(int i=n-1; i>=0; --i){
        if(x[i] < tmp)
            ans[i] = false;
        if(d[i] < 2 * tmp)
            tmp += d[i];
    }

    int q;
    cin >> q;
    while(--q >= 0){
        int a;
        cin >> a;
        -- a;
        if(ans[a])
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 5888
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
#define ll long long
#define MOD 998244353

ll dp[4][2][200010];

void chmax(ll& a, ll b) {
	a = max(a, b);
}

int main() {
	for (int i = 0;i < 200010;i++) {
		for (int j = 0;j < 4;j++) {
			dp[j][0][i] = dp[j][1][i] = LLONG_MIN / 3;
		}
	}
	int N;
	cin >> N;
	ll A;
	for (int i = 0;i < N;i++) {
		cin >> A;
		if (i == 0) {
			//選ぶ
			dp[3][1][0] = A;
			//選ばない
			dp[1][0][0] = 0;
			continue;
		}
		//選ぶ
		chmax(dp[1][1][i], dp[0][0][i - 1] + A);
		chmax(dp[2][1][i], dp[1][0][i - 1] + A);
		chmax(dp[3][1][i], dp[2][0][i - 1] + A);
		//選ばない
		chmax(dp[0][0][i], dp[1][0][i - 1]);
		chmax(dp[0][0][i], dp[1][1][i - 1]);
		chmax(dp[1][0][i], dp[2][0][i - 1]);
		chmax(dp[1][0][i], dp[2][1][i - 1]);
		chmax(dp[2][0][i], dp[3][0][i - 1]);
		chmax(dp[2][0][i], dp[3][1][i - 1]);
	}
	if (N & 1) {
		cout << max(dp[1][0][N - 1], dp[1][1][N - 1]) << endl;
	}
	else {
		cout << max(dp[2][0][N - 1], dp[2][1][N - 1]) << endl;
	}
}


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
ll mod = 1000000007;

int main() {
    ll n, k;
    cin >> n >> k;
    ll a[n];
    rep(i, n) { cin >> a[i]; }

    repd(i, k, n) {
        if (a[i - k] < a[i]) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 5160
n, m = map(int, input().split())
lrc = []
for _ in range(m):
    lrc.append(tuple(map(int, input().split())))
lrc.sort()

inf = 10**15
dp = [inf]*(n+1)
dp[1] = 0

for l, r, c in lrc:
    for i in range(r, l, -1):
        if dp[i] > dp[l] + c:
            dp[i] = dp[l] + c
        else:
            break

ans = -1 if dp[n] == inf else dp[n]
print(ans)


Measured memory_bytes: 64252
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <string.h>
#include <math.h>
#include <map>

using namespace std;

int main(){
	int N, T, c[1000], t[1000], ans = 1e9;
	cin >> N >> T;

	for (int i = 0; i < N; ++i){
		cin >> c[i] >> t[i];
	}

	for (int i = 0; i < N; ++i){
		if (c[i] < ans && t[i] <= T)
			ans = c[i];
	}

	if (ans == 1e9)
		cout << "TLE" << endl;
	else
		cout << ans << endl;

	return 0;
}

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

int main(void) {
  string S, T;
  cin >> S >> T;
  bool flag = S == T;
  for (int i = 0; i < (int)S.length(); i++) {
    rotate(S.begin(), S.begin() + 1, S.end());
    if (S == T) {
      flag = true;
      break;
    }
  }
  cout << (flag ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	void doIt() { 
		while(true){
			int n = sc.nextInt();
			if(n == 0)break;
			String str[] = new String[n];
			int a[] = new int [n];
			int b[] = new int [n];
			int max = 0;
			for(int i = 0;i < n;i++){
				str[i] = sc.next();
				a[i] = sc.nextInt();
				b[i] = sc.nextInt();
				max = max + a[i];
			}
			for(int i = 0;i < n;i++){
				int k = 0;
				int l = 0;
				for(int j = 0;j < n;j++){
					if(max - a[j] <= b[j]){
						if(a[j] > k){
							k = a[j];
							l = j;
						}	
					}
				}
				max = max - a[l];
				a[l] = 0;
				b[l] = -10;
				System.out.println(str[l]);
			}
		}
     }
    public static void main(String[] args) {
    	// TODO Auto-generated method stub
    	new Main().doIt();
    }
}

Measured memory_bytes: 20500
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string blue[110];
  for (int i=0; i<n; i++) {
    cin >> blue[i];
  }
  int m;
  cin >> m;
  string red[110];
  for (int i=0; i<m; i++) {
    cin >> red[i];
  }
  int a = 0;
  for (int i=0; i<n; i++) {
    int add = 0;
    for (int j=0; j<n; j++) {
      if (blue[i] == blue[j]) {
        add++;
      }
    }
    for (int j=0; j<m; j++) {
      if (blue[i] == red[j]) {
        add--;
      }
    }
    a = max(add,a);
  }
  cout << a << endl;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
using namespace std;
const int N=206,M=11;
int a[N][N],b[M];
int n,m,p,s;
void work (void)
{
	int i,j,k,t;
	for (i=1;i<=n;i++)
	for (j=1;j<=n;j++)
	if (j!=i)
	for (k=1;k<=n;k++)
	if (k!=i&&k!=j)
	{
		t=a[j][i]+a[i][k];
		if (t<a[j][k])
		a[j][k]=t;
	}
	for (i=1;i<p;i++)
	s+=a[b[i]][b[i+1]];
	while (next_permutation (b+1,b+p+1)==1)
	{
		t=0;
		for (i=1;i<p;i++)
		t+=a[b[i]][b[i+1]];
		if (t<s)
		s=t;
	}
	cout<<s;
}
int main (void)
{
	int i,j,k,u;
	cin>>n>>m>>p;
	for (i=1;i<=n;i++)
	for (j=1;j<=n;j++)
	if (j!=i)
	a[i][j]=1000000000;
	for (i=1;i<=p;i++)
	cin>>b[i];
	for (i=1;i<=m;i++)
	{
		cin>>j>>k>>u;
		a[j][k]=u;
		a[k][j]=u;
	}
	sort (b+1,b+p+1);
	work ();
	return 0;
}


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

int main() {
	string S;
	cin >> S;
	int64_t ans = 0, leftB = 0;
	for (int i = 0, l = S.length();i < l;++ i) {
		if (S[i] == 'B') ++ leftB;
		else ans += leftB;
	}
	cout << ans;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

まず、右側にあるBをひっくり返す手段はないためこれで固定
次に、それ以外の場所を考える
連続したBWBWBW……操作を行うと、N(N+1)/2回の操作後にWWWBBBになる
これ、1回操作を行うごとにBを右に1個ずらす操作と考えることができるよね
よって、答えはBを全部右側に移すのに必要な操作回数に等しい
*/

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
 }
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll k;
  cin>>k;
  PQR que;
  set<ll> s;
  for(int i=1;i<10;i++){
    que.pu(i);
    s.insert(i);
    if(sz(s)==k){
      COUT(*rbegin(s));
      return 0;
    }
  }
  while(sz(que)){
    ll p=que.top();
    que.pop();
    string d=to_string(p);
    ll st=max(0,d[sz(d)-1]-'1');
    ll la=min(9,d[sz(d)-1]-'0'+1);
    for(int i=st;i<=la;i++){
      ll nx=p*10+i;
      que.pu(nx);
      s.insert(nx);
      if(sz(s)==k){
        COUT(*rbegin(s));
        return 0;
      }
    }
  }
}

Measured memory_bytes: 6008
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::unordered_set;
using std::map;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{
  ui n, k; cin >> n >> k;
  --n; --k;
  ui a;
  for(ui i = 0; i < n; ++i) cin >> a;

  cout << (n + (k - 1)) / k << CRLF;
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


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

using namespace std;

// Repetitions
#define FOR(i,a,n) for(ll i = ((ll) a); i < ((ll) n); ++i)
#define FORR(i, s, g) for(ll i = ((ll)s - 1); i >= ((ll) g); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)

// Container Utils
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORTALL(v) sort(ALL(v))
#define SZ(a) int((a).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

// For Debug
#define DMP(x)  cerr << #x << " = " << (x) << endl
#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

// Aliases
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef string str;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

// I/O Asynchronizing
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

inline ll combi2(const ll n) {
    return n * (n - 1) / 2;
}

int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    str s1, s2;
    REP(i, (tx - sx)) {
        s1 += 'R';
        s2 += 'L';
    }
    REP(i, (ty - sy)) {
        s1 += 'U';
        s2 += 'D';
    }
    cout << s1 + s2 + "DR" + s1 + "ULUL" + s2 + "DR\n";

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define ll long long
#define int long long 
# define INF 2e5+5
#define ar array
# define fr first
# define sc second
#define wt(x) int x;cin>>x;while(x--)
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl
//#define cerr if(false)cerr
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> pbds;

void  c_p_c(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
 
#ifndef ONLINE_JUDGE
  freopen("input1.txt","r",stdin);
  freopen("output1.txt","w",stdout);
#endif
 }
 
/*int power(int a,int b,int mod){
    a=a%mod;
    if(a==0){
        return 1;
    }
    int res=1;
    while(b){
        if(b&1){
            res=(res*a)%mod;
        }
        b>>=1;
        a=(a*a)%mod;
    }
    return res;
 }
 
int  MMI(int p){
    return power(p,MOD-2,MOD);
}*/
const int mxN=5e5;
int n,m;
int iv[mxN+1],f1[mxN+1],f2[mxN+1];
int nck(int n,int k){
    return f1[n]*f2[k]%mod*f2[n-k]%mod;
}
int32_t main()
{
    c_p_c();
    
    cin>>n>>m;
    iv[1]=1;
    for(int i=2;i<=mxN;i++){
        iv[i]=mod-mod/i*iv[mod%i]%mod;
    }
    f1[0]=f2[0]=1;
    for(int i=1;i<=mxN;i++){
        f1[i]=f1[i-1]*i%mod;
        f2[i]=f2[i-1]*iv[i]%mod;
    }
     int ans=0;
     for(int i=0;i<=n;i++){
        ll c=i&1?mod-1:1;
        c=c*nck(n, i)%mod*nck(m, i)%mod*f1[i]%mod*nck(m-i, n-i)%mod*nck(m-i, n-i)%mod*f1[n-i]%mod*f1[n-i]%mod;
        ans=(ans+c)%mod;
     }
     cout<<ans<<"\n";



    


        



         
 
 
    
      return 0;
       
        }
        
        
 
        
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
        

        


























//abcdef-abcdef
//factorial vs power
//multiplication table
//salary changing
//Obtain a Permutation
//Shift and Replace

Measured memory_bytes: 15376
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   //setprecsion
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <utility>   // pair, make_pair
#include <vector>    // vector

#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>  //sin, cos, tan

using namespace std;
using Graph = vector<vector<int>>;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

void Main()
{
  ll n; cin >> n;
  ll x = 0;
  ll X = n;
  while(X)
  {
    x += X % 10;
    X /= 10;
  }
  cout << (n % x == 0?"Yes":"No");
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  //cout << setfill('0') << internal << setw(4); 0埋め４桁
  Main();
  return 0;
}


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

int main( ) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t,n,i,a,b;
    t = 1;
    while(t--) {
     a = b = 0;
	 cin >> n;
	 int arr[n];
	 for(i = 0; i < n; i++)
	  cin >> arr[i];
	 for(i = 1; i < n; i++) {
	  if(arr[i] > arr[i - 1])
	   b = i;
	  a = max(a, i - b);
	 }
	 cout << a << endl;
    }
    return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxN = 2e6+7;
const int maxV = 90010;
//const int INF = 1e9+9;
//const ll INF = (1ll)<<60;
const int INF = 2e9+9;
const int MOD = 1000003;

int Q;
ll power(ll x,ll p)
{
	if(p==0)
		return 1;
	ll t = power(x,p/2);
	t = t*t%MOD;
	if(p%2 == 1)
		t = t*x%MOD;
	return t;
}
ll c[maxN];
int main()
{
	scanf("%d",&Q);
	c[0] = 1ll;
	for(int i=1;i<=2*MOD;i++)
	{
		c[i] = c[i-1]*i%MOD;
	}
	for(int i=1;i<=Q;i++)
	{
		int x,d,n;
		scanf("%d%d%d",&x,&d,&n);
		ll ans = 0;
		if(x == 0)
		{
			ans = 0;
		}
		else if(d == 0)
		{
			ans = power(x,n);
		}
		else if(x*power(d,MOD-2)%MOD+ n-1>=MOD)
		{
			ans = 0;
		}

		else
		{
			ll tmp = power(d,n);
			ll p = x*power(d,MOD-2)%MOD;
			ll q = c[p+n-1]*power(c[p-1],MOD-2)%MOD;
			ans = tmp*q%MOD;
		}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 16512
#!/usr/bin/env python3
import sys
import collections

N = int(input())
A = list(map(int, input().split()))
Q = int(input())

d = collections.Counter(A)
ans = 0
for k, v in d.items():
    ans += k * v

for i in range(Q):
    B,C = list(map(int, input().split()))
    if B in d:
        val = d[B]
        ans -= B * d[B]
        ans += C * d[B]
        if C in d:
            d[C] = d[C] + d[B]
        else:
            d[C] = d[B]
        d.pop(B)

    print(ans)

Measured memory_bytes: 86548
#include <iostream>
#include <cstdlib>
#include<algorithm>
using namespace std;

pair<int,int>p[2*100000+1];

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>p[i].second>>p[i].first;
    sort(p,p+n);
    int a;
    for(int i=0;i<n;i++){
        a+=p[i].second;
        if(a>p[i].first){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

main(){
  int n;
  while(1){
    cin >> n;
    if(n==0) break;

    int data[130];
    for(int i=0;i<130;i++){
      data[i]=i;
    }
    for(int i=0;i<n;i++){
      char a, b;
      cin >> a >> b;
      data[(int)a]=(int)b;
    }

    int m;
    cin >> m;
    for(int i=0;i<m;i++){
      char in;
      cin >> in;
      cout << (char)data[(int)in];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 852
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }

const ll INF=1e18;
const int mx=200005;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int ans=0;
    V<ll> a(n);
    cinf(n,a);
    sort(all(a));
    for(int i=0;i<n-2;i++){
        for(int j=i+1;j<n-1;j++){
            for(int k=j+1;k<n;k++){
                if(a[i]+a[j]>a[k]&&a[i]+a[k]>a[j]&&a[j]+a[k]>a[i]&&a[i]!=a[j]&&a[j]!=a[k]&&a[k]!=a[i]) ans++;
            }
        }
    }
    cout<<ans<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
*/

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

int main()
{
    long long N;
    cin >> N;
    long long ans=0;
    for (int i=1; i<N; i++)
    {
        ans += (N-1)/i;
        //cout << i << " " << (N-1)/i << endl;
    }
    cout << ans << endl;
}

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

using namespace std;

using ll = long long;

bool pre_judge(string& s, int n) {
    if (s[n - 1] == '1') return false;
    if (s[0] == '0') return false;
    if (s[n - 2] == '0') return false;
    for (int i = 1; i < n / 2; i++) {
        if (s[i] != s[n - 2 - i]) return false;
    }
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    if (!pre_judge(s, n)) {
        cout << -1 << endl;
        return 0;
    }

    vector< vector<int> > g(n);
    g[0].push_back(1);
    int cur = n - 1;
    for (int i = 1; i < n - 1; ) {
        cur--;
        for (int j = cur; j > 0; j--) {
            if (s[j - 1] == '0') continue;
            int idx = i + 1;
            while (cur > j) {
                g[i].push_back(idx);
                idx++;
                cur--;
            }
            g[i].push_back(idx);
            i = idx;
            break;
        }
        if (cur == 0) break;
    }

    for (int i = 0; i < n; i++) {
        for (int j : g[i]) {
            cout << i + 1 << " " << j + 1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 6992
#define ll long long
#define ffor(i,a,b) for (int i=(a);i<(b);i++)
#define rfor(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define rep(i,n) for (int i=0;i<(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define SIZE 100001
#define MOD 1000000007
#define INF 100000000
using namespace std;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	ll ans = 0;
	for(int i=1; i<=n; i++){
		ans +=i;
	}

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

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

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

using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    vector<int> length;
    // 全ての i について
    int now = 0;
    int l = 0, r = 0 ;
    vector<int> len;
    for(int l=0;l<N;l++){
        if(l>r)r = l ;
        while( (now + A[r]) == (now^A[r]) && r < N){
            now += A[r];
            r++;
        }
        now -= A[l];
        len.push_back(r-l);
    }
    ll ans = 0;
    for(auto x:len)ans += x;
    cout << ans << endl;
}

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

#define EPS (1e-7)

typedef struct {
	int x,y,r;
} wall_t;

typedef struct {
	int tx,ty,sx,sy;
} query_t;

int hitcheck_circle(wall_t w,query_t q) {
	int in=0;
	int a,b,c;
	int minx,miny,maxx,maxy,temp;
	/* sieve */
	minx=q.tx;maxx=q.sx;
	if(minx>maxx){temp=minx;minx=maxx;maxx=temp;}
	miny=q.ty;maxy=q.sy;
	if(miny>maxy){temp=miny;miny=maxy;maxy=temp;}
	if(w.x+w.r<minx || maxx<w.x-w.r)return 0;
	if(w.y+w.r<miny || maxy<w.y-w.r)return 0;
	/* check if dist<=r */
	if((q.tx-w.x)*(q.tx-w.x)+(q.ty-w.y)*(q.ty-w.y)<=w.r*w.r)in++;
	if((q.sx-w.x)*(q.sx-w.x)+(q.sy-w.y)*(q.sy-w.y)<=w.r*w.r)in++;
	if(in==1)return 1;
	if(in==2)return 0;
	a=q.ty-q.sy;
	b=q.sx-q.tx;
	c=(q.tx-q.sx)*q.ty-(q.ty-q.sy)*q.tx;
	if((a*w.x+b*w.y+c)*(a*w.x+b*w.y+c)<=w.r*w.r*(a*a+b*b)) {
		/* check if really hit */
		c=-c; /* convert a*x+b*y+c=0 to a*x+b*y=c */
		if(b==0) {
			double yy=w.r*w.r-((double)c/a-w.x)*((double)c/a-w.x);
			double y1,y2;
			y1=sqrt(yy);y2=-y1;
			y1+=w.y;y2+=w.y;
			return (miny<y1+EPS && y1<maxy+EPS) || (miny<y2+EPS && y2<maxy+EPS);
		} else {
			double cb=(double)c/b;
			double ab=(double)a/b;
			double x2k,xk,tk;
			double x1,x2;
			x2k=1.0+ab*ab;
			xk=-2*w.x+2.0*(w.y-cb)*ab;
			tk=w.x*w.x+(w.y-cb)*(w.y-cb)-w.r*w.r;
			x1=(-xk+sqrt(xk*xk-4.0*x2k*tk))/(2.0*x2k);
			x2=(-xk-sqrt(xk*xk-4.0*x2k*tk))/(2.0*x2k);
			return (minx<x1+EPS && x1<maxx+EPS) || (minx<x2+EPS && x2<maxx+EPS);
		}
	}
	return 0;
}
int main(void) {
	int n;
	wall_t w[100];
	int m;
	int i;
	while(scanf("%d",&n)==1 && n>0) {
		for(i=0;i<n;i++)scanf("%d%d%d",&w[i].x,&w[i].y,&w[i].r);
		scanf("%d",&m);
		for(i=0;i<m;i++) {
			query_t q;
			int j;
			int hidden;
			scanf("%d%d%d%d",&q.tx,&q.ty,&q.sx,&q.sy);
			hidden=0;
			if(q.tx!=q.sx || q.ty!=q.sy) {
				for(j=0;j<n;j++) {
					if(hitcheck_circle(w[j],q)) {
						hidden=1;
						break;
					}
				}
			}
			puts(hidden?"Safe":"Danger");
		}
	}
	return 0;
}

Measured memory_bytes: 580
package main

import "fmt"

func main() {
	var a, b int
	slice := []int{1,2,3}
	ans := []int{}

	fmt.Scanf("%d", &a)
	fmt.Scanf("%d", &b)
	for i := 0;i < len(slice);i++ {
		if (slice[i] != a && slice[i] != b) {
			ans = append(ans, slice[i])
		}
	}

	if (len(ans) > 0) {
		fmt.Printf("%d", ans[0])
	}
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>
using namespace std;
#define All(v) (v).begin(),(v).end()
const long long mod = 1000000007;
const long long inf = mod*mod;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
signed main(){
    int n;
    cin>>n;
    int dp[100010];
    //dp[i]:i円払うのに必要な最低回数
    for(int i=0;i<=n;i++)dp[i]=i;
    for(int i=0;i<=n;i++){
        int k = 6;
        while(i-k>=0){
            dp[i]=min(dp[i-k]+1,dp[i]);
            k *= 6;
        }
        int j = 9;
        while(i-j>=0){
            dp[i]=min(dp[i-j]+1,dp[i]);
            j *= 9;
        }
    }
    cout<<dp[n]<<endl;
}

Measured memory_bytes: 640