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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N, A, B, C;
    cin >> N >> A >> B >> C;
    vector<int> L(N);
    for (int i = 0; i < N; i++) {
        cin >> L[i];
    }

    int mi = 1 << 29;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            for(int k = 0; k < N; k++) {
                if (i == j || j == k || i == k) continue;
                
                vector<int> I;
                for(int l = 0; l < N; l++) {
                    if (l == i || l == j || l == k) continue;
                    I.push_back(l);
                }
                
                int M = I.size();
                for(int si = 0; si < 1 << M; si++) {
                    for(int sj = 0; sj < 1 << M; sj++) {
                        for(int sk = 0; sk < 1 << M; sk++) {
                            if ((si & sj) != 0) continue;
                            if ((sj & sk) != 0) continue;
                            if ((si & sk) != 0) continue;
                            
                            int sum1 = L[i];
                            int sum2 = L[j];
                            int sum3 = L[k];
                            
                            int cost = 0;
                            for(int l = 0; l < M; l++) {
                                if (si >> l & 1) {
                                    sum1 += L[I[l]];
                                    cost += 10;
                                } else if (sj >> l & 1) {
                                    sum2 += L[I[l]];
                                    cost += 10;
                                } else if (sk >> l & 1) {
                                    sum3 += L[I[l]];
                                    cost += 10;
                                }
                            }
                            cost += abs(sum1 - A) + abs(sum2 - B) + abs(sum3 - C);
                            mi = min(mi, cost);
                            
                        }
                    }
                }
                
                
            }
        }
    }
    cout << mi << endl;
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}


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

