akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

ostream& operator<<(ostream& os, const pair<char, int>& unit) {
  return os << unit.first << "^" << unit.second;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, d1, d2;
  cin >> n >> d1 >> d2;
  function<vector<vi>(int)> calc = [&](int d) {
    vector<vi> ret(n * 2, vi(n * 2, -1));
    vector<pair<int, int>> v;
    for (int i = 0; i * i <= d; ++i) {
      int j = sqrt(d - i * i);
      if (i * i + j * j != d) continue;
      v.emplace_back(i, j);
      v.emplace_back(-i, j);
      v.emplace_back(i, -j);
      v.emplace_back(-i, -j);
    }
    function<void(int, int)> dfs = [&](int x, int y) {
      for (const auto& pr : v) {
        int xi = x + pr.first, yi = y + pr.second;
        if (xi >= 0 && xi < n * 2 && yi >= 0 && yi < n * 2 && ret[xi][yi] == -1) {
          ret[xi][yi] = !ret[x][y];
          dfs(xi, yi);
        }
      }
    };
    for (int i = 0; i < n * 2; ++i)
      for (int j = 0; j < n * 2; ++j)
        if (ret[i][j] == -1) {
          ret[i][j] = 0;
          dfs(i, j);
        }
    return ret;
  };
  vector<vi> r1 = calc(d1), r2 = calc(d2);
  vector<vi> res(n * 2, vi(n * 2));
  vi cn(4);
  for (int i = 0; i < n * 2; ++i)
    for (int j = 0; j < n * 2; ++j)
      ++cn[res[i][j] = r1[i][j] | (r2[i][j] << 1)];
  int v = max_element(cn.begin(), cn.end()) - cn.begin();
  int cnt = 0;
  for (int i = 0; i < n * 2; ++i) {
    for (int j = 0; j < n * 2; ++j)
      if (res[i][j] == v) {
        cout << i << ' ' << j << '\n';
        if (++cnt == n * n) break;
      }
    if (cnt == n * n) break;
  }

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


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

int main(void)
{
	int a, b;
	while (cin >> a >> b, a != 0 || b != 0)
		if (a < b){
			cout << a << " " << b << "\n";
		}else{
			cout << b << " " << a << "\n";
		}
		return 0;
}

Measured memory_bytes: 1160
N, Y = map(int, (input().split(' ')))
for x in range(N + 1):
  for y in range(N + 1 - x):
    if 10000 * x + 5000 * y + 1000 * (N - x - y) == Y:
      print(x, y, N-x-y)
      exit()
print('-1 -1 -1')

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main(){long long m=0,p=0,i;
string s;
cin>>s;
for(i=0;i<3;i++){
    if(s[i]=='A')
    m++;
    if(s[i]=='B')
    p++;
}if(m==0||p==0){
    cout<<"No";
}else
cout<<"Yes";
  return 0;
}


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

ll lcm(ll a,ll b){
  ll r,tmp,g,a2,b2;
  a2=a;
  b2=b;
  if(b==0){
    g=0;
  }else{
    if(a<b){
      tmp = a;
      a = b;
      b = tmp;
    }
 
  /* ユークリッドの互除法 */
    r = a % b;
    while(r!=0){
      a = b;
      b = r;
      r = a % b;
    }
    g=b;
  }
  
  return a2/g*b2;
}

int main(){
  ll n;
  ll ans=1;
  cin>>n;
  rep(i,n){
    ll t;
    cin>>t;
    ans=lcm(ans,t);
    
  }
  
  cout<<ans<<endl;
  
  
  
  
}



Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter

val br = BufferedReader(InputStreamReader(System.`in`))
val pw = PrintWriter(System.out)
fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    // 回答をここに書く
    val D = nextInt()
    val s = when {
        D == 25 ->"Christmas"
        D == 24 ->"Christmas Eve"
        D == 23 ->"Christmas Eve Eve"
        D == 22 ->"Christmas Eve Eve Eve"
        else -> ""
    }
    println(s)
}

// 入力取得
fun next() = br.readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() =listOfString().map { it.toInt() }
fun listOfLong() =listOfString().map { it.toLong() }
fun listOfDouble() =listOfString().map { it.toDouble() }

// 約数のList
fun divisor(value : Long) : List<Long> {
    val max = Math.sqrt(value.toDouble()).toLong()
    return (1..max)
        .filter { value % it == 0L }
        .map { listOf(it, value / it) }
        .flatten()
        .sorted()
}

// 範囲内の素数を取得
// fromだけ指定すると戻り値の個数で素数判定ができる
fun prime(from : Long, to : Long = from) : List<Long> {
    return (from..to).filter { i ->
        val max = Math.sqrt(i.toDouble()).toLong()
        (2..max).all { j ->  i % j != 0L }
    }
}

// 素因数分解
fun decom(value : Long) : List<Long>{
    if (value == 1L) return listOf(1)
    val max = Math.sqrt(value.toDouble()).toLong()
    return prime(2, max).filter { value % it == 0L }
}

// 最大公約数
fun gcd(a : Long, b : Long) : Long {
    return if (a % b == 0L) b else gcd(b, a % b)
}

// 文字列を入れ替え
fun swap(base : String, a : String, b : String) : String {
    return base.map {
        when (it) {
            a.toCharArray()[0] -> b
            b.toCharArray()[0] -> a
            else -> it.toString()
        }
    }.joinToString()
}

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 31260
#include <iostream>

