akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <limits>
#include <utility>
#include <vector>
#include <tuple>

const int N = 200000;

int n, d, a[N], par[N];
std::pair<long long, std::pair<int, int>> candidates[N];

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

long long cost(const std::pair<int, int>& p)
{
    return 1LL * d * std::abs(p.first - p.second) + a[p.first] + a[p.second];
}

int main()
{
    scanf("%d%d", &n, &d);
    for (int i = 0; i < n; ++ i) {
        scanf("%d", a + i);
        par[i] = i;
    }
    int comp = n;
    long long result = 0;
    while (comp > 1) {
        for (int i = 0; i < n; ++ i) {
            candidates[i] = std::make_pair(std::numeric_limits<long long>::max(), std::make_pair(-1, -1));
        }
        for (int t = 0; t < 2; ++ t) {
            std::tuple<long long, int, int> best[3];
            best[0] = std::make_tuple(std::numeric_limits<long long>::max(), -1, 0);
            best[1] = std::make_tuple(std::numeric_limits<long long>::max(), -1, 0);
            for (int ii = 0; ii < n; ++ ii) {
                int i = t ? n - 1 - ii : ii;
                int idx = 0;
                if (std::get<1>(best[idx]) == find(i)) {
                    idx ++;
                }
                if (~std::get<1>(best[idx])) {
                    int j = std::get<2>(best[idx]);
                    candidates[find(i)] = std::min(candidates[find(i)], std::make_pair(cost(std::make_pair(i, j)), std::make_pair(i, j)));
                }
                long long value = a[i] - 1LL * d * ii;
                best[2] = std::make_tuple(value, find(i), i);
                std::sort(best, best + 3);
                if (std::get<1>(best[0]) == std::get<1>(best[1])) {
                    best[1] = best[2];
                }
            }
        }
        for (int i = 0; i < n; ++ i) {
            auto e = std::make_pair(candidates[i].second.first, candidates[i].second.second);
            if (~e.first && find(e.first) != find(e.second)) {
                comp --;
                par[find(e.first)] = find(e.second);
                result += cost(e);
            }
        }
    }
    std::cout << result << std::endl;
}


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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n;
  std::cin >> n;
  std::vector<int64_t> a(n);
  std::cin >> a;
  auto b = a;
  std::sort(b.begin(), b.end());

  int64_t p = 0;

  for (int64_t i = 0; i < n; i++) {
    if (a[i] != b[i]) {
      p++;
    }
  }
  if (p == 0 || p == 2) {
    std::cout << "YES" << std::endl;
  } else {
    std::cout << "NO" << std::endl;
  }

  return 0;
}

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


int main()
{
	//freopen("input16.txt","r",stdin);freopen("output16.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int w,h,n,i,xl=0,xr,yu,yd=0,x,y,a;
	cin>>w>>h>>n;
	xr=w;
	yu=h;
	for (i=0;i<n;i++){
		cin>>x>>y>>a;
		if (a==1){
			if (xl<x){
				xl=x;
			}
		}
		else if (a==2){
			if (xr>x){
				xr=x;
			}
		}
		else if (a==3){
			if (yd<y){
				yd=y;
			}
		}
		else {
			if (yu>y){
				yu=y;
			}
		}
	}
	if (xl>=xr||yu<=yd){
		cout<<"0";
	}
	else {
		cout<<abs(xl-xr)*abs(yu-yd);
	}
	return 0;
}

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

