akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int descending_compare(const void *a, const void *b){
    if (*(long long*)a > *(long long*)b){
        return -1;
    }else if (*(long long*)a == *(long long*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int left, mid, right;
    left = 0, right = n;
    mid = (left + right)/2;
    while ((left+1 != mid || mid+1 != right) && mid != left){
        if (key > a[mid]){
            left = mid;
        }else{
            right = mid+1;
        }
        mid = (left + right)/2;
    }
    if (a[left] >= key)return left;
    if (a[mid] >= key)return mid;
    if (a[right] >= key)return right;
    return n;
}

//greatest common divisor
unsigned long gcd(unsigned long x, unsigned long y){
    if (y == 0){ 
        return x;
    }else if (x > y){
        return gcd(y, x % y);
    }else{
        return gcd(x, y % x);
    }
}

unsigned long lcm(unsigned long x, unsigned long y){
    unsigned long g = gcd(x, y);
    return x*y/g;

}



long long factorial(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i);
    }
    return rtn;
}

/*
int struct_ascending_compare(const void *p, const void *q) {
return ((struct_name*)p)->member_name - ((struct_name*)q)->member_name;
}*/

/*unsigned long long pascal[100][100] = {0};
void make_pascal(void){
    for (int i = 0; i < 100; i++){
        pascal[i][0] = 1;
    }
    pascal[1][1] = 1;
    for (int i = 2; i < 100; i++){
        for (int j = 1; j < 100; j++){
           pascal[i][j] = (pascal[i-1][j-1]+pascal[i-1][j]);
        }
    }
}*/

char field[51][51];
int v[51][51];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
int h, w;
int dfs(int y, int x){
    for (int i = 0; i < 4; i++){
        if (x + dx[i] >= 0 && x + dx[i] < w && y + dy[i] >= 0 && y + dy[i] < h){
            if (field[y + dy[i]][x + dx[i]] == '.' && v[y + dy[i]][x + dx[i]] > v[y][x] + 1){
                v[y + dy[i]][x + dx[i]] = v[y][x] + 1;
                dfs(y + dy[i], x + dx[i]);
            }
        }
    }
    return 0;
}


int main(void){
    int INF = 100000000;
    int cnt = 0;
    scanf("%d %d", &h, &w);
    for (int i = 0; i < 51; i++){
        for (int j = 0; j < 51; j++){
            v[i][j] = INF;
        }
    }
    scanf("%d %d", &h, &w);
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            scanf(" %c", &field[i][j]);
            if (field[i][j] == '#') cnt++;
        }
    }
    v[0][0] = 1;
    dfs(0, 0);
    if (v[h-1][w-1] == INF){
        printf("-1\n");
        return 0;
    }
    printf("%d\n", h*w - v[h-1][w-1] - cnt);

}

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

using vi = std::vector<int>;

int main()
{
	int n, m, Q;
	scanf("%d%d%d", &n, &m, &Q);
	std::vector<vi> table(n + 1, vi(n + 1));
	for (int i{}; i < m; i++)
	{
		int l, r;
		scanf("%d%d", &l, &r);
		table[l][r]++;
	}
	for (int i{}; i <= n; i++)
		for (int j{}; j < n; j++)
			table[i][j + 1] += table[i][j];
	for (int i{}; i <= n; i++)
		for (int j{}; j < n; j++)
			table[j + 1][i] += table[j][i];
	
	for (int i{}; i < Q; i++)
	{
		int p, q;
		scanf("%d%d", &p, &q);
		p--;
		printf("%d\n", table[q][q] + table[p][p] - table[p][q] - table[q][p]);
	}

	return 0;
}

Measured memory_bytes: 1920
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
s = input()
t = input()
num = len(s)
print('Yes' if t[:num] == s else 'No')

Measured memory_bytes: 9060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=1e6;
const int inf=1e9;
int main(){
	int N;cin>>N;
	long A[N+1],B[N+1];
	A[0]=0; B[0]=0;
	long v;
	rep(i,0,N){
		cin>>v;
		A[i+1]=A[i]^v;
		B[i+1]=B[i]+v;
	}
	long cnt=0;
	rep(i,0,N){
		int a=i,b=N+1;
		while(b-a>1){
			if((A[i]^A[(a+b)/2]) == B[(a+b)/2]-B[i]) a=(a+b)/2;
			else b=(a+b)/2;
		}cnt+=a-i;
	}
	cout<<cnt<<endl;
}

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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    
    int result;
    if (b < c || d < a) {
        result = 0;
    } else {
        result = min(b,d) - max(a,c);
    }
    
    cout << result << endl;
}


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


Measured memory_bytes: 2072
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();
		int c = (a+b);
		if(c%2==1) {
			System.out.println(c/2+1);
		}else {
			System.out.println(c/2);
		}
	}

}

Measured memory_bytes: 21844
#include <stdio.h>
#include <stdlib.h>


int main (void){
        long long int N,M;
        scanf("%lld %lld",&N,&M);
        if (N>=2&&M>=2) {
                printf("%lld\n",(N-2)*(M-2) );
        }else if(N==1&&M==1) {
                printf("1\n");
        }else if(N==1) {
                printf("%lld\n",M-2 );
        }else{
                printf("%lld\n",N-2 );
        }

        return 0;
}


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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
typedef long long ll;

