akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main(){
  string ans="WA";
  string s; cin>>s;
  if(s[0]=='A'){
    int cnt=0;
    int Cplace;
    for(int i=2;i<s.size()-1;i++){
      if(s[i]=='C'){
        cnt++;
        Cplace=i;
      }
    }
    if(cnt==1){
      int cnt2=0;
      for(int i=1;i<s.size();i++){
        if(i!=Cplace){
          if(s[i]-'a'<0)cnt2++;
        }
      }
      if(cnt2==0)ans="AC";
    }
  }
  cout<<ans<<endl;
}

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

for i in range(k):
    if a >= b:
        b = b * 2
        continue
    if a < b and b >= c:
        c = c * 2
if a < b and b < c:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9168
// ABC 152-E
// 2020.1.19 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

typedef long long ll;

#define gc() getchar_unlocked()

int in() {
	int n = 0; int c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

#define SIZE  1000005
int power[SIZE];

int ptbl[] = {
		 3,   5,   7,  11,  13,  17,  19,  23,  29,
   31,  37,  41,  43,  47,  53,  59,  61,  67,  71,
   73,  79,  83,  89,  97, 101, 103, 107, 109, 113,
  127, 131, 137, 139, 149, 151, 157, 163, 167, 173,
  179, 181, 191, 193, 197, 199, 211, 223, 227, 229,
  233, 239, 241, 251, 257, 263, 269, 271, 277, 281,
  283, 293, 307, 311, 313, 317, 331, 337, 347, 349,
  353, 359, 367, 373, 379, 383, 389, 397, 401, 409,
  419, 421, 431, 433, 439, 443, 449, 457, 461, 463,
  467, 479, 487, 491, 499, 503, 509, 521, 523, 541,
  547, 557, 563, 569, 571, 577, 587, 593, 599, 601,
  607, 613, 617, 619, 631, 641, 643, 647, 653, 659,
  661, 673, 677, 683, 691, 701, 709, 719, 727, 733,
  739, 743, 751, 757, 761, 769, 773, 787, 797, 809,
  811, 821, 823, 827, 829, 839, 853, 857, 859, 863,
  877, 881, 883, 887, 907, 911, 919, 929, 937, 941,
  947, 953, 967, 971, 977, 983, 991, 997, 0 };

void prime_factor(int n) {
	int i, d, t;
	int *pp;

	if ((n & 1) == 0) {
		t = 0;
		do n >>= 1, t++;
		while ((n & 1) == 0);
		if (power[2] < t) power[2] = t;
	}
	for (pp = ptbl; n > 1 && *pp > 0; pp++) {
		if (n % *pp) continue;
		d = *pp, t = 0;
		do n /= d, t++;
		while (n % d == 0);
		if (power[d] < t) power[d] = t;
	}
	if (n > 1 && power[n] == 0) power[n] = 1;
}

#define MOD 1000000007
int A[10005]; int N;

int pow_mod(int x, int p) {
	int r = 1;
	while (p) {
		if (p & 1) r = (ll)r * x % MOD;
		x = (ll)x * x % MOD;
		p >>= 1;
	}
	return r;
}

int extended_gcd(int a, int b, int *x, int *y) {
	int d;

	if (b == 0) { *x = 1; *y = 0; return a; }
	d = extended_gcd(b, a % b, y, x);
	*y -= a / b * (*x);
	return d;
}

int inverse(int a) {
    int x, y;
    extended_gcd(a, MOD, &x, &y);
    return x;
}

int main()
{
	int i, P;
	ll ans;
	
	N = in();
	for (i = 0; i < N; ++i) {
		A[i] = in();
		prime_factor(A[i]);
	}
	P = pow_mod(2, power[2]);
	for (i = 3; i < 1000000; i+=2) {
		if (power[i] > 1) P = (ll)P * pow_mod(i, power[i]) % MOD;
		else if (power[i] == 1) P = (ll)P * i % MOD;
	}
	ans = 0;
	for (i = 0; i < N; ++i) {
		ans += (ll)P * inverse(A[i]) % MOD;
	}
	ans %= MOD;
	if (ans < 0) ans += MOD;
	printf("%d\n", (int)ans);
	return 0;
}


Measured memory_bytes: 2816
package main

import "fmt"

const mod = 2019

func main() {
	var L, R int
	fmt.Scan(&L, &R)

	done := make([]bool, 2019)
	min := 1 << 32
	for i := L; i < R; i++ {
		if done[i%mod] {
			continue
		}
		for j := i + 1; j <= R; j++ {
			if j != i+1 && j%mod == (i+1)%mod {
				// 一周した
				done[i%mod] = true
				break
			}
			n := (i % mod) * (j % mod) % mod
			if n == 0 {
				fmt.Println(n)
				return
			}
			if n < min {
				min = n
			}
		}
	}

	fmt.Println(min)
}


Measured memory_bytes: 512
N, K=map(int,input().split(' '))
H=list(map(int,input().split(' ')))
dp=[]

for i in range(N):
	if i==0:
		dp.append(0)
	elif i==1:
		dp.append(abs(H[1]-H[0]))
	else:
		d = min([ dp[i-j]+abs(H[i]-H[i-j]) for j in range(1,K+1) if i-j>=0])
		dp.append(d)
		
print(dp[N-1])

Measured memory_bytes: 57824
using LIB;
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        while (true)
        {
            if (io.r<int>() == 0) { break; }
            int[] n = io.r<int>(' ');
            double ave = n.Average();
            double sd = 0;
            foreach (int buf in n)
            {
                sd += Math.Pow(ave - buf, 2);
            }
            sd = Math.Sqrt(sd / n.Count());
            io.w(sd);
        }
        io.wflush();
    }
}

