akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
#include<vector>
#include<map>
#include<algorithm>
#define int long long int
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	  int h,w;
	  cin>>h>>w;
      vector<int> row[h+1];
      int i,j;
      for(i=1;i<=h;i++)
      {
		  row[i].push_back(0);
	  }
	  vector<int> col[w+1];
	  for(j=1;j<=w;j++)
	  {
		  col[j].push_back(0);
	  }
	  char mat[h+1][w+1];
	  for(i=1;i<=h;i++)
	  {
		  for(j=1;j<=w;j++)
		  {
			  cin>>mat[i][j];
			  if(mat[i][j]=='#')
			  {
				  row[i].push_back(j);
				  col[j].push_back(i);
			  }
		  }
	  }
      for(i=1;i<=h;i++)
          row[i].push_back(w+1);
       for(j=1;j<=w;j++)
          col[j].push_back(h+1);
	  int answer=0;
	  for(i=1;i<=h;i++)
	  {
		  for(j=1;j<=w;j++)
		  {
			   if(mat[i][j]=='.')
			   {
				   auto it=lower_bound(row[i].begin(),row[i].end(),j);
				   int x=*it;
				   it--;
				   int y=*it;
				   auto it2=lower_bound(col[j].begin(),col[j].end(),i);
				   int p=*it2;
				   it2--;
				   int q=*it2;
				   int val=(x-y-1+p-q-1-1);
				   answer=max(answer,val);
			   }
		  }
	  }
	  cout<<answer<<endl;
}


Measured memory_bytes: 70912
def main():
  n, m = input_list()
  if n < 2:
    nk = 0
  else:
    nk = combinations_count(n, 2)
  if m < 2:
    mk = 0
  else:
    mk = combinations_count(m, 2)
  print(nk+mk)
  
def count_section_by_zero(data):
  count = 0
  flg = False
  start = 0
  for i, d in enumerate(data):
    if flg is False and d != 0:
      count += 1
      flg = True
      
    if d == 0:
      flg = False
  return count

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def input_list():
  return list(map(int, input().split()))

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

# 2で割り切れる回数
def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c

# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

import math
import fractions
import collections
from functools import reduce
main()

Measured memory_bytes: 5688
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>

using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, x) for(int i=1;i<=(int)(x);i++)
#define rrep(i, x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i, x) for(int i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007
#define put2darr(arr, row, col) rep(i, row) { rep(j, col) { printf("%18d", arr[i][j]); } cout << endl; }

using namespace std;

template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

/* 1..10
 * rep:   0 1 2 3 4 5 6 7 8 9
 * reps:  1 2 3 4 5 6 7 8 9 10
 * rrep:  9 8 7 6 5 4 3 2 1 0
 * rreps: 10 9 8 7 6 5 4 3 2 1
 */


int a, b, q;
ll x[100000];
vector<ll> s;
vector<ll> t;

ll binaryA(ll pos, ll l, ll r, vector<ll> &dist) {
    if (l >= r) {
        if (dist[l] <= pos) return l;
        else if (l > 0 && dist[l - 1] <= pos) return l - 1;
        else return -1;
    }
    ll m = (l + r) / 2;
    if (dist[m] < pos)return binaryA(pos, m + 1, r, dist);
    else return binaryA(pos, l, m, dist);
}

ll binaryD(ll pos, ll l, ll r, vector<ll> &dist) {
    if (l >= r) {
        if (dist[l] >= pos) return l;
        else if (l < dist.size() - 2 && dist[l + 1] >= pos) return l + 1;
        else return -1;
    }
    ll m = (l + r) / 2;
    if (dist[m] < pos) return binaryD(pos, m + 1, r, dist);
    else return binaryD(pos, l, m, dist);
}

int main() {
    cin >> a >> b >> q;
    ll tmp;
    rep(i, a) {
        scanf("%lld", &tmp);
        s.push_back(tmp);
    }
    rep(i, b) {
        scanf("%lld", &tmp);
        t.push_back(tmp);
    }
    rep(i, q) {
        scanf("%lld", &x[i]);
    }
    rep(i, q) {
        ll tx = x[i];
        ll as = binaryA(tx, 0, a - 1, s);
        ll ds = binaryD(tx, 0, a - 1, s);
        ll at = binaryA(tx, 0, b - 1, t);
        ll dt = binaryD(tx, 0, b - 1, t);
        ll ans = 1LL << 60;
        if (as >= 0 && at >= 0) {
            chmin(ans, tx - min(s[as], t[at]));
        }
        if (ds >= 0 && dt >= 0) {
            chmin(ans, max(s[ds], t[dt]) - tx);
        }
        if (as >= 0 && dt >= 0) {
            chmin(ans, min(t[dt] - tx, tx - s[as]) + (t[dt] - s[as]));
        }
        if (at >= 0 && ds >= 0) {
            chmin(ans, min(s[ds] - tx, tx - t[at]) + (s[ds] - t[at]));
        }
        printf("%lld\n",ans);
    }
}


Measured memory_bytes: 3828
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

#define PP pair<ll, P>
ll h, w, v[1100][1100];

