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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<Long> pos = new ArrayList<>();
		pos.add(sc.nextLong());
		for(int i = 0; i < n; i++) {
			pos.add(sc.nextLong());
		}
		Collections.sort(pos);
		long pre = pos.get(0);
		List<Long> dist = new ArrayList<>();
		for(int i = 1; i < pos.size(); i++) {
			long tmp = pos.get(i);
			dist.add(tmp - pre);
			pre = tmp;
		}
		long ans = dist.get(0);
		for(int i = 1; i < dist.size(); i++) {
			ans = gcd(ans, dist.get(i));
		}
		System.out.println(ans);

	}

	public static long gcd(long a, long b) {
		long ans = 0;
		if(a > b) {
			long tmp = b;
			b = a;
			a = tmp;
		}
		if(b % a == 0) {
			ans = a;
		} else {
			b = b % a;
			ans = gcd(a, b);
		}
		return ans;
	}

}


Measured memory_bytes: 60280
#include<bits/stdc++.h>
using namespace std;
#include<string>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define intarr(arr, n)  ll arr[n];  for (ll i = 0; i < n; i++)  cin >> arr[i]
#define inpvec(vec,n) for(ll i=0;i<n;i++){ll v;cin>>v;vec.push_back(v);}
#define ff first
#define ss second
#define pb push_back
#define mkp make_pair
#define vec vector<ll>
#define pi pair<ll,ll>
#define changeline cout<<endl
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(),v.end()
#define mod2 998244353
#define NO cout << "NO" <<endl
#define YES cout << "YES" <<endl
#define mem(arr,val) memset(arr,val,sizeof(arr));
const ll mod=1e9+7;

