akhauriyash/Code-Regression huggingface dataset:
import fractions
n, m = map(int, input().split())
*a, = map(int, input().split())

lcm = a[0]//2

for x in a:
    x //= 2
    g = fractions.gcd(lcm, x)
    if (lcm//g)%2 != (x//g)%2:
        print(0)
        quit()

    lcm = lcm*x//g

print((m//lcm + 1)//2)


Measured memory_bytes: 16280
package main
import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	N := nextInt()
	S := nextLine()
	for i := 0; i < len(S); i++ {
		toInt := int(S[i])
		if toInt + N > 90 {
			fmt.Print(string(toInt + N - 90 + 64))
		} else {
			fmt.Print(string(toInt + N))
		}
	}
	fmt.Println()
}

Measured memory_bytes: 896
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    H = LI()

    ans = 0
    m = 0
    for i in H:
        if i >= m:
            ans += 1
        m = max(i, m)

    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10056
n = int(input())
l = sorted(list(map(int,input().split())))
ans = 0
if n<3:
  print(0)
  exit()
for i in range(n-2):
  for j in range(i,n-1):
    for k in range(j,n):
      if l[i]+l[j]>l[k] and l[i]+l[k]>l[j] and l[k]+l[j]>l[i] and l[i]!=l[j]!=l[k]:
        ans +=1
     
print(ans)

Measured memory_bytes: 9232
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int r,g,b;
    cin>>r>>g>>b;
    int num=(r*100)+(g*10)+b;
    if(num%4==0){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second
signed main(){
  int h,w;
  cin>>h>>w;
  if(h!=2&&w!=2)cout<<max((int)1,h-2)*max((int)1,w-2)<<endl;
  else cout<<0<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int bin_search(int S[],int left,int right,int x){
	int pivot=((right+left)/2);
	if(S[left]==x || S[right]==x || S[pivot]==x){
		return 1;
	}
	if(left > right){
		return 0;
	}
	int ans=0;

	if(S[pivot] > x){
		ans=bin_search(S,left+1,pivot,x);
	}else{
		ans=bin_search(S,pivot,right-1,x);
	}

	return ans;
}

int main(){
	int n,*S;
	int q,T;
	int count=0;

	scanf("%d",&n);
	S=(int*)malloc(sizeof(int)*n);
	for(int i=0;i<n;i++){
		scanf("%d",&S[i]);
	}
	scanf("%d",&q);
	for(int i=0;i<q;i++){
		scanf("%d",&T);
		count+=bin_search(S,0,n-1,T);
		
	}
	printf("%d\n",count);

   return 0;
}


Measured memory_bytes: 2100
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

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

ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}

//-----------------------ここから-----------

int main(void){
    int k, s;
    cin >> k >> s;

    int ans = 0;

    for(int i = 0; i <= k; i++){
        for(int j = 0; j <= k; j++){
            if(i + j <= s && s - (i + j) <= k){
                ans++;
            }
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
X, N = input().split()
X = int(X)
N = int(N)

if N == 0:
    print(X)
    exit()

P = input().split()
for i in range(len(P)):
    P[i] = int(P[i])

if X not in P:
    print(X)
    exit()


abs_num_p = X + 1
abs_num_n = X - 1
while True:

    if abs_num_p in P:
        flag_p = True
    else:
        flag_p = False

    if abs_num_n in P:
        flag_n = True
    else:
        flag_n = False
    if(  flag_p == True  and flag_n == True ):
        abs_num_p += 1
        abs_num_n -= 1
        continue;
    elif(flag_p == True  and flag_n == False):
        print(abs_num_n)
        break;
    elif(flag_p == False and flag_n == True ):
        print(abs_num_p)
        break;
    elif(flag_p == False and flag_n == False):
        print(abs_num_n)
        break;

    i += 1


Measured memory_bytes: 9232
import java.util.Arrays;
import java.util.Scanner;


public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int w = sc.nextInt();
			int h = sc.nextInt();
			
			if(w == 0){
				break;
			}
			
			char[][] input = new char[h][w];
			
			for(int i = 0; i < h; i++){
				String str = sc.next();
				
				for(int j = 0; j < w; j++){
					input[i][j] = str.charAt(j);
				}
			}
			
			String[][] dp = new String[h][w];
			
			for(int i = 0; i < h ; i++){
				Arrays.fill(dp[i], "");
			}
			
			String result = "0";
			for(int i = 0; i < h; i++){
				for(int j = 0; j < w; j++){
					if(!Character.isDigit(input[i][j])){
						continue;
					}
					
					String uNum = "";
					String lNum = "";
					
					if(i != 0 && !dp[i - 1][j].equals("0")){
						uNum = dp[i - 1][j];
					}
					
					if(j != 0 && !dp[i][j - 1].equals("0")){
						lNum = dp[i][j - 1];
					}
					
					uNum += input[i][j];
					lNum += input[i][j];
					
					String tmp = comp(uNum, lNum);
					dp[i][j] = tmp;
					
					result = comp(result, tmp);
				}
				
			}
			
			//debug
//			for(int i = 0; i < h; i++){
//				for(int j = 0; j < w; j++){
//					System.out.print(dp[i][j]+" ");
//				}
//				System.out.println();
//			}
			System.out.println(result);
		}
	}
	
	static String comp(String str1, String str2){
		if(str1.length() > str2.length()){
			return str1;
		}
		else if(str1.length() < str2.length()){
			return str2;
		}
		
		//文字列の長さが等しい場合の処理
		for(int i = 0; i < str1.length(); i++){
			if(str1.charAt(i) > str2.charAt(i)){
				return str1;
			}
			else if(str1.charAt(i) < str2.charAt(i)){
				return str2;
			}
		}
		
		return str1;
	}

}



Measured memory_bytes: 67824
AC = 0
WA = 0
TLE = 0
RE = 0

N = int(input())
for _ in range(N):
    TMP = input()
    #print(TMP)
    if TMP == "AC":
        AC += 1
    elif TMP == "WA":
        WA += 1
    elif TMP == "TLE":
        TLE += 1
    elif TMP == "RE":
        RE += 1

print("AC x " + str(AC))
print("WA x " + str(WA))
print("TLE x " + str(TLE))
print("RE x " + str(RE))

Measured memory_bytes: 9176
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		int n = in.nextInt();
		int xor_sum = 0;
		for ( int i = 0; i < n; i++ ) {
			xor_sum = xor_sum ^ in.nextInt();
		}
		
		if(xor_sum == 0) System.out.println("Yes");
		else System.out.println("No");
		
		in.close();
	}
}

Measured memory_bytes: 49108
#include"iostream"
#include"cmath"
#include"string"
#include"string.h"
#include"algorithm"
#include"vector"
#include"map"
#include"queue"
#include"stack"
#include"set"
#include"climits"
#include"deque"
#include"tuple"
#include"iomanip"
using namespace std;
#define int                  int64_t
#define double               long double
#define vi                   vector<int>
#define di                   deque<int>
#define si                   set<int>
#define vpii                 vector<pair<int,int>>
#define dpii                 deque<pair<int,int>>
#define pi                   pair<int,int>
#define pub                  push_back
#define puf                  push_front
#define pob                  pop_back
#define pof                  pop_front
#define all(a)               (a).begin(),(a).end()
#define rall(a)              (a).rbegin(),(a).rend()
#define PI                   3.1415926535897932384626433832795
#define rep(i,s,n)           for(int i = s; i < n; ++i)
#define repe(i,s,n)          for(int i = s; i <= n; ++i)
#define repr(i,n,s)          for(int i = n;i >= s; --i)
#define read(a)              for(auto& x : a) cin >> x
#define speak(a)             for(auto x : a) cout << x << ' '
#define work(x,a)            for(auto& x : a)
#define endl                 '\n'
#define gap                  ' '
#define MAX                  LLONG_MAX
#define MIN                  LLONG_MIN
#define min3(a,b,c)          min(a, min(b, c))
#define max3(a,b,c)          max(a, max(b, c))
#define MOD                  1000000007
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;cin >> n;
    rep(i,0,10000) if(1000*i>=n) return cout<<1000*i-n,0;
}


