akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
typedef long long ll;
ll n,ans=1LL,MOD=1000000007,cnt;
string s;
ll f(ll n){
    if(n==1)return 1;
    return n*f(n-1)%MOD;
}
int main(void){
    cin>>n>>s;
    for(int i=0;i<2*n;i+=2){
        if(s[i]=='W')s[i]='B';
        else s[i]='W';
    }
    for(int i=0;i<n*2;i++){
        //cout<<s<<endl;
        //cout<<ans<<cnt<<endl;
        if(s[i]=='W')cnt++;
        else{
            ans*=cnt;
            ans%=MOD;
            cnt--;
        }
        //cout<<cnt<<endl;
        if(cnt==-1){
            cout<<0<<endl;
            return 0;
        }
    }
    if(cnt!=0)cout<<0<<endl;
    else cout<<ans*f(n)%MOD<<endl;
}


Measured memory_bytes: 2180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define fori(i, m, n) for(int i = m; i < (int)n; i++)
#define forl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define all(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string bans(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int a,b;cin>>a>>b;
  int ans=0;
  fori(i,a,b+1){
    int val=i;
    if(val%10==val/10000){
      val%=10000;val/=10;
      if(val%10==val/100){
        ans++;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;cin>>s;
  int n=s.size();
  int now=(n+1)/2;
  for(int i=n/2-1;i>=0;i--){
    if(s[i]==s[i+1]&&s[n-i-1]==s[n-i-2])now++;
    else {
      cout<<now<<endl;
      return 0;
    }
  }
  cout<<n<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main()
{
	char a;
	cin >> a;
	if(a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u') {
		cout << "vowel" << endl;
	} else {
		cout << "consonant" << endl;
	}
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 200010
using namespace std;
typedef int ll;
ll p[N];
map<ll,ll>mp;
      ll a;
bool check(ll k)
{
  mp.clear();
    for(ll i=2;i<=a;i++)
        if(p[i]>p[i-1])
        continue;
    else
    {
        if(k==1)
            return false;
    
    
       while(mp.size()){
        ll u=mp.rbegin() -> first;
        if(u>p[i])
        mp.erase(u);
        else
            break;
       }


        ll j=p[i];
        while(j&&mp[j]+1==k)
        {

            mp.erase(j);
              j--;
        }
       if(j==0)
        return false;
       mp[j]++;
    }
    return true;



}
int main() {


        cin>>a;
        for(ll i=1;i<=a;i++)
            cin>>p[i];

        ll l=1,r=a,mid;


        while(l<r)
        {
            mid=(l+r)>>1;
            if(check(mid))
                r=mid;
            else
                l=mid+1;
        }

        cout<<l<<endl;
    return 0;
}


Measured memory_bytes: 4408
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()


N = n()

points = []
for i in range(N):
    points.append(n())
points = sorted(points)

import sys

total = sum(points)
if total % 10 > 0:
    print(total)
    sys.exit()

for p in points:
    if (total - p) % 10 > 0:
        print(total - p)
        sys.exit()

print(0)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int dx[] = {0, 0, 1, -1};
constexpr int dy[] = {1, -1, 0, 0};

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

    int k, n;

    ll h[112345];

    cin >> n >> k;
    REP(i, n)
    {
        cin >> h[i];
    }

    sort(h, h + n);

    ll res = INF;

    for (int i = 0; i < n - k + 1; i++)
    {
        res = min(res, h[i + k - 1] - h[i]);
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define il inline
#define db double
#define ls rt << 1
#define rs rt << 1 | 1
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define rep0(i, n) for(int i = 0; i < (n); i ++)
#define per0(i, n) for(int i = (n) - 1; i >= 0; i --)
#define ept 1e-9
#define INF 0x3f3f3f3f
#define sz(x) (x).size()
#define ALL(x) (x).begin(), (x).end()
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
inline ll read1()
{
	ll x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
using namespace std;

const int N = 305;
const ull p1 = 5557;
const int p2 = 2333;
const int mod = 998244353;

struct Node
{
	ull s1;
	int s2;
	Node(){}
	Node(ull s1, int s2):s1(s1),s2(s2){}
	friend Node operator+(Node a,Node b)
	{
		return Node(a.s1 + b.s1, (a.s2 + b.s2) % mod);
	}
	friend Node operator-(Node a,Node b)
	{
		return Node(a.s1 - b.s1, (a.s2 - b.s2 + mod) % mod);
	}
	friend Node operator*(Node a,Node b)
	{
		return Node(a.s1 * b.s1, 1ll * a.s2 * b.s2 % mod);
	}
	friend bool operator==(Node a,Node b)
	{
		return (a.s1 == b.s1 && a.s2 == b.s2);
	}
}Hash[N][N],p[N],Hash2[N][N];
int n,ans,tag;
char s[N][N];

void init()
{
	rep0(i, n)
		rep0(j, n)
			rep0(k, n)
				Hash[i][j] = Hash[i][j] * Node(p1, p2) + Node(s[(i +k) % n][j], s[(i + k) % n][j]);
			
	rep0(j, n)
		rep0(i, n)
			rep0(k, n)
				Hash2[j][i] = Hash2[j][i] * Node(p1, p2) + Node(s[i][(j + k) % n], s[i][(j + k) % n]);
}

int main()
{
	n = read();
	rep0(i, n) scanf("%s", s[i]);
	p[0] = Node(1, 1); 
	rep(i, 1, n)
		p[i] = p[i - 1] * Node(p1, p2);
	init();
	rep0(i, n)
		rep0(j, n)
		{
			tag = 1;
			rep0(k, n)
			{
				if (Hash[i][(j + k) % n] == Hash2[j][(i + k) % n]) continue;
				tag = 0;
				break;
			}
			ans += tag;
		}
	
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 3200
import java.util.*;
 
public class Main{
 
	public static void main(String[] args){
 
		Scanner sc = new Scanner(System.in);
        String ss[] = {sc.next(),sc.next(),sc.next()};
      	int counts[] = {0,0,0};
      	boolean game = true;
      	int istack;
      	char cstack;
      	Map<Character, Integer> pMap1 = new HashMap<Character, Integer>();
		pMap1.put('a',0);
      	pMap1.put('b',1);
      	pMap1.put('c',2);
      	Map<Integer,Character> pMap2 = new HashMap<Integer,Character>();
		pMap2.put(0,'A');
      	pMap2.put(1,'B');
      	pMap2.put(2,'C');
      	
      	cstack = ss[0].charAt(0);
      	counts[0]++;
      	istack = istack = pMap1.get(cstack);
       	while(game){
          	if(counts[istack] == ss[istack].length()) {
              System.out.println(pMap2.get(istack));
              game = false;
            } else{            	              	
              	cstack = ss[istack].charAt(counts[istack]); 
                counts[istack]++;
              	istack = pMap1.get(cstack);         }
        }
   }
}


Measured memory_bytes: 35580
#include<bits/stdc++.h>
using namespace std; 
using ll = long long;

void solve() {
    ll L, R;
    cin >> L >> R;
    if (R - L >= 2019) {
        cout << "0\n";
    }
    else
    {
        ll ans = LLONG_MAX;
        for (ll i = L; i < R; ++i) {
            for (ll j = i + 1; j <= R; ++j) {
                ans = min(ans, (i * j) % 2019);
            }
        }
        cout << ans << "\n";
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t = 1;
    while(t--) {
        solve();
    }
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) begin(x),end(x)
typedef long long ll;
int OO = 0x3f3f3f3f;

string s, k;
int ss, sk;
int mem[3003][3003];
int solve(int x, int y)
{
    int op1, op2;
    if(x == ss || y == sk)
        return 0;

    if(mem[x][y] != -1)
        return mem[x][y];

    if(s[x] == k[y])
        return mem[x][y] = solve(x+1, y+1)+1;

    op1 = solve(x+1, y);
    op2 = solve(x, y+1);

    return mem[x][y] = max(op1, op2);
}


void print(int x, int y)
{
    if(x == ss || y == sk)
        return;

    if(s[x] == k[y])
    {
        cout << s[x];
        print(x+1, y+1);
        return;
    }

    int optimal = solve(x, y);
    int op1 = solve(x+1, y);
    int op2 = solve(x, y+1);


    if(op1 == optimal)
        print(x+1, y);
    else
        print(x, y+1);
}

int main()
{
    cin >> s >> k;
    ss = s.size();
    sk = k.size();
    memset(mem, -1, sizeof mem);
    print(0, 0);
    return 0;
}


Measured memory_bytes: 35840
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define ll long long

int n;
ll a[212345];
char z;

int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

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

  
  for(int i=0;i<n;i++){
    scanf("%lld",&a[i]);}
  
  
  sortdown(a,n);
  ll tmp=n-2;
  ll ans=a[0];
  int ind=1;
  while(tmp>0){
    if(tmp==1){
      ans+=a[ind];}
    else{
      ans+=a[ind]*2;}
    ind++;
    tmp-=2;}
  printf("%lld\n",ans);
  
  return 0;
}


Measured memory_bytes: 4688
#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 <bitset>
using namespace std;
typedef long long ll;

int main() {
	ll N; cin >> N;
	vector<ll> A(N);
	ll sum = 0;
	ll mod = 1e9 + 7;
	for (int i = 0; i < N; i++) {
		cin >> A.at(i);
		sum += A.at(i);
	}
	ll buf = sum, ans = 0;
	for (int i = 0; i < N; i++) {
		sum -= A.at(i);
		buf = sum;
		sum %= mod;
		ans += sum * A.at(i);
		ans %= mod;
		sum = buf;
	}
	cout << ans << endl;
}


Measured memory_bytes: 4760
x=gets.to_i
l=[]
2000.times do |i|
  l << i**5
end
2000.times do |i|
  i.times do |j|
    if l[i]-l[j]==x
      puts i,j
      exit
    elsif l[i]+l[j]==x
      puts i,-j
      exit
    end
  end
end


Measured memory_bytes: 14352
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (int) 1e9+7
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define vi vector<int>
ll xpow(ll a, ll b)
{
	if (b == 0)
		return 1;
	if (b % 2 == 0)
	{
		ll k = xpow(a, b / 2);
		return k * k;
	}
	if (b % 2 != 0)
		return a * xpow(a, b - 1);
}
int main()
{

#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out1.txt", "w", stdout);
#endif
	fio;
	string s;
	cin >> s;
	int cnt = 0;
	if (s[0] == 'R' and s[1] == 'R' and s[2] == 'S') {
		cout << "2" << endl;
	}
	else if (s[0] == 'S' and s[1] == 'R' and s[2] == 'R')
		cout << "2" << endl;
	else if (s[0] == 'S' and s[1] == 'S' and s[2] == 'S')
		cout << "0" << endl;
	else if (s[0] == 'R' and s[1] == 'R' and s[2] == 'R')
		cout << "3" << endl;
	else
		cout << "1" << endl;
}

Measured memory_bytes: 3652
#include<stdio.h>
int main(void)
{
	int W,H,x,y,r;
	do{
		scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	}while(-100>x||x>100||-100>y||y>100||0>=W||W>100||0>=H||H>100||0>=r||r>100);
	if(r<=x&&x<=W-r&&r<=y&&y<=H-r){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 584
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

H, W = MAP()
a = [LIST() for _ in range(H)]

cnt = 0
move = []
for i in range(H):
	for j in range(W):
		if i == H-1 and j == W-1:
			print(cnt)
			for x in move:
				print(*x)
			exit()
		if i%2 == 0:
			if a[i][j]%2 and j == W-1:
				a[i][j] -= 1
				a[i+1][j] += 1	
				cnt += 1
				move.append((i+1, j+1, i+2, j+1))
			elif a[i][j]%2:
				a[i][j] -= 1
				a[i][j+1] += 1
				cnt += 1
				move.append((i+1, j+1, i+1, j+2))
		else:
			if a[i][W-j-1]%2 and j == W-1:
				a[i][W-j-1] -= 1
				a[i+1][W-j-1] += 1
				cnt += 1
				move.append((i+1, W-j, i+2, W-j))
			elif a[i][W-j-1]%2:
				a[i][W-j-1] -= 1
				a[i][W-j-2] += 1
				cnt += 1
				move.append((i+1, W-j, i+1, W-j-1))

Measured memory_bytes: 31840
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    int a,b,h;
    cin>>a>>b>>h;
    cout<<(a+b)*h/2<<endl;

    return 0;
}

Measured memory_bytes: 256
import math

def cc(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n, p = map(int, input().split())
a = list(map(int, input().split()))
o = 0
e = 0
s = 0
for i in a:
  if i%2:
    o += 1
  else:
    e += 1
if p:
  for j in range(1,o+1,2):
    s += cc(o, j)
else:
  for k in range(0,o+1,2):
    s += cc(o, k)
print(s*2**e)
  


Measured memory_bytes: 3064
#include <bits/stdc++.h>
                        
#define int long long
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define FRE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

using namespace std;
int n, W;
int dp[105][100005];                  
int32_t main()
{
    IOS //FRE
 
    cin >> n >> W;
    int w[n], v[n];
    for(int i = 0; i < n; i++) 
        cin >> w[i] >> v[i];
    
    for(int j = w[0]; j <= W; j++)
        dp[0][j] = v[0];
    
    for(int i = 1; i < n; i++){
        for(int j = 0; j <= W; j++){
            if(j - w[i] >= 0)
                dp[i][j] = max(dp[i - 1][j - w[i]] + v[i], dp[i - 1][j]);
            else dp[i][j] = dp[i - 1][j];
        }
    }
    cout << dp[n - 1][W];
 
    return 0;
}

Measured memory_bytes: 80128
S,t=$<.map &:chomp
r=nil
(0..S.size-t.size).each{|i|
	s=S.dup
	if t.size.times.all?{|j|
		if s[i+j]=='?' || s[i+j]==t[j]
			s[i+j]=t[j]
		end
	}
		s.tr!('?','a')
		r=s if !r||r>s
	end
}
puts r||:UNRESTORABLE

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

int main(void){

	string s;
	string t;

	cin >> s;
	cin >> t;

	int n = s.length();
	int m = t.length();

	vector< vector<int> > arr(n+1, vector<int>(m+1,0));

	for(int i=1;i<n+1;i++){
		for(int j=1;j<m+1;j++){
			if(s[i-1]==t[j-1]){
				arr[i][j] = arr[i-1][j-1]+1;
			}
			else{
				arr[i][j] = max(arr[i-1][j],arr[i][j-1]);
			}
		}
	}

	int i=n;
	int j=m;

	int count=0;
	string ans;
	while(count<arr[n][m]){

		if(s[i-1]==t[j-1]){
			ans.push_back(s[i-1]);
			count += 1;
			i-=1;
			j-=1;
		}
		else{
			if(arr[i-1][j]>arr[i][j-1]){
				i-=1;
			}
			else{
				j-=1;
			}
		}

	}

	reverse(ans.begin(),ans.end());
	cout << ans;
}

Measured memory_bytes: 37376
#include <stdio.h>
#define N 100000
#define Q 50000

int main() {

  int i,j,n,q,count=0,left,right,mid;
  int S[N],T[Q];

  scanf("%d",&n);
  for(i=0; i<n; i++) {
    scanf("%d",&S[i]);
  }

  scanf("%d",&q);
  for(i=0; i<q; i++) {
    scanf("%d",&T[i]);
    left = 0;
    right = n;
    while(left<right) {
      mid = (left + right) / 2;
      if(S[mid]==T[i]) {
        count++;
        break;
      } 
      else if(T[i]<S[mid]) right = mid;
      else left	= mid +	1;
    }
  }

  printf("%d\n",count);

  return 0;
}

Measured memory_bytes: 1184
fun main(args: Array<String>) {
    abd084d()
}

fun abd084d() {
    val q = readLine()!!.toInt()
    val lrList = (1..q).map { readLine()!!.split(" ").map { it.toInt() } }.map { Pair(it[0], it[1]) }
    val max = lrList.maxBy { it.second }!!.second

    val primes = genPrime(max)

    val cumulativeSum = LongArray(max + 2)
    for (i in 0..max) cumulativeSum[i + 1] = cumulativeSum[i] +
            if (i.toLong() in primes && (i.toLong() + 1) / 2 in primes) 1 else 0

    val answer = lrList.map {
        val (left, right) = it
        cumulativeSum[right + 1] - cumulativeSum[left]
    }

    println(answer.joinToString(System.lineSeparator()))
}

private fun genPrime(max: Int): LongArray {
    val sqrt = Math.ceil(Math.sqrt(max.toDouble())).toLong()
    val primes = mutableListOf<Long>()

    var target = (2..max.toLong()).toList()

    while (target.isNotEmpty() && target.first() <= sqrt) {
        val prime = target.first()
        primes.add(prime)
        target = target.filterNot { it % prime == 0L }
    }

    primes.addAll(target)

    return primes.toLongArray()
}


Measured memory_bytes: 83100
def p_a():
    A, B = map(int, input().split())
    print(A * B if A < 10 and B < 10 else -1)


def p_b():
    N = int(input())
    for i in range(1, 10):
        for j in range(1, 10):
            if N == i * j:
                print("Yes")
                exit()
    print("No")


def p_c():
    pass


def p_d():
    pass


def p_e():
    pass


def p_f():
    pass


if __name__ == '__main__':
    p_b()


Measured memory_bytes: 38640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>

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

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<P, int> PP;
const double PI = 3.14159265358979323846;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+17 + 10;

int main(){
	int n;
	double x[101], y[101];
	std::cin >> n;
	rep(i, n)std::cin >> x[i];
	rep(i, n)std::cin >> y[i];

	rep(i, 3){
		double ans = 0;
		rep(j, n)ans += pow(abs(x[j] - y[j]), i + 1);
		ans = pow(ans, 1.0 / (i + 1));
		printf("%.10lf\n", ans);
	}
	double ans = 0;
	rep(i, n)ans = std::max(ans, std::abs(x[i] - y[i]));
	printf("%.10lf\n", ans);
	return 0;
}

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

using namespace std;
using LL = long long;

int main(){
    double W,H,x,y;cin >> W >> H>> x >> y;
    cout<<1.0*H*W/2<<" ";
    if(W/2 == x && H/2 == y){
        cout<<1<<endl;
    }else{
        cout<<0<<endl;
    }
}


Measured memory_bytes: 384
require 'pp'
N,M = readline.chomp.split.map(&:to_i)
A = Array.new(N)
N.times do |i|
  a,b = readline.chomp.split.map(&:to_i)
  A[i] = [a,b]
end

A.sort_by! {|(a,b)| a }

sum = 0
sum_p = 0
A.each do |a,b|
  n = [M-sum, b].min
  sum += n
  sum_p += n * a
  break if sum == M
end

puts sum_p


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

int main() {
    int N;
    cin >> N ;
    vector<int>a(N); 
    for( int i=0; i<N; ++i){
        cin >> a.at(i);
    }
    int ans;
    ans = 0;
    for( int i=0; i<N-1; ++i){
        for( int j=i+1; j<N; ++j ){
            ans += a.at(i)*a.at(j);
        }
    }
    cout << ans << endl;
}

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

int main() {
  int Si,S1,S2,S3;
  cin >> Si;
  S1 = Si / 100;
  S2 = (Si /10) % 10;
  S3 = Si % 10;
  cout << S1 + S2 + S3 << endl;
  
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
a = int(input())
f = [list(map(int,input().split())) for i in range(a)]
p = [list(map(int,input().split())) for i in range(a)]
joisino_mask = [[0],[1]]
import copy
for _ in range(9):
    temp_joisino_mask = []
    for i in joisino_mask:
        temp_joisino_mask.append(i+[0])
        temp_joisino_mask.append(i+[1])
    joisino_mask = temp_joisino_mask

joisino_mask.pop(0)
cur_max = -1 * float("inf")
for mask in joisino_mask:
    mask_p = 0
    for i,misei in enumerate(f):
        common_time_cnt = sum(list(map(lambda x,y:(x+y)//2,mask,misei)))
        mask_p += p[i][common_time_cnt]
    if mask_p > cur_max:
        cur_max = mask_p
print(cur_max)

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

using namespace std;

int main()
{
  string a, b;
  cin >> a >> b;
  
  int num_a, num_b;
  cin >> num_a >> num_b;
  cin.get();
  
  string chosen;
  cin >> chosen;
  
  if (chosen == a) {
    num_a -= 1;
  } else {
  	num_b -= 1;
  }
  
  cout << num_a << " " << num_b << "\n";
  return 0;
}

Measured memory_bytes: 256
program test
implicit none
integer(8) :: i,j,k,m,n,nn,a(100000),ma(100000),suma(100000),sumb(100000),ans=0,combo=1

read(*,*) n,m
read(*,*) (a(i),i=1,n)

do i=1,n
	ma(i) = mod(a(i),m)
enddo

do i=1,n
	if(i==1)then
	suma(i) = ma(i)
	else
	suma(i) = mod(suma(i-1) + ma(i),m)
	endif
enddo

call heapsort2(n,suma(1:n),sumb(1:n))

do i=2,n
	if(suma(i) == suma(i-1)) then
		combo = combo + 1
	else
		if(suma(i-1) == 0) then
			ans = ans + i-1
		endif
		ans = ans + combo*(combo-1)/2
		combo = 1
	endif
enddo

if(combo > 1) then
		ans = ans + combo*(combo-1)/2
endif

if(suma(n) == 0) then
	ans = ans + n
endif

write(*,*) ans

contains

subroutine heapsort2(n,y1,y2)

	implicit none
	integer(8),intent(in) :: n
	integer(8),intent(inout) :: y1(1:n)
	integer(8),intent(inout) :: y2(1:n)
	integer(8) :: i,k,j,l
	integer(8) :: t1,t2
	
	l = n/2+1
	k = n

	do while (k /= 1)
		 if(l > 1) then
				l = l-1
				t1 = y1(l)
				t2 = y2(l)
				
		 else
				t1 = y1(k)
				t2 = y2(k)
				y1(k) = y1(1)
				y2(k) = y2(1)
				k = k-1
				if(k == 1) then
					 y1(1) = t1
					 y2(1) = t2
					 exit
				endif
		 endif

		 i = l
		 j = l+l

		 do while(j <= k)
				if(j < k) then
					 if(y1(j) < y1(j+1)) j = j+1
				endif
				
				if (t1 < y1(j)) then
					 y1(i) = y1(j)
					 y2(i) = y2(j)
					 i = j
					 j = j+j
				else
					 j = k+1
				endif
		 
		 enddo
		 
		 y1(i) = t1
		 y2(i) = t2
	
	enddo
	return

end subroutine heapsort2

end program

Measured memory_bytes: 3968
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>

using namespace std;

char S[200002];
int counter[2020];

int main()
{
    int len, i, total, pot;
    long long pairs;

    scanf("%s", &S[1]);

    len = strlen(&S[1]);
    memset(counter, 0, sizeof counter);
    total = 0;
    ++counter[0];
    pairs = 0;
    pot = 1;
    for(i = len; i >= 1; --i){
        total = (total + pot * (S[i] - '0')) % 2019;
        pairs += counter[total];
        ++counter[total];
        pot = pot * 10 % 2019;
    }
    printf("%I64d", pairs);

    return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; //intじゃ扱えないことに注意！

#define rep(i, n) for(int i = 0; i < (int)(n); i++) //範囲外参照とループの初期化に注意！
const double pi = 3.14159265359;

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

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

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

  int ans = 0;
  for(int i = 0; i < K; i++){
      ans += p[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
 using namespace std;
#define INF 1000000000
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
int H,W;
int main(){
    cin>>H>>W;
    REP(i,H){
        string s;
        cin>>s;
        cout<<s<<endl;
        cout<<s<<endl;
    }
}

Measured memory_bytes: 384
/*
 * Name        : e
 * Creat       : Fri Jul 12 11:20:29 CST 2019
 * Accept      : Fri Jul 12 14:12:32 CST 2019
 * Author      : landcold7
 * Motivation  : Action speaks louder more than words
 */
#include <bits/stdc++.h>
using namespace std;

#define x first
#define y second
#define sz(x) ((int)(x).size())
#ifndef _has_trace
#define trace(...)
#endif
typedef long long ll;

const int mod = 1e9 + 7;

struct mint {
  ll x;
  mint(ll _x = 0) : x(_x % mod) {}

  mint& operator+= (const mint a) {
    if ((x += a.x) >= mod) {
      x -= mod;
    }
    return *this;
  }

  mint& operator-=(const mint a) {
    if ((x -= a.x) < 0) {
      x += mod;
    }
    return *this;
  }

  mint& operator*=(const mint a) {
    x = ((x * a.x) % mod);
    return *this;
  }

  mint operator+(const mint a) const {
    mint ret(*this);
    return ret += a;
  }

  mint operator-(const mint a) const {
    mint ret(*this);
    return ret -= a;
  }

  mint operator*(const mint a) const {
    mint ret(*this);
    return ret *= a;
  }

  mint pow(ll t) const {
    if (t == 0) {
      return 1;
    }
    mint ret = pow(t >> 1);
    ret *= ret;
    if (t & 1) {
      ret *= *this;
    }
    return ret;
  }

  // For prime mod
  // TODO(landcold7): generic case
  mint inv() const {
    return pow(mod - 2);
  }

  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }

  mint operator/(const mint a) const {
    mint ret(*this);
    return ret /= a;
  }
  friend ostream& operator<< (ostream& os, mint& a) {
    os << "Mint(" << a.x << ")";
    return os;
  }
};

template <typename T>
struct combina {
  vector<T> fact, fact_inv;
  combina(int n) : fact(n + 1), fact_inv(n + 1) {
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) {
      fact[i] = fact[i - 1] * i;
    }
    fact_inv[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) {
      fact_inv[i - 1] = fact_inv[i] * i;
    }
  }

  T nck(int n, int k) {
    return (*this)(n, k);
  }

  T npk(int n, int k) {
    // nPk = nCk * k!
    T ret = nck(n, k);
    ret *= fact[k];
    return ret;
  }

  T operator() (int n, int k) {
    if (k < 0 || n < k) {
      return T(0);
    }
    return fact[n] * fact_inv[k] * fact_inv[n - k];
  }
};

const int N = 1e5 + 7;
vector<int> g[N];
combina<mint> comb(N);
int k;
mint ans;

void dfs(int u, int pr = -1) {
  for (auto v : g[u]) {
    if (v != pr) {
      dfs(v, u);
    }
  }
  int n = (pr == -1 ? k : k - 2);
  int c = (pr == -1 ? sz(g[u]) + 1 : sz(g[u]) - 1);
  ans *= comb.npk(n, c);
}

void solve() {
  int n;
  cin >> n >> k;
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  trace(comb(5, 3), comb.npk(5, 3));
  ans = 1;
  dfs(0);
  cout << ans.x << "\n";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}


Measured memory_bytes: 10752
#include<iostream>
using namespace std;
int main()
{
	int n = 0;
	cin >> n;
	int* arr = new int[n];
	int count1 = 1;
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}
	int min = arr[0];
	for (int i = 1; i < n; i++)
	{
		if (arr[i]<=min)
		{
			count1++;
			min = arr[i];
		}
	}
	cout << count1;
	delete[] arr;
	return 0;
}

Measured memory_bytes: 1024
n, k = map(int, input().split())
s = input()
str_list = list(s)
if str_list[k-1] == 'A':
    str_list[k-1] = 'a'
elif str_list[k-1] == 'B':
    str_list[k-1] = 'b'
elif str_list[k-1] == 'C':
    str_list[k-1] = 'c'
# またリストから文字列へ戻す
str_changed = "".join(str_list)
print(str_changed)

Measured memory_bytes: 3060
import sys
def inpl(): return list(map(int, sys.stdin.readline().split()))
N, K = map(int, sys.stdin.readline().split())
A = inpl()
dic = {}
for i in range(N):
    dic[i+1] = A[i]
i = 1
visit = []
visit_set = set()
while i not in visit_set:
    visit.append(i)
    visit_set.add(i)
    i = dic[i]
find = visit.index(i)
if K < find:
    print(visit[K])
else:
    root = visit[find:]
    length = len(root)
    K = (K-find) % length
    print(root[K])

Measured memory_bytes: 155872
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#define int(x) int x; scanf("%d",&x);
#define lnt(x) long long x; scanf("%lld",&x);
#define dbl(x) double x; scanf("%lf",&x);
#define str(x) string x; cin >> x;
#define fo(i,a,b) for (int i=(a);i<(b);i++)
#define rf(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define rp(i,n) for (int i=0;i<(n);i++)
#define rrp(i,n) for (int i=(n)-1;i>=0;i--)
#define inf INT_MAX/3
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pcc pair<char,char>
#define pci pair<char,int>
#define vs vector<string>
#define vi vector<int>
#define ll long long
#define inx(x) scanf("%d",&x);
#define ot(x) printf("%d",&x);
#define eot(x) cout<<x<<endl;
#define sot(x) cout<<x<<" ";
using namespace std;
int main(){
	int(N)
	int ans=N*N*N;
	eot(ans)
	return 0;

}

Measured memory_bytes: 1208
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    int i,j,n;

   char s[101];
   int sum,max=0,k;
   scanf("%d",&n);
   scanf("%s",s);

   for (i=0;i<n;i++)
   {
  int a[101]={0};
   int b[101]={0};
    for (k=0;k<=i;k++)
    a[s[k]-'a']=1;
    for(j=i+1;j<n;j++)
    b[s[j]-'a']=1;
         sum=0;
       for(j=0;j<26;j++)
        {
            if(a[j]==1&&b[j]==1)
            sum++;
        }
 if(sum>max)
    max=sum;
   }
   printf("%d",max);

return 0;

   }





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

void LCS(string s1,string s2){
 int m=s1.length();
 int n=s2.length();
 if(m==1&&n==1){if(s1[0]==s2[0])cout<<s1<<endl;else cout<<"";return;}
 int dp[m+1][n+1];
 for(int i=0;i<m;i++)dp[i][0]=0;
 for(int j=0;j<n;j++)dp[0][j]=0;
 
 for(int i=1;i<=m;i++){
     for(int j=1;j<=n;j++){
         if(s1[i-1]==s2[j-1]){
             dp[i][j]=1+dp[i-1][j-1];
         }
         else
         dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
         
     }
 }
 
 //for(int i=0;i<=m;i++){for(int j=0;j<=n;j++){cout<<dp[i][j]<<" ";}cout<<endl;}
 int lenpos=dp[m][n];
 char s[lenpos+1];
 s[lenpos]='\0';
 int i=m;
 int j=n;
 while(i>=0&&j>=0){
     if(s1[i-1]==s2[j-1]){s[lenpos-1]=s1[i-1];lenpos--;i--;j--;}
     else if(dp[i-1][j]>dp[i][j-1]){i--;}
     else {j--;}
     
 }
cout<<s<<endl;
 //cout<<s.length()<<endl;
 
}
int main() {
    string s1,s2;
    cin>>s1;
    cin>>s2;
    LCS(s1,s2);
    //cout<<resl<<endl;

}

Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> void Max(T &m, const T q) { if (m < q) m = q; }
template<typename T> void Min(T &m, const T q) { if (m > q) m = q; }
template<typename T1, typename T2> pair<T1, T2> operator+(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

string S;
string T = "keyence";

void YES()
{
    puts("YES");
    exit(0);
}

int main()
{
    cin >> S;
    REP(s, 7)
    {
        bool flg = true;
        REP(i, 7)
        {
            int pos = i;
            if (i >= s) pos = S.length() - 7 + i;
            if (S[pos] != T[i]) flg = false;
        }

        if (flg) YES();
    }

    puts("NO");
}


Measured memory_bytes: 256
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
#文字列を一文字ずつ数字に変換、'5678'を[5,6,7,8]とできる
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
#文字列として取得
def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().rstrip().split()
def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

N, K= MI()
S = [0]+LI()
S += [0]
dp = [INF]*(N+5)
dp[1] = 0
for i in range(N):
    for j in range(1,K+1):
        if i+j <= N:
            dp[i+j] = min(dp[i+j],dp[i] + abs(S[i+j]-S[i]))
print(dp[N])


Measured memory_bytes: 76832
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

bool flag = 0;

ll saiki(int x,vector<ll> &a,vector<set<int> > &st){
    if(flag)return -1;    
    if(st[x].size()==0){
        return a[x];
    }
    ll tmp = 0;
    ll mx = 0;
    for(auto k:st[x]){
        st[k].erase(x);
        ll z = saiki(k,a,st);
        mx = max(mx,z);
        tmp += z;
    }
    ll ans = 2*a[x]-tmp;
    ll k = a[x]-ans;
    if(k>tmp-mx||k>tmp/2){
        flag = 1;
        return -1;
    }
    if(ans<0||ans>tmp){
        flag = 1;
        return -1;
    }else{
        return ans;
    }
}



int main(){
    int n;
    cin >> n;
    vector<ll>a(n);
    rep(i,n){
        cin >> a[i];
    }
    vector<set<int> > st(n);
    rep(i,n-1){
        int x,y;
        cin >> x >> y;
        x--;
        y--;
        st[x].insert(y);
        st[y].insert(x);
    }
    if(n==2){
        if(a[0]==a[1]){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
        return 0;
    }
    int x = 0;
    if(st[x].size()==1){
        x = *st[x].begin();
    }
    ll p = saiki(x,a,st);
    if(flag||p!=0){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }
    return 0;
}

Measured memory_bytes: 25728
# coding: utf-8
import sys
import bisect


"""Template"""


class IP:
    """
    入力を取得するクラス
    """
    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: 数
        """
        return int(input())

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数で合計
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if ((i >> j) & 1) == 1:
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val


"""ここからメインコード"""


def main():
    # 1文字に省略
    r, e = range, enumerate
    ip = IP()
    id = Idea()

    """コピーコードです。https://atcoder.jp/contests/abc105/submissions/4088632 
    こちらを参考にテストを行っています。"""
    n = ip.I()
    # それぞれ半分全列挙
    list1 = [(-2) ** i for i in r(16)]
    list2 = [(-2) ** (i + 16) for i in r(16)]
    list1_bin, list1_val = id.Bfs2(list1)
    list2_bin, list2_val = id.Bfs2(list2)

    # 2分探索
    ans = 0
    for i in r(len(list1_val)):
        j = bisect.bisect_left(list2_val, n - list1_val[i])

        if j < len(list2_val) and list1_val[i] + list2_val[j] == n:
            ans = list2_bin[j] + list1_bin[i]
            break
    print(int(ans))


main()

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

int gcd(int a, int b){
    if( a<0 ) a = -a;
    if( b<0 ) b = -b;
    while( b!=0 ){
        a %= b;
        if( a==0 ) return b;
        b %= a;
    }
    return a;
}

int main(){

	int n;
	scanf("%d", &n);
	
	long long sum = 0;
	for(int i = 1; i <= n; ++i){
		for(int j = 1; j <= n; ++j){
			for(int k = 1; k <= n; ++k){
        int cur = gcd(i, j);
        sum += gcd(cur, k);

			}
		}
	}
	printf("%lld", sum);
	return 0;

}

Measured memory_bytes: 3828
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,a[100005]={},m=1e9;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a[i];
    m=min(m,a[i]);
  }
  for(int i=0; i<n; i++) {
    if(a[i]==m) {
      cout << i+1 << endl;
      return 0;
    }
  }
}




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

int main(void) {
	int n,m, max,max2;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	max = a[0];
	
	for (int j = 1; j < n ; j++) {
		if (max <= a[j]) {
			max2 = max;
			max = a[j];
			m = j;
		}
		if (max2 < a[j]&&a[j]<max) {
			max2 = a[j];
		}
	}
	for (int i = 0; i < n; i++) {
		if (m == i) {
			cout << max2 << endl;
		}
		else {
			cout << max << endl;
		}
	}
}



Measured memory_bytes: 2432
/*ツリー構造*/
#include <stdio.h>
#include <stdlib.h>
#define N 100001

typedef struct node{
  int no;
  int depth;
  int nch;
  int *c;
  int pa;
} Node;

int main(){
  Node a[N];
  int n, i, j, num, ch, count=0;

  scanf("%d", &n);

  for(i=0; i<n; i++){
    a[i].pa = -1;
    a[i].depth = -2;
  }
  
  for(i=0; i<n; i++){
    scanf("%d%d", &num, &ch);
    if (ch != 0) count++;
    a[num].no = num;
    a[num].nch = ch;
    a[num].c = (int *)malloc(sizeof(int) * ch);
    for (j=0; j<ch; j++){
      scanf("%d", &a[num].c[j]);
      a[a[num].c[j]].pa = a[num].no;
    }
  }

  
  for (i=0; i<n; i++){
    if(a[i].pa == -1) a[i].depth =0;
  }
  
  if (n>1){
    j=0;
    while(1){
      for (i=0; i<n; i++){
	if(a[i].pa == a[a[i].pa].no)
	  a[i].depth = a[a[i].pa].depth+1;
      }
      j++;
      if (count == j) break;
    }
  }
  
  for (i=0; i<n; i++){
    printf("node %d: parent = %d, depth = %d, "
	   , a[i].no, a[i].pa, a[i].depth);
    
    if (a[i].pa == -1){
      printf("root, [");
      for (j=0; j<a[i].nch; j++){
	if (j == a[i].nch-1)
	  printf("%d", a[i].c[j]);
	else
	  printf("%d, ",a[i].c[j]);
      }
      printf("]\n");
    }
    
    else if (a[i].nch != 0){
      printf("internal node, [");
      for (j=0; j<a[i].nch; j++){
	if (j == a[i].nch-1)
	  printf("%d", a[i].c[j]);
	else
	  printf("%d, ",a[i].c[j]);
      }
      printf("]\n");
    }
    
    else printf("leaf, []\n");
  }

  for (i=0; i<n; i++)
   free(a[i].c);
  
  return 0;
}



Measured memory_bytes: 8108
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};

vector<ll> prime;

void setPrime() {
    for (ll i=2; i<=1000000; i++) {
        bool ok = true;
        for (int e: prime) {
            
            if (i%e==0) {
                ok = false;
                break;
            }
            if (e*e>i) {
                break;
            }
        }
        if (ok) {
            prime.push_back(i);
        }
    }
}

vector<ll> x;
void f() {
    rep(i, 1000) {
        if (i==0) x.push_back(0);
        else {
            x.push_back(x.back()+i);
        }
    }
}

int main(){
    ll n;
    cin >> n;
    setPrime();
    
    vector<ll> v;
    for (ll p: prime) {
        ll num = 0;
        while (n%p==0) {
            n /= p;
            num++;
        }
        if (num>0) {
            v.push_back(num);
        }
        if (n==1) break;
    }
    if (n!=1) v.push_back(1);

    ll ans = 0;
    f();

    for (ll e: v) {
        auto it = upper_bound(whole(x), e);
        it--;
        ans += (it-x.begin());
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll inf=100000000;
ll px[]=  { 1, 0, -1, 0 };
ll py[]=  { 0, 1, 0, -1 };
int main() {
    ios::sync_with_stdio(0);cin.tie(NULL); cout.tie(NULL);
    ll n,m,i,j,x,y,k,sx,sy;
    cin>>n>>m>>k;
    cin>>x>>y>>sx>>sy;
    
    ll dist[n+5][m+5];
    char arr[n+5][m+5];
    bool vis[n+5][m+5];
    memset(vis,false,sizeof(vis));
    
    for(i=0;i<=n;i++)
     for(j=0;j<=m;j++)
      dist[i][j]=inf;
      
    dist[x][y]=0;vis[x][y]=true;
    
    for(i=1;i<=n;i++)
     for(j=1;j<=m;j++)
      cin>>arr[i][j];
    
    queue< pair<ll,ll> > pq;
    
    pq.push(make_pair(x,y));
    
    while(!pq.empty()){
       pair<ll,ll> p=pq.front(); pq.pop();
       x=p.first, y=p.second;
       
       for(i=0;i<4;i++){
            for(j=1;j<=k;j++){
                ll dx= x +px[i]*j    , dy= y+ py[i]*j ;
                if(dx<1||dy<1||dx>n||dy>m)break;
                if(arr[dx][dy]=='@')break;
                if(vis[dx][dy] && dist[dx][dy]<=dist[x][y])break;
                if(vis[dx][dy])continue;
                vis[dx][dy]=true;
                dist[dx][dy]= 1 + dist[x][y];
                pq.push( make_pair(dx,dy));
            }    
       }
    }
    
    if(!vis[sx][sy])cout<<"-1";
    else cout<<dist[sx][sy];
}

Measured memory_bytes: 26080
from itertools import accumulate
from math import sqrt
from sys import stdin
MIN, MAX = 10**5+1, 0

def is_prime(x):
    if x == 2:
        return True

    if x < 2 or x % 2 == 0:
        return False

    i = 3
    while i <= sqrt(x):
        if x % i == 0:
            return False
        i = i + 2
    
    return True

Q = int(stdin.readline().rstrip())

LR = []
for i in range(Q):
    l, r = [int(_) for _ in stdin.readline().rstrip().split()]
    if l < MIN:
        MIN = l
    if r > MAX:
        MAX = r
    LR.append((l, r))

primes = [is_prime(i) and is_prime((i+1)//2) for i in range(MIN, MAX+1)]
primes = [0]+primes
primes = list(accumulate(primes))

for i in range(Q):
    print(primes[LR[i][1] - MIN+1] - primes[LR[i][0] - MIN])

Measured memory_bytes: 21096
from math import ceil
N = int(input())
CSF = [list(map(int, input().split())) for _ in range(N - 1)]

for j in range(N):
    if j == N - 1:
        print(0)
        exit()
    cc, ss, ff = CSF[j]
    t = ss + cc
    for i in range(j + 1, N - 1):
        c, s, f = CSF[i]
        if t <= s:
            t = s + c
        else:
            num = ceil(t / f)
            t = num * f + c
    print(t)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;

int main(){
  int a,b;
  cin >> a >> b;
  
  for (int i = 1; i <= 3; i++) {
    if (i != a && i != b) {
      cout << i;
      break;
    }
  }
  
  return 0;
}



Measured memory_bytes: 256