akhauriyash/Code-Regression huggingface dataset:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

N = I()

ans = 0
for i in range(1,N):
    if i!=N-i and i<=N//2:
        ans += 1
print(ans)

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

#define pb push_back

#define ll long long

#define ft first

#define sd second

using namespace std;

const int N = 5050 ;

bool used[N];

ll z , r , w ;

int main(){

    string s , t ;
    cin >>s >> t ;
    t=t+s;
    for(int i = 0 ; i < t.size(); i ++ ){
        cout<<t[i];
    }

}


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

using namespace std;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    if (abs(a - b) % 2 == 0) {
        cout << "Alice" << endl;
    } else {
        cout << "Borys" << endl;
    }
    return 0;
}


Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int N;
  cin >> N;
  
  vector<string> W(N);
  for (int i = 0; i < N; i++) {
    cin >> W[i];
    for (int j = 0; j < i; j++) {
      if (W[i] == W[j]) {
        cout << "No" << endl;
        return 0;
      }
    }
    if (i != 0 && W[i-1].back() != W[i].front()) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  
  return 0;
}
  

Measured memory_bytes: 256
/*      ###########################
        #  Author : Pranay Garg   #
        #  College : SGSITS       #
        ###########################
*/      
#include<bits/stdc++.h>
#define ll long long int
#define ironman ios_base::sync_with_stdio(false);cin.tie(NULL);
#define MOD 1000000007
#define endl '\n'
using namespace std;
void fastio()
{
    ironman
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        freopen("error.txt","w",stderr);
    #endif
}
ll parent[100005];
ll find(ll a)
{
    std::vector<ll> v;
    while(parent[a]>0)
    {
        v.push_back(a);
        a = parent[a];
    }
    for(ll i=0;i<v.size();i++)
        parent[v[i]] = a;
    return a;
}
bool prime[100005];
void SieveOfEratosthenes(int n) 
{  
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
}  
void union1(ll a, ll b)
{
    a = find(a);
    b = find(b);
    if(a!=b)
    {
        parent[a] = min(parent[a],parent[b]);
        parent[b] = a;
    }
}  
ll n,k;
ll arr[100002];
ll dp[100002];
int main()
{
    memset(dp,-1,sizeof(dp));
    //fastio();
    //ll n;
    cin >> n >> k;
//    ll arr[n];
    for(ll i=0;i<n;i++)
        cin >> arr[i];
    dp[0] = 0;
    for(ll i=1;i<n;i++)
    {
        if(i-1>=0)
            dp[i] = dp[i-1]+abs(arr[i]-arr[i-1]);
        for(ll j=i-2;j>=0 && i-j<=k;j--)
        {
            dp[i] = min(dp[i],dp[j]+abs(arr[i]-arr[j]));
        }
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1792
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

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

	cin >> N >> K;
	if (N == 0) {
		cout << "" << endl;
		return 0;
	}
	vector<string>s(N + 1);
	for (auto &i : s)cin >> i;
	vector<bitset<1024 * 1024>>bs(N + 1);
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j < 1 << i; j++) {
			if (s[i][j] == '1')bs[i][j].flip();
		}
	}
	vector<vector<vector<int>>>num(N + 1);
	for (int i = 0; i <= N; i++) {
		num[i].resize(1 << i, vector<int>(1 << (N + 2 - i), 0));
	}
	for (int i = 0; i < 1 << N; i++) {
		if (bs[N].test(i)) {
			num[N][i][1] = 1;
			if (i & 1)num[N][i][3] = 1;
			else num[N][i][2] = 1;
		}
	}
	vector<int>box(1 << (N+2));
	for (int i = 0; i < (N+2); i++) {
		box[1 << i]++;
	}
	for (int i = 1; i < 1 << (N+2); i++) {
		box[i] += box[i - 1];
	}

	for (int i = N - 1; i > 0; i--) {
		for (int j = 0; j < num[i].size(); j++) {
			if (bs[i].test(j)) {
				num[i][j][1]++;
				if (j & 1)num[i][j][3]++;
				else num[i][j][2]++;
			}
			
			for (int k = 1; k < num[i+1][0].size(); k++) {
				num[i][j][k] += num[i + 1][j * 2][k];
				num[i][j][k] += num[i + 1][j * 2 + 1][k];
				
				if (j & 1) {
					int dif = box[k] - 1;
					int nxk = k;
					nxk += 1 << (dif + 1);

					num[i][j][nxk] += num[i + 1][j * 2][k];
					num[i][j][nxk] += num[i + 1][j * 2 + 1][k];
					
					if (num[i + 1][j * 2].size() > nxk&&nxk > 1) {
						num[i][j][nxk] -= num[i + 1][j * 2][nxk];
						num[i][j][nxk] -= num[i + 1][j * 2 + 1][nxk];
					}
					
				}
				
				else {
					int dif = box[k] - 1;
					int nxk = k;
					nxk -= 1 << dif;
					nxk += 1 << (dif + 1);
					//cout << k << " " << nxk << endl;
					//if(num[i][j].size()<=nxk)assert(0);
					num[i][j][nxk] += num[i + 1][j * 2][k];
					num[i][j][nxk] += num[i + 1][j * 2 + 1][k];
					if (num[i + 1][j * 2].size() > nxk&&nxk > 1) {
						num[i][j][nxk] -= num[i + 1][j * 2][nxk];
						num[i][j][nxk] -= num[i + 1][j * 2 + 1][nxk];
					}
				}
				
			}
			
		}
	}
	string ans;
	for (int j = 1; j < 1 << (N + 1); j++) {
		if (num[1][0][j] + num[1][1][j] < K)continue;
		int dig = box[j] - 1;
		if (dig < ans.size())continue;
		string st(dig, '0');
		for (int k = 0; k < dig; k++) {
			if ((j >> k) & 1)st[k] = '1';
		}
		reverse(st.begin(), st.end());
		if (st.size() > ans.size())ans = st;
	}
	cout << ans << endl;
}


