akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<queue>
#include<bitset>
#include<complex>
#include<cmath>
using namespace std;
template<typename __T>
inline void read(__T &x)
{
    x=0;
    int f=1;char c=getchar();
    while(!isdigit(c)){if(c=='-')	f=-1;c=getchar();}
    while(isdigit(c))	{x=x*10+c-'0';c=getchar();}
    x*=f;
}
template<typename T>
T rabs(T x)
{
	return x>0?x:-x;
}
int n;
int s[100005];
int main()
{
	read(n);
	long long ans=0;
	for(int i=1;i<=n;i++)
	{
		read(s[i]);
		ans=ans+rabs(s[i-1]-s[i]);
	}
	ans+=rabs(s[n]);
	for(int i=1;i<=n;i++)
	{
		int pre=i-1;
		int nex=(i==n)?0:i+1;
		cout<<ans-rabs(s[i]-s[pre])-rabs(s[i]-s[nex])+rabs(s[nex]-s[pre])<<endl;
	}
	return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
map<string,int>h;
string s;
int n;
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>s;
        h[s]++;
    }
    int num=0;
    
    cout<<h.size();
    return 0;
}

Measured memory_bytes: 19136
/*  Bismillahir Rahmanir Rahim  */

#include <bits/stdc++.h>

using namespace std;

int n, x;

int main(){
	scanf("%d", &n);
	deque <int> q;
	for(int i = 1; i <= n; ++i){
		scanf("%d", &x);
		if(i & 1) q.push_back(x);
		else q.push_front(x);
	}
	vector <int> ans;
	while(!q.empty()){
		ans.push_back(q.front());
		q.pop_front();
	}
	if(n & 1) reverse(ans.begin(), ans.end());
	for(auto u : ans){
		printf("%d ", u);
	}
	printf("\n");
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef double ld;

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define MOD 1000000007
#define PI 3.14159265

#define MAX 501


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int a , b;
    cin >> a >> b;
    a--;
    b--;
    cout << a * b << endl;

    return 0;
}


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	puts(a * b % 2 == 0 ? "Even" : "Odd");
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define INF 110000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,int> P;

ll p[100],a[100];

ll bur(int L,ll M){
  if(M==0) return 0;
  else if(L==0) return 1;
  else if(M<=1) return 0;
  else if(M<=1+a[L-1]) return bur(L-1,M-1);
  else if(M==2+a[L-1]) return p[L-1]+1;
  else if(M<=2*a[L-1]+2) return p[L-1]+1+bur(L-1,M-a[L-1]-2);
  else if(M==3+a[L-1]*2) return p[L];
}

int main(){
  int N;
  ll X;
  cin>>N>>X;

  p[0]=1; a[0]=1;

  for(int i=1;i<=N;i++){
    p[i]=2*p[i-1]+1;
    a[i]=2*a[i-1]+3;
  }

  cout<<bur(N,X)<<endl;
}


Measured memory_bytes: 256
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
using namespace std;
using ll=long long;
#define mod  1000000007

int main(int argc, char const *argv[]) {
  int a,b,x;
  std::cin >> a >> b >> x;
  if(a<=x && a+b>=x) printf("YES\n");
  else printf("NO\n");
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var nabc = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var n = nabc[0];
        var a = nabc[1];
        var b = nabc[2];
        var c = nabc[3];
        var ls = new int[n];
        for (int i = 0; i < ls.Length; i++)
        {
            ls[i] = int.Parse(Console.ReadLine());
        } 

        var abc = nabc.Skip(1).ToArray();
        var min = Dfs(ls, 0, abc, new int[abc.Length], abc.Sum());
        Console.WriteLine(min);
    }

    static int Dfs(int[] ls, int i, int[] bs, int[] ks, int mp)
    {
        if (i >= ls.Length)
        {
            return ks.Any(x => x == 0) ? int.MaxValue : mp;
        }

        var min = Dfs(ls, i + 1, bs, ks, mp);
        for (int j = 0; j < bs.Length; j++)
        {
            var d = 0 <= bs[j] && bs[j] < ls[i]
                ? bs[j] + bs[j] - ls[i]
                : ls[i] <= bs[j]
                ? ls[i]
                : -ls[i];
            if (ks[j] > 0)
            {
                mp += 10;
            }
            ks[j]++;
            mp -= d;
            bs[j] -= ls[i];
            min = Math.Min(min, Dfs(ls, i + 1, bs, ks, mp));
            bs[j] += ls[i];
            mp += d; 
            ks[j]--;
            if (ks[j] > 0)
            {
                mp -= 10;
            }
        }
        return min;
    }
}


Measured memory_bytes: 15444
n,t=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
a=[]
for j in range(n):
  if t>=l[j][1]:
    a.append(l[j][0])
if len(a)==0:print('TLE')
else:
  print(min(a))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(v, n) sort(v, v+n)
