akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <deque>
#include <queue>
#include <set>
#include <functional>
#include <cmath>
#include <set>
#include <map>


//マクロ
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)
#define All(a) (a).begin(),(a).end()
#define RAll(a) (a).rbegin(),(a).rend()
#define dump(x)  cerr << #x << " = " << (x) << endl;

//定数
#define INF 1e9
#define INFL 1e18
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
using Graph = vector<vector<int>>;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数

//使用する関数
template<class T>bool chmax(T &a, const T &b) {
	if (a < b) { a = b; return 1; }
	return 0;
}
template<class T>bool chmin(T &a, const T &b) {
	if (a > b) { a = b; return 1; }
	return 0;
}

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

	int n;
	cin >> n;

	cout << (1000 - n%1000)%1000 << endl;
}

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

int main()
{
 int N;
 int K;
 int x[100005];
 int dist[100005];
 int distm;
 int distp;
 int mindist=2000000005;
 int i;

 scanf("%d %d",&N,&K);
 for(i=0;i<K-1;i++) scanf("%d",&x[i]);

 for(i=K-1;i<N;i++)
 {
  scanf("%d",&x[i]);
  if(x[i-K+1]>=0) dist[i-K+1]=x[i];
  if(x[i]<=0) dist[i-K+1]=-x[i-K+1];
  if((x[i]>=0)&(x[i-K+1]<=0))
  {
    distp=2*x[i]-x[i-K+1];
    distm=x[i]-2*x[i-K+1];
    if(distp>distm) 
    {
      dist[i-K+1]=distm;
    }else{
      dist[i-K+1]=distp;
    }
  }
  if(mindist>dist[i-K+1]) mindist=dist[i-K+1];
 }

 printf("%d\n",mindist);
 return 0;
}


Measured memory_bytes: 768
BIG_NUM = 2000000000


N = int(input())
x = 0

for i in range(1,N+1):

    if i%3 == 0:
            print(" %d"%i,end = "");
    else:
        x = i
        while (x):
            if x%10 == 3:
                print(" %d"%i,end = "")
                break
            x //= 10
print()



Measured memory_bytes: 5872
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

struct Vector2{
	int x;
	int y;
};

Vector2 pos[10000];

bool map[5001][5001];

Vector2 add_v(Vector2 a, Vector2 b){
	Vector2 res;
	res.x = a.x + b.x;
	res.y = a.y + b.y;
	return res;
}

Vector2 decr_v(Vector2 a, Vector2 b){
	Vector2 res;
	res.x = a.x - b.x;
	res.y = a.y - b.y;
	return res;
}

int norm2_v(Vector2 v){
	return (v.x * v.x + v.y * v.y);
}

Vector2 rotate90(Vector2 pos){
	Vector2 hoge;
	hoge.x = -pos.y;
	hoge.y = pos.x;
	return hoge;
}

Vector2 rotate270(Vector2 pos){
	Vector2 hoge;
	hoge.x = pos.y;
	hoge.y = -pos.x;
	return hoge;
}

bool checker(Vector2 pos1, Vector2 pos2, bool map[5001][5001]){
	Vector2 pos3, pos4, diff1, diff2;
	diff1 = decr_v(pos2, pos1);
	diff2 = decr_v(pos1, pos2);
	pos3 = add_v(pos1, rotate90(diff1));
	pos4 = add_v(pos2, rotate270(diff2));
	if(pos3.x >= 0 && pos3.x <= 5000 && pos3.y >= 0 && pos3.y <= 5000 && pos4.x >= 0 && pos4.x <= 5000 && pos4.y >= 0 && pos4.y <= 5000){
		if(map[pos3.x][pos3.y] && map[pos4.x][pos4.y]){
			return true;
		}
	}
	pos3 = add_v(pos1, rotate270(diff1));
	pos4 = add_v(pos2, rotate90(diff2));
	if(pos3.x >= 0 && pos3.x <= 5000 && pos3.y >= 0 && pos3.y <= 5000 && pos4.x >= 0 && pos4.x <= 5000 && pos4.y >= 0 && pos4.y <= 5000){
		if(map[pos3.x][pos3.y] && map[pos4.x][pos4.y]){
			return true;
		}
	}
	return false;
}

int main(){
	int n;
	while(true){
		cin >> n;
		if(n == 0){
			break;
		}
		
		for(int i = 0; i <= 5000; i++){
			for(int j = 0; j <= 5000; j++){
				map[i][j] = false;
			}
		}
		
		for(int i = 0; i < n; i++){
			cin >> pos[i].x >> pos[i].y;
			map[pos[i].x][pos[i].y] = true;
		}
		
		int max = 0;
		
		for(int i = 0; i < n; i++){
			for(int j = i + 1; j < n; j++){
				if(checker(pos[i], pos[j], map)){
					if(max < norm2_v(decr_v(pos[i], pos[j]))){
						max = norm2_v(decr_v(pos[i], pos[j]));
					}
				}
			}
		}
		
		printf("%d\n", max);
	}
	return 0;
}

Measured memory_bytes: 25592
class Queue:
    def __init__(self,values):
        self.values = values

    def empty(self):
        if len(self.values) == 0:
            return True
        else:
            return False

    def enqueue(self,v):
        self.values.append(v)

    def dequeue(self):
        if len(self.values) <= 0:
            raise
        else:
            v = self.values[0]
            del self.values[0]
            return v

n,q = map(int,raw_input().split(' '))
processes = []
for i in range(n):
    n,t = raw_input().split(' ')
    processes.append((n,int(t)))

queue = Queue(processes)

clock = 0
done = []
while not queue.empty():
    p = queue.dequeue()
    n = p[0]
    t = p[1]
    if t <= q:
        clock+=t
        done.append((n,clock))
    else:
        queue.enqueue((n,t-q))
        clock+=q

