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

#define F(i, a, b) for(int i=a; i<b; i++)
#define mem(arr, val) memset(arr, val, sizeof(arr))
#define rev(str) reverse(str.begin(), str.end())
#define UPPER(str) transform(str.begin(), str.end(), str.begin(), ::toupper)
#define LOWER(str) transform(str.begin(), str.end(), str.begin(), ::tolower)

#define MOD 1000000007
#define INF 1000000000000001
#define epsilon 1e-15

typedef long long int ll;
typedef unsigned long long int ull;

const int MAX = 100;

int gcd(int a, int b){
	if(b==0) return a;

	return gcd(b, a%b);
}



int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int K;
    cin >> K;
    if(K%7==0) K/=7;
    if(K==1){
    	cout << '1';
    	return 0;
    }

    if(gcd(K, 10)!=1){
    	cout << -1;
    	return 0;
    }

    ull x = 0;

    for(int i=1; i<=K; i++){
    	x = ((10*x)%K + 1)%K;
    	if(x%K == 0){
    		cout << i;
    		return 0;
    	}
    }

    return 0;
   
}

Measured memory_bytes: 3648
#include <stdio.h>
#include <iostream>

using namespace std;

long N;
long ans;
 
int main() {
	cin >> N;
	ans = 0;
	for(long i = N;i>0 ;i--){
		if (i%3 != 0 && i%5 != 0){
			ans = ans + i;
		}
	}
	cout << ans << "\n";
	return 0;
}

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

using namespace std;

