akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 int main()
 {
   int w,h;
   char map[100+5][100+5];
   while(cin>>h>>w&&(w||h))
   {
     bool flag=false;
     int map2[100+5][100+5]={{0}};
     for(int i=0;i<h;i++)
     {
       for(int j=0;j<w;j++)
       {
         cin>>map[i][j];        
       }        
     }               
     int step=0;
     int x=0;
     int y=0;
     while(1)
     {
       if(map2[x][y]==1) 
       {
         flag=true;
         break;                  
       }
       if(map[x][y]=='>') 
       {
         map2[x][y]=1;
         y++;
         step++;
         //cout<<">"<<" ";                      
       }        
       if(map[x][y]=='<')
       {
         map2[x][y]=1;
         y--;
         step++;   
         //cout<<"<"<<" ";                   
       }
       if(map[x][y]=='v')
       {
         map2[x][y]=1;
         x++;
         step++;         
         //cout<<"v"<<" ";             
       }
       if(map[x][y]=='^')
       {
         map2[x][y]=1;
         x--;
         step++;         
         //cout<<"^"<<" ";             
       }
       if(map[x][y]=='.')
       {
         break;                  
       }
       if(flag) break;
     }        
     if(flag) cout<<"LOOP"<<endl;
     else cout<<y<<" "<<x<<endl;
   }
   //while(1);
   return 0;
 }

 
 

Measured memory_bytes: 3120
class BreadthFirstSearch:

    def __init__(self, h, w, maze):
        self.h = h
        self.w = w
        self.maze = maze
        self.visited = [[0] * w for _ in range(h)]
        self.queue = []
        self.dx_dy = [[1, 0], [-1, 0], [0, 1], [0, -1]]
        self.ans = 0

    def search(self):
        for i in range(self.h):
            for j in range(self.w):
                if self.maze[i][j] != ".":
                    continue
                self.queue.append((i, j))
                self.visited[i][j] = 1

                while len(self.queue) > 0:
                    now = self.queue.pop(0)
                    for dx, dy in self.dx_dy:
                        x = now[0] + dx
                        y = now[1] + dy
                        if x < 0 or self.h <= x:
                            continue
                        if y < 0 or self.w <= y:
                            continue
                        if self.maze[x][y] == "#":
                            continue
                        if self.visited[x][y] == 0:
                            self.visited[x][y] = self.visited[now[0]][now[1]] + 1
                            self.queue.append((x, y))
                for l in range(self.h):
                    for m in range(self.w):
                        self.ans = max(self.ans, self.visited[l][m])
                self.queue = []
                self.visited = [[0] * self.w for _ in range(self.h)]


def main():
    h, w = map(int, input().split())
    maze = [list(input()) for _ in range(h)]
    bfs = BreadthFirstSearch(h, w, maze)
    bfs.search()
    print(bfs.ans-1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 44252
#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int N;
  bool four = false;
  cin >> N;
 
  rep(i, N)
  {
    string S;
    cin >> S;
    if (S == "Y")
    {
        four = true;
    }
  }
  if (four)
  {
    cout << "Four" << endl;
  }else
  {
    cout << "Three" << endl;
  }
}

