akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
using namespace std;
using ull = unsigned long long;
using ll = long long;
ll a[200001], sum[200001];
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ull n;
	cin >> n;
	for (size_t i = 1; i <= n; i++) {
		cin >> a[i];
		sum[i] = sum[i - 1] + a[i];
	}
	ll ans = sum[n];
	size_t ptr1 = 1, ptr2 = 3, t;
	for (size_t i = 2; i < n - 1; i++) {
		ll curdif = abs(sum[i] - sum[ptr1] - sum[ptr1]);
		while ((t = ptr1 + 1) < i) {
			ll tcurdif = abs(sum[i] - sum[t] - sum[t]);
			if (tcurdif < curdif) {
				ptr1 = t;
				curdif = tcurdif;
			}
			else
				break;
		}
		curdif = abs(sum[ptr2] - sum[i] - (sum[n] - sum[ptr2]));
		while ((t = ptr2 + 1) < n) {
			ll tcurdif = abs(sum[t] - sum[i] - (sum[n] - sum[t]));
			if (tcurdif < curdif) {
				ptr2 = t;
				curdif = tcurdif;
			}
			else
				break;
		}
		ll p = sum[ptr1], q = sum[i] - sum[ptr1], r = sum[ptr2] - sum[i], s = sum[n] - sum[ptr2];
		ll x = min(min(p, q), min(r, s));
		ll y = max(max(p, q), max(r, s));
		ll t_ans = y - x;
		if (t_ans < ans) {
			ans = t_ans;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3328
# ARC086C - Not so Diverse (ABC081C)
n, k = list(map(int, input().rstrip().split()))
lst = sorted(list(map(int, input().rstrip().split())))
dic = {}
for i in lst:
    if i not in dic:
        dic[i] = 1
    else:
        dic[i] += 1

cnt = sorted([i for i in dic.values()], reverse=True)
print(sum(cnt[k:]))

Measured memory_bytes: 33696
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<functional>
using namespace std;
#define ll long long int
#define ld long double
using namespace __gnu_pbds;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,
tree_order_statistics_node_update> in_set;
#define rep(n) for(ll i=0;i<(n);i++)
#define jrep(n) for(ll j=0;j<(n);j++)
#define krep(n) for(ll k=0;k<(n);k++)
#define all(a) (a).begin(), (a).end()
#define dpp(a) cout<<(a).first<<" "<<(a).second<<endl;
#define append push_back
#define mod 2000007
#define ff first
#define ss second
#define ffast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fast ios::sync_with_stdio(0);
ll pw(ll x,ll y,ll p=mod){ll r=1; x=x%p;while(y>0){ if(y&1)r=(r*x)%p;
y=y>>1;x=(x*x)%p;} return r; } 

void solve(ll ts){
    ll a,b,c; cin>>a>>b>>c;
    if(b*c>=a) cout<<"Yes\n"; else cout<<"No\n";
}
 
int main(){
    ffast
    ll t=1;
//    cin>>t;
    rep(t) solve(i+1);
}
 
 
// *p.find_by_order(n) : nth value (0 indexed)
// p.order_of_key(7): index of 7 (0 indexed)


Measured memory_bytes: 3636
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <map>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <string>

const int MAX_N = 100050;
int R, C, N;

int x[MAX_N][3], y[MAX_N][3];

std::map<int, int> left, down;
std::map<int, int, std::greater<int>> right, up;


int main(int argc, char **argv) {
    std::cin >> R >> C >> N;

    for (int i = 1; i <= N; i++) {
        std::cin >> x[i][1] >> y[i][1] >> x[i][2] >> y[i][2];
    }

    for (int i = 1; i <= N; i++) {
        if ((x[i][1] == 0 || x[i][1] == R || y[i][1] == 0 || y[i][1] == C) &&
            (x[i][2] == 0 || x[i][2] == R || y[i][2] == 0 || y[i][2] == C)
        ) {
            //std::cout << "check:" << i << std::endl;
            if (x[i][1] == 0) {
                up[y[i][1]] = i;
            } else if (x[i][1] == R) {
                down[y[i][1]] = i;
            } else if (y[i][1] == 0) {
                left[x[i][1]] = i;
            } else if (y[i][1] == C) {
                right[x[i][1]] = i;
            }

            if (x[i][2] == 0) {
                up[y[i][2]] = i;
            } else if (x[i][2] == R) {
                down[y[i][2]] = i;
            } else if (y[i][2] == 0) {
                left[x[i][2]] = i;
            } else if (y[i][2] == C) {
                right[x[i][2]] = i;
            }
        }
    }

    std::vector<int> vec;
    for (auto itr = left.begin(); itr != left.end(); ++itr) {
        if (0 < vec.size() && vec.back() == itr->second) {
            vec.pop_back();
        } else {
            vec.push_back(itr->second);
        }
        //std::cout << itr->second << " " << vec.size() << std::endl;
    }

    for (auto itr = down.begin(); itr != down.end(); ++itr) {
        if (0 < vec.size() && vec.back() == itr->second) {
            vec.pop_back();
        } else {
            vec.push_back(itr->second);
        }
        //std::cout << itr->second << " " << vec.size() << std::endl;
    }

    for (auto itr = right.begin(); itr != right.end(); ++itr) {
        if (0 < vec.size() && vec.back() == itr->second) {
            vec.pop_back();
        } else {
            vec.push_back(itr->second);
        }
        //std::cout << itr->second << " " << vec.size() << std::endl;
    }

    for (auto itr = up.begin(); itr != up.end(); ++itr) {
        if (0 < vec.size() && vec.back() == itr->second) {
            vec.pop_back();
        } else {
            vec.push_back(itr->second);
        }
        //std::cout << itr->second << " " << vec.size() << std::endl;
    }

    if (vec.size() == 0) {
        std::cout << "YES" << std::endl;
    } else {
        std::cout << "NO" << std::endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 12544
#include<stdio.h>
  
int main(void)
{
    long a[10000], min, max, sum;
    int n, i;
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%ld", &a[i]);
    }
    sum = 0;
    max = a[0];
    min = a[0];
    for(i = 0; i < n; i++){
        sum = sum + a[i];
        if(max < a[i]){
            max = a[i];
        }
        if(min > a[i]){
            min = a[i];
        }
    }
    printf("%ld %ld %ld\n", min, max, sum);
    return 0;
}

Measured memory_bytes: 1928
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    vector<int> e(12);
    for(int i=0; i<12; ++i)
        cin >> e[i];

    sort(e.begin(), e.end());
    if(e[0] == e[3] && e[4] == e[7] && e[8] == e[11])
        cout << "yes" << endl;
    else
        cout << "no" << endl;

    return 0;
}

Measured memory_bytes: 3132
#include <iostream>


int main(){
int a,b;
char p;

while(1){

std::cin>>a>>p>>b;
if(p=='?')break;
 else if(p=='+'){
std::cout<<a+b<<"\n";
} else if(p=='-'){
std::cout<<a-b<<"\n";
} else if(p=='*'){
std::cout<<a*b<<"\n";
} else if(p=='/'){
std::cout<<a/b<<"\n";
} 

}

return 0;
}

Measured memory_bytes: 3104
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;
int a, b, c, d, e, f;
const double eps = 1e-6;
const int MAXN = 3000 + 10;
bool water[MAXN];
bool sugar[MAXN];

double solve(int water, int suger) {
}
int main() {
//    freopen("test.txt", "r", stdin);
    cin >> a >> b >> c >> d >> e >> f;
    water[0] = true;
    sugar[0] = true;
    for (int i = 0; i <= f; i++) {
        if (water[i]) {
            if (i+100*a <= f) water[i+100*a] = true;
            if (i+100*b <= f) water[i+100*b] = true;
        }
        if (sugar[i]) {
            if (i+c <= f) sugar[i+c] = true;
            if (i+d <= f) sugar[i+d] = true;
        }
    }
    double rate = -1;
    int ret[2];
    for (int i = 100; i <= f; i += 100) {
        if (!water[i]) continue;
        int tmp = f - i;
        double tmp1 = (double)e / 100.0 * i;
        tmp = min(tmp, (int)tmp1);
        for (int j = tmp; j >= 0; j--) {
            if (sugar[j]) {
                if ((double)j/i > rate) {
                    rate = (double)j / i;
                    ret[0] = i;
                    ret[1] = j;
                }
                break;
            }
        }
    }
    cout << ret[0]+ret[1] << ' ' << ret[1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 100000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };



int main() {
	char a[3][3];
	rep(i, 0, 3)rep(j, 0, 3)cin >> a[i][j];
	cout << a[0][0] << a[1][1] << a[2][2] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAX_N = 2e5 + 5;
const long long mod = 1e9 + 7;

int n, k, s;
void solve() {
    int i = 0;
    for(i = 0; i < k; i++)
        cout << s << " ";
    for(i = k; i < n; i++) {
        if(s == 1e9) cout << 1 << " ";
        else cout << s + 1 << " ";
    }
}


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int test = 1;
    //cin >> test;
    while(test--){
        int i = 0;
        cin >> n >> k >> s;
        solve();
    }

    return 0;
}


Measured memory_bytes: 1280
N=int(input())
Robot=[]
for i in range(N):
    x,l = map(int,input().split())
    Robot.append([x-l,x+l])

Robot.sort(key=lambda x: x[1])

ans = 1
ac_max = Robot[0][1]
for i in range(1,N):
    if ac_max <= Robot[i][0]:
        ans += 1
        ac_max = Robot[i][1]

print(ans)

Measured memory_bytes: 21336
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    N=int(readline())
    C=[0]*(N-1)
    S=[0]*(N-1)
    F=[0]*(N-1)
    for i in range(N-1):
        C[i],S[i],F[i]=map(int,readline().split())

    for i in range(N):
        if i==N-1:
            print(0)
            break
        for j in range(i,N-1):
            if j==i:
                t=S[j]+C[j]
            else:
                if t<S[j]:
                    t+=S[j]-t
                else:
                    t+=(S[j]-t)%F[j]
                t+=C[j]
        print(t)

if __name__=="__main__":
    main()

Measured memory_bytes: 3188
//In the name of Allah
#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define int long long 

const int N=1e5+200;

int a[N],b[N];

int32_t main(){
    ios::sync_with_stdio(0);cin.tie(0);
 	int n; 
	cin>>n; 
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
	}
	int ans=0;
	for(int i=n-1;i>=0;i--){
		int tmp=b[i]-((a[i]+ans)%b[i]);
		if(tmp==b[i])tmp=0;
		ans+=tmp;
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 1792
from math import gcd

N=int(input())
A = [0] + list(map(int, input().split()))
L = [0]*(N+2)
R = [0]*(N+2)
ans = 0
L[0] = 0
R[N+1] = 0
for i in range(1, N+1):
    L[i+1] = gcd(L[i], A[i])
for i in range(N, 0, -1):
    R[i] = gcd(R[i+1], A[i])
for i in range(N+1):
    ans = max(ans, gcd(L[i], R[i+1]))
print(ans)

Measured memory_bytes: 86844
class Tree:
    def __init__(self, orders):
        self.root = None
        for order in orders:
            if len(order) == 1:
                self.inorder_print()
                self.preorder_print()
            else:
                if len(order[0]) == 4:
                    self.find(int(order[1]))
                else:
                    self.insert(int(order[1]))

    def insert(self, key):
        z = Node(key)
        y = None
        x = self.root
        while x:
            y = x
            if z.key < x.key:
                x = x.left
            else:
                x = x.right
        z.parent = y

        if not y:
            self.root = z
        elif z.key < y.key:
            y.left = z
        else:
            y.right = z

    def find(self, key):
        self.root.find(key)

    def inorder_print(self):
        self.root.inorder_print()
        print()

    def preorder_print(self):
        self.root.preorder_print()
        print()


class Node:
    def __init__(self, key):
        self.key = key
        self.parent = None
        self.left = None
        self.right = None

    def find(self, key):
        k = self.key
        if key == k:
            print('yes')
        elif key < k:
            if self.left:
                self.left.find(key)
            else:
                print('no')
        else:
            if self.right:
                self.right.find(key)
            else:
                print('no')

    def inorder_print(self):
        if self.left:
            self.left.inorder_print()
        print(' {}'.format(self.key), end='')
        if self.right:
            self.right.inorder_print()

    def preorder_print(self):
        print(' {}'.format(self.key), end='')
        if self.left:
            self.left.preorder_print()
        if self.right:
            self.right.preorder_print()


if __name__ == '__main__':
    import sys
    m = int(input())
    orders = [line.strip().split() for line in sys.stdin]
    Tree(orders)


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

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n;
  	cin >> n;
    string s;
    cin >> s;
    if (n < s.length()) {
        s=s.substr(0,n);
        cout << s << "...\n";
    } else {
        cout << s << "\n";
    }
}


Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n,k;
vector<int> w;

bool check(int m){
	int i = 0,count = 0;
	while(true){
		count++;
		if(count > k) return false;
		int sum = 0;
		while(sum + w[i] <= m and i != n) sum += w[i], i++;
		if(i == n) break;
	}
	return true;
}

int bainary_search(int right){
	int left = 0, mid;
	while(left < right){
		mid = (left + right) / 2;
		if(check(mid) == true) right = mid;
		else left = mid + 1;
	}
	return left;
}

int main(){
	cin >> n >> k;
	w.resize(n);
	int maxR = 0;
	for(int i = 0; i < n; i++) cin >> w[i], maxR += w[i];
	cout << bainary_search(maxR) << endl;
	return 0;
}

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

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

  if (a+b > c+d) {
    cout << "Left" << endl;
  }
  else if (a+b == c+d) {
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}


Measured memory_bytes: 384
import sys, math,os
from io import BytesIO, IOBase
#from bisect import bisect_left as bl, bisect_right as br, insort
#from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
#from itertools import permutations,combinations
def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(Decimal, data().split()))
def outl(var) : sys.stdout.write(' '.join(map(str, var))+'\n')
def out(var) : sys.stdout.write(str(var)+'\n')
sys.setrecursionlimit(100000)
INF = float('inf')
mod = int(1e9)+7
from decimal import Decimal


def main():

    n=int(data())
    cnt=0
    i=2
    while i<(int(n**0.5)+1):
        if n%i==0:
            t=i
            while n%t==0:
                cnt+=1
                n//=t
                t*=i
            t//=i
            while t>1:
                if n%t==0:
                    n//=t
                else:
                    t//=i
        i+=1
    if n!=1:
        cnt+=1
    out(cnt)


if __name__ == '__main__':
    main()

Measured memory_bytes: 10144
#include <cstdio>

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

    char c[n];
    scanf("%s", c);

    int left[26], right[26];
    for (int i = 0; i < 26; i++) {
        left[i] = right[i] = 0;
    }

    for (int i = 0; i < n; i++) {
        int index = c[i] - 'a';
        right[index]++;
    }

    int numCommon = 0, maxNumCommon = 0;
    for (int i = 0; i < n; i++) {
        int index = c[i] - 'a';
        right[index]--;
        if (left[index] == 0 && right[index] > 0) {
            numCommon++;
            if (numCommon > maxNumCommon) {
                maxNumCommon = numCommon;
            }
        } else if (left[index] > 0 && right[index] == 0) {
            numCommon--;
        }
        left[index]++;
    }

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

Measured memory_bytes: 256
fn main() {
  let n: u32 = get::val();
  let xs: Vec<usize> = get::list();
  
  let comb = 3usize.pow(n);
  let odd = xs.iter().map(|&x|if x%2==0 {2} else {1}).product::<usize>();
  let ans = comb - odd;
  println!("{}", ans);
}

#[allow(dead_code)]
mod get {
  use std::io::*;
  use std::str::*;

  pub fn val<T: FromStr>() -> T {
    let mut buf = String::new();
    stdin().read_line(&mut buf).ok();
    buf.trim().parse::<T>().ok().unwrap()
  }

  pub fn vals<T: FromStr>(n: usize) -> Vec<T> {
    let mut vec: Vec<T> = vec![];
    for _ in 0 .. n {
      vec.push(val());
    }
    vec
  }

  pub fn tuple<T1: FromStr, T2: FromStr>() -> (T1, T2) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).ok();
    let mut it = buf.trim().split_whitespace();
    let x = it.next().unwrap().parse::<T1>().ok().unwrap();
    let y = it.next().unwrap().parse::<T2>().ok().unwrap();
    (x, y)
  }

  pub fn tuples<T1: FromStr, T2: FromStr>(n: usize) -> Vec<(T1, T2)> {
    let mut vec: Vec<(T1, T2)> = vec![];
    for _ in 0 .. n {
      vec.push(tuple());
    }
    vec
  }

  pub fn tuple3<T1: FromStr, T2: FromStr, T3: FromStr>() -> (T1, T2, T3) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).ok();
    let mut it = buf.trim().split_whitespace();
    let x = it.next().unwrap().parse::<T1>().ok().unwrap();
    let y = it.next().unwrap().parse::<T2>().ok().unwrap();
    let z = it.next().unwrap().parse::<T3>().ok().unwrap();
    (x, y, z)
  }

  pub fn tuple3s<T1: FromStr, T2: FromStr, T3: FromStr>(n: usize) -> Vec<(T1, T2, T3)> {
    let mut vec: Vec<(T1, T2, T3)> = vec![];
    for _ in 0 .. n {
      vec.push(tuple3());
    }
    vec
  }

  pub fn list<T: FromStr>() -> Vec<T> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).ok();
    buf.trim().split_whitespace().map(|t| t.parse::<T>().ok().unwrap()).collect()
  }

  pub fn lists<T: FromStr>(h: usize) -> Vec<Vec<T>> {
    let mut mat: Vec<Vec<T>> = vec![];
    for _ in 0 .. h {
      mat.push(list());
    }
    mat
  }
}

