akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<numeric>
using namespace std;
const int BUF = 300005;
const int MOD = 1000000007;

int n;
long long vList[BUF];


void read() {
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> vList[i];
}


void work() {
    int cntBit[63] = {};
    /*
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 64; ++j) {
            if (vList[i] & (1 << j))
                ++cntBit[j];
        }
    }
    */
    
    long long ans = 0;
    for (int i = 1; i < n; ++i) {
        for (int j = 0; j < 63; ++j) {
            if (vList[i - 1] & (1LL << j))
                ++cntBit[j];
        }

        long long toAdd = 0;
        for (int j = 0; j < 63; ++j) {
            if (vList[i] & (1LL << j)) {
                toAdd = (toAdd + ((i - cntBit[j]) % MOD) * ((1LL << j) % MOD)) % MOD;
            } else {
                toAdd = (toAdd + ((cntBit[j]    ) % MOD) * ((1LL << j) % MOD)) % MOD;
            }
        }
        ans = (ans + toAdd) % MOD;
    }
    cout << ans << endl;
}


int main() {
    read();
    work();
    return 0;
}


Measured memory_bytes: 2560
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
static const int INF = 2000000000;


int main(){
  int n;
  cin >> n;
  vector<int> x(n), y(n), h(n);
  rep(i, n) cin >> x[i] >> y[i] >> h[i];
  for (int Cx = 0; Cx <= 100; Cx++){
    for (int Cy = 0; Cy <= 100; Cy++){
      bool ok = true;
      int H = -1;
      for (int i = 0; i < n; i++){
        if (h[i] != 0){
          if (H == -1) H = h[i] + abs(x[i] - Cx) + abs(y[i] - Cy);
          else if (H != h[i] + abs(x[i] - Cx) + abs(y[i] - Cy)) ok = false;
        }
      }

      for (int i = 0; i < n; i++){
        int tmp = max(0, H - abs(x[i] - Cx) - abs(y[i] - Cy));
        if (h[i] != tmp) ok = false;
      }

      if (ok){
        cout << Cx << " " << Cy << " " << H << "\n";
        return 0;
      }
    }
  }
}


Measured memory_bytes: 256
def mapt(fn, *args):
    return tuple(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))
  

def main():
    n, t = Input()
    data = [Input() for _ in range(n)]
    ans = 1001

    for cost, time in data:
        if time <= t:
            ans = min(ans, cost)

    if ans == 1001:
        print("TLE")
    else:
        print(ans)


main()

Measured memory_bytes: 9132
s = list(input())
# print(s)
cnt=0
flag=0
for i in s:
    if cnt==0:
        cnt+=1
        pre=i
        continue
    else:
        if pre==i:
            flag=1
            # print("hoge")
    pre = i
    cnt+=1 
    # print(cnt)
if flag==0:
    print("Good")
