akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <assert.h>
#include <algorithm>
#include <vector>
#include <string>

struct union_find{
  std::vector<int> par;
  union_find(int N) {
    for (int i = 0; i < N; i++) {
      par.push_back(i);
    }
  }

  int root(int x) {
    if (par[x] == x) {
      return x;
    } else {
      par[x] = root(par[x]);
      return par[x];
    }
  }

  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx != ry) {
      if (rx < ry) {
        par[ry] = rx;
      } else {
        par[rx] = ry;
      }
    }
    return;
  }
};

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

  int N, M;
  std::cin >> N >> M;
  union_find uf(N);
  
  for (int i = 0; i < M; i++) {
    int X, Y, Z;
    std::cin >> X >> Y >> Z;
    uf.unite(X-1, Y-1);
  }
  int res = 0;
  for (int i = 0; i < N; i++) {
    if (i == uf.root(i)) {
      res++;
    }
  }
  std::cout << res << std::endl;

  return 0;
}


Measured memory_bytes: 892
#include <stdio.h>

int main (){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if(x+r<=W  &&  x-r>=0  &&  y+r<=H  &&  y-r>=0){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    
    return 0;
}

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

typedef long long ll;

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

    int n, m;
    cin >> n >> m;
    ll h[n];
    for(int i = 0; i < n; ++i) 
        cin >> h[i];
    vector<vector<int>> mp(n);
    while(m--) {
        int a, b;
        cin >> a >> b;
        mp[a-1].push_back(b);
        mp[b-1].push_back(a);
    }

    int ans = 0;
    bool b = 1;
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < mp[i].size(); ++j) {
            if(h[i] <= h[mp[i][j] - 1]) {
                b = 0;
                break;
            }
        }
        if(b) 
            ++ans;
        b = 1;
    }

    cout << ans << '\n';

    return 0;
}



Measured memory_bytes: 9272
#include <vector>
#include <cassert>
#include <iostream>
using namespace std;

const int mod = 1000000007;

int main()
{
    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<int> > dp(h+1, vector<int>(w,0));
    dp[0][0] = 1;
    for(int i=0; i<h; i++)
    {
        for(int j=0; j<w; j++)
        {
            for(int k=0; k < 1 << (w-1); k++)
            {
                bool ok = true;
                for(int l=0;l<w-2;l++)
                {
                    if(((k>>l)&1) && ((k >> (l+1))&1)) ok = false;
                }
                if(ok)
                {
                    if(j >= 1 && ((k >> (j-1))&1))
                    {
                        dp[i+1][j-1] += dp[i][j];
                        dp[i+1][j-1] %= mod;
                    }
                    else if(j <=w-2 && ((k >> j) & 1))
                    {
                        dp[i+1][j+1] += dp[i][j];
                        dp[i+1][j+1] %= mod; 
                    }
                    else
                    {
                        dp[i+1][j] += dp[i][j];
                        dp[i+1][j] %= mod;
                    }
                }
            }
        }
    }
    cout << dp[h][k-1] << endl;
    return 0;
}

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

#define rep(X,N) for(ll X = 0LL; X < (N); X++)
#define ALL(V) (V).begin(),(V).end()
#define endl "\n"

using namespace std;
typedef long long ll;

const double PI = 3.1415926535897932384626;
const ll MODN = 1000000007;
const ll MODN2 = 998244353;
const double EPS = 1e-10;

