akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define F            first
#define S            second
#define pb(x)        push_back(x)
#define mp(a,b)      make_pair(a,b)
#define mt(a,b,c)    make_tuple(a,b,c)
#define sz           size()
#define all(A)       A.begin(), A.end()
#define mem(a, b)    memset(a, b, sizeof(a))   // all elements of A are b=0 or b=-1 else don't work
#define f0(i,b)      for(ll i=0;i<(b);i++)
#define f1(i,b)      for(ll i=1;i<=(b);i++)
#define f2(i,a,b)    for(ll i=(a);i<=(b);i++)
#define f3(i,b,a)    for(ll i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(ll i=(a);i!=(b);i+=(c))

#define mod          10000007
#define PI           acos(-1.0)
#define MAX3(a,b,c)  max(a,max(b,c))
/*------------------------Bitmask-------------------------------*/
#define bitOn(N,pos)      (N | (1LL<<(pos)))
#define bitOff(N,pos)     (N & (~(1LL<<(pos))))
#define bitCheck(N,pos)   ((bool)(N & (1LL<<(pos))))
#define bitFlip(a,k)      (a^(1LL<<(k)))

#define whilee(i,t)  while(i!=t)
#define  sl(a)       scanf("%lld",&a)
#define  pl(a)       printf("%lld\n",a)

//x = 1e18 means 10^18
//for(auto it =A.begin(); it!=A.end(); it++)
//sort(A.begin(),A.end()); //sort(A, +n, greater<int>());
//binary_search(A.begin(),A.end(),x);
//reverse(A.begin(), A.end());
//cout << *max_element(A.begin(), A.end());
//cout << *min_element(A.begin(), A.end());
//count(A.begin(), A.end(), X); //counts the occurrences of X
//distance(A.begin(),A.end());  //distance between first to last element
//accumulate(A.begin(), A.end(), 0); //add
//next_permutation(A.begin(), A.end());
//prev_permutation(A.begin(), A.end());
//swap(S[0], T[0]);

//scanf("%lld",&x);
//printf("%lld\n",x);
//printf("%I64d\n", a);
//while (scanf("%lld %lld", &a, &b) == 2)
//printf("Case %lld: %lld\n", t++, a);
/*----------------------- Graph Moves---------------------------*/
// int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1};  // 4 Direction
// int dx[] = {1,-1,0,0,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1,1,-1};  // 8 Direction // Kings Move
// int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};  // Knight Direction
// int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};  // Hexagonal Direction

//vector <ll> A;
//deque <ll> A;
//queue <ll> A;
//stack <ll> A;
//list <int> A;
//set <ll> A;
//map <ll,ll> A;
//unordered_map <ll, ll> A;
//pair <ll,ll> A ;
//tuple <ll, ll, ll> A;
//vector <pair <ll,ll>> A;
//bitset<32> bset1;
//bool ok = true;
//char ch;
//string S, T, U;

ll i=0, j=0, k=0, a, b, c, d, e, f, g, h, l, m, n, o, p, q, r, s, t=1, u, v, w, x, y, z, maxx=INT_MIN, minn=INT_MAX, ans=0, sum=0, flag=0, cnt=0;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);//NULL
    cout.tie(nullptr);//NULL

    cin>>a>>b>>c;
    cout<<c<<" "<<a<<" "<<b<<endl;
    return 0;
}


Measured memory_bytes: 384
use scanner::Scanner;

fn main() {
    let mut sc = Scanner::new();
    let mut a: usize = sc.read();
    let mut b: usize = sc.read();
    let k: usize = sc.read();

    for i in 0..k {
        if i % 2 == 0 {
            if a % 2 == 1 {
                a = a - 1;
            }
            b += a / 2;
            a /= 2;
        } else {
            if b % 2 == 1 {
                b -= 1;
            }

            a += b / 2;
            b /= 2;
        }
    }
    println!("{} {}", a, b);
}

mod scanner {
    pub struct Scanner<'a> {
        s: String,
        words: ::std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new() -> Scanner<'a> {
            let s = String::new();
            let words = unsafe { ::std::mem::transmute(s.split_whitespace()) };
            Scanner { s: s, words: words }
        }

        pub fn read<T: ::std::str::FromStr>(&mut self) -> T {
            match self.words.next() {
                Some(x) => x.parse().ok().unwrap(),
                None => {
                    self.load();
                    self.read()
                }
            }
        }

        fn load(&mut self) {
            self.s.clear();
            ::std::io::stdin().read_line(&mut self.s).unwrap();
            self.words = unsafe { ::std::mem::transmute(self.s.split_whitespace()) };
        }
    }
}


Measured memory_bytes: 4352
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        System.out.println(a[n-1]-a[0]);
    }
}