Measured memory_bytes: 449404
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
using static AtCoder.Program;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            new ABC131().SolveC(new ConsoleInput(Console.In, ' '));
        }

        //ユークリッドの互助法 最大公約数
        public static long Gcd(long a, long b)
        {
            if (a < b)
                // 引数を入替えて自分を呼び出す
                return Gcd(b, a);
            while (b != 0)
            {
                var remainder = a % b;
                a = b;
                b = remainder;
            }
            return a;
        }

        // 最小公倍数
        public static long Lcm(long a, long b)
        {
            return a * b / Gcd(a, b);
        }

    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }

    }
  class ABC131
  {
  	public void SolveC(ConsoleInput cin)
        {
            var a = cin.ReadLong;
            var b = cin.ReadLong;
            var c = cin.ReadLong;
            var d = cin.ReadLong;
            var multC = (b / c) - ((a - 1) / c);
            var multD = (b / d) - ((a - 1) / d);
            var multCandD = (b / Lcm(c, d)) - ((a - 1) / Lcm(c, d));
            WriteLine((b + 1 - a) - (multC + multD - multCandD));
            ReadLine();

        }
  }
}

Measured memory_bytes: 13268
class UnionFind():
  def __init__(self,size):
    self.table=[-1for _ in range(size)]
  def root(self,x):
    while self.table[x]>=0:
      x=self.table[x]
    return x
  def unite(self,x,y):
    s1=self.root(x)
    s2=self.root(y)
    if s1!=s2:
      if self.table[s1]!=self.table[s2]:
        if self.table[s1]<self.table[s2]:
          self.table[s2]=s1
        else:
          self.table[s1]=s2
      else:
        self.table[s1]-=1
        self.table[s2]=s1
    return
  def same(self,x,y):
    return self.root(x)==self.root(y)
I=lambda:list(map(int,input().split()))
n,m=I()
p=I()
u=UnionFind(n)
for _ in range(m):
  a,b=I()
  u.unite(a-1,b-1)
print(sum(u.same(i,j-1)for i,j in zip(range(n),p)))

Measured memory_bytes: 14452
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
 int a;
 cin >> a;
 if (a<1200) cout << "ABC" << endl;
 else cout << "ARC" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18

ll mod = 1e9+7;
  
int main() {
	// 入力
	string S;cin>>S;
    
	// 解法
    ll ans[S.size()] = {0};
    ll tmp_coord = 0;
    ll L_count = 0;
    ll R_count = 0;
    REP(i,S.size()){
        if (i==0) R_count++;
        else if (S.substr(i-1, 2)=="RR"){
            R_count++;
        }
        else if (i==S.size()-1 & S.substr(i-1, 2)=="LL"){
            L_count++;
            ans[i-L_count] += (L_count)/2;
            ans[i-L_count+1] += (L_count+1)/2;
            // REP(i,S.size()) printf("%lld ", ans[i]);
            // printf("\n");
        }
        else if (i==S.size()-1 & S.substr(i-1, 2)=="RL"){
            ans[i-1] += (R_count+1)/2;
            ans[i] += (R_count)/2;
            L_count = 1;
            ans[i-L_count] += (L_count)/2;
            ans[i-L_count+1] += (L_count+1)/2;
            // REP(i,S.size()) printf("%lld ", ans[i]);
            // printf("\n");
        }
        else if (S.substr(i-1, 2)=="RL"){
            ans[i-1] += (R_count+1)/2;
            ans[i] += (R_count)/2;
            R_count = 0;
            L_count = 1;
            // REP(i,S.size()) printf("%lld ", ans[i]);
            // printf("\n");
        }
        else if (S.substr(i-1, 2)=="LR"){
            ans[i-L_count-1] += (L_count)/2;
            ans[i-L_count] += (L_count+1)/2;
            R_count = 1;
            L_count = 0;
            // REP(i,S.size()) printf("%lld ", ans[i]);
            // printf("\n");
        }
        else if (S.substr(i-1, 2)=="LL"){
            L_count++;
        }

    }

	//出力
    REP(i,S.size()) printf("%lld ", ans[i]);
    printf("\n");
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
const ll nmax=8;
bool graph[nmax][nmax];

ll dfs(ll v,ll n,bool visited[nmax]){
    bool ok=true;
    for(ll i=0;i<n;i++){
        if(visited[i]==false){
            ok=false;
        }
    }
    if(ok) return 1;
    ll ret=0;
    for(ll i=0;i<n;i++){
        if(graph[v][i]==false) continue;
        if(visited[i]) continue;
        visited[i]=true;
        ret+=dfs(i,n,visited);
        visited[i]=false;
    }
    return ret;
}
int main() {
    ll n,m;
    cin >> n >> m;
    for(ll i=0;i<m;i++){
        ll a,b;
        cin >> a >> b;
        a--;b--;
        graph[a][b]=graph[b][a]=true;
    }
    bool visited[nmax];
    for(ll i=0;i<n;i++) visited[i]=false;
    visited[0]=true;
    cout << dfs(0,n,visited) << endl;
}

Measured memory_bytes: 3600
object Main extends App {
  val in = io.Source.stdin.getLines.toIndexedSeq.head
  val len = in.length
  val ret = (0 to len-3).foldLeft(Int.MaxValue){ (a,i) =>
    val num:Int = ("" + in(i) + in(i+1) + in(i+2)).toInt
    val diff = Math.abs(num - 753)
    Math.min(a, diff)
  }
  println(ret)
}


Measured memory_bytes: 25504
import java.util.Scanner;

public class Main {


    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {
    	Scanner sc=new Scanner(System.in);

    	int a=sc.nextInt();
    	int b=sc.nextInt();

    	int p=a*b;

    	if(p%2==0) {
    		System.out.println("Even");
    	}else {
    		System.out.println("Odd");
    	}


    }

}







Measured memory_bytes: 21716
import java.util.Random;
import java.util.Scanner;

public class Main {
    static int d = 365;
    static int[] c = new int[26];
    static int[][] s = new int[d][26];
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Random random = new Random();
        sc.nextInt();
        for (int i=0;i<26;i++){
            c[i]=sc.nextInt();
        }
        for (int i=0;i<d;i++){
            for (int j=0;j<26;j++){
                s[i][j]=sc.nextInt();
            }
        }
        int[] contest = new int[d];
        int count = 100000;
        for (int i=0;i<d;i++)contest[i]=random.nextInt(26);
        for (int i=0;i<count;i++){
            int[] instance = contest.clone();
            int times = random.nextInt(6)+6;
            int[] choose = new int[times];
            for (int j=0;j<times;j++)choose[j]=random.nextInt(d);
            for (int j=0;j<times;j++)instance[choose[j]]=random.nextInt(26);
            if (function(contest)<function(instance))contest=instance;
        }
        for (int i=0;i<d;i++)System.out.println(contest[i]+1);
    }
    static long function(int[] contest){
        long satisfaction = 0;
        int[] interval = new int[26];
        for (int i=0;i<d;i++){
            satisfaction+=s[i][contest[i]];
            for (int j=0;j<26;j++)interval[j]++;
            interval[contest[i]]=0;
            for (int j=0;j<26;j++)satisfaction-=c[j]*interval[j];
        }
        return  satisfaction;
    }
}


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

