akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF 2000000000
using namespace std;
int main() {
    int h, n;
    cin >> h >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
    vector<vector<int>> dp(1100, vector<int>(11000, INF));
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= h; j++) {
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            dp[i+1][min(h, j+a[i])]
                = min(dp[i+1][min(h, j+a[i])], dp[i+1][j] + b[i]);
        }
    }
    cout << dp[n][h] << endl;
    return 0;
}

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

#define N 128
#define INT(X) \
  ( *( (const int *)(X) ) )

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

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int i;
  int n;

  while ( scanf ( "%d", &n ) == 1 )
  {
    int res = 0;
    int d[ N ];

    for ( i = 0; i < n; ++i )
    {
      scanf ( "%d", d + i );
    }
    qsort ( d, n, sizeof ( int ), comparator );

    for ( i = 1; i < n; ++i )
    {
      d[ i ] += d[ i - 1 ];
    }
    for ( i = 0; i < n; ++i )
    {
      res    += d[ i ];
    }

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

  return ( 0 );
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n; cin>>n;
  for(int i=0;i<n;i++){
    int a; cin>>a;
    if(a%2){
      cout<<"first"<<endl;
      return 0;
    }
  }
  cout<<"second"<<endl;
  return 0;
}

Measured memory_bytes: 3608
let split_string ?(pattern="") = Str.split @@ Str.regexp pattern
let s = read_line () |> split_string |> Array.of_list
let k = Scanf.sscanf (read_line ()) "%d" @@ fun k -> k

let s_len = Array.length s

let f = 
  let cnt = Array.of_list @@ fst @@ Array.fold_left (fun (acc, before) ch ->
    match acc with
      | [] -> ([1], ch)
      | x :: xs -> ((if before = ch then ((x + 1) :: xs) else 1 :: acc), ch)
  ) ([], "") s in
  if Array.length cnt = 1 then s_len * k / 2
  else
  (cnt |> Array.map (fun i -> i / 2) |> Array.fold_left (+) 0) * k -
    if s.(0) = s.(s_len - 1) then let a, b = cnt.(0), cnt.(Array.length cnt - 1) in (a / 2 + b / 2 - (a + b) / 2) * (k - 1)
    else 0

let () =
  Printf.printf "%d\n" @@ match s_len with
    | 1 -> k / 2
    | 2 -> if s.(0) = s.(1) then k else 0
    | _ -> f

Measured memory_bytes: 384
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
struct UnionFind{
  vector<int> data;
  int __size;
  UnionFind(int sz) {
  data.assign(sz, -1);
  __size = sz;
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);//親は負でサイズを保存
    __size--;
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  bool same(int x, int y){
    return find(x) == find(y);
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }

  int union_count() {
    return (__size);
  }
};
int main() {
  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    uf.unite(a, b);
  }
  cout << uf.union_count() - 1 << endl;
  return 0; 
}

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

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

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

int MOD=1000000007;
int modpow(int a,int x){
  if(a<0)a+=MOD;
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}

int gyaku(int n){
    return modpow(n,MOD-2);
}

auto factor(int n){
  map<int,int>res;
  for(int i=2;i*i<=n;i++){
      for(; n%i==0;n/=i) res[i]++;
  }
  if(n>1)res[n]++;
  return res;
}
////////////////////////////////////////////////////////////
signed main() {
  int n;
  cin>>n;
  int t=sqrt(n);
  for(int i=t;i>=1;i--){
    if(n%i==0){
      cout<<max(floor(log10(n/i))+1,floor(log10(i))+1);
      exit(0);
    }
  }
}


Measured memory_bytes: 4112
#include<iostream>

int x = 0  , y = 1 ;

int main()
{
	for(;(x != 0) || (y != 0);)
	{
		std::cin >> x  >> y;
		if(( x != 0 ) || ( y != 0 ))
		{
			if(x <= y)
			{
				std::cout << x << " " << y << std::endl ;
			}
			else
			{
				std::cout << y << " " << x << std::endl ;
			}
		}
	}
}

Measured memory_bytes: 1160
#include <iostream>

using namespace std;

typedef long long Long;
const Long MOD = Long(1e9 + 7);

Long pow(Long base, Long x) {
    if (x == 0) return 1;
    if (x % 2 == 1) return base * pow(base, x - 1) % MOD;
    Long y = pow(base, x / 2);
    return y * y % MOD;
}