Measured memory_bytes: 4352
n = int(input())
s = input()
ls = list(s)
la = [chr(i) for i in range(65, 65+26)]
lind = []
for i in range(len(s)):
    for j in range(len(la)):
        if ls[i] == la[j]:
            lind.append(la.index(la[j]))
            break
lans = [la[lind[i]-26+n] for i in range(len(s))]
ans = ''.join(lans)
print(ans)

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

namespace ConsoleApplication2
{
    public class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(" ".ToCharArray());
            long min = long.Parse(str[0]);
            long max = long.Parse(str[1]);
            int count = Contest(min, max);

            Console.WriteLine("{0}", count);
        }

        public static int Contest(long min, long max)
        {
            int count = 0;

            for (; min <= max; count++, min *= 2) ;

            return count;
        }
    }
}


Measured memory_bytes: 11220
#include<iostream>
using namespace std;
int main()
{
  int n,ans=0;
  cin>>n;
  for(int i=1;i<=n;i++)
  {
    int a;
    cin>>a;
    if(i%2==0) continue;
    ans += a%2==1;
  }
  cout<<ans;
}

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

using namespace std;

const int N = 1234567;

vector <int> g[N];
int a[N];
bool err;

int dfs(int v, int pr) {
  int sz = g[v].size();
  int sum = 0;
  int cnt = 0;
  int mx = 0;
  for (int j = 0; j < sz; j++) {
    int u = g[v][j];
    if (u == pr) {
      continue;
    }
    cnt++;
    int cur = dfs(u, v);
    sum += cur;
    mx = max(mx, cur);
  }
  if (cnt == 0) {
    return a[v];
  }
  if (a[v] > sum || a[v] < mx || 2 * a[v] < sum) {
    err = true;
    return 0;
  }
  return 2 * a[v] - sum;
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
  }
  if (n == 2) {
    puts(a[0] == a[1] ? "YES" : "NO");
    return 0;
  }
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    x--; y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  err = false;
  int res = -1;
  for (int i = 0; i < n; i++) {
    if ((int) g[i].size() > 1) {
      res = dfs(i, -1);
      break;
    }
  }
  puts((res == 0 && !err) ? "YES" : "NO");
  return 0;
}