#define VSORT(v) sort(v.begin(), v.end())
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 999999999
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
    int N;
    cin >> N;
    vector<vector<string>> SP(N, vector<string>(2));
    vector<vector<string>> SP2(N, vector<string>(2));
    REP(i,N){
        cin >> SP[i][0] >> SP[i][1];
        SP2[i][0] = SP[i][0];
        SP2[i][1] = SP[i][1];
    }


    sort(&SP2[0], &SP2[N], [](auto& x, auto& y){return x[0] < y[0];});
    REP(i,N){
        REP(j,N-1){
            if(toInt(SP2[j][1])<toInt(SP2[j+1][1])&&SP2[j][0]==SP2[j+1][0])swap(SP2[j][1],SP2[j+1][1]);
        }
    }
    REP(i,N){
        REP(j,N){
             if((SP2[i][0]==SP[j][0])&&(SP2[i][1]==SP[j][1])){
                 cout << j+1 <<endl;
                 break;
             }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<map>
using namespace std;
template <class T>
bool find(vector<T> v, T key) {
	for (size_t i = 0; i < v.size(); i++)
		if (v[i] == key)return true;
	return false;
}
void out() { cout << "!OUT\n"; }
int main() {
	string s = "splatoo";
	string before;
	vector<string>v;
	while (true) {
		cout << "?" << s << "n\n" << flush;
		cin >> before;
		if (find(v, before)) { out(); return 0; }
		if (before[0] != 'n') { out(); return 0; }
		s = before[before.size() - 1] + s;
		if (s.size() >= 10)s = s.substr(0, 5);
		v.push_back(before);
	}
}

Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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 T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    string S;
    cin >> S;
    vector<char> L;
    for (char c : S)
    {
        L.push_back(c);
    }
    int Q;
    cin >> Q;
    bool inv = false;
    while (Q--)
    {
        int T;
        cin >> T;
        if (T == 1)
        {
            inv = !inv;
        }
        if (T == 2)
        {
            int F;
            char c;
            cin >> F;
            cin >> c;
            if (!inv)
            {
                if (F == 1)
                    L.insert(L.begin(), c);
                else
                {
                    L.push_back(c);
                }
            }
            if (inv)
            {
                if (F == 2)
                    L.insert(L.begin(), c);
                else
                {
                    L.push_back(c);
                }
            }
        }
    }
    if (!inv)
        for (int i = 0; i < L.size(); i++)
        {
            cout << L[i];
        }

    else
    {
        for (int i = L.size() - 1; i >= 0; i--)
        {
            cout << L[i];
        }
    }

    return 0;
}

Measured memory_bytes: 1096
import math
n, m = [int(i) for i in input().split()]
p = [0 for i in range(n + 1)]
for _ in range(m):
    p[int(input())] = 1
    
a = []
a.append(1)
if p[1] == 1:
    a.append(0)
else:
    a.append(1)
for i in range(2, n + 1):
    if p[i] == 1:
        a.append(0)
    else:
        a.append((a[i - 2] + a[i - 1]) % 1000000007)
    
print(a[n])

Measured memory_bytes: 7848
def b_palindrome_phobia(S):
    a_cnt = S.count('a')
    b_cnt = S.count('b')
    c_cnt = S.count('c')
    count = [a_cnt, b_cnt, c_cnt]
    ans = 'YES' if max(count) - min(count) <= 1 else 'NO'
    return ans

S = input().strip()
print(b_palindrome_phobia(S))

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

#include <stdio.h>

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

int partition (int array[], int l, int r) {
    int pivot = array[r];
    int i = (l - 1);

    for (int j = l; j <= r - 1; j++) {
        if (array[j] <= pivot) {
            i++;
            swap(&array[i], &array[j]);
        }
    }
    swap(&array[i + 1], &array[r]);
    return (i + 1);
}

void quickSort(int array[], int l, int r) {
    if (l < r) {
        int pivot = partition(array, l, r);
        quickSort(array, l, pivot - 1);
        quickSort(array, pivot + 1, r);
    }
}



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

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

  for(int i=0;i<N;i++){
       cin >> A[i];
   }
  
   quickSort(A, 0, sizeof(A) / sizeof(A[0]) - 1);
  
   // 出力
   int before = -99999;
  
   for(int i=0;i<N;i++){
       if(before == A[i])  {
           cout << "NO" << endl;
           return 0;
       }
       before = A[i];
   }
   cout << "YES" << endl;

   return 0;
}


Measured memory_bytes: 1024
<?php

	$n = trim(fgets(STDIN));
	for($i=0; $i<$n; $i++){
	    $p[$i] = trim(fgets(STDIN)) - 1;
	    $q[$p[$i]] = $i;
	}
	
	$x = 0;
	$tmp = 0;
	
	for($i=0; $i<$n; $i++){
	    if($tmp == 0){
	        $tmp = 1;
	    } else {
	        if($q[$i-1] < $q[$i]) $tmp++;
	        else{
	            if($tmp > $x) $x = $tmp;
	            $tmp = 1;
	        }
	    }
	}
	if($tmp > $x) $x = $tmp;
	echo $n - $x;
?>

Measured memory_bytes: 23284
#include <iostream>
#include <string>

using namespace std;

typedef long long ll;

