akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int g;
int main() {
	string s;
	cin >> s;
	int l = s.length();
	for (int i = 0; i < l; i++) {
	    if (s[i] == 'g')
	        g++;
	}
	printf("%d\n", std::min(l / 2, g) - std::min(l - l / 2, l - g));
	return 0;
}

Measured memory_bytes: 512
if __FILE__ == $0
	while line = gets
		a,b,c,d,e,f = line.chomp!.split(" ").map(&:to_i)
		y = ((a.to_f * f) - (c.to_f * d)) / ((a.to_f * e) - (b.to_f * d))
		x = (c.to_f / a) - ((b.to_f / a) * y)
		print(format("%.3f",x)," ",format("%.3f",y),"\n")
	end
end

Measured memory_bytes: 8608
#include<stdio.h>

int main(){
    int surface[24][3]={{1,2,3},{2,3,1},{3,1,2},
                        {1,3,5},{3,5,1},{5,1,3},
                        {1,5,4},{5,4,1},{4,1,5},
                        {1,4,2},{4,2,1},{2,1,4},
                        {6,2,4},{2,4,6},{4,6,2},
                        {6,4,5},{4,5,6},{5,6,4},
                        {6,5,3},{5,3,6},{3,6,5},
                        {6,3,2},{3,2,6},{2,6,3}};
    int a_dice[6];
    int b_dice[6];
    int i,j;
 
    for(i=0;i<6;i++)scanf("%d", &a_dice[i]);
    for(i=0;i<6;i++)scanf("%d", &b_dice[i]);

    for(i=0;i<24;i++){
        if((a_dice[surface[i][0]-1]==b_dice[0]) && (a_dice[surface[i][1]-1]==b_dice[1])  && (a_dice[surface[i][2]-1]==b_dice[2])){
            if((a_dice[6-surface[i][0]]==b_dice[5]) && (a_dice[6-surface[i][1]]==b_dice[4])  && (a_dice[6-surface[i][2]]==b_dice[3])){
                printf("Yes\n");
                return 0;
            }
        }
    }
    printf("No\n");
    return 0;
}

int func(){

}


Measured memory_bytes: 2108
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

typedef long long ll;

int max(int a, int b){
  if(a > b) return a;
  else return b;
}
int min(int a, int b){
  if(a < b) return a;
  else return b;
}

int sort(const void *a ,const void *b){
  return *(int*)a - *(int*)b;
}

int f(int a){
  int count = 0;
  int flag = 0;
  for(int i = 1; i <= pow(a,0.5); ++i){
    if(a % i == 0) count ++;
    if(i*i == a)flag = 1;
  }
  count *= 2;
  if(flag == 1) --count;
  return count;
}