else:
    print("Bad")



Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=200005,mod=998244353;
int n,q,p[N],tr[N<<2],s[N<<2],tag[N<<2];
void build(int k,int l,int r)
{
	if(l==r)
	{
		s[k]=p[l];
		tr[k]=p[l];
		return;
	}
	int mid=l+r>>1;
	build(k<<1,l,mid);
	build(k<<1|1,mid+1,r);
	s[k]=(s[k<<1]+s[k<<1|1])%mod;
	tr[k]=(tr[k<<1]+tr[k<<1|1])%mod;
}
void pushdown(int k)
{
	if(tag[k])
	{
		tag[k<<1]=tag[k];
		tr[k<<1]=tag[k]*s[k<<1]%mod;
		tag[k<<1|1]=tag[k];
		tr[k<<1|1]=tag[k]*s[k<<1|1]%mod;
		tag[k]=0;
	}
}
void update(int k,int l,int r,int a,int b,int v)
{
	if(l==a&&r==b)
	{
		tr[k]=s[k]*v%mod;
		tag[k]=v;
		return;
	}
	pushdown(k);
	int mid=l+r>>1;
	if(b<=mid) update(k<<1,l,mid,a,b,v);
	else if(a>mid) update(k<<1|1,mid+1,r,a,b,v);
	else update(k<<1,l,mid,a,mid,v),update(k<<1|1,mid+1,r,mid+1,b,v);
	tr[k]=(tr[k<<1]+tr[k<<1|1])%mod;
}
signed main()
{
	ios::sync_with_stdio(false);
	cin>>n>>q;
	p[n]=1;
	for(int i=n-1;i>=1;i--)
		p[i]=p[i+1]*10%mod;
	build(1,1,n);	
	while(q--)
	{
		int l,r,v;
		cin>>l>>r>>v;
		update(1,1,n,l,r,v);
		cout<<tr[1]<<endl;
	}
	return 0;
}

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

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

    int n;
    cin >> n;
    int cur = -1;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (a == cur) {
            cur = a;
        } else if (a > cur) {
            cur = a - 1;
        } else {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 892
a, b, k = list(map(int, input().split()))
ans = set()
for i in range(a, a + k):
    if i <= b:
        ans.add(i)
for i in range(b - k + 1, b + 1):
    if i >= a:
        ans.add(i)

ansL = list(ans)
ansL.sort()
for i in ansL:
    print(i)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace Contest
{
    class Scanner
    {
        private string[] line = new string[0];
        private int index = 0;
        public string Next()
        {
            if (line.Length <= index)
            {
                line = Console.ReadLine().Split(' ');
                index = 0;
            }
            var res = line[index];
            index++;
            return res;
        }
        public int NextInt()
        {
            return int.Parse(Next());
        }
        public long NextLong()
        {
            return long.Parse(Next());
        }
        public string[] Array()
        {
            line = Console.ReadLine().Split(' ');
            index = line.Length;
            return line;
        }
        public int[] IntArray()
        {
            return Array().Select(int.Parse).ToArray();
        }
        public long[] LongArray()
        {
            return Array().Select(long.Parse).ToArray();
        }
    }

    class Program
    {
        private int N, Y;
        private void Scan()
        {
            var sc = new Scanner();
            N = sc.NextInt();
            Y = sc.NextInt();
        }

        public void Solve()
        {
            Scan();
            for(int i =0;i<=N;i++)
            {
                for(int j=0;i+j<=N;j++)
                {
                    var k = N - (i + j);
                    if(i*10000+j*5000+k*1000==Y)
                    {
                        Console.WriteLine($"{i} {j} {k}");
                        return;
                    }
                }
            }
            Console.WriteLine("-1 -1 -1");
        }

        static void Main(string[] args)
        {
            new Program().Solve();
        }
    }
}

Measured memory_bytes: 13268
N, K = map(int, input().split())
A = list(map(int, input().split()));

t1 = [0]
for i in range(1,N):
    tentou = 0
    for j in range(i):
        if(A[j]>A[i]):
            tentou += 1
    t1.append(tentou)

t2 = []
for i in range(0,N-1):
    tentou = 0
    for j in range(i+1,N):
        if(A[i]<A[j]):
            tentou += 1
    t2.append(tentou)
t2.append(0)

answer=0
for i in range(N):
    answer += t1[i]*K
    answer += (t1[i]+t2[i])*K*(K-1)//2

print(answer % 1000000007)

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

int main() {
    int a,b;
    cin >> a >> b;
    if(a < b){
        cout << "a < b" << endl;
    }else if(a > b){
        cout << "a > b" << endl;
    }else if(a == b){
        cout << "a == b" << endl;
    }
}


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

#define int long long

string s;
string t = "keyence";

// keyence
void check1() {
  if (s == "keyence") {
    puts("YES");
    exit(0);
  }
}

// ...keyence
void check2() {
  int first = 0;
  for (int i = s.size() - 1; i >= 0; i--) {
    if (s[i] == 'k') {
      first = i;
      break;
    }
  }

  if (s.substr(first, 7) == t)  {
    puts("YES");
    exit(0);
  }
}

// keyence...
void check3() {
  if (s.substr(0, 7) == "keyence") {
    puts("YES");
    exit(0);
  }
}

// ke...ce
void check4() {
  string sr = s;
  reverse(sr.begin(), sr.end());
  string tr = t;
  reverse(tr.begin(), tr.end());

  if (s.substr(0, 1) == "k" && sr.substr(0, 6) == "ecneye") {
    puts("YES");
    exit(0);
    return;
  }
  if (s.substr(0, 2) == "ke" && sr.substr(0, 5) == "ecney") {
    puts("YES");
    exit(0);
    return;
  }
  if (s.substr(0, 3) == "key" && sr.substr(0, 4) == "ecne") {
    puts("YES");
    exit(0);
    return;
  }
  if (s.substr(0, 4) == "keye" && sr.substr(0, 3) == "ecn") {
    puts("YES");
    exit(0);
    return;
  }
  if (s.substr(0, 5) == "keyen" && sr.substr(0, 2) == "ec") {
    puts("YES");
    exit(0);
    return;
  }
  if (s.substr(0, 6) == "keyenc" && sr.substr(0, 1) == "e") {
    puts("YES");
    exit(0);
    return;
  }
}

signed main() {
  cin >> s;

  check1();
  check2();
  check3();
  check4();

  puts("NO");

  return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc152/tasks/abc152_e

require 'prime'

def mod_pow(x, n, mod)
  ret = 1
  while n > 0
    ret = ret * x % mod if n & 1 > 0
    x = x * x % mod
    n >>= 1
  end
  ret
end

def mod_inverse(x, mod)
  mod_pow(x, mod - 2, mod)
end

MOD = 10**9+7

N = gets.to_i
As = gets.split.map(&:to_i)

pd = {}
As.each do |a|
  pd.merge!(Hash[a.prime_division]) { |k, ov, nv| [ov, nv].max }
end

lcm = pd.reduce(1) { |a, (k, v)| v.times.reduce(a) { |b| b * k % MOD } % MOD }
# lcm = pd.reduce(1) { |a, (k, v)| v.times.reduce(a) { |b| b * k } }
# p pd
# p lcm

ans = 0
As.each do |a|
  ans = (ans + lcm * mod_inverse(a, MOD) % MOD) % MOD;
  # ans += lcm / a
end

puts ans
# puts ans % MOD


Measured memory_bytes: 3964
def solve(string):
    a, b = map(int, string.split())
    if b == 0:
        return "0"
    bin_a = "{:040b}".format(a)
    bin_b = "{:040b}".format(b)
    aa = [-1 if _a == "0" else int(bin_a[i + 1:] or "0", 2) for i, _a in enumerate(bin_a)]
    bb = [-1 if _b == "0" else int(bin_b[i + 1:] or "0", 2) for i, _b in enumerate(bin_b)]
    index = 0
    while True:
        if bb[index] != -1:
            break
        index += 1
    ans = []
    while index < 40:
        tmp = 0
        tmp += (bb[index] + 1) % 2 if bb[index] >= 0 else 0
        tmp += aa[index] % 2 if aa[index] > 0 else 0
        ans.append(str(tmp % 2))
        index += 1
    ans[-1] = str((b - a) // 2 % 2) if a % 2 == b % 2 == 0 else str(((b - a) // 2 + 1) % 2)
    return str(int("".join(ans), 2))


if __name__ == '__main__':
    print(solve(input()))


Measured memory_bytes: 3064
import math
N, M = map(int, input().split())

def factorization(n):
    factor_list = []
    if n < 1:
        return factor_list
    limit = int(math.sqrt(n))+1
    for i in range(1, limit):
        if n % i == 0:
            factor_list.append(i)
            if not n == i**2:
                factor_list.append(n//i)
    factor_list.sort()
    return factor_list

factor = factorization(M)


ans = 1
for f in factor:
    if N * f <= M and f > ans:
        ans = f
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
using namespace std;

long long gcd2(long long x ,long long  y){
long long r;
if(x<y)swap(x,y);
while(y>0){
    r=x%y;
    x=y;
    y=r;
}
return x;
}

using namespace std;
int main(){
  long long A,B;
  long long C,D;
  cin >> A >> B >> C >> D;
    long long gcd;
    gcd=gcd2(C,D);
    long long LCM=C*D/gcd;

    long long Bnumber;//0~BまででC,Dで割り切れる数の個数
    Bnumber=B/C+B/D-B/LCM;

    long long Anumber;//0~A-1まででC,Dで割り切れる数の個数
Anumber=(A-1)/C+(A-1)/D-(A-1)/LCM;

    long long answer;
    answer=(B-A+1)-(Bnumber-Anumber);

    cout << answer <<endl;
 return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <limits.h>
#include <map>
#include <numeric>

namespace test {
	std::string to_string (char val) {
		return std::string (1, val);
		// return std::string{val};
	}
	//if( str.find ("r") != string::npos)
}

using namespace std;
typedef long long int llint;

int main (void) {
	int a,b; cin >> a >> b;
	if (a + b >= 10) {
		cout << "error" << endl;
	}
	else {
		cout << a + b << endl;
	}
	return 0;
}

Measured memory_bytes: 256
// C.

#include <iostream>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[])
{
	int n;
	cin >> n;
	int ans = 1 << 30;
	for (int i = 0; i <= n; ++i) {
		auto count = [](int f, int r) {
			int c = 0;
			for (int i = 1; r > 0; i *= f) {
				c += (r % (i * f)) / i;
				r -= r % i;
			}
			return c;
		};
		ans = min(ans, count(6, i) + count(9, n - i));
	}
	cout << ans << endl;
	return 0;
}


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

typedef long long ll;

int main() {
	string s;
	cin >> s;
	set< char> ss;
	for (auto& e:s) {
		ss.insert(e);
	}
	char ch = 'a';
	for(auto& e:ss) {
		if (ch == e) {
			ch++;
		}
	}
	if (ch > 'z') {
		cout << "None";
	} else {
		cout << ch;
	}
	
	return 0;
}


Measured memory_bytes: 3740
use proconio::input;
use proconio::marker::Usize1;
use std::collections::VecDeque;
use std::cmp::max;

struct Node {
    edge: Vec<(usize, i64)>,
    parent: usize,
    depth: i64,
}

struct RootedTree {
    node: Vec<Node>,
    root: usize,
}

impl Node {
    fn new(parent: usize) -> Self {
        Node {
            edge: Vec::new(),
            parent: parent,
            depth: 0,
        }
    }
}

impl RootedTree {
    fn new(n: usize, r: usize) -> Self {
        RootedTree {
            node: (0..n).map(|i| Node::new(i)).collect(),
            root: r,
        }
    }

    fn add_edge(&mut self, v0: usize, v1: usize, weight: i64) {
        self.node[v0].edge.push((v1, weight));
        self.node[v1].edge.push((v0, weight));
    }

    fn build(&mut self) {
        let mut q: VecDeque<(usize, usize, i64)> = VecDeque::new();
        q.push_back((self.root, self.root, 0));

        while let Some((i, p, d)) = q.pop_back() {
            self.node[i].depth = d;
            self.node[i].parent = p;
            if let Some(idx) = self.node[i].edge.iter()
                .position(|&(i, _)| i == p) {
                self.node[i].edge.remove(idx);
            }

            for &(nxt, weight) in self.node[i].edge.iter() {
                let depth = weight + d;
                q.push_back((nxt, i, depth));
            }
        }
    }
}

fn main()
{
    input! {
    n:usize,
    a:Usize1,
    b:Usize1,
    edge:[(Usize1,Usize1);n-1],
    }

    let mut tree = RootedTree::new(n, b);
    for (a, b) in edge {
        tree.add_edge(a, b, 1);
    }
    tree.build();

    let mut q = VecDeque::new();
    q.push_back((a, 0));
    let inf = 1i64 << 60;
    let mut v = vec![inf; n];
    v[a] = 0;
    while let Some((idx, cst)) = q.pop_front()
    {
        let cst = cst + 1;
        let p = tree.node[idx].parent;
        if v[p] > cst {
            v[p] = cst;
            q.push_back((p, cst));
        }
        for &(nxt, _) in tree.node[idx].edge.iter()
        {
            if v[nxt] <= cst {
                continue;
            }
            v[nxt] = cst;
            q.push_back((nxt, cst));
        }
    }

    let mut ans = 0;
    for i in 0..n {
        let node = &tree.node[i];
        if node.edge.len() == 0 {
            continue;
        }
        if v[i] > node.depth {
            continue;
        }
        ans = max(ans, node.depth);
    }
    println!("{}", ans);
}

Measured memory_bytes: 13860
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] len = new int[n];
        int sum = 0;
        int max = 0;
        for(int i=0;i<n;i++){
        	int temp = sc.nextInt();
            if(temp>max){
              max = temp;
            }
            sum+=temp;
        }
		System.out.println(max<sum-max?"Yes":"No");
	}
}

Measured memory_bytes: 22740
#include <iostream>
 #include <cstdio> 
#include <cstring> 
using namespace std;
 int main(){
 char a[50],b[50],c[100]; 
while(cin>>a>>b){ 
int i,j;
 c[0]=a[0]; 
for(i=1,j=0;i<=100;i++)
{
 if(i%2!=0)
 {c[i]=b[j];
j++;} 
else
c[i]=a[j]; 
} 
cout<<c<<endl; 
}
 return 0;
 } 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main() {
    const ll AMAX = 100000;
    vector<ll> count(AMAX);
    ll N,K;
    cin >> N >> K;
    REP(i, N){
        ll A,B;
        cin >> A >> B;
        count[A] += B;
    }
    for(int ans = 1; ans <= AMAX; ans++){
        
        if (K <= count[ans]){
            cout << ans << endl;
            break;
        }
        K -= count[ans];
    }
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
using namespace std;
int nrcif(int n)
{
    int cnt=0;
    while(n)
    {
        n/=10;
        cnt++;
    }
    return cnt;
}
int put10(int x)
{
    int a=1;
    for(int i=1;i<=x;i++)
        a=a*10;
    return a;
}
int main()
{
    int a,b;
    cin>>a>>b;
    int nr;
    nr=a*put10(nrcif(b))+b;
    int x=sqrt(nr);
    if(x*x==nr)
        cout<<"Yes";
        else
            cout<<"No";
    return 0;
}


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

int main(){
	int h,w,m;cin>>h>>w>>m;
	multiset<int>se;
	map<int,int>cnt;
	map<int,vector<int>>mp;
	rep(i,m){
		int x,y;scanf("%d%d",&x,&y);
		mp[x].push_back(y);
		cnt[y]++;
	}
	for(auto p:cnt){
		se.insert(p.second);
	}
	int Max=0;
	for(auto&p:mp){
		for(int&y:p.second){
			se.erase(se.find(cnt[y]));
			cnt[y]--;
			se.insert(cnt[y]);
		}
		Max=max(Max,(int)p.second.size()+*se.rbegin());
		for(int&y:p.second){
			se.erase(se.find(cnt[y]));
			cnt[y]++;
			se.insert(cnt[y]);
		}
	}
	cout<<Max<<endl;
}

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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()

Int INF = 1e18;
Int mod = 1e9+7;
//Int mod = 998244353;

int main() {
    vector<int> res;
    vector<int> a(501, 0);
    for (int i = 1; i <= 500; i++) {
        a[i] = i;
    }
    for (int i = 0; i < 500; i++) {
        a[i + 1] += a[i];
    }
    while (true) {
        int n;
        cin >> n;
        if (n == 0) break;
        int cnt = 0;
        for (int i = 0; i <= 500 - 1; i++) {
            for (int j = i + 1; j <= 500; j++) {
                if (j - i > 1 and a[j] - a[i] == n) {
                    //cout << i << " " << j << endl;
                    cnt++;
                }
            }
        }
        res.push_back(cnt);
    }
    for (int i = 0; i < (int)res.size(); i++) {
        dump(res[i]);
    }
    return 0;
}



Measured memory_bytes: 3168
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
	int n, q, cnt = 0,ret; 
	vector <int> S, T;
	cin >> n;
	for(int i = 0; i < n; i++) {cin >> ret; S.push_back(ret);}
	cin >> q;
	for(int i = 0; i < q; i++) {cin >> ret; T.push_back(ret);}

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

	for(int i = 0, j = 0; i < n, j < q; ){
		if(S[i] == T[j]){cnt++; i++; j++;}
		else if(S[i] < T[j]) i++;
		else j++;
	}

	cout << cnt;
	cout << endl;
}

Measured memory_bytes: 1804
import java.util.Scanner;

public class Main {
	static boolean[] isPrime;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long P = sc.nextLong();
		sc.close();
		if(N == 1) {
			System.out.println(P);
			System.exit(0);
		}
		long ans = 1;
		long t = (long)Math.pow(P, (double)1 / N);
		t += 2;
		for(long k = 2; k <= t; k++) {
			long s = (long)Math.pow(k, N);
			if(P % s == 0) {
				ans = k;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23124
// Problem : C - Guess The Number
// Contest : AtCoder Beginner Contest 157
// URL : https://atcoder.jp/contests/abc157/tasks/abc157_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#define DEBUG(...) cerr << #__VA_ARGS__ << ": ", debug(__VA_ARGS__);
#else
#define DEBUG(...)
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator << (ostream &os, const vector<T> &v) {os << "["; for (int i=0; i<(int)v.size(); i++) {if (i) os << ", "; os << v[i];} return os << "]";}
void debug() {cerr << "\n";} template<typename T, typename... Args> void debug(T x, Args... args) {cerr << x << "; "; debug(args...);}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    
    int n, m;
    cin >> n >> m;
    
    vector<int> ret(n, -1);
    for (int i=0; i<m; i++) {
        int s, c;
        cin >> s >> c;
        if (ret[s-1] != -1 && ret[s-1] != c) {
            cout << "-1\n";
            return 0;
        }
        ret[s-1] = c;
    }
    
    if (n > 1 && ret[0] == 0) {
        cout << "-1\n";
        return 0;
    }
    
    if (ret[0] == -1)
        ret[0] = (n > 1);
    for (int i=1; i<n; i++)
        if (ret[i] == -1)
            ret[i] = 0;
    
    for (int i : ret)
        cout << i;
    cout << "\n";

    return 0;
}


Measured memory_bytes: 256
Scanf.scanf "%d" (fun n ->
    let t = Array.init n (fun _ -> Scanf.scanf " %d" (fun t -> t)) in
    let sum = Array.fold_left (+) 0 t in
    Scanf.scanf " %d" (fun m ->
        for i = 1 to m do
            Scanf.scanf " %d %d" (fun p x ->
                let p = p - 1 in
                Printf.printf "%d\n" @@ sum + x - t.(p)
            )
        done
    )
)

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


const int INF = 1e9+5;

int main(){
    int n,k;
    cin>>n>>k;
    vector<int> h(n);
    for(int& x : h) scanf("%d", &x);

    vector<int> dp(n, INF);
    dp[0]=0;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<=i+k; j++){
            if(j<n)
                dp[j]=min(dp[j], dp[i]+abs(h[j]-h[i]));
            else break;
        }
    }

    cout<<dp[n-1];
}

Measured memory_bytes: 4120
#include<iostream>
#include<algorithm>
#include<string>
#include<numeric>
#include<vector>
using namespace std;

int main(){
  int n;
  cin >> n;
  int v[n];
  int c[n];
  for (int i=0;i<n;i++){
    cin >> v[i];
  }
  for (int i=0;i<n;i++){
    cin >> c[i];
  }
  int d;
  int count = 0;
  for (int i=0;i<n;i++){
    d = v[i]-c[i];
    if (d>0) count += d;
  }

  cout << count << endl;
  return 0;
}


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

facts = [0]
n = 1
while True:
    facts.append(n ** 5)
    if facts[-1] - facts[-2] > X:
        break
    n += 1

facts = set(facts)

for f0 in facts:
    f1 = None
    if abs(f0 - X) in facts:
        f1 = abs(f0 - X)
        r0 = int(f0 ** 0.2)
        r1 = int(f1 ** 0.2)
        if f0 - f1 == X:
            print(r0, r1)
        else:
            print(r0, -r1)
        break


Measured memory_bytes: 9448
#include<iostream>
#include<cstdio>

using namespace std;

int n;
int a[3];
int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=100000000;i++){
		bool f=true;
		for(int j=0;j<n;j++){
			if(a[j]%i!=0)f=false;
		}
		if(f)printf("%d\n",i);
	}
	return 0;
}