int main() {
    string s;   ll k;   cin >> s >> k;  int n = s.length();
    for (int i = 0; i < n; i++) {
        ll d = (26 - (s[i]-'a')) % 26;
        if (d > k)
            continue;
        
        s[i] = 'a';
        k -= d;
    }

    if (k > 0) {
        int t = s[n-1]-'a';
        s[n-1] = (k%26 + t) % 26 + 'a';
    }
    cout << s << endl;
    return 0;
}

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int a[]{300000,200000,100000};
int main(){
	int x,y;cin>>x>>y;
	if(x==1&&y==1){
		cout<<1000000<<endl;
	}
	else{
		x--;y--;
		cout<<(x<3?a[x]:0)+(y<3?a[y]:0)<<endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn=212345;
const int mod=1000000007;
int h,w,a,b,fac[maxn],rev[maxn];
inline int ksm(int x,int n) {
    int ret=1;
    while (n) {
        if (n&1) ret=1ll*ret*x%mod;
        n>>=1;
        x=1ll*x*x%mod;
    }
    return ret;
}
inline int C(int x,int y) {
    return 1ll*fac[x]*rev[y]%mod*rev[x-y]%mod;
}
int main()
{
    fac[0]=rev[0]=1;
    for (int i=1;i<maxn;++i) {
        fac[i]=1ll*fac[i-1]*i%mod;
        rev[i]=ksm(fac[i],mod-2);
    }
    scanf("%d%d%d%d",&h,&w,&a,&b);
    int res=C(h+w-2,w-1);
    for (int i=1;i<=b;++i) {
        int y=i,x=h-a;
        res=((res-1ll*C(x+y-2,y-1)*C(w-x+h-y-1,w-y)%mod)%mod+mod)%mod;
    }
    printf("%d\n",res);
    return 0;
}


Measured memory_bytes: 1920
A, B, C, D = map(int, input().split())
takahashi_hp = A 
aoki_hp = C
while True:
  aoki_hp -= B
  if aoki_hp <= 0:
    break
  takahashi_hp -= D
  if takahashi_hp <= 0:
    break
if takahashi_hp <= 0:
  print("No")
else:
  print("Yes")

Measured memory_bytes: 9140
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<functional>
using namespace std;
typedef long long LL;
inline long long read()
{
	long long kk=0,f=1;
	char cc=getchar();
	while(cc<'0'||cc>'9'){if(cc=='-')f=-1;cc=getchar();}
	while(cc>='0'&&cc<='9'){kk=(kk<<1)+(kk<<3)+cc-'0';cc=getchar();}
	return kk*f;
}
const LL mod=1e9+7;
int main()
{
	LL n=read(),k=read();
	LL asd=1;
	for(LL i=k;i<=n;++i)
	{
		asd=((asd+(n+1)*i%mod)%mod-i*i%mod+1)%mod;
	}
	printf("%lld\n",(asd+mod)%mod);
}

Measured memory_bytes: 3776
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;

int main(){
    int a,b;
    cin>>a>>b;
    if(a%3==0||b%3==0||(a+b)%3==0){
        cout<<"Possible"<<endl;
    }else{
        cout<<"Impossible"<<endl;
    }
    
    
 
return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i, x) for (long long i = 0; i < x; i++)
#define repn(i, x) for (long long i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rrepn(i, n) for (int i = ((int)(n)); i > 0; --i)
#define SZ(x) ((int)(x).size())
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;
}
vector<pair<string, P>> vec;
// vector<vector<int>> data(3, vector<int>(4));

int main() {
    int D;
    cin >> D;
    vector<int> c(26);
    rep(i, 26) cin >> c[i];
    vector<vector<int>> s(D, vector<int>(26));
    rep(i, D) rep(j, 26) cin >> s[i][j];

    vector<int> t(D);
    // rep(i, D) {
    //     cin >> t[i];
    //     t[i]--;
    // }

    rep(i, D) {
        int now = 0;
        rep(j, 26) {
            if (now <= s[i][j]) {
                now = s[i][j];
                t[i] = j;
            }
        }
    }

    auto scoring = [&]() {
        vector<int> last(26);
        int score = 0;
        rep(i, D) {
            score += s[i][t[i]];
            last[t[i]] = i + 1;
            int m = 0;
            rep(j, 26) m += c[j] * (i + 1 - last[j]);
            score -= m;
            // cout << score << endl;
        }
        return score;
    };

    int score = scoring();
    srand((unsigned int)time(NULL));
    rep(i, 20000) {
        int d = rand() % D;
        int q = rand() % 26;
        int old = t[d];
        t[d] = q;
        int now = scoring();
        if (score > now) {
            t[d] = old;
        } else {
            score = now;
        }
    }

    rep(i, D) { cout << t[i] + 1 << endl; }
    return 0;
}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
//#define int long long
using namespace std;
const int MOD = 1000000007;
//const int INF = 1e15;
using Graph = vector<vector<int>>;

//(i, j)に到着する道のりのうち、差がkのものがあるか
bool dp[85][85][26000];

int main(){
  int H, W;
  cin >> H >> W;

  vector<vector<int>> A(H+2, vector<int>(W+2));
  for( int i = 0; i < H; i++ ){
    for( int j = 0; j < W; j++ ) cin >> A[i][j];
  }

  vector<vector<int>> B(H+2, vector<int>(W+2));
  for( int i = 0; i < H; i++ ){
    for( int j = 0; j < W; j++ ) cin >> B[i][j];
  }

  int mid = 12800;
  dp[0][0][mid + A[0][0]-B[0][0]] = true;
  dp[0][0][mid + B[0][0]-A[0][0]] = true;

  for( int i = 0; i < H; i++ ){
    for( int j = 0; j < W; j++ ){
      for( int k = -12800; k <= 12800; k++ ){
        if( dp[i][j][mid+k] == true ){
          //下へ移動する場合
          dp[i+1][j][mid+k + A[i+1][j]-B[i+1][j]] = true; //Aを赤く塗ったとき
          dp[i+1][j][mid+k + B[i+1][j]-A[i+1][j]] = true; //Bを赤く塗ったとき
          //右へ移動する場合
          dp[i][j+1][mid+k + A[i][j+1]-B[i][j+1]] = true;
          dp[i][j+1][mid+k + B[i][j+1]-A[i][j+1]] = true;
        }
      }
    }
  }

  int ans = 13000;
  for( int i = 0; i < 26000; i++ ){
    if( dp[H-1][W-1][i] == true ){
      ans = min(ans, abs(i-mid));
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 175232
#include <stdio.h>

int main(void){
  int ki = 0,gu = 0;
  int i,K;
  
  scanf("%d",&K);
  for(i = 1;i <= K; ++i){
    if(i % 2)	++ki;
    else ++gu;
  }
  printf("%d\n",ki * gu);
}

Measured memory_bytes: 128
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long



using namespace std;

void file(){
	#ifndef ONLINE_JUDGE
    	freopen("in.txt", "r", stdin);
	#endif
}
int tc;
const int N=1e6+5,M=2e6+5,MOD=1e9+7,OO=1e9;

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//file();
	int n,m;
	scanf("%d %d",&n,&m);
	std::vector<vector<int>> a(m,std::vector<int>(2));
	for(int i=0;i<m;i++){
		scanf("%d%d",&a[i][0],&a[i][1]);
	}
	for(int i=0;i<=999;i++){
		string s;
		int x=i;
		while(x){
			s+=(x%10)+'0';
			x/=10;
		}
		reverse(s.begin(),s.end());
		if (s.empty())
			s+='0';
		if (s.size()!=n)
			continue;
		bool ok=true;
		for(int i=0;i<m;i++){
			int p=a[i][0]-1;
			if (s[p]-'0'!=a[i][1])
				ok=false;
		}
		if (ok)
			return !printf("%s\n",s.c_str());
	}
	printf("-1\n");
}		



Measured memory_bytes: 256
A = input()
for i in range(0,2**3):
	X = [0]*3
	for k in range(3):
		if (i>>k)&1:
			X[k] = "+"
		else:
			X[k] = "-"
	if eval(A[0]+X[0]+A[1]+X[1]+A[2]+X[2]+A[3]) == 7:
		print(A[0]+X[0]+A[1]+X[1]+A[2]+X[2]+A[3]+"=7")
		break

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

using namespace std;
 
/// ----------------------------- (Debug) ------------------------------
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {ris << "(" << d.first << ", " << d.second << ")";}
sim dor(rge<c> d) {*this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]";}
#else
sim dor(const c&) { ris; }
#endif
};
vector<char*> tokenizer(const char* args) {
	char *token = new char[111]; strcpy(token, args); token = strtok(token, ", ");
	vector<char*> v({token});
	while(token = strtok(NULL,", ")) v.push_back(token);
	return reverse(v.begin(), v.end()), v;
}
void debugg(vector<char*> args) { cerr << "\b\b "; }
template <typename Head, typename... Tail>
void debugg(vector<char*> args, Head H, Tail... T) {
	debug() << " [" << args.back() << ": " << H << "] ";
	args.pop_back(); debugg(args, T...);
}
#define harg(...) #__VA_ARGS__
#ifndef ONLINE_JUDGE
#define dbg(...) { debugg(tokenizer(harg(__VA_ARGS__, \b\t-->Line)), __VA_ARGS__, __LINE__); cerr << endl;}
#else
#define dbg(...) { }
#endif
/// -----------------------------------------------------------------------
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi; 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)    
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define print(x) cout << x << "\n";
#define REP(i,a,b) for(i=a;i<=b;i++)
#define RAP(i,a,b) for(i=a;i>=b;i--)
#define spa <<" "<<
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
ll mod=1e9+7;
const int MX=0x3f3f3f3f;

int main(){
	IOS;
	int x;
	cin>>x;
	if(x>=1800) cout<<"1";
	else if(x>=1600) cout<<"2";
	else if(x>=1400) cout<<"3";
	else if(x>=1200) cout<<"4";
	else if(x>=1000) cout<<"5";
	else if(x>=800)	cout<<"6";
	else if(x>=600) cout<<"7";
	else cout<<"8";
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

typedef long long ll;
typedef struct {
    ll x, y;
    ll cost;
} state;

const ll inf = 1ll << 60ll;
const ll dy[] = {1, 0, -1, 0};
const ll dx[] = {0, 1, 0, -1};

ll h, w;
queue<state> que;
vector<vector<ll>> min_cost(1005, vector<ll>(1005, inf));

int main()
{
    ll ans = 0;
    char ch;
    
    cin >> h >> w;
    for (ll i = 0; i < h; i++) {
        for (ll j = 0; j < w; j++) {
            cin >> ch;

            if (ch == '#') {
                que.push((state){j, i, 0});
                min_cost[i][j] = 0;
            }
        }
    }

    while(!que.empty()) {
        state now = que.front();
        que.pop();
        
        for (ll i = 0; i < 4; i++) {
            ll ny = now.y + dy[i];
            ll nx = now.x + dx[i];
            ll ncost = now.cost + 1;

            if (ny >= 0 && ny < h &&
                nx >= 0 && nx < w &&
                min_cost[ny][nx] == inf) {
                
                min_cost[ny][nx] = ncost;
                que.push((state){nx, ny, ncost});
            }
        }
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            ans = max(ans, min_cost[i][j]);

            /*
            if (min_cost[i][j] == inf) {
                cout << i << ' ' << j << endl;
            }
            */
        }
    }

    cout << ans << endl;

    return 0;
}


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

#define INIT_CAP 10
#define INF 1000000000

#define min(a, b) (((a) < (b)) ? (a) : (b))

const int di[4] = {-1, 0, 1, 0};
const int dj[4] = {0, 1, 0, -1};

typedef struct {
	int to, w;
} Edge;

typedef struct {
	Edge *elem;
	int cap, size;
} VecEdge;

typedef struct {
	int num, d;
} PNumDis;

VecEdge adj[30 * 30 * 4];
PNumDis heap[30 * 30 * 4 * 4];
int hsize;
int d[30 * 30 * 4];

int w, h;
int field[30][30];

void init(int n) {
	while (n--)
		adj[n] = (VecEdge){malloc(sizeof(Edge) * INIT_CAP), INIT_CAP, 0};
}

inline void add(int from, int to, int w) {
	if (adj[from].size == adj[from].cap) {
		adj[from].cap <<= 1;
		adj[from].elem = realloc(adj[from].elem, sizeof(Edge) * adj[from].cap);
	}
	adj[from].elem[adj[from].size++] = (Edge){to, w};
}

void freeAll(int n) {
	while (n--)
		free(adj[n].elem);
}

inline void insert(int num, int d) {
	int i;
	for (i = hsize++; i > 0 && d < heap[i - 1 >> 1].d; i = i - 1 >> 1)
		heap[i] = heap[i - 1 >> 1];
	heap[i] = (PNumDis){num, d};
}

inline int calcNextIdx(int i) {
	return i * 2 + 1 + (i * 2 + 2 < hsize && heap[i * 2 + 1].d > heap[i * 2 + 2].d);
}

inline PNumDis delete(void) {
	int i;
	int nextIdx;
	const PNumDis root = heap[0], last = heap[--hsize];

	for (i = 0; i * 2 + 1 < hsize && last.d > heap[nextIdx = calcNextIdx(i)].d; i = nextIdx)
		heap[i] = heap[nextIdx];
	heap[i] = last;

	return root;
}

void dijkstra(int n, int s) {
	int i;

	for (i = 0; i < n; i++)
		d[i] = INF;

	d[s] = 0;
	insert(s, 0);
	while (hsize > 0) {
		const PNumDis fromP = delete();

		if (fromP.d > d[fromP.num])
			continue;

		for (i = 0; i < adj[fromP.num].size; i++) {
			const Edge e = adj[fromP.num].elem[i];
			if (fromP.d + e.w < d[e.to]) {
				d[e.to] = fromP.d + e.w;
				insert(e.to, d[e.to]);
			}
		}
	}
}

int main(void) {
	int i, j, k, l;

	while (scanf("%d %d", &w, &h), w) {
		int c[4];

		for (i = 0; i < h; i++)
			for (j = 0; j < w; j++)
				scanf("%d", field[i] + j);

		for (i = 0; i < 4; i++)
			scanf("%d", c + i);

		init(h * w * 4);
		for (i = 0; i < h; i++)
			for (j = 0; j < w; j++)
				for (k = 0; k < 4; k++)
					for (l = 0; l < 4; l++) {
						int nd = k + l & 3;
						int ni = i + di[nd], nj = j + dj[nd];
						if (ni >= 0 && ni < h && nj >= 0 && nj < w)
							add(i * w * 4 + j * 4 + k, ni * w * 4 + nj * 4 + nd, l == field[i][j] ? 0 : c[l]);
					}

		dijkstra(h * w * 4, 1);

		printf("%d\n", min(d[(h - 1) * w * 4 + (w - 1) * 4 + 1], d[(h - 1) * w * 4 + (w - 1) * 4 + 2]));

		freeAll(h * w * 4);
	}

	return 0;
}

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

int n;
string c;
vector<int> r, w;

int solve();

int main() {
  cin >> n >> c;
  for (int i = 0; i < n; ++i)
    if (c[i] == 'R')
      r.push_back(i);
    else
      w.push_back(i);
  cout << solve() << endl;
  return 0;
}

int solve() {
  int res = 0;
  reverse(r.begin(), r.end());
  int len = min(r.size(), w.size());
  for (int i = 0; i < len; ++i)
    if (w[i] < r[i]) ++res;
  return res;
}


Measured memory_bytes: 4728
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#define INF 1e9
#define MAX_N 200001

using namespace std;

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

int main() {
    int N;
    int X[MAX_N];
    int sorted_X[MAX_N];
    cin >> N;
    for (int i = 0; i < N; ++i) {
        cin >> X[i];
        sorted_X[i] = X[i];
    }
    sort(sorted_X, sorted_X + N);
    
    int l = sorted_X[N/2 - 1];
    int r = sorted_X[N/2];
    
    for (int i = 0; i < N; ++i) {
        if (X[i] <= l) {
            printf("%d\n", r);
        } else {
            printf("%d\n", l);
        }
    }
    
    return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "}"; return os; }

LL solve(LL t, map<LL,LL>& rest_map, vector<pair<LL,LL>>& shop){
    sort(shop.begin(), shop.end(), [](const pair<LL,LL>& op1, const pair<LL,LL>& op2){
        return op1.first*(op2.second+1) > op2.first*(op1.second+1);
        });
    vector<vector<LL>> dp(shop.size()+1, vector<LL>(30, t+1));
    dp[0][0] = 0;

    for(LL i = 0; i < shop.size(); ++i){
        for(LL j = 0; j < 29; ++j){
            if(dp[i][j] > t) continue;
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            LL cost = (dp[i][j]+1)*shop[i].first + shop[i].second;
            dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j] + 1 + cost);
        }
    }

    LL ans = 0;
    for(LL i = 0; i < 30; ++i){
        LL rest = t - dp[shop.size()][i];
        if(rest < 0) continue;
        auto it = rest_map.lower_bound(rest);
        if(it == rest_map.end() || it->first > rest){
            --it;
        }
        ans = max(ans, i + it->second);
    }
    /*
    cerr << rest_map << endl;
    cerr << shop << endl;
    cerr << dp << endl;
    */
    return ans;
}