for p in done:
    print p[0],p[1]

Measured memory_bytes: 14072
#include <bits/stdc++.h>
#include<list>
#include<algorithm>
#define ll long long int
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define rep(a,b,c) for(a=b;a<c;a++)
#define repr for(i=n-1;i>=0;i--)
#define pll pair<ll, ll>
#define inf 100000001
#define mod 1000000007
#define lb lower_bound
#define up upper_bound
#define rep1 for(i=1;i<=n;i++)
#define vr vector
#define ef else if
#define all(x) (x).begin(), (x).end()
#define SORT(A) sort(A.begin(), A.end());
#define REVERSE(A) reverse(A.begin(), A.end());
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll myXOR(unsigned long long int x, unsigned long long int y)
{
    return (x|y)&(~x|~y);   
}
ll powerLL(ll x, ll n) 
{ 
    ll result = 1; 
    while (n) { 
        if (n & 1) 
            result = result * x % mod; 
        n = n / 2; 
        x = x * x % mod; 
    }
    return result; 
}
int main()
{
    fastio
    ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,r,t,u,w,x,y,z;
    string str, ss, str1;
    double rad;
    cin>>rad;
    double res = (double)((double)(44.0)/(double)7.0)*rad;
    printf("%0.20f\n", res);
}

Measured memory_bytes: 3780
S = list(str(input()))
K = int(input())

ind = 0
for s in S:
    i = int(s)

    if i == 1:
        num = pow(i, 5000000000000000)
        if num + ind >= K:
            print(i)
            break
        else:
            ind += num
    else:
        print(i)
        break

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define pb push_back
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