namespace LIB
{
    public class io
    {
        private const int WMAX = 1000;
        private static StringBuilder S = new StringBuilder();
        public static T r<T>() { return util.parse<T>(r()); }
        public static T[] r<T>(char s = ' ') { return r().Split(s).Select(util.parse<T>).ToArray(); }
        public static T[] r<T>(int l) { T[] r = new T[l]; for (int i = 0; i < l; i++) { r[i] = r<T>(); } return r; }
        public static T[][] r<T>(int l, char s = ' ') { T[][] r = new T[l][]; for (int i = 0; i < l; i++) { r[i] = r<T>(s); } return r; }
        private static string r() { return Console.ReadLine(); }
        public static void w(object v, bool lf = true) { S.Append(util.parse<string>(v)); if (lf == true) { S.Append('\n'); } if (S.Length >= WMAX) { wflush(); } }
        public static void wflush() { Console.Write(S.ToString()); S.Length = 0; }
    }
    public class util
    {
        public static T parse<T>(object value) { return (T)(Convert.ChangeType(value, typeof(T))); }
    }
    public class memo<Key, Result>
    {
        private Dictionary<Key, Result> R;
        public memo() { R = new Dictionary<Key, Result>(); }
        public Result exec(Key k, Func<Key, Result> f) { Result r; if (R.ContainsKey(k)) { r = R[k]; } else { r = f(k); R.Add(k, r); } return r; }
    }
}

Measured memory_bytes: 10528
N, M = map(int, input().split())
xy = [[int(i)-1 for i in input().split()] for _ in range(M)]

cnt = [0] * N
v = [[] for _ in range(N)]
for x, y in xy :
  v[x].append(y)
  cnt[y] += 1
  
s = []
for i in range(N) :
  if cnt[i] == 0 :
    s.append(i)

dp = [0] * N
while s :
  cur = s.pop()
  for nex in v[cur] :
    dp[nex] = max(dp[nex], dp[cur] + 1)
    cnt[nex] -= 1
    if cnt[nex] == 0 :
      s.append(nex)
      
print(max(dp))