int main(){
    LL n, t;
    cin >> n >> t;
    vector<LL> rest;
    vector<pair<LL,LL>> shop;
    for(LL i = 0; i < n; ++i){
        LL a, b;
        cin >> a >> b;
        if(a == 0){
            rest.push_back(b);
        }else{
            shop.emplace_back(a, b);
        }
    }
    sort(rest.begin(), rest.end());
    map<LL,LL> rest_map;
    rest_map[0] = 0;
    LL cum = 0;
    for(LL i = 0; i < rest.size(); ++i){
        cum += rest[i]+1;
        rest_map[cum] = i+1;
    }

    cout << solve(t, rest_map, shop) << endl;
    return 0;
}



Measured memory_bytes: 58476
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
using ll = long long;
#define pi 3.1415926

int x[3];

int main(){
    int n, k;
    cin >> n >> k;
    if(n%k == 0)
        cout << "0";
    else    
        cout << "1";
}
	


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

using namespace std;

#define NONE 0
#define LEFT 1
#define RIGHT 2
#define N 500000

struct Cell{
	int idx, left, right;

	Cell(){

	}

	Cell(int idx, int left, int right){
		this->idx = idx;
		this->left = left;
		this->right = right;
	}
};

int s[N + 2];
int l[N + 2];
int r[N + 2];
Cell c[N + 2];
int dp[N + 2][3];
int n, m;