Measured memory_bytes: 1188
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>

using namespace std;
using llong = long long;
const int MOD=1000000007;

int main(int argc, char**argv){
    int k, s;
    cin >> k >> s;
    int counter = 0;
    for (int i = 0; i <= k; i++){
        for (int j = 0; j <= k; j++){
            // for (int x = 0; x <= k; x++){
            //     if (i + j + x == s) counter++;
            // }
            if (0 <= s - i - j && s - i - j <= k) {
                counter++;
                // cout << i << " " << j << " " << s - i - j << endl;
            }
        }
    }
    cout << counter << endl;

    return 0;
}







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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

template<typename T>
struct Kruskal{
  struct edge{
    ll from,to;
    T cost;
    ll used;
    edge(ll from,ll to,T cost):
      from(from),to(to),cost(cost),used(0){}
    bool operator<(const edge& e) const{
      return cost<e.cost;
    }
  };
  vector<ll> r,p;
  vector<edge> es;

  Kruskal(){}
  Kruskal(ll n):r(n,1),p(n){
    iota(p.begin(),p.end(),0);
  }

  ll find(ll x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }

  bool same(ll x,ll y){
    return find(x)==find(y);
  }

  void unite(ll x,ll y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }

  void add_edge(ll u,ll v,T c){
    es.emplace_back(u,v,c);
  }