int main()
{
	int n;
	scanf("%d",&n);
	long double sum=0.0;
	for(int i=0;i<n;++i){
		long double a;
		scanf("%Lf",&a);
		sum+=1.0/a;
	}
	printf("%.10Lf",1.0/sum);
	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
#define double long double
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, int> pli;
typedef pair<lint, lint> pll;
typedef complex<double> xy_t;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

using poly=vector<xy_t>;

poly dft(poly f, int n, int sgn){
    int bit_num = 0;
    while(1 << bit_num < n) ++bit_num;
    rep(i, n){
        int j = 0;
        rep(k, bit_num) j |= (i >> k & 1) << (bit_num - k - 1);
        if(i < j) swap(f[i], f[j]);
    }

    for(int k=1; k<n; k*=2){
        xy_t z_i = xy_t(1.0);
        xy_t z = polar(1.0, sgn * 2*M_PI / (2*k));
        rep(i, k){
            for(int j=0; j<n; j+=k*2){
                xy_t s = f[i+j];
                xy_t t = f[i+j+k] * z_i;
                f[i+j] = s + t;
                f[i+j+k] = s - t;
            }
            z_i *= z;
        }
    }

    return f;
}

poly idft(poly f, int n){
    f = dft(f, n, -1);
    rep(i, n) f[i] /= n;
    return f;
}

poly convolute(poly g, poly h){
    int sz = g.size() + h.size() - 1;
    int n = 1;
    while(n < sz) n *= 2;
    g.resize(n);
    h.resize(n);

    g = dft(g, n, 1);
    h = dft(h, n, 1);

    poly f(n);
    rep(i, n) f[i] = g[i] * h[i];
    f = idft(f, n);
    return f;
}

int main(){
    int n;
    lint m;
    scanf("%d%lld", &n, &m);
    poly a(MAX);
    rep(i, n){
        int x;
        scanf("%d", &x);
        a[x]+=1;
    }
    poly b=a, c=convolute(a, b);
    lint ans=0;
    int cur=(int)c.size()-1;
    while(m){
        lint t=(lint)(c[cur].real()+0.5);
        if(t<=m){
            m-=t;
            ans+=t*cur;
            --cur;
        }
        else{
            ans+=m*cur;
            break;
        }
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 49544
import bisect
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
C.sort()
ans = 0
for i in B:
    x = bisect.bisect_left(A, i)
    y = bisect.bisect_right(C, i)
    y = N - y
    ans += x*y
print(ans)

Measured memory_bytes: 105444
wx=[]
wy=[]

def readdata():
    z=[]
    try:
        while True:
            z.append(raw_input())
    except: return z

def nextpath(p, dir0):
    for e in [3,0,1,2]:
        dp = ispath(p, (dir0+e)%4)
        if dp!=[]: break
    return dp

def ispath(p, dir1):
    y,x = p
    dp = []
    if   dir1==0 and y>0            and wy[y-1][x]=="1": dp= 0
    elif dir1==1 and x<len(wx[0])   and wx[y][x]  =="1": dp = 1
    elif dir1==2 and y<len(wy[0])-1 and wy[y][x]  =="1": dp = 2
    elif dir1==3 and x>0            and wx[y][x-1]=="1": dp = 3
    return dp

def f0037():
    p =[0,0]
    dp = 1
    msg = []
    while True:
        dp = nextpath(p, dp)
        p[0]+=[-1,0,1,0][dp]
        p[1]+=[0,1,0,-1][dp]
        msg.append("URDL"[dp])
        if p==[0,0]: break 
    return msg

z = readdata()
wx = z[0::2]
wy = z[1::2]
msg = f0037()    
print "".join(msg)

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

int main()
{
  string s, p; cin >> s >> p;
  // 文字列をコピーして結合
  s = s + s;
  if (s.find(p) != ::string::npos) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }



  return 0;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string N;
    cin >> N;
    if (N[0] == N[1] && N[1] == N[2]
        || N[1] == N[2] && N[2] == N[3]) {
            cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3572
// AOJ 2442: ConvexCut
// 2017.11.17 bal4u@uu

#include <stdio.h>
#include <string.h>

int x[51], y[51];

long long norm(int dx, int dy)
{
	return (long long)dx*dx + (long long)dy*dy;
}

int parallel(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
{
	return (long long)(y2-y1)*(long long)(x4-x3) == (long long)(x2-x1)*(long long)(y4-y3);
}

int main()
{
	int n, n2, i, j;

	scanf("%d", &n);
	if (n & 1) goto na;
	n2 = n >> 1;
	for (i = 0; i < n; i++) scanf("%d%d", x+i, y+i);
	x[n] = x[0], y[n] = y[0];
	for (j = n2, i = 0; i < n2; i++, j++) {
		if (norm(x[i]-x[i+1], y[i]-y[i+1]) != norm(x[j]-x[j+1], y[j]-y[j+1])) goto na;
		if (!parallel(x[i], y[i], x[i+1], y[i+1], x[j], y[j], x[j+1], y[j+1])) goto na;
	}
	printf("%.10lf %.10lf\n", (x[0]+x[n2])/2.0, (y[0]+y[n2])/2.0);
	return 0;
na: puts("NA");
	return 0;
}

Measured memory_bytes: 1820
n = int(input())
march = [0] * 5
for i in range(n):
    s = input()
    if s[0] == "M":
        march[0] += 1
    elif s[0] == "A":
        march[1] += 1
    elif s[0] == "R":
        march[2] += 1
    elif s[0] == "C":
        march[3] += 1
    elif s[0] == "H":
        march[4] += 1
P = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2]
Q = [1, 1, 1, 2, 2, 3, 2, 2, 3, 3]
R = [2, 3, 4, 3, 4, 4, 3, 4, 4, 4]
res = 0
for i in range(10):
    res += march[P[i]] * march[Q[i]] * march[R[i]]
print(res)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int k;
    char s[105];
    scanf("%d",&k);
    scanf("%s",s);
    int n=strlen(s);
    if(k>=n)
        printf("%s\n",s);
    else
    {
        for(int i=0; i<k; i++)
            printf("%c",s[i]);
        printf("...\n");
    }
    return 0;
}


Measured memory_bytes: 3684
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
using namespace std;




int main()
{
    int n;scanf("%d",&n);
    if (n%2==0) n-=1;
    n/=2;
    printf("%d\n",n);


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

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

ll lcm(ll a, ll b) {
	/* 自然数 a > b を確認・入替 */
	ll tmp, r, x = a*b;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
  /* 最小公倍数を出力 */
	return x/b;
}

int main() {
	ll a, b, c, d;
	cin >> a >> b >> c >>d;

	ll divC, divD, divCD; //c, d, c*d で割り切れる個数
	divC = b/c - (a-1)/c;
	divD = b/d - (a-1)/d;

	ll CD= lcm(c,d);
	//cout << CD << endl;
	divCD = b/CD - (a-1)/CD;
	ll ans = b-a+1 - (divC - divCD + divD);

	cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import numpy as np
import itertools

H, W, K = map(int, input().split())
choco = []
for i in range(H):
    choco.append([int(x) for x in list(input())])

arr = np.array(choco)

# W方向にGREEDY
count = (H-1) + (W-1)


for k in range(H):
    
    # この時点で同じ回数以上切ることが確定なら終了
    if count <= k:
        break

    # H 方向に切り込み
    for comb in itertools.combinations(range(1,H),k):

        # スライスを作っておく
        t = (None,) + comb + (None,)
        s = [slice(t[j],t[j+1],) for j in range(len(t)-1)]
        
        sum_p = [0] * (k+1)
        
        cut = k
        
        for col in zip(*choco):

            # 各ブロック毎の合計を算出
            sum_a = [sum(col[b]) for b in s]
            
            # K を超えるブロックが存在していないか？
            if any(map(K.__lt__, sum_a)):
                # 不成立
                break
            
            # 前まで分割されていないブロックと合わせて、合計を算出
            
            sum_b = [x + y for x,y in zip(sum_p, sum_a)]

            if any(map(K.__lt__, sum_b)):
                cut += 1
                sum_p = sum_a
            else:
                sum_p = sum_b
                
                # 割った位置を記録
        
        else:
            count = min(count,cut)

print(count)

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

#define rep for(int i = 0;i<n;i++)
const int MOD = 1000000007;

int main(){
     int k,x;cin >> k >> x;
     int top = max(-1000000, x-k+1);
     int end = min(1000000, x+k-1);
     for(int i  = top;i<= end;i++){
             cout << i << " ";
     }
     cout << endl;
}


Measured memory_bytes: 384
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;
const ll MOD = ll(1e9+7);

int main(){
  ll h, w;cin>>h>>w;
  if(min(h, w)==1LL){
    cout<<1<<endl;
  }else if((h*w)%2!=0LL){
    cout<<h*w/2LL+1LL<<endl;
  }else{
    cout<<h*w/2LL<<endl;
  }
 //  system("read -n 1 -s -p \"Press any key to continue...\"");
}


Measured memory_bytes: 3540
package main

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

func main() {
	k := readi()
	a := readi()
	b := readi()

	ans := "NG"
	for i := a; i <= b; i++ {
		if i%k == 0 {
			ans = "OK"
		}
	}
	fmt.Println(ans)
}

/*-------------------utilities-------------------*/

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func chmin(x *int, y int) bool {
	if *x > y {
		*x = y
		return true
	}
	return false
}

func chmax(x *int, y int) bool {
	if *x < y {
		*x = y
		return true
	}
	return false
}

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

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

func comb(n, k int) int {
	if n < k {
		return 0
	}
	if n < 0 || k < 0 {
		return 0
	}
	return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD
}

func factorical(n int) int {
	if n > 0 {
		return n * factorical(n-1)
	}
	return 1
}

/*-------------------init-------------------*/

const (
	INF = 1000000000000000000
	MOD = 1e9 + 7

	COMB_MAX = 510000
)

var (
	readString func() string
)

var (
	fac  = [COMB_MAX]int{}
	finv = [COMB_MAX]int{}
	inv  = [COMB_MAX]int{}
)

func init() {
	readString = newReadString(os.Stdin)
}

func combInit() {
	fac[0] = 1
	fac[1] = 1
	finv[0] = 1
	finv[1] = 1
	inv[1] = 1
	for i := 2; i < COMB_MAX; i++ {
		fac[i] = fac[i-1] * i % MOD
		inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD
		finv[i] = finv[i-1] * inv[i] % MOD
	}
}

/*-------------------inputs-------------------*/

func readi() int {
	return int(readi64())
}

func readi64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readf() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}


Measured memory_bytes: 1756
while f = gets
  a = f.to_f
  sum = a
  a *= 2.0
  sum += a
  a /= 3.0
  sum += a
  a *= 2.0
  sum += a
  a /= 3.0
  sum += a
  a *= 2.0
  sum += a
  a /= 3.0
  sum += a
  a *= 2.0
  sum += a
  a /= 3.0
  sum += a
  a *= 2.0
  sum += a
  puts sum
end

Measured memory_bytes: 8636
#include <iostream>
#include <string>
using namespace std;
int main(void){
    // Your code here!
    int K;      cin >> K;
    string s;   cin >> s;
    if(s.length() <= K){
        cout << s << endl;
        return 0;
    } else {
        for(int i = 0; i < K; i++){
            cout << s[i];
        }
        cout << "..." << endl;
        return 0;
    }
    return 0;
}

Measured memory_bytes: 3128
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
    long long n;
    long long sum=0;
    long long same=1;
    string s[100005];
    cin >> n;
    for(long long i=1;i<=n;i++)
    {
        cin >> s[i];
        sort(s[i].begin(),s[i].end());
    }
    sort(s+1,s+n+1);
    for(long long i=1; i<=n;i++)
    {
        if(s[i]==s[i-1])
        {
            sum+=same;
            same++;
        }
		else
            same=1;
    }
    cout << sum;
    return 0;
}


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  cout << "{";
  for (int i = 0; i < vec.size(); i++)
    os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  cout << "}";
  return os;
}
// ====================================================================

int main() {
  ll n;
  cin >> n;
  vector<ll> v(n);
  for (int i = 0; i < n; i++) { cin >> v[i]; }

  vector<ll> dp(n);        // n人目まで考えた時…
  vector<ll> mae(100010);  // 前にi人いるよって言った人の数
  dp[0] = 1;
  for (int i = 0; i < n; i++) {
    if (0 < i) dp[i] = dp[i - 1];
    if (v[i] == 0) {
      dp[i] = dp[i] * (3 - mae[0]) % MOD;
    } else {
      dp[i] = dp[i] * (mae[v[i] - 1] - mae[v[i]]) % MOD;
    }
    mae[v[i]]++;
  }

  cout << dp[n - 1] % MOD << endl;
}


Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int cnt = 0;
    for(int i = 0;i < 5 ; i++) {
      if(sc.nextInt() == 0) {
        cnt = i + 1;
        break;
      }
    }
    System.out.println(cnt);
  }

}