bool inter(int x, int y){
	return c[x].idx + c[x].right + 1 == c[y].idx;
}

int solve(int x, int last){
	if (x > m){
		return 0;
	}

	if (dp[x][last] != -1){
		return dp[x][last];
	}

	if (c[x].left and c[x].right){ // If current is candidate
		if (last == NONE or !inter(x - 1, x)){
			return dp[x][last] = max(solve(x + 1, NONE), max(solve(x + 1, LEFT) + c[x].left, solve(x + 1, RIGHT) + c[x].right));
		}

		if (last == LEFT){
			if (c[x].left == 1){
				return dp[x][last] = solve(x + 1, NONE);
			}

			return dp[x][last] = max(solve(x + 1, NONE), max(solve(x + 1, LEFT) + c[x].left - 1, solve(x + 1, RIGHT) + c[x].right));
		}

		return dp[x][last] = max(solve(x + 1, NONE), solve(x + 1, RIGHT) + c[x].right - 1);
	}

	return dp[x][last] = solve(x + 1, NONE);
}

int main(){
	int i;

	scanf("%d", &n);

	for (i = 1; i <= n; i++){
		scanf("%1d", s + i);
	}

	for (i = 1; i <= n; i++){
		if (s[i]){
			l[i] = l[i - 1] + 1;
		}
		else{
			l[i] = 0;
		}
	}

	for (i = n; i >= 1; i--){
		if (s[i]){
			r[i] = r[i + 1] + 1;
		}
		else{
			r[i] = 0;
		}
	}

	m = 0;

	for (i = 1; i <= n; i++){
		if (!s[i]){
			m++;
			c[m] = Cell(i, l[i - 1], r[i + 1]);
		}
	}

	memset(dp, -1, sizeof(dp));

	printf("%d\n", solve(1, NONE));

	return 0;
}

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