  T build(){
    sort(es.begin(),es.end());
    T res=0;
    for(auto &e:es){
      if(!same(e.from,e.to)){
        res+=e.cost;
        unite(e.from,e.to);
        e.used=1;
      }
    }
    return res;
  }
};

const int MOD = 100000;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

int main(void) {
  int n;
  cin >> n;

  vector<ll> x(n), y(n);
  REP(i, n) cin >> x[i] >> y[i];

  Kruskal<ll> g(n);

  vector<int> ord(n);
  iota(all(ord),0);
  sort(all(ord),[&](int i,int j){
    if(x[i] == x[j]) return y[i] < y[j];
    return x[i] < x[j];
  });

  for(int j = 0; j < n - 1; j++){
    int now = ord[j];
    int nxt = ord[j+1];
    ll cost = min(abs(x[now] - x[nxt]), abs(y[now] - y[nxt]));
    g.add_edge(now, nxt, cost);
  }

  sort(all(ord),[&](int i,int j){
    if(y[i] == y[j]) return x[i] < x[j];
    return y[i] < y[j];
  });

  for(int j = 0; j < n - 1; j++){
    int now = ord[j];
    int nxt = ord[j+1];
    ll cost = min(abs(x[now] - x[nxt]), abs(y[now] - y[nxt]));
    g.add_edge(now, nxt, cost);
  }

  cout << g.build() << endl;

  return 0;
}

