akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF 1000000007
using namespace std;

int n;
pair<int,int> a[100010];

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;i++){
		int x,l;
		cin>>x>>l;
		a[i].first=x+l;
		a[i].second=x-l;
	}
	sort(a+1,a+n+1);
	int cnt=0,pre=-INF;
	for(int i=1;i<=n;i++){
		if(a[i].second>=pre){
			cnt++;
			pre=a[i].first;
		}
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 1024
N = input()
num = len(N)
mod_sum = [0]*2019
mod_sum[0] = 1
ans = 0
a = 0
d = 1
for i in range(num):
  a = (a + int(N[-i-1])*d)%2019
  d = (d*10)%2019
  mod_sum[a] += 1
for i in mod_sum:
  ans += i*(i-1)//2
print(ans)


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

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 0;
    }
    return 1;
}

int main(){
    int n;
    cin >> n;
    vector<int> h(n), dp(n, 2e09);
    for (int i = 0; i < n; i++) cin >> h.at(i);
    dp.at(0) = 0;
    
    for (int i = 1; i < n; i++){
        chmin(dp.at(i), dp.at(i-1)+abs(h.at(i)-h.at(i-1)));
        if (i > 1){
            chmin(dp.at(i), dp.at(i-2)+abs(h.at(i)-h.at(i-2)));
        }
    }
    cout << dp.at(n-1) << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <queue>
#include <algorithm>
#include <vector>

using namespace std;
typedef long long ll;

int a[50], b[50], c[50], d[50];
int N, M;
int iabs(int x){
  return (x > 0) ? x : (-x);
}

int dis(int i, int j){
  return iabs(a[i]-c[j]) + iabs(b[i]-d[j]);
}


int main(){
  cin >> N >> M;
  for(int i = 0; i < N; i++)  cin >> a[i] >> b[i];
  for(int i = 0; i < M; i++)  cin >> c[i] >> d[i];

  for(int i = 0; i < N; i++){
    int min = dis(i, 0);
    int point = 0;
    for(int j = 1; j < M; j++){
      if(dis(i, j) < min){
        min = dis(i, j);
        point = j;
      }
    }
    cout << point+1 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, p: "List[int]"):
    print(sum(sorted(p)[:K]))
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, p)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9032
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 110;
const ll INF = 2e9+10;

int n, t, cnt;
int main(){
    #ifdef Irene
    freopen("in.txt", "r", stdin);
    #endif // Irene
    //ios_base::sync_with_stdio(false);

    cin >> n;
    for(int i = 1;i <= n;i++){
        cin >> t;
        if(t == cnt + 1)cnt++;
    }
    cout << ((n-cnt) < n ? n-cnt : -1) << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define all(v) v.begin(),v.end()
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int,int>;
  
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    int p[n + 5];
    reps(i,n){
      cin >> p[i];
    }

    int sum = 0;
    reps(i,n - 1){
      if(i == p[i]){
	sum ++;
	swap(p[i],p[i + 1]);
      }
    }
    if(n == p[n]){
      sum ++;
    }
    cout << sum << '\n';
    return 0;
}


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

#define ll long long
#define ull unsigned long long
#define vii vector<int>
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pdd pair<double,double>
#define pldld pair<long long double, long long double>
#define ff first
#define ss second
#define pb push_back
#define read freopen("alu.txt","r",stdin);
#define write freopen("vorta.txt","w",stdout);
#define fastio ios::sync_with_stdio(false); cin.tie(NULL);
#define PI 2*acos(0.0)
#define DEBUG(x) cerr << #x << " = " << x << endl

const int MAX = 1e6 + 5, MOD = 1e9 + 7 , MAXLG = log2(MAX)+1;
const ll inf = 1e18 + 5;

int arr[MAX];
map<int,int>mp;
map<int,bool>vis;
int main(){

    fastio;
    int n,m;
    cin>>n>>m;
    bool ok = true;
    bool baal = false;
    for(int i=0; i<m; i++){
        int a,b;
        cin>>a>>b;
        if(a == 1 && !b) baal = true;
        if(vis[a] && mp[a] != b) ok = false;
        vis[a] = true;
        mp[a] = b;
    }

    if(!ok || (n > 1 && baal)){
        cout<<-1<<"\n";
        return 0;
    }

    if(n == 1){
        cout<<mp[1]<<"\n";
        return 0;
    }

    string s = "";
    if(mp.find(1) != mp.end()) s.pb(mp[1] + '0');
    else s.pb('1');

    for(int i=2; i<=n; i++){
        if(mp.find(i) == mp.end()) s.pb('0');
        else s.pb(mp[i] + '0');
    }
    cout<<s<<"\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <numeric>


int main()
{
	int a, b;

	std::cin >> a >> b;

	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
		std::cout << "Possible" << std::endl;
	}
	else {
		std::cout << "Impossible" << std::endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
  size_t N;
  std::cin >> N;

  std::string buf;
  std::cin >> buf;
  const char* S = buf.c_str();

  size_t K;
  std::cin >> K;

  const char target = S[K-1];

  for (size_t i = 0; i < N; i++) {
    if (S[i] == target) {
      std::cout << S[i];
    } else {
      std::cout << "*";
    }
  }
  std::cout << std::endl;

  return 0;
}


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

int INF=1001001001;

int main(void){
    int n, m, l;
    cin>>n>>m>>l;
    vector<vector<int> > dist(n, vector<int>(n, INF));
    rep(i, n){
        dist[i][i]=0;
    }
    rep(i,m){   
        int a, b, c;
        cin>>a>>b>>c;
        --a;--b;
        dist[a][b]=dist[b][a]=c;
    }

    rep(k, n)rep(i, n)rep(j, n) dist[i][j]=min(dist[i][j], dist[i][k]+dist[k][j]);
    vector<vector<int> > dist2(n, vector<int>(n, INF));
    rep(i, n)rep(j, n){
        if(dist[i][j]<=l) dist2[i][j]=1;
    }
    rep(k, n)rep(i, n)rep(j, n) dist2[i][j]=min(dist2[i][j], dist2[i][k]+dist2[k][j]);

    int q;
    cin>>q;
    rep(i, q){
        int s, t;
        cin>>s>>t;
        --s;--t;
        int ans=dist2[s][t]-1;
        if(dist2[s][t]==INF) ans=-1;
        cout<<ans<<endl;
    }

}

Measured memory_bytes: 1280
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <type_traits>
#include <map>

using namespace std;


int main(int argc, const char * argv[]) {
    int n, k;
    cin >> n >> k;
    map<int, int> mp;
    int tmp;
    for(int i = 0; i < n; i++){
        cin >> tmp;
        mp[tmp]+= 1;
    }
    //cout << mp.size() << endl;
    vector<pair<int, int>> vp;
    for(auto itr = mp.begin(); itr != mp.end(); itr++){
        vp.push_back(make_pair(mp[itr->first], itr->first));
    }
    
    sort(vp.begin(), vp.end());
//    for(int i = 0; i < mp.size(); i++){
//        cout << vp[i].first << "," << vp[i].second << endl;
//    }
    if(mp.size() <= k){
        cout << 0 << endl;
        return 0;
    }
    int ans = 0;
    for(int i = 0; i < mp.size() - k; i++){
        ans += vp[i].first;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 11768
import java.util.*;
import java.io.*;
import java.util.function.*;

class Main {
    static Scanner scanner = new Scanner();
    static int mod = 1000000007;
    static long inf = 0x7ffffffffffffffL;

    public static void main(String[]$) throws Exception {
        int n = scanner.nextInt();
        System.out.println(n % 2 == 0 ? n / 2 - 1 : n / 2);
    }

    static class System {
        static PrintWriter out = new PrintWriter(java.lang.System.out);

        static {
            Runtime.getRuntime().addShutdownHook(new Thread(System.out::flush));
        }

        static void exit() {
            java.lang.System.exit(0);
        }
    }

    static class Scanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(java.lang.System.in), 0x10000);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        char[][] nextCharArray(int n, int m) {
            char[][] a = new char[n][m];
            for (int i = 0; i < n; i++) {
                a[i] = next().toCharArray();
            }
            return a;
        }
        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }

        int[] nextIntArray(int n, IntUnaryOperator op) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = op.applyAsInt(nextInt());
            }
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextLong();
            }
            return a;
        }

        long[] nextLongArray(int n, LongUnaryOperator op) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = op.applyAsLong(nextLong());
            }
            return a;
        }
    }
}