int main(){
  int x,y;
  int d[] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
  cin >> x >> y;
  if(d[x]==d[y])cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    ll a, b, k;
    cin >> a >> b >> k;
    ll x = min(a, k);
    a -= x;
    k -= x;
    b -= min(k, b);
    cout << a << " " << b << endl;
    return 0;
}


Measured memory_bytes: 256
h, w = list(map(int, input().split()))
masu = h * w
ans = 0
if h >= 2 and w >= 2:
    if masu % 2 == 0:
        ans = masu/2
    else:
        ans = (masu+1)/2
else:
    ans = 1
print(int(ans))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define STRINGIFY(n) #n
#define TOSTRING(n) STRINGIFY(n)
#define PREFIX "#" TOSTRING(__LINE__) "| "
#define debug(x) \
{ \
  std::cout << PREFIX << #x << " = " << x << std::endl; \
}

std::ostream& output_indent(std::ostream& os, int ind) {
  for(int i = 0; i < ind; i++) os << " ";
  return os;
}

template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p);
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v);

template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p) {
  return (os << "(" << p.first << ", " << p.second << ")");
}
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
  os << "[";
  for(int i = 0;i < v.size();i++) os << v[i] << ", ";
  return (os << "]");
}

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }

int main() {
  i64 N, K;
  cin >> N >> K;
  vector<pair<i64, i64>> vec;
  i64 cnt = 0;
  rep(i,0,N) {
    i64 a = 0;
    cin >> a;
    if(a >= 0) {
      vec.push_back({ a, 0 });
      cnt++;
    }
    else {
      vec.push_back({ -a, 1 });
    }
  }
  const i64 MOD = 1e9 + 7;
  if(cnt == 0) {
    sort(all(vec));
    if(K % 2 == 0) {
      reverse(all(vec));
    }
    i64 ans = 1;
    rep(i,0,K) {
      ans = (ans * ((-vec[i].first + MOD) % MOD)) % MOD;
    }
    cout << ans << endl;
    return 0;
  }
  sort(rbegin(vec), rend(vec));
  vector<vector<i64>> take(2);
  vector<i64> last(2, -1);
  rep(i,0,K) {
    take[vec[i].second].push_back(vec[i].first);
  }
  rep(i,K,N) {
    if(last[vec[i].second] == -1) {
      last[vec[i].second] = vec[i].first;
    }
  }
  if(K != N && take[1].size() % 2 == 1) {
    i64 select = 0;
    if(take[1].size() == 0) {
      select = 1;
    }
    else if(take[0].size() == 0) {
      select = 0;
    }
    else if(last[0] == -1) {
      select = 1;
    }
    else if(last[1] == -1) {
      select = 0;
    }
    else {
      if(last[1] * take[1].back() >= last[0] * take[0].back()) {
        select = 1;
      }
      else {
        select = 0;
      }
    }
    take[select].push_back(last[select]);
    take[1 - select].pop_back();
  }
  i64 ans = 1;
  for(auto x: take[0]) { ans = (ans * x) % MOD;
  }
  for(auto x: take[1]) { ans = (ans * x) % MOD;
  }
  if(take[1].size() % 2 == 1) {
    ans = (-ans + MOD) % MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 10052
import sys
inf = float('inf')

n, m = map(int, sys.stdin.readline().split())
graph = [None] * m
for i in range(m):
  a, b = map(int, sys.stdin.readline().split())
  res = 0
  for c in map(int, sys.stdin.readline().split()):
    res |= 1 << (c - 1)
    graph[i] = (a, res)


def main():
  dp = [[0] * (1 << n) for _ in range(m + 1)]
  for i in range(1, 1 << n):
    dp[0][i] = inf

  for i in range(m):
    for j in range(1 << n):
      dp[i+1][j] = min(dp[i][j ^ (j & graph[i][1])] + graph[i][0], dp[i][j])

  ans = dp[m][(1<<n)-1]
  print(-1 if ans == inf else ans)

if __name__ == '__main__':
  main()

Measured memory_bytes: 147036
#include<stdio.h>
#include<stdlib.h>

struct tree{
  int id;
  int p;
  int d;
  char *type;
  int *c;
  int k;
};

/*int pcheck(struct tree *T,int n, int id){
  int i, j;
  for(i=0; i<n; i++){
    for(j=0; j<T[i].k; j++){
      if(id == T[i].c[j]){
        return T[i].id;
      }
    }
  }
  return -1;
  }*/

int depth(struct tree *T, int d){
  if(T[d].p == -1){
    return 0;
  }
  else{
    return depth(T, T[d].p)+1;
  }
}

int main(){

  int n, i, k, j,cnt, id;
  struct tree *u, a;

  scanf("%d",&n);
  u = (struct tree *)malloc(sizeof(struct tree) * n);
  for(i=0; i<n; i++){
    u[i].p = -1;
  }
  for(i=0; i<n; i++){
    scanf("%d%d", &id, &k);
    u[id].id = id;
    u[id].c = (int *)malloc(sizeof(int) * k);
    u[id].k = k;
    u[id].d = 0;
    for(j=0; j<k; j++){
      scanf("%d", &u[id].c[j]);
      u[u[id].c[j]].p = u[id].id;
    }
  }

  for(i=0; i<n; i++){
    if(u[i].p == -1){
      u[i].type = "root";
    }
    else if(u[i].k!=0){
      u[i].type = "internal node";
    }
    else{
      u[i].type = "leaf";
    }

    u[i].d = depth(u, i);
    printf("node %d: parent = %d, depth = %d, %s, [", u[i].id, u[i].p, u[i].d, u[i].type);
    for(j=0; j<u[i].k-1; j++){
      printf("%d, ", u[i].c[j]);
    }
    if(u[i].k-1==j){
      printf("%d]\n", u[i].c[j]);
    }
    else{
      printf("]\n");
    }
  }

  return 0;
}


Measured memory_bytes: 9132
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iterator>
//#include<math.h>

using namespace std;
#define int long long
/*                      */    //#undef int
#define INF 1000000009
#define INFL 1000000000000000018ll
#define mod 1000000007ll
#define pb push_back
#define fi first
#define se second
#define mk make_pair
typedef pair<pair<int, int> , pair<int, int> > PA;
typedef priority_queue<int> PQ;
typedef priority_queue<PA, vector<PA>, greater<PA> >PQG;

int N;
double T, A;
double ans = 1000000009.0;
int ret;
double abss(double a)
{
    if(a < 0)return -a;
    else return a;
}

signed main()
{
    cin >> N >> T >> A;
    for(int i = 0; i < N; i++){
        double h;
        cin >> h;
        double res = abss(A - (T - h * 0.006));
        if(ans > res){
            ans = res;
            ret = i + 1;
        }
    }
    cout << ret << endl;

    return 0;
}
/*




*/



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define print(x) cout << (x) << endl;
#define printa(x, n) for(ll i = 0; i < n; i++) {cout << (x[i]) << " ";} cout << endl;
using namespace std;
using ll = long long;

const int INF = 1e9 + 7;
vector<vector<int>> dp(1005, vector<int>(10005, INF));

int main(void) {
    
    ll h, n;
    cin >> h >> n;
    int a[n + 1], b[n + 1];
    rep (i, n) cin >> a[i + 1] >> b[i + 1];

    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= h; j++) {
            int tmp = (j + a[i] - 1) / a[i];
            dp[i][j] = min(dp[i - 1][j], tmp * b[i]);
            if (j - a[i] >= 0) {
                dp[i][j] = min(dp[i][j], dp[i][j - a[i]] + b[i]);
            }
        }
    }
    
    cout << dp[n][h] << endl;
    return 0;
}