int main() {
    int M, N; cin >> M >> N;
    cout << pow(M, N) << endl;
    return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
const int INF = 1001001001;

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

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y) swap(x, y);

	while (0 < y) {
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
Type lcm(Type x, Type y)
{
	return x * y / gcd(x, y);
}

template<class Type>
bool is_prime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2) {
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++) {
		if (isPrime[i]) {
			Type j = i + i;
			while (j <= n) {
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binary_search_judge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binary_search(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok)) {
		int mid = (ng + ok) / 2;
		if (binary_search_judge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	int odd = 0;
	int four = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] % 2 != 0) odd++;
		else if (a[i] % 4 == 0) four++;
	}

	if (a.size() % 2 == 0) {
		if (odd <= four) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	else {
		if (odd <= four + 1) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

	char s;
	cin >> s;
	if(s=='A'){
		cout << "T" << endl;
	} else if(s=='T'){
		cout << "A" << endl;
	} else if(s=='C'){
		cout << "G" << endl;
	} else {
		cout << "C" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
from collections import deque

def bfs(graph, visited, ss):
  queue = deque([ss])
  visited[ss] = 0
  ans = [0]*n
  while queue:
    s = queue.popleft()
    for new_s in graph[s] :
      if visited[new_s] == -1:
        #　移動回数の計算
        visited[new_s] = visited[s] + 1
        queue.append(new_s)
        ans[new_s] = s
  return ans

n,m = map(int,input().split())
graph = [[] for j in range(n)]

for i in range(m):
    a,b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

visited = [-1]*n
ans = bfs(graph, visited, 0)

print('Yes')
for i in range(1,n) :
  print(ans[i]+1)

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

using namespace std;

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;

const int MAX = 1E5+5;
ll a[MAX];

void max_heapify (ll a[], int i, int n){
	int left = 2*i;
	int right = 2*i+1;
	int largest;
	if (left <= n && a[left] > a[i])
		largest = left;
	else
		largest = i;
	if (right <= n and a[right] > a[largest])
		largest = right;
	if (largest != i){
		int temp = a[i];
		a[i] = a[largest];
		a[largest] = temp;
		max_heapify(a,largest,n);
	}
}

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

    int n,m;

    cin >> n >> m;

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

    for (int i=n/2; i>=1; --i){
    	max_heapify(a,i,n);
    }

    for(int i=1; i<=m; ++i){
    	a[1] /= 2;
    	max_heapify(a,1,n);
    }

    ll ans = 0LL;

    for(int i=1; i<=n; ++i){
    	ans += a[i];
    }

    cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4380
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#include<string>
#include<functional>
#include<set>
#include<unordered_map>
#define int long long
using namespace std;

int c[1000], d[1000];
unordered_map<int, int>U;
signed main() {
	int a, b; scanf("%lld%lld", &a, &b);
	for (int e = 0; e < a; e++)scanf("%lld", &c[e]);
	for (int e = 0; e < a; e++)scanf("%lld", &d[e]);
	for (int e = 0; e < a; e++) {
		for (int f = 0; f < a; f++) {
			U[c[e] + d[f]]++;
		}
	}
	int ans = 0;
	for (int e = 0; e < a; e++)scanf("%lld", &c[e]);
	for (int e = 0; e < a; e++)scanf("%lld", &d[e]);
	for (int e = 0; e < a; e++) {
		for (int f = 0; f < a; f++) {
			ans += U[b - (c[e] + d[f])];
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 82048
#include <bits/stdc++.h>
#define MAXN 1000100
#define pii pair<int, int>
#define pb push_back
#define inf 1e18
#define fi first
#define se second
#define mt make_tuple
typedef long long ll;

using namespace std;

int a, b, c;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> a >> b >> c;
    if(a + b + c < 22) cout << "win";
    else cout << "bust";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define reprr(i, m, n) for (ll i = m; i < n; i++)
#define inf (1ll<<40)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll N, K; cin >> N >> K;
    vvll s(N);
    rep(i, N) {
        ll t, d; cin >> t >> d; t--;
        s[t].push_back(d);
    }

    for (auto &v : s) {
        sort(all(v), greater<ll>());
        if (v.empty()) v.push_back(-inf);
    }

    sort(all(s), [&](vll a, vll b){return a[0] > b[0];});

    ll cur = 0;
    priority_queue<ll> que;
    rep(i, K) {
        cur += s[i][0];
        for (ll j = 1; j < s[i].size(); j++) que.push(s[i][j]);
    }
    for (int i = K; i < N; i++) rep(j, s[i].size()) que.push(s[i][j]);

    ll res = cur + K * K;
    for (ll x = K - 1; x >= 1; x--) {
        ll v = s[x][0];
        ll w = que.top();
        if (v < w) {
            que.pop(); cur += w;
            que.push(v); cur -= v;
        }
        res = max(res, cur + x * x);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 8696
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    n,m = map(int, input().split())
    adj = [[] for _ in range(n)] #頂点数, 場合によって変える
    for _ in range(m):
        a,b = map(int, input().split())
        adj[a-1].append(b-1)
    def bfs(start):
        pre = [-1]*n
        d = deque([start])

        while d:
            v = d.popleft()
            for nv in adj[v]:
                if nv == start:
                    path = []
                    while v != -1:
                        path.append(v+1)
                        v = pre[v]
                    return path

                if pre[nv] != -1:
                    continue
                pre[nv] = v
                d.append(nv)

        return []
    
    res = [0]*(n+1)
    for i in range(n):
        temp = bfs(i)
        if 0 < len(temp) < len(res):
            res = temp
    if len(res) <= n:
        print(len(res))
        print(*res, sep='\n')
    else:
        print(-1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 43244
N = gets.to_i
Xs, Ys = readlines.map{|l| l.split.map(&:to_i)}.transpose

@p = Array.new(N + 1, -1)

def root(x)
  @p[x] < 0 ? x : @p[x] = root(@p[x])
end

def unite(x, y)
  x, y = root(x), root(y)
  if x != y
    x, y = y, x if @p[y] < @p[x]
    @p[x] += @p[y]
    @p[y] = x
  end
end

hx, hy = {}, {}
Xs.zip(Ys, [*0 ... N]) do |x, y, i|
  unite(i, hx[x]) if hx[x]
  hx[x] = i
  unite(i, hy[y]) if hy[y]
  hy[y] = i
end
puts (0 ... N).group_by{|i| root(i)}.values.inject(-N){|s, a| s + a.map{|i| Xs[i]}.uniq.size * a.map{|i| Ys[i]}.uniq.size}

Measured memory_bytes: 33516
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var XYABC = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var (X, Y, A, B, C) = (XYABC[0], XYABC[1], XYABC[2], XYABC[3], XYABC[4]);

        var p = ReadLine().Split(' ').Select(s => int.Parse(s));
        var q = ReadLine().Split(' ').Select(s => int.Parse(s));
        var r = ReadLine().Split(' ').Select(s => int.Parse(s));

        var px = p.OrderByDescending(n => n).Take(X);
        var qy = q.OrderByDescending(n => n).Take(Y);
        
        var pqr = r.Concat(px).Concat(qy).OrderByDescending(n => n);

        var ans = pqr.Take(X + Y).Sum(n => (long)n);

        WriteLine(ans);
    }
}


Measured memory_bytes: 54468
#include <iostream>
#include <math.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main() {
	string S;
	bool n = false, s = false, e = false, w = false;
	cin >> S;
	for (int i = 0; i < S.size(); i++)
	{
		if (S[i] == 'N') {
			n = true;
		}
		if (S[i] == 'S') {
			s = true;
		}
		if (S[i] == 'E') {
			e = true;
		}
		if (S[i] == 'W') {
			w = true;
		}
	}
	if (n != s || e != w)cout << "No";
	else cout << "Yes";
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<vector>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;

int main(){
    int n;
    int A[200000];
    int ans[200000]={};
    cin >> n;
    for(int i=0;i<n-1;i++){
        cin >> A[i];
        ans[A[i]-1]++;
    }
    for(int i=0;i<n;i++){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 5156
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (b)-1; i >= (a); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
const ld EPS = 1e-12L;
const ld PI = 3.1415926535897932385L;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ull x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class S, class T>inline bool chmax(S &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class S, class T>inline bool chmin(S &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin >> n;
    vll a(n);
    multiset<ll> b;
    rep(i, n){
        cin >> a[i];
        b.emplace(a[i]);
    }
    ll ans = 0;
    while(!b.empty()){
        ll c = *b.rbegin();
        ll x = 1;
        while(x <= c) x <<= 1;
        b.erase(b.find(c));
        if(b.find(x-c) != b.end()){
            b.erase(b.find(x-c));
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11264
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int h1,m1,h2,m2,k;
int main() {
    scanf("%d %d %d %d %d",&h1,&m1,&h2,&m2,&k);
    printf("%d",h2*60+m2-h1*60-m1-k);
	return 0;
}


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

#define pi 3.14159265358979323846264338327950L

int main()
{
    int a, b, h, m;

    cin >> a >> b >> h >> m;

    long double angle = pi * 2 * ( (long double)h / 12.0 + ((long double)m / 60.0) / 12.0 - (long double)m / 60.0);

    long double ans = (long double)(a*a + b*b) - (long double)(2*a*b*cosl(angle));

    cout <<fixed << setprecision(10) << sqrt(ans) << endl;


    return 0;
}


Measured memory_bytes: 4088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
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; }

const int mod = 1000000007;
const int inf = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ll s;
    cin >> s;
    int v = 1e9;
    ll y2 = (s + v -1)/v;
    ll x2 = v-s%v==v?0:v-s%v;
    cout << 0 <<" " << 0 <<" "<< 1000000000 <<" "<< 1 <<" " << x2 << " " << y2; 
}

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

const int MAX_N = 2005;
int L[MAX_N][MAX_N] = {0};
int R[MAX_N][MAX_N] = {0};
int U[MAX_N][MAX_N] = {0};
int D[MAX_N][MAX_N] = {0};

int main(void){
    int H,W;
    cin >> H >> W;
    vector<string> field(H);
    for(int i=0;i<H;i++) cin >> field[i];

    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(field[i][j]=='#') continue;
            if(j==0) L[i][j] = 1;
            else L[i][j] = L[i][j-1] + 1;
        }
    }
    for(int i=0;i<H;i++){
        for(int j=W-1;j>=0;j--){
            if(field[i][j]=='#') continue;
            if(j==W-1) R[i][j] = 1;
            else R[i][j] = R[i][j+1] + 1;
        }
    }
    for(int j=0;j<W;j++){
        for(int i=0;i<H;i++){
            if(field[i][j]=='#') continue;
            if(i==0) U[i][j] = 1;
            else U[i][j] = U[i-1][j] + 1;
        }
    }
    for(int j=0;j<W;j++){
        for(int i=H-1;i>=0;i--){
            if(field[i][j]=='#') continue;
            if(i==H-1) D[i][j] = 1;
            else D[i][j] = D[i+1][j] + 1;
        }
    }

    int maxlight = 0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            int now = L[i][j] + R[i][j] + U[i][j] + D[i][j] -3;
            maxlight = max(maxlight, now);
        }
    }
    cout << maxlight << endl;
}

Measured memory_bytes: 67072
#include<stdio.h>
#define MAX 100000

int A[MAX],n;

int partition(int p, int r){
  int x,i,j,tmp;
  x = A[r];
  i = p - 1;
  for(j = p ; j < r ; j++){
    if(A[j] <= x){
      i = i + 1;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }
  tmp = A[i + 1];
  A[i + 1] = A[r];
  A[r] = tmp;
  
  return i + 1;
}

int main(){
  int i,q;
  scanf("%d",&n);
  for(i = 0 ; i < n ; i++){
    scanf("%d",&A[i]);
  }
  q = partition(0,n - 1);
  for(i = 0 ; i < n ; i++){
    if(i)printf(" ");
    if(i == q)printf("[");
    printf("%d",A[i]);
    if(i == q)printf("]");
  }
  printf("\n");
  return 0;
}



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

int main()
{
  vector<int> a(3);

  rep(i, 3) cin >> a[i];

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

  cout << abs(a.at(2) - a.at(1)) + abs(a.at(1) - a.at(0));
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define INT long long int
using namespace std;
INT n, t, ans = 987654321;

int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>t;
    for(int i = 0 ; i < n ; i++ )
    {
        int x, y;
        cin>>x>>y;
        if( y <= t ) ans = min(ans, (INT)x);
    }
    if( ans == 987654321 ) cout<<"TLE\n";
    else cout<<ans<<endl;
}


Measured memory_bytes: 256
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let a=read::<i32>();
    let _=read::<i32>();
    let c=read::<i32>();
    println!("{}",c-a)
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <iomanip>
#include <cmath>

using namespace std;

void solve(){
	int n, ai, max = 0;
	cin >> n;
	vector<int> a, b(n);
	for (int i = 0; i < n; i++){
		cin >> ai;
		if (ai > max) max = ai;
		a.push_back(ai);
	}
	vector<int> c(max + 1, 0);
	for (int i = 0; i < n; i++) c[a[i]]++;
	for (int i = 1; i <= max; i++) c[i] += c[i - 1];
	for (int i = n - 1; i >= 0; i--){
		b[c[a[i]] - 1] = a[i];
		c[a[i]]--;
	}
	for (int i = 0; i < n; i++){
		if (i) cout << " ";
		cout << b[i];
	}
	cout << endl;
}

signed main(){
	solve();
}

Measured memory_bytes: 18920
#include<bits/stdc++.h>
using namespace std;
int x;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>x;
	for(int i=1;i<=x;i++)
		if(i*360%x==0)
		{
			cout<<i*360/x<<endl;
			break;
		}
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define fori(i, m, n) for(int i = m; i < (int)n; i++)
#define forl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define all(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string btos(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int n,q;
  string s;
  cin>>n>>s>>q;
  vector<set<int>> tbl(26);
  rep(i,n){
    tbl[s[i]-'a'].insert(i);
  }
  rep(i,q){
    int type;cin>>type;
    if(type==1){
      int cur;cin>>cur;cur--;
      char ch;cin>>ch;
      char tar=s[cur];
      if(ch==tar)continue;
      tbl[ch-'a'].insert(cur);
      tbl[tar-'a'].erase(cur);
      s[cur]=ch;
    }else{
      int l,r;cin>>l>>r;l--;r--;
      int cnt=0;
      for(int j=0;j<26;j++){
        set<int> &pos=tbl[j];
        auto it=pos.lower_bound(l);
        if(it!=pos.end()&&*it<=r){
          cnt++;
        }
      }
      cout<<cnt<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 26116
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = n % 500;
        if (b <= a)
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}

Measured memory_bytes: 21844
# coding: utf-8

import sys
import math
import collections
import itertools
from inspect import currentframe
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def MI() : return map(int, input().split())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def chkprint(*args) : names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}; print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

N = I()
H = LI()

l = 0
ans = 0

for r in range(1, N) :
    if H[r - 1] < H[r] :
        l = r
    ans = max(ans, r - l)

print(ans)

Measured memory_bytes: 68976
#include<bits/stdc++.h>
#define append push_back
#define endl "\n"
#define N 100000
#define M 1000000007
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long int
#define cover(arr,val) memset(arr,val,sizeof(arr)) 
using namespace std;
int main()
{
	IOS;
	int n;
	cin >> n;
	ll arr[N],dp[N];
	for(int i=0;i<n;i++)
		cin >> arr[i];
	dp[n-1]=0;
	dp[n-2]=abs(arr[n-1]-arr[n-2]);
	for(int i=n-3;i>=0;i--)
	{
		dp[i] = min(abs(arr[i]-arr[i+2])+dp[i+2],abs(arr[i+1]-arr[i])+dp[i+1]);
	}
	cout << dp[0] << endl;
	return 0;
}


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

using namespace std;

bool isValid(int min, int max, int k){
	
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int n=0, k=0, max=0, min=123;
    
    for(int i=0; i<5; i++){
		cin >> n;
		if(n >= max) max = n;
		if(n <= min) min = n;
	}
	
    cin >> k;
    if( (max - min) > k ) cout << ":(" << endl;
    if( (max- min) <= k) cout << "Yay!" << endl;
    	
	
	return 0;
}

Measured memory_bytes: 256
// AUTHOR - SANDEEP PRADHAN
#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <iomanip>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <memory.h>
#include <assert.h>
#include<limits.h>


#define eps 1e-8
#define PI 3.141592653589793
#define bsize 512

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define bs 1000000007

using namespace std;


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

    vector<double> a(n);
    for(int i = 0; i < n; i++)
        cin>>a[i];

    vector<double> dp(n + 1);  // dp[i] - probability that there are i heads so far
    dp[0] = 1;
    for(int i = 0; i < n; i++) {
        for(int j = i + 1; j >= 0; j--) {   //j - no. of heads till now
            dp[j] = (j == 0 ? 0 : dp[j-1] * a[i]) + dp[j] * (1 - a[i]);
        }
    }

    double answer = 0;
    for(int heads = ceil(n/2.0); heads <= n; heads++) {
            answer += dp[heads];
    }

    cout << fixed << setprecision(9) << answer;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		
        Scanner scan = new Scanner(System.in);
        
        String str1 = scan.nextLine();
        
        
        int n = Integer.parseInt(str1);
        int[] l = new int[n];
        for (int i = 0 ; i<n ;i++) {
        	l[i]= Integer.parseInt(scan.next());
        }
        
        int max = 0 ;
        int hen  = 0;
        
        for (int i :l) {
        	if(i>max) {
        		hen += max;
        		max=i;
        	}else {
        		hen +=i;
        	}
        }
        String ans ;
        if (max<hen) {
        	ans = "Yes";
        }else {
        	ans = "No";
        }
        

		System.out.println(ans);
    }
}

Measured memory_bytes: 22996
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function root(par::Vector{Int},x::Int)
    index=par[x]
    while par[index]!=index
        index=par[index]
    end
    return index
end

function unite(par::Vector{Int},siz::Vector{Int},x::Int,y::Int)
    rx,ry=root(par,x),root(par,y)
    if rx==ry
        return 0
    elseif rx>ry
        rx,ry=ry,rx
    end
    par[ry]=rx
    siz[rx]+=siz[ry]
end

function same(par::Vector{Int},x::Int,y::Int)
    return root(par,x)==root(par,y)
end

function main()
    n,m,k=parseMap(split(readline()))
    par=[i for i in 1:n]
    siz=[1 for i in 1:n]
    ans=[-1 for i in 1:n]   # 自分を除いておく

    # 友達候補をUnion-Findで実装
    for i in 1:m
        a,b=parseMap(split(readline()))
        unite(par,siz,a,b)
        ans[a]-=1   # 友達なら候補ではないので-1
        ans[b]-=1   # 友達なら候補ではないので-1
    end

    # ブロック関係の相手を友達関係から除外
    for i in 1:k
        c,d=parseMap(split(readline()))
        if same(par,c,d)
            ans[c]-=1   # 友達候補に含まれていれば除外
            ans[d]-=1   # 友達候補に含まれていれば除外
        end
    end

    for i in 1:n
        ans[i]+=siz[root(par,i)]
    end
    println(join(ans," "))
end
main()

Measured memory_bytes: 170588
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int main(){
    int i,j,n,m,s1=0,cut1=0,s2=0,cut2=0,len;
    char a[]={"JOI"};
    char b[]={"IOI"};
    char c[10000];
    while(scanf("%s",c)!=EOF){
    len=strlen(c);
        s1=0;
        s2=0;
        cut1=0;
        cut2=0;
    for(i=0;i<len;i++){
        if(a[s1]==c[i]){
            s1++;
            if(s1==3){
                cut1++;
                s1=0;
            }
        }
        else{
            s1=0;
            if(a[s1]==c[i]){
                s1++;
            }
        }
        if(b[s2]==c[i]){
            s2++;
            if(s2==3){
                cut2++;
                s2=1;
            }
        }
        else{
            s2=0;
            if(b[s2]==c[i]){
                s2++;
            }
        }
    }
    cout<<cut1<<endl<<cut2<<endl;
    }
    return 0;
}

Measured memory_bytes: 3040
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

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

int main(int argc, char **argv)
{
    int N;
    cin >> N;
    ll H[N];
    REP(i, N) cin >> H[i];

    bool f = true;
    ll prev = H[N - 1];
    for (int i = N - 2; i >= 0; --i) {
        if (H[i] > prev + 1) {
            f = false;
            break;
        }
        else if (H[i] == prev + 1) {
            prev = H[i] - 1;
        }
        else {
            prev = H[i];
        }
    }
    if (f) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 1024
import sys
from collections import Counter

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K, *AB = map(int, read().split())
    c = Counter()
    for a, b in zip(*[iter(AB)] * 2):
        c[a] += b

    num = 0
    for k, n in sorted(c.items()):
        num += n
        if num >= K:
            ans = k
            break

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 108236
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 

using namespace std;
using namespace __gnu_pbds; 
#define     mod            (int)1e9+7
#define     MOD             998244353
#define     ll              long long
#define     mp              make_pair
#define     F               first
#define     S               second
#define     t()             int test;cin>>test;while(test--)
#define     ii              pair<int,int>
#define     que_max         priority_queue <int>
#define     IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define     endl            "\n"
typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif


 
int main()
 
{  
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif

    IOS;

    int n;
    cin>>n;
    std::vector<ll int> v(n);

   ll int xorr=0;

    for(auto &i: v )
      {
        cin>>i;
        xorr ^=i;
      }
   for(auto i: v)
   {
     cout<<(i^xorr)<<" ";
   }   
     


    
    
    
  
   
}

Measured memory_bytes: 4732
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

string sa,sb;

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	cin>>a>>b;
	cout<<6-a-b<<endl;
}

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

int main(){
int M,N;
int ans1=1,ans2=1;
  cin >> N >> M;
  if(N<2){
  	ans1 = 0;
  }else if(M<2){
  	ans2 =0;
  }
  if(N>=2){
  	for(int i=N;i>=N-1;i--){
    	ans1 *= i;
    }
  }
  if(M>=2){
  	for(int j=M;j>=M-1;j--){
   		ans2 *= j;
    }
  }


  cout << ans1/2 + ans2/2 <<endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.Collections;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        
        if(n % (2 * d + 1) == 0) {
            System.out.println((int)(n / (2 * d + 1)));
        }else {
            System.out.println((int)(n / (2 * d + 1)) + 1);
        }
        
        
    }
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
    /*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
int main() {
    int n,d;
    cin >> n>>d;
    ll ans =0;
    for(int i=0;i<n;i++){
        double x,y;
        cin >>x>>y;
        double che =pow(x,2)+pow(y,2);
        che = pow(che,0.5);
        if(d>=che)ans++;
    }
    cout<<ans<<endl;
}
    



Measured memory_bytes: 4468
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;
const ll mod=100000;
ll n,m,s[100001],a[100001];
ll now=0;
ll imos[100001];
int main()
{
	cin>>n>>m;
	for(ll i=0;i<n-1;i++){
		cin>>s[i];	
		s[i]%=mod;
	}
	for(ll i=0;i<m;i++) cin>>a[i];
	for(ll i=0;i<m;i++){
		if(a[i]>0){
			imos[now]+=1;
			now+=a[i];
			imos[now]-=1;
		}
		else{
			imos[now]-=1;
			now+=a[i];
			imos[now]+=1;
		}
	}
	for(ll i=1;i<n-1;i++){
		imos[i]+=imos[i-1];
	}
	ll ans=0;
	for(ll i=0;i<n-1;i++){
		ans=(ans+imos[i]*s[i])%mod;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 5440
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int sum = scan.nextInt();
		int s = sum%60;
		int h = sum/3600;
		int m = (sum%3600)/60;
		System.out.println(h+":"+m+":"+s);
	}
}

Measured memory_bytes: 17164
// eddy1021
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
#define mod9 1000000009LL
#define mod7 1000000007LL
#define INF  1023456789LL
#define INF16 10000000000000000LL
#define eps 1e-9
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#ifndef ONLINE_JUDGE
#define debug(...) printf(__VA_ARGS__)
#else 
#define debug(...)
#endif
inline LL getint(){
  LL _x=0,_tmp=1; char _tc=getchar();    
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
inline LL add( LL _x , LL _y , LL _mod = mod7 ){
  _x += _y;
  return _x >= _mod ? _x - _mod : _x;
}
inline LL sub( LL _x , LL _y , LL _mod = mod7 ){
  _x -= _y;
  return _x < 0 ? _x + _mod : _x;
}
inline LL mul( LL _x , LL _y , LL _mod = mod7 ){
  _x *= _y;
  return _x >= _mod ? _x % _mod : _x;
}
LL mypow( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 1LL;
  LL _ret = mypow( mul( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = mul( _ret , _a , _mod );
  return _ret;
}
LL mymul( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 0LL;
  LL _ret = mymul( add( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = add( _ret , _a , _mod );
  return _ret;
}
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
#define Bye exit(0)
int __ = 1 , _cs;
/*********default*********/
#define N 101010
void build(){

}
LL n , l , t , x[ N ] , d[ N ];
vector< pair<LL,LL> > o;
void init(){
  n = getint();
  l = getint();
  t = getint();
  for( int i = 0 ; i < n ; i ++ ){
    x[ i ] = getint();
    d[ i ] = getint();
    if( d[ i ] == 2 ) d[ i ] = -1;
    o.push_back( { x[ i ] , i } );
  }
  sort( o.begin() , o.end() );
}
LL ans[ N ];
void solve(){
  vector<LL> p;
  LL nc = 0;
  for( int i = 0 ; i < n ; i ++ ){
    LL pos = x[ i ] + d[ i ] * t;
    LL fp = ( pos % l + l ) % l;
    LL g = pos > 0 ? pos / l : ( pos - l + 1 ) / l;
    nc += g;
    p.push_back( fp );
  }
  nc = ( nc % n + n ) % n;
  sort( p.begin() , p.end() );
  for( int i = 0 ; i < n ; i ++ )
    ans[ o[i].second ] = p[ ( i + nc ) % n ];
  for( int i = 0 ; i < n ; i ++ )
    printf( "%lld\n" , ans[ i ] );
}
int main(){
  build();
  //__ = getint();
  while( __ -- ){
    init();
    solve();
  }
}


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

namespace ABC098_A_Add_Sub_Mul
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			string[] input = Console.ReadLine().Split(' ');

			int a = int.Parse(input[0]);
			int b = int.Parse(input[1]);
			
			List<int> abArr = new List<int>();
			abArr.Add(a + b);
			abArr.Add(a - b);
			abArr.Add(a * b);

			int index = abArr.IndexOf(abArr.Max());

			Console.WriteLine(abArr[index]);
		}
	}
}

Measured memory_bytes: 13152
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

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

    for(int i = 0; i < s.size(); ++i){
        s[i] += n;
        if(s[i] > 'Z'){
            s[i] = s[i] % 'A' + 39;
        }
        cout << s[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iomanip>
#include<iostream>
#include<queue>
#include<string>
#include<unordered_set>
#include<vector>
using namespace std;
typedef long long ll;
const ll INF = 1000000000000000000;

ll N;
unordered_set<ll> us;

bool contains(ll x){
    if(us.count(x)>0){
        return true;
    }else{
        return false;
    }
}

int main() {
    cin >> N;
    for(int i=0; i<N; i++){
        ll x;
        cin >> x;
        if(contains(x)){
            cout << "NO" << endl;
            return 0;
        }else{
            us.insert(x);
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 8520
/*⠄⢰⣧⣼⣯⠄⣸⣠⣶⣶⣦⣾⠄⠄⠄⠄⡀⠄⢀⣿⣿⠄⠄⠄⢸⡇⠄⠄
⠄⠄⠄⣾⣿⠿⠿⠶⠿⢿⣿⣿⣿⣿⣦⣤⣄⢀⡅⢠⣾⣛⡉⠄⠄⠄⠸⢀⣿⠄
⠄⠄⢀⡋⣡⣴⣶⣶⡀⠄⠄⠙⢿⣿⣿⣿⣿⣿⣴⣿⣿⣿⢃⣤⣄⣀⣥⣿⣿⠄
⠄⠄⢸⣇⠻⣿⣿⣿⣧⣀⢀⣠⡌⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠿⠿⣿⣿⣿⠄
⠄⢀⢸⣿⣷⣤⣤⣤⣬⣙⣛⢿⣿⣿⣿⣿⣿⣿⡿⣿⣿⡍⠄⠄⢀⣤⣄⠉⠋⣰
⠄⣼⣖⣿⣿⣿⣿⣿⣿⣿⣿⣿⢿⣿⣿⣿⣿⣿⢇⣿⣿⡷⠶⠶⢿⣿⣿⠇⢀⣤
⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣽⣿⣿⣿⡇⣿⣿⣿⣿⣿⣿⣷⣶⣥⣴⣿⡗
⢀⠈⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠄
⢸⣿⣦⣌⣛⣻⣿⣿⣧⠙⠛⠛⡭⠅⠒⠦⠭⣭⡻⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⠄
⠘⣿⣿⣿⣿⣿⣿⣿⣿⡆⠄⠄⠄⠄⠄⠄⠄⠄⠹⠈⢋⣽⣿⣿⣿⣿⣵⣾⠃⠄
⠄⠘⣿⣿⣿⣿⣿⣿⣿⣿⠄⣴⣿⣶⣄⠄⣴⣶⠄⢀⣾⣿⣿⣿⣿⣿⣿⠃⠄⠄
⠄⠄⠈⠻⣿⣿⣿⣿⣿⣿⡄⢻⣿⣿⣿⠄⣿⣿⡀⣾⣿⣿⣿⣿⣛⠛⠁⠄⠄⠄
⠄⠄⠄⠄⠈⠛⢿⣿⣿⣿⠁⠞⢿⣿⣿⡄⢿⣿⡇⣸⣿⣿⠿⠛⠁⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠉⠻⣿⣿⣾⣦⡙⠻⣷⣾⣿⠃⠿⠋⠁⠄⠄⠄⠄⠄⢀⣠⣴
⣿⣿⣿⣶⣶⣮⣥⣒⠲⢮⣝⡿⣿⣿⡆⣿⡿⠃⠄⠄⠄⠄⠄⠄⠄⣠⣴⣿*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

ll MAX(ll a){return a;}
ll MIN(ll a){return a;}
template<typename... Args>
ll MAX(ll a,Args... args){return max(a,MAX(args...));}
template<typename... Args>
ll MIN(ll a,Args... args){return min(a,MIN(args...));}

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	char c;
	cin>>c;
	
	if ('A'<=c && c<='Z') cout<<"A";
	else cout<<"a"<<endl;
}


Measured memory_bytes: 3692
#include<stdio.h>
main(){
  int x,y,gcd,a,b;
  scanf("%d %d",&x,&y);
  while(1){
    a = x % y;
    b = y;
    x =b;
    y = a;
    if(y == 0){
      gcd = x;
      break;
    }
  }
  printf("%d\n",gcd);
  return 0;
}

Measured memory_bytes: 592
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
struct monster
{
	long long x,h;
}a[500005];
bool cmp(monster a,monster b)
{
	return a.x<b.x;
}
int main()
{
	long long n,d,hurt,ans=0,l=0,r=0,now=0;
	scanf("%lld%lld%lld",&n,&d,&hurt);
	for(long long i=0;i<n;i++) scanf("%lld%lld",&a[i].x,&a[i].h);
	sort(a,a+n,cmp);
	while(r<n)
	{
		ans+=(a[r].h+hurt-1)/hurt;
		now+=(a[r].h+hurt-1)/hurt;
		r++;
		while(a[r].x>2*d+a[l].x&&l<r)
		{
			now-=(a[l].h+hurt-1)/hurt;
			l++;
		}
		a[r].h-=now*hurt;
		if(a[r].h<0) a[r].h=0;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 4480
#include<stdio.h>

char c;
int f;
int nextInt();
int min(int a, int b);

int H, W, N, X, Y, low[200001], p, i, j;
int MAX = 524288;

int main(void){
	H=nextInt();
	W=nextInt();
	N=nextInt();
	for(i=2; i<=H; i++){
		low[i]=MAX;
	}
	for(i=0; i<N; i++){
		X=nextInt();
		Y=nextInt();
		if(Y<low[X]){
			low[X]=Y;
		}
	}
	for(i=2; i<=H; i++){
		if(low[i]==MAX){
		}else if(low[i]+p==i){
			p++;
		}else if(low[i]+p<i){
			printf("%d\n", i-1);
			return 0;
		}
	}
	printf("%d\n", H);
	return 0;
}

int nextInt(){
	f=0;
	c = getchar();
	while((c<'0')||('9'<c)){
		c=getchar();
	}
	while((c>='0')&&(c<='9')){
		f=f*10+(c-'0');
		c=getchar();
	}
	return f;
}

int min(int a, int b){
	return a>b?b:a;
}


Measured memory_bytes: 896
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

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

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = INF+7;

struct edge{int to,cost;};
	
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n,ma,mb;
	cin >> n >> ma >> mb;

	int a[n],b[n],c[n];
	for(int i=0;i<n;i++){
		cin >> a[i] >> b[i] >> c[i];
	}
	int num=500;
	int dp[n][num][num];
	for(int i=0;i<n;i++){
		for(int j=0;j<num;j++){
			for(int k=0;k<num;k++){
				dp[i][j][k] = INF;
			}
		}
		dp[i][a[i]][b[i]] = c[i];
	}
	dp[0][0][0] = 0;
	for(int k=1;k<n;k++){
		for(int i=0;i<num;i++){
			for(int j=0;j<num;j++){
				dp[k][i][j] = min(dp[k][i][j],dp[k-1][i][j]);
				if(i-a[k]>=1 && j-b[k]>=1 && dp[k-1][i-a[k]][j-b[k]]!=INF){
					dp[k][i][j] = min(dp[k][i][j],dp[k-1][i-a[k]][j-b[k]]+c[k]);
				}
			}
		}
	}
	int x,y,ans=INF;
	for(int i=1;;i++){
		y=ma*i; x=mb*i;
		if(y>=num || x>=num){
			break;
		}
		if(dp[n-1][y][x]!=INF){
			ans = min(ans,dp[n-1][y][x]);
		}
	}
	if(ans==INF) cout << "-1\n";
	else		cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 39296
#include<iostream>

using namespace std;

#define rep(i,n) for(i=0;i<(n);i++)
#define For(i,a,b) for(i=(a);i<(b);i++)

int main(){
  int i,j,k;
  int a,b;

  cin >> a >> b;
  if(a<b) cout << "a < b";
  else if(a>b) cout << "a > b";
  else cout << "a == b";
  cout << endl;
  
  return 0;
}

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

int main(){
  ll Q,H,S,D,N;
  cin>>Q>>H>>S>>D>>N;
  H=min(H,2*Q);
  S=min(S,2*H);
  D=min(D,2*S);

  cout<<N/2*D+(N%2)*S<<endl;

}


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

using namespace std;

typedef long long ll;

typedef long double ld;

const int N = 105;

int n;
int a[N];
int b[N];

int c[N];
int d[N];

int cnt;
int used[N];
int with[N];

bool match(int idx){
    for(int i = 1; i <= n; i++){
        if(a[idx] < c[i] && b[idx] < d[i] && !used[i]){
            used[i] = 1;
            if(!with[i] || match(with[i])){
                with[i] = idx;
                return true;
            }
        }
    }
    return false;
}

int main(){
    scanf("%d" , &n);
    for(int i = 1; i <= n; i++){
        scanf("%d%d" , &a[i] , &b[i]);
    }
    for(int i = 1; i <= n; i++){
        scanf("%d%d" , &c[i] , &d[i]);
    }
    int bst = 0;
    for(int i = 1; i <= n; i++){
        memset(used , 0 , sizeof used);
        if(match(i))
            bst++;
    }
    printf("%d\n" , bst);
}


Measured memory_bytes: 3788