Measured memory_bytes: 30676
#include<bits/stdc++.h> 
using namespace std; 
#define x first
#define y second
#define forn(i, n) for(int i = 0; i < int(n); ++i)
typedef pair<int, int> pii;
const int MAXN = 1000000+10;
int N;
//  vector<string> br(MAXN);


void solve(){
	cin>>N;
	vector<pair<int,int> > def1;
	vector<pair<int,int> > def2;
	int run = 0;
	forn(i,N){
		string ss;
		
		cin>>ss;
		int s1 = ss.size();
		int mina = 1000001;
		int co = 0;
		forn(j,s1){
			if(ss[j] == '(')
				co++;
			else
				co--;
			mina = min(co,mina);
		}
		if(mina>=0){
			run+=co;
		}
		else if(co>=0){
			def1.push_back({-mina,co});
		}
		else{
			def2.push_back({mina-co,-mina});
		}
		
		//cout<<mina<<" "<<co<<endl;
  	}
  	sort(def1.begin(),def1.end());
  	sort(def2.begin(),def2.end());
  	forn(i,def1.size()){
  		if(run-def1[i].x<0){
  			cout<<"No"<<endl;
  			return;
		}
		run+=def1[i].y;	
	}
	forn(i,def2.size()){
  		if(run-def2[i].y<0){
  			cout<<"No"<<endl;
  			return;
		}
		run-=def2[i].x+def2[i].y;	
	}
    

	
	//cout<<run<<" "<<"run"<<endl;
	if(run == 0){
		cout<<"Yes"<<endl;
		return;
	}
	else{
		cout<<"No"<<endl;
		return;
	}
	
	
	
}
int main(){
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	solve();
	
	return 0;	
}