signed main() {
    string S; cin >> S;
    int K; cin >> K;
    int N = S.size();
    vector<string> v;
    rep(i,5){
        rep(j,N-i){
            v.push_back(S.substr(j,i+1));
        }
    }
    sort(v.begin(),v.end());
    decltype(v)::iterator result = unique(v.begin(),v.end());
    v.erase(result,v.end());
    cout << v[K-1] << endl;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int A[3];
  cin>>A[0]>>A[1]>>A[2];

  int ans = INF;
  for(int i=0;i<3;i++) Min(ans, A[0] + A[1] + A[2] - A[i]);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(int i=int(n);i>=0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long;
using P = pair<int, int>;
using lP = pair<ll, ll>;
using fP = pair<double, double>;
ll const mod = 998244353;
const ll MAX = 300000;
using vi = vector<int>;
using vc = vector<char>;
using vd = vector<double>;
using vs = vector<string>;
using vp = vector<P>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvd = vector<vector<double>>;
using vvc = vector<vector<char>>;
using vvp = vector<vector<P>>;
using vvb = vector<vector<bool>>;
template <typename T>
bool chmax(T& a, const T b) { if (a < b) { a = b; return true; } return false; }
template <typename T>
bool chmin(T& a, const T b) { if (a > b) { a = b; return true; } return false; }


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


int main() {
    string s;
    cin >> s;
    int n = s.size();
    for(int i=n;i>=0;) {
        bool ok = false;
        int index = i;
        if (i - 5 < 0)break;
        if (s.substr(i - 5, 5) == "dream") {
            index = i - 5;
            if (index == 0) {
                cout << "YES" << endl;
                return 0;
            }
            ok = true;
        }

        if (s.substr(i - 5, 5) == "erase") {
            index = i - 5;
            if (index == 0) {
                cout << "YES" << endl;
                return 0;
            }
            ok = true;
        }
        if (index!=0&&i - 6 < 0)break;
        if (s.substr(i - 6, 6) == "eraser") {
            index = i - 6;
            if (index == 0) {
                cout << "YES" << endl;
                return 0;
            }
            ok = true;
        }
        if (index>0&&i - 7 < 0)break;
        if (s.substr(i - 7, 7) == "dreamer") {
            index = i - 7;
            if (index == 0) {
                cout << "YES" << endl;
                return 0;
            }
            ok = true;
        }

        i = index;
        if (!ok) {
            break;
        }
        else if (i == 0) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}

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

int main(){
    int n,m;
    cin >> n >> m;
    long long dp[100010];
    bool a[100010];
    for(int i=0;i<100010;i++){
        a[i] = false;
        dp[i] = 0;
    }
    
    for(int i=0;i<m;i++) {
        int A;
        cin >> A;
        a[A] = true;
    }

    
    
    dp[0]=1;
    if(!a[1]) dp[1]=1;
    else dp[1]=0;

    for(int i=2;i<=n;i++){
        if(a[i]){         /// not exist
            dp[i]=0;
            //cout << "i=" << i << 0 << endl;
        }
        else{             /// exist
            dp[i]+=(dp[i-1]+dp[i-2])%1000000007;
            //cout << "i=" << i << " " << dp[i] << endl;
        }
    }
    cout << dp[n] << endl;
    
}


Measured memory_bytes: 1152
use std::io::Read;
use std::collections::BinaryHeap;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let m: usize = iterator.next().unwrap().parse().unwrap();
    let mut pq: BinaryHeap<usize> = BinaryHeap::new();
    for _ in 0..n {
        pq.push(iterator.next().unwrap().parse().unwrap());
    }

    for _ in 0..m {
        let discounted = pq.pop().unwrap() / 2;
        pq.push(discounted);
    }

    let ans: usize = pq.iter().sum();

    return ans.to_string();
}


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main() {
  ll n;
  cin >> n;
  ll sum = 0;
  REP(i, n) {
    ll a;
    cin >> a;
    if (a % 2 == 0) ++sum;
  }

  string ans = (sum == n) ? "second" : "first";

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

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

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
//#define MOD 1000000007
#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

vector<vector<pair<int,ll>>> G;

vector<ll> dijkstra(int N,int p){
	vector<ll> dist(N,LINF);
	vector<bool> visited(N,false);
	priority_queue<pair<ll,int>> q;
	dist[p] = 0;
	q.push(make_pair(0,p));
	while(!q.empty()){
		pair<ll,int> f = q.top();
		q.pop();
		int u = f.second;

		if(dist[u] < f.first*(-1)) continue;
		visited[u] = true;

		rep(i,G[u].size()){
			int v = G[u][i].first;
			if(visited[v] == true) continue;

			if(dist[v] > dist[u] + G[u][i].second){
				dist[v] = dist[u] + G[u][i].second;
				q.push(make_pair(dist[v]*(-1),v));
			}
		}
	}
	return dist;
}

int main(){
    int N,M; cin >> N >> M;
    G.resize(N);
    rep(i,N-1){
        G[i+1].emplace_back(i,0);
    }
    rep(i,M){
        int l,r;
        ll c;
        cin >> l >> r >> c;
        l--; r--;
        G[l].emplace_back(r,c);
    }
    vector<ll> dist = dijkstra(N,0);
    if(dist[N-1] == LINF) cout << -1 << endl;
    else cout << dist[N-1] << endl;

}


Measured memory_bytes: 10104
main = do
    n <- readLn :: IO Int
    a <- map read . words <$> getLine :: IO [Int]
    b <- map read . words <$> getLine :: IO [Int]
    print $ f a b
  where
    f _ [] = 0
    f (ai:a) (bi:b) =
        let m1 = min bi ai
            (aj:aa) = a
            m2 = min (bi - m1) aj
        in m1 + m2 + f (aj - m2:aa) b


Measured memory_bytes: 98172
n=int(input())
a=[int(input()) for i in range(n)]
a.sort()
t=n//2
if(n%2==0):
    ans=a[t]-a[t-1]+(sum(a[t+1:])-sum(a[:t-1]))*2
else:
    a1=(sum(a[t+1:])-sum(a[:t-1]))*2-a[t]-a[t-1]
    a2=(sum(a[t+2:])-sum(a[:t]))*2+a[t]+a[t+1]
    ans=max(a1,a2)
print(ans)

Measured memory_bytes: 7512
#include<bits/stdc++.h>
#define ll long long

#define nl printf("\n")
#define pb(x) push_back(x)

#define S(a) scanf("%d",&a)
#define S2(a,b) scanf("%d%d",&a,&b)
#define S3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define P(a) printf("%d",a)

#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a<b)?a:b)

#define PLC(a) printf("%lld ",a)
#define PLN(a) printf("%lld\n",a)
#define SL(a) scanf("%lld",&a)
#define SL2(a,b) scanf("%lld%lld",&a,&b)
#define SL3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define SL4(a,b,c,d) scanf("%lld%lld%lld%lld",&a,&b,&c,&d)

#define CLR(a) memset(a,0,sizeof(a))
#define SET(a) memset(a,-1,sizeof(a))
#define FOOL(a) memset(a,false,sizeof(a))
#define fr(i,a,n) for(ll i=a;i<=n;i++)
#define pi acos(-1.0)
#define po 1000000
#define co 1000000
#define mx 100001
#define pll pair<ll,ll>
using namespace std;
ll a[mx];
int main()
{
    ll n,i,y,x,y2,z,xx;
     SL(n);
     y=0;
     for(i=0;i<n;i++)SL(x),a[i]=x,y=max(x,y);
     z=a[0];
     if(z==y)z=a[1];
     y2=y/2;
     if(y%2==0)
     {
        xx=z-y2;
        if(xx<0)xx*=-1;
    }
     else
     {
          if(z<=y2)xx=y2-z;
          else xx=z-y2-1;
     }
     for(i=0;i<n;i++)
     {
        if(y%2==0)
        {
            x=y2-a[i];
            if(x<0)x*=-1;
            if(x<xx)xx=x,z=a[i];
        }
        else
        {
             if(a[i]<=y2)x=y2-a[i];
             else x=a[i]-y2-1;
             if(x<xx)xx=x,z=a[i];
        }
     }
     PLC(y);PLN(z);
}

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

int main(void) {
  vector<int> a(3);
  cin >> a[0] >> a[1] >> a[2];

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

  int n = a[2] - a[1] + a[2] - a[0];
  int res;
  if(n%2==1){
    res = n/2+2;
  } else {
    res = n/2;
  }

  cout << res << endl;
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define INFTY 2000000000

int A[100001];
char B[100001][1];
int partition(int p,int r){
  int x=A[r],i=p-1,j,a;
  char b;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i=i+1;
      a=A[i];A[i]=A[j];A[j]=a;
      b=B[i][0];B[i][0]=B[j][0];B[j][0]=b;
    }
  }
  a=A[i+1];A[i+1]=A[r];A[r]=a;
  b=B[i+1][0];B[i+1][0]=B[r][0];B[r][0]=b;
  return i+1;
}
void quickSort(int p,int r){
  int q;
  if(p<r){
    q=partition(p,r);
    quickSort(p,q-1);
    quickSort(q+1,r);
  }
}
void bubbleSort(int C[100001],char D[100001][1],int n){
  int i,j,c;
  char d;
  for(i=0;i<n;i++){
    for(j=n-1;j>i;j--){
      if(C[j]<C[j-1]){
	c=C[j];C[j]=C[j-1];C[j-1]=c;
	d=D[j][0];D[j][0]=D[j-1][0];D[j-1][0]=d;
      }
    }
  }
}void merge(int C[100001],char D[100001][1],int left,int mid,int right){
  int n1,n2,i,j,k,L1[100001],R1[100001];
  char L2[100001][1],R2[100001][1];
  n1=mid-left;
  n2=right-mid;

  for(i=0;i<n1;i++){
    L1[i]=C[left+i];
    L2[i][0]=D[left+i][0];
  }
  for(i=0;i<n2;i++){
    R1[i]=C[mid+i];
    R2[i][0]=D[mid+i][0];
  }
  L1[n1]=INFTY;
  R1[n2]=INFTY;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    if(L1[i]<=R1[j]){
      C[k]=L1[i];
      D[k][0]=L2[i][0];
      i=i+1;
    }
    else{
      C[k]=R1[j];
      D[k][0]=R2[j][0];
      j=j+1;
    }
  }
}
void mergeSort(int C[100001],char D[100001][1],int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(C,D,left,mid);
    mergeSort(C,D,mid,right);
    merge(C,D,left,mid,right);
  }
}