public class Program
{
    static void Main()
    {
        var HW = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var hw = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

        Console.WriteLine((HW[0] - hw[0]) * (HW[1] - hw[1]));
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MOD = 998244353;

int power(int x, int t)
{
	int ret = 1;
	while(t > 0) {
		if(t & 1) ret = 1LL * ret * x % MOD;
		x = 1LL * x * x % MOD;
		t >>= 1;
	}
	return ret;
}

int fac[405], ifac[405];
int n, a[405], b[405], sa, sb;
int dat[405][405];

int main()
{
	fac[0] = 1;
	rep1(i, 400) fac[i] = 1LL * fac[i - 1] * i % MOD;
	ifac[400] = power(fac[400], MOD - 2);
	for(int i = 400; i >= 1; i --) ifac[i - 1] = 1LL * ifac[i] * i % MOD;
	
	scanf("%d", &n);
	rep(i, n) {
		scanf("%d%d", &a[i], &b[i]);
		sa += a[i];
		sb += b[i];
	}
	
	dat[0][0] = 1;
	
	rep(i, n) for(int j = sa; j >= 0; j --) for(int k = sb; k >= 0; k --) {
		int cur = 0, cc = 1;
		rep(cl, min(k + 1, b[i])) {
			cur = (cur + 1LL * ifac[cl] * dat[j][k - cl] % MOD * cc) % MOD;
			cc = 1LL * cc * a[i] % MOD;
		}
		dat[j][k] = ((j < a[i] ? 0 : dat[j - a[i]][k]) - cur + MOD) % MOD;
	}
	
	dat[sa][0] = 0;
	rep(i, sa) for(int j = 0; j <= sb; j ++) dat[i][j] = (MOD - dat[i][j]) % MOD;
	
	int ans = 0;
	int si = power(sa, MOD - 2);
	rep(i, sa) for(int j = 0; j <= sb; j ++) {
		int cs = 1LL * fac[j] * power(si, j) % MOD * power((1 - 1LL * i * si % MOD + MOD) % MOD, MOD - j - 2) % MOD;
		ans = (ans + 1LL * dat[i][j] * cs) % MOD;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 896
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"def main():\n"
"  from collections import deque\n"
"  s,*c=open(0)\n"
"  h,w=map(int,s.split())\n"
"  f=[-1]*h*w\n"
"  q=deque()\n"
"  a,p=q.append,q.popleft\n"
"  for i,c in enumerate(''.join(t[:w]for t in c)):\n"
"    if c=='#':\n"
"      a(i)\n"
"      f[i]=0\n"
"  while q:\n"
"    i=p()\n"
"    v=f[i]+1\n"
"    j,k,l,m,u=i+w,i-w,i+1,i-1,i%w\n"
"    if h*w>j and f[j]<0:\n"
"      a(j)\n"
"      f[j]=v\n"
"    if k>=0 and f[k]<0:\n"
"      a(k)\n"
"      f[k]=v\n"
"    if w>u+1and f[l]<0:\n"
"      a(l)\n"
"      f[l]=v\n"
"    if u and f[m]<0:\n"
"      a(m)\n"
"      f[m]=v\n"
"  print(v-1)\n"
"if __name__=='__main__':\n"
"  main()\n"
"\"";
  system(s);
  return 0;
}            

Measured memory_bytes: 52380
n = int(input())

if 1800 <= n:
  print(1)
elif 1600 <= n:
  print(2)
elif 1400 <= n:
  print(3)
elif 1200 <= n:
  print(4)
elif 1000 <= n:
  print(5)
elif 800 <= n:
  print(6)
elif 600 <= n:
  print(7)
else:
  print(8)

Measured memory_bytes: 8992
#include <cstdio>
#include <iostream>
#include <utility>
using namespace std;

int main(){
	while(1){
		int n, d[10000], p[10000];
		long m, ans=0;
		
		//入力
		scanf(" %d %ld", &n, &m);
		if(n==0) break;	
		for(int i=0; i<n; ++i){
			scanf(" %d %d", &d[i], &p[i]);
			ans += d[i]*p[i];
		 }
		//期待値の最も高いところから順に護衛
		for(int i=0; i<n; ++i){
			for(int j=i; j<n; ++j){
				if(p[i]<p[j]){
					swap(p[i], p[j]);
					swap(d[i], d[j]);	
				}
			}
		}
				
		for(int i=0; i<n; ++i){
			if(m>=d[i]){
				m -= d[i];	
				ans -= d[i]*p[i]; 
			}
			else{
				ans -= m*p[i];	
				break;
			}
		} 
		printf("%ld\n", ans);	
	}
	return 0;
}

Measured memory_bytes: 1264
#include <bits/stdc++.h>
#define INF 2e9
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}

int main(){
  int K, N;
  cin >> K >> N;
  vector<int> A(N);
  for(int i=0; i<N; ++i) cin >> A.at(i);
  sort(A.begin(), A.end());
  int max_diff=0;
  for(int i=0; i<N; ++i){
    if(i!=N-1) max_diff = max(max_diff, A.at(i+1)-A.at(i));
    else max_diff = max(max_diff, A.at(0)+K-A.at(i));
  }
  cout << K-max_diff << endl;
}

Measured memory_bytes: 1024
def read():
    return int(input())


def readlist():
    return list(map(int, input().split()))


def readmap():
    return map(int, input().split())


N = read()
A = readlist()

n = max(A)

mi = 999999999999999999999
for a in A:
    if n != a:
        if abs(a - n/2) < mi:
            b = a
            mi = abs(a - n/2)

print(n, b)

Measured memory_bytes: 14428
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()
S=input()

if S.count('R')>S.count('B'):
    Yes()
else:
    No()


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

using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#ifdef int
const ll INF = (1LL<<60);
#else
const int INF = (1LL<<30);
#endif
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

VI g[100010];
int a[100010], root;

int dfs(int v, int p) {
  int res = (g[v].size()>1) ? 2*a[v] : a[v];
  for(int i: g[v]) {
    if(i == p) continue;
    int tmp = dfs(i, v);
    if(tmp>a[v]) {
      cout << "NO" << endl;
      exit(0);
    }
    res -= tmp;
  }
  if(res < 0 || res > a[v]) {cout << "NO" << endl; exit(0);}
  return res;
}

signed main(void)
{
  int n;
  cin >> n;
  REP(i, n) cin >> a[i];
  REP(i, n-1) {
    int p, q;
    cin >> p >> q;
    p--, q--;
    g[p].PB(q);
    g[q].PB(p);
  }
  if(n == 2) {
    if(a[0] == a[1]) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
  }
  root = 0;
  while(g[root].size() == 1) root++;
  if(dfs(root, -1)) cout << "NO" << endl;
  else cout << "YES" << endl;

  return 0;
}


Measured memory_bytes: 10496
#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處

int main() {
    string s, t;
    cin >> s >> t;
    int ans = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] != t[i]) {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3812
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

#include<atcoder/all>
using namespace atcoder;

int main(void)
{
    IOS
    int n, q;
    cin >> n >> q;
    fenwick_tree<ll> ft(n);
    REP(i,n) {
        int a; cin >> a;
        ft.add(i,a);
    }
    REP(i,q) {
        int t; cin >> t;
        if (t == 0) {
            int p, x;
            cin >> p >> x;
            ft.add(p,x);
        } else {
            int l, r;
            cin >> l >> r;
            OUT(ft.sum(l,r))
        }
    }

    return 0;
}

Measured memory_bytes: 8260
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <sstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <vector <int>> vii;
typedef vector <long long> vll;
typedef vector <string> vs;
typedef vector <char> vc;
typedef set <int> si;
typedef set <string> ss;
typedef queue <int> qi;
typedef queue <long long> qll;
typedef queue <string> qs;
typedef queue <char> qc;
typedef struct board board;
typedef pair <int, int> pi;
typedef pair <long long, long long> pll;
typedef pair <int, pair<int, int>> pii;

#define eb emplace_back
#define ppb pop_back
#define clr(a) a.clear()
#define F first
#define S second
#define mkp make_pair

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

#define left(x) x * 2
#define right(x) x * 2 + 1

#define meme(a, b, c) fill(a + 1, a + 1 + b, c)

#define max(a, b) (a > b ? a : b)
#define min(a, b) (a > b ? b : a)
#define abs(a) (a > 0? a : -(a))

#define move(s) s += "#"

#define fr(i, a, b) for (ll i = a; i <= b; ++ i)
#define rf(i, a, b) for (ll i = a; i >= b; -- i)

#define eprintf(...) fprintf(stderr, __VA_ARGS__);

void to_pray() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cerr << "Ready\n";
}

const int N = 4e6 + 10;
const int NN = 1e3 + 10;
const int NNN = 2e3 + 9;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll LLINF = 1e12 + 7;
const ll P = 53;
const int EPS = 1e-9 - 8;
const int vN = 2e4 + 10;
const int sz = (1 << 22) - 1;
const double PI = acos(-1);

int main () {
    to_pray();
    
    int n, a;
    cin >> n >> a;
    
    cout << n - a + 1;
    
    cout << '\n';
    return 0;
}

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

#define pb push_back

const int MAXN=100005;

int p[MAXN],blo[MAXN];
vector <int> G[MAXN];
queue <int> q;

void bfs(int s)
{
	blo[s]=s;
	q.push(s);
	while (!q.empty())
	{
		int u=q.front();q.pop();
		for (int v:G[u])
			if (!blo[v])
			{
				blo[v]=s;
				q.push(v);
			}
	}
}

int main()
{
	//freopen("read.txt","r",stdin);
	int n,m;
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
		scanf("%d",&p[i]);
	while (m--)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		G[u].pb(v);
		G[v].pb(u);
	}
	for (int i=1;i<=n;i++)
		if (!blo[i])
			bfs(i);
	int ans=0;
	for (int i=1;i<=n;i++)
		if (blo[i]==blo[p[i]])
			ans++;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 6528
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    Main m = new Main(sc);
    m.show(m.solve());
    // m.debug();
  }

  Scanner sc;
  int N = 0;
  String s = null;
  boolean answer = true;

  // 標準入力用のコンストラクタ
  public Main(Scanner sc) {
    this.sc = sc;
    N = sc.nextInt();
    s = sc.next();
  }

  // 判定処理
  boolean solve() {
      int countR = 0;
      int countB = 0;
      for (int i = 0; i < N; ++i){
        if (s.charAt(i) == 'R'){
            ++countR ;
        } else {
            ++countB;
        }
      }
      if (countR <= countB){ //赤と青が同じか、青のほうが多かったら
        answer = false; 
      }
      
      return answer;
  }

  // 回答の表示
  void show(boolean answer) {
      if (answer){
        System.out.println("Yes");
      } else {
        System.out.println("No");
      }
      
  }
    
}