Measured memory_bytes: 7656
#include<iostream>
using namespace std;
int main(){
	int A,B,C,D;
	cin>>A>>B>>C>>D;
	int min,max;
	if(A>C){
		max=A;
	}else{
		max=C; 
	}
	if(B<D){
		min=B;
	}else{
		min=D;
	}
	if(min-max<0){
		cout<<"0"<<endl;
	}else{
		cout<<min-max<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
import sys

input_line = input().split(" ")
a = int(input_line[1])
b = int(input_line[0])
str = input()

dtr = str[a-1:a].translate(str.maketrans('ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'))

ans = str[:a-1] + dtr + str[a:]
print(ans)

Measured memory_bytes: 38384
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<map>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<set>
using namespace std;
typedef pair<int,int> P;
#define X first
#define Y second
int N;
P p[3002];
//map<int,map<int,int> > M;
set<P> S;
int area(int mx,int my){
  //  printf("%d %d\n",mx,my);
  double line = sqrt(mx*mx+my*my);
  line*=line;
  line *= 10;
  int ret = (int)line;
  ret+=5;
  ret/=10;
  return ret;
}
int main(){
  while(1){
    scanf("%d",&N);
    if(!N) break;
    //    M.clear();
    for(int i=0;i<N;i++){
      scanf("%d %d",&p[i].X,&p[i].Y);
      //      M[p[i].X][p[i].Y]=1;
      S.insert(p[i]);
    }
    int res=0;
    sort(p,p+N);
    for(int i=0;i<N;i++){
      for(int j=i+1;j<N;j++){
	int x = p[i].X, y = p[i].Y;
	int mx = p[j].X - x;
	int my = p[j].Y - y;
	if(S.find(P(x-my,y+mx))!=S.end()){
	  if(S.find(P(x-my+mx,y+mx+my))!=S.end())
	    res = max(res,area(mx,my));
	}
	if(S.find(P(x+my,y-mx))!=S.end()){
	  if(S.find(P(x+my+mx,y-mx+my))!=S.end())
	    res = max(res,area(mx,my));
	}

	/*
	  if(M[x+my][y+mx]){
	  if(M[x+my+mx][y+mx+my])
	  res = max(res,area(mx,my));
	  }
	  if(M[x-my][y+mx]){
	  if(M[x-my+mx][y+mx+my])
	  res = max(res,area(mx,my));
	  }
	*/
      }
    }
    printf("%d\n",res);
    S.clear();

  }
}

Measured memory_bytes: 1344
N, M = map(int, input().split())
possibility = [False] * N  # True: 赤いボールが入っている可能性がある
possibility[0] = True
balls = [1] * N  # 箱に入っているボールの数
for i in range(M):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    if possibility[x]:
        possibility[y] = True
    balls[x] -= 1
    balls[y] += 1
    if balls[x] == 0:
        possibility[x] = False

ans = possibility.count(True)
print(ans)


Measured memory_bytes: 4596
<?php
$tri_status = [0,0,0,0];
while (true) {
    fscanf(STDIN, "%d %d %d", $a, $b, $c);
    if ($a + $b <= $c || $b + $c <= $a || $c + $a <= $b) {
        break;
    }
    $num_arr = [$a, $b, $c];
    sort($num_arr);
    
    $result = is_triangle($num_arr[0] ** 2, $num_arr[1] ** 2, $num_arr[2] ** 2);
    $tri_status[0]++;
    $tri_status[$result]++;
}
echo implode(' ', $tri_status)."\n";
// echo "\n";

function is_triangle($a, $b, $c) {
        if ($a + $b == $c) {
            return 1;
        } elseif ($a + $b < $c){
            return 3;
        } else {
            return 2;
        }

    return 4;
}
?>


Measured memory_bytes: 9288
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long int ll;

const ll N = 1e3 + 5, MOD = 1e9 + 7;

ll dp[N][N];
char matrix[N][N];

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

  int h, w;

  cin >> h >> w;

  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++)
      cin >> matrix[i][j];

  dp[0][0] = 1;

  for (int i = 1; i < w; i++) {
    if (matrix[0][i] == '.')
      dp[0][i] = dp[0][i-1];
    else
      dp[0][i] = 0;
  }

  for (int i = 1; i < h; i++) {
    if (matrix[i][0] == '.')
      dp[i][0] = dp[i-1][0];
    else
      dp[i][0] = 0;
  }

  for (int i = 1; i < h; i++)
    for (int j = 1; j < w; j++)
      if (matrix[i][j] == '.')
        dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % MOD;
      else
        dp[i][j] = 0;

  cout << dp[h-1][w-1] << endl;
  
  return 0;
}


Measured memory_bytes: 9088
def ok?(x)
  return false if x <= 0
  return true if x > 1999
  a = (x / 100)
  l = a * 100
  r = a * 100 + a * 5
  (l..r).cover?(x)
end
ARGF.each do |x|
  p ok?(x.to_i) ? 1 : 0
end


Measured memory_bytes: 14412
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
const long INF = 1000000009;

int n;