int main(){
  int n,i,C[100001];
  char D[100001][1],s[20];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s %d",B[i],&A[i]);
    strcpy(D[i],B[i]);
    C[i]=A[i];
  }
  quickSort(0,n-1);
  mergeSort(C,D,0,n);
  strcpy(s,"Stable");
  for(i=0;i<n;i++){
    if(A[i]!=C[i] || B[i][0]!=D[i][0]){
      strcpy(s,"Not stable");
      break;
    }
  }
  printf("%s\n",s);
  for(i=0;i<n;i++){
    printf("%c %d\n",B[i][0],A[i]);
  }
  return 0;
}



Measured memory_bytes: 4160
H, W, D = list(map(int,input().split()))
arr = [[0 for i in range(2)] for j in range(H*W+1)]

for i in range(H):
  tmp = list(map(int,input().split()))
  for j in range(len(tmp)):
    x = tmp[j]
    arr[x][0], arr[x][1] = i, j

cumsum = [0] * (H*W+1)
for i in range(D+1,H*W+1):
  cumsum[i] = cumsum[i-D] + abs(arr[i-D][0] - arr[i][0]) + abs(arr[i-D][1] - arr[i][1])

Q = int(input())
for i in range(Q):
  L,R = list(map(int,input().split()))
  print(cumsum[R] - cumsum[L])

Measured memory_bytes: 18612
/* In the name of Allah */
#include <bits/stdc++.h>
using namespace std;

const int N = 2000 + 5, P = 1e9 + 7;
int n, k, fact[N * N], rev[N * N], dp[N][N];

int power(int a, int b) {
	if (!b)
		return 1;
	int ans = power(a, b >> 1);
	ans = 1LL * ans * ans % P;
	if (b & 1)
		ans = 1LL * ans * a % P;
	return ans;
}

int C(int n, int k) {
	return 1LL * fact[n] * rev[k] % P * rev[n - k] % P;
}

void readInput() {
	cin >> n >> k;
}

void solve() {
	if (k == 1)
		return;
	fact[0] = rev[0] = dp[1][0] = dp[1][1] = 1;
	for (int i = 1; i < n * k; i++)
		rev[i] = power(fact[i] = 1LL * fact[i - 1] * i % P, P - 2);
	for (int i = 2; i <= n; i++) {
		for (int j = i; j; j--)
			dp[i][j] = (1LL * i * C(k * i - j - 1, k - 2) % P * dp[i - 1][j - 1] % P + dp[i][j + 1]) % P;
		dp[i][0] = dp[i][1];
	}
}

void writeOutput() {
	if (k == 1) {
		cout << "1\n";
		return;
	}
	cout << dp[n][0] << endl;
}

int main() {
	ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	readInput(), solve(), writeOutput();
	return 0;
}


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

struct data {
  long long id, cost;
};
bool operator<(const data &l, const data &r) {
  if(l.cost != r.cost) return l.cost < r.cost;
  return l.id < r.id;
}

