akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws java.io.IOException {
		Scanner sc = new Scanner(System.in);

		while (true) {
			boolean map[][] = new boolean[21][21];
			int n = sc.nextInt();
			if (n == 0)
				break;
			for (int i = 0; i < n; i++) {
				map[sc.nextInt()][sc.nextInt()] = true;
			}
			int m = sc.nextInt();
			int x = 10;
			int y = 10;
			int ans = 0;
			if(map[x][y])ans++;
			for (int i = 0; i < m; i++) {
				char d = sc.next().charAt(0);
				int mov = sc.nextInt();
				switch (d) {
				case 'N':
					for (int j = 0; j < mov; j++) {
						y++;
						if (map[x][y]) {
							ans++;
							map[x][y] = false;
						}

					}
					break;
				case 'W':
					for (int j = 0; j < mov; j++) {
						x--;
						if (map[x][y]) {
							ans++;
							map[x][y] = false;
						}

					}
					break;
				case 'E':
					for (int j = 0; j < mov; j++) {
						x++;
						if (map[x][y]) {
							ans++;
							map[x][y] = false;
						}

					}
					break;
				case 'S':
					for (int j = 0; j < mov; j++) {
						y--;
						if (map[x][y]) {
							ans++;
							map[x][y] = false;
						}

					}
					break;
				}
			}
			if (ans == n)
				System.out.println("Yes");
			else
				System.out.println("No");

		}
	}
}

Measured memory_bytes: 13000
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

D = I()
c = [0] + LI()
s = [0] + [[0] + LI() for _ in range(D)]

last = [[0]*27 for _ in range(D+1)]
t = [0]

for i in range(1,D+1):
    r = 0
    manzoku = 0
    for j in range(1,27):
        m = s[i][j]
        for k in range(1,27):
            if k != j:
                m -= c[k]*(i-last[i-1][k])
            else:
                continue
        if j == 1:
            r = 1
            manzoku = m
        else:
            if manzoku < m:
                manzoku = m
                r = j
    t.append(r)
    for j in range(1,27):
        if j == r:
            last[i][j] = i
        else:
            last[i][j] = last[i-1][j]


dq = []
for i in range(1,D+1,7):
    for j in range(1,27):
        dq.append([i,j])

from copy import deepcopy

for d,q in dq:
    t0 = t[d]
    last2 = deepcopy(last)
    manzoku = s[d][q] - s[d][t0]
    for j in range(d,D+1):
        if j == d:
            last2[d][t0] = last2[d-1][t0]
            manzoku -= c[t0] * (d - last2[d][t0])
            last2[d][q] = d
            manzoku += c[q] * (d - last2[d-1][q])
        else:
            if last2[j][t0] == d:
                last2[j][t0] = last2[d-1][t0]
                manzoku -= c[t0] * (d - last2[d][t0])
            if last2[j][q] == last2[d-1][q]:
                last2[j][q] = d
                manzoku += c[q] * (d - last2[d-1][q])
    if manzoku > 0:
        t[d] = q
        last = last2

del t[0]

print(*t,sep='\n')

Measured memory_bytes: 155212
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long int int64;

const int MOD = (int) 1e9 + 7;

int mul(int a, int b)
{
    return (a * 1LL * b) % MOD;
}

void ssub(int &a, int b)
{
    a -= b;
    if (a < 0) a += MOD;
}

const int N = (int) 1e5 + 100;
const int ALP = 26;
char str[N];
int cnt[ALP];


int main(int,  char **)
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

    int n;
    scanf("%d", &n);
    scanf("%s", str);
    for (int i = 0; i < n; i++)
        cnt[str[i] - 'a']++;

    int ans = 1;
    for (int i = 0; i < ALP; i++)
        ans = mul(ans, (cnt[i] + 1));

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


	return 0;
}




Measured memory_bytes: 384
#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const long long INF = 1LL << 60;
using pll = pair<long long, long long>;