Measured memory_bytes: 39424
#include<iostream>
using namespace std;
int main()
{
  int k;
  int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cin >> k;
  cout << a[k-1] << endl;
  return 0;
}

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

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

vector<ll> pow_list(int n, int k, ll mod) {
  vector<ll> rtn(k + 1,0);
  rtn[1] = 1;
  rep(i,2,k + 1) {
    rtn[i] = modpow(i,n,mod);
  }
  return rtn;
}

ll mod(ll val, ll m) {
  ll res = val % m;
  if (res < 0) res += m;
  return res;
}

int main() {
  int n,k;
  cin >> n >> k;
  ll p = 1000000007;
  vector<ll> line(k + 1,0);
  ll ans = 0;
  vector<ll> pl = pow_list(n,k,p);
  revrep(i, k + 1, 1) {
    ll a = pl[k / i];
    ll b = 0;
    for (int j = i * 2; j <= k; j += i) {
      b += line[j];
      b %= p;
    }
    line[i] = mod(a - b, p);

    ans += (line[i] * i) % p;
    ans %= p;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4840
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
        String s[] = new String[n];
        int count[] = new int[n];
        for(int i = 0; i < n; i++){
        	s[i] = sc.next();
            count[i] = 0;
        }
        Arrays.sort(s);
        int max = 0;
        for(int i = 0; i < n - 1; i++){
        	for(int j = i + 1; j < n; j++){
            	if(s[i].equals(s[j])){
                	count[i]++;
                }else{
                	break;
                }
            }
            max = Math.max(max, count[i]);
            i += count[i];
        }
        for(int i = 0; i < n; i++){
        	if(max == count[i]){
            	System.out.println(s[i]);
            }
        }
    }
}