int main(){

  int n;
  scanf("%d",&n);

  ll ans = 0;
  ll y;
  for(int j = 1; j <= n; ++j){
    y = n/j; // jの倍数の個数
    ans += j*(y*(y+1)/2);
  }

  printf("%lld",ans);

  return 0;
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int A[101010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>A[i];
	sort(A,A+N);
	reverse(A,A+N);
	FOR(i,N) {
		if(A[i]>i+1 && A[i+1]>i+1) continue;
		
		x=A[i]-i;
		y=i;
		while(A[y]>i) y++;
		y-=i;
		
		if(x%2 && y%2) return _P("Second\n");
		return _P("First\n");
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 640
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>

using namespace std;

#define lint long long
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF (int)(1e9+10)
#define LLINF (lint)(1e18+10)

int main(){
    int h, w;
    cin >> h >> w;
    int a[505][505];
    rep(i, h){
        rep(j, w){
            cin >> a[i][j];
        }
    }
    vector<int> v;
    rep(i, h){
        rep(j, w){
            if(a[i][j] % 2 == 1){
                a[i][j]--;
                v.push_back(i+1);
                v.push_back(j+1);
                if(i < h-1){
                    a[i+1][j]++;
                    v.push_back(i+2);
                    v.push_back(j+1);
                }else if(j < w-1){
                    a[i][j+1]++;
                    v.push_back(i+1);
                    v.push_back(j+2);
                }
            }
        }
    }
    int l = v.size()/4;
    cout << l << endl;
    l *= 4;
    rep(i, l){
        cout << v[i];
        if(i%4 == 3){
            cout << endl;
        }else{
            cout << " ";
        }
    }
    return 0;
}

Measured memory_bytes: 5232
#define LOCAL
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char c) {return to_string((string) &c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll N; cin >> N;
    ll n = 1LL << N;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<vector<Pll>> dp(n, vector<Pll>(N+1, {0,0}));
    rep(i,n){
        dp[i][0] = {a[i], 0};
    }
    auto merge = [&](Pll &a, Pll &b) -> Pll{
        Pll ret;
        if(a.first > b.first){
            ret.first = a.first;
            if(a.second > b.first)ret.second = a.second;
            else ret.second = b.first;
        }
        else{
            ret.first = b.first;
            if(a.first > b.second)ret.second = a.first;
            else ret.second = b.second;
        }
        return ret;
    };
    rep(i,n){
        rep(j,N){
            if((i >> j) & 1){
                dp[i][j+1] = merge(dp[i][j], dp[i & ~(1LL << j)][j]);
            }
            else{
                dp[i][j+1] = dp[i][j];
            }
        }
    }

    vector<ll> ans(n);
    reps(i,n-1){
        chmax(ans[i], ans[i-1]);
        chmax(ans[i], dp[i][N].first + dp[i][N].second);
    }

    reps(i,n-1){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 103424
n,m=map(int, input().split())
list=[-1]*(n+1)
for i in range(m):
    s,c=map(int,input().split())
    if list[s]==-1:
        list[s]=c
    if list[s]!=c:
        print(-1)
        list[0]=0
        break

for i in range(1,n+1):
    if i==1:
        if list[i]==0:
            if n==1:
                list[i]=0
            else:
                print(-1)
                list[0]=0
                break
        if list[i]==-1:
            if n==1:
                list[i]=0
            else:
                list[i]=1


    else:
        if list[i]==-1:
            list[i]=0

if list[0]==-1:
    a=0
    for i in range(1,n+1):
        a+=list[i]*(10**(n-i))
    #print(list)
    print(a)


Measured memory_bytes: 38256
package main

import (
	"fmt"
)

func main() {
	var m, f, r int

	for {
		fmt.Scan(&m, &f, &r)
		if m == -1 && f == -1 && r == -1 {
			break
		}

		t := m + f

		if m == -1 || f == -1 {
			fmt.Println("F")
		} else if t >= 80 {
			fmt.Println("A")
		} else if t >= 65 {
			fmt.Println("B")
		} else if t >= 50 {
			fmt.Println("C")
		} else if t >= 30 {
			if r >= 50 {
				fmt.Println("C")
			} else {
				fmt.Println("D")
			}
		} else {
			fmt.Println("F")
		}
	}
}



Measured memory_bytes: 1132
#include<iostream>
using namespace std;
long long int ans=100000000000;
long long int k;
void dfs(long long int a, long long int b) {
  if(a==0) {
    ans=min(b, ans);
    return ;
  }
  dfs(a-1, b*2);
  dfs(a-1, b+k);
}
int main(void) {
  long long int n;
  cin>>n>>k;
  dfs(n, 1);
  cout<<ans<<endl;
  return 0;
}


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

const int N = 3005;

int main(){
	cout << setprecision(10) << fixed;

	int n;
	cin >> n;

	vector<long double> p(n);
	long double dp[N][N];

	memset(dp , 0 , sizeof(dp));
	for(int i = 0 ; i < n ; i++){
		cin >> p[i];
	}

	dp[0][0] = (1-p[0]);
	dp[0][1] = p[0];

	for(int i = 1 ; i < n ; i++){
		for(int j = 0 ; j <= n ; j++){
			dp[i][j] += dp[i-1][j]*(1-p[i]);	
			if (j > 0) dp[i][j] += dp[i-1][j-1]*(p[i]);
		}
	}

	long double ans = 0;
	for(int i = n/2 + 1 ; i < 3000 ; i++){
		ans += dp[n-1][i];
	}

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


Measured memory_bytes: 144968
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

int main(void)
{
  int x;
  cin >> x;
  if(x>=30){printf("Yes\n");}
  else{printf("No\n");}
  return 0;
}


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

int main() {
  int a,b,c,x;
  cin >> a >> b >> c >> x;
  
  int sum=0;int count=0;
  for(int i=0;i<=a;i++){
  	for(int j=0;j<=b;j++){
    	for(int k=0;k<=c;k++){
        sum = 500*i+100*j+50*k;
        if(sum == x){
        count++;}
        }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3592
object Main {
  def bfs(ar: Array[String], x: Int, y: Int, w: Int, h: Int): Array[String] = {
    if (x < 0 || x >= w || y < 0 || y >= h)
      return ar
    if (ar(y)(x) != '.')
      return ar
    // ????????\?????????????????????????????????????????£???
    var br = ar
    br(y) = br(y).patch(x, "C", 1)
    br = bfs(ar, x - 1, y, w, h)
    br = bfs(br, x + 1, y, w, h)
    br = bfs(br, x, y + 1, w, h)
    br = bfs(br, x, y - 1, w, h)
    return br
  }


  def solve(ar: Array[String], room: Array[Int]): Int = {
    var x = -1
    var y = -1
    for(i <- 0 until ar.length) {
      val tmp = ar(i).indexOf('@')
      if (tmp != -1) {
        x = tmp
        y = i
      }
    }
    var br = ar
    br(y) = br(y).patch(x, ".", 1)
    br = bfs(br, x, y, room(0), room(1))
    var cnt = 0
    for(res <- br)
      cnt += res.count{_ == 'C'}
    cnt
  }

  def main(args: Array[String]) = {
    var room = io.StdIn.readLine().split(' ').map(_.toInt)
    while (room(0) != 0) {
      val ar = new Array[String](room(1))
      for (i <- 0 until room(1))
        ar(i) = io.StdIn.readLine()
      println(solve(ar, room))
      room = io.StdIn.readLine().split(' ').map(_.toInt)
    }
  }
}

Measured memory_bytes: 68244
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
   int a,b;
   cin >> a >> b;
   if(a*b %2 == 0) puts("Even");
   else puts("Odd");
    
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for(auto&& i : a){
        cin >> i;
    }
    while(q--){
        long long x;
        cin >> x;
        long long s = 0, g = 0, score = 0;
        long long ans = 0;
        while(g < n){
            score += a[g];
            while(x < score){
                ans += g - s;
                score -= a[s];
                s++;
            }
            g++;
        }
        while(s < g){
            ans += g - s;
            s++;
        }
        cout << ans << "\n";
    }
}


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

int main() {
 int N,K;
  cin >> N>> K;
  int sum=0;
  int B[N]={0};
  int d[K],A[N];
  for(int i=0;i<K;i++){
    cin >>d[i];
    for(int l=0;l<d[i];l++){
      cin >>A[l];
      B[A[l]-1]++;
    }
  }
  
  for (int i=0;i<N;i++){
    if (B[i] ==0){
      sum++;
    }
  }
  cout << sum <<endl;
  
      
  
}

Measured memory_bytes: 3596
while True:
    N = int(input())
    if N == 0:
        break
    min_w = 0
    max_w = 0
    min_h = 0
    max_h = 0
    points = [[0, 0]]
    for i in range(N-1):
        n, d = map(int, input().split())
        w = points[n][0]
        h = points[n][1]
        if d == 0:
            w -= 1
            min_w = min(min_w, w)
        elif d == 1:
            h -= 1
            min_h = min(min_h, h)
        elif d == 2:
            w += 1
            max_w = max(max_w, w)
        elif d == 3:
            h += 1
            max_h = max(max_h, h)
        points.append([w, h])
    print(max_w + 1 - min_w, max_h + 1 - min_h)



Measured memory_bytes: 5616
import sys
sys.setrecursionlimit(10**7)

def cur(current,e,dist,color):
    for it in e[current]:
        if color[it]!=-1: continue
        color[it]=(color[current]+dist[(it,current)])%2
        cur(it,e,dist,color)

N=int(input())
e=[[] for i in range(N+1)]
dist={}
for i in range(N-1):
    u,v,w=map(int,input().split())
    e[u].append(v)
    e[v].append(u)
    dist[(u,v)],dist[(v,u)]=w,w
memo=[-1]*N




color=[-1]*(N+1)
color[1]=0
cur(1,e,dist,color)

for i in range(1,N+1):
    print(color[i])

Measured memory_bytes: 92368
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
bool chmin(ll& a, ll  b) { if (b < a) { a = b; return 1; } return 0; }
bool chmax(ll& a, ll b) { if (b > a) { a = b; return 1; } return 0; }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    cin >> k >> q;
    vl A;
    rep(i, k) {
        cin >> x;
        A.push_back(x);
    }

    while (q--) {
        cin >> n >> x >> p;
        n--;
        x = x % p;
        a = n / k;
        b = n % k;
        vl B,C;
        rep(i, k) {
            B.push_back((A[i]+p-1) % p+1);
        }
        C.push_back(0);
        rep(i, k) {
            C.push_back(C.back() + B[i]);
        }
        y = x+a * C[k] + C[b];
        cout << n - y / p << endl;
    }
}

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

using namespace std;

int main() {
    string s, t;
    cin >> s;
    cin >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());
    if (s < t) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
#define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
#define rep(i,a,b) for(register int i=(a);i<int(b);++i)
#define mem(x,v) memset(x,v,sizeof(x))
#define fi first
#define se second
#define gc getchar
#define pc putchar
inline ll read(){
    ll x=0,f=1;char c=gc();
    for(;!isdigit(c);c=gc())if(c=='-')f=-1;
    for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
    return x*f;
}
inline void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);putchar(x%10+'0');}
inline void wri(ll x){write(x);pc(' ');}
inline void writeln(ll x){write(x);pc('\n');}
const int maxn = 2e5+233;
unordered_map<int,int> M[maxn];
vector<int> edge[maxn];
int n,ans[maxn],mx[maxn];
int f(int x,int fa,int w){
	if(M[x].count(w)) return M[x][w];
	int ret=0;
	for(auto v:edge[x]) if(v!=fa&&v<=w) ret+=f(v,x,w)+1;
	return M[x][w]=ret;
}
void dfs(int u,int fa){
	mx[u]=max(mx[fa],fa);
	if(u>mx[fa]) ans[u]=ans[fa]+f(u,fa,mx[u])+1; else
				 ans[u]=ans[fa]-f(u,fa,mx[fa])+f(u,fa,mx[u]);
	if(u==1) ans[u]=0;
	for(auto v:edge[u]) if(v!=fa) dfs(v,u);
}
int main(){
	n = read();
	rep(i,1,n){
		int a = read(),b = read();
		edge[a] . push_back(b);
		edge[b] . push_back(a);
	}dfs(1,0);
	Rep(i,2,n) wri(ans[i]);
	return 0;
}


Measured memory_bytes: 53248
#[allow(unused_imports)]
use std::cmp::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

const INF: u64 = 1 << 60;

fn warshall_floyd(n: usize, mut edges: Vec<Vec<u64>>) -> Vec<Vec<u64>> {
    for k in 0..n {
        for i in 0..n {
            for j in 0..n {
                edges[i][j] = min(edges[i][j], edges[i][k] + edges[k][j]);
            }
        }
    }
    edges
}

struct Permutation {
    n: usize,
    idx: usize,
}
impl Permutation {
    fn new(n: usize) -> Permutation {
        Permutation { n: n, idx: 0 }
    }
}
impl Iterator for Permutation {
    type Item = Vec<usize>;
    fn next(&mut self) -> Option<Vec<usize>> {
        let mut r = vec![0; self.n];
        let mut idx = self.idx;
        for k in 1..self.n {
            r[k] = idx % (k + 1);
            idx /= k + 1;
        }
        if idx > 0 {
            return None;
        }
        r.reverse();
        let mut b = vec![true; self.n];
        b[r[0]] = false;
        for k in 1..self.n {
            let mut count = 0;
            for j in 0..self.n {
                if b[j] {
                    if count == r[k] {
                        r[k] = j;
                        b[j] = false;
                        break;
                    }
                    count += 1;
                }
            }
        }
        self.idx += 1;
        return Some(r);
    }
}

fn calc_cost(edges: &Vec<Vec<u64>>, r: &Vec<usize>) -> u64 {
    let mut cost = 0;
    for i in 0..r.len() - 1 {
        cost += edges[r[i]][r[i + 1]];
    }
    cost
}

fn main() {
    let v: Vec<usize> = read_vec();
    let (N, M, R) = (v[0], v[1], v[2]);
    let r: Vec<usize> = read_vec();
    let mut r = r.iter().map(|&r| r - 1).collect::<Vec<_>>();

    let mut edges = vec![vec![INF; N]; N];
    for i in 0..M {
        let mut v: Vec<usize> = read_vec();
        let (a, b, c) = (v[0] - 1, v[1] - 1, v[2]);
        edges[a][b] = c as u64;
        edges[b][a] = c as u64;
    }
    for k in 0..N {
        for i in 0..N {
            for j in 0..N {
                edges[i][j] = min(edges[i][j], edges[i][k] + edges[k][j]);
            }
        }
    }
    let mut ans = std::u64::MAX;
    for ord in Permutation::new(R) {
        let mut ac = 0;
        for i in 1..R {
            let a = r[ord[i - 1]];
            let b = r[ord[i]];
            ac += edges[a][b];
        }
        ans = min(ans, ac);
    }
    println!("{}", ans)
}


Measured memory_bytes: 4352
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author mikit
 */

#include <iostream>
#include <fstream>

#include <iostream>

class BContestWithDrinksEasy {
public:
  void solve(std::istream &in, std::ostream &out) {
    using std::endl;
    int n;
    in >> n;
    int t[n];
    int sum = 0;
    for (int i = 0; i < n; i++) {
      in >> t[i];
      sum += t[i];
    }
    int m;
    in >> m;
    for (int i = 0; i < m; i++) {
      int p, x;
      in >> p >> x;
      out << (sum - t[p - 1] + x) << endl;
    }
  }
};


int main() {
  BContestWithDrinksEasy solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


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

int main()
{
  int n,r;

  cin >> n >> r;

  if(n < 10) r += (100 * (10 - n));

  cout << r << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstring>

using namespace std;

int dp[80001][11];

int main()
{
    string S;
    while (cin>>S, S!="0") {
        memset(dp, 0, sizeof(dp));
        
        for (int i=0; i<S.size(); i++) {
            int d = S[i] - '0';
            
            if (d>0) dp[i+1][d] = 1;
            for (int j=0; j<=10; j++) {
                dp[i+1][(j*10+d)%11] += dp[i][j];
            }
            
            // for (int j=0; j<=10; j++) cerr << dp[i+1][j] << " ";
            //  cerr << endl;
        }
        
        int ans = 0;
        for (int i=0; i<=S.size(); i++) {
            ans += dp[i][0];
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 4760
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2")  //Enable AVX

using namespace std;

using ll = long long;

#define mp make_pair

const int p = 1000000007;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}

/*struct DSU {
    vector<int> sz;
    vector<int> parent;

    void make_set(int v) {
        parent[v] = v;
        sz[v] = 1;
    }

    int find_set(int v) {
        if (v == parent[v])
            return v;
        return parent[v] = find_set(parent[v]);
    }

    void union_sets(int a, int b) {
        a = find_set(a);
        b = find_set(b);
        if (a != b) {
            if (sz[a] < sz[b])
                swap(a, b);
            parent[b] = a;
            sz[a] += sz[b];
        }
    }

    DSU(int n) {
        sz.resize(n);
        parent.resize(n);
        for (int i = 0; i < n; i++) make_set(i);
    }
};*/

/*const int N = 1000000;

vector<int> facs(N), invfacs(N);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
    invfacs[N-1] = inv(facs[N-1]);
    for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}*/



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

    int x;
    cin>>x;
    for (int i = 1; i<=100000; i++)
    {
        x-=i;
        if (x<=0) {cout<<i; return 0;}
    }


}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
int n,m;
while(1){
scanf("%d%d",&n,&m);
if(n==0)return 0;
for(int i=0;i<m;i++){
printf("#");
}
printf("\n");
for(int i=2;i<n;i++){
printf("#");
for(int j=2;j<m;j++){
printf(".");
}
printf("#\n");
}
for(int i=0;i<m;i++){
printf("#");
}
printf("\n\n");
}
}

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

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

  vector<long> x(n);
  vector<long> y(n);

  long long tmp=0;
  int ans=0;
  for(int i=0;i<n;i++){
    cin >> x[i] >> y[i];
  }
  for(int i=0;i<n;i++){
    tmp = x[i]*x[i];
    tmp += y[i]*y[i];
    if(tmp<=d*d){
      // cout << tmp << " " << d*d << endl;
      ans++;
    }
  }

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


Measured memory_bytes: 6428
#include <iostream>
#include <unordered_set>
using namespace std;
int main() {
    unordered_set<int> s;
    int n;
    cin >> n;
    bool ans = true;
    for (int i = 0; i < n; i++) {
        int t;
        cin >> t;
        if (ans) {
            if (s.find(t) == s.end()) {
                s.insert(t);
            } else {
                ans = false;
            }
        }
    }
    if (ans) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 8520
import sys

#N = 5
#ss = ['W', 'Vacant', 'W', 'Vacant', 'M']

def judge(x):
    print(x)
    sys.stdout.flush()
    s = input()
    #s = ss[x]
    
    if s=='Vacant':
        print(x)
        exit()
        
    if x%2==0 and s!=ini_s:
        return True
    elif x%2==1 and s==ini_s:
        return True
    else:
        return False

N = int(input())
print(0)
sys.stdout.flush()
ini_s = input()
#ini_s = ss[0]

if ini_s=='Vacant':
    print(0)
    exit()

print(N-1)
sys.stdout.flush()
last_s = input()
#last_s = ss[N-1]

if last_s=='Vacant':
    print(N-1)
    exit()

l, r = 1, N-1
    
while l<=r:
    m = (l+r)//2
        
    if judge(m):
        r = m-1
    else:
        l = m+1

print(l-1)
exit()

Measured memory_bytes: 38852
from collections import deque

# 頂点数と辺数
N, M = map(int, input().split())
# 辺
AB = [map(int, input().split()) for _ in range(M)]

# 無向グラフの隣接リスト
link = [[] for _ in range(N + 1)]
for a, b in AB:
  link[a].append(b)
  link[b].append(a)
    
# BFSのデータフレーム
dist = [-1] * (N + 1)  # 始点から頂点iの距離
que = deque([1])       # 頂点1を始点としたキュー

# BFS 開始 (キューが空になるまで探索を行う)
while que:
    v = que.popleft() # キューから先頭頂点 v を取り出す
    
    for i in link[v]:
      # 未訪問頂点 i について距離情報を更新してキューに追加する
      if dist[i] == -1:
        dist[i] = v
        que.append(i)

# 結果出力（各頂点の頂点1からの距離）        
print('Yes')
print('\n'.join(str(v) for v in dist[2:]))

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

using namespace std;

int main() {
    int A,B,K; cin>>A>>B>>K;

    vector<int> kn;
    
    for (int i=1;i<=min(A,B);i++) {
        if (A%i==0 && B%i==0) {
            kn.push_back(i);
        }
    }

    sort(kn.begin(), kn.end(), greater<int>());

    cout << kn[K-1] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;

int main() {
    string S;
    cin >> S;
    int N = S.size() + 1;
    vector<ll> a(N);
    vector<ll> b(N);
    for (int i = 0; i < S.size(); i++) {
        if (S[i] == '<') {
            a[i + 1] = a[i] + 1;
        }
    }
    for (int i = S.size() - 1; i >= 0; i--) {
        if (S[i] == '>') {
            b[i] = b[i + 1] + 1;
        }
    }
    ll sum = 0;
    for (int i = 0; i < N; i++) {
        sum += max(a[i], b[i]);
    }
    cout << sum << endl;
 }

Measured memory_bytes: 8708
#include <iostream>

using namespace std;

int main()
{
   int32_t k, s;
   cin >> k >> s;

   int32_t count{ 0 };
   for(auto i = 0; i <= k; ++i) {
       for(auto j = 0; j <= k && i + j <= s; ++j) {
           if(0 <= s - i - j && s - i - j <= k) {
               ++count;
           }
       }
   }

   cout << count;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    vv<int> rbg = vvec(N + 1, 3, 0);
    vector<ll> dp(N + 1, 0LL);
    dp[0] = 1;
    rep(i, N) {
        int cnt = 0;
        int d = 0;
        rep(c, 3) {
            if (A[i] == rbg[i][c]) {
                if (d == 0) d = c;
                cnt++;
            }
        }

        dp[i + 1] = dp[i] * cnt % MOD;

        rep(c, 3) rbg[i + 1][c] = rbg[i][c];
        rbg[i + 1][d]++;
    }

    write(dp[N]);
}

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

int main(void)
{
    string s;
    cin>>s;
    if(s.find("AC")!=-1)
    {
        cout <<"Yes"<<endl;
    }
    else
    {
        cout <<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))

a = [i * 20000 for i in range(n)]
b = [(n - i - 1) * 20000 for i in range(n)]

for i, c in enumerate(p):
    a[c - 1] += i + 1
    b[c - 1] += i + 1

print(" ".join(map(str, a)))
print(" ".join(map(str, b)))


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);
  int n;
  cin >> n;
  ll k;
  cin >> k;
  vector<int> a(n);
  rep(i, n) {
    cin >> a[i];
  }
  ll ans = 0;
  rep(i, n-1) {
    rep2(j, i+1, n) {
      if (a[i] > a[j]) {
        ans++;
      }
    }
  }
  constexpr ll x = pow(10,9) + 7;
  if (k == 1) {
    cout << ans%x << endl;
    return 0;
  }
  ll ans2 = 0;
  rep(i, n*2-1) {
    rep2(j, i+1, n*2) {
      if (a[i%n] > a[j%n]) {
        ans2++;
      }
    }
  }
  ans2 -=  ans*2;
  if (k % 2 == 0) {
    ans2 = (ans2 * (k/2))%x;
    ans2 = (ans2 * (k-1))%x;
  } else {
    ans2 = (ans2 * ((k-1)/2))%x;
    ans2 = (ans2 * k)%x;
  }
  ans = (ans * k)%x;
  ans2 = (ans + ans2)%x;
  cout << ans2 << endl;
  return 0;
}


Measured memory_bytes: 256
// 22
#include <bits/stdc++.h>
using namespace std;
#define coutc "\033[48;5;196m\033[38;5;15m"
#define endc "\033[0m"
#define endl '\n'
#define M(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...) M(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rep4(_, x, n, s) for (int _ = x; (s < 0) ? _ > n : _ < n; _ += s)
#define rep3(_, x, n) rep4(_, x, n, (x < n ? 1 : -1))
#define rep2(_, n) rep3(_, 0, n)
#define rep1(n) rep2(i, n)
#define fi first
#define se second
#define pb push_back
#define pairii pair<int, int>
#define all(x) x.begin(), x.end()
#define len(x) int(x.size())
#define lli __int128_t
#define li long long int
#define ld long double
// 4
template <class A, class B>
ostream &operator<<(ostream &o, const pair<A, B> &p) {
  return o << "(" << p.fi << ", " << p.se << ")";
}
// 5
template <class T>
ostream &operator<<(ostream &o, const vector<T> &v) {
  rep(i, len(v)) o << setw(7) << left << v[i];
  return o << endc << endl << coutc;
}
// 5
template <class A, class B>
ostream &operator<<(ostream &o, const map<A, B> &m) {
  for (auto &kv : m) o << kv;
  return o;
}
// 7
template <class T, class... Ts>
void debug(const T &e, const Ts &... r) {
#ifdef DEBUG
  cerr << coutc << e;
  ((cerr << " " << r), ..., (cerr << endc << endl));
#endif
}
// 3
void _main(int tc) {
  int n;
  cin >> n;
  vector<vector<int>> adj(n);
  auto addEdge = [&](int u, int v) { adj[u].pb(v); };
  rep(n - 1) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    addEdge(u, v);
    addEdge(v, u);
  }
  const int mod = 1e9 + 7;
  function<pairii(int, int)> f = [&](int u, int p) -> pairii {
    li ifwhitecnt = 1, ifblackcnt = 1;
    for (int v : adj[u]) {
        if (v == p) continue;
        auto ans = f(v, u);
        ifwhitecnt = (ifwhitecnt * ((ans.fi + ans.se) % mod)) % mod;
        ifblackcnt = (ifblackcnt * ans.fi) % mod;
    }
    return {ifwhitecnt, ifblackcnt};
  };
  auto ans = f(0, 0);
  cout << (((li)ans.fi + ans.se) % mod) << endl;
}
// 7
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0), exit(0);
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}

Measured memory_bytes: 14080
#include <iostream>
using namespace std;
int main(void){
    int N,K,x,sum=0;
    cin>>N>>K;
    for(int i=0;i<N;i++){
        cin>>x;
        if(K/2<x)sum+=2*(K-x);
        else sum+=2*x;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define all(x) (x).begin(),(x).end()
using namespace std;
using P=pair<int,int>;
using G=vector<vector<int>>;
using ll=long long;




int main(){
    int n,m;
    cin>>n>>m;
    int c[m],s[m];

    rep(i,0,m){
        cin>>s[i]>>c[i];
    }

    vector<int> ans(n,-1);

    rep(i,0,m){
        if(n>1 && s[i]==1 && c[i]==0){
            cout<<-1<<endl;
            return 0;
        }
        if(ans[s[i]-1]!=-1 && ans[s[i]-1]!=c[i]){
            cout<<-1<<endl;
            return 0;
        }
        if(ans[s[i]-1]==-1){
            ans[s[i]-1]=c[i];
        }
    }

    if(ans[0]==-1 and n>1) ans[0]=1;

    rep(i,0,n) if(ans[i]==-1) ans[i]=0;

    for(int i=0;i<n;i++){
        cout<<ans[i];
    }
    cout<<endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
const ll MOD = 1e9+7;
const ll inf = (LLONG_MAX>>2);
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  set<char> s1,s2;
  for(int i = 0; i < s.size(); ++i){
    if(i&1) s2.insert(s[i]);
    else s1.insert(s[i]);
  }
  for(char c : s1){
    if(c == 'L'){
      cout << "No";
      return 0;
    }
  }
  for(char c : s2){
    if(c == 'R'){
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}

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

int main() {
  
  //データの数
  int N, A=1, i;
  cin >> N;
  
  vector<int> data ( N,0 );
  
  for(i = 0; i < N ; i++){
  	cin >> data.at(i) ;
  }
  
  for(i = 0; i < N ; i++){
  	A=data.at(A-1);
    if(A == 2){
      break;
    }
  }
  
  if(i == N){
  	cout << -1 << endl;
  }
  else{
  	cout << i+1 << endl;
  }
  
}


Measured memory_bytes: 3780
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int K = Integer.parseInt(in.next());
            int x = 7 % K;
            int i = 1;
            Set<Integer> s = new HashSet<>();
            while (!s.contains(x)) {
                if (x == 0) {
                    out.println(i);
                    return;
                } else {
                    s.add(x);
                    x = (x * 10 + 7) % K;
                    ++i;
                }
            }
            out.println(-1);
        }

    }
}



Measured memory_bytes: 102572
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt = fst . fromJust . BS.readInt

readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine

getIntList = readIntList <$> BS.getLine

simulate table k a b c = do
  if k == c
    then return "YES"
    else do
      p <- VUM.read table k
      if p /= 0
        then return "NO"
        else do
          VUM.write table k 1
          simulate table ((k + a) `mod` b) a b c

main = do
  [a, b, c] <- getIntList
  table <- VUM.replicate b 0 :: IO (VUM.IOVector Int)
  sentense <- simulate table (a `mod` b) a b c
  putStrLn sentense


Measured memory_bytes: 3784
#include <bits/stdc++.h>
    #define rep(i,n) for(int i = 0; i < (n); i++)
     
    using namespace std;
    using ll = long long;
    using P = pair<int,int>; // 1 つの証言を表す構造体 // 「人」と「0 or 1」
    using Graph = vector<vector<int>>;
    
    int main() {
    int a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    ll ans = 0;
    for(int i = 1; i <= 100000; i++){
    	if(i > x && i> y) break;
    	else if (i>x) ans+=min(b,c*2);
    	else if (i>y) ans+=min(a,c*2);
    	else ans+=min(a+b,c*2);
    }
   	cout << ans << endl;
     return 0;
    }
    

Measured memory_bytes: 256
#include <iostream>
#define INF 1000000
using namespace std;

int q;
string x,y;
int _dp[1010][1010];
int result[150];

int dp(int posx,int posy){
	if(_dp[posx][posy]) return _dp[posx][posy];
	if(posx == 0 || posy == 0){
		_dp[posx][posy] == 0;
		return 0;
	}else{
		int max = dp(posx-1,posy);
		if(max < dp(posx,posy-1)) max = dp(posx, posy-1);
		if(x[posx-1] == y[posy-1] && max < dp(posx-1,posy-1)+1)
			max = dp(posx-1,posy-1)+1;
		_dp[posx][posy] = max;
		return max;
	}
}

int main(void){
	cin >> q;
	
	for(int i=0; i<q; i++){
		cin >> x >> y;
		result[i] = dp(x.size() ,y.size());
		std::fill((int*) _dp, (int*) (_dp + 1010), 0);
	}
	
	for(int i=0; i<q; i++) cout << result[i] << endl;
	
	return 0;
}


Measured memory_bytes: 7284
package main

import (
        "fmt"
        "sort"
)

func main() {
        var a, b int
        fmt.Scanf("%d %d", &a, &b)
        var c []int
        c = append(c, a + b)
        c = append(c, a + a - 1)
        c = append(c, b + b - 1)
        sort.Ints(c)
        fmt.Println(c[2])
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
#define fo(i,x,y) for(int i=x;i<=y;i++)
#define fd(i,x,y) for(int i=x;i>=y;i--)
using namespace std;

const int maxn=107,maxm=5000007;
const int inf=0x1fffffff;

int n,m,fi[maxm],la[maxm],ne[maxm],va[maxm],tot=1;
char a[maxn][maxn];

#define Leaf(x,y) (1+x*m+y-m)
#define LEAF(x,y) (1+n*m+x*m+y-m)
#define Row(x) (1+n*m+n*m+x)
#define Col(x) (1+n*m+n*m+n+x)
int N;
void add(int a,int b,int c){
	tot++;
	ne[tot]=fi[a];
	la[tot]=b;
	va[tot]=c;
	fi[a]=tot;
}
void Add(int a,int b,int c){
	add(a,b,c);
	add(b,a,0);
}
void Init(){
	scanf("%d%d",&n,&m);
	N=2+2*n*m+n+m;
	fo(i,1,n) scanf("%s",a[i]+1);
	fo(i,1,n)
		fo(j,1,m){
			if (a[i][j]=='.') continue;
			if (a[i][j]=='S') Add(1,Leaf(i,j),inf);
			if (a[i][j]=='T') Add(LEAF(i,j),N,inf);
			/*fo(k,1,n)
				if (i!=k && a[k][j]!='.')
					add(LEAF(i,j),Leaf(k,j),inf);
			fo(k,1,m)
				if (j!=k && a[i][k]!='.')
					add(LEAF(i,j),Leaf(i,k),inf);*/
			Add(LEAF(i,j),Row(i),inf);
			Add(LEAF(i,j),Col(j),inf);
			Add(Leaf(i,j),LEAF(i,j),(a[i][j]=='o'?1:inf));
		}
	fo(i,1,n) fo(j,1,m)
		if (a[i][j]!='.'){
			Add(Row(i),Leaf(i,j),inf);
			Add(Col(j),Leaf(i,j),inf);
		}
}

int Ans,Cnt[maxm],bz[maxm];
int gap(int v,int Flow){
	int Used=0;
	if (v==N) 
		return Flow;
	for(int k=fi[v];k;k=ne[k])
		if (va[k] && bz[la[k]]+1==bz[v]){
			int i=gap(la[k],min(Flow-Used,va[k]));
			va[k]-=i;
			va[k^1]+=i;
			Used+=i;
			if (Used==Flow || bz[1]==N) return Used;
		}
	if (!--Cnt[bz[v]]) bz[1]=N;
	Cnt[++bz[v]]++;
	return Used;
}
void Solve(){
	Cnt[0]=N;
	while (bz[1]<N && Ans<inf){
		Ans+=gap(1,inf);
	}
}

bool Vis[maxm];
void dfs(int v){
	if (Vis[v]) return;
	Vis[v]=true;
	for(int k=fi[v];k;k=ne[k])
		if (va[k])
			dfs(la[k]);
}
void Print(){
	dfs(1);
	if (Ans>=inf) printf("-1\n");
	else printf("%d\n",Ans);
}

int main(){
	Init();
	Solve();
	Print();
	return 0;
}

Measured memory_bytes: 12544
import itertools

N, M  = tuple([int(x) for x in input().split(' ')])
AB = [tuple([int(x) for x in input().split(' ')]) for i in range(N)]

ans = 0
count = 0
for a, b in sorted(AB, key=lambda x: x[0]):
        if M - count <= b:
                ans +=  (M - count) * a
                break
        else:
                count += b
                ans += a * b

print(ans)

Measured memory_bytes: 18900
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.TreeSet;
 
public class Main {
	static int n;
	static long half;
	static int[] a;
 
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		n = Integer.parseInt(br.readLine());
		String[] sa = br.readLine().split(" ");
		a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		br.close();
 
		half = (long) n * (n + 1) / 4;
		TreeSet<Integer> set = new TreeSet<>();
		for (int i = 0; i < n; i++) {
			set.add(a[i]);
		}
		Integer[] arr = set.toArray(new Integer[0]);
 
		int ok = -1;
		int ng = arr.length;
		while (Math.abs(ok - ng) > 1) {
			int mid = (ok + ng) / 2;
			if (judge(arr[mid])) {
				ok = mid;
			} else {
				ng = mid;
			}
		}
		System.out.println(arr[ok]);
	}
 
	static boolean judge(int med) {
		int[] b = new int[n + 1];
		for (int i = 0; i < n; i++) {
			if (a[i] >= med) {
				b[i + 1] = 1;
			} else {
				b[i + 1] = -1;
			}
		}
		for (int i = 1; i < b.length; i++) {
			b[i] += b[i - 1];
		}
 
		long t = tentousuu(b);
		return t <= half;
	}
 
	static long tentousuu(int[] a) {
		int n = a.length;
		int min = Integer.MAX_VALUE;
		int max = Integer.MIN_VALUE;
		for (int i = 0; i < n; i++) {
			min = Math.min(min, a[i]);
			max = Math.max(max, a[i]);
		}
		min--;
		int[] b = new int[n];
		for (int i = 0; i < n; i++) {
			b[i] = a[i] - min;
		}
 
		BIT bit = new BIT(max - min);
		long ret = 0;
		for (int i = 0; i < n; i++) {
			ret += i - bit.sum(b[i]);
			bit.add(b[i], 1);
		}
		return ret;
	}
 
	static class BIT {
		int n;
		long[] arr;
 
		public BIT(int n) {
			this.n = n;
			arr = new long[n + 1];
		}
 
		void add(int idx, long val) {
			for (int i = idx; i <= n; i += i & -i) {
				arr[i] += val;
			}
		}
 
		long sum(int idx) {
			long sum = 0;
			for (int i = idx; i > 0; i -= i & -i) {
				sum += arr[i];
			}
			return sum;
		}
	}
}

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

int main(){
    string a;
    cin >> a;
    if(a == "MON"){
        cout << "6" <<endl;
    
    }else if(a == "TUE"){
        cout << "5" << endl;
    }else if(a == "WED"){
        cout << "4" << endl;
    }else if(a == "THU"){
        cout << "3" << endl;
    }else if(a== "FRI"){
        cout  << "2" << endl;
    }else if(a == "SAT"){
        cout << "1"<< endl;
    }else{
        cout << "7" << endl;
    }
    

}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define LL long long
#define pb push_back

const int N = 305;
const int MOD = 998244353;
bitset<N> a[N];
vector<bitset<N>> base;
LL q_pow(LL n, LL k) {
	LL res = 1;
	while (k) {
		if (k & 1) res = (res*n) % MOD;
		k >>= 1;
		n = (n*n) % MOD;
	}
	return res;
}
int main() {
	int n, m, t;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; ++i) {
		a[i].reset();
		for (int j = m - 1; j >= 0; --j) {
			scanf("%d", &t);
			if (t) a[i].flip(j);
		}
	}
	for (int i = 0; i < n; i++) {
		for (bitset<N> b : base) {
			bitset<N> bb = b ^ a[i];
			for (int j = 0; j < m; j++) {
				if (bb[j] < a[i][j]) {
					a[i] = bb;
					break;
				}
				else if (bb[j] > a[i][j]) break;
			}
		}
		if (a[i].any()) base.pb(a[i]);
	}
	int cnt = (int)base.size();
	printf("%lld\n", ((q_pow(2, n + m - 1) - q_pow(2, n + m - 1 - cnt)) % MOD + MOD) % MOD);
	//system("pause");
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  while(cin>>n,n) {
    int cnt[26]; CLR(cnt);
    vector<string> C(n); FOR(i,0,n) cin >> C[i];
    int mx = 0;
    char mxc;
    bool next = false;
    FOR(i,0,n) {
      cnt[C[i][0] - 'A']++;
      if(mx <= cnt[C[i][0] - 'A']) {
        mx = max(mx, cnt[C[i][0] - 'A']);
        mxc = C[i][0];
      }
      bool win = true;
      FOR(j,0,26) {
        if(mxc - 'A' == j) continue;
        if(mx <= cnt[j] + n - i - 1) {
          win = false;
          break;
        }
      }
      if(win) {
        cout << mxc << " " << i + 1 << endl;
        next = true;
        break;
      }
    }
    if(next) continue;
    int t = 0;
    int ans = 0;
    FOR(i,0,26) {
      if(cnt[i] == mx) {
        ans = i;
        t++;
      }
    }
    if(t == 1) {
      cout << char(ans + 'A') << " " << n << endl;
    } else {
      cout << "TIE" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3184
#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;
#define MP make_pair
#define PB push_back
#define ll long long
#define int long long
#define f(i,x,n) for(int i=x;i<n;i++)
#define ld long double
#define mod 1000000007
int n;
int a[100005];
multiset <int> se;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	f(i,0,n)
	{
		cin>>a[i];
	}
	se.insert(a[0]);
	int ans=1;
	f(i,1,n)
	{
		// cout<<ans<<endl;
		if(*(se.begin())<a[i])
		{
			auto itr=se.lower_bound(a[i]);
			itr--;
			se.erase(itr);
			se.insert(a[i]);
		}
		else
		{
			se.insert(a[i]);
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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


// type definitions
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef complex<int> ci;
typedef complex<double> cd;
typedef complex<long double> cld;

// macros
#define rep(i, a, b) for(int i=a; i<b; i++)
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define all(c) c.begin(), c.end()
#define tr(c, it) for(auto it=(c).begin(); it!=c.end(); it++)
#define pb push_back
#define mp make_pair
#define bitcount __builtin_popcount
#define ispresent(c, x) ((c).find(x) != (c).end())
#define watch(x) cout<< (#x) << " is " << (x) <<"\n";
#define sz(x) ((int)((x).size()))
#define UNIQUE(c) (c).resize(unique(all(c)) - (c).begin())
#define pii2ll(p) ((ll)(p).first<<32 | (p).second)

// template functions
template <typename T>
inline void printV(vector<T>& a) { rep(i, 0, sz(a)) { cout<<a[i]<<" "; } cout<<"\n"; }
template <typename T>
inline void printV(vector<T>& a, int n) { rep(i, 0, n) { cout<<a[i]<<" "; } cout<<"\n"; }
template <typename T>
inline void printVV(vector<vector<T>>& a)
{
	rep(i, 0, sz(a)) {
		printV(a[i]);
	}
	cout<<"\n";
}

template <typename T>
inline void clearVV(vector<vector<T>>& a)
{
	for(auto& x:a) {
		x.clear();
	}
	a.clear();
}
template <typename T>
inline void assignVV(vector<vector<T>> &a, T val)
{
	for(int i=0; i<sz(a); i++) {
		for(int j=0; j<sz(a[i]); j++) {
			a[i][j]=val;
		}
	}
}


// constants
const long double eps = 1e-9;
const int inf = 5e8;
const int modn = 1e9+7;
const int MAX = 1e5;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // Your code here
	int n, m;
	cin>>n>>m;
	vector<vector<int>> adj(n);
	for(int i=0; i<m; i++) {
		int u, v;
		cin>>u>>v;
		u--, v--;
		adj[u].push_back(v);
	}
	
	vector<int> dp(n, -1);
	
	function<void(int)> solve = [&](int i)
	{
		if(dp[i]!=-1) return;
		dp[i]=0;
		for(int v:adj[i]) {
			solve(v);
			dp[i]=max(dp[i], 1+dp[v]);
		}
	};
	int ans=0;
	for(int i=0; i<n; i++) {
		solve(i);
		ans=max(ans, dp[i]);
	}
	cout<<ans<<"\n";
    return 0;
}



Measured memory_bytes: 8832
a, b, m = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = min(A) + min(B)

for _ in range(m):
    x, y, c = map(int, input().split())
    x -= 1
    y -= 1
    cnt = A[x] + B[y] - c
    ans = min(ans, cnt)

print(ans)

Measured memory_bytes: 24776