int partition(vector<int> &a, int p, int r){
    int base = a.at(r);
    int i = p - 1;
    for(int j = p; j < r; j++){
        if(a.at(j) <= base){
            i++;
            int tmp = a.at(i);
            a.at(i) = a.at(j);
            a.at(j) = tmp;
        }
    }
    a.at(r) = a.at(i+1);
    a.at(i+1) = base;
    return i+1;
}



int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n){
        cin >> a.at(i);
    }
    int index = partition(a, 0, n-1);

    for(int i = 0; i < n-1; i++){
        if(i == index){
            cout << "[" << a.at(i) << "] ";
        }else{
            cout << a.at(i) << " ";
        }
    }
    cout << a.at(n-1) << endl;

}


Measured memory_bytes: 3128
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		String tile = scan.next();
		String[] array = new String[tile.length()];
		int count = 0;

		for(int i=0;i<tile.length();i++) {
			array[i] = tile.substring(i,i+1);
		}

		for(int i=0;i<tile.length()-1;i++) {
			if(array[i].equals("0") && array[i+1].equals("0")) {
				array[i+1] = "1";
				count++;
			}else if(array[i].equals("1") && array[i+1].equals("1")) {
				array[i+1] = "0";
				count++;
			}
		}

		System.out.println(count);
		scan.close();
	}

}


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

using namespace std;
typedef long long ll;