Measured memory_bytes: 74456
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		List<Integer> list = new ArrayList<>();		// 整数列
		int count = 0;								// 操作回数用

		int num = scan.nextInt();					// 整数の個数
		for(int i = 0; i < num; i++) {
			list.add(scan.nextInt());
		}

		out:
		while(true) {
			for(int i = 0; i < num; i++) {
				int tmp = list.get(i);

				if(tmp % 2 == 0)
					list.set(i, tmp / 2);
				else
					break out;
			}
			count++;
		}

		System.out.println(count);
		scan.close();
	}
}


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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for(int i = (int)(n); i > 0; --i)
#define all(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define rall(f,x,...) ([&](decltype((x)) whole) { return (f)(rbegin(whole), rend(whole), ## __VA_ARGS__); })(x)
#define sz(a) (int)(a).size()
#define mins(a,...) a = min({a, ## __VA_ARGS__})
#define maxs(a,...) a = max({a, ## __VA_ARGS__})
#define plusMod(a,b) a = (a % mod + b % mod) % mod
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) {
    return os.put(os.widen('\n'));
}
template<typename A, size_t N, typename T>
void fillArray(A(&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}

int n, m;
void solve() {
    cin >> n >> m;

    int l = 1, r = n;
    rep(i, m) {
        int lm, rm;
        cin >> lm >> rm;

        maxs(l, lm);
        mins(r, rm);
    }

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


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

    solve();

    cout << flush;

    return 0;
}


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


public class Test
{	
	public static void Main()
	{
		string even = Console.ReadLine();
        string odd = Console.ReadLine();
        string ans = "";

        int a = 0;
        int b = 0;
        for(int i = 0 ; i < (odd.Length + even.Length) ; i++)
        {
            if(i%2 == 1)
            {
                ans += odd[a].ToString();
                a++;
            }
            else
            {
                ans += even[b].ToString();
                b++;
            }
        }

        Console.WriteLine(ans);
	}

}

Measured memory_bytes: 11092
#include <stdio.h>

int main(void)
{
	int n = 0;
	char s[5];

	scanf("%s", s);
	for (int i = 0; s[i] != '\0'; i++) {
		if (s[i] == '+')	n++;
		else				n--;
	}
	printf("%d", n);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define RREPALL(i,v) for (int i = v.size()-1; i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n)
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int main()
{
    int n, a, b;
    cin>>n>>a>>b;
    cout<<min(a*n,b)<<endl;

    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

"""
奇数番目集合、偶数番目集合の中で自由にできるのが操作2．
操作1で集合間のやりとりをする
"""

import numpy as np

N = int(input())
A = np.fromstring(sys.stdin.read(),dtype=np.int64,sep='\n')

B = np.sort(A)

answer = len(np.setdiff1d(A[::2],B[::2]))
print(answer)

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

int main() {
	string str;
	int m, h;

	while (1) {
		cin >> str;
		if (str == "-")
			break;

		cin >> m;
		
		for (int i = 0; i < m; i++) {
			cin >> h;
			str += str.substr(0, h);
			str.erase(0, h);
		}

		cout << str << endl;
	}

	return 0;
}

Measured memory_bytes: 1228
from sys import stdin
import math
def LI(): return list(map(int,stdin.readline().rstrip().split()))

tmp = LI()
n,k = [tmp.pop(0) for _ in range(2)]
score = -1
ans = 0
for i in range(1,n+1):
    if k <= i:
        ans += 1/n
    else:
        x = math.log2(k/i)
        ix = int(x)
        if ix<x:
            ix += 1
        ans += pow(1/2,ix)/n

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    string s;
    cin >> s;
    if(s == "AAA" || s == "BBB"){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    return 0;
}

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

int main(int argc, char **argv){
	int n = 0;

	std::cin >> n;

	for(int i = 0; i < n; i++){
		std::vector<int> v(3);

		std::cin >> v[0] >> v[1] >> v[2];
		std::sort(v.begin(), v.end());

		if(v[2] * v[2] == v[0] * v[0] + v[1] * v[1]){
			std::cout << "YES";
		}
		else{
			std::cout << "NO";
		}
		std::cout << std::endl;
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll INF=1000000000;

vector<ll> pw2(51,1); vector<ll> pw10(19,1);
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll mid(ll x,ll y,ll z){return x>y?y>=z?y:min(z,x):x>=z?x:min(y,z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll myceil(ll x,ll y){if(x<=y) return 1;else if(x%y==0) return x/y;else return x/y+1;}
vector<ll> divisor(ll x){
	vector<ll> div;
	for(int i=1;i*i<=x;i++){
		if(i*i!=x && x%i==0){
			div.pb(i);
			div.pb(x/i);
		}
		else if(x%i==0) div.pb(i);
	}
	return div;
}

int main(){
	//......####
	// 0 1 2 ... N-1
	//0 1 2 ... N-1 N
	//切れ目が0~N
	ll N; cin>>N;
	string s; cin>>s;

	vector<ll>left(N+1,0);
	vector<ll>right(N+1,0);
	rep(i,N){
		if(s[i]=='#') left[i+1]=left[i]+1;
		else left[i+1]=left[i];
	}
	for(int i=N-1;i>=0;i--){
		if(s[i]=='.') right[i]=right[i+1]+1;
		else right[i]=right[i+1];
	}
	ll ans=INF;
	rep(i,N+1){
		ans=min(ans,left[i]+right[i]);
	}
	cout<<ans;
	
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int W,a,b;
 cin >> W >> a >> b;
 
  if(b+W<a) cout << a-(b+W) <<endl;
  else if(a+W < b) cout << b-(a+W) << endl;
  else cout << 0 << endl;
}
   

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<cmath>
#include<cstdio>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(){
    int y,m,d;
    char c1,c2;
    cin >> y >> c1 >> m >> c2 >> d;
    cout << (m <= 4 ? "Heisei":"TBD") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const long long MAX=1e9 + 5;


int main(void){
  int N;
  cin >> N;
  
  vector<long long> a(N);
  for(int i=0; i<N; i++) cin >> a[i];
  sort(a.begin(), a.end()); 

  int count = 0;
  for(int i=0; i<N; i++){
     int k = i;
     int odd = 1;
     while(a[k] == a[k+1]){
	odd++;
	k++;
      	i=k;
     }//while
     if(odd%2 ==1) count++;
  }//for

  cout << count << "\n";
}//main


Measured memory_bytes: 4044
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    string s;
    getline(cin,s);
    REP(i,s.length()){
    	if ('a' <= s[i] && s[i] <= 'z')
    	{
    		cout << (char)(s[i] - 'a' + 'A');
    	}else if ('A' <= s[i] && s[i] <= 'Z')
    	{
    		cout << (char)(s[i] - 'A' + 'a');
    	}else{
    		cout << s[i];
    	}
    }
    cout << endl;
}

Measured memory_bytes: 1172
# A = [list(map(int, input().split())) for _ in range(3)]
# k = int(input())
# B = [int(input()) for _ in range(n)]
# X = list(map(int, input().split()))
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = []
for _ in range(M):
    x, y, c = map(int, input().split())
    total = a[x-1] + b[y-1] - c
    ans.append(total)
ans.append(min(a)+min(b))
print(min(ans))



Measured memory_bytes: 18736
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
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;
}
 
//-----------------------ここから-----------
ll n, z, w;
vector<ll> a;
ll memo[3000][3];

ll dp(int i, int j, ll last1, ll last2){
	if(i == n){
		if(j == 1){
			return abs(last2 - last1);
		} else {
			return abs(last1 - last2);
		}
	}
	//cout << "s1 " << i << " " << j << endl;
	if(memo[i][j] != -INF) return memo[i][j];

	if(j == 0){
		ll res = -INF;
		for(int k = i + 1; k <= n; k++){
			//cout << "loop " << i << " " << j  << " " << k << endl;
			res = max(res, dp(k, 1, a[k], last2));
		}

		//cout << "s2 " << i << " " << j << endl;

		
		return memo[i][j] = res;
	} else {
		ll res = INF;
		for(int k = i + 1; k <= n; k++){
			res = min(res, dp(k, 0, last1, a[k]));
		}
		return memo[i][j] = res;
	}
}

int main(void){
	cin >> n >> z >> w;
	a.resize(n + 1);

	for(int i = 1; i <= n; i++) cin >> a[i];

	for(int i = 0; i <= n; i++){
		for(int j = 0; j < 3; j++){
			memo[i][j] = -INF;
		}
	}

	cout << dp(0, 0, z, w) << endl;
}

Measured memory_bytes: 512
/*#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <array>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
*/

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())

typedef long long ll;
const ll INF = LLONG_MAX - 100;
const ll mod = 1e9 + 7;
const int MAX_N = 5e5 + 5;
int dx[] = { -1LL,0,1LL,0 }, dy[] = { 0,1LL,0,-1LL };
vector<ll> prime;

ll inv[MAX_N], fac[MAX_N];

template <class T = ll> T in() { T x; cin >> x; return (x); }
inline ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; }return a; }
inline ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
inline ll POW(ll a, ll b) { ll c = 1LL; while (b > 0) { if (b & 1LL) { c = a * c%mod; }a = a * a%mod; b >>= 1LL; }return c; }
inline void _nCr() { fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) { fac[i] = fac[i - 1LL] * i%mod; }for (int i = 0; i < MAX_N; i++) { inv[i] = POW(fac[i], mod - 2); } }
inline ll nCr(ll n, ll r) { return (fac[n] * inv[r] % mod)*inv[n - r] % mod; }
inline void PRI(ll n) { bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) { a[i] = 1LL; }for (int i = 2; i < n + 1LL; i++) { if (a[i]) { prime.pb(i); ll b = i; while (b <= n) { a[b] = 0; b += i; } } } }