Measured memory_bytes: 72416
public class Main{
  public static void main(String[] args)
  {
	for(int i = 1; i < 10; i++)
        {
            for(int j = 1; j < 10; j++)
            {
            	System.out.println(i + "x" + j + "=" + i*j);
            }
        }
  }   
}


Measured memory_bytes: 24076
N,D = map(int,input().split())
L = []
for i in range(N):
    X = list(map(int,input().split()))
    L.append(X)
import itertools
C = list(itertools.combinations(L,2))
ans = 0
for i in range(len(C)):
    s = 0
    for j in range(D):
        s += (C[i][0][j]-C[i][1][j])**2
    s = s**0.5
    if s == int(s):
        ans += 1
print(ans)

Measured memory_bytes: 39024
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <tuple>
#include <cassert>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define mp(a,b) make_pair((a), (b))
#define mt(a,b,c) make_tuple((a),(b),(c))

typedef long long ll;

int main(){
    unsigned long long m = 1;
    int n; cin >> n;
    vector<unsigned long long> v(n); rep(i,n) cin >> v[i];
    sort(v.begin(), v.end());
    if(v[0]==0){cout << 0 << endl; return 0;}
    rep(i,n){
        if(1000000000000000000UL / m < v[i]){ cout << -1 << endl; return 0;}
        else m = m * v[i];
    }
    cout << m << endl;
    return 0;
}

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct UnionFind{
  ll N;
  llvec p;
  llvec cnt;
  UnionFind(ll n){
    N = n;
    p=llvec(N);
    cnt=llvec(N, 0);
    rep(i, N){
      p[i] = i;
      cnt[i] = 1;
    }
  }

  void con(ll a, ll b){
    P at = root(a);
    P bt = root(b);
    if(at.second!=bt.second){
      if(at.first>bt.first){
        swap(at, bt);
        swap(a, b);
      }
      p[at.second] = bt.second;
      cnt[bt.second]+=cnt[at.second];
      p[a]=bt.second;
    }
  }

  P root(ll a){
    ll atmp = a;
    ll c=0;
    while(atmp!=p[atmp]){
      atmp = p[atmp];
      c++;
    }
    p[a] = atmp;
    return {c, atmp};
  }

  bool is_con(ll a, ll b){
    P at=root(a);
    P bt=root(b);
    return at.second == bt.second;
  }
  
};

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }  
};


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  string S, T;
  cin >> S >> T;
  ll ans = 0;
  rep(i, S.size()){
    if(S[i]!=T[i])ans ++ ;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 3836
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll to;
	ll d;
};