Measured memory_bytes: 3640
a, b, k = map(int, input().split())

min = a
if b < min:
  min = b

ans_lists = []
for i in range(1, min+1, 1):
  if a%i == 0 and b%i == 0:
    ans_lists.append(i)

ans_lists.reverse()
ans = ans_lists[k-1]

print(ans)

Measured memory_bytes: 9144
#include <algorithm>
#include <cstdio>
#include <cstring>

const int N = 105;

int n, A[N], B[N], C[N], D[N];

inline bool check(int i, int j) {
  return A[i] < C[j] && B[i] < D[j];
}

int match[N];
bool vis[N];

bool dfs(int x) {
  for (int y = 0; y < n; ++y) if (!vis[y] && check(x, y)) {
    vis[y] = true;
    if (match[y] == -1 || dfs(match[y])) {
      match[y] = x;
      return true;
    }
  }
  return false;
}

int Solve() {
  int ans = 0;
  memset(match, -1, sizeof match);
  for (int x = 0; x < n; ++x) {
    memset(vis, 0, sizeof vis);
    if (dfs(x)) ++ans;
  }
  return ans;
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d%d", &A[i], &B[i]);
  for (int i = 0; i < n; ++i) scanf("%d%d", &C[i], &D[i]);
  printf("%d\n", Solve());
  return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
#define N 100005
#define ll long long
#define MOD 1000000007
ll x,y;
map<ll,bool> vis;
ll p[N];
int pn;
ll gcd(ll a,ll b)
{
	if(b==0) return a;
	else return gcd(b,a%b);
}
int main()
{
	scanf("%lld %lld",&x,&y);
	ll d=gcd(x,y);
	int ans=1;
	if(d%2==0) ans++;
	while(d%2==0)
		d/=2;
	for(ll i=3;i*i<=d;i+=2)
		if(d%i==0)
		{
			ans++;
			while(d%i==0)
				d/=i;
		}
	if(d!=1) ans++;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
function gets(str){
  this._s = str.split("\n");
  this._y = 0;
};
gets.prototype = {
  a: function(f){
    var s = this._s, y = this._y, r;
    if(typeof s[y] === "string")s[y] = s[y].split(" ").reverse();
    r = s[y].pop();
    if(!s[y].length)this._y++;
    return f?r:+r;
  },
  l: function(f){
    var s = this._s[this._y++].split(" ");
    return f?s:s.map(a=>+a);
  },
  m: function(n,f){
    var s = this._s, y = this._y, r = [], i = 0;
    if(f)for(;i < n; i++)r[i] = s[y+i].split(" ");
    else for(;i < n; i++)r[i] = s[y+i].split(" ").map(a=>+a);
    this._y += n;
    return r;
  },
};
var o=new gets(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var n = o.a();
  if(n === 1)return "Hello World";
  var a = o.a();
  var b = o.a();
  return a+b;
}

Measured memory_bytes: 7372
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.AGC_Challenge
{
    class _019_A
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            long[] qhsd = ReadLongs();
            long n = ReadLong();

            qhsd[1] = Math.Min(qhsd[0] * 2, qhsd[1]);
            qhsd[2] = Math.Min(qhsd[1] * 2, qhsd[2]);
            qhsd[3] = Math.Min(qhsd[2] * 2, qhsd[3]);
            long                res = (n / 2) * qhsd[3];
            if (n % 2 == 1)
            {
                res += qhsd[2];
            }
            Console.WriteLine(res);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3)                                                \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << endl
#define dump_4(x1, x2, x3, x4)                                            \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5)                                        \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
  CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl

#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 all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

using namespace std;

using ll = long long;

const long long MOD = 1000000007;

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

void solve(ll N, ll M, std::vector<ll> a) {
  vector<ll> dp(N + 1, 0);
  vector<bool> r(N, false);

  dp.at(0) = 1;
  rep(i, M) r.at(a.at(i)) = true;

  rep(i, N) {
    if (r.at(i)) continue;
    dp.at(i + 1) += dp.at(i) % MOD;
    if (i != 0) dp.at(i + 1) += dp.at(i - 1) % MOD;
  }

  cout << dp.at(N) % MOD << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll N;
  scanf("%lld", &N);
  ll M;
  scanf("%lld", &M);
  std::vector<ll> a(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &a[i]);
    a.at(i)--;  // 0-indexed
  }
  solve(N, M, std::move(a));
  return 0;
}


Measured memory_bytes: 4764
from bisect import bisect_left, bisect_right

N = int(input())
Ls = list(map(int, input().split()))

Ls.sort()
#print(Ls)

ans = 0
for i in range(N):
    for j in range(i+1, N):
        k = bisect_left(Ls, Ls[i]+Ls[j])
        ans += k-j-1
print(ans)


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
//const ll INF = 1e18;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

int main()
{
	ll n,a,b;
	cin >> n >> a >> b;
	vector<ll> x(n);
	rep(i,n) cin >> x[i];
	ll ans = 0,ma = 0;
	for(int i = 1; i < n; i++){
		ans += min(b,a*(x[i]-x[i-1]));
		//ma = max(ma,x[i]-x[i-1]);
	}
	//ans -= max(ma-b,0LL);

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

Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long lint;
using namespace std;
int main(){
  int N,K;
  cin>>N>>K;
  int P[N];
  for(int i=0;i<N;i++)cin>>P[i];
  set<int> s;
   for(int i=0;i<K;i++)s.insert(P[i]);
  int ans=1;
  for(int i=0;i<N-K;i++) {
    if(P[i]==*s.begin() and P[i+K]>*s.rbegin())ans--;  
    // cerr<<*s.begin()<<" "<<*s.rbegin()<<endl;
    ans++;
    s.erase(P[i]);
    s.insert(P[i+K]);
  }    //相交区间   单调队列 
  int a=0,b=1;
 for(int i=1;i<N;i++)
  {
    if(P[i-1]<P[i])b++;
    else b=1;
    if(b==K)a++;
  }  
  ans-=max(a-1,0);    //不相交区间 
  cout<<ans<<endl;
  return 0;
}


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

int main()
{
  int n;
  while (cin >> n) {
    if (n == 0)
      break;

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

    int target;
    cin >> target;

    int ans = 0, low = 0, high = n-1;
    while (low <= high) {
      ++ans;
      int mid = (low + high) / 2;
      if (array[mid] == target)
	break;
      else if (array[mid] < target)
	low = mid+1;
      else
	high = mid-1;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

typedef struct {
    int ipt; int num;
} tpl;

int asc(const void *a, const void *b) {
    return ((tpl *)a)->ipt - ((tpl *)b)->ipt;
}

int main(void){
    int N;
    scanf("%d", &N);
    int a[100000 + 10];
    tpl array[100000 + 10];
    for (int i = 0; i < N; i++) {
        scanf("%d", &array[i].ipt);
        array[i].num = i + 1;
    }
    qsort(array,N,sizeof (tpl), asc);
    for (int i = 0; i < N; i++) {
        printf("%d ",array[i].num);
    }

}


Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
int N;
vector<int> nums;
stack<int> ans;
bool anscheck = true;

int main(void) {
    // insert code here...
    
    cin >> N;
    for(int i = 0; i < N; i++){
        int a;
        cin >> a;
        nums.push_back(a);
    }
    
    while(!nums.empty()){
        bool check = false;
        for(int i = nums.size() - 1; i >= 0; i--){
            if(nums[i] == i+1){
                ans.push(i+1);
                nums.erase(nums.begin()+i);
                check = true;
                break;
            }
        }
        if(check==false){
            anscheck = false;
            break;
        }
        
    }
    
    if(anscheck==false){
        cout << -1 << endl;
    }else{
        while(!ans.empty()){
            cout << ans.top() << endl;
            ans.pop();
        }
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
double eps=1e-1;
double b[10];
double ABS(double a){return max(a,-a);}
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<a+3;i++)scanf("%lf",b+i);
		bool ok=false;
		for(int i=0;i<a+2;i++){
			double v=0;
			for(int j=0;j<a+2;j++){
				if(i==j)continue;
				double ks=b[j];
				for(int k=0;k<a+2;k++){
					if(i==k||j==k)continue;
					ks*=(double)((a+2)-k)/(j-k);
				}
				v+=ks;
			}
			//printf("%d: %.12f\n",i,v);
			if(ABS(v-b[a+2])<eps){
				printf("%d\n",i);ok=true;
				break;
			}
		}
		if(!ok)printf("%d\n",a+2);
	}
}

Measured memory_bytes: 1072
let n = read_int()

let ab = Array.init n (fun _ -> Scanf.scanf " %d %d" (fun a b -> a, b))

let cd = Array.init n (fun _ -> Scanf.scanf " %d %d" (fun c d -> c, d))

let list = Array.make n 0
let li = ref 0

let rec f i j p =
  if i = n then p
  else
    let c, d = cd.(i) in
    let rec g j =
      if j < n then (
        let a, b = ab.(j) in
        if a < c then (
          list.(!li) <- b;
          li := !li + 1;
          g (j + 1)
        ) else j
      ) else j in
    let j = g j in
    let rec g k l m =
      if k = !li then l
      else if list.(k) < d && m < list.(k) then g (k + 1) k list.(k)
      else g (k + 1) l m in
    let l = g 0 ~-1 ~-1 in
    if l > -1 then (
      list.(l) <- list.(!li - 1);
      li := !li - 1;
      f (i + 1) j (p + 1)
    ) else f (i + 1) j p

let () =
  Array.sort (fun (x1, _) (x2, _) -> x1 - x2) ab;
  Array.sort (fun (x1, _) (x2, _) -> x1 - x2) cd;
  let ans = f 0 0 0 in
  Printf.printf "%d\n" ans


Measured memory_bytes: 3872
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  int sum=0;
  for(int i=0;i<N;i++){
    int l,r;
    cin >>l >>r;
    sum+=(r-l+1);
  }
  
  cout << sum <<endl;
  
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define NIL -1
#define TRUE 1
#define FALSE 0
#define MAX 500000

typedef struct{
  int parent;
  int left;
  int right;
  int key;
}node;

void insert(int);
int find(int, int);
void inorder(int);
void preorder(int);

int root=-1;
node T[MAX];

int main(){
  int n, num,  i;
  char command[10];

  scanf("%d", &n);

  for( i=0 ; i<n ; i++ ){
    T[i].parent = NIL;
    T[i].left = NIL;
    T[i].right = NIL;
  }
    
  for( i=0 ; i<n ; i++ ){
    scanf("%s",command);
    
    if(strcmp(command, "insert") == 0){
      scanf("%d",&T[i].key);
      insert(i);
    }
    else if(strcmp(command, "find") == 0){
      scanf("%d",&num);
      if(find(0, num) == TRUE) printf("yes\n");
      else printf("no\n");
    }
    else if(strcmp(command, "print") == 0){
      inorder(0);
      printf("\n");
      preorder(0);
      printf("\n");
    }
  }

  return 0;
}

void insert(int z){
  int x = root;
  int y = NIL;
  
  while(x != NIL){
    y = x;
    
    if(T[z].key < T[x].key){
      x = T[x].left;
    }
    else{
      x = T[x].right;
    }
  }
  T[z].parent = y;

  //T???????????´???
  if(y == NIL){
    root = z;
  }
  else if(T[z].key < T[y].key){
    T[y].left = z;
  }
  else{
    T[y].right = z;
  }
}

int find(int x, int key){
  if(T[x].key == key) return TRUE;
  if( key<T[x].key && T[x].left!=NIL ){
    return find(T[x].left, key);
  }
  if( key>T[x].key && T[x].right!=NIL ){
    return find(T[x].right, key);
  }
  return FALSE;
}

void inorder(int x){
  if(x != NIL){
    inorder(T[x].left);
    printf(" %d", T[x].key);
    inorder(T[x].right);
  }
}

void preorder(int x){
  if(x != NIL){
    printf(" %d", T[x].key);
    preorder(T[x].left);
    preorder(T[x].right);
  }
}

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

int main() {
  int N, A;
  cin >> N >> A;
  if(N <= A){
    cout << "Yes" << endl;
  }
  else if(N - 500 * (N / 500) <= A){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,pos,a[100005];
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	for (int i=1;i<=n+1;i++)
		if (a[i+1]<=i){
			pos=i-1; break;
		}
	int t1=a[pos+1]-pos,t2;
	for (int i=1;i<=n;i++)
		if (a[i+1]<=pos){
			t2=i-pos;
			break;
		}
	if (t1%2==0||t2%2==0)
		puts("First");
	else puts("Second");
}

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

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

using namespace std;
using ll = long long;

int main(void) {
  int n;
  cin >> n;
  int num;
  int k = 0;
  int g = 0;
  
  rep(i, n) {
    cin >> num;
    if (num % 2) {
      k++;
    } else {
      g++;
    }
  }
  int ans = pow(3, n) - pow(2, g);
  cout << ans << endl;
}



Measured memory_bytes: 512
#include <stdio.h>

int n;

int main(void)
{
	scanf("%d", &n);
	
	for(int i = 1 ; i <= 9 ; i++)
	{
		for(int j = 1 ; j <= 9 ; j++)
		{
			if(n == i * j)
			{
				printf("Yes");
				return 0;
			}
		}
	}
	
	printf("No");
	return 0;
}

Measured memory_bytes: 128
require 'pp'
n, w = gets.split.map(&:to_i)
wv = []
n.times do
  wv << gets.split.map(&:to_i)
end
wv.sort_by! { |y| y[1] }
INF = 10 ** 15
dp = Array.new(100001, INF)
dp[0] = 0
wv.each do |tw, tv|
  100000.downto(tv).each do |cv|
    dp[cv] = dp[cv-tv] + tw if dp[cv] > dp[cv-tv] + tw
  end
end
max = 0
dp.each_with_index do |di, idx|
  if di <= w && idx > max
    max = idx
  end
end
pp max

Measured memory_bytes: 2812
fun intLong() = readLine()?.split(" ")?.map(String::toLong) ?: TODO()
fun main(args: Array<String>) {
    val (k, a, b) = intLong()
    if (k <= a || a >= b) {
        println("${k + 1}")
        return
    }
    val aa = a + 1
    val t = (b - a) * ((k - aa) / 2)
    val r = (k - aa) % 2
    println("${Math.max(b + t + r, k + 1)}")
}

Measured memory_bytes: 35960
int t,n,m,l,i,j,a,b,k,P[1001],T[1001],Q[2001],C[2001][2001],V[2001],d[1001][1001];
int match(s){int i=l;for(;i<l+l;i++)if(C[s][i]&&!V[i])if(V[i]=1,Q[i]<0||match(Q[i]))return Q[s]=i,Q[i]=s,1;return 0;}
main(){
  for(;scanf("%d%d%d",&n,&m,&l),l;printf("%d\n",l-t)){
	memset(C,0,sizeof(C));memset(Q,0xff,sizeof(Q));
	memset(d,11,sizeof(d));for(i=0;i<n;i++)d[i][i]=0;
    for(i=0;i<m;i++)scanf("%d%d%d",&a,&b,&k),d[a][b]=d[b][a]=k;
	for(i=0;i<l;i++)scanf("%d%d",P+i,T+i);
	for(k=0;k<n;k++)for(i=0;i<n;i++)for(j=0;j<n;j++)if(d[i][j]>d[i][k]+d[k][j])d[i][j]=d[i][k]+d[k][j];
	for(i=0;i<l;i++)for(j=0;j<l;j++)if(i!=j&&d[P[i]][P[j]]<99999&&T[i]+d[P[i]][P[j]]<=T[j])C[i][l+j]=C[l+j][i]=1;
    for(t=i=0;i<l;i++)memset(&V,0,sizeof(V)),t+=match(i);
  }
  return 0;
}

Measured memory_bytes: 20204
#include "bits/stdc++.h"
 
using namespace std;
 
#define int long long
 
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FORR(i, a, b) for (int i = (a); i >= (b); i--)
 
#define pb push_back
#define VDEL(v, n) v.erase(v.begin() + (n))
#define ALL(v) v.begin(), v.end()
 
#define INT_INF 200000000
 
#define TINT(str) atoi(str.c_str())
#define TSTR(num) to_string(num)
 
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<vector<int>> VII;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
 
//the end of library zone

string s;
 
signed main() {
    cin >> s;

    int cv = 0;

    int ans = 0;

    REP(i, s.length()){
        if(s[i] == 'W'){
            ans += (i - cv);
            cv++;
        } 
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>
#include<functional>
#include<unordered_set>
#include<unordered_map>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;
const long long ll_max = 9223372036854775807;
const long long ll_min = -9223372036854775807;
const int int_max = 2147483647;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> ret;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			ret[i] ++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

template<typename T>
T modinv(T a, T m) {
	T b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}



// 繰り返し二乗法
ll pow2(ll n, ll p, ll mod) {
	if (p == 0 || n == 1) {
		return 1;
	}
	else {
		ll ret = pow2(n * n % mod, p / 2, mod);
		if (p % 2 == 1) {
			ret *= n;
		}
		return ret % mod;
	}
}


#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)



int main() {
	const ll mod = 998244353;
	ll n, k;
	cin >> n >> k;

	vll t(n + 1, 0);
	vector<pair<ll, ll>> vp(k);
	rep(i, 0, k) {
		cin >> vp[i].first >> vp[i].second;
	}

	t[1] = 1;
	repeq(i, 2, n) {
		t[i] = t[i - 1];
		rep(j, 0, k) {
			ll tmp = t[max(0LL, i - vp[j].first)] - t[max(0LL, i - vp[j].second - 1)];
			if (tmp < 0) {
				tmp += mod;
			}
			t[i] += tmp;
			if (t[i] >= mod) {
				t[i] %= mod;
			}
		}
	}

	ll ans = t[n] - t[n - 1];
	if (ans < 0) {
		ans += mod;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4776
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
//二項係数
//参考 http://drken1215.hatenablog.com/entry/2018/06/08/210000
#define MAX 1000005
long long fac[MAX], finv[MAX], inv[MAX];

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


int main(){
    COMinit();
    long long x,y,ans,t,a,b,z,low,high,m;
    cin>>x>>y;
    if((x+y)%3!=0) cout<<0<<endl;
    else{
        t=x+y;
        a=max(x,y)-min(x,y)+(t/3-(max(x,y)-min(x,y)))/2;
        b=(t/3-(max(x,y)-min(x,y)))/2;
        t/=3;  
        low=min(a,b);
        high=max(a,b);//これ、a+b=tだからhighもlowも計算する必要ないけど自戒のために残しておく。
        //ちゃんとコンビネーションの定義を明確に覚えておく。
    cout<<COM(t,low)<<endl;
    }
}

Measured memory_bytes: 23680
#include<iostream>
using namespace std;
int main(){
	int n,l,g,i,t=0;
	cin>>n>>l;
	g=l+n-1;
	for(i=0;i<n;i++)t+=l+i;
	if(l*g<=0){
		cout<<t;
	}else{
		if(l>0){
			cout<<t-l;
		}else{
			cout<<t-g;
		}
	}
}

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

int main(void)
{
    long long N;
    cin >> N;
    vector<char> vec(0);
    while(1)
    {
        if(N % 26 == 0)
        {
            vec.insert(vec.begin(), 'z');
            N = N / 26 - 1;
        }
        else
        {
            vec.insert(vec.begin(), (N % 26) + 'a' - 1);
            N = N / 26;
        }
        if (N == 0)
        {
            break;
        }
    }
    for (long long i = 0; i < vec.size(); i++)
    {
        cout << vec[i];
    }
    cout << endl;
}

Measured memory_bytes: 3624
// AOJ 2538 Stack Maze
// 2018.2.2 bal4u

#include <stdio.h>
#include <string.h>
#include <ctype.h>

char map[53][53];
char mk[53][53][53][53];
int memo[53][53][53][53];
char a[53][53][11][2], hi[53][53];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int calc(int lr, int lc, int rr, int rc)
{
	int i, r, c, t, ans;

	if ((ans = memo[lr][lc][rr][rc]) >= 0) return ans;
	if (lc > rc || lr > rr) { ans = 0; goto done; }
	if (map[lr][lc] == '#' || map[rr][rc] == '#' ||
		!mk[lr][lc][rr][rc]) { ans = -1; goto done; }

	ans = 0;
	for (i = 0; i < hi[lr][lc]; i++) {
		r = a[lr][lc][i][0], c = a[lr][lc][i][1];
		if (r < lr || r > rr || c < lc || c > rc) continue;
		t = calc(lr+1, lc, r-1, c) + 1 + calc(r, c, rr, rc); if (t > ans) ans = t;
		t = calc(lr, lc+1, r-1, c) + 1 + calc(r, c, rr, rc); if (t > ans) ans = t;
		t = calc(lr+1, lc, r, c-1) + 1 + calc(r, c, rr, rc); if (t > ans) ans = t;
		t = calc(lr, lc+1, r, c-1) + 1 + calc(r, c, rr, rc); if (t > ans) ans = t;
	}
	t = calc(lr+1, lc, rr, rc); if (t > ans) ans = t;
	t = calc(lr, lc+1, rr, rc); if (t > ans) ans = t;
done:
	return memo[lr][lc][rr][rc] = ans;;
}

int main()
{
	int H, W, r, c, u, v, k;

	while (H = in()) {
		W = in();
		memset(mk, 0, sizeof(mk));
		memset(hi, 0, sizeof(hi));
		memset(memo, -1, sizeof(memo));

		for (r = 1; r <= H; r++) {
			fgets(map[r]+1, 53, stdin);
			for (c = 1; c <= W; c++) if (map[r][c] != '#') {
				mk[r][c][r][c] = 1;
				for (u =1 ; u <= r; u++) for (v = 1; v <= c; v++) {
					if (mk[u][v][r-1][c] || mk[u][v][r][c-1]) {
						mk[u][v][r][c] = 1;
						if (isupper(map[r][c]) && islower(map[u][v]) &&
							(map[r][c] & 0x1f) == (map[u][v] & 0x1f)) {
							k = hi[u][v]++;
							a[u][v][k][0] = r, a[u][v][k][1] = c;
						}
					}
				}
			}
		}

		printf("%d\n", calc(1, 1, H, W));
	}
	return 0;
}


Measured memory_bytes: 40464
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int grundy(const vector<vecint>& g, int i, int p) {
  int x = 0;
  for (int c: g[i]) {
    if (c == p) continue;
    x ^= grundy(g, c, i) + 1;
  }
  return x;
}

int main()
{
  int n;
  cin>>n;
  vector<vecint> g(n);
  for(int i:irange(0,n-1)) {
    int x,y;
    cin>>x>>y;
    --x;--y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  int m = grundy(g, 0, -1);
  if (m == 0) {
    cout << "Bob" << endl;
  } else {
    cout << "Alice" << endl;
  }
  return 0;
}


Measured memory_bytes: 11904
s = gets.chomp

mae = s.slice(0..1)
ato = s.slice(2..3)

def yy?(s)
  if s.to_i < 100
    true
  else
    false
  end
end

def mm?(s)
  if s.to_i > 0 && s.to_i < 13
    true
  else
    false
  end
end

if yy?(mae) && mm?(ato)
  if yy?(ato) && mm?(mae)
    puts "AMBIGUOUS"
  else
    puts "YYMM"
  end
elsif yy?(ato) && mm?(mae)
  puts "MMYY"
else
  puts "NA"
end


Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long int lo;
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define inf (lo)1e9;
#define FOR for(lo i = 0 ; i < n ; i++)
#define FORV for(lo i = 0 ; i < (lo)v.size() ; i++)
#define ii pair<lo,lo>
#define iii pair<lo, pair<lo,lo> >
lo a,b,c,d,e,n,m,k,t,h,x,y,a1[100005],a2[100005];
char c1,c2,c3,c4;
string s1,s2,s3,s4;
double d1,d2,d3;
vector <lo> v;
map <lo,lo> mp1;
map <string,lo> mp2;
set <lo> stt;
queue <lo> q;
priority_queue <lo> pq;
lo vis [10000];
int main() {
    // freopen("gir.gir", "r", stdin);
    // freopen("cik.cik", "w", stdout);
    cin >> a1[0] >> a1[1] >> a1[2];
    sort(a1, a1 + 3);
    if(a1[0] == 5 && a1[1] == 5 && a1[2] == 7){
        cout << "YES\n";
    }
    else{
        cout << "NO\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
//using ll=long long;

int main(){
    int a1, a2, a3;
    cin >> a1 >> a2 >> a3;
    int mx = max(max(abs(a1 - a2), abs(a2 - a3)), max(abs(a2 - a3), abs(a3 - a1)));
    cout << abs(a1 - a2) + abs(a2 - a3) + abs(a3 - a1) - mx << endl;
    
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/perl

use strict;
use warnings;

my $n = <STDIN>;
my @a;
{
    my $in = <STDIN>;
    @a = split(" ", $in);
}
my $l = 0;
my $r = 0;
my $li = 0;
my $ri = $n - 1;
while ($ri-$li>=0) {
    if ($l<=$r) {
        $l += $a[$li];
        $li++;
    } else {
        $r += $a[$ri];
        $ri--;
    }
}
my $ans = abs($l-$r);

print "$ans\n";

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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1000000000

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const long double EPS = 0.0000000001;

int  h,w;

int bfs(int sy, int sx, int gy, int gx, string s[]){
	int reach[h][w];
	for(int i = 0; i < h; i++)for(int j = 0; j < w; j++)reach[i][j] = 0;
	queue<P> q;
	q.push(P(sy, sx));
	while(!q.empty()){
		P point = q.front(); q.pop();
		int cy = point.first;  int cx = point.second;
		for(auto v: {P(1, 0), P(-1, 0), P(0, 1), P(0,-1)}){
			int ny = cy + v.first; int nx = cx + v.second;
			// 到達できるかの判定
			// 到達条件は，迷路の幅の範囲内，すでに訪問していないこと，壁じゃないこと
			if(ny < 0 or ny > h - 1)continue;
			if(nx < 0 or nx > w - 1)continue;
			if(reach[ny][nx] != 0)continue;
			if(s[ny][nx] == '#')continue;

			reach[ny][nx] = reach[cy][cx]+1;
			q.push(P(ny, nx));
		}
	}
	return reach[gy][gx];
}

int main(){
	cin >> h >> w;
	string s[h];
	for(int i = 0; i < h; i++)cin >> s[i];

	int ans = 0;
	for(int sy = 0; sy < h; sy++)for(int sx = 0; sx < w; sx++){
		if(s[sy][sx] == '#')continue;
		for(int gy = 0; gy < h; gy++)for(int gx = 0; gx < w; gx++){
			if(s[gy][gx] == '#')continue;
			if(sx == gx and sy == gy)continue;
			ans = max(ans, bfs(sy,sx, gy, gx, s));
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
cnt = int(input())
in_str = [int(i) for i in input().split()]
in_str.sort()
#print("in_str[cnt // 2-1]",in_str[cnt // 2-1])
#print("in_str[cnt//2]",in_str[cnt//2])
print(in_str[cnt//2] - in_str[cnt // 2-1])



Measured memory_bytes: 14428
from operator import mul
from functools import reduce
n,k = map(int,input().split())
mod = 10**9+7

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

for l in range(1,k+1):
  if n-k+1 < l:
    print(0)
    continue
  a = cmb(k-1,l-1)
  b = cmb(n-k+1,l)
  print(a*b%mod)

Measured memory_bytes: 3944
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#include <utility>
#include <vector>
using namespace std;
#define mp make_pair
typedef pair<int, int> P;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int N, M;
char maze[110][110];
unsigned int minp[110][110];

int main() {
	for(;;) {
		memset(minp, -1, sizeof minp);
		scanf(" %d %d", &N, &M);
		if(!N && !M) break;
		for(int i = 0; i < M; i++) {
			scanf(" %s", maze[i]);
		}

		// P = (x, y)
		// maze[y][x]
		queue<P> que;
		{
			P put;
			for(int x = 0; x < N; x++) {
				for(int y = 0; y < M; y++) {
					if(maze[y][x] == '&') {
						put.first = x;
						put.second = y;
						minp[y][x] = 0;
						maze[y][x] = '.';
					}
				}
			}
			que.push(put);
		}
		;
		while(!que.empty()) {
			P p = que.front();
			que.pop();

			// push
			for(int i = 0; i < 4; i++) {
				int nx = p.first + dx[i];
				int ny = p.second + dy[i];
				if(0 <= nx && nx < N && 0 <= ny && ny < M && maze[p.second][p.first] == '.' && maze[ny][nx] == '.' && minp[ny][nx] > minp[p.second][p.first]) {
					minp[ny][nx] = minp[p.second][p.first];
					que.push(mp(nx, ny));
				}

				if(0 <= nx && nx < N && 0 <= ny && ny < M && maze[p.second][p.first] == '#' && maze[ny][nx] == '#' && minp[ny][nx] > minp[p.second][p.first]) {
					minp[ny][nx] = minp[p.second][p.first];
					que.push(mp(nx, ny));
				}

				if(0 <= nx && nx < N && 0 <= ny && ny < M && maze[p.second][p.first] == '.' && maze[ny][nx] == '#' && minp[ny][nx] > minp[p.second][p.first]) {
					minp[ny][nx] = minp[p.second][p.first] + 1;
					que.push(mp(nx, ny));
				}

				if(0 <= nx && nx < N && 0 <= ny && ny < M && maze[p.second][p.first] == '#' && maze[ny][nx] == '.' && minp[ny][nx] > minp[p.second][p.first]) {
					minp[ny][nx] = minp[p.second][p.first];
					que.push(mp(nx, ny));
				}
			}
		}
		unsigned int minv = 100000000;
		for(int i = 0; i < N; i++) {
			minv = min(minv, min(minp[0][i], minp[M - 1][i]));
		}
		for(int i = 0; i < M; i++) {
			minv = min(minv, min(minp[i][0], minp[N - 1][i]));
		}
		printf("%d\n", minv);
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

int main()
{
  int n;
  int i;

  cin >> n;

  while (n--){
    int ai = 1, bi = 1;
    int ans = 0;
    int ball[10], a[10] = {0}, b[10] = {0};
    
    for (i = 0; i < 10; i++){
      cin >> ball[i];
    }
    for (i = 0; i < 10; i++){
      if (ball[i] > a[ai - 1]){
        ans++;
        a[ai++] = ball[i];
      }
      else if (ball[i] > b[bi - 1]){
        ans++;
        b[bi++] = ball[i];
      }
      else {
        cout << "NO" << endl;
        break;
      }
    }
    if (ans == 10) cout << "YES" << endl;
  }
}

Measured memory_bytes: 1152
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>

using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

int main() {

    ll A,B;
    cin >> A >> B;
    ll out = 0;
    out += max(A,B);
    if(out==A) out += max(A-1,B);
    else out += max(A,B-1);
    cout << out << endl;
    return 0;
}

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

using namespace std;

template <class T>
class SegmentTree
{
private:
	int n; // 葉の数
	vector<T> data; // データを格納するコンテナ
	T def;
	function<T(T, T)> operation; // 区間クエリで使う処理
	function<T(T, T)> update; // 点更新で使う処理

	// 区間[a, b)の総和, ノードk=[l, r)に着目している
	T _query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l) return def;
		if (a <= l && r <= b) return data[k];
		else {
			T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子
			T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子
			return operation(c1, c2);
		}
	}

public:
	// _n: 必要サイズ, _def: 初期値かつ単位元, _operation: クエリ関数, _updata: 点更新関数
	SegmentTree(size_t _n, T _def, function<T(T, T)> _operation, function<T(T, T)> _update)
		: n(_n), def(_def), operation(_operation), update(_update) {
		n = 1; while (n < _n) n *= 2;
		data = vector<T>(2 * n - 1, def);
	}

	// 場所iの値をxで更新
	void change(int i, T x) {
		i += n - 1;
		data[i] = update(data[i], x);
		while (i > 0) {
			i = (i - 1) / 2;
			data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
		}
	}

	// 半開区間[a, b)でクエリを実行
	T query(int a, int b) {
		return _query(a, b, 0, 0, n);
	}

	// 添字でアクセス
	T operator[](int i) {
		return data[i + n - 1];
	}
};

void solve(const int & N, const int & Q, SegmentTree<long long> & st) {
	int c, x, y; cin >> c >> x >> y; // c: コマンド(0: 点更新, 1: 区間クエリ)

	if (c == 0) st.change(x, y);
	else {
		cout << st.query(x, y + 1) << endl;
	}
}

int main(void) {
	int N, Q; cin >> N >> Q;
	SegmentTree<long long> st(N, (1LL << 31) - 1
		, [](long long a, long long b) {return min(a, b); }
		, [](long long d, long long x) {return x; });

	rep(q, Q) solve(N, Q, st);

	return 0;
}


Measured memory_bytes: 4912
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#include<math.h>
#include<unordered_set>

using namespace std;

const int MAX = 100010;

int parent(int uft[], int child) {
	if (uft[child] == -1)return child;
	return uft[child] = parent(uft, uft[child]);
}

int main() {
	int N, M;
	int p[MAX];

	int uft[MAX];
	for (int i = 0; i < MAX; i++)uft[i] = -1;

	cin >> N >> M;
	for (int i = 0; i < N; i++) {
		cin >> p[i];
	}

	for (int i = 0; i < M; i++) {
		int x, y;
		cin >> x >> y;

		int p1 = parent(uft, x - 1);
		int p2 = parent(uft, y - 1);
		if(p1 != p2)uft[p1] = p2;
	}

	int ans = 0;
	for (int i = 0; i < N; i++) {
		int p1 = parent(uft, p[i] - 1);
		int p2 = parent(uft, i);
		if (p1 == p2)ans++;
	}

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 1148
// AOJ 2678 Cube Coloring
// 2018.2.27

#include <stdio.h>

#define ABS(a)	((a)>=0?(a):-(a))
int N;
int a[3], b[3], c[3];
long long df[3002];
long long df2[3002];
long long ans[1002];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

void calc(int a, int b, int c, int s)
{
	int i, x;
	long long t;

	if (a < b) x = a, a = b, b = x;
	if (a < c) x = a, a = c, c = x;
	if (b < c) x = b, b = c, c = x;
	if (!c) return;

	if (b == 1) {
		df[0] += a / N, df[N] -= a / N;
		df[s]++, df[s + a % N]--;
	} else if (c == 1) {
		if (a >= N) {
			t = (long long)(a / N) * b;
			df[0] += t, df[N] -= t;
			calc(a % N, b, c, s);
		} else {
			df2[s]++, df2[s + b]--;
			df2[s + a]--, df2[s + a + b]++;
		}
	} else if (a >= N) {
		t = (long long)a / N * b * c;
		df[0] += t, df[N] -= t;
		calc(a % N, b, c, s);
	} else for (i = 0; i < c; i++) calc(a, b, 1, (s + i) % N);
}

int main()
{
	int X, Y, Z, A, B, C, n3, i, ii, j, k;
	long long sum;

	X = in(), Y = in(), Z = in(), A = in(), B = in(), C = in(), N = in();
	n3 = 3*N;
	a[0] = A, a[1] = 1, a[2] = X-A-1;
	b[0] = B, b[1] = 1, b[2] = Y-B-1;
	c[0] = C, c[1] = 1, c[2] = Z-C-1;
	for (i = 0; i < 3; i++) for (j = 0; j < 3; j++) for (k = 0; k < 3; k++) {
		calc(a[i], b[j], c[k], (ABS(i-1) + ABS(j-1) + ABS(k-1)));
    }
    sum = 0; for (i = 0; i < n3; i++) sum += df2[i], df[i] += sum;
	sum = 0; for (ii = i = 0; i < n3; i++) {
		sum += df[i], ans[ii] += sum;
		if (++ii == N) ii = 0;
	}
	printf("%lld", ans[0]);
	for (i = 1; i < N; i++) printf(" %lld", ans[i]);
	putchar('\n');
	return 0;
}


Measured memory_bytes: 2100
//#include <bits/stdc++.h>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define D(x) cout << #x " is " << x << endl
#define INF 1000000000
#define pb push_back
#define F first
#define S second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

int main()
{
    int n; cin >> n;
    vi v(n*2); rep(i, n*2) cin >> v[i]; sort(v.begin(), v.end());
    int counter = 0; rep(i, n*2) if (i % 2 == 0) counter += v[i];
    cout << counter << endl;

    return 0;
}


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

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

	vector<int> C(9);//[color_no]<count>
	int n = 0;//number of colors
	while(N--){
		int a; cin>>a;
		int b = min(8, a/400);
		if(C[b] == 0) n++;
		C[b]++;
	}

	if(C[8] > 0) n--;
	int minC = max(1, n);
	int maxC = n + C[8];
	printf("%d %d\n", minC, maxC);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <iomanip>

int main() {
	long long N; std::cin >> N;
	std::vector<int> A(N);
	long long all = 0;
	for (auto& r : A) {
		std::cin >> r;
		all += r;
	}
	long long dall = 0;
	long long p = 0;
	for (long long i = 0; i < N; ++i) {
		dall += A[i];
		if (dall > all / 2) {
			p = i;
			break;
		}
	}
	dall -= A[p];
	long long dall2 = 0;
	long long p2 = 0;
	for (long long i = N - 1; i >= 0; --i) {
		dall2 += A[i];
		if (dall2 > all / 2) {
			p2 = i;
			break;
		}
	}
	dall2 -= A[p2];
	std::cout << std::min(all - (dall * 2), all - (dall2 * 2)) << std::endl;

}


Measured memory_bytes: 4028
strr = input()

if strr == "A" or strr =="B" or strr == "C" or strr == "D" or strr =="E" or strr =="F" or strr =="G" or strr =="H" or strr =="I" or strr =="J" or strr =="K" or strr =="L" or strr =="N" or strr =="M" or strr =="O" or strr =="P" or strr =="Q" or strr =="R" or strr =="S" or strr =="T" or strr =="U" or strr =="V" or strr =="W" or strr =="X" or strr =="Y" or strr =="Z":
    print("A")
else:
    print("a")

Measured memory_bytes: 9064
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
m = [0] * N
p = N - 1
q = N - 1
while p >= 0:
    while q >= 0 and b[p] < c[q]:
        m[p] += 1
        q -= 1
    p -= 1
for i in range(N-2, -1, -1):
    m[i] = m[i] + m[i + 1]

p = N - 1
q = N - 1
h = [0] * N
while p >= 0:
    while q >= 0 and a[p] < b[q]:
        h[p] += m[q]
        q -= 1
    p -= 1
for i in range(N-2, -1, -1):
    h[i] = h[i] + h[i + 1]
print(sum(h))


Measured memory_bytes: 24540
#include <bits/stdc++.h>
using namespace std;
int main() {
    string n;
    cin>>n;

    int sum=0;

    for(int i=0;i<n.size();i++){
        sum+=n[i]-'0';
    }

    int nn=atoi(n.c_str());

    if(nn%sum==0){
        cout<<"Yes"<<endl;
    }
    else {
        cout<<"No"<<endl;
    }
}

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

using namespace std;

int main(){
    string s,t; cin >> s >> t;
    
    sort(s.begin(),s.end());
    sort(t.rbegin(),t.rend());
    
    if(s < t)
        cout << "Yes" << endl;
    
    else
        cout << "No" << endl;
}


Measured memory_bytes: 256