bool prime(ll n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
bool subsequence_checker(string str1, string str2, ll m, ll n) 
{ 
    if (m == 0) return true; 
    if (n == 0) return false; 
    if (str1[m-1] == str2[n-1]) 
        return subsequence_checker(str1, str2, m-1, n-1); 
    return subsequence_checker(str1, str2, m, n-1); 
}
ll inv(ll a)
{
    ll p=mod2;
    ll b=p-2,ans=1;
    for(;b > 0;a = a * a % p,b >>= 1)if(b & 1)ans = ans * a % p;
    return ans;
}
ll ncr(ll n,ll m)
{
    ll p=mod2;
    if(m > n)return 0;
    ll up=1,down=1;
    for(int i=n-m+1;i<n+1;i++)up*=i,up%=p;
    for(int i=1;i<m+1;i++)down*=i,down%=p;
    return up*inv(down)%p;
}

ll countDigit(ll n)
{   
    return floor(log10(n) + 1); 
}  
ll a_pow_b(ll a,ll b)
{
    ll p=1000000007;
    ll ans=1;
    for(;b > 0;a = a * a % p,b >>= 1)if(b & 1)ans = ans * a % p;
    return ans;
}
ll gcd(ll a,ll b) 
{ 
    if (b==0) 
        return a; 
    return gcd(b,a%b);      
} 
ll lcm(ll a, ll b)  
{  
    return (a*b)/gcd(a, b);  
}
bool isPerfectSquare(ll x) 
{   
  long double sr = sqrt(x); 
  return ((sr - floor(sr)) == 0); 
}
ll ncr123(ll n, ll k){
    if (k == 1) {
        return n;
    }
    if (k == 2) {
        return n * (n - 1) / 2;
    }
    if (k == 3) {
        return n * (n - 1) * (n - 2) / 6;
    }
}
bool com(const pi &a,const pi &b)   //acc to second element sort for vec of pi
{ 
    if(a.second==b.second)
        return a.first<b.first;
    return a.second<b.second;
}


void solve(){

string s;
    cin>>s;

    ll size=s.length();
    ll n=s[size-1]-'0';

    map<ll,string> m;

    m[3]="bon";
    m[0]=m[1]=m[6]=m[8]="pon";

    if(m.count(n)==0){
        cout<<"hon"; return;
    }

    cout<<m[n];
    return;
}
 
 
int main()
{
    IOS;
    ll t;
    //cin>>t;
    t=1;

    while(t--){
        solve();
        cout<<endl;
    }

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Measured memory_bytes: 3696
void main()
{
    int[] tmp = readln.split.to!(int[]);
    int n = tmp[0], m = tmp[1];
    string s = readln.chomp;

    int[] move;
    while (n > 0)
    {
        bool ok;
        foreach_reverse (i; 1 .. m+1)
        {
            if (n - i < 0) continue;

            if (s[n-i] == '0')
            {
                ok = true;
                n -= i;
                move ~= i;
                break;
            }
        }

        if (!ok)
        {
            break;
        }
    }

    if (n == 0)
    {
        reverse(move);
        move.to!(string[]).join(" ").writeln;
    }
    else
    {
        writeln(-1);
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 7036
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <time.h>
#include <algorithm>
#include <set>
#define MAXX 111
#define ll long long
using namespace std;



int dp[MAXX+1][MAXX+1][MAXX+1];


int main() {

    for(int a=MAXX;a>=0;a--)
        for(int b=MAXX;b>=0;b--)
            for(int c=MAXX;c>=0;c--) {
                if (a==b && b==c) {
                    dp[a][b][c]=0;
                    continue;
                }
                
                dp[a][b][c]=(1<<30);
                
                if (a+1 <= MAXX && b+1 <= MAXX)
                    dp[a][b][c]=min(dp[a][b][c],1+dp[a+1][b+1][c]);
                
                if (b+1 <= MAXX && c+1 <= MAXX)
                    dp[a][b][c]=min(dp[a][b][c],1+dp[a][b+1][c+1]);
                
                if (a+1 <= MAXX && c+1 <= MAXX)
                    dp[a][b][c]=min(dp[a][b][c],1+dp[a+1][b][c+1]);
                
                
                
                if (a+2 <= MAXX)
                    dp[a][b][c]=min(dp[a][b][c],1+dp[a+2][b][c]);
                
                if (b+2 <= MAXX)
                    dp[a][b][c]=min(dp[a][b][c],1+dp[a][b+2][c]);
                
                if (c+2 <= MAXX)
                    dp[a][b][c]=min(dp[a][b][c],1+dp[a][b][c+2]);
                
            }
    
    int A,B,C;
    cin>>A>>B>>C;
    
    
    cout << dp[A][B][C] << endl;
    
    
}

Measured memory_bytes: 5760
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<ctime>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<deque>
#include<map>
#include<cstring>
#include<stack>
#include<cctype>
#include<cstdio>
#include<bitset>
#ifdef LOCAL
	#define enu(i,n) for(int i=0;i<n;i++)
	#define tri(x) x*(x+1)/2;
	#define sqrsum(x) x*(x+1)*(2*x+1)/6;
	#define sqrsum_range(a,b) sqrsum(b)-sqrsum(a-1);
#endif
#define FOR(i,a,b) for(int i=a,_b=b;i<_b;i++)
#define REP(i,a,b) FOR(i,a,b+1)
#define ll_max 9223372036854775807LL
#define ll_min -9223372036854775808LL
#define int_max 2147483647
#define int_min -2147483648
#define PI 3.141592653589793238462653383
#define eps 0.00000001
#define elif else if
using namespace std;
void fast()
{
	cin.tie(NULL);
	cout.tie(NULL);
	ios_base::sync_with_stdio(false);
	return ;
}
bool isprime(int x)
{
	if(x<2)
		return false;
	for(int i=2;i<=sqrt(x);i++)
		if(x%i==0)
			return false;
	return true;
}
int GCD(int a,int b)
{
	return (b?GCD(b,a%b):a);
}
struct Tm
{
	int h,m,s;
	bool add()
	{
		s++;
		if(s==60)
			m++,
			s=0;
		if(m==60)
			h++,
			m=0;
		return (h<100);
	}
	void print()
	{
		printf("%02d:%02d:%02d",h,m,s);
		return ;
	}
	void println()
	{
		print();
		puts("");
	}
};
vector<int> G[100100];
int dist[100100][2];
void dfs(int now,int pre,int x)
{
	for(int i=0;i<G[now].size();i++)
		if(G[now][i]!=pre)
		{
			dist[G[now][i]][x]=dist[now][x]+1;
			dfs(G[now][i],now,x);
		}
	return ;
}
int main()
{
	int N;
	cin>>N;
	for(int i=1;i<N;i++)
	{
		int a,b;
		cin>>a>>b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dfs(1,0,0);
	dfs(N,0,1);
	int cnt1=0,cnt2=0;
	for(int i=1;i<=N;i++)
		if(dist[i][0]<=dist[i][1])
			cnt1++;
		else	cnt2++;
	if(cnt2>=cnt1)
		puts("Snuke");
	else	puts("Fennec");
	return 0;
}

Measured memory_bytes: 14336
#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;

int task[3];
int flag[3] = {1,1,1};
int ans = 5000;
int buffa;

int solve(){
	for(int i = 0;i<3;i++)
	{
		flag[i] = 0;
		for(int j = 0;j<3;j++)
		{
			if(flag[j] == 1)
			{
				buffa = abs(task[j] - task[i]);
				flag[j] = 0;
				for(int h = 0;h<3;h++)
				{
					if(flag[h] == 1)
					{
						buffa += abs(task[h] - task[j]);
						if(buffa < ans)
							ans = buffa;
						//printf("%d %d %d\n%d\n",flag[0],flag[1],flag[2],ans);
					}
				}
				flag[j] = 1;
			}
		}
		flag[i] = 1;
	}
}

int main(){
	
	for(int i = 0;i<3;i++)
	{
		cin >> task[i];
	}
	
	solve();
	printf("%d\n",ans);
	
	return 0;
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: usize,
        q: usize,
        a: [u64; n],
        query: [(usize, usize, usize); q],
    }
    let mut segtree = SegmentTree::new(&a, std::u64::MIN, |a, b| a + b);
    for (qq, x, y) in query {
        match qq {
            0 => segtree.update_with(x as usize, |v| v + y as u64),
            1 => println!("{}", segtree.query(x, y)),
            _ => unreachable!(),
        }
    }
}
struct SegmentTree<T: Copy> {
    n: usize,            // size of data
    f: fn(T, T) -> T,    // binary operation of the monoid
    e: T,                // identity element of the monoid
    binary_tree: Vec<T>, // 1-indexed binary tree (parent: x/2, left_child: x*2, right_child: x*2+1, sibling: x^1, is_x_left_child: x%2==0, is_x_right_child: x%2==1)
}
impl<T: Copy> SegmentTree<T> {
    /// O(n) # create segment tree (e is identity element for a function f in type T)
    fn new(data: &[T], e: T, f: fn(T, T) -> T) -> Self {
        let (n, binary_tree) = (data.len(), vec![e; 2 * data.len().next_power_of_two()]);
        let segment_tree = SegmentTree {
            n,
            f,
            e,
            binary_tree,
        };
        segment_tree.init(data)
    }

    /// O(n) # init segment tree by given data
    fn init(mut self, data: &[T]) -> Self {
        let leaf_offset = self.leaf_offset();
        for (i, &di) in data.iter().enumerate() {
            self.binary_tree[leaf_offset + i] = di;
        }
        for i in (1..leaf_offset).rev() {
            self.binary_tree[i] = (self.f)(self.binary_tree[i * 2], self.binary_tree[i * 2 + 1]);
        }
        self
    }

    /// O(1) # get beginning index of the segment tree leaf
    fn leaf_offset(&self) -> usize {
        self.n.next_power_of_two()
    }

    /// O(log(n)) # set leaf[k] = x, and update segment tree. (non-recursive)
    fn update_with<U>(&mut self, k: usize, f: U)
    where
        U: Fn(T) -> T,
    {
        let mut current = self.leaf_offset() + k;
        self.binary_tree[current] = f(self.binary_tree[current]);
        while current / 2 > 0 {
            current /= 2;
            self.binary_tree[current] = (self.f)(
                self.binary_tree[current * 2],
                self.binary_tree[current * 2 + 1],
            );
        }
    }

    /// O(log(n)) # calculate f(l, l+1, ..., r-1). note the half interval [l, r). (non-recursive)
    fn query(&self, l: usize, r: usize) -> T {
        let (mut l, mut r) = (self.leaf_offset() + l, self.leaf_offset() + r);
        let mut result = self.e;
        while l < r {
            if l % 2 == 1 {
                result = (self.f)(result, self.binary_tree[l]);
                l += 1; // l is right child, so move to next subtree.
            }
            if r % 2 == 1 {
                result = (self.f)(result, self.binary_tree[r ^ 1]);
            }
            l /= 2;
            r /= 2;
        }
        result
    }
}


Measured memory_bytes: 41212
import itertools
import copy

def countKuro(table):
	return sum(sum(table, []))

height, width, kuro = map(int, input().split())

constanttable = []
for _ in range(height):
	line = []
	str = input()
	for char in str:
		if char == '.':
			line.append(0)
		else:
			line.append(1)
	constanttable.append(line)

counter = 0
heightconds = list(itertools.product(range(2), repeat = height))
widthconds = list(itertools.product(range(2), repeat = width))

for h, heightcond in enumerate(heightconds):
	table = copy.deepcopy(constanttable)
	for l, linecond in enumerate(heightcond):
		if linecond == 1:
			table[l] = [0] * width

	if countKuro(table) < kuro:
		continue

	for widthcond in widthconds:
		transposed_table = list(map(list, zip(*table)))
		for c, columncond in enumerate(widthcond):
			if columncond == 1:
				transposed_table[c] = [0] * height

		if countKuro(transposed_table) == kuro:
			counter += 1

print(counter)

Measured memory_bytes: 9340
#include<bits/stdc++.h>
using namespace std;
int main() {
  int l;
  cin >> l;
  if ( l != 1 ) {
    double m = l*l*l/27;
    cout << fixed << setprecision(8);
    cout << m << endl;
  }
  else {
    double n = 0.33333333;
    double k = n*n*n;
    cout << fixed << setprecision(8);
    cout << k << endl;
  }
}

Measured memory_bytes: 256
//Robs Code
/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <queue>
#include <map>
/***********MACROS***************/
#define int long long int
#define fri(l,k) for (i=l;i<=k;i++)
#define frj(l,k) for (j=l;j>=k;j--)
#define fij(a,b,l,k) for(i=a;i<=b;i++) for(j=l;j<=k;j++)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define mxsz 1e5+10
#define mod 1e9 + 7
#define pii pair<int,int>
using namespace std;
const int N = 1e5 + 1;
int n,m,i,j,l,k,x,y,a,b,cnt[3],sum[3];
/***********MAIN**************/
vector<int> dp,v;
int brute(int indx){
	if(indx >= (n)){
		return 1e9;
	}
	if(indx == (n-1))
		return 0;
	if(dp[indx] != -1){
		return dp[indx];
	}
	int ans1 = 1e7,ans2 = 1e7;
	ans1 = brute(indx+1) + abs(v[indx] - v[indx+1]);
	ans2 = brute(indx+2) + abs(v[indx] - v[indx+2]);
	return dp[indx] = min(ans1,ans2);
}
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin>>n;
	v.assign(n+5,0);
	for(auto &x : v){
		cin>>x;
	}
	dp.assign((int)1e5+1,-1);
	cout<<brute(0);
    return 0;
}
//.........

Measured memory_bytes: 4992
# -*- coding: utf-8 -*-


def main():
    s = input()
    q = int(input())

    queries = (input().split() for i in range(q))

    flg = True
    result = s
    pre = ""
    post = ""
    for query in queries:
        if "1" == query[0]:
            flg = not flg
        elif "2" == query[0]:
            if ("1" == query[1] and flg) or ("2" == query[1] and not flg):
                pre = query[2] + pre
            else:
                post += query[2]

    if flg:
        print(pre + result + post)
    else:
        print((pre + result + post)[::-1])


if __name__ == '__main__':
    main()

Measured memory_bytes: 4436
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

// Ypos/left/right/Xpos/sanso/
int dp[10][10][10][10][51];
int a,b;
int get(int s,int d,int lim){
	if(d<0){
		a = s;
		b = -d;
	}else{
		a = min(lim,s + d);
		b = 0;
	}
}
int solve(int W,int H,int f,int m,int o,vector<vector<int> >data){
	int ret = (1<<29);
	if(o<2)return ret;
	rep(i,10)rep(j,10)rep(k,10)rep(l,10)rep(m,51)dp[i][j][k][l][m] = (1<<29);
	rep(i,W){
		get(o-1,data[0][i],m);
		dp[0][i][i][i][a] = b;
	}
	for(int y=0;y<H;y++){
		rep(Q,m){
			for(int s=2;s<=m;s++){
				rep(l,W)for(int r=l;r<W;r++){
					rep(x,W){
						// left
						if(x > 0){	
							if(l==x){
								get(s-1,data[y][x-1],m);
								dp[y][x-1][r][x-1][a] = 
									min(
										dp[y][x-1][r][x-1][a],
										dp[y][l][r][x][s] + b
									);
							}else{
								dp[y][l][r][x-1][s-1] = 
									min(
										dp[y][l][r][x-1][s-1],
										dp[y][l][r][x][s]
									);
							}
						}
						
						// right 
						if(x < W-1){
							if(r==x){
								get(s-1,data[y][x+1],m);
								dp[y][l][x+1][x+1][a] = 
									min(
										dp[y][l][x+1][x+1][a],
										dp[y][l][r][x][s] + b
									);
							}else{
								dp[y][l][r][x+1][s-1] = 
									min(
										dp[y][l][r][x+1][s-1],
										dp[y][l][r][x][s]
									);
							}
						}
					}
				}
			}
			for(int s=2;s<=m;s++){
				rep(l,W)for(int r=l;r<W;r++){
					rep(x,W){
						if(y < H-1){
							get(s-1,data[y+1][x],m);
							dp[y+1][x][x][x][a] = 
								min(
									dp[y+1][x][x][x][a],
									dp[y][l][r][x][s] + b
								);
						}
					}
				}
			}
		}
	}
	for(int s=1;s<=m;s++){
		rep(l,W)for(int r=l;r<W;r++){
			rep(x,W){
				ret = min(dp[H-1][l][r][x][s],ret);
			}
		}	
	}
	return ret;
}
int main(){
	int W,H,f,m,o;
	while(cin >> W >> H , W){
		cin >> f >> m >> o;
		vector< vector<int> > data(H,vector<int>(W));
		rep(i,H)rep(j,W)cin >> data[i][j];
		int ret = solve(W,H,f,m,o,data);
		if(ret <= f ) cout << ret << endl;
		else cout << "NA" << endl;
	}
}

Measured memory_bytes: 2916
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {
            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }

        
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var  input = Reads();
            var d = input[0];
            var n = input[1];
            if (d == 0)
            {
                if (n != 100)
                    Console.WriteLine(n);
                else
                    Console.WriteLine(101);
            }
            else if (d == 1)
            {
                if (n != 100)
                    Console.WriteLine(n * 100);
                else
                    Console.WriteLine(10100);
            }
            else
            {
                if (n != 100)
                    Console.WriteLine(n * 10000);
                else
                    Console.WriteLine(1010000);
            }
           

            
           
            Console.Out.Flush();
        }
    }
}

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