int main() {
  // 標準入力が早くなる。Cスタイルの入出力とC++スタイルの入出力を混合させてはならない。
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  map<long long, long long> sum;
  map<long long, long long> dif;

  for (int i = 1; i <= N; i++) {
    int tmp;
    cin >> tmp;
    ++sum[i + tmp];
    ++dif[i - tmp];
  }
  long long res = 0;

  for (int i = 0; i < N; i++) {
    res += sum[i] * dif[i];
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 46504
#include <stdio.h>

#define min(x, y) ((x) < (y) ? (x) : (y))

int main(void)
{
    int cost[100][100];
    int time[100][100];
    int n, m;
    int k;
    
    while (1){
        for (int i = 0; i < 100; i++){
            for (int j = 0; j < 100; j++){
                cost[i][j] = time[i][j] = 100000000;
            }
        }
        
        scanf("%d %d", &n, &m);
        
        if (n == 0){
            break;
        }
        
        for (int i = 0; i < n; i++){
            int a, b, c, t;
            
            scanf("%d%d%d%d", &a, &b, &c, &t);
            a--;
            b--;
            cost[a][b] = cost[b][a] = min(cost[a][b], c);
            time[a][b] = time[b][a] = min(time[a][b], t);
        }
        
        for (int k = 0; k < m; k++){
            for (int i = 0; i < m; i++){
                for (int j = 0; j < m; j++){
                    cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
                    time[i][j] = min(time[i][j], time[i][k] + time[k][j]);
                }
            }
        }
        
        
        scanf("%d", &k);
        for (int i = 0; i < k; i++){
            int a, b, r;
            
            
            scanf("%d%d%d", &a, &b, &r);
            
            a--;
            b--;
            
            if (r == 0){
                printf("%d\n", cost[a][b]);
            }
            else {
                printf("%d\n", time[a][b]);
            }
        }
    }
    
    return (0);
}

Measured memory_bytes: 844
// atcoder/abc168/B/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  int k;
  str s;
  while (cin >> k >> s) {
    if (s.size() <= k) cout << s << endl;
    else {
      for (int i = 0; i < k; ++i) {
        cout << s[i] ;
      }
      cout << "..." << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <float.h>
#include <stdlib.h>
#include <functional>
#include <limits>
#include <numeric>
#include <type_traits>
#include <queue>
#include <fstream>
#include <bitset>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i <= (int)(n); i++)
#define sort1(v) sort(v.begin(),v.end())
#define reverse(v) reverse(v.begin(),v.end())
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> p;
bool paircom (pair<int,int> p,pair<int,int> q){
return p.second<q.second;
}

void count(vector<int> v,vector<int>& ans){
    sort1(v);
    int n=v.size();
  int k=1;
  int i=1;
  bool bl=true;
    while(true){
    while(bl){
        if(v[i-1]==v[i]){
        k++;    
      }else{
          bl=false;
      }
      i++;
      }
      ans.push_back(k);
      if(i>=(n-1))break;
      k=1;
      bl=true;
    }
    }




int main() {
  int l,r,d,n,k;
  cin >> l >> r >> d;
  n=(l-1)/d;
  k=r/d;
  int ans=k-n;
  cout << ans;

}
    

Measured memory_bytes: 3648
#include <iostream>

using namespace std;

int main(){
  int D;
  cin >> D;
  if(D == 25) cout << "Christmas" <<endl;
  else if(D == 24) cout << "Christmas Eve" <<endl;
  else if(D == 23) cout << "Christmas Eve Eve" <<endl;
  else cout << "Christmas Eve Eve Eve" <<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

std::vector<int> prime_fac(int a){
    std::vector<int> primes;
    int max = (int)std::sqrt(a);

    for(int i=1; i<=max; i++){
        if (a%i==0) {
            primes.push_back(i);
            primes.push_back(a/i);
        }
    }
    return primes;
}

int main(){
    int N;
    std::cin >> N;
    int ans = 0;

    std::vector<int> a(N);

    for(int i=0;i<N;i++){
        std::cin >> a[i];
    }

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

    for(auto i=a.begin();i!=a.end();i++){
        std::vector<int> primes;
        primes = prime_fac(*i);
        for(auto j=primes.begin(); j!=primes.end();j++){
            if(std::upper_bound(a.begin(),a.end(),*j)-std::lower_bound(a.begin(),a.end(),*j)>1){
                break;
            }
            if (std::binary_search(a.begin(), a.end(), *j)){
                if (std::lower_bound(a.begin(),a.end(),*j)!=i) {
                    break;
                }
            }
            if (j==primes.end()-1){
                ans+=1;
            }
        }
    }
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 3504
import java.util.*;
import static java.lang.System.*;

public class Main {

	Scanner sc = new Scanner(in);
	
	void run() {
		int n, p, pp;
		int[] num;
		int turn;
		L:while (true) {
			n = sc.nextInt();
			p = sc.nextInt();
			pp = p;
			if (n == 0 && p == 0) break;
			num = new int[n];
			turn = 0;
			while (turn <= 1000000) {
				if (p == 0) {
					p += num[turn%n];
					num[turn%n] = 0;
				} else if (p > 1) {
					p--;
					num[turn%n]++;
				} else {
					p--;
					num[turn%n]++;
					if (num[turn%n] == pp) {
						out.println(turn%n);
						continue L;
					}
				}
				turn++;
			}
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 20232
N = int(input())
seat = []
seats_occ = 0
for i in range(N):
    x = list(map(int,input().split()))
    seat.append(x)
    
for i in range(N):
    seats_occ += (seat[i][1] - seat[i][0]) + 1
    
print(seats_occ)

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

int n, a[100010];

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        int x;
        scanf("%d", &x);
        a[x]++;
    }
    int best = 0;
    for (int i = 0; i <= 100000; i++) {
        int tot = a[i] + a[i + 1] + a[i + 2];
        best = max(best, tot);
    }
    printf("%d\n", best);
    return 0;
}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
	int n,k;
	cin >> n >> k;
	vector<set<int>> nodes(n+1);
	int m = 0;
	for (int i = 0; i < 8; i++) {
		for (int j = 2+i; j <= n; j++) {
			if ((j & (1<<i)) > 0) {
				nodes[i+1].insert(j);
				m++;
			}
		}
	}
	cout << m << endl;
	for (int i = 1; i <= n; i++) {
		for (auto&& j : nodes[i]) {
			cout << i << " " << j << endl;
		}
	}
	for (int i = 0; i < k; i++) {
		int ans = 0, j = 0;
		string s;
		while(j < 8) {
			cout << j + 1 << endl;
			cin >> s;
			if (s == "Yes") {
				goto end;
			}
			if (s == "Near") {
				ans += (1<<j);
			}
			j++;
		}
		cout << ans << endl;
		cin >> s;
end:
		int tmp;
	}
	return 0;
}



Measured memory_bytes: 3308
#include <stdio.h>

int main(void)
{
	int num[3];
	int counta,countb,countc;

	for(counta=0;counta<3;counta++){
		scanf("%d", &num[counta]);
	}
	
	for(countb=0;countb<2;countb++){
		if(num[countb]>num[countb+1]){
			int tmp = num[countb];
			num[countb] = num[countb+1];
			num[countb+1] = tmp;
		}
	}
	for(countc=0;countc<1;countc++){
		if(num[countc]>num[countc+1]){
			int tmp = num[countc];
			num[countc] = num[countc+1];
			num[countc+1] = tmp;
		}
	}

	printf("%d %d %d\n", num[0], num[1], num[2]);

	return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		int[][] F = new int[N][10];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < 10; j++) {
				F[i][j] = sc.nextInt();
			}
		}
		
		int[][] P = new int[N][11];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < 11; j++) {
				P[i][j] = sc.nextInt();
			}
		}
		
		int max = Integer.MIN_VALUE;
		for (int i = 1; i < (1 << 10); i++) {
			
			int x = 0;
			for (int n = 0; n < N; n++) {
				int count = 0;
				for (int j = 0; j < 10; j++) {
					if (((i>>>j)&1) == 1 && F[n][j] == 1) count++;
				}
				x += P[n][count];
			}
			max = Math.max(max, x);
		}
		
		System.out.println(max);
	}
}

Measured memory_bytes: 27904
#include<iostream>

int main()
{
	int n;
	std::cin >> n;
	int input_numbers[n];
	for(int i=0; i<n; i++) {
		std::cin >> input_numbers[i];
	}
	for(int i=n-1; i>=0; i--) {
		std::cout << input_numbers[i];
		if(i != 0) {
			std::cout << " ";
		} else {
			std::cout << "\n";
		}
	}

	return 0;
}

Measured memory_bytes: 1164
import java.util.Scanner;

/**
 *
 * @author k16075kk
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int W = sc.nextInt();
        int H = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int r = sc.nextInt();
        
        if (0 <= x-r && x+r <= W && 0<= y - r && y+r <= H) {
             System.out.println("Yes");
            
        } else {
            System.out.println("No");
        }
    }
}



Measured memory_bytes: 26244
import sys
sys.setrecursionlimit(10**6)
n=int(input())
edge=[[] for i in range(n)]
for i in range(n-1):
    x,y,z=map(int,input().split())
    edge[x-1].append([y-1,z])
    edge[y-1].append([x-1,z])
q,k=map(int,input().split())
dist=[-1]*n
def dfs(node,d):
    dist[node]=d
    for i in edge[node]:
        if dist[i[0]]==-1:
            dfs(i[0],d+i[1])
dfs(k-1,0)
for i in range(q):
    x,y=map(int,input().split())
    print(dist[x-1]+dist[y-1])

Measured memory_bytes: 139220
// https://atcoder.jp/contests/abc133/tasks/abc133_b
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

void solve() {
    int N, D;
    cin >> N >> D;
    vector<vector<int>> X(N, vector<int>(D));
    REP(i, N) REP(j, D) cin >> X[i][j];
    int ans = 0;
    REP(i, N) {
        FOR(j, i + 1, N) {
            int dist = 0;
            REP(k, D) { dist += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]); }
            double d = sqrt(dist);
            if (ceil(d) == floor(d)) {
                ans++;
            }
        }
    }
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 3672
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
 
using namespace std;
 
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-10;

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

int h, w;
vector<string> s;

int d[100][100];
bool outOfRange(int y, int x){
	if(x < 0 || x >= w || y < 0 || y >= h){
		return true;
	}
	return false;
}

void dfs(int y, int x){
	//cout<<y<<" "<<x<<endl;
	for(int i = 2; i < 4; i++){
		int nx = x + dx[i], ny = y + dy[i];
		if(outOfRange(ny, nx)) continue;
		int c = s[ny][nx]-'0' ;
		if(d[ny][nx] <= d[y][x] + c) continue;
		d[ny][nx] = d[y][x] + c;
		dfs(ny, nx);
	}
}

int main(){
	string t;
	cin>>h>>w;
	rep(i, h){
		cin>>t;
		s.pb(t);
	}
	rep(i, 100){
		rep(j,100){
			d[i][j] = INF;
		}
	}
	d[0][0] = s[0][0]-'0';
	dfs(0, 0);
	// for(int i = 0; i < h; i++){
	// 	for(int j = 0; j < w; j++){
	// 		cout<<" "<<d[i][j];
	// 	}
	// 	cout<<endl;
	// }
	cout<<d[h-1][w-1]<<endl;
}

Measured memory_bytes: 1264
#define NDEBUG

#include <unordered_map>
#include <functional>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <utility>
#include <string>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <tuple>
#include <set>
#include <map>

// [0, max)
#define FOR0(var, max) for (sl (var) = 0; (var) < (max); ++(var))
// [min, max)
#define FORi(var, min, max) for (sl (var) = (min); (var) < (max); ++(var))
// [min, max)
#define FORi_INV(var, min, max) for (sl (var) = (max) - 1; (var) + 1 > (min); --(var))
#define FORITER(var, iter) for (auto (iter) = (var).begin(); (iter) != (var).end(); (iter)++)
#define FORITER_INV(var, iter) for (auto (iter) = (var).rbegin(); (iter) != (var).rend(); (iter)++)

// a < b < c
#define LTLT(a, b, c) (((a) < (b)) && ((b) < (c)))
// a <= b < c
#define LELT(a, b, c) (((a) <= (b)) && ((b) < (c)))
// a < b <= c
#define LTLE(a, b, c) (((a) < (b)) && ((b) <= (c)))
// a <= b <= c
#define LELE(a, b, c) (((a) <= (b)) && ((b) <= (c)))

#ifndef NDEBUG
#  define MASSERT(cond) m_assert(cond, __LINE__, #cond);
#else
#  define MASSERT(...)
#endif

using namespace std;

using uc = unsigned char;
using ui = unsigned int;
using ul = unsigned long long int;

using sc = signed char;
using si = signed int;
using sl = signed long long int;

using ld = long double;

void m_assert(const bool& cond, const sl& line, const char *condstr) {
  if (!cond) {
    cerr << "Assertion Failed: " << condstr << " at line " << line << endl;
    exit(1);
  }
}

const static char table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

static si N;
static string S;

void solve(void) {
  FORITER(S, it) {
    cout << table[(*it - 'A' + N) % 26];
  }
  cout << endl;
}

int main(void) {
  cin >> N;
  cin >> S;
  solve();
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    char S[4];
    gets(S);
    int i,len,k=0,p=0;
    len=strlen(S);
    for(i=0;i<len;i++)
    {
        if(S[i]=='A'||S[i]=='B' || S[i]=='C')
        {
            k++;
        }
        else if(S[i]=='A'||S[i]=='R' || S[i]=='C')
        {
            p++;
        }
    }
    if(k==len) printf("ARC\n");
    else printf("ABC\n");
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

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

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

vector<int64> V, W;
vector<vector<PLL>> q;
vector<int64> res;
int64 N;

void dfs(int64 v, vector<vector<PLL>>& st, int64 d) {
//  cout << v << endl;
  vector<vector<PLL>> tmp(st);
  int fl = d >= 11;
  vector<PLL> nxt(st[fl]);
  for (auto &x : st[fl]) {
    nxt.emplace_back(x.fs + W[v], x.sc + V[v]);
  }
  sort(all(nxt));
  st[fl] = vector<PLL>();
  st[fl].reserve(nxt.size());
  for (auto &&x : nxt) {
//    if (st[fl].size())
//      cout << st[fl].back().fs << " " << st[fl].back().sc << " : " << x.fs << " " << x.sc << endl;
    if (st[fl].empty()) {
      st[fl].push_back(x);
    } else if (st[fl].back().fs == x.fs) {
      st[fl].pop_back();
      st[fl].push_back(x);
    } else if (st[fl].back().sc < x.sc) {
      st[fl].push_back(x);
    }
  }

//  REP(i, 2) {
//    cout << v << " " << i << ": ";
//    for (auto x : st[i]) {
//      cout << "(" << x.fs << " " << x.sc << ") ";
//    }
//    cout << endl;
//  }

  sort(all(q[v]), [](PLL a, PLL b) {
    return a.sc < b.sc;
  });

  int64 l =0, pre = 0;
  for (auto idxL : q[v]) {
    int64 idx, L;
    tie(idx, L) = idxL;
    res[idx] = pre;
    FOR(i, l, st[fl].size()) {
      PLL x = st[fl][i];
      if (x.fs > L) break;
      int64 now = x.sc;
      if (fl) {
        int ind = upper_bound(all(st[0]), PLL(L - x.fs, INF_LL)) - st[0].begin();
        now += st[0][ind-1].sc;
      } else {
        l = i;
      }
      chmax(res[idx], now);
      chmax(pre, now);
    }
  }

  REP(i, 2) {
    if (v*2 + i + 1 < N) dfs(v * 2 + i + 1, st, d+1);
  }
  swap(st, tmp);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	V = vector<int64>(N);
  W = vector<int64>(N);
	REP(i, N) cin >> V[i] >> W[i];
	int64 Q;
	cin >> Q;
	vector<int64> v(Q), L(Q);
	res.resize(Q, 0);
	q = vector<vector<PLL>>(N);
	REP(i, Q) {
	  cin >> v[i] >> L[i];
	  q[v[i]-1].emplace_back(i, L[i]);
	}
	vector<vector<PLL>> st(2, vector<PLL>({PLL(0, 0)}));
  dfs(0, st, 0);
  REP(i, res.size()) {
    cout << res[i] << endl;
  }
}


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

int n;
string s;

int main(){
	cin>>s;
	for(int i = 0;i <= 2;i++){
		if(s[i] == s[i + 1]){
			n++;
		}
	}
	if(n == 0){
		cout<<"Good"<<endl;
	}else{
		cout<<"Bad"<<endl;
	}
}


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

int a, b, n;
struct cross{
	bool works;
	int access;
};
cross map[17][17];//not use a=0 || b=0.

void read()
{
	cin >> n;
	for (int i = 1; i <= a; i++){
		for (int j = 1; j <= b; j++){
			map[i][j].works = false;
			map[i][j].access = 0;
		}
	}
	for (int i = 0; i < n; i++){
		int x, y;
		cin >> x >> y;
		map[x][y].works = true;
	}
	map[1][1].access = 1;
	return;
}

void dpa(int crossa, int crossb){
	if (crossa > a){ return; }
	if (map[crossa + 1][crossb].works){ return; }
	map[crossa + 1][crossb].access += map[crossa][crossb].access;
	return;
}

void dpb(int crossa, int crossb){
	if (crossb > b){ return; }
	if (map[crossa][crossb + 1].works){ return; }
	map[crossa][crossb + 1].access += map[crossa][crossb].access;
	return;
}

void solve(){
	for (int i = 2; i < a + b; i++){
		if (i <= ((a <= b) ? a : b)){
			for (int j = 1; j < i; j++){
				dpa(i - j, j);
				dpb(i - j, j);
			}
		}
		else if (a >= b && i <= a + 1){
			for (int j = 1; j <= b; j++){
				dpa(i - j, j);
				dpb(i - j, j);
			}
		}

		else if (i <= b + 1){
			for (int j = i - a; j <= i; j++){
				dpa(i - j, j);
				dpb(i - j, j);
			}
		}

		else {
			for (int j = i - a; j <= b; j++){
				dpa(i - j, j);
				dpb(i - j, j);
			}
		}
	}
}

int main()
{
	while (1){
		cin >> a >> b;
		if (!a && !b){ break; }
		read();
		solve();
		cout << map[a][b].access << endl;
	}
	return 0;
}

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

int main(){
	int N, x, X=0, A;
	cin >> N;
	cin >> A;
		for (; A % 2 == 0; A = A / 2) {
			X++;
		}
//	cout << "x=" << X << endl;
	N--;
	for(;N>0;N--) {
		x = 0;
		cin >> A;
		for (; A % 2 == 0; A = A / 2) {
			x++;
		}
		//	cout << "x=" << x << endl;
		if (x < X) {
			X = x;
		}
	}
	cout << X << endl;
 }

Measured memory_bytes: 256
N = int(input())
a = [int(input()) for _ in range(N)]

hantei = False
index = 0
cnt = 1
for i in range(N):
    # 今いる場所がボタン2ならば終わり
    if a[index] == 2:
        hantei = True
        break
    index = a[index]-1
    cnt += 1
if hantei:
    print(cnt)
else:
    print(-1)


Measured memory_bytes: 7084
class Union_Find
    def initialize(n); @parent_or_size = Array.new(n, -1); end

    def merge(a, b)
        x = leader(a)
        y = leader(b)

        return x if x == y
        x, y = y, x if @parent_or_size[x] > @parent_or_size[y]
        @parent_or_size[x] += @parent_or_size[y]
        @parent_or_size[y] = x
    end

    def same(a, b); leader(a) == leader(b); end
    def leader(a); @parent_or_size[a] < 0 ? a : (@parent_or_size[a] = leader(@parent_or_size[a])); end
    def size(a); -@parent_or_size[leader(a)]; end

    def groups
        n = @parent_or_size.size
        result = Array.new(n) {[]}

        n.times {|i| result[leader(i)] << i}
        result.compact!
    end
end

n, q = gets.split.map(&:to_i)
uf = Union_Find.new(n)

q.times do
    t, u, v = gets.split.map(&:to_i)
    t == 0 ? uf.merge(u,v) : (puts uf.same(u,v) ? 1 : 0)
end


Measured memory_bytes: 15696
#include<bits/stdc++.h>
using namespace std;
int main() {
	char letter;
	scanf("%c", &letter);
	switch(letter) {
	case 'A':
		cout << "T";
		break;
	case 'T':
		cout << "A";
		break;
	case 'C':
		cout << "G";
		break;
	case 'G':
		cout << "C";
		break;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>

using namespace std;
typedef long long int LL;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)


int xcomp(vector<LL>& a, vector<LL>& b) {
	return a[0] < b[0];
}

#define XSORT(c) sort((c).begin(),(c).end(),xcomp)

#define ALL(x) (x).begin(),(x).end()
LL mod = 1000000007;

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

	int sum = 1;
	int minus = 1;

	REP(i, N) {
		int a;
		cin >> a;
		if (a % 2 == 0) {
			minus *= 2;
		}
		else {

		}
		sum *= 3;
	}

	cout << sum - minus << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b,c,d,n,m,i,j,array[100000+10],p,q,sum=0,cnt1=0,cnt,cnt2=0,cnt3=0,flag=0;
    long long int it,st,ct,qt;
    string str,ptr;
    vector<long long int> veci;
    vector<char>vecc;
    vector<string>vecs;
    queue<long long int>vecq;
    set<long long int>si;
    cin>>n>>m;
    for(i=0; i<m; i++)
    {
        cin>>array[i];
        sum=sum+array[i];
    }
    if(sum>n)
        cout<<-1<<endl;
    else cout<<n-sum<<endl;




    return 0;
}


Measured memory_bytes: 3720
import java.io.*;
import java.nio.CharBuffer;
import java.util.NoSuchElementException;

public class Main {

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        int a = scanner.nextInt();
        int b = scanner.nextInt();
        if (a == b)
            writer.println(0);
        else if ((a + b) % 2 == 0)
            writer.println((a + b) / 2);
        else
            writer.println("IMPOSSIBLE");
        writer.close();
    }

    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }


        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

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

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

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 24916
import sys
from collections import defaultdict


def input():
    return sys.stdin.readline().rstrip()


def main():
    T1, T2 = map(int, input().split())
    A1, A2 = map(int, input().split())
    B1, B2 = map(int, input().split())

    len1 = T1 * A1 + T2 * A2
    len2 = T1 * B1 + T2 * B2
    first1 = T1 * A1
    first2 = T1 * B1
    second1 = T2 * A2
    second2 = T2 * B2

    if len1 == len2:
        print("infinity")
        exit()

    if len1 > len2:
        if first1 < first2:
            a, b = divmod(first2 - first1, len1 - len2)
            if b == 0:
                print(a * 2)
                exit()
            else:
                print(a * 2+1)
                exit()
        else:
            print(0)
            exit()

    if len2 > len1:
        if first2 < first1:
            a, b = divmod(first1 - first2, len2 - len1)
            if b == 0:
                print(a * 2 )
                exit()
            else:
                print(a * 2+1)
                exit()
        else:
            print(0)
            exit()



if __name__ == "__main__":
    main()


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

int main(){
	int n;
  	cin >> n;
  	vector<int> x(n), y(n);
  	rep(i, n) cin >> x[i] >> y[i];
  
  	auto dist = [&](int i, int j){
    	double dx = x[i] - x[j];
      	double dy = y[i] - y[j];
      	return sqrt(dx * dx + dy * dy);
    };
  
	double len = 0;
  	rep(i, n)rep(j, i){
    	len += dist(i, j);
    }
  	int num = 2;
  	for(int i = n-1; i >= 1; i--) num *= i;
  	int fact = 1;
  	for(int i = n; i >= 1; i--) fact *= i;
  	double ans = (len * num) / fact;
  	printf("%.10f\n", ans);
}

Measured memory_bytes: 3804
#include<iostream>
#include<queue>

#define N_MAX 101
#define M_MAX 101
#define INFTY 1<<30

using namespace std;

int cost[N_MAX][M_MAX];
int w[N_MAX][N_MAX];
bool edge[N_MAX][N_MAX];
bool vis[N_MAX][M_MAX];
bool det[N_MAX][M_MAX];
bool rescue[N_MAX];

struct state{
	int pos;
	int st;
	int cost;
	bool operator<(const state &t) const { return cost > t.cost; }
};

int dijkstra(state &s, int hospital, int N, int M){
	int ans = INFTY;
	priority_queue<state> qs;
	
	qs.push( s );
	while( !qs.empty() ){
		state now = qs.top();
		qs.pop();

		cost[ now.pos ][ now.st ] = now.cost;
		vis[ now.pos ][ now.st ] = false;

		if( now.pos == hospital ){
			ans = min( ans, now.cost );
			continue;
		}
		
		for(int i = 0; i < N; ++i){
			if( edge[ now.pos ][ i ] ){
				if( rescue[ now.pos ] ){
					for(int j = 0; j <= M - now.st; ++j){
						state t = now;

						t.pos = i;
						t.st = now.st - w[ now.pos ][ i ] + j;
						//t.cost += w[ now.pos ][ i ] + j;

						if( t.st < 0 )
							continue;
						if( cost[i][t.st] > t.cost + w[ now.pos ][i] + j ){
							cost[i][t.st] = t.cost + w[ now.pos ][i] + j;
							t.cost += w[ now.pos ][ i ] + j;
							qs.push( t );
						}
						/*
						if( !vis[ i ][ t.st ] && t.cost < cost[ i ][ t.st ] ){
							vis[ i ][ t.st ] = true;
							qs.push( t );
						}
						*/
					}
				}else{
					state t = now;
					t.pos = i;
					t.st -= w[ now.pos ][ i ];
					if( t.st < 0 )
						continue;
					if( cost[i][t.st] > t.cost + w[ now.pos ][i] ){
						cost[i][t.st] = t.cost + w[ now.pos ][i];
						t.cost += w[ now.pos ][ i ];
						qs.push( t );
					}
					/*t.cost += w[ now.pos ][ i ];
					
					if( !vis[ i ][ t.st ] && t.cost < cost[ i ][ t.st ] ){
						vis[ i ][ t.st ] = true;
						qs.push( t );
					}*/
				}
			}
		}
	}
	return ans;
}