///////////////////////////

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

	ll N = s.size();

	ll a = -1;
	ll b = -1;

	rep(i, N - 2) {
		if (s[i] == s[i + 2]) { a = i+1; b = i + 3; }
	}

	rep(i, N - 1) {
		if (s[i] == s[i + 1]) { a = i+1; b = i + 2; }
	}

	cout << a << " " << b;

	system("PAUSE");
}

Measured memory_bytes: 760
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 1005;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N;
    cin >> N;
    vector<vector<int> > table(MAX, vector<int>(MAX));
    for (int i = 0; i < N; i++) for (int j = 0; j < N-1; j++) cin >> table[i][j];
    for (int i = 0; i < N; i++) for (int j = 0; j < N-1; j++) table[i][j]--;

    map<pii, int> mp;
    vector<int> cnt(MAX);
    queue<int> q;
    for (int i = 0; i < N; i++) q.push(i);

    int days = 0;
    while (!q.empty()) {
        queue<int> qn;
        while (!q.empty()) {
            int a = q.front(); q.pop();
            int b = table[a][cnt[a]];
            if (a > b) swap(a, b);
            int c = mp[pii(a, b)]++;
            if (c == 0) continue;
            cnt[a]++, cnt[b]++;
            if (cnt[a] < N - 1) qn.push(a);
            if (cnt[b] < N - 1) qn.push(b);
        }
        q = qn;
        days++;
    }
    bool can = true;
    for (int i = 0; i < N; i++) {
        if (cnt[i] != N-1) can = false;
    }
    if (can) cout << days << '\n';
    else cout << -1 << '\n';
}



Measured memory_bytes: 35712
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
int main(int argc, const char * argv[]) {



    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin>>n;
    string s;
    int p;
    tuple<string,int,int>x[n];
    rep(i,n){
        cin>>s>>p;
        x[i]=make_tuple(s,-p,i+1);
    }
    sort(x,x+n);
    rep(i,n){
        cout<<get<2>(x[i])<<endl;
    }

    return 0;
}


Measured memory_bytes: 3608
from collections import deque

N, M = map(int, input().split())
rinsetu = [set() for _ in range(N + 1)]
for i in range(M):
    a, b = map(int, (input().split()))
    rinsetu[a].add(b)
    rinsetu[b].add(a)

grp = 0
color = ["white"] * (N + 1)
color_2 = ["white"] * (N + 1)
color[0] = "black"
for i in range(1, N + 1):
    count=1
    if color[i] == "white":
        d = deque()
        d.append(i)
        a = set()
        a.add(i)
        while (d):
            k = d.popleft()
            color[k] = "black"
            color_2[k]="black"
            for j in rinsetu[k]:
                if color[j] == "white" and color_2[j]=="white":
                    color_2[j]="black"
                    d.append(j)
                    count+=1
        grp=max(grp,count)