int main() {
  int a,b;
  cin>>a>>b;
  if(a>b){swap(a,b);}
  rep(i,b){cout<<a;}
  cout<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789

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

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

int H, W;
int N;
int s_x, s_y;
string S;
string T;
int dp[212345][4];

bool ans = false;

int main(){
	
	cin>>H>>W>>N;
	cin>>s_y>>s_x;
	cin>>S;
	cin>>T;
	
	dp[N][0] = 0;
	dp[N][1] = W+1;
	dp[N][2] = 0;
	dp[N][3] = H+1;
	
	REP( i, N ){
		int idx = N-i-1;
		REP( j, 4 ) dp[idx][j] = dp[idx+1][j];
		if( T[idx] == 'R' && dp[idx][0] > 0 ) dp[idx][0]--; 
		if( T[idx] == 'L' && dp[idx][1] < W+1 ) dp[idx][1]++;
		if( T[idx] == 'D' && dp[idx][2] > 0 ) dp[idx][2]--;
		if( T[idx] == 'U' && dp[idx][3] < H+1 ) dp[idx][3]++;
		if( S[idx] == 'L' ) dp[idx][0]++;
		if( S[idx] == 'R' ) dp[idx][1]--;
		if( S[idx] == 'U' ) dp[idx][2]++;
		if( S[idx] == 'D' ) dp[idx][3]--;
		if( dp[idx][0] + 1 >= dp[idx][1] ) ans = true;
		if( dp[idx][2] + 1 >= dp[idx][3] ) ans = true;
		if( ans ){
			//cout<<"***"<<idx<<endl;
			break;
		}
	}
	/*
	REP( i, N+1 ){
		printf("%d %d %d %d\n", dp[i][0], dp[i][1], dp[i][2], dp[i][3]);
	}*/
	
	if( dp[0][0] >= s_x || dp[0][1] <= s_x ) ans = true;
	if( dp[0][2] >= s_y || dp[0][3] <= s_y ) ans = true;
	
	if( ans ) puts("NO");
	else{	puts("YES");}
	
	return 0;
}

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

int main(){
    int N,M,K;
    cin >> N >> M >> K;
    for(int i=0;i<=N;i++){
        for(int t=0;t<=M;t++){
            if(t*N+i*M-i*t*2==K){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 384
from itertools import combinations
n,m,x = map(int, input().split())
ca = [list(map(int, input().split())) for _ in range(n)]

ans = 10**9
for i in range(1, n+1):
  for j in combinations(ca, i):
    t = [0]*(m+1)
    for k in j:
      for l in range(m+1):
        t[l] += k[l]
    if all(t[a] >= x for a in range(1,m+1)):
      ans = min(ans, t[0])
if ans != 10**9:
  print(ans)
else:
  print(-1)

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

int main() {
	int n,i,k,j;
	cin>>n>>k;
	int ht[n];
	for(i=0;i<n;i++)
	{
	    cin>>ht[i];
	}
	int dp[n];
	dp[0]=0;
	dp[1]=abs(ht[1]-ht[0]);
	for(i=2;i<=n;i++)
	{
	    dp[i]=INT_MAX;
	    for(j=1;j<=min(i,k);j++)
	    {
	        dp[i]=min(abs(ht[i-j]-ht[i])+dp[i-j],dp[i]);
	    }
	}
	cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 4444
#include <bits/stdc++.h>
#define maxN 3002
#define mod 1000000007
using namespace std;

//FILE *fin = freopen("d.in", "r", stdin);

int n, m;

int dp[2][maxN][2];

int ans;

int Mod(int &x)
{
    if (x >= mod)
        x -= mod;
}

int main()
{
    scanf("%d %d", &n, &m);
    dp[0][0][1] = 1;
    for (int i = 1; i <= n; ++ i)
        dp[0][i][0] = 1;
    for (int j = 0; j < m; ++ j)
    {
        int t = j & 1;
        memset(dp[!t], 0, sizeof(dp[!t]));
        for (int i = 0; i <= n; ++ i)
        {
            for (int sp = 0; sp < 2; ++ sp)
                if (dp[t][i][sp])
                {
                    if (n - i >= 1)
                    {
                        dp[!t][i + 1][sp] += dp[t][i][sp];
                        Mod(dp[!t][i + 1][sp]);
                    }
                    if (i >= 1)
                    {
                        dp[!t][i][(i == 1) || sp] += dp[t][i][sp];
                        Mod(dp[!t][i][(i == 1) || sp]);
                    }
                    if (n - i >= 1)
                    {
                        dp[!t][i][sp] += dp[t][i][sp];
                        Mod(dp[!t][i][sp]);
                    }
                    if (i >= 1)
                    {
                        dp[!t][i - 1][(i == 1) || sp] += dp[t][i][sp];
                        Mod(dp[!t][i - 1][(i == 1) || sp]);
                    }
                }
        }
    }
    for (int i = 0; i <= n; ++ i)
    {
        ans += dp[m & 1][i][1];
        Mod(ans);
    }

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


Measured memory_bytes: 384
n=int(input())
a=list(map(int,input().split()))
pair=[]
for i in range(n):
    if i+1 > a[i]:
        w=i+1
        i=a[i]
    else:
        w=a[i]
        i+=1
    pair.append([i,w])
pair.sort()
ans=0
for i in range(len(pair)-1):
    if pair[i]==pair[i+1]:
        ans+=1
print(ans)

Measured memory_bytes: 20564
var
  n,m,i,j,s:longint;
  a:array[0..1000,0..1000] of char;
  p:boolean;
begin
  readln(n,m);
  for i:=1 to n do
  begin
    for j:=1 to m do read(a[i,j]);
    readln;
  end;
  for i:=1 to n do
  begin
    for j:=1 to m do
    begin
      p:=true;
      if a[i,j]='#' then begin write('#');p:=false; end;
      if p then
      begin
           s:=0;
           if a[i-1,j]='#' then s:=s+1;
           if a[i+1,j]='#' then s:=s+1;
           if a[i-1,j-1]='#' then s:=s+1;
           if a[i-1,j+1]='#' then s:=s+1;
           if a[i,j+1]='#' then s:=s+1;
           if a[i,j-1]='#' then s:=s+1;
           if a[i+1,j-1]='#' then s:=s+1;
           if a[i+1,j+1]='#' then s:=s+1;
           write(s);
      end;
    end;
    writeln;
  end;
end.

Measured memory_bytes: 128
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;
int t, T;

int main() {
#ifdef Albin
	freopen("Input.txt", "r", stdin);
	//freopen("Output.txt", "w", stdout);
#endif // Albin
	double r;
	cin >> r;
	cout << 2 * acos(-1) * r << endl;


	return 0;
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
#define long long long
using namespace std;
template<class A, class B>inline bool chmax(A &a, const B &b){return (a<b)?a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return (a>b)?a=b,1 : 0;}
using pii = pair<int,int>;

long f(int n) {
  if (n & 1) return 3*n + 1;
  else return n/2;
}
static long a[1000005] = {};

int main()
{
  int s;
  map<long, bool> exist;

  cin >> s;
  a[1] = s;
  exist[s] = true;

  int m = INT_MAX;
  for (int i = 2; i < 1000'005; ++i) {
    a[i] = f(a[i-1]);
    if (exist[a[i]]) {
      m = i;
      break;
    }
    exist[a[i]] = true;
  }

  cout << m << endl;

  return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
#include <array>
#include <numeric>
#include <regex>
#include <bitset>
#include <deque>

using namespace std;
typedef long long ll;
typedef pair<int, int> p_ii;

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;



int main() {
    ll n,m;
    cin>>n>>m;
    m/=2;
    if(n<m)cout<<(n+m)/2<<endl;
    else cout<<m<<endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int k = scan.nextInt();
        int height[] = new int[n];
        for(int i = 0; i < n; i++){
            int h = scan.nextInt();
            height[i] = h;
        }
        int count = 0;
        for(int i = 0; i < n; i++){
            if(height[i] >= k){
                count += 1;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 51076
/**
*    created: 10.07.2020 16:51:09
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1LL << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

signed main() {

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

    string s; cin >> s;
    int l, r;
    rep(i,s.size()) if (s[i] == 'A') {l = i; break;}
    for (int i = s.size()-1; i >= 0; i--) if (s[i] == 'Z') {r = i; break;}
    cout << r - l + 1 << endl;
    return 0;
}

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

using ll = long long;

vector<ll> nums;

void dfs(ll now, int c7, int c5, int c3) {
    // cout << now << endl;
    if(now >= 1e9)
        return;
    if(c7 > 0 && c5 > 0 && c3 > 0) {
        nums.push_back(now);
    }
    dfs(now * 10 + 7, c7 + 1, c5, c3);
    dfs(now * 10 + 5, c7, c5 + 1, c3);
    dfs(now * 10 + 3, c7, c5, c3 + 1);
}

int main() {
    int n;
    cin >> n;
    dfs(0, 0, 0, 0);
    sort(nums.begin(), nums.end());
    ll ans;

    for(ans = 0; ans < nums.size(); ans++) {
        if(nums[ans] > n)
            break;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <queue>
#include <stack>
#include <deque>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = (int)(a);(i) > (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, n) &((x)[0]), &((x)[n])
#define BRK(x) { (x); break; }
#define ADD(a, b) ((((a)%MOD)+((b)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mt make_tuple
#define fi first
#define se second
#define EPS (1e-20)
#define INF 2147483647
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using VLL = std::vector<llint>;
using MCI = std::map<char, int>;
using namespace std;



int N, M;
bool g[10][10];


bool judge(VI& perm){
	rep(i, 0, N-1)
		if(!g[perm[i]][perm[i+1]]) return false;
	return true;
}


int solve(){
	int ans = 0;
	VI perm = VI(N);
	iota(ALL(perm), 0);
	do {
		if(judge(perm)) ans++;
	} while(next_permutation(perm.begin()+1, perm.end()));
	return ans;
}


signed main(){
	cin >> N >> M;
	rep(i, 0, M){
		int a, b;
		cin >> a >> b, a--, b--;
		g[a][b] = g[b][a] = true;
	}

	cout << solve() << endl;

	return 0;
}

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

int main(){
  int64_t N,x;
  cin>>N>>x;
  vector<int64_t> a(N);
  for(int i=0;i<N;++i) cin>>a[i];

  //K回転して揃えるときの最小値
  int64_t ans=0;
  for(int i=0;i<N;++i) ans += a[i];
  
  vector<int64_t> b=a;
  for(int K=1;K<N;++K){
    int64_t subans=0;
    for(int i=0;i<N;++i){
      b[i]=min(b[i],a[(i+(N-K))%N]);
      subans += b[i];
    }
    ans=min(ans,subans+K*x);
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, L;
  cin >> N >> L;
  
  int i,j;
  int sum = 0;
  int least,sa,sa1,check;
  int num;
  
  for(i = 1;i <= N;i++){
    sum += (i + L - 1);
  }
  for(i = 1;i <= N;i++){
    check = 0;
    for(j = 1;j <= N;j++){
      if(j == i){
        continue;
      }
      check += (j + L - 1);
    }
    sa = check - sum;
    if(sa < 0){
      sa *= -1;
    }
    if(sa < sa1 || i == 1){
      least = check;
      sa1 = sa;
    }
  }
  cout << least << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}

vector<ll> g[MAX*2];
ll c[MAX*2];

void bfs(ll s) {
  ll i, u, v;
  ll used[MAX*2]={};
  queue<ll> q;
  q.push(s);
  while(q.size()) {
    u=q.front(); q.pop();
    used[u]=1;
    for(i=0; i<g[u].size(); i++) {
      v=g[u][i];
      
      if(used[v]) continue;
      c[v]+=c[u];
      q.push(v);
    }
  }
  
}

int main() {
  ll N, Q;
  cin >> N >> Q;
  ll i;
  
  for(i=0; i<N-1; i++) {
    ll a, b;
    cin >> a >> b;
    a--; b--;
    g[a].pb(b);
    g[b].pb(a);
  }
  
  for(i=0; i<Q; i++) {
    ll p, x;
    cin >> p >> x;
    p--;
    c[p]+=x;
  }
  
  bfs(0);
  for(i=0; i<N; i++) {
    pt(c[i]);
  }
  
  
}













Measured memory_bytes: 19440
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e15+9
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

ll n, a[1000];

int main(){
	ll MIN = INF, MAX = -INF;
	ll ans = INF;
	cin >> n;
	REP(i, n){
		cin >> a[i];
		MIN = min(MIN, a[i]);
		MAX = max(MAX, a[i]);
	}
	FOR(i, MIN, MAX + 1){
		ll sum = 0;
		REP(j, n){
			sum += (a[j] - i)*(a[j] - i);
		}
		ans = min(ans, sum);
	}
	cout << ans << endl;
}

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

using namespace std;

template <typename T>
T gcd(T a, T b) {
  return (b ? gcd(b, a % b) : a);
}

static const int64_t MOD = 1000000007;

int64_t modpow(int64_t base, int64_t k, int64_t mod) {
  base %= mod;
  int64_t answer = 1;
  while (k > 0) {
    if (k & 1) answer = (answer * base) % mod;
    base = (base * base) % mod;
    k >>= 1;
  }
  return answer;
}

int main() {
  int N;
  cin >> N;
  unordered_map<int64_t, unordered_map<int64_t, int64_t>> M;
  int64_t zeros = 0;
  unordered_set<int64_t> S;
  for (int i = 0; i < N; i++) {
    int64_t a, b;
    S.insert(a);
    scanf("%ld %ld", &a, &b);
    if (a == 0 && b == 0) {
      zeros++;
    } else if (a == 0) {
      M[0][1]++;
    } else if (b == 0) {
      M[1][0]++;
    } else {
      int64_t g = gcd(a, b);
      a /= g;
      b /= g;
      M[a][b]++;
    }
  }

  int64_t answer = 1;
  unordered_map<int64_t, unordered_set<int64_t>> used;
  for (const auto& p : M) {
    int64_t A1 = p.first;
    for (const auto& p2 : M[A1]) {
      int64_t B1 = p2.first;
      int64_t C1 = p2.second;
      if (M.find(-A1) != M.end() && M[-A1].find(B1) != M[-A1].end()) {
        C1 += M[-A1][-B1];
      }

      if (used[A1].count(B1)) continue;
      if (used[-A1].count(-B1)) continue;
      if (used[-B1].count(A1)) continue;
      if (used[B1].count(-A1)) continue;

      used[A1].insert(B1);
      used[-A1].insert(-B1);
      used[-B1].insert(A1);
      used[B1].insert(-A1);

      int64_t C2 = 0;
      if (M.find(-B1) != M.end() && M[-B1].find(A1) != M[-B1].end()) {
        C2 += M[-B1][A1];
      }
      if (M.find(B1) != M.end() && M[B1].find(-A1) != M[B1].end()) {
        C2 += M[B1][-A1];
      }

      int64_t K = modpow(2, C1, MOD);
      K = (K + modpow(2, C2, MOD)) % MOD;
      K = (K - 1 + MOD) % MOD;
      answer = (answer * K) % MOD;
    }
  }

  answer = (answer + MOD - 1 + zeros) % MOD;
  cout << answer << endl;

  return 0;
}


Measured memory_bytes: 162328
#include<bits/stdc++.h>
using namespace std;
string a;
int ans=1,b[10010];
int main(){
    cin>>a;
    for(int i=0;i<a.size();i++) b[i]=a[i]-'0';
    sort(b,b+a.size());
    for(int i=1;i<a.size();i++){
        if(a[i]==a[i-1]) ans++;
        else ans=1;
        if(ans==3) return cout<<"Yes"<<endl,0;
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] xs = new int[n];
    for (int i = 0; i < xs.length; i++) {
      xs[i] = sc.nextInt();
    }
    Arrays.sort(xs);
    int a = 0;
    int b = 0;
    int index = 0;
    for (int i = n - 1; i >= 0; i--) {
      if (index % 2 == 0)
        a += xs[i];
      else
        b += xs[i];
      index++;
    }

    System.out.println(a - b);
    sc.close();
  }
}


Measured memory_bytes: 35832
n = input()
h = input().split()
res = []
ct = 0

for i in range(len(h) - 1):
  if int(h[i]) >= int(h[i+1]):
    ct = ct + 1
  else:
    res.append(ct)
    ct = 0

res.append(ct)

print(max(res))

Measured memory_bytes: 11132
from math import inf
A=26

D=int(input())

C=[0]+list(map(int,input().split())) #減る満足度のベース
S=[0]*(D+1) #S[d][i] :(d+1)日目にコンテストiを開催した時の満足度

for i in range(1,D+1):
    S[i]=[0]+list(map(int,input().split()))


L=[0]*(A+1)
for d in range(1,D+1):
    M=-inf
    E=0

    for j in range(1,A+1):
        X=0
        for k in range(1,A+1):
            if j!=k:
                X-=C[k]*(d-L[k]+1)
                
        if M<=X+S[d][j]:
            M=X+S[d][j]
            E=j

    print(E)
    
    for j in range(1,A+1):
        if j!=E:
            L[j]+=1
        else:
            L[j]=0


Measured memory_bytes: 74556
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////
int main(){
    int H,W,h,w;
    cin >> H >> W >> h >> w;
    int a[501][501] = {};


    if ((H % h == 0) and (W % w == 0)){
        printf("No\n");
        return 0;
    }

    int B = (1000000000 - 1) / (h*w - 1);
    FORq(i,1,H){
        FORq(j,1,W){
            if ((i%h == 0) and (j%w == 0)) {
                a[i][j] = -((h*w-1)*B+1);
            }else{
                a[i][j] = B;
            } 
        }
    }


    printf("Yes\n");
        FORq(i,1,H){
            FORq(j,1,W){
                printf("%d ",a[i][j]);
                printf("\n");
        }
    }

}


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

using namespace std;

const int maxn=1400;

int dp[maxn][maxn],g[maxn][maxn];

int getlargestsquare(int h,int w)
{
    int maxwidth=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            dp[i][j]=(g[i][j]+1)%2;
            maxwidth|=dp[i][j];
        }
    }
    for(int i=1;i<h;i++){
        for(int j=1;j<w;j++){
            if(g[i][j]){
                dp[i][j]=0;
            }else{
                dp[i][j]=min(dp[i-1][j-1],min(dp[i-1][j],dp[i][j-1]))+1;
                maxwidth=max(maxwidth,dp[i][j]);
            }
        }
    }
    return maxwidth*maxwidth;
}

int main()
{
    int h,w;
    cin>>h>>w;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>g[i][j];
        }
    }
    printf("%d\n",getlargestsquare(h,w));
    return 0;
}



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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

const int INF=INT_MAX-1;

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


    int s,w;
    cin >> s >> w;
    if(s<=w)
        cout << "unsafe\n";
    else
        cout << "safe\n";
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) ((int)(a).size())
#define PB(a) push_back(a)
#define EMP emplace
#define EMPB(...) emplace_back(__VA_ARGS__)
#define MP(a, b) make_pair(a, b)
#define MT(...) make_tuple(__VA_ARGS__)
#define Bit(n) (1LL << (n))
using namespace std;
using pii = pair<int, int>;
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const int INF = 1LL << 30;
const double EPS = 1e-10;

int dy[4] = {-1, 0, 0, 1};
int dx[4] = {0, -1, 1, 0};

int H, W;
string s[410];
int used[410][410];
int cw, cb;

bool contain(int y, int x) {
  return y >= 0 && y < H && x >= 0 && x < W;
}

void dfs(int y, int x) {
  if (s[y][x] == '.') cw++;
  else cb++;
  used[y][x] = 1;
  for (int i = 0; i < 4; i++) {
    int ny = y + dy[i];
    int nx = x + dx[i];
    if (contain(ny, nx) && !used[ny][nx] && (s[ny][nx] != s[y][x])) {
      dfs(ny, nx);
    }
  }
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> H >> W;
  REP(i, H) cin >> s[i];
  int ans = 0;
  REP(i, H) REP(j, W) if (!used[i][j]) {
    cw = 0;
    cb = 0;
    dfs(i, j);
    ans += cw*cb;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 14208
def chmin(a, b)
  a > b ? b : a
end
n,l = gets.split.map(&:to_i)
tas = []
sum = 0
(1..n).each do |i|
    tas << i + l - 1
    sum += i + l - 1
end

k = tas[0]

(1..n - 1).each do |i|
    if tas[i - 1].abs > tas[i].abs
        k = tas[i]
    end
end

puts sum - k


Measured memory_bytes: 1788
#include <iostream>
#include <fstream>
#include <set>
using namespace std;

int main()
{
    //ifstream cin("input.txt");

    set<int> s;
    int n, d;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> d;
        s.insert(d);
    }
    cout << int(s.size());
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

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

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};

int main(){
    int n, a, b; cin>>n>>a>>b;
    cout << min(a, b) << " " << max(0, a+b-n) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int H = sc.nextInt();
    int W = sc.nextInt();
    int h = sc.nextInt();
    int w = sc.nextInt();
    
    int brack = h*W+w*H-h*w;
    int white =H*W-brack;
    System.out.println(white);
  }
}
    

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string a, b, c;
  cin >> a >> b >> c;
  
  if (a[a.size()-1]==b[0] && b[b.size()-1]==c[0])
    cout << "YES";
  else
    cout << "NO";
}

Measured memory_bytes: 3612
def resolve():
    d, n = map(int, input().split())
    if d == 0:
        if n == 100:
            print(101)
        else:
            print(n)
    elif d == 1:
        if n == 100:
            print(10100)
        else:
            print(n*100)
    else:
        if n == 100:
            print(1010000)
        else:
            print(n*10000)
resolve()

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


#define MAX 200000
#define SENTINEL 2000000000
typedef long long ll;

int L[MAX / 2 + 2], R[MAX / 2 + 2];

ll merge(int A[], int n, int left, int mid, int right) {
	int i, j, k;
	ll cnt = 0;
	int n1 = mid - left;
	int n2 = right - mid;
	for (i = 0; i < n1; i++)L[i] = A[left + i];
	for (i = 0; i < n2; i++)R[i] = A[mid + i];
	L[n1] = R[n2] = SENTINEL;
	i = j = 0;
	for (k = left; k < right; k++) {
		if (L[i] <= R[j]) {
			A[k] = L[i++];
		}
		else {
			A[k] = R[j++];
			cnt += n1 - i;
		}
	}
	return cnt;


}

ll mergeSort(int A[], int n, int left, int right) {
	int mid;
	ll v1, v2, v3;
	if (left + 1 < right) {
		mid = (left + right) / 2;
		v1 = mergeSort(A, n, left, mid);
		v2 = mergeSort(A, n, mid, right);
		v3 = merge(A, n, left, mid, right);
		return v1 + v2 + v3;

	}else return 0;
}

int main() {
	int A[MAX], n, i;

	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> A[i];
	}

	ll ans = mergeSort(A, n, 0, n);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4640
#include <stdio.h>

int order(int n) {
	int ord = 0;
	while (n > 0) {
		n /= 10;
		ord++;
	}
	return ord;
}

int main(void) {
	int a, b;
	while (scanf("%d%d", &a, &b) == 2) {
		printf("%d\n", order(a+b));
	}
	return 0;
}

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

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

    int n;
    cin >> n;
    vector<int> ds(n);
    for (int i = 0; i < n; i++) cin >> ds[i];
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            ans += ds[i] * ds[j];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
/// ???
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e5 + 10;
struct Node{
	int typ,val;
	bool operator<(const Node &rsh)const{
		return val>rsh.val;
	}
}arr[maxn];
bool vis[maxn];
int main(){
	int N,K;
	scanf("%d%d",&N,&K);
	for(int i = 0 ; i < N ; ++i){
		Node &now = arr[i];
		scanf("%d%d",&now.typ,&now.val);
	}
	sort(arr,arr+N);

	stack<int> S;
	int cnt = 0,typ = 0;
	LL ans = 0,res = 0;
	for(int i = 0 ; i < N; ++i){
		Node &now = arr[i];
		if(cnt < K){
			if(!vis[now.typ]){
				vis[now.typ] = 1;
				++typ;
			}else
				S.push(now.val);
			res += now.val;
			++cnt;
			ans = max(ans,res + 1ll*typ*typ);
		}else{
			if(S.empty()) break;
			if(vis[now.typ]) continue;
			vis[now.typ] = 1 ;
			++typ;
			res += now.val;
			res -= S.top(); S.pop();
			ans= max(ans,res+1ll*typ*typ);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1280
h=int(input())
w=int(input())
n=int(input())

if h > w:
    if n%h==0:
        answer=int(n/h)
    else:
        answer=int(n/h)+1
else:
    if n%w==0:
        answer=int(n/w)
    else:
        answer=int(n/w)+1
print(answer)

 

Measured memory_bytes: 2940
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    C=list(map(int,input().split()))
    
    def COMinit(n,MOD):
        fac,finv,inv=[0]*max(2,n+1),[0]*max(2,n+1),[0]*max(2,n+1)
        fac[0]=fac[1]=1
        finv[0]=finv[1]=1
        inv[1]=1
        for i in range(2,(n+1)):
            fac[i]=fac[i-1]*i%MOD
            inv[i]=MOD-inv[MOD%i]*(MOD//i)%MOD
            finv[i]=finv[i-1]*inv[i]%MOD
        return fac,finv,inv
    
    fac,finv,inv=COMinit(N,MOD)
    
    def COM(n, k, MOD):
        if n<k or n<0 or k<0:
            return 0
        return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD
    
    def modinv(a, mod):
        b,u,v = mod,1,0
        while b:
            t=a//b
            a-=t*b
            a,b=b,a
            u-=t*v
            u,v=v,u
        u%=mod
        if u < 0:
            u+=mod
        return u

    def modpow(n,k,MOD):
        if k<0:
            return pow(modinv(n,MOD),-k,MOD)
        else:
            return pow(n,k,MOD)
    
    C.sort(reverse=1)
    ans=0
    for i in range(N):
        ans+=(modpow(2,i,MOD)+i*modpow(2,i-1,MOD))*2*modpow(2,N-(i+1),MOD)*C[i]
        ans%=MOD
    ans*=pow(2,N-1,MOD)
    ans%=MOD
    print(ans)

if __name__ == '__main__':
    main()


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

struct PrimalDual{
  const int INF = 1<<28;
  typedef pair<int,int> P;
  struct edge{
    int to,cap,cost,rev;
    edge(){}
    edge(int to,int cap,int cost,int rev):to(to),cap(cap),cost(cost),rev(rev){}
  };

  int n;
  vector<vector<edge> > G;
  vector<int> h,dist,prevv,preve;

  PrimalDual(){}
  PrimalDual(int sz):n(sz),G(sz),h(sz),dist(sz),prevv(sz),preve(sz){}
  
  void add_edge(int from,int to,int cap,int cost){
    G[from].push_back(edge(to,cap,cost,G[to].size()));
    G[to].push_back(edge(from,0,-cost,G[from].size()-1));
  }

  int flow(int s,int t,int f){
    int res=0;
    fill(h.begin(),h.end(),0);
    while(f>0){
      priority_queue<P,vector<P>,greater<P> > que;
      fill(dist.begin(),dist.end(),INF);
      dist[s]=0;
      que.push(P(0,s));
      while(!que.empty()){
        P p=que.top();que.pop();
        int v=p.second;
        if(dist[v]<p.first) continue;
        for(int i=0;i<(int)G[v].size();i++){
          edge &e=G[v][i];
          if(e.cap>0&&dist[e.to]>dist[v]+e.cost+h[v]-h[e.to]){
            dist[e.to]=dist[v]+e.cost+h[v]-h[e.to];
            prevv[e.to]=v;
            preve[e.to]=i;
            que.push(P(dist[e.to],e.to));
          }
        }
      }
      if(dist[t]==INF) return -1;
      for(int v=0;v<n;v++) h[v]+=dist[v];
      int d=f;
      for(int v=t;v!=s;v=prevv[v]){
        d=min(d,G[prevv[v]][preve[v]].cap);
      }
      f-=d;
      res+=d*h[t];
      for(int v=t;v!=s;v=prevv[v]){
        edge &e=G[prevv[v]][preve[v]];
        e.cap-=d;
        G[v][e.rev].cap+=d;
      }
    }
    return res;
  }
};

int main(){
  int n;
  while(cin>>n,n){
    PrimalDual p(368);
    r(i,n){
      int a,b,c;
      cin>>a>>b>>c;
      p.add_edge(a,b+1,1,-c);
    }
    r(i,367)p.add_edge(i,i+1,2,0);
    cout<<-p.flow(0,366,2)<<endl;
  }
}


Measured memory_bytes: 3124
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;

struct UnionFind {
	vector<int> par;
	vector<int> rank;
	vector<int> diff_weight;

	UnionFind(int n = 1, int SUM_UNITY = 0) {
		init(n, SUM_UNITY);
	}

	void init(int n = 1, int SUM_UNITY = 0) {
		par.resize(n); rank.resize(n); diff_weight.resize(n);
		for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
	}

	int root(int x) {
		if (par[x] == x) {
			return x;
		}
		else {
			int r = root(par[x]);
			diff_weight[x] += diff_weight[par[x]];
			return par[x] = r;
		}
	}

	int weight(int x) {
		root(x);
		return diff_weight[x];
	}

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

	bool merge(int x, int y, int w) {//unite
		w += weight(x); w -= weight(y);
		x = root(x); y = root(y);
		if (x == y) return false;
		if (rank[x] < rank[y]) swap(x, y), w = -w;
		if (rank[x] == rank[y]) ++rank[x];
		par[y] = x;
		diff_weight[y] = w;
		return true;
	}

	int diff(int x, int y) {//頂点間の距離
		return weight(y) - weight(x);
	}
};

void solve(int N) {
	map<string, int>id;
	UnionFind uni(210);
	int k = 1;
	bool F = 1;
	REP(i, N) {
		string ichi, t1, eq, ten, t2;
		cin >> ichi >> t1 >> eq >> ten >> t2;
		int val = 0;

		if (ten[3] == '-') {
			int a = 4;
			while (a < ten.size()) {
				val *= 10;
				val += ten[a] - '0';
				a++;
			}
			val *= -1;
		}
		else {
			int a = 3;
			while (a < ten.size()) {
				val *= 10;
				val += ten[a] - '0';
				a++;
			}
		}
		
		//cout << val << endl;
		if (id[t1] == 0)id[t1] = k++;
		if (id[t2] == 0)id[t2] = k++;
		if (uni.issame(id[t1], id[t2])) {
			//cout << uni.diff(id[t1], id[t2]) << endl;
			if (uni.diff(id[t2], id[t1]) != val) {
				F = false;
			}
		}
		else {
			uni.merge(id[t2], id[t1], val);
		}
	}
	if(F)cout << "Yes" << endl;
	else cout << "No" << endl;
	return;
}


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

	int N;
	while (1) {
		cin >> N;
		if (N == 0)break;
		solve(N);
	}

	return 0;
}




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

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			var a = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
			a.Sort();
			int max = a[n - 1];
			a.RemoveAt(n - 1);
			double mean = (double)max / 2;
			var b = a.Select(x => Math.Abs(x - mean)).ToList();
			double min = b.Min();
			int m = b.IndexOf(min);
			int mm = a[m];
			
			Console.WriteLine($"{max} {mm}");
		}
	}
}


Measured memory_bytes: 24416
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdlib.h>
#include<stdio.h>
#include<vector>
#include<utility>
#include<queue>
#include<stdbool.h>
using namespace std;
#define N (1000000000+7)
typedef pair<int, int> P;

int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };


int main(void) {
	int n, sum = 0;
	cin >> n;
	vector<int>l(n);
	for (int i = 0;i < n;i++)cin >> l[i];
	sort(l.begin(), l.end());
	for (int i = 0;i < n - 1;i++)sum += l[i];
	if (l[n - 1] < sum)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

int N, M;
vector<int> adj[100000];
vector<int> adj_rev[100000];

int find_root(){
  for(int i = 0; i < N; i++){
    if(adj_rev[i].size() == 0){
      return i;
    }
  }
}

int main(){
  cin >> N >> M;
  for(int i = 0; i < N - 1 + M; i++){
    int a, b;
    cin >> a >> b;
    adj[a - 1].push_back(b - 1);
    adj_rev[b - 1].push_back(a - 1);
  }
  int root = find_root();

  int depth[100000] = {};
  for(int i = 0; i < N; i++){
    depth[i] = -1;
  }

  int parent_visited_count[100000] = {};
  stack<int> st;
  st.push(root);
  depth[root] = 0;
  while(!st.empty()){
    int now = st.top(); st.pop();

    if(parent_visited_count[now] < adj_rev[now].size()){
      continue;
    }

    for(int i = 0; i < adj[now].size(); i++){
      int next = adj[now][i];
      parent_visited_count[next]++;
      if(depth[next] < depth[now] + 1){
	depth[next] = depth[now] + 1;
	st.push(next);
      }
    }
  }

  for(int i = 0; i < N; i++){
    if(i == root){
      cout << 0 << endl;
    }else{
      for(int j = 0; j < adj_rev[i].size(); j++){
	if(depth[i] == depth[adj_rev[i][j]] + 1){
	  cout << adj_rev[i][j] + 1 << endl;
	}
      }
    }
  }
}



Measured memory_bytes: 12544
#include<cstdio>
#include<string>

using namespace std;

int main()
{
	char input[4];
	char temp;
	string str;

	scanf("%s", input);

	str = input;

	if (str.size() == 3)
	{
		temp = str[0];
		str[0] = str[2];
		str[2] = temp;
	}

	printf("%s", str.c_str());

	return 0;
}

Measured memory_bytes: 256
def count_c(li1, li2):
    c = 0
    for i in range(10):
        if li1[i] == 1 and li1[i] == li2[i]:
            c += 1
    return c


n = int(input())
open_time_list = [list(map(int, input().split())) for _ in range(n)]
profit_list = [list(map(int, input().split())) for _ in range(n)]
ans = -10000000000000000000000000000000000
# [1, 0, 1, 0, 0, 0, 1, 1, 0, 1]総当たり
for i in range(1, 2 ** 10):
    f_list_joisino = list(map(int, list(format(i, 'b').zfill(10))))
    temp_profit = 0
    for profit_index, f_list in enumerate(open_time_list):
        temp_profit += profit_list[profit_index][count_c(
            f_list, f_list_joisino)]
    if ans < temp_profit:
        ans = temp_profit

print(ans)


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

using namespace std;
#define ll long long
#define ld long double
#define PI 3.141592653L
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll INF = (ll)1e18;
const int N = 2e6 + 5;
const ll MOD = 998244353;

int parent[N];

int gcd(int a, int b) { 
    if (a == 0) 
        return b;  
    return gcd(b%a, a);  
} 
   
int lcm(int a, int b) {  
    return (a*b)/gcd(a,b);  
} 

ll pow(ll x, ll y, ll p) {
    if(y == 0) return 1;
    ll res = 1;
    x %= p;
    if(x == 0) return 0LL;
    while(y > 0) {
        if(y & 1) res = (res*x) % p;
        y >>= 1;
        x = (x*x) % p;
    }
    return res;
}

int find(int x) {
    return x == parent[x] ? x : parent[x] = find(parent[x]);
}

void Union(int x, int y) {
    int xPar = find(x), yPar = find(y);
    if(xPar != yPar) parent[xPar] = yPar;
}

void solve() {
    ll a;
    cin >> a;
    cout << (a + a*a + a*a*a) << endl;
    return;
}

int main()
{
    IOS
    //int t;
    //cin >> t;
    //while(t--) 
    solve();
    return 0; 
}


Measured memory_bytes: 3640
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll;
typedef vector<vector<long long> > vvll;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i,n) _rep2((i),0,(n))
#define _rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define fi first
#define se second
#define mkp make_pair
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	int n;
	cin>>n;
	ll L;
	cin>>L;
	ll T;
	cin>>T;
	vll a,b;
	vector<pll> in(n);
	ll cnt = -1;
	rep(i,n){
		ll x,w;
		cin>>x>>w;
		in[i] = pll(x, w);
		if(w==1){
			if(cnt<0) cnt = i;
			a.PB(x);
		}
		else{
			b.PB(x);
		}
	}
	if(b.size()==0 || a.size()==0){
		rep(i,n){
			ll tmp = in[i].fi;
			if(in[i].se==1){
				tmp += T%L;
				tmp %= L;
			}
			else{
				tmp -= T%L - L;
				tmp %= L;
			}
			cout<<tmp<<endl;
		}
		return;
	}
	for(ll x: b){
		cnt += 2*T/L;
		ll d;
		if(x>a[0]){
			d = x-a[0];
		}
		else{
			d = L-a[0] + x;
		}
		// cout<<d<<endl;
		if(d <= 2*T%L){
			cnt++;
		}
	}
	// cout<<cnt<<endl;
	cnt %= n;
	vll pos(n);
	ll p;
	rep(i,n){
		ll tmp = in[i].fi;
		if(in[i].se==1){
			tmp += T%L;
			tmp %= L;
		}
		else{
			tmp -= T%L - L;
			tmp %= L;
		}
		if(in[i].fi == a[0] && in[i].se == 1) p = tmp;
		pos[i]=tmp;
	}
	sort(ALL(pos));
	vll ans(n);
	for(int i=n-1; i>=0; i--){
		if(pos[i] == p){
			rep(j,n){
				int ind = (cnt+j)%n;
				ans[ind] = pos[(i+j)%n];
			}
			break;
		}
	}
	rep(i,n){
		cout<<ans[i]<<endl;
	}
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 5364