Measured memory_bytes: 14060
N, K = map(int, input().split())
h = [int(input()) for _ in range(N)]
h.sort(reverse=True)
cnt = 10**9
for i in range(N-K+1):
  rng = h[i]-h[i+K-1]
  if rng < cnt:
    cnt = rng
print(cnt)


Measured memory_bytes: 7384
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Data.Maybe (fromJust)
import Debug.Trace

modNum :: Int
modNum = 10^9 + 7

solve :: Int -> Int -> Int
solve 0 a = a
solve x a = solve (x - 1) ((x * a) `mod` modNum)

main :: IO ()
main = do
    n <- (fst . fromJust . BS.readInt) <$> BS.getLine
    print $ solve n 1

Measured memory_bytes: 8444
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct edge{
    int u,v,cost;
    bool operator<(const edge& v) const {
        return cost < v.cost;
    }
};
const int INF = 1001001001;
const edge imEg = {-1,-1,INF};
vector<edge> es(10000, imEg);
int V,E;
vector<int> par;
vector<int> rnk;

void init_union_find(int n) {
    par.resize(n);
    rnk.resize(n);
    for(int i=0; i<n; i++) {
        par[i] = i;
        rnk[i] = 0;
    }
}

int find(int x) {
    if(x != par[x]) par[x] = find(par[x]);
    return par[x]; 
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x == y) return;
    if(rnk[x] > rnk[y]) par[y] = x;
    else par[x] = y;
    if(rnk[x] == rnk[y]) rnk[y]++;
}

int kruskal() {
    init_union_find(V);
    sort(es.begin(), es.end());
    int res = 0;
    for(int i=0; i<E; i++) {
        edge e = es[i];
        if(find(e.u) != find(e.v)) {
            unite(e.u, e.v);
            res += e.cost;
        }
    }
    return res;
}

int main() {
    cin >> V;
    E = 0;
    for(int i=0; i<V; i++) {
        for(int j=0; j<V; j++) {
            int w;
            cin >> w;
            if(w != -1) {
                struct edge e = {i,j,w};
                es[E] = e;
                E++;
            }
        }
    }
    cout << kruskal() << endl;
    return 0;
}


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

#define LIST_ISIZE 1

typedef struct {
	int n, c, *v;
} list;

void init(list *l) {
	l->n = 0;
	l->c = LIST_ISIZE;
	l->v = malloc(l->c * sizeof *l->v);
}

void add(list *l, int v) {
	if (l->n+1 > l->c) {
		l->c *= 2;
		l->v = realloc(l->v, l->c * sizeof *l->v);
	}
	l->v[l->n++] = v;
}

typedef struct {
	list same, diff;
} node;

node graph[100000];
int paint[100000];

void dfs(int v) {
	node gc = graph[v];
	for (int i = 0; i < gc.same.n; i++) {
		if (paint[gc.same.v[i]] != -1) continue;
		paint[gc.same.v[i]] = paint[v];
		dfs(gc.same.v[i]);
	}
	for (int i = 0; i < gc.diff.n; i++) {
		if (paint[gc.diff.v[i]] != -1) continue;
		paint[gc.diff.v[i]] = !paint[v];
		dfs(gc.diff.v[i]);
	}
}