#define int long long
#define ld long double
#define pii pair<int,int>
#define pb push_back
#define pf push_front
#define pof pop_front
#define mp make_pair
#define x first
#define y second

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

	char a;
	cin>>a;
	if (a<='Z' && a>='A')
		cout<<"A"<<endl;
	else
		cout<<"a"<<endl;
	return 0;
}

Measured memory_bytes: 3528
package main

import "fmt"

func getSum(nums []int) (sum int) {
	sum = 0
	for i := 0; i < len(nums); i++ {
		sum += nums[i]
	}
	return
}

func main() {
	var N int
	fmt.Scan(&N)
	T := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&T[i])
	}
	total := getSum(T)
	var M int
	fmt.Scan(&M)
	diffs := make([]int, M)
	for i := 0; i < M; i++ {
		var p, x int
		fmt.Scan(&p, &x)
		diffs[i] = x - T[p-1]
	}
	for i := 0; i < M; i++ {
		fmt.Println(total + diffs[i])
	}
}


Measured memory_bytes: 512
#include<iostream>
#include<string>

using namespace std;

int main(){
   int N;
   string temp;
   int AC=0,WA=0,TLE=0,RE=0;
   cin >> N;
   for( int i=0; i<N ;i++){
      cin >> temp;
      if(temp=="AC"){
         AC++;
      }
      if(temp=="WA"){
         WA++;
      }
      if(temp=="TLE"){
         TLE++;
      }
      if(temp=="RE"){
         RE++;
      }
   }
   cout << "AC x " << AC << endl;
   cout << "WA x " << WA << endl;
   cout << "TLE x " << TLE << endl;
   cout << "RE x " << RE << endl;
   return 0;
}


Measured memory_bytes: 3236
from bisect import bisect_left

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, n + 1):
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

l = primes(100000)
l.append(100003)
print(l[bisect_left(l, int(input()))])

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

S = input()[:-1]
T = input()[:-1]
acc0, acc1 = [0]*(len(S)+1), [0]*(len(S)+1)

for i in range(len(S)):
    acc0[i+1] = acc0[i]+(1 if S[i]=='A' else 0)
    acc1[i+1] = acc1[i]+(1 if S[i]=='B' else 0)

acc2, acc3 = [0]*(len(T)+1), [0]*(len(T)+1)

for i in range(len(T)):
    acc2[i+1] = acc2[i]+(1 if T[i]=='A' else 0)
    acc3[i+1] = acc3[i]+(1 if T[i]=='B' else 0)

q = int(input())

for _ in range(q):
    a, b, c, d = map(int, input().split())
    A_diff = acc0[b]-acc0[a-1]-(acc2[d]-acc2[c-1])
    B_diff = acc1[b]-acc1[a-1]-(acc3[d]-acc3[c-1])
    
    if A_diff%3==B_diff%3:
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 56024
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>

using namespace std;
typedef long long ll;

int n,m,q;
int li,ri,pi,qi;
vector<vector<int>> vt;