using namespace std;

int main()
{
	int n;
	long long y;
	int yi;
	cin >> n;
	cin >> y;
	yi = y / 1000;
	if (yi / 10 == n && yi % 10 == 0)
	{
		cout << n << ' ' << 0 << ' ' << 0;
		return 0;
	}
	if (yi / 5 == n && yi % 5 == 0)
	{
		cout << 0 << ' ' << n << ' ' << 0;
		return 0;
	}
	if (yi == n)
	{
		cout << 0 << ' ' << 0 << ' ' << n;
		return 0;
	}
	yi -= n;
	int a = 0, b = 0, c = n;
	for (int i = 0; i <= n; ++i)
	{
		int yt = yi - b * 4;
		if (yt < 0)
			break;
		if (yt % 9 == 0)
		{
			int d9 = yt / 9;
			if (d9 <= c)
			{
				a = d9;
				c -= d9;
				cout << a << ' ' << b << ' ' << c;
				return 0;
			}
		}
		else
		{
			b++;
			c--;
		}
	}
	cout << "-1 -1 -1";
}

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

#define reps(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) reps(v, 0, n)
#define lep(v, n) reps(v, 1, n + 1)

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }
template<typename T> void show(T& a, char del='\n', char last='\n'){ rep(i, a.size() - 1) cout << a[i] << del; cout << a[a.size() - 1] << last; }

const int INF = 1 << 29;