ll v1[4] = { 0,0,1,-1 }, v2[4] = { 1,-1,0,0 };
string s[1100];
int main() {
	cin >> h >> w;
	REP(i, h) {
		cin >> s[i];
	}
	queue<PP> q;
	REP(i, h) {
		REP(j, w) {
			v[i][j] = INF;
		}
	}
	REP(i, h) {
		REP(j, w) {
			if (s[i][j] == '#') {
				REP(k, 4) {
					ll x = i + v1[k], y = j + v2[k];
					if (x >= 0 and x < h and y >= 0 and y < w) {
						if(s[x][y] == '.' and v[x][y] == INF){
							q.push(PP(1, P(x, y)));
							v[x][y] = 1;
						}
					}
				}
			}
		}
	}
	while (!q.empty()) {
		PP now = q.front();
		q.pop();
		ll i = now.second.first, j = now.second.second;
		REP(k, 4) {
			ll x = i + v1[k], y = j + v2[k];
			if (x >= 0 and x < h and y >= 0 and y < w) {
				if (s[x][y] == '.') {
					if (v[x][y] > now.first + 1) {
						q.push(PP(now.first + 1, P(x, y)));
						v[x][y] = now.first + 1;
					}
				}
			}
		}
	}

	ll ans = 0;
	REP(i, h) {
		REP(j, w) {
			if(v[i][j] != INF) ans = max(ans, v[i][j]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 21904
#include <stdio.h>

int main()
{
	long long int i,n,count = 0;
	
	scanf("%lld",&n);
	
	for(i = 100;i < n;count++)
	{
		i += (i * 0.01);
	}
	
	printf("%lld\n",count);
	
	return 0;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
#define LL long long
using namespace std;
LL mpo(LL a, LL n, LL m) {
  LL ret = 1;
  LL kj = 2ll;
  while (n) {
    if (n % kj) ret *= a;
    a = a * a;
    a %= m;
    ret %= m;
    n /= kj;
  }
  return ret;
}
int main () {
  LL n, a, b;
  cin >> n >> a >> b;
  LL m = 1e9 + 7;
  LL ans = mpo(2, n, m);
  LL kj = 1;
  for (LL i = 1; i <= b; i ++) {
    kj *= i;
    kj %= m;
  }
  kj = mpo(kj, m - 2, m);
  LL kja = kj;
  for (LL i = a + 1; i <= b; i ++) {
    kja *= i;
    kja %= m;
  }
  for (LL i = 0ll; i < a; i ++) {
    kja *= (n - i);
    kja %= m;
  }
  for (LL i = 0ll; i < b; i ++) {
    kj *= (n - i);
    kj %= m;
  }
  ans = ans - kj - kja - 1;
  while (ans < 0) ans += m;
  cout << ans << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <stdio.h>
using namespace std;
#define M1 (ll)1000000007
#define M2 (ll)998244353
#define Pi 3.141592653
#define exp 2.71828
#define ll long long
#define ull unsigned long long
#define pi pair<int,int>
#define pl pair<ll,ll> 
#define vi vector<int>
#define vl vector<ll>
#define di deque<int>
#define dl deque<ll>
#define dii deque<pi>
#define dll deque<pl>
#define vvi vector<vi>
#define vvl vector<vl>
#define vii vector<pi>
#define vll vector<pl>
#define pb push_back
#define pp pop_back
#define pf push_front
#define pt pop_front
#define mp make_pair
#define in insert
#define er erase
#define ff first
#define ss second
#define ub upper_bound
#define lb lower_bound
#define rp(i,a,b) for(int i=a;i<b;i++)
#define rpt(i,a,b,t) for(int i=a;i<b&&t<1;i++)
#define rep(i,n) for(int i = 0 ; i<n ; i++)
#define rept(i,n,t) for(int i = 0 ; i<n&&t<1 ; i++)
#define repr(i,n) for(int i = n-1 ; i>=0 ; i--)
#define reprt(i,n,t) for(int i=n-1;i>=0&&t<1;i--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define SORT(v) sort(v.begin(),v.end())
int main() {
    int n;
    cin>>n;
    int x;
    int c[4]={0};
    for(int i=0;i<n;++i) cin>>x,++c[x];
    double t1,t2;
    double dp[n+1][n+1][n+1];
    dp[0][0][0]=0;
    n = (double)n;
    for(int i=0;i<c[3]+1;++i){
        for(int j=0;j<c[2]+c[3]+1;++j){
            for(int k=0;k<(int)n+1 && i+j+k<=(int)n;++k){
                if(i+j+k == 0 || i+j+k>(int)n) continue;
                t1 = i+j+k;
                t2 = 0;
                dp[i][j][k] = n/t1;
                t2 += (i!=0)?(((double)i/n)*dp[i-1][j+1][k]):0;
                t2 += (j!=0)?(((double)j/n)*dp[i][j-1][k+1]):0;
                t2 += (k!=0)?(((double)k/n)*dp[i][j][k-1]):0;
                t2 += 1;
                dp[i][j][k] *= t2;
            }
        }
    }
    cout<<setprecision(10)<<dp[c[3]][c[2]][c[1]];
}


Measured memory_bytes: 110916
n, m = list(map(int, input().split()))
x = list(map(int, input().split()))

if n >= m:
  print(0)
  exit(0)

x.sort()

if n == 1:
  print(x[-1]-x[0])
  exit(0)

d = [0] * (m - 1)
for i in range(m - 1):
  d[i] = x[i + 1] - x[i]

d.sort()

print(sum(d[:-n + 1]))


Measured memory_bytes: 13960
#include <iostream>
#include <math.h>
using namespace std;

int main(void){
  long N;
  cin>>N;
  long retval=N+1;
  for(int i=1;i<sqrt(N)+1;i++){
    if(N%i==0){
      retval=min(retval,i-2+N/i);
    }
  }
  cout<<retval<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

// 線分ab の偏角 [-π, π] を返す
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax = a.first, ay = a.second, bx = b.first, by = b.second;
    return atan2(by - ay, bx - ax);
}

void solve(){
    int n;
    cin >> n;
    vector<pair<long double, long double>> xy;
    REP(i,n){
        long double a, b;
        cin >> a >> b;
        if(a == 0 && b == 0) continue;
        xy.emplace_back(a, b);
    }
    pair<long double, long double> o(0, 0);
    sort(xy.begin(), xy.end(), [&](auto a, auto b){return argument(o, a) < argument(o, b);});
    long double ans = 0;
    int m = xy.size();
    REP(i,m){
        long double x = 0, y = 0;
        REP(j,m){
            x += xy[(i+j)%m].first;
            y += xy[(i+j)%m].second;
            chmax(ans, hypot(x, y));
        }
    }
    printf("%.12Lf\n", ans);
}

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

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

*H, = map(int, input().split())

max = 0
count = 0
node = 0
while node<N-1:

    if H[node]<H[node+1]:
        if max < count:
            max = count
        count = 0
        node = node + 1
        continue
    count = count + 1
    node = node + 1
if max < count:
    max = count
print(max)

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

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	int n, a;
	cin >> n;
	string s;
	cin >> s;
	int cnt = 0;
	for(int i = 0; i < n; i++) {
		if(s[i] == 'R') cnt += 1;
	}
	int k = cnt;
	for(int i = 0; i < k; i++) {
		if(s[i] == 'R') cnt -= 1;
	}
	cout << cnt;
	return 0;
}

Measured memory_bytes: 3736
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

ll gcd(ll a, ll b) {		// ユークリッドの互除法
	if (b == 0) return a;
	return gcd(b, a % b);
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll t;
	cin>>t;
	REP(testcase,t) {
		ll a,b,c,d;
		cin>>a>>b>>c>>d;
		if(a<b) {
			cout<<"No"<<endl;
			continue;
		}
		if(d<b) {
			cout<<"No"<<endl;
		} else if(d==b) {
			if(a<=c) {
				cout<<"Yes"<<endl;
			} else {
				if((a-c)%b==0) {
					cout<<"Yes"<<endl;
				} else {
					ll tmp=(a-c)/b;
					if(a-(tmp+1)*b>=0) cout<<"Yes"<<endl;
					else cout<<"No"<<endl;
				}
			}
		} else {
			if(c<b) {
				if(d%b==0) {
					if((a-c)%b==0) {
						cout<<"Yes"<<endl;
					} else {
						ll tmp=(a-c)/b;
						if(a-(tmp+1)*b>=0) cout<<"Yes"<<endl;
						else cout<<"No"<<endl;
					}
				}
				else {
					ll tmp=(a-c)/b;
					ll pivo=0;
					if(a<c) pivo=a-b;
					else {
						if((a-c)%b==0) pivo=c;
						else pivo=(a-(tmp+1)*b);
					}
					ll g=gcd(d%b,b);
					ll k=(c-pivo)/g+1;
					if(pivo+k*g<b) cout<<"No"<<endl;
					else cout<<"Yes"<<endl;
				}
			} else  {
				cout<<"Yes"<<endl;
			}
		}

	}
	return 0;
}


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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_back
#define fast                     \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(NULL);
#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...)       \
	F_ORC(__VA_ARGS__) \
	(__VA_ARGS__)

#define E_ACH2(x, a) for (auto &x : a)
#define E_ACH3(x, y, a) for (auto &[x, y] : a)
#define E_ACH4(x, y, z, a) for (auto &[x, y, z] : a)
#define E_ACHC(...) GET5(__VA_ARGS__, E_ACH4, E_ACH3, E_ACH2)
#define EACH(...)       \
	E_ACHC(__VA_ARGS__) \
	(__VA_ARGS__)

template <typename A, typename B>
inline void chmin(A &a, B b)
{
	if (a > b)
		a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b)
{
	if (a < b)
		a = b;
}

const int mxn = 5e5;
const int M = 1e9 + 7;

ll pw(ll b, ll e)
{
	ll res = 1;
	while (e)
	{
		if (e % 2)
			res = (res * b) % M;
		b = (b * b) % M;
		e >>= 1; // e/=2;
	}
	return res;
}

ll iv[mxn + 1], f1[mxn + 1], f2[mxn + 1];
ll nck(int n, int k)
{
	return f1[n] * f2[k] % M * f2[n - k] % M;
}

int main()
{
	fast;
	string s;
	cin >> s;
	int i = 0, ans = 0;
	while (i < 3)
	{
		int cur = 0;
		while (i < 3 && s[i] == 'R')
		{
			cur++;
			i++;
		}
		ans = max(ans, cur);
		i++;
	}
	cout << ans << en;
}

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

using namespace std;

#define pii pair<int,int>
#define ll long long
#define s second
#define f first

ll a[100005];
int n;

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


Measured memory_bytes: 1024
n,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
ans,cnt=[0,0]
for i in range(n):
    cnt+=a[i]
    if cnt>x: break
    ans+=1
    if i==n-1 and cnt!=x: ans-=1
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

#define MOD 1000000007

class BIT{
  static const int MAX_N = 1 << 17;
  int n, bit[MAX_N+1];
public:
  BIT(int n_){
    n = n_;
    for(int i=0; i<n+1; i++) bit[i] = 0;
  }
  int sum(int i){
    int s = 0;
    while(i>0){
      s+=bit[i];
      i-=i&(-i);
    }
    return s;
  }
  void add(int i, int x){
    while(i<=n){
      bit[i]+=x;
      i+=i&(-i);
    }
  }
};

int main(){
  ll N, K;
  cin >> N >> K;
  vector<ll> v;
  rep(i,N){
    ll a;
    cin >> a;
    v.push_back(a);
  }

  BIT bit1(1<<17), bit2(1<<17);

  rep(i,N){
    bit1.add(v[i],1);
  }

  ll ret = 0;

  rep(i,N){
    ll a = N - bit1.sum(v[i]);
    ll b = i - bit2.sum(v[i]);

    //cerr << i << " " << a << " " << b << endl;
    
    ret += (b * K) % MOD;
    ret %= MOD;
    ret += (a * ((K * (K-1) / 2) % MOD)) % MOD;
    ret %= MOD;
   
    bit2.add(v[i],1);
  }
  
  cout << ret << endl;
  
  
  return 0;
}



Measured memory_bytes: 1280
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner scan = new java.util.Scanner(System.in);
        for(;;){
            int H = scan.nextInt();
            int W = scan.nextInt();
            if(H != 0 && W != 0){
                for(int i = 1; i <= H; i++){
                    System.out.print("#");
                    if(i != 1 && i != H){
                        for(int j = 1; j < W; j++){
                            if(j != W - 1){
                                System.out.print(".");
                            }else{
                                System.out.print("#");
                            } 
                        }
                    }else{
                        for(int j = 1; j < W; j++){
                            System.out.print("#");
                        }
                    }
                    System.out.println();
                }
                System.out.println();
            }else{
                break;
            }
        }    
    }
}

Measured memory_bytes: 34948
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n; i++)
#define all(v) (v).begin(), (v).end()
#define decimal fixed << setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
int a,b;
cin>>a>>b;
cout << (b%a==0 ? a+b:b-a) <<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    long long int a,b,k;
    cin>>a>>b>>k;
    if(k>=a)
    {
        cout<<"0"<<" ";
        if(k-a<b)
        {
            cout<<b-(k-a)<<" ";
        }
        else
        {
            cout<<"0"<<" ";
        }
    }
    else
    {
        cout<<a-k<<" ";
        cout<<b<<" ";
    }

          return 0;
}


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

int main() {
  int A,B,C,X,Y;
  cin >> A >> B >> C >> X >> Y;

  
  int p = (X > Y)? A:B;
  int ans1 = C*2 * min(X,Y) + p * abs(X-Y); // 残り
  
  int ans2 = (A*X) + (B*Y);
  
  int ans3 = C*2 * max(X,Y);
  
  cout << min(min(ans1, ans2), ans3) << endl;
}

Measured memory_bytes: 256
n, a, b, c, d = [int(item) for item in input().split()]
s = "#" + input().rstrip() + "#"

front = min(a, b, c, d)
back = max(a, b, c, d)
for i in range(front, back):
    if s[i] == "#" and s[i+1] == "#":
        print("No")
        exit()
if d > c:
    print("Yes")
    exit()
state = "No"
if d < c:
    for i in range(b, d+1):
        if s[i-1] == "." and s[i] == "." and s[i+1] == ".":
            state = "Yes"
            break
print(state)

Measured memory_bytes: 3636
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define pb          push_back
#define mp          make_pair
#define mt          make_tuple
#define get0(x)     (get<0>(x))
#define get1(x)     (get<1>(x))
#define get2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       9223372036854775807LL
#define LLMIN       -9223372036854775808LL
#define IMAX        2147483647
#define IMIN        -2147483648
typedef long long LL;
using namespace std;

int main(void){
    int H,W;
    vector<string> vs;
    cin>>H>>W;
    REP(i,H){string s;cin>>s;vs.pb(s);}
    int y=0,x=0;
    while(1){
        vs[y][x]='.';
        if(y+1<H&&vs[y+1][x]=='#')
            y++;
        else if(x+1<W&&vs[y][x+1]=='#')
            x++;
        else
            break;
    }
    // REP(i,H)
        // cout<<vs[i]<<endl;
    int c=0;
    REP(i,H)REP(j,W)c+=(vs[i][j]=='#');
    if(c==0&&y==H-1&&x==W-1)
        cout<<"Possible"<<endl;
    else
        cout<<"Impossible"<<endl;
     return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.regex.Pattern;

public class Main {
    public void solve(BufferedReader stdin, PrintWriter stdout) throws NumberFormatException, IOException {
        int[] line1 = Pattern.compile(" ").splitAsStream(stdin.readLine()).mapToInt(Integer::parseInt).toArray();
        int[] line2 = Pattern.compile(" ").splitAsStream(stdin.readLine()).mapToInt(Integer::parseInt).toArray();

        int m1 = line1[0];
        int d1 = line1[0];
        int m2 = line2[0];
        int d2 = line2[0];

        if (m1 == m2) {
            stdout.println(0);
        } else {
            stdout.println(1);
        }

    }


    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter stdout = new PrintWriter(System.out, false);
        new Main().solve(stdin, stdout);
        stdout.flush();
    }
}


Measured memory_bytes: 27092
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <stack>

using std::vector;
using std::printf;
using std::cout;
using std::endl;
using std::string;
using std::cin;
using std::pair;
using std::sort;

#define i64t long long int
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))