int main(void) {
	int n, m;
	scanf("%d%d", &n, &m);

	for (int i = 0; i < n; i++) {
		init(&graph[i].same);
		init(&graph[i].diff);
	}

	for (int i = 0; i < m; i++) {
		int a, b, s;
		scanf("%d%d%d", &a, &b, &s);
		a--; b--; s %= 2;
		if (s) {
			add(&graph[a].diff, b);
			add(&graph[b].diff, a);
		} else {
			add(&graph[a].same, b);
			add(&graph[b].same, a);
		}
	}

	for (int i = 0; i < n; i++) paint[i] = -1;

	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (paint[i] != -1) continue;
		paint[i] = 0;
		cnt++;
		dfs(i);
	}

	for (int i = 0; i < n; i++) {
		free(graph[i].same.v);
		free(graph[i].diff.v);
	}

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


Measured memory_bytes: 14592
a, b = gets.split.map(&:to_i)
a -= 1
a = (a.even? ? ((a / 2) % 2) ^ a : ((a + 1)/ 2) % 2)
b = (b.even? ? ((b / 2) % 2) ^ b : ((b + 1)/ 2) % 2)
puts a ^ b

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> xs(n);
  for (int i = 0; i < n; i++) {
    cin >> xs[i];
  }

  int c = n - 1;
  int d = -2;
  for (int i = 0; i < n; i++) {
    cout << xs[c] << " ";
    c += d;
    if (c == -1) {
      c = 0;
      d = 2;
    }
    if (c == -2) {
      c = 1;
      d = 2;
    }
  }
  cout << endl;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    int sum = 0;
    rep(i, 0, n){
        cin >> a[i];
        a[i] *= n;
        sum += a[i];
    }
    int ave = sum / n;
    int MIN = INF, ans = -1;
    rep(i, 0, n){
        int tmp = abs(ave - a[i]);
        if(tmp < MIN){
            MIN = tmp;
            ans = i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>
    
using namespace std;

typedef long long ll;

int main() {
    int n, h, w;
    cin >> n >> h >> w;
    cout << (n+1-h)*(n+1-w) << endl;
}

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

answer = sum([x ** 2 for x in li_x])
for p in range(min(li_x),max(li_x) + 1):
    answer = min(answer, sum([(x - p) ** 2 for x in li_x]))

print(answer)


Measured memory_bytes: 2940
#リスト内包表記を使う場合
N=int(input())
A=[int(x) for x in input().split()]
#Aはa1-aNを含むリスト
#これはめちゃめちゃ簡単で最大値-最小値でいい

A=sorted(A)
ans=A[N-1]-A[0]
print(ans)

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

int main() {
    int H,W,K;
    cin >> H >> W >> K;
    char map[H][W]={0};
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >> map[i][j];
        }
    }
    int ans=0;
    for(int bit_h=0;bit_h<(1<<H);bit_h++){
        for(int bit_w=0;bit_w<(1<<W);bit_w++){
            int cnt=0;
            for(int i=0;i<H;i++){
                for(int j=0;j<W;j++){
                    if( !(bit_h&(1<<i)) && !(bit_w&(1<<j)) && map[i][j]=='#'){
                        cnt++;
                    }
                }
            }
            if(cnt==K){
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    std::string s;
    std::cin >> s;
    int a = std::stoi(s.substr(0, 2)), b = std::stoi(s.substr(2, 2));
    if (a == 0) {
        if (b == 0) std::cout << "NA";
        else if (b <= 12) std::cout << "YYMM";
        else std::cout << "NA";
    } else if (a <= 12) {
        if (b == 0) std::cout << "MMYY";
        else if (b <= 12) std::cout << "AMBIGUOUS";
        else std::cout << "MMYY";
    } else {
        if (b == 0) std::cout << "NA";
        else if (b <= 12) std::cout << "YYMM";
        else std::cout << "NA";
    }
    std::cout << std::endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.BigDecimal;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    double n = sc.nextDouble();
    double m = sc.nextDouble();
    double d = sc.nextDouble();
    BigDecimal bd1 = new BigDecimal(2 * (n - d));
    if(d == 0) bd1 = new BigDecimal(n - d);
    BigDecimal bd2 = new BigDecimal(m - 1);
    BigDecimal bd3 = new BigDecimal(n * n);
    BigDecimal bd4 = bd1.multiply(bd2);
    BigDecimal result = bd4.divide(bd3, 10, BigDecimal.ROUND_HALF_UP);
    System.out.println(result);
  }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, s, e) for (ll i = s; i < e; i++)
#define Forr(i, s, e) for (ll i = s; i > e; i--)
#define pb push_back
#define ll long long
#define int ll
#define mp make_pair
ll mod = 1000000007;
ll mod2 = 500000004;
signed main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cout << fixed << setprecision(8);
    ll n;
    cin >> n;
    ll a[n];
    ll sum = 0;
    For(i, 0, n)
    {
        cin >> a[i];
        sum += a[i] % mod;
    }
    ll ans = 0;
    For(i, 0, n)
    {

        ll x1 = (sum - (a[i] % mod)) % mod;
        ll x2 = ((a[i] % mod) * (x1 % mod)) % mod;
        ans += x2 % mod;
    }
    ans = ((ans % mod) * (mod2)) % mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5212
# -*- coding: utf-8 -*-

N = int(input())
g = list([-1 for j in range(N)] for i in range(N))
for i in range(N):
    a = int(input())
    for _ in range(a):
        x, y = map(int, input().split())
        g[i][x - 1] = y

ans = 0
for i in range(1 << N):
    d = list((i >> j) & 1 for j in range(N))
    ok = True
    for j in range(N):
        if d[j]:
            for k in range(N):
                if g[j][k] == -1:
                    continue
                if g[j][k] != d[k]:
                    ok = False
    if ok:
        ans = max(ans, sum(d))

print(ans)


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

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) {
        int d, t, s;
        cin >> d >> t >> s;
        if (d <= s * t) cout << "Yes";
        else cout << "No";
    }
    return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
const int mod=1000000007;
int h[111];
int n;
int fpow2(int y)
{
	if(y==0)
		return 1;
	int ret=fpow2(y>>1);
	ret=(long long)ret*ret%mod;
	if(y&1)
		(ret<<=1)%=mod;
	return ret;
}
pair<int,int> solve(int l,int r,int nh)
{
	int mi=1010101010,cnt=0;
	for(int i=l;i<=r;i++)
		mi=min(mi,h[i]);
	for(int i=l;i<=r;i++)
		cnt+=(mi==h[i]);
	int h1=1,h2=1,st=0;
	pair<int,int> dp;
	for(int i=l;i<=r+1;i++)
		if(h[i]>mi)
		{
			if(st==0)
				st=i;
		}
		else
		{
			if(st)
			{
				dp=solve(st,i-1,mi);
				h1=(long long)dp.first*h1%mod;
				h2=((long long)dp.first*2+dp.second)*h2%mod;
				st=0;
			}
		}
	return make_pair((long long)h1*fpow2(mi-nh)%mod,((long long)h2*fpow2(cnt)+mod+mod-h1-h1)%mod);
}
int main()
{
	pair<int,int> dp;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&h[i]);
	dp=solve(1,n,0);
	printf("%d",(dp.first+dp.second)%mod);
	return 0;
}