typedef pair<int, pair<int, int>> edge;

class UnionFind {
private:
	vector<int> par;
public:
	UnionFind(int N) { par = vector<int>(N, -1LL); }
	int find(int x);
	ll size(int x);
	void unite(int x, int y);
	bool same(int x, int y);
};



class Kruskal {
private:
	UnionFind *uf;
	vector<edge> e;
public:
	vector<edge> mst;
	Kruskal(int N) { uf = new UnionFind(N); }
	void add(int x, int y, ll z);
	void run();
};



//----UnionFind-------------------------------
int UnionFind::find(int x) {
	if (par[x] < 0) return x;
	else return par[x] = find(par[x]);
}

ll UnionFind::size(int x) {
	return -par[find(x)];
}

void UnionFind::unite(int x, int y) {
	x = find(x);
	y = find(y);

	//大きい方に小さい方をくっ付ける
	if (size(x) < size(y)) swap(x, y);
	par[x] += par[y];
	par[y] = x;
}

bool UnionFind::same(int x, int y) {
	x = find(x);
	y = find(y);
	return x == y;
}



//----Kruskal-------------------------------
void Kruskal::add(int x, int y, ll z) {
	//x < y
	if (x > y) swap(x, y);
	e.push_back({ z,{x,y} });
}

void Kruskal::run() {
	sort(e.begin(), e.end());
	e.erase(unique(e.begin(), e.end()), e.end());
	for (auto x : e) {
		if (uf->same(x.second.first, x.second.second)) {
			continue;
		}
		else {
			mst.push_back(x);
			uf->unite(x.second.first, x.second.second);
		}
	}
}

signed main() {
	int n;
	cin >> n;
	int a[n];
	multiset<int> mp;
	set<int> se;
	REP (i,n) {cin >> a[i];mp.insert(a[i]);se.insert(a[i]);}
	int cnt = 0;
	for (auto x : se) cnt += mp.count(x)-1;
	if (cnt % 2 == 0) cout << se.size() << endl;
	else cout << se.size()-1 << endl;
}

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

using namespace std;

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

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

	int N, K;
	cin >> N >> K;

	int x = (N-1) * (N-2) / 2;
	if(K > x){
		cout << -1 << endl;
		return 0;
	}

	int max_cnt = x - K;
	cout << N - 1 + max_cnt << endl;
	for(int i = 0; i < N - 1; i++){
		cout << 1 << " " << (i+2) << endl;
	}

	int a = 2;
	int b = 3;
	for(int i = 0; i < max_cnt; i++){
		cout << a << " " << b << endl;
		if(b == N){
			b = a + 2;
			a++;
		}else{
			b++;
		}
	}

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma optimize ("Ofast")
string str1,str2;
int dp[3005][3005];

int main() {
	std::ios_base::sync_with_stdio(false);
	cin>>str1>>str2;
	int len1=str1.size(),len2=str2.size();
	for (int i=len1-1;i>=0;--i) {
		for (int j=len2-1;j>=0;--j) {
			if (str1[i]==str2[j]) 
				dp[i][j]=dp[i+1][j+1]+1;
			else 
				dp[i][j]=max(dp[i+1][j],dp[i][j+1]);
		}
	}
	int fir=0,sec=0;
	while(fir<len1&&sec<len2) {
        if(str1[fir]==str2[sec]) {
            putchar(str1[fir]);
            fir++;
            sec++;
        }
		else if(dp[fir][sec]==dp[fir+1][sec]) fir++;
        else sec++;
    }
	return 0;
}

Measured memory_bytes: 35456
#include <iostream>

using namespace std;

long long int gcd(long long int a, long long int b) {
  return (a%b ? gcd(b, a%b) : b);
}

