akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 10000000000000000
#define endl '\n'
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

signed main(void){
    int n,m; cin>>n>>m;
    vector<int> x(n),y(n),z(n);
    rep(i,n)cin>>x.at(i)>>y.at(i)>>z.at(i);
    int ans=0;
    for(int i=-1; i<=1; i+=2)for(int j=-1; j<=1; j+=2)for(int k=-1; k<=1; k+=2){
        priority_queue<int> prique;
        rep(l,n){
            prique.push(x.at(l)*i+y.at(l)*j+z.at(l)*k);
        }
        int sum=0;
        rep(l,m){
            sum+=prique.top(); prique.pop();
        }
        chmax(ans, sum);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

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

    int N, K;
    cin >> N >> K;
    vector<ll> A(N);

    rep(i, N) { cin >> A[i]; }

    int cnt = 0;
    while (true) {
        vector<ll> sum(N + 1, 0);
        bool judge = 1;
        rep(i, N) {
            int a = A[i];
            int left = max(0, i - a);
            int right = min(N, i + a + 1);
            sum[left] += 1;
            sum[right] -= 1;
        }

        rep(i, N + 1) { sum[i + 1] += sum[i]; }

        rep(i, N) {
            A[i] = sum[i];
            if (A[i] != N)
                judge = 0;
        }

        cnt++;
        if (cnt == K || judge) {
            rep(i, N) { cout << A[i] << " "; }
            return 0;
        }
    }
}

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

#define SZ(x) (((int)x.size()))
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

using namespace std;

const int maxn = 200*1000+10, mod = 1000000007;
ll f[maxn], tmp, rf[maxn], fin[maxn], ad[maxn], au[maxn], z[maxn];
int n, u, v;
bool mark[maxn];
vector<int> vec[maxn], tam[maxn];
vector<ll> idk[maxn], l[maxn], r[maxn];

ll power(ll a, int b, int m)
{
	if (b == 0)
		return 1;
	ll c = power(a, b / 2, m);
	if (b & 1)
		return (((c * c) % m) * a) % m;
	return (c * c) % m;
}

void dfs1(int x)
{
	z[x]++;
	mark[x] = 1;
	ad[x] = 1;
	for (auto &w : vec[x])
	{
		if (mark[w])
			continue;
		tam[x].push_back(w);
		dfs1(w);
		z[x] += z[w];
		ad[x] *= (ad[w] * rf[z[w]]) % mod;
		ad[x] %= mod;
		idk[x].push_back((ad[w] * rf[z[w]]) % mod);
	}
	l[x].push_back(1);
	for (auto &w : idk[x])
		l[x].push_back((l[x].back() * w) % mod);
	r[x].push_back(1);
	for (int i = SZ(tam[x]) - 1; i >= 0; i--)
		r[x].push_back((r[x].back() * idk[x][i]) % mod);
	ad[x] *= f[z[x] - 1];
	ad[x] %= mod;
}

void dfs2(int x, int p, int ind)
{
	if (x > 0)
	{
		tmp = (((au[p] * l[p][ind]) % mod) * r[p][SZ(tam[p]) - 1 - ind]) % mod;
		tmp *= f[n - 1 - z[x]];
		tmp %= mod;
		au[x] = (tmp * rf[n - z[x]]) % mod;
		fin[x] = (((l[x].back() * ((tmp * rf[n - z[x]]) % mod)) % mod) * f[n - 1]) % mod;
	}
	for (int i = 0; i < SZ(tam[x]); i++)
		dfs2(tam[x][i], x, i);
}

int main()
{
	ios::sync_with_stdio(0);
	f[0] = rf[0] = 1;
	for (int i = 1; i < maxn; i++)
	{
		f[i] = (f[i - 1] * i) % mod;
		rf[i] = power(f[i], mod - 2, mod);
	}
	scanf("%d", &n);
	for (int i = 0; i < n - 1; i++)
	{
		scanf("%d %d", &u, &v);
		u--;
		v--;
		vec[u].push_back(v);
		vec[v].push_back(u);
	}
	dfs1(0);
	fin[0] = ad[0];
	au[0] = 1;
	dfs2(0, -1, 0);
	for (int i = 0; i < n; i++)
		printf("%lld\n", fin[i]);
	return 0;
}


Measured memory_bytes: 64256
import java.util.*;

public class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            int n = sc.nextInt();
            if(n==0) break;

            int[] h = new int[200];
            int[] r = new int[200];

            int idx = 0;
            for(; idx<n; idx++){
                h[idx] = sc.nextInt();
                r[idx] = sc.nextInt();
            }
            int m = sc.nextInt();
            for(; idx<n+m; idx++){
                h[idx] = sc.nextInt();
                r[idx] = sc.nextInt();
            }

            idx = 0;
            int[][] hr = new int[n+m][2];
            for(; idx<n; idx++){
                hr[idx][0] = h[idx];
                hr[idx][1] = r[idx];
            }
            for(; idx<n+m; idx++){
                hr[idx][0] = h[idx];
                hr[idx][1] = r[idx];
            }

            Arrays.sort(hr, new Comparator<int[]>(){
                    public int compare(int[] a, int[] b){
                        return a[0] - b[0];
                    }
                });


            int[] dp = new int[n+m];
            Arrays.fill(dp,1);
            for(int k=0; k<n+m; k++){
                for(int i=0; i<n+m; i++){
                    for(int j=0; j<n+m; j++){
                        if(hr[i][0]<=hr[j][0]) break;
                        if(hr[i][1]<=hr[j][1]) continue;
                        dp[i] = Math.max(dp[i],dp[j]+1);
                    }
                }
            }

            int ans = 0;
            for(int i=0; i<n+m; i++) ans = Math.max(ans, dp[i]);

            System.out.println(ans);
        }
    }

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