print(grp)

Measured memory_bytes: 160328
#include <bits/stdc++.h>                                           
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;  
typedef unsigned long long ull;         
typedef vector < pii > vpii;                                   	
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;
 
typedef tree < int, null_type, less < int >, rb_tree_tag, tree_order_statistics_node_update > ordered_set;
 
const int inf = 1e9, maxn = 2e5 + 48, mod = 998244353, N = 2e3 + 17;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 300;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = acos(-1);
const ll INF = 1e18;
 
 
int n, a[N*3], m, add, dp[N][N], b[N*3], mx[N], mx1;
bool good[N][N], good1[N];
 
main () {
	cin >> n;
	for (int i = 1; i <= n * 3; ++i)
		cin >> a[i];
 
	b[++m] = a[1];
	b[++m] = a[2];
 
	for (int j = 1; j < n; ++j) {
		if (a[j*3] == a[j*3 + 1] && a[j*3 + 1] == a[j*3 + 2]) {
			++add;
		} else {
			b[++m] = a[j*3];
			b[++m] = a[j*3 + 1];
			b[++m] = a[j*3 + 2];	
		}
	}
 
	b[++m] = a[n*3];
 
	good[b[1]][b[2]] = 1;
	good[b[2]][b[1]] = 1;
	good1[b[1]] = good1[b[2]] = 1;
 
	for (int i = 1; i < m / 3; ++i) {
		vi v;
		for (int j = 0; j < 3; ++j) 
			v.pb(b[i*3 + j]);
 
		vector < pair < pii, int > > V;
 
		for (int j = 1; j < 7; ++j) {
			vi v1, v2;
			for (int x = 0; x < 3; ++x)
				if (j & (1 << x))
					v1.pb(v[x]);
				else
					v2.pb(v[x]);
 
			if (sz(v1) == 1) {
				int a = v1[0], b = v2[0], c = v2[1];
				V.pb({{b, c}, mx1});
				if (good[a][a])
					V.pb({{b, c}, dp[a][a] + 1});
			} else {
				int a = v2[0], b = v1[0], c = v1[1];
				if (b == c) {
					for (int x = 1; x <= n; ++x) 
						if (good[x][b]) 
							V.pb({{x, a}, dp[x][b] + 1});					
				}
 
				for (int x = 1; x <= n; ++x) 
					if (good1[x])
						V.pb({{x, a}, mx[x]});
			}
		}
 
		for (auto x : V) {
			good1[x.f.f] = good1[x.f.s] = 1;
			good[x.f.f][x.f.s] = good[x.f.s][x.f.f] = 1;
			dp[x.f.f][x.f.s] = max(dp[x.f.f][x.f.s], x.s);
			dp[x.f.s][x.f.f] = max(dp[x.f.s][x.f.f], x.s);
			mx1 = max(mx1, x.s);
			mx[x.f.f] = max(mx[x.f.f], x.s);
			mx[x.f.s] = max(mx[x.f.s], x.s);
		}
 
	}
 
	int ans = 0;
	for (int x = 1; x <= n; ++x)
		for (int y = 1; y <= n; ++y)
			if (good[x][y]) 
				ans = max(ans, dp[x][y] + (x == y && y == b[m])); 
			
 
 
	cout << ans + add << endl;
}

Measured memory_bytes: 38092
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
int main() {
	int A, B, C;	cin >> A >> B >> C;
	for (int i = A; i <= A*B; i += A) {
		if (i%B == C) {
			cout << "YES" << endl;
			cin >> A;
			return 0;
		}
	}
	cout << "NO" << endl;
	cin >> A;
}

Measured memory_bytes: 256
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

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

#include<iostream>
#include<iomanip>


using namespace std;

int main()
{
    int r;
    cin>>r;
    
    double pi = 3.14159265358979323846;
    cout<<setprecision(9)<<pi*2*r;
    
}


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

int main(){
    int n,m,s,g;
    cin >> n >> m;
    vector<int> G[100001],route(2);
    set<int> st[100001];
    vector<bool> visited(n+1,false);
    for(int i = 0;i < m;i ++){
        int a,b;
        cin >> a >> b;

        G[a].push_back(b),G[b].push_back(a);
        st[a].insert(b),st[b].insert(a);

        if(!i) {
            s=a,g=b;
            visited[s]=1,visited[g]=1;
            route[0]=s,route[1]=g;
            st[s].erase(g);
            st[g].erase(s);
        }    
    }
    while(st[s].size()||st[g].size()){
        if(st[s].size()){
            int s1 = *st[s].begin();
            while(st[s].size()&&visited[s1]) {
                st[s].erase(s1);
                if(st[s].size()) s1 = *st[s].begin();
            }
            if(!st[s].size()) continue;
            st[s].erase(s1),st[s1].erase(s);
            s = s1;
            visited[s]=1;
            route.insert(route.begin(),s);
        }
        if(st[g].size()){
            int g1 = *st[g].begin();
            while(st[g].size()&&visited[g1]) {
                st[g].erase(g1);
                if(st[g].size()) g1 = *st[g].begin();
            }
            if(!st[g].size()) continue;
            st[g].erase(g1),st[g].erase(g);
            g = g1;
            visited[g]=1;
            route.push_back(g);
        }
    }
    cout << route.size() << endl;
    for(int i = 0;i < route.size();i ++){
        cout << route[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 20856
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(std::unique(all(x)), x.end());
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=acos(-1);
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<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...));
}