Measured memory_bytes: 35664
#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()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

int main(){
  int N, Q;
  cin >> N >> Q;
  vector<int> A(Q), B(Q);
  REP(i,Q) {
    cin >> A[i] >> B[i]; --A[i]; --B[i];
  }

  set<int> st;
  vector<int> cup(N);
  iota(ALL(cup), 0);
  int ball = 0;
  st.insert(0);
  st.insert(cup[ball + 1]);
  REP(i,Q) {
    swap(cup[A[i]], cup[B[i]]);
    if(A[i] == ball) ball = B[i];
    else if(B[i] == ball) ball = A[i];
    if(ball - 1 >= 0) st.insert(cup[ball - 1]);
    if(ball + 1 < N) st.insert(cup[ball + 1]);
  }
  cout << st.size() << endl;
  return 0;
}



Measured memory_bytes: 1536
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

template <class T> void swap(T& a, T& b) { T t = std::move(a); a = std::move(b); b = std::move(t); }

// nのk乗をmで割った余り(n^k(mod m))を求める
ll pow_mod(ll n, ll k, ll m){
    if(k == 0){
        return 1;
    }
    else if(k % 2 == 1){
        return pow_mod(n, k-1, m) * n % m;
    }
    else{
        ll t = pow_mod(n, k/2, m);
        return t * t % m;
    }
}

int main(void)
{
    ll N, i, A[100001], C[100001], judge=1;

    cin >> N;

    for(i=0; i<=100000; i++){
        C[i] = 0;
    }

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

    if(C[0]!=1 && C[1]!=2){
        judge = 0;
    }
    else if(C[0]==1){
        for(i=0; i<=N; i++){
            if(i%2==0){
                if(i==0 && C[i]!=1) judge=0;
                else if(i!=0 && C[i]!=2) judge = 0;
            }
        }
    }
    else{
        for(i=0; i<=N; i++){
            if(i%2==1 && C[i]!=2) judge = 0;
        }
    }

    if(judge == 0){
        cout << 0 << endl;
    }

    else{
        cout << pow_mod(2,N/2,div1) << endl;
    }

    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

class Main {
public static void main (String[] args){
int count = 0;
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
if (a >= 1 && a <= 10000){
if (b >= 1 && b <= 10000){
if (c >= 1 && c <= 10000){
if (a <= b) {
for (int i = a ; i <= b ; i++){
if (c % i == 0){
count++;
}
}
System.out.println(count);
}
}
}
}
}
}



Measured memory_bytes: 26352
N=readline.to_i

sorted_a = readline.split.map(&:to_i).sort
grouped_a = sorted_a.group_by{|x|x}

count_with_zero = []
(sorted_a.last+1).times do |number|
  numbers = grouped_a[number] || []
  count_with_zero.push(numbers.size);
end

# p count_with_zero

delta_cumulative_count = 
  count_with_zero.map.with_index do |count, i|
    i>0 ? 
      count_with_zero[i-1].to_i + count_with_zero[i].to_i + count_with_zero[i+1].to_i
    :
      count_with_zero[i].to_i + count_with_zero[i+1].to_i
  end

p delta_cumulative_count.max




Measured memory_bytes: 18272
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REP(a, b, m) for (ll a = (ll)(b); a < (ll)(m); a++)

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    bool flag = true;
    while (flag)
    {
        c -= b;
        if (c <= 0)
        {
            cout << "Yes" << endl;
            break;
        }
        a -= d;
        if (a <= 0)
        {
            cout << "No" << endl;
            break;
        }
    }
}

Measured memory_bytes: 3636
import sys
for line in sys.stdin.readlines():
    li=[0]*10
    for i in map(int,line.strip()):
        li[i]+=1
    ans=[]
    for addnum in [i for i in xrange(1,10) if not li[i]>=4]:
        t_li=li[:]
        t_li[addnum]+=1
        for remnum in [i for i in xrange(1,10) if t_li[i]>=2]:
            t2_li=t_li[:]
            t2_li[remnum]-=2
            top=1
            while (not -1 in t2_li) and top<=7:
                if t2_li[top]==0:
                    top+=1
                elif t2_li[top]>=3:
                    t2_li[top]-=3
                else:
                    for i in xrange(3):
                        t2_li[top+i]-=1
            if top==8 and (t2_li[8]==0 or t2_li[8]==3) and (t2_li[9]==0 or t2_li[9]==3):
                ans.append(addnum)
                break
    if ans==[]:print 0
    else:print " ".join(map(str,ans))
