akhauriyash/Code-Regression huggingface dataset:
#include <inttypes.h>
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

intmax_t get_gcd(intmax_t a, intmax_t b)
{
    while (b != 0) {
        intmax_t r = a % b;
        a = b;
        b = r;
    }

    return a;
}

int main(int argc, char const* argv[])
{
    int64_t N, X, x[(int)1e5];
    int64_t gcd, d[(int)1e5];

    scanf("%" PRId64 "%" PRId64, &N, &X);
    for (int i = 0; i < N; i++) {
        scanf("%" PRId64, &x[i]);
        d[i] = llabs(x[i] - X);
    }

    gcd = d[0];
    for (int i = 1; i < N; i++) {
        gcd = get_gcd(gcd, d[i]);
    }

    printf("%" PRId64 "\n", gcd);
}


Measured memory_bytes: 1792
n = int(input())
# x > yの時、購入。x <= yの時、買わない。購入したら、その差を加えていく。
v = list(map(int, input().split()))
c = list(map(int, input().split()))

# print(v)
ans = 0
for i in range(n):
    if v[i] > c[i]:
        ans = ans + v[i] - c[i]
    else:
        pass

print(ans)


Measured memory_bytes: 2940
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()
	k := nextInt()
	m := map[int]int{}
	for i := 0; i < n; i++ {
		m[nextInt()]++
	}

	if len(m) <= k {
		fmt.Println(0)
		return
	}
	s := make([]pair, len(m))
	sidx := 0
	for k, v := range m {
		s[sidx] = pair{v, k}
		sidx++
	}
	sortPairs(s)
	diff := len(m) - k
	ccnt := 0
	for i := 0; i < diff; i++ {
		ccnt += s[i].f
	}

	fmt.Println(ccnt)

}

// Pair ソート
// s := make([]pair, n)
// sortPairs(s)
type pair struct { // f=first, s=second
	f int
	s int
}

// []pair をf->sの順でソートする
func sortPairs(s []pair) {
	sort.Slice(s, func(i, j int) bool {
		if s[i].f == s[j].f { // fが同じ場合はsを比較する
			return s[i].s < s[j].s
		}
		return s[i].f < s[j].f
	})
	return
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 16516
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn=55;
LL a[maxn];



int main()
{
    LL k;
    cin>>k;
    if(k<=100)
    {
    cout<<2<<endl;
    if(k%2==1)
    {
        printf("%lld %lld\n", k/2+3, k/2);
    }   
    else printf("%lld %lld\n", k/2+1, k/2+1);
    }
    else 
    {
        LL n=50;
        int i, j;
        cout<<n<<endl;
        for(i=0; i<k%n; i++)
        {
            a[i]-=k%n-1;
            a[i]+=k/n+n+n-1;
        }
        j=i;
        for(; i<n; i++)a[i]=n-1+k/n-j;
        for(i=0; i<n; i++)printf(i==n-1?"%lld\n":"%lld ", a[i]);
    }

}


Measured memory_bytes: 256
n=int(input())
lists=[0 for i in range(n)]
for i in range(n):
    a=int(input())
    lists[i]=a
flag=True
for i in range(n):
    if lists[i]%2!=0:
        flag=False
        break
if flag:
    print("second")
else:
    print("first")

Measured memory_bytes: 7080
s = input()
a = s.lower()
l = len(s)
c = 0
n = 0

if s[0] == 'A':
  for i in range(2 , l-1):
    if s[i] == 'C':
      c += 1
  if c == 1:
    for i in range(1,l):
      if s[i] != a[i]:
        n += 1
    if n == 1:
      print('AC')
      exit()
print('WA')

Measured memory_bytes: 9040
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
long Nim(long A,long K){
	while(1){
		if(A < K){
			return 0;
		}
		if(A % K == 0){
			return A / K;
		}
		long t = A / K;
		long m = t*K;
		long d = max((A-m) - (A-m) % (t+1),t+1);
		A -= d;
	}
}
void Calc(){
	int N = rei();
	long ans = 0;
	for(int i=0;i<N;i++){
		ans ^= Nim(rel(),rel());
	}
	if(ans == 0){
		cout << "Aoki" << endl;
	}
	else{
		cout << "Takahashi" << endl;
	}
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define sp(x) setprecision(x)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
ll dp[10][10];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n; cin>>n;
    for(int i=1;i<=n;i++){
        int x=i;
        while(x>=10) x/=10;
        dp[x][i%10]++;
        //cout<<i<<" "<<x<<i%10<<endl;
    }
    ll ans=0;
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            ans+=(dp[i][j]*dp[j][i]);
        }
        //ans-=(dp[i][i]*dp[i][i]);
    }
    cout<<ans<<endl;
}

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

int main(){
    int N, Q;
    int l, r;
    cin >> N >> Q;
    int ans[Q], S_AC[N+1];
    char S[N+1];
    for(int i=0; i<Q; i++) ans[i] = 0;
    for(int i=1; i<N+1; i++){
        cin >> S[i];
        S_AC[i] = 0;
    }
    S_AC[0] = 0;
    for(int i=1; i<N+1; i++){
        if(S[i] == 'A' && S[i+1] == 'C'){
            S_AC[i] = S_AC[i-1]+1;
            //cout << "S_AC["<< i << "]  =  " << S_AC[i] << endl;
        }else{
            S_AC[i] = S_AC[i-1];
        }
        //else cout << "S_AC["<< i << "]  =  " << S_AC[i] << "　0のはず" << endl;
    }
    for(int i=0; i<Q; i++){
        cin >> l >> r;
        ans[i] = S_AC[r-1] - S_AC[l-1];
    }
    for(int i=0; i<Q; i++) cout << ans[i] << endl;
}

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

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s,t;
    cin >> s >> t;
    int n = (int)s.size(), m = (int)t.size();
    int dp[n+1][m+1];

    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= m; j++){
            if(i == 0 || j == 0)dp[i][j] = 0;
            else if(s[i-1] == t[j-1])
                dp[i][j] = dp[i-1][j-1]+1;
            else
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
        }
    }
    string st = "";
    int i = n, j = m;
    while(i > 0 && j > 0){
        if(s[i-1] == t[j-1])st += s[i-1],i--,j--;
        else if(dp[i][j] == dp[i-1][j])i--;
        else j--;
    }
    reverse(st.begin(),st.end());
    cout << st;

    return 0;
}


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