int main() {
    int n;
    cin>>n;
    vector<int> c(n+1);
    c[0]=-1;
    for(int i = 1; i <= n; i++) {
        cin>>c[i];
    }

    vector<ll> dp(n+10);
    vector<ll> cnt(200100);
    dp[0]=1;
    for(int i = 1; i <= n; i++) {
        dp[i]+=dp[i-1];
        if(c[i-1]==c[i]) continue;
        dp[i]+=cnt[c[i]];
        cnt[c[i]]+=dp[i-1];
        
        dp[i]%=MOD;
        cnt[c[i]]%=MOD;
    }
    cout<<dp[n]<<endl;
}



Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
bitset<2005> reach[2005];
vector<int> E[2005];
int mxh;
void dfs(int x, int root, int p = -1, int h = 0) {
	if (h > mxh) return;
	reach[root][x] = 1;
	for (int y : E[x]) {
		if (y == p) continue;
		dfs(y, root, x, h + 1);
	}
}
int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	vector<pair<int, int>> edges;
	for (int i = 1; i < n; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		E[a].push_back(b);
		E[b].push_back(a);
		edges.emplace_back(a, b);
	}
	mxh = k / 2;
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		dfs(i, i);
		if (k % 2 == 0) ans = max(ans, (int)reach[i].count());
	}
	if (k % 2) {
		for (auto& e : edges) {
			auto tot = reach[e.first] | reach[e.second];
			ans = max(ans, (int)tot.count());
		}
	}
	printf("%d\n", n - ans);
}


Measured memory_bytes: 896
# Problem C - Half and Half

# input
A, B, C, X, Y = map(int, input().split())

# initialization
min_count = min(X, Y)
max_count = max(X, Y)
dp = [0] * (max_count + 1)

# dynamic programming
for i in range(1, min_count+1):
    dp[i] = min(A+B+dp[i-1], C*2+dp[i-1])

if X>Y:
    for i in range(min_count+1, max_count+1):
        dp[i] = min(A+dp[i-1], C*2+dp[i-1])
elif Y>X:
    for i in range(min_count+1, max_count+1):
        dp[i] = min(B+dp[i-1], C*2+dp[i-1])

# output
print(dp[max_count])


Measured memory_bytes: 39664
N = int(input())
S = input()

alp = "abcdefghijklmnopqrstuvwxyz"
x = [1] * 26
for i in range(N):
    x[alp.find(S[i])] += 1
plo = 1
for i in range(26):
    plo *= x[i]
print((plo-1)%(10**9+7))



Measured memory_bytes: 3188
#include<stdio.h>
#include<string.h>

int main(void){
  struct data{
    char name[11];
    unsigned int point;
    unsigned char times[31];
  }person[20];
  unsigned int i,j,k,m,n,t,num;
  while(scanf("%u%*c",&n) && n){
    for(i=0;i<n;i++){
      scanf("%s%*c",person[i].name);
      person[i].point=0;
      for(j=0;j<31;j++) person[i].times[j]=0;
      scanf("%u%*c",&m);
      for(j=0;j<m;j++){
	scanf("%u%*c",&t);
	person[i].times[t]=1;
      }
    }
    for(i=0;i<31;i++){
      num=0;
      for(j=0;j<n;j++) num+=person[j].times[i];
      for(j=0;j<n;j++) if(person[j].times[i]) person[j].point+=n-num+1;
    }
    num=0;
    for(i=1;i<n;i++) if(person[i].point<person[num].point || (person[i].point==person[num].point && strcmp(person[i].name,person[num].name)<0) ) num=i;
    printf("%u %s\n",person[num].point,person[num].name);
  }
  return 0;
}

Measured memory_bytes: 0
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=100000;

int n; ll L,T;
ll x[MAXN]; int dir[MAXN];
pair<ll,ll> tmp[MAXN];
ll ret[MAXN];

int simulate(int at,ll CT) {
	ll t=0;
	int nxt=at;
	//puts("");
	while(true) {
		nxt=(nxt+1)%n; while(dir[nxt]==+1) nxt=(nxt+1)%n;
		ll nt=(x[nxt]-x[at])/2; while(nt<=t) nt+=L/2;
		//printf("%lld = %d\n",nt,nxt);
		if(nt>CT) return at;
		at=(at+n-1)%n; while(dir[at]==-1) at=(at+n-1)%n;
		ll nnt=(x[nxt]-x[at])/2; while(nnt<=nt) nnt+=L/2;
		//printf("%lld = %d\n",nnt,at);
		if(nnt>CT) return nxt;
		t=nnt;
	}
}

void solve() {
	int pos=-1; REP(i,n) if(dir[i]>0) { pos=i; break; }
	if(pos==-1) { REP(i,n) ret[i]=((x[i]-T)%L+L)%L; return; }
	int neg=-1; REP(i,n) if(dir[i]<0) { neg=i; break; }
	if(neg==-1) { REP(i,n) ret[i]=(x[i]+T)%L; return; }

	int fullperiod=(simulate(pos,L)+n-pos)%n;
	ll fulltimes=T/L;
	int diff=fulltimes*fullperiod%n;
	int topos=(pos+n-diff)%n;

	int remperiod=T%L==0?0:(simulate(pos,T%L-1)+n-pos)%n;
	//printf("fullperiod=%d fulltimes=%lld remperiod=%d -> delta=%d\n",fullperiod,fulltimes,remperiod,delta);

	REP(i,n) tmp[i]=MP(((x[i]+dir[i]*(T-1))%L+L)%L,((x[i]+dir[i]*T)%L+L)%L);
	int npos=(pos+remperiod)%n; ll nposx=tmp[npos].first;
	sort(tmp,tmp+n);
	int off=0; REP(i,n) if(tmp[i].first==nposx) off=i-topos;
	REP(i,n) { int j=(i+n+off)%n; ret[i]=tmp[j].second; }
}

