akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define MOD 1000000007LL
#define STR_EQ(s1,s2)       strcmp(s1,s2)==0
#define rep(i,l,n) for(int (i)=(l);(i)<(n);(i)++)
#define invrep(i,l,n) for(int (i)=(l);(i)>=(n);(i)--)
//#define MOD 998244353LL
//#define MOD 1000000009LL
const long long INF = 1LL << 60;
typedef long long ll;
ll llabs(ll a){if(a<0)return -a;return a;}//abs
void swap(ll *a,ll *b){ll tmp=*a;*a=*b;*b=tmp;}//swap
int fact(int a){int r=1;for(int i = 1;i<=a;i++)r*=i;return r;}//factral
ll addm(ll a, ll b){ll x = (a%MOD+b%MOD)%MOD;if (x < 0) x+=MOD;return x;}//addmod,submod
ll mulm(ll a, ll b){return(a%MOD*b%MOD)%MOD;}//mulmod
ll lpow(ll x,ll n){ll ans = 1;while(n){if(n&1) ans*=x;x*=x;n>>=1;}return ans;} //power
ll powm(ll x,ll n){x%=MOD;ll ans = 1;while(n){if(n&1) ans=mulm(ans,x);x=mulm(x,x);n>>=1;}return ans;} //power mod
ll lgcd(ll a, ll b){if(a==b) return a;if(a<b) swap(&a,&b);if (b == 0) return a;return lgcd(b, a%b);}//gcd
ll llcm(ll a, ll b){return a*b/lgcd(a,b);};//lcm
ll legcd(ll a,ll b,ll *x,ll *y){if(b==0){*x=1;y=0;return a;}ll q = a/b;ll g = legcd(b,a-q*b,x,y);ll z = *x-q*(*y);*x=*y;*y=z;return g;}//extra_gdd
ll divm(ll a,ll b){ll x,y;a%=MOD;b%=MOD;legcd(b,MOD,&x,&y);x%=MOD;if(x<0) x+=MOD;return x;}//divmod_with_extra_gdd
ll permutation(ll n, ll m){if(n<m) return 0;if(n-m < m) m = n-m;int ans = 1;for(int i = 0;i<m;i++) ans*=(n-i);return ans;}//nPm
ll combination(ll n, ll m){return permutation(n,m)/m;}//nCm
int acmpinum(const void * left, const void * right){
	if (*(int *)left > *(int *)right) return 1;
	else if (*(int *)left < *(int *)right) return -1;
	else return 0;
}//qsort(int配列,配列の長さ,sizeof(int),acmpinum);
int dcmpinum(const void * left, const void * right){
	if (*(int *)left > *(int *)right) return -1;
	else if (*(int *)left < *(int *)right) return 1;
	else return 0;
}//qsort(int配列,配列の長さ,sizeof(int),dcmpinum);
int acmpllnum(const void * left, const void * right){
	if (*(ll *)left > *(ll *)right) return 1;
	else if (*(ll *)left < *(ll *)right) return -1;
	else return 0;
}//qsort(ll配列,配列の長さ,sizeof(ll),acmpllnum);
int dcmpllnum(const void * left, const void * right){
	if (*(ll *)left > *(ll *)right) return -1;
	else if (*(ll *)left < *(ll *)right) return 1;
	else return 0;
}//qsort(ll配列,配列の長さ,sizeof(ll),dcmpllnum);
int cmpchar(const void* left, const void* right) {
    char *left_char = (char *)left;
    char *right_char = (char *)right;
    return strcmp( left_char, right_char );
}//qsort(文字列配列,1,文字列の長さ,cmpchar);

typedef struct{
  int num;
  int flag;
}ball;

int main(){
    int N,M;
    scanf("%d %d",&N,&M);
  	int x[M],y[M];
  	rep(i,0,M) scanf("%d %d",&x[i],&y[i]);
  	ball b[N];
    rep(i,0,N){
      b[i].num=1;
      if(i==0) b[0].flag=1;
      else b[i].flag=0;
    }
  	rep(i,0,M){
      b[y[i]-1].num++;
      if(b[x[i]-1].flag==1) b[y[i]-1].flag=1;
      if(b[x[i]-1].num-- == 1) b[x[i]-1].flag=0;
    }
  	int ans=0;
  	rep(i,0,N) ans+=b[i].flag;
  	printf("%d\n",ans);
    return 0;
}

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

#define rep(i,n) for(ll i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;
//	std::cout<<std::fixed<<std::setprecision(10);

int main() {
	int a, b;
	cin >> a >> b;
	cout << 6 - a - b << endl;


	return 0;
}

Measured memory_bytes: 764
import sys

sys.setrecursionlimit(10**7)

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, k = na()
a = na()
for i in range(n):
    a[i] -= 1
ct = [0 for i in range(n)]
seen = [False] * n
def dfs(v):
    nv = a[v]
    seen[v] = True
    if ct[v] + 1 == k:
        return nv, 0
    elif seen[nv]:
        loop = ct[v] - ct[nv] + 1
        res = (k - ct[v] - 1) % loop
        return nv, res
    else:
        ct[nv] = ct[v] + 1
        return dfs(nv)

nv, res = dfs(0)
for i in range(res):
    nv = a[nv]
print(nv + 1)

Measured memory_bytes: 151216
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <math.h>
#include <unordered_map>
#include <bits/stdc++.h>

using namespace std;

int main(){
    long n;
    long m;
    double a = 0;
    long cnt;

    scanf("%ld", &n);

    m = sqrt(n);

    for(long i = 1; i <= n; i++){
        cnt = 0;
        for (long x = 1; x <= m; x++){
            for (long y = 1; y <= m;y++){
                for(long z = 1;z <= m;z++){
                    a = pow(x + y, 2) + pow(z + y, 2) + pow(x + z, 2);
                    if (a > 2 * i)
                    {
                        break;
                    }
                    else if(a == 2*i)
                    {
                        cnt++;
                    }
                }
            }
        }
        printf("%ld\n", cnt);
    }

            
    return 0;
}


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