int main(){

	scanf("%d %d %d",&n,&m,&q);
vt.resize(n+1);
for(int i =1 ; i <= n ; i++){
	vt[i].resize(n+1);
}

	for(int i = 0; i < m ; i++){
		scanf("%d %d",&li,&ri);
		vt[li][ri]++;
	}

	for(int i = 1; i<= n ;i++){
		for(int j = 1; j <= n ; j++){
			vt[i][j] += vt[i][j-1];
		}
	}

	for(int i = 0 ; i < q;  i++){
		scanf("%d %d",&pi,&qi);
		int cnt = 0;
		for(int j = pi ; j <= qi ; j++){
			cnt += (vt[j][qi] - vt[j][pi-1]);
		}
		printf("%d\n",cnt);
	}


}

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

#define var auto
#define long long long
#define ll long
#define Max std::max
#define Min std::min
#define Abs std::abs

void Solve();

using namespace std;

int main() {
    while (true) {
        Solve();
    }
}

void Solve() {
    int n, r;
    cin >> n >> r;
    if (n == 0 && r == 0) exit(0);
    int ball = r;
    vector<int> hands(n);
    for (int i = 0; true; i = (i + 1) % n) {
        if (ball == 0){
            ball = hands[i];
            hands[i] = 0;
        }
        else{
            hands[i] += 1;
            ball -= 1;
            if (hands[i] == r){
                cout << i << endl;
                return;
            }
        }
    }
}



Measured memory_bytes: 3036
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define P pair<ll,ll>
#define Graph vector<vector<P>>
#define fi first
#define se second
constexpr ll mod=1000000007;
constexpr ll INF=(1ll<<60);
constexpr double pi=3.14159265358979323846;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<typename T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}

int main(){
    string s;cin>>s;
    vector<string> vec={"SUN","MON","TUE","WED","THU","FRI","SAT","SUN"};

    rep(i,7){
        if(s==vec[i]) cout<<7-i<<endl;
    }  

    return 0;
}

Measured memory_bytes: 3568
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
    int a,b,i,k;
    while(scanf("%d%d",&a,&b)==2)
    {
        if(a<=b)
            printf("%d\n",a);
        else
        {
            printf("%d\n",a-1);
        }
    }
    return 0;
}


Measured memory_bytes: 128
from collections import defaultdict


# 累乗
def power(a, n, p):
    bi = str(format(n, "b"))  # 2進表現に
    res = 1
    for i in range(len(bi)):
        res = (res * res) % p
        if bi[i] == "1":
            res = (res * a) % p
    return res


N = int(input())
D = list(map(int, input().split()))
MOD = 998244353

if D[0] != 0 or 0 in D[1:]:
    print(0)
    exit(0)

cnt = defaultdict(int)
for d in D:
    cnt[d] += 1

ans = 1
for i in range(1, max(D) + 1):
    if cnt.get(i) is None:
        print(0)
        exit(0)
    num = pow(cnt[i - 1], cnt[i], MOD)
    ans = ans * num % MOD
print(ans)


Measured memory_bytes: 62892
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll N, K, T, W, H, M, C;

const int MAX = 5100000;
const int MOD = 1e9 + 7;

const double PI=3.14159265358979323846;


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

vector<double> cx, cy, c;
 ll MM = 1e12;

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

std::vector<int> Eratosthenes(int n ){
    std::vector<bool> is_prime( n + 1 );
    for( int i = 0; i <= n; i++ ) is_prime[ i ] = true;
    std::vector<int> P;
    for( int i = 2; i <= n; i++ ){
        if( is_prime[ i ] ){
            for( int j = 2 * i; j <= n; j += i ){
                is_prime[ j ] = false;
            }
            P.emplace_back( i );
        }
    }
    return P;
}

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

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