Measured memory_bytes: 35672
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use itertools_num::ItertoolsNum;
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::iter;
#[allow(unused_imports)]
use superslice::*;

fn run() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let a: usize = sc.read();
    let b: usize = sc.read();

    let ans = (a >= 1) && (a <= 9) && (b >= 1) && (b <= 9);
    if ans {
        println!("{}", a * b);
    } else {
        println!("-1");
    }
}

fn main() {
    std::thread::Builder::new()
        .name("run".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(run)
        .unwrap()
        .join()
        .unwrap();
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn read_pairs<T: std::str::FromStr>(&mut self, n: usize) -> Vec<(T, T)> {
        (0..n).map(|_| (self.read(), self.read())).collect()
    }
    pub fn read_pairs_1_indexed(&mut self, n: usize) -> Vec<(usize, usize)> {
        (0..n)
            .map(|_| (self.read::<usize>() - 1, self.read::<usize>() - 1))
            .collect()
    }
    pub fn read_chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    pub fn read_char_grid(&mut self, n: usize) -> Vec<Vec<char>> {
        (0..n).map(|_| self.read_chars()).collect()
    }
    pub fn read_matrix<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n)
            .map(|_| (0..m).map(|_| self.read()).collect())
            .collect()
    }
}


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

int main(void) {
  int64_t N;
  cin >> N;
  // 4/N = 1/h + 1/n + 1/w
  // 4 = N/h + N/n + N/w
  // 4 = (nwN + hwN + hnN) / hnw
  // 4*hnw = nwN + hwN + hnN
  // 4hnw - nwN - hnN = hwN
  // n(4hw - wN - hN) = hwN

  for (int64_t h = 1; h <= 3500; ++h) {
    for (int64_t w = 1; w <= 3500; ++w) {
      int64_t hwN = h * w * N;
      int64_t nTmp = 4 * h * w - w * N - h * N;
      if (nTmp <= 0) continue;
      if (hwN % nTmp == 0) {
        cout << h << " " << w << " " << hwN / nTmp << endl;
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fo(i, n) for (i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define ll long long
#define si(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define ss(s) scanf("%s", s)
#define pi(x) printf("%d\n", x)
#define pl(x) printf("%lld\n", x)
#define ps(s) printf("%s\n", s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << ", " << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;


int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    int n, m, i, j, k;
    cin>>n;
    int orig[n];
    fo(i, n) 
        cin>>orig[i];
    cin>>m;
    int ind[m], price[m];
    fo(i, m) {
        cin>>ind[i]>>price[i];
    }

    fo(i, m) {
        int copy[n] = {0};
        fo(j, n) {
            copy[j] = orig[j];
        }
        copy[ind[i]-1] = price[i];
        int sum = 0;
        fo(k, n) {
            sum+=copy[k];
        }
        cout<<sum<<endl;
    }

return 0;
}

Measured memory_bytes: 3620
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
#define ll long long
int ans[10005];
int main()
{
    int n;
    for(int i=1;i<=200;i++)
    {
        for(int j=1;j<=200;j++)
        {
            for(int k=1;k<=200;k++)
            {
                int tmp=i*i+j*j+k*k+i*k+i*j+k*j;
                if(tmp>10001)continue;
                ans[tmp]++;
            }
        }
    }
    scanf("%d",&n);
    for(int i=1;i<=n;i++)printf("%d\n",ans[i]);
    return 0;
}




Measured memory_bytes: 3752
#include <iostream>
#include <iomanip>
#include <climits>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <unordered_map>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <random>
#define _USE_MATH_DEFINES
#include <math.h>
#include <complex>

using namespace std;

#define INF (int)1e8
#define _INF (int)-1e8
#define INFLL (long long)1e15
#define _INFLL (long long)-1e15
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> P;

/*******************************************************/

int main() {
  int n, k; cin >> n >> k;
  vi a(200005, 0);
  Loop(i, n) {
    int x; cin >> x;
    a[x]++;
  }
  sort(a.begin(), a.end(), greater<int>());
  int sum = 0;
  Loop(i, a.size()) {
    if (i < k) continue;
    else sum += a[i];
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 1152
#include <stdio.h>
int main(void) {
    int i,j,s;
    for(i = 1;i <= 9;i++ ){
        for(j = 1;j <= 9;j++){
            s = j * i;
            printf("%dx%d=%d\n",i,j,s);
        }
    }
    return 0;
}

Measured memory_bytes: 524
#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {
	int N = 0;
	int M = 0;
	char contain[1200][1200];
	char check[1200][1200];
	cin>>N>>M;
	for(int i=1;i<=900;i++)
	{
		for(int j=1;j<=900;j++)
		{
			contain[i][j] = 0;
		}
	}
	for(int i=1;i<=N;i++)
	{
		for(int j=1;j<=N;j++)
		{
			cin>>contain[i][j];
		}
	}
	for(int i=1;i<=M;i++)
	{
		for(int j=1;j<=M;j++)
		{
			cin>>check[i][j];
		}
	}
	int end = 0;
	for(int i=0;i<=N;i++)
	{
		for(int j=0;j<=N;j++)
		{
				end = 0;
				for(int x=0;x<=M;x++)
				{
					for(int z=0;z<=M;z++)
					{
						if((contain[x+i][z+j]==check[x][z])&&(contain[x+i][z+j]!=0)&&(check[x][z]!=0))
						{
							end += 1;
						}
					}
				}
				if(end == M*M)
				{
					cout<<"Yes";
					cout<<endl;
					return 0;
				}
			
		}
	}
	cout<<"No";
	cout<<endl;
	return 0;
	
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 9, P = 1e9 + 7;

int f[N], n, g[N], ans;

void up (int &x, int y) { x += y; if (x >= P) x -= P; }

int main () {
	scanf("%d", &n);
	int S = 1ll * (n - 1) * (n - 1) % P;
	g[0] = f[0] = 1;
	for (int i = 1, j; i < n; ++i) {
		f[i] = (g[i - 1] - (i > 1 ? f[i - 2] : 0) + P) % P;
		j = (min(i + 1, n - 1) + S) % P;
		ans = (1ll * f[i - 1] * j + ans) % P;
		g[i] = (g[i - 1] + f[i]) % P;
	}
	ans = (1ll * f[n - 1] * n + ans) % P;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 8064
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>

#include <memory>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>
using namespace std;


int main(int argc, char *argv[]) {
	string s;
	cin >> s;
	int res = 0;
	for (int i = 0; i < s.size() - 1 - i; i++) {
		if (s[i] != s[s.size() - 1 - i])
			res++;
	}
	cout << res << endl;
}


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

int gcd(int a,int b){
  if(b==0) return a;
  return gcd(b,a%b);
}

int main(){
  int n,X; cin>>n>>X;
  int log; cin>>log;
  log=abs(log-X);
  for(int i=0;i<n-1;i++){
    int x; cin>>x;
    log=gcd(log,abs(x-X));
  }cout<<log<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        string s = sc.Next();

        Dictionary<char, int> dic = new Dictionary<char, int>();

        foreach (var c in s)
        {
            if (dic.ContainsKey(c))
            {
                dic[c]++;
            }
            else
            {
                dic.Add(c, 1);
            }
        }

        bool ok = true;

        foreach (var item in dic)
        {
            if (item.Value % 2 != 0)
            {
                ok = false;
                break;
            }
        }

        string answer = ok ? "Yes" : "No";

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
int main(){
  long n,k,atk(0);
  
  cin >> n >> k;
  vector<int> a(n);
  
  for(int i = 0;i<n;i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  for(int i = 0;i<(n-k);i++){
    atk += a.at(i);
  }
  cout << atk << endl;
}

Measured memory_bytes: 1024
N,X = map(int,input().split())
L = list(map(int,input().split()))
K = []
ans = 0
K.append(0)
for i in range(N):
    K.append(K[i]+L[i])
for j in range(N+1):
    if int(K[j])> X:
        ans += 0
    else:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

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; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

const ll INF = 1000000000000000000;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> p(n+1, 0);
    rep (i, m) {
        int k;
        cin >> k;
        p[k]++;
        cin >> k;
        p[k]++;
    }
    rep (i, n+1) {
        if (p[i] % 2) {
            cout << "NO" << endl;
            exit(0);
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){

	int a, b,d=0, i, c;
	cin>>a>>b>>c;
	int s[4];
	s[0]=a, s[1]=b, s[2]=c;
	sort(s, s+3);
	reverse(s, s+3);
	for(i=1; i<3; i++){
		c=s[i]-s[i-1];
		c=abs(c);
		d+=c;
	}
	cout<<d<<"\n";

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(ll i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(ll i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
bool isPrime(int n){
    for(int i=2;i*i<=n;i++){
        if(n%i==0){
            return false;
        }
    }
    return n!=1;
}
vi divisor(int n){
    vi res;
    for(int i=1;i*i<=n;i++){
        if(n%i==0){
            res.pb(i);
            if(i!=n/i)res.pb(n/i);
        }
    }
    return res;
}
map<int,int> primeFactor(int n){
    map<int,int> res;
    for(int i=2;i*i<=n;i++){
        while(n%i==0){
            res[i]++;
            n/=i;
        }
    }
    if(n!=1){
        res[n]=1;
        return res;
    }
}
const int MAX_N=55555;
int prime[MAX_N];
bool is_prime[MAX_N+1];
int sieve(int n){
    int p=0;
    REP(i,n+1){
        is_prime[i]=true;
    }
    is_prime[0]=is_prime[1]=false;
    for(int i=2;i<=n;i++){
        if(is_prime[i]){
            prime[p++]=i;
            for(int j=2*i;j<=n;j+=i){
                is_prime[j]=false;
            }
        }
    }
    return p;
}
int main(){
    int n;
    cin>>n;
    int k=n;
    sieve(55555);
    FOR(i,2,MAX_N+1){
        if(!k)break;
        if(is_prime[i]&&i%5==1){
            if(k!=n)cout<<" ";cout<<i;
            k--;
        }
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 384
#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'){c=Getchar();rev|=c=='-';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=1000005,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,sum,dp[N];

int main(){
#ifdef rqgao2014
	freopen("input.txt","r",stdin);
#endif
	read(n);
	if(n==1){puts("1");return 0;}
	dp[0]=dp[1]=1;
	for(int i=2;i<=n;i++){
		if(i>=3) ch(sum,dp[i-3]);
		dp[i]=(dp[i-1]+sum)%mod;
	}
	int ans=(ll)dp[n-1]*n%mod;
	for(int i=0;i<n-1;i++){
		ch(ans,(ll)dp[i]*(n-1)%mod*(n-1));
		ch(ans,(ll)dp[i]*min(i+2,n-1));
	}
	print(ans);
	return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define fo(x, n) for(int i = x; i <= n; i++)
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector <int> vi;
const int MOD = 1e9 + 7;

void solve(){
    int a, b;
    cin >> a >> b;
    int x = 0;
    if(a == b) x = 1;
    else if(a == 1 || b == 1){
        if(a == 1) x = 2;
        else x = 3;
    }
    else{
        if(a > b) x = 2;
        else x = 3;
    }
    cout << (x == 1 ? "Draw" : x == 2 ? "Alice" : "Bob");
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0);
	int T = 1;
    //cin >> T;
    fo(1, T){
        solve();
    }
}



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

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

const int INF=1e9;
const int MOD=1e9+7;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

int main()
{
	for(int n,s,w,q;cin>>n>>s>>w>>q && n|s|w|q;){
		vi a(n);
		{
			int g=s;
			rep(i,n){
				a[i]=(g/7)%10;
				g=g%2?g/2^w:g/2;
			}
		}
		
		if(q==2 || q==5){
			int cnt=0,res=0;
			rep(i,n){
				if(a[i])
					cnt++;
				if(a[i]%q==0)
					res+=cnt;
			}
			cout<<res<<endl;
		}
		else{
			vi t(n,1);
			per(i,n-1) t[i]=t[i+1]*10%q;
			map<int,int> cnt;
			cnt[0]=1;
			int val=0,res=0;
			per(i,n){
				(val+=a[i]*t[i])%=q;
				if(a[i])
					res+=cnt[val];
				cnt[val]++;
			}
			cout<<res<<endl;
		}
	}
}

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

#define ll long long int
const int sz=110;
vector<int> prime;
int siz;
bool mark[sz];
void seive()
{
    int i,j,k,sq;
    sq=sqrt(sz);
    for(i=3;i<sz;i+=2) mark[i]=true;

    for(i=3;i<=sq;i+=2){
        if(mark[i]){
            for(j=i*i;j<sz;j+=i) mark[j]=false;
        }
    }
    prime.push_back(2);
    for(i=3;i<sz;i+=2) if(mark[i]) prime.push_back(i);
}

int fun(int n)
{
    int i,j,k;
    seive();
    siz=prime.size();
    int sum[siz];

    memset(sum,0,sizeof sum);
    for(i=0;i<siz;i++){
        int tit=prime[i];
        while(tit<=n){
            sum[i]+=(n/tit);
            tit*=prime[i];
        }
    }

    int ans=0;

    for(i=0;i<siz;i++){
        if(sum[i]>=74) ++ans;
        for(j=i+1;j<siz;j++){
            if(sum[i]>=2 && sum[j]>=24) ++ans;
            if(sum[j]>=2 && sum[i]>=24) ++ans;

            if(sum[i]>=4 && sum[j]>=14) ++ans;
            if(sum[j]>=4 && sum[i]>=14) ++ans;

            for(k=j+1;k<siz;k++){
                if(sum[i]>=2 && sum[j]>=4 && sum[k]>=4) ++ans;
                if(sum[j]>=2 && sum[k]>=4 && sum[i]>=4) ++ans;
                if(sum[k]>=2 && sum[j]>=4 && sum[i]>=4) ++ans;
            }
        }
    }

    return ans;
}
int main()
{
    int n;
    cin>>n;
    int ans=fun(n);
    cout<<ans<<'\n';
}


Measured memory_bytes: 3604
#include<iostream>

using namespace std;
int main(){
   int x, y;
   cin >> x >> y;
   int hi = max(x, y);
   int n;
   cin >> n;
   int op;
   if(n % hi == 0)
    op = (n / hi);
   else op = (n / hi) + 1;
   cout << op;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1e18;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

int N, d[100010];

int main() {
    cin >> N;
    rep(i, N) cin >> d[i];
    sort(d, d+N);
    int left = d[N/2 - 1];
    int right = d[N/2];

    cout << right - left << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main() {
    int A, B, T;
    cin>>A>>B>>T;
    cout << B*(T/A) << endl;
}


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

int main(){
    cout.precision(10);
    int n;
    cin>>n;
    vector<double> dp(n+1);
    cin>>dp[0];
    dp[1] = 1-dp[0];
    for(int i=1; i<n; ++i){
        double h,t;
        cin>>h;
        t=1-h;
        for(int j=i; j>=0; --j){
            dp[j+1]+=dp[j]*t;
            dp[j]=dp[j]*h;
        }
    }
    
    double ans=0;
    for(int i=0; i<=(n-1)/2; ++i) ans+=dp[i];
    cout<<ans<<"\n";
}

Measured memory_bytes: 3828
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#include<map>
#include<cstring>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const ll LLINF = 1LL<<60;
/* -- template -- */

const int T_MAX = 1e5 + 1;
int rec[30][T_MAX];
int sum[T_MAX];
int main(){
    int N, C; cin >> N >> C;
    rep(i, N){
        int s, t, c; cin >> s >> t >> c;
        --c;
        rec[c][s] += 1;
        rec[c][t] -= 1;
    }
    rep(i, C){
        rep(j, T_MAX - 1){
            rec[i][j + 1] += rec[i][j];
            if(rec[i][j] == 0 && rec[i][j + 1] == 1)rec[i][j] = 1;
        }
    }
    int maxv = 0;
    rep(i, T_MAX){
        rep(j, C){
            sum[i] += rec[j][i];
        }
        maxv = max(maxv, sum[i]);
    }
    cout << maxv << endl;
}


Measured memory_bytes: 12416
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int N,M;
  cin>>N>>M;
  int k[N];
  vector<int> C[N];
  set<int> E[N];
  REP(i,N)k[i]=0;
  REP(i,N+M-1){
    int a,b;
    cin>>a>>b;
    a--;b--;
    k[b]++;
    C[a].push_back(b);
    E[b].insert(a);
  }
  int root;
  REP(i,N){
    if(k[i]==0){
      root=i;
      break;
    }
  }
  // cerr<<root<<endl;
  int d[N],r[N];
  REP(i,N){
    d[i]=-1;
    r[i]=0;
  }
  d[root]=0;
  r[root]=-1;
  queue<int> q;
  q.push(root);
  while(!q.empty()){
    int p=q.front();
    q.pop();
    for(auto i:C[p]){
      E[i].erase(p);
      if(d[i]<=d[p]){
        r[i]=p;
        d[i]=d[p]+1;
      }
      if(E[i].empty())q.push(i);
    }
  }
  REP(i,N)cout<<r[i]+1<<endl;
  return 0;
}


Measured memory_bytes: 16896
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define N 200000
#define MOD 1000000007
using namespace std;
using namespace __gnu_pbds;
typedef long long LL;
template<typename T>
using indexed_set = tree<T,null_type,less<T>,rb_tree_tag, tree_order_statistics_node_update>;

LL a[N+1];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	LL n, k; cin >> n >> k;
	for(int i = 1; i <= n; i++)
		cin >> a[i];

	indexed_set<pair<LL,int> > tracker;
	tracker.insert({0,0});

	LL sum = 0;
	LL ans = 0;
	for(LL i = 1; i <= n; i++)
	{
		sum += a[i];
		//Count number of PST[j] such that (PST[i]-PST[j])/(i-j) >= k, or PST[i]-PST[j] >= ki - kj
		//PST[i]-ki >= PST[j]-kj or
		//(PST[i]-ki,i) > (PST[j]-kj,j)
		ans += (LL)tracker.order_of_key({sum-k*i,i});
		tracker.insert({sum-k*i,i});
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 14336
#include <algorithm>
#include <cmath>
#include <climits>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int char2int(char c) {
	return (int)c - (int)'0';
}
int main() {
	int ans = INT_MAX;
	string S; 
	cin >> S;
	for (size_t i = 0; i < S.size() - 2; i++) {
		int num = char2int(S[i]) * 100 + char2int(S[i + 1]) * 10  + char2int(S[i+2]);
		ans = min(ans, abs(num - 753));
	}
	cout << ans << endl;
}

Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long a = in.nextLong(), b = in.nextLong();
		in.close();
		long targ = getGCD(a, b);

		// 素因数分解
		long cnt = 1;
		if (targ % 2 == 0 ) {
			cnt++;
			while ( targ % 2 == 0 ) {
				targ /= 2;
			}
		}

		Long div = 3L;
		while ( div <= Math.sqrt(targ) ) {
			if ( targ % div == 0 ) {
				cnt++;
			}
			while ( targ % div == 0 ) {
				targ /= div;
			}
			div += 1;
		}

		if ( targ != 1 ) cnt++;
		System.out.println(cnt);
	}

	private static long getGCD(long a, long b) {
		if ( b == 0 ) return a;
		else return getGCD(b, a % b);
	}
}


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

const int MAXN = 1e5 + 10;

vector <int> Adj[MAXN];
int N, K;
int fa[MAXN], dep[MAXN];
int answer;

void DFS(int cur)
{
	dep[cur] = 1;
	for(int x : Adj[cur])
		DFS(x), dep[cur] = max(dep[cur], dep[x] + 1);

	if(fa[cur] != 1 && dep[cur] == K)
		answer++, dep[cur] = 0;
}

int main()
{
	cin >> N >> K;
	cin >> fa[1];

	if(fa[1] != 1)	//Loop
		fa[1] = 1, answer ++;

	for(int i = 2; i <= N; i++)
	{
		cin >> fa[i] ;
		Adj[fa[i]].push_back(i);
	}
	DFS(1);

	cout << answer << endl ;
}



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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N; scanf("%d", &N);
  vector<int> A(N + 5);
  int most = -INF, most_ix = -1, least = INF, least_ix = -1;
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &A[i]);
    if (A[i] > most) {
      most_ix = i;
      most = A[i];
    }
    if (A[i] < least) {
      least_ix = i;
      least = A[i];
    }
  }

  vector<pair<int, int>> ans;
  if (least >= 0) {
    for (int i = 1; i < N; ++i) {
      ans.push_back(make_pair(i + 1, i));
    }
  }
  else if (most < 0) {
    for (int i = N; i > 1; --i) {
      ans.push_back(make_pair(i - 1, i));
    }
  }
  else {
    if (abs(least) <= most) {
      for (int i = 1; i <= N; ++i) {
        if (A[i] < 0) {
          ans.push_back(make_pair(i, most_ix));
        }
      }
      // a[i] >= 0
      for (int i = 1; i < N; ++i) {
        ans.push_back(make_pair(i + 1, i));
      }
    }
    else {
      for (int i = 1; i <= N; ++i) {
        if (A[i] > 0) {
          ans.push_back(make_pair(i, least_ix));
        }
      }
      // a[i] < 0
      for (int i = N; i > 1; --i) {
        ans.push_back(make_pair(i - 1, i));
      }
    }
  }

  // check
  // for (pair<int, int> p : ans) {
  //   A[p.first] += A[p.second];
  // }
  // fprintf(stderr, "DEBUG: A=");
  // copy(A.begin() + 1, A.begin() + 1 + N, ostream_iterator<int>(cerr, ", "));
  // fprintf(stderr, "\n");

  int n = ans.size();
  printf("%d\n", n);
  for (pair<int, int> p : ans) {
    printf("%d %d\n", p.second, p.first);
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    int n, m, t, p;
    //int cnt[661][661];
    for(;;) {
        cin >> n >> m >> t >> p;
        vector<vector<int>> cnt(1000,vector<int>(1000,0));
        if(n == 0 && m == 0 && t == 0 && p == 0) return 0;
        rep(i, m) {
            rep(j, n) {         
                cnt[i][j] = 1;
            }
        }
        /*
        for(int i = m; i <= 660 ; i++) {
            for(int j = n; j <= 660; j++) {
                cnt[i][j] = 0;
            }
        }
        */
        int a = -1, b = -1;
        rep(i, t) {
            int d, c; cin >> d >> c;
            if(d == 2) {
                a += c;
                int l = a;
                for(int k = a; k >= 0; k--) {
                    l ++;
                    rep(j, 600) {
                        cnt[l][j] += cnt[k][j];
                        cnt[k][j] = 0;
                    }
                }
            } if(d == 1) {
                b += c;
                int l = b;
                for(int k = b; k >= 0; k--) {
                    l ++;
                    rep(j, 600) {
                        cnt[j][l] += cnt[j][k];
                        cnt[j][k] = 0;
                    }
                }
            }
        }
        rep(j, p) {
            int x, y; cin >> x >> y;
            cout << cnt[y  + a + 1][x + b + 1] << endl;
        }
       
        /*rep(i, m) {
            rep(j, n) {
                cout << cnt[i + a + 1][j + b + 1] << " ";
            }
            cout << endl;
        }
        */
        
    }
	return 0;
}


Measured memory_bytes: 6916