Measured memory_bytes: 256
N,K=map(int,input().split())
A=[]
for i in range(N):
    a=int(input())
    A.append(a)
#####segfunc#####
def segfunc(x, y):
    return max(x,y)
#################

#####ide_ele#####
ide_ele =0
#################

class SegTree:
    def __init__(self, init_val, segfunc, ide_ele):
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        # 配列の値を葉にセット
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        # 構築していく
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res
Ma=max(A)
Tree=[0]*(Ma+1)
seg = SegTree(Tree, segfunc, ide_ele)
ans=0
for i in range(N):
    a=A[i]
    l=max(0,a-K)
    r=min(a+K,Ma)
    Ans=seg.query(l,r+1)
    seg.update(a, Ans+1)
    ans=max(ans,Ans+1)
print(ans)

Measured memory_bytes: 148284
#include<bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ri(x) scanf("%d",&(x))
#define ri2(x,y) scanf("%d %d",&(x),&(y))
#define ri3(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rll(x) scanf("%lld",&(x))
#define rll2(x,y) scanf("%lld %lld",&(x),&(y))
#define rll3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
#define gc(x) ((x) = getchar())
using namespace::std;

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> tll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<tll> vtll;
typedef vector<string> vs;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;

ll gcd(ll a, ll b){ return b==0?a:gcd(b,a%b);}

ll add(ll a, ll b, ll m = MOD){
	return a + b < m? a + b : a + b - m;
}

ll mul(ll a, ll b, ll m = MOD){
	return (a * b) % m;
}

ll pow_mod(ll a, ll b, ll m = MOD){
	ll res = 1LL;
	a = a%m;
	while(b){
		if(b&1) res = mul(res,a,m);
		b >>= 1;
		a = mul(a,a,m);
	}
	return res;
}

ll fastexp(ll a, ll b){
	ll res = 1LL;
	while(b){
		if(b&1) res = res*a;
		b >>= 1;
		a *= a;
	}
	return res;
}

int gcdExtendido(int a, int b, int *x, int *y){
	if(a == 0){
		*x = 0;
		*y = 1;
		return b;
	}
	int x1, y1;
	int gcd = gcdExtendido(b%a,a,&x1,&y1);
	
	*x = y1-(b/a)*x1;
	*y = x1;
	return gcd;
}

int modInverso(int a, int m){
	int x, y;
	int g = gcdExtendido(a,m,&x,&y);
	if(g!=1) return -1;
	else return (x%m + m)%m;
}

/****************************************
*************P*L*A*N*T*I*L*L*A************
*****************************************/

const int N = 200000+5;

int n;
int h;
int w;
int f[N];
int fi[N];
int x[N];
int y[N];
int memo[N];

void init(){
	f[0] = 1;
	for(int i=1; i<N; i++) f[i] = mul(f[i-1], i);
	fi[N-1] = pow_mod(f[N-1],MOD-2);
	for(int i=N-2; i>=0; i--){
		fi[i] = mul(i + 1, fi[i+1]);
	}
}

int C(int n, int k){
	return mul(f[n], mul(fi[n-k], fi[k]));
}

int main(){
	init();
	ri3(h,w,n);
	for(int i=0; i<n; i++){
		ri2(x[i], y[i]);
	}
	x[n] = h;
	y[n] = w;
	n += 1;
	vector<int> p(n);
	iota(all(p),0);
	sort(all(p),[&](int i, int j){
		if(x[i] == x[j]) return y[i] < y[j];
		return x[i] < x[j];
	});
	for(int i=0; i<n; i++){
		int posi = p[i];
		memo[i] = C(x[posi] + y[posi] - 2, x[posi] - 1);
		for(int j=0; j<i; j++){
			int posj = p[j];
			if(y[posj] > y[posi]) continue;
			int paths = mul(memo[j], C(x[posi] - x[posj] + y[posi] - y[posj], x[posi] - x[posj]));
			memo[i] = add(memo[i], mul(MOD-1, paths));
		}
	}
	printf("%d\n",memo[n-1]);
	return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
#define P pair<int, int>

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

    ll odd , n4 ;
    odd  = 0 ;
    n4 =  0;
    ll a ;
    rep(i , n){
        cin >> a ;
        if(a % 4 == 0){
            n4++ ;
        }else if(a%2 == 1){
            odd++ ;
        }
        
    } 
    
    bool ans = false;
    if(n4 >= n/2){
        ans = true;
    }
    else if(n4 >= odd){
        ans = true;
    }
    if(ans){
        printf("Yes");
    }
    else{
        printf("No");
    }
    return 0 ;
}

 



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
    FASTINOUT;
    int m1,d1,m2,d2;
    cin>>m1>>d1>>m2>>d2;
    if ((m2==m1+1 ||(m1==12&&m2==1))&&(d2==1))
        cout<<1;
    else
        cout<<0;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
#define rep(i, n) for ( int i = 0; i < n; i++)
static int C[20][3] = {{5,4,1},{6,0,2},{7,1,3},{8,2,4},{9,3,0},{0,11,10},{1,12,11},{2,13,12},{3,14,13},{4,10,14},{15,9,5},{16,5,6},{17,6,7},{18,7,8},{19,8,9},{10,16,19},{11,17,15},{12,18,16},{13,19,17},{14,15,18}};
static const int dx[3] = {0, -1, 1};
static const int dy[3] = {1, 0, 0};
static const int MAX = 205;
static const int SHIFT = 102;