int main()
{
  int n;
  cin>>n;
  int a[200005];
  for(int i=0;i<n;i++)
    cin>>a[i];
    int k=1,cnt=0;
  for(int i=0;i<n;i++){
    if(a[i]==k) {
        k++;
    }
    else cnt++;
  }
  if(cnt==n) cout<<-1;
  else cout<<cnt;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
#define vi vector<int>
#define tests int t; cin>>t; while(t--)
#define ll long long
#define vll vector<long long>
#define srt(v) sort(v.begin(), v.end())
#define srtg(v) sort(v.begin(), v.end(), greater<int> ())
#define FOR(k, n) for(int k=0; k<n; k++)
#define pb push_back
 
 
using namespace std;
using namespace std::chrono;
 
char nums[10] = { '0','1','2','3','4','5','6','7','8','9' };
char alphsl[26] = { 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' };
const int MOD = 1000000007;
char alphs[26] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };
 
 int cnt[100001];
 
 
void solve() {
 
   ll n;
   cin>>n;
   ll sum=0;
   vll v(n);
   for(int i=0; i<n; i++){
       cin>>v[i];
       sum+=v[i];
       cnt[v[i]]++;
   }
    ll q;
    cin>>q;
    for(int i=0; i<q; i++){
        ll a, b;
        cin>>a>>b;
        sum-=cnt[a]*a;
        sum+=cnt[a]*b;
        cnt[b]+=cnt[a];
        cnt[a]=0;
        cout<<sum<<endl;
}
   
   
}
 
 
int main() {
 
    ios_base::sync_with_stdio(false);
    cin.tie(0);
 
        
        solve();
 
 
    return 0;
}

Measured memory_bytes: 4532
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
 int x,a,b;
 cin >> x >> a >> b;
 int A=abs(x-a);
 int B=abs(x-b);
 if(A<B)cout << 'A' << endl;
 else if(A>B)cout << 'B' << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
string s;int n;
main()
{
	cin>>n>>s;
	int cnt=0;
	bool flag=false;
	do{
		flag=false;
		bool w[1<<17]={};
		int st=0;
		bool se=false,wo=true;
		if(cnt==4)
		{
			cout<<-1<<endl;
			return 0;
		}
		while(st<n&&s[st]!='o')st++;
		if(st==n)
		{
			for(int i=0;i<n;i++)cout<<'W';
			cout<<endl;
			return 0;
		}
		if(cnt<2)
		{
			w[st]=se;
			if(cnt==0)
			{
				if(s[(st-1+n)%n]==s[(st+1)%n])
				{
					w[(st-1+n)%n]=w[(st+1)%n]=se;
				}
				else
				{
					w[(st-1+n)%n]=w[(st+1)%n]=wo;
				}
			}
			else
			{
				if(s[(st-1+n)%n]==s[(st+1)%n])
				{
					w[(st-1+n)%n]=w[(st+1)%n]=wo;
				}
				else
				{
					w[(st-1+n)%n]=w[(st+1)%n]=se;
				}
			}
		}
		else
		{
			w[st]=wo;
			if(cnt==2)
			{
				if(s[(st-1+n)%n]==s[(st+1)%n])
				{
					w[(st-1+n)%n]=se,w[(st+1)%n]=wo;
				}
				else
				{
					w[(st-1+n)%n]=wo,w[(st+1)%n]=se;
				}
			}
			else
			{
				if(s[(st-1+n)%n]==s[(st+1)%n])
				{
					w[(st-1+n)%n]=wo,w[(st+1)%n]=se;
				}
				else
				{
					w[(st-1+n)%n]=se,w[(st+1)%n]=wo;
				}
			}
		}
		cnt++;
		for(int i=1;i<n-1;i++)
		{
			if(s[(st+i)%n]=='o'&&w[(st+i)%n]==se||
					s[(st+i)%n]=='x'&&w[(st+i)%n]==wo)
			{
				w[(st+i+1)%n]=w[(st+i-1+n)%n];
			}
			else
			{
				w[(st+i+1)%n]=!w[(st+i-1+n)%n];
			}
		}
		if(s[(st+n-1)%n]=='o'&&w[(st+n-1)%n]==se||
				s[(st+n-1)%n]=='x'&&w[(st+n-1)%n]==wo)
		{
			if(w[(st+n-2)%n]!=w[st])
			{
				flag=true;
			}
		}
		else
		{
			if(w[(st+n-2)%n]==w[st])
			{
				flag=true;
			}
		}
		if(s[st]=='o'&&w[st]==se||
				s[st]=='x'&&w[st]==wo)
		{
			if(w[(st+n-1)%n]!=w[(st+1)%n])
			{
				flag=true;
			}
		}
		else
		{
			if(w[(st+n-1)%n]==w[(st+1)%n])
			{
				flag=true;
			}
		}
		for(int i=0;!flag&&i<n;i++)
		{
			cout<<(w[i]==se?'S':'W');
		}
		if(!flag)cout<<endl;
	}while(flag);
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M;
  cin >> N;
  vector<string> strN(N);
  for (int i=0; i<N; i++) cin >> strN.at(i);
  cin >> M;
  vector<string> strM(M);
  for (int i=0; i<M; i++)  cin >> strM.at(i); 

  int ans = 0;
  map<string, int> table;
  for (int i=0; i<N; i++) table[strN.at(i)]++;
  for (int i=0; i<M; i++) table[strM.at(i)]--;
    
  auto bg = table.begin(), ed = table.end();
  for (auto iter = bg; iter != ed; iter++) {
        // first: key, second: value
//        cout << "key = " << iter->first << "\n";
//        cout << "value = " << iter->second << "\n";
    if(iter->second > ans) ans = iter->second;
    }
  cout << ans << endl;
}

Measured memory_bytes: 3544
// <------------- Template -----------------------> //


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(0);	
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll ,ll> 			pll;
typedef pair<ld,ld> 			pld;
typedef unordered_map<ll,ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5+7;
const ll 	MAX7 	= 	1e+7+7;
const ll 	MAXN 	= 	2 * 1e18;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9+7;

vll adj[200];ll visit[300]={};

// <------------- Declare Variables Here ------------> //

ll T=1;
ll n,x,y,q;
string s,t;
ll sum = 0;
// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

void MAIN() {
	cin>>n;
	vll a(n);
	for(ll i=0;i<n;i++) cin>>a[i];
	ll i=0;
	ll tt = 1;
	while(i<n) {
		if(a[i]==tt) {
			tt++;
		}
		i++;
	}
	tt--;
	if(tt == 0) cout<<-1;
	else cout<<n-tt;
 }

int main() {
	fastio;randomINT;
	//cin>>T;
	while(T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 4792
import java.util.*;
import java.util.stream.*;
class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int a,b;
        String op;
        a = input.nextInt();
        b = input.nextInt();
        if (a < b){
            op = "<";
        } else if (a > b){
            op = ">";
        } else {
            op = "==";
        }
        System.out.printf("a %s b\n",op);
    }
}


Measured memory_bytes: 26400
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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

int main() {
  string s;
  cin >> s;
  ll k;
  cin >> k;
  int target = 0;
  rep (i, s.size()) {
    if (s[i] != '1') break;
    target++;
  }
  if (target < k) {
    P(s[target]);
  } else {
    P(1);
  }



  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
    int64_t k;
    cin >> k;

    auto m = k / 50;
    auto r = k % 50;

    cout << 50 << endl;
    const auto* delim = "";
    for (auto i : irange(0L, r)) {
        cout << delim << 49 + m + 1 + 50 - r;
        delim = " ";
    }

    for (auto i : irange(r, 50L)) {
        cout << delim << 49 + m - r;
        delim = " ";
    }
    cout << endl;
}

Measured memory_bytes: 764
import sys
import math
input = sys.stdin.readline
n = int(input())
s = input().strip()
def idx(c):
	if c == 'R':
		return 0
	elif c == 'G':
		return 1
	else:
		return 2

cnt = [[0] * n, [0] * n, [0] * n]
for i in range(n):
	for c in range(3):
		if i > 0:
			cnt[c][i] = cnt[c][i - 1]
	cnt[idx(s[i])][i] += 1

ans = 0
for i in range(n):
	for j in range(i + 1, n):
		if s[i] != s[j]:
			rem = 3 - idx(s[i]) - idx(s[j])
			ans += cnt[rem][j - 1] - cnt[rem][i]
			if (i + j) % 2 == 0 and idx(s[(i + j) // 2]) == rem:
				ans -= 1
print(ans)


Measured memory_bytes: 69240
import scala.io.{StdIn => in}

object Main extends App {
  val Array(n, q) = in.readLine.split(" ").map(_.toInt)
  val s = in.readLine

  val table = Array.ofDim[Int](n)

  var acc = 0
  for(i <- 0 until n-1) {
    val ss = s.substring(i,i+2)
      table(i) = acc
    if(ss == "AC") {
      acc += 1
    }
  }
  table(n-1) = acc

  // debug(table.mkString(" "))
  val out = new java.io.PrintWriter(System.out)
  Iterator.continually(in.readLine)
    .take(q)
    .map(_.split(" ").map(_.toInt))
    .foreach(e => {
      val l = e(0) - 1
      val r = e(1) - 1
      // debug(l,r)
      out.println(table(r) - table(l))
    })
  out.flush

  def debug(any:Any*):Unit = {
    if(this.getClass.toString == "class Main$") return
    println(any.mkString(" "))
  }
}

Measured memory_bytes: 52424
import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container;
import std.numeric, std.math;
import core.bitop;

T RD(T = string)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }

long mod = pow(10, 9) + 7;
long moda(long x, long y) { return (x + y) % mod; }
long mods(long x, long y) { return ((x + mod) - (y % mod)) % mod; }
long modm(long x, long y) { return (x * y) % mod; }

void main()
{
	auto N = RD!long;
	auto A1 = RDR.split.to!(long[]);
	auto A2 = RDR.split.to!(long[]);

	auto dp = new long[](N+1);
	foreach (i; 0..N+1)
	{
		dp[i+1] = dp[i] + A1[i];
	}
	long sum2;
	foreach_reverse (i; 0..N)
	{
		sum2 += A2[i];
		dp[i+1] += sum2;
	}
	dp.sort();

	writeln(dp[N]);
	stdout.flush();
}

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

int main() {
	int A, B, C, K;
	cin >> A >> B >> C >> K;
	for (int i = 0; i <= K; i++) {
		int AA=A, BB=B;
		for (int ii = 0; ii < i; ii++) BB *= 2;
		for (int j = 0; j <= K-i; j++) {
			int CC = C;
			for (int jj = 0; jj < j; jj++) CC *= 2;
			if (AA < BB && BB < CC) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 3628
main = do
    n <- readLn :: IO Int
    print $ sum $ map (findG . snd) $ pfacTup n

findG n = length $ takeWhile (<=n) $ scanl1 (+) [1..]

sqrtInt :: Int -> Double
sqrtInt = sqrt . fromIntegral

pfacTup :: Int -> [(Int,Int)]
pfacTup n = fAux (takeWhile(<=floor(sqrtInt n))primes) n where
    fAux    _     1 = []
    fAux    []    n = [(n,1)]
    fAux q@(p:ps) n = if n`rem`p==0
        then let e = head (dropWhile (\x-> n`rem`(p^x) == 0) [1..])-1
            in (p,e):(fAux q (n`quot`(p^e)))
        else fAux ps n

primes :: [Int]
primes = f [2..] where f (p:ps) = p:(filter ((/=0).(`rem`p)) ps)

Measured memory_bytes: 4920
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using P = pair<int,int>;
ll MAX(ll a,ll b,ll c){return max(a,max(b,c));}
ll MIN(ll a,ll b,ll c){return min(a,min(b,c));}
const ll mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    int n;
    cin >> n;
    int num[n]={0};
    rep(i,n-1){
        int x;
        cin >> x;
        num[x-1]++;
    }
    rep(i,n){
        cout << num[i] << endl;
    }
}

Measured memory_bytes: 4336
n = int(input())
f = []
ans = -10**9

for i in range(n):
    a = "".join(input().split())
    a = int(a, 2)
    f.append(a)

p = [list(map(int, input().split())) for i in range(n)]

for i in range(1, 2**10):
    ref = 0
    for j in range(n):
        cnt = bin(i & f[j]).count("1")
        ref += p[j][cnt]
    else:
        ans = max(ans, ref)

print(ans)

Measured memory_bytes: 9220
N= int(input())
li = [list(map(int,input().split())) for _ in range(N-1)]

for i in range(N-1):
    ci,si,fi = li[i]
    time = si+ci
    for j in range(i+1,N-1):
        cj,sj,fj = li[j]
        if time%fj != 0:
            time = ((time//fj)+1)*fj
        #print(i,time)
        if time < sj:
            time = sj
        time += cj
    print(time)
print(0)

Measured memory_bytes: 9208
//                          VIVEK UPADHYAY
//                          MANIT, BHOPAL(M.P)
/**********************************************************************************************/
/**********************************************************************************************/
//                        $$ JAB-TAK TODEGA NHI,
//                           TAB -TAK CHODEGA NHI :D

// g++ -std=c++11 file_name.cpp
// ./file_name.out
#include<iostream>
#include<algorithm>
#include<vector>
#include<list>
#include<cstdlib>
#include<unistd.h>
#include<string>
#include<cstring>
#include<stack>
#include<queue>
#include<utility>
#include<cmath>
#include<set>
#include<unordered_map>
#include<cstdio>
#include<map>
#include<numeric>
using namespace std;
#define F first
#define S second
#define mk(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define LINE cout<<"\n" ;
#define ok cout<<"ok\n" ;
#define dbg(x) cout<<#x<<" = "<<(x)<<"\n";
#define fill(A, VAL) memset(A, VAL, sizeof(A))
#define sz(a) ((int) a.size())
typedef long long ll;
const int MAXN = 2010 ;
const int MAX = 1e7 + 1 ;
const ll inf = 1e18 ;
int main () {
    
    string s ;
    cin >> s ;
    stack<int> p ;
    for(int i =0 ; i < sz(s) ;i++) {
        if(sz(p)==0){
            p.push(s[i]) ;
            continue ;
        }
        if((p.top()=='0' && s[i]=='1') || (p.top()=='1' && s[i]=='0')) p.pop() ;
        else p.push(s[i]) ;
    }
    cout<<sz(s)-sz(p)<<endl;
    return 0 ;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
string s;
int xd;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> s;
    int maxi = 0;
    for(int i = 0; i <= s.size(); i++)
    {
        if(xd && (i == s.size() ||s[i] == 'S'))
            maxi = max(maxi, xd), xd = 0;
        if(s[i] == 'R')
            xd++;
        maxi = max(maxi, xd);
    }
    cout << maxi << "\n";
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << '\n';
typedef int64_t Int;
Int mod = 1e9+7;
Int INF = 1e9+18;

Int n, q;
string s;
char t[200001], l[200001];

bool f(Int cur, Int d) {
    for (Int i = 0; i < q; i++) {
        if (s[cur] == t[i]) {
            if (l[i] == 'L') {
                cur--;
            }
            else {
                cur++;
            }
        }
    }
    return cur == d;
}

int main() {
    ios::sync_with_stdio(false);   
    cin >> n >> q;
    cin >> s;
    s = '.' + s + '.';
    for (Int i = 0; i < q; i++) cin >> t[i] >> l[i];
    Int res = n;
    Int ok = 1;
    Int ng = n + 1;
    while (abs(ok - ng) > 1) {
        Int mid = (ok + ng) / 2;
        if (f(mid, 0)) {
            ok = mid;
        }
        else {
            ng = mid;
        }
    }
    res -= ok;
    if (ok == 1 && !f(1, 0)) res++;
    ok = n;
    ng = 0;
    while (abs(ok - ng) > 1) {
        Int mid = (ok + ng) / 2;
        if (f(mid, n + 1)) {
            ok = mid;
        }
        else {
            ng = mid;
        }
    }
    res -= n - ok + 1;
    if (ok == n && !f(n, n + 1)) res++;
    dump(res);
    return 0;
}

Measured memory_bytes: 976
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
const int INF = 1e9;  int f = 0;
vector<int> v;long long int dp[100011]; int a[100010];
long long int h[100010]; long long int n, m;
int main() {
	cin >> n;
	cout << n * n << endl;
}

Measured memory_bytes: 256
# C - Vacation

N = int(input()) # days
happy_list = [] # action cost list
for i in range(N):
    happy_action = list(map(int, input().split()))
    happy_list.append(happy_action)

happy_cost_max = 0 # result prepare
happy_cost_list = [ [0]*3 for i in range(N+1)] # DP list

# DP loop
for i in range(N):
    happy_action = happy_list[i]
    for j in range(3):
        pre_cost = happy_cost_list[i][j]
        for k in range(3):
            if not j==k:
                new_cost = max(happy_cost_list[i+1][k], pre_cost+happy_action[j])
                happy_cost_list[i+1][k] = new_cost

happy_cost_max = max(happy_cost_list[N])
print(happy_cost_max)


Measured memory_bytes: 74200
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T>
bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for(int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T>
vector<T> make_v(size_t a) {
    return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) {
    for(auto& e : t) {
        fill_v(e, v);
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans = 0;
    vector<int> v(n), c(n);
    for(int i = 0; i < n; i++) {
        cin >> v[i];
    }
    for(int i = 0; i < n; i++) {
        cin >> c[i];
        ans += max(0, v[i] - c[i]);
    }
    cout << ans << endl;
}


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

num = [0] * 4
for i in range(N):
    S = input()
    if S == "AC":
        num[0] += 1
    elif S == "WA":
        num[1] += 1
    elif S == "TLE":
        num[2] += 1
    else:
        num[3] += 1
for i, value in enumerate(["AC", "WA", "TLE", "RE"]):
    print(value, "x", num[i])

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef pair<int, int> ii;
typedef pair<ll, ll> pll;

bool isP(string a){
	for ( int i = 0 ; i < a.length() ; i++ ){
		if ( (i+1) % 2 == 1 && a[i] == 'L' )
			return false;
		else if ( (i+1) % 2 == 0 && a[i] == 'R' )
			return false;
	}
	return true;
}

int main( int argc, char *argv[] ) {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	string A;

	cin >> A;
	if (isP(A)){
		cout << "Yes" << "\n";
	}else{
		cout << "No" << "\n";
	}

	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
using namespace std;
 
int main(){
  int n;
  cin >> n;
   
  string u[257];
  for(int i=0;i<n;i++)cin >> u[i];
 
  int m;
  cin >> m;
   
  string t;
  int sta = 1;
  for(int i=0;i<m;i++){
    cin >> t;
     
    int flg = 0;
    for(int i=0;i<n;i++){
      if(t == u[i]) {
    flg = 1;
    sta++;
    break;
      }
    }
 
    if(flg == 1){
      if(sta%2 == 1) cout << "Closed by ";
      else cout << "Opened by ";
      cout << t << endl;
    }
    else cout << "Unknown "<<t<<endl;
     
  }
  return 0;
}

Measured memory_bytes: 3212
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
	long long n;
	while(~scanf("%lld",&n))
	{
		int sum=0;
		long long t=n;
		while(t)
		{
			sum+=t%10;
			t/=10;
		}
		if(n%sum==0)
		{
			printf("Yes\n");
		}
		else
		{
			printf("No\n");
		}
	}
}

Measured memory_bytes: 256
N = gets.to_i
As, Bs = readlines.map{_1.split.map(&:to_i)}

ta, tb = As.tally, Bs.tally
(puts 'No'; exit) if ta.merge(tb){_2 + _3}.values.max > N
puts 'Yes'
ta.default = 0; tb.default = 0
cs, ds = [ta[0]], [tb[0]]
(1 .. N).each do |i|
  cs[i] = cs[i - 1] + ta[i]
  ds[i] = ds[i - 1] + tb[i]
end
of = cs[1 ..].zip(ds[.. -2]).map{_1 - _2}.max % N
puts Bs.cycle(2).drop(N - of).take(N).join(' ')

Measured memory_bytes: 70440
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define MAX 100010
#define Mod 1000000007
typedef long long ll;

using namespace std;

ll ans, cnt;
ll n;

ll fac[MAX], finv[MAX], inv[MAX];

void comInit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < n; i++) {
    fac[i] = fac[i - 1] * i % Mod;
    inv[i] = Mod - inv[Mod % i] * (Mod / i) % Mod;
    finv[i] = finv[i - 1] * inv[i] % Mod;
  }
}

ll com(ll n, ll r) {
  if (n < r)
    return 0;
  if (n < 0 || r < 0)
    return 0;
  return fac[n] * (finv[r] * finv[n - r] % Mod) % Mod;
}

int main() {
  ll k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n)
  {
    cin >> a[i];
  }
  comInit();

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

  ll maxsum = 0;
  rep(i, n)
  {
    maxsum += (com(i, k - 1) * a[i]) % Mod;
    maxsum %= Mod;
  }

  reverse(a.begin(), a.end());
  ll minsum = 0;
  rep(i, n)
  {
    minsum += (com(i, k - 1) * a[i]) % Mod;
    minsum %= Mod;
  }

  cout << (maxsum - minsum) % Mod << endl;

  return 0;
}


Measured memory_bytes: 3328
// Marcin Knapik
#include<bits/stdc++.h>

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;

// #include <ext/pb_ds/assoc_container.hpp> // order_of_key
// #include <ext/pb_ds/tree_policy.hpp> // find by order
// using namespace __gnu_pbds; 
// #define ordered_set tree< pair<int, int> , null_type,less<pair<int, int>>, rb_tree_tag,tree_order_statistics_node_update>  

// const ll MAX_LL = 0xFFFFFFFFFFFFFFFF;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define losuj(a, b) uniform_int_distribution<ull>(a, b)(rng)
#define losuj_real(a, b) uniform_real_distribution<long double>(a, b)(rng)

typedef long double             ld;
typedef long long               ll;
typedef unsigned long long      ull;
typedef pair<ll, ll>            pll;
typedef pair<int, int>          ii;
typedef vector<int>             vi;
typedef vector<ii>              vii;
typedef vector<vi>              vvi;
typedef vector<vector<ii>>      vvii;
typedef vector< ll >            vll;
typedef vector< pll >           vpll;
 
#define sz(a)                   (int)(a).size()
#define pb                      push_back
#define all(c)                  (c).begin(), (c).end()
#define rall(c)                 (c).rbegin(), (c).rend()
#define FOR(i, a)               for (int i = 0; i < (a); i++)
#define f                       first
#define s                       second
 
template <class T> inline bool setmin(T &a, T b){if (a > b)return a = b, 1;return 0;}
template <class T> inline bool setmax(T &a, T b){if (a < b)return a = b, 1;return 0;}
 
template<class T> inline T fast(T a,T b,T mod) {ll res = 1; while(b){if(b&1) res = (res*a)%mod;a = (a*a)%mod;b >>= 1;}return res;}
template<class T> inline T russian(T a, T b, T mod) {ll res = 0; while(b){if(b&1) res = (res + a)%mod; a = (a+a)%mod; b>>=1;}return res;}
template <class T> istream &operator>>(istream &os, vector<T> &container){for (auto &u : container)os >> u;return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &container){for (auto &u : container)os << u << " ";return os;}
template<typename T> inline T gcd(T a, T b) { while (b)swap(a %= b, b); return a; }
  
const ll INF = 1e9 + 7;
const ll mod = 998244353;
const ll N = 1e5+7;
const ll T = 1<<20;
const ll BIG_INF = 1e18 + 7;

ll n, m, k, q;
	
vi tab;
pll dp[404][404];

pll policz(int a, int b){
	if(dp[a][b].f != BIG_INF)
		return dp[a][b];
	if(a == b)
		return dp[a][b] = {0, tab[a]};
	ll waga = policz(a, a).s + policz(a+1, b).s;
 	ll mini = BIG_INF;
 	for(int i = a; i < b; i++)
 		mini = min(mini, policz(a, i).f + policz(i+1, b).f);
 	return dp[a][b] = {mini + waga, waga};
}

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

    cin >> n;
    tab.resize(n);
    cin >> tab;

    FOR(i, 404)
    	FOR(j, 404)
    		dp[i][j] = {BIG_INF, 0};

    cout << policz(0, n-1).f << '\n';
}

Measured memory_bytes: 2816
import itertools

N = int(input())
XY = []
for _ in range(N):
  x, y = map(int, input().split())
  XY.append([x, y])

nums = [i for i in range(N)] 
numlist = list(itertools.permutations(nums))
L = []
for n in numlist:
  l = 0
  for i in range(N - 1):
    d = (XY[n[i]][0] - XY[n[i + 1]][0]) **2 + (XY[n[i]][1] - XY[n[i + 1]][1]) ** 2
    l += d ** (1/2)
  L.append(l)  
print(sum(L)/len(L))

Measured memory_bytes: 9460
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=205,INF=1<<30;
const double eps=1e-4;
typedef vector<double> vec;
typedef vector<vec> mat;

vec gauss_jordan(const mat& A,const vec &b){
    int n=A.size();
    mat B(n,vec(n+1));
    
    for(int i=0;i<n;i++) for(int j=0;j<n;j++) B[i][j]=A[i][j];
    
    for(int i=0;i<n;i++) B[i][n]=b[i];
    
    for(int i=0;i<n-1;i++){
        int pivot=i;
        for(int j=i;j<n;j++){
            if(abs(B[j][i])>abs(B[pivot][i])) pivot=j;
        }
        swap(B[i],B[pivot]);
        
        if(abs(B[i][i])<eps) return vec();
        
        for(int j=i+1;j<=n;j++) B[i][j]/=B[i][i];
        for(int j=0;j<n;j++){
            if(i!=j){
                for(int k=i+1;k<=n;k++) B[j][k]-=B[j][i]*B[i][k];
            }
        }
    }
    
    vec x(n);
    
    for(int i=0;i<n;i++) x[i]=B[i][n];
    return x;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int d;cin>>d;
        //cout<<d<<endl;
        if(d==0) break;
        vec X(d+3);
        for(int i=0;i<d+3;i++) cin>>X[i];
        
        for(int k=0;k<d+3;k++){
            mat A;
            vec B;
            for(int i=0;i<d+3;i++){
                if(i==k) continue;
                vec C(d+2);
                for(int j=0;j<=d;j++){
                    C[j]=1;
                    for(int t=0;t<d-j;t++) C[j]*=i;
                }
                A.push_back(C);
                B.push_back(X[i]);
            }
            
            vec C=gauss_jordan(A,B);
            
            if(si(C)==0) continue;
            
            bool ok=true;
            
            for(int i=0;i<d+3;i++){
                if(i==k) continue;
                double sum=0.0;
                for(int j=0;j<=d;j++){
                    double c=C[j];
                    for(int t=0;t<d-j;t++) c*=i;
                    sum+=c;
                }
                if(abs(sum-X[i])>eps) ok=false;
            }
            
            if(ok){
                cout<<k<<endl;
                break;
            }
        }
    }
}




Measured memory_bytes: 3112
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

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

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

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

int main(void) {
    int N;
    vector<int> a(100010);
    ll x = 0;
    cin >> N;
    for (int i=0;i<N;i++) cin >> a[i];
    for (int i=0;i<N;i++) x ^= a[i];
    if (x == 0) cout << "Yes" << endl;
    else cout << "No" << endl;


    return 0;
}


Measured memory_bytes: 640
H, W = gets.chop.split.map(&:to_i)

line_array = []
(0..W+1).to_a.each do |i|
  line_array << '#'
end

puts line_array.join('')
(1..H).to_a.each do
  puts "##{gets.chop}#"
end
puts line_array.join('')

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
  ll n;
  cin >> n;
  vector<ll> even(100010, 0), odd(100010, 0);
  bool flag = true;
  ll ev = 0, ov = 0;
  rep(i, 0, n){
    ll t; cin >> t;
    if(i%2 == 0){
      even[t]++;
      if(even[t] > even[ev]) ev = t;
    }else{
      odd[t]++;
      if(odd[t] > odd[ov]) ov = t;
    }
  }
  sort(even.begin(),even.end(),greater<ll>());
  sort(odd.begin(),odd.end(),greater<ll>());
  if(ev == ov){
    cout << n - max(even[0]+odd[1],even[1]+odd[0]) << endl;
  }else{
    cout << n - even[0] - odd[0] << endl;
  }
  return 0;
}

Measured memory_bytes: 4840
import java.io.FileInputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	static int x, y, s;
	
	private static int calc(int num, int percent)
	{
		double ret = num * (100 + percent) / 100;
		ret = Math.floor(ret);
		return (int)ret;
	}
	
	private static void start()
	{
		int ayen, byen;
		int max = 0;
		
		for(ayen = 1;ayen < s;ayen++)
			for(byen = 1;byen < s;byen++)
			{
				int aa = calc(ayen, x);
				int bb = calc(byen, x);
				
				if((aa + bb) == s)
				{
					int tmp = calc(ayen, y) + calc(byen, y);
					max = Math.max(max, tmp);
				}
			}
		
		System.out.println(max);
	}
	
	public static void main(String[] args)
	{
		
		Scanner sca = new Scanner(System.in);
		
		while(true)
		{
			x = sca.nextInt();
			y = sca.nextInt();
			s = sca.nextInt();
			if(x == 0) break;
			
			start();
		}
	}
}

Measured memory_bytes: 21020
import std.stdio, std.string, std.conv;
import std.array, std.algorithm, std.range;

void main()
{
    int[string] c;
    string mw; c[mw]=0;
    string ml;
    foreach(w;readln().split())
    {
        if(w in c){ if(++c[w]>c[mw]) mw=w; }
        else c[w]=1;
        if(ml.length < w.length) ml=w;
    }
    writeln(mw," ",ml);
}

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


#define fi first
#define se second
#define pb push_back
#define ll long long 
const int MAX = 3e5+5;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif




int main(){
	int n,maxx = 0,minn = MAX; cin >> n;
	vector<int > arr(n);
	for(int i = 0; i < n; i++){
		cin >> arr[i];
		maxx = max(maxx,arr[i]);
	}
	int countMaxx = 0;
	for(auto i : arr){
		if(i == maxx){
			countMaxx++;
		}
	}
	int diff = MAX;
	for(auto i : arr){
		if(i < maxx and abs(maxx - i) < diff){
			diff = abs(maxx - i);
			minn = i;
		}
	}
	// debug(minn,maxx,countMaxx);
	for(auto i : arr){
		if(i == maxx){
			if(countMaxx > 1){
				cout << maxx << "\n";
			}else{
				cout << minn << "\n";
			}
		}else if(i < maxx){
			cout << maxx << "\n";
		}
	}
}



















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

int main() {
  int a, b;
  string s, t, u;

  cin >> s >> t;
  cin >> a >> b;

  cin >> u;

  if (s == u) {
    a--;
  }
  else if (t == u) {
    b--;
  }

  cout << a << " " << b << endl;
  return 0;
}

Measured memory_bytes: 256
// https://beta.atcoder.jp/contests/abc061

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

ui64 N, K;
map<int, ui64> int_to_count;

int main() {
    cin >> N >> K;
    ui64 a, b;
    for (int i = 0; i < N; ++i) {
        cin >> a >> b;
        int_to_count[a] += b;
    }

    int ans = 0;
    ui64 sum = 0;
    for (auto p : int_to_count) {
        sum += p.second;
        if (K <= sum) {
            ans = p.first;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4224
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<utility>

using namespace std;

typedef long long ll;

#define F first
#define S second

const ll MAXN = 1e5 + 10;

ll n, m, pos[MAXN];
char dir[MAXN];
ll tm;
pair<ll, char>	sec[MAXN];
ll gec[MAXN];
map<ll, ll>	mp;

void solve(){
	ll cur = 0;
	ll tot = 2LL * tm;
	for (ll i = 1; i < n; i++)
		if (sec[0].S != sec[i].S){
			ll dis = (sec[0].S == 'R'?sec[i].F - sec[0].F:m - (sec[i].F - sec[0].F));
			ll temp = tot;
			temp -= dis;
			if (temp >= 0){
				if (sec[0].S == 'R'){
					cur = (cur + 1) % n;
					cur = (cur + temp/m) % n;
				}
				else{
					cur = (cur - 1 + n) % n;
					cur = ((cur - temp/m) % n + n) % n;
				}
			}
		}
	
	for (ll i = 0; i < n; i++)
		gec[i] = (sec[i].S == 'R'?(sec[i].F + tm) % m:((sec[i].F-tm) % m + m) % m);
	ll temp = gec[0];
	sort(gec, gec + n);
	int p = 0;
	while (gec[p] != temp)	p++;
	if (sec[0].S == 'R' && p + 1 < n && gec[p + 1] == gec[p])	p++;

	for (ll i = 0; i < n; i++, cur = (cur + 1) % n, p = (p + 1) % n)
		mp[sec[cur].F] = gec[p];
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m >> tm;
	for (ll i = 0; i < n; i++){
		int t;
		cin >> pos[i] >> t;
		if (t == 1)
			dir[i] = 'R';
		else
			dir[i] = 'L';
		sec[i] = {pos[i], dir[i]};
	}
	sort(sec, sec + n);
	solve();
	for (ll i = 0; i < n; i++)
		cout << mp[pos[i]] << "\n";
	return 0;
}


Measured memory_bytes: 10752
import java.util.Scanner;
class Main {
	int H = 0,W = 0,i,j,a,b;
	public void ch() {
		Scanner sc = new Scanner(System.in);
		H = sc.nextInt();
		W = sc.nextInt();
		while(H != 0 || W != 0) {
			for(i = 1; i <= H;i++) {
				for(j = 1; j <= W;j++) {
					a = i % 2;
					b = j % 2;
					if(b == 1) {
						if(a == 1) {
							System.out.print("#");
						} else {
							System.out.print(".");
						}
					} else if(a == 0) {
						System.out.print("#");
					} else {
						System.out.print(".");
					}
				}
			System.out.println();
			}
			System.out.println();
			H = sc.nextInt();
			W = sc.nextInt();
		}
	}
	public static void main(String[] args) {
		new Main().ch();
	}
}

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


int main()
{
    int n;
    std::cin >> n;
    std::vector<std::vector<std::pair<int,long long>>> hen(n);
    std::vector<long long> dist(n);
    for(int i = 0; i < n - 1; i++){
        int a,b,c;
        std::cin >> a >> b >> c;
        a--; b--;
        hen[a].push_back({b,c});
        hen[b].push_back({a,c});
    }
    int q,k; std::cin >> q >> k;
    k--;

    std::vector<bool> seen(n);
    std::queue<std::pair<int,long long>> que; // ver / cost
    que.push({k,0});
    seen[k] = 0;
    while(que.size()){
        auto cur = que.front();
        que.pop();
        for(auto i : hen[cur.first]){
            if(seen[i.first])continue;
            que.push({i.first,cur.second + i.second});
            seen[i.first] = true;
            dist[i.first] = cur.second + i.second;
        }
    }
    for(int i = 0; i < q; i++){
        int x,y;
        std::cin >> x >> y; x--; y--;
        std::cout << dist[x] + dist[y] << std::endl;
    }

}


Measured memory_bytes: 10736
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define PI (acos(-1))
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD = 1000000007;
// ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
ll powMod(ll x, ll k, ll m) {//x^k (mod n)
	if (k == 0)     return 1;
	if (k % 2 == 0) return powMod(x*x % m, k/2, m);
	else            return x*powMod(x, k-1, m) % m;
}
int N,K;
vi PP;

int invmap[114514];
map<int,int> mm;
vi datas;
int main(){
	string str;
	cin>>str;
	if(str=="Sunny")cout<<"Cloudy"<<endl;
	else if(str=="Cloudy")cout<<"Rainy"<<endl;
	else cout<<"Sunny"<<endl;
}




Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<algorithm>
#include<iomanip>
#include<bitset>
using namespace std;

int n, a[2][200];

int main() {
    //freopen("ttt", "r", stdin);

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

    int r = a[1][1] + a[2][n];
    for(i = 2; i <= n; ++i)
        a[1][i] += a[1][i - 1];
    for(i = n - 1; i; --i) {
        a[2][i] += a[2][i + 1];
        r = max(r, a[2][i] + a[1][i]);
    }

    cout << r;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int i = 0;i < n;i++)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()

template<class T> bool chmax(T& a,T b){ if(a < b){ a = b; return true; }else return false; }
template<class T> bool chmin(T& a,T b){ if(a > b){ a = b; return true; }else return false; }
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;
using vpi = vector<Pi>;
using vpl = vector<Pl>;
 
void lyn(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}
 
#define debug(arr) cout << #arr << " = " << arr << '\n'
#define debug2(a,b) cout << "[" << #a << "," << #b << "] = " << "[" << a << "," << b << "]" << '\n'
template<class T> ostream &operator << (ostream& out, const vector<T>& arr) {
	cout << "{"; for (int i = 0; i < arr.size(); i++)cout << (!i ? "" : ", ") << arr[i]; cout << "}";
	return out;
}
template<class T> ostream &operator << (ostream& out, const vector<vector<T> >& arr) {
	cout << "{\n"; for (auto& vec : arr)cout << "  " << vec << ",\n"; cout << "}";
	return out;
}
template<class S,class T> ostream &operator << (ostream& out, const pair<S,T>& p){
  cout << "{" << p.first << "," << p.second << "}" << '\n';
  return out;
}
template<class T> istream &operator >> (istream& in, vector<T>& arr) {
	for (auto& i : arr)cin >> i; return in;
}

int main(void){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //cout << fixed << setprecision(20);
  
  ll a,b,c,d;cin >> a >> b >> c >> d;
  //cout << max({a*c,a*d,b*c,b*d,0LL}) << '\n';
  ll ans = -LONG_MAX;
  chmax(ans,a*c);
  chmax(ans,a*d);
  chmax(ans,b*c);
  chmax(ans,b*d);
  if((a <= 0 && 0 <= b) || (c <= 0 && 0 <= d)) chmax(ans,0LL);
  cout << ans << '\n';
  return 0;
}


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

int main()
{
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  int all = 0;
  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
    all += A.at(i);
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  int cnt = 0;
  for (int i = 0; i < N; i++)
  {
    if (A.at(i) >= all*1.0/(4*M)) cnt++;
  }
  if (cnt >= M) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vll=vector<ll>;
int main(){
  ll x,y,a,b,c,ans=0;
  cin>>x>>y>>a>>b>>c;
  vll p,q,r,np,nq;
  for(ll i=0;i<a;i++){
    ll ai;
    cin>>ai;
    p.push_back(ai);
  }for(ll i=0;i<b;i++){
    ll bi;
    cin>>bi;
    q.push_back(bi);
  }for(ll i=0;i<c;i++){
    ll ci;
    cin>>ci;
    r.push_back(ci);
  }
  sort(p.begin(),p.end());
  reverse(p.begin(),p.end());
  sort(q.begin(),q.end());
  reverse(q.begin(),q.end());
  for(ll i=0;i<x;i++){
    np.push_back(p.at(i));
  }for(ll i=0;i<y;i++){
    nq.push_back(q.at(i));
  }
  np.insert(np.end(),nq.begin(),nq.end());
  np.insert(np.end(),r.begin(),r.end());
  sort(np.begin(),np.end());
  reverse(np.begin(),np.end());
  for(ll i=0;i<x+y;i++){
    ans+=np.at(i);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 6964