int main(){

    string s;
    cin >> s;

    int size = s.size();
    int count = 0;

    vector<int> xcount;
    vector<char> notx;

    rep(i, size){
        if(s[i] == 'x'){
            count++;
        }else{
            notx.push_back(s[i]);
            
            xcount.push_back(count);
            count = 0;
        }
    }

    xcount.push_back(count);

    int ans = 0;

    rep(i, xcount.size() / 2){
        ans += max(xcount[i], xcount[xcount.size() - 1 - i]) - min(xcount[i], xcount[xcount.size() - 1 - i]);
    }

    rep(i, notx.size()){
        if(notx[i] != notx[notx.size() - 1 - i]){
            ans = -1;
            break;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4036
#define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cctype>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
#include <utility>
#include <numeric>
using namespace std;
const int INF=1<<30;

typedef pair<int,int> P;

int main(){
	
	int n,a,b;
	cin>>n>>a>>b;
	int ans=0;
	int t;
	for(int i=0;i<n;i++){
		cin>>t;
		if(t<a||t>=b)
		 ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.readline().split()))
def FI(): return list(map(float, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): pass
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


n = I()
p = FI()
dp = [0] * (n + 2)
dp[0] = 1
for i in range(n):
    for j in range(i + 1, -1, -1):
        dp[j] = dp[j - 1] * p[i] + dp[j] * (1 - p[i])


print(sum(dp[n // 2 + 1:]))


Measured memory_bytes: 78176
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	var grid [100][100]int

	a := getNextInt64(scanner)
	b := getNextInt64(scanner)

	paint := 1
	lc, mc := a, b
	if a > b {
		paint = 0
		lc, mc = b, a
		for y := 0; y < 100; y++ {
			for x := 0; x < 100; x++ {
				grid[y][x] = 1
			}
		}
	}

	for y := 2; y < 98; y += 4 {
		c := 0
		for x := 1; x < 99 && mc > 0; x += 2 {
			grid[y][x] = paint
			c++
			mc--
			if c%2 == 0 {
				if lc == 1 {
					continue
				}
				grid[y-1][x] = paint
				grid[y+1][x] = paint
				if c == 2 {
					grid[y-1][x-2] = paint
					grid[y+1][x-2] = paint
					mc++
				}
				for dx := -1; dx <= 1 && lc > 1; dx += 2 {
					for dy := -1; dy <= 1; dy += 2 {
						grid[y+dy][x+dx] = paint
					}
					lc--
				}
			}
		}
	}

	fmt.Fprintln(writer, fmt.Sprintf("%d %d", 100, 100))

	for y := 0; y < 100; y++ {
		for x := 0; x < 100; x++ {
			if grid[y][x] == 0 {
				fmt.Fprint(writer, ".")
				continue
			}
			fmt.Fprint(writer, "#")
		}
		fmt.Fprintln(writer, "")
	}

	writer.Flush()
}


Measured memory_bytes: 896
lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

D = lines[0][0]
Inf = 10 ** 10

last_date = []
for i in 1..26 do
  last_date.push(0)
end

for i in 1..D do
  max_satis = - Inf
  best_contest = 0
  for k in 1..26 do
    now_satis = 0
    now_satis += lines[i+1][k-1]
    for j in 1..26 do
      if j != k then
        now_satis -= (i - last_date[k-1]) * lines[1][j-1]
      end
    end
    now_satis += lines[1][k-1] * 325
    if now_satis > max_satis then
      max_satis = now_satis
      best_contest = k
    end
  end
  last_date[best_contest-1] = i
  if i < D then
    puts best_contest
  else
    print best_contest
  end
end

Measured memory_bytes: 14388
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int number = sc.nextInt();
    int[] count = new int[number];
    int[] data = new int[110];
    for (int i = 0; i < number; i++) {
      count[i] = sc.nextInt();
    }
    for (int i = 0; i < number; i++) {
      data[count[i]]++;
    }
    int answer = 0;
    for (int i = 1; i <= 100; i++) {
      if (data[i] > 0) {
        answer++;
      }
    }
    System.out.println(answer);
                          
  }
}

Measured memory_bytes: 22356
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main(void){
  int n;
  int a;
  vector<int> v;
  ll max = 0;
  cin >> n;
  for(int i = 0; i < 3 * n; i++){
    cin >> a;
    v.push_back(a);
  }
  sort(v.begin(), v.end(), greater<int>());
  for(int i = 1; i < 2 * n; i += 2) max += v[i];
  cout << max << endl;
  return 0;
}


Measured memory_bytes: 2420
def main():
    n,m = map(int,input().split(" "))
    hs = list(map(int,input().split(" ")))
    check = [True]*n
    for i in range(m):
        a,b = map(int,input().split(" "))
        if hs[a-1] < hs[b-1]:
            check[a-1] = False
        elif hs[b-1] < hs[a-1]:
            check[b-1] = False
        elif hs[a-1] == hs[b-1]:
            check[a-1] = False
            check[b-1] = False
    
    print(check.count(True))
main()

Measured memory_bytes: 20124
import java.util.Scanner;


public class Main{
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNextInt()) {
			int[] result = weights(sc.nextInt());
			printArray(result);
		}
		sc.close();
	}
	
	static int[] weights(int weight) {
		int[] result = new int[10];
		int remain = weight;
		for(int i = 9; i >= 0; i--) {
			result[i] = remain/pow2(i);
			remain = remain - result[i] * pow2(i);
		}
		return result;
	}
	
	static int pow2(int n) {
		int result = 1;
		for(int i = 0; i < n; i++) {
			result *= 2;
		}
		return result;
	}
	
	static void printArray(int[] array) {
		int i;
		for(i = 0; i < array.length; i++) {
			if(array[i] != 0) {
				System.out.print((array[i] * pow2(i)));
				i++;
				break;
			}
		}
		for(;i < array.length; i++) {
			if(array[i] != 0) {
				System.out.print(" " + (array[i] * pow2(i)));
			}
		}
		System.out.println();
	}
}

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

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

int main(void){
  int N, i;
  scanf("%d", &N);
  int A[N];
  
  for(i = 0; i < N; ++i)
     scanf("%d", &A[i]);
  
  qsort(A, N, sizeof(int), comfun);
  
  int arr[1000001] = {0}, ans = 0;
  
  for(i = 0; i < N; ++i){
    
    if(arr[A[i]] == 0){
      ++ans;
      for(int j = 1; j * A[i] <= 1000000; ++j)
        arr[j * A[i]] = 1;
      if(i < N - 1){
        if(A[i] == A[i + 1])
          --ans;
      }
    }
    
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 6400
def main():
    from sys import stdin, setrecursionlimit
    setrecursionlimit(10**6)
    r = stdin.readline()[:-1]
    #n = int(stdin.readline()[:-1])   
    #r = [stdin.readline() for i in range(n)]
    #t = [int(stdin.readline()) for i in range(n)]

    n, i = map(int, r.split())
    print(n-i+1)

if __name__ == '__main__':
    main()



Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
using namespace std;

int main(){
    // あとで消す
    //std::ifstream in("ain2.txt");
    //std::cin.rdbuf(in.rdbuf());

    string S,T,U;
    int A,B;
    cin >> S >> T;
    cin >> A >> B;
    cin >> U;

    if(S==U){
        cout << A-1 << ' ' << B << endl;
    }else{
        cout << A << ' ' << B-1 << endl;
    }
    

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
	long ans=1,i=1;
	string str,temp1,temp2;
	cin>>str;
	temp2.push_back(str.at(0));
	while(i<str.size()){
		temp1=temp2;
		temp2.erase(temp2.begin(),temp2.end());
		while(i<str.size()){
			temp2.push_back(str.at(i));
			i++;
			if(temp1!=temp2){
				//cout<<temp1<<endl;
				ans++;
				break;
			}
		}
	}
	//cout<<temp2<<endl;
	cout<<ans;
	return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define ll long long
#define double long double
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define ALL(V) ((V).begin(),(V).end())
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LaL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
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;}
using namespace std;

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

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

int main(void) {
    int N = 0;
    int *a = NULL;

    scanf("%d", &N);

    a = calloc(N, sizeof(int));

    int i;
    for (i = 0; i < N; i++) {
        scanf("%d", &(a[i]));
    }

    int friend = 0;

    for (i = 0; i < N; i++) {
        //printf("i = %d; a[i] = %d; a[a[i]] = %d;\n", i, a[i], a[a[i]]);
        if (a[a[i] - 1] == i + 1) {
            friend++;
        }
    }

    friend /= 2;

    printf("%d\n", friend);

    return EXIT_SUCCESS;
}


Measured memory_bytes: 512
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

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

	cin >> N;
	vector<long long int>v(N);
	for (int i = 0; i < N; i++)cin >> v[i];
	long long int odd = 0;
	long long int even = 0;
	for (int i = 1; i < N; i += 2) {
		odd += max(0LL, v[i]);
	}
	for (int i = 0; i < N; i += 2) {
		even += max(0LL, v[i]);
	}
	vector<int>ans;
	if (!odd && !even) {
		while (v.size() > 1) {
			if (v.front() < v.back()) {
				ans.push_back(1);
				v.erase(v.begin());
			}
			else {
				ans.push_back(v.size());
				v.pop_back();
			}
		}
		cout << v.front() << endl;
		cout << ans.size() << endl;
		for (auto i : ans)cout << i << endl;
		return 0;
	}
	//cout << odd << " " << even << endl;
	if (odd > even) {
		if (N % 2 == 0) {
			if (v.back() < 0) {
				ans.push_back(N);
				N--;
			}
		}
		for (int i = N - 1 - ((N - 1) % 2 == 0); i >= 0; i -= 2) {
			if (v[i] < 0) {
				ans.push_back(i + 1);
				N -= 2;
			}
		}
		ans.push_back(1);
		N--;
		while (N > 1) {
			ans.push_back(2);
			N -= 2;
		}
	}
	else {
		if (N % 2) {
			if (v.back() < 0) {
				ans.push_back(N);
				N--;
			}
		}
		for (int i = N - 1 - ((N - 1) % 2); i > 0; i -= 2) {
			if (v[i] < 0) {
				ans.push_back(i + 1);
				N -= 2;
			}
		}
		if (v[0] < 0) {
			ans.push_back(1);
			ans.push_back(1);
			N -= 2;
		}
		while (N > 1) {
			ans.push_back(2);
			N -= 2;
		}
	}
	cout << max(odd, even) << endl;
	cout << ans.size() << endl;
	for (auto i : ans)cout << i << endl;
	return 0;
}

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

using namespace std;

#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define _repis(i,a,b,s) for(int i=a, i##_len(b); i<i##_len; i+=s)
#define REP(...) _overload3(__VA_ARGS__,_repis,_repi,_rep,)(__VA_ARGS__)

#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < v.size();++i)

#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl
#define POSS(n) cout<<((n)?"POSSIBLE":"IMPOSSIBLE")<<endl

int main(){
    int a,b;
    cin>>a>>b;
    if(a+b==15){
        cout<<"+\n";
    }else if(a*b==15){
        cout<<"*\n";
    }else{
        cout<<"x\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
  int n,i,j,k;
  scanf("%d %d",&n,&k);
  vector<int>a(n);
  vector<int>dp(n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  auto isValid = [&](int i){
    if(i<n)
      return true;
    return false;
  };
  dp[n-1] = 0;
  for(i=n-2;i>=0;i--){
    dp[i] = dp[i+1] + abs(a[i+1] - a[i]);
    for(j=i+2;j<=i+k;j++){
      if(isValid(j)){
        dp[i] = min(dp[i],dp[j] + abs(a[j] - a[i]));
      }
    }
  }
  printf("%d\n",dp[0]);
}

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

using namespace std;


long long MOD = 1000000007;

void solve() {
    long long N, K; cin >> N >> K;

    long long ans = 0;
    for (long long k = K; k <= N+1; k++) {
        long long left = k * (k-1) / 2;
        long long right = (N + N-(k-1)) * k / 2;
        ans += right - left + 1;
        ans %= MOD;
    }

    cout << ans << endl;
}


int main() {
    solve();
    return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
using ll=long long;
using namespace std;


vector<ll> p;
vector<ll> m;
int state;
ll zero;
ll K;
ll cnt(ll x){
    ll res=0;
    if(state){
        int ps=p.size();
        int ms=m.size();
        int pt=0;
        for(int i=ps-1;i>=0;i--){
            while(pt<ms){
                if(p[i]*m[pt]<x){
                    pt++;
                }else{
                    res+=ms-pt;
                    break;
                }
            }
        }
    }else{
        int ps=p.size();
        int pt=ps-1;
        for(int i=0;i<ps;i++){
            while(pt>i){
                if(p[i]*p[pt]>x){
                    pt--;
                }else{
                    res+=(pt-i);
                    break;
                }
            }
        }
        int ms=m.size();
        pt=ms-1;
        for(int i=0;i<ms;i++){
            while(pt>i){
                if(m[i]*m[pt]>x){
                    pt--;
                }else{
                    res+=(pt-i);
                    break;
                }
            }
        }
    }
    //cout<<"cnt:in,res:"<<x<<" "<<res<<endl;
    return res;
}

ll BS(ll st,ll ed){
    //cout<<"st,ed:"<<st<<" "<<ed<<endl;
    if(state){
        if(ed-st<=1){
            return st;
        }
        ll mid=(st+ed)/2;
        ll res=cnt(mid);
        if(res>=K){
            return BS(mid,ed);
        }else{
            return BS(st,mid);
        }
    }else{
        if(ed-st<=1){
            return ed;
        }
        ll mid=(st+ed)/2;
        ll res=cnt(mid);
        if(res<K){
            return BS(mid,ed);
        }else{
            return BS(st,mid);
        }
    }
}

int main(){
    int N;
    p.clear();
    m.clear();
    zero=0;
    ll a;
    //*
    cin>>N>>K;

    for(int i=0;i<N;i++){
        cin>>a;
        if(a>0){
            p.push_back(a);
        }else if(a==0){
            zero++;
        }else{
            m.push_back(-a);
        }
    }
    //*/


    sort(p.begin(),p.end());
    sort(m.begin(),m.end());
    ll ps=p.size();
    ll ms=m.size();
    ll mnum=ps*ms;
    ll npnum=mnum+zero*(ms+ps)+zero*(zero-1)/2;
    if(mnum>=K){
        state=1;
        cout<<-1*BS(p[0]*m[0],p[ps-1]*m[ms-1]+1)<<endl;
    }else if(npnum>=K){
        cout<<0<<endl;
    }else{
        state=0;
        K-=npnum;
        ll x,y;
        if(ps>0 && ms>0){
            x=min(p[0],m[0]);
            y=max(p[ps-1],m[ms-1]);
        }else if(ps>0){
            x=p[0];
            y=p[ps-1];
        }else{
            x=m[0];
            y=m[ms-1];
        }
        //cout<<K<<endl;
        cout<<BS(x*x-1,y*y)<<endl;
    }

    return 0;
}

Measured memory_bytes: 5124
#include <bits/stdc++.h>
#include <fstream>
#include <vector>
#include <bitset>
#include <unordered_map>
#include <algorithm>
#include <queue>
#include <math.h>
#include <iomanip>
 
using namespace std;
  
/********** TEMPLATE STARTS HERE ***********/
    
#define IOS ios::sync_with_stdio(false), cin.tie(0);
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define pb push_back
#define test int t; cin >> t; while(t--)
#define skip continue
#define stop break
#define sz(v) (int)v.size()
#define endl '\n'
#define PI 3.1415926535897932384626433832795
#define EPS 1e-9
#define gcd __gcd 
#define mp make_pair
#define FO(i, a) for(auto & i : a)
#define debug(a) cout << #a << ": " << a << endl
#define debug1(a, l, r) FR(i, l, r) cout << a[i] << " "; cout << endl
#define SET(a, b) memset(a, b, sizeof(a));
#define refresh fflush(stdout);
#define digits(n) (int)(log10(n) + 1)
  
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <long long> vl;
typedef vector <pii> vii;
typedef vector <pll> vll;
    
const int INF = 0x3f3f3f3f;
const int LINF = 0x3f3f3f3f3f3f3f3f;
    
template <typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template <typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
   
/*********** TEMPLATE ENDS HERE *************/

main()
{
	IOS
	
	int a, b, c;
	cin >> a >> b >> c;
	
	cout << a + b + c + max(a, max(b, c)) * 9;
	
	
}

Measured memory_bytes: 256
n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
flag = 0
for i in range(n-m+1):
    for j in range(n-m+1):
        c = [x[j:j+m] for x in a[i:i+m]]
        if c == b:
            flag = 1
            break
print('Yes') if flag == 1 else print('No')

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

typedef vector<ll> vecll;
typedef vector<ld> vecld;
typedef vector<bool> vecbl;
typedef vector<vector<ll> > matll;
typedef vector<vector<ld> > matld;
typedef vector<vector<bool> > matbl;
#define mp make_pair;

const ll prime = 1000000000 + 7;
const ld PI = 2 * acos(0.0);

/*
cout << fixed << setprecision(10);
*/

bool my_comp(pll a, pll b) {
	if (a.first != b.first) {
		return a.first < b.first;
	}

	return a.second < b.second;
}

ll power(ll n, ll k) {
	ll p = 1000000000 + 7;
	if (k == 1) {
		return n;
	}
	ll m = n * n;
	m %= p;
	if (k % 2 == 0) {
		return power(m, k / 2);
	}
	m = power(m, k / 2);
	m *= n;
	m %= p;
	return m;
}

ll com(ll n, ll k) {
	// nCk
	ll p = 1000000000 + 7;

	ll ans = 1;
	for (ll i = 1; i <= n; i++)
	{
		ans *= i;
		ans %= p;
	}

	for (ll i = 2; i <= k; i++)
	{
		ans *= power(i, p - 2);
		ans %= p;
	}

	for (ll i = 2; i <= n-k; i++)
	{
		ans *= power(i, p - 2);
		ans %= p;
	}

	return ans;
}

int main() {

	ll n;
	cin >> n;
	vecll a(n);
	for (ll i = 0; i < n; i++)
	{
		cin >> a[i];
	}

	vecll keta(60);
	for (ll i = 0; i < n; i++)
	{
		for (ll j = 0; j < 60; j++)
		{
			keta[j] += a[i] % 2;
			a[i] /= 2;
		}
	}

	ll e;
	ll sum = 0;
	ll d;
	for (ll i = 0; i < 60; i++)
	{
		ll k = keta[i];
		e = (ll)1 << i;
		e %= prime;
		d = e * k;
		d %= prime;
		d *= (n - k);
		d %= prime;
		sum += d;
		sum %= prime;
	}



	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;pair <int, int> p[200100];int N,n[200100],d[200100];
int main() {cin>>N;for(int i=0;i<N;i++)cin>>p[i].first>>p[i].second;sort(p,p+N);d[N]=1;for(int i=N;i--;){int c=i+1;while(c<N&&p[c].first<p[i].first+p[i].second)c=n[c];d[i]=(d[i+1]+d[n[i]=c])%998244353;}cout<<d[0]<<"\n";}

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vii = vector<pair<int, int>>;

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; }

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

// 素因数分解; 返り値は(素数, 乗数)のvector配列
vector<pair<ll, int>> factorize(ll n) {
	vector<pair<ll, int>> res;
	for (ll i = 2; i * i <= n; ++i) {
		if (n % i) continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1) res.emplace_back(n, 1);
	return res;
}

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };
constexpr auto MAX = 100010;

// ──────────────────────────────────────────────────────────────────────────────

int main() {
	int h, a; cin >> h >> a;
	cout << round_int(h, a) << endl;;
}

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

string station = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

int search(char c){
  for(int i = 0; i < 52; i++){
    if(station[i] == c) return i;
  }
  return -1;
}

int main(void){
  int n;
  while(cin >> n && n != 0){
    int key[100];
    for(int i = 0; i < n; i++) cin >> key[i];
    string ms;
    cin >> ms;
    for(int i = 0; i < ms.size(); i++){
      int index = search(ms[i]);
      index = (index - key[i % n]) % 52;
      if(index < 0) index += 52;
      ms[i] = station[index];
    }
    cout << ms << endl;
  }
  return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast","no-stack-protector","unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
#define int long long
#define F(i,L,R) for(int i=L;i<R;++i)
#define FE(i,L,R) for(int i=L;i<=R;++i)
#define getI(a) scanf("%lld",&a)
#define getII(a,b) scanf("%lld%lld",&a,&b)
#define getIII(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define VgetI(n) int (n); scanf("%lld",&(n))
#define VgetII(n,m) int (n),(m); scanf("%lld%lld",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k))
#define debug(x) cout<<(#x)<<"="<<x<<"\n";
#define qq cout<<"QQ\n";
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define f first
#define s second
#define INF 2000000000
int c[15],a[15][15],choose[15],n,m,x;
int ans;
int calc(){
	int ANS=0;
	F(i,0,n) if(choose[i]) ANS+=c[i];
	return ANS;
}
bool legal(){
	int lv[15]={0};
	F(i,0,n) if(choose[i]) F(j,0,m) lv[j]+=a[i][j];
	F(i,0,m) if(lv[i]<x) return 0;
	return 1;
}
void dfs(int index){
	if(index==n){
		if(legal()){
			int curr=calc();
			ans=min(ans,curr);
		}
		return;
	}
	choose[index]=0;
	dfs(index+1);
	choose[index]=1;
	dfs(index+1);
}
main(){
	while(~getIII(n,m,x)){
		F(i,0,n){
			getI(c[i]);
			F(j,0,m) getI(a[i][j]);
		}
		ans=INF;
		F(i,0,15) choose[i]=0;
		dfs(0);
		printf("%lld\n",ans==INF?-1:ans);
	}
}


Measured memory_bytes: 3812
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include <iomanip>
using namespace std;
typedef long long ll;
const int INF=1000000000;
const int MOD=1000000007;
#define PI 3.14159265359;

int main()
{
 int f=1;
 double a, b, x, theta;
 cin >> a >> b >> x;
 if(x==a*a*b){
   f=0;
   cout << 0;
 }else if(x>=a*a*b*0.5){
   theta=atan(0.5*a*a*a/(b*a*a-x));
 }else{
   theta=atan(2*x/(a*b*b));
 }
 if(f==1){
 cout << fixed;
 cout << setprecision(10) << 90-180*theta/PI;
 }
 return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main() {
    double a, b, c, s, l, h, PI = acos(-1.0);
    cin >> a >> b >> c;
    s = a*b*sin(c*PI/180.0)/2.0;
    l = a+b+(sqrt(a*a+b*b-2*a*b*cos(c*PI/180.0)));
    h = b*sin(c*PI/180.0);
    cout << fixed << setprecision(15) << s << endl << l << endl << h <<endl;
    return 0;
}


Measured memory_bytes: 3616
a, b, k = gets.split.map(&:to_i)
d = a.gcd(b)
sqrt_d = Math.sqrt(d).to_i

small_divs = []
(1..sqrt_d).each{|n|
    next if d % n != 0
    if k == 1
        puts d / n
        exit
    else
        k -= 1
    end
    if !(n == sqrt_d && sqrt_d == Math.sqrt(d))
        small_divs.push(n)
    end
}
puts small_divs.reverse()[k - 1]


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;
const int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int Mod = 1000000000 + 0;
//{{{ templates
#define TT_ template<typename T>inline
#define TTF_ template<typename T,typename F>inline
TT_ T sq(T x){return x*x;}
TT_ T In(){T x;cin>>x;return x;}
TT_ void Out(T&x){cout<<x;}
TT_ void sort(T&v){sort(begin(v),end(v));}
TT_ void revs(T&v){reverse(begin(v),end(v));}
TT_ void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT_ int ubnd(T&v,typename T::value_type x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT_ int lbnd(T&v,typename T::value_type x){return lower_bound(begin(v),end(v),x)-begin(v);}
TTF_ void inpt(T&v,int n,F f){for(v.reserve(n);n--;v.emplace_back(f()));}
TTF_ void show(T&v,F f,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),f(x);cout<<e;}
TT_ typename T::iterator minel(T&v){return min_element(begin(v),end(v));}
TT_ typename T::iterator maxel(T&v){return max_element(begin(v),end(v));}

inline void fast_io(){ios_base::sync_with_stdio(0);cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline ll pow_mod(ll a,ll k,ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a,ll p){return pow_mod(a,p-2,p);}
//}}} priority_queue queue deque front stringstream max_element min_element insert count make_tuple

int main()
{
  while (int N = in()){
    vector<int> X(N), Y(N);
    for (int i = 1; i < N; i++){
      int ni, di;
      ni = in(), di = in();
      X[i] = X[ni] + dx[di];
      Y[i] = Y[ni] + dy[di];
    }
    printf("%d %d\n", *maxel(X) - *minel(X) + 1, *maxel(Y) - *minel(Y) + 1);
  }

  return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
#define rep2(i,m,n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;
template <typename T>
T sq(T x){
  return x * x;
}

signed main (){
  int N;
  cin >> N;
  string s;
  cin >> s;

  int ans =0;
  int max_ans =0;
  rep(i,N){
if(s.at(i) == 'I'){
ans++;
}
if(s.at(i) == 'D'){
ans--;
}
max_ans = max(ans,max_ans); 
}
cout << max_ans << endl;
    return 0;
}


Measured memory_bytes: 256
N=int(input())

ok=False
count=0
for i in range(N):
    d1,d2=map(int, input().split())
    if d1==d2:
        count+=1
    else:
        count=0

    if count==3:
        ok=True
        break

if ok:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 62396
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007



int main() {
	string a, b, c;
	cin >> a >> b >> c;
	if (a.back() == b[0] && b.back() == c[0])print("YES");
	else print("NO");






	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include<vector>
template<typename T>
struct weightedUF{
	int n;
	vector<int>parent,rank;
	vector<T>dweight;
	weightedUF(int n_=0,T defvalue=0):n(n_),parent(n_),rank(n_,1),dweight(n_,defvalue)
	{
		for(int i=0;i<n;i++)parent[i]=i;
	}
	int find(int a)
	{
		if(parent[a]==a)return a;
		else
		{
			int ar=find(parent[a]);
			dweight[a]+=dweight[parent[a]];
			return parent[a]=ar;
		}
	}
	T weight(int a)
	{
		find(a);
		return dweight[a];
	}
	bool same(int a,int b)
	{
		return find(a)==find(b);
	}
	bool unite(int a,int b,T w)//a+w==b
	{
		w+=weight(a);w-=weight(b);
		a=find(a);b=find(b);
		if(a==b)return false;
		if(rank[a]<rank[b])
		{
			parent[a]=b;
			dweight[a]=-w;
			rank[b]+=rank[a];
		}
		else
		{
			parent[b]=a;
			dweight[b]=w;
			rank[a]+=rank[b];
		}
		return true;
	}
	T diff(int a,int b)
	{
		return weight(b)-weight(a);
	}
};
main()
{
	int N,M;cin>>N>>M;
	weightedUF<int>UF(N);
	for(;M--;)
	{
		int L,R,D;cin>>L>>R>>D;
		L--,R--;
		if(UF.same(L,R))
		{
			if(UF.diff(L,R)!=D)
			{
				cout<<"No"<<endl;
				return 0;
			}
		}
		else
		{
			UF.unite(L,R,D);
		}
	}
	cout<<"Yes"<<endl;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
double pi = 3.141592653589793;
ll mod = 1000000007;
ll INF = 1000000001;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;



int main(){
    int n;
    bool ok = 0;
    cin >> n;
    REP(i, 1, 10){
        if(n/i<=9&&n%i==0){
            ok = 1;
            break;
        }
    }
    if(ok){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }    
}


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

int main(int argc, char const *argv[]) {
    int N;
    scanf("%d", &N);
    int *t1 = (int *)malloc(sizeof(int) * N);
    int *t2 = (int *)malloc(sizeof(int) * N);
    int i;
    int som = 0;
    for (i = 0; i < N; i++)
        scanf("%d", t1 + i);

    for (i = 0; i < N; i++)
        scanf("%d", t2 + i);

    for (i = 0; i < N; i++) {
        if (t1[i] - t2[i] > 0)
            som += t1[i] - t2[i];
    }

    printf("%d", som);

    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X;
    cin >> X;
    cout << (X ^ 1) << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <string.h>
#include <vector>
#include <deque>
#include <math.h>
#include <algorithm>
#include <map>

using namespace std;
int main() {
    int A,B;
    cin >> A >> B;
    if(A>=13){
        cout << B;
    }else if(A>=6){
        cout << B/2;
    }else{
    cout << 0;
    }
    return 0;
}

Measured memory_bytes: 888
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    public static void Main()
    {
        hoge();
        //System.Console.ReadLine();
    }

    public static void hoge()
    {
        var vars = System.Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray();
        ulong n = vars[0];
        ulong a = vars[1];
        ulong b = vars[2];


        ulong ans1 = (n / (a + b));
        ans1 *= a;
        ulong amari = n % (a + b);
        ulong ans2 = a;


        if (a > amari)
        {
            ans2 = amari;
        }

        System.Console.WriteLine(ans1 + ans2);

    }

}


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

void solve()
{
	string s,t;
	cin>>s;
	cin>>t;
	ll mini = LLONG_MAX;
	for (int i = 0; i+t.length() <= s.length(); ++i)
	{
		ll cnt = 0;
		for(int j = 0 ; j< t.length(); j++)
		{
			if(s[i+j]!=t[j])
				cnt++;
		}
		mini = min(mini,cnt);
	}
	cout<<mini<<endl;
}

int main()
{
	ll t = 1;
	// cin>>t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 3632
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>

using namespace std;

#define mod 1000000007

int cancutnum(long long int l)
{
	// cout << l << endl;
	if(l < 3) return 0;
	long long int rest = (l - 1) / 2;
	return cancutnum(rest) + 1;
}

int main()
{
	int x;
	cin >> x;
	long long int left = 0, right = (long long int)pow(2, 45) + 1;
	while(right - left > 1){
		long long int mid = (left + right) / 2;
		if(cancutnum(mid) >= x + 1) right = mid;
		else left = mid;
	}
	cout << left << endl;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;
const ll inf = 1e18;


const int K = (1<<9);

int n;
ll v[maxn], w[maxn];
vector<pair<ll,ll>> dp[K+10];



vector<pair<ll,ll>> all;


void go(int at, ll val, ll wei) {
    if (at==0) {
	all.push_back({wei, val});
	return;
    }
    go(at/2, val, wei);
    go(at/2, val+v[at], wei+w[at]);
}

void compute(int at) {
    all.clear();
    go(at, 0, 0);
    sort(all.begin(), all.end());

    auto &res = dp[at];
    for (auto p: all) {
	if (res.empty() || res.back().second < p.second) {
	    res.push_back(p);
	}
    }
}


ll dfs(int at, ll val, ll sack) {
    if (sack<0) {
	return -inf;
    }
    if (at==0) {
	return val;
    }
    if (at<=K) {
	auto iter = std::prev(upper_bound(dp[at].begin(),
					  dp[at].end(),
					  make_pair(sack, inf)));
	return val+iter->second;
    }
    return max(dfs(at/2, val, sack), dfs(at/2, val+v[at], sack-w[at]));
}


ll solve(int at, ll L) {
    return dfs(at, 0, L);
}


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

    cin>>n;
    for (int i=1; i<=n; i++) {
	cin>>v[i]>>w[i];
    }

    for (int i=1; i<=min(n, K); i++) {
	compute(i);
    }

    int q;
    cin>>q;
    while (q--) {
	int v, L;
	cin>>v>>L;
	cout<<solve(v,L)<<"\n";
    }
    
    
    return 0;
}


Measured memory_bytes: 10228
#include<cstdio>

int main(){
	char N[1001];

	while(1){
		int i=0,S=0;
		scanf("%s",N);
		while(N[i]){
			//if(N[i]=='\n')break; //?????§?????????N???????????????0?????????????????????????????????????????????
            S += (N[i]-'0'); //??¢??????????????????????¶?????????????char??????????????????????????????
            i++;
        }
        if(S==0)break;
        printf("%d\n",S);
	}
	
	return 0;
}

Measured memory_bytes: 2756
n = int(input())
a = list(map(int, input().split()))
ans = 0
r_wa = [a[0]]
for i in range(n) :
  if i>0 :
    r_wa.append(r_wa[i-1]+a[i])

for i in range(n-1) :
  ans += a[i]*(r_wa[n-1]-r_wa[i])
  ans = ans%1000000007
print(ans)

Measured memory_bytes: 31572
// 2014/09/04 Tazoe

#include <iostream>
using namespace std;

int main()
{
	int b1, b2, b3;
	cin >> b1 >> b2 >> b3;

	if((b1==1 && b2==1 && b3==0) || (b1==0 && b2==0 && b3==1)){
		cout << "Open" << endl;
	}
	else{
		cout << "Close" << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
using Graph = vector<vector<int>>;


int main() {
  ll n, k; cin >> n >> k;
  if(2*n < k){
    cout << 0 << endl;
    return 0;
  }
  if(k%2 != 0){
    ll a = n/k;
    cout << a*a*a << endl;
  }else{
    ll a = n/k; 
    ll b = (n-k/2)/k+1;
    cout << a*a*a + b*b*b << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int MAX=1e6+10;
char str[100][100];
int main()
{
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        cin >> str[i][j];
    }
    bool flag = false;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            if(str[i][j] == '#')
            {
                int sum = 0;
                if(str[i+1][j] != '#')sum++;
                if(str[i-1][j] != '#')sum++;
                if(str[i][j+1] != '#')sum++;
                if(str[i][j-1] != '#')sum++;
                if(sum == 4)flag = true;
            }
        }
    }
    if(!flag)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long 
#define mod 1000000007

int main()
{
	ll n;
	cin>>n;
	if(n==1)
	{
		cout<<1<<endl;
		return 0;
	}
	if(n%2==1) n--;
	int ma=-1,maa=0;;
	for(int i=n;i>=2;i-=2)
	{
		int c=0;
		for(int j=i;j>=2;)
		{
			if(j%2==0)
			{
				j=j/2;
				c++;
			}
			else
				break;

		}
		if(c>ma)
		{
			maa=i;
			ma=c;
		}
	}
	cout<<maa<<endl;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    int n,k;cin>>n>>k;
    int res=0;
    for(int i=0;i<n;i++){
        int x;cin>>x;
        res += min(x,abs(k-x));
    }
    cout<<res*2<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long r,d,x,n;
	scanf("%d %d %d",&r,&d,&x);
	for(int i=0;i<10;i++)
	{
		n=r*x-d;
		printf("%lld\n",n);
		x=n;
	}
	return 0;
}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * 3107.cc: Spot The Difference
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_H = 2000;
const int MAX_W = 2000;

/* typedef */

/* global variables */

char a[MAX_H][MAX_W + 4], b[MAX_H][MAX_W + 4];

/* subroutines */

/* main */

int main() {
  int h, w;
  scanf("%d%d", &h, &w);

  for (int y = 0; y < h; y++) scanf("%s", a[y]);
  for (int y = 0; y < h; y++) scanf("%s", b[y]);

  int c = 0;
  for (int y = 0; y < h; y++)
    for (int x = 0; x < w; x++)
      if (a[y][x] != b[y][x]) c++;

  printf("%d\n", c);
  return 0;
}



Measured memory_bytes: 11040
#define _USE_MATH_DEFINES

#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>

using namespace std;

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

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

const int Maxn = 100010;
const int INF = (int) 1e9;

class edge {
public:
    int from, to;
    ll cost;

    edge(int t, ll c) : from(-1), to(t), cost(c) {}

    edge(int f, int t, ll c) : from(f), to(t), cost(c) {}

    bool operator<(const edge &e) const {
        return cost < e.cost;
    }

    bool operator>(const edge &e) const {
        return cost > e.cost;
    }
};

int n, m;

vector<vector<edge>> g;
int d[Maxn];

bool ng;

void dfs(int i){
    for (auto &e : g[i]) {
        if (d[e.to] == INF){
            d[e.to] = d[i] + e.cost;
            dfs(e.to);
        }else if (d[e.to] != d[i] + e.cost){
            ng = true;
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    g.resize(n);
    for (int i = 0; i < m; ++i) {
        int l, r, c;
        cin >> l >> r >> c;
        l--, r--;
        g[l].emplace_back(r, c);
        g[r].emplace_back(l, -c);
    }

    fill(d, d + n, INF);
    for (int i = 0; i < n; ++i) {
        if (d[i] == INF) {
            d[i] = 0;
            ng = false;
            dfs(i);
            if (ng) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 15232
#include <iostream>
#include <sstream>
using namespace std;
#include <bits/stdc++.h>
#include<utility>
#include <algorithm>
#include<iterator>
#define  go return 0
#define pb push_back
#define lp(j, n)  for(int j=0; j<(int)(n); ++j)
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v)   ((v).begin()), ((v).end())
#define sz(v)    ( (int)((v).size()) )
#define F first
#define S second
#define m_p make_pair
typedef long long ll;
typedef double db;
typedef vector<int> ve;
typedef pair<int, int> pi;
typedef vector<pair<int,int> > vpii;
typedef map<int, int> mii;
const ll N=1e5+5;
ll arr[N],A[N],ARR[N]  ;
bool visited[N]={};
int cnt[N]={};
bool f;
int main()
{

  int n; cin>>n;
  ve arr(n),A(n);
  rep(i,n&&cin>>arr[i])
  {
      A[i]=arr[i];
  }
     sort(all(A),greater<int>());
  rep(i,n)
 {
    if(arr[i]!=A[0])
        cout<<A[0]<<endl;
    else
        cout<<A[1]<<endl;
 }
go;
}


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


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

  for(ll a = -1000; a<1000;a++){
    for(ll b = -1000; b<1000; b++){
      if(x == a*a*a*a*a - b*b*b*b*b){
        cout << a << " " << b << endl;
        return 0;
      }

    }
  }

  return 0;
    

}


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

int n, m, p, x, t[105];
long long sum;

void calc() {
    for (int i = 0; i < n; ++i) sum += t[i];
}

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

    cin >> n;
    for (int i = 0; i < n; ++i) cin >> t[i];
    calc();
    cin >> m;
    for (int i = 0; i < m; ++i) {
        cin >> p >> x;
        int ans = sum - t[p-1] + x;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256