#define rep(i,n) for((i)=0;i<(int)(n);i++)
using namespace std;

int main() {
	string S[100];
	int N, L;
	cin >> N >> L;
	int i;
	rep(i, N) {
		cin >> S[i];
	}

	rep(i, N) {
		for (int j = i + 1; j < N; j++) {
			if (S[i].compare(S[j]) > 0) {
				S[i].swap(S[j]);
			}
		}
	}
	rep(i, N) {
		cout << S[i];
	}
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(){
  char str[100];
  fgets(str,sizeof(str),stdin);
  char abc[10]="ABC";
   int i=0;
  while(str[i]==abc[i]){
    i++;
  }
    if(i==3)
  printf("ARC");
      else
        printf("ABC");
  
}

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

using namespace std;

int main() {
  int n, h;
  cin >> n >> h;
  vector<int> a(n);
  vector<int> b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  const auto amax = *max_element(a.begin(), a.end());
  sort(b.begin(), b.end(), greater<int>());
  int ans = 0;
  for (auto e : b) {
    if (amax < e) {
      h -= e;
      ++ans;
      if (h <= 0) break;
    }
  }
  if (h > 0) {
    ans += (h + amax - 1) / amax;
  }
  cout << ans << endl;

  return 0;
}


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  int a, b;
  cin >> a >> b;
  if (1 <= a && a <= 9 && 1 <= b && b <= 9) {
    cout << a * b << endl;
  } else {
    cout << -1 << endl;
  }
}


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