void ResetGraph(){
	for(int i = 0; i < N_MAX; ++i){
		rescue[ i ] = false;
		for(int j = 0; j < N_MAX; ++j){ edge[i][j] = false; w[i][j] = INFTY; }
		for(int j = 0; j < M_MAX; ++j){ cost[i][j] = INFTY; vis[i][j] = det[i][j] = false; }
	}
}

int main(){
	while(true){
		int ans = 0;
		int N,M,L,K,A,H;
		state s;
		scanf("%d%d%d%d%d%d", &N, &M, &L, &K, &A, &H);
		if( N == 0 && M == 0 && L == 0 && K == 0 && A == 0 && H == 0 )
			break;

		ResetGraph();
		for(int i = 0; i < L; ++i){
			int t; scanf("%d", &t);
			rescue[ t ] = true;
		}
		rescue[ A ] = true;
		rescue[ H ] = true;
		for(int i = 0; i < K; ++i){
			int x, y, t; scanf("%d%d%d", &x, &y, &t);
			w[ x ][ y ] = w[ y ][ x ] = t;
			edge[ x ][ y ] = edge[ y ][ x ] = true;
		}
		s.pos = A;
		s.st = M;
		s.cost = 0;

		ans = dijkstra( s, H, N, M );
		if( ans == INFTY )
			puts("Help!");
		else
			printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;
#define N 26
#define iteration 5000

ll d,ansv,nowv;
vector<ll> c(N),ans,now;
vector<vector<ll> > s;
vector<ll> last(N,0);
ll cost(vector<ll> &tmp){
 ll sum = 0;
 for(ll i=0;i<N;i++) last[i] = 0;
 for(ll i=0;i<d;i++){
  sum += s[i][tmp[i]];
  last[tmp[i]] = i+1;
  for(ll j=0;j<N;j++) sum -= (i+1-last[j])*c[j];
 }
 return sum;
}

/*
ll cost(){
 return cost(now);
}
*/

int main(){
 cin>>d;
 //ll c[N];
 for(ll i=0;i<N;i++)cin>>c[i];
 //ll s[d][N];
 s = vector<vector<ll> > (d,vector<ll>(N));
 for(ll i=0;i<d;i++)for(ll j=0;j<N;j++)cin>>s[i][j];

 srand( time(NULL) );
 ansv=0,nowv=0;
 ans = now = vector<ll>(d,0);

 for(ll i=0;i<N;i++){
  vector<ll> tmp(d);
  for(ll j=0;j<N;j++)tmp[j] = rand()%N;
  
  ll tv = cost(tmp);
  if( tv > nowv ){
   ansv = nowv = tv;
   ans = now = tmp;
  }
 }


 
 ll Iteration = iteration;
 while(Iteration){
  Iteration--;
  if(rand()%100 != 0 ){
   //1-opt
   ll day = rand()%d;
   // vector<ll> tmp = now;
   ll first = now[day];
   ll fv = nowv;
   ll T= 10;
   for(ll t=0;t<T;t++){
    ll i = rand()%N;
    now[day] = i;
    nowv = cost(now);
    if( nowv < fv ){
     if( nowv < ansv ){
      ansv = nowv;
      ans = now;
     }
     first = i;
     fv = nowv;
    }
   }
    nowv = fv;
    now[day] = first;
  
  }else{
   
   ll t = rand()%10;
   for(ll i=0;i<t;i++){
    now[rand()%d] = rand()%N;
   }
   nowv = cost(now);
   if( nowv < ansv ){
    ansv = nowv;
    ans = now;
   }
   
  }
 }



 for(ll i=0;i<d;i++)cout<<ans[i]+1<<endl;


    return 0;
}


Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pr(a) cout<<(a)<<endl
 
int main() {
  int n,m;
  while(cin >> n && n) {
    bool a[21][21];
    memset(a,false,sizeof(a));
    rep(i,n) {
      int x,y;
      cin >> x >> y;
      a[x][y]=true;
    }
    cin >> m;
    int x=10,y=10;
    bool b[21][21];
    memset(b,false,sizeof(b));
    if(a[10][10]) b[10][10]=true;
    rep(i,m) {
      char c;
      int z;
      cin >> c >> z;
      rep(k,z) {
        if(c=='N') y++;
        if(c=='S') y--;
        if(c=='E') x++;
        if(c=='W') x--;
        if(a[x][y]) b[x][y]=true;
      }
    }
    int cnt=0;
    rep(i,21) {
      rep(j,21) cnt+=b[i][j];
    }
    if(cnt==n) pr("Yes");
    else pr("No");
  }
  return 0;
}


Measured memory_bytes: 1152
import math
N = int(input())

results = [0]*N


def calc(x, y, z):
    return x**2 + y**2 + z**2 + x*y + y*z + z*x


for x in range(1, int(math.sqrt(N))):
    for y in range(1, int(math.sqrt(N))):
        for z in range(1, int(math.sqrt(N))):
            result = calc(x, y, z) - 1
            if result >= N:
                continue
            else:
                results[result] += 1

for result in results:
    print(result)


Measured memory_bytes: 9296
import java.io.*;
import java.util.*;
import java.math.*;
import static java.lang.Math.*;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Double.parseDouble;
import static java.lang.String.*;

public class Main {

    static int n,m;
    static List<Integer> [] g;
    static int [] vis;
    
    public static void main(String[] args) throws IOException{
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder out = new StringBuilder();
        StringTokenizer tk;

        tk = new StringTokenizer(in.readLine());
        n = parseInt(tk.nextToken()); m = parseInt(tk.nextToken());
        
        g = new List[n];
        for(int i=0; i<n; i++)
            g[i] = new ArrayList();
        
        for(int i=0,a,b; i<m; i++) {
            tk = new StringTokenizer(in.readLine());
            a = parseInt(tk.nextToken()); b = parseInt(tk.nextToken());
            a--; b--;
            
            g[a].add(b);
            g[b].add(a);
        }
        
        vis = new int[n];
        Arrays.fill(vis, -1);
        Queue<Integer> q = new LinkedList();
        q.add(0);
        vis[0] = 0;
        
        while(!q.isEmpty()) {
            int s = q.remove();
            
            for(int v : g[s])
                if(vis[v]==-1) {
                    vis[v] = vis[s]+1;
                    q.add(v);
                }
        }
        
        System.out.println(vis[n-1]==2 ? "POSSIBLE" : "IMPOSSIBLE");
    }
}


Measured memory_bytes: 87844
#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
using namespace std;
////////////// Prewritten code follows. Look down for solution. ////////////////
#define x first
#define y second
#define LEN(x) ((int)(x).size())
#define ALL(x) x.begin(), x.end()
using ll = long long;
using llu = long long unsigned;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
using vpii = vector<pii>;

const ld EPS = 1e-9;
inline int cmp(ld x, ld y = 0, ld tol = EPS) {
	return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}

const int MOD = 998244353;
inline int mod(ll x, int m = MOD) {
	return (int)(((x%m) + m)%m);
}

template<typename T, typename M = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, M, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

////////////////////////// Solution starts below. //////////////////////////////

const int N = 2e5 + 10;

int n, k;
set<int> s;
int bit[N];

void add(int p, int v) {
	for(int i = p; i < N; i +=(i&-i))
		bit[i] = (bit[i]+v)%MOD;
}

int sum(int p) {
	int ret = 0;
	for(int i = p; i; i-= (i&-i))
		ret = (ret+bit[i])%MOD;
	return ret;
}

int main () {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);
	cin >> n >> k;
	while(k--) {
		int l, r;
		cin >> l >> r;
		while(l <= r) s.insert(l++);
	}
	int lst = -1;
	pii interv = {-1, -1};
	vector<pii> vec;
	for(int v : s) {
		if(interv.y == -1 || interv.y != v-1) {
			if(interv.x != -1)
				vec.push_back(interv);
			interv = {v, v};
		}
		else if (interv.y == v-1)
			interv.y++;
	}
	vec.push_back(interv);

	add(1, 1);
	for(int i = 2; i <= n; i++) {
		// cout << "\ni = " << i << '\n';
		for(pii p : vec) {
			// cout << "p = " << p.x << ' ' << p.y << '\n';
			int l, r;
			r = i-p.x;
			l = max(0, i-p.y-1);
			if(l <= r) {
				// cout << "sum(" << r << ") = " << sum(r) << '\n';
				// cout << "sum(" << l << ") = " << sum(l) << '\n';
				add(i, mod(sum(r) - sum(l)));
			}
		}
	}
	cout << mod(sum(n)-sum(n-1)) << '\n';

	

	return 0;
}


Measured memory_bytes: 13676
M, D = map(int, input().split())

count = 0
for month in range(1, M + 1):
    for day in range(1, D + 1):
        if day < 10:
            continue
        day_str = str(day)
        d10 = int(day_str[0])
        d1 = day % 10
        if d1 >= 2 and d10 >= 2 and d1 * d10 == month:
            count += 1
print(count)


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

using namespace std;
using ll = long long;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

#define LOCAL
#ifdef LOCAL
#define show(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

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

    // input
    ll N;
    cin >> N;

    vector<ll> A(N);
    FOR(i, 0, N){
        cin >> A.at(i);
    }

    ll tallest = A[0];
    ll count = 1;

    FOR(i, 1, N){
        if(A[i]>=tallest){
            count++;
        }
        tallest = max(tallest, A[i]);
    }

    p(count);
    
    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <iostream>

using namespace std;

int main() {
  int a[3];
  for (int i = 0; i < 3; ++i) {
    scanf("%d", &a[i]);
  }

  if (a[0] == a[1]) {
    cout << a[2] << endl;
  } else if (a[0] == a[2]) {
    cout << a[1] << endl;
  } else {
    cout << a[0] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
//#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld  double
#define pii pair<int,int>
#define pip pair<int,pii>
#define ppi pair<pii,int>
#define ppp pair<pii,pii>
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define ff first
#define ss second
#define warmup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 200003, mod=998244353;
const ll inf=(1e9+11);
ll fact[N], ifact[N];

ll power(ll b,int p)
{
    ll r=1;
    while(p)
    {
        if(p&1)
            r*=b, r%=mod;
        b*=b, b%=mod;
        p>>=1;
    }
    return r;
}

void pre()
{
    int i,j;
    fact[0]=1;
    for(i=1;i<N;++i)
        fact[i]=fact[i-1]*i % mod;
    ifact[i-1]=power(fact[i-1],mod-2);

    for(i=i-2;i>=0;--i)
        ifact[i]=ifact[i+1]*(i+1) % mod;
}

inline int ncr(int n,int r)
{
    return (((fact[n]*ifact[r] % mod)*ifact[n-r] % mod));
}

signed main()
{
    warmup

    pre();
    int n,m,k,i,j;
    cin>>n>>m>>k;
    ll ans=0,ct=m;
    ct*=power(m-1,n-1);
    ct%=mod;
    if(m==1)
        return cout<<(k==n-1 ? 1:0), 0;

    for(i=0;i<=k;++i)
    {
        ans+=ncr(n-1,i)*ct % mod;
        if(ans>=mod)
            ans-=mod;

        ct*=power(m-1,mod-2);
        ct%=mod;
    }
    cout<<ans;

    return 0;
}


Measured memory_bytes: 6780
import sys, os

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

def solve():
    n = f()[0]
    x = f()

    y = sorted(x)
    for i in range(n):
        if x[i]<y[n//2]:
            print(y[n//2])
        else:
            print(y[n//2 -1])

solve()


Measured memory_bytes: 26772
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define REP(i,n) FOR(i,0,n)
using namespace std;
int main(){
  int n;
  cin>>n;
  std::vector<int> a(n);
  int mina=1000000001;int maxa=0;
  REP(i,n){
    cin>>a[i];
    mina=min(mina,a[i]);
    maxa=max(maxa,a[i]);
  }
  cout<<maxa-mina<<endl;
}


Measured memory_bytes: 256
n,a,b=map(int,input().split())
mod=10**9+7
def comb(n,k):
    temp=1
    k=min(k,n-k)
    for i in range(1,k+1):
        temp=temp*pow(i,mod-2,mod)
        temp=temp*(n-i+1)%mod

    return temp%mod
#二分累乗法を勉強する
ans=pow(2,n,mod)-1-comb(n,a)-comb(n,b)
print(ans%mod)

Measured memory_bytes: 3188
#include <stdio.h>

int main(void){
  int one,a,i,n,k;
  
  scanf("%d %d",&n,&k);
  for(i=0;i<n;i++){
    scanf("%d",&a);
    if(a==1) one=i;
  }
  
  a  =  (one)/(k-1) + (n-1-one)/(k-1);
  a += ((one)%(k-1) + (n-1-one)%(k-1) + (k-2))/(k-1);
  
  printf("%d",a);
  
  return 0;
}

Measured memory_bytes: 128