Measured memory_bytes: 3608
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(int (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const double PI = 3.1415926535897932384626433832795;
const int mod = 1000000007;
const int INF = 1001001001;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
ll sum(ll l, ll r) {
  return (l + r) * (r - l + 1) / 2;
}

int main() {
  int n, k;
  cin >> n >> k;
  ll l = 0, r = 0;
  for(int i = 0; i <= n; ++i) {
    l += i;
  }
  r = l;

  mint ans = 0;
  for(int i = n + 1; i >= k; --i) {
    ll l = sum(0, i - 1), r = sum(n - i + 1, n);
    ans += r - l + 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
constexpr int MAX = 1005;
inline void lcs(string X, string Y) {
	vv(int, dp, MAX, MAX, 0);
	int len_X = len(X);
	int len_Y = len(Y);
	rep(i, 0, len_X) {
		rep(j, 0, len_Y) {
			dp[i + 1][j + 1] = (X[i] == Y[j] ? dp[i][j] + 1 : max(dp[i][j + 1], dp[i + 1][j]));
		}
	}
	P(dp[len_X][len_Y]);
}
int main() {
	int n; cin >> n;
	string s1, s2;
	rep(i, 0, n) {
		cin >> s1 >> s2;
		lcs(s1, s2);
	}
	return 0;
}

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

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

    int n,a,b;
    cin >> n >> a >> b;
    
    int ans = b;
    if(a*n < b){
        ans = a*n;
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int i=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int i=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1'000'000'007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

int main(){
    long long N;
    cin >> N;
    vector<long long> A(N+1);
    vector<long long> C(N+1);
    REP(i, N+1) cin >> A[i];

    C[N] = A[N];
    for(int i=N-1; i>=0; i--) C[i] = C[i+1] + A[i];

    if(N==0){
        if(A[0]==1) cout << 1 << endl;
        else cout << -1 << endl;
        return 0;
    }

    vector<long long> B(N+1);
    B[0] = 1;
    long long cur = 1;
    for(long long d=1; d<=N; d++){
        long long sm = 0;
        sm = C[d];
        cur = min(2*(cur-A[d-1]), sm);
        B[d] = cur;
    }
    REP(d, N+1) if(B[d] <= 0){
        cout << -1 << endl;
        return 0;
    }
    for(int d=0; d<N; d++){
        if(B[d+1] > (B[d]-A[d])*2){
            cout << -1 << endl;
            return 0;
        }
    }
    if(B[N]!=A[N]){
        cout << -1 << endl;
        return 0;
    }
    long long ans = 0;
    REP(i, N+1) ans += B[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5632
names = [ "Mon", "Tues", "Wednes", "Thurs", "Fri", "Satur", "Sun" ]
lengths = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

day [m, d] = (names !! ((ndays + offset) `mod` 7)) ++ "day"
  where ndays  = sum (take (m - 1) lengths) + d - 1  -- num of days from Jan/1
        offset = 3  -- the day of 2004/Jan/1

main = do
  s <- getLine
  if s == "0 0"
     then return ()
     else do putStrLn . day . map read . words $ s
             main

Measured memory_bytes: 3972
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
    int n,a,b,ans=0;
    cin>>n>>a>>b;
    for(int i=1;i<=n;i++)
    {
        int x=i;
        int sum=0;
        while(x){
            sum+=x%10;
            x=x/10;
        }
        if(sum>=a&&sum<=b) ans+=i;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.lang.ArrayIndexOutOfBoundsException;
import java.math.BigInteger;

/**
 * @author yoshikyoto
 */
class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(new InputStreamReader(System.in));
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		boolean[] visited = new boolean[60];
		int time = 0;
		
		while(!visited[time % 60]) {
			visited[time % 60] = true;
			int start = time % 60;
			time += a;
			int end = time % 60;
			// System.out.println(start + " " + end);
			int d = (time % 60 - c + 60) % 60;
			if(start < end){
				if(start <= c && c <= end) {
					System.out.println(time - d);
					return;
				}
			}else{
				if(c <= end || start <= c) {
					System.out.println(time - d);
					return;
				}
			}
			time += b;
		}
		System.out.println(-1);
	}
}

Measured memory_bytes: 17364
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 1005

struct LOC{
	LOC(int arg_loc){
		loc = arg_loc;
	}
	bool operator<(const struct LOC &arg) const{ //場所の昇順
		return loc > arg.loc;
	}
	int loc;
};

struct Info{
	Info(int arg_loc){
		loc = arg_loc;
	}
	bool operator<(const struct Info &arg) const{ //場所の降順
		return loc < arg.loc;
	}
	int loc;
};

int N,M;
bool check[NUM];

bool rangeCheck(int pos){

	if(pos >= 1 && pos <= M){
		return true;
	}else{
		return false;
	}
}

int main(){

	scanf("%d %d",&N,&M);

	for(int i = 1; i <= M; i++){
		check[i] = false;
	}

	int tmp,num_filled = 0;
	priority_queue<LOC> to_fill;
	priority_queue<Info> students;

	for(int loop = 0; loop < M; loop++){
		scanf("%d",&tmp);
		check[tmp] = true;
		students.push(Info(tmp));
	}

	for(int pos = 1; pos <= M; pos++){
		if(check[pos]){

			num_filled++;

		}else{

			to_fill.push(LOC(pos));
		}
	}

	int ans = 0;
	int next_fill,pre_student_pos;

	while(num_filled < M){

		next_fill = to_fill.top().loc;
		to_fill.pop();

		pre_student_pos = students.top().loc;
		students.pop();

		num_filled++;
		ans++;

		if(rangeCheck(pre_student_pos)){ //元々生徒がいた場所が、1～Mなら埋める必要が生じる
			num_filled--;
			to_fill.push(pre_student_pos);
		}
	}

	printf("%d\n",ans);

	return 0;
}



Measured memory_bytes: 3240
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

ans = 0
min_diff = 10**5
for i in range(N):
  if abs((T - H[i]*0.006) - A) < min_diff:
    ans = i+1
    min_diff = abs((T - H[i]*0.006) - A)
print(ans)


Measured memory_bytes: 3060
W, H ,N = input().split()
a = []
for i in range(int(N)):
    a.append(list(map(int, input().split())))

W=int(W)
H=int(H)
N=int(N)

wl=[0,W]
hl=[0,H]

for x in a:
	if x[2]==1:
		wl[0]=max(wl[0],x[0])
	elif x[2]==2:
		wl[1]=min(wl[1],x[0])
	elif x[2]==3:
		hl[0]=max(hl[0],x[1])
	elif x[2]==4:
		hl[1]=min(hl[1],x[1])

high=0
width=0
if wl[1]-wl[0]>0:
	width=wl[1]-wl[0]
if hl[1]-hl[0]>0:
	high=hl[1]-hl[0]
print(high*width)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define inf (ll)1e9
#define mod (ll)(1e9+7)
#define d(x) cerr<<#x<<"="<<x<<endl;
#define p(x) cout<<(x)<<endl
#define ps(x) cout<<(x);
#define pfix(d,x) cout << fixed << setprecision(d) << x << endl;
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define minel(v) *min_element(all(v))
#define minind(v) distance((v).begin(), min_element(all(v)))
#define maxel(v) *max_element(all(v))
#define maxind(v) distance((v).begin(), max_element(all(v)))
#define fi first
#define se second
ll a[101][101],b,c,d,n,m,x,y,z,k,h,w,sum,mi,ma,ans,s,t,l,r,res,tmp,itr,p,q;
bool flag;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int dx8[8]={1,1,0,-1,-1,-1,0,1},dy8[8]={0,1,1,1,0,-1,-1,-1};
char cha;
string st;
typedef map<int, int> imap;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<pair<ll,ll> > VP;


int main(){
    cin>>l>>r;
    VL v;
    rep(i,l,r+1){
        v.pb(i%2019);
        if(v.size()>5000)break;
    }
    sort(all(v));
    rep(i,10)d(v[i]);
    mi=inf;
    rep(i,v.size())rep(j,i+1,v.size()){
        mi=min(mi,v[i]*v[j]%2019);
    }
    p(mi);
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>

int main() {
  std::string s; std::cin >> s;
  if (s == "Sunny") std::cout << "Cloudy" << std::endl;
  else if (s == "Cloudy") std::cout << "Rainy" << std::endl;
  else std::cout << "Sunny" << std::endl;
  
  return 0;
}

Measured memory_bytes: 3548
#include<iostream>
#define INF 999999999999
using namespace std;

long long map[210][211];
int n;

int floyd() {
	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			if (map[i][k] == INF){
			    continue;
			}
			for (int j = 0; j < n; j++) {
				if (map[k][j] == INF){
				    continue;
				}
				if (map[i][j] > map[i][k] + map[k][j]) {
					map[i][j] = map[i][k] + map[k][j];
				}
			}
		}
	}
	return 0;
}
int main() {
	int m;
	cin >> n >> m;
	int a, b;
	long long c;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			map[i][j] = INF;
		}
	}
	for (int i = 0; i < n; i++){
	    map[i][i] = 0;
	}
	while (m--) {
		cin >> a >> b >> c;
		if (map[a][b] > c){
		    map[a][b] = c;
		}
	}
	floyd();
	bool flag = false;
	for (int i = 0; i < n; i++){
	    if (map[i][i] < 0){
	        flag = true;
	    }
	}
	if (flag){
	    cout << "NEGATIVE CYCLE" << endl;
	}
	else{
	    for (int i = 0; i < n; i++) {
		    for (int j = 0; j < n; j++) {
			    if (map[i][j] == INF){
			        cout << "INF";
			    }
			    else{
			        cout << map[i][j];
			    }
			    if (j != n - 1){
			        cout << " ";
			    }
		    }
		    cout << endl;
	    }
	}
	return 0;
}



Measured memory_bytes: 3264
# python 3.4.3
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# library
# -------------------------------------------------------------



# -------------------------------------------------------------
# main
# -------------------------------------------------------------
from collections import deque

S = input().rstrip()
d = deque()

for s in S:
    if s == "B":
        if len(d) > 0:
            d.pop()
    else:
        d.append(s)

print("".join(d))

Measured memory_bytes: 3316
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=510;
int a[N],id[N],w[N*N];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
inline bool cmp(const int &x,const int &y) {return a[x]<a[y];}
int main() {
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) a[i]=gi(),id[i]=i;
    sort(id+1,id+1+n,cmp);
    for(int i=1;i<=n;i++) {
	int t=id[i],p=1;w[a[t]]=t;
	for(int j=1;j<t;j++) {
	    while(w[p]) ++p;
	    w[p]=t;
	}
	if(p>a[t]) return puts("No"),0;
    }
    for(int i=1;i<=n;i++) {
	int t=id[i],p=1;
	for(int j=t+1;j<=n;j++) {
	    while(w[p]) ++p;
	    if(p<a[t]) return puts("No"),0;
	    w[p]=t;
	}
    }
    puts("Yes");
    for(int i=1;i<=n*n;i++) printf("%d ",w[i]);
    return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


const int MAX_N = 112345;
int ans[MAX_N];
int N;
string s;

bool solve(int a0, int a1) {
  ans[0] = a0;
  ans[1] = a1;
  for (int i = 2; i < N + 2; i++) {
    ans[i] = ans[i-2] ^ ans[i-1] ^ (s[i-1] == 'x');
  }
  // pv(ans, ans + N + 2);
  if (ans[0] != ans[N]) return false;
  if (ans[1] != ans[N+1]) return false;
  return true;
}

int main2() {
  cin >> N;
  cin >> s;
  s += s[0];
  s += s[1];

  bool yes = false;
  REP(i, 2) REP(j, 2) {
    bool found = solve(i, j);
    if (found) { yes = true; goto END;}
  }
  END:;
  if (yes) {
    REP(i, N) printf("%c", ans[i] ? 'W' : 'S');
    printf("\n");
  } else {
    cout << -1 << endl;
  }
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
const int M=1e5+5;
long long  a[M];
int main()
{
	int n;
	cin >>n;
	for(int i=0;i<n;i++){
		cin >>a[i];
	} 
	int max=0,cnt=0;
	for(int i=0;i<n-1;i++){
		if(a[i] >= a[i+1]){
			cnt++;
			if(max < cnt) max=cnt;
		}
		else {
			cnt=0;
		}		
	}
	cout <<max<<endl;
}


Measured memory_bytes: 1024
// Aizu Vol-10 1007: JPEG Compression
// 2017.8.18 bal4u@uu

#include <stdio.h>

int a[12][12];

int main()
{
	int n, cno;
	int r, c, k, m, f;

	for (cno = 1; ; cno++) {
		scanf("%d", &n); if (!n) break;
		m = k = f = 1;
		do {
			if (f) for (r = k - 1, c = 0; r >= 0; r--, c++) a[r][c] = m++;
			else   for (r = 0, c = k - 1; c >= 0; r++, c--) a[r][c] = m++;
			f = !f;
		} while (++k <= n);
		k = n - 1;
		do {
			if (f) for (r = n - 1, c = n - k; c < n; r--, c++) a[r][c] = m++;
			else   for (r = n - k, c = n - 1; r < n; r++, c--) a[r][c] = m++;
			f = !f;
		} while (--k >= 1);
		printf("Case %d:\n", cno);
		for (r = 0; r < n; r++) {
			for (c = 0; c < n; c++) printf("%3d", a[r][c]);
			putchar('\n');
		}
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define ALL(a) (a).begin(),(a).end()
#define CHMIN(a, b) a = min((a),(b))
#define CHMAX(a, b) a = max((a),(b))
#define ZP(a, len) cout << setfill('0') << setw(len) << right << a << endl;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};

int N, M;

signed main() {
    cin >> N >> M;
    pair<int, int> P[M];
    rep(i, M) cin >> P[i].second >> P[i].first;
    sort(P, P + M);

    int ans = 0, tail = 0;
    rep(i, M) {
        if (tail <= P[i].second) {
            ans += 1;
            tail = P[i].first;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MAX = 1e5+5;
vector<LL> GRAPH[MAX];
bool vis[MAX];
stack<LL> s;
LL dist[MAX];

void DFS(LL x)
{
        vis[x] = true;
        for(int i = 0 ; i < GRAPH[x].size() ; i++)
        {
                if(!vis[GRAPH[x][i]])
                {
                        DFS(GRAPH[x][i]);
                }
        }
        s.push(x);
}


int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        LL n,m;
        cin >> n >> m;
        memset(dist , 0 , sizeof(dist));
        memset(vis,false,sizeof(vis));
        while(m--)
        {
                LL x,y;
                cin >> x >> y;
                GRAPH[x].push_back(y);
        }
        for(int i = 1 ; i <= n ; i++)
        {
                if(!vis[i])
                {
                        DFS(i);
                }
        }
        while(!s.empty())
        {
                LL x = s.top();
                for(int i = 0 ; i <GRAPH[x].size() ; i++)
                {
                        dist[GRAPH[x][i]] = max(dist[GRAPH[x][i]] , dist[x] + 1);
                }
                s.pop();
        }
        LL ans = -1;
        for(int i = 1 ; i <= n ; i++)
        {
                ans = max(ans , dist[i]);
        }
        cout << ans << endl;
        return 0;
}

Measured memory_bytes: 9472
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

inline bool canMakeTree(vi d){
  int max_d = 0;
  rep(i,d.sz){
    if(d[i]) max_d = i;
  }

  for(int i=0;i<(max_d+1)/2;i++){
    if(d[i]) return false;
  }

  if(d[(max_d+1)/2] != (max_d%2 ? 2 : 1)) return false;

  for(int i=(max_d+1)/2+1;i<=max_d;i++){
    if(d[i]<2) return false;
  }

  if(d[1] > 2) return false;

  return true;
}

int main(){
  int n;
  cin >> n;
  vi d(n,0);

  rep(i,n){
    int a;
    cin >> a;
    d[a]++;
  }

  cout << (canMakeTree(d) ? "Possible" : "Impossible") << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		String str=sc.nextLine();
		char[] cArr=str.toCharArray();
		int count=0;
		long res=0;
		for(int i=cArr.length-1;i>=0;i--){
			if(cArr[i]=='B'){
				res+=count;
			}
			else{
				count++;
			}
		}
		System.out.println(res);
	}

}


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

#define F first
#define S second
#define pb(x) push_back(x)
#define forr(i, a, b) for(int i = a;i <= b;i++)
#define sz(s) int(s.size())
#define ioi ios_base::sync_with_stdio(false)
#define all(x) x.begin(), x.end()
#define tie cin.tie(nullptr);cout.tie(nullptr);
//#define int long long

using namespace std;

int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

main(){ioi;tie;
	int n;
	cin >> n;
	cout << a[--n];
/*
	int a, b;
	cin >> a >> b;
	cout << ;
	/*
	cout <<  ((n + 1) >> 1) ; 
	*/
}

//Coded by LoliThief or ProRedWood or Lolivillian;



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

int main() {
    int n,a,min=100;
    cin >> n;
    for(int i = 0;i < n;i ++){
        int b = 0;
        cin >> a;
        for(;;){
            if(a%2 == 0){
                a /= 2;
                b ++;
            }else{
            break;
            }
        }
        if(b < min){
            min = b;
        }

    }
    cout << min << endl;
}



Measured memory_bytes: 256
/*
lakshaygpt28
Lakshay Gupta
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
using vll = vector < ll >;

template < typename T > using OrderedSet = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;


#ifndef ONLINE_JUDGE
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
    cerr << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define debug(...)
#endif

#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

const db PI = acos(-1);
const ll LINF = LLONG_MAX;
const int INF = INT_MAX, MOD = 1e9 + 7, N = 1e5 + 10;

ll a[N];

int main() {
    fast_io();
    ll n;
    cin >> n;
    for (ll i = 1; i <= n; i++) {
        cin >> a[i];
    }
    ll ans = 0;
    sort(a + 1, a + n + 1);
    cout << a[n / 2 + 1] - a[n / 2] << "\n";
    return 0;
}


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

const int N = (int) 2e6 + 10 ;
const int inf = (int) 2e9 ;

int tower[N] ;

int main(){
//    freopen("in.txt" , "r" , stdin ) ;
    int sum = 0 ;
    for( int i = 1 ; i <= 999 ; i++ ) {
        sum += i ;
        tower[i] = sum ;
    }
    int a , b ; scanf("%d %d" , &a , &b ) ;
    for( int i = 2 ; i <= 999 ; i++ ) {
        if( tower[i - 1] - a == tower[i] - b ) {
            printf("%d\n" , tower[i - 1] - a ) ;
            return 0 ;
        }
    }
    return 0 ;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
	int n, m;
	cin >> n >> m;
	vector<string> v(n), u(m);
	rep(i,n) cin >> v[i];
	rep(i,m) cin >> u[i];
	for (int i = 0; i < n - m + 1; i++) {
		for (int j = 0; j < n - m + 1; j++) {
			bool b = true;
			for (int k = 0; k < m; k++) {
				for (int l = 0; l < m; l++) {
					if (v[i + k][j + l] == u[k][l]) continue;
					b = false;
				}
			}
			if (b) {
				cout << "Yes" << endl;
				return;
			}
		}
	}
	cout << "No" << endl;
}

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

Measured memory_bytes: 3588
use std::io::stdin;
use std::str::FromStr;
#[allow(dead_code, unused_mut)]
fn read<T: FromStr>() -> T {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().parse().ok().expect("1")
}
#[allow(dead_code, unused_mut)]
fn read_vec<T: FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().expect("2"))
        .collect()
}
#[allow(dead_code, unused_mut)]
fn read_two<T: FromStr>() -> (T, T) {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let mut x = s.split_whitespace().map(|x| x.parse().ok().unwrap());
    (x.next().unwrap(), x.next().unwrap())
}
#[allow(dead_code, unused_mut)]
fn read_three<T: FromStr>() -> (T, T, T) {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let mut x = s.split_whitespace().map(|x| x.parse().ok().unwrap());
    (x.next().unwrap(), x.next().unwrap(), x.next().unwrap())
}
#[allow(dead_code)]
fn remove_whitespace(s: &str) -> String {
    s.chars().filter(|c| !c.is_whitespace()).collect()
}
fn main() {
    let n: i32 = read();
    if n == 1 {
        println!("1");
    } else if n <= 3 {
        println!("2");
    } else if n <= 7 {
        println!("4");
    } else if n <= 15 {
        println!("8");
    } else if n <= 31 {
        println!("16");
    } else if n <= 63 {
        println!("32");
    } else if n <= 100 {
        println!("64");
    }
}

Measured memory_bytes: 4352
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	alist := make([]int, n)
	blist := make([]int, n)
	clist := make([]int, n)
	bsum := 0
	for i := 0; i < n; i++ {
		alist[i] = nextInt()
	}
	for i := 0; i < n; i++ {
		blist[i] = nextInt()
		bsum += blist[i]
	}
	for i := 0; i < n-1; i++ {
		clist[i] = nextInt()
	}
	for i := 1; i < n; i++ {
		if alist[i]-alist[i-1] == 1 {
			bsum += clist[alist[i-1]-1]
		}
	}

	fmt.Println(bsum)
}

// ---- readfunc
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1776
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int h,w,k,ans=0;
  cin>>h>>w>>k;
  int c[h][w];
  for(int i=0;i<h;i++){
  	for(int j=0;j<w;j++){
    	char s;
        cin>>s;
        if(s=='.')c[i][j]=0;
        else c[i][j]=1;
    }
  }
  for(int i=0;i<(1<<h);i++){
  	for(int j=0;j<(1<<w);j++){
    	int cnt=0;
      for (int p=0;p<h;p++){
        for(int q=0;q<w;q++){
            if (i&(1<<p)){
            	if(j&(1<<q)){
                	if(c[p][q]==1) cnt++;
                }
            }
        }
      }
      if(cnt==k) ans++;
    }
  }
  cout<<ans;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define degreeToRadian(deg) (((deg)/360)*2*M_PI)
#define radianTodegree(rad) (((rad)/2/M_PI)*360)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const int MOD = 1e9 + 7;

//cin.tie(0);ios::sync_with_stdio(false);
//cout << fixed << setprecision(15) << y << endl;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  ll sum = 0;
  rep (i, n) cin >> a[i];
  for (int i = 1; i < n; i++) {
    if (a[i - 1] > a[i]) {
      sum += a[i - 1] - a[i];
      a[i] = a[i - 1];
    }
  }

  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 4036
n = gets.chomp.to_i
a = gets.split.map(&:to_i)
hash = {}
a.each do |i|
  if hash.has_key?(i)
    hash[i] += 1
  else
    hash[i] = 0
  end
end

array = []
hash.each do |ngo|
  if ngo[1] >= 3
    array.push(ngo[0]) 
    array.push(ngo[0])
  elsif ngo[1] > 0   
    array.push(ngo[0])
  end
end
array.sort!{|a,b|b<=>a}
puts array.size > 1 ? array[0] * array[1] : 0


Measured memory_bytes: 17540
n = int(input())
S = [input() for i in range(n)]

alpha = "abcdefghijklmnopqrstuvwxyz"

count = [50]*26
for i, x in enumerate(alpha):
    for s in S:
        count[i] = min(count[i], s.count(x))
ans = []
for i, x in zip(count, alpha):
    ans.append(x*i)
print("".join(ans))


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <map>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <queue>
using namespace std;

#define MAXV 1000000000
#define MOD 1000000007
using ll = long long;

bool operator<(const pair<int, int>& a, const pair<int, int>& b) {
	if (a.first == b.first) {
		return a.second < b.second;
	}
	return a.first < b.first;
}

int main() {

	int  y, m, d;
	while (cin >> y >> m >> d) {
		if (y < 1868) {
			cout << "pre-meiji" << endl;
		}
		else if (y == 1868 && m < 9) {
			cout << "pre-meiji" << endl;
		}
		else if (y == 1868 && m == 9 && d < 8) {
			cout << "pre-meiji" << endl;
		}
		else {
			int t = y * 10000 + m * 100 + d;
			if (t <= 1912 * 10000 + 7 * 100 + 29) {
				cout << "meiji" << " " << y - 1868 + 1 << " " << m << " " << d << endl;
			}
			else if(t <= 1926*10000 + 12*100 + 24){
				cout << "taisho" << " " << y - 1912 + 1 << " " << m << " " << d << endl;
			}
			else if (t <= 1989 * 10000 + 1 * 100 + 7) {
				cout << "showa" << " " << y - 1926 + 1 << " " << m << " " << d << endl;
			}
			else {
				cout << "heisei" << " " << y - 1989 + 1 << " " << m << " " << d << endl;
			}
		}
	}
}


Measured memory_bytes: 3004
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 文字列の入力
		String[] yoho = sc.next().split("");
        String[] actual = sc.next().split("");
        int ans = 0;
        for(int i = 0; i < yoho.length; i++) {
          if (yoho[i].equals(actual[i])) {
            ans++;
          }
        }
    
		// 出力
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
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;
}
const int dx[8] = { -1,0,1,-1,1,-1,0,1 };
const int dy[8] = { 1,1,1,0,0,-1,-1,-1 };


//LOVE NyantakoGG	https://www.youtube.com/channel/UC6XdFs8T6Ei54O0FYl3PVVA


using namespace std;



int main() {
	int N, M, X, Y;
	cin >> N >> M >> X >> Y;
	vector<int>x(N), y(M);
	for (int i = 0; i < N; i++) {
		cin >> x[i];
	}
	for (int i = 0; i < M; i++) {
		cin >> y[i];
	}
	sort(x.begin(), x.end());
	sort(y.begin(), y.end());
	int xM, ym;
	xM = x[N - 1];
	ym = y[0];
	int ans = 0;
	for (int i = X + 1; i <= Y; i++) {
		if (xM < i && ym >= i) {
			ans++;
		}
	}
	if (ans) {
		cout << "No War" << endl;
		return 0;
	}
	else {
		cout << "War" << endl;
	}
}


Measured memory_bytes: 256
// Program.cpp

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

typedef long long           ll;
typedef pair<int, int>      pii;
typedef vector<int>         vi;

#define fr(i, n)            for(int i=0; i<(n); ++i)
#define frC(i, n)           for(int i=0; (i<(n)) && (c); ++i)
#define frA(i, a, n)        for(int i=a; i<=(n); ++i)
#define frD(i, a, n)        for(int i=a; i>=(n); --i)
#define fill(a)             memset(a, 0, sizeof(a))
#define revsort(a, b)       sort(a, b, greater<int>())
#define dout                if(DEBUGGING) cout
#define dbg                 if(DEBUGGING) 
#define endl                "\n"

int DEBUGGING    =          0;
const int INF    =          1000000000;
const int MOD    =          1000000007;
const double PI  =          3.1415926535897932;
const double EPS =          1e-7;

void solve(int TEST_CASE){
    int n, W;
    cin >> n >> W;
    int w[n];
	long long int v[n];
	for(int i=0;i<n;++i){
		cin >> w[i] >> v[i]; 
	}

	long long int dp[W+1];
	//stores current value at weight w
	for(int i=0;i<W+1;++i){
		dp[i] = 0;
	}

	for(int i=0;i<n;++i){
		long long int v2[W+1];
		for(int i=0;i<W+1;++i){
			v2[i] = 0;
		}

		for(int j=0;j<W+1-w[i];++j){
			v2[j+w[i]] = dp[j]+v[i];
		}

		for(int j=0;j<W+1;++j){
			if(v2[j]>dp[j])
				dp[j] = v2[j];
		}
	}
	cout << *max_element(dp,dp+W+1) << endl;    
}

int main(int argc, char* argv[]){
    if(argc==2 && argv[1][1]=='v') DEBUGGING = 1;
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);
    int nTestCases=1;
    //cin >> nTestCases;
    frA(i,1,nTestCases) solve(i);
    return 0;
}

Measured memory_bytes: 5204
/*
   THE DARK NIGHT RISES
I LOVE YOU 72 AND WILL FOREVER DO SO
Patience, Persistence, Perseverance, Passion, Purpose
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
const int N = 1e5 + 20 ;
#define F first
#define S second
# define all(v) v.begin(),v.end()          
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define mk make_pair
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define sz(x)       (int)x.size()
const long long int mod=1e9 + 7;
const long double EPS=1e-12;
#define mem( a, val ) memset(a, val, sizeof( a ) )
#define deci( x ) cout<<fixed<<setprecision( x );
#define bitcount( x ) __builtin_popcountll( x )
 
const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};


 
int solve()
{
	char temp ;
	rep(i,0,3) {
		cin >> temp ;
		if(temp=='7') return cout << "Yes\n",0 ;
	}
	cout << "No\n";
	return 0 ;
	
    
    
}
int main()
{
    fast;
    ll t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
 
    return 0;
}
// Patience, Persistence, Perseverance, Passion, Purpose
// I LOVE YOU 72 AND WILL FOREVER DO SO.

Measured memory_bytes: 3648
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    t=0
    if N%2==0:
        t=1+N
    else:
        t=N
        
    ans=[]
    for i in range(1,N+1):
        for j in range(i+1,N+1):
            if i+j!=t:
                ans.append([i,j])
    print(len(ans))
    for i in range(len(ans)):
        print(' '.join(map(str, ans[i])))
    


main()


Measured memory_bytes: 42096
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define rrep(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = int(s); i < int(n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n,l,t;
    cin >> n >> l >> t;
    vvi v(2);
    vi x(n),w(n);
    rep(i,n) {
        cin >> x[i] >> w[i];
        w[i]--;
        v[w[i]].pb(x[i]);
    }
    sort(all(v[0]));
    sort(all(v[1]));
    vi ans(n);
    rep(i,n) {
        if(w[i] == 0) {
            ll pos = x[i]+t;
            pos %= l;
            ll r = (ll)x[i]+(ll)2*t;
            ll k = r/l;
            r %= l;
            if(v[1].size() == 0) {
                ans[i] = pos;
                continue;
            }
            auto it = lower_bound(all(v[1]),r);
            auto bit = upper_bound(all(v[1]),x[i]);
            ll cnt = (ll)k*v[1].size()+(it-v[1].begin())-(bit-v[1].begin());
            ans[ll(i+cnt)%n] = pos;
        } else {
            ll pos = x[i]-t;
            pos %= l;
            pos += l;
            pos %= l;
            ll r = (ll)x[i]-(ll)2*t;
            ll ol = r;
            r %= l;
            r += l;
            r %= l;
            ll k = (ol-r)/l;
            if(v[0].size() == 0) {
                ans[i] = pos;
                continue;
            }
            auto it = upper_bound(all(v[0]),r);
            auto bit = lower_bound(all(v[0]),x[i]);
            ll cnt = (ll)(-k)*v[0].size()+(bit-v[0].begin())-(it-v[0].begin());
            ans[((ll(i-cnt)%n)+n)%n] = pos;
        }
    }
    rep(i,n) cout << ans[i] << '\n';
}


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

int main()
{
    int n,m,ans;

    cin >> n;
    vector<int> h(n);
    rep(i, n) {
        cin >> h[i];
    }

    ans = 0;
    int i = 0;
    do {
        if (h[i] == 0) {
            ++i;
            continue;
        }

        for (int j = i;j < n;++j) {
            if (h[j] == 0)
                break;
            --h[j];
        }
        ++ans;

    } while (i < n);

    cout << ans << endl;
    return(0);
}


Measured memory_bytes: 3604
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7

d = defaultdict(int)


def prime_factorization(n):  # 素因数分解
    res = []
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            cnt = 0
            while n % i == 0:
                cnt += 1
                n //= i
            res.append((i, cnt))
    if n > 1:
        res.append((n, 1))
    return res


for a in A:
    for i in range(2, int(a ** 0.5) + 1):
        if a % i == 0:
            cnt = 0
            while a % i == 0:
                cnt += 1
                a //= i
            d[i] = max(d[i], cnt)
    if a != 1:
        d[a] = max(d[a], 1)

ans = 0
lcm = 1
for k, v in d.items():
    lcm *= pow(k, v, mod)
    lcm %= mod

for a in A:
    if a == 1:
        ans += lcm
        continue
    l = lcm*pow(a, mod-2, mod)
    ans += l
    ans %= mod

print(ans % mod)


Measured memory_bytes: 4844
# -*- 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():
    S,W=map(int,input().split())
    if S<=W:
        print('unsafe')
    else:
        print('safe')

if __name__ == '__main__':
    main()


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

using namespace std;

const int contest[] = { 111, 222, 333, 444, 555, 666, 777, 888, 999 };

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

    auto it = lower_bound(contest, contest + 9, n);

    cout << contest[it - contest] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <cstring>
#define pb push_back

using namespace std;

/** End of definitions and includes **/
/** Here go the code! **/

const int maxn = 1e5 + 3;

int n,par[maxn],depth[maxn],sum[maxn];
vector<int> g[maxn];

void dfs(int u)
{ 
	sum[u] = 1;
	for (size_t i = 0;i < g[u].size(); i++)
	{
		int v = g[u][i];
		if (v != par[u]) 
		{
			par[v] = u;
			depth[v] = depth[u] + 1;
			dfs(v);
			sum[u] += sum[v];
		}
	}
}

int main()
{
	scanf("%d",&n);
	for (int i = 0;i < n-1;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	par[1] = -1;
	depth[1] = 0;
	dfs(1);
	int snuke = n;
	for (int i =0;i< (depth[n]-1) / 2;i++) snuke = par[snuke];
	snuke = sum[snuke];
	int fennec = n - snuke;
	if (snuke >= fennec) printf("Snuke");
	else printf("Fennec");
	printf("\n");
	return 0;
}

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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define IPT(t, x) t ipt; cin >> ipt; x.push_back(ipt);
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;
string s;

int main() {
    cin >> x;
    double now = 100.0;
    cnt = 0;
    while (now < (double)x) {
        cnt++;
        now *= 1.01;
        now = floor(now);
    }

    MSG(cnt)
}


Measured memory_bytes: 3632
fn main() {
    let s: Vec<char> = {
        let s = read::<String>();
        s.chars().into_iter().collect()
    };

    if s[0] == s[1] || s[1] == s[2] || s[2] == s[3] {
        println!("Bad");
    } else {
        println!("Good");
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://arc087.contest.atcoder.jp/tasks/arc087_b>
問題文============================================================
 二次元平面の原点にロボットが置かれています。 最初、ロボットは x 軸の正の向きを向いています。
 
 このロボットに命令列 s が与えられます。 s は次の 2 文字のみからなり、先頭から末尾まで順に実行されます。
 
 F : 今向いている向きに長さ 1 だけ移動する。
 T : 時計回りまたは反時計回りの好きな方向に 90 度だけ向きを変える。
 ロボットの目標は、命令列をすべて実行し終わった後に座標 (x,y) にいることです。
 この目標が達成可能か判定してください。
 
=================================================================

解説=============================================================

================================================================
*/

const int Base = 10000;
bool dpx[4050][2*Base];
bool dpy[4050][2*Base];

void solve(){
    string s; cin >> s;
    int x,y; cin >> x >> y;
    vector<int> xs,ys;
    
    bool dir = true;
    int cnt = 0;
    for(int i = 0; i < s.length();i++){
        if(s[i] == 'T'){
            if(dir){
                xs.push_back(cnt);
            }else{
                ys.push_back(cnt);
            }
            cnt = 0;
            dir = !dir;
        }else{
            cnt++;
        }
    }
    if(dir){
        xs.push_back(cnt);
    }else{
        ys.push_back(cnt);
    }
    
    dpx[1][xs[0] + Base] = true;
    for(int i = 1; i < (int)xs.size();i++){
        for(int j = 0; j < 2*Base;j++){
            if(!dpx[i][j]) continue;
            dpx[i+1][j+xs[i]] = dpx[i+1][j-xs[i]] = true;
        }
    }
    
    dpy[0][Base] = true;
    for(int i = 0; i < (int)ys.size();i++){
        for(int j = 0; j < 2*Base;j++){
            if(!dpy[i][j]) continue;
            dpy[i+1][j+ys[i]] = dpy[i+1][j-ys[i]] = true;
        }
    }
    if(dpx[xs.size()][Base + x] && dpy[ys.size()][Base + y]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    solve();
	return 0;
}


Measured memory_bytes: 156416