int main(){
  while(1){
    int n;
    cin>>n;
    if(n==0)break;
    int ans=0;
    int sta=0;
    int l=0;
    int r=0;
    for(int i=0;i<n;i++){
      string s;
      cin>>s;
      if(s=="lu"){
        l=1;
      }else if(s=="ru"){
        r=1;
      }else if(s=="ld"){
        l=0;
      }else if(s=="rd"){
        r=0;
      }
      if(sta==0&&l==1&&r==1){
        ans++;
        sta=1;
      }else if(sta==1&&l==0&&r==0){
        ans++;
        sta=0;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3164
import math

while True:

    # 学生の数を受け取る
    n = int(input())
    if n == 0:
        break
    
    # 学生の点数を受け取る
    score = [i for i in map(int, input().split())]
    
    # 標準偏差aを求める
    m = sum(score) / n
    tmp = 0
    for j in range(n):
        tmp += (score[j] - m) ** 2
    a = math.sqrt(tmp / n)
    print(a)

    continue



Measured memory_bytes: 5708
#include <bits/stdc++.h>
using namespace std;
void dfs(int node, int w, vector<vector<int>> &edge, vector<int> &weight, vector<bool> &used){
    if(used[node]) return;
    weight[node] += w;
    used[node] = true;
    for(auto e: edge[node]){
        if(used[e]) continue;
        dfs(e, weight[node], edge, weight, used);
    }
} 

int main(){
    int n,q;
    cin >> n >> q;
    vector<vector<int>> edge(n, vector<int>());
    vector<int> weight(n,0);
    vector<bool> used(n, false);
    for(int i=0;i<n-1;i++){
        int a,b;
        cin >> a >> b;
        a--;b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    for(int i=0;i<q;i++){
        int p,x;
        cin >> p >> x;
        p--;
        weight[p] += x;
    }
    dfs(0, 0, edge, weight, used);
    for(int i=0;i<n;i++){
        cout << weight[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 29824
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

int main(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << (a-c)*(b-d) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

//int mid(int x, int y, int z){
//  int a[3];
//  a[0] = x; a[1] = y; a[2] = z;
//  sort(a, a + 3);
//  return a[1];
//}
//
//bool check(int n, int x, int a[]){
//  int result[n][2 * n - 1];
//  for(int i = 0; i < 2 * n - 1; i++){
//    result[n - 1][i] = a[i];
//  }
//  for(int i = n - 2; i >= 0; i--){
//    for(int j = 0; j < 2 * (i + 1) - 1; j++){
//      result[i][j] = mid(
//        result[i + 1][j],
//        result[i + 1][j + 1],
//        result[i + 1][j + 2]);
//    }
//  }
//  return x == result[0][0];
//}

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

  int n, x;
  cin >> n >> x;

  if(x == 1 || x == (2 * n - 1)){
    cout << "No" << endl;
    return 0;
  }

  if(n == 2){
    if(x != 2){
      cout << "No" << endl;
    }
    else{
      cout << "Yes" << endl;
      cout << "1\n2\n3" << endl;
    }
    return 0;
  }

  int a[2 * n - 1];
  queue< int > r;
  if(x != 2){
    a[n - 2] = x - 1;
    a[n - 1] = x;
    a[n] = x + 1;
    a[n + 1] = x - 2;
    for(int i = 0; i < 2 * n - 1; i++){
      if(i + 1 == x - 1 ||
          i + 1 == x ||
          i + 1 == x + 1 ||
          i + 1 == x - 2) continue;
      r.push(i + 1);
    }
  }
  else{
    a[n - 2] = x + 1;
    a[n - 1] = x;
    a[n] = x - 1;
    a[n + 1] = x + 2;
    for(int i = 0; i < 2 * n - 1; i++){
      if(i + 1 == x + 1 ||
          i + 1 == x ||
          i + 1 == x - 1 ||
          i + 1 == x + 2) continue;
      r.push(i + 1);
    }
  }

  for(int i = 0; i < n - 2; i++){
    a[i] = r.front(); r.pop();
  }
  for(int i = n + 2; i < 2 * n - 1; i++){
    a[i] = r.front(); r.pop();
  }

  string buf;
  for(int i = 0; i < 2 * n - 1; i++){
    buf += to_string(a[i]) + "\n";
  }

  cout << "Yes" << endl;
  cout << buf;

  //cout << check(n, x, a);

  return 0;
}


Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<tuple>
#include<cmath>


#define MOD 1000000007
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back

typedef long long ll;

using namespace std;

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

int main(){
    int N,K;
    cin>>N>>K;
    vector<int> A(N);

    rep(i,0,N){
        cin>>A[i];
    }

    cout<<(N-1-1)/(K-1)+1;
    return 0;
}

Measured memory_bytes: 640
import numpy as np
 
n = int(input())
li = [[int(i) for i in input().split()] for _ in range(n)]
arr = np.array(li)

tmp_index = np.arange(arr.shape[0])
x, y = np.meshgrid(tmp_index, tmp_index)
distances = np.linalg.norm(arr[x]-arr[y], axis=2)
print(np.sum(distances) / n)

Measured memory_bytes: 21796
#include<stdio.h>

int main(){
    
    int r,c,i,j;
    int rc[101][101]={0};
    
    scanf("%d %d",&r,&c);
    for(i=0; i<r; i++){
        for(j=0; j<c; j++){
            scanf("%d",&rc[i][j]);
        }
    }
    for(i=0; i<r; i++){
        for(j=0; j<c; j++){
            rc[i][c] += rc[i][j];
            rc[r][j] += rc[i][j];
        }
    }
    for(i=0; i<r; i++){
        rc[r][c] += rc[i][c];
    }
    
    for(i=0; i<r+1; i++){
        for(j=0; j<c+1; j++){
            if(j<c) printf("%d ",rc[i][j]);
            else printf("%d\n",rc[i][j]);
        }
    }
    
    return 0;
}

Measured memory_bytes: 648
n, k = map(int, input().split())


MAX_PAIR = (n-1)*(n-2)//2
if MAX_PAIR < k:
    print(-1)
else:
    m = n-1+MAX_PAIR-k
    print(m)
    for v2 in range(2, n+1):
        print(1, v2)
        m -= 1
    if m == 0:
        exit()

    for v in range(2, n):
        for v2 in range(v+1, n+1):
            print(v, v2)
            m -= 1
            if m == 0:
                exit()

Measured memory_bytes: 3608
ddd = [input() for i in range(2)]
eee = ddd[0].split()
fff = ddd[1].split()
longest_distance = int(eee[0]) + int(fff[0]) - int(fff[-1])
for i in range(len(fff) - 1):
    distance = int(fff[i+1]) - int(fff[i])
    if longest_distance < distance:
        longest_distance = distance
shortest_road = int(eee[0]) - longest_distance
print(shortest_road)


Measured memory_bytes: 18508
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _1_1_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] i  = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            Array.Sort(i);
            Console.WriteLine(i[0] +  " " + i[1] + " " + i[2]);
        }
    }
}



Measured memory_bytes: 16424
a, b = map(int, input().split())
o1 = o2 = o3 = -1
for i in range(min(a+1, (b//10000)+1))[::-1]:
    for j in range(min(a-i+1, ((b-10000*i)//5000)+1))[::-1]:
        k = a-i-j
        if b == i*10000+j*5000+k*1000:
            o1 = i
            o2 = j
            o3 = k
            break
print(o1, o2, o3)


Measured memory_bytes: 3188
#include <stdio.h>
#include <math.h>

int main(void)
{
    int N;
    int T, A;
    int H;
    double avr, min, dif;
    int num;
    int i;
    
    scanf("%d%*c", &N);
    scanf("%d %d%*c", &T, &A);
    for(i = 0; i < N; i++){
        scanf("%d%*c", &H);
        avr = T - H * 0.006;
        dif = fabs(A - avr);
        if(i == 0 || dif < min){
            min = dif;
            num = i;
        }
    }
    printf("%d\n", num + 1);
    
    return 0;
}

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

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX], facn[MAX];

// テーブルを作る前処理
void COMinit(ll n) {
    fac[0] = fac[1] = 1;
    facn[1] = n; 
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        facn[i] = facn[i-1] * (n-i+1) % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}


// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return facn[k] * finv[k] % MOD;
}

ll modpow(int n, ll x) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res*x%MOD;
    x = x*x%MOD;
    n>>=1;
  }
  return res;
}

int main() {

    ll n, a, b; cin >> n >> a >> b;
  COMinit(n);

  
  ll ans = (modpow(n, 2) - 1 + MOD)%MOD;

  
  ans = (ans - COM(n, a) + MOD)%MOD;

  
  ans = (ans - COM(n, b) + MOD)%MOD;
  cout << ans << endl;
}

Measured memory_bytes: 16128
import sys
input = sys.stdin.readline
from collections import *

def factorize(n):
    fct = []
    
    for i in range(2, int(n**0.5)+1):
        c = 0
        
        while n%i==0:
            n //= i
            c += 1
            
        if c>0:
            fct.append((i, c))
    
    if n>1:
        fct.append((n, 1))
    
    return fct

N = int(input())
fs = factorize(N)
ans = 0

for _, C in fs:
    c = 1
    
    while C-c>=0:
        ans += 1
        C -= c
        c += 1

print(ans)

Measured memory_bytes: 66332
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <numeric>
#include <vector>
#include <set>
#include <queue>

using namespace std;

void solve(int n){
	int val[30];
	int bridge[30];
	for(int i=0;i<n;i++){
		scanf("%d%d",&val[i],&bridge[i]);
	}
	bool used[30];
	for(int i=0;i<n;i++){
		used[i] = false;
	}
	int ans = 0;
	for(int t=0;t<n;t++){
		// ?????£?????????????????§????????????????????????????????????????????????????????¢???
		int target = 0;
		for(int i=1;i<n;i++){
			if(used[i])continue;
			if(used[target] || bridge[i]<bridge[target] || (bridge[i]==bridge[target] && val[i]>bridge[target])){
				target = i;
			}
		}
		used[target] = true;
		// ?????£?????????
		if(ans+val[target] <= bridge[target]){
			ans += val[target];
		}else{
			printf("No\n");
			return;
		}
	}
	printf("Yes\n");
	return;
}

int main(){
	while(true){
		int n;
		scanf("%d",&n);
		if(n==0)break;
		solve(n);
	}
	return 0;
}

Measured memory_bytes: 1168
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef complex<double> P;
static const double EPS = 1e-8;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

int main(void){
  int n;
  cin>>n;
  while(n--){
    string snake;
    cin>>snake;
    if(snake[0]=='>'&&snake[1]=='\''&&snake[snake.size()-1]=='~'){
      int count=0;
      int end;
      for(int i=2;i<snake.size()&&snake[i]=='='; i++){
        count++;
        end = i;
      }
      end++;
      if(count&&snake[end]=='#'&&end+count+2==snake.size()){
        bool yes = true;
        for(int i=end+1;i<snake.size()-1;i++){
          if(snake[i]!='=')yes = false;
        }
        if(yes){
          cout<<"A"<<endl;
        }else{
          cout<<"NA"<<endl;
        }
      }else{
        cout<<"NA"<<endl;
      }
    }else if(snake[0]=='>'&&snake[1]=='^'&&snake[snake.size()-1]=='~'&&snake[snake.size()-2]=='~'
        &&snake[snake.size()-3]=='='){
      bool yes = true;
      for(int i=2;i<snake.size()-2;i++){
        if(i%2==0&&snake[i]!='Q') yes = false;
        if(i%2==1&&snake[i]!='=') yes = false;
      }
      if(yes){
        cout<<"B"<<endl;
      }else{
        cout<<"NA"<<endl;
      }
    }else{
      cout<<"NA"<<endl;
    }
  }
  return 0;
}

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

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

    int a[30];
    for (int i = 0; i < w; ++i) {
        a[i] = i + 1;
    }

    while (n--) {
        int i,j;
        scanf("%d,%d", &i, &j);
        swap(a[i-1], a[j-1]);
    }

    for (int i = 0; i < w; ++i) {
        cout << a[i] << "\n";
    }

    return 0;
}

Measured memory_bytes: 1244
#include<bits/stdc++.h>
 using namespace std;
int main(){
  int n, res; cin >> n;
  for (size_t i = 1; i < 10; i++) {
    if (n <= 111*i) {
      res = 111*i;
      break;
    }
  }
    cout << res << "\n";

}


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

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

  vector<int> L(N);
  for(int i=0;i<N;++i){
    cin>>L.at(i);
  }

  int D=0;
  int count=1;
  int i=0;
  while(i<N && D+L.at(i)<=X){
    D=D+L.at(i);
    ++count;
    ++i;
  }

  cout<<count<<endl;
}

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

const int N = 100005;
const int MAX = 1 << 16;
const int inf = 1e9;

int n, a[N];
int cnt[16];
int dp[MAX];
int fxor[MAX];
int ans;
vector<int> rem;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for (int i = 1; i < n; ++i) {
		int u, v, w; cin >> u >> v >> w;
		a[u] ^= w;
		a[v] ^= w;
	}

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

	for (int i = 1; i < 16; ++i) {
		ans += cnt[i] / 2;
		cnt[i] %= 2;
		if (cnt[i]) rem.push_back(i);
	}

	int sz = rem.size();
	for (int mask = 0; mask < (1 << sz); ++mask) {
		for (int i = 0; i < sz; ++i) if (mask >> i & 1) fxor[mask] ^= rem[i];
	}
	
	for (int mask = 0; mask < (1 << sz); ++mask) dp[mask] = inf;
	dp[0] = 0;
	for (int mask = 1; mask < (1 << sz); ++mask) {
		for (int submask = mask; submask > 0; submask = mask & (submask - 1)) {
			if (fxor[submask] == 0) {
				dp[mask] = min(dp[mask], dp[mask ^ submask] + __builtin_popcount(submask) - 1);
			}
		}
	}

	cout << ans + dp[(1 << sz) - 1] << endl;
}

Measured memory_bytes: 896
#include <stdio.h>
#include <string.h>

int main(void)
{
    char buff[256];   

       scanf("%s",buff);        

        if(!strcmp(buff, "A"))   
            printf("T");      
        else if(!strcmp(buff, "T"))  
           printf("A");
          else if(!strcmp(buff, "G"))   
           printf("C");
          else if(!strcmp(buff, "C"))   
           printf("G");
 return(0);
    }

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

int main()
{
    ll h, w;
    cin >> h >> w;
    P m[h][w];
    rep(i, h)
    {
        string s;
        cin >> s;
        rep(j, s.size())
        {
            if (s[j] == '#')
                m[i][j] = {-1, -1};
            else
                m[i][j] = {0, 0};
        }
    }
    rep(i, h) rep(j, w)
    {
        P p = m[i][j];
        if (p.first == -1)
            continue;
        if (p.first == 0)
        {
            for (ll k = i; k < h; k++)
            {
                if (k == h - 1 || m[k + 1][j].first == -1)
                {
                    for (ll l = i; l <= k; l++)
                    {
                        m[l][j].first = k - i + 1;
                    }
                    break;
                }
            }
        }
        if (p.second == 0)
        {
            for (ll k = j; k < w; k++)
            {
                if (k == w - 1 || m[i][k + 1].second == -1)
                {
                    for (ll l = j; l <= k; l++)
                    {
                        m[i][l].second = k - j + 1;
                    }
                    break;
                }
            }
        }
    }
    ll ans = 0;
    rep(i, h) rep(j, w)
    {
        P p = m[i][j];
        ans = max(ans, p.first + p.second - 1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 66116
def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


x=int(input())

while is_prime(x)==False:
    if x%2==0:
        x+=1
    else:
        x+=2
    
print(x)

Measured memory_bytes: 2940
//  ROAD TO GREEN
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <queue>
#include <set>
#include <bitset>

#define ll long long
#define uint unsigned int
#define ull unsigned ll
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define speedhack() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define do(x) for(int i = 1; i <= x; i++){ solve(); }

using namespace std;
const ll MAXN = 2e9+2;
const ll SIZE = 1e5+2;
const ll mod = 1e9+7;
vector<bool> used(SIZE,false);


void solve(){
	int n,m;
	cin >> n >> m;
	int maxx = 0;
	int minn = 1e6;
	for(int i = 1; i <= m; i++){
		int l,r;
		cin >> l >> r;
		maxx = max(maxx,l);
		minn = min(minn,r);
	}
	int ans = minn-maxx+1;
	if(minn-maxx < 0){
		cout << 0 << endl;
	}else{
		cout << ans << endl;
	}
}

int main(){ 
	speedhack()
	// int it; cin >> it;
	int it = 1;
	do(it);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mp make_pair
 #define pb push_back
 const int N =(1e5) + 1;

int main() 
{
 fast;

 int n;
 cin>>n;
 int x , y, z;
 cin>>x>>y>>z;
 int dp[n][3]={};
 dp[0][0] = x;
dp[0][1] = y;
 dp[0][2] = z;

 for (int i = 1; i < n; ++i)
 {
   cin >> x >> y >> z;
  
   dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + x;
   dp[i][1] = max(dp[i-1][0],dp[i-1][2]) + y;
   dp[i][2] = max(dp[i-1][0],dp[i-1][1]) + z; 
 }
int max1 = 0;
for (int i = 0; i < 3; ++i)
{
 max1 = max(max1,dp[n-1][i]);
}
cout<<max1;

}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  
  int n;
  cin >> n;
  int h[n], t[n];
  for(int& i : h)
    	cin >> i;
  for(int& i : t)
    	i = 1e9;
  t[0] = 0;
  for(int i = 0; i < n-1; i++) {
    	t[i+1] = min(t[i+1], t[i] + abs(h[i] - h[i+1]));
    	t[i+2] = min(t[i+2], t[i] + abs(h[i] - h[i+2]));
  }
  t[n-1] = min(t[n-1], t[n-2] + abs(h[n-1] - h[n-2]));
  cout << t[n-1];
}

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

/*alias*/
#define REP(i,n) for (int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
using ll=long long;

using namespace std;

/*input*/
string s;

/*funcs*/


/*main*/
int main(){
    cin>>s;
    int k=s.length();
    int rest=15-k;
    int count=0;
    for(int i=0;i<k;i++){
        if(s[i]=='o'){
            count++;
        }
    }
    if(count+rest>=8){
        cout<<"YES";
    }else{
        cout<<"NO";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>  
 
using namespace std;
 
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define FORr(i, j, k) for(int i = j; i >= k; --i)
#define repr(i, j) FOR(i, j, 0)
#define INF (1 << 30)
#define MOD 1e9 + 7
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;

int N;
ll K;
vector<P> p;

int main() {
	scanf("%d %lld", &N, &K);
	rep(i, N) {
		ll a, b;
		scanf("%lld %lld", &a, &b);
		p.push_back(P(a, b));
	}
	sort(p.begin(), p.end());
	ll total = 0;
	rep(i, p.size()) {
		total += p[i].second;
		if(total >= K) {
			cout << p[i].first << endl;
			break;
		}
	}
	return 0;
}

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

#define mp          make_pair
#define pb          push_back
#define ff          first
#define ss          second
#define ii          pair<int,int>
#define mod         1e9+7
#define inf         1e18

typedef long long int ll;
typedef long double ld;

#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;


int dp[3005][3005];   //as per constraints

int lcs(string s1,string s2,int l1,int l2)
{
    for(int i=0;i<l1+1;i++)
    {
        for(int j=0;j<l2+1;j++)
        {
            if(i==0 or j==0)
                dp[i][j]=0;
        }
    }

    for(int i=1;i<l1+1;i++)
    {
        for(int j=1;j<l2+1;j++)
        {
            if(s1[i-1] == s2[j-1])
                dp[i][j]=1+dp[i-1][j-1];
            else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }

    return 0;
}

void solve()
{
    string s1,s2;
    cin>>s1>>s2;
    string s="";

    int l1=s1.size();
    int l2=s2.size();
    lcs(s1,s2,l1,l2);

    int i=l1,j=l2;
    while(i>0 and j>0)
    {
        if(s1[i-1]==s2[j-1])
        {
            s.push_back(s1[i-1]);
            i--;
            j--;
        }
        else
        {
            if(dp[i][j-1] > dp[i-1][j])
                j--;
            else
                i--;
        }
    }
    
    reverse(s.begin(),s.end());
    cout<<s<<endl;
}

int main()
{
    fio;
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int t=1;
//    cin>>t;
    for(int i=0;i<t;i++)
    {
        solve();
    }
    return 0;
} 

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;

int main(){
  int H,W;
  cin >> H >> W;
  vector<vector<int> > a(H);
  vector<vector<int> > b(H);

  REP(i,H){
    REP(j,W){
      int v;
      cin >> v;
      a[i].push_back(v);
    }
  }
  REP(i,H){
    REP(j,W){
      int v;
      cin >> v;
      b[i].push_back(v);
    }
  }

  int MAXAB=(H+W)*80;
  bool dp[H][W][MAXAB];

  REP(i,H)REP(j,W)REP(k,MAXAB)dp[i][j][k]=false;

  dp[0][0][abs(a[0][0]-b[0][0])] = true;

  REP(i,H)REP(j,W){
    if(i==0 && j ==0)continue;
    if(i!=0){
      REP(k,MAXAB){
        if(dp[i-1][j][k]==false)continue;
        dp[i][j][k+abs(a[i][j]-b[i][j])] = true;
        dp[i][j][abs(k-abs(a[i][j]-b[i][j]))] = true;
      }
    }
    if(j!=0){
      REP(k,MAXAB){
        if(dp[i][j-1][k]==false)continue;
        dp[i][j][k+abs(a[i][j]-b[i][j])] = true;
        dp[i][j][abs(k-abs(a[i][j]-b[i][j]))] = true;
      }
    }
  }

  REP(k,MAXAB){
    if(dp[H-1][W-1][k] == false)continue;
    printf("%d\n",k);
    break;
  }

}



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

    #define ll long long
    #define ff first
    #define ss second
    #define pb push_back
    #define vll vector<ll>
    #define mll map<ll,ll>
    #define MOD 1000000007
    #define pll pair<ll,ll>
constexpr ll INF = 1999999999999999997; 
    #define fastio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
    int main() {
      fastio;
      int n;
      cin>>n;
    string a,b;
    cin>>a>>b;
    
   // vector<char>ans;
   for(int i=0;i<n;i++)
   {
       cout<<a[i]<<b[i];
   }

    }

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

int main(){
  int k,n;
  cin >> k >> n;
  vi a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(),a.end());
  int ans = 0;
  rep(i,n){
    if(i == n-1) ans = max(ans, k-a[n-1]+a[0]);
    else ans = max(ans, a[i+1]-a[i]);
  }
  cout << k-ans << endl;
}


Measured memory_bytes: 3972
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <iomanip>
using namespace std;
typedef long long ll;

#define rep(i,n) for (int i=0; i<(n); i++)
const int INF =1001001001;
const ll BIG = 1000000007;
const double PI = 3.141592653589793;

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> to[n];
    rep(i,m) {
        int a,b;
        cin >> a >> b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    queue<int> q;
    vector<int> dist(n,0);
    vector<int> visit(n,INF);
    q.push(0);
    dist[0] = 0; 
    while(!q.empty()){
        int i = q.front(); q.pop();
        for(auto j:to[i]){
            if(visit[j]!=INF) continue;
            visit[j] = i;
            dist[j] = dist[i]+1;
            q.push(j);
        }
    }
    cout << "Yes" << endl;
    rep(i,n){
        if(i==0) continue;
        int ans = visit[i];
        ++ans;
        cout << ans << endl;
    }
    return 0;
}


/*
vector<int> to[100005];

int main(){
    int n,m;
    cin >> n >> m;
    rep(i,m) {
        int a,b;
        cin >> a >> b;
        --a; --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    for(auto a: to[3]){
        cout << a << endl;
    }
    queue<int> q;
    vector<int> dist(n, INF);
    vector<int> pre(n, -1);
    dist[0] = 0;
    q.push(0);
    while (!q.empty()) {
        int v = q.front(); q.pop();
        for(auto u: to[v]){
            if(dist[u]!=INF) continue;
            dist[u] = dist[v]+1;
            pre[u] = v;
            q.push(u);
        }
    }
    cout << "Yes" << endl;
    rep(i,n){
        if(i==0) continue;
        int ans = pre[i];
        ++ans;
        cout << ans << endl;
    }
    return 0;
}

*/

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

int main()
{
    long H;
    int N;
    cin >> H >> N;
    int A[N];
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        H -= A[i];
        if (H <= 0)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;



int main(){
    while(1){
        int m,f,r;
        cin>>m>>f>>r;
        if(m==-1&&f==-1&&r==-1) break;
        int s=m+f;
        if(m==-1||f==-1) cout<<"F"<<endl;
        else if(s>=80) cout<<"A"<<endl;
        else if(s>=65) cout<<"B"<<endl;
        else if(s>=50) cout<<"C"<<endl;
        else if(s>=30){
            if(r>=50) cout<<"C"<<endl;
            else   cout<<"D"<<endl;
        }
        else  cout<<"F"<<endl;
}}

Measured memory_bytes: 1156
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int mask[15],p[15];
int main()
{
	memset(mask,0,sizeof(mask));
	int n,m,k,s,out=0;
	cin>>n>>m;
	rep(i,m){
		cin>>k;
		rep(j,k){
			cin>>s;s--;mask[i]+=(1<<s);
		}
	}
	rep(i,m) cin>>p[i];
	rep(i,(1<<n)){
		int f=1;
		rep(j,m){
			int x=(i&mask[j]);
			if(__builtin_popcount(x)%2!=p[j]) f=0;
		}
		out+=f;
	}
	cout<<out<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include "cmath"
using namespace std;

int main(int argc, const char * argv[]) {
    long long  a;
    cin>>a;
    if (a==0) {
        cout<<2<<endl;
    }else if (a==1) {
        cout<<1<<endl;
    }else{
        long long  x=2;
        long long  y=1;
        long long out=0;
        for (long long i = 0; i<a-1; i++) {
            out=x+y;
            x=y;
            y=out;
        }
        cout<<out<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import os
import sys
from io import BytesIO, IOBase
import math


def inputIntArray():
    return list(map(int, input().rstrip().split()))


def inputArray():
    return input().rstrip().split()


def inputVars():
    return map(int, input().rstrip().split())


def inputNum():
    return int(input())


def main():
    totalAnimals, noOfLegs = inputVars()
    ans = 'No'
    for num in range(totalAnimals+1):
        rest = totalAnimals-num
        if 2*num+4*rest==noOfLegs:
            ans = 'Yes'
            break
    print(ans)



#.........................................FAST INPUT OUTPUT.......................................
BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

#....................................END OF FAST I/O............................................

if __name__ == "__main__":
    main()

Measured memory_bytes: 63040
#include <iostream>

using namespace std ;

int main()
{
  long long int a, b, x, y, t, gcd, lcm;

  while(cin>>x>>y)
  {
     a = x;
     b = y;

    while (b != 0)
        {
            t = b;
            b = a % b;
            a = t;
        }

    gcd = a;
    lcm = (x*y)/gcd;


    cout<<gcd<<" "<<lcm<<endl ;
  }




  return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

	string S; cin >> S;

	cout << "2018"+S.substr(4,6) << endl;

	return 0;

}


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

typedef long long ll;

int main(){
    ll k, n;
    cin>> k >> n;

    vector<ll> a(2*n);
    vector<ll> dis(n+1);

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

    ll ans = 1e18;
    for(int i=0; i<n; i++){
        ans = min(ans, abs(a[i+n-1] - a[i]));
    }
    cout<< ans <<endl;
    return 0;
}

Measured memory_bytes: 7932
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for (uint64_t i = 0;     i <  n; ++i)
#define N_TIMES_REV(i, n) for ( int64_t i = n - 1; i >= 0; --i)

#ifdef __DEBUG__
template<typename T, typename U>
std::ostream& operator<<(std::ostream &os, const std::pair<T, U> &pair)
{
  os << pair.first << ": " << pair.second;
  return os;
}

template<class ForwardIterator>
std::ostream& _iterator_to_display(
  std::ostream &os, 
  ForwardIterator begin, ForwardIterator end, 
  const std::string &delim = ", "
)
{
  auto itr = begin;
  while (itr != end) {
    os << *itr;
    ++itr;
    if (itr != end) os << delim;
  }
  return os;
}

template<typename T>
std::ostream& operator<<(std::ostream &os, const std::list<T> &list)
{
  _iterator_to_display(os, list.begin(), list.end());
  return os;
}

template<typename T>
std::ostream& operator<<(std::ostream &os, const std::vector<T> &vector)
{
  _iterator_to_display(os, vector.begin(), vector.end());
  return os;
}

template<typename T, class C=std::less<T>>
std::ostream& operator<<(std::ostream &os, const std::set<T> &set)
{
  _iterator_to_display(os, set.begin(), set.end());
  return os;
}

template<typename T, typename U, class C=std::less<T>>
std::ostream& operator<<(std::ostream &os, const std::map<T, U> &map)
{
  _iterator_to_display(os, map.begin(), map.end());
  return os;
}
#endif /* __DEBUG__ */

int main(int argc, char **argv)
{
  std::array<unsigned, 3> A;
  N_TIMES(n, 3) std::cin >> A[n];
  
  std::sort(A.begin(), A.end());
  
  std::cout << (A[2] - A[0]) << std::endl;
  
  return 0;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    ll S;
    cin >> S;
    ll x1, y1, x2, y2, x3, y3;
    x1 = y1 = 0;

    ll t = sqrt(S);
    if (t * t == S) {
        x2 = t;
        y2 = 0;
        x3 = 0;
        y3 = t;
    } else {
        x2 = t + 1;
        y2 = x2 * x2 - S;
        x3 = 1;
        y3 = t;
    }

//    cout << x1 << " " << y1 << " " << x2 << " " << y2 << " " << x3 << " " << y3 << endl;

    if (t * t == S) {
        cout << x1 << " " << y1 << " " << x2 << " " << y2 << " " << x3 << " " << y3 << endl;
//        cout << "0 0 " << t << " " << "0 0 " << t << "\n";
        return 0;
    }
    t += 1;
    ll e = t * t - S;
    cout << x1 << " " << y1 << " " << x2 << " " << e << " " << x3 << " " << t << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,a,b) for(int i=(a),ed=(b);i<=ed;++i)
#define pb(x) push_back((x))
inline int read(){
	register int x=0,f=1;register char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=0;ch=getchar();}
	while(isdigit(ch)){x=x*10+(ch^'0');ch=getchar();}
	return f?x:-x;
}

const int N=1e5+10;
int n,m,p[N],vis[N],f[N],head[N],num;
inline int find(int x){return f[x]=f[x]==x?f[x]:find(f[x]);}
struct edge{int to,next;}e[N<<1];
inline void add(int u,int v){e[++num]=(edge){v,head[u]},head[u]=num;}
vector<int> E[N];
ll dp[N],s[N],a[N],b[N],w[N];
inline bool cmp_w(const int &a,const int &b){return w[a]<w[b];}

inline void Dfs(int u){
	s[u]=b[u];
	for(int v:E[u]){
		Dfs(v);s[u]+=s[v];
	}
	if(s[u]==b[u]){dp[u]=b[u]+w[u];return;}
	for(int v:E[u]){
		dp[u]=min(dp[u],s[u]-s[v]+max(w[u],dp[v]));
	}
}

int main(){
	//freopen("in.in","r",stdin);
	n=read(),m=read();
	REP(i,1,n)a[i]=read(),b[i]=read(),w[i]=max(a[i]-b[i],0ll),p[i]=i;
	REP(i,1,m){
		int u=read(),v=read();
		add(u,v),add(v,u);
	}
	REP(i,1,n)f[i]=i;
	sort(p+1,p+n+1,cmp_w);
	REP(i,1,n){
		vis[p[i]]=1;
		for(int j=head[p[i]];j;j=e[j].next){
			if(!vis[e[j].to])continue;
			int x=find(e[j].to);
			if(x^p[i])f[x]=p[i],E[p[i]].pb(x);
		}
	}
	int pa=find(1);
	REP(i,1,n)dp[i]=1e18;
	Dfs(pa);
	printf("%lld\n",dp[pa]);
	return 0;
}


Measured memory_bytes: 14848
#include <iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include <string>
#include <set>
#include <bitset>

using namespace std;
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define i64 int64_t
#define tos(x) to_string(x)

int main() {
	int n;
	cin >> n;
	int a = 0;
	ff(i, 1, 10) {
		a = n / i;
		if (a < 10 && n % i == 0) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
def io_tmp():
    global input
    import io, sys
    f = io.BytesIO(sys.stdin.buffer.read())
    input = f.readline

io_tmp()


from scipy.sparse.csgraph import floyd_warshall
import numpy as np

N, M, L = map(int, input().split())
graph = np.zeros((N, N), dtype=np.int64)
for _ in range(M):
    s, t, w = map(int, input().split())
    if w <= L:
        graph[s-1, t-1] = graph[t-1, s-1] = w
dist = floyd_warshall(graph, directed=False)
dist = floyd_warshall(dist <= L, directed=False)
dist[np.isinf(dist)] = 0.0

Q = int(input())
ans = []
for _ in range(Q):
    s, t = map(int, input().split())
    ans.append(int(dist[s-1][t-1]) - 1)
print(*ans, sep='\n')


Measured memory_bytes: 19628
#include <bits/stdc++.h>
#define F(i, l, r) for(int i = (l), _end_ = (int)(r); i <= _end_; ++i)
#define f(i, r, l) for(int i = (r), _end_ = (int)(l); i >= _end_; --i)
#define Set(a, v) memset(a, v, sizeof(a))
#define file(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
using namespace std;

template<typename T>bool chkmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool chkmin(T &a,T b){return (a>b)?a=b,1:0;}

inline int read() {
 int x = 0, fh = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar() ) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar() ) x = (x<<1) + (x<<3) + (ch ^ '0');
    return x * fh;
}
int n,k;
int dp[2005][2005];
const int mod=1e9+7;
long long qpow(long long x,long long y){
    long long res=1;
	while(y){
	    if(y&1)res=res*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return res;
}
int ff[2005*2500],inv[2005*2500];
int main () {
#ifndef ONLINE_JUDGE
//file("agc002f");
#endif
    n=read();k=read();
	k--;
	if(!k){
	  puts("1");
	  return 0;
	}
	ff[0]=1;
	F(i,1,n*k+n+k)ff[i]=1ll*i*ff[i-1]%mod;
	inv[n*k+n+k]=qpow(ff[n*k+n+k],mod-2);
	f(i,n*k+n+k-1,0)inv[i]=1ll*inv[i+1]*(i+1)%mod;
	dp[0][0]=1;
	F(i,0,n){
	   F(j,i,n){
	     if(i)dp[i][j]=dp[i-1][j];
		 if(j)dp[i][j]=(dp[i][j]+1ll*dp[i][j-1]*inv[k-1]%mod*ff[i+(j-1)*k+k-1]%mod*inv[i+(j-1)*k]%mod)%mod;
	   }
	}
	printf("%lld\n",1ll*dp[n][n]*ff[n]%mod);
    return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  string joi = "JOI";
  vary(ll,ans,3,0);
  ll cnt = 0;
  ll ma = 0;
  s += "J";
  rep(i,s.size()){
    if(s[i] == joi[cnt]){
      ans[cnt]++;
    }
    else if(cnt < 2 && s[i] == joi[cnt+1] && ans[cnt] > 0){
      ++cnt;
      ans[cnt]++;
    }
    else{
      cnt = 0;
      if(ans[0] >= ans[1] && ans[1] <= ans[2]){
        ma = max(ma,ans[1]);
      }
      ans[0] = ans[1] = ans[2] = 0;
      if(s[i] == 'J') ans[0]++;
    }
  }
  cout << ma << endl;
  return 0;
}

Measured memory_bytes: 4568