void run() {
	scanf("%d%lld%lld",&n,&L,&T); L*=4; T*=4;
	REP(i,n) scanf("%lld%d",&x[i],&dir[i]),x[i]*=4,dir[i]=dir[i]==1?+1:-1;
	solve();
	REP(i,n) printf("%lld\n",ret[i]<0?ret[i]:ret[i]/4);
}

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


Measured memory_bytes: 4736
#include <stdio.h>

int main(void){
    int f1=0,s1=0,a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a % 5 == 0)
        f1++;
    if(a % 7 == 0)
        s1++;
    if(b % 5 == 0)
        f1++;
    if(b % 7 == 0)
        s1++;
    if(c % 5 == 0)
        f1++;
    if(c % 7 == 0)
        s1++;
    if(f1 == 2 && s1 == 1)
        puts("YES");
    else
        puts("NO");

    return 0;
}


Measured memory_bytes: 128
n, k = gets.chomp.split(" ").map(&:to_i)
pi = gets.chomp.split(" ").map(&:to_f)
dp = [0]
ans = 0

n.times do |i|
    dp << dp[i] + (1 + pi[i]) / 2.0
end

(n-k+1).times do |i|
    ans = [ans, dp[i+k]-dp[i]].max
end
puts ans

Measured memory_bytes: 21124
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef queue<ii> qii;

int nd;
vi dir;

void bfs(vvi &cv, vi &vis, int j) {
	qii ns;
	vis[0] = 0;
	ns.push(ii(j, 0));
	while (!ns.empty()) {
		ii e = ns.front(); ns.pop();
		if (vis[e.first] == -1) {
			vis[e.first] = vis[e.second] + 1;
			dir[e.first] = e.second;
			nd++;
			for (int i = 0; i < (int)cv[e.first].size(); i++) {
				if (vis[cv[e.first][i]] == -1)
					ns.push(ii(cv[e.first][i], e.first));
			}
		}			
	}
}

int main() {FIN
	
	int n, m, v, u, i;
	nd = 0;
	cin >> n >> m;
	vvi cv(n + 1);
	vi vis(n + 1, -1);
	dir = vi(n + 1);
	for (i = 0; i < m; i++) {
		cin >> u >> v;
		cv[u].push_back(v);
		cv[v].push_back(u);
	}
	
	bfs(cv, vis, 1);
	
	if (nd == n) {
		cout << "Yes\n";
		for (i = 2; i <= n; i++)
			cout << dir[i] << "\n";
	} else
		cout << "No\n";
	
	return 0;
}


Measured memory_bytes: 11152
N, Y = gets.split(" ").map(&:to_i)

res = "-1 -1 -1"
(0..N).each do |a|
  (0..(N - a)).each do |b|
    c = N - a - b
    if 10000 * a + 5000 * b + 1000 * c == Y
      res = "#{a} #{b} #{c}"
    end
  end
end
puts res


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

int main() {
  int N;
  cin >> N;
  
  int a, b, c, d;
  d = N % 10;
  N /= 10;
  c = N % 10;
  N /= 10;
  b = N % 10;
  N /= 10;
  a = N;

  bool tri = false;
  if(b == c) {
    if(a == b || c == d) {
      tri = true;
    }
  }
  
  if(tri) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
N = int(input())
mod = pow(10, 9) + 7
A = [0]*(N+1)
for i in range(2, N+1):
  for j in range(2, N+1):
    while i % j == 0:
      i //= j
      A[j] += 1
ans = 1
for i in range(len(A)):
  if A[i] != 0:
    ans *= A[i] + 1
print(ans % mod)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int , int> P;
typedef pair<ll, ll> PL;
const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;
 
bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

ll n;

ll a[100010],b[100010],sa[100010],samem[100010];
ll suma,sumsa;
 
int main(){
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        suma += a[i];
    }
    for(int i = 0; i < n; i++){
        cin >> b[i];
        sa[i] = b[i]-a[i];
        sumsa += sa[i];
    }
    sort(sa,sa+n);
  
    ll ans = 0;
    if(sumsa > 0){
        cout << -1 << endl;
        return 0;
    }

    ll minus = 0;
    for(int i = 0; i < n; i++){
        if(b[i] > a[i]) minus += b[i]-a[i];
    }

    ll sum = 0;
    while(minus > sum){
        sum += abs(sa[ans]);
        ++ans;
    }
    for(int i = 0; i < n; i++){
        if(b[i] > a[i]) ++ans;
    }
    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;

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

    ll ans = 0;
    if (k >= a) {
        ans += a;
    } else {
        // k < a
        ans += k;
    }
    k -= a;
    k -= b;

    if (k > 0) {
        ans -= k;
    }

    cout << ans << endl;

}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int a, b;
    cin >> a >> b;
    cout << max(0LL, a - 2 * b) << endl;
}

Measured memory_bytes: 256