template<typename T>
void dump(vector<T> vec) {
    for (auto x : vec) {
        std::cout << x << " ";
    }
    std::cout << std::endl;
}

// ---------------------------

const i64t MOD = 1000000007;

int main() {
    int N;
    cin >> N;

    vector<int> A(N+1, 0);
    vector<int> B(N+1, 0);
    vector<int> C(N, 0);

    int tmp;
    for (int i = 1; i <= N; ++i) {
        cin >> tmp; A[i] = tmp;
    }
    for (int i = 1; i <= N; ++i) {
        cin >> tmp; B[i] = tmp;
    }
    for (int i = 1; i <= N-1; ++i) {
        cin >> tmp; C[i] = tmp;
    }

    // dump<int>(A);
    // dump<int>(B);

    int ret = 0;
    int prev = 0;
    for (int i = 1; i <= N; ++i) {
        ret += B[A[i]];
        if (A[i] == prev + 1) {
            ret += C[prev];
        }
        prev = A[i];
        // printf("%d\n", ret);
    }
 
    printf("%d\n", ret);
    
}

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

int main() {
  int w, h, n;
  cin >> w >> h >> n;
  vector<int> x(n), y(n), a(n);
  rep(i,n) cin >> x[i] >> y[i] >> a[i];
  vector<vector<bool>> map(h, vector<bool>(w, true));
  rep(i, n) {
    if(a[i] == 1) {
      rep(j,h) {
        rep(k,x[i]) map[j][k] = false;
      }
    }
    else if(a[i] == 2) {
      rep(j,h) {
        rep(k,w - x[i]) map[j][k + x[i]] = false;
      }
    }
    else if(a[i] == 3) {
      rep(j,y[i]) {
        rep(k,w) map[j][k] = false;
      }
    }
    else if(a[i] == 4) {
      rep(j,h - y[i]) {
        rep(k,w) map[j + y[i]][k] = false;
      }
    }
  }
  int ans = 0;
  rep(i,h) {
    rep(j,w) {
      if(map[i][j]) ans++;
    }
  }
    
  cout << ans << endl;
}

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