Measured memory_bytes: 21588
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
	int f[1000],m,n,p,c,i;
	while(cin >> n >> m) {
		if (n+m==0) break;
		for (i=0;i<n;i++) f[i]=0;
		p=n-1;
		for (i=0;i<n;i++) {
			c=0; 
			while(true) {
				p=(p+1) % n;
				if (f[p]==0) {c++; if (c==m) { f[p]=1; break;}}
			}
		}
		cout << p+1 << endl;
     }
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<long> a(n);
    long ans = LONG_MAX;

    for (int i=0; i<n; i++) cin>>a[i];

    vector<long> r(n+2,0);
    vector<long> l(n+2,0);

    for (int i=0; i<n; i++) {
        l[i+1] = l[i] + a[i];
        r[i+1] = r[i] + a[n-i-1];
    }

    for (int i=0; i<n; i++) {
        ans = min(ans, abs( r[n-i] - l[i] ));
    }

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


Measured memory_bytes: 4992
N = input()
A = list(map(int, input().split()))
 
if 0 in A:
    print(0)
    exit()
 
A = sorted(A)[::-1]
val = 1
 
for a in A:
    val *= a
    if val > 10 ** 18:
        print(-1)
        exit()
print(val)

Measured memory_bytes: 84788
#include<iostream>

using namespace std;

void solve1() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b &&b== c) {
		cout << 1 << endl;

	}
	else if (a == b || b == c || a == c) {
		cout << 2 << endl;
	}
	else
		cout << 3 << endl;
}

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

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

#define pb push_back
#define mp make_pair
#define ll long long int
#define all(x) x.begin(), x.end()

void solve() {

    int n, m;
    cin >> n >> m;
    map<int, int> arr;
    for (size_t i = 0; i < n; i++)
    {
        int tmp; cin >> tmp;
        if(arr.find(tmp) == arr.end()) {
            arr[tmp] = 1;
        } else {
            arr[tmp] += 1;
        }
    }
    

    // map<int, int> count;
    for (int i = 0; i < m; i++)
    {
        int b, c;
        cin >> c >> b;
        if(arr.find(b) == arr.end()) {
            arr[b] = c;
        } else {
            arr[b] += c;
        }
    }

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

        auto x = arr.end();
        --x;
        
        // cout << "picking: " << x->first " and count: " << x-> second << "\n";

        ans += x->first;
        x->second -= 1;
        if(x->second == 0) {
            arr.erase(x);
        }
    }

    cout << ans << "\n";

    

    


}

int main() {
    ios_base::sync_with_stdio(false);

    solve();
    return 0;
}