int main()
{
  int k;
  long long int ans = 0;
  cin >> k;
  for (int a = 1; a <= k; a++) {
    for (int b = 1; b <= k; b++) {
      for (int c = 1; c <= k; c++) {
        ans += gcd(gcd(a, b), c);
      }
    }
  }
  
  cout << ans << endl;
}
        

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

//オーバーフロー
//コーナーケース

typedef long long ll;
ll a[1<<18];
ll sum[1<<18];

int main() {
    ll n,k;
    cin >> n >> k;
    map<ll,ll> mp;
    ll ans = 0;
    mp[1]++;
    a[0] = 1;
    sum[0] = 0;
    for (int i = 1; i <= n; i++) {
        cin >> sum[i];
        sum[i] += sum[i - 1];
        a[i] = sum[i] - i + 1;
        while (a[i] < k) a[i] += k;
        a[i] %= k;
        sum[i] %= k;
        if (i >= k) {
            mp[a[i - k]]--;
        }
        ans += mp[a[i]];
        mp[a[i]]++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 16384
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef long long LL;
typedef pair<int,int> pa;
typedef vector<int> vec;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
int w,h,t,x,y,n;
vec v[500010];
int main(){
	cin>>h>>w>>n;
	FOR(i,1,n){
		getint(x),getint(y);
		v[x].pb(y);
	}
	t=1;
	FOR(i,2,h){
		FOR(j,0,SZ(v[i])-1) if (v[i][j]<=t) return cout<<i-1<<endl,0;
		bool ok=1;
		FOR(j,0,SZ(v[i])-1) if (v[i][j]==t+1) ok=0;
		if (ok) ++t;
	}
	cout<<h<<endl;
	return 0;
}

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



int main()
{
	int X,i;

	cin >> X;

	if (X <= 2) {
		cout << "2";
		return 0;
	}


	if (X % 2 == 0) {
		X = X + 1;
	}


	for (i = 3; i < X + 1; i= i + 2) {

		if (X % i == 0  && X != i) {
			X = X + 1;
			i = 3;
		}
		else {
			if (X % i == 0 && X == i) {
				cout << X << "\n";
			}

		}


	}


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	cin >> n >> m;
	int a[n],b[n],c[m],d[m];
	for(int i=0;i<n;i++){
		cin >> a[i] >> b[i];
	}
	for(int i=0;i<m;i++){
		cin >> c[i] >> d[i];
	}
	for(int i=0;i<n;i++){
		long long int min=10000000000;
		int ans=0;
		for(int j=0;j<m;j++){
			int sum1=0;
			int sum2=0;
			if(a[i]-c[j]>=0){
				sum1=a[i]-c[j];
			}else{
				sum1=-1*(a[i]-c[j]);
			}
			if(b[i]-d[j]>=0){
				sum2=b[i]-d[j];
			}else{
				sum2=-1*(b[i]-d[j]);
			}
			int sum=sum1+sum2;
			if(sum<min){
				min=sum;
				ans=j+1;
			}
		}
		cout << ans << endl;
	}
    return 0;
}


Measured memory_bytes: 256
from math import sqrt

N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]

dp = [[0]*N for _ in range(N)]
for i in range(N):
    for j in range(N):
        if i == j:
            pass
        elif i > j:
            dp[i][j] = dp[j][i]
        else:
            dp[i][j] = sqrt((XY[i][0]-XY[j][0])**2 + (XY[i][1]-XY[j][1])**2)

ans = 0
for i in range(N):
    for j in range(N):
        ans += dp[i][j]
print(ans/N)


Measured memory_bytes: 38256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
#include<queue>
#include<algorithm>
#include <functional>
#include<vector>
using namespace std;

long long N, K;
long long ans=0;

int main() {
	cin >> N >> K;
	long long a=0, b=0;
	for (int i = 1; i <= N; i++) {
		if(K%2==0){
			if (i%K == 0) a++;
			else if (i%K == (K / 2)) b++;
		}
		else {
			if (i%K == 0) a++;
		}
	}
	ans = a * a*a + b * b*b;


	cout << ans << endl;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    res = 0
    pre = -1
    for i in range(n):
        res += B[A[i] - 1]
        if pre + 1 == A[i]:
            res += C[pre - 1]
        pre = A[i]
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3064
//
// Created by misclicked on 2020/3/14.
//

#include <bits/stdc++.h>

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

#define ONLINE_JUDGE
#ifdef ONLINE_JUDGE
#define cerr if (false) cerr
#endif

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#else
    ios_base::sync_with_stdio(false);
    cin.tie();
#endif
    long double a, b, c;
    cin >> a >> b >> c;
    long double left = a + b + 2 * sqrtl(a * b);
    long double right = c;
    if (left < right) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int ch[30];
int hi[30];

int main()
{
	int n;cin >> n;
	
	string str;cin >> str;
	REP(i,str.size())
	{
		ch[str[i]-'a']++;
	}
	
//	SHOW1d(ch,26);
	
	REP(i,n-1)
	{
		REP(j,30)hi[j] = 0;
		cin >> str;
		REP(j,str.size())
		{
			hi[str[j]-'a']++;
		}
		REP(j,30)
		{
			ch[j] = min(ch[j],hi[j]);
		}
//		SHOW1d(ch,26);
	}
	
	REP(i,26)
	{
		REP(j,ch[i])
		{
			char tmp = 'a' + i;
			cout << tmp;
		}
	}
	cout << endl;
		

	return 0;
}

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

int main()
{
	int n,a,b;
	scanf("%d %d %d",&n,&a,&b);
	char string[n];
	scanf("\n%s",string);
	int i;
	int passed = 0;
	int o = 0;


	for (i=0;i<n;i++){
		if (string[i] == 'c') printf("No\n");
		else if (string[i] == 'a') {
			if (passed < a+b) {
				printf("Yes\n");
				passed++;
			} 
			else printf("No\n");
		} else {
			o++;
			if (passed < a+b && o <= b){
				printf("Yes\n");
				passed++;
			}
			else printf("No\n");
		}
	}
	return 0;
}

Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;

int main(){
  int n;
  while(~scanf("%d",&n)){
    int patterns[2001];
    memset(patterns,0,sizeof(patterns));
    for(int a=0;a<=1000;a++){
      for(int b=0;b<=1000;b++){
	patterns[a+b]++;
      }
    }

    ll res = 0;
    for(int lhs=0;lhs<=2000;lhs++){
      for(int rhs=0;rhs<=2000;rhs++){
	if(lhs == n - rhs){
	  res += patterns[lhs] * patterns[rhs];
	}
      }
    }
    printf("%lld\n",res);
  }
}

Measured memory_bytes: 1196
N = int(input())
A = list(map(int, input().split()))

P = {}
Q = {}

for i in range(N):
    if i+1 - A[i] in P:
        P[i+1 - A[i]] += 1
    else:
        P[i+1 - A[i]] = 1
    if i+1 + A[i] in Q:
        Q[i+1 + A[i]] += 1
    else:
        Q[i+1 + A[i]] = 1

res = 0
for k,v in P.items():
    if k in Q:
        res += v * Q[k]

print(res)



Measured memory_bytes: 57480
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

template<class T> using OS = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll long long
#define ld double
#define ull unsigned long long

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

    int k;
    cin >> k;
    int out = 0;
    for (int i = 1; i <= k; i++)
        for (int j = 1; j <= k; j++)
            for (int l = 1; l <= k; l++)
                out += __gcd(__gcd(i, j), l);
    cout << out;

    return 0;
}

Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		String firstNum = n.substring(0, 1);

		if (Integer.parseInt(n) > Integer.parseInt(firstNum + firstNum + firstNum)) {
			int a = Integer.parseInt(firstNum) + 1;
			System.out.println(String.valueOf(a) + String.valueOf(a) + String.valueOf(a));
		} else if (Integer.parseInt(n) <= Integer.parseInt(firstNum + firstNum + firstNum)) {
			System.out.println(firstNum + firstNum + firstNum);
		}
	}
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>                  
using namespace std;   
int main(){ 
  string s1, s2; cin >> s1 >> s2;   
  int64_t sum = 0;         
  for(int i=0;i<s1.size();i++)   
     sum += (s1[i] != s2[i]);     
  cout << sum << "\n";                         
return 0;                           
}  