Measured memory_bytes: 39680
import numpy as np
X = int(input())
ans = 1
for b in range(2, 1+int(np.ceil(np.sqrt(X)))):
    p = 0
    while np.power(b, p) <= X:
        p += 1
    p -= 1
    ans = max(ans, np.power(b, p))
print(ans)


Measured memory_bytes: 12488
A, B, C, D = map(int, input().split())
# takahashi life:A attack:B
# aoki life:C attack:D
while A and C > 0:
    C = C - B
    if C <= 0:
      print("Yes")
      break
    A = A - D
    if A <= 0:
      print("No")
      break

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

bool isposs(char c){
    if(c=='A'||c=='G'||c=='T'||c=='C') return true;
    return false;
}

int main() {

    string s;
    cin>>s;
    ll ans=0;
    ll dp[s.length()+1]{0};

    for(ll i=0;s[i];i++){
        if(i==0){
            dp[i]=isposs(s[i]);
        }
        else{
            if(isposs(s[i]))
                dp[i]=dp[i-1]+1;
            else{
                dp[i]=0;
            }
        }
        ans=max(ans,dp[i]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
N = int(input())
A = []
A.append(list(map(int,input().split())))
A.append(list(map(int,input().split())))
row = 0
top_line = 0
down_line = sum(A[1][:])
ans = 0
for i in range(N):
    top_line=top_line+A[0][i]
    ans = max(ans,top_line+down_line)
    down_line=down_line-A[1][i]

print(ans)

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

using namespace std;

typedef long long ll;

int n;
double arr[102];
double ans;

int main(){
    cin >> n;
    for(int i=1; i<=n; i++) cin >> arr[i];
    for(int i=1; i<=n; i++) ans += 1/arr[i];
    printf("%.8f", 1/ans);
}


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

class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader is = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(is);
		int i = 1;
		boolean b = true;
		while (b) {
			String str = br.readLine();
			if (str.equals("0")) {
				b = false;
			} else {
				System.out.println("Case " + i + ": " + str);
				i++;
			}
		}
	}
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

using namespace std;
using ll = long long;

uint64_t xor64() {
  static uint64_t x = 88172645463325252ULL;
  x = x ^ (x << 13); x = x ^ (x >> 7);
  return x = x ^ (x << 17);
}

int randint(int a, int b) {
  return xor64() % (b - a) + a;
}

double randdouble(double a, double b) {
  return (double)xor64() / ULLONG_MAX;
}

void solve() {
  clock_t start = clock();
  int N; cin >> N;
  vector<ll> X(N), Y(N); rep(i, N) cin >> X[i] >> Y[i];
  vector<bool> used(N);
  ll ans = 0;
  ll curr = 0;
  auto f = [&](ll x, ll y) {
    return x * x + y * y;
  };
  ll sx = 0;
  ll sy = 0;
  int k = 0;
  double elapsed = 0;
  ll cnt = 0;
  while (true) {
    cnt++;
    k++;
    if (k == 1000) {
      elapsed = (clock() - start) / (1.95 * CLOCKS_PER_SEC);
      k = 0;
    }
    if (elapsed >= 1) break;
    int r = randint(0, N);
    ll prev = curr;
    ll tx = used[r] ? sx - X[r] : sx + X[r];
    ll ty = used[r] ? sy - Y[r] : sy + Y[r];
    curr = f(tx, ty);
    ans = max(ans, curr);
    if (curr > prev || randdouble(0, 1) > elapsed) {
      sx = tx;
      sy = ty;
      used[r] = !used[r];
    } else {
      curr = prev;
    }
  }
  cerr << cnt << endl;
  cout << fixed << setprecision(15) << sqrt(ans) << endl;
}

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

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
    int N;
    int M=1;
    int count=0;
    int countM=0;
    bool a=true;
    cin >> N;
    if(N==1){
    }else{
        for(int i=2;i<=N;i+=2){
            int I=i;
            while(a==true){
                if(I%2==1){
                    a=false;
                }else{
                    I/=2;
                    count++;
                    if(count > countM){
                        countM=count;
                        M=i;
                        
                    }
                }
            }
            count=0;
            a=true;
        }
    }
    cout << M <<endl;
return 0;
}


Measured memory_bytes: 256
def main():
    input_data = [int(input()) for i in range(5)]
    k = int(input())

    input_data.sort()
    input_data.reverse()

    temp = input_data[0] - input_data[4]
    if temp > k :
        print(":(")
    else:
        print('Yay!')

if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
import java.util.*;

public class Main {
	
	public static void main(String[] args) {

		//input
		Scanner sc = new Scanner(System.in);
		
		//calculation
		Long ans = 1L;
		for(Long N = sc.nextLong();N>1;N--){
			ans *= N;
		}
		//output
		System.out.println(ans);
	}
}

Measured memory_bytes: 17152
#include<iostream>
using namespace std;
int main(){
  string s, t;
  cin >> s >> t;
  int cnt = 0;
  for(int i =0; i<3; i++){
    if(s[i] == t[i]){
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 384
import sys
sys.setrecursionlimit(1000000)

def search_obj(x,y,grids):
    ans = [0,0]
    curr_state = grids[y][x]
    grids[y][x] = '0'    
    obj_state = '.'
    if(curr_state == '.'):
        ans[0] += 1
        obj_state = '#'
    elif(curr_state == '#'):
        ans[1] += 1
    
    if(grids[y-1][x] == obj_state):
        a,b = search_obj(x,y-1,grids)
        ans[0] += a
        ans[1] += b

    if(grids[y][x-1] == obj_state):
        a,b = search_obj(x-1,y,grids)
        ans[0] += a
        ans[1] += b

    if(grids[y+1][x] == obj_state):
        a,b = search_obj(x,y+1,grids)
        ans[0] += a
        ans[1] += b

    if(grids[y][x+1] == obj_state):
        a,b = search_obj(x+1,y,grids)
        ans[0] += a
        ans[1] += b

    return ans
    

H,W = (int(x) for x in input().split())
s = ""
ans = 0
for _ in range(W+2):
    s+="0"
s = list(s)
grids = [s]

for _ in range(H):
    si = input()
    si = "0"+si+"0"
    grids.append(list(si))
    
grids.append(s)

for i in range(W):
    for j in range(H):
        if(grids[j+1][i+1]!='0'):
            a,b = search_obj(i+1,j+1,grids)
            ans += a*b

print(ans)

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

int main() {
  int a, b, result;
  char op;

  while (true) {
    cin >> a >> op >> b;

    if (op == '?') {
      return 0;
    }

    if (op == '+') {
      result = a + b;
    } else if (op == '-') {
      result = a - b;
    } else if (op == '*') {
      result = a * b;
    } else if (op == '/') {
      result = a / b;
    } else {
      return -1;
    }

    cout << result << endl;
  }
}

Measured memory_bytes: 1160
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=1e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,m,a[1005]={},b[1005]={},c[1005]={},d[105][105]={},ans=0;
  cin >> n >> m;
  for(int i=0; i<n; i++) {
    for(int j=0; j<n; j++) {
      if(i!=j) {
        d[i][j]=INF;
      }
    }
  }
  for(int i=0; i<m; i++) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--,b[i]--;
    d[a[i]][b[i]]=d[b[i]][a[i]]=c[i];
  }
  for(int i=0; i<n; i++) {
    for(int j=0; j<n; j++) {
      for(int k=0; k<n; k++) {
        if(i!=j&&i!=k&&j!=k) {
          d[j][k]=min(d[j][k],d[j][i]+d[i][k]);
        }
      }
    }
  }
  for(int i=0; i<m; i++) {
    if(d[a[i]][b[i]]<c[i]) {
      ans++;
    }
  }
  cout << ans << endl;
}



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


#define M 1000000007
#define pb push_back
#define mp make_pair
#define s second
#define f first
#define mod 998244353
#define sz(v) (int)(v).size()

#define pii pair<int, int>
#define vi vector<int>
#define ll long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)

ll add(ll a,ll b)
{
	a%=M;
	b%=M;
	ll p = (a+b)%M;
	return (p+M)%M;
}

ll mul(ll a,ll b)
{
	a%=M;
	b%=M;
	ll p = (a*b)%M;
	return (p+M)%M;
}


int main()
{
	fastio;
	ll i,n,a[200010];
	cin>>n;
	ll cur=1;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		if(a[i]==cur)
			cur++;
	}
	if(cur==1)
		cout<<"-1"<<endl;
	else
		cout<<n-cur+1<<endl;
    return 0;
}





Measured memory_bytes: 5208
#include <iostream>
using namespace std;
int main(void){
    int n,m;
    cin>>n>>m;
    while(n>=500){
        n=n-500;
    }
    if(n<=m){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}


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

using ll = long long;
const int INF = 1e9+100;

const int S = 4e5;
int rcnt[S] = {0};
int ccnt[S] = {0};
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	set<pair<int,int>> m;
	int h, w, n;
	cin>>h>>w>>n;
	int mxr = 0, mxc = 0;
	for (int i = 0; i < n; i++){
		int x, y;
		cin>>x>>y;
		rcnt[y]++;
		ccnt[x]++;
		mxr = max(rcnt[y], mxr);
		mxc = max(ccnt[x], mxc);
		m.emplace(x, y);
	}
	vector<int> mxRows, mxCols;
	for (int i = 0; i < S; i++){
		if (rcnt[i] == mxr){
			mxRows.push_back(i);
		}
		if (ccnt[i] == mxc){
			mxCols.push_back(i);
		}
	}
	for (auto &it: mxRows){
		for (auto &itt: mxCols){
			if (m.count({itt, it}) == 0){
				cout<<mxr+mxc<<'\n';
				return 0;
			}
		}
	}
	cout<<mxr+mxc-1<<'\n';
		
	return 0;
}

// bool f = 1;
			// for (auto &itt: it.second){
			// 	if (p.count(itt) == 0){
			// 		cout<<rmax+cmax<<'\n';
			// 		return 0;
			// 	}
			// }


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

int main(){
  long long A, B, C, D;
  cin >> A >> B >> C >> D;
  //C<Dの最大公約数
  long long E = max(C,D);
  long long F = min(C,D);
  long long r = E%F;
  while(r!=0){
    E = F;
    F = r;
    r = E%F;
  }
  long long LCM = C * D / F;
  long long ans = (B-A+1)-(B/C-(A-1)/C)-(B/D-(A-1)/D)+(B/LCM-(A-1)/LCM);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;

int main(){
	int n;
	cin >> n;
	vector<int> a(n+1);
	for(int i = 0;i < n+1;i++)cin >> a[i];
	vector<int> b(n);
	for(int i = 0;i < n;i++)cin >> b[i];

	ll ans = 0;
	for(int i = 0;i < n;i++){
		int l = min(b[i],a[i]);
		a[i] -= l;
		b[i] -= l;
		ans += l;
		int r = min(b[i],a[i+1]);
		a[i+1] -= r;
		ans += r;
	}

	cout << ans << endl;
}


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

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

using namespace std;
const int INF = 1000000000;
int h,w;

int func(const vector<pair<int,int>>& v, int f, int t,
    const vector<vector<int>>& d,
    vector<vector<int>>& memo, bool fst = false) {
  if (memo[f][t] >= 0) return memo[f][t];
  int mxn = 0;
  vector<pair<int,int>> nv;
  for(auto p:v) {
    int fp,tp;
    tie(fp,tp) = p;
    if (d[f][fp] < INF && d[tp][t] < INF) {
      if (f == fp && !fst) continue;
      nv.push_back(p);
    }
  }
  for (auto p:nv) {
    int fp,tp;
    tie(fp,tp) = p;
    mxn = max(mxn, func(nv, fp, tp, d, memo) + func(nv, tp, t, d, memo) + 1);
  }
  return memo[f][t] = mxn;
}


int main() {
  while(1){
    cin>>h>>w;
    if(!h) break;
    vector<string> m(h+1, string(w+1, '#'));
    REP(i,h) {
      string l;
      cin>>l;
      m[i] = l + "#";
    }
    int n = h*w;
    vector<vector<int>> d(n, vector<int>(n,INF));
    d[0][0] = 0;
    d[n-1][n-1] = 0;
    REP(i,h)REP(j,w) {
      int ind = i*w+j;
      if (m[i][j] != '#') {
        if (m[i+1][j] != '#') d[ind][ind + w] = 1;
        if (m[i][j+1] != '#') d[ind][ind + 1] = 1;
      }
    }
    REP(i,n)REP(j,n) {
      int ji=j/w, jj=j%w;
      if (ji > 0)
        d[i][j] = min(d[i][j], d[i][j-w] + d[j-w][j]);
      if (jj > 0)
        d[i][j] = min(d[i][j], d[i][j-1] + d[j-1][j]);
    }
    int diff = 'A' - 'a';
    vector<pair<int, int>> v;
    REP(i,n)REP(j,n) {
      int ii=i/w, ij=i%w;
      int ji=j/w, jj=j%w;
      if (m[ii][ij] < 'a' || 'z' < m[ii][ij]) continue;
      if (d[i][j] < INF && m[ii][ij] + diff == m[ji][jj]) v.emplace_back(i,j);
    }
    vector<vector<int>> memo(n, vector<int>(n, -1));
    if (d[0][n-1] < INF)
      cout << func(v, 0, n-1, d, memo, true) << endl;
    else
      cout << "-1" << endl;
  }
  return 0;
}

Measured memory_bytes: 50204
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

def main():
  n, m = map(int, input().split())
  ipy = [(i+1, )+(tuple(map(int, input().split()))) for i in range(m)]
  ipy.sort(key=lambda x:x[2])
  kens = set([p for i,p,y in ipy])
  di = {ken:0 for ken in kens}

  ans = []
  for i,p,y in ipy:
    di[p] += 1
    number = ('%06d%06d' % (p, di[p]))
    ans += [(i, number)]
  ans.sort(key=lambda x:x[0])

  for _, number in ans:
    print(number)
  pass

if __name__=='__main__':
  main()

Measured memory_bytes: 47728
#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug  freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
#define pb push_back
#define all(x) x.begin(),x.end()
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
const int maxn = 1e6+10;
const int maxM = 1e6+10;
const int inf = 0x3f3f3f3f;
const ll inf2 = 0x3f3f3f3f3f3f3f3f;


int N,M,K;
ll w1[maxn],w2[maxn];
void solve(){
    int ans = 0;
    for(int i = 1;i<=M;i++) w2[i] += w2[i-1];
    int idx = upper_bound(w2+1,w2+M+1,K) - w2;
    ans = idx-1;
    for(int i =1;i<=N;i++){
        if(K>=w1[i]){
            K-=w1[i];
            int idx = upper_bound(w2+1,w2+M+1,K) - w2;
            ans = max(ans,i + idx-1);
        }else break;
    }
    cout<<ans<<'\n';
}
int main(){
//    debug;
    ios;

    cin>>N>>M>>K;
    for(int i =1;i<=N;i++) cin>>w1[i];
    for(int i =1;i<=M;i++) cin>>w2[i];
    solve();


    return 0;
}

Measured memory_bytes: 6784
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
int main(void){
    int n, z=0;
    ll a[100000], b[100000], c[100000];
    vector<int> v;
    cin>>n;
    v.push_back(0);
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]>a[z]){
            z=i;
            v.push_back(i);
        }
        b[i]=0;
        c[i]=0;
    }
    for(int i=0;i<n;i++){
        if(a[i]<=a[0]){
            b[0]+=a[i];
            continue;
        }
        int l=0, r=v.size()-1;
        while(l+1<r){
            int m=(l+r)/2;
            if(a[v[m]]<=a[i]){
                l=m;
            }else{
                r=m;
            }
        }
        c[l]++;
        b[v[r]]+=a[i]-a[v[l]];
    }
    for(int i=v.size()-1;i>=0;i--){
        if(i<v.size()-1)c[i]+=c[i+1];
        if(i>0){
            b[v[i]]+=c[i]*(a[v[i]]-a[v[i-1]]);
        }else{
            b[v[i]]+=c[i]*a[v[i]];
        }
    }
    for(int i=0;i<n;i++){
        cout<<b[i]<<endl;
    }
}


