akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>


using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

typedef pair<ll, ll> P;

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;
typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;


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

    vector<ll> rocks(n);
    rep(i, n) cin >> rocks[i];
    map<ll, ll> m;
    for (ll l : rocks) m[l]++;

    vector<int> v;
    v.push_back(0);

    vector<ll> rt(n);

    rep(i, n) if (i > 0) if (rocks[v.back()] < rocks[i]) v.push_back(i);
    for (int i = v.size() - 2; i >= 0; i--) {
        while (m.rbegin()->first > rocks[v[i]]) {
            auto r = *m.rbegin();
            m.erase(r.first);
            rt[v[i + 1]] += (r.first - rocks[v[i]]) * r.second;
            m[rocks[v[i]]] += r.second;
        }
    }

    for (auto e : m) rt[0] += e.first * e.second;

    rep(i, n) cout << rt[i] << endl;

}


Measured memory_bytes: 10876
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 300001;

int N;
string S;
int ans = MOD,cum[2][MX];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N >> S;
    F0R(i,sz(S)) {
        cum[0][i+1] = cum[0][i];
        cum[1][i+1] = cum[1][i];
        if (S[i] == 'W') cum[0][i+1] ++;
        else cum[1][i+1] ++;
    }
    F0R(i,sz(S)) {
        ans = min(ans,cum[0][i]+cum[1][sz(S)]-cum[1][i+1]); // east to east
    }
    cout << ans;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)

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

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

int n;
const int N = 2001;
ll dp[N][N];
int a[N];
int p[N];

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

  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  iota(p, p + n, 0);
  sort(p, p + n, [&](int l, int r) {
    return a[l] > a[r];
  });

  for (int i = 0; i < n; ++i) {
    for (int j = 0; i + j < n; ++j) {
      int k = i + j;
      int index = p[k];
      int value = a[index];
      dp[i + 1][j] = max(dp[i + 1][j],
                         dp[i][j] + 1LL * abs(index - i) * value);
      dp[i][j + 1] = max(dp[i][j + 1],
                         dp[i][j] + 1LL * abs(n - 1 - j - index) * value);
    }
  }
  ll res = 0;
  for (int i = 0; i <= n; ++i) {
    int j = n - i;
    res = max(res, dp[i][j]);
  }
  cout << res << endl;

  return 0;
}


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

vector <int> from[200010];
int dp[200010][3];
int maxj[200010];
int ans[200010];

void dfs(int x, int last) {
	for (int i = 0; i < from[x].size(); i++) {
		int v = from[x][i];
		if (v == last) continue;
		maxj[v] = max(maxj[x], x), dfs(v, x);
	}
	if (x == 1) return ;
	if (x > maxj[x]) {
		dp[x][0] = 1;
		for (int i = 0; i < from[x].size(); i++) {
			int v = from[x][i];
			if (v == last) continue;
			if (v <= maxj[x]) dp[x][0] += dp[v][1];
		}
		ans[x] = dp[x][0];
	} else if (maxj[x] == last) {
		dp[x][0] = 1, dp[x][1] = x <= maxj[last];
		for (int i = 0; i < from[x].size(); i++) {
			int v = from[x][i];
			if (v == last) continue;
			if (v <= maxj[x]) dp[x][0] += dp[v][0];
			if (v <= maxj[last] && x <= maxj[last]) dp[x][1] += dp[v][2];
		}
		ans[x] = dp[x][0] - dp[x][1];
	} else {
		dp[x][0] = dp[x][1] = dp[x][2] = 1;
		for (int i = 0; i < from[x].size(); i++) {
			int v = from[x][i];
			if (v == last) continue;
			if (v <= maxj[x]) dp[x][0] += dp[v][0];
			if (v <= maxj[last]) dp[x][1] += dp[v][1];
			if (v <= maxj[maxj[last]]) dp[x][2] += dp[v][2];
		}
		ans[x] = 0;
	}
}

void get_ans(int x, int last) {
	ans[x] += ans[last];
	for (int i = 0; i < from[x].size(); i++) {
		int v = from[x][i];
		if (v == last) continue;
		get_ans(v, x);
	}
}