Measured memory_bytes: 3852
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll a,b,c,d;


int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>a>>b>>c>>d;
    ll tp = c/b;
    if(c%b!=0)tp++;
    ll tp2 = a/d;
    if(a%d!=0)tp2++;
    Yes(tp2>=tp);
    return 0;
}

Measured memory_bytes: 3648
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D - Lucky PIN
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 30000;

/* typedef */

/* global variables */

char s[MAX_N + 4];
int ds[10][MAX_N], cs[10];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d%s", &n, s);

  for (int i = 0; s[i]; i++) {
    int d = s[i] - '0';
    ds[d][cs[d]++] = i;
  }

  int cnt = 0;
  for (int a = 0; a <= 9; a++) {
    int ai = lower_bound(ds[a], ds[a] + cs[a], 0) - ds[a];
    if (ai < cs[a]) {
      int ad = ds[a][ai];
      for (int b = 0; b <= 9; b++) {
	int bi = lower_bound(ds[b], ds[b] + cs[b], ad + 1) - ds[b];
	if (bi < cs[b]) {
	  int bd = ds[b][bi];
	  for (int c = 0; c <= 9; c++) {
	    int ci = lower_bound(ds[c], ds[c] + cs[c], bd + 1) - ds[c];
	    if (ci < cs[c]) cnt++;
	  }
	}
      }
    }
  }

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


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

#define INF 1000000007
#define ll long long
#define F first
#define S second
#define pii pair<ll int,ll int>
#define pb push_back
#define ppb pop_back
#define vi vector<ll int>

int h,w,grid[100][100],ans[100][100];

int solve(int i,int j){
	int an = INF;
	int a=0;
	if(j-1>=0){
		a =	ans[i][j-1];
		if(grid[i][j-1] && !grid[i][j]) a++;
		an = min(an,a);
	}
	if(i-1>=0){
		a = ans[i-1][j];
		if(grid[i-1][j] && !grid[i][j]) a++;
		an = min(an,a);
	}
	return min(an,a);
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	//cin >> t;
	while(t--){
		char c;
		cin >> h >> w;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				cin >> c;
				if(c == '.'){
					grid[i][j] = 0;
				}
				else{
					grid[i][j] = 1;
				}
				ans[i][j] = solve(i,j);
			}
		}
		if(grid[h-1][w-1]) ans[h-1][w-1]++;
		cout << ans[h-1][w-1];
	}
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <inttypes.h>