Measured memory_bytes: 3960
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<ctime>
#define INF 1e9
using namespace std;
const int maxn=123;
int n,r,d;
int main()
{
	scanf("%d%d",&n,&r);
	if(n>=10)
		d=r;
	else
		d=r+100*(10-n);
	printf("%d",d);
	return 0;
}

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

using namespace std;

int a[100005];

int main()
{
    int n, k, q;
    cin>>n>>k>>q;


    int temp;
    for(int i=1; i<=q; i++)
    {
        cin>>temp;
        a[temp]++;
    }

    int minreq = q-k;

    for(int i=1; i<=n; i++)
    {
        //if(q>=k)
        //{
            if(a[i]<=minreq )    cout<<"No"<<endl;
            else    cout<<"Yes"<<endl;
        //}
        //else    cout<<"Yes"<<endl;
    }

    return 0;
}

Measured memory_bytes: 1024
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}
}

use input::*;

fn main() {
    let (n, m): (usize, usize);
    input!(n, m);
    let mut v = vec![vec![999999999; n]; n];
    let mut input_str = vec![];
    for _ in 0..m {
        let (a, b, c): (usize, usize, isize);
        input!(a, b, c);
        input_str.push((a - 1, b - 1, c));
        v[a - 1][b - 1] = c;
        v[b - 1][a - 1] = c;
        v[a - 1][a - 1] = 0;
        v[b - 1][b - 1] = 0;
    }

    for k in 0..n {
        for i in 0..n {
            for j in 0..n {
                v[i][j] = std::cmp::min(v[i][j], v[i][k] + v[k][j]);
            }
        }
    }

    let mut ans = 0;

    for (a, b, c) in input_str {
        let mut flag = true;
        for i in 0..n {
                if v[a][i] == v[b][i] + c{
                    flag = false;
                    break;
                }
        }
        if flag {
            ans += 1;
        }
    }

    p(ans);
}