int main () {
	int n; scanf("%d", &n);
	for (int i = 1; i < n; i++) {
		int u, v; scanf("%d%d", &u, &v);
		from[u].push_back(v), from[v].push_back(u);
	}
	dfs(1, 1), get_ans(1, 1);
	for (int i = 2; i <= n; i++) {
		printf("%d ", ans[i]);
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 28928
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;

namespace CP
{
    class Atria
    {
        static void Main(string[] args)
        {
            int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray();
            int a = s[0];
            int b = s[1];
            WriteLine(
                a>b ? "safe":"unsafe"
                );
        }
    }
}

Measured memory_bytes: 28272
#include<bits/stdc++.h>
using namespace std;
int main(){
    map<string,int> mp;
    string s;
    int k;
    cin >> s >> k;
    for(int i=0;i<s.length();i++){
        string t;
        for(int j=i;j<min(i+k,(int)s.length());j++){
            t.push_back(s[j]);
            mp[t]++;
        }
    }
    int c=0;
    for(auto u:mp){
        c++;
        if(c==k){
            cout << u.first << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 1920
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
int cmp(const void *a, const void *b);
//your code here!

int main(void){
    char w[101], s[27]={0};
    scanf("%s", w);
    rep(i, 0, strlen(w)){
        s[w[i]-'a']++;
    }
    rep(i, 0, 26){
        if(s[i]%2){
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}

int cmp(const void *a, const void *b){
    ll A=*(ll *)a, B=*(ll *)b;
    if(A==B)return 0;
    else return A>B ? 1:-1;//昇順ソート
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringJoiner;

public class Main {
	private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	public static void main(String[] args) throws Exception {
		int n = Integer.parseInt(br.readLine());
		int[] array = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();

		boolean flag = true;
		int counter = 0;
		for(int i = 0; flag; i++){
			flag = false;
			for(int j = n - 1; i + 1 <= j; j--){
				if(array[j] < array[j-1]){
					int v = array[j-1];
					array[j-1] = array[j];
					array[j] = v;
					flag = true;
					counter++;
				}
			}
		}

		StringJoiner sj = new StringJoiner(" ");
		Arrays.stream(array).forEach(v -> sj.add(String.valueOf(v)));
		System.out.println(sj);
		System.out.println(counter);
	}
}



Measured memory_bytes: 31076
#include <bits/stdc++.h>
using namespace std;
int main(){  
  int N,x=0,MAX=0;
  string S;
  cin>>N>>S;
  for(int i=0;i<N;i++){
    if(S.at(i)=='I')x++,MAX=max(MAX,x);
    else x--;
  }
  cout<<MAX<<endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
bridges = [[] for i in range(N)]

for i in range(M):
    a, b = map(int, input().split())
    bridges[a - 1].append(b - 1)
    bridges[b - 1].append(a - 1)

ans = [-1] * N
q = [0]
while len(q) > 0:
    nq = []
    for t in q:
        for e in bridges[t]:
            if ans[e] < 0:
                nq.append(e)
                ans[e] = t
    q = nq

if -1 in ans:
    print('No')
else:
    print("Yes")
    for a in ans[1:]:
      print(a + 1)


Measured memory_bytes: 34420
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	long long a,b,c,d,ans;
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	ans = max(max(a * c,b * d),max(b * c,a * d));
	printf("%lld\n",ans); 
}

Measured memory_bytes: 1736
#include <iostream>

void PrintArray(int arr[], int length){
    for(int i = 0; i < length; ++i){
        std::cout << arr[i] << ((i == length-1) ? "\n" : " ");
    }
}

void InsertionSort(int arr[], int length){
    PrintArray(arr, length);
    for(int i = 1; i < length; ++i){
        int key = arr[i];
        int j = i-1;
        while(j >= 0 && arr[j] > key){
            arr[j+1] = arr[j];
            --j;
        }
        arr[j+1] = key;
        PrintArray(arr, length);
    }
}

int main(void){
    int length ;
    std::cin >> length;
    int* arr = new int[length];
    for(int i = 0; i < length; ++i) std::cin >> arr[i];
    InsertionSort(arr, length);
    delete[] arr;
}


Measured memory_bytes: 3076
#include<iostream>
#include<cstring>
using namespace std;
string s;
int f[200000];
bool check(int x)
{
	if(f[x]!=-1)return f[x];
	if(x==s.size())return 1;
	if(s.size()-x>6&&s.substr(x,7)=="dreamer"&&check(x+7))return f[x]=1;
	if(s.size()-x>5&&s.substr(x,6)=="eraser"&&check(x+6))return f[x]=1;
	if(s.size()-x>4&&s.substr(x,5)=="dream"&&check(x+5))return f[x]=1;
	if(s.size()-x>4&&s.substr(x,5)=="erase"&&check(x+5))return f[x]=1;
	return f[x]=0;
}
int main()
{
	cin>>s;
	memset(f,-1,sizeof f);
	cout<<(check(0)?"YES":"NO")<<endl;
	return 0;
}

Measured memory_bytes: 3648
import sys

stdin = sys.stdin

n = int(stdin.readline())
s = stdin.readline()

tmp = 0
ans = 0
for i in range(1,n):
    for j in set(s[0:i]):
        if j in set(s[i:]):
            tmp += 1
    ans = max(ans, tmp)
    tmp = 0
print(ans)


Measured memory_bytes: 3060
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    w, h, x, y = map(int, input().split())

    print(w * h / 2, int(x * 2 == w and y * 2 == h))


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>

using namespace std;

int main() {
	int num, sum;

	while (cin >> num, num != -1) {
		sum = 1150;
		sum += max(0, min(10, num - 10) * 125);
		sum += max(0, min(10, num - 20) * 140);
		sum += max(0, max(0, num - 30)  * 160);
		cout << 4280 - sum << endl;
	}

	return 0;
}


Measured memory_bytes: 3000
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from sys import stdin
import math

# 標準入力をスペースで区切って、intに変換 listに収納
today_weather = stdin.readline().rstrip()

if today_weather == "Sunny":
    print("Cloudy")
elif today_weather == "Cloudy":
    print("Rainy")
else:
    print("Sunny")


Measured memory_bytes: 2940
A = input()
B = input()
C = input()
now = 'a'
na = 0
nb = 0
nc = 0
for _ in range(303):
    if now == 'a':
        if na == len(A):
            print('A')
            break
        now = A[na]
        na += 1
    elif now == 'b':
        if nb == len(B):
            print('B')
            break
        now = B[nb]
        nb += 1
    else:
        if nc == len(C):
            print('C')
            break
        now = C[nc]
        nc += 1

Measured memory_bytes: 3064
#include <iostream>
#include <cstring>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
int n;
char a[N];
int cnt[26][N];
int main() {
  	ios::sync_with_stdio(false);
  	cin>>n>>a+1;
  	for(int i=1;i<=n;i++){
  		for(int j=0;j<26;j++)cnt[j][i]=cnt[j][i-1];
  		cnt[a[i]-'A'][i]++;
  	}
  	LL ans=0;
  	for(int i=1;i<=n;i++){
  		for(int j=i+1;j+1<=n;j++){
  			if(a[i]==a[j])continue;
  			int nx;
  			if(a[i]!='R'&&a[j]!='R')nx='R'-'A';
  			if(a[i]!='G'&&a[j]!='G')nx='G'-'A';
  			if(a[i]!='B'&&a[j]!='B')nx='B'-'A';
  			if(2*j-i<=n)ans+=cnt[nx][n]-cnt[nx][2*j-i];
  			ans+=cnt[nx][min(n,2*j-i-1)]-cnt[nx][j];
  		}
  	}
  	cout<<ans<<'\n';
 	return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
 
using namespace std;
vector<bool>b(2e5+1,false);
vector<vector<int>>tree(2e5+1);
 void dfs(int cur, int prev , int &count)
{
 
    for (int i=0; i<tree[cur].size(); i++)
    {
        if (b[tree[cur][i]]==false)
            {   
				count++;
				b[tree[cur][i]]=true;
				dfs(tree[cur][i], cur , count);
			}
    }
    return;
}
 
void add(int u,int v)
{
    tree[u].push_back(v);
    tree[v].push_back(u);
}
int main()
{
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
int n,m;
cin>>n>>m;
int maxi=1;
for(int i=0;i<m;i++)
{   int x,y;
	cin>>x>>y;
	add(x,y);
}
for(int i=1;i<=n;i++)
{
	if(b[i]==false)
	{
		int x=0;
		dfs(i,0,x);
		maxi=max(maxi,x);
	}
}
	cout<<maxi<<endl;

}

 
 

 


Measured memory_bytes: 29804
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
   input! {
       n: usize,
       v: [i64; n],
   } 

    let mut before;
    let mut tmp = v[0]*2;
    for i in 1..n {
        if i % 2 == 0 {
            tmp = tmp + v[i]*2;
        } else {
            tmp = tmp - v[i]*2;
        }
        //println!("tmp {} = {} ", i, tmp);
    }

    before = tmp / 2;
    print!("{} ", before);
    for i in 0..n-1 {
        let ans = v[i]*2 - before;
        print!("{} ", ans);
        before = ans;
    }
    println!("");

}


Measured memory_bytes: 5372
import java.util.Scanner;

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

		if (t.startsWith(s)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 35672
#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
int a[100005];
int b[100005];
int main()
{
	int n;
	int k;
	int ans;
	while(scanf("%d%d",&n,&k)!=EOF)
	{
		ans=99999;
		int m=0;
		for(int i=0;i<n;i++)
		{
			scanf("%d",&a[i]);
		}
		sort(a,a+n);
		for(int i=0;i<n;i++)
		{
			if((i+k)>n)
			break;
			b[i]=a[i+k-1]-a[i];
			m++;
		}
		sort(b,b+m);
		printf("%d\n",b[0]);
	}
	return 0;
 } 

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}
void debug(istringstream&){}
template <char sep=',', class Head, class... Tail>
void debug(istringstream& iss, Head&& head, Tail&&... tail)
{
  string name;
  getline(iss, name, ',');
  cout << sep << name << "=" << head;
  debug(iss, forward<Tail>(tail)...);
}
#define DEBUG(...) \
  do{ \
    istringstream ss(#__VA_ARGS__); \
    debug<' '>(ss, __VA_ARGS__); \
    cout<<endl; \
  }while(0)


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;


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

  int N, Q;
  cin >> N >> Q;
  string S;
  cin >> S;

  VI ixs;
  REP(i,N-1){
    if(S[i] == 'A' && S[i+1] == 'C')
      ixs.PB(i);
  }
  ixs.PB(N);

  while(Q--){
    int l, r;
    cin >> l >> r;
    --l;
    auto b = lower_bound(ALL(ixs), l) - begin(ixs);
    auto e = lower_bound(ALL(ixs), r-1) - begin(ixs);


    cout << e-b << endl;
  }

  return 0;
}


Measured memory_bytes: 1228
n,m=map(int,input().split())
A=[list(map(int,input().split()))for i in range(n)]
A=sorted(A,key=lambda y:y[0])
cnt=0#ドリンクの本数
ans=0
for i in range(n):
    cnt+=A[i][1]
    if m<=cnt:
        over=cnt-m #mを超えた時の超過本数
        ans+=(A[i][0]*A[i][1])-(over*A[i][0])
        break
    else:
        ans+=A[i][0]*A[i][1]
print(ans)

Measured memory_bytes: 29796
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll= long long;
using ld= long double;
using vl= vector<ll>;
using vd= vector<ld>;
using vs= vector<string>;
using vb= vector<bool>;
using vvl= vector<vector<ll>>;
using vvd= vector<vector<ld>>;
using vvs= vector<vector<string>>;
using vvb= vector<vector<bool>>;
using pll= pair<ll, ll>;
constexpr ll mod= 1e9 + 7;
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for(ll(i)= 0; (i) < (n); (i)++)
#define REPS(i, n) for(ll(i)= 1; (i) <= (n); (i)++)
#define RREP(i, n) for(ll(i)= (n - 1); (i) >= 0; (i)--)
#define RREPS(i, n) for(ll(i)= (n); (i) > 0; (i)--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())
#define YES(n) ((n) ? "YES" : "NO")
#define Yes(n) ((n) ? "Yes" : "No")
#define yes(n) ((n) ? "yes" : "no")

template <class T>
inline void chmin(T &a, T b) {
    if(a > b) { a= b; }
}

template <class T>
inline void chmax(T &a, T b) {
    if(a < b) { a= b; }
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    ll N,Q;
    cin >> N >> Q;
    dsu d(N);
    vl A(Q);
    vl U(Q);
    vl V(Q);
    REP(i,Q)cin >> A[i] >> U[i] >> V[i];
    REP(i,Q){
        if(A[i] == 0){
            d.merge(U[i],V[i]);
        }else{
            cout << (d.same(U[i],V[i])?1:0) << "\n";
        }
    }
}

Measured memory_bytes: 8204
/**
    __author__ : srv_twry
**/

#include<bits/stdc++.h>
using namespace std;

typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;

const ll MOD = 1000000007;
const ll INF = 1e15+5;
const double eps = 1e-7;
const double PI = acos(-1.0);

#define FOR(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RFOR(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define ull unsigned long long
#define deb(x )     cerr << #x << " = "<< x << endl;
#define endl    "\n"
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define fill(x, y) memset(x, y, sizeof(y))
#define all(x) (x).begin(), (x).end()

inline void debug_vi(vi a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void debug_vll(vll a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}

bool ge(const ll& a, const ll& b) { return a >= b; }
bool le(const ll& a, const ll& b) { return a <= b; }
bool eq(const ll& a, const ll& b) { return a == b; }
bool gt(const ll& a, const ll& b) { return a > b; }
bool lt(const ll& a, const ll& b) { return a < b; }
int sgn(const ll& x) { return le(x, 0) ? eq(x, 0) ? 0 : -1 : 1; }
/*----------------------------------------------------------------------*/

const int N = 1e5+5;
int n,m; 
ll cost[N], p2[50];

int main(){
    std::ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
 	p2[0] = 1LL;
 	FOR(i, 1, 51) {
 		p2[i] = p2[i-1] * 2LL;
 	}
 	cin>>n>>m;
    priority_queue<double> pq;
 	FOR(i, 0, n) {
 		cin>>cost[i];
 		pq.push(cost[i]);
 	}
 	while(!pq.empty() && m) {
 		double tp = pq.top(); pq.pop();
 		tp /= 2.0; m--;
 		if(abs(tp) > eps) {
 			pq.push(tp);
 		}
 	}
 	ll ans = 0;
 	while(!pq.empty()) {
 		double tmp = pq.top(); pq.pop();
 		ans += static_cast<ll>(tmp);
 	}
 	cout<<ans;
    return 0;
}

Measured memory_bytes: 1912
#include<bits/stdc++.h>
using namespace std;
char c[100005];
int main()
{
	scanf("%s",c+1);
	int lenc=strlen(c+1);
	int ans1=0,ans2=0;
	for(int i=1;i<=lenc;++i)
	{
		if(i%2==1)
		{
			if(c[i]=='0') 
			   ++ans1;
		}
		else
		{
		    if(c[i]=='1') 
			   ++ans1;
		}
		//cout<<i<<" "<<ans1<<endl;
	}
	for(int i=1;i<=lenc;++i)
	{
		if(i%2)
		{
			if(c[i]=='1') 
			    ++ans2;
		}
		else
		{
	         if(c[i]=='0') 
			     ++ans2;
	    }
		//cout<<i<<" "<<ans2<<endl;
	}
	//cout<<ans1<<" "<<ans2<<endl;
	int ans=min(ans1,ans2);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3952
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<list>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------


int g[5];

int main()
{
	int a, b;
	for (int i = 0;i < 3;i++) {
		cin >> a >> b;
		g[a]++;
		g[b]++;
	}

	for (int i = 1;i <= 4;i++) {
		if (g[i] > 2) {
			cout << "NO" << endl;
			return 0;
		}
	}

	cout << "YES" << endl;

	return 0;
}


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

typedef long long LL;
typedef vector<int> VI;

#define REP(x, n) for (int x = 0; x < (n); ++x)
#define INF (1e9 + 1)
#define EPS 1e-9

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int result = b + c - a;
    if (result <= 0) {
        cout << "0\n";
    }
    else {
        cout << result << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int read( ){
	int x=0,y=1;char ch=' ';
	for(;(ch!='-' && (ch>'9' || ch<'0'));ch=getchar( ));
	if(ch=='-')y=-1,ch=getchar( );
	for(;ch>='0' && ch<='9';ch=getchar( ))x=x*10+ch-48;
	return x*y;
}
const int N=1e3+10;
int n,m;
int d[N][N],f[N][N];
int main( ){
	int x,y,z,k;
	n=read();m=read();
	for(register int i=1;i<=n;++i)
		for(register int j=1;j<=m;++j)
			d[i][j]=read();
	for(register int i=0;i<=100;++i)
		for(register int j=0;j<=100;++j)
			for(register int x=1;x<=n;++x)
				for(register int y=1;y<=m;++y)
					f[i][j]=max(f[i][j],d[x][y]-i*x-j*y);
	for(register int x=1;x<=n;++x)
		for(register int y=1;y<=m;++y){
			int mn=1000;
			for(register int i=0;i<=100;++i)
				for(register int j=0;j<=100;++j)
					mn=min(mn,i*x+j*y+f[i][j]);
			if(mn!=d[x][y]){
				puts("Impossible");return 0;
			}
		}
	puts("Possible");
	printf("202 %d\n",200+101*101);
	for(register int i=1;i<=100;++i)
		printf("%d %d X\n",i,i+1);
	for(register int i=102;i<=201;++i)
		printf("%d %d Y\n",i,i+1);
	for(register int i=0;i<=100;++i)
		for(register int j=0;j<=100;++j)
			printf("%d %d %d\n",i+1,202-j,f[i][j]);	
	puts("1 202");
	return 0;
}
/*
1<=x<=n  1<=y<=m 
f[i][j] :经过 i 个 x,j 个 y,其它边和的最小值 
d[x][y] = min( i * x + j * y + f[i][j] )
d[x][y] <= i * x + j * y + f[i][j]
f[i][j] >= d[x][y] - i * x - j * y

f[i][j] = max( d[x][y] - i * x - j * y )
这样可能存在 dR[x][y] > d[x][y]
但每个 f[i][j] 都存在一组 x,y dR[x][y]=d[x][y]
所以 f[i][j] 不能调小，此时 impossible 

*/

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

int main() {
  string S;
  cin >> S;
  string t = "abcdefghijklmnopqrstuvwxyz";
  
  bool can = true;
  for(int i = 0; i < 26;) {
    for(int j = 0; j < S.size(); j++) {
      if(t[i] == S[j]) {
        i++;
        break;
      }
      if(t[i] != S[S.size()-1] && S.size() -1 == j) {
        can = false;
        cout << t[i] << endl;
        break;
      } 
    }
    if(can == false) {
      break;
    }
  }
  
  if(can == true) {
    cout << "None" << endl;
  }
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int main()
{
    Fast;
    long long t,n,m,i,j,k,x=0,y=0,z;
    string s,ss;
    cin>>s>>ss;
    cin>>n>>m;
    string sss;
    cin>>sss;
    if(sss==ss){
        m--;
    }
    if(sss==s){
        n--;
    }
    cout<<n<<" "<<m<<endl;
}


Measured memory_bytes: 256
S = list(input())
S1 = S[0:int((len(S) - 1) / 2)]
S2 = S[int((len(S) + 3) / 2) - 1:]

if len(S1) % 2 == 0:
    S3 = S1[0:int((len(S1) - 1) / 2) + 1]
    S4 = S1[int((len(S1) + 3) / 2) - 1:]
    S4.reverse()
else:
    S3 = S1[0:int((len(S1) - 1) / 2)]
    S4 = S1[int((len(S1) + 3) / 2) - 1:]
    S4.reverse()

if S1 == S2 and S3 == S4:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38256
#define DINGER_GISBAR
#include <bits/stdc++.h>
using namespace std;
const long long MOD = static_cast<int>(1e9) + 7;
//{{{TEMPLATE_BEGIN
#include <unistd.h>
using namespace std::rel_ops;
#ifdef ZEROKUGI
#include <dumper.hpp>
#define dump(x) dumper::dumper(cerr, __LINE__, (#x), (x), 50, 1, 1)
#define tick(...) dumper::tick(__VA_ARGS__)
#pragma message "Compiling " __FILE__
#else
#define dump(x)
#define tick(...)
#endif
typedef long long lint;
typedef unsigned long long ulint;
typedef long double ldouble;
typedef vector<int> vint;
#define rep(i, n)                                                              \
    for (int i = 1, i##_len = static_cast<int>(n); i < i##_len; i++)
#define all(c) begin(c), end(c)
#define perm(c)                                                                \
    sort(all(c));                                                              \
    for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))
#define uniquenize(v) (v).erase(unique(all(v)), end(v))
#define cauto const auto &
#define memset(x, y) memset(x, y, sizeof(x))
#define popcount __builtin_popcount
#define gcd __gcd
inline lint bit(int x) {
    return 1LL << x;
}
template <class T>
inline int size(const T &a) {
    return (int)a.size();
}
template <class T>
inline bool chmin(T &a, const T &b) {
    return a > b ? a = b, 1 : 0;
}
template <class T>
inline int clamp(T v, T lo, T hi) {
    return (v > hi) - (v < lo);
}
template <class T>
inline bool chmax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}
template <class T>
inline pair<vector<T>, char> operator*(const vector<T> &v, const char &c) {
    return make_pair(v, c);
}
template <class T>
inline istream &operator>>(istream &is, vector<T> &v) {
#ifdef ZEROKUGI
    if (v.empty()) {
        cerr << "Error L" << __LINE__ << ": vector size is zero." << endl;
        exit(EXIT_FAILURE);
    }
#endif
    for (auto &x : v)
        is >> x;
    return is;
}
template <class T>
inline ostream &operator<<(ostream &os, const pair<vector<T>, char> &v) {
    bool t = 0;
    for (const T &x : v.first) {
        if (t)
            os << v.second;
        os << x;
        t = 1;
    }
    return os;
}
template <class T>
inline ostream &operator<<(ostream &os, vector<T> &v) {
    return os << v * ' ';
}
struct before_main {
    before_main() {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
        tick(0, 0);
    };
} __before_main;
//}}}TEMPLATE_END

int main() {
    int n;
    cin >> n;
    rep (i, 3501)
        rep (j, i + 1) {
            if (4 * i * j - n * i - n * j == 0)
                continue;
            lint k = n * 1LL * i * j / (4LL * i * j - n * i - n * j);
            if(k <= 0) continue;
            if (4LL * i * j * k == n * 1LL * (i * j + j * k + k * i)) {
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
}


Measured memory_bytes: 256
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[] for _ in range(num)]
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

N,M = II()
p = []
S = []
for i in range(M):
    a,b = map(str, input().split())
    p.append(int(a))
    S.append(b)

ac = [False]*N
pn = [0]*N
acn = 0
pnn = 0

for i in range(M):
    if S[i]=='WA':
        pn[p[i]-1] += 1
    else:
        if ac[p[i]-1]==False:
            acn += 1
            ac[p[i]-1] = True
            pnn += pn[p[i]-1]

print(acn,pnn)

Measured memory_bytes: 53852
N,K = map(int,input().split())

data = [list(map(int,input().split())) for i in range(2*K)]

S = []
S = set(S)
for i in range(K):
    for j in range(data[2*i][0]):
        S.add(data[2*i+1][j])

print(N-len(S))

Measured memory_bytes: 9216
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<functional>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};




signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin>>n;
    cout<<n*n*n<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const int MOD=1e9+7;


int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<pair<int,int>> a(n);
    rep(i,n) {
        cin >> a[i].first;
        a[i].second=i;
    }
    sort(a.begin(),a.end(),greater<>());
    vector<vector<ll>> dp(n+1,vector<ll>(n+1));
    rep(i,n) {
        rep(j,i+1) {
            ll dl=abs(a[i].second-j),dr=abs(n-1-(i-j)-a[i].second);
            ll ac=a[i].first;
            dp[i+1][j]=max(dp[i+1][j],dp[i][j]+ac*dr);
            dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+ac*dl);
        }
    }
    ll ans=0;
    rep(i,n+1) ans=(dp[n][i]>ans)?dp[n][i]:ans;
    cout << ans << endl;
}

Measured memory_bytes: 34676
open Printf
open Scanf

let () =
  let n = scanf "%d" (fun x -> x) in
  Array.init n (fun _ -> scanf " %f" (fun x -> x))
  |> Array.map (fun x -> 1.0 /. x)
  |> Array.fold_left (+.) 0.0
  |> (fun x -> 1.0 /. x)
  |> printf "%.15f\n"

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

int main(){
  int a, b;
  cin >> a >> b;
  
  if (a > b) {
    cout << "a > b" << endl;
  } 
  else if ( a < b ){
    cout << "a < b" << endl;
  } 
  else {
    cout << "a == b" << endl;
  }
  
  return 0;
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int n; cin >> n;
    string s; cin >> s;

    map<char, char> mp;
    mp['S'] = 'W';
    mp['W'] = 'S';
    vector<string> t = {"SS", "SW", "WS", "WW"};

    for (int i = 0; i < 4; ++i) {
        string k = t[i];

        for (int j = 1; j < n - 1; ++j) {
            if (s[j] == 'o') {
                if (k[j] == 'S') {
                    //羊
                    k.push_back(k[j - 1]);
                } else {
                    //狼
                    k.push_back(mp[k[j - 1]]);
                }
            } else {
                if (k[j] == 'S') {
                    //羊
                    k.push_back(mp[k[j - 1]]);
                } else {
                    //狼
                    k.push_back(k[j - 1]);
                }
            }
        }

        bool ok = false;
        if (s[n - 1] == 'o') {
            if (k[n - 1] == 'S') {
                //羊
                if (k[n - 2] == k[0]) {
                    ok = true;
                }
            } else {
                //狼
                if (k[n - 2] != k[0]) {
                    ok = true;
                }
            }
        } else {
            if (k[n - 1] == 'S') {
                //羊
                if (k[n - 2] != k[0]) {
                    ok = true;
                }
            } else {
                //狼
                if (k[n - 2] == k[0]) {
                    ok = true;
                }
            }
        }

        if (!ok) continue;

        if (s[0] == 'o') {
            if (k[0] == 'S') {
                //羊
                if (k[n - 1] == k[1]) {
                    cout << k << endl;
                    return 0;
                }
            } else {
                //狼
                if (k[n - 1] != k[1]) {
                    cout << k << endl;
                    return 0;
                }
            }
        } else {
            if (k[0] == 'S') {
                //羊
                if (k[n - 1] != k[1]) {
                    cout << k << endl;
                    return 0;
                }
            } else {
                //狼
                if (k[n - 1] == k[1]) {
                    cout << k << endl;
                    return 0;
                }
            }
        }
    }

    cout << -1 << endl;
}

Measured memory_bytes: 3992
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF (1<<30)
#define LINF (1LL<<60)

#define MAX_V 5050

struct edge {
    int to; // 行き先
    ll cap; // 容量
    int rev; // 逆辺
    edge() {}
    edge(int to, ll cap, int rev) :to(to), cap(cap), rev(rev) {}
};

vector<edge> G[MAX_V]; // グラフの隣接リスト表現
int level[MAX_V]; // sからの距離
int iter[MAX_V]; // どこまで調べ終わったか

// fromからtoへ向かう容量capの辺をグラフに追加する
void add_edge(int from, int to, ll cap) {
    G[from].push_back(edge(to, cap, (int)G[to].size()));
    G[to].push_back(edge(from, 0, (int)G[from].size() - 1));
}

// sからの最短距離をBFSで計算する
void bfs(int s){
    fill(level,level+MAX_V,-1);
    queue<int> q;
    level[s] = 0;
    q.push(s);
    while(!q.empty()){
        int v = q.front(); q.pop();
        for(int i = 0; i < (int)G[v].size();i++){
            edge& e = G[v][i];
            if(e.cap > 0 && level[e.to] < 0){
                level[e.to] = level[v] + 1;
                q.push(e.to);
            }
        }
    }
}

// 増加パスをDFSで探す
ll dfs(int v, int t,ll f){
    if(v == t) return f;
    for(int &i = iter[v]; i < G[v].size();i++){
        edge &e = G[v][i];
        if(e.cap > 0 && level[v] < level[e.to]){
            ll d = dfs(e.to,t,min(f,e.cap));
            if(d > 0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

ll max_flow(int s,int t){
    ll flow = 0;
    for(;;){
        bfs(s);
        if(level[t] < 0) return flow;
        fill(iter,iter+MAX_V,0);
        ll f;
        while((f = dfs(s,t,LINF)) > 0){
            flow += f;
        }
    }
}

int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll V,E; cin >> V >> E;
    for(int i = 0; i < E;i++){
        int u,v; ll c; cin >> u >> v >> c;
        add_edge(u, v, c);
    }
    cout << max_flow(0, V-1) << endl;
	return 0;
}



Measured memory_bytes: 3416
#include "bits/stdc++.h"
#define REP(i,a,b) for(i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define SQR(X)  ( (X)*(X) )
#define CUBE(X) ( (X)*(X)*(X) )
#define ALL(a) (a).begin(),(a).end()
#define ifnot(a) if(not a)
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;
 
 
void reader(int &a){scanf("%d",&a);}
void reader(double &a){scanf("%lf",&a);}
void reader(char a[]){scanf("%s",a);}
void reader(ll &a){scanf("%lld",&a);}
void reader(ull &a){scanf("%llu",&a);}
// void reader(string& a){cin >> a;};
template<class T,class U> void reader(T& t,U& u){reader(t); reader(u);}
template<class T,class U,class V> void reader(T& t,U& u,V& v){reader(t); reader(u); reader(v);}
 
void writer(int a,char c) {printf("%d",a); putchar(c);}
void writer(ll a,char c) {printf("%lld",a); putchar(c);}
void writer(double a,char c) {printf("%.20lf",a); putchar(c);}
void writer(char a[]) {printf("%s",a);};
void writer(char a[],char c) {printf("%s",a);putchar(c);};
void writer(char a,char c) {putchar(a); putchar(c);};
template<class T>void writerLn(T t){writer(t,'\n');}
template<class T,class U>void writerLn(T t,U u){writer(t,' ');writer(u,'\n');}
template<class T,class U,class V> void writerLn(T t,U u,V v){writer(t,' ');writer(u,' ');writer(v,'\n');}
template<class T> void writerArr(T x[], int n){int i;if(!n){putchar('\n');return;}rep(i,n-1) writer(x[i],' ');writer(x[n-1],'\n');}
template<class T> void writerVec(vector<T> x){int n=x.size();int i;if(!n){putchar('\n');return;}rep(i,n-1) writer(x[i],' ');writer(x[n-1],'\n');}
 

 
// #define int ll
 
bool test = 1;

//............................
#define MAX 300000
signed main(){
  int i,j,k,l;
  while(1) {
	int n,r;
	cin >> n >> r;
	if(n == 0) break;
	vector<int> now(n);
	rep(i,n) {
	  now[i] = n-1-i;
	}
	rep(i,r) {
	  int p,c;
	  cin >> p >> c;
	  vector<int> next = now;
	  rep(j,c) {
		next[j] = now[p-1+j];
	  }
	  rep(j,p-1) {
		next[c+j] = now[j];
	  }
	  now = next;
	}
	cout << now[0]+1 << endl;
  }
  return 0;
}

Measured memory_bytes: 1220
class RollingHash:
    def __init__(self, s: list, base: int = 1007, mod: int = 10**9 + 7):
        self.s = s
        self.n = len(s)
        self.base = base
        self.mod = mod

        # preprocess
        self.h_cum = [0] * (self.n + 1)  # h_cum[i] = (hash of s[:i])
        self.b_pow = [1] * (self.n + 1)  # b_pow[i] = base ** i
        for i in range(self.n):
            self.h_cum[i + 1] = (self.h_cum[i] * base + s[i]) % mod
            self.b_pow[i + 1] = (self.b_pow[i] * base) % mod

    def get_hash(self, l: int, r: int) -> int:
        # get hash value of the substring s[l:r]
        hash_val = self.h_cum[r] - self.h_cum[l] * self.b_pow[r - l] % self.mod
        if hash_val < 0:
            hash_val += self.mod
        return hash_val


class RollingHashMulti:
    def __init__(self,
                 s: list,
                 base_list: list = [1007, 2009],
                 mod_list: list = [10**9 + 7, 10**9 + 9]):
        self.n = len(base_list)
        self.base_list = base_list
        self.mod_list = mod_list
        self.rh_list = [
            RollingHash(s, base_list[i], mod_list[i]) for i in range(self.n)
        ]

    def get_hash(self, l: int, r: int) -> tuple:
        return tuple(self.rh_list[i].get_hash(l, r) for i in range(self.n))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

a_xor = [a[i % n] ^ a[(i + 1) % n] for i in range(n * 2)]
b_xor = [b[i % n] ^ b[(i + 1) % n] for i in range(n * 2)]

a_xor_rh = RollingHashMulti(a_xor)
b_xor_rh = RollingHashMulti(b_xor)

for k in range(n):
    if a_xor_rh.get_hash(k, k + n) == b_xor_rh.get_hash(0, n):
        x = a[k] ^ b[0]
        print(k, x)


Measured memory_bytes: 128080
#include<stdio.h>
int main(void){
	int a, b, c;
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);
	if ((a < b) && (b < c)){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	

	return 0;



}

Measured memory_bytes: 1008
# include <bits/stdc++.h>
# define INF 1e9
using namespace std;

int main(){


    int A, B;
    cin >> A >> B;
    int ans;
    for(int i=A; i<B+1; ++i){
      string s = to_string(i);
      string t = to_string(i);
      reverse(t.begin(), t.end());
      if(s == t) ans++;
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int x;
  cin >> x;
  if(x == 0){
    cout << 1 << endl;
  }
  else{
    cout << 0 << endl;
  }
}

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

int main(){
	string s;cin >> s;
	long long  ans=0,len=(int)s.size()-1;
	for(int i=0;i<(1<<len);++i){
		long long sum=s.at(0)-'0';
		for(int j=0;j<len;++j){
			if(i & (1<<j)){
				ans+=sum;
				sum=0;
			}
			sum=sum*10 + (s.at(j+1)-'0');
		}
		ans+=sum;
	}
	cout << ans << endl;
}


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

struct Edge {
  int to;
  int len;
};

typedef pair<int, int> Pair;

int n;
int ans;
int ps[114514];
int ds[114514];
vector<Edge> es[114514];

Pair dfs(int v, int p) {
  Pair ret(-1, -1);

  if (es[v].size() == 1) {
    ret = Pair(-2, -2);
  }

  for (int i=0; i<es[v].size(); i++) {
    Edge &e = es[v][i];
    int u = e.to;
    if (p == u) continue;
    Pair res = dfs(u, v);
    if (es[v].size() == 1) {
      ret = max(ret, res);
    } else if (res == Pair(-2, -2)) {
      ret = max(ret, Pair(0, v));
    } else {
      assert (res != Pair(-1, -1));
      ret = max(ret, Pair(res.first+e.len, res.second));
    }
  }

  return ret;
}

void dfs2(int v, int p) {
  if (es[v].size() == 1) {
    ans -= es[v][0].len*2;
  }

  for (int i=0; i<es[v].size(); i++) {
    Edge &e = es[v][i];
    int u = e.to;
    if (p == u) continue;
    dfs2(u, v);
  }
}

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

    for (int i=1; i<n; i++) {
      scanf("%d", &ps[i]);
      ps[i]--;
      es[i].clear();
    }
    es[0].clear();

    ans = 0;
    for (int i=1; i<n; i++) {
      scanf("%d", &ds[i]);
      ans += ds[i]*3;
      es[i].push_back({ps[i], ds[i]});
      es[ps[i]].push_back({i, ds[i]});
    }

    Pair p1 = dfs(0, 0);
    Pair p2 = dfs(p1.second, p1.second);
    //printf("dia: %d %d\n", p2.first, p2.second);
    ans -= p2.first;
    dfs2(0, 0);
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 6036
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
a,v=n1()
b,w=n1()
t=n0()

ans="NO"
if w<v:
    k=(v-w)*t
    if k>=abs(a-b):
        ans="YES"
print(ans)

Measured memory_bytes: 9244
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    long sum =0;

    for (int i = 1; i <= n; i++) {
      if(i%5 != 0  && i%3 != 0) {
        sum += i;
      }
    }
    System.out.println(sum);
  }
}


Measured memory_bytes: 27176
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<numeric>
#include<climits>
#include<queue>
 
using namespace std;

int find(int i, vector<int>& par) {
	if (par[i] == i) return i;
	return par[i] = find(par[i], par);
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<pair<int, int>> x(n);
	vector<pair<int, int>> y(n);
	for (int i = 0; i < n; i++) {
		int xi, yi;
		cin >> xi >> yi;
		x[i]=make_pair(xi, i);
		y[i]=make_pair(yi, i);
	}
	sort(x.begin(), x.end());
	sort(y.begin(), y.end());
	vector<tuple<int, int, int>> edge;
	for (int i = 1; i < n; i++) {
		edge.push_back(make_tuple(x[i].first - x[i - 1].first, x[i].second, x[i - 1].second));
		edge.push_back(make_tuple(y[i].first - y[i - 1].first, y[i].second, y[i - 1].second));
	}
	sort(edge.begin(), edge.end());
	vector<int> par(n);
	vector<int> rank(n,0);
	iota(par.begin(), par.end(), 0);
	long long ans = 0;
	for (const auto& e : edge) {
		int px = find(get<1>(e), par);
		int py = find(get<2>(e), par);
		if (px == py) continue;
		ans += get<0>(e);
		if (rank[px] < rank[py]) {
			par[px] = py;
		}
		else {
			par[py] = px;
			if (rank[px] == rank[py]) rank[px]++;
		}
	}

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

Measured memory_bytes: 6516