akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;

int main(void) {
	int A, B;
	string win;

	cin >> A >> B;

	if (A == 1)
		A = 14;
	if (B == 1)
		B = 14;

	if (A > B)
		win = "Alice";
	else if(A < B)
		win = "Bob";
	else win = "Draw";

	cout << win << endl;

}

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

const int mod = 1e9 + 7;

void add(int &x,int y) {
	x += y; if (x >= mod) x -= mod;
}

int mul(int x,int y) {
	return (long long) x * y % mod;
}

int pw(int x,int y) {
	int ret = 1;
	while (y) {
		if (y & 1) ret = mul(ret, x);
		x = mul(x, x);
		y >>= 1;
	}
	return ret;
}

pair<int,int> solve(vector<int> h) {
	int n = h.size();
	int mn = mod, cnt = 0;
	for (int i = 0; i < n; ++i) {
		if (mn > h[i]) {
			mn = h[i], cnt = 0;
		}
		cnt += (h[i] == mn);
	}
	
	int l = 0, r = 0;
	vector<pair<int,int>> vec; 
	while (l < n) {
		vector<int> new_h;
		while (l < n && h[l] == mn) l++;
		r = l;
		while (r < n && h[r] > mn) r++;
		for (int i = l; i < r; ++i) new_h.push_back(h[i] - mn);
		if (new_h.size()) vec.push_back(solve(new_h));
		l = r;	
	}
	pair<int,int> ret;
	ret.first = pw(2, mn);
	for (auto p : vec) ret.first = mul(ret.first, p.first);
	ret.second = pw(2, cnt);
	for (auto p : vec) ret.second = mul(ret.second, p.first + p.second);
	int coef = pw(2, mn); add(coef, mod - 2);
	for (auto p : vec) coef = mul(coef, p.first);
	add(ret.second, coef);
	return ret;
}

int main() {
	ios_base::sync_with_stdio(false);
	int n; cin >> n;
	vector<int> h(n);
	for (int i = 0; i < n; ++i) cin >> h[i];
	cout << solve(h).second << '\n';
}


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

int findAnsItertavely(vector<int> &A, int n, int k, vector<int> &dp)
{
	dp[0] = 0;

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

	return dp[n-1];

}

int main()
{

	int n, k;
	cin>>n>>k;

	vector<int> A(n, 0);
	for(int i = 0; i < n; i++)
		cin>>A[i];

	vector<int> dp(n, INT_MAX);
	int ans = 0;

	ans = findAnsItertavely(A, n, k, dp);
	
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 3988
import sys

INPUT = lambda: sys.stdin.readline().rstrip()
MAP = lambda: map(int, INPUT().split())

sys.setrecursionlimit(10 ** 9)


def main():
    K, X = MAP()
    ans = [0] * (2*K - 1)

    for i in range(2*K - 1):
        ans[i] = X - K + 1 + i

    print(*ans, sep=" ")

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
import java.util.*;
public class Main{
	public static void main(String[] args){
		int ans = 0;
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int syou = (M - M%N) / N;
		
		for(int i=syou; i>=1; i--){
			if(M % i == 0){
				System.out.println(i);
				break;
			}
		}
	}
}

Measured memory_bytes: 25172
x,k,d = map(int, raw_input().split())
def f(x,k,d):
	if k == 0:
		return abs(x)

	if abs(x) <= d:
		if k % 2 == 0:
			if k <= 2:
				return abs(x)
			else:
				return min(abs(x),abs(x-2*d), abs(x+2*d) )#f(x+d,k-1,d), f(x-d,k-1,d))	
		else:
			return min(abs(x+d), abs(x-d))
	else:
		if x > d:
			if x/d <= k:
				return f(x - (x/d) * d, k - x/d, d)
			elif x / d > k:
				#get as close to zero as u can
				return f(x - k*d, 0, d)
		elif x < -d:
			return f(-x, k, d)

print f(x,k,d)

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

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

    int ans = 0;
    if (n > 1) {
        ans += (n * (n-1) /2) ;
    }
    if (m > 1) {
        ans +=  m *(m - 1) / 2;
    }
    cout << ans << endl;
}

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

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

int N;
vector<int> G[110000];
const int INF = 1 << 29;

int rec(int v, int p) {
	int all = 0;
	int zero_num = 0;
	for (auto to : G[v]) {
		if (to == p) continue;
		int tmp = rec(to, v);
		all += tmp;
		if (tmp == 0) ++zero_num;
	}
	if (zero_num > 1) all += zero_num - 1;
	//cout << v << ", " << all << endl;

	return all;
}

int main() {
	cin >> N;
	int r = -1;
	for (int i = 0; i < N - 1; ++i) {
		int a, b;
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
		if (G[a].size() > 2) r = a;
		if (G[b].size() > 2) r = b;
	}
	if (r == -1) {
		cout << 1 << endl;
		return 0;
	}
	cout << rec(r, -1) << endl;
}













Measured memory_bytes: 8704
#include <iostream>

using namespace std;