Measured memory_bytes: 25272
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define print(x) cout << x << "\n";

int main()
{
    string s, t;
    cin >> s >> t;

    sort(all(s));
    sort(all(t), greater<char>());

    string ans = t > s?"Yes":"No";

    cout << ans << endl;

}

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

int main(int argc, char const *argv[])
{
  while(1)
  {
    int x, y;
    cin >> x >> y;
    if(x==0 && y==0) break;

    if(x > y)
    {
      int tmp = x;
      x = y;
      y = tmp;
    }
    cout << x << " " << y << endl;
  }
  return 0;
}

Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int (i)=0;(i) < (N); (i)++)
#define all(V) V.begin(), V.end()
using i64 = long long;
using P = pair<int,int>;


int main(){
    int N;
    cin >> N;
    i64 ans = 0;
    rep(i,N) ans += i;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int main(){
    char str[25];
    scanf("%s",str);
    int len=strlen(str);
    for(int i=len-1;i>=0;i--)
        printf("%c",str[i]);
    printf("\n");
    return 0;
}



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

int main(){
    long long  x;
    cin >> x;
    for(int i = 1; ; i++){
        if(i*(i+1)/2 >= x){
            cout << i << endl;
            return 0;
        } 
    }
    return 0;
}

Measured memory_bytes: 384
a,b,c = gets.split.map(&:to_i)
index = 0
if a.odd? || b.odd? || c.odd? then
    puts '0'
    exit
end
if a == b && a == c then
    puts '-1'
    exit
end
loop do
    break if a.odd? || b.odd? || c.odd?
    index += 1
    xa = a/2
    xb = b/2
    xc = c/2
    a = xb + xc
    b = xa + xc
    c = xa + xb
end
puts index

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

int main() {
    int n;
    cin >> n;
    auto h = vector<int>(n);
    for (auto &h_i : h)
        cin >> h_i;

    int max_moves = 0;
    int pos = 0;
    int h_curr = h[0];
    int moves = 0;

    for (;;) {
        if (pos == n - 1) {
            max_moves = max(max_moves, moves);
            break;
        }
        int h_next = h[pos + 1];
        if (h_next <= h_curr) {
            moves++;
            pos++;
            h_curr = h[pos];
            continue;
        }

        max_moves = max(max_moves, moves);
        moves = 0;
        pos++;
        h_curr = h[pos];
    }

    cout << max_moves;
    return 0;
}


Measured memory_bytes: 640
package main

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

type YX struct {
	y int
	x int
}

func main() {
	var h, w int
	fmt.Scan(&h, &w)
	var a = make([][]byte, h)
	var d = make([][]int, h)
	var reader = bufio.NewReaderSize(os.Stdin, 1024)
    var ql = make([]YX, 0)
    var ans = 0

	for y := 0; y < h; y++ {
		l, _, _ := reader.ReadLine()
		a[y] = make([]byte, w)
		d[y] = make([]int, w)
		copy(a[y], l)
		for x := 0; x < w; x++ {
			if a[y][x] == '.' {
				d[y][x] = -1
			} else {
				ql = append(ql, YX{y, x})
			}
		}
	}

	for len(ql) > 0 {
		var newql = make([]YX, 0)
		for _, q := range ql {
			el := []bool{false, false, false, false}
			if q.y > 0 {
				el[0] = true
			}
			if q.y < h-1 {
				el[2] = true
			}
			if q.x > 0 {
				el[3] = true
			}
			if q.x < w-1 {
				el[1] = true
            }
            ans = d[q.y][q.x]
			for i, e := range el {
				if e {
					switch i {
					case 0:
						y, x := q.y-1, q.x
						if d[y][x] == -1 {
							d[y][x] = d[q.y][q.x] + 1
                            newql = append(newql, YX{y, x})
						}
					case 1:
						y, x := q.y, q.x+1
						if d[y][x] == -1 {
							d[y][x] = d[q.y][q.x] + 1
							newql = append(newql, YX{y, x})
						}
					case 2:
						y, x := q.y+1, q.x
						if d[y][x] == -1 {
							d[y][x] = d[q.y][q.x] + 1
							newql = append(newql, YX{y, x})
						}
					case 3:
						y, x := q.y, q.x-1
						if d[y][x] == -1 {
							d[y][x] = d[q.y][q.x] + 1
							newql = append(newql, YX{y, x})
						}
					}
				}
			}
		}
		ql = newql
	}

	fmt.Println(ans)
}

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


#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define all(x) begin(x), end(x)
#define loop(i,n) for(int i=0; i<n; i++)
#define rep(i,a,b,c) for(int i=a; i<b; i+=c)
#define brep(i,a,b,c) for(int i=a; i>b; i-=c)
#define tc(t) int t; cin>>t; while(t--)
#define sz(v) int((v).size())
#define pb push_back

const int N = 2e5 + 10;


using namespace std;

int main()
{

#ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
#endif

   IOS;

   ll n;
   cin >> n;

   ll a[n];

   ll cnt[100010] = {};

   ll sum=0;

   loop(i, n)
   {
      cin >> a[i];

      cnt[a[i]]++;

      sum+=a[i];

   }


   ll q;
   cin >> q;


   while (q--)
   {
      ll b, c;
      cin >> b >> c;
     
      sum -= cnt[b]*(b-c);

      cnt[c] += cnt[b];

      cnt[b] = 0;

      cout<<sum<<endl;

   }




   return 0;
}


Measured memory_bytes: 5148
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, P;
    cin >> N >> P;
    int cnt[2] = {};
    int tmp;
    rep(i, N) {
        cin >> tmp;
        cnt[tmp % 2]++;
    }
    ll ans = pow(2, N);
    if (cnt[0] == N) {
        if (P == 0){ 
            cout << ans << endl;
        } else {
            cout << "0" << endl;
        }
        return 0;
    }
    cout << ans/2 << endl;
  
    return 0;
}