using namespace std;
/*
void print(vector<int>& v)
{
  const int NO = 4;
  bool ex[5] = {false,false,false,false,false};
  int c[5]; c[NO] = 0;
  for (int i = 0; i < 8; ++i) {
    if (!ex[v.at(i)]) {
      int a = 0, b = v[i];
      for (auto j = i+1; v[j] != v.at(i); j++) {
        a ^= v.at(j);
      }
      ex[v[i]] = true;
      c[b] = a;
    }
  }
  
  if (c[0] != 0 && c[0] == c[1] && c[2] == c[1] && c[2] == c[3]) {
    for_each(v.begin(), v.end(), [](int x) {
      cout << x << " ";
    });

    for (int i = 0; i <= 4; i++) {
      if (i != NO)
      cout << i << ":" << c[i] << " ";
    }
    
    cout << endl;
  }
}
*/

int main(void) {
  int M, K; cin >> M >> K;
  int N = (1 << M);

  if (M == 0) {
    if (K == 0) {
      cout << "0 0" << endl;
    } else {
      cout << -1 << endl;
    }
  } else if (M == 1) {
    if (K == 0) {
      cout << "0 0 1 1" << endl;
    } else {
      cout << -1 << endl;
    }
  } else {
    if (K < N) {
      for (int i = 0; i < N; i++) {
        if (K != i)
          cout << i << " ";
      }
      cout << K << " ";
      for (int i = N-1; i > -1; i--) {
        if (K != i)
          cout << i << " ";
      }
      cout << K << endl;
    } else {
      cout << -1 << endl;
    }
  }
/*
  vector<int> n4;
  for (int i = 0; i < 4; i++) {
    n4.push_back(i);
    n4.push_back(i); 
  }

  do {
    print(n4);
  } while (next_permutation(n4.begin(), n4.end()));
*/
  return 0;
}