Measured memory_bytes: 4352
#include <vector>
#include <iostream>
#include <string>
#include <unordered_map>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <cstdio>
#include <cmath>
#include <utility>
#include <bitset>
#include <complex>
#include <stack>
#include <tuple>
#include <math.h>
 
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll INF = 1e15;
const double eps=1e-8;
const ll MOD = (1e9)+7;
const ll MAX_N = 1 << 17;

int main(){
	ll N;
	cin >> N;
	vector<ll> A(N);
	ll sum=0;
	for(ll i=0;i<N;i++){
		cin >> A[i];
		sum+=A[i];
	}
	ll one=N*(N+1)/2;
	if(sum%one!=0){
		cout << "NO" << endl;
	}else if(N==1){
		cout << "YES" << endl;
	}else{
		ll num=sum/one;
		ll cul=0;
		bool ok=true;
		for(ll i=0;i<N;i++){
			ll before=(i-1+N)%N;
			cul+=(num-(A[i]-A[before]))/N;
			if((num-(A[i]-A[before]))%N!=0 || num-(A[i]-A[before])<0)
				ok=false;
		}
		if(ok && (cul==num))
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef vector<int>Vl;
typedef pair<int,int>pii;
typedef vector<pii>Vll;
typedef vector<pair<int,pair<int,int> > >Vlll;
#define S second
#define F first
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define sl(n) cin>>n 
#define pl(n) cout<<n<<" "
const int Nx=2e5+2;
const int inf=(int)(1e19+10LL);
void solve()
{
 string str;
 sl(str);
 reverse(str.begin(),str.end());
 int n=str.length();
 vector<int>dp(2019,0);
 int m=2019;
 int total=0,x=1,ans=0;
 for(int i=0;i<n;i++){
 	dp[total]++;
 	total+=((str[i]-'0')*x);
 	total=total%m;
 	 ans+=dp[total];
 	//dp[total]++;
 	x=(x*10)%m;
 }
 cout<<ans<<endl;

}

signed main(){
  int test=1;
// sl(test);
 while(test--){
 	solve();
 }
 
}

Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

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

/*-------------------------------------------*/

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

    int Q;
    cin >> Q;
    rep(_, Q) {
        ll A, B;
        cin >> A >> B;
        if(A > B) swap(A, B);
        if(A >= B - 1)
            cout << 2 * A - 2 << endl;
        else {
            ll x = sqrt(A * B);
            if(x * x >= A * B) x--;
            cout << 2 * x - (x * (x + 1) < A * B ? 1 : 2) << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>
#include <stack>
#include <bitset>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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(a>b){a=b;return 1;}return 0;}

//0 mada 1 kanousei 2 zettai nai
int possible[1000100];

template <typename T>
class UnionFind {
public:
  T n;
  vector <T> d;
  UnionFind(T n) :d(n, -1) {} 
  int find(T x){
    if(d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(T x, T y){
    x = find(x);
    y = find(y);
    if(x == y) return false;
    if(d[y] < d[x]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  int size(T x){ return -d[find(x)];}
  bool same(T x, T y){
    return find(x) == find(y);
  }
};

ll answer[1000100];


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

  int n, m;
  cin >> n >> m;

  UnionFind<int> uf = UnionFind<int>(n+1);

  
  REP(i, m){
    ll x, y, z;
    cin >> x >> y >> z;
    uf.unite(x, y);
  }
  
  ll ans = 0LL;

  
  FOR(i,1,n+1){
    int val = uf.find(i);
    if(answer[val] == 0){
      ans++;
      answer[val]++;
    }
  }

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


Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <map>

typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
using namespace std;

int main() {
    int N;
    ll A[200001] = {};
    cin >> N;
    REP(i, N) {
        int a;
        cin >> a;
        A[i + 1] = A[i] + a;
    }

    map<ll, int> count;
    REP(i, N + 1)
        count[A[i]]++;
    ll ans = 0;
    for (auto p : count) {
        if (p.second != 1)
            ans += (ll)p.second * (p.second - 1) / 2;
    }

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

Measured memory_bytes: 14336
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

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

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
ll countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}
int to_num(char c) {
	if (c >= '0' && c <= '9')return (c - '0');
	else return -1;
}

int main() {
	int n;
	cin >> n;
	vector<int> t(n);
	int sum = 0;
	REP(i, n) {
		cin >> t[i];
		sum += t[i];
	}
	int m;
	cin >> m;
	int x, y; 
	REP(i,m){
		cin >> x >> y;
		cout << sum - t[x - 1] + y << endl;
	}

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define HEAP(...) priority_queue<__VA_ARGS__ >
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > > 
#define pii pair<int,int> 
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define dprintf(...) fprintf(stderr,__VA_ARGS__)
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#define SZ(x) ((int)x.size())
using namespace std;
template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
const int BufferSize=1<<16;
char buffer[BufferSize],*Bufferhead,*Buffertail;
bool Terminal;
inline char Getchar(){
	if(Bufferhead==Buffertail){
		int l=fread(buffer,1,BufferSize,stdin);
		if(!l){Terminal=1;return 0;}
		Buffertail=(Bufferhead=buffer)+l;
	}
	return *Bufferhead++;
}
template<class T>inline bool read(T &x){
	x=0;char c=Getchar(),rev=0;
	while(c<'0'||c>'9'){rev|=c=='-';c=Getchar();if(Terminal)return 0;}
	while(c>='0'&&c<='9') x=x*10+c-'0',c=Getchar();
	if(c=='.'){
		c=Getchar();double t=0.1;
		while(c>='0'&&c<='9') x=x+(c-'0')*t,c=Getchar(),t=t/10;
	}
	x=rev?-x:x;
	return 1;
}
template<class T1,class T2> inline bool read(T1 &x,T2 &y){return read(x)&read(y);}
template<class T1,class T2,class T3> inline bool read(T1 &x,T2 &y,T3 &z){return read(x)&read(y)&read(z);}
template<class T1,class T2,class T3,class T4> inline bool read(T1 &x,T2 &y,T3 &z,T4 &w){return read(x)&read(y)&read(z)&read(w);}
inline bool reads(char *x){
	char c=Getchar();
	while(c<33||c>126){c=Getchar();if(Terminal)return 0;}
	while(c>=33&&c<=126) (*x++)=c,c=Getchar();
	*x=0;return 1;
}
template<class T>inline void print(T x,const char c='\n'){
	if(!x){putchar('0');putchar(c);return;}
	if(x<0) putchar('-'),x=-x;
	int m=0,a[20];
	while(x) a[m++]=x%10,x/=10;
	while(m--) putchar(a[m]+'0');
	putchar(c);
}
//--------------------------------head---------------------------------------------

const int inf=0x3f3f3f3f;
const int N=100005,M=100005,mod=1e9+7;
template<class T,class S> inline void ch(T &x,const S y){x=(x+y)%mod;}
inline int exp(int x,int y,const int mod=::mod){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

int n,m,col[N],cnt[2];
vi g[N];
bool isok,vis[N];
ll ans=0;

inline void dfs(int x,int c){
	if(vis[x]){
		if(col[x]!=c) isok=0;
		return;
	}
	cnt[c]++;col[x]=c;
	vis[x]=1;
	for(int y:g[x])
		dfs(y,c^1);
}

int main(){
#ifdef rqgao2014
	freopen("input.txt","r",stdin);
#endif
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		int x,y;scanf("%d%d",&x,&y);
		g[x].pb(y);g[y].pb(x);
	}
	for(int i=1;i<=n;i++)
		if(!vis[i]){
			clr(cnt,0);isok=1;
			dfs(i,0);
			if(isok) ans+=(ll)cnt[0]*cnt[1]; else ans+=(ll)(cnt[0]+cnt[1])*(cnt[0]+cnt[1]-1)/2;
		}
	printf("%lld\n",ans-m);
	return 0;
}

Measured memory_bytes: 6528
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
	int n, d, x;
	cin >> n >> d >> x;
	int a[110];
	rep(i, n) {
		cin >> a[i];
	}
	int ans = 0;
	rep(i, n) {
		for (int j = 0; j < d; ++j) {
			int xx = j * a[i] + 1;
			if (xx > d) {
				break;
			}
			ans++;
		}
	}
	ans += x;
	cout << ans << endl;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	while(true){
		ll N=in();
		if(!N) break;

		vector<pair<ll,double>> P(N);
		REP(i,N){
			P[i].first=in();
			ll H=in(),W=in();
			P[i].second = abs(22-10000.0*W/(H*H));
		}
		sort(ALL(P),[](pair<ll,double>& l,pair<ll,double>& r){return l.second==r.second ? l.first<r.first : l.second<r.second;});
		out(P[0].first);
	}
	
	return 0;
}



Measured memory_bytes: 3060
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;
#define n_max 10000
#define INF 10001000

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep2(i,a,n) for(int i = a; i < (n); i++)
#define in(a) cin >> a
#define out(a) cout << a << endl
typedef long long ll; 

int main()
{
    int ans = 0;
    int p,q,r;

    cin >> p >> q >> r;
    int a = max(p,max(q,r));
    cout << p+q+r - a << endl;

    return 0;
}


Measured memory_bytes: 256
/**
 *    author:  tourist
 *    created: 09.01.2020 00:03:40       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<vector<int>> g(n);
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  function<int(int, int)> Dfs = [&](int v, int pr) {
    int d = 1;
    for (int u : g[v]) {
      if (u == pr) {
        continue;
      }
      d -= Dfs(u, v);
    }
    if (d < 0 || (v == 0 && d == 1)) {
      cout << "First" << '\n';
      exit(0);
    }
    return d;
  };
  Dfs(0, -1);
  cout << "Second" << '\n';
  return 0;
}


Measured memory_bytes: 5888
#include<iostream>
#include<array>
#include<algorithm>
using namespace std;

int main(){

	array<int, 3> temp;
	for (auto& a : temp) {
		cin >> a;
	}
	if ( temp[0] < temp[1] && temp[1] < temp[2]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <string>
int main(int argc, char const *argv[]) {
  int A,B;
  std::string result;
  std::cin >> A>>B;
  if(A == 1) A = 14;
  if(B == 1) B = 14;
  if(A>B) result = "Alice";
  else if(A<B) result = "Bob";
  else result = "Draw";
  std::cout << result << '\n';
  return 0;
}


Measured memory_bytes: 256