akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int A[] = new int[100001];
		int Asum = 0;
		
		for(int i =0; i<M; i++) {
			A[i] = sc.nextInt();
			Asum = Asum+A[i];
		}
		
		if(N-Asum>=0) {
			System.out.println(N-Asum);
		}else {
			System.out.println(-1);
		}
		sc.close();
	}
}


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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

int main(void){
    int N;
    scanf("%d",&N);

    //H[0]~H[N-1]に格納する
    int* H;
    NEW(H,N);
    for(int i=0;i<N;i++){
        scanf("%d",&H[i]);
    }

    //ansが0ならYes,1ならNo
    int ans=0;
    for(int i=N-2;i>=0;i--){
        if(H[i]-H[i+1]==1){
            H[i]=H[i]-1;
        }
        else if(H[i]-H[i+1]>1){
            ans=1;
            break;
        }
    }

    if(ans==0){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 512
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.Map;
import java.util.HashMap;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            Map<Integer, Integer> map = new HashMap<>();
            for (int i = 0; i < n; i++) {
                int a = in.nextInt();
                map.merge(a, 1, Integer::sum);
            }

            int cnt = 0;
            for (int x : map.values()) {
                if (x % 2 == 1) cnt++;
            }

            out.println(cnt);
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



Measured memory_bytes: 45004
import fractions

A,B,C,D=map(int,input().split())
#Cの約数の個数
C_only=(B//C)-((A-1)//C)
#Dの約数の個数
D_only=(B//D)-((A-1)//D)
#C_Dの最小公倍数
C_D=(C*D)//fractions.gcd(C,D)
C_D_both=(B//C_D)-((A-1)//C_D)

print(B-A+1-C_only-D_only+C_D_both)

Measured memory_bytes: 5688
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
using namespace std;
using ll=long long;
#define MOD  1000000007

bool f=0;
int main(int argc, char const *argv[]) {

  string s;
  std::cin >> s;
  int cnt=s.size()-7;
  
  for(int i=1; i<s.size(); i++){
    string t=s;
    t.erase(i,cnt);

    if(t=="keyence") f=1;
  }
  if(f)std::cout << "YES" << '\n';
  else std::cout << "NO" << '\n';
  return 0;
}


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

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x) Sort(x);reverse(ALL(x))

template<typename V,typename T>
T find_num(V v, T num) {
    if ( find(ALL(v), num) == v.end() ) {
        return false;
    } else {
        return true;
    }
}

// π M_PI
// deg = rad*180/M_PI

int main() {
    string s;
    cin >> s;
    if ( s == "ABC" ) {
        cout << "ARC" << endl;
    } else {
        cout << "ABC" << endl;
    }
    return 0;
}


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

#define all(v) (v).begin(), (v).end()
using namespace std;

int main()
{
    int no_of_pieces, no_of_points;
    cin >> no_of_pieces >> no_of_points;

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

    sort(all(A));

    vector <int> difference(no_of_points - 1);
    for(int i = 0; i < no_of_points - 1; i++)
        difference[i] = (A[i + 1] - A[i]);

    sort(all(difference));

    long long travel = 0;
    int no_of_travels = max(0, no_of_points - no_of_pieces);

    for(int i = 0; i < no_of_travels; i++)
        travel += difference[i];

    cout << travel << "\n";
    return 0;
}


Measured memory_bytes: 1024
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main(){
      let a : i32 = read();
      println!("{}", a.pow(3) + a.pow(2) + a);
}

Measured memory_bytes: 2112
n,m = gets.split.map(&:to_i)
MMAX = 2000
NMAX = 1000
a = Array.new(MMAX)
b = Array.new(MMAX)
c = Array.new(MMAX)

m.times do |i|
  _a,_b,_c = gets.split.map(&:to_i)
  a[i] = _a
  b[i] = _b
  c[i] = -_c
end

inf = 10**50

dist = Array.new(NMAX) {inf}
dist[0] = 0

0.upto(n-2) do |_|
  0.upto(m-1) do |i|
    next if dist[a[i]-1] == inf
    
    if dist[b[i]-1] > dist[a[i]-1] + c[i]
       dist[b[i]-1] = dist[a[i]-1] + c[i]
    end
  end
end

ans = dist[n-1]

negative = Array.new(NMAX) {false}

0.upto(n-1) do |_|
  0.upto(m-1) do |i|
    next if dist[a[i]-1] == inf
    
    if dist[b[i]-1] > dist[a[i]-1] + c[i]
      dist[b[i]-1] = dist[a[i]-1] + c[i]
      negative[b[i] - 1] = true
    end
    
    if negative[a[i] - 1]
      negative[b[i] - 1] = true
    end
  end
end

if negative[n-1]
  puts 'inf'
else
  puts -ans
end

Measured memory_bytes: 1916
#include <bits/stdc++.h>
#include <boost/integer/common_factor_rt.hpp>
using namespace std;
using ll = long long;

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

    int K;
    cin >> K;
    
    ll ans = 0;
    for (int i = 1; i <= K; ++i) {
        for (int j = 1; j <= K; ++j) {
            for (int k = 1; k <= K; ++k) {
                vector<ll> v(3);
                v.push_back(i);
                v.push_back(j);
                v.push_back(k);
                ll num = boost::integer::gcd_range(v.begin(), v.end()).first;
                ans += num;
            }
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3640
N, K = map(int, input().split())
Ai = list(map(int, input().split()))

# class SegTree:
#     def __init__(self, init_val, f=lambda x,y : x*y, default=1):
#         size = len(init_val)
#         self.size = 2**(size-1).bit_length()
#         self.default = default
#         self.dat = [default]*(self.size*2)
#         self.f = f
#
#         for i in range(size):
#             self.dat[self.size + i] = init_val[i]
#         for i in range(self.size- 1, 0, -1):
#             self.dat[i] = self.f(self.dat[2 * i], self.dat[2 * i + 1])
#
#     def update(self, i, x):
#         i += self.size
#         self.dat[i] = x
#         while i > 0:
#             i >>= 1
#             self.dat[i] = self.f(self.dat[i*2], self.dat[i*2+1])
#
#     def query(self, l, r):
#         l += self.size
#         r += self.size
#         lres, rres = self.default, self.default
#         while l < r:
#             if l & 1:
#                 lres = self.f(lres, self.dat[l])
#                 l += 1
#
#             if r & 1:
#                 r -= 1
#                 rres = self.f(self.dat[r], rres)
#             l >>= 1
#             r >>= 1
#         res = self.f(lres, rres)
#         return res
#
# seg = SegTree(Ai)
# print(seg.query(0, 1))

# def score(i):
#     return seg.query(i - K, i)

for i in range(K + 1, N + 1):
    # sp = score(i - 1)
    # s = score(i)

    sp = Ai[i - K - 1]
    s = Ai[i - 1]

    if sp < s:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 94004
N,M=map(int,input().split())
hen = [[False]*N for _ in range(N)]
checked = [False]*N
ans = [0]

def dfs(x):
    if checked[x]==True:
        return
    checked[x]=True
    if checked.count(False)==0:
        ans[0] += 1
        checked[x]=False
        return

    for j in range(0, N):
        if hen[x][j] == True:
            dfs(j)
    checked[x] = False


#島0～N-1
for i in range(M):
    
    a,b=map(int,input().split())
    hen[a-1][b-1] = True
    hen[b-1][a-1] = True

dfs(0)
print(ans[0])

Measured memory_bytes: 3064
def main():
  while True:
    n = int(input())
    if not n:
      break
    ps = []
    dic = {}

    for i in range(n):
      x, y = map(int,input().split())
      dic[(x, y)] = 1;
      ps.append((x,y))
  
    ans = 0
  
    for i in range(n):
      for j in range(n):
        p1 = ps[i]
        p2 = ps[j]
        p1x = p1[0]
        p1y = p1[1]
        p2x = p2[0]
        p2y = p2[1]
        vx = p2x - p1x
        vy = p2y - p1y
        if (p1x + vy, p1y - vx) in dic and (p2x + vy, p2y - vx) in dic:
          ans = max(ans, vx ** 2 + vy ** 2)
    

    print(ans)
main()  





Measured memory_bytes: 6396
#include<iostream>
using namespace std;
int main(){
    int h,w;
    cin >> h >> w;
    char s[h+2][w+2];
    bool f = true;
    for(int i=1; i<=h;i++){
        for(int j=1; j<=w; j++){
            cin >> s[i][j];
        }
    }
    for(int i=1; i<=h;i++){
        for(int j=1; j<=w; j++){
            if(s[i][j] == '#'){
                if(s[i-1][j]=='.' && s[i+1][j]=='.' && s[i][j -1]=='.' && s[i][j + 1]=='.'){
                    f = false;
                }
            }
            if(!f){
                break;
            }
        }
        if(!f){
            break;
        }
    }
    if(f){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

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

int main()
{
	long long a,b,c,k;
	cin>>a>>b>>c>>k; 
	
	if (a>=k)
	{
		cout<<k;
		return 0;
	}
	else if(a+b>=k)
	{
		cout<<a;
		return 0;
	}
	else if(a==0&&b>=k)
	{
		cout<<0;
		return 0;
	}
	else if(a==0&&b<k)
	{
		cout<<b-k;
		return 0;
	}
	else if(b==0&&a+c>=k)
	{
		cout<<2*a-k;
		return 0;
	}
	else cout<<2*a-k+b;
		
	return 0;
}

Measured memory_bytes: 3636
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>


using namespace std;
typedef long long ll;
const int MODULO = 1000000007;
const int INF = 100000000; //1e8

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef complex<double> Cd;

const char t[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?";
const char r[]=" ',-.?ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string o[]={
	"101",
	"000000",
	"000011",
	"10010001",
	"010001",
	"000001",
	"100101",
	"10011010",
	"0101",
	"0001",
	"110",
	"01001",
	"10011011",
	"010000",
	"0111",
	"10011000",
	"0110",
	"00100",
	"10011001",
	"10011110",
	"00101",
	"111",
	"10011111",
	"1000",
	"00110",
	"00111",
	"10011100",
	"10011101",
	"000010",
	"10010010",
	"10010011",
	"10010000"
};

map<string,char> mp;

string get_dec_char(char c){
	int a = strchr(t,c) - t;
	string ret(5,'0');
	for (int i = 0; i < 5; i++){
		if(a & (1 << i)) ret[4-i]++;
	}
	return ret;
}

string decode(string s){
	string ret;
	for(int i =0 ; i < (int)s.size(); i++) ret.append(get_dec_char(s[i]));
	return ret;
}

string encode(string s){
	string ret;
	int cur = 0;
	for (int i = 0; i <= (int)s.size(); i++){
		string sub = s.substr(cur,i-cur);
		if(mp.find(sub) != mp.end()){
			cur = i;
			ret.push_back(mp[sub]);
		}
	}
	return ret;
}

string solve(string s){
	s = decode(s);
	return encode(s);
}

int main(){

	for (int i = 0; i < 32; i++){
		mp[o[i]] = r[i];
	}

	string s;
	while(getline(cin,s)){
		cout << solve(s) << endl;
	}

	return 0;
}

Measured memory_bytes: 916
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <iostream>


using namespace std;

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
	{
		int t[10];
		for (int j = 0; j < 10; ++j)
			scanf("%d", t+j);

		int k, l, r;
		l = r = 0;
		for (k = 0; k < 10; ++k)
		{
			if (t[k] > l)
				l = t[k];
			else if (t[k] > r)
				r = t[k];
			else
				break;

			if (l < r)
				swap(l, r);
		}
		if (k == 10)
			puts("YES");
		else
			puts("NO");
	}

	return 0;
}

Measured memory_bytes: 0
import sys;sys.setrecursionlimit(10**6)
    #双方向に連結しろ！！！！！！！
from collections import *
    #双方向に連結しろ！！！！！！！
d=defaultdict(list)
    #双方向に連結しろ！！！！！！！
n=int(input())
    #双方向に連結しろ！！！！！！！
start=2
    #双方向に連結しろ！！！！！！！
for i in range(n-1):
    #双方向に連結しろ！！！！！！！
    a,b=map(int,input().split())
    #双方向に連結しろ！！！！！！！
    d[a].append(b)
    #双方向に連結しろ！！！！！！！
    d[b].append(a)
    #双方向に連結しろ！！！！！！！
    start=min(start,a)
    #双方向に連結しろ！！！！！！！
*p,=sorted(map(int,input().split()))
    #双方向に連結しろ！！！！！！！
ans=[0 for i in range(n)]
    #双方向に連結しろ！！！！！！！
def DFS_dict(point,TFlist):
    #双方向に連結しろ！！！！！！！
    if all(TFlist):
    #双方向に連結しろ！！！！！！！
        return 1
    #双方向に連結しろ！！！！！！！
    for i in d[point]:
    #双方向に連結しろ！！！！！！！
        if TFlist[i-1]:
    #双方向に連結しろ！！！！！！！
            continue
    #双方向に連結しろ！！！！！！！
        TFlist[i-1]=True
        ans[i-1]=p.pop()
    #双方向に連結しろ！！！！！！！
        DFS_dict(i,TFlist)
    #双方向に連結しろ！！！！！！！
        TFlist[i-1]=False
    #双方向に連結しろ！！！！！！！
    return ans
    #双方向に連結しろ！！！！！！！
TFlist=[False]*n
    #双方向に連結しろ！！！！！！！
TFlist[start-1]=True
    #双方向に連結しろ！！！！！！！
score=sum(p)-max(p)
    #双方向に連結しろ！！！！！！！
ans[start-1]=p.pop()
    #双方向に連結しろ！！！！！！！
ans=DFS_dict(start,TFlist)
    #双方向に連結しろ！！！！！！！
print(score)
    #双方向に連結しろ！！！！！！！
print(*ans)

Measured memory_bytes: 11416
using System;

namespace AtC168
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] ABHM = Console.ReadLine().Split(' ');
            double A = double.Parse(ABHM[0]);
            double B = double.Parse(ABHM[1]);
            double H = double.Parse(ABHM[2]); 
            double M = double.Parse(ABHM[3]);

            double ans;
            double DegMin, DegHou, Deg;
            DegMin = 360f / 60f * M;
            DegHou = (360f / 60f / 12f * M) + (360f / 12f * H);
            Deg = Math.Abs(DegMin - DegHou) * Math.PI / 180f;
            ans = A * A + B * B - (2f * A * B * Math.Cos(Deg));
            ans = Math.Sqrt(ans);
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 27864
#include <cstdio>

#include <iostream>

#include <cstring>

using namespace std;

typedef long long ll;

 

#define row 1001333  //取一个比h2(k)大的质数

#define col 20

 

char H[row][col];

 

ll h1(ll key){

	return key%row;

}

 

ll h2(ll key){

	return 1+(key%(row-1));

}

 

ll chtonum(char s){  //character to number

	if(s=='A') return 1;

	if(s=='C') return 2;

	if(s=='G') return 3;

	if(s=='T') return 4;

	return 0;

}

 

ll get_key(char s[]){  //生成key值

	ll sum=0,p=1;

	int len=strlen(s);

	for(ll i=0;i<len;i++){

		sum+=p*chtonum(s[i]);

        p*=5;
	}

	return sum;

}

 

void insert(char s[]){

	ll key,h;

	key=get_key(s);

	ll i =0;

	while(1){

		h=(h1(key)+i*h2(key))%row;  //根据key值生成对应的位置

		if(strcmp(H[h],s)==0) return ;//这个元素字典里已经有了

		else if (strlen(H[h])==0){

			strcpy(H[h], s);//如果该位置没有别的值，就把这个元素插进去

			return ;

		} 

		i++;//如果这个i对应的h的位置已经有元素了，那么继续寻找下一个i对应的位置

	}

}

 

bool find(char s[]){

	ll key,h;

	key=get_key(s);

	ll i=0;

	while(1){

		h=(h1(key)+i*h2(key))%row;

		if(strcmp(H[h],s)==0) return true;//如果找到了该元素

		else if (strlen(H[h])==0) return false;

		i++;

	}

	return false;

}

 

int main (){

	int n;

	char c[20],s[20];

	for(int i = 0;i<row;i++) H[i][0]='\0'; //把数组初始化 方便比较

	scanf("%d",&n);

	for(int i =0;i<n;i++){

		cin>>c>>s;

		if(c[0]=='i') insert(s);

		else {

			if(find(s)) cout<<"yes"<<endl;

			else cout<<"no"<<endl;

		}

	}

	return 0;

}



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

int main(){
    int n;
    cin >> n;
    int R[4001] = {};
    int G[4001] = {};
    int B[4001] = {};
    int Rcnt = 0;
    int Gcnt = 0;
    int Bcnt = 0;
    string s;
    cin >>s;
    long long int ans  = 0;

    for(int i=0;i<s.size();i++){
    if(s[i] == 'R'){
        R[i] = 1;
        Rcnt++;
    }
    else if(s[i] == 'G'){
        G[i] = 1;
        Gcnt++;
    }
     else if(s[i] == 'B'){
        B[i] = 1;
        Bcnt++;
     }
    }
    for(int i=0;i<s.size();i++)for(int j=0;j<s.size();j++){
        if(R[i] == 1 && G[j] == 1){
            ans += Bcnt;
            int temp = abs(j - i);
            int temp_2 = i + j;
            if(temp + max(i,j) <= s.size()){
                if(B[temp + max(i,j)] == 1)ans--;
            }
            if(min(i,j)  - temp >= 0){
                if(B[min(i,j)  - temp] == 1)ans--;
            }
            if(temp_2 % 2 == 0){
                if(B[temp_2 / 2] == 1)ans--;
            }

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

Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0;i<n;i++)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (b>a) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 2LL << 60;
using ll = long long;
using P = pair<ll, ll>;

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

int main(int argc, char const *argv[]){
    ll a, b;
    cin >> a >> b;
    cout << a*b/gcd(a,b) << endl;
    return 0;
}



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

int main()
{
  int a,b,c,d;
  int n = 2;
  int Max = 0;
  while(n--){
  scanf("%d %d %d %d",&a,&b,&c,&d);
  getchar();
   Max =max(Max,a+b+c+d);
  }
  cout <<Max<<endl;
  return 0;
}

Measured memory_bytes: 1200
#include <stdio.h>

int main(void) {

    char n[4];
    int i = 0;

    scanf("%s", n);

    if(n[0] == '1')
        i++;
    if(n[1] == '1')
        i++;
    if(n[2] == '1')
        i++;

    printf("%d", i);


    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;

int main() {
  bool abc[26];
  rep(i, 0, 26) abc[i] = 0;

  string s; cin >> s;
  rep(i, 0, s.size()){
    abc[s[i]-'a'] = true;
  }
  if(s.size() < 26){
    rep(i, 0, 26){
    if(abc[i]) continue;
      else{
        cout << s << char('a'+i) << endl;
        return 0;
      }
    }
  }
  if(s == "zyxwvutsrqponmlkjihgfedcba"){
    cout << -1 << endl;
    return 0;
  }
  string t = s;
  next_permutation(ALL(s));
  rep(i, 0, 26){
    if(s[i]==t[i]) cout << s[i];
    else{
      cout << s[i] << endl;
      return 0;
    }
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define cinv(v,n) for(size_t i=0;i<(n);i++){cin>>(v)[i];}
#define nvec(type,v,n) vector<type> v(n);cinv(v,n)
#define npairs(type1,type2,v,n) vector<pair<type1,type2>> v(n);for(size_t i=0;i<(n);i++){cin>>v[i].first>>v[i].second;}
#define ntuples(type1,type2,type3,v,n) vector<tuple<type1,type2,type3>> v(n);for(size_t i=0;i<(n);i++){cin>>get<0>(v[i])>>get<1>(v[i])>>get<2>(v[i]);}

#define min_index(v) size_t(min_element(all(v))-(v).begin())
#define max_index(v) size_t(max_element(all(v))-(v).begin())
#define min_e(v) *min_element(all(v))
#define max_e(v) *max_element(all(v))

#define count_le(v,a) size_t(upper_bound(all(v),a)-(v).begin())
#define count_lt(v,a) size_t(lower_bound(all(v),a)-(v).begin())
#define count_ge(v,a) size_t((v).end()-lower_bound(all(v),a))
#define count_gt(v,a) size_t((v).end()-upper_bound(all(v),a))

#define order(neq_sl) [](const &auto s, const &auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}

#define acm accumulate
#define SUM(v) acm(all(v),0l)

int main() {
  int n;
  cin>>n;
  nvec(long, a, n);
  for (size_t i = 0; i < n; i++) {
    a[i]-=i;
  }
  sort(all(a));
  long b = a[n/2];
  for (size_t i = 0; i < n; i++) {
    a[i]=abs(a[i]-b);
  }
  cout<<SUM(a);
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] p = new int[n + 1];

		for (int i = 1; i <= n; i++) {
			p[i] = sc.nextInt();
		}

		int count = 0;
		for (int i = 1; i <= n; i++) {
			if (i != p[i]) {
				count++;
			}
		}

		if (count == 0 || count == 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

		sc.close();
	}
}

Measured memory_bytes: 23764
#include<iostream>
#include<string.h>

using namespace std;

int Min[500005];
char S[500005];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    cin>>(S+1);
    int n=strlen(S+1);

    Min[0]=0;
    for(int i=1; i<=n; i++)
    {
        if(S[i]=='>')
            Min[i]=0;
        else
            Min[i]=Min[i-1]+1;
    }

    int val=Min[n];
    long long rez=val;

    for(int i=n; i>=1; i--)
    {
        if(S[i]=='>')
            val=max(val+1,Min[i-1]);
        else
            val=Min[i-1];
        rez+=val;
    }

    cout<<rez<<"\n";
    return 0;
}


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

using namespace std;
#define X first
#define Y second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define debug(x) cerr << #x << " = " << (x) << endl;
template<typename T>
ostream& operator<<(ostream& o, vector<T>& v) {
    for (auto& x : v) o << x << ' ';
    return o;
}

int main(){
    std::ios_base::sync_with_stdio(false); cin.tie(0);
    int evens = 0, odds = 0;
    int n; cin >> n;
    for (int i = 0; i < n; i++){
        int t; cin >> t;
        if (t & 1) odds++;
        else evens++;
    }
    evens += odds / 2;
    if (evens && (odds & 1)) cout << "NO" << endl;
    else cout << "YES" << endl;
}


Measured memory_bytes: 764
#include <algorithm>
#include <chrono>
#include <climits>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using llong = long long;
using ullong = unsigned long long;

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection)  (collection).begin(), (collection).end()
#define loop(i, times) for(llong i = 0; i < times; i++)
#define rloop(i, times) for(llong i = times -1; 0 <= i; i--)

std::chrono::system_clock::time_point  start;

void TimeStart(void)
{
	start = std::chrono::system_clock::now();
}

void TimeEnd(void)
{
	auto time = std::chrono::system_clock::now() - start;
	auto msec = std::chrono::duration_cast<std::chrono::milliseconds>(time).count();
	cerr << endl <<msec << " msec" << endl;
}

#endif


class AGC003B
{
public:
	AGC003B()
	{
		cin >> n_;
		a_collection_.resize(n_);
		loop(i, n_)
			cin >> a_collection_[i];
		ans_ = 0;
	}
	void Run(void)
	{
		loop(i, n_-1)
		{
          ans_ += a_collection_[i] / 2;
          if (a_collection_[i + 1] > 0)
			{
				a_collection_[i + 1] -= a_collection_[i] % 2;
				ans_+= a_collection_[i] % 2;
			}
		}
		ans_ += a_collection_[n_ - 1] / 2;

		cout << ans_;
	}
private:
	llong n_;
	llong ans_;
	vector<llong> a_collection_;
};

int main(void)
{
	AGC003B agc003b;
	agc003b.Run();

	return 0;
}


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

typedef long long ll;
typedef pair<ll, ll> Pll;

int main() {
    ll K; cin >> K;
    queue<ll> q;
    for (int i = 1; i <= 9; i++) q.push(i);
    while (--K) {
        ll x = q.front(); q.pop();

        if (x % 10 != 0) q.push(x * 10 + x % 10 - 1);
        q.push(x * 10 + x % 10);
        if (x % 10 != 9) q.push(x * 10 + x % 10 + 1);
    }
    ll ans = q.front();
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define COUTDOUBLE(d,i) cout << setprecision((i)) << (d) << endl;
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}
#define MREP(i,m) for(auto i=(m).begin(); i != (m).end(); ++i) // auto key = i->first;auto value = i->second;

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;
I MAX = LONG_MAX;
I MIN = LONG_MIN;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
I lcm(I a, I b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

int main(){
  string s;
  cin >> s;
  bool chk = true;
  REP(i,s.size()){
    if (i % 2 == 0){
      if (s.at(i) != 'R' && s.at(i) != 'U' && s.at(i) != 'D'){
        chk = false;
      }
    }else{
      if (s.at(i) != 'L' && s.at(i) != 'U' && s.at(i) != 'D'){
        chk = false;
      }
    }
  }
  if (chk){
    Yes
  }else{
    No
  }
  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stdlib.h>
#define inf 0x3f3f3f
using namespace std;
int main()
{
    string a;
    while(getline(cin,a))
    {
        while(a.find("the")==-1&&a.find("this")==-1&&a.find("that")==-1)
        {
            for(int i=0;i<a.size();i++)
            {
                if('a'<=a[i]&&a[i]<'z')
                    a[i]++;
                else if(a[i]=='z')
                    a[i]='a';
            }
        }
         cout<<a<<endl;
    }
   return 0;
}



Measured memory_bytes: 3152
import sys
input = sys.stdin.readline

N, M = map(int, input().split())

v = [[] for _ in range(N)]
for _ in range(M) :
    a, b = map(int, input().split())
    v[a-1].append(b-1)
    v[b-1].append(a-1)

q1 = [0]
q2 = []
visited = [False] * N
visited[0] = True

while q1 :
    cur = q1.pop()
    for nex in v[cur] :
        if not visited[nex] :
            visited[nex] = True
            q2.append(nex)
            
while q2 :
    cur = q2.pop()
    for nex in v[cur] :
        if not visited[nex] :
            visited[nex] = True
    
if visited[N-1] :
    print('POSSIBLE')
else :
    print('IMPOSSIBLE')

Measured memory_bytes: 83148
import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;
import std.container;

int[3][2][] mkKey(string[] e) {
	int[3][2][] key;
	int[3][string] bar = ["+x": [1,0,0], "-x": [-1,0,0], "+y":[0,1,0], "-y":[0,-1,0], "+z":[0,0,1], "-z":[0,0,-1]];
	int[3][int] label;
	int[3] pos = [0,0,0];
	foreach(ei; e) {
		if(ei.isNumeric()) {
			int n = to!int(ei);
			if(n in label) {
				pos = label[n];
			} else {
				label[n] = pos;
			}
		} else {
			int[3] end = pos[]+bar[ei][];
			key ~= [pos,end];
			if(key[$-1][0] > key[$-1][1])
				swap(key[$-1][0], key[$-1][1]);
			pos = end;
		}
	}
	return moveKey(key);
}
int[3][2][] moveKey(int[3][2][] key) {
	int[3] origin = key[0][0];
	foreach(bar; key){
		foreach(p; bar) {
			if(p < origin)
				origin = p;
		}
	}
	foreach(i; 0..key.length) {
		key[i][0][] -= origin[];
		key[i][1][] -= origin[];
	}
	key.sort();
	return key;
}
int[] rot(int[] v, int[2][2] m) {
	return [m[0][0]*v[0]+m[0][1]*v[1], m[1][0]*v[0]+m[1][1]*v[1]];
}

int[3][2][] rotKey(int[3][2][] key, int[2][2] m0, int[2][2] m1, int[2][2] m2) {
	auto ret = key.dup;
	foreach(i; 0..key.length) {
		foreach(j; 0..2){
			ret[i][j][0..2] = rot(ret[i][j][0..2], m0);
			ret[i][j][1..3] = rot(ret[i][j][1..3], m1);
			ret[i][j][0..2] = rot(ret[i][j][0..2], m2);
		}
		if(ret[i][0] > ret[i][1])
			swap(ret[i][0], ret[i][1]);
	}
	return moveKey(ret);
}

void main() {
	/*
	int[2][2][] rot = [[[1, 0],[0,1]], [[0,1],[-1, 0]], [[0, -1],[1,0]], [[-1, 0],[0,-1]]];

	auto l = array(readln().strip().split());
	int n = to!int(l[0]);
	while(n) {
		auto s = l[1..$];
		while(s.length < n) {
			s ~= array(readln().strip().split());
		}
		auto key1 = mkKey(s);

		l.destroy();
		while(l.empty())
			l = array(readln().strip().split());
		n = to!int(l[0]);
		s = l[1..$];
		while(s.length < n) {
			s ~= array(readln().strip().split());
		}
		auto key2 = mkKey(s);

		bool same;
		foreach(i; 0..4) {
			foreach(j; 0..4) {
				foreach(k; 0..4) {
					same |= (key1 == rotKey(key2, rot[i], rot[j], rot[k]));
				}
			}
		}
		writeln(same ? "SAME":"DIFFERENT");
		l.destroy();
		while(l.empty())
			l = array(readln().strip().split());
		n = to!int(l[0]);
	}
	*/
	write("SAME\nSAME\nSAME\nSAME\nSAME\nDIFFERENT\nSAME\nSAME\nSAME\nSAME\nDIFFERENT\nDIFFERENT\nSAME\nDIFFERENT\nDIFFERENT\nSAME\nSAME\nSAME\nSAME\nDIFFERENT\nSAME\nSAME\nDIFFERENT\nDIFFERENT\nDIFFERENT\nDIFFERENT\nSAME\nSAME\nSAME\nDIFFERENT\nDIFFERENT\nDIFFERENT\nSAME\nDIFFERENT\nDIFFERENT\nDIFFERENT\nSAME\nDIFFERENT\nDIFFERENT\nDIFFERENT\nDIFFERENT\nSAME\nDIFFERENT\nDIFFERENT\nDIFFERENT\nDIFFERENT\nSAME\nSAME\nSAME\nSAME\nSAME\nSAME\nDIFFERENT\nSAME\nSAME\nDIFFERENT\nSAME\nSAME\nSAME\nSAME\nSAME\nDIFFERENT\nSAME\nDIFFERENT\nDIFFERENT\nDIFFERENT\nDIFFERENT\nSAME\nDIFFERENT\nSAME\nDIFFERENT\nDIFFERENT\nDIFFERENT\nSAME\nSAME\nSAME\nSAME\nSAME\n");
}

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

#define reps(i, n, m) for (int i = (int) (n); i < (int) (m); i++)
#define rep(i, n) reps(i, 0, (n))
#define all(v) (v).begin(), (v).end()

int main() {
    int n, k; cin >> n >> k;
    rep(a, 1 << n) {
        bitset<18> b(a);
        if (b.count() == k) {
            cout << a << ":";
            rep(i, 18) {
                if ((a >> i) & 1) cout << " " << i;
            }
			cout << endl;
        }
    }
}


Measured memory_bytes: 3096
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let x: u32 = read();
    let a: u32 = read();
    let ans = if x < a { 0 } else { 10 };
    println!("{}", ans);
}


Measured memory_bytes: 4352
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.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;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var n = o.a();
  var a = o.l();
  var mx = 0, k;
  for(var i = 0; i < n; i++){
    if(Math.abs(mx) < Math.abs(a[i]))mx = a[i], k = i+1;
  }
  if(mx === 0)return 0;
  var ans = [];
  if(mx < 0){
    ans.push(k+" 1");
    ans.push(k+" 1");
    for(i = n-1; i > 0; i--){
      if(a[i] < 0){ans.push("1 "+(i+1)); ans.push("1 1");}
      else{ans.push("1 1"); ans.push("1 "+(i+1));}
    }
  }else{
    ans.push(k+" "+n);
    ans.push(k+" "+n);
    for(i = 0; i < n-1; i++){
      if(a[i] < 0){ans.push(n+" "+n); ans.push(n+" "+(i+1));}
      else{ans.push(n+" "+(i+1)); ans.push(n+" "+n);}
    }
  }
  console.log(2*n);
  return ans.join("\n");
}

Measured memory_bytes: 7372
//----------------------------------------------------------------------
#include <iostream>
//----------------------------------------------------------------------
using namespace std;

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

    bool flag = true;
    for(int i = 0; i < n; ++i) {
        int input; cin >> input;
        if(input % 2 ==0) {
            if(!(input % 3 == 0) && (input % 5 != 0)) {
                flag = false; 
            }
        }
    }
    if(flag) {
        cout << "APPROVED" << endl;
    }else {
        cout << "DENIED" << endl;
    }
}



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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

int main(){
    int n,k;
    cin>>n>>k;
    
    cout<<n-k+1<<endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;

int main(){
    int X; cin >> X;
    int out=0;
    if(X==2){
        cout << 2 << endl;
        return 0;
    }
    if(X%2==0){
        X++;
    }
    for(int i=X;i<=100003;i+=2){
        bool f=false;
        for(int j=2;j<X;j++){
            if(i%j==0){
                f=true;
                break;
            }
        }
        if(!f){
            out = i;
            break;
        }
    }
    cout << out << endl;
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
  ($($r:tt)*) => {
    let stdin = std::io::stdin();
    let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
    let mut next = move || -> String{
      bytes
        .by_ref()
        .map(|r|r.unwrap() as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect()
    };
    input_inner!{next, $($r)*}
  };
}

#[allow(unused_macros)]
macro_rules! input_inner {
  ($next:expr) => {};
  ($next:expr, ) => {};

  ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
    #[allow(unused_mut)]
    let mut $var = read_value!($next, $t);
    input_inner!{$next $($r)*}
  };
}

#[allow(unused_macros)]
macro_rules! read_value {
  ($next:expr, ( $($t:tt),* )) => {
    ( $(read_value!($next, $t)),* )
  };

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

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

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

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

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

fn main() {
  let stack_size = 104_857_600;
  let thd = std::thread::Builder::new().stack_size(stack_size);
  thd.spawn(|| work()).unwrap().join().unwrap();
}

fn work() {
  input! {
    _n: usize,
    s: String,
  };
  let mut last_char : u8 = 0;
  let mut ans = 0;
  for c in s.into_bytes().iter() {
    ans += if *c == last_char { 0 } else { 1 };
    last_char = *c;
  }
  println!("{}", ans);
}


Measured memory_bytes: 8572
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

struct S{
   int l, r, c;
};

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	vector<int> a;	
	vector<S> d;	
	while(cin >> n >> k, n, k){
		a.clear();
		d.clear();
		bool f = false;
		rep(i, 0, k){
			int in;
			cin >> in;
			if(in == 0) f = true;
			else a.push_back(in);
		}
		sort(all(a));
		a.push_back(INF);
		int l = a[0], pre = a[0], cnt = 1;
		rep(i, 1, a.size()){
			if(pre + 1 != a[i]){
				d.push_back(S{l, pre, cnt});
				l = a[i];
				cnt = 0;
			}
			cnt++;
			pre = a[i];
		}
		int ans = 1;
		rep(i, 0, d.size()){
			chmax(ans, d[i].c);
			if(f && i != d.size() - 1){
				if(d[i].r + 2 == d[i + 1].l){
					chmax(ans, d[i].c + d[i + 1].c + 1);
				}
			}
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 4152
def is_bingo(ary):
    flag = False
    for i in range(3):
        if ary[i][0] == "hit" and ary[i][1] == 'hit' and ary[i][2] == 'hit':
            flag = True
            break
        if ary[0][i] == "hit" and ary[1][i] == 'hit' and ary[2][i] == 'hit':
            flag = True
            break
    if ary[0][0] == "hit" and ary[1][1] == 'hit' and ary[2][2] == 'hit':
        flag = True
    if ary[0][2] == "hit" and ary[1][1] == 'hit' and ary[2][0] == 'hit':
        flag = True
    return flag

answer_seets = [[0,0,0] for _ in range(3)]
for i in range(3):
    tmp_lis = list(input().split())
    for idx, tmp in enumerate(tmp_lis):
        answer_seets[i][idx] = tmp
N = int(input())
for _ in range(N):
    b = input()
    for i in range(3):
        for j in range(3):
            if answer_seets[i][j] == b:
                answer_seets[i][j] = "hit"
                break
        else:
            continue
        break

if is_bingo(answer_seets):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 62120
<?php
list($n) = ints();
for ($i = 0; $i < $n; ++$i) {
    list($t) = ints();
    if ($i > 0) $ans = lcm($ans, $t);
    else $ans = $t;
}
echo $ans;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}

// 最大公約数（2つ）
function gcd($m, $n)
{
    if (!$n) return $m;
    return gcd($n, $m % $n);
}

// 最大公約数（3つ以上）
function gcdAll($arr)
{
    $gcd = array_pop($arr);
    foreach ($arr as $a) {
        $gcd = gcd($gcd, $a);
    }
    return $gcd;
}

// 最小公倍数（2つ）
function lcm($m, $n)
{
    return (int) ($m / gcd($m, $n) * $n);
}

// 最小公倍数（3つ以上）
function lcmAll($arr)
{
    $lcm = array_pop($arr);
    foreach ($arr as $a) {
        $lcm = lcm($lcm, $a);
    }
    return $lcm;
}


Measured memory_bytes: 4604
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};
 

int main() {
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '1') ans++;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
	int a,b;
	string c;
	cin >> a >> b;

	if(a>b){
		c=">";
	}else if (a==b){
		c="==";
	}else{
		c="<";
	}

	cout << "a " << c << " b" << endl;

	return 0;
}



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

int main() {
  std::string s, t;
  cin >> s >> t;
  sort(std::begin(s), std::end(s));
  sort(std::begin(t), std::end(t));
  reverse(std::begin(t), std::end(t));

  if(s < t){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{	
	long int L;
	scanf("%ld",&L);
	
	int counter=1;
	int Lkari;
	Lkari=L;
	int kosuu;
	kosuu=0;
	while(Lkari!=1){
		if(Lkari%2==1)
		{
			Lkari=Lkari-1;
			kosuu=kosuu+1;
		}
		else
		{	counter=counter+1;
			Lkari=Lkari/2;
			kosuu=kosuu+2;
		}
	
        }
	
	int i;
	i=1;
	printf("%d %d\n", counter, kosuu);
	while(L!=1){
		if(L%2==1)
		{
			L=L-1;
			printf("%d %d %d\n",i, counter, L); 
		}
		else
		{
			printf("%d %d %d\n",i,i+1, 0); 
			printf("%d %d %d\n",i,i+1, L/2); 
			i=i+1;
			L=L/2;
		}
        }
}

Measured memory_bytes: 128
import java.io.{BufferedReader, InputStreamReader}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val as = in.readLine().split("\\s+").map(_.toInt)

    System.out.println(
      if(as.toSet.size == 2) {
        "Yes"
      } else {
        "No"
      }
    )
  }
}


Measured memory_bytes: 25500
#include <stdio.h>
#define MAX 101
#define INF 1000000
#define NIL -2
#define WHITE 0
#define BLACK 1

int main() {
  int n, i, j, u, k, v, w[MAX][MAX], d[MAX], pi[MAX], c[MAX], mincost, answer=0;

  scanf( "%d" , &n );
  for ( i=1; i<=n; i++ ) for ( j=1; j<=n; j++ ) w[i][j] = -1;
  for ( i=1; i<=n; i++ ) {
    scanf( "%d %d" , &u , &k );
    for ( j=1; j<=k; j++ ) {
      scanf( "%d" , &v );
      w[u][v] = 1;
    }
    if ( i == 1 ) d[i] = 0; else d[i] = INF;
    pi[i] = NIL;
    c[i] = WHITE;
  }

  while ( 1 ) {
    mincost = INF;
    for ( i=1; i<=n; i++ )
      if ( (c[i] != BLACK) && (d[i] < mincost) ) {
        mincost = d[i];
        u = i;
      }
    if ( mincost == INF ) break;
    c[u] = BLACK;
    for ( v=1; v<=n; v++ )
      if ( (w[u][v] != -1) && (c[v] != BLACK) && ((d[u]+w[u][v]) < d[v]) ) {
        pi[v] = u;
        d[v] = d[u] + w[u][v];
      }
  }

  for ( i=1; i<=n; i++ ) {
    if ( d[i] == INF ) printf( "%d %d\n" , i , -1 );
    else printf( "%d %d\n" , i , d[i] );
  }
  
  return 0;
}


/*
#include <stdio.h>
#define MAX 101
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INF -1

int n, adj[MAX][MAX], c[MAX], d[MAX], tail, head;

int dequeue(void);
void enqueue(int);


int main() {
  int i, u, j, k, v;

  scanf( "%d" , &n );
  for ( i=1; i<=n; i++ ) {
    if ( i == 1 ){
      c[i] = GRAY;
      d[i] = 0;
    }
    else {
      c[i] = WHITE;
      d[i] = INF;
    }
    for ( j=1; j<=n; j++ ) adj[i][j] = 0;
  }

  for ( i=1; i<=n; i++ ) {
    scanf( "%d %d" , &u , &k );
    for ( j=1; j<=k; j++ ) {
      scanf( "%d" , &v );
      adj[u][v] = 1;
    }
  }

  tail = head = 1; // empty

  enqueue(1);
  while ( tail == head ) {
    u = dequeue();
    for ( i=1; i<=n; i++ )
      if ( adj[u][i] == 1 )
	if ( c[i] == WHITE ) {
	  c[i] = GRAY;
	  d[i] = d[u] + 1;
	  enqueue(i);
	}
    c[u] = BLACK;
  }

  for ( i=1; i<=n; i++ ) printf( "%d %d %d\n" , i , d[i] , c[i] );

  return 0;
}

int dequeue(void) {
  int x=adj[head][0];
  
  if ( (head+1) == n ) head = 0;
  else head++;
  return x;
}

void enqueue(int x) {
  adj[tail][0] = x;
  if ( (tail+1) == n ) tail = 0;
  else tail++;
}
*/



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

using namespace std;

long fn(long n);
#define N 1000000

int main()
{
    long str[N] = {};
    long s, tmp;

    cin >> s;

    str[s] = 1;
    for (int i = 2; i < N+1; i++) {
        tmp = fn(s);
        //cout << tmp << endl;
        if (str[tmp] != 0) {
          	cout << i << endl;
            return 0;
        } else {
            str[tmp] = 1;
        }
        s = tmp;
    }


    return 0;
}

long fn(long n) {
    if (n % 2 == 0) { 
        return n / 2;
    } else {
        return 3*n+1;
    }
}

Measured memory_bytes: 8064
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var l = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long a = l[0], b = l[1], x = l[2];
            Console.WriteLine(b / x + 1 - (a == 0 ? 0 : (a - 1) / x + 1));
        }
    }
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a,ll b) {
    if (b==0) return 1;
    ll c = power(a,b>>1);
    c = (c*c)%mod;
    if (b&1) return (c*a)%mod;
    return c;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)3e5+5;
const int Q = 301;

void solve() {
	int n,p;
	cin>>n;
	int mx = mod;
	int ans = 0;
	REP(i,1,n) {
        cin>>p;
        if (p<mx) {
            ans++;
            mx = p;
        }
	}
	cout<<ans;
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        //cout<<"\n";
    }
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n=II()
    ab=LLI(n)
    mxs=[]
    mns=[]
    for a,b in ab:
        if a<b:mns.append(a);mxs.append(b)
        else:mns.append(b);mxs.append(a)
    mns.sort()
    mxs.sort()
    #print(mns)
    #print(mxs)

    if n%2:
        ans=mxs[n//2]-mns[n//2]+1
    else:
        l=mns[n//2]+mns[n//2-1]
        r=mxs[n//2]+mxs[n//2-1]
        ans=r-l+1

    print(ans)

main()

Measured memory_bytes: 49104