int main(){
	scanf("%d", &n);
	printf("%d\n", n/3);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <cfloat>
#include <cmath>
#define EPS 1.0e-5
using namespace std;

class P{
public:
  short to, dis;
  P();
  P(int t,int d){ to=t; dis=d; }
};
class S{
public:
  char m; // 現在地
  short st; // 馬車券の使用状態
  double time; // 所要時間
  S();
  S( int M,int ST,double t ){ m=M; st=ST; time=t; };
  bool operator<(const S &s) const {
    return time > s.time;
  }
};

int main(){
  int n,m,p,a,b, x,y,z;
  int t[8];
  vector<P> v[30];
  priority_queue<S> que;
  double min[30][1<<8]; // 最小経過時間

  while( cin>>n>>m>>p>>a>>b && (n|m|p|a|b) ){
    --a;--b;
    for( int i=0;i<n;i++ ) cin>>t[i];
    for( int i=0;i<m;i++ )
      v[i].clear();
    for( int i=0;i<p;i++ ){
      cin >> x >> y >> z;
      --x; --y; // 0-indexed
      v[x].push_back( P(y,z) );
      v[y].push_back( P(x,z) );
    }
    for( int i=0;i<m;i++ )
      for( int j=0,k=1<<n;j<k;j++ )
	min[i][j] = DBL_MAX;
    
    while( !que.empty() ) que.pop();

    min[a][0]=0;
    que.push( S(a,0,0.0) );
    double ans = DBL_MAX;
    while( !que.empty() ){
      S s=que.top(); que.pop();
      
      if( s.m==b ){	ans=s.time; break;      }
      if( min[s.m][s.st] < s.time ) continue;

      for( unsigned int i=0;i<v[s.m].size();i++ ){
	P p=v[s.m][i];
	if( p.to==s.m ) continue;
	for( int j=0;j<n;j++ ){
	  int nState = s.st | (1<<j);
	  if( nState==s.st ) continue;
	  double nCost = s.time+(double)p.dis/t[j];
	  if( abs( nCost-min[p.to][nState] ) < EPS )
	    continue;
	  if( nCost < min[p.to][nState] ){
	      que.push( S(p.to,nState,nCost) );
	      min[p.to][nState] = nCost;
	    }
	}
      }
    }
      if( fabs(ans-DBL_MAX)<EPS )
      cout << "Impossible" << endl;
    else
      cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1668
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <ctime>
#include <cstdlib>
#include <bitset>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
ll n , s , Min , tmp;

bool ok(int b){
    ll p = 0;
    for(ll x=n;x;x/=b)
        p += x%b;
    return p == s;
}

void check(ll b){
    ll a = tmp / b , c = s - a;
    if(a >= 0 && a <= b && c >= 0 && c <= b){
        if(Min == -1 || Min > b + 1)
            Min = b + 1;
    }
}

int main(){
    scanf("%lld%lld",&n,&s);
    int up = sqrt(n) + 0.5;
    for(int i=2;i<=up;++i) if(ok(i)){
        printf("%d\n",i);
        return 0;
    }
    if(n < s) return printf("-1\n") , 0;
    tmp = n - s;
    Min = -1;
    for(int i=1;1ll*i*i<=tmp;++i) if(tmp % i == 0){
        check(i);
        check(tmp/i);
    }
    if(Min == -1 && n == s) Min = n + 1;
    if(Min == -1) printf("-1\n");
    else printf("%lld\n",Min);
    return 0;
}


Measured memory_bytes: 256
"""

AtCoder Grand Contest 013 C - Ants on a Circle
https://atcoder.jp/contests/agc013/tasks/agc013_c

おなじみの蟻の問題と同じく、ぶつかる＝すれ違ったと考えることができる。
円形なので、最初に隣り合っている蟻としかぶつからない

また、一周して元の位置に戻ってくるみたいなことも起こりうる
・全員同じ向き
ぶつからないので、移動距離をそのまま計算
・一匹でも向き違いがいる場合
すれ違ったと考えていい。その際二匹の番号が入れ替わるようなイメージ。
　- ある蟻の番号が決まれば他の蟻の番号も初期の位置関係から決められるが？
　- どの蟻の番号が決まればいい？
　- 原点の通行量で考える
　- T秒後に差し引きで右から左に２匹いどうしたら、1,2,3,4,...,Nが、　3,4,5,6,...,N,1,2　になっているということ。
　- なので、T秒後の位置を求めて、原点における左右の通行量分ずらしてあげるとよい

"""



N,L,T = map(int, input().split())

nxtX = [0] * N
cnt_LR = 0

for i in range(N):
    x,w = map(int, input().split())

    if w == 1:
        nxtX[i] = (x + T) % L
        cnt_LR += (x + T) // L

    else:
        """
        -13 % 3 = 3 * (-5) + 2 的な感じで商が負で余りが正
        """
        nxtX[i] = (x - T) % L
        cnt_LR += (x - T) // L

nxtX.sort()
# 全体で一周していると効果0なので、ずれの分を求める。これは正の値にしかならない
# 正なので、右にいくらずれているか
cnt_LR %= N
"""
1,2,3,4,5,6,7,8 -> 7,8,1,2,3,4,5,6 みたいなずれ方を、[1~6] + [7,8]とするみたいな感じ
"""
ans = nxtX[cnt_LR:] + nxtX[:cnt_LR]
for n in ans:
    print(n)

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

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

const long long INF = 1LL << 60;

long long dp[110000]; // greater than n + k

int main(){
  int n; cin >> n;
  int k; cin >> k;
  long long h[110000];
  for(int i = 0; i < n; ++i)cin >> h[i];

  // init
  for(int i = 0; i < 110000; ++i)dp[i] = INF;
  // initial condition
  dp[0] = 0;

  for(int i = 0; i < n; ++i){
    for(int j = 1; j < k + 1; ++j){
      dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
    }
  }

  cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S,T;
    cin >> S >> T;
    int N = S.size(),M = T.size();
    int ans = 1e9;
    for(int i=0;i+M<=N;i++){
        int now = 0;
        for(int j=0;j<M;j++){
            now += S[i+j]!=T[j];
        }
        ans = min(ans,now);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3616
import numpy as np

N,K=map(int,input().split())
h=list(map(int,input().split()))
# N,K=4,150
# h=[150, 140, 100, 200]

harry=np.array(h)
ans=np.count_nonzero(harry>=K)

print(ans)


# import sys
# print(sys.version_info)

Measured memory_bytes: 36384
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n, l[200], s = 0;
    cin >> n;
    for(int i = 0; i < 2 * n; i++){
        cin >> l[i];
    }
    sort(l, l + 2 * n);
    for(int i = 0; i < 2 * n; i += 2){
        s += l[i];
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
    char c;
    cin >> c;
    if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c =='o') {
        cout << "vowel" << endl;
    } else {
        cout << "consonant" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	char a[200001],b[200001];
	scanf("%s %s",&a,&b);
	int i,count=0;
	for(i=0;;i++){
		if(a[i]=='\0') break;
		if(a[i]!=b[i]) count++;
	}
	printf("%d\n",count);
	return 0;
}

Measured memory_bytes: 2120
#include<iostream>
#define 🤔 ;
#define 🎤 << " " <<
using namespace std 🤔
int main() {
  int 丸, 山, 彩 🤔 🤔
  cin >> 丸 >> 山 >>彩 🤔 🤔
  cout <<  彩 🎤 丸 🎤 山  🤔 🤔 🤔 🤔
}

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

namespace CompCsharp
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split('/');
            int year = int.Parse(s[0]);
            int month = int.Parse(s[1]);
            int day = int.Parse(s[2]);

            if (IsHeisei(year, month, day))
            {
                Console.WriteLine("Heisei");
            }
            else
            {
                Console.WriteLine("TBD");
            }
                
        }

        static bool IsHeisei(int year, int month, int day)
        {
            if (year >= 2020)
            {
                return false;
            }

            if (year == 2019 && month >= 5)
            {
                return false;
            }

            return true;

        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define inf (long long)1e9
using namespace std;

long long n, q, x;
vector<long long> a;

long long solve();

int main() {
  cin >> n >> q;
  a.resize(n);
  for(int i = 0; i < n; ++i) cin >> a[i];
  for(int i = 0; i < q; ++i) {
    cin >> x;
    cout << solve() << endl;
  }
  return 0;
}

long long solve() {
  long long ans = 0, l = 0, r = 0, sum = 0;
  for(l = 0; l < n; ++l) {
    while(r < n && sum + a[r] <= x) sum += a[r++];
    ans += r - l;
    sum -= a[l];
  }
  return ans;
}


Measured memory_bytes: 3536
import java.io.*;
import java.util.*;

public class Main{
   	static void main() throws Exception{
   		int n=sc.nextInt();
   		long[]in=new long[n];
   		for(int i=0;i<n;i++) {
   			in[i]=sc.nextLong();
   			if(in[i]==0) {
   				pw.println(0);
   				return;
   			}
   		}
   		long inf=(long)1e18;
   		long ans=1;
   		
   		for(long i:in) {
   			if(inf/i<ans) {
   				pw.println(-1);
   				return;
   			}
   			ans*=i;
   		}
   		
   		pw.println(ans);
	}
	public static void main(String[] args) throws Exception{
		pw=new PrintWriter(System.out);
		sc = new MScanner(System.in);
		int tc=1;
		while(tc-->0)main();
		pw.flush();
	}
	static PrintWriter pw;
	static MScanner  sc;
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] intArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] longArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public int[] intSortedArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public long[] longSortedArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public Integer[] IntegerArr(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] LongArr(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
	static void shuffle(int[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			int tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
	static void shuffle(long[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			long tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
}


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

typedef long long ll;
typedef long double ld;
#define size(a) int((a).size())
#define present(c, x) (c.find(x) != c.end()) 

template <class T>
void printArray(vector<T> arr) {for (T a: arr) cout << a << " ";cout << '\n';}
void printVerdict(bool verdict) {cout << (verdict ? "YES": "NO") << '\n';}
void printDecimal(double d) {printf("%.9f\n", d);}
bool inrange(int val, int start, int end) {return val >=start && val <= end;}

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(0);
	int a,b; cin >> a >> b;
	cout << max(a-2*b, 0) << '\n';
}



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

#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define inter ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
 
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
 
const ll MAX = 1e5+10;

ll dp[10010][100][2],pot[MAX],mod = 1e9+7;
string s;
ll d;

ll DP(ll n,ll r,ll f){
	if(n<0 && r == 0) return 1;
	if(n<0 && r!=0) return 0;
	ll &ans = dp[n][r][f];
	if(ans!=-1) return ans;
	ans = 0;

	f(i,0,10){
		ll x = (r - i%d +d)%d;
		if(f == 1 && s[n]-'0' == i){
			ans += DP(n-1,x,1);
			break;
		}
		ans+=DP(n-1,x,0);
	} 
	return ans%=mod;
}



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

	memset(dp, -1,sizeof dp);

	reverse(all(s));
	cout << (DP(s.size()-1,0,1) +mod-1)%mod << endl;
}


Measured memory_bytes: 20060
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll inf = 1e9 + 7;
const ll Mod = 998244353;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

int main(){
  int A[3];
  cin >> A[0] >> A[1] >> A[2];
  sort(A, A + 3);
  printf("%d %d %d\n", A[0], A[1], A[2]);
  return 0;
}



Measured memory_bytes: 3160
//abc043_a.cpp
//Fri Oct 19 22:30:27 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	int ans = 0;
	for (int i=1;i<=n;i++){
		ans += i;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define title "title"
#define ll long long
#define ull unsigned ll
#define fix(x) fixed<<setprecision(x)
#define pii pair<ll,ll>
#define vint vector<ll>
#define pb push_back
using namespace std;
void Freopen(){
	freopen(title".in","r",stdin);
	freopen(title".out","w",stdout);
}
ll read(){
	ll g=0,f=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch){if(ch=='-')f=-1;ch=getchar();}
	while('0'<=ch&&ch<='9'){g=g*10+ch-'0';ch=getchar();}
	return g*f;
}
const ll N=305;
ll n,a[N],re,all,ans;
signed main(){
//	freopen("a.in","r",stdin);
//	freopen("52.out","w",stdout);
	n=read();
	for(ll i=1;i<=n;i++)a[i]=read();
	for(ll i=3;i<=n;i++)re^=a[i];
	all=a[1]+a[2];all-=re;if(all<0)return puts("-1"),signed();
	for(ll i=42;i>=0;i--){
		if(2*(1ll<<i)<=all){
			if((re>>i&1))return puts("-1"),signed();
			ans+=(1ll<<i);all-=2*(1ll<<i);
		}
	}if(all)return puts("-1"),signed();
	if(ans>a[1])return puts("-1"),signed();
	for(ll i=42;i>=0;i--)if((re>>i&1)&&(ans+(1ll<<i))<=a[1])ans+=(1ll<<i);
	if(ans==0)return puts("-1"),signed();
	return cout<<a[1]-ans,signed();
}

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

int main(void) {
	int A[3],max=INT_MIN,min=INT_MAX;
	
	for (int i = 0; i < 3; i++) {
		cin >> A[i];
		if (max < A[i])max = A[i];
		if (min > A[i])min = A[i];
	}
	
	cout<<max-min;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
char a[30];
char b[30];
int main(){
	scanf("%s",a + 1);
	int i = 1;
	int p = 1;
	while(a[i] != '\0'){
		for(int j = 1 ; j < p ; j++){
			if(a[i] == b[j]){
				printf("no");
				return 0;
			}
		}
		b[p++] = a[i];
		i++;
	}
	printf("yes");
}
 

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef pair<ll, ll> P;
#define ALL(v) v.begin(),v.end()

const int MOD = 1000000007;
const int MAX = 5100000;
ll gcd(ll a, ll b) {
    return (b==0) ? a : gcd(b, a%b);
}

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// 以下から
const int MAX_N = 100000;
struct Edge {
    int to;
    int id;
};

const int D = 80 * 160 + 10;
const int D2 = D*2;
typedef bitset<D2> bs;
int a[100][100];
bs dp[90][90];



const int N = 20;
int h;
int w;
vector<vector<char>> maze(N, vector<char>(N,'#'));

const int MAX_WH = 21;
int d[MAX_WH][MAX_WH];
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
const int INF = 1001001001;
int bfs(int x, int y) {
    queue<P> que;
    rep(i,MAX_WH) {
        rep(j,MAX_WH) {
            d[j][i] = INF;
        }
    }
    que.push(P(x,y));
    d[x][y] = 0;

    while (que.size()) {
        P p = que.front(); que.pop();
        for (int i=0; i< 4; i++) {
            int nx = p.first + dx[i];
            int ny = p.second + dy[i];
            if (0 <= nx && nx < w && 0 <= ny && ny < h && maze[nx][ny] != '#' && d[nx][ny] == INF) {
                que.push(P(nx,ny));
                d[nx][ny] = d[p.first][p.second] + 1;
            }
        }
    }
    int mx = 0;
    rep(i,h) rep(j,w) {
            if (d[j][i] == INF) continue;
            mx = max(mx, d[j][i]);
        }
    return mx;
}

bool pairCompare(const P& firstElof, const P& secondElof)
{
    return firstElof.first < secondElof.first;
}
void dfs(){

}
const int MX = 100000;
vector<int> G[MX];

int main(){
    int n; cin >> n;
    vector<int> v(n,0);
    rep(i,n) {
        cin >> v[i];
    }
    string ans = "APPROVED";
    rep(i,n) {
        if (v[i]%2==0) {
            if (v[i]%3!=0 & v[i]%5!=0) {
                ans = "DENIED";
            }
        }
    }

    cout << ans << endl;

}



Measured memory_bytes: 4352
import java.util.HashSet

fun main(args: Array<String>) {
    val sc = java.util.Scanner(System.`in`)
    val N = sc.next().toInt()
    val s = HashSet<Int>()
    for (i in 0 until N){
        s.add(sc.next().toInt())
    }
    println(s.size)
}

Measured memory_bytes: 31272
// Hina Arare

#include <iostream>

using namespace std;

int main(){
	int N;
	cin >> N;
	bool in_4_type = false;

	for (int i = 0; i < N; ++i){
		char type;
		cin >> type;
		if (type == 'Y')
			in_4_type = true;
	}

	if (in_4_type)
		cout << "Four" << endl;
	else
		cout << "Three" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
ll a,b,x,y,z;
int main()
{
	cin>>a>>b;
	x=a+b;
	y=a-b;
	z=a*b;
	cout<<max(z,max(x,y));
	return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Abhilash Mandaliya
 */
public class Main {
    public static void main (String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader( inputStream );
        PrintWriter out = new PrintWriter( outputStream );
        TaskA solver = new TaskA();
        solver.solve( 1, in, out );
        out.close();
    }

    static class TaskA {
        public void solve (int testNumber, InputReader in, PrintWriter out) {
            out.println( ( in.nextInt() - 1 ) * ( in.nextInt() - 1 ) );
        }

    }

    static class InputReader {
        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar;
        private int snumChars;

        public InputReader (InputStream st) {
            this.stream = st;
        }

        public int read () {
            if ( snumChars == - 1 )
                throw new InputMismatchException();
            if ( curChar >= snumChars ) {
                curChar = 0;
                try {
                    snumChars = stream.read( buf );
                } catch ( IOException e ) {
                    throw new InputMismatchException();
                }
                if ( snumChars <= 0 )
                    return - 1;
            }
            return buf[curChar++];
        }

        public int nextInt () {
            int c = read();
            while ( isSpaceChar( c ) ) {
                c = read();
            }
            int sgn = 1;
            if ( c == '-' ) {
                sgn = - 1;
                c = read();
            }
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while ( ! isSpaceChar( c ) );
            return res * sgn;
        }

        public boolean isSpaceChar (int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == - 1;
        }

    }
}



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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;
const ll MOD = 1e9 + 7;


int main() {
    int n, k; cin >> n >> k;
    V<int> h(n);
    for(int i = 0; i < n; i++) cin >> h[i];

    V<int> dp(n + 1, INT_INF);
    dp[0] = 0;
    for(int i = 1; i < n; i++){
        for(int j = 1; j <= k; j++){
            if(j <= i){
                dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
            }
        }
    }
    cout << dp[n - 1] << endl;


}


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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<char> &s, int a) { return s.find(a) != s.end(); }


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;
const int mod = 1000000007;

int main() {
    string s;

    map<char, int> m;
    cin >> s;

    for (char c : s) {
        m[c]++;
    }

    for (auto e : m) {
        int i = e.second;
        if (i % 2 != 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;


}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

typedef pair<int, int> pii;

int n, a, b, x, y;
pair<pii, int> ps[100000];

int s;
vector<int> es[100000];
int deg[100000];
int imos[100001];

void conn(int u, int v) {
	es[u].push_back(v);
	es[v].push_back(u);
}

void solve() {
	CLEAR(imos);
	sort(ps, ps + n);
	REP(i, n) {
		int x = ps[i].first.first, y = ps[i].first.second, v = ps[i].second;
		pair<pii, int> pl = MP(MP(x + s, y - s + 1), 0), pu = MP(MP(x + s, y + s), n);
		int l = lower_bound(ps, ps + n, pl) - ps;
		int u = upper_bound(ps, ps + n, pu) - ps;
		if (u > l) {
			conn(v, ps[l].second);
			deg[v] += u - l;
			++deg[ps[l].second];
			++imos[l]; --imos[u - 1];
		}
	}
	REP(i, n) {
		if (imos[i] > 0) {
			deg[ps[i + 1].second] += imos[i];
			conn(ps[i].second, ps[i + 1].second);
		}
		imos[i + 1] += imos[i];
	}
}

bool used[100000];

int main(int argc, char **argv) {
	cin >> n >> a >> b;
	--a; --b;
	REP(i, n) {
		cin >> x >> y;
		ps[i].first = MP(x + y, x - y);
		ps[i].second = i;
		deg[i] = 0;
	}
	s = max(abs(ps[a].first.first - ps[b].first.first), abs(ps[a].first.second - ps[b].first.second));

	solve();
	REP(i, n) ps[i].first = MP(ps[i].first.second, -ps[i].first.first);
	solve();

	ll res = 0;
	queue<int> q;
	q.push(a);
	q.push(b);
	CLEAR(used);
	while (!q.empty()) {
		int v = q.front(); q.pop();
		if (used[v]) continue;
		used[v] = true;
		res += deg[v];
		REP(i, es[v].size()) q.push(es[v][i]);
	}

	cout << (res / 2) << endl;

	return 0;
}


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

int a[300001];
bool solve1(int n){
	int p = 0;
	for(int i = 0;i < n;i++){
		if(i > p)return 0;
		p = max(p, i+(a[i]/10));
	}
	return p >= n-1;
}

bool solve2(int n){
	int p = n-1;
	for(int i = n-1;i >= 0;i--){
		if(i < p)return 0;
		p = min(p, i-(a[i]/10));
	}
	return p <= 0;
}

int main(){
	int n;
	scanf("%d", &n);
	for(int i = 0;i < n;i++)scanf("%d", &a[i]);
	bool x = solve1(n);
	bool y = solve2(n);
	if(x && y)printf("yes\n");
	else printf("no\n");
	return 0;
}


Measured memory_bytes: 4320
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define repb(i, n) for(int i = n;i >= 0;i--)
#define reps(i, m, n) for(int i = m;i < n;i++)
#define repsb(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long ll;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
using namespace std;
int n,p,i=0,temp,pos;
bool flg=true;
int pre[50]={};

void cal(void){
  while(true){
    if(temp){
      pre[pos]++;
      temp--;
      if(pre[pos]==p){
        cout<<pos<<endl;
        return;
      }
    }
    else{
      temp=pre[pos];
      pre[pos]=0;
    }
    pos++;
    if(pos==n) pos=0;
  }
}
int main(int argc, char const *argv[]) {

 while (true) {
   cin>>n>>p;
   if(n==0&&p==0) break;
   rep(i,n) pre[i]=0;
   temp=p;
   pos=0;
   cal();
 }
 return 0;
}



Measured memory_bytes: 2992
use std::io::Read;
use std::cmp::min;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let k: usize = iterator.next().unwrap().parse().unwrap();
    let s: Vec<char> = iterator.next().unwrap().chars().collect();

    let mut score: usize = 0;
    for i in 1..n {
        if s[i - 1] == s[i] {
            score += 1;
        }
    }
    let ans = min(score + 2 * k, n - 1);
    ans.to_string()
}


Measured memory_bytes: 2544
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	Int a, v, b, w, t;
	cin >> a >> v >> b >> w >> t;

	bool ans = true;
	if (a < b) {
		Int na = a + v * t;
		Int nb = b + w * t;
		ans = (na >= nb);
	} else {
		Int na = a - v * t;
		Int nb = b - w * t;
		ans = (na <= nb);
	}
	cout << (ans ? "YES" : "NO") << endl;

	return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define N 300005
#define endl "\n"
#define mod 1000000007
ll n,m; ll dp[N]; 
vector<ll> vc[N];
ll maxval(ll i){
	if(dp[i]!=-1){
		return dp[i];
	}
	ll j,k=0;
	for(j=0;j<vc[i].size();j++){
		k=max(k,maxval(vc[i][j])+1);
	}
	return dp[i]=k;
}
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l;
	cin>>n>>m;
	memset(dp,-1,sizeof(dp));
	for(i=1;i<=m;i++){
		cin>>k>>l;
		vc[k].ps(l);
	}
	
	l=0;
	for(i=1;i<=n;i++){
		l=max(l,maxval(i));
	}
	cout<<l;
	return 0;
}


Measured memory_bytes: 14464
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rrep(i,n,a) for(int i=n;i>=a;i--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
#define lla(s) s.rbegin(),s.rend()
#define pcnt(b) __builtin_popcount(b)
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const ll INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    int a[3]={0,0,0},n=s.length();
    rep(i,0,n){
        a[(int)(s[i]-'a')]++;
    }
    if(n==1){cout<<"YES"<<endl;return 0;}
    rep(i,0,3){
        if(a[i]*2>n){cout<<"NO"<<endl;return 0;}
        else if(a[i]!=n/3&&a[i]!=n/3+1){cout<<"NO"<<endl;return 0;}
    }
    cout<<"YES"<<endl;return 0;
}


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)

using namespace std;

#define I 1
#define O 0

#define MAX 2010


int memo[MAX][MAX][2];
int N,M;
string S,T;

int dfs(int n,int m,int type) {
  if( n == 0 && m == 0 ) {
    if( type == O ) return -2;
    return 1;
  }
  int &ret = memo[n][m][type];
  if( ret != -1 ) return ret;
  if( type == O ) ret = 0;
  else            ret = 1;
  if( n ) {
    int new_type = ( S[N-n] == 'I' ) ? I : O;
    if( type != new_type ) {
      int v = dfs(n-1,m,new_type);
      if( v != -2 ) ret = max(ret,v+1);
    }
  }
  if( m ) {
    int new_type = ( T[M-m] == 'I' ) ? I : O;
    if( type != new_type ) {
      int v = dfs(n,m-1,new_type);
      if( v != -2 ) ret = max(ret,v+1);
    }
  }
  return ret;
}

void compute() {
  memset(memo,-1,sizeof memo);
  int maxi = 0;
  rep(n,N+1) rep(m,M+1) {
    if( n && S[N-n] == 'I' ) {
      maxi = max(maxi,dfs(n-1,m,I));
    }
    if( m && T[M-m] == 'I' ) {
      maxi = max(maxi,dfs(n,m-1,I));
    }
  }
  cout << maxi << endl;
}

int main() {
  cin >> N >> M >> S >> T;
  compute();
  return 0;
}

Measured memory_bytes: 32784