Measured memory_bytes: 1792
def sieve(n):
    is_prime = [True for _ in range(n)]
    is_prime[0] = False

    for i in range(2, n + 1):
        if is_prime[i - 1]:
            j = i
            f = 0
            while j <= n:
                if f and j in b:
                    return False
                if j in b:
                    f = True
                is_prime[j - 1] = False
                j += i
    return True


from math import gcd
from functools import reduce


def gcd_list(numbers):
    return reduce(gcd, numbers)


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
b = set(a)
c = Counter(a)
f = 0
for i in c:
    if i != 1 and c[i] > 1:
        f = 1
if ((1 in a and len(b) == 1) or sieve(10 ** 6)) and f == 0:
    print("pairwise coprime")
elif gcd_list(a) == 1:
    print("setwise coprime")
else:
    print("not coprime")


Measured memory_bytes: 285840
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>

using namespace std;

//conversion
//------------------------------------------
inline long toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline long toLong(string s) {long v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-12;
const int INF = 10000;

struct edge{int to,cost;};
typedef pair<int,int> P;//firstは最短距離,secondは頂点番号

int main(){
	int T;
	cin>>T;
	
	REP(t,T){
		int y,m,d;
		cin>>y>>m>>d;
		int sum=0;
		if(y%3!=0&&m%2==0){
			sum+=20-d;
			d=1;
			if(m==10){
				y++;m=1;
			}else{
				m++;
			}
		}else{
			sum+=21-d;
			if(m==10){
				y++;m=1;
			}else{
				m++;
			}
		}
		
		while(y<1000){
			while(m<=10){
				if(y%3!=0&&m%2==0){
					sum+=19;
				}else{
					sum+=20;
				}
				m++;
				
			}
			m=1;y++;
		}
		cout<<sum<<endl;
	}
	
	return 0;
}

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

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

int main(){
  double a;
  while(~scanf("%lf",&a)){
    double sum = a;
    REP(i,1,10){
      if( i%2 ){
	a *= 2.0;
      }else{
	a /= 3.0;
      }
      sum += a;
#if DEB
      printf("%lf\n",a);
#endif
    }
    printf("%lf\n",sum);
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define pb push_back

using namespace std;

const int N=100005,fc[3]={2,0,1},bc[3]={1,2,0};
int n,m,col[N],V[3],num;
long long ans;
bool vis[N],ok;
vector<int> E1[N],E2[N];

void dfs(int x,int c){
	col[x]=c,V[c]++,vis[x]=true,num+=E1[x].size(); 
	for(int v:E1[x])
		if(vis[v])ok&=col[v]==bc[c];else dfs(v,bc[c]);
	for(int v:E2[x])
		if(vis[v])ok&=col[v]==fc[c];else dfs(v,fc[c]);
}

int main(){
	scanf("%d%d",&n,&m);
	for(int i=1,u,v;i<=m;i++)scanf("%d%d",&u,&v),E1[u].pb(v),E2[v].pb(u);
	for(int i=1;i<=n;i++)if(!vis[i]){
		int&a=V[0],&b=V[1],&c=V[2];
		ok=true,a=b=c=num=0,dfs(i,0);
		if(!ok)
			ans+=(long long)(a+b+c)*(a+b+c);
		else if(!a||!b||!c)
			ans+=num;
		else
			ans+=(long long)a*b+(long long)b*c+(long long)c*a;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 16384
#include<iostream>
#define N 100000
#define MOD 1000000007
using namespace std;
typedef long long LL;
LL dx[N];
LL dy[N];
int main()
{
	LL n, m; cin >> n >> m;
	LL prev; 
	cin >> prev;
	for(int i = 1; i < n; i++)
	{
		LL nxt; cin >> nxt;
		dx[i-1] = nxt-prev;
		prev = nxt;
	}
	cin >> prev;
	for(int i = 1; i < m; i++)
	{
		LL nxt; cin >> nxt;
		dy[i-1] = nxt-prev;
		prev = nxt;
	}

	LL sum1 = 0, sum2 = 0;
	for(LL i = 0; i < n-1; i++)
		sum1 += dx[i]*((i+1)*(n-1-i)%MOD), sum1 %= MOD;
	for(LL i = 0; i < m-1; i++)
		sum2 += dy[i]*((i+1)*(m-1-i)%MOD), sum2 %= MOD;
	cout<<((sum1*sum2)%MOD+MOD)%MOD<<endl;

	return 0;
}

Measured memory_bytes: 1792
import sys

x = {}

for line in sys.stdin:
  for l in line:
    if l.isalpha():
      c = l.lower()
      x[c] = x.get(c,0)+1

for i in range(26):
  c = chr(ord('a')+i)
  print(f'{c} : {x.get(c,0)}')


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

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
    ll t,i,j,temp1,temp2,x,y,sum=0,o,n,m,k,d;
    cin >> x;
    for(i=0;i<150;i++){
        for(j=0;j<150;j++){
            temp1 = (i*i*i*i*i);
            temp2 = (j*j*j*j*j);
            if(temp1-temp2==x){
                cout << i << " " << j;
                return 0;
            }
            else if(temp1+temp2==x){
                cout << i << " " << -j;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3648
n = int(input())
s = [input() for i in range(n)]
m = int(input())
t = [input() for i in range(m)]
st = s + t
d = {}
for i in range(n+m):
	d.setdefault(st[i],0)
for i in s:
	d[i] += 1
for i in t:
	d[i] -= 1

print(max(int(max(d.values())), 0))

Measured memory_bytes: 3064
#!/usr/bin/env python3

from itertools import product
H, W, K = map(int, input().split())
CC = [list(input()) for _ in range(H)]

C = []

for i in range(H):
    a = []
    for j in range(W):
        if CC[i][j] == '.':
            a.append(0)
        else:
            a.append(1)
    C.append(a)
ret = 0
for ph in product([0,1], repeat=H):
    for pw in product([0,1], repeat=W):
        cnt = 0
        for i in range(len(ph)):
            if ph[i] == 0:
                for j in range(len(C[i])):
                    if C[i][j] == 1 and pw[j] == 0:
                        cnt += 1
        if cnt == K: ret += 1

print(ret)




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

constexpr int MaxN = 100000;
constexpr int MaxM = 100000;

int main()
{
	int N, M;
	vector<int> X;
	
	cin >> N >> M;
	for (int i = 0; i < M; ++i)
	{
		int x;
		cin >> x;
		X.push_back(x);
	}

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

	vector<int> dif;
	for (int i = 0; i < X.size() - 1; ++i)
	{
		dif.push_back(X[i + 1] - X[i]);
	}

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

	int sum = 0;
	for (int i = 0; i < static_cast<int>(dif.size()) - N + 1; ++i)
	{
		int a = dif.size() - N + 1;

		sum += dif[i];
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 1400
mod = int(1e9+7)
def add(a, b):
    c = a + b
    if c >= mod:
        c -= mod
    return c

def main():
    #A, B = [int(x) for x in raw_input().split()]
    ch = raw_input()
    
    if ch.isupper():
        print('A')
    else:
        print('a')
    

main()

Measured memory_bytes: 85296
#include <stdio.h>

int main(void)
{
	int x[10000];
	int i;
	
	for (i = 0; 1; i++){
		scanf("%d", &x[i]);
		if (x[i] == 0){
			break;
		}
		printf("Case %d: %d\n", i + 1, x[i]);
	}
	
	return (0);
}

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

int main() {
  int N ,K , x , sum;
  cin >> N >> K;
  sum = 0 ;
  
  for ( int i = 0; i < N ;i++){
    cin >> x ;
    if(x < (K - x )){
      sum += 2*x;
    }else {
      sum += 2*(K - x);
    }
  }

  cout << sum <<endl;
}



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

using namespace std;

int main(){
	ll a,b;
	
	cin>>a>>b;
	
	while(a*b>0){
		if(a>b) a=a%b;
			else b=b%a;
	}
	
	cout<<a+b<<endl;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	int t,n;
	cin>>t>>n;
	int ar[t];
	for(int i=0;i<t;++i) cin>>ar[i];
	sort(ar,ar+t,greater<int>());
	int sum=0;
	for(int i=0;i<n;++i) sum+=ar[i];
	cout<<sum;
	return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int n;cin>>n;
    vector<int> a(n);
    for(int i = 0; n > i; i++){
        cin>>a[i];
    }
    sort(a.begin(),a.end(),greater<int>());
    int nw = 0;
    for(int i = n; 0 < i; i--){
      while(true){
        if(nw == i){
          cout << i << endl;
          return 0;
        }
        if(i <= a[nw]){
          nw++;
        }else{
          break;
        }
      }
      //cout << i << " " << nw << endl;
    }
}


Measured memory_bytes: 3136
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
    int N = sc.nextInt(); //ドーナツの種類の数
    int X = sc.nextInt(); //粉の量(グラム)
    int[] m = new int[N]; //それぞれのドーナツに必要な粉の量
    for(int i = 0; i < N; i++){
      m[i] = sc.nextInt();
    }
    int max = 0; //作れる最大個数
    
    //全ドーナツを1個ずつ作ったときの、残りの粉の量を調べる
    //ついでに一番必要な粉の量が少ないドーナツも調べる
    int all1 = 0;
    int min = X;
    for(int i=0; i<N; i++){
      all1 += m[i];
      if( m[i] < min) min = m[i];
    }
    X = X - all1;
    
    //残った粉で何個作れるかを調べる
    int count = N;
    while(X - min >= 0){
    	count++;
      X -= min;
    }
    
    System.out.println(count);
    
  }
}




Measured memory_bytes: 21716
#include <iostream>
#include <numeric>

using namespace std;

typedef long long ll;

ll k;

ll solve(ll a, ll t = 2) {
    if (!t) return a;
    ll ans = 0;
    for (int i = 1; i <= k; ++i) ans += solve(gcd(a, i), t - 1);
    return ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin >> k;
    ll ans = 0;
    for (ll i = 1; i <= k; ++i) ans += solve(i);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3668
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  [n,l] <- getl $ wrds toInt
  solve <$> replicateM n getLine >>= putStrLn

solve :: [String] -> String
solve = concat . sort

toInt :: String -> Int
toInt = read

wrds :: (String -> a) -> String -> [a]
wrds f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine


Measured memory_bytes: 1404
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define re return
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
int a,b;
int main() { 
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
  cin>>a>>b;
  a=a*3+b;
  cout<<a/2<<endl;
    return 0; 
}

Measured memory_bytes: 256
x, y = map(int, input().split())
a = [4, 6, 9, 11]
b = 0
c = 0
if x == 2 or y == 2:
    print("No")
else:
    if x in a:
        b = 1
    if y in a:
        c = 1
    if (b + c) % 2 == 0:
        print("Yes")
    else:
        print("No")

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

int main()
{
    int N, counT = 0;
    cin >> N;

    char str[N];
    scanf("%s", &str);

    for(int i=0; i<N-2; i++)
    {
        if(str[i]=='A' && str[i+1]=='B' && str[i+2]=='C')
        {
            counT++;
            i += 2;
        }
    }

    cout << counT;

    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
#define INF 1e9
typedef long long ll;

int main(void){
  int N;cin >> N;
  ll A[N];
  int i;REP(i,N){
    ll x;cin >> x;
    A[i] = x-(i+1);
  }
  sort(A,A+N);
  ll res = 0;
  REP(i,N){
    int b = A[N/2];
    res += abs(A[i] -b);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 1792
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

ll n;
int ans;

void dfs(bool f1=0,bool f2=0,bool f3=0,ll num=0){
  if(num>n) return;
  if(f1&&f2&&f3) ans++;
  dfs(1,f2,f3,10*num+7);
  dfs(f1,1,f3,10*num+5);
  dfs(f1,f2,1,10*num+3);
}

int main(){
  ans=0;
  cin >> n;
  dfs();
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std ;
 
#define pb(n) push_back(n)
#define fi first
#define se second
#define X real()
#define Y imag()

#define value(x,y,w,h) (x >= 0 && x < w && y >= 0 && y < h)

#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
 
#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))
 
typedef long long ll ;
typedef deque<int> di ;
typedef deque<ll> dl ;
typedef map<string,int> dict;
typedef complex<double> comd;
typedef pair<int,int> pii;
 
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};
int res;
int n,s;
void solve(int a,int b,int c){
    if(b > n || a > s) return;
    if(a == s && b == n){
        ++res;
        return;
    }
    REP(i,c+1,10){
            solve(a+i,b+1,i);
    }
    return ;
}

int main(){
    while(cin>> n >> s){
        if( n + s == 0) break;
        res = 0;
        if(s <= 55){
            rep(i,10){
                solve(i,1,i);
            }
        }
        cout << res << endl;
    }

    return 0;
}

Measured memory_bytes: 3080
#include<stdio.h>
#include<string.h>
int main(){
char a[1001][33];
int b[1001],i,j,k=0,l=1,thi=0,ans,ans1=0,c=0,m;
for(i=0;i<1000;i++){
b[i]=0;
}
while(scanf("%c",&a[k][0])!=EOF){
while(1){
scanf("%c",&a[k][l]);
if(a[k][l]==' ' || a[k][l]=='\0'){
if(thi<l){
thi=l;
ans=k;
}
k++;
break;
}
l++;
}
l=1;
}
for(i=0;i<k;i++){
for(j=0;j<k;j++){
if(strcmp(a[i],a[j])==0){
c++;
}
}
if(c>ans1){
ans1=c;
m=i;
}
c=0;
}
printf("%s",a[m]);
for(i=0;i<thi;i++){
printf("%c",a[ans][i]);
}
printf("\n");
return 0;
}


Measured memory_bytes: 1932
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		long a=sc.nextLong(), b=sc.nextLong(), x=sc.nextLong();
		long count = b / x - a / x;
		if(a % x == 0) {
			count++;
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 22100
(let ((n (read)))
  (loop :named main
        :for x :from 1 :to 9
        :if (and (= (mod n x) 0) (<= 1 (/ n x) 9))
        :do (progn
              (format t "Yes~%")
              (return-from main))
        :finally (format t "No~%")))


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

#define MAX 10001
#define NIL -1

int primes[MAX];
int N;
int isDisc = NIL;

bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}

int main()
{

    while(std::scanf("%d", &N) != EOF) {

        //if we filled primes array before until N, skip the first loop
        int start = (isDisc == NIL) ? 1 : isDisc;
        for (int i = start; i <= N; i++) {
            if (isPrime(i) == true) { primes[i] = i; }
            else { primes[i] = 0; }
        }
        if (N > isDisc) { isDisc = N; }


        int cnt = 0;

        for (int i = 1; i <= N/2; i++) {
            if (primes[i] != 0 && primes[N+1-i] != 0) cnt++;
        }
        cnt *= 2;

        if (N % 2 != 0 && primes[N/2 + 1] != 0){ cnt++; }

        std::cout << cnt << std::endl;
    }
    return 0;
}



Measured memory_bytes: 3176
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections

n = int(input())
a = sorted(list(map(int,input().split())))
x = [0]*100002
for i in range(n):
    x[a[i]]+=1
ans = 0
for i in range(100000):
    c = x[i] + x[i+1] + x[i+2]
    ans = max(ans,c)
print(ans)

Measured memory_bytes: 14320
#include<cstdio>
#include<cstdlib>
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>

typedef long long ll;
const int Max = 1e5 + 5;
using namespace std;

int main(){
	int i, j, n, m, k;
	ll ans;
	while(~scanf("%d %d", &n, &k)){
		int a[Max], b[Max];
		m = 0;
		for(i = 0; i < n; i++) scanf("%d", &a[i]);
		sort(a, a + n);
		for(i = 0; i <= n - k; i++)
			b[m++] = a[i + k - 1] - a[i];
		sort(b, b + m);
		cout << b[0] << endl;
	}
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,j) for(int i=0;i<j;i++)
#define REP(i,j,z) for(int i=j;i<z;i++)
int main()
{
	ll N;
	ll cnt=0;
	ll num=0;
	ll flag=false;
	cin>>N;
	vector<ll> P(N);
	rep(i,N) cin>>P[i];
	rep(i,N){
		if(P[i]==i+1){
			if(flag) flag^=1;
			else cnt++,flag^=1;
		}else flag=0;
	}
	cout<<cnt<<endl;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int T[100];
int H[100];
int sumT,sumH;
int m,n;
int main(){
  while(cin >> n >> m && n+m != 0){
    sumT = sumH = 0;
    for(int i = 0;i < n;i++){
      cin >> T[i];
      sumT += T[i];
    }
    for(int i = 0;i < m;i++){
      cin >> H[i];
      sumH += H[i];
    }
    bool isfind = false;
    for(int i = 0;i < n && !isfind;i++){
      for(int j = 0;j < m && !isfind;j++){
	if(sumH-sumT == (H[j] - T[i])*2){
	  cout << T[i] << ' ' << H[j] << endl;
	  isfind = true;
	}
      }
    }
    if(isfind == false){
      cout << -1 << endl;
    }
  }
}

Measured memory_bytes: 0
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Reader sc = new Reader();
        PrintWriter pw = new PrintWriter(System.out);
        
        try {
            long x = sc.nextLong();
            long k = sc.nextLong();
            long d = sc.nextLong();

            if(x < 0) x = -x;

            long steps = x/d;
            if(steps >= k) {
                pw.println(x - k*d);
            }
            else {
                long a1 = x%d;
                long a2 = x%d-d;
                k -= steps;
                long ans = 0;
                if(k%2 == 0) {
                    ans = a1;
                }
                else {
                    ans = a2;
                }
                ans = Math.abs(ans);
                pw.println(ans);
            }
        }
        finally {
            pw.flush();
            pw.close();
        }
    }
    
    static class Reader {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while(!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                }
                catch(IOException io) {
                    io.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}


Measured memory_bytes: 32920
#include <cstdio>
#include <iostream>
#include <algorithm>
typedef long long ll;
using namespace std;
const int maxn=1e5+100;
inline ll read()
{
	ll f=1,k=0;char c=getchar();
	while (c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
	while (c>='0'&&c<='9')k=k*10+c-'0',c=getchar();
	return k*f;
}
int a[maxn];
const int up=1e5;
int cnt[maxn][2];
int mx[20],val[20];
int MX[20],VAL[20];
signed main()
{
	int n=read();
	for (int i=1;i<=n;i++)cnt[a[i]=read()][i&1]++;
	for (int i=1;i<=up;i++)
	{
		if (cnt[i][0]>=mx[0])mx[1]=mx[0],val[1]=val[0],mx[0]=cnt[i][0],val[0]=i;
		else if (cnt[i][0]>=mx[1])mx[1]=cnt[i][0],val[1]=i;
		
		if (cnt[i][1]>=MX[0])MX[1]=MX[0],VAL[1]=VAL[0],MX[0]=cnt[i][1],VAL[0]=i;
		else if (cnt[i][0]>=MX[1])MX[1]=cnt[i][0],VAL[1]=i;
	}
	if (VAL[0]!=val[0])
	{
		printf("%d\n",n-mx[0]-MX[0]);
	}
	else printf("%d\n",min(n-MX[0]-mx[1],n-MX[1]-mx[0]));
//	cout << mx << " "<<mx2<<endl;
// 	printf("%d\n",n-mx-mx2);
}


Measured memory_bytes: 1408
/*Remember: The Struggle is Important*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

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

#define     int          long long int
#define     ld           long double
#define     fast()       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)       x.begin(),x.end()
#define     mem(a,b)     memset(a,b,sizeof(a))
#define     gcd(a,b)     (__gcd((a),(b)))
#define     lcm(a,b)     (((a)*(b))/gcd((a),(b)))
#define     pb           push_back
#define     ins          insert
#define     pii          pair<int,int>
#define     F            first
#define     S            second
#define     show(x)      for(auto c:x)cout<<c<<" ";cout<<"\n";
#define     show2(x)     for(auto c:x)cout<<c.F<<" "<<c.S<<"\n";

const int inf=1e18,M=1e9+7;
const int N=2e4+10;

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

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

    vector<int> dp(N,inf);
    dp[0]=0;

    int ans=inf;
    for(int i=1;i<N;++i)
    {
        for(int j=0;j<n;++j)
        {
            if(i-a[j]>=0)
                dp[i]=min(dp[i],dp[i-a[j]]+b[j]);
        }

        if(i>=h)
            ans=min(ans,dp[i]);
    }

    cout<<ans;
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
const int MOD=998244353;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;cin >> n >> k;
    int ans=0;
    for(int i=0;i<n;i++){
        int x;cin >> x;
        ans+=2*min(x,k-x);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
//#include "pch.h"
#include <iostream>
#include <math.h>

using namespace std;

int n;
long long a[100001];
long long L[100001];
long long R[100001];

//*********************************************************
// 最大公約数（Greatest Common Divisor）を返す。
// 引数に０がある場合は０を返す。
//*********************************************************
long long gcd(long long m, long long n)
{
	// 引数に０がある場合はmax(m,n)を返す
	if ((0 == m) || (0 == n))
		return (m + n);

	// ユークリッドの方法
	while (m*n != 0)
	{
		if (m > n) m = m % n;
		else         n = n % m;
	}
	if (m < n) {
		return n;
	}
	else {
		return m;
	}

}//gcd

int main() {

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

	L[0] = 0;
	R[0] = 0;

	for (int i = 1; i <= n; i++) {
		L[i] = gcd(L[i - 1], a[i]);
		R[i] = gcd(R[i - 1], a[n - i + 1]);
	}

	long long wkans = 0;
	for (int i = 1; i <= n; i++) {
		long long wk = gcd(L[i - 1], R[n - i]);
		if (wk > wkans)wkans = wk;
	}

	cout << wkans << endl;
    


//	system("pause");



	


}

Measured memory_bytes: 2560
def main():
    H, W = map(int, input().split())
    A = [input() for _ in range(H)]
    ansr = [None for _ in range(H)]
    ansb = [None for _ in range(H)]
    for i in range(0, H):
        if i % 2 == 0:
            ansr[i] = ["#"] * (W-1) + ["."]
            ansb[i] = ["."] * (W-1) + ["#"]
        else:
            ansr[i] = ["#"] + ["."] * (W-1)
            ansb[i] = ["."] + ["#"] * (W-1)
    for i in range(H):
        for j in range(W):
            if A[i][j] == "#":
                ansr[i][j] = "#"
                ansb[i][j] = "#"
    for i in range(H):
        print("".join(ansr[i]))
    print()
    for i in range(H):
        print("".join(ansb[i]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 46320
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define INF 100000000000
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}


int main()
{
    int n, x, d;
    cin >> n >> d >> x;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    int ans = x;
    rep(i,n) {
        if (a[i] == 1) {
            ans += d/a[i];
        } else {
            ans += 1 + floor((d-1)/a[i]);
        }
    }
        
    cout << ans << endl;

    return 0;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;


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

    double w,h,x,y; cin>>w>>h>>x>>y;
    if(x==w/2.0 && y==h/2.0){
        cout<<w*h/2.0<<' '<<1<<endl;
    }
    else cout<<w*h/2<<' '<<0<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
int H,W,h,w;
int ans[500][500];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>H>>W>>h>>w;
    if(H%h==0&&W%w==0){
        cout <<"No"<<"\n";
        return 0;
    }
    else if(H%h==0){
        rep(i,0,H){
            rep(j,0,W){
                if(i%h==0&&j%w==0) ans[i][j]=1000;
                if(i%h==0&&j%w==W%w) ans[i][j]=-1001;
            }
        }
    }
    else if(W%w==0){
        rep(i,0,H){
            rep(j,0,W){
                if(i%h==0&&j%w==0) ans[i][j]=1000;
                if(j%w==0&&i%h==H%h) ans[i][j]=-1001;
            }
        }
    }
    else{
        rep(i,0,H){
            rep(j,0,W){
                if(i%h==0&&j%w==0) ans[i][j]=1000;
                if(i%h==0&&j%w==W%w) ans[i][j]=1000;
                if(j%w==0&&i%h==H%h) ans[i][j]=1000;
                if(j%w==W%w&&i%h==H%h) ans[i][j]=-3001;
            }
        }
    }
    cout <<"Yes"<<"\n";
    rep(i,0,H){
        rep(j,0,W){
            if(j==W-1) cout <<ans[i][j]<<"\n";
            else cout <<ans[i][j]<<" ";
        }
    }
}

Measured memory_bytes: 2560