int main(){
	int a, b;
	cin >> a >> b;
	int ans = 0;
	for(int i = a; i <= b; i++){
		int temp = i;
		vector<int> N(5);
		for(int j = 4; j >= 0; j--){
			N[j] = temp % 10; 
			temp = temp / 10;
		}
		
		if(N[0] == N[4] && N[1] == N[3]){
			ans++;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args) {
        int n = int.Parse(Console.ReadLine());
        long[] aryA = ToLongArray(Console.ReadLine(), n+1);
        long[] aryB = ToLongArray(Console.ReadLine(), n);


        Console.WriteLine(process(n, aryA, aryB));
        Console.ReadLine();
    }

    static long process(int n, long[] aryA, long[] aryB) {
        long count = 0;
        for(var i=0; i<n+1; i++) {
            //前勇者割り当て
            if (i > 0) { 
                var v = Math.Min(aryA[i], aryB[i - 1]);
                aryA[i] -= v;
                aryB[i - 1] -= v;
                count += v;
            }
            //後勇者割り当て
            if (i < n) {
                var v = Math.Min(aryA[i], aryB[i]);
                aryA[i] -= v;
                aryB[i] -= v;
                count += v;
            }
        }
        return count;
    }

    static int[] ToIntArray(string strs, int n) {
        int[] ret = new int[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++) ret[i] = int.Parse(spl[i]);
        return ret;
    }
    static long[] ToLongArray(string strs, int n) {
        long[] ret = new long[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++) ret[i] = long.Parse(spl[i]);
        return ret;
    }
}

Measured memory_bytes: 31708
#include<iostream>  
#include<cstring>  
#include<string>  
#include<cstdio>  
#include<cmath>  
#include<vector>  
#include<queue>  
#include<algorithm>  
using namespace std;
#define inf 0x3f3f3f3f  
#define ll long long  
const int maxn = 1e5 + 500;
char a[100][100];
int n, m;
bool ok(int i, int j) {
	if (i - 1 >= 0 && a[i - 1][j] == '#')
		return true;
	if (j - 1 >= 0 && a[i][j - 1] == '#')
		return true;
	if (i + 1 <n  && a[i + 1][j] == '#')
		return true;
	if (j + 1 <m && a[i][j + 1] == '#')
		return true;
	return false;
}
int main()
{
	while (~scanf("%d%d", &n, &m)) {
		for (int i = 0; i < n; i++)
			scanf("%s", &a[i]);
		int key = 1;
		for(int i=0;i<n;i++)
			for(int j=0;j<m;j++)
				if (a[i][j]=='#'&&!ok(i, j)) {
					key = 0; break;
				}
		if (key)cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[2 * n];
		for (int i = 0; i < 2 * n; i++) {
			arr[i] = sc.nextInt();
		}
		Arrays.sort(arr);
		int res = 0;
		for (int i = 0; i < 2 * n;) {
			res += arr[i];
			i += 2;
		}
		System.out.println(res);

	}

}


Measured memory_bytes: 10060
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;

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;
}

const int MSB_POS = 40;

vector<ll> as;
vector<ll> ones;

void calc_ones() {
    for (int i = MSB_POS; i >= 0; i--) {
        ll cnt = 0;
        for (auto &a : as) {
            if (a & (1LL << i)) {
                cnt++;
            }
        }
        ones[i] = cnt;
    }
}

ll solve(const ll N, const ll K) {
    ll ans = 0;

    // candidate with K
    for (int j = MSB_POS; j >= 0; j--) {
        bool has_bit_k = (K & (1LL << j)) != 0;
        if (has_bit_k) {
            ans += (N - ones[j]) * (1LL << j);
        } else {
            ans += ones[j] * (1LL << j);
        }
    }

    for (int i = MSB_POS; i >= 0; i--) {
        ll d_of_k = (K & (1LL << i));
        if (d_of_k == 0) continue;

        ll acc = 0;

        // above i
        for (int j = MSB_POS; j > i; j--) {
            bool has_bit_k = (K & (1LL << j)) != 0;
            if (has_bit_k) {
                acc += (N - ones[j]) * (1LL << j);
            } else {
                acc += ones[j] * (1LL << j);
            }
        }

        // at i
        acc += ones[i] * (1LL << i);

        // below i
        for (int j = i - 1; j >= 0; j--) {
            acc += max(ones[j], N - ones[j]) * (1LL << j);
        }

        chmax(ans, acc);
    }

    return ans;
}

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

    as.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> as[i];
    }

    ones.resize(MSB_POS + 1);
    calc_ones();

    cout << solve(N, K) << endl;

    return 0;
}


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

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << '\n'; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) std::cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << '\n';
}

// 0-indexed Graph class
class Graph {
    typedef struct {
        Int to, weight, cap, rev;
    } edge;
public:
    vector<vector<edge>> G;
    Int node_num;
    Graph(Int in) : node_num(in) {
        G.resize(in);
    }
    void add_edge(Int s, Int t, Int c) {
        edge add = {t, c, c, 0};
        G[s].push_back(add);
    }
    vector<Int> dijkstra(Int s) {
        vector<Int> dist(node_num, INF);
        priority_queue<pair<Int, Int>, vector<pair<Int, Int>>, greater<pair<Int, Int>>> q;
        q.push({0, s});
        dist[s] = 0;
        while (not q.empty()) {
            pair<Int, Int> p = q.top();
            q.pop();
            Int cur = p.second;
            if (dist[cur] < p.first) continue;
            for (Int i = 0; i < (Int)G[cur].size(); i++) {
                Int to = G[cur][i].to;
                Int cost = G[cur][i].weight;
                if (dist[to] > dist[cur] + cost) {
                    dist[to] = dist[cur] + cost;
                    q.push({dist[to], to});
                }
            }
        }
        return dist;
    }
};