int main()
{
    int h1, m1, h2, m2, k;
    cin>>h1>>m1>>h2>>m2>>k;

    int wakeTime = h2 - h1;
    wakeTime *= 60;
    wakeTime += (m2-m1);

    int study = wakeTime - k;
    cout<<study<<endl;

    return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long LL;
const int N = 200010;
LL a[N],b[N];
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++){
		scanf("%lld",a+i);
	}
	for(int i=1;i<=m;i++){
		scanf("%lld",b+i);
	}
	LL t=0,i; 
	for(i=1;i<=n;i++){
		if(t+a[i]<=k){
			t+=a[i];
		}
		else{
			break;
		}
	}
	LL ans,j;
	for(j=1;j<=m;j++){
		if(t+b[j]<=k){
			t+=b[j];
		}
		else{
			break;
		}
	}
	i--;
	ans=i+j-1;
	for(;i>=1;i--){
		t-=a[i];
		for(;j<=m;j++){
			if(t+b[j]<=k){
				t+=b[j];
			}
			else{
				break;
			}
		}
		ans=max(ans,i+j-2);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6884
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
const ll maxn=1e5+10;
const ll mod=1e9+7;
ll dp[maxn][2];
ll len;
ll dfs(ll pos,ll lead){
    if(pos==len)return 1;
    ll tmp=0;
    if(dp[pos][lead]!=-1)return dp[pos][lead];
    if(lead){
        if(s[pos]=='0'){
            tmp+=dfs(pos+1,1);
        }
        else {
            tmp+=dfs(pos+1,0);
            tmp+=2*dfs(pos+1,1);
        }
    }
    else{
        tmp+=3*dfs(pos+1,0);
    }
    dp[pos][lead]=tmp%mod;
    return tmp%mod;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>s;
    memset(dp,-1,sizeof(dp));
    len=s.size();
    cout<<dfs(0,1)<<endl;
}


Measured memory_bytes: 6736
#include <bits/stdc++.h>
using namespace std;
 
#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define mp make_pair
#define mod 1000000007
#define qmod 998244353
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
 
const int MOD = 1e9 + 7;
const int INF = 1e9 + 5;
const ll LINF = LLONG_MAX;

int main(){
	ll k,n;
	cin>>k>>n;
	ll a[n],b[n];
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}
	for(ll i=0;i<n;i++){
		if(i!=n-1){
			b[i] = a[i+1]-a[i]; 
		}
		else{
			b[i] = k-a[i]+a[0];
		}
	}
	sort(b,b+n);
	ll sum=0;
	for(int i=0;i<n-1;i++){
		sum +=b[i];
	}
	cout<<sum<<endl;
	

}

Measured memory_bytes: 3328
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: String,
    }
    let ans = s.replace("2017", "2018");
    println!("{}", ans);
}


Measured memory_bytes: 4352
#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() {
	ll n, m = pow(10, 9)+7, ans= 1;
	string s;
	vi v(27, 0);
	cin >> n >> s;
	for(char c: s) ++v[c-'a'];
	REP(i, 0, 27){
		ans *= (v[i]+1);
		ans %= m;
	}
	cout << (ans - 1) % m;

}


Measured memory_bytes: 512
#include<stdio.h>

#define N 500000
#define Keeper 1000000001

int count;

void Merge(int *,int,int,int);
void MergeSort(int *,int,int);

int main(){
  int i;
  int Re[N],lo;

  scanf(" %d",&lo);
  for(i = 0 ; i < lo ; i++){
    scanf(" %d",&Re[i]);
  }

  MergeSort(Re,0,lo);

  for(i = 0 ; i < lo-1 ; i++){
    printf("%d ",Re[i]);
  }

  printf("%d\n%d\n",Re[lo-1],count);

  return 0;
}

  void Merge(int *X,int lside,int center,int rside){
    int i,j,k;
    int Lreng,Rreng;
    int Left[N/2+3],Right[N/2+3];

    Lreng = center - lside;
    Rreng = rside - center;

    for(i = 0 ; i < Lreng ; i++){
      Left[i] = X[lside+i];
    }

    for(i = 0 ; i < Rreng ; i++){
      Right[i] = X[center+i];
    }

    Left[Lreng] = Keeper;
    Right[Rreng] = Keeper;

    i = 0;
    j = 0;

    for(k = lside ; k < rside ; k++){
      if(Left[i] <= Right[j]){
        X[k] = Left[i];
        i++;
        count++;
      }
      else{
        X[k] = Right[j];
        j++;
        count++;
      }
    }

  }

  void MergeSort(int *X,int lside,int rside){
    int center;

    if(lside+1 < rside){
      center = (lside+rside) / 2;
      MergeSort(X,lside,center);
      MergeSort(X,center,rside);
      Merge(X,lside,center,rside);
    }
    }



Measured memory_bytes: 5760
while True:
    a, op, b = input().split()   # 3変数ともに文字列として読み込む
    a =int(a)                   # a を整数に変換
    b =int(b)                   # b を整数に変換


    if op=="?": # opが"?"の時は終了
        break
    else:    #opが"?"以外の時
        if op=="+":
            print(a+b)
        if op=="-":
            print(a-b)
        if op=="*":
            print(a*b)
        if op=="/":
            print(int(a/b))


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

#define all(x) (x).begin(),(x).end()
#define pb push_back
#define pf push_front
#define sz(x) (int)(x).size()
#define lb lower_bound 
#define ub upper_bound 
#define mp make_pair
#define fi first
#define se second
#define setbits(x) __builtin_popcount(x)
#define zerobits(x) __builtin_ctz(x)
#define setbitsll(x) __builtin_popcountll(x)
#define zerobitsll(x) __builtin_ctzll(x)
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