class State{
public:
  int x, y, b, r, c;
  State(){}
  State(int x, int y, int b, int r):x(x), y(y), b(b), r(r){ c = 0;}
};

State getNext(State u, int r){
  int bt[3], nt[3], nb, nr = -1;
  int nx = dx[r];
  int ny = dy[r];
  if ( (u.x + u.y)%2  ){ nx *= (-1); ny *= (-1); }
  nx += u.x;
  ny += u.y;

  rep(i, 3) bt[i] = C[u.b][i];
  rotate(bt, bt + u.r, bt + 3);
  nb = bt[r]; // next bottom
  rep(i, 3) nt[i] = C[nb][i];

  rep(i, 3){
    if ( u.b == nt[r] ){ nr = i; break; }
    rotate(nt, nt+1, nt+3);
  }

  return State(nx, ny, nb, nr);
}

int bfs(int gx, int gy, int gb){
  bool vis[MAX][MAX][20][3];
  queue<State> Q;
  rep(i, MAX)rep(j, MAX) rep(k,20) rep(l,3) vis[i][j][k][l] = false;
  Q.push(State(SHIFT, SHIFT, 0, 0));
  vis[SHIFT][SHIFT][0][0] = true;
  State u, v;
  while(1){
    u = Q.front(); Q.pop();
    if ( u.x == gx && u.y == gy && u.b == gb ) return u.c;
    rep(r, 3){
      v = getNext(u, r);
      if ( !vis[v.x][v.y][v.b][v.r] ){
	vis[v.x][v.y][v.b][v.r] = true;
	v.c = u.c + 1;
	Q.push(v);
      }
    }
  }
}

main(){
  int gx, gy, gb;
  while(1){
    cin >> gx >> gy >> gb;
    if ( gx == 0 && gy == 0 && gb == 0 ) break;
    gx += SHIFT;
    gy += SHIFT;
    cout << bfs(gx, gy, gb) << endl;
  }
}

Measured memory_bytes: 4008
#include <iostream>

using namespace std;

int main() {
    int N, H, W;
    cin >> N >> H >> W;

    int window[N * W];
    fill(window, window + N * W, 0);

    int x;
    for (int i = 0; i < N; i++) {
        cin >> x;
        if (i % 2 == 0) {
            window[i * W + x] += 1;
            window[(i + 1) * W + x] += -1;
        } else {
            window[i * W - x] += 1;
            window[(i + 1) * W - x] += -1;
        }
    }

    int ans = 0;

    for (int i = 0; i < N * W; i++) {
        if (i > 0) window[i] += window[i - 1];
        if (window[i] == 0) ans += H;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 	int h, n, sum = 0;
  	cin >> h >> n;
  	int a[n];
  	for(int i = 0; i < n; i++) {
      	cin >> a[i];
      	sum += a[i];
    }
  	cout << ((sum >= h) ? ("Yes") : ("No")) << endl;
  	return 0;
}

Measured memory_bytes: 640
N, K = map(int, input().split())
p = list(map(int, input().split()))

res = sum(p[:K])
res_max = res
i_max = 0
for i in range(1, N-K+1):
    res += p[i+K-1] - p[i-1]
    if res > res_max:
        res_max = res
        i_max = i

ans = 0
for j in range(K):
    ans += (p[i_max + j] + 1) / 2
print(ans)


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

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    cout << min(b / a, c) << endl;
}

Measured memory_bytes: 3552
#include <stdio.h>
int a[999],b[999];
int main(void){
  int i=0;
  int k=0;
  while(1){
    scanf("%d%d",&a[i],&b[i]);
    if(a[i]==0&&b[i]==0) break;
    i++;
  }
  while(k<i){
    int j;
    int l;
    for(j=0;j<a[k];j++){
      for(l=0;l<b[k];l++){
	printf("#");
      }
      printf("\n");
    }
    printf("\n");
    k++;
  }
  return 0;
}

Measured memory_bytes: 576
from collections import defaultdict
import heapq

def main():
    N, M = map(int, input().split())
    d = defaultdict(list)
    for _ in range(N):
        A, B = map(int, input().split())
        d[A].append(B)

    num_list = []
    heapq.heapify(num_list)
    ans = 0
    for i in range(1,M+1):
        if d[i]:
            for j in d[i]:
                heapq.heappush(num_list,-j)
        
        if num_list:
            ans -= heapq.heappop(num_list)

    print(ans)

    


main()

Measured memory_bytes: 77656
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let uvw: Vec<(usize, usize, i64)> = (0..n - 1)
        .map(|_| {
            let u = input();
            let v = input();
            let w = input();
            (u, v, w)
        })
        .collect();

    let mut path = vec![vec![]; n + 1];
    for &(u, v, w) in &uvw {
        path[u].push((v, w));
        path[v].push((u, w));
    }

    let mut visited = vec![false; n + 1];
    let mut d = vec![0; n + 1];
    visited[1] = true;
    dfs(1, 0, &mut d, &mut visited, &path);

    let out = std::io::stdout();
    let mut buf = std::io::BufWriter::new(out.lock());
    for i in 1..n + 1 {
        writeln!(buf, "{}", d[i] % 2).unwrap();
    }
}

fn dfs(
    cur: usize,
    dist: i64,
    d: &mut Vec<i64>,
    visited: &mut Vec<bool>,
    path: &Vec<Vec<(usize, i64)>>,
) {
    d[cur] = dist;
    for &(next, cost) in &path[cur] {
        if !visited[next] {
            visited[next] = true;
            dfs(next, dist + cost, d, visited, path);
        }
    }
}


Measured memory_bytes: 21884
#include<stdio.h>
int main(void)
{
	char str[21]={NULL};
	char aaa[21]={NULL};
	int i=0;
	int count=0;
	int dainyu=0;
	scanf("%20s",&str);
	for (i=0;i<20;i++)
	{
		if (str[i]==NULL)
		{
			break;
		}
		else
		{
			count++;
		}
	}
	for (i=count-1;i>=0;i--)
	{
		aaa[dainyu]=str[i];
		dainyu++;
	}
	printf("%s\n",&aaa);
	return 0;
}

Measured memory_bytes: 524