akhauriyash/Code-Regression huggingface dataset:
use std::io;

fn main() {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let s = buf.trim();
	if s == "a" || s == "e" || s == "i" || s == "o" || s == "u" {
		println!("vowel");
	}else{
		println!("consonant");
	}
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    double n,m;
    cin>>n>>m; double a[(int)n];double sum=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    ll c=0;sum=sum/4;
    for(int i=0;i<n;i++){
        if(a[i]>=sum/m) c++;
    }
    (c>=m) ? cout<<"Yes\n": cout<<"No\n";
    return 0;
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	const inputLines = input.split("\n");
	const line0 = inputLines[0];
	const line1 = inputLines[1];
	const line2 = inputLines[2];

	const k = parseInt(line0, 10);
	const s = line1;
	var output = s;

	if (k < s.length) {
		output = s.substr(0, k);
		output += "...";
	}

	//出力
	console.log('%s',output);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

// node index.js
// 1
// 2 3
// test
// (Ctrl + D)

Measured memory_bytes: 29624
#include <iostream>
#include <vector>
#include <set>
using namespace std;

vector<int> d;

vector<vector<int> >g;

int CNT = 0;

int start = 0;
int tar = 0;

void dfs(int a,int pre){
	for(auto x:g[a]){
		if(x!=pre){
			if(x==start)continue;
			if(x==tar)CNT++;
			else{
				dfs(x,a);
			}
		}
	}
}


int main(){
	int n,m;
	cin >> n >> m;
	d.resize(n);
	g.resize(n);
	for(int i=0;i<m;i++){
		int a,b;
		cin >> a >> b;
		a--;b--;
		d[a]++;
		d[b]++;
		g[a].push_back(b);
		g[b].push_back(a);	
	}
	int cnt = 0;
	bool flag = 0;
	bool fflag = 0;
	vector<int> p;
	for(int i=0;i<n;i++){
		if(d[i]%2!=0){
			flag = 1;
			break;
		}
		if(d[i]>=6){
			fflag = 1;
		}
		if(d[i]==4){
			cnt++;
			p.push_back(i);
		}
	}
	if(flag){
		cout << "No" << endl;
	}else if(fflag){
		cout << "Yes" << endl;
	}else if(cnt<=1){
		cout << "No" << endl;
	}else if(cnt>2){
		cout << "Yes" << endl;
	}else{
		start = p[0];
		tar = p[1];
		dfs(p[0],-1);
		if(CNT==4){
			cout << "No" << endl;
		}else{
			cout << "Yes" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 7296
import sys
n = int(input())
xyh = [list(map(int, input().split())) for i in range(n)]
xyh.sort(key=lambda x: -x[2])
for cx in range(101):
    for cy in range(101):
        good = True
        h = xyh[0][2]+abs(cx-xyh[0][0])+abs(cy-xyh[0][1])
        for i in range(n):
            if xyh[i][2] != max(h-abs(cx-xyh[i][0])-abs(cy-xyh[i][1]), 0):
                good = False
                break
        if good:
            print(cx, cy, h)
            sys.exit()


Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main()
{
  int a,b,k;
  cin >> a >> b >> k;
  int c=k/2;
  int d=k%2;
  
  if(k==1){
    if (a%2==1){
      a=a-1;
    }
    b=b+a/2;
    a=a-a/2;
  }
  
  
  else{
  
  for (int i=0;i<c;i++){
     if (a%2==1){
      a=a-1;
    }
    b=b+a/2;
    a=a-a/2;
    
     if (b%2==1){
      b=b-1;
    }
    a=a+b/2;
    b=b-b/2;
  }//for 
    
    
    if(d==1){
       if (a%2==1){
      a=a-1;
    }
    b=b+a/2;
    a=a-a/2;
    }
    
    
  }//else
  
  cout << a <<" " <<  b << endl;
  
}

Measured memory_bytes: 256
C = input()
alphabet_list  = [
    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 
    'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 
    'w', 'x', 'y', 'z'
]
for i, alphabet in enumerate(alphabet_list):
    if C == alphabet:
        print(alphabet_list[i + 1])
        break


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#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 all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

typedef long long ll;

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

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

const int INF = 1e9;
const ll INFLL = 1e18;
const ll MOD = 1e9+7;

const double PI = acos(-1.0);

int V,E;
int Tmax;
vector<vector<pair<int, int>>> Graph;
vector<vector<pair<int, int>>> info;
vector<int> command;
void INPUT(){
    cin>>V>>E;
    Graph.resize(V);
    rep(_, E){
        int u,v,d;
        cin>>u>>v>>d;
        u--;v--;
        Graph[u].push_back({v,d});
        Graph[v].push_back({u,d});
    }
    cin>>Tmax;
    info.resize(Tmax);
    rep(i, Tmax){
        int N_new;
        cin>>N_new;
        rep(_, N_new){
            int new_id, dst;
            cin>>new_id>>dst;
            info[i].push_back({new_id,dst});
        }
    }
    command.resize(Tmax);
    rep(i,Tmax)command[i] = -1;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    INPUT();
    rep(i,Tmax){
        cout<<command[i]<<'\n';
    }
}

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


void bfs(int s,vector<vector<int>> &V,vector<int> &D){
  queue<int> q;
  q.push(s);
  int u;
  while(!q.empty()){
    u=q.front();q.pop();
    for(int k=0;k<V.at(u).size();k++){
      if(D.at(V.at(u).at(k))==-1){
        D.at(V.at(u).at(k))=u;
        q.push(V.at(u).at(k));
      }
    }
  } 
}

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

  vector<vector<int>> V(N);
  vector<int> D(N);

  for(int i=0;i<N;i++){
    D.at(i) = -1;
  }
  int a,b;
  for(int i=0;i<M;i++){
    cin >> a >> b;
    V[a-1].push_back(b-1);
    V[b-1].push_back(a-1);
  }
  
  bfs(0,V,D);
  cout << "Yes" << endl;
  for(int i=1;i<N;i++){
    cout << D.at(i)+1 << endl;
  }
  

}



Measured memory_bytes: 10164
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const int MAXN = 310;

int n;
int a[MAXN];
int cc[4];
ld dp[305][305][305];

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cout.precision(20);
	cout.setf(ios::fixed);
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	for (int i = 0; i < n; ++i)
		++cc[a[i]];
	for (int k = 0; k <= cc[3]; ++k)
		for (int j = 0; j <= cc[2] + cc[3]; ++j)
			for (int i = 0; i <= cc[1] + cc[2] + cc[3]; ++i) {
				if (i == 0 && j == 0 && k == 0)
					continue;
				if (i)
					dp[i][j][k] += i * dp[i - 1][j][k];
				if (j)
					dp[i][j][k] += j * dp[i + 1][j - 1][k];
				if (k)
					dp[i][j][k] += k * dp[i][j + 1][k - 1];
				dp[i][j][k] /= n;
				dp[i][j][k] += 1;
				dp[i][j][k] /= ld(i + j + k) / n;
			}
	cout << dp[cc[1]][cc[2]][cc[3]] << "\n";
	return 0;
}




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


int main() {
    int A,B;
    string S;
    cin>>A>>B>>S;
    for(int i=0;i<A+B+1;i++){
        if(i==A)continue;
       else if(!('0'<=S[i]&&S[i]<='9')){
            cout<<"No"<<endl;
            return 0;
        }
    }
    if (S[A]!='-'){
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
import copy


# global
cards_origin = []


# function
def BubbleSort(count, cards):
    for i in range(count):
        for j in range(count-1, i, -1):
            if cards[j][1] < cards[j-1][1]:
                cards[j], cards[j-1] = cards[j-1], cards[j]


def SelectionSort(count, cards):
    for i in range(count):
        minj = i
        for j in range(i, count):
            if cards[j][1] < cards[minj][1]:
                minj = j
        cards[i], cards[minj] = cards[minj], cards[i]
        

def SuitOrder(cards, numbers):
    for i in range(len(cards)):
        numbers[cards[i][1]].append(cards[i][0])


def IsStable(numbers1, numbers2):
    for i in range(len(numbers1)):
        if numbers1[i] != numbers2[i]:
            return "Not stable"

    return "Stable"



if __name__ == "__main__":

    # 入力
    in_count = int(input())
    in_cards = input().split(" ")

    # 入力されたカードの値を独自の配列に格納 ["suit", number]
    for i in range(in_count):
        cards_origin.append([in_cards[i][0], int(in_cards[i][1])])

    # リストをコピーしておく
    cards_bubble = copy.deepcopy(cards_origin)
    cards_selection = copy.deepcopy(cards_origin)

    # 関数呼び出し
    BubbleSort(in_count, cards_bubble)
    SelectionSort(in_count, cards_selection)

    # 1から9までの数字に対し、絵柄がどの順番で出現するか求め、0-9のリストに格納
    # _originとbubble, _originとselectionでそれぞれ比較する
    order_origin = []
    order_bubble = []
    order_selection = []
    for i in range(10):
        order_origin.append([])
        order_bubble.append([])
        order_selection.append([])

    
    SuitOrder(cards_origin, order_origin)
    SuitOrder(cards_bubble, order_bubble)
    SuitOrder(cards_selection, order_selection)
    

    bubble_is_stable = IsStable(order_origin, order_bubble)
    selection_is_stable = IsStable(order_origin, order_selection)

    # 表示
    for i in range(len(cards_bubble)):
        print("%s%d" % (cards_bubble[i][0], cards_bubble[i][1]), end="")
        if i != len(cards_bubble)-1:
            print(" ", end="")
    print()
    print(bubble_is_stable)


    for i in range(len(cards_selection)):
        print("%s%d" % (cards_selection[i][0], cards_selection[i][1]), end="")
        if i != len(cards_selection)-1:
            print(" ", end="")
    print()
    print(selection_is_stable)



Measured memory_bytes: 6352
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

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

vec<int, 2> makeCostTable(const string& a, const string& b) {
  int N = a.size();
  vec<int, 2> cost = make_v(N + 1, N + 1, 0);
  for (int c1 = N - 1; c1 >= 0; c1--) {
    for (int c2 = N - 1; c2 >= 0; c2--) {
      cost[c1][c2] = cost[c1 + 1][c2 + 1] + (a[N - c1 - 1] == b[N - c2 - 1]);
    }
  }
  return cost;
}

int solve(const string& a, const string& b) {
  int N = a.size();
  auto cost = makeCostTable(a, b);
  vec<int, 2> dp = make_v(N + 1, N + 1, 1 << 29);
  dp[0][0] = 0;
  for (int c1 = 0; c1 <= N; c1++) {
    for (int c2 = 0; c2 <= N; c2++) {
      if (c1 + 1 <= N) {
        chmin(dp[c1 + 1][c2], dp[c1][c2] + cost[c1][c2]);
      }
      if (c2 + 1 <= N) {
        chmin(dp[c1][c2 + 1], dp[c1][c2] + cost[c1][c2]);
      }
    }
  }
  return dp[N][N];
}

int main() {
  int H, W;
  while (cin >> H >> W) {
    vector<string> grid(H);
    for (int i = 0; i < H; i++) cin >> grid[i];
    int res = 0;
    for (int j = 0; j + 1 < W; j++) {
      string a = "", b = "";
      for (int i = 0; i < H; i++) {
        a += grid[i][j];
        b += grid[i][j + 1];
      }
      res += solve(a, b);
    }
    cout << res << endl;
  }
  return 0;
}


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

typedef long long ll;

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

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

    vector<ll> A(N);

    

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

    sort(A.begin(), A.end());

    for(int i=0; i<N-1; i++){
        // cout << A[i] << endl;
        if(A[i] == A[i+1]){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<algorithm>

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;

    int count = 0;
    for (int i = a; i <= b; i++) {
        char s[6];
        sprintf(s, "%d", i);
        if (s[0] == s[4] && s[1] == s[3]) {
            count++;
        }
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
#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>;

int main() {
  int N, M, hw_day = 0;
  cin >> N >> M;
  rep(i, M){
    int A_i;
    cin >> A_i;
    hw_day += A_i;
  }

  int rest_day = N - hw_day;

 if (rest_day >= 0) cout << rest_day << endl;
 else cout << -1 << endl;

}


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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void print1(T begin, T end) {
	while (begin != end) {
		cerr << (*begin) << " ";
		*begin++;
	}
	cerr << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
	for (int i = 0; i < height; i++) {
		for (int j = 0; j < width; j++) {
			cerr << " " << Array[i][j];
		}
		cerr << endl;
	}
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
	std::cerr << head << " ";
	print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

// ------------------------------------------------------------------------------------------

string S;
int Q;

string A, B;

signed main() {
	cin >> S >> Q;

	bool omote = true;

	while (Q--) {
		int Ti;
		cin >> Ti;
		if (Ti == 1) {
			// reverse(all(S));
			omote = !omote;
		} else {
			int Fi;
			cin >> Fi;
			char Ci;
			cin >> Ci;
			if ((omote and Fi == 1) or (!omote and Fi == 2)) {
				A.push_back(Ci);
			} else {
				B.push_back(Ci);
			}
			/*
			if (Fi == 1) {
				// S = Ci + S;
				if (omote) {
					S = Ci + S;
				} else {
					S += Ci;
				}
			} else {
				// S += Ci;
				if (omote) {
					S += Ci;
				} else {
					S = Ci + S;
				}
			}
			*/
		}
	}

	reverse(all(A));
	S = A + S + B;

	if (!omote) {
		reverse(all(S));
	}
	cout << S << endl;

	return 0;
}

Measured memory_bytes: 1348
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[])
{
    ll x;
    cin >> x;
    if (x % 11 == 0)
        cout << x / 11 * 2 << endl;
    else
    {
        if (x % 11 > 6)
        {
            cout << x / 11 * 2 + 2 << endl;
        }
        else
        {
            cout << x / 11 * 2 + 1 << endl;
        }
    }
}

Measured memory_bytes: 256
from sys import stdin
input = lambda: stdin.readline().rstrip("\r\n")
from collections import defaultdict as vector, deque as que
read = lambda: list(map(int,input().split()))
from bisect import bisect
from heapq import heappush as hpush,heappop as hpop

n,m,k=read()
A=read()
B=read()
a,b=[0],[0]
for i in range(n):
	a.append(a[i]+A[i])
for i in range(m):
	b.append(b[i]+B[i])
ans=0;j=m
for i in range(0,n+1):
	curr=a[i]
	if curr>k:
		break
	while(b[j]>k-curr):
		j-=1
	ans=max(ans,i+j)
print(ans)



Measured memory_bytes: 137688
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;

const int Maxn = 100005;
int n, m, st, ed;
int dist[Maxn][3];
vector <int> g[Maxn];

int main() {
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; ++ i) {
		int u, v;
		scanf("%d %d", &u, &v);
		g[u].push_back(v);
	}
	scanf("%d %d", &st, &ed);
	queue <pair <int, int> > que;
	que.push({st, 0});
	memset(dist, 0x3f, sizeof (dist));
	dist[st][0] = 0;
	while (!que.empty()) {
		int u = que.front().first;
		int d = que.front().second;
		que.pop();
		for (auto &v: g[u])
			if (dist[v][(d + 1) % 3] > dist[u][d] + 1) {
				dist[v][(d + 1) % 3] = dist[u][d] + 1;
				que.push({v, (d + 1) % 3});
			}
	}
	if (dist[ed][0] < 0x3f3f3f3f)
		printf("%d\n", dist[ed][0] / 3);
	else
		puts("-1");
	return 0;
}

Measured memory_bytes: 6912
#include<bits/stdc++.h>
using namespace std;
int main()
{
	 string s; cin>>s;
	 if(s=="KIHBR"||s=="AKIHBR"||s=="AKIHABR"||s=="AKIHABAR"||s=="AKIHABARA"||
	 s=="KIHABR"||s=="KIHABAR"||s=="KIHABR"||s=="KIHABAR"||s=="KIHBAR"||
	 s=="KIHBARA"||s=="KIHBRA"||s=="AKIHBARA"||s=="AKIHABRA"||s=="AKIHBRA"||
	 s=="KIHABARA") puts("YES");
	 else puts("NO");
	 
}

/*
AKIHABARA
*/

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=(int)(b);i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

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

#define INF INT_MAX/3

ll a[51];

int main(){
  cin.sync_with_stdio(false);
  int n, mini = INF, maxi = -INF, p, q;
  cin >> n;
  rep(i, n) {
    cin >> a[i];
    if (mini > a[i]) mini = a[i], p = i;
    if (maxi < a[i]) maxi = a[i], q = i;
  }
  vector<P> ans;
  if (mini < 0 && maxi > 0) {
    if (abs(mini) > abs(maxi)) {
      rep(i, n) {
        if (i == p) continue;
        ans.pb(P(p + 1, i + 1));
        a[i] += mini;
      }
      maxi += mini;
      ans.pb(P(p + 1, p + 1));
      a[p] += mini;
      mini += mini;
    } else {
      rep(i, n) {
        if (i == q) continue;
        ans.pb(P(q + 1, i + 1));
        a[i] += maxi;
      }
      mini += maxi;
      ans.pb(P(q + 1, q + 1));
      a[q] += maxi;
      maxi += maxi;
    }
  }
  if (mini <= 0 && maxi <= 0) {
    repr(i, n, 1) if (a[i - 1] > a[i]) {
      ans.pb(P(i + 1, i));
      a[i - 1] += a[i];
    }
  } else {
    repl(i, 1, n) if (a[i - 1] > a[i]) {
      ans.pb(P(i, i + 1));
      a[i] += a[i - 1];
    }
  }
  cout << ans.size() << endl;
  rep(i, ans.size()) cout << ans[i].fi << " " << ans[i].se << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>

using namespace std;

#define sz(X) ((int)(X).size())
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define all(X) (X).begin(),(X).end()
#define FOR(i, a, n) for(int i=(a), __ ## i=(n); i<__ ## i; i++)
#define REP(I,N) FOR(I,0,N)
#define PR(X) cout<<#X<<" = "<<(X)<<" "
#define PRL cout<<endl
#define PRV(X) {cout<<#X<<" = {";REP(__prv,sz(X)-1)cout<<(X)[__prv]<<",";if(sz(X))cout<<*(X).end();cout<<"}"<<endl;}

template<class T> ostream &operator<<(ostream &os, const vector<T> &vec)
{
	os << '{';
	REP(i, sz(vec))
	{
		os << vec[i];
		if (i + 1 != sz(vec))
			os << ',';
	}
	os << '}';
	return os;
}

template<class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &par)
{
	os << '(' << par.X << ',' << par.Y << ')';
	return os;
}

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<bool> VB;
typedef vector<unsigned long long> VULL;
typedef vector<vector<int>> VVI;
typedef queue<int> QI;

int gcd(int x, int y)
{
	return y ? gcd(y, x % y) : abs(x);
}

template<class T> T sqr(T x)
{
	return x * x;
}

LL a[100001];
LL b[100001];
LL sa[100001];
LL sb[100001];
map<LL, bool> masked;
map<LL, int> mask;
int num;

int add(LL n)
{
	if (!masked[n])
	{
		mask[n] = num++;
		masked[n] = true;
	}
	return mask[n];
}

bool used[100001];

int main()
{
	ios::sync_with_stdio(false);
	num = 0;
	int N;
	cin >> N;
	REP(i, N)
	{
		cin >> a[i + 1];
		a[0] ^= a[i + 1];
		sa[i + 1] = a[i + 1];
	}
	sa[0] = a[0];
	REP(i, N)
	{
		cin >> b[i + 1];
		b[0] ^= b[i + 1];
		sb[i + 1] = b[i + 1];
	}
	sb[0] = b[0];

	sort(sa, sa + N + 1);
	sort(sb, sb + N + 1);

	REP(i, N + 1)
	{
		if (sa[i] != sb[i])
		{
			cout << -1;
			return 0;
		}
	}

	VVI edge(N + 1);
	VVI back(N + 1);
	FOR(i, 1, N + 1)
	{
		if (a[i] != b[i])
		{
			int x = add(a[i]);
			int y = add(b[i]);
			edge[x].pb(y);
			back[y].pb(x);
		}
	}

	int comps = 0;
	int res = 0;
	REP(i, num)
	{
		if (used[i])
			continue;
		comps++;
		QI que;
		que.push(i);
		used[i] = true;
		int ed = 0;
		while (!que.empty())
		{
			int u = que.front();
			que.pop();

			ed += sz(edge[u]);

			REP(j, sz(edge[u]))
			{
				if (!used[edge[u][j]])
				{
					used[edge[u][j]] = true;
					que.push(edge[u][j]);
				}
			}
			REP(j, sz(back[u]))
			{
				if (!used[back[u][j]])
				{
					used[back[u][j]] = true;
					que.push(back[u][j]);
				}
			}
		}
		res += ed;
	}

	res += comps - 1;
	if (!masked[a[0]])
	{
		add(a[0]);
		res++;
	}
	if (!masked[b[0]])
	{
		add(b[0]);
		res++;
	}

	cout << res;

	return 0;
}

Measured memory_bytes: 26880
#include <stdio.h>
#include <math.h>

int main(void) {
	int n, r = 0, i;
	
	scanf("%d", &n);
	
	for (i = 0; i <= 5; i++)
		r += n % (int)pow(10, i+1) / (int)pow(10, i);
	
	if (r == 1 && n != 1)
		r = 10;
	
	printf("%d\n", r);
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  string s,t,u;
  cin>>s>>t>>u;
  string S,T;
  S="abcdefghijklmnopqrstuvwxyz";
  T="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  for(ll i=0;i<26;i++) {
if(S[i]==s[0]) {
cout<<T[i];
}
  }
     for(ll i=0;i<26;i++) {
if(S[i]==t[0]) {
cout<<T[i];
}
     }
        for(ll i=0;i<26;i++) {
if(S[i]==u[0]) {
cout<<T[i];
}
        }
          
          cout<<endl;
        }


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

#define INF INT_MAX
#define UINF UINT_MAX
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef std::pair<int,int> pii;

using namespace std;

int main() {
    int n,k;
    cin >> n >> k;
    vector<int> h(n);
    REP(i,n)cin >> h[i];

    int ans = 0;
    REP(i,n)if(h[i] >= k)ans++;

    cout << ans << endl;

    return 0;
}

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

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef long long int ll;
typedef vector<ii> vii;
typedef vector<ll> vll;

int n, m, i, j, a;
unordered_map<int, int> d;
int main() {
	cin >> n;
	for(i = 0; i < n; i++) {
		cin >> a;
		if(!d.count(a)) {
			d.insert(make_pair(a,0));
		} else d[a]++;
	}
	cin >> m;
	for(i = 0; i < m; i++) {
		cin >> a;
		if(!d.count(a)) {
			puts("NO");
			return 0;
		} else {
			if(d[a] > 0) d[a]--;
			else d.erase(a);
		}
	}
	puts("YES");
	return 0;
}

Measured memory_bytes: 8520
#include <bits/stdc++.h>
using namespace std;
 
int xs[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
int ys[8] = {1, 1, 1, 0, 0, -1, -1, -1};
 
int h, w;
 
bool check(int x, int y){
    if (x >= 0 && x < h && y >= 0 && y < w){
        return true;
    }
    
    return false;
}
 
int main(){
    
    //int h, w;
    cin >> h >> w;
    
    string s;
    vector<vector<int>>arr(h, vector<int>(w));
    for(int i = 0; i < h; i++){
        cin >> s;
        for(int j = 0; j < w; j++){
            s[j] == '.' ? arr[i][j] = 1 : arr[i][j] = 0; 
        }
    }
    string res;
    for(int i = 0; i < h; i++){
        res = "";
        for(int j = 0; j < w; j++){
            if(arr[i][j] == 1){
                int total = 0;
                for(int k = 0; k < 8; k++){
                    if(check(i+xs[k], j+ys[k]) && arr[i+xs[k]][j+ys[k]] == 0){
                        total += 1;
                    }
                }
                res += (char)(total + '0');
            }
            else { 
                res += '#'; 
            }
        }
        cout << res  << endl; 
    }
    
    
    return 0;
    
}

Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef set<int> si;
typedef string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
ll N;
ll gold[2][3];
ll dp[4][25000010];
int main(){
  cin>>N;
  rep(i,2){
    rep(j,3){
      cin>>gold[i][j];
    }
  }
  fill(dp,0);
  rep(i,4){
    rep(j,N+1){
      if(i==0) dp[i][j]=N;
      else{dp[i][j]=max(dp[i-1][j],(j-gold[0][i-1]>=0?dp[i][j-gold[0][i-1]]+gold[1][i-1]-gold[0][i-1]:0));}
    }
  }
  ll M=dp[3][N];
  fill(dp,0);
  rep(i,4){
    rep(j,M+1){
      if(i==0) dp[i][j]=M;
      else{dp[i][j]=max(dp[i-1][j],(j-gold[1][i-1]>=0?dp[i][j-gold[1][i-1]]+gold[0][i-1]-gold[1][i-1]:0));}
    }
  }
  prin(dp[3][M]);
  
  return 0;
}


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

int isprime(int);

int main(){
  int n,i,j,A[10000],count=0,a,b;
  scanf("%d",&n);
  if(n<0 || n>10000) exit(1);
  for(i=0; i<n; i++){
    scanf("%d",&A[i]);
    if(A[i]<=1 || A[i]>100000000) exit(2);
  }

  for(i=0; i<n; i++){
    a = isprime(A[i]);
    if(a == 1) count++;
  }

  printf("%d\n",count);
}

int isprime(int x){
  int i;

  if(x == 2) return 1;
  if(x < 2 || x%2 == 0) return 0;

  i=3;
  while(i <= sqrt(x)){
    if(x%i == 0) return 0;
    i = i+2;
  }

  return 1;

}


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

int main() {
  map<int, int> MA;
  int a;
  while (cin >> a) {
    MA[a]++;
    if (MA[a] > 2) return cout << "NO" << "\n", 0;
  }
  cout << "YES" << "\n";
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int D = scanner.nextInt();
		int N = scanner.nextInt();

		if (D == 0) {
			if (N != 100) {
				System.out.println(N);
			} else {
				System.out.println(N+1);
			}
		} else if (D == 1) {
			if (N != 100) {
				System.out.println(N*100);
			} else {
				System.out.println((N+1)*100);
			}
		} else {
			if (N != 100) {
				System.out.println(N*10000);
			} else {
				System.out.println((N+1)*10000);
			}
		}
	}
}

Measured memory_bytes: 21844
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>

#define rep(i,n) for(int i = 0; i < n; i++)
#define ENDL "\n"
#define print(i) std::cout << (i) << "\n"

#define int long long // at least int64 > 9*10^18
#define all(v) v.begin(), v.end()

signed main() {
	int s;
	std::cin >> s;
	long double x = std::sqrt(s);
	int a = std::ceil(x);
	int d = a;
	int c = a*d-s;
	int b = 1;
	std::cout << 0 << ' ';
	std::cout << 0 << ' ';
	std::cout << a << ' ';
	std::cout << b << ' ';
	std::cout << c << ' ';
	std::cout << d << ' ';
	return 0;
}


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

int main(){
    int n; 
    fl p;
    cin >> n;
    p = ((n+1)/2)/(float)(n);
    printf("%.10f",p);
    return 0;
}

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

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

int main(){
	int N;
	cin >> N;
	vector<vector<int>> G(N);
	map<P,int> d;
	rep(i,N-1){
		int u,v,w;
		cin >> u >> v >> w;
		u--; v--; w%=2;
		d[P(u,v)] = d[P(v,u)] = w;
		G[u].push_back(v);
		G[v].push_back(u);
	}

	vector<int> used(N,-1);
	used[0] = 0;
	queue<int> que;
	que.push(0);
	while(!que.empty()){
		int x = que.front(); que.pop();
		for(int u : G[x]){
			if(used[u]==-1){
				used[u] = used[x] xor d[P(x,u)];
				que.push(u);
			}
		}
	}

	for(int u : used)cout << u << endl;
}


Measured memory_bytes: 18816
from functools import reduce
import math
import sys
 
K = int(input())
 
def gcd(*args):
  return reduce(math.gcd, args)
 
if K==1:
  print("1")
  sys.exit()
elif K==2:
  print("9")
  sys.exit()
 
ans = K * (K+1)//2
for i in range(1,K):
  for j in range(i+1,K+1):
    ans += 6*math.gcd(i,j)
  
for i in range(1,K-1):
  for j in range(i+1, K):
    for k in range(j+1, K+1):
      ans += 6 * gcd(i,j,k)
      
print(ans)

Measured memory_bytes: 9564
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int> H(N);
  for(int i=0;i<N;i++)	cin>>H[i];
  int hotel=1;
  int flag=-1;
  for(int i=1;i<N;i++){
    flag=0;
    for(int j=0;j<i;j++){
      if(H[i]<H[j])	flag=1;
    }
    if(flag==0)	hotel++;
  }
  
  cout<<hotel<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

string solve(const string& w) {
  map<char, int> mp;
  for (auto c : w) {
    if (mp.find(c) == mp.end()) {
      mp.insert(make_pair(c, 1));
    } else {
      ++mp[c];
    }
  }

  for (auto p : mp) {
    if (p.second % 2 != 0) return "No";
  }
  return "Yes";
}

int main() {
  string w;
  cin >> w;
  cout << solve(w) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;float m;cin>>n>>m;
  vector<int>a(n);
  int sum=0;
  for(int i=0;i<n;++i){
    cin>>a[i];
    sum+=a[i];
  }
  float tmp=sum/(4*m);
  int cnt=0;
  for(int i=0;i<n;++i){
    if(a[i]>=tmp){
      cnt++;
    }
  }
  if(cnt>=m){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		sc.close();

		System.out.println(calc(a-1) ^ calc(b));
	}

	private static long calc(long val) {
		if (val <= 0) {
			return 0L;
		}
		String str = Long.toBinaryString(val);
		long base = 2;
		boolean[] odd = new boolean[41];
		for (int i = 0; i < str.length(); i++) {
			if (i == 0) {
				long mod = val % 4;
				if (mod == 1 || mod == 2) {
					odd[i] = true;
				}
			} else {
				base *= 2;
				long mod = val % base;
				long cnt = Math.max(mod + 1 - base / 2, 0);
				if (cnt % 2 == 1) {
					odd[i] = true;
				}
			}
		}

		StringBuilder sb = new StringBuilder();
		for (int i = str.length(); i >= 0; i--) {
			if (odd[i]) {
				sb.append("1");
			} else {
				sb.append("0");
			}
		}
//		System.out.println(Long.parseLong(sb.toString(), 2));
		return Long.parseLong(sb.toString(), 2);
	}
}


Measured memory_bytes: 23636
s = input()
len_s = len(s)
total_sum = 0
for i in range(2 ** (len_s - 1)):
    sum_array = []
    prev_place = 0
    for j in range(len_s - 1):
        if (i >> j) & 1:
            sum_array.append(int(s[prev_place:j+1]))
            prev_place = j+1
    if prev_place != len_s:
        sum_array.append(int(s[prev_place:len_s]))
    total_sum += sum(sum_array)
print(total_sum)

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

using namespace std;

int partition(vector<int> &A, int p, int r);

int main() {
	
	vector<int> p;
	p.clear();
	
	int n;
	int point;
	while(cin >> n) {
		
		int data;
		for(int i=0;i<n;i++) {
			
			cin >> data;
			p.push_back(data);
			
			
		}
		
		point = partition(p, 0, n-1);
		
		for(int i = 0; i < n-1; i++) {
			
        if(i == point) 
            cout << "[" << p[i] << "] ";
            
        else
            cout << p[i] << " ";

    }
    if(point == n-1)
        cout << "[" << p[n-1] << "]\n";
        
    else
        cout << p[n-1] << "\n";

	}
	
	return 0;
}

int partition(vector<int> &A, int p, int r) {
	
	int x = A[r];
	int i = p - 1;
	
	for(int j=p;j<=r-1;j++)
		if(A[j] <= x) {
			i++;
			swap(A[i], A[j]);
		}
		swap(A[i+1], A[r]);
	return i+1;
}


Measured memory_bytes: 3380
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        int hp = scanner.nextInt();
        int n = scanner.nextInt();
        int accumrate = 0;
        for (int i = 0; i < n; i++) {
            int a = scanner.nextInt();
            accumrate += a;
            if(accumrate >= hp){
                break;
            }
        }
        if(accumrate >= hp)
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}

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

int main() {
  char c;
  cin >> c;
  if (c == 'a') {
    cout << "vowel" << endl;
  }
  else if (c == 'e') {
    cout << "vowel" << endl;
  }
  else if (c == 'i') {
    cout << "vowel" << endl;
  }
  else if (c == 'o') {
    cout << "vowel" << endl;
  }
  else if (c == 'u') {
    cout << "vowel" << endl;
  }
  else if (c != 'a', 'e', 'i', 'o', 'u') {
    cout << "consonant" << endl;
  }
}

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

int main(){
	int n,m;scanf("%d %d",&n,&m);
	int WA[n+2];
	int AC[n+2];
	int num,ans1(0),ans2(0);
	string test;
	for(int i=0;i<=n;i++){
			WA[i]=0;
			AC[i]=0;
		}
	for(int i=1;i<=m;i++){
			cin>>num>>test;
			if(AC[num]==1)continue;
			if(test == "AC"){
					AC[num]=1;
					ans1++;
					ans2 += WA[num];
				}
			else if(test == "WA"){
					WA[num]++;
				}	
		}
	printf("%d %d",ans1,ans2);	
	return 0;
	} 


Measured memory_bytes: 4480
#include<iostream>

using namespace std;

int main(){
	int b[100], a[100][100];
	int n, m;
	int ans[100] = { 0 };
	cin >> n >> m;
	for (int i = 0; i < n; i++){
		for (int q = 0; q < m; q++){
			cin >> a[i][q];
		}
	}
	for (int i = 0; i < m; i++){
		cin >> b[i];
	}
	for (int i = 0; i < n; i++){
		for (int q = 0; q < m; q++){
			ans[i] += a[i][q] * b[q];
		}
	}
	for (int i = 0; i < n; i++){
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 3108
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;

;;

int main(){
  ;;
    int n;
    cin >> n;
    int d[n];
    for(int i = 0; i < n; ++i) {cin >> d[i];};
    ;
    sort(d, d+sizeof(d)/sizeof(d[0]));;
    int tmp = d[0]-1;;
    int cnt = 0;;
    for(int i = 0; i < sizeof(d)/sizeof(d[0]); ++i){;;;
        if(tmp == d[i]) {;++cnt;};
        tmp = d[i];
    };;;
    cout << (n-cnt) << endl;;
}

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

int prime[1000000];


bool isPrime(int n) {
  int x = sqrt(static_cast<double>(n));
  for (int i = 3; i <= x; i += 2) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}


void get_prime(int max_num) {
  int primecount = 1;
  prime[2] = primecount;
  for (int i = 3; i <= max_num; i += 2) {
    if (isPrime(i))
      prime[i] = ++primecount;
    else
      prime[i] = primecount;
  }
}


int main () {
  int ns[31];
  int i = 0, max_num;
  while (std::cin >> ns[i]) {
    max_num = std::max(max_num, ns[i]);
    if (ns[i] % 2 == 0 && ns[i] != 2)
      ns[i] --;
    i ++;
  }
  get_prime(max_num);
  for (int j = 0; j < i; j ++) {
    std::cout << prime[ns[j]] << std::endl;
  }
  return 0;
}

Measured memory_bytes: 6940
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>

using namespace std;

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

int main() {
	int p[100], x[100];
	int t[100];
	
	int n;
	cin >> n;
	REP(i, n) scanf("%d", &t[i]);
	
	int m;
	cin >> m;
	REP(i, m) scanf("%d %d", &p[i], &x[i]);
	
	int sum = 0;
	REP(i,n) sum += t[i];
	
	REP(i, m) printf("%d\n", sum - (t[p[i]-1] - x[i]));
	
	return 0;
}

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


def all_pat_num(level):
    return(pow(2, level + 1) - 1)


def pat(level, x):
    if level == 0:
        if (x == 0):
            return 0
        else:
            return 1
    L = pow(2, level + 1) - 3
    if x == 1:
        ans = 0
    elif x <= 1 + L:
        ans = pat(level-1,x-1)
    elif x == 2 + L:
        ans = all_pat_num(level-1) + 1
    elif x < 2 + L + L:
        ans = all_pat_num(level-1) + 1 + pat(level - 1, x - 2 - L)
    else:
        ans = all_pat_num(level)
    return(ans)

print(pat(N, X))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
using ll = long long;
using namespace std;
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;
}

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

    int N;
    cin >> N;
    vector<vector<int>> graph(N), cost(N);

    REP(i, N - 1) {
        int a, b, w;
        cin >> a >> b >> w;
        a--;
        b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
        cost[a].push_back(w);
        cost[b].push_back(w);
    }

    vector<int> ans(N, -1);
    queue<int> q;
    ans[0] = 0;
    q.push(0);
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        REP(i, graph[v].size()) {
            int u = graph[v][i];
            int w = cost[v][i];
            if (ans[u] != -1) {
                continue;
            }
            ans[u] = (ans[v] + w) % 2;
            q.push(u);
        }
    }

    REP(i, N) { std::cout << ans[i] << '\n'; }
    return 0;
}

Measured memory_bytes: 11904
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int bit = 0;
        for (int i=0; i<N; i++) {
            bit |= sc.nextInt();
        }
        System.out.println(Integer.numberOfTrailingZeros(bit));
    }
}

Measured memory_bytes: 23892
#include <iostream>
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>

using Pair = std::pair<uint64_t, uint64_t>;
int main() {
  uint64_t n = 0;
  uint64_t k = 0;
  scanf("%llu %llu", &n, &k);
  std::vector<Pair> values;

  for (int i = 0; i < n; i++) {
    uint64_t a = 0;
    uint64_t b = 0;
    scanf("%llu %llu", &a, &b);
    values.push_back({a, b});
  }
  std::sort(values.begin(), values.end(), [](const Pair& x, const Pair& y){return x.first < y.first;});
  

  uint64_t count = 0;
  for (const auto &map: values) {
    count += map.second;
    if (count >= k) {
      std::cout << map.first << std::endl;
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 2420
#include<stdio.h>


int main(){

  int i, n, a, sum;

  while(1){
    scanf("%d", &n);
    
    if(n == 0){
      break;
    } else {
      sum = 0;
      for(i = 0;i < n / 4;i++){
	
	scanf("%d", &a);
	
	sum += a;
      }
      
      printf("%d\n", sum);
    }
  }
  
  
  return 0;
  
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i,n) for (int i = 0; i < (n); ++i)

const string YES = "Yes";
const string NO = "No";

void solve(long long X, long long Y){
    string ans = NO;

    rep(i,200){
        rep(j,200){
            if(i + j != X) continue;
            if(2 * i + 4 * j != Y) continue;
            ans = YES;
        }
    }

    cout << ans << endl;

}

int main(){
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    solve(X, Y);
    return 0;
}


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

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;

ll GCD(ll x, ll y){
	return y ? GCD(y, x%y) : x;	
}

int n, m, x;
vector<string> v;
string s = "";

void dfs(int i){
	if(i==n){
		v.push_back(s);
		return;
	}
	for(char c='0';c<='1';c++){
		if(s.size()<i+1){
			s.push_back(c);
			dfs(i+1);
		}else{
			s[i] = c;
			dfs(i+1);
		}
	}
	return;
}

int main() {
	cin >> n >> m >> x;
	int c[15];
	int a[15][15];
	ll ans = 1LL;
	ll alg[15];
	for(int i=0;i<n;i++){
		cin >> c[i];
		ans += c[i];
		for(int j=0;j<m;j++){
			cin >> a[i][j];
			alg[j] = 0LL;
		}
	}
	ll csum1 = ans;
	dfs(0);
	for(int i=0;i<v.size();i++){
		ll price = 0LL;
		for(int j=0;j<n;j++){
			if(v[i][j]=='1'){
				price += c[j];
				for(int k=0;k<m;k++){
					alg[k] += a[j][k];
				}
			}
		}
		bool flag = true;
		for(int k=0;k<m;k++){
			if(alg[k]<x){
				flag = false;
			}
			alg[k] = 0LL;
		}
		if(flag){
			ans = min(ans, price);
		}
	}
	if(ans==csum1){
		cout << -1 << endl;
		return 0;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3704
#include <bits/stdc++.h>
#define ll long long
#define N 6005
using namespace std;

int n;
ll P, f[N][N*2];

void add(ll &a, ll b){
    a += b;
    if(a >= P) a -= P;
}

int main()
{
    cin >> n >> P;
    f[0][N] = 1;
    n *= 3;
    for(int i = 0; i <= n; i++){
        for(int j = -i; j <= i; j++){
            // 考虑从后往前逐位确定,除了每段的开头,位置x的方案为x
            // 但每段开头必须是前缀最大值,所以只有一种方案
            add(f[i+1][j+N+1], f[i][j+N]);
            add(f[i+2][j+N-1], f[i][j+N]*(i+1)%P);
            add(f[i+3][j+N], f[i][j+N]*(i+1)%P*(i+2)%P);
        }
    }
    ll ans = 0;
    for(int i = 0; i <= n; i++){
        add(ans, f[n][i+N]);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 561664
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
  
int main(void){
    ll a, b, c;
    
    cin >> a >> b >> c;
    //cout << sqrt(a) << " " << sqrt(b) << " " << sqrt(c) << endl;
    if (((c-a-b)>0) && ((4*a*b) < (c-a-b)*(c-a-b))) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define REP(i,a,b) for (auto i = a; i != b; i++)
#define ll long long int
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second
#define pb push_back
#define SQ(a) (a)*(a)
 
using namespace std;


int main()
{
    std::ios::sync_with_stdio(false);
    int T = 1;
    //cin>>T;
    for(int t = 1;t<=T;t++)
    {
        int n;
        cin>>n;
        if(n >= 30)
        	cout<<"Yes"<<endl;
        else
        	cout<<"No"<<endl;
    }

    return 0;
}


Measured memory_bytes: 3636
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
K, N = map(int, input().split())
A = list(map(int, input().split()))
A = A + [A[0] + K]

max_diff = 0
for i in range(1, N + 1):
    max_diff = max(max_diff, A[i] - A[i - 1])

print(K - max_diff)









Measured memory_bytes: 34112
#include <bits/stdc++.h>
using namespace std;
template<class T = int> using V = vector<T>;

using R = long double;

int main() {
  int n;
  while (cin >> n, n) {
    int k; cin >> k;
    k = n - k;
    V<> x(n), y(n);
    for (int i = 0; i < n; ++i) cin >> x[i] >> y[i];
    constexpr R rt3 = sqrt((R)3);
    V<R> X(n), Y(n);
    for (int i = 0; i < n; ++i) {
      X[i] = rt3 * x[i] - y[i];
      Y[i] = rt3 * x[i] + y[i];
    }
    V<> ordX(n), ordY(n);
    iota(begin(ordX), end(ordX), 0);
    iota(begin(ordY), end(ordY), 0);
    sort(begin(ordX), end(ordX), [&](int i, int j) { return X[i] < X[j]; });
    sort(begin(ordY), end(ordY), [&](int i, int j) { return Y[i] < Y[j]; });
    R res = 1e10;
    for (int lb = 1; lb <= 10000; ++lb) {
      int m = ordX.size();
      if (m < k) break;
      int r = k;
      for (int l = 0; l <= m - k; ++l) {
        int i = ordX[l], j = ordY[r - 1];
        R xl = (X[i] + lb) / rt3;
        R xr = (Y[j] - lb) / rt3;
        res = min(res, xr - xl);
        if (l == m - k) break;
        if (Y[i] <= Y[j]) {
          while (r < m and X[ordY[r]] <= X[i]) ++r;
          ++r;
        }
      }
      for (int i = 0; i < n; ++i) if (y[i] == lb) {
        ordX.erase(find(begin(ordX), end(ordX), i));
        ordY.erase(find(begin(ordY), end(ordY), i));
      }
    }
    res *= 3;
    cout << fixed << setprecision(15) << res << '\n';
  }
}


Measured memory_bytes: 3564