int main() {
    Int n, m;
    cin >> n >> m;
    Graph G(4 * n);
    for (Int i = 0; i < m; i++) {
        Int u, v;
        cin >> u >> v;
        u--, v--;
        G.add_edge(u, n + v, 1);
        G.add_edge(n + u, 2 * n + v, 1);
        G.add_edge(2 * n + u, 3 * n + v, 1);
    }
    for (Int i = 0; i < n; i++) {
        G.add_edge(3 * n + i, i, 0);
    }
    Int s, t;
    cin >> s >> t;
    s--, t--;
    vector<Int> d = G.dijkstra(s);
    print(d[3 * n + t] == INF ? -1 : d[3 * n + t] / 3);
    return 0;
}


Measured memory_bytes: 34292
#include <math.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <vector>

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

typedef pair<int, int> P;
using ll = long long;
const int INF = 1e8;

int main() {
  int A, B, H, M;
  cin >> A >> B >> H >> M;
  static const long double pi = 3.141592653589793238462643383279502;
  long double m_rad = M * 6 * pi / 180;
  long double h_rad = (H * 30 + 0.5 * M) * pi / 180;
  long double m_x = B * cosl(m_rad);
  long double m_y = B * sinl(m_rad);
  long double h_x = A * cosl(h_rad);
  long double h_y = A * sinl(h_rad);

  long double ans =
      sqrtl((h_x - m_x) * (h_x - m_x) + (h_y - m_y) * (h_y - m_y));
  cout << fixed << setprecision(20) << ans << endl;
  return 0;
}


Measured memory_bytes: 4164
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int N; string S; vector<int> P;
int memo[1 << 18][19];
int winner(int a, int b) {
    int x = P[a], y = P[b];
    if (x > y) swap(x, y), swap(a, b);
    return (S[y - x - 1] == '0' ? a : b);
}
int f(int a, int b, int n) {
    a = (a + (1 << N)) % (1 << N);
    b = (b + (1 << N)) % (1 << N);
    if (memo[a][n] != -1) return memo[a][n];
    if (n == 1) {
        return memo[a][n] = winner(a, b);
    } else {
        int s = f(a, a + (1<<n)/2 - 1, n-1);
        int t = f(a + (1<<n)/2, b, n-1);
        return memo[a][n] = winner(s, t);
    }
}
int main() {
    cin >> N >> S;
    P.resize(1 << N); for (auto &p : P) cin >> p;
    for (int i = 0; i < (1 << N); i++) {
        for (int j = 0; j <= N; j++) {
            memo[i][j] = -1;
        }
    }
    for (int k = 0; k < (1 << N); k++) {
        cout << P[f(k, k - 1, N)] << '\n';
    }
    return 0;
}


Measured memory_bytes: 23672
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define pb push_back
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);

  vector<string> s(2);
  ll n;
  cin >> n >> s[0] >> s[1];

  ll ans = 3;
  for(ll i = 0; i < n; i++){
    if(i == 0 && s[0][0] != s[1][0]){
      ans = 6;
      i++;
      continue;
    }
    if(i == 0) continue;
    if(s[0][i] == s[1][i]){
      if(s[0][i-1] == s[1][i-1]) ans *= 2;
      ans %= mod;
    }else{
      if(s[0][i-1] == s[1][i-1]) ans *= 2;
      else ans*= 3;
      ans %= mod;
      i++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint(ll 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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
  bool operator==(const mint rhs) const { return x == rhs.x; }
  bool operator!=(const mint rhs) const { return x != rhs.x; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  ll n,k;
  cin >> n >> k;
  vector<ll> a(n), s(n+1,0);  
  rep(i,n) cin >> a[i];
  sort(all(a));
  combination comb(n);

  mint min_sum = 0, max_sum = 0;
  rep(i,n-k+1) {
    min_sum += comb(n-1-i,k-1)*a[i];
  }
  for (int i = k-1; i < n; ++i) {
    max_sum += comb(i,k-1)*a[i];
  }
  cout << max_sum - min_sum << endl;
  return 0;
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define answer cout << ans << endl;
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
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; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}

signed _main(){
  int A,B,K; cin >> A >> B >> K;
  A-=K;
  if(A<0) B+=A;
  cout << max(0LL,A) << " " << max(0LL,B) << endl;
  return 0;
}


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

int main(){
    
    ll N;
    cin >> N;
    vector<ll>a(N);
    for(ll i = 0; i < N; i++)cin >> a[i];
    ll ans = 1145141919;
    for(ll x = -100; x <= 100; x++){
        ll tmp = 0;
        for(ll i = 0; i < N; i++)tmp += (x - a[i]) * (x - a[i]);
        ans = min(ans, tmp);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#ABC128B-GuideBook.py

from sys import stdin

input = stdin.readline

N = int(input())

SP = []

for i in range(N):
    sp = input().split()
    SP.append([sp[0],int(sp[1]),i+1])

SP.sort(key=lambda x:(x[0],-x[1]))

for sp in SP:
    print(sp[2])


Measured memory_bytes: 3060