struct Unionfind {
  // tree number
  vector<int> par;
  // tree rank
  vector<int> treerank;
  // constructor
  Unionfind(int n = 1) { stree(n + 1); }
  // make and initialization
  void stree(int n = 1) {
    par.resize(n);
    treerank.resize(n);
    for(int i = 0; i < n; ++i) {
      par[i] = i;
      treerank[i] = 0;
    }
  }
  // search root
  int root(int x) {
    if(par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  // is same?
  bool issame(int x, int y) { return root(x) == root(y); }

  // add
  // already added, return 0
  bool uni(int x, int y) {
    x = root(x);
    y = root(y);
    if(x == y) return 0;
    if(treerank[x] < treerank[y])
      par[x] = y;
    else if(treerank[y] < treerank[x])
      par[y] = x;
    else {
      par[y] = x;
      ++treerank[x];
    }
    return 1;
  }
};

long long n, m, ans = -1;
bool ch[100005][2] = {0};
vector<data> v;
Unionfind uf;

void solve();

int main() {
  cin >> n >> m;
  uf = Unionfind(n + 1);
  v.resize(n);
  for(int i = 0; i < n; ++i) {
    cin >> v[i].cost;
    v[i].id = i;
  }
  sort(v.begin(), v.end());
  for(int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    uf.uni(x, y);
  }
  solve();
  if(ans == -1)
    cout << "Impossible" << endl;
  else
    cout << ans << endl;
  return 0;
}

void solve() {
  long long now = 0, cnt = 0;
  for(int i = 0; i < n; ++i)
    if(!ch[uf.root(v[i].id)][1]) {
      now += v[i].cost;
      ++cnt;
      ch[i][0] = 1;
      ch[uf.root(v[i].id)][1] = 1;
    }
  if(cnt == 1) now = 0;
  if(n < (cnt - 1) * 2) return;
  cnt = (cnt - 1) * 2 - cnt;
  for(int i = 0; i < n; ++i)
    if(!ch[i][0] && cnt > 0) {
      now += v[i].cost;
      if(--cnt == 0) break;
    }
  ans = now;
}

Measured memory_bytes: 2816
#include <iostream>
#include <climits>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

#define ll long long

void solve()
{
	ll n, k;

	cin >> n >> k;

	vector<ll> a(n);
	bool test = false;

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

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

	ll temp = 0;

	for (int i = 0; i < n - k; i++)
	{
		temp += a[i];
	}

	cout << temp;
}

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

	solve();

	return 0;
}

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


int main(){
    int n,k;
    cin>>n>>k;
    int h[n];
    int dp[n];
    for(int i=0;i<n;i++)    cin>>h[i];
    dp[0] = 0;
    dp[1] = dp[0] + abs(h[1]-h[0]);
    for(int i=2;i<n;i++){
        dp[i] = dp[i-1]+ abs(h[i]-h[i-1]);
        for(int j=2;j<=k;j++){
            if(i-j>=0)
                dp[i] = min(dp[i], dp[i-j]+ abs(h[i]-h[i-j]));
        } 
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1024
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Reflection.Emit;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
        checked {
#if DEBUG
            MyDebugger.Test(process, "../TextFile1.txt");
            //TestCaseMaker.MakeTestCase1("../TextFile2.txt");
            //MyDebugger.Test(process, "../TextFile2.txt");
#else
            object ret = process(new StreamReader(Console.OpenStandardInput()));
            Console.WriteLine(ret);
#endif
        }
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());

        if (n < 600) return 8;
        if (n < 800) return 7;
        if (n < 1000) return 6;
        if (n < 1200) return 5;
        if (n < 1400) return 4;
        if (n < 1600) return 3;
        if (n < 1800) return 2;
        if (n < 2000) return 1;

        return 0;
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        if (n == 0) return ret;
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


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

int main(){
    map<char,int> ans;
    string w;
    cin >> w;
    for(int i=0;i<w.size();i++){
        ans[w[i]]++;
    }
    map<char,int>::iterator it;
    for(it=ans.begin();it!=ans.end();it++){
        if(it->second%2!=0){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

void solve(const vector<vector<vector<pair<int, int> > > >& jump, vector<vector<int> >& visited, int x, int y)
{
	visited[y][x] = 1;
	for (int i = 0; i < jump[y][x].size(); ++i) {
		const pair<int, int>& p = jump[y][x][i];
		if (!visited[p.second][p.first])
			solve(jump, visited, p.first, p.second);
	}
}

int main()
{
	int N;
	while (~scanf("%d", &N)) {
		if (N == 0)
			break;
		vector<vector<vector<pair<int, int> > > > jump(N, vector<vector<pair<int, int> > >(N));
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				int x, y;
				scanf("%d %d", &x, &y);
				jump[i][j].push_back(pair<int, int>(x, y));
				jump[y][x].push_back(pair<int, int>(j, i));
			}
		}

		int ans = 0;
		vector<vector<int> > visited(N, vector<int>(N, 0));
		for (int y = 0; y < N; ++y) {
			for (int x = 0; x < N; ++x) {
				if (visited[y][x])
					continue;
				solve(jump, visited, x, y);
				++ans;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.*;
import java.awt.geom.*;
public class Main {

	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n == 0) break;
			int s = sc.nextInt();
			int numbers = n * 2;
			int [] takestone = new int[numbers];
			for(int i = 0; i < numbers; i++){
				takestone[i] = sc.nextInt();
			}
			boolean [][] dp = new boolean[numbers][s + 1];
			for(int i = 0; i < numbers; i++){
				if(i % 2 == 0){
					dp[i][1] = false;
				}
				else{
					dp[i][1] = true;
				}
			}
			for(int i = 2; i <= s; i++){
				for(int j = 0; j < numbers; j++){
					boolean iswin = dp[(j+1) % numbers][i-1];
					for(int k = 2; k <= takestone[j]; k++){
						if(i- k <= 0) break;
						if(j % 2 == 0){
							iswin = iswin || dp[(j+1) % numbers][i - k];
						}
						else{
							iswin = iswin && dp[(j+1) % numbers][i - k];
						}
					}
					dp[j][i] = iswin;
				}
			}

			System.out.println(dp[0][s] ? 1 : 0);
		}
	}

	public static void main(String[] args) {
		Main obj = new Main();
		obj.doit();
	}
}

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

using namespace std;

int main() {
    string s;
    cin >> s;
    int len = s.length();
    len += len%2;
    while(len>3) {
        len-=2;
        if(s.substr(0, len/2) == s.substr(len/2, len/2)) break;
    }

    cout << len << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
#define ll long long
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int main(){
	fastio();
	ll a,b,c;
	cin>>a>>b>>c;

	ll p = c - a - b;

	if(p<=0){
		cout<<"No";
		return 0;
	}
	ll k  = a*b;

	k = k*4ll;

	p = p*p;

	if(p>k){
		cout<<"Yes";
	}else{
		cout<<"No";
	}
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

const int kMaxN = 300001;

int t[kMaxN * 4];
int n, k, x, v, ans;

void C(int i, int ml, int mr, int nl, int nr) {
  if (ml == nl && mr == nr) {
    v = max(v, t[i]);
    return;
  }
  int m = (ml + mr) >> 1;
  if (nl <= m) {
    C(i * 2, ml, m, nl, min(nr, m));
  }
  if (nr > m) {
    C(i * 2 + 1, m + 1, mr, max(m + 1, nl), nr);
  }
}

void U(int i, int l, int r, int x, int v) {
  if (l == r) {
    t[i] = max(t[i], v);
    return;
  }
  int m = (l + r) >> 1;
  if (x <= m) {
    U(i * 2, l, m, x, v);
  } else {
    U(i * 2 + 1, m + 1, r, x, v);
  }
  t[i] = max(t[i * 2], t[i * 2 + 1]);
}

int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    v = 0;
    C(1, 0, kMaxN - 1, max(x - k, 0), min(x + k, kMaxN - 1));
    U(1, 0, kMaxN - 1, x, v + 1);
    ans = max(ans, v + 1);
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 7688
//#pragma GCC optimize "trapv"
//-D_GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define pm(m) for(auto itr=(m).begin();itr!=(m).end();itr++){itr->first<<" "<<itr->second<<"\n";}
#define int long long int
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define ii pair<int,int>
#define Max 100000+5
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define f first
#define s second
#define pb push_back
#define bug(x) cout<<(x)<<" ";exit(0);
int mod = 1000000007;
int mod1 = 998244353;
vector<int> g[Max];
bool vis[Max];
int d, x, y;
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
void ex(int A, int B) {
    if(B == 0) {
        d = A;
        x = 1;
        y = 0;
    }
    else {
        ex(B, A%B);
        int temp = x;
        x = y;
        y = temp - (A/B)*y;
    }
}


void dfs(int u){

	vis[u]=1;
	for(int i=0;i<g[u].size();i++){
		int v=g[u][i];
		if(vis[v]!=1)
			dfs(v);
	}
}



int power(int a,int b){
    if(b==1)return a;
    if(a>mod)a%=mod;
    int r=1;
    while(b){
        if(b&1)r=r%mod*a%mod;
        a=a%mod*a%mod;
        b/=2;
    }
    return r;
}
class uf{
    vector<int> v;
    vector<int> sz;
    
    
    public :
    uf(int n){
        v.resize(n+1);
        iota(v.begin()+1,v.end(),1);
        sz.resize(n+1,1);
        //1 to sz
    }
    int root(int b){
        while(v[b]!=b){
            b = v[b];
        }   
        return b;
    }
    void u(int a, int b){
        //combine a and b
        
        int ra=root(a);
        int rb=root(b);
        if(ra==rb)return ;
        if(sz[ra]<sz[rb]){
            v[ra] = v[rb];
            sz[rb]+=sz[ra];
        }else{
            v[rb]=v[ra];
            sz[ra]+=sz[rb];
        }
    }
    bool f(int a,int b){
        //same set
        return (root(a)==root(b));
    }
   
    
};
vector<int> matmul(vector<int> a,vector<int> b){
    vector<int> c(4,0);
    c[0] = (a[0]%mod*b[0]%mod + a[1]%mod*b[2]%mod)%mod;
    c[1] = (a[0]%mod*b[1]%mod + a[1]%mod*b[3]%mod)%mod;
    c[2] = (a[2]%mod*b[0]%mod + a[3]%mod*b[2]%mod)%mod;
    c[3] = (a[2]%mod*b[1]%mod + a[3]%mod*b[3]%mod)%mod;
    return c;
}
vector<int> id={1,0,0,1};

int32_t main(){
	IO
	//freopen("input.txt","r",stdin);
    	//freopen("output.txt","w",stdout);
	int n,k;
	cin>>n>>k;
	vector<int> v(n);
	for(int i=0;i<n;i++)cin>>v[i];
	vector<int> dp(n);
	dp[0]=0;
	for(int i=1;i<n;i++){
	    int ans=INT_MAX;
	    for(int j=1;j<=k;j++){
	        if(i-j>=0){
	            ans=min(ans,dp[i-j]+abs(v[i-j]-v[i]));
	        }
	    }
	    dp[i]=ans;
	}
	cout<<dp[n-1]<<"\n";
}

Measured memory_bytes: 7144
#include <iostream>
#include <sstream>
#include <string>
#include <map>
using namespace std;

class data
{
public:
	int nm,ct;
	data(){nm=ct=0;}
};

int main()
{
	char c;
	int n,d,m=1;
	string  str;
	map<int,data> mp;
	map<int,data>::iterator it;

	while(getline(cin,str))
	{
		if(str=="")
		{
			m=2;
			continue;
		}

		stringstream ss;
		ss << str;
		ss >> n >> c >> d;

		mp[n].nm |= m;
		mp[n].ct++;
	}

	for(it=mp.begin(); it!=mp.end(); it++)
	{
		if(it->second.nm==3)
		{
			cout << it->first << " " << it->second.ct << endl;
		}
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
  for(;;){
    int n;
    cin >> n;
    if(n==0) break;
    vector<int> v(n);
    for(int i=0; i<n; i++){
      cin >> v[i];
    }
    sort(v.begin(),v.end());
    int ret = 0;
    for(int i=1; i<v.size()-1; i++){
      ret += v[i];
    }
    ret /= n-2;
    cout << ret << endl;
  }
  return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using Tup = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<(v)<<"\n";
#define fl cout<<flush;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl '\n'
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld pi=3.141592653589793238;

//すべて半閉区間で扱う
struct cBIT {
  vector<ll> v;
  ll n;
  cBIT(ll n) : n(n), v(n) {}
  void add(ll i, ll x) {
    i++;
    while (i <= n) {
      v[i - 1] += x;
      i += i & -i;
    }
  }
  ll sum(ll i) {
    ll r = 0;
    while (i >= 1) {
      r += v[i - 1];
      i -= i & -i;
    }
    return r;
  }
  ll sum(ll l, ll r){
    if(l>=r)return 0;
    return sum(r)-sum(l);
  }
  ll get(ll i){return sum(i+1)-sum(i);}
};
 
struct BIT {
  cBIT p, q;
  BIT(ll n) : p(n + 1), q(n + 1) {}
  void add(ll l, ll r, ll w) {
    p.add(l, -w * l);
    p.add(r, w * r);
    q.add(l, w);
    q.add(r, -w);
  }
  void add(ll i, ll w){
    add(i,i+1,w);
  }
  ll sum(ll r) {
    return p.sum(r) + q.sum(r) * r;
  }
  ll sum(ll l, ll r){
    if(l>=r)return 0;
    return sum(r)-sum(l);
  }
  ll get(ll i){return sum(i+1)-sum(i);}
};
//↑すべて半閉区間で扱う

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll K;
    cin >> K;
    vector<ll> A(N,0);
    for(ll i=0;i<N;++i)cin>>A[i];
    for(ll i=0;i<min(K,50LL);++i){
        BIT tree(N);
        for(ll j=0;j<N;++j){
            tree.add(max(0LL,(j-A[j])),min(N,(j+A[j]+1)),1);
        }
        for(ll j=0;j<N;++j)A[j]=tree.get(j);
    }
    for(ll i=0;i<N;++i){
        cout<<A[i]<<" ";
    }cout<<endl;fl

    return 0;
}


Measured memory_bytes: 7956
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ull  = unsigned long long;

int main(){
  ull a; string b;
  cin >> a >> b;
  ull c = (100 * (b[0]-48)) + (10 * (b[2]-48)) + (b[3]-48);
  //cout << c << endl;
  
  ull r = a % 100;
  ull q = a - r;
  
  ull ans1 = (q/100) * c;
  ull ans2 = r * c;
  ans2 /= 100;
  //cout << ans1 << " " << ans2 << endl;
  
  cout << ans1 + ans2 << endl;
}

Measured memory_bytes: 3612
package main

import (
	"fmt"
)

func main() {
	var x, n int
	fmt.Scan(&x, &n)
	
	p := make(map[int]bool, n)
	
	num := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&num)
		p[num] = true
	}

	diff := 0
	for {
		if !p[x-diff] {
			fmt.Println(x - diff)
			return
		}
		if !p[x+diff] {
			fmt.Println(x + diff)
			return
		}
		diff++
	}

}

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

#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
#define mp(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ll IINF = INT_MAX;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        ans += 1ll * i * (i + 1) / 2;
    }
    for (int i = 0; i < n -  1; i++) {
        ll u, v;
        cin >> u >> v;
        if (u > v) swap(u, v);
        ans -= u * (n - (v - 1));
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3668
S = input()
ans = ['AKIHABARA', 'AKIHABAR', 'AKIHABRA', 'AKIHABR', 'AKIHBARA', "AKIHBAR", 'AKIHBRA', 'AKIHBR', 'KIHABARA', 'KIHABAR', 'KIHABRA', 'KIHABR', 'KIHBARA', "KIHBAR", 'KIHBRA', 'KIHBR']
if S in ans:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 9084
import collections

n = int(input())

s = []

for i in range(n):
    s.append(input())

m = int(input())

t = []

for i in range(m):
    t.append(input())

l = list(set(s + t))

ans = 0

for word in l:
    ans = max(ans, s.count(word) - t.count(word))

print(ans)


Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,c,d,e,n;
  string s,ss,sss;
  cin>>n;
  vi A(n);
  bool ans = true;
  for(auto &a:A){
    cin>>a;
    if(a%2 == 0){
      if(!(a%3 == 0 || a%5 == 0)){
	ans = false;
      }
    }
  }
  if(ans)
  cout<<"APPROVED" <<endl;
  else
    cout<<"DENIED"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fuckit(){	\
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL); \
}
using namespace std;
typedef long long ll;
int main()
{
	fuckit();
	ll n,m,x,y,i,sum=0;
	cin>>n;
	int ara[n];
	for(i=0;i<n;i++){
		cin>>ara[i];
	}
	for(i=0;i<n;i++){
		sum+=ara[i];
	}

	cin>>m;
	for(i=0;i<m;i++){
		cin>>x>>y;
		sum-=ara[x-1];
		sum+=y;
		cout<<sum<<endl;
		sum-=y;
		sum+=ara[x-1];
	}
	return 0;	
}


Measured memory_bytes: 256
n = int(input())
a = []
b = []
for _ in range(n):
    p,q = map(int,input().split())
    a.append(p)
    b.append(q)
t = 0
for (i,j) in zip(a[::-1],b[::-1]):
    if (i+t)%j!=0:
        t += j-(i+t)%j
print(t)


Measured memory_bytes: 12624
n,k = map(lambda x: int(x),input().split())
r,s,p = map(lambda x: int(x),input().split())
t = input()
ans = ''
dont = 'free'
count = 0
for i in range(n):
    if i - k >= 0 :
        dont = ans[i-k]
    if t[i] == 'r' and dont != 'p':
        ans += 'p'
        count += p
    elif t[i] == 's' and dont != 'r' :
        ans += 'r'
        count += r
    elif t[i] == 'p' and dont != 's':
        ans += 's'
        count += s
    else :
        ans += 'f'
print(count)


Measured memory_bytes: 3444
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
#define db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'
const int inf = 1e9+7;
const int N = 1e6+9;

void solve() {
    ll a, b, n;
    cin>>n;
    if(n==1) {
    	cout<<"a\n";
    	return;
    }
    
    string s;
    while(n) {
        ll r=n%26;
        char ch;
        
        if(r==0) {
        	ch='z';
        	n--;
        }
        else {
        	ch='a'+(r-1);
        }
        s.pb(ch);
        n/=26;
    }
    reverse(s.begin(), s.end());
    cout<<s<<endl;
}
int main() {
    ios_base::sync_with_stdio(0);
    int T=1 ,cas=0;
    while(T--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3632
function Main(input) {
	input = input.trim().split("\n").map(function(x) { return x.split(" ")});
	let N = parseInt(input[0][0], 10);
	let K = parseInt(input[0][1], 10);
	let a = input[1].map(e => parseInt(e, 10));
	let aCheck = Array.from({length:1e5 + 1},() => false);
	for (x of a){
		aCheck[x] = true;
	}
	let DP = Array.from({length: K + 1}, () => 0);
	//2なら後攻の勝利、1なら先攻の勝利
	DP[0] = 2;
	for (let i = 1; i <= K; i++){
		DP[i] = 2;
		for (let x of a){
			if (x > i) break;
			if (DP[i - x] === 2) {
				DP[i] = 1;
				break;
			}
		}
	}
	if (DP.pop() === 1) console.log("First");
	else console.log("Second");

}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 33944
#include<stdio.h>
int main()
{
	int n,x,y;
	scanf("%d",&n);
	for(x=1;x<=n;x++){
		y=x;
		if(x%3==0||x%10==3){
			printf(" %d",x);
		}
		else{while(1){
			y=y/10;
			if(y%10==3){printf(" %d",x);
				break;
			}if(y==0)break;
		}
		}
	}
		printf("\n");
		return 0;
}


Measured memory_bytes: 2112
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
const ll MAX_N=1e5,MOD=998244353;
ll N,xyz[MAX_N*3];
string S;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>N>>S;
	map<char,ll> mp;
	mp['R']=0;
	mp['G']=1;
	mp['B']=2;
	vector<ll> col[3];
	REP(i,3*N){
		char c=S[i];
		col[mp[c]].push_back(i);
	}
	REP(i,N){
		vector<ll> vec;
		REP(j,3){
			vec.push_back(col[j][i]);
		}
		sort(vec.begin(),vec.end());
		REP(j,3){
			xyz[vec[j]]=j;
		}
	}
	ll ans=1,cnt1=0,cnt2=0;
	REP(i,N*3){
		switch(xyz[i]){
			case 0:{
				cnt1++;
				break;
			}
			case 1:{
				ans*=cnt1;
				ans%=MOD;
				cnt1--;
				cnt2++;
				break;
			}
			case 2:{
				ans*=cnt2;
				ans%=MOD;
				cnt2--;
				break;
			}
		}
	}
	REP(i,N){
		ans*=i+1;
		ans%=MOD;
	}
	cout<<ans<<endl;
}

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

bool primeNumber(int n){
    if(n<2) return false;
    else{
        for(int i = 2; i * i <= n; i++){
            if(n % i == 0) return false;
        }
        return true;
    }
}
int main(void){
    int x;
    cin >> x;
    bool check = false;
    while(1){
        check = primeNumber(x);
        if(check==true){
            cout << x << endl; 
            return 0;
        }
        x++;
    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

int N;

LL A[123456];

int main(void)
{
	LL sum = 0;
	cin >> N;
	for (int i = 1; i <= N; ++i) {
		cin >> A[i];
	}
	sum += abs(A[1]);
	for (int i = 1; i <= N; ++i) {
		sum += abs(A[i + 1] - A[i]);
	}
	for (int i = 1; i <= N; ++i) {
		LL change = abs(A[i + 1] - A[i - 1]) - abs(A[i + 1] - A[i]) - abs(A[i - 1] - A[i]);
		cout << sum + change << endl;
	}
	return 0;
}


Measured memory_bytes: 2048
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int total = sc.nextInt();
		for(int i = 0;i <=n;i++) {
			int otoshidama = 10000 * i;
			for(int j = 0; j <= n -i;j++) {
				otoshidama += ((5000 * j) + (1000 * (n-i-j)));
				if(otoshidama == total) {
					System.out.println(i + " " + j + " " + (n -i -j) );
					return;
				}else {
					otoshidama = 10000 * i;
				}
			}
		}
		System.out.println("-1 -1 -1");
	}
}

Measured memory_bytes: 39456
#include <cstdio>
#include <algorithm>
#include <vector>

const int N = 50;
int n, m;
int br;
std::vector<int> g[N];
int d[N];
bool u[N];

int dfs(int v, int p = -1) 
{
	u[v] = true;
	int md = d[v];
	for (int i = 0; i < (int)g[v].size(); ++i) if (g[v][i] != p) {
		if (u[g[v][i]]) md = std::min(d[g[v][i]], md);
		else {
			d[g[v][i]] = d[v] + 1;
			int got = dfs(g[v][i], v);
			if (got > d[v]) ++br;
			md = std::min(got, md);
		}
	}
	return md;
}

int main() 
{
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		--a;
		--b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(0);
	printf("%d\n", br);
	return 0;
}


Measured memory_bytes: 3248
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <list>
#include <bitset>
using namespace std;

int main()
{
    int N;
    cin >> N;
    int n = N;
    int sum = 0;
    while (n != 0)
    {
        sum += n % 10;
        n /= 10;
    }
    if (N % sum)
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#define ll long long
using namespace std;

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 ll INF = 1LL << 60;

int main()
{
  int N;
  cin >> N;
  vector<int> a(N), b(N), c(N);
  for (int i = 0; i < N; i++)
  {
    cin >> a[i] >> b[i] >> c[i];
  }

  vector<ll> last_a(N), last_b(N), last_c(N);
  last_a[0] = a[0];
  last_b[0] = b[0];
  last_c[0] = c[0];

  for (int i = 1; i < N; i++)
  {
    last_a[i] = max(last_b[i - 1], last_c[i - 1]) + a[i];
    last_b[i] = max(last_a[i - 1], last_c[i - 1]) + b[i];
    last_c[i] = max(last_a[i - 1], last_b[i - 1]) + c[i];
  }

  ll ans;
  ans = max(last_a[N - 1], last_b[N - 1]);
  ans = max(ans, last_c[N - 1]);

  cout << ans << endl;
}

Measured memory_bytes: 3712