Measured memory_bytes: 512
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		String s = sc.next();
		String t = sc.next();
		
		// 計算
		String result = "No";
		char[] ss = s.toCharArray();
		Arrays.sort(ss);
		String s2 = String.valueOf(ss);
		char[] temp = t.toCharArray();
		Arrays.sort(temp);
		char[] tt = new char[temp.length];
		for(int i = 0; i < tt.length; i++){
		    tt[i] = temp[tt.length - 1 - i];
		}
		String t2 = String.valueOf(tt);
		if(s2.compareTo(t2) < 0) result = "Yes";
		
		// 出力
		System.out.println(result);
	}
}



Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
const ll MOD = 1000000007;//998244353;
#include<bits/stdc++.h>
using namespace std;
const int NIL = -1;
const long long INF = 1e17;
struct BellmanFord {
   struct vertex {
      int id;
      int p;
      long long d;
   };
   struct edge {        
      int EndPoint;
      long long weight;
      edge(int EndPoint, long long weight):
         EndPoint(EndPoint),weight(weight){}
   };
   vector<vector<int>> X;
   vector<bool> Y;
   struct Graph {
      vector<vertex> V;
      vector<vector<edge>> E;
      Graph(int n=0):V(n),E(n){};
   };
   Graph G;
   int s;
   BellmanFord(int n, int s):G(n),s(s),Y(n, false),X(n){
      Y[n-1] = true;
      init();
   }
   void init(){
      for (int i = 0; i < G.V.size(); i++){
         G.V[i].id = i;
         G.V[i].p = NIL;
         G.V[i].d = INF;
      }
      G.V[s].d = 0;
   }
   void add(int v, int w, long long weight){
      G.E[v].push_back(edge(w, weight));
      X[w].push_back(v);
   }
   void Relax(vertex u, vertex &v, long long w){
      if (u.d == INF || w == INF)return;
      if (v.d > u.d + w){
         v.d = u.d + w;
         v.p = u.id;
      }
   }
   bool solve() {
      for (int i = 0; i < G.V.size()-1; i++)
         for (int j = 0; j < G.E.size(); j++)
            for (int k = 0; k < G.E[j].size(); k++)
               Relax(G.V[j], G.V[G.E[j][k].EndPoint], G.E[j][k].weight);
      for (int i = 0; i < Y.size()-1; i++)
         for (int j = 0; j < X.size(); j++)
            for (int k = 0; k < X[j].size(); k++)
               if (Y[j])Y[X[j][k]] = true;
      for (int i = 0; i < G.E.size(); i++)
         for (int j = 0; j < G.E[i].size(); j++){
            if (G.V[i].d == INF)continue;
            if (!Y[G.E[i][j].EndPoint])continue;
            if (G.V[G.E[i][j].EndPoint].d > G.V[i].d + G.E[i][j].weight)
               return false;
         }
      return true;
   }
   vertex Min(){
      long long dist = INF;
      vertex v;
      for (auto &&i : G.V){
         if (i.d < dist)
            v = i;
      }
      return v;
   }
   void PrintPath(vertex v) {
      if (v.id == s)cout << s << " ";
      else if (v.p == NIL)cout << -1 << endl;
      else {
         PrintPath (G.V[v.p]);
         cout << v.id << " ";
      }
   }
};
/*main関数*/
//BellmanFord bf(n,s)、
//for(|E|) bf.add(v,w,weight)
//if bf.solve() bf.PrintPath()
//else -inf

int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int n, m, p;
   cin >> n >> m >> p;
   BellmanFord bf(n,0);
   rep(i,m){
      int a, b, c; cin >> a >> b >> c;
      a--; b--;
      bf.add(a, b, p-c);
   }
   if (bf.solve()) cout << (-bf.G.V[n-1].d > 0 ? -bf.G.V[n-1].d : 0) << endl;
   else cout << -1 << endl;
}

Measured memory_bytes: 3960
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long


signed main(){
  int n,a,b,c,d;
  cin>>n>>a>>b>>c>>d;
  string s;
  int now=0,mx=0;
  cin>>s;
  if(c<d){
    repi(i,a-1,c){
      if(s[i]=='#' && s[i+1]=='#'){cout<<"No"<<endl;return 0;}
    }
    repi(i,b-1,d){
      if(s[i]=='#' && s[i+1]=='#'){cout<<"No"<<endl;return 0;}
    }
  }else{
    // cout<<b-1<<" "<<d<<endl;
    repi(i,b-2,d+1){
      if(s[i]=='.') now++;
      else{
	mx=max(mx,now);
	now=0;
      }
    }
    mx=max(mx,now);
    if(mx<3){cout<<"No"<<endl;return 0;}
  }
  
  
  cout<<"Yes"<<endl;
  
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB(x) push_back(x)
#define MP make_pair
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) max_element(x.begin(),x.end())
#define MIN(x) min_element(x.begin(),x.end())
#define couty cout<<'Y'<<'e'<<'s'<<endl
#define coutn cout<<'N'<<'o'<<endl
#define coutY cout<<'Y'<<'E'<<'S'<<endl
#define coutN cout<<'N'<<'O'<<endl
//cout << std::fixed << std::setprecision(15);
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e9;
const long long MOD = 1e9+7;
signed main(){
    int h,n; cin >>h>>n;
    vint a(n); rep(i,n) cin >> a[i];
    if(SUM(a)>=h) couty;
    else coutn;
    
    
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

//#define int             long long
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
//mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
 

int32_t main()
{
    //c_p_c();
    int n,w;
    cin>>n>>w;
    vi a(n+1);
    vi v(n+1);
    int dp[n+1][w+1];
    for(int i=1;i<=n;i++){
        cin>>a[i]>>v[i];
    }
    //for(int i=1;i<=n;i++)cout<<a[i]<<" "<<v[i]<<endl;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=w;j++)dp[i][j]=0;
    }
    for(int i=0;i<=n;i++){
        dp[0][i]=0;
        dp[i][0]=0;
    }
    for(int i=1;i<=n;i++){
        for(int j=0;j<=w;j++){
            if(a[i]<=j){
                dp[i][j]=dp[i-1][j];
                dp[i][j]=max(dp[i][j],v[i]+dp[i-1][j-a[i]]);
            }else dp[i][j]=dp[i-1][j];
           //cout<<dp[i][j]<<" ";
        }//cout<<endl;
    }
    cout<<dp[n][w];
    return 0;
}


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