int main(){
    cin >> N;
    vector<ll> v(N);
    REP(i,N) cin >> v[i];
    vector<ll> dp1(N+1), dp2(N+1);

    dp1[0] = 0; dp2[0] = 0;

    for(int i = 1; i < N+1; ++i){
        dp1[i] = gcd(dp1[i-1], v[i-1]);
        dp2[i] = gcd(dp2[i-1], v[N-i]);
        //cout << dp1[i] << " " << dp2[i] << "\n";
    }
    ll ans = 1;
    for(int i = 0; i < N; ++i){
        ans = max(ans, gcd(dp1[i] , dp2[N-i-1]));
    }
    cout << ans ;
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int mod = 1E9 + 7;
const int inf = 1 << 29;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  unsigned long long ans = 1;
  unsigned long long tmp;
  bool flag = false;
  rep(i, n) {
    tmp = ans;
    ans *= a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (tmp != (ans / a[i])) {
      flag = true;
    }
    if (ans > 1000000000000000000LL) {
      flag = true;
    }
  }
  if (flag) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 4032
#include<iostream>
#include<algorithm>
#include<cassert>
#include<vector>
#include<fstream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<queue>
#include<map>

using namespace std;
#define REP(m,n) for(int i=m;i<n;++i)
#define REPj(m,n) for(int j=m;j<n;++j)
#define INF 10000000000000000
#define MOD 1000000007
#define ll long long
#define mp make_pair

int main() {
	int n;
	cin >> n;
	int ans = 0;
	REP(0, n) {
		int a, b;
		cin >> a >> b;
		ans += b - a + 1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import collections
import math
n, m = map(int, input().split())
a = input().split()
a = [int(m) for m in a]
b = [0]
t = 0
for i in range(n):
    t += a[i]
    b.append(t)
mod = m
c = []
for i in range(n + 1):
    c.append(b[i] % mod)

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
ans = 0
col = collections.Counter(c)
for i in col:
    if col[i] != 1:
        ans += comb(col[i], 2)
print(ans)

Measured memory_bytes: 18768
#include<stdio.h>
int main(){
	int x1,x2,x3,x4,y1,y2,y3,y4;
	scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
	
	int dx,dy;
	dx = x2 - x1;
	dy = y2 - y1;
	
	x3 = x2 - dy;
	y3 = y2 + dx;
	x4 = x1 - dy;
	y4 = y1 + dx;
	
	printf("%d %d %d %d",x3,y3,x4,y4);
	
}

Measured memory_bytes: 128
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Aizu
{
	class Program
	{
		static void Main(string[] args)
		{
			var answers = new List<int>();

			while (true)
			{
				var n = int.Parse(ReadLine());
				if(n == 0)
				{
					break;
				}

				var blocks = ReadLine().Split(' ').Select(value => int.Parse(value)).ToArray();

				var maxima = new int[n, n];
				for(var i = 0; i < n; i++)
				{
					for(var j = 0; j < n; j++)
					{
						maxima[i, j] = -1;
					}
				}

				answers.Add(Dp(maxima, 0, n - 1, blocks));
			}

			answers.ForEach(value => WriteLine(value));
		}

		private static int Dp(int[,] maxima, int left, int right, int[] blocks)
		{
			if(maxima[left, right] != -1)
			{
				return maxima[left, right];
			}
			if(right - left < 1)
			{
				return maxima[left, right] = 0;
			}

			var max = 0;

			if(Abs(blocks[left] - blocks[right]) <= 1 && Dp(maxima, left + 1, right - 1, blocks) == right - left - 1)
			{
				max = right - left + 1;
			}

			for(var i = left; i < right; i++)
			{
				max = Max(max, Dp(maxima, left, i, blocks) + Dp(maxima, i + 1, right, blocks));
			}

			return maxima[left, right] = max;
		}
	}
}



Measured memory_bytes: 31824
import sys
fin = sys.stdin.readline


N, K = [int(elem) for elem in fin().split()]
h_list = [int(fin()) for _ in range(N)]
h_list.sort()
min_dist = float('inf')
for i in range(N - K + 1):
    dist = h_list[i + K - 1] - h_list[i]
    min_dist = min(min_dist, dist)
print(min_dist)


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

ll gcd(ll a,ll b){
  while(b!=0){
    a%=b;
    swap(a,b);
  }
  return a;
}

ll kaizyou(ll N){
  ll num=1;
  for(ll i=1;i<=N;i++){
  num*=i;
  }
  return num;
}

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

 
int main(){
  int N;
  cin >> N;
  vector<int>X(N);
  rep(i,N){
    cin >> X.at(i);
  }
  int ans=1e9;
  int num=0;
  for(int i=1;i<=100;i++){
    num=0;
    rep(j,N){
      num+=pow(X.at(j)-i,2);
    }
    ans=min(ans,num);
  }
  cout << ans << endl;    
}
      
  
  
  

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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<char, int>;

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( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e18;
const int MOD = 1e9 + 7;

signed main(){
    int a[3];
    REP( i, 3 ) cin >> a[i];
    sort( a, a + 3 );

    int ans = 0;
    REP( i, 2 ){
        ans += a[i + 1] - a[i];
    }

    cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

std::random_device seed_gen;
std::mt19937 engine(seed_gen());
constexpr int prob = 26;
const double TL = 1.970;
// const double TL = 0.100;

vector<ll> c,l;
vector<vector<int>> s;
int d;

ll score(vector<int> &t) {
    ll sat = 0;
    rep (i, prob) l[i] = -1;
    rep (dy, d) {
        int k = t[dy];
        sat += s[dy][k];
        l[k] = dy + 1;
        rep (i, 26) sat -= c[i] * (dy - l[i]);
    }
    return sat;
}

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    clock_t start = clock(), end;
    cin >> d;
    c.resize(prob); l.resize(prob);
    s.resize(d); rep (i, s.size()) s[i].resize(prob);
    rep (i, c.size()) cin >> c[i];
    rep (i, s.size()) { rep (j, s[0].size()) { cin >> s[i][j]; }}

    vector<int> t(d), tmp;
    rep (i, d) t[i] = engine() % prob;
    tmp = t;
    ll max_score = -(ll)1e18;
    int count = 1, k;
    while (true) {
        // write here
        
        do {
            k = engine() % d;
            tmp[k] = engine() % prob;
        } while (tmp[k] == t[k]);
        if (chmax(max_score, score(tmp))) t = tmp;

        if (count % 100 == 0) {
            end = clock();
            if (static_cast<double>(end - start) / CLOCKS_PER_SEC > TL) break;
        }
        count++;
    }
    
    rep (i, t.size()) cout << t[i] + 1 << "\n";
    return 0;
}

Measured memory_bytes: 3744
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

typedef long long ll;
using namespace std;

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

  map<ll, ll> m;

  for (ll i = 0; i < n; i++) {
    ll t;
    cin >> t;

    // TODO
    auto itr = m.find(t);
    if (itr != m.end()) {
      // hasKey
      m.erase(itr);
    } else {
      m[t] = 1;
    }
  }

  cout << m.size() << endl;

  return 0;
}

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

#define mod 1000000007

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

using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;

int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
 
int main(void){
	
	int K;
    cin >> K;
    int ans = 0;

    rep(i, K){
        rep(j, K){
            rep(k, K){
                int a = gcd(i, j);
                ans += gcd(a, k);
            }
        }
    }

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

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;

  map<char, int> m;
  m['R'] = 0;
  m['G'] = 1;
  m['B'] = 2;

  vector<vector<int>> cnt(3, vector<int>(n, 0));
  rep(i, n) {
    if (i) rep(j, 3) cnt[j][i] = cnt[j][i - 1];
    cnt[m[s[i]]][i]++;
  }

  ll ans = 0;
  REP(i, 0, n) REP(j, i + 1, n) if (s[i] != s[j]) {
    if (j + 1 >= n) break;

    int idx = 3 - m[s[i]] - m[s[j]];
    ans += cnt[idx][n - 1] - cnt[idx][j];

    int k = j + (j - i);
    if (k < n && idx == m[s[k]]) ans--;
  }

  cout << ans << endl;
}


Measured memory_bytes: 3680
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

const INF=2<<40
const maxN=110
const maxV=100010
function main()
    n::Int,w::Int=parseMap(split(readline()))
    dp::Array{Int,2}=fill(INF,maxN,maxV) # 最大価値は10^3 x 100
    dp[1]=0
    for i in 1:n
        weight::Int,value::Int=parseMap(split(readline()))
        for j in 1:maxV
            if j-value>=1
                dp[i+1,j]=min(dp[i+1,j],dp[i,j-value]+weight)
            end
            dp[i+1,j]=min(dp[i+1,j],dp[i,j])
        end
    end
    for j in maxV:-1:1
        if dp[n+1,j]<=w
            println(j-1)
            break
        end
    end
end
main()

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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int di[] = {0, 1, 0, -1};
int dj[] = {1, 0, -1, 0};

int n;
vvi g;
vvi d;
void dfs(int i, int j){
    rep(k,4){
        int ni = i + di[k];
        int nj = j + dj[k];
        if(ni < 0 || n <= ni) continue;
        if(nj < 0 || n <= nj) continue;
        if(d[ni][nj] > d[i][j] + g[i][j]){
            d[ni][nj] = d[i][j] + g[i][j];
            dfs(ni, nj);
        }
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    cin >> n;
    g = vvi(n, vi(n));
    d = vvi(n, vi(n));
    vector<tuple<int,int>> P;
    rep(_,n*n){
        int p; cin >> p;
        p--;
        int i = p / n;
        int j = p % n;
        P.emplace_back(i, j);
    }

    rep(i,n) rep(j,n){
        g[i][j] = 1;
        d[i][j] = min({i,j,n-i-1,n-j-1});
    }
    int ans = 0;
    for(auto p : P){
        int i = get<0>(p);
        int j = get<1>(p);
        ans += d[i][j];
        g[i][j] = 0;
        dfs(i, j);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 26476
#include <iostream>
using namespace std;
int n;
int a[1000];
void output(){
    for(int i=0;i<n;i++){
        cout<<a[i];
        if(i+1<n){
            cout<<" ";
        }
    }
    cout<<endl;
}

int main() {
    //read
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    output();
    //solve
    for(int i=1;i<n;i++){
        int v = i;
        while(v>0&&a[v-1]>a[v]){
                int tmp = a[v];
                a[v]=a[v-1];
                a[v-1]=tmp;
                v--;
        }
        output();
    }
}

Measured memory_bytes: 1168
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        byte a = sc.nextByte();
        byte b = sc.nextByte();
        byte time = (byte)(a + b);
        if(time >= 24){
            time = (byte)(time - 24);
        }
        System.out.println(time);
    }
}

Measured memory_bytes: 25172
#include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 200000 + 5;
int n, x[N], y[N];
int mn = 1e9 + 10, mx = -1;

ll get(int s, int e, int v) {
	if (v <= s) return s - v;
	return v - e;
}

ll calc1() {
	int mx1 = -1, mx2 = -1, mn1 = 1e9 + 10, mn2 = 1e9 + 10;
	mx1 = mx, mn1 = mn;
	vector<pair<int, int> > v, u;
	for (int i = 0; i < n; ++i) {
		if (x[i] == mn) {
			mx2 = max(mx2, y[i]);
			mn2 = min(mn2, y[i]);
		}
		else if (y[i] == mx) {
			mx2 = max(mx2, x[i]);
			mn2 = min(mn2, x[i]);
		}
		else {
			v.push_back(make_pair(x[i], y[i]));
		}
	}
	random_shuffle(v.begin(), v.end());
	int xd, yd;
	int mn3 = 1e9 + 10, mx3 = -1;
	bool ok = true;
	while (1) {
		u.clear();
		for (int i = 0; i < v.size(); ++i) {
			xd = v[i].X, yd = v[i].Y;
			if (xd > yd) swap(xd, yd);
			if (xd >= mn2) mx2 = max(mx2, xd);
			else if (yd <= mx2) mn2 = min(mn2, yd);
			else u.push_back(make_pair(xd, yd));
			
		}
		u.swap(v);
		if (u.size() == v.size())
			break;
	}
	int xdd, ydd;
	for (int i = 0; i < v.size(); ++i) {
		xd = v[i].X, yd = v[i].Y;
		
		xdd = get(mn2, mx2, xd);
		ydd = get(mn2, mx2, yd);

		if (xdd < ydd) {
			mx2 = max(mx2, xd);
			mn2 = min(mn2, xd);
		}
		else {
			mx2 = max(mx2, yd);
			mn2 = min(mn2, yd);
		}
	}
	return (ll(mx1) - mn1) * (ll(mx2) - mn2);
}

ll calc2() {
	int mx1 = -1, mx2 = -1, mn1 = 1e9 + 10, mn2 = 1e9 + 10;
	mx1 = mx, mn2 = mn;
	for (int i = 0; i < n; ++i) {
		mn1 = min(mn1, y[i]);
		mx2 = max(mx2, x[i]);
	}
	return (ll(mx1) - mn1) * (ll(mx2) - mn2);
}

int main() {
	srand(time(0));
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d%d", x + i, y + i);
		mn = min(mn, min(x[i], y[i]));
		mx = max(mx, max(x[i], y[i]));
	}

	if (mn == mx) return puts("0"), 0;
	for (int i = 0; i < n; ++i)
		if (x[i] > y[i])
			swap(x[i], y[i]);

	printf("%lld\n", min(calc1(), calc2()));
	return 0;
}



Measured memory_bytes: 4084
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define MOD 1000000007

int main(void) {
  int w, a, b;
  cin >> w >> a >> b;
  if(b > a+w)
  cout << b-(a+w) << endl;
  else if(a > b+w)
  cout << a-(b+w) << endl;
  else 
  cout << 0 << endl;
}

Measured memory_bytes: 3636
//-----------------------
// author : xyqkoala
// time : 2020-08-03
//-----------------------

#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;

typedef long long LL;
const int MOD = 1e9+7;

void solve();


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


void solve(){
	int n,d;
	cin>>n>>d;
	int res = 0;
	for(int i=0;i<n;i++){
		int x,y;
		cin>>x>>y;
		if((1ll *x*x + 1ll*y*y)<=1ll * d * d){
			res++;
		}
	}
	cout<<res<<endl;
}


Measured memory_bytes: 3668
#include <cstdio>

int main()
{
  int a, b;
  scanf("%d %d", &a, &b);
  if (((a ^ b) & 1) == 1)
  {
    puts("IMPOSSIBLE");
  }
  else
  {
    printf("%d\n", (a + b) / 2);
  }
  return 0;
}

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

template <class T> using V = vector<T>;

using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;


#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) __lcm(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;



int main() {
  ll n;
  	ci(n)
  vch A(n);
  vch B(n);
  vch C(n);
  
  	st sa,sb,sc;
      ci(sa)
      ci(sb)
      ci(sc)
  ll ans=0;
  FOR(i,0,n){
	A[i]=sa.at(i);
    B[i]=sb.at(i);
    C[i]=sc.at(i);
      }
  FOR(i,0,n){
    if(A[i]!=B[i]){
      ans+=1;
    }
    else{
	  ans+=0;
    }
  }
  FOR(i,0,n){
	if(A[i]!=C[i]&&B[i]!=C[i]){
      ans+=1;
    }
  }
  co(ans)
}
      


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main (){
  int N,K,x,add,mul;
  cin >> N >> K;
  x = 1;
  
  for(int i = 0; i < N;i++){
    mul = x * 2;
    add = x + K;
    if(mul <= add)
      x = mul;
    else
      x = add;
  }
  cout << x << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  long long n,k,i,l,r,m,c,ll,rr,mm;
  cin>>n>>k;
  vector<long long> a(n);
  for (i=0;i<n;i++) cin>>a.at(i);
  sort(a.begin(),a.end());
  l=-1e18;
  r=1e18;
  while (r-l>1) {
    m=(l+r)/2;
    c=0;
    for (i=0;i<n;i++) {
      if (a.at(i)<0) {
        if (a.at(i)*a.at(n-1)>m) continue;
        ll=-1;rr=n-1;
        while (rr-ll>1) {
          mm=(ll+rr)/2;
          if (a.at(i)*a.at(mm)<=m) rr=mm;
          else ll=mm;
        }
        c+=n-rr;
      }
      else if (a.at(i)==0 && 0<=m) c+=n;
      else if (a.at(i)>0) {
        if (a.at(i)*a.at(0)>m) continue;
        ll=0;rr=n;
        while (rr-ll>1) {
          mm=(ll+rr)/2;
          if (a.at(i)*a.at(mm)<=m) ll=mm;
          else rr=mm;
        }
        c+=ll+1;
      }
      if (a.at(i)*a.at(i)<=m) c--;
    }
    if (c<2*k) l=m;
    else r=m;
  }
  cout<<r<<endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)
#define BITBOOL(x,a) (((x)>>(a))&1)
int main(){
  //std::cout << std::fixed << std::setprecision(20);
  int n, k,ans=0,h[100005];
  cin >> n >> k;
  FOR(i,0,n) cin >> h[i];
  FOR(i,0,n)if(h[i]>=k) ans++;
  cout << ans;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int n;
int m =0;
int *a;

void select_sort()
{
	for(int i=0; i<n-1; i++)
	{
		int minj = i;
		for (int j=i+1; j<n; j++)
		{
			if (a[minj] > a[j])
			{
				minj = j;
			}
		}
		
		if (minj != i)
		{
			int ai = a[i];
			a[i] = a[minj];
			a[minj] = ai;
			m++;
		}
	}
}

int main()
{
	cin >> n;
	a = new int[n];
	for (int i = 0; i < n;	i++)
	{
		cin >> a[i];
	}
	
	select_sort();
	
	for (int i=0; i<n;	i++)
	{
		if (i) cout << ' ';
		cout << a[i];
	}
	
	cout << endl;
	cout << m << endl;
	
	return 0;
}

Measured memory_bytes: 1192
a = gets.to_i
b = gets.to_i
c = gets.to_i
d = gets.to_i
ctn = 0

(0..a).each do |i|
  (0..b).each do |j|
    (0..c).each do |k|
      ctn +=1 if d == i*500 + j*100 + k*50
    end
  end
end
  
puts ctn

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

using namespace std;
using ll = long long;

void solve(ll N, vector<ll> d) {
  sort(d.begin(),d.end());
  cout << d[N/2] - d[N/2-1] << endl;
}

int main() {
  ll N;
  cin >> N;
  vector<ll> d(N);
  for (int i = 0; i < N; i++) {
    cin >> d[i];
  }
  solve(N, move(d));
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define FOR(i, b, n) for (ll i = b; i < n; ++i)

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

void solve(ll X, ll K, ll D) {
  ll n = X / D;
  if (K <= abs(n)) {
    if (X > 0)
      X -= K * D;
    else
      X += K * D;
  } else {
    X -= n * D;
    if (X > 0)
      X -= ((K - n) % 2) * D;
    else
      X += ((K - n ) % 2) * D;
  }
  cout << abs(X) << endl;
}

int main(){
  // int 3E4  long 2E9  ll 9E18
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll X;
  cin >> X;
  ll K;
  cin >> K;
  ll D;
  cin >> D;

  solve(X, K, D);

  return 0;
}


Measured memory_bytes: 3652
def main():
    import sys
    from collections import Counter
    input = sys.stdin.readline

    N, mod = map(int, input().split())
    S = input().rstrip('\n')

    if mod == 2 or mod == 5:
        S = S[::-1]
        ans = 0
        for i, s in enumerate(S):
            s = int(s)
            if s%mod == 0:
                ans += N - i
        print(ans)
        exit()

    M = [0] * N
    S = S[::-1]
    for i, s in enumerate(S):
        s = int(s)
        M[i] = (M[i-1] + (s * pow(10, i, mod))%mod)%mod
    M.reverse()
    M.append(0)
    C = Counter(M)
    ans = 0
    for x in C:
        ans += (C[x] * (C[x]-1)) // 2
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 45740
program main
  implicit none
  integer(8) :: n, i, dig, cnt(0:2018), res
  integer(8), allocatable :: d(:)
  integer(8), parameter :: m = 2019
  character(200000) :: s
  read *, s
  n = len(trim(s))
  allocate (d(n))

  read (s(n:n), *) dig
  cnt = 0
  cnt(0) = 1
  d(n) = dig
  cnt(d(n)) = cnt(d(n)) + 1
  do i = n - 1, 1, -1
    read (s(i:i), *) dig
    d(i) = d(i + 1) + pow(10_8, n - i) * dig
    d(i) = modulo(d(i), m)
    cnt(d(i)) = cnt(d(i)) + 1
  end do

  res = 0
  do i = 0, 2018
    res = res + cnt(i) * (cnt(i) - 1) / 2
  end do
  print "(i0)", res
  contains

  recursive function pow(n, p) result(res)
    integer(8), intent(in) :: n, p
    integer(8) :: res
    if (p == 0) then
      res = 1
    else if (modulo(p, 2_8) == 0) then
      res = modulo(pow(n, p / 2) ** 2, m)
    else
      res = modulo(pow(n, p - 1) * n, m)
    end if
  end function pow
end program main


Measured memory_bytes: 4808
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()){
			double n = sc.nextDouble();
			int count = 0;
			while(n>1.0){
				n /= 3;
				count++;
			}
			System.out.println(count);
		}
	}	
}

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

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

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

  // ソート
  sort(d.begin(), d.end());

  // N/2番目に難しい問題から、N/2-1番目に難しい問題を引く
  int answer = d[d.size() / 2] - d[d.size() / 2 - 1];

  cout << answer << endl;

  return 0;
}

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

int main() {
  string S;
  cin>>S;
  vector<int>a(S.size()-2);
  for(int i=0;i<S.size()-2;i++){
    int A=(S.at(i)-'0')*100+(S.at(i+1)-'0')*10+S.at(i+2)-'0';
    a.at(i)=abs(753-A);
  }
  sort(a.begin(),a.end());
  cout<<a.at(0)<< endl;
}
  
  

Measured memory_bytes: 256
//Never stop trying
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef string str;
typedef long long ll;
#define int ll
typedef double db;
typedef long double ld;

typedef pair<int,int> pi;
#define fi first
#define se second

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;

#define pb push_back
#define eb emplace_back
#define pf push_front

#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"

const int MOD = 1e9+7; //998244353
const ll INF = 1e18;
const int nx[4]={0,0,1,-1}, ny[4]={1,-1,0,0}; //right left down up

void IO(){
#ifndef ONLINE_JUDGE 
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout); 
#endif 
}

int32_t main(){
   boost;
   IO();
	
  	int N; cin>>N;
  	int a[N];
  	for(int i=0; i<N; i++) cin>>a[i];

  	int ans=0;
  	for(int i=0; i<N; i++) for(int j=i+1; j<N; j++) for(int k=j+1; k<N; k++){
  		int t[3]={a[i],a[j],a[k]};
  		sort(t,t+3);
  		if(t[0]+t[1]>t[2] && t[0]!=t[1] && t[0]!=t[2] && t[1]!=t[2]) ans++;
  	}
  	cout << ans << endl;

   return 0;
}



Measured memory_bytes: 3656