int compare_int(const void *a, const void *b){//qsort 整数比較<
	return *(int*)a - *(int*)b;
}
int compare_int2(const void *a, const void *b){//qsort 整数比較>
	return *(int*)b - *(int*)a;
}

//void func(int k,char *s,int i){
//	char *b={"A"};
//	if(i==k){
//		strcat(b,s);
//		strcpy(s,b);
//		strcat(s,"B");
//		strcat(s,"C");
//	}else{
//		strcat(b,s);
//		strcpy(s,b);
//		strcat(s,"B");
//		strcat(s,"C");
//		func(k,s,i+1);
//	}
//}

int main(void){
	int a,b,c,k;
	int i;

	scanf("%d %d %d",&a,&b,&c);
	scanf("%d",&k);

	for(i=0;i<=k;i++){
		if(a<b){
			if(b<c){
				printf("Yes");
				return 0;
			}else{
				c=2*c;
			}
		}else{
			if(b<c){
				b=2*b;
			}else{
				c=2*c;
			}
		}
	}
	printf("No");

	return 0;
}


Measured memory_bytes: 1724
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll N, K, P = 1000000007;
  std::cin >> N >> K;
  std::vector<ll> A(N);
  vvl dp = vv(N, K+1, 0, ll);
  for(int i=0;i<N;i++) std::cin >> A[i];
  vvl pre = vv(N, K+1, 0, ll);
  for(int j=N-1;j>=0;j--){
    if(j==N-1){
      for(int i=0;i<=K;i++) {
        if(i<=A[j]) dp[N-1][i] = 1;
        pre[j][i] = ((i==0?0:pre[j][i-1]) + dp[j][i])%P;
      }
    }else{
      for(int i=0;i<=K;i++){
        dp[j][i] = (pre[j+1][i]-(i>=A[j]+1?pre[j+1][i-A[j]-1]:0)+P)%P;
        pre[j][i] = ((i==0?0:pre[j][i-1]) + dp[j][i])%P;
      }
    }
  }
  std::cout << dp[0][K] << '\n';
  return 0;
}


Measured memory_bytes: 157552
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL -1
using namespace std;
const int64_t MOD = 1e9 + 7;

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

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

	int ans = 0;
	for (int i = 1; i < v.size() - 1; i++) {
		int sum = v.at(i - 1) + v.at(i) + v.at(i + 1);
		if (sum > ans) ans = sum;
	}

	cout << ans << endl;
}

Measured memory_bytes: 3768
n = gets.to_i
nums = gets.split( " " ).map { |val| val.to_i }
puts( nums.join( " " ) )

for i in ( 1 ... nums.length )
	key = nums[i]
	j = i - 1
	while 0 <= j && key < nums[j]
		nums[ j+1 ] = nums[j]
		j -= 1
	end
	nums[ j+1 ] = key
	puts( nums.join( " " ) )
end

Measured memory_bytes: 6112
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
#define print(x) cerr << (#x) << "is "<< x << "\n"
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int a,b;
   cin >> a >> b;
   int ans = max({2*a-1,2*b-1,a+b});
   cout << ans << '\n';
   return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <cmath>
#include <numeric>
#include <functional>
#include <stack>
#include <iomanip>
#include <map>