signed main() {
    long long A, B, V, W, T;

    cin >> A >> V >> B >> W >> T;
    bool res = false;

    long long sa;
    if (A > B) sa = A - B;
    else sa = B - A;

    if (W >= V) {
        cout << "NO"  << endl;
        return 0;
    }

    long long c = V - W;

    for (long long i=0; i<T; i++) {
        if (sa > 0) sa -= c;
        else sa += c;

        if (sa <= 0) {
            res = true;
            break;    
        }
    }
/*
    long long a = A;
    long long b = B;

    for (long long i=0; i<T; i++) {
        if (a < b) {
            a += V;
            b += W;
        } else {
            a -= V;
            b -= W;
        }

        if (a == b) {
            res = true;
            break;
        }
    }
*/

    if (res == true) cout << "YES" << endl;
    else             cout << "NO"  << endl;

    return 0;
}



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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    ll N, Q;
    cin >> N >> Q;

    ll ans = (N-2) * (N-2);
    int mh = N, mv = N;
    vector<int> hor(N+1, -1), ver(N+1, -1);
    for (int i=0; i<Q; ++i) {
        int n, x;
        cin >> n >> x;
        if (n == 1) {
            if (ver[x] == -1) {
                ans -= mh - 2;
                for (int j=x; j<mv; ++j) ver[j] = mh;
                mv = x;
            } else {
                ans -= ver[x] - 2;
            }
        } else {
            if (hor[x] == -1) {
                ans -= mv - 2;
                for (int j=x; j<mh; ++j) hor[j] = mv;
                mh = x;
            } else {
                ans -= hor[x] - 2;
            }
        }
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 4776
from operator import attrgetter

class Restaurant:
    def __init__(self, city, point, num):
        self.city = city
        self.point = point
        self.num = num

n = int(input())

restaurants = []
for i in range(n):
    c, p = map(lambda x: x, input().split(' '))
    restaurants.append(Restaurant(c, 100 - int(p), i + 1))

result = sorted(restaurants, key=attrgetter('city', 'point'))
for r in result:
    print(str(r.num))
    

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace dwacon
{
    class Program
    {

        static void Main(string[] args)
        {
           var read  =Console.ReadLine();
            var split = read.Split(' ');
            long a = long.Parse(split[0]);
            long b = long.Parse(split[1]);
            long looking = a;
            int output = 1;
            while (true)
            {
                if (looking * 2 <= b)
                {
                    looking *= 2;
                    output++;
                }
                else break;

            }
            Console.WriteLine(output);
        }


    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  for(int i = 0; i < N; i++) cin >> d[i];
  sort(d.begin(), d.end(), greater<int>());
  int ans = 1;
  for(int i = 1; i < N; i++) {
    if(d[i] != d[i - 1]) ans++;
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/python3
import math

def f():
    print(-1)
    exit()

def gen(p, n, s, t, u, v, result):
    a = [ [ -1 for i in range(n) ] for j in range(n) ]
    for i in range(n):
        ub = (u[i] >> p) & 1
        vb = (v[i] >> p) & 1
        if s[i] == 0:
            if ub == 1:
                a[i] = [ 1 for j in range(n) ]
        else:
            if ub == 0:
                a[i] = [ 0 for j in range(n) ]
            
        if t[i] == 0:
            if vb == 1:
                for j in range(n):
                    if a[j][i] == 0:
                        f()
                    a[j][i] = 1
        else:
            if vb == 0:
                for j in range(n):
                    if a[j][i] == 1:
                        f()
                    a[j][i] = 0

    for i in range(n):
        ub = (u[i] >> p) & 1
        if s[i] == 1 and ub == 1:
            if 1 in a[i]:
                continue
            
            for j in range(n):
                vb = (v[j] >> p) & 1
                if t[j] == 1 and vb == 1:
                    a[i][j] = 1
                    break

                if t[j] == 0 and vb == 0:
                    if [ a[k][j] for k in range(n) ].count(1) < n - 1:
                        a[i][j] = 1
                        break;
            else:
                f()

    for i in range(n):
        ub = (u[i] >> p) & 1
        if s[i] == 0 and ub == 0:
            if a[i].count(1) == n:
                f()
                
    for j in range(n):
        vb = (v[j] >> p) & 1
        if t[j] == 1 and vb == 1:
            if 1 in [ a[k][j] for k in range(n) ]:
                continue

            for i in range(n):
                ub = (u[i] >> p) & 1
                if s[i] == 1 and ub == 1:
                    a[i][j] = 1
                    break

                if s[i] == 0 and ub == 0:
                    if a[i].count(1) < n - 1:
                        a[i][j] = 1
                        break
            else:
                f()

    for j in range(n):
        vb = (v[j] >> p) & 1
        if t[j] == 0 and vb == 0:
            if [ a[k][j] for k in range(n) ].count(1) == n:
                fi()
                
    for i in range(n):
        for j in range(n):
            v = a[i][j] if a[i][j] >= 0 else 0
            result[i][j] = result[i][j] | (v << p)

n = int(input())
s = tuple(map(int, input().split()))
t = tuple(map(int, input().split()))
u = tuple(map(int, input().split()))
v = tuple(map(int, input().split()))

p = math.log2(max(u + v))

if p.is_integer():
    p = int(p) + 1
else:
    p = int(math.ceil(p))
    
result = [ [ 0 for i in range(n) ] for j in range(n) ]


for i in range(p):
    gen(i, n, s, t, u, v, result)

for i in range(n):
    print(' '.join(map(str, result[i])))


Measured memory_bytes: 172304
#include <stdio.h>
int main(){
  int n,i,swap,A[2]={1,1};
  scanf("%d",&n);
  for(i=1;i<n;i++){
    swap=A[1];
    A[1]+=A[0];
    A[0]=swap;
  }
  printf("%d\n",A[1]);
  return 0;
}



Measured memory_bytes: 2052
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
 
int main() {
 long int N;
  cin>>N;
 long int D = N*(N+1)/2;
//    cout<<D<<endl;
   long int S = N/3;
 long int x = 0;
 long int y =0;
  for(int i=0;i<=S;i++){
   long int SB = i*3;
//    cout<<SB<<endl;
    if(SB%5==0){
      continue;
    }
    else{
   x = x+SB;
      }
      }
//  cout<<x<<endl;
  long int G = N/5;
    for(int j=0;j<=G;j++){
   long int GB = j*5;
//    cout<<GB<<endl;
      y=y+GB;
      }
//  cout<<y<<endl;
  
 long int A = D-x-y;
  cout<<A<<endl;
     
    

}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int K, N;
    cin >> N >> K;
    int a = (N - 1) / (K - 1);
    if ((N - 1) % (K - 1) != 0) {
        a++;
    }
    cout << a << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;

#define MAX 100

int n, s[MAX];

int main() {
	while (1) {
		scanf("%d", &n);
		if (n == 0)
			return 0;

		for(int i = 0; i < n; i++)
			scanf("%d", s + i);
		sort(s, s + n);

		int ans = 0;
		for(int i = 1; i < n - 1; i++)
			ans += s[i];

		printf("%d\n", ans / (n - 2));
	}
}

Measured memory_bytes: 0
package main

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

var scanner = bufio.NewScanner(os.Stdin)

var childList [][]int
var counter []int
var used []bool

func main() {
	scanner.Split(bufio.ScanWords)

	N, Q := nextInt(), nextInt()
	a := make([]int, N-1)
	b := make([]int, N-1)
	childList = make([][]int, N)
	for i := 0; i < N-1; i++ {
		a[i], b[i] = nextInt(), nextInt()
		childList[a[i]-1] = append(childList[a[i]-1], b[i]-1)
		childList[b[i]-1] = append(childList[b[i]-1], a[i]-1)
	}
	p := make([]int, Q)
	x := make([]int, Q)
	for i := range p {
		p[i], x[i] = nextInt(), nextInt()
	}

	counter = make([]int, N)
	for i, v := range p {
		counter[v-1] += x[i]
	}

	used = make([]bool, N)
	dfs(0)
	for _, v := range counter {
		fmt.Printf("%v ", v)
	}
	fmt.Println()
}

func dfs(parent int) {
	used[parent] = true
	for _, v := range childList[parent] {
		if used[v] {
			continue
		}
		counter[v] += counter[parent]
		dfs(v)
	}
}

func next() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}


Measured memory_bytes: 50176
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<cmath>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define A 0
#define B 1
#define C 2
int N;
int main() {
	scanf("%d", &N);
	vector<vector<int>> x(N, vector<int>(3));
	vector<vector<int>> dp(N + 1, vector<int>(3, 0));
	rep(i, 0, N)scanf("%d%d%d", &x[i][A], &x[i][B], &x[i][C]);
	rep(i, 1, N + 1) {
		rep(d, 0, 3) {
			rep(d2, 0, 3)if (d2 != d)dp[i][d2] = max(dp[i - 1][d] + x[i - 1][d2], dp[i][d2]);
		}
	}
	printf("%d", max(max(dp[N][0], dp[N][1]), dp[N][2]));
	return 0;
}

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

using namespace std;

#define ll long long 
#define Coming ios_base :: sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

vector<pair<int,int>>v;

int main()
{
	
	int a[5];
	
	for(int i = 0; i < 5; i++) 
	{
		cin >> a[i];
		
	    int ans1 = a[i]%10;
	
	    if(ans1 == 0) ans1 = 0;
	    else ans1 = 10-ans1;
	
	    v.push_back(make_pair(ans1, a[i]));
    
     }
	
	
	sort(v.begin(), v.end());
	
	
	//for(int i = 0; i < 5; i++) cout << v[i].first << " " << v[i].second << endl;
	
	//cout << endl;
	
	int sum  = 0;
	
	for(int i = 0; i < 5; i++)
	{
		if(v[i].second % 10 == 0) sum += v[i].second;
		else
		{
			 sum += v[i].second;
	         if(i != 4) sum += 10 - (v[i].second % 10);
		}
	}
	
	cout << sum << endl;
	
	v.clear();
	
	return 0;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    a,b,c,d,e,f = LI()
    f += 1
    a *= 100
    b *= 100
    m = [0] * f
    s = [0] * f
    m[0] = 1
    s[0] = 1
    for i in range(f-a):
        if m[i] == 1:
            m[i+a] = 1
    for i in range(f-b):
        if m[i] == 1:
            m[i+b] = 1

    for i in range(f-c):
        if s[i] == 1:
            s[i+c] = 1
    for i in range(f-d):
        if s[i] == 1:
            s[i+d] = 1

    mr = 0
    r = [a,0]
    e = e / (100+e)
    for i in range(0,f):
        if m[i] == 0:
            continue
        for j in range(1,f-i):
            if i+j >= f:
                break
            if s[j] == 0:
                continue
            k = j / (i+j)
            if k > e:
                break
            if k > mr:
                mr = k
                r = [i+j, j]

    return ' '.join(map(str,r))


print(main())





Measured memory_bytes: 67052
#include <cmath>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
#define REP(i,n) for(int i = 0; i < n; i++)

int func(int n){
    if(n  % 2  == 0){
        return n / 2;
    }else{
        return 3 * n + 1;
    }
}

int main(void)
{
    int s;
    cin >> s;
    vector<int> v;
    v.push_back(s);

    for(int i = 0; i < 1100000; i++){
        int f = func(v[i]);
        v.push_back(f);
    }
    int res = 0;
    for(auto num : v){
        if(num == 4 || num == 2 || num == 1)
            break;
        res++;
    }

    cout << res + 4 << endl;

    return 0;
}


Measured memory_bytes: 10604
#include <iostream>
#include <assert.h>
#include <vector>
#include <algorithm>
//#include <functional>


int main(){
    int32_t A,B;
    std::cin >> A >> B;

    int32_t plus = A + B;
    int32_t minus = A - B;
    int32_t mul = A * B;
    int32_t res = std::max(plus,minus);
    res = std::max(res, mul);

    std::cout << res;

    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class Main {
    static List<Coordinate> coordinateList = new ArrayList();
    static double result = 0;
    static int count = 0;
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        int N = input.nextInt();

        for (long i = 0; i < N; i++) {
            coordinateList.add(new Coordinate(input.nextInt(),input.nextInt()));
        }


        int[] arr = new int[N];
        for (int i = 0; i < N; i++){
            arr[i] = i;
        }

        perm(arr,0,N,N);

        System.out.println(result/count);

    }

    public static double distance(int x1, int y1, int x2, int y2){
        return Math.sqrt(Math.pow(Math.abs(x1 - x2),2) + Math.pow(Math.abs(y1 - y2),2));
    }

    public static void perm(int[] arr, int depth, int n, int k) {
        if (depth == k) {
            count++;
            for(int i = 0; i < n - 1; i ++){
                result += distance(coordinateList.get(arr[i]).x,coordinateList.get(arr[i]).y,coordinateList.get(arr[i+1]).x,coordinateList.get(arr[i+1]).y);
            }
            return;
        }

        for (int i = depth; i < n; i++) {
            swap(arr, i, depth);
            perm(arr, depth + 1, n, k);
            swap(arr, i, depth);
        }
    }

    public static void swap(int[] arr, int i, int j) {
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }
}

class Coordinate {
    int x;
    int y;

    public Coordinate(int x, int y){
        this.x = x;
        this.y = y;
    }
}


Measured memory_bytes: 23308
#include <bits/stdc++.h>
#define int long long
using namespace std;

main()
{
	string s;
	cin >> s;
	
	int ans = 0 , b = 0;
	
	for(int i = 0; i < (int)s.size(); i++)
	{
		if(s[i] == 'B')b++;
		else
			ans += b;
	}
	
	cout << ans;
}

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

int main() {
    string s;
    cin >> s;
    bool ans = false;
    for (int i = 0; i < s.size()-1; i++) {
        if (s.at(i) == 'A' && s.at(i+1) == 'C') {
            ans = true;
        }
    }
    if (ans) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{

    int i_inputA;
    int i_inputB;
    int i_output = 6;

    scanf("%d\n%d", &i_inputA, &i_inputB);
    
    i_output -= i_inputA + i_inputB;

    printf("%d", i_output);

}

Measured memory_bytes: 128
#include<iostream>
#include<set>
#include<vector>
#include <algorithm>
using namespace std;
int N;
long long A,B[100005]={};
int main(){
	cin>>N;
	vector<long long> st;
	for(int i=0;i<N;++i){
		cin>>A;
		st.push_back(A);
	}
	sort(st.begin(),st.end());
	for(int i=1;i<=N;++i){
		B[i]=st[i-1]+B[i-1];
	}
	int ans=1;
	for(int i=1;i<=N;++i){
		B[i]=st[i-1]+B[i-1];
		if(B[i]*2<st[i])ans=i+1;
	}
	cout<<N-ans+1<<endl;
	return 0;
}


Measured memory_bytes: 1908
// VALUE THE SACRIFICES..
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
#define int long long
#define out_of_reach ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,n) for(i=0; i < n; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define mod 1000000007
// -----------------------------------------------------------------
signed main()
{
    out_of_reach;
    int t=1;
    //  cin>>t;
    while(t--)
    {
        int n,k,i,j,m;
        cin>>k>>n;
        int ar[n];
        rep(i,n)
            cin>>ar[i];
        sort(ar,ar+n);
        int ans=0;
        for(i=1; i<n; i++)
            ans = max(ans,ar[i]-ar[i-1]);
        ans = max(ans , k - ar[n-1] +ar[0]);
        cout<<k-ans;
    }
    return 0;
}


Measured memory_bytes: 1792
use std::io::*;
use std::str::FromStr;

fn main() {
    let cin = stdin();
    let mut sc = Scanner::new(cin.lock());

    loop {
        let h: usize = sc.next();
        let w: usize = sc.next();

        if h == 0 && w == 0 {
            break;
        }

        for x in 0..h {
            let inner = if x == 0 || x == h - 1 { "#" } else { "." };
            println!("#{}#", inner.repeat(w - 2));
        }
        println!();
    }
}

/* ========== Scanner ========== */

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn read<T: FromStr>(&mut self) -> Option<T> {
        let token = self
            .reader
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn next<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.read() {
            s
        } else {
            writeln!(stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.next()).collect()
    }

    fn chars(&mut self) -> Vec<char> {
        self.next::<String>().chars().collect()
    }
}



Measured memory_bytes: 5028
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	int n;
	cin >> n;
	set<int> mys;
	for(int i = 0; i < n; i++) {
		int inp;
		cin >> inp;
		mys.insert(inp);
	}
	if(mys.size() == n) cout << "YES\n";
	else cout << "NO\n";
}


Measured memory_bytes: 9600
#include <iostream>
#include<cstdio>
int main()
{
    int a,b,c;
	scanf("%d %d %d", &a,&b,&c);
	if (a <= b&&b<=c ) printf("%d %d %d\n",a,b,c); 
	else if (a <= b&&b <= c) printf("%d %d %d\n",a,b,c);
	else if (a <=c&&c <= b) printf("%d %d %d\n",a,c,b);
	else if (b <= c&&c <= a) printf("%d %d %d\n",b,c,a);
	else if (c <= a && a <= b) printf("%d %d %d\n",c,a,b);
	else printf("%d %d %d\n", c, b, a);
	return 0;
}



Measured memory_bytes: 3212
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
const int mod=1e9+7;
int n,f[300005][3][3];
char s[300005];
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	f[0][0][0]=1;
	for(int i=0;i<n;i++)
	{
		for(int a=0;a<=2;a++)
		for(int b=0;b<=2;b++)
		{
			if(s[i+1]!='0')
			{
				if(b) f[i+1][a][b-1]=(f[i+1][a][b-1]+f[i][a][b])%mod;
				else f[i+1][min(a+1,2)][b]=(f[i+1][min(a+1,2)][b]+f[i][a][b])%mod;
			}
			if(s[i+1]!='1')
			{
				if(b==2) f[i+1][a][b-1]=(f[i+1][a][b-1]+f[i][a][b])%mod;
				else f[i+1][a][b+1]=(f[i+1][a][b+1]+f[i][a][b])%mod;
			}
		}
	}
	int ans=0;
	for(int a=0;a<=2;a++)
	for(int b=0;b<=a;b++) ans=(ans+f[n][a][b])%mod;
	printf("%d\n",ans);
}

Measured memory_bytes: 14608
#include <stdio.h>

int main(){
  int n;
  scanf("%d",&n);
  int h[n],max,count;
  max = 0;
  count = 0;
  for(int i = 0; i < n; ++i){
    scanf("%d",&h[i]);
    if(h[i] >= max){
      max = h[i];
      count++;
    }
  }
  printf("%d\n",count);
  return 0;
}

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    # ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    
    int x=0;
    cin>>x;
    if(x>29)
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3644
import itertools
ref = {5:1,9:2,13:3}
dx = [0, 0, 1, 0,-1, 1, 1,-1,-1, 2, 0,-2, 0]
dy = [0,-1, 0, 1, 0,-1, 1, 1,-1, 0, 2, 0,-2]

def isOn(x,y):
    return 0<=x<10 and 0<=y<10

def minus(C,x,y,size):
    for i in range(size):
        C[y+dy[i]][x+dx[i]] -= 1

def plus(C,x,y,size):
    for i in range(size):
        C[y+dy[i]][x+dx[i]] += 1

def canMinus(C,x,y,size):
    return all([isOn(x+dx[i],y+dy[i]) and C[y+dy[i]][x+dx[i]]>0 for i in range(size)])

def findAns(C,drops,sp):
    if len(drops) == 0:
        return []
    for i in range(sp,100):
        if C[i/10][i%10] > 0:
            break
        sp += 1
    for size in set(drops):
        for i in range(size):
            sx,sy = sp%10+dx[i],sp/10+dy[i]
            if isOn(sx,sy) and C[sy][sx] > 0:
                if canMinus(C,sx,sy,size):
                    minus(C,sx,sy,size)
                    drops.remove(size)
                    ans = findAns(C,drops,sp)
                    if ans != False:
                        ans.append([sx,sy,size])
                        return ans
                    drops.append(size)
                    plus(C,sx,sy,size)
    return False

n = int(raw_input())
C = [map(int, raw_input().split()) for i in range(10)]
sm = sum([sum(C[i]) for i in range(10)])
dropList = [list(a) for a in itertools.combinations_with_replacement([0,13,9,5],n) if sum(a) == sm]
for drops in dropList:
    ans = findAns(C,drops,0)
    if ans != False:
        break
        
for a in ans:
    print  a[0],a[1],ref[a[2]]

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

int main() {
  int N,W;
  int64_t vmax = 101*1000;
  int64_t wmax = 1000000002;
  
  vector<int64_t> w(102,0),v(102,0);
  vector< vector<int64_t> > dp(101,vector<int64_t>(vmax,wmax));

  cin >> N >> W;
  for (int i=0;i<N;++i ) {
    cin >> w[i] >> v[i];
  }
  dp[0][0] = 0;
  dp[0][v[0]] = w[0];
  // 配るDP
  for (int i=0;i<N-1;++i){
    for (int j=0;j<vmax;++j){
      dp[i+1][j] = min( dp[i+1][j], dp[i][j] );
      if ( dp[i][j]+w[i+1] <= W ) {
        dp[i+1][j+v[i+1]] = min( dp[i+1][j+v[i+1]], dp[i][j]+w[i+1] );
      }
    }
  }
  int64_t maxv = 0;
  for ( int64_t i=0;i<vmax;++i) {
    if ( dp[N-1][i] <= W ) {
      maxv = max( maxv, i );
    }
  }
  cout << maxv << endl;
}


Measured memory_bytes: 81024
#include <iostream>
using namespace std;
 
int A;
int B;
int C;
 
int main(){
  cin >> A >> B >> C;
  if((A == B && A != C) || (C == B && A != C) || (A == C && A != B)){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
}

Measured memory_bytes: 256
def fact(n)
  [*1..n].inject(1){|f,i| f*i}
end

def rank(n,array)
  nums=[*1..n]
  rank=0
  (n-1).times do |i|
    j=nums.index(array[i])
    if i==n-2
      rank+= j==0 ? 1:2
    else
      rank+=fact(n-1-i)*j
      nums.delete(array[i])
    end
  end
  return rank
end

n=gets.to_i
ps=gets.split.map(&:to_i)
qs=gets.split.map(&:to_i)

puts (rank(n,ps)-rank(n,qs)).abs


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

#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
const double PI = 3.141592653589793238462643383279;
const int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template<typename T, typename U> inline bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> inline bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
struct Init {
    Init() {
        cout << fixed << setprecision(20);
    };
} init;

int N, M;
int S, T;
vint G[110000];
bool visited[110000][3];
signed main() {
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int u, v;
        cin >> u >> v;
        G[u].push_back(v);
    }
    cin >> S >> T;
    queue<pint> q;
    q.push({S, 0});
    while (!q.empty()) {
        int cur = q.front().first, dist = q.front().second;
        q.pop();
        if (cur == T && dist % 3 == 0) {
            cout << dist / 3 << endl;
            return 0;
        }
        if (visited[cur][dist % 3]) { continue; }
        visited[cur][dist % 3] = true;
        for (int i = 0; i < G[cur].size(); i++) { q.push({G[cur][i], dist + 1}); }
    }
    cout << -1 << endl;
}


Measured memory_bytes: 7168
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
d=dict(Counter(a))
ans=sum(a)
q=int(input())
for _ in range(q):
    b,c=map(int,input().split())
    if b not in d.keys():
        print(ans)
        continue
    ans+=(c*d[b]-b*d[b])
    print(ans)
    if c in d.keys(): d[c]+=d[b]
    else: d[c]=d[b]
    d[b]=0

Measured memory_bytes: 21296
#include<stdio.h>
int main(void)
{
	int n,a[3],i,x;
	scanf("%d",&n);
	for(i=0;i<n;i++) scanf("%d",&a[i]);
	x=a[0];
	for(i=1;i<n;i++){
		if(a[i]<x) x=a[i];
	}
	for(i=1;i<=x;i++){
		if(n==2){
			if(a[0]%i==0&&a[1]%i==0) printf("%d\n",i);
		}
		else{
			if(a[0]%i==0&&a[1]%i==0&&a[2]%i==0) printf("%d\n",i);
		}	
	}
	return 0;
}	

Measured memory_bytes: 2752
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <cstring>
#include <list>  
#include <cassert>
#include <climits>
#include <bitset>
#include <chrono>
#include <random>
using namespace std;

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
std::mt19937 rnd((int)std::chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

int w, h, lim;

// 2*interior=2*area-boundary+2 <= 2*lim
// 2*area=x*(y+dy)+(w-x)*y
// boundary=gcd(x,y)+gcd(w,dy)+gcd(w-x,y+dy)
// -> x*(y+dy)+(w-x)*y-gcd(x,y)-gcd(w,dy)-gcd(w-x,y+dy)+2 <= 2*lim
// bruteforce dy and x -> y*w-(gcd(x,y)+gcd(w-x,y+dy)) <= 2*lim-x*dy+gcd(w,dy)-2 = RHS
// since gcd part in [1..w] if y<=RHS/w always ok and if y>RHS/w+1 never ok -> only need to check y=floor(RHS/w)+1

ll calc(int w, int h) {
	ll ret = 0;
	FORE(x, 1, w - 1) {
		REPE(dy, h - 2) {
			int mlt = dy == 0 ? 1 : 2;
			if (2 * lim - (ll)x*dy + w <= 0) break;
			ll rhs = 2 * lim - (ll)x*dy + gcd(w, dy) - 2;
			ll ysafe = rhs / w;
			ll yvalid = min(ysafe, (ll)h - dy - 1);
			if (yvalid >= 1) ret += mlt*(yvalid - 1 + 1);
			ll ycheck = ysafe + 1;
			if (ycheck >= 1 && ycheck + dy <= h - 1 && (ll)ycheck*w - (gcd(x, ycheck) + gcd(w - x, ycheck + dy)) <= rhs) ret += mlt;
		}
	}
	/*FORE(x, 1, w - 1) {
		FORE(y, 1, h - 1) {
			REPE(dy, h - y - 1) {
				int mlt = dy == 0 ? 1 : 2;
				if ((ll)x*(y + dy) + (ll)(w - x)*y - gcd(x, y) - gcd(w, dy) - gcd(w - x, y + dy) <= 2 * lim) {
					printf("\t(%d,%d,%d):%d\n", x, y, dy, mlt);
					ret += mlt;
				}
			}
		}
	}*/
	//printf("(%d,%d): %lld\n", w, h, ret);
	return ret;
}

ll solve() {
	return 2 * calc(w, h) + 2 * calc(h, w);
}

void run() {
	scanf("%d%d%d", &w, &h, &lim);
	printf("%lld\n", solve());
}

int main() {
	run();
	return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  int v = -1;
  for(int i=0; i<n; i++) {
    cin >> a.at(i);
    v += a.at(i);
  }
  v /= (4 * m);
  int count = 0;
  for(int i=0; i<n; i++) {
    if(a.at(i) > v) {
      count++;
    }
  }
  if(count < m)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}

Measured memory_bytes: 256