#temp

Measured memory_bytes: 4284
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

ll dp[10101];

void solve() {
    int h, n;
    cin >> h >> n;
    rep(i, 10101) dp[i] = 1LL << 58;
    dp[0] = 0;
    vector<int> A(n), B(n);
    rep(i, n) cin >> A[i] >> B[i];
    rep(i, n) {
        rep(j, h){
            dp[min(h, j + A[i])] = min(dp[min(h, j + A[i])], dp[j] + B[i]);
        }
    }
    cout << dp[h] << endl;
    return ;
}

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


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;

int main(){
    
    while(true){
        int n,r; cin>>n>>r;
        if(n==0&&r==0)break;
        
        vector<int> a(n);
        REP(i,n)a[i]=i+1;
        reverse(a.begin(),a.end());
        
        REP(kai,r){
            stack<int> sta;
            int p,c; cin>>p>>c;
            REP(i,c)sta.push(a[i+p-1]);
            REP(i,c)a.erase(a.begin()+p-1);
            REP(i,c){
                a.insert(a.begin(),sta.top());
                sta.pop();
            }
            /*REP(i,a.size())cout<<a[i]<<" ";
            cout<<endl;*/
        }
        
        cout<<a[0]<<endl;
        
    }
    
    return 0;
}

Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
	/*
	iとjとkはループ変数、limit_valueとsum_valueは入力される上限値と合計値
	calc_valueは3つの数値を足した結果を、countは組み合わせの数を格納
	*/

	int i, j, k;
	int limit_value, sum_value;
	int calc_value, count;

	while(1){
		//初期値は0
		count = 0;
		scanf("%d %d", &limit_value, &sum_value);

		//データセットがともに0ならば終了
		if((limit_value == 0) && (sum_value == 0)){
			break;
		}
		else{
			//総当たりで組み合わせを探す
			for(i = 1; i <= (limit_value - 2); i++){
				for(j = (i + 1); j <= (limit_value - 1); j++){
					for(k = (j + 1); k <= limit_value; k++){
						calc_value = i + j + k;
						if(calc_value == sum_value){
							count++;
						}
					}
				}
			}
			//結果を出力
			printf("%d\n", count);
		}
	}

	return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
int gcd(int a,int b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

//最小公倍数
int lcm(int a,int b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

// 素因数分解
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

// 10進数から2進数
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}




int main() {
 ll n;
 cin >> n;
 ll a[n+1];
 vector <ll> ans;
 bool ok = 0;
 rep (i,n){
   if (i%2 == 0) ok = 1;
   else ok = 1 - ok;
   cin >> a[i];
   if (!ok){
   ans.push_back(a[i]);
   }
   if (ok) {
     ans.insert(ans.begin(),a[i]);
   }
   
 }
if (!ok) reverse(ans.begin(),ans.end());
 for (auto x : ans){
   cout << x << " ";
 }
 cout << endl;
}

Measured memory_bytes: 6628
import java.util.*;
public class Main {
    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
      int n = Integer.parseInt(sc.next());
      int k = Integer.parseInt(sc.next());
      int x = Integer.parseInt(sc.next());
      int y = Integer.parseInt(sc.next());
      int sum = 0;
      if (n<=k){
         sum = n*x;
      } else {
         sum = k*x+(n-k)*y;
      }
     System.out.println(sum);
      
    }
}

Measured memory_bytes: 22868
import java.util.Scanner;

public class Main {

    public static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        var sb = new StringBuilder();
        for (int l = 1; l <= n; l++) {
            int cnt = 0;
            for (int i = 1; i * i <= n; i++) {
                for (int j = 1; j * j <= n; j++) {
                    int c = i * i + j * j + i * j - l;
                    int b = i + j;
                    double ans1 = (-b + Math.sqrt((b * b) - 4 * c)) / 2.0;
                    if (!Double.isNaN(ans1) && ans1 > 0.0 && (int)ans1 == ans1) {
                        cnt++;
                    }
                }
            }
            sb.append(cnt);
            sb.append("\n");
        }
        System.out.println(sb.toString());
    }
}

Measured memory_bytes: 35612
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int n , w , weight[111] , score[111] , dp[111][111111] , sum , ans;

int main() {
	for (int i = 0; i < 111; i++) for (int j = 0; j < 111111; j++) dp[i][j] = 1e9;
	scanf("%d %d" , &n , &w);
	for (int i = 1; i <= n; i++) {
		scanf("%d %d" , &weight[i] , &score[i]);
		sum += score[i];
	}
	
	dp[1][0] = 0;
	dp[1][score[1]] = weight[1];
	for (int i = 2; i <= n; i++) {
		for (int j = 0; j < score[i]; j++) dp[i][j] = dp[i-1][j];
		for (int j = score[i]; j <= sum; j++) dp[i][j] = min(dp[i-1][j] , dp[i-1][j-score[i]]+weight[i]);
	}
	
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= sum; j++) {
			if (dp[i][j] <= w) {
				ans = max(ans , j);
			}
		}
	}
	
	printf("%d" , ans);
		
	return 0;
}