Measured memory_bytes: 9600
#include <stdio.h>
int main(void){
	int n,k;
	scanf("%d %d",&n,&k);
	int d,i,num[10]={0};
	for(i=0;i<k;i++){
		scanf("%d",&d);
		num[d]=1;
	}
	int flag;
	for(i=n;;i++){
		int tmp=i;
		flag=1;
		while(tmp>=1){
			if(num[tmp%10]==1){
				flag=0;
				break;
			}
			tmp/=10;
		}
		if(flag==1){
			printf("%d",i);
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include<stdio.h>

int n, A[50];

int solve(int i, int t){
  if ( i >= n ) return 0;
  if ( A[i] == t ) return 1;
  if ( solve(i + 1, t) ) return 1;
  if ( solve(i + 1, t - A[i]) ) return 1;
  return 0;
}

int main(){
  int i, l, m, t;
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) scanf("%d", &A[i]);
  scanf("%d", &m);
  for ( i = 0; i < m; i++ ) {
    scanf("%d", &l);
    t = solve(0, l);
    if (t == 1) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}


Measured memory_bytes: 2108
n = int(input())
s = input()
s = s.replace('R', '0') 
s = s.replace('G', '1')
s = s.replace('B', '2')

t = [[0] * (n + 5) for _ in range(3)]

for i in range(n):
    for j in range(3):
        t[j][i + 1] = t[j][i] + (s[i] == chr(48 + j))

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        if s[i] == s[j]: continue
        h = 99 - (ord(s[i]) + ord(s[j]))
        ans += t[h][n] - t[h][j]
        if 2 * j - i < n and s[2 * j - i] == chr(48 + h): ans -= 1
print(ans)

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

#define ll long long

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    unordered_map<ll, ll> l, r;
    for(int i = 0; i < n; i++){
        ll tmpl, tmpr;
        tmpl = i - a[i];
        tmpr = i + a[i];
        l[tmpl]++;
        r[tmpr]++;
    }

    ll ans = 0;
    for(auto x : l){
        ans += x.second * r[x.first];
    }

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

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

bool func() {
    int m, n_min, n_max;
    scanf("%d", &m);
    scanf("%d", &n_min);
    scanf("%d", &n_max);

    if(m==0 && n_min==0 && n_max==0) return true;

    int pre = -1;
    pair<int, int> max_diff = make_pair(-1, 0);;
    vector<int> data;
    for(int i=0; i<m; i++) {
        int tmp;
        scanf("%d", &tmp);
        data.push_back(tmp);
        
        if(pre!=-1) {
            if(max_diff.first <= (pre-tmp) && i>=n_min && i<=n_max) {
                max_diff = make_pair(pre-tmp, i);
            }
        }
        pre = tmp;
    }

    printf("%d\n", max_diff.second);
    return false;
}

int main() {
    bool flag = false;
    while(!flag) {
        flag = func();
    }
}



Measured memory_bytes: 3188
n,m = map(int,input().split())
ka = []
for _ in range(n):
    ka.append(list(map(int,input().split())))
x = []
for i in range(n):
    for j in range(1,ka[i][0]+1):
        x.append(ka[i][j])
cnt = 0
for i in range(1,m+1):
    if x.count(i)==n:
        cnt += 1
print(cnt)


Measured memory_bytes: 3060
N = input()
num_str = input()
num_str_list = num_str.split(" ")

result = 0
temp_result = 0

pre_num = int(num_str_list.pop(0))

for num_str in num_str_list:
    num = int(num_str)
    if num > pre_num:
        if result < temp_result:
            result = temp_result
        temp_result = 0
    else:
        temp_result += 1
    pre_num = num

if result < temp_result:
    result = temp_result

print(result)


Measured memory_bytes: 11124
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll max(ll a, ll b){ 
	if(a >= b) return a;
	else if(a < b) return b;
}

int main(){
	string s;
	cin >> s;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == ',')cout << " ";
		else cout << s[i];
	}
	cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

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

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(ll i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll,ll> P;
typedef long double ld;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep (i, n) cin >> a[i];
    ll sum[1000][1000] = {};
    rep (i, n) {
        rep (j, n) {
            sum[i][j] = (i > j ? sum[i - 1][j] : 0) + (i >= j ? a[i] : 0);
            eprintf("%3lld ", sum[i][j]);
        }
        eprintf("\n");
    }
    int m = 40;
    ll ans = 0;
    reprev(x, m) {
        int count = 0;
        ll tmp = ans + (1LL << x);
        rep (i, n) {
            rep (j, n) {
                if (i >= j && (sum[i][j] & tmp) == tmp) {
                    count++;
                }
            }
        }
        if (count >= k) ans = tmp;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
ll dp[100007];
int main(){
  ll n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  dp[0] = 0;
  ll count = 0;
  for (ll i = 1; i < n; i++){
    if(s[i]=='C'&&s[i-1]=='A'){
      count++;
    }
    dp[i] = count;
  }
  rep(i,q){
    ll l, r;
    cin >> l >> r;
    print(dp[r - 1] - dp[l-1]);
  }
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){
	int N;
	cin >> N;
	N *= 2;
	vector<int> L(N);
	for(int i=0;i<N;i++)cin >> L[i];
	sort(L.begin(), L.end());
	int res = 0;
	for(int i=0;i<N;i+=2){
		res += min(L[i], L[i+1]);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))

ans = 0
for i in range(1, n-1):
    if p[i-1] < p[i] < p[i+1] or p[i-1] > p[i] > p[i+1]:
        ans += 1
    else:
        continue
        
print(ans)

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

int64_t ver(int64_t x, int64_t k){
	return abs(x - k);
}

int main(){
	int64_t N, K;
  	cin >> N >> K;
  	int64_t x, x2;
//  	x2 = N;
//	N = ver(N,K);
//  	cout << N << endl;
//  	while(x2 > N){x2 = N; N = ver(N,K);}
//  	cout << x2 << endl;
 	x2 = N % K;
  	if(abs(x2 - K) < x2){cout << abs(x2 - K) << endl;}
  	else{cout << x2 << endl;}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;



int main(){
  int n;
  cin >> n;
  if(n == 1) {
    cout << 1 << endl;
    return 0;
  }

  int ans = 2;
  REP(i,7){
    ans *= 2;
    if(ans > n){
      ans /= 2;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3588
using System;

namespace AtCoder.ABC099
{
    public class A
    {
        public static void Solve()
        {
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);

            if (a >= 1000)
            {
                Console.WriteLine("ABD");
            }
            else
            {
                Console.WriteLine("ABC");
            }
        }    
    }
}

namespace AtCoder {
    class Program
    {
        static void Main(string[] args)
        {
            ABC099.A.Solve();
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  maxn = 1e6 + 5;

map<int,pair<int,int> >M;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int x;cin>>x;
	for(int i=0;i<=200;i++){
		for(int j=-200;j<=i;j++){
			M[pow(i,5)-pow(j,5)]=make_pair(i,j);
		}
	}
	cout<<M[x].first<<" "<<M[x].second<<'\n';
	return 0;
}


Measured memory_bytes: 4404
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};


  
int main(){
  
  int d,g;
  cin>>d>>g;
  int p[d],c[d];
  REP(i,d){
    cin>>p[i]>>c[i];
  }
  
  int ans=1000;
  bool flag;
  int temp;
  int cnt;
  for(int mask=0;mask<(1<<d);mask++){
    flag = false;
    temp = g;
    cnt = 0;
    REP(i,d){
      if((mask>>i) & 1){
        cnt += p[i];
        temp -= 100*(i+1)*p[i];
        temp -= c[i];
      }
    }
    
    for(int i=d-1;i>=0;i--){
      if((mask>>i) & 1)continue;
      for(int j=1;j<p[i];j++){
        if(temp>0){
          cnt++;
          temp -= 100*(i+1);
        }else{
          flag = true;
          break;
        }
      }
      if(flag)break;
    }
    
    if(temp>0)continue;
    ans = min(ans,cnt);
  }
  
  cout<<ans<<endl;    
  return 0;
}


Measured memory_bytes: 256
//============================================================================
// Name        : AOJ.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
using namespace std;

int main() {
	int a,b;
	char op;
	while(1){
		cin>>a>>op>>b;
		if (op=='?')break;
		if (op=='+')cout<<a+b<<endl;
		else if (op=='-')cout<<a-b<<endl;
		else if (op=='*')cout<<a*b<<endl;
		else if (op=='/')cout<<a/b<<endl;
	}


	return 0;
}

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


Measured memory_bytes: 80128
#include <iostream>
using namespace std;
int main(){
    int x,y; 
    while(1){
       cin >> x >> y;
       if(x==0 && y==0) break;
       
       if(x<y){
            cout<< x <<" "<< y << endl;
       }else{
            cout<< y <<" "<< x << endl;
       }
    }
    return 0;
}

Measured memory_bytes: 1160
#include <cstdio>

int main(){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if(r + x <= W && r + y <= H && x >= 0 && y >= 0 && x - r >= 0 && y - r >=0){
        printf("Yes\n");
    }
    else{printf("No\n");}
    return 0;
}


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

using namespace std;

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

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(pi c, pi d){
	return c.S < d.S;
}

int main() {
	int ans = 0;
	string s;
	cin >> s;
	REP(i, 1, (int)s.size()){
		if(s[i] != s[i-1]) ++ans;
	}
	cout << ans;

}


Measured memory_bytes: 512
#include <stdio.h>

#define MAX (100000 + 2)
#define NIL (-1)

struct node {
        int parent;
        int left_child;
        int right_brother;
};

struct node T[MAX];
int D[MAX];

int
get_depth(int id)
{
        int depth = 0;

        while (T[id].parent != NIL) {
                id = T[id].parent;
                depth++;
        }

        return depth;
}

void
print_children(int id)
{
        int child;
        int i;

        child = T[id].left_child;

        for (i = 0; child != NIL; i++) {
                if (i)
                        printf(", %d", child);
                else
                        printf("%d", T[id].left_child);
                child = T[child].right_brother;
        }
}

int
main(void)
{
        int node_num;
        int dimention = MAX - 1;
        int id;
        int id_left;
        int i, j;
        int read_array[MAX];

        scanf("%d", &node_num);

        for (i = 0; i < node_num; i++)
                T[i].parent = T[i].left_child = T[i].right_brother = NIL;

        for (i = 0; i < node_num; i++) {
                read_array[1] = MAX - 1;

                for (j = 0; j < dimention + 2; j++) {
                        scanf("%d", &read_array[j]);

                        if (j == 0)
                                id = read_array[0];
                        if (j == 1)
                                dimention = read_array[1];

                        if (j == 2)
                                T[id].left_child = read_array[j];
                        if (2 < j)
                                T[id_left].right_brother = read_array[j];
                        id_left = read_array[j];

                        if (1 < j)
                                T[read_array[j]].parent = id;
                }
                T[id_left].right_brother = NIL;
        }

        for (i = 0; i < node_num; i++)
                D[i] = get_depth(i);

        for (i = 0; i < node_num; i++) {
                printf("node %d: parent = %d, depth = %d, ", i, T[i].parent, D[i]);

                if (T[i].parent == NIL)
                        printf("root, ");
                else if (T[i].left_child == NIL)
                        printf("leaf, ");
                else
                        printf("internal node, ");

                printf("[");
                print_children(i);
                printf("]\n");
        }

        return 0;
}


Measured memory_bytes: 3676
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
    int tmp;
    int n ;
    cin >> n ;
    string b, now;
    bool t = true;
    map<string, int> count;
    REP(i, n){
        cin >> now;
        if(i>0 && b[b.size() - 1] != now[0]) t = false;
        if(count[now] > 0) t = false;
        count[now] ++; 
        b = now;
    }
    if (t) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    //cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

int main(){
  int n,ans=0;
  cin >> n;
  vi p(n);
  rep(i,0,n)  cin >> p[i];

  rep(i,1,n-1){
    if((p[i-1] < p[i] && p[i] < p[i+1]) || (p[i-1] > p[i] && p[i] > p[i+1])){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl "\n"
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);

    ll n,k;
    cin >> n >> k;

    ll alpha=n%k;
    ll beta=k-alpha;
    cout << min(alpha,beta) << endl;

    return 0;    
}


Measured memory_bytes: 256
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
debt = 100000.0
for i in xrange(int(raw_input())):
    debt += debt * 0.05
    debt = debt - (debt % 1000.0) + (1000.0 if debt % 1000.0 else 0.0)
print(int(debt))

Measured memory_bytes: 4244
import java.util.*

fun main(args:Array<String>?): Unit {
    while(true){
        val n = readLine()!!.trim().toInt()
        if (n == 0) return
        val pages = readLine()!!.trim().split(' ').map(String::toInt)
        var i = 0
        val list = LinkedList<String>()
        while(i < n){
            val a = pages[i]
            var current = a
            while(i + 1 < n && pages[i + 1] == current + 1){
                current = pages[++i]
            }
            if (a != current){
                list.add("$a-$current")
            }else {
                list.add(a.toString())
            }
            ++i
        }
        println(list.joinToString(" "))
    }
}


Measured memory_bytes: 31944
n = int(input())

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

f = prime_factorize(n)

ans = 0
for i in set(f):
    c = f.count(i)
    j = 1
    while True:
        if 0 <= c-j:
            ans += 1
            c = c-j
            j += 1
        else:
            break

print (ans)


Measured memory_bytes: 9212
n,m = (int(num) for num in input().split())
h = [int(num) for num in input().split()]
l = [1] * n
a = 0
b = 0
for _ in range(m):
    a,b = (int(num)-1 for num in input().split())
    if h[a] <= h[b]:
        l[a] = 0
    if h[a] >= h[b]:
        l[b] = 0
#print(l)        
print(sum(l))

Measured memory_bytes: 20024
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <cstdlib> //絶対値整数abs
#include <cmath>   //絶対値少数fbs
#include <math.h>
using namespace std;
#define rep(i, N) for (ll i = 0; i < (N); i++)
typedef long long ll;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll S;
    cin >> S;
    ll sum = 0;
    ll keta;
    keta = log10(S);
    ll t = 1;
    for (ll i = 0; i < keta; i++)
    {
        t *= 10;
    }
    vector<ll> vec(keta + 1);
    rep(i, keta + 1)
    {
        ll num;
        num = S / t;
        vec.at(i) = num;
        S -= t * num;
        t /= 10;
        //cout << vec.at(i) << " ";
    }
    //cout << endl;
    for (ll bit = 0; bit < (1 << keta); bit++)
    {
        ll big = 0;
        ll t = 1;
        for (ll i = 0; i < keta; i++)
        {
            if (bit & (1 << i))
            {
                for (ll j = i; j >= big; j--)
                {
                    sum += vec.at(j) * t;
                    //cout << vec.at(j) << " " << t << endl;
                    t *= 10;
                }
                big = i + 1;
                t = 1;
            }
        }
        ll k = 1;
        for (ll i = keta; i >= big; i--)
        {
            sum += vec.at(i) * k;
            //cout << vec.at(i) << " " << k << endl;
            k *= 10;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>

const int N = 1e5 + 51;

int p[N];
int f(int x) { return x[p] ? x[p] = f(x[p]) : x; }

int n, m, q, op[N], x[N], y[N], cnt, c0;
int main() {
	scanf("%d%d%d", &n, &m, &q), cnt = n;
	for (int i = 1; i <= q; i++) {
		scanf("%d%d%d", x + i, y + i, op + i), x[i]++, y[i]++;
		int u = x[i], v = y[i];
		if (!op[i]) {
			c0++;
			if ((u = f(u)) != (v = f(v))) u[p] = v, cnt--;
		}
	}
	for (int i = 1; i <= q; i++)
		if (op[i] && f(x[i]) == f(y[i])) return puts("No"), 0;
	if (n - (c0 == q) <= m && m <= n - cnt + 1ll * cnt * (cnt - 1) / 2)
		puts("Yes");
	else
		puts("No");
}

Measured memory_bytes: 1664
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,a[2004],ans,L,R;
inline int abs(int x) {
	return x>0?x:-x;
}
inline bool ok(int x) {
	return a[x]+L>R;
}
inline int find(int l,int r) {
	while (l<r) {
		int mid=l+r>>1;
		if (ok(mid)) r=mid;
		else l=mid+1;
	}
	return ok(r)?r:0;
}
int main() {
	scanf("%d",&n);
	int m=n;
	for (int i=1;i<=n;++i) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for (int i=1;i<m-1;++i) {
		for (int j=i+2;j<=m;++j) {
			L=a[i],R=a[j];
			int pos=find(i+1,j-1);
			if (pos) ans+=j-pos;
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,P> cake;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;
const ll INF=1000000000000000;

vector<ll> pw2(51,1); vector<ll> pw10(19,1);
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll mid(ll x,ll y,ll z){return x>y?y>=z?y:min(z,x):x>=z?x:min(y,z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll myceil(ll x,ll y){if(x<=y) return 1;else if(x%y==0) return x/y;else return x/y+1;}
vector<ll> divisor(ll x){
	vector<ll> div;
	for(int i=1;i*i<=x;i++){
		if(i*i!=x && x%i==0){
			div.pb(i);
			div.pb(x/i);
		}
		else if(x%i==0) div.pb(i);
	}
	return div;
}
vector<ll> vectorprime(ll x){
	vector<bool> is_prime(x+1);
	vector<ll> prime;
	rep(i,x+1) is_prime[i]=true;
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<=x;i++){
		if(is_prime[i]){
			prime.pb(i);
		}
		for(int j=i*2;j<=x;j+=i) is_prime[j]=false;
	}
	return prime;
}

//a,b x
int main(){
	ll X,Y,Z,K; cin>>X>>Y>>Z>>K;
	vector<ll> A(X+1,INF);
	vector<ll> B(Y+1,INF);
	vector<ll> C(Z+1,INF);
	rep1(i,X) cin>>A[i];
	rep1(i,Y) cin>>B[i];
	rep1(i,Z) cin>>C[i];
	sort(A.bg,A.ed,greater<ll>());
	sort(B.bg,B.ed,greater<ll>());
	sort(C.bg,C.ed,greater<ll>());

	vector<ll> ans(K+1);
	set<pair<P,ll>> se;
	priority_queue<cake> que;
	que.push(mp(mp(A[1]+B[1]+C[1],1),mp(1,1)));
	se.insert(mp(mp(1,1),1));
	rep1(scr,K){
		cake Q=que.top(); que.pop();
		ans[scr]=Q.a.a;
		ll x=Q.a.b,y=Q.b.a,z=Q.b.b;

		ll mem=se.sz;
		se.insert(mp(mp(x+1,y),z));
		if(se.sz!=mem && x<X) que.push(mp(mp(A[x+1]+B[y]+C[z],x+1),mp(y,z)));
		mem=se.sz;
		se.insert(mp(mp(x,y+1),z));
		if(se.sz!=mem && y<Y) que.push(mp(mp(A[x]+B[y+1]+C[z],x),mp(y+1,z)));
		mem=se.sz;
		se.insert(mp(mp(x,y),z+1));
		if(se.sz!=mem && z<Z) que.push(mp(mp(A[x]+B[y]+C[z+1],x),mp(y,z+1)));
	}
	rep1(i,K) cout<<ans[i]<<endl;
}

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

int main() {
  int N; cin >> N; // 数列の大きさ
  vector<int> A(N); // 判定用配列
  rep(i,N) { A.at(i) = i+1;}

  if(debug) {rep(i,N){cout << "A.at(i):" << A.at(i) << endl;}}

  int a=0,b=0;  // P,Q の出現順

  int tmp_i;  // 入力数値（仮
  int P=0;  // 数列Ｐ
  rep(i,N){
    cin >> tmp_i;
    P = P * 10 + tmp_i;
  }
  int Q=0;  // 数列Ｑ
  rep(i,N){
    cin >> tmp_i;
    Q = Q * 10 + tmp_i;
  }

  if(debug) {cout << "P:" << P << " Q:" << Q << endl;}
  int tmp_int;  // 順列に対応する数値
  int tmp_order=0;  // 何番目か？
	sort(A.begin(),A.end());		// arrays は string でも動く
	do {
	  // 順列に対する処理
    tmp_int = 0;
    rep(i,N){tmp_int = tmp_int*10 + A.at(i);}
    tmp_order++;
    if(debug) {cout << "tmp_order:" << tmp_order << " tmp_int:" << tmp_int << endl;}
    if ( P == tmp_int ) {a=tmp_order;}
    if ( Q == tmp_int ) {b=tmp_order;}

    if ( a!=0 && b!=0 ){break;}

	} while (next_permutation(A.begin(),A.end()));

  cout << abs(b-a) << endl;
}


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

const int maxn = 111;
char s[maxn], t[maxn];

signed main() {
  // freopen("in", "r", stdin);
  while(~scanf("%s %s", s, t)) {
    int n = strlen(s);
    char tmp[maxn], m = 0;
    memset(tmp ,0, sizeof(tmp));
    bool flag = 0;
    for(int i = 0; i < n; i++) {
      for(int j = 0; j < n; j++) {
        tmp[j] = s[(m+i+j)%n];
      }
      if(strcmp(t, tmp) == 0) {
        flag = 1;
        break;
      }
    }
    flag ? puts("Yes") : puts("No");
  }
  return 0;
}

Measured memory_bytes: 256
// Salvage Robots
// * frank_c1
// * 2017 / 12 / 17
 
#include <bits/stdc++.h>
using namespace std;
 
const int maxn = 105;
char s[maxn][maxn];
int r[maxn][maxn], c[maxn][maxn];
int f[maxn * maxn >> 2][maxn * maxn >> 2];
int h, w, X, Y;
 
inline int encode(int l, int r, int M) {
	return r * M + l;
}
 
inline void chkmax(int& x, int v) {
	x = max(x, v);
}
 
int dfs(int lX, int rX, int lY, int rY) {
	int cX = encode(lX, rX, X), cY = encode(lY, rY, Y);
	if (f[cX][cY] >= 0) return f[cX][cY]; f[cX][cY] = 0;
	if (lX < X - 1) {
		chkmax(f[cX][cY], dfs(lX + 1, rX, lY, rY) + (rX + 1 <= X - lX - 1 ? max(0, r[X - lX - 1][min(Y + rY, w - lY)] - r[X - lX - 1][max(Y - lY, rY + 1) - 1]) : 0));
	}
	if (rX < h - X) {
		chkmax(f[cX][cY], dfs(lX, rX + 1, lY, rY) + (X + rX + 1 <= h - lX ? max(0, r[X + rX + 1][min(Y + rY, w - lY)] - r[X + rX + 1][max(Y - lY, rY + 1) - 1]) : 0));
	}
	if (lY < Y - 1) {
		chkmax(f[cX][cY], dfs(lX, rX, lY + 1, rY) + (rY + 1 <= Y - lY - 1 ? max(0, c[min(X + rX, h - lX)][Y - lY - 1] - c[max(X - lX, rX + 1) - 1][Y - lY - 1]) : 0));
	}
	if (rY < w - Y) {
		chkmax(f[cX][cY], dfs(lX, rX, lY, rY + 1) + (Y + rY + 1 <= w - lY ? max(0, c[min(X + rX, h - lX)][Y + rY + 1] - c[max(X - lX, rX + 1) - 1][Y + rY + 1]) : 0));
	}
	return f[cX][cY];
}
 
int main() {
	scanf("%d%d", &h, &w);
	for (int i = 1; i <= h; ++i) scanf("%s", s[i] + 1);
	for (int i = 1; i <= h; ++i) for (int j = 1; j <= w; ++j) 
		if (s[i][j] == 'E') X = i, Y = j;
	for (int i = 1; i <= h; ++i) for (int j = 1; j <= w; ++j) {
		r[i][j] = r[i][j - 1] + (s[i][j] == 'o');
		c[i][j] = c[i - 1][j] + (s[i][j] == 'o');
	}
	memset(f, -1, sizeof(f));
	return printf("%d\n", dfs(0, 0, 0, 0)), 0;
}

Measured memory_bytes: 30080
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#define mod 998244853 
using namespace std;
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++)
	{
	    cin >> a[i];
	}
	sort(a, a+n);
	double x=a[0];
	for(int i = 1; i < n; i++)
	{
	    x+=a[i];
	    x=x/2.0;
	}
	cout << x << '\n';
}


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

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
constexpr int DX[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int sgn(int x) { return (x > 0) - (x < 0); }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int K;
bool ap[1100000];
signed main() {
    cin >> K;
    int cur = 0, ans = 0;
    while (true) {
        ans++;
        ((cur *= 10) += 7) %= K;
        if (cur == 0) { break; }
        if (ap[cur]) { fin(-1); }
        ap[cur] = true;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4576
import sys
sys.setrecursionlimit(10**9)

N = int(input())

E = []
T = [[] for i in range(N)]
for i,n in enumerate(range(N-1)):
    a,b = map(int,input().split())
    E.append((a-1,b-1))
    T[a-1].append(b-1)

# print(E)
# print(T)



R = [None for i in range(N)]
def dfs(using, cur):
    R[cur] = using
    i=0
    for t in T[cur]:
        if i==using:
            i+=1
        dfs(i,t)
        i+=1


dfs(-1, 0)

print(max(R)+1)
# print(K)
for e in E:
    print(R[e[1]]+1)

# print(K)


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

int main(){
	int K, A, B;
	cin >> K;
	cin >> A >> B;
	bool flag = false;
	for(int i = A; i <= B; i++){
		if(i%K==0) flag = true;	
	}

	if(flag) cout << "OK" << endl;
	else cout << "NG" << endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

const int M = 101;
int idx, ri;
vi record;
int d2i[M];
vector<vi> graph;

void dfs(int v, int depth, int ord){
    d2i[depth] = v;

    while(graph[v].size() != ord){
        assert(graph[v].size() < ord);

        int r = record[idx++];

        if(r < 0){
            int nd = depth + r;
            int nv = d2i[nd];
            graph[ v].push_back(nv);
            graph[nv].push_back( v);
        }
        else {
            int nv = ri++;
            graph[ v].push_back(nv);
            graph[nv].push_back(v);
            dfs(nv, depth + 1, r);
        }
    }
}

int main(void){
    int T; cin >> T;
    rep(loooop, T){
        record = vi();
        for(int r; cin >> r, r;) record.push_back(r);

        rep(i, M) d2i[i] = -1;
        graph = vector<vi>(M);

        idx = 0, ri = 0;
        dfs(ri++, 0, record[idx++]);

        int n = ri;
        rep(i, n){
            cout << i + 1;
            sort(_all(graph[i]));
            for(auto & e : graph[i]) cout << " " << e + 1;
            cout << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll dp[100010];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,w,weight,val;
    cin >> n >> w;
    while (n--) {
        cin >> weight >> val;
        for (int capacity = w; capacity >= 0; capacity--) {
            if (weight <= capacity) dp[capacity] = max(dp[capacity], dp[capacity-weight]+val);
        }
    }
    cout << dp[w] << "\n";
    return 0;
}

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

int main(){
    string str;
    const char* cstr;
    cin >> str;

    cstr = str.c_str();

    char a, b;

    a = cstr[0];
    if(cstr[1] == a){
        b = cstr[2];
        if(b == a) cout << "No" << endl;
        else if(cstr[3] == b) cout << "Yes" << endl;
        else cout << "No" << endl;
    }else{
        b = cstr[1];
        if(cstr[2] == a && cstr[3] == b) cout << "Yes" << endl;
        else if(cstr[2] == b && cstr[3] == a) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 256
def miller_rabin(n, k=10000):
    import random
    if n == 2:
        return True
    if n == 1 or n & 1 == 0:
        return False
    d = (n - 1) >> 1
    while d & 1 == 0:
        d >>= 1
    for _ in range(k):
        a = random.randint(1, n - 1)
        t = d
        y = pow(a, t, n)
        while t != n - 1 and y != 1 and y != n - 1:
            y = (y * y) % n
            t <<= 1
        if y != n - 1 and t & 1 == 0:
            return False
    return True
def main():
  x=int(input())
  for i in range(x,1000000):
    if miller_rabin(i):
      print(i)
      return
main()

Measured memory_bytes: 47452
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

long long int n,m,now,r=100001,l=100000,a[100005],b[100005],res[200005]={};
long long int used[100005]={};
queue<long long int> qu[100005];

int main() {
    const long long int mod = 1000000007,INF=99999999999999;
	map<long long int, long long int>mp;
    string str[2005],tmp;
	cout << fixed << setprecision(10);
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        cin>>a[i]>>b[i];
        qu[a[i]].push(b[i]);
        qu[b[i]].push(a[i]);
    }
    res[100000]=1;
    used[1]=1;
    now=1;
    while(!qu[now].empty()){
        if(used[qu[now].front()]==1){
            qu[now].pop();
        }else{
            now=qu[now].front();
            res[r]=now;
            r++;
            used[now]=1;
        }
    }
    
    now=1;
    while(!qu[now].empty()){
        if(used[qu[now].front()]==1){
            qu[now].pop();
        }else{
            
            now=qu[now].front();
            l--;
            res[l]=now;
            used[now]=1;
        }
    }
    cout<<r-l<<endl;
    for(long long int i=l;i<r;i++){
        cout<<res[i]<<" ";
    }
    
} 


Measured memory_bytes: 71936
function main(lines) {
  const S = s();

  const ans = S + (S[S.length-1] === 's' ? 'es' : 's');
  
  return ans;
}



const lines = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");

let lineCount = 0;
const s = () => lines[lineCount++];
const n = () => Number(s());
const b = () => BigInt(s());
const sa = () => s().split(' ');
const na = () => sa().map(Number);
const ba = () => sa().map(BigInt);
const getLines = (n) => lines.slice(lineCount, lineCount += n);

const ans = main(lines);
console.log( ans );

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

int main() {
  ll n, d, a;
  cin >> n >> d >> a;
  
  vector<pair<ll, ll>> m(n);
  ll x, h;
  for (ll i = 0; i < n; i++) {
    cin >> x >> h;
    m[i].first = x;
    m[i].second = (h + a - 1) / a;
  }

  sort(m.begin(), m.end());

  ll ans = 0;
  ll damage = 0;
  queue<pair<ll, ll>> q;

  for (ll i = 0; i < n; i++) {
    while (!q.empty()) {
      if (q.front().first < m[i].first) {
        damage -= q.front().second;
        q.pop();
      } else {
        break;
      }
    }

    ll bomb = max(m[i].second - damage, 0ll);
    damage += bomb;
    ans += bomb;

    ll right = m[i].first + 2 * d;
    q.push(make_pair(right, bomb));
  }

  cout << ans << endl;
}


Measured memory_bytes: 6656
while true
	a, cla, b = gets.chomp.split
	a, b = a.to_i, b.to_i
	case cla
	when "+"
		puts a + b
	when "-"
		puts a - b
	when "*"
		puts a * b
	when "/"
		puts a / b
	else
		break
	end
end

Measured memory_bytes: 8704
mod = 998244353
 
N = int(input())
D = [int(x) for x in input().split()]
 
dep = max(D)
dict = [0]*(dep+1)

#print(dict)
 
for d in D:
    dict[d]+=1
#print(dict)
if(dict[0]!=1 or D[0]!=0):
    ans = 0
else:
    ans = 1
    for de in range(1,dep+1):
        ans *= (dict[de-1]**dict[de])%mod
        #print(ans)
        ans %= mod
print(ans)

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

using namespace std;
typedef long long ll;

const int N=2e5+100;
typedef pair<int,int>pa;
map<pa,int>mp;
ll ans[10];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    int h,w,n;
    cin>>h>>w>>n;
    for(int i=1;i<=n;i++){
        int a,b;
        cin>>a>>b;
        for(int i=-2;i<=0;i++)
         for(int j=-2;j<=0;j++){
             int aa=a+i;
             int bb=b+j;
             if(aa>=1&&aa<=h-2&&bb>=1&&bb<=w-2){
                mp[make_pair(aa,bb)]++;
             }
        }
    }
    ans[0]=1ll*(h-2)*(w-2);
    for(auto it=mp.begin();it!=mp.end();it++){
        ans[it->second]++;
        ans[0]--;
    }
    for(int i=0;i<=9;i++){
        cout<<ans[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 59796
/*
Created on 13-09-20 17:30

@author: roastedcoder

*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod = 1e9+7;
const int INF = INT_MAX;
#define endl "\n"
#define pb push_back
#define roastedcoder ios_base::sync_with_stdio(false); cin.tie(NULL);
//__________________________________________________________________

int main() {
	roastedcoder
	int n; cin>>n;
	ll a[n], b[n];
	for(int i = 0; i<n; i++) {
		int x, y; cin>>x>>y;
		a[i] = x+y;
		b[i] = x-y;
	}
	sort(a, a+n);
	sort(b, b+n);
	ll res = a[n-1]-a[0];
	res = max(res, b[n-1]-b[0]);
	cout<<res<<endl;
}

//__________________________________________________________________
/*
Sample Input:


Sample Output:


*/



Measured memory_bytes: 6716