int main() {
	long long n;

	std::cin >> n;

	std::vector<double> v(n);

	for (long long i = 0; i < n; i++)
	{
		std::cin >> v[i];
	}

	// 昇順にソート
	std::sort(v.begin(), v.end());
	
	long long num = n;

	while (num != 1) {
		std::vector<double> v2;
		v2.push_back((v[0] + v[1]) / 2.0);
		for (long long i = 2; i < v.size(); i++)
		{
			v2.push_back(v[i]);
		}
		num = v2.size();
		std::sort(v2.begin(), v2.end());
		v = v2;
	}

	std::cout << v[0] << std::endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;


int josephus(int n, int k) {
  if (n == 1) {
    return 0;
  }
  return (josephus(n - 1, k) + k) % n;
}

int main() {
  while (true) {
    int n, k, m;
    cin >> n >> k >> m;
    if (n + k + m == 0) {
      break;
    }

    m = (m - k + 1 + n) % n;
    cout << (josephus(n, k) + m - 1 + n) % n + 1 << endl;
  }

  return 0;
}

Measured memory_bytes: 3272
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#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 <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back


map<char,string> dic;

main(){


  dic[' ']="101";
  dic['\'']="000000";
  dic[',']="000011";
  dic['-']="10010001";
  dic['.']="010001";
  dic['?']="000001";
  dic['A']="100101";
  dic['B']="10011010";
	
  dic['C']="0101";
  dic['D']="0001";
  dic['E']="110";
  dic['F']="01001";
  dic['G']="10011011";
  dic['H']="010000";
  dic['I']="0111";
  dic['J']="10011000";
	
  dic['K']="0110";
  dic['L']="00100";
  dic['M']="10011001";
  dic['N']="10011110";
  dic['O']="00101";
  dic['P']="111";
  dic['Q']="10011111";
  dic['R']="1000";
	
  dic['S']="00110";
  dic['T']="00111";
  dic['U']="10011100";
  dic['V']="10011101";
  dic['W']="000010";
  dic['X']="10010010";
  dic['Y']="10010011";
  dic['Z']="10010000";
  string str;
  
  while(getline(cin,str)){
    string code;
    rep(i,str.size()){
      code+=dic[str[i]];
    }
    
    while(code.size()%5)code+='0';

    for(int i=0;i<code.size();){
      string dec;
      rep(j,5)dec+=code[i+j];
      i+=5;
      
      int by=0;
      //cout<<dec<<endl;
      for(int j=0;j<5;j++){
        by=by*2+dec[j]-'0';
      }
      if(by<26)cout<<char(by+'A');
      else{
        switch(by){
        case 26:
          cout<<' ';
          break;
        case 27:
          cout<<'.';
          break;
        case 28:
          cout<<',';
          break;
        case 29:
          cout<<'-';
          break;
        case 30:
          cout<<'\'';
          break;
        case 31:
          cout<<'?';
          break;
        }
      }
    }
    cout<<endl;
  }
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>

using namespace std;

typedef struct tagPATTERN
{
	int hash;
	int set;
} PATTERN;

PATTERN *history;
int history_count;
int que_bottom;

void solve();
int make_hash(int* pattern);
void get_pattern(int* pattern,int hash);
void save_history(int* pattern,int set);

int main()
{
	int pattern[8],hash;
	solve();

	while(cin >> pattern[0] >> pattern[1] >> pattern[2] >> pattern[3] >> pattern[4] >> pattern[5] >> pattern[6] >> pattern[7])
	{
		hash = make_hash(pattern);
		for(int i=0;i<history_count;i++)
			if(hash == history[i].hash)
				printf("%d\n",history[i].set);
	}
	return 0;
	
}

void save_history(int* pattern,int set)
{
	int hash;
	hash = make_hash(pattern);
	for(int i=0;i<history_count;i++)
		if(history[i].hash == hash)
			return;
	history_count++;
	history = (PATTERN *)realloc(history,sizeof(PATTERN)*(history_count));
	history[history_count-1].hash = hash;
	history[history_count-1].set = set;
}

void solve()
{
	int zeropos,hash,set;
	int pattern[8] = {0,1,2,3,4,5,6,7};
	history_count = 0;
	save_history(pattern,0);
	que_bottom = 0;

	for(;;)
	{
		hash = history[que_bottom].hash;
		set = history[que_bottom].set;
		get_pattern(pattern,hash);
		for(int i=0;i<8;i++)
			if(pattern[i] == 0)
			{
				zeropos = i;
				break;
			}
		if(zeropos < 4)  //down
		{
			pattern[zeropos] = pattern[zeropos+4];
			pattern[zeropos+4] = 0;
			save_history(pattern,set+1);
			get_pattern(pattern,hash);
		}
		if(zeropos > 3)  // up
		{
			pattern[zeropos] = pattern[zeropos-4];
			pattern[zeropos-4] = 0;
			save_history(pattern,set+1);
			get_pattern(pattern,hash);
		}
		if((zeropos!=3)&&(zeropos!=7)) //right
		{
			pattern[zeropos] = pattern[zeropos+1];
			pattern[zeropos+1] = 0;
			save_history(pattern,set+1);
			get_pattern(pattern,hash);
		}
		if((zeropos!=0)&&(zeropos!=4)) // left
		{
			pattern[zeropos] = pattern[zeropos-1];
			pattern[zeropos-1] = 0;
			save_history(pattern,set+1);
			get_pattern(pattern,hash);
		}
		que_bottom++;
		if(history_count == que_bottom)
			break;
	}
}

int make_hash(int* pattern)
{
	int hash = 0;
	for(int i=0;i<8;i++)
		hash |= (pattern[7-i]) << (3*i);
	return hash;
}

void get_pattern(int* pattern,int hash)
{
	for(int i=0;i<8;i++)
	{
		pattern[7-i] = hash % 8;
		hash /= 8;
	}
}

Measured memory_bytes: 1476
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long

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

  ll N,M,p,x,y; cin >> N >> M;
  vector<ll> pvec(M),yvec(M);
  map<ll,list<ll>> ylistmap;
  vector<map<ll,ll>> ordermap(N+1);
  for (ll i = 0; i < M; ++i) {
    cin >> p >> y;
    pvec[i] = p; yvec[i] = y;
    ylistmap[p].push_back(y);
  }
  for (ll i = 0; i <= N; ++i) ylistmap[i].sort(); 

  for (ll i = 1; i <= N; ++i) {
    vector<ll> v(ylistmap[i].begin(),ylistmap[i].end());
    for (ll j = 0; j < v.size(); ++j) {
      (ordermap[i])[v[j]] = j+1;
    }
  }
  for (ll i = 0; i < M; ++i) {
    p = pvec[i];
    x = (ordermap[p])[yvec[i]];
    printf("%06d%06d\n",p,x);
  }
  return 0;
}

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

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-9)
#define MOD (int)(1e9+7)
#define INF numeric_limits<int>::infinity()
#pragma endregion


int main()
{
    while(true) {
        int n;
        cin >> n;
        if (n==0) return 0;
        int ret = 1000 - n;

        int ans = 0;

        ans += ret / 500;
        ret = ret % 500;

        ans += ret / 100;
        ret = ret % 100;

        ans += ret / 50;
        ret = ret % 50;

        ans += ret / 10;
        ret = ret % 10;

        ans += ret / 5;
        ret = ret % 5;

        ans += ret;

        P(ans);
    }

    return 0;
}

Measured memory_bytes: 3044