Measured memory_bytes: 52044
import sys
n=int(input())
a=[int(input()) for i in range(n)]
for i in range(n):
  if a[i]>i:
    print(-1)
    sys.exit()
ct=0
for i in range(n-1,0,-1):
  if a[i]-1>a[i-1]:
    print(-1)
    sys.exit()
  elif a[i]-1==a[i-1]:
    ct+=1
  else:
    ct+=a[i]
print(ct)

Measured memory_bytes: 11048
#include <bits/stdc++.h>
#define endk '\n'
using namespace std;

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

  int n;
  vector<double> v;
  double entra;
  cin >> n;
  while (cin >> entra) v.push_back(entra);
  sort(v.begin(), v.end());
  double ans = v[0];
  for (int i = 1; i < v.size(); i++)
    ans = (ans + v[i])/2;
  cout << fixed << ans << endk;
  return 0;}


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

int main() {
  int N;
  cin >> N;
  
  if ( N / 10 == 111 ) {
    cout << "Yes" << endl;   
  }
  else if ( N / 10 == 222) {
    cout << "Yes" << endl;
  }
  else if ( N / 10 == 333) {
    cout << "Yes" << endl;
  }
  else if ( N / 10 == 444) {
    cout << "Yes" << endl;
  }
  else if ( N / 10 == 555) {
    cout << "Yes" << endl;
  } 
  else if ( N / 10 == 666) {
    cout << "Yes" << endl;
  }
  else if ( N / 10 == 777) {
    cout << "Yes" << endl;
  }
  else if ( N / 10 == 888) {
    cout << "Yes" << endl;
  }
  else if ( N / 10 == 999) {
    cout << "Yes" << endl;
  }
  else if ( N % 1000 == 111) {
    cout << "Yes" << endl;
  }
  else if ( N % 1000 == 222) {
    cout << "Yes" << endl;
  }
  else if ( N % 1000 == 333) {
    cout << "Yes" << endl;
  }
  else if ( N % 1000 == 444) {
    cout << "Yes" << endl;
  }
  else if ( N % 1000 == 555) {
    cout << "Yes" << endl;
  }
  else if ( N % 1000 == 666) {
    cout << "Yes" << endl;
  }
  else if ( N % 1000 == 777) {
    cout << "Yes" << endl;
  }
  else if ( N % 1000 == 888) {
    cout << "Yes" << endl;
  }
  else if ( N % 1000 == 999) {
    cout << "Yes" << endl;
  }
  else if ( N % 1000 == 0 ) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template<typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template<typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template<typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template<typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template<typename T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

void solve() {
  int n, x;
  cin >> n >> x;
  if (x == 1 || x == 2 * n - 1) no();
  cout << "Yes" << '\n';
  if (n == x) {
    reps(i, 2 * n - 1) cout << i << '\n';
  } else if (n > x) {
    rep(i, 2 * n - 1) {
      int j = i + x + n;
      if (j > 2 * n - 1) {
        j %= 2 * n - 1;
      }
      cout << j << '\n';
    }
  } else {
    rep(i, 2 * n - 1) {
      int j = x - n + 1 + i;
      if (j > 2 * n - 1) {
        j %= 2 * n - 1;
      }
      cout << j << '\n';
    }
  }
}


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

#define REP(i, n) for(int i=0; i<n; i++)
#define REPR(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)

#define INF 2e9
#define ll long long

int main(){
    int n, l;
    cin>>n>>l;
    int a[n];
    int ans = 300;
    int gokei = 0;

    REP(i, n){
        a[i] =  l + i;
        gokei += a[i];
        if(a[i]<abs(ans)){
            ans = a[i];
        }
    }

    cout<<gokei-ans<<endl;

    return 0;
}

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

using namespace std;
using ll =long long;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
using P = pair<int,int>;
//Write From this Line

int main()
{
	string s;
	cin >> s;
	string t = "ABC";
	string r = "ARC";
	if(s == t){
		cout << r << endl;
	} else {
		cout << t << endl;
	}
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
int main(){
char c;
int n[26]={};
while(cin>>c){
c= tolower(c);
if(isalpha(c)){
n[c-'a']++;
}
}
for(int i=0;i<26;i++){
printf("%c : %d\n",i+'a',n[i]);
}
}

Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int n,a[200000],xor1;
    cin>>n;
    cin>>a[0]>>a[1];
    xor1=a[0]^a[1];
    for(int i=2;i<n;i++)
    {
        cin>>a[i];
        xor1=xor1^a[i];
    }
    for(int i=0;i<n;i++)
    {
        cout<<(xor1^a[i])<<" ";
    }
}


Measured memory_bytes: 4416
n = int(input())
t = list(map(int, input().split()))
m = int(input())
px = [list(map(int, input().split())) for _ in range(m)]

s = sum(t)

for i in range(m):
    p, x = px[i][0], px[i][1]
    print(s - t[p-1] + x)



Measured memory_bytes: 3060
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define reg register
typedef long long ll;
template<typename T>inline T read(){
	reg T x=0;reg short f=1;reg char c=getchar();
	for(;!isdigit(c);f=c=='-'?-1:1,c=getchar());
	for(;isdigit(c);x=x*10+(c^48),c=getchar());
	return x*f;
}
int map[505][505],r[505][505],b[505][505],h,w;
int main(){
	h=read<int>();w=read<int>();
	for(reg int i=1;i<=h;i++)r[i][1]=b[i][w]=1;
	for(reg int i=1;i<=h;i++)for(reg int j=2;j<w;j++)if(i&1)r[i][j]=1;else b[i][j]=1;
	for(reg int i=1;i<=h;i++,getchar())
		for(reg int j=1;j<=w;j++)
			if(getchar()=='#')r[i][j]=b[i][j]=1;
	for(reg int i=1;i<=h;i++,puts(""))
		for(reg int j=1;j<=w;j++)
			putchar(r[i][j]?'#':'.');
	puts("");
	for(reg int i=1;i<=h;i++,puts(""))
		for(reg int j=1;j<=w;j++)
			putchar(b[i][j]?'#':'.');
	return 0;
}

Measured memory_bytes: 2688
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<iostream>
#include<set>
#include<map>
#define re register
#define ll long long
using namespace std;
inline int gi(){
	int f=1,sum=0;char ch=getchar();
	while(ch>'9'|| ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return sum*f;
}
const double eps=1e-10,Pi=acos(-1.0);
struct node{
	double x,y;
	node operator+(node b){return (node){x+b.x,y+b.y};}
	node operator-(node b){return (node){x-b.x,y-b.y};}
	node operator*(double b){return (node){x*b,y*b};}
	double len(){return sqrt(x*x+y*y);}
};
int fh(double a){return fabs(a)<eps?0:a>eps?1:-1;}
double cross(node a,node b){return a.x*b.y-a.y*b.x;}
double dot(node a,node b){return a.x*b.x+a.y*b.y;}
node projection(node p1,node p2,node p){node v=p2-p1;return p1+v*(dot(v,p-p1)/dot(v,v));}
node reflection(node p1,node p2,node p){node P=projection(p1,p2,p);P=P*2-p;return P;}
void Counter_Clockwise(node p1,node p2,node p){
	if(cross(p2-p1,p-p1)>eps){puts("COUNTER_CLOCKWISE");return;}
	if(cross(p2-p1,p-p1)<-eps){puts("CLOCKWISE");return;}
	if(dot(p2-p1,p-p1)<-eps){puts("ONLINE_BACK");return;}
	if(dot(p2-p1,p2-p1)>=dot(p-p1,p2-p1)){puts("ON_SEGMENT");return;}
	puts("ONLINE_FRONT");
}
bool insegment(node A,node B,node p){
	if(fh(cross(B-A,p-A)))return false;
	return ((fh(p.x-A.x)>=0 && fh(B.x-p.x)>=0) || (fh(p.x-A.x)<=0 && fh(B.x-p.x)<=0)) && ((fh(p.y-A.y)>=0 && fh(B.y-p.y)>=0) || (fh(p.y-A.y)<=0 && fh(B.y-p.y)<=0));
}
int parallel(node A1,node A2,node B1,node B2){
	if(!fh(cross(B2-B1,A2-A1)))return 2;
	if(!fh(dot(B2-B1,A2-A1)))return 1;
	return 0;
}
bool intersection(node A1,node A2,node B1,node B2){
	if(!fh(cross(B2-B1,A2-A1))){
		if(insegment(A1,A2,B1) || insegment(A1,A2,B2) || insegment(B1,B2,A1) || insegment(B1,B2,A2))return true;
		return false;
	}
	return fh(cross(A1-B1,B2-B1)*cross(A2-B1,B2-B1))<=0 && (fh(cross(B1-A1,A2-A1)*cross(B2-A1,A2-A1))<=0);
}
int main(){
	node p1,p2,p3,p4;
	int Q=gi();
	while(Q--){
		p1.x=gi();p1.y=gi();p2.x=gi();p2.y=gi();
		p3.x=gi();p3.y=gi();p4.x=gi();p4.y=gi();
		printf("%d\n",parallel(p1,p2,p3,p4));
	}
	return 0;
}



Measured memory_bytes: 3232
#include <iostream>
#include <vector>
using namespace std;
int a[100];

int bubbleSort(int a[], int n) {
  bool flag = true;
  int tmp, count=0;
  while (flag) {
    flag = false;
    for (int i = n-1; i > 0; --i) {
      if (a[i] < a[i-1]) {
        tmp = a[i];
        a[i] = a[i-1];
        a[i-1]=tmp;
        flag=true;
        count++;
      }
    }
  }
  return count;
}

int main(int argc, char *argv[])
{
  int n, num=0;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  num=bubbleSort(a, n);
  for (int i = 0; i < n; ++i) {
    cout << a[i];
    if(i!=n-1)cout<<" ";
    else cout<<"\n";
  }
  cout<<num<<endl;
  return 0;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define pll pair<ll,ll>
ll INF = 1000000007;

vector<ll>m;

/***************/
 #define amin main
/***************/

ll exp(ll x, ll n)
{if(n==0) return 1;if(n==1) return x%INF;if(n%2==0) return exp((x*x)%INF,n/2); else return(x*exp((x*x)%INF,n/2))%INF;}
void factorize(long long n) 
{ 
    int count = 0; 
  
    // count the number of times 2 divides  
    while (!(n % 2)) { 
        n >>= 1; // equivalent to n=n/2; 
        count++; 
    } 
  
    // if 2 divides it 
    if (count) 
        {
        	m.pb(count); 
        }
  
    // check for all the possible numbers that can  
    // divide it 
    for (long long i = 3; i <= sqrt(n); i += 2) { 
        count = 0; 
        while (n % i == 0) { 
            count++; 
            n = n / i; 
        } 
        if (count) 
          {  
          	m.pb(count);
  			}
    } 
  
    // if n at the end is a prime number. 
    if (n > 2) 
       { 
       	m.pb(1); 
		}
} 
  

int amin()
{
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t,i;
	ll n;
	cin>>n;
	factorize(n);
	ll sum =0;
	for(i=0;i<m.size();i++)
	{
		ll a = ((ll)sqrt(1+8*m[i])-1)/2;
		sum +=a;

	}
	cout<<sum<<endl;


	
	

	
	


	
	return 0;
}

Measured memory_bytes: 3700
const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const Arr = (input.trim()).split("\n");
const N1 = Number(Arr[0]);
const arr1 = Arr[1].split(" ").map(Number);
const arr2 = Arr[3].split(" ").map(Number);

const summing = (a, b) => a + b;
console.log(arr2.map(key => {   
  let mid;
  let left = 0;
  let right = N1;
  if (key < arr1[0] || arr1[N1-1] < key) return 0;
  while (left < right) {
    mid = Math.floor((left + right) / 2);
    if (key < arr1[mid]) right = mid;
    else if (key > arr1[mid]) left = mid + 1;
    else return 1;
  }
  return 0;
}).reduce((a, b) => a + b, 0));



Measured memory_bytes: 34940
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    long long a[3];
    cin>>a[0]>>a[1]>>a[2];
    if((a[0]&1) && (a[1]&1) && (a[2]&1)){
        sort(a,a+3);
        cout<<a[0]*a[1]<<"\n";
    }else cout<<"0\n";
    return 0;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
from bisect import *
from collections import *
from heapq import *

int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline()[:-1]
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def MF(): return map(float, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LF(): return list(map(float, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
dij = [(0, 1), (1, 0), (0, -1), (-1, 0)]

def main():
    while 1:
        n,p0=MI()
        if n==0:break
        i=0
        s=[0]*n
        p=p0
        while 1:
            if p:
                s[i]+=1
                if s[i]==p0:
                    break
                p-=1
            else:
                p+=s[i]
                s[i]=0
            i=(i+1)%n
        print(i)

main()



Measured memory_bytes: 6024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007;
#define MOD2 998244353;
#define INF ((1<<30)-1);
#define LINF (1LL<<60);
#define EPS (1e-10);
typedef long long Int;
typedef pair<Int, Int> P;

int64_t dp[220000];
int64_t h[220000];
int64_t a[220000];
P flowers[220000];

int64_t bit[220000];

void set_val(int64_t *bit, int ind, int64_t val) {
    ind++;
    while (ind < 220000) {
        bit[ind] = max(bit[ind], val);
        ind += ind & -ind;
    }
}

int64_t max_val(int64_t *bit, int ind) {
    int64_t res = 0;
    ind++;
    while (ind) {
        res = max(res, bit[ind]);
        ind -= ind & -ind;
    }
    return res;
}


int main() {
    int n;
    cin >> n;
    rep(i,n) {
        cin >> h[i];
        flowers[i] = P(h[i], i);
    }
    rep(i,n) cin >> a[i];
    sort(flowers, flowers + n);

    int64_t ans = 0;
    for (auto p : flowers) {
        int i = p.second;
        dp[i] = a[i];

        dp[i] = max_val(bit, i-1) + a[i];
        set_val(bit, i, dp[i]);
        ans = max(ans, dp[i]);
    }
    cout << ans << endl;
}

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

int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    rep(i,n) cin>>a[i];
    ll ans=1000100001;
    for(int i=-100;i<101;i++){
        ll cnt=0;
        rep(j,n){
            int temp=pow(a[j]-i,2);
            cnt+=temp;
        }
        ans=min(cnt,ans);
    }
    cout<<ans<<endl;
}

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

int main(){
  int n,k;
  cin>>n>>k;
  int x[n];
  rep(i,0,n) cin>>x[i];
  int ans=0;
  rep(i,0,n) ans+=2*min(x[i],k-x[i]);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
N, M, X = map(int, input().split())

A = [list(map(int, input().split())) for _ in range(N)]

ans = 10 ** 7
for i in range(1 << N):
    s = [0] * M
    kari = 0
    for j in range(N):
        if (i >> j) % 2 == 1:
            kari += A[j][0]
            for k in range(M):
                s[k] += A[j][k+1]
    if min(s) >= X:
        ans = min(ans, kari)

if ans == 10 ** 7:
    ans = -1
print(ans)

Measured memory_bytes: 9148
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

#define int long long

const int N=1e4+5;
bool v[N];
int a[N],b[N],n,g;

bool check(int p){
  	if(a[0]%p) return 0;
	for(int i=0;i<p-1;i++) b[i]=0;
	for(int i=0;i<n;i++) b[i%(p-1)]=(b[i%(p-1)]+a[i])%p;
	for(int i=0;i<p-1;i++) if(b[i]) return 0;
	return 1;
}

signed main(){
	read(n);
	for(int i=n;~i;i--) read(a[i]),g=__gcd(g,abs(a[i]));
	n++;
	for(int i=2;i<=n;i++) if(!v[i]){
		if(check(i)) write(i),puts("");
		for(int j=i+i;j<=n;j+=i) v[j]=1;
	}
	for(int i=2;i*i<=g;i++) if(g%i==0){
		while(g%i==0) g/=i;
		if(i>n) write(i),puts("");
	}
	if(g>n) write(g);
}


Measured memory_bytes: 3804
#!/usr/bin/env python3
def f(xs, ys):
    acc = 0
    for x, y in zip(xs, ys):
        acc += min(x, y)
    return acc
n = int(input())
l = sorted(map(int,input().split()))
ans = max(f(l[0::2], l[1::2]), f(l[1::2], l[2::2]))
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    long long N, A, B, C, D, E;
    cin >> N >> A >> B >> C >> D >> E;
    
    long long MinTime = min({A, B, C, D, E});
    
    long long ans = (N + MinTime - 1) / MinTime + 4;
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
#include <map>
using namespace std;
typedef long long ll;

const ll MOD = 1e9+7;
ll a[200000];
ll rui[200001];
map<ll,int> mp;
int main()
{
	int n;
	ll k;
	ll ans=0;
	cin>>n>>k;
	for(int i=0;i<n;i++)
		cin>>a[i];
	rui[0]=0;
	for(int i=0;i<n;i++)
		rui[i+1]=rui[i]+a[i];
	for(int i=0;i<n+1;i++)
	{
		rui[i]-=i;
		rui[i]=(rui[i]+k)%k;
		//cerr<<rui[i]<<" ";
	}
	//cerr<<endl;
	for(int i=0;i<n+1;i++)
	{
		if(i>=k)
			mp[rui[i-k]]--;
		ans+=mp[rui[i]];
		mp[rui[i]]++;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main()
{
  int N, M;
  cin >> N >> M;
  int left = 1, right = N;
  bool shift = true;
  for (int i = 0; i < M; i++)
  {
    cout << left << " " << right << endl;
    left++, right--;
    if (N%2 == 0 && shift && right - left <= N+left - right)
    {
      right--;
      shift = false;
    }
  }
}


Measured memory_bytes: 3636
sx, sy, tx, ty = gets.split.map(&:to_i)

dx = tx - sx
dy = ty - sy

U = ?U
D = ?D
L = ?L
R = ?R

print U*dy + R*dx + D*dy + L*dx

dx += 1
dy += 1

puts L + U*dy + R*dx  + D + R + D*dy + L*dx + U


Measured memory_bytes: 1916
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0045
Sum and Average
"""
import sys
import math


def main(args):
    sum = 0
    total_pieces = 0
    number_of_data = 0
    for line in sys.stdin:
        unit_price, pieces = line.strip().split(',')
        sum += int(unit_price) * int(pieces)
        total_pieces += int(pieces)
        number_of_data += 1
    print('{0}\n{1}'.format(sum, math.ceil(total_pieces / number_of_data)))


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 7612
import sys


def _ia(): return map(int, sys.stdin.readline().strip().split())


def main():
    n, d = _ia()
    d2 = d ** 2
    cnt = 0
    for _ in range(n):
        x, y = _ia()
        if x**2 + y**2 <= d2:
            cnt += 1
    return cnt


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 68708
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let R: f64 = read();
    println!("{}", R * 2.0 * std::f64::consts::PI);
}


Measured memory_bytes: 2160
#include<bits/stdc++.h>
using namespace std;
int main()
{long int a,b,c,d;
 cin>>a>>b>>c>>d;
 long long  arr[4];
arr[0]=a*d;
 arr[1]=a*c;
 arr[2]=b*d;
 arr[3]=b*c;
long long  maximum=arr[0];
 for(int i=1;i<4;i++){
 maximum=max(maximum,arr[i]);}
 cout<<maximum;
 return 0;}

Measured memory_bytes: 3620
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{

  public static void main(String[] args) throws IOException
  {
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);
    String[] sl = r.readLine().split("[\\s]+");
    int n = Integer.parseInt(sl[0]);
    int c = Integer.parseInt(sl[1]);
    int d[][] = new int[30][30];
    int count[][] = new int[3][30];

    for(int i = 0; i < c; i++)
    {
      sl = r.readLine().split("[\\s]+");
      for(int j = 0; j < c; j++)
      {
        d[i][j] = Integer.parseInt(sl[j]);
      }
    }

    for(int i = 0; i < n; i++)
    {
      sl = r.readLine().split("[\\s]+");
      for(int j = 0; j < n; j++)
      {
        count[(i + j) % 3][Integer.parseInt(sl[j]) - 1]++;
      }
    }
    
    int sel[] = new int[3];
    int min = Integer.MAX_VALUE;
    
    for(sel[0] = 0; sel[0] < c; sel[0]++)
    {
      for(sel[1] = 0; sel[1] < c; sel[1]++)
      {
        if(sel[0] == sel[1])
        {
          continue;
        }
        for(sel[2] = 0; sel[2] < c; sel[2]++)
        {
          if(sel[1] == sel[2] || sel[0] == sel[2])
          {
            continue;
          }
          
          int stress = 0;
          for(int i = 0; i < 3; i++)
          {
            for(int j = 0; j < c; j++)
            {
              stress += count[i][j] * d[j][sel[i]];
            }
          }
          min = Math.min(min, stress);
        }
      }
    }
    
    System.out.println(min);

  }


}

Measured memory_bytes: 46068
import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
n,q=map(int,input().split())
es=[[] for i in range(n)]
for i in range(n-1):
   a,b=map(int,input().split())
   es[a-1].append(b-1)
   es[b-1].append(a-1)
use=[1]*n
cnt=[0]*n
for _ in range(q):
    p,x=map(int,input().split())
    cnt[p-1]+=x
def dfs(v,c):
    k=c+cnt[v]
    cnt[v]=k
    use[v]=0
    for i in es[v]:
        if use[i]:
            dfs(i,k)
dfs(0,0)
print(*cnt)

Measured memory_bytes: 232496