int main()
{
    int n;
    cin >> n ;
    vector<int> a(n);
    for (int i = 0; i < n; i++){
        cin >>  a[i];
    }
    long long int sum=0;
    for (int i = 0; i < n; i++){
        sum += a[i];
    }
    long long int min = *min_element(a.begin(), a.end());
    long long int max = *max_element(a.begin(), a.end());

    printf("%ld %ld %lld\n", min, max, sum);
}


Measured memory_bytes: 3248
#include <stdio.h>

int main(void) {
	int N, M;
	int s[16], c[16];
	int i;

	int seiyaku[16];

	if (scanf("%d%d", &N, &M) != 2) return 1;
	for (i = 0; i < M; i++) {
		if (scanf("%d%d", &s[i], &c[i]) != 2) return 1;
	}

	for (i = 0; i < N; i++) seiyaku[i] = -1;
	for (i = 0; i < M; i++) {
		if (seiyaku[s[i] - 1] < 0) {
			seiyaku[s[i] - 1] = c[i];
		} else {
			if (seiyaku[s[i] - 1] != c[i]) {
				puts("-1");
				return 0;
			}
		}
	}
	if (N > 1 && seiyaku[0] == 0) {
		puts("-1");
		return 0;
	}
	if (N == 1 && seiyaku[0] < 0) seiyaku[0] = 0;
	for (i = 0; i < N; i++) {
		putchar('0' + (seiyaku[i] < 0 ? (i == 0 ? 1 : 0) : seiyaku[i]));
	}
	putchar('\n');

	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void) {
	int N, C;
	int i;
	int sumipe = 0;
	if (scanf("%d%d", &N, &C) != 2) return 1;
	for (i = 0; i < C; i++) {
		int p;
		if (scanf("%d", &p) != 1) return 1;
		sumipe += p;
	}
	printf("%d\n", (sumipe + N) / (N + 1));
	return 0;
}