typedef vector<int> vi;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef vector<string> vs;
typedef unsigned long long ull;
typedef long double ld;
typedef map<int,int> mii;

const int MOD = 1e9+7;
const ll INF = 1e18; //
const ld PI = acos((ld)-1);
const int maxN = 2e5+1;
vl arr(maxN);
ll n,k,x,sum = 0;

bool check (ll m) {
	ll cuts = 0;
	F0R(i,n) {
		cuts += ((arr[i]-1)/m);
	}
	if (cuts > k)return false;
	else return true;
}

void solve () {
	cin >> n >> k;
	F0R(i,n) {
		cin >> arr[i];
	}
	ll s = 1,e = 1e9;
	ll ans;
	while (s <= e) {
		ll m = (s+e)/2;
		if (check(m)) {
			ans = m;
			e = m-1;
		} else {
			s = m+1;
		}
	}
	cout << ans << '\n';

}

int main () {
#ifndef ONLINE_JUDGE
	freopen("input1.txt","r",stdin);
	freopen("output1.txt","w",stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
	return 0;	
}



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

int main()
{
	std::vector<int> vec;

	for (int i = 0; i < 3; i++) {
		int temp;
		std::cin >> temp;
		vec.push_back(temp);
	}

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

	for (int i = 0; i < 3; i++) {
		std::cout << vec[i];
		if (i != 2) {
			std::cout << " ";
		}
		else {
			std::cout << std::endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3160
/* *
 *
 * Author: Hamkor
 *
 * */
 
#include <bits/stdc++.h>

using namespace std;

/* * * *   * * *   	* * * */
typedef long long ll;
const int oo = 1e9;
const ll mod = 100000000;
typedef complex<ll> P;
#define X real()
#define Y imag()
/* * * *   * * *   	* * * */
 int f(int n){
	 return n%2==0? n/2: 3*n + 1;
 }
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int s, i = 2, x, y; cin>>s;
	set<int> a; a.insert(s);
	x = s;
	while (true){
		y = f(x);
		if (a.count(y)){cout<<i; return 0;}
		else a.insert(y);
		x = y;
		++i;
	}
	return 0;
}

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

int main(){
    int s;
    cin >> s;
    vector<int> a;
    a.push_back(s);
    int ans;
    for(int i = 2; i <= 1000010; i++){
        int tmp;
        if(a[i-2] % 2 == 0) tmp = a[i-2] / 2;
        else tmp = 3 * a[i-2] + 1;
        auto res = find(a.begin(), a.end(), tmp);
        if(res != a.end()){
            ans = i;
            break;
        } else {
            a.push_back(tmp);
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
w,h,n=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
a=[0,w,0,h]
for i in range(n):
  if l[i][2]==1:
    a[0]=max(a[0],l[i][0])
  elif l[i][2]==2:
    a[1]=min(a[1],l[i][0])
  elif l[i][2]==3:
    a[2]=max(a[2],l[i][1])
  else:
    a[3]=min(a[3],l[i][1])
print(max(a[1]-a[0],0)*max(a[3]-a[2],0))

Measured memory_bytes: 3064
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>

////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

#pragma gcc target ("avx2")
#pragma gcc optimization ("Ofast")
#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2LL) //等差数列の和、初項,末項,項数
#define pb push_back
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int d;
	scanf("%d", &d);
	vector<ll> c(26);
	rep(i, 26)scanf("%lld", &c[i]);
	vector<vector<ll>> s(d, vector<ll>(26));
	rep(i, d)rep(j, 26)scanf("%lld", &s[i][j]);
	vector<ll> last(26);
	ll ans = 0, tmp;
	int idx = 1;

	rep(i, d) {
		ans = -INF;
		rep(k, 26) {
			int t = k + 1;
			tmp = 0;
			tmp += s[i][t - 1];
			rep(j, 26) if(j != k) tmp -= (c[j] * (i + 1 - last[j]));
			if (ans < tmp) idx = k + 1, ans = tmp;
		}
		last[idx - 1] = i + 1;
		printf("%d\n", idx);
	}

	Please AC;
}

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

using namespace std;

int
main(int argc, char* argv[]) {
  string s, t;
  int i, n;
  cin >> s;
  cin >> t;

  n = s.size();
  for(i=0; i<n; i++) {
    if(s == t) {
      cout << "Yes" << endl;
      return 0;
    }
    t = t.substr(1) + t.substr(0,1);
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 760
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;
typedef long long ll;

const int    INF = 1000000000;
const int    MOD = 1000000007;
const double EPS = 1e-8;

typedef pair<int, int> P;

int main(){
    int N;
    while(cin >> N){
        vector<P> v(N);
        for(auto& p : v) cin >> p.second >> p.first;
        sort(v.begin(), v.end());
        vector<int> min_time(N + 1, INF);
        min_time[0] = 0;
        int ans = 0;
        for(int i = 0; i < N; i++){
            int T = upper_bound(min_time.begin(), min_time.end(), v[i].first - v[i].second) - min_time.begin() - 1;
            ans = max(ans, T + 1);
            for(int t = T; t >= 0; t--){
                min_time[t + 1] = min(min_time[t + 1], min_time[t] + v[i].second);
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1200
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int n = sc.nextInt();
    int m = sc.nextInt();

    int[] a = new int[n];
    int[] b = new int[n];
    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
      b[i] = sc.nextInt();
    }

    List<Integer> index = new ArrayList<>(n);
    for (int i = 0; i < n; i++) index.add(i);
    index.sort(Comparator.comparingInt(i -> a[i]));

    Queue<Integer> queue = new PriorityQueue<>(Comparator.comparingInt(i -> -b[index.get(i)]));
    long ans = 0;
    int i = 0;
    for (int d = 1; d <= m; d++) {
      while (i < n && a[index.get(i)] == d) queue.add(i++);
      if (!queue.isEmpty()) ans += b[index.get(queue.remove())];
    }
    os.println(ans);
  }
}

Measured memory_bytes: 69028
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL K;
std::vector<LL>ans;

LL f(LL n)
{
	LL res = 0;
	while (n > 0)
	{
		res += n % 10;
		n /= 10;
	}
	return res;
}

int main()
{
	in >> K;
	for (LL i = 0; i <= 20; ++i)
	{
		for (LL j = 1; j <= 500; ++j)
		{
			if (i == 0 && j == 1) continue;
			LL tmp = j * pow(10LL, i);
			--tmp;
			ans.push_back(tmp);
		}
	}
	std::sort(ans.begin(), ans.end());
	ans.erase(std::unique(ans.begin(), ans.end()), ans.end());
	rep(i, ans.size())
	{
		for (int j = i + 1; j < ans.size(); ++j)
		{
			if ((long double)ans[i] / f(ans[i]) > (long double)ans[j] / f(ans[j]))
			{
				ans.erase(ans.begin() + i);
				--i;
				break;
			}
		}
	}
	rep(i, K) out << ans[i] << std::endl;
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,s;
  cin>>s;
  a=s/100;
  b=s%100;
  if((a==0 || a>12) && (b==0 || b>12)) cout<<"NA"<<'\n';
  else if((a<=12 && a!=0)&&(b<=12 && b!=0)) cout<<"AMBIGUOUS"<<'\n';
  else if(a<=12 && a!=0) cout<<"MMYY"<<'\n';
  else cout<<"YYMM"<<'\n';
  return 0;
}

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

int cache[201][201][201] = {0};

int gcd(int a, int b, int c) {
    if (b < a) swap(a, b);
    if (c < a) swap(a, c);
    if (c <  b) swap(b, c);
    if (!cache[a][b][c]) {
      cache[a][b][c] =__gcd(__gcd(a, b), c);
    }
    return cache[a][b][c];
}

int main () {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int K;
    cin >> K;
    long long sum = 0;
    for (int i = 1; i <= K; ++i) {
        for (int j = 1; j <= K; ++j) {
            for (int k = 1; k <= K; ++k) {
                sum += gcd(i, j, k);
            }
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 20012
from collections import deque

def main():
    N=int(input())
    A=[int(x) for x in input().split()]
    
    dictionary={}
    for num in A:
        if num in dictionary:
            dictionary[num]+=1
        else:
            dictionary[num]=1
    
    ans=0
    d=deque()
    
    for key,value in sorted(dictionary.items()):
        if value>=2:
            d.append(key)
            if value>=4:
                d.append(key)
    
    d=sorted(d,reverse=True)
    if len(d)==0:
        ans=0
    else:
        ans=d[0]*d[1]
    print(ans)

if __name__=="__main__":
    main()

Measured memory_bytes: 21412
#include <cstdio>

using namespace std;

int K;

int main()
{
	scanf("%d", &K);
	if (K <= 500)
	{
		printf("%d\n", K);
		for (int i = 1;i <= K;++i)
		{
			for (int j = 1;j <= K;++j)
				printf("%d ", i);
			printf("\n");
		}
	}
	else
	{
		int N = ((K / 4) + (K % 4 != 0)) * 2;
		printf("%d\n", N);
		for (int i = 1;i <= N;++i)
		{
			for (int j = 1, v;j <= N;++j)
			{
				v = (i + j) % N + (i & 1) * N + 1;
				if (v > K)
					v -= N;
				printf("%d ", v);
			}
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 1152
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

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

	string s;
  cin>>s;
  if(s=="Sunny")cout<<"Cloudy"<<endl;
  if(s=="Cloudy")cout<<"Rainy"<<endl;
  if(s=="Rainy")cout<<"Sunny"<<endl;
}


Measured memory_bytes: 256
while True:
    mid_test, end_test, add_test = map(int, input().split())
    if mid_test == end_test == add_test == -1:
        break
    if mid_test == -1 or end_test == -1:
        print('F')
    elif mid_test + end_test >= 80:
        print('A')
    elif 65 <= (mid_test + end_test) < 80:
        print('B')
    elif 50 <= (mid_test + end_test) < 65:
        print('C')
    elif 30 <= (mid_test + end_test) < 50:
        if add_test >= 50:
            print('C')
        else:
            print('D')
    else:
        print('F')



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

using namespace std;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;

#define gi(x) ((x) = F())
#define gii(x, y) (gi(x), gi(y))
#define giii(x, y, z) (gii(x, y), gi(z))

int F()
{
	char ch;
	int x, a;
	while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
	if (ch == '-') ch = getchar(), a = -1;
	else a = 1;
	x = ch - '0';
	while (ch = getchar(), ch >= '0' && ch <= '9')
		x = (x << 1) + (x << 3) + ch - '0';
	return a * x;
}

const int N = 1e5 + 10;

int n, deg[N];

int64 A[N];

VI edge[N];

void dfs(int u, int fa)
{
	if (deg[u] <= 1) return;
	int64 x = 0, cnt = 0, la = 0;
	for (auto v : edge[u])
	{
		if (v == fa) continue;
		dfs(v, u);
		x += A[v];
		la = max(la, A[v]);
	}
	cnt = min(x >> 1, x - la);
	if (x >= A[u] && x <= A[u] + cnt)
	{
		int64 c = x - A[u];
		A[u] -= c;
	}
	else
	{
		puts("NO");
		exit(0);
	}
}

int main()
{
	gi(n);
	for (int i = 1; i <= n; ++i) gi(A[i]);
	for (int i = 1; i < n; ++i)
	{
		int a, b;
		gii(a, b);
		edge[a].pb(b);
		edge[b].pb(a);
		++deg[a], ++deg[b];
	}
	if (n == 2)
	{
		puts(A[1] == A[2] ? "YES" : "NO");
		return 0;
	} 
	int root = 1;
	for (; deg[root] == 1; ++root);
	dfs(root, 0);
	if (!A[root]) puts("YES");
	else puts("NO");
}


Measured memory_bytes: 13568
#include "bits/stdc++.h"

using namespace std;

#define int long long
#define PB push_back
#define MP make_pair
#define ALL(V) V.begin(), V.end()
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<int, pii> pipii;
typedef pair<pii, pii> pipi;

constexpr int INF = 1LL << 60;
constexpr int MOD = 1000000007;
constexpr int MAX_N = 100005;
constexpr int dx[] = { 0, 1, 0, -1 };
constexpr int dy[] = { 1, 0, -1, 0 };

int n, a[MAX_N], b[MAX_N];

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

    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i] >> b[i];
    }

    int ans = 0, sum = 0;
    for (int i = n; 1 <= i; --i) {
        a[i] += sum;
        int cur = a[i] / b[i] + (a[i] % b[i] ? 1 : 0);
        ans += cur * b[i] - a[i];
        sum += cur * b[i] - a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>

int main() {
    int i, a[200001], N;
    scanf("%d", &N);

    for (i = 1; i <= N; i++) {
        scanf("%d", &a[i]);
    }

    int count = 0; 
    int num = 1;
    for (i = 1; i <= N; i++) {
        if (a[i] == num) {
            num++;
        }
        else count++;
    }

    if (num == 1) printf("-1");
    else printf("%d", count);

    return 0;
}

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

using namespace std;

int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	int ans=0;
	for(int i=0;i<n;i++){
		int x;
		scanf("%d",&x);
		if(x>=k) ans++;
	}
	printf("%d",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

int dp[100011];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	string s; cin>>s;
	int n=s.length();
	for(int i=0;i<26;i++)
	{
		int mx=0; int mxid=-1;
		dp[0]=(s[0]==char('a'+i)?1:-1);
		for(int j=1;j<n;j++)
		{
			dp[j]=((s[j]==char('a'+i))?1:-1)+dp[j-1];
			if(dp[j]>mx)
			{
				cout<<mxid+2<<' '<<j+1<<'\n';
				return 0;
			}
			if(dp[j-1]<mx)
			{
				mx=dp[j-1];
				mxid=j-1;
			}
		}
	}
	cout<<-1<<' '<<-1<<'\n';
}


Measured memory_bytes: 848
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<vector<int>> dag(N);
  for (int i = 0; i < M; i++) {
    int s, t;
    cin >> s >> t;
    dag[--s].push_back(--t);
  }
  long double dp[N];
  dp[N - 1] = 0;
  for (int j = N - 2; j >= 0; j--) {
    dp[j] = 0;
    for (int u : dag[j]) dp[j] += dp[u];
    dp[j] /= dag[j].size();
    dp[j] += 1;
  }
  long double ans = dp[0];
  debug(ans);
  for (int i = 0; i < N - 1; i++) {
    if (dag[i].size() == 1) continue;
    long double sum = 0, mx = 0;
    for (int u : dag[i]) {
      sum += dp[u];
      mx = max(mx, dp[u]);
    }
    dp[i] = (sum - mx) / (dag[i].size() - 1) + 1;
    debug(i);
    for (int j = i - 1; j >= 0; j--) {
      dp[j] = 0;
      for (int u : dag[j]) dp[j] += dp[u];
      dp[j] /= dag[j].size();
      dp[j] += 1;
    }
    debug(dp[0]);
    ans = min(ans, dp[0]);
  }
  cout << fixed << setprecision(12) << ans << '\n';
  return 0;
}


Measured memory_bytes: 4696
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin>>n,n){
        string str[4]={"a","b","c","d"};
        int num[4]={1000000,1000000,0,0};
        for(int i=0,sum;i<n;i++){
            string st;
            cin>>st;
            sum=0;
            for(int j=0,minute,second;j<4;j++){
                cin>>minute>>second;
                sum+=60*minute+second;
            }
            if(sum<num[1]){
                num[1]=sum;
                str[1]=st;
                if(num[1]<num[0]){
                    swap(num[0],num[1]);
                    swap(str[0],str[1]);
                }
            }
            if(sum>num[2]){
                num[2]=sum;
                str[2]=st;
                if(num[2]>num[3]){
                    swap(num[2],num[3]);
                    swap(str[2],str[3]);
                }
            }
        }
        for(int i=0;i<3;i++)cout<<str[i]<<endl;
    }
}

Measured memory_bytes: 1208
#include<iostream>
#include<bits/stdc++.h>
#define mod 1000000007
#define make_pair mp
#define pb push_back
#define pf push_front
#define all(vec) vec.begin(),vec.end()
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define lli long long int
using namespace std;
int main(){
  int n;
  cin>>n;
  int a[n][3];
  for(int i=0;i<n;i++){
    for(int j=0;j<3;j++){
      cin>>a[i][j];
    }
  }
  int dp[n][3];
  dp[0][0]=a[0][0];dp[0][1]=a[0][1];dp[0][2]=a[0][2];
  for(int i=1;i<n;i++){
    dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i][0];
    dp[i][1]=max(dp[i-1][0],dp[i-1][2])+a[i][1];
    dp[i][2]=max(dp[i-1][1],dp[i-1][0])+a[i][2];
  }
  cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
//   cout<<dp[n-1][0]<<endl<<dp[n-1][1]<<endl<<dp[n-1][2]<<endl;
  return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 long long a,b,c,d;
  cin>>a>>b;
  c=a;
  d=b;
  if(a>b){
    while(1){
      if(b == 0) cout << "aerror" << endl;
      if(a%b==0){
        cout<<d*c/b<<endl;
        break;
      }
      else{
      int temp = a;
      a = b;
      b=temp%b;
      }
      //cout << a << " " << b << endl;
    }
  }
  else if(b>a){
    while(1){
      if(a == 0) cout << "berror" << endl;
      if(b%a==0){
        cout<<c*d/a<<endl;
        break;
      }
      else{
      int temp = b;
      b = a;
      a= temp%a;
      }
      //cout << a << " " << b << endl;
    }
  }
   else if(b==a){
     cout<<a<<endl;
   }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

LL phi(LL n) {
    if (n==0) return 0;
    LL r=n;
    for (LL i=2; i*i<=n; i++) {
	if (n%i==0) {
	    r-=r/i;
	    for (;n%i==0;) n/=i;
	}
    }
    if (n>1) r-=r/n;
    return r;
}

LL safe_mul(LL x, LL y, LL mod) {
    x %= mod;
    y %= mod;
    LL r = 0;
    for (; y; y>>=1) {
	if (y&1) {
	    r += x;
	    if (r >= mod) r -= mod;
	}
	x += x;
	if (x >= mod) x -= mod;
    }
    return r;
}

LL powMod(LL x, LL y, LL mod) {
    x %= mod;
    LL r = 1;
    for (; y; y>>=1) {
	if (y&1) r = safe_mul(r, x, mod);
	x = safe_mul(x, x, mod);
    }
    return r % mod;
}

LL rec(LL A, LL M) {
    if (M == 1) {
	return 2;
    }

    LL ph = phi(M);
    LL r = rec(A, ph);
    LL k = powMod(A, r, M*ph) + M * ph;
    // A^r == r (mod phi(M));
    // A^(A^r) == A^r (mod M);
    return k;
}

void MAIN() {
    LL A, M;
    scanf("%lld%lld", &A, &M);
    LL k = rec(A, M);
    printf("%lld\n", k);
//    eprintf("%lld %lld\n", powMod(A, k, M), k % M);
}

int main() {
    int TC = 1;
    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;

#define rep(idx, N) for (u64 idx = 0; idx < N; idx++)

i32 toBit(char c) {
  if (c == 'R') {
    return 1;
  } else if (c == 'G') {
    return 2;
  } else {
    return 4;
  }
}

int main() {
  i32 n;
  string s;
  cin >> n >> s;

  map<u32, u32> color;

  u64 ans = 0;
  rep(i, n) {
    auto c = toBit(s.at(i));
    auto find = c ^ 7;

    if (i >= 2) {

      u64 inc = 1;
      for (int j = 1; j <= 4; j *= 2) {
        if (j != c) {
          inc *= color[j];
        }
      }

      ans += inc;

      for (int j = i - 1; j>0 && j - ((i32)i - j) >= 0; j--) {
        if ((toBit(s[i]) | toBit(s[j]) | toBit(s.at(j - (i - j)))) == 0b111) {
          ans--;
        }
      }
    }

    color[c] += 1;
  }

  cout << ans;

  return 0;
}


Measured memory_bytes: 3584
#include<stdio.h>
long long n,m;
int s(long long a, long long b)
{
    int ans = 1;
    a = a % 1000000007;
    while(b>0)
	{
        if(b % 2 == 1)
        ans = (ans * a) % 1000000007;
        b = b/2;
        a = (a * a) % 1000000007;
    }
    return ans;
}
int main()
{
	scanf("%lld%lld",&m,&n);
	printf("%lld\n",s(m,n));
}


Measured memory_bytes: 2016
#include<stdio.h>

int main(void){
    int n;
    scanf("%d",&n);
    register int i,j,k,l;
    int ans[n];
    for(i = 0;i < n;i++)ans[i] = 0;
    for(i = 3;i <= 2020;i++){
        for(j = 1;j <= i-2;j++)for(k = 1;k <= i-1-j;k++){
            l = i - j - k;
            int tn = i * i - j * k - k * l - j * l;
            if(tn > 0 && tn <= n)ans[tn-1]++;
        }
    }
    for(i = 0;i < n;i++)printf("%d\n",ans[i]);
}

Measured memory_bytes: 1732
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
string str;
cin>>str;
int N;cin>>N;
for(int i=0;i<N;i++){
	string m;cin>>m;
	if(m=="print"){
		int a,b;
		cin>>a>>b;
		cout<<str.substr(a,b-a+1)<<endl;
	}
	else if(m=="reverse"){
		int a,b;cin>>a>>b;
		string::iterator it;it=str.begin();
		std::reverse(it+a,it+b+1);
	}
	else if(m=="replace"){
		int a,b;string p;
		cin>>a>>b>>p;
			for(int i=0;a<=b;i++){
				str[a]=p[i];
				a++;		
		}
	}
}

return 0;
}

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

int main() {
  int a[9];
  rep(i, 9) cin >> a[i];
  int n; cin >> n;
  int b[n];
  rep(i, n) cin >> b[i];
  
  rep(i, n) {
    rep(j, 9) {
      if (a[j] == b[i]) a[j] = 0;
      else continue;
    }
  }
  
  int l1, l2, l3, l4, l5, l6 ,l7 ,l8;
  l1 = a[0]+a[1]+a[2]; l2 = a[3]+a[4]+a[5];
  l3 = a[6]+a[7]+a[8]; l4 = a[0]+a[3]+a[6];
  l5 = a[1]+a[4]+a[7]; l6 = a[2]+a[5]+a[8];
  l7 = a[0]+a[4]+a[8]; l8 = a[2]+a[4]+a[6];
  if (l1==0||l2==0||l3==0||l4==0||l5==0||l6==0||l7==0||l8==0)
    cout << "Yes";
  else cout << "No";
}

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

int main() {

	int N,count=0,tmp=1; cin>>N;
  vector<int> A(N);
  for(int i=0; i<N;i++){
    cin>>A.at(i);}
  
  for(int i=0; i<N; i++){
  if(A.at(i)==tmp){count++;tmp++;}
  }
  
if(count==0){cout<<-1<<endl;}
  else{cout<<N-count<<endl;}
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
    string s;
    cin >> s;
    if (s == "SUN"){
        cout << 7 << endl;
    }else if(s == "MON"){
        cout << 6 << endl;
    }else if(s == "TUE"){
        cout << 5 << endl;
    }else if(s == "WED"){
        cout << 4 << endl;
    }else if(s == "THU"){
        cout << 3 << endl;
    }else if(s == "FRI"){
        cout << 2 << endl;
    }else if(s == "SAT"){
        cout << 1 << endl;
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	int n;
	cin >> n;
	long long int sum_a[200001] = {};
	for(int i = 0; i < n; i++){
		long long int a;
		cin >> a;
		if(i > 0) sum_a[i] = sum_a[i - 1];
		sum_a[i] += a;
	}
	long long int ans = (long long int)mod * 200001;
	for(int i = 0; i < n - 1; i++){
		ans = min(ans, abs(sum_a[i] - (sum_a[n - 1] - sum_a[i])));
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    ios::sync_with_stdio(false);
    int n,m,k;
    cin>>n>>m>>k;
    int ans=0;
    bool ar[n][m];
    for(int i=0;i<n;i++)for(int j=0;j<m;j++){
        char x;cin>>x;
        ar[i][j]= x == '#';
    }
    for(int i=0;i<(1<<n);i++){
        for(int j=0;j<(1<<m);j++){
            int cnt=0;
            for(int x=0;x<n;x++){
                for(int y=0;y<m;y++){
                    if(ar[x][y]&&(i&(1<<x))&&(j&(1<<y)))cnt++;
                }
            }
            if(cnt==k)ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

void solve(long long N)
{
    long long ans = 0;
    for (long long i = 1; i <= N; i++)
    {
        if (i % 3 != 0 && i % 5 != 0)
        {
            ans += i;
        }
    }

    cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long N;
    scanf("%lld", &N);
    solve(N);
    return 0;
}


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

long long gcd(long long a,long long b){
	if(a<b)swap(a,b);
	if(b==0)return a;
	return gcd(b,a%b);
}

long long lcm(long long a,long long b){
	return a/gcd(a,b)*b;
}

int main(){
	long long n,m;
	scanf("%lld%lld",&n,&m);
	long long arr[n];
	for(int i=0;i<n;i++){
		scanf("%lld",&arr[i]);arr[i]/=2;
	}
	long long l=1;
	for(int i=0;i<n;i++){
		l=lcm(l,arr[i]);
		if(m<l){printf("0");return 0;}
	}
	bool poss=1;
	for(int i=0;i<n;i++){
		if((l/arr[i])%2==0)poss=0;
	}
	if(!poss)printf("0");
	else{
		printf("%lld",((m/l)+1)/2);
	}
}

Measured memory_bytes: 1024
# s = input()
# n = int(input())
h1, m1, h2, m2, k = map(int, input().split())
# l = list(map(int, input().split()))
if m1 <= m2:
    t = (h2 - h1)*60 + m2 - m1
else:
    t = (h2 - h1 - 1)*60 + (60 - abs(m1 - m2))
# if t <= k:
#     print(0)
# elif t%k == 0:
#     print(t - k)
# else:
#     print(t - t%k)

print(max(0, t-k))

Measured memory_bytes: 9176
def write_and_erase(N: int, A: list)->int:
    d = {}
    for a in A:
        d.setdefault(a, 0)
        d[a] = (d[a] + 1) % 2

    return sum(v for v in d.values())


if __name__ == "__main__":
    N = int(input())
    A = [int(input()) for _ in range(N)]
    ans = write_and_erase(N, A)
    print(ans)


Measured memory_bytes: 16272
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int W = sc.nextInt();
		int H = sc.nextInt();
		int N = sc.nextInt();
		int[] x = new int[N];
		int[] y = new int[N];
		int[] a = new int[N];

		int xmin = 0;
		int xmax = W;
		int ymin = 0;
		int ymax = H;
		for (int i = 0; i < N; ++i) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
			a[i] = sc.nextInt();
			if (a[i] == 1) {
				xmin = Math.max(xmin, x[i]);
			} else if (a[i] == 2) {
				xmax = Math.min(xmax, x[i]);
			} else if (a[i] == 3) {
				ymin = Math.max(ymin, y[i]);
			} else if (a[i] == 4) {
				ymax = Math.min(ymax, y[i]);
			}
		}
		if (xmax > xmin && ymax > ymin)
			System.out.println((xmax - xmin) * (ymax - ymin));
		else {
			System.out.println(0);
		}
	}
}


Measured memory_bytes: 10320
N = int(input())
num = list(map(int,input().split()))
temp = list(map(int,input().split()))
ans=0
distance=1000000
for i in range(len(temp)):
	if(abs(num[1]-(num[0]-temp[i]*0.006))<distance):
		ans=i+1
		distance=abs(num[1]-(num[0]-temp[i]*0.006))
print(ans)

Measured memory_bytes: 3064
// {{{ by shik
#include <bits/stdc++.h>
#include <unistd.h>
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x),end(x)
#define REP(i,n) for ( int i=0; i<int(n); i++ )
#define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ )
#define FOR(it,c) for ( auto it=(c).begin(); it!=(c).end(); it++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

#ifdef SHIK
template<typename T>
void _dump( const char* s, T&& head ) { cerr<<s<<"="<<head<<endl; }

template<typename T, typename... Args>
void _dump( const char* s, T&& head, Args&&... tail ) {
    int c=0;
    while ( *s!=',' || c!=0 ) {
        if ( *s=='(' || *s=='[' || *s=='{' ) c++;
        if ( *s==')' || *s==']' || *s=='}' ) c--;
        cerr<<*s++;
    }
    cerr<<"="<<head<<", ";
    _dump(s+1,tail...);
}

#define dump(...) do { \
    fprintf(stderr, "%s:%d - ", __PRETTY_FUNCTION__, __LINE__); \
    _dump(#__VA_ARGS__, __VA_ARGS__); \
} while (0)

template<typename Iter>
ostream& _out( ostream &s, Iter b, Iter e ) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}

template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.first<<","<<p.second<<")"; }
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T, size_t N>
ostream& operator <<( ostream &s, const array<T,N> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
template<typename A, typename B>
ostream& operator <<( ostream &s, const map<A,B> &c ) { return _out(s,ALL(c)); }
#else
#define dump(...)
#endif

template<typename T>
void _R( T &x ) { cin>>x; }
void _R( int &x ) { scanf("%d",&x); }
void _R( long long &x ) { scanf("%" PRId64,&x); }
void _R( double &x ) { scanf("%lf",&x); }
void _R( char &x ) { scanf(" %c",&x); }
void _R( char *x ) { scanf("%s",x); }

void R() {}
template<typename T, typename... U>
void R( T& head, U&... tail ) {
    _R(head);
    R(tail...);
}

template<typename T>
void _W( const T &x ) { cout<<x; }
void _W( const int &x ) { printf("%d",x); }
template<typename T>
void _W( const vector<T> &x ) {
    for ( auto i=x.cbegin(); i!=x.cend(); i++ ) {
        if ( i!=x.cbegin() ) putchar(' ');
        _W(*i);
    }
}

void W() {}
template<typename T, typename... U>
void W( const T& head, const U&... tail ) {
    _W(head);
    putchar(sizeof...(tail)?' ':'\n');
    W(tail...);
}

#ifdef SHIK
#define FILEIO(...)
#else
#define FILEIO(name) do {\
    freopen(name ".in","r",stdin); \
    freopen(name ".out","w",stdout); \
} while (0)
#endif

// }}}

const int N=1e5+10;
int n;
VI e[N];

void dfs( int p ) {
    for ( int i:e[p] ) {
        e[i].erase(find(ALL(e[i]),p));
        dfs(i);
    }
}

int go( int p ) {
    int s=0;
    for ( int i:e[p] ) s^=go(i)+1;
    return s;
}

int main() {
    R(n);
    REP(i,n-1) {
        int a,b;
        R(a,b);
        e[a].PB(b);
        e[b].PB(a);
    }
    dfs(1);
    int sg=go(1);
    W(sg ? "Alice" : "Bob");
    return 0;
}


Measured memory_bytes: 10368