int main()
{
  int g[128][128];
  rep(i, 128) rep(j, 128) g[i][j] = INF;
  rep(i, 128) g[i][i] = 0;
  int n = in();
  rep(i, n){
    int f = in() - 1;
    rep(j, in()){
      g[f][in() - 1] = 1;
    }
  }
  rep(k, n){
    rep(i, n){
      rep(j, n){
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
  rep(p, in()){
    int f, t, v;
    f = in() - 1;
    t = in() - 1;
    v = in();
    if (g[f][t] + 1 <= v) printf("%d\n", g[f][t] + 1);
    else puts("NA");
  }
  return 0;
}

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

bool is_square(int n)
{
    for (int i = 0; i <= n; i++)
    {
        if (i * i == n)
        {
            return true;
        }
    }
    return false;
}
double distance(double x1, double y1, double x2, double y2)
{
    return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

int main()
{
    int n,k;
    cin >> n >> k;
    ll ans=k;
    for (size_t i = 0; i < n-1; i++)
    {
        ans *= k - 1;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, int> P;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a)  (a).rbegin(),(a).rend()
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; }
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int n, m; cin >> n >> m;
    vector<P> c(n);
    rep(i, n)
    {
        cin >> c[i].first >> c[i].second;
    }
    sort(ALL(c));

    ll ans = 0;
    rep(i, n)
    {
        if (m >= c[i].second)
        {
            ans += c[i].second * c[i].first;
            m -= c[i].second;
        }
        else
        {
            ans += m * c[i].first;
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;

const int N=1e5+10;

int n,a[N];

int main()
{
	scanf("%d",&n);
	int m=0;
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		if(!m||x!=a[m]) a[++m]=x;
	}
	int Ans=1;
	int opt=a[2]>a[1];
	for(int i=3;i<=m;i++)
	{
		if((a[i]>a[i-1])!=opt)
		{
			opt=a[i+1]>a[i];
			Ans++;
		}
	}
	cout<<Ans<<endl;
	return 0;
}
	

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

using namespace std;

int main(){
    long long n;
    cin >> n;
    long long a = n, b = 0;
    
    for(int i = 1; i < n ; i++){
        if(i > (n / i))break;
        if(n % i == 0 && (i - 1) - (n / i) - 1 < a){
            b = i;
            a = (i - 1) + (n / i) - 1;
        }
    }
    cout << a << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> p(N);
  for(int i = 0; i < N; i++){
    cin >> p.at(i);
  }
  int sum = 0;
  for(int i = 0; i < N - 2; i++){
    int a = (p.at(i) - p.at(i + 1)) * (p.at(i + 1) - p.at(i + 2));
    if(a > 0){
      sum++;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
import math
def ip():return int(input())
def imp():return map(int,input().split())
def impstr():return map(str,input().split())
def limp():return list(map(int,input().split()))

n=ip()
t,a=imp()
h=limp()
index=0
ans=10**18
for i in range(n):
    if abs(a-(t-h[i]*0.006))<ans:
        ans=abs(a-(t-h[i]*0.006))
        index=i
print(index+1)


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define x first
#define y second
#define mod 1e9+7
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rof(i,a,b) for(ll i=a;i>b;i--)

ll lcm(ll a, ll b){
    return a / __gcd(a, b) * b;
}
//memset can initialize to 0 or -1 ONLY
// memset(a,0,sizeof(a[0][0])*n*n); //2D array
//memset(a, 0, sizeof(a));  //1D array
//memset(str, 't', sizeof(str)); // string
void solve()
{
 ll x,y,a,b,c;cin>>x>>y>>a>>b>>c;
vector<pair<int,int> > v;   
    f(i,0,a) {int h;cin>>h;
   	v.push_back(make_pair(h,0));
    }
    f(i,0,b) {int h;cin>>h;
    	v.push_back(make_pair(h,1));
    }
    f(i,0,c) {int h;cin>>h;
    	v.push_back(make_pair(h,2));
    }





    sort(v.begin(),v.end(),greater<pair<int,int>>());
    ll ans=0;
  //  f(i,0,a+b+c) cout<<v[i].first<<" "<<v[i].second<<endl;
    //x 0 wale // y 1 wale
   // cout<<"---------------------------";
int xx=0,yy=0,cl=0;
    f(i,0,a+b+c)
    {

    	if(v[i].second==0)
    	{
    		if(xx>=x) continue;
    		ans+=v[i].first;
    		xx++;
    	}
    	else if(v[i].second==1)
    	{

    		if(yy>=y) continue;
    		ans+=v[i].first;
    		yy++;
    	}
    	else
    	{
    		ans+=v[i].first;
    		cl++;
    	}

//cout<<" "<<v[i].first<<"  "<<v[i].second<<endl;
    	if(xx+yy+cl>=x+y)
    		break;
    }
    cout<<ans;
}


int main()
{

ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll t=1;
   // cin>>t;
    while(t--)
    {
    
    solve();
    
    }

}

Measured memory_bytes: 6512
#include "bits/stdc++.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define repr(i,a,n) for(ll i = n-1;i >= a;i--)
#define LINF (ll)1e17
#define INF (int)1e9
#define MOD (ll)1e9+7
#define sMOD 1e5
#define fs first
#define sc second

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
	
}

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





signed main(){
	ll n;
	cin >> n;
	ll a[n];

	rep(i,0,n){
		ll m;
		cin >> m;
		a[m-1] = i+1;
	}

	rep(i,0,n) cout << a[i] << " ";
	cout << endl;
    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1e9;
const int MOD = 1e9+7;

void print() { cout << endl; }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head << ((sizeof...(tail)!=0)?" ":""); print(forward<Tail>(tail)...); }
template <class T> void print(vector<T> &vec) { for (auto& a : vec) { cout << a << ((&a!=&vec.back())?" ":""); } cout << endl; }
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec); } }

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

    int n, m, x; cin >> n >> m >> x;
    vector<int> cost(n);
    vector<vector<int>> skill(n, vector<int>(m));
    rep(i, n) {
        cin >> cost[i];
        rep(j, m) cin >> skill[i][j];
    }
    // print(skill);

    int ans = INF;
    rep(bit, 1<<n) {
        int tmp = 0;
        vector<int> rikaido(m, 0);
        rep(i, n) {
            if (bit & 1<<i) {
                tmp += cost[i];
                rep(j, m) rikaido[j] += skill[i][j];
            }
        }
        bool ok = true;
        rep(i, m) if (rikaido[i]<x) ok = false;
        if (ok) ans = min(ans, tmp);
    }

    if (ans==INF) cout << -1 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N,D;
    cin>>N>>D;
    int count=0;
    for(int i=0;i<N;i++){
        vector<double>vec(2);
        cin >> vec.at(0)>>vec.at(1);
        double A=sqrt(vec.at(0)*vec.at(0)+vec.at(1)*vec.at(1));
        if (D>=A){
            count ++;
        }
    }
    cout << count <<endl;
}

Measured memory_bytes: 3780
while True:
    List = input().split()

    a = int(List[0])
    op = List[1]
    b = int(List[2])

    if op == "?":
        break
    elif op == "+":
        print("%d"%(a+b))
    elif op == "-":
        print("%d"%(a-b))
    elif op == "*":
        print("%d"%(a*b))
    elif op == "/":
        print("%d"%(a/b))


Measured memory_bytes: 5596
"use strict"
function main(arg) {
    var s = arg.trim().split("\n")[0]
    s = s.split('')
    var bk = ''
    var isSuccess = true
    for (var i = 0; i < s.length; i++) {
        if (s[i] === bk) {
            isSuccess = false
        }
        bk = s[i]
    }
    if (isSuccess) {
        console.log('Good')
    } else {
        console.log('Bad')
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
#include <cstdio>
#include <algorithm>
using namespace std;

int n;
int maxcnt;
int cnt[101];

int main() {
  while (1) {
    if (scanf("%d", &n) != 1) break;
    cnt[n]++;
    maxcnt = max(maxcnt, cnt[n]);
  }

  for (int i=1; i<=100; i++) {
    if (maxcnt == cnt[i]) {
      printf("%d\n", i);
    }
  }
}

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

using namespace std;

#define ll long long

const int N=1e6+5;

int n,freq[N],a[N],k,tc,x,m,l,r,sum,ans,u,v;

char s[N];

int main(){
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int m,d;
    scanf("%d%d",&m,&d);
    for(int i=1;i<=m;i++){
        for(int j=22;j<=d;j++){
            if (j%10<2)
                continue;
            if ((j%10) * ((j/10)%10) == i)
                ans++;
        }
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 256
from functools import lru_cache
import math


@lru_cache(maxsize=None)
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    return a*b//gcd(a, b)


def lcm_all(lst):
    curr = 1
    for l in lst:
        curr = lcm(curr, l)
    return curr


def divide_count(x):
    ans = 0
    while True:
        q, r = divmod(x, 2)
        if r == 0:
            ans += 1
            x = q
        else:
            break
    return ans



def submit():
    n, m = map(int, input().split())
    alist = list(map(int, input().split()))

    a_divide_count = [divide_count(a) for a in alist]
    for a in a_divide_count[1:]:
        if a != a_divide_count[0]:
            print(0)
            return

    l = lcm_all(alist)
    x = l // 2
    if x > m:
        print(0)
    else:
        print(math.ceil(m // x / 2))


if __name__ == "__main__":
    submit()

Measured memory_bytes: 14868
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> H(N);
    rep(i, N) cin >> H[i];
    vector<bool> vec(N, true);
    rep(i, M) {
        int A, B;
        cin >> A >> B;
        if (H[A - 1] <= H[B - 1]) vec[A - 1] = false;
        if (H[B - 1] <= H[A - 1]) vec[B - 1] = false;
    }
    int ans = 0;
    rep(i, N) if (vec[i] == true) ans += 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3788
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <list>
#include <set>
#include <queue>
#include <iterator>
#include <bitset>
#include <bits/stdc++.h>
#include <vector>
#include <cctype>
#include <algorithm>
#define ll             long long
#define _              ios_base::sync_with_stdio(0);cin.tie(0);
#define loop           for(i=0;i<n;i++)
#define pb             push_back
#define tc()           int t;cin>>t;while(t--) 
#define pi             acos(-1)         
 
using namespace std;
 
ll i,j,temp;

 
int main()
{_
    
   int n;
   cin>>n;
   temp = n%10;

   if(temp==2 || temp==4 || temp==5 || temp==7 || temp==9 ){
   		cout<<"hon"<<endl;
   }
   else if(temp==0 ||temp==1 ||temp==6 ||temp==8){
   	cout<<"pon"<<endl;
   }
   else{
   	cout<<"bon"<<endl;
   }
 
return 0;
}

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

int main(){
	string s;
	cin>>s;
	
	int cnt=15-s.size();
	REP(i,s.size()){
		if(s[i]=='o') cnt++;
	}
	
	if(cnt>=8) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define isz(x) (int)(x).size()
using vi = std::vector<int>;
using vvi = std::vector<vi>;
int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0);
	for (int n, s, t; std::cin >> n >> s >> t; ) {
        vvi adj(1+n);
        for (int i = 1; i < n; i++) {
            int u, v; std::cin >> u >> v;
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        auto bfs = [&](int u) {
            vi dist(1+n, 10*n);
            dist[u] = 0;
            std::queue<int> queue;
            queue.push(u);
            while (isz(queue)) {
                u = queue.front(); queue.pop();
                for (int v : adj[u]) {
                    if (dist[v] > dist[u] + 1) {
                        dist[v] = dist[u] + 1;
                        queue.push(v);
                    }
                }
            }
            return dist;
        };
        auto dist_s = bfs(s);
        auto dist_t = bfs(t);
        int answ = -1;
        for (int i = 1; i <= n; i++) {
            if (dist_s[i] < dist_t[i]) {
                int curr;
                if (isz(adj[i]) == 1) {
                    curr = dist_t[i] - 1;
                } else {
                    curr = dist_t[i];
                }
                if (answ < curr) answ = curr;
            }
        }
        assert(answ != -1);
        std::cout << answ << std::endl;
    }
}

Measured memory_bytes: 6656
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class F { public static void Main() => (new Solver()).Solve(); }

public class Solver
{
	public void Solve()
	{
		long N = GetLong();
		long cnt = 0;
		for(long i = 0; i < N; i++)
			cnt += (i + 1) * (N - i);

		for(long i = 0; i < N - 1; i++)
		{
			long u = GetLong() - 1;
			long v = GetLong() - 1;
			cnt -= (Min(u, v) + 1) * (N - Max(u, v));
		}
		WriteLine(cnt);
	}
}

public static class MyIO
{
	private static string[] args = new string[0];
	private static int cnt = 0;
	private static IEnumerable<string> getArgs(long N) => Range(0, N).Select(_ => getArg());
	private static string getArg()
	{
		if(cnt == args.Length) { args = Console.ReadLine().Split(); cnt = 0; }
		return args[cnt++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray();
	public static long[] GetLongs(long N) => getArgs(N).Select(long.Parse).ToArray();
	public static double[] GetDoubles(long N) => getArgs(N).Select(double.Parse).ToArray();
	public static decimal[] GetDecimals(long N) => getArgs(N).Select(decimal.Parse).ToArray();
	public static string[] GetStrings(long N) => getArgs(N).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) < 0) x = y; }
	public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) > 0)	x = y; }
	public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; }
	public static long rightShift(long x, long y) => (x >> (int)y);
	public static long leftShift(long x, long y) => (x << (int)y);
	public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L;
	public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
	public static long lcm(long x, long y) => (x / gcd(x,y)) * y;	
	public static IEnumerable<int> Range(long start, long count) => Enumerable.Range((int)start, (int)count);
	public static void Sort(this List<string> source) => source.Sort(StringComparer.Ordinal);
}


Measured memory_bytes: 45968
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
int main(){
int a=read(),b=read(),c=read();
ll k;read(k);
write(k&1?b-a:a-b);
}

Measured memory_bytes: 256
/*
* @Author: kabbo
* @Date:   2020-05-10 18:03:01
* @Last Modified by:   kabbo
* @Last Modified time: 2020-05-10 18:11:22
*/
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define endl '\n'
#define ull unsigned long long
#define ll long long
const int mod = 1e9 + 7;
using u64 = uint64_t;
using u128 = __uint128_t;
void solve() {
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	ll sum = 0;
	sum += k >= a ? a * 1 : k * 1;
	k -= a;
	sum += k >= 0 && k >= b ? 0 : 0;
	k -= b;
	if (k >= 0)
		sum += (k * (-1));
	cout << sum << endl;

}
int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	/*int t;
	cin >> t;
	for (int i(1); i <= t; ++i) {
		printf("Case %d: ", i);*/
	solve();
	//}
#ifndef LOCAL_DEFINE
	cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
#endif
	return 0;
}

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

#define range(i, l, r) for (int i = (int)l; i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = ((int)(r) - 1); i >= (int)l; --(i))

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define rwhole(f,x,...) ([&](decltype((x)) whole) { return (f)(rbegin(whole), rend(whole), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using int32 = int;
using int64 = long long;

const int mod     = 1e9 + 7;
const int32 inf   = 1001001001;
const int64 infll = 1001001001001001001ll;

const int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}, dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const string YES = "YES", NO = "NO", Yes = "Yes", No = "No", yes = "yes", no = "no";

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(16); cerr << fixed << setprecision(16); } } iosetup;

template <typename T = int64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }

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

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solver() {
  int N = input(), M = input();

  int l = 0, r = inf;
  range(i, 0, M) {
    int L = input(), R = input();
    
    chmax(l, L);
    chmin(r, R);
  }

  cout << max(0, r - l + 1) << endl;
}

signed main(int argc, char *argv[]) {
  solver();
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int a[3][3];
int d[3][3];
int main() {
rep(i,3)rep(j,3){
  cin >> a[i][j];
	}
	int n;
	cin >> n;
	for (int ni = 0; ni < n; ni++) {
		int x;
		cin >> x;
		rep(i, 3)rep(j, 3) if(a[i][j] == x) d[i][j] = 1;
	}

	bool ans = false;
	rep(i, 3) {
		int cnt = 0;
		rep(j, 3) cnt += d[i][j];
		if (cnt == 3) ans = true;
	}
	rep(i, 3) {
		int cnt = 0;
		rep(j, 3) cnt += d[j][i];
		if (cnt == 3) ans = true;
	}	
	{
		int cnt = 0;
		rep(j, 3) cnt += d[j][j];
		if (cnt == 3) ans = true;
	}
	{
		int cnt = 0;
		rep(j, 3) cnt += d[j][2-j];
		if (cnt == 3) ans = true;
	}
	puts(ans ? "Yes" : "No");
	return 0;
	
}

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

int n;
queue <pair <int,int>> q;
map <int,int> dp;

void add(int x,int l)
{
	x%=n;
	q.push({x,l});
	dp[x]=l;
}

int main()
{
	cin>>n;
	if(n==7) return 0 * printf("1");

	add(7,1);
	while(not q.empty())
	{
		auto p=q.front();
		q.pop();

		int val=(10ll*p.first+7)%n;
		if(dp.find(val)==dp.end()) add(val,p.second+1);
	}

	if(dp.find(0)!=dp.end()) cout<<dp[0];
	else cout<<-1;
}

Measured memory_bytes: 50420
#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <cmath>


using namespace std;


typedef long long ll;
typedef long double ld;


const ll MOD_CONST = 1000000007ll;


ll modSum(ll a, ll b, ll MOD = MOD_CONST) {
  return ((a % MOD) + (b % MOD)) % MOD;
}


ll modSubtract(ll a, ll b, ll MOD = MOD_CONST) {
  return (((a % MOD) - (b % MOD)) + MOD + MOD) % MOD;
}


ll modProd(ll a, ll b, ll MOD = MOD_CONST) {
  return ((a % MOD) * (b % MOD)) % MOD;
}


ll getPowMod(ll x, ll e, ll MOD = MOD_CONST) {
  if (e == 0) return 1;
  if (e % 2 == 0) {
    ll tmp = getPowMod(x, e/2, MOD);
    return modProd(tmp, tmp);
  } else {
    ll tmp = getPowMod(x, e-1, MOD);
    return modProd(tmp, x);
  }
}


ll getPow(ll x, ll e) {
  if (e == 0) return 1;
  if (e % 2 == 0) {
    ll tmp = getPow(x, e/2);
    return tmp * tmp;
  } else {
    ll tmp = getPow(x, e-1);
    return tmp * x;
  }
}


ll getInverse(ll x, ll MOD = MOD_CONST) {
  return getPowMod(x, MOD-2, MOD);
}


bool isEven(ll x) {
  ll tmp = ((x % 2) + 2) % 2;
  return tmp == 0;
}


ll getSumOfDigitsInBase(ll n, ll b) {
  ll ret = 0;
  while (n > 0) {
    ret += n % b;
    n /= b;
  }
  return ret;
}


vector<int> getKMP(string &s) {
  int len = (int)s.size();
  vector<int> ret (len, 0);
  for (int i = 1 ; i < len ; i++) {
    int at = ret[i-1];
    while (at > 0 && s[i] != s[at]) {
      at = ret[at-1];
    }
    if (s[i] == s[at]) {
      at++;
    }
    ret[i] = at;
  }
  return ret;
}


string getSubstring(string &s, int from, int to) {
  int l = to-from+1;
  if (l <= 0) {
    return "";
  }
  return s.substr(from, l);
}

ll gcd(ll a, ll b, ll & x, ll & y) {
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    ll x1, y1;
    ll d = gcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}


pair<ll, ll> getIntersectingRange(ll a1, ll b1, ll a2, ll b2) {
  ll s = max(a1, a2);
  ll e = min(b1, b2);

  return {s, e};
}


bool isNonEmptyIntersection(ll a1, ll b1, ll a2, ll b2) {
  auto p = getIntersectingRange(a1, b1, a2, b2);
  return p.first <= p.second;
}


double getPointDistance(double x1, double y1, double x2, double y2) {
  double dx = x1-x2;
  double dy = y1-y2;
  double d = (dx * dx) + (dy * dy);
  return sqrt(d);
}


bool isPrime(ll x) {
  if (x == 2 || x == 3 || x == 5 || x == 7) return true;
  if (x < 10) return false;
  ll till = min((ll)sqrt(x) + 1, x-1);
  for (ll i = 2 ; i <= till ; i++) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}
















ll x;


void input() {
  cin >> x;
}


void preprocess() {
}


void solve() {
  ll ans = 2 * (x / 11);
  ll rem = x % 11;
  if (rem > 0) {
    ans += 1 + (rem / 7);
  }
  cout << ans;
}


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

  int T;
//  cin >> T;
  T = 1;

  for (int i = 0 ; i < T ; i++) {
    input();
    preprocess();
    solve();
  }

  return 0;
}


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

int main()
{
	int n;
	int seq[16];
	int tmp[16];
	while(cin>>n,n){
		for(int i=0; i<n; i++)
			cin>>seq[i];
			
		int ans = 0;
		int k;
		do{
			map<int,int> mii;
			for(int i=0; i<n; i++)
				tmp[i] = seq[i];
			for(int i=0; i<n; i++)
				mii[seq[i]]++;
				
			for(int i=0; i<n; i++)
				seq[i] = mii[seq[i]];
			
			ans++;
			for(k=0; k<n && seq[k]==tmp[k]; k++)
				;
		}while( k!=n );
		
		printf("%d\n",ans-1);
		for(int i=0; i<n; i++){
			if( i==0 )
				printf("%d",seq[i]);
			else
				printf(" %d",seq[i]);
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
using namespace std;
//const ll llf=(1ll<<63)-1;
typedef long long ll;
const ll llf=(1ll<<63)-1;
ll dp[2010][2010];ll a[2010];
int main()
{
    ll n,x;
    cin>>n>>x;
    int i;
    for(i=1;i<=n;i++)
        cin>>a[i];
    int k;
    for(i=1;i<=n;i++)
        dp[i][0]=a[i];
    for(k=1;k<n;k++)
    {
        for(i=1;i<=n;i++)
        {
            int temp=i-k;
            if(temp<=0) temp+=n;
            dp[i][k]=min(dp[i][k-1],(ll)a[temp]);
        }
    }
    ll sum=0;ll ans=llf;
    for(i=0;i<n;i++)
    {
        sum=0;
        for(int j=1;j<=n;j++)
            sum+=dp[j][i];
        sum+=i*x;
        ans=min(ans, sum);
    }
    cout<<ans<<endl;
    return 0;
}

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

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

const long long INF = 1LL << 60;

//入力
double N;
int cnt,ans = 10000000;
int a[150];


int main(){
    cin >> N;
    rep (i,N) {
        cin >> a[i];
    }
    for (int i = -100; i <= 100; i++){
        cnt = 0;
        rep (j,N){
            cnt += pow(abs(a[j] - i),2);
        }
        ans = min(ans,cnt);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

    vector<int> W(n);
    vector<int> V(n);
    
    int maxV = 0;
    for(int i = 0; i < n; i++)
    {
        cin >> W[i] >> V[i];
        maxV += V[i];
    }
    
    vector<vector<ll>> dp(n+1,vector<ll>(maxV+1,w+1));
    
    for(int i = 0; i <= n; i++)
    {
        dp[i][0] = 0;
    }

    for(int i = n-1; i >= 0; i--)
    {
        for(int j = 1; j <= maxV; j++)
        {
            if(j >= V[i])
            {
                dp[i][j] = min(dp[i+1][j-V[i]]+W[i],dp[i+1][j]);
            }
            else
            {
                dp[i][j] = dp[i+1][j];
            }
        }
    }
    
    for(int i = maxV; i >= 0; i--)
    {
        if(dp[0][i] <= w)
        {
            cout << i << '\n';
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll n, k;
	cin >> n >> k;
	
	vector<P> v, iv;
	for(ll i = 1; i*i <= n; i++){
		v.push_back(P(i, 1));
		iv.push_back(P(n/i, n/i));
	}
	
	ll m = v.size();
	zep(i, 0, m-1){iv[i].second -= iv[i+1].second;}
	zep(i, 0, m){iv[m-1].second -= v[i].second;}
	
	ll dp[k][2*m];
	zep(i, 0, m){dp[0][i] = v[i].second;}
	zep(i, 0, m){dp[0][2*m-1-i] = iv[i].second;}
	m *= 2;

	zep(i, 1, k){
		ll sm = 0;
		zep(j, 0, m){
			sm += dp[i-1][j];
			sm %= MOD;
			dp[i][m-1-j] = sm;
		}
		
		zep(j, 0, m){
			dp[i][j] *= dp[0][j];
			dp[i][j] %= MOD;
		}
	}
	
	ll ans = 0;
	zep(j, 0, m){
		ans += dp[k-1][j];
		ans %= MOD;
	}
	print(ans)
	return 0;
}

Measured memory_bytes: 50932
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;
int main()
{
	int n, a, b, i, j, k, x;
	scanf("%d%d", &a, &b);
	
	for (i = b - a + 1; i <= b; i++)
		printf("%d ", i);
	if (a != 1)
	{
		for (i = b + 1; i <= a + b - 1; i++)
			printf("%d ", i);
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define MAX (100000)
#define pii pair<int, int>

/////////////////////////////////////////////////////////

class XY{
public:
  ll x, y;
  XY() {x = y = 0;}
  XY(ll u, ll v) {x = u; y = v;}
};

template<typename T1, typename T2>
void chmin(T1 &a, T2 b) {if(a > b) a = b;}
template<typename T1, typename T2>
void chmax(T1 &a, T2 b) {if(a < b) a = b;}

template<typename T1, typename T2>
ll mypow(T1 a, T2 n){
  if(n == 0) return 1;
  if(n == 1) return a;
  if(n % 2) return a * mypow(a, n - 1);
  ll tmp = mypow(a, n / 2);
  return tmp * tmp;
}

template<typename T>
int BS(vector<T> V, int left, int right, T key){
  int mid = (left + right) / 2;
  if(V[mid] <= key) left = mid;
  else right = mid;
  if(right - mid == 1) return left;
  else return BS(V, left, right, key);
}

ll comb(ll n, ll r){
	ll res = 1;
  rep(i, 0, r){
    res *= n - i;
    res /= i + 1;
  }
  return res;
}

/////////////////////////////////////////////////////////

void Main() {
  int N; string S, T; cin >> N >> S >> T;
  int res = 2 * N;
  rep(i, 0, N){
    if(S.substr(i, N - i) == T.substr(0, N - i)){
      res = N + i;
      break;
    }
  }
  cout << res << endl;
}

/////////////////////////////////////////////////////////

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << std::fixed << std::setprecision(15);

  Main();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<58;
const ll mod=1e9+7;

int main(){
  ll i,j;
  ll n;
  cin>>n;
  ll ans=INF;
  for(i=1;i*i<=n;i++){
    if(n%i==0){
      ans=min(ans,i+n/i);
    }
  }
  cout<<ans-2<<endl;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
q=[0 for q in range(n)]
t=[0 for q in range(n)]
p=[]
x=0
for i in range(m):
    a=list(input().split())
    p.append(a)
    a[0]=int(a[0])
    if a[1]=="AC":
        q[a[0]-1]=1
    else:
        if q[a[0]-1]==0:
            t[a[0]-1]+=1
            
for i in range(n):
    if q[i]==1:
        x+=t[i]
print(str(q.count(1))+" "+str(x))

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

using ll = long long; 

int main() {
  int a,b;
  string s,t,u;
  cin >> s >> t >> a >> b >> u;

  if (u == s) {
    a--;
  }
  else {
    b--;
  }
  
  cout << a << ' ' << b << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int l;
    while(cin >> l, l){
        int sum = 0, ans = -1;
        rep(i,12){
            int m,n;
            cin >> m >> n;
            sum+= (m - n);
            if(l <= sum && ans == -1){
                ans = i + 1;
            }
        }
        if(ans == -1) cout << "NA" << endl;
        else cout << ans << endl;
    }
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <new>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <iomanip>
#include <limits>
#include <numeric>
#include <type_traits>

typedef long long ll;
typedef long double ld;

using namespace std;
using Graph = vector<vector<ll>>;

#define rep(i, N) for (ll i = 0; i < (ll)(N); ++i)
#define ALL(a) (a).begin(),(a).end()

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

ll fac(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

int main(){
    ll N,b=0,sum=0;
    cin >> N;
    for(ll i=1;sum<N;i++){
        sum += i;
        if(sum>=N){
            b=i;
            break;
        }
    }

    for(ll i=1;i<b+1;i++){
        if(sum-N!=i){
        cout << i << endl;
        }
    }
    return 0;
}

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

using namespace std;

#define llong long long int
#define ldouble long double
#define ternary(condition, x, y) ((condition) ? x : y) 
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) x.begin(), x.end()
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)

const static llong MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    llong n, m;
    cin >> n >> m;

    llong sub_ans_x = 0;
    for (int i = 1; i <= n; ++i) {
        llong x;
        cin >> x;
        sub_ans_x += (i - 1) * x - (n - i) * x;
        sub_ans_x %= MOD;
    }

    llong sub_ans_y = 0;
    for (int i = 1; i <= m; ++i) {
        llong y;
        cin >> y;
        sub_ans_y += (i - 1) * y - (m - i) * y;
    }

    llong ans = (sub_ans_x % MOD) * (sub_ans_y % MOD);

    cout << ans % MOD << endl;

    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

var inf = 100000000000

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	a := make([]int, n)
	b := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	c := make([]int, m)
	d := make([]int, m)
	for i := 0; i < m; i++ {
		fmt.Scan(&c[i], &d[i])
	}

	for i := 0; i < n; i++ {
		min := inf
		ans := 0
		for j := 0; j < m; j++ {
			distance := abs(a[i]-c[j]) + abs(b[i]-d[j])
			if distance < min {
				min = distance
				ans = j + 1
			}
		}
		fmt.Println(ans)
	}
}


Measured memory_bytes: 512
/****************************
/////  Shubham Singhal
/////  LNMIIT
*****************************/
#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define lwr lower_bound
#define upr upper_bound
#define pq priority_queue
#define umap unordered_map
#define rep(i,n) for(i=0; i<n;i++)
#define repp(i,a,n) for(i=a; i<n;i++)
#define precise(x) cout<<fixed<<setprecision(x)
#define all(x) x.begin(),x.end()
#define lcm(a,b) (a*b)/__gcd(a,b)
#define prn(x) cout<<x<<"\n"
#define prn2(x, y) cout<<x<<" "<<y<<"\n"
#define prn3(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define prn4(x, y, z, a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<"\n"
#define prnv(x) for(auto i:x) cout<<i<<" "; cout<<"\n"
#define MOD 1000000007
#define MAX 300005
using namespace std;
 
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd; 
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;
const long long INF64 = 1'000'000'000'000'000'000ll;
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
void doc()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
}
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
}
int N, C[3<<17], D[3<<17], F[3<<17];
 
int main(){
    cin>>N;
    for(int i = 0;i < N; i++){
        int x; cin>>x;
        C[x]++;
    }
    for(int i = 0; i <= N; i++)D[C[i]]++;
    ll L = 0, R = 0;
    for(int i = 1; i <= N; i++) R+=D[i];
    for(int x = 1; x <= N; x++){
        R -= D[x];
        L += x*D[x];
        F[x]=(L+R*x)/x;
    }
    int id = N;
    for(int K = 1; K <= N; K++){
        while(id>0 && F[id]<K) id--;
        cout<<id<<endl;
    }
    return 0;
}

Measured memory_bytes: 4224
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    int a[3],k;
    cin>>a[0]>>a[1]>>a[2]>>k;
    sort(a,a+3);
    for(int i=0;i<k;i++){
        a[2]=a[2]*2;
    }
    cout<<a[0]+a[1]+a[2]<<endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static long N, K;
    static long[] a, b;

    public static void Main(string[] args)
    {
        //checked
        {
            {
                var input = Console.ReadLine().Split();
                N = long.Parse(input[0]);
                K = long.Parse(input[1]);
            }
            a = new long[N];
            b = new long[N];
            for (int i = 0; i < N; i++)
            {
                var input = Console.ReadLine().Split();
                a[i] = int.Parse(input[0]);
                b[i] = int.Parse(input[1]);
            }

            var slot = new long[a.Max()+1];

            for (int i = 0; i < N; i++)
            {
                slot[a[i]] += b[i];
            }
            
            long k = 0;
            long ans;
            for (ans = 0; ans < slot.Length; ans++)
            {
                k += slot[ans];
                if (k >= K)
                    break;
            }

            Console.WriteLine(ans);
        }
    }
}


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

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string>vst;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef map<int,int> dct;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define all(ct) ct.begin() , ct.end()
#define endl "\n"
#define fr(i,a) for(auto i:a)
#define f(i,a,b) for(int i=a;i<b;++i)
#define fd(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define in(d,v) d.find(v)!=d.end()
#define mp make_pair
#define pi 3.14159265

bool compare(pair<pii,vector<int>> a, pair<pii,vector<int>> b){
    if(a.first.first*b.first.second==a.first.second*b.first.first)
        return a.first.second>b.first.second;
    return a.first.first*b.first.second<a.first.second*b.first.first;
}

const int mod = 1e9 + 9;
const ll inf = ll(1e18);

ll modexp(ll x,ll n){
    if(n==0)return 1;
    if(n%2==0)return modexp((x*x)%mod,n/2);
    return (x*modexp((x*x)%mod,n/2))%mod;
}
vl dp(1e7+1);
int main(){
    fastio;
    int a,b;
    cin>>a>>b;
    if(a>b)swap(a,b);
    if(a==1 and b==3)cout<<2<<endl;
    else if(a==2)cout<<1<<endl;
    else if(b==2)cout<<3<<endl;
}

Measured memory_bytes: 78336
a,b,c,d= readlines.map(&:to_i)
cnt = 0
 (0..a).each do |i|
  (0..b).each do |j|
    (0..c).each do |k|
      cnt += 1 if d == 500 * i + 100 * j + 50 * k
   end
  end
end
puts cnt

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	vector<string>t={"maerd"s,"remaerd"s,"esare"s,"resare"s};
	string s;
	cin>>s;
	reverse(s.begin(),s.end());
	int i,j;
	for(i=0,j=0;i<t.size();++i){
		string s2=s.substr(j,t.at(i).size());
		if(s2==t.at(i)){
			j+=t.at(i).size();
			i=-1;
		}
	}
	if(j==s.size())cout<<"YES\n"s;
	else cout<<"NO\n"s;
}

Measured memory_bytes: 512