Measured memory_bytes: 2144
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
using namespace std;

int main()
{
	double a, b;
	cin >> a >> b;
	if (ceil((a + b) / 2) == floor((a + b) / 2))cout <<  setprecision(15) << (a + b) / 2 << endl;
	else cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

int main(){
    int N; std::cin >> N;
    std::vector<int> a;
    for(int i=0; i<N; i++){
        int b; std::cin>>b; a.push_back(b);
    }

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

    std::vector<int> v(a.back()+1,0);
    for(auto ai : a){
        if(v[ai]){
            v[ai] = 2;
            continue;
        }
        for(int i=ai; i<a.back()+1; i+=ai) v[i]++;
    }

    int ans=0;
    for(auto ai : a){
        if(v[ai]==1) ans++;
    }

    std::cout << ans;
    return 0;
}


Measured memory_bytes: 7884
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int num[3];
  	int cnt = 0;
  
    cin >> num[0] >> num[1] >> num[2];
  
  	sort(num, num + 3);
  
  	if (num[0] == 5) {
      cnt++;
    }
  	if (num[1] == 5) {
      cnt++;
    }
  	if (num[2] == 7) {
      cnt++;
    }
  	
  	if (cnt == 3) {
      cout << "YES" << endl;
    }
  	else {
      cout << "NO" << endl;
    }
  	return (0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define endl '\n'
#define pb push_back
#define mod 1000000007
#define mp make_pair
#define pi acos(-1)
#define line cout<<"----------------------------"<<endl
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
#define bug(x) cerr << "[" << #x << "] = ["<<x<<"]"<<'\n'
using namespace std;
ll  n;
ll  ara[10009];
ll bigmod(ll a, ll b,ll m)
{
    ll ans=1; a%=m;
    while(b)
    {
        if(b&1) ans=(ans*a)%m;
        b>>=1;
        a=(a*a)%m;
    }
    return ans;
}
ll facto[1000009];
bitset<10000009>prime;
vector<int> v;
void sieve()
{
    for(int i=3;i*i<=1000000;i+=2)
    {
        if(prime[i]==false)
        {
            for(int j=i*i;j<=1000000;j+=2*i)
            {

                prime[j]=true;
            }
        }
    }
    v.pb(2);
    for(int i=3;i<=1000000;i+=2) if(prime[i]==false ) v.pb(i);
}
int main()
{
    sieve();
    cin>>n;
    for(ll  i=0;i<n;i++) cin>>ara[i];
    ll lc=1;
    ll lc1=1;
    for(ll  i=0;i<n;i++)
    {
        ll x=ara[i];
        for(ll  j=0; j<v.size() and v[j]*v[j]<=x;j++)
        {
            if(x%v[j]==0)
            {
                ll cnt=0;
                while(x%v[j]==0) cnt++,x/=v[j];
                facto[v[j]]=max(facto[v[j]],cnt);
            }

        }
        if(x>1) facto[x]=max(facto[x],1LL);
    }
    for(ll  i=1;i<=1000000;i++)
    {
        if(facto[i])
        {
            lc*=bigmod(i,facto[i],mod);
            lc%=mod;
        }
    }
    ll ans=0;
    for(ll  i=0;i<n;i++)
    {
        ll ans2=lc*bigmod(ara[i],mod-2,mod);
        ans2%=mod;
        ans+=ans2; ans%=mod;
    }
    cout<<ans<<endl;
}


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

typedef long long ll;

#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0)
#define endl '\n'
#define DB(x) cout<<#x<<" : "<<x<<'\n'
#define PB push_back

const int INF = 1e9 + 5;

vector<int> depth(1e5+1,-INF);
bitset<(int)1e5+1> visited(0);
    
void max_self(int &a, int b){
    a = max(a,b);
}

int dfs(int index, vector<int> graph[]){
    visited[index] = 1;
    int _depth = 0;
    for(int node: graph[index]){
        if(visited[node]){
            max_self(_depth , 1 + depth[node]);
        }
        else{
            max_self(_depth, 1 + dfs(node,graph));
        }
    }
    depth[index] = _depth; // memoization
    return _depth;
}

int main(){
    // FASTIO;
    int N,M;
    cin>>N>>M;
    vector<int> graph[N+1];
    int temp1,temp2;
    //constructing a graph
    for(int i= 0; i<M; ++i){
        cin>>temp1>>temp2;
        graph[temp1].PB(temp2);
    }

    int ans = -INF;
    for(int node = 1; node< N+1; ++node){ //unconnected graphs will be taken care
        if(!visited[node]){
            max_self(ans , dfs(node,graph));
        }
    }
    cout<<ans;
  return 0;
}


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

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

int main() {
    int a, b, ans;
    cin >> a >> b;
    if (a > b) {
        ans = a + (a - 1);
    } else if (a == b) {
        ans = a + b;
    } else if (a < b) {
        ans = b + (b - 1);
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	long long n;
	cin>>n;
	
	cout<<(n/500*1000)+(n%500/5*5)<< endl;
	return 0;
}


Measured memory_bytes: 256
import sys
import numpy as np

n = int(input())
tasks = np.fromstring(sys.stdin.read(), sep=' ').reshape((n, 2))
a = tasks[:, 0]
b = tasks[:, 1]
i = b.argsort()
print('Yes' if (np.add.accumulate(a[i]) <= b[i]).all() else 'No')


Measured memory_bytes: 22768
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,-1,0,1,-1,-1,1};
const int dy[]={0,1,0,-1,1,1,-1,-1};
const int INF = 1e9;
const long long LINF = 1e18;
const double EPS = 1e-8;
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
typedef pair<int,int> Pii;
typedef vector<int> vi;
typedef pair<string, int> Psi;
typedef pair<ll, ll> Pll;
int main(){

	int N;
	cin >> N;
	int id[100010]={};
	map<Pii,int> memo;
	rep(i,N){
		int tmp;
		cin >> tmp;
		--tmp;
		id[i] = tmp;
	}
	int cnt = 0;
	rep(i,N){
		if(i == id[id[i]]){
			if(memo[Pii(i,id[i])] != 1 && memo[Pii(id[i],i)] != 1){
				++cnt;
			}
			memo[Pii(i,id[i])] = memo[Pii(id[i],i)] = 1;
		}

	}
	cout << cnt << endl;

	return 0;
}

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

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

  int m = S.size();
  
  string s_tmp;
  for(int i = 0; i <= m; ++i){
    for(int j = i; j <= m; ++j){
      s_tmp = S.substr(0, i) + S.substr(j);
      if(s_tmp == "keyence"){
        cout << "YES" << endl;
        return 0;
      }
    }
  }

  cout << "NO" << endl;
}

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

int main(){
  int N, count; cin >> N;
  count = 0;
  vector<int> a(N);
  for(int i = 0; i < N; i++){
    cin >> a.at(i);
    if(a.at(i) != i + 1)
      count++;
  }
  
  if(count == 0 )
    cout << "YES" << endl;
  else if(count == 2 )
    cout << "YES" << endl;
    else
    cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> llll;
typedef vector<llll> vllll;

int main(){
  int N;cin>>N;
  vll a;
  int m=0;
  vllll ans;
  for (int i=0;i<N;++i){ll a_;cin>>a_;a.push_back(a_);}
  int top=N;
  ll smallest=0;
  int smallest_pos=N-1;
  for (int i=N-1;i>=0;--i){
    if(smallest>a[i]){smallest_pos=i;smallest=a[i];}
    if (a[i]>=abs(smallest)){top=i;}
  }

  llll p;
  int i;


  if(top!=0&&top!=1){
    a[top-1]+=2*a[smallest_pos];
    p=make_pair(smallest_pos, top-1);
    ans.push_back(p);
    ans.push_back(p);
    m+=2;
  }

  if(top!=N-1){
    i=top;
    while(i<N-1){
      a[i+1]+=a[i];
      p=make_pair(i,i+1);
      ans.push_back(p);
      m++;
      if(a[i+1]>=a[i]){i++;}
    }
  }

  if(top!=0&&top!=1){
    i=top-1;
    while(i>0){
      a[i-1]+=a[i];
      p=make_pair(i,i-1);
      ans.push_back(p);
      m++;
      if(a[i-1]<=a[i]){i--;}
    }
  }

  cout << m << endl;
  for (int j=0;j<m;++j){
    llll q=ans[j];
    ll x=q.first, y=q.second;
    cout << x+1 << ' ' << y+1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    const int ROOM = 10;
    const int FLOOR = 3;
    const int BUILDING = 4;
    int x[BUILDING][FLOOR][ROOM] = {};

    int n, b, f, r, v;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d %d %d %d", &b, &f, &r, &v);
        x[b - 1][f - 1][r - 1] += v;
    }
    for (int b = 0; b < BUILDING; b++)
    {
        if (b != 0)
        {
            for (int i = 0; i < ROOM * 2; i++)
            {
                printf("#");
            }
            printf("\n");
        }
        for (int f = 0; f < FLOOR; f++)
        {
            for (int r = 0; r < ROOM; r++)
            {
                printf("%2d", x[b][f][r]);
            }
            printf("\n");
        }
    }
}


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

const ll MAXN = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;

ll N, ans=1000, tmp=0;
vector<ll> A;

signed main(){
    cin >> N;
    for(int i=0;i<N;i++) {
        ll a;
        cin >> a;
        A.push_back(a);
    }
    for(int i=0;i<N-1;i++) {
        if(A[i]<A[i+1]) {
            ll num = ans/A[i];
            tmp += num;
            ans -= A[i]*num;
        }
        if(A[i]>A[i+1]) {
            ans += A[i]*tmp;
            tmp = 0;
        }
    }
    ans += A.back()*tmp;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <utility>
#include <vector>
#include <queue>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> P;
typedef long long LL;
#define ALL(a) (a).begin(),(a).end()
#define PB push_back
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define INF 1000000

VVI C;

int dijkstra(int s) {
  int d[10];
  priority_queue<P, vector<P>, greater<P> > q;
  fill(d, d+10, INF);
  d[s] = 0;
  q.push(P(0, s));

  while(!q.empty()) {
    P p = q.top(); q.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    REP(i, 10) {
      if (d[i] > d[v] + C[v][i]) {
        d[i] = d[v] + C[v][i];
        q.push(P(d[i], i));
      }
    }
  }
  return d[1];
}

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

  REP(i, 10) {
    VI v;
    REP(j, 10) {
      int c;
      cin >> c;
      v.PB(c);
    }
    C.PB(v);
  }
  int d[10];
  REP(i, 10)
    d[i] = dijkstra(i);
  int score = 0;
  REP(i, H) {
    REP(j, W) {
      int a;
      cin >> a;
      if (a == -1)
        continue;
      score += d[a];
    }
  }
  cout << score << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>
#include <string>
#include <queue>
using namespace std;
#pragma warning (disable: 4996)

long long N, A[1 << 19], ans;
long long mod = 1000000007;

int main() {
	scanf("%lld", &N);
	for (int i = 0; i < N; i++) scanf("%lld", &A[i]);

	for (int i = 0; i < 60; i++) {
		long long s1 = 0, s2 = 0;
		for (int j = 0; j < N; j++) {
			if ((A[j] / (1LL << i)) % 2 == 1) s2++;
			else s1++;
		}
		long long R = s1 * s2 % mod;
		long long R2 = (1LL << i) % mod;
		ans += R * R2;
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
const int maxn=100000+10;
int x[maxn],xx[maxn],w[maxn];
int k,l,r,s,t,n,m;
long long c;
inline int read(){
	int r=0,w=1;
	char ch=getchar();
	while(ch>'9'||ch<'0'){ if(ch=='-') w=-1;ch=getchar(); }
	while(ch>='0'&&ch<='9'){ r=r*10+ch-'0'; ch=getchar(); }
	return r*w;
}
int main(){
    n=read(),l=read(),t=read();
    for(int i=1;i<=n;i++)
        x[i]=read(),w[i]=read();
	for(int i=1;i<=n;i++){
        if (w[i]==2) w[i]=-1;
        r=x[i]+w[i]*t;
        if (r>0) (c+=r/l)%=n;
        else if (r<0) (c+=(r+1)/l-1)%=n;
        xx[i]=(r%l+l)%l;
    }
    sort(xx+1,xx+n+1);
    c=(c+n)%n;
    for(int i=c+1;i<=n;i++)
        printf("%d\n",xx[i]);
    for(int i=1;i<=c;i++) printf("%d\n",xx[i]);
}

Measured memory_bytes: 2432
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
ll dp[305][90005]={0};
ll dp2[305][90005]={0};
const ll mod=998244353;
ll pow(ll x,ll y){
  if(y==0) return 1;
  ll ret=pow(x,y/2);
  ret*=ret;
  ret%=mod;
  if(y%2==1) ret*=x;
  return ret%mod;
}
int main(){
  ll n,sum=0;
  cin>>n;
  ll array[305]={0};
  for(ll i=1;i<=n;i++){
    cin>>array[i];
    sum+=array[i];
  }
  for(ll i=1;i<=n;i++){
    if(array[i]>=(sum+1)/2){
      cout<<0<<endl;
      return 0;
    }
  }
  const ll ferm=pow(2,mod-2);
  //cout<<ferm<<endl;
  dp[0][0]=1;
  dp2[0][0]=1;
  for(ll i=0;i<n;i++){
  //  dp[i+1][array[i+1]]+=pow(2,n-1);
  //  dp2[i+1][array[i+1]]++;
    for(ll j=0;j<90005;j++){
      dp[i+1][j]+=dp[i][j]*2;
      dp[i+1][j]%=mod;
      dp[i+1][j+array[i+1]]+=dp[i][j];
      dp[i+1][j+array[i+1]]%=mod;

      dp2[i+1][j]+=dp2[i][j];
      dp2[i+1][j+array[i+1]]+=dp2[i][j];
      dp2[i+1][j]%=mod;
      dp2[i+1][j+array[i+1]]%=mod;
    }
  }
  ll ans=pow(3,n);
  for(ll i=(1+sum)/2;i<90005;i++) {
    ans-=dp[n][i]*3;
    if(ans<0){
      while(ans<0) ans+=mod;
    }
    ans%=mod;
  }
//  cout<<ans<<endl;
  if(sum%2==0){
   ans+=dp2[n][sum/2]*3;
   ans%=mod;
  }
  if(ans<0){
    while(ans<0) ans+=mod;
  }
  ans%=mod;
  /*for(int i=0;i<=n;i++){
    for(int j=0;j<5;j++) cout<<dp[i][j]<<" ";
    cout<<endl;
  }*/
  cout<<ans<<endl;
}


Measured memory_bytes: 427520
#include<iostream>
#define min(a,b) a<b?a:b
using namespace std;
long long int p[100005];
long long int t[100005][5];
int main(){
	long long int n,m;
	long long int a,b,c;
	long long int i,j,k;
	long long int s=0;
	cin>>n>>m;
	for(i=0;i<m;i++){
		cin>>p[i],p[i]--;
	}
	for(i=0;i<n-1;i++){
		for(j=0;j<3;j++){cin>>t[i][j];}
	}
	for(i=0;i<m-1;i++){
		a=min(p[i],p[i+1]);
		b=p[i]+p[i+1]-a;
		t[a][3]++,t[b][3]--;
	}
	k=0;
	for(i=0;i<n-1;i++){
		k+=t[i][3];
		s+=min(k*t[i][0],k*t[i][1]+t[i][2]);
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 7732
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s, t;
    cin >> s >> t;
    
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());
    
    if (s < t) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll N, M;
ll Ps[100005];
ll A, B;
vector<ll> adj[100005];
pair<ll, ll> vis[100005], vis1[100005];

void dfs(int ind, int cnt) {
	vis[ind].first = 1;
	vis[ind].second = cnt;
	vis1[Ps[ind - 1]].first = 1;
	vis1[Ps[ind - 1]].second = cnt;
	for(int i = 0; i < adj[ind].size(); i++) {
		if(!vis[adj[ind][i]].first) {
			vis[adj[ind][i]].first = 1;
			dfs(adj[ind][i], cnt);
		}
	}
}


int main() {
	scanf("%lld %lld", &N, &M);
	for(int i = 0; i < N; i++) {
		scanf("%lld", &Ps[i]);
	}
	for(int i = 0; i < M; i++) {
		scanf("%lld %lld", &A, &B);
		adj[A].push_back(B);
		adj[B].push_back(A);
	}
	int cnt = 0;
	for(int i = 1; i <= N; i++) {
		if(!vis[i].first) {
			dfs(i, cnt);
			cnt++;
			// cout << " yes";
		}
	}
	ll ans = 0;
	for(int i = 1; i <= N; i++) {
		// cout << i << " "<< vis[i].second << " this\n" << i << " " << vis1[i].second << " that\n";
		if(vis[i].second == vis1[i].second) {
			ans++;
		}
	}
	printf("%lld\n", ans);
	return 0;
}
/*
	Powered by Buggy Plugin
*/


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

template<typename T> struct BIT {
    int max_n;
    vector<T> data;
    const T unit;
    BIT<T>(int n, T u = T(0)) : max_n(n), unit(u) {
        data.assign(max_n + 1, u);
    }
    void add(int i, T x) {
        while ( i <= max_n ) {
            data[i] += x;
            i += i & -i;
        }
    }
    T sum(int i) {
        T s = unit;
        while ( i > 0 ) {
            s += data[i];
            i -= i & -i;
        }
        return s;
    }
};


ll solve() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i];
    }
    vector<ll> ac(N);
    copy(A.begin(), A.end(), ac.begin());
    ac.push_back(0);
    sort(ac.begin(), ac.end());
    ac.erase(unique(ac.begin(), ac.end()), ac.end());
    vector<ll> a(N);
    for ( int i = 0; i < N; i++ ) {
        a[i] = lower_bound(ac.begin(), ac.end(), A[i]) - ac.begin();
    }

    BIT<ll> b(N+1, 0);
    vector<int> mi;
    ll am = 0;
    for ( int i = 0; i < N; i++ ) {
        b.add(1,1);
        b.add(a[i] + 1, -1);
        if ( am < a[i] ) {
            am = a[i];
            mi.push_back(i);
        }
    }

    vector<ll> ans(N);
    int ib = 1;
    for( int i : mi ) {
        while ( ib <= a[i] ) {
            ll na = ac[ib] - ac[ib-1];
            ll nb = b.sum(ib);
            ans[i] += na * nb;
            ib++;
        }
    }

    for ( int i = 0; i < N; i++ ) {
        cout << ans[i] << "\n";
    }
    return 0;
}

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


Measured memory_bytes: 5872
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]
    a = f()
    num_diff = len(set(a))
    to_eat = n - num_diff
    if to_eat%2:
        to_eat += 1
    
    print(n - to_eat)
    

solve()


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

using namespace std;

char ans[10];
int Getlen(){
	int x = 10;
	for(int i = 1; i <= 9; ++i){
		printf("? %d\n",x);
		fflush(stdout);
		scanf("%s",ans);
		if(ans[0] == 'N')return i;
		x *= 10;
	}
	x = 9;
	for(int i = 1; i <= 9; ++i){
		printf("? %d\n",x);
		fflush(stdout);
		scanf("%s",ans);
		if(ans[0] == 'Y')return i;
		x *= 10;x += 9;
	}return 10;
}
int main(){
	int len = Getlen();
	//printf("%d\n",len);
	if(len == 10){
		printf("! %d\n",1000000000);
		fflush(stdout);
		return 0;
	}
	int Ans = 0;
	for(int bit = 1; bit < len; ++bit){
		int l = 0,r = 9,re = 0;
		Ans *= 10;
		while(l <= r){
			int mid = l + r >> 1;
			printf("? %d\n",Ans + mid);
			fflush(stdout);
			scanf("%s",ans);
			if(ans[0] == 'Y')re = mid,l = mid + 1;
			else r = mid - 1;
		}
		Ans += re;
	}
	Ans *= 10;
	for(int i = (len == 1); i <= 9; ++i){
		printf("? %lld\n",10LL * (Ans + i));
		fflush(stdout);
		scanf("%s",ans);
		if(ans[0] == 'Y'){
			printf("! %d\n",Ans + i);
			fflush(stdout);
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 596
using System;
using System.Linq;
class Hello
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int k = int.Parse(Console.ReadLine());
        var x = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var sum = x.Sum(e => Math.Min(e * 2, Math.Abs(e - k) * 2));
        Console.WriteLine(sum);
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;

void fnInput(int& rnTrgSu, int& rnTrgKin)
{
  cin >> rnTrgSu >> rnTrgKin;
}

int fnRcsSch(int nPos, int nTrgSu, int nTrgKin, vector<int>& rvnNumMoney)
{
  vector<int> cnvnMoney{10000, 5000, 1000};

  if (nTrgKin < 0)  return -1;
  if (nPos == rvnNumMoney.size() - 1)
  {
    rvnNumMoney[nPos] = nTrgSu;
    if (nTrgKin - cnvnMoney[nPos] * nTrgSu == 0)
      return 1;
    else
      return 0;
  }

  for (int i = 0; i <= nTrgSu; i++)
  {
    rvnNumMoney[nPos] = i;
    int nRtn = fnRcsSch(nPos + 1, nTrgSu - i, nTrgKin - cnvnMoney[nPos] * i, rvnNumMoney);
    if      (nRtn == -1)  return 0;
    else if (nRtn)        return 1;
  }

  return 0;
}

int fnExhSch(int nTrgSu, int nTrgKin)
{
  vector<int> vnNumMoney(3);

  if (fnRcsSch(0, nTrgSu, nTrgKin, vnNumMoney))
  {
    for (int i = 0; i < vnNumMoney.size(); i++)
    {
      if ( i )  cout << " ";
      cout << vnNumMoney[i];
    }
    cout << endl;
  }
  else
    cout << -1 << " " << -1 << " " << -1 << endl;
}

int main()
{
  int nTrgSu, nTrgKin;
  
  fnInput(nTrgSu, nTrgKin);
  fnExhSch(nTrgSu, nTrgKin);

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
          long long int a,b,c;
          cin>>a>>b;
          c=a-b*2;
          if(c>0)
          {
                    cout<<c<<endl;
          }
          else
                    cout<<"0\n";
return 0;
}


Measured memory_bytes: 3500