akhauriyash/Code-Regression huggingface dataset:
import sys, io, os, re
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor, ceil
from copy import copy, deepcopy
from collections import deque
from fractions import gcd
from functools import reduce
from itertools import groupby
from heapq import heapify, heappush, heappop

# sys.setrecursionlimit(5000)

n1 = lambda: int(sys.stdin.readline().strip())
nn = lambda: list(map(int, sys.stdin.readline().strip().split()))
f1 = lambda: float(sys.stdin.readline().strip())
fn = lambda: list(map(float, sys.stdin.readline().strip().split()))
s1 = lambda: sys.stdin.readline().strip()
sn = lambda: list(sys.stdin.readline().strip().split())
nl = lambda n: [n1() for _ in range(n)]
fl = lambda n: [f1() for _ in range(n)]
sl = lambda n: [s1() for _ in range(n)]
nm = lambda n: [nn() for _ in range(n)]
fm = lambda n: [fn() for _ in range(n)]
sm = lambda n: [sn() for _ in range(n)]

def array1(n, d=0): return [d] * n
def array2(n, m, d=0): return [[d] * m for x in range(n)]
def array3(n, m, l, d=0): return [[[d] * l for y in xrange(m)] for x in xrange(n)]
def linc(A, d=1): return map(lambda x: x + d, A)
def ldec(A, d=1): return map(lambda x: x - d, A)

X = n1()

if 400 <= X < 600: print(8)
elif X < 800:      print(7)
elif X < 1000:     print(6)
elif X < 1200:     print(5)
elif X < 1400:     print(4)
elif X < 1600:     print(3)
elif X < 1800:     print(2)
elif X < 2000:     print(1)


Measured memory_bytes: 72864
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
//#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
inline void out(int x){
	if(x>=10)out(x/10);
	putchar(x%10+'0');
}
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	int n,s=0;
	cin>>n;
	ll d;
	cin>>d;
	fo(i,0,n){
		ll x,y;
		cin>>x>>y;
		if(x*x+y*y<=d*d)s++;
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 3636
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        
        String s = sc.next();
        
        if(s.length() == a+b+1 && s.charAt(a) == '-'){
            for(int i = 0; i < s.length(); i++){
               char c = s.charAt(i);
               
               if(i != a && c == '-'){
                   System.out.println("No");
                   return;
               }
          }
          System.out.println("Yes");
          return;
        }
        
        System.out.println("No");
    }
}


Measured memory_bytes: 23252
n = io.read("*n")
t = {}
for i = 1, n do
  t[i] = io.read("*n") - i
end
table.sort(t)
mid = n % 2 == 0 and n / 2 or (n + 1) / 2
midval = t[mid]
sum = 0
for i = 1, n do
  sum = sum + math.abs(t[i] - midval)
end
print(sum)


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
const int mod= 1e9 + 7;

string s;
bool match(string t){
	if(s.size() < t.size()) return 0;
	for(int i=1; i<=t.size(); i++){
		if(t[t.size()-i] != s[s.size()-i]) return 0;
	}
	return 1;
}

int main(){
	cin >> s;
	while(s.size()){
		if(match("dream")){
			for(int j=0; j<5; j++) s.pop_back();
			continue;
		}
		if(match("dreamer")){
			for(int j=0; j<7; j++) s.pop_back();
			continue;
		}
		if(match("erase")){
			for(int j=0; j<5; j++) s.pop_back();
			continue;
		}
		if(match("eraser")){
			for(int j=0; j<6; j++) s.pop_back();
			continue;
		}
		puts("NO");
		return 0;
	}
	puts("YES");
	return 0;
}


Measured memory_bytes: 540
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_C
{
    class C059
    {
        static void Main(string[] args)
        {
            string[] s1 = Console.ReadLine().Split(' ');
            int n = int.Parse(s1[0]);
            string[] a= Console.ReadLine().Split(' ');

            long counter1 = 0, counter2 = 0;
            long[] S1 = new long[n+1]; //0+-+-+-
            long[] S2 = new long[n+1]; //0-+-+-+
            for (int i = 1; i <= n; i++)
            {
                long x = long.Parse(a[i-1]);
                long x1 = x, x2 = x;
                long n1 = S1[i - 1] + x;
                long n2 = S2[i - 1] + x;

                if (i % 2 == 0)
                {
                    if (n1 >= 0)
                    {
                        counter1 += n1 + 1;
                        x1 -= (n1 + 1);
                    }
                    if (n2 <= 0)
                    {
                        counter2 += -n2 + 1;
                        x2 += (-n2 + 1);
                    }
                }
                else
                {
                    if (n1 <= 0)
                    {
                        counter1 += -n1 + 1;
                        x1 += (-n1 + 1);
                    }
                    if (n2 >= 0)
                    {
                        counter2 += n2 + 1;
                        x2 -= (n2 + 1);
                    }
                }
                S1[i] = S1[i - 1] + x1;
                S2[i] = S2[i - 1] + x2;
            }

            long c = Math.Min(counter1, counter2);
            Console.WriteLine(c);
        }
    }
}

Measured memory_bytes: 29916
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;

int h,w,n;
int a[10010],mp[110][110];

int main()
{
    scanf("%d%d",&h,&w);
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    int k=1;
    for(int i=1;i<=h;i++)
    {
        int j;
        if(i%2==1) j=1;
        else j=w;
        while(j>=1&&j<=w)
        {
            while(a[k]<=0) k++;
            if(a[k]>0)
            {
                mp[i][j]=k;
                a[k]--;
                if(i%2==1) j++;
                else j--;
            }
        }
    }
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            printf("%d ",mp[i][j]);
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 384
N = gets.chomp.to_i
a = Array.new(N)
answer = 0
c = Array.new(N-1)

str = gets.split
for i in 0...N do
    a[i] = str[i].to_i
end

str = gets.split
for i in 0...N do
    answer += str[i].to_i
end

str = gets.split
for i in 0...N-1 do
    c[i] = str[i].to_i
end

for i in 0...N-1 do
    if a[i+1] == a[i] + 1
        answer += c[a[i]-1]
    end
end

puts answer

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

int n;
int data[20];

int abs(int x) {
  return (x > 0) ? x : -x;
}
int rec(int p, int A, int B) {
  static int min;
  if(p == 0) min = 999999;
  if(p == n) {
    int temp = abs(A-B);
    if(temp < min) min = temp;
    return 0;
  }
  rec(p+1, A+data[p], B);
  rec(p+1, A, B+data[p]);
  return min;
}

int main() {
  while(1) {
    cin >> n;
    if(n == 0) break;
    for(int i = 0; i < n; i++) {
      cin >> data[i];
    }
    cout << rec(0, 0, 0) << endl;
  }
  return 0;
}

Measured memory_bytes: 864
#include<bits/stdc++.h>
#define int long long
using namespace std;
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; }

template<typename T> class SegmentTree
{
 public:
    using Func=function<T(T,T)>;
    int sz;
    vector<T> data;
    Func func;
    T e;

    SegmentTree(int n,Func func,T e):func(func),e(e){
        sz=1;
        while(sz<n) sz*=2;
        data.assign(2*sz-1,e);
    }
    void update(int k,int x){
        k+=sz-1; data[k]=x;
        while(k>0){
            k=(k-1)/2;
            data[k]=func(data[2*k+1],data[2*k+2]);
        }
    }
    T get(int l,int r){
        // [l,r)
        T resL=e,resR=e;
        for(l+=sz-1,r+=sz-1;l<r;l/=2,r/=2){
            if((l&1)==0) resL=func(resL,data[l]);
            if((r&1)==0) resR=func(resR,data[--r]); 
        }
        return func(resL,resR);
    }
    T operator[](int k){ return data[k+sz-1]; }
};

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

    int N,Q; cin>>N>>Q;
    SegmentTree<int> seg(N,[](int a,int b){return min(a,b);},INT_MAX);
    while(Q--){
        int q,x,y; cin>>q>>x>>y;
        if(q==0) seg.update(x,y);
        else cout<<seg.get(x,y+1)<<endl;
    }
    return 0;
}


Measured memory_bytes: 4872
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	int n;cin>>n;
	int s[n],sum=0;
	bool chk=0;
	rep(i,n) {
		cin>>s[i];
		if(s[i]%10!=0) chk=1;
		sum+=s[i];
	}
	if(chk){
		if(sum%10!=0) cout<<sum<<"\n";
		else{
			int cnt=inf;
			rep(i,n){
				if(s[i]%10!=0) cnt=min(cnt,s[i]);
			}
			cout<<sum-cnt<<"\n";
		}
	}
	else cout<<0<<"\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
#define int long long
#define pb(x) push_back(x)
#define fi first
#define se second
#define mp(x,y) make_pair(x,y);
/*struct comp
{
    bool operator()()
    {
        
    }
};*/
int32_t main() {
    int t=1;
    //cin>>t;
    while(t--)
    {
     int x;
     cin>>x;
     int curr=100;
     int cnt=0;
     while(curr<x)
     {
         cnt++;
         curr+=(curr/100);
     }
     cout<<cnt;
     
    }
}

Measured memory_bytes: 3632
#include<stdio.h>

int main(void)
{
	int i,a=0,b;
	int n, m, k;
	char s[4], t[20];

	scanf("%s", &s);

for(int i=0;i<3;i++)
	if (s[i] == 'R') {
		a++;
	}
if (a == 0)
printf("0");
if (a == 1)
printf("1");
if(a==3)
printf("3");
if (a == 2) {
	if (s[1] == 'R') {
		printf("2");
	}
	else { printf("1"); }
}


	return 0;
}

Measured memory_bytes: 1644
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
#include <iomanip>
#include <limits>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
typedef priority_queue<ll> PQ_HIGH;
typedef priority_queue<ll,VL,greater<ll>> PQ_LOW;//昇順

void test(priority_queue<pair<ll,ll>> que){
  while(!que.empty()){
    cout<<que.top().first<<" "<<que.top().second<<endl;
    que.pop();
  }
}

int main(){
  int x,n;cin>>x>>n;
  VI p(n);
  REP(i,n){cin>>p[i];}
  int min=10000;
  int ans;
  for(int i=-10;i<110;i++){
    int key=0;
    for(int j=0;j<n;j++){
      if(i==p[j]){
        key=1;
        break;
      }
    }
    int tmp=abs(x-i);
    if(tmp<min&&key==0){
      min=tmp;
      ans=i;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3196
num = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for i in range(1, num + 1):
    judge = str(input())
    if judge == "AC":
        ac += 1
    elif judge == "WA":
        wa += 1
    elif judge == "TLE":
        tle += 1
    elif judge == "RE":
        re += 1
        
print("AC x " + str(ac))
print("WA x " + str(wa))
print("TLE x " + str(tle))
print("RE x " + str(re))

Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  vector<int> data(N);
  int ans = 0, count = 0, minnum = 1000000;
  for(int i = 0; i < N; i++) {
    cin >> data.at(i);
    ans += data.at(i);
    if(data.at(i) % 10 == 0) count++;
    else minnum = min(minnum, data.at(i));
  }
  if (ans % 10 == 0) ans -= minnum;
  if(count == N)cout << 0 << endl;
  else cout << ans << endl;
  return 0;
}


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

int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        vector<int> a;
        for(int j=0;j<s.size();j++)a.push_back(s[j]-'0');
        sort(a.begin(),a.end());
        int mi=0,ma=0;
        for(int j=0;j<s.size();j++){
            mi*=10;
            ma*=10;
            ma+=a[s.size()-1-j];
            mi+=a[j];
        }
        cout<<ma-mi<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 3176
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := intScanner()
	as := intSliceScanner(n)
	bs := make([]int, n)
	copy(bs, as)
	sort.Ints(bs)
	d := make(map[int]int)
	for i, v := range bs {
		d[v] = i
	}
	ans := 0
	for i, v := range as {
		if i%2 != d[v]%2 {
			ans++
		}
	}
	fmt.Println(ans / 2)
}


Measured memory_bytes: 9520
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cstring>
#include <climits>
using namespace std;
#define ll long long
#define FOR(i,n) for(int i=0;i<n;i++)
#define sz(x) (int)(x.size())
#define all(x) (x).begin(),(x).end()
template<typename tp> void read(tp &x) {cin >> x;}
template<typename tp, typename... Args> void read(tp& x, Args&... args) {read(x);read(args...);}
const int mxN = (int)1e5,INF = (int)1e9,MOD = (int)1e9+7;

void solve()
{
	int n;
	read(n);
	vector<int> a(n),b(n),c(n);
	FOR(i,n)
	{
			read(a[i]);
			c[i] = i+1;
	}
	FOR(i,n) read(b[i]);
	if(b == a)
	{
		cout << "0\n";
		return;
	}
	int count = 0,flag = 0;
	do
	{
		if(!flag && (c==a || c==b))
		{
			flag = 1,count++;
			continue;
		}
		if(flag)count++;
		if(flag && (c==a||c==b))
			break;
	}
	while(next_permutation(all(c)));
	cout << count-1 << '\n';
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int test = 1;
	//read(test);
	while(test--)
		solve();
	return 0;
}



Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
int main() {
    int x, n;
    cin >> n >> x;
    vector<int> ls(n,0);
    for (int i = 0; i < n; ++i) cin >> ls[i];
    int cnt=0, d = 0;
    for (; cnt < n; ++cnt) {
        d += ls[cnt];
        if (d > x) break;
    } 
    cout << cnt + 1 << endl; 
    return 0;
}

Measured memory_bytes: 256
# input
S = input()
T = input()

# solution
if len(set(S + T)) == 1 and len(S) < len(T):
    res = 'Yes'
else:
    res = 'No'
    for s in S:
        for t in T:
            if s < t:
                res = 'Yes'
                break

# output
print(res)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,s,n) for (int i = (s); i < n; ++i)
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> x(n);
  rep(i,0,n) cin >> x[i];
  int ans = 1000000000;
  rep(i,0,n-k+1) {
    int a = x[i], b = x[i+k-1];
    if (b < 0) {
      ans = min(ans, abs(a));
    } else if (a >= 0) {
      ans = min(ans, b);
    } else {
      ans = min(ans, b-a + min(abs(a), abs(b)));
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3712
#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#a,bの最小公倍数
def lcm(a, b):
    return a * b // gcd (a, b)
B = int(input())
L = list(map(int, input().split()))
d=L[0]
mod=1000000007
for i in range(B):
  d=lcm(d,L[i])
ans=0
for i in range(B):
  ans+=d//L[i]
print(ans%mod)


Measured memory_bytes: 4084
%:pragma GCC optimize("Ofast")
%:pragma GCC target("sse3","sse2","sse")
%:pragma GCC target("avx","sse4","sse4.1","sse4.2","ssse3")
%:pragma GCC target("f16c")
%:pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector")
%:pragma GCC diagnostic error "-fwhole-program"
%:pragma GCC diagnostic error "-fcse-skip-blocks"
%:pragma GCC diagnostic error "-funsafe-loop-optimizations"
%:pragma GCC diagnostic error "-std=c++14"

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>

using namespace std;

#define Whats(x) cout<<#x<<" is "<<x<<endl
#define Divhe() cout<<">>>>>>>>>>>>>>>"<<endl
#define Divshe() cout<<"<<<<<<<<<<<<<<<"<<endl
#define Oops() cout<<"!!!!!!!!!!!!!!!"<<endl

/*
-<Unlimited Blade Works>-
*/

const int N=5200;
const int MOD=1e9+7;

int Mul(int a,int b)
{
	unsigned long long x=(long long)a*b;
	unsigned xh=(unsigned)(x>>32),xl=(unsigned)x,d,m;
	asm
		(
		 "divl %4;\n\t"
		 :"=a"(d),"=d"(m)
		 :"d"(xh),"a"(xl),"r"(MOD)
		);
	return m;
}

int U(int x,int y)
{
	return ((x+=y)>=MOD)?(x-MOD):x;
}

void SU(int& x,int y)
{
	((x+=y)>=MOD)?(x-=MOD):0;
}

int D(int x,int y)
{
	return ((x-=y)<0)?(x+MOD):x;
}

void SD(int& x,int y)
{
	((x-=y)<0)?(x+=MOD):0;
}

int n;
vector<int> G[N];

int sz[N],dp[N][N],cm[N];

void Dfs(int u,int fa=0)
{
	sz[u]=dp[u][1]=1;
	for(int v:G[u])if(v!=fa)
	{
		Dfs(v,u);
		int sm=0;
		for(int i=2;i<=sz[v];i+=2)
			SD(sm,Mul(dp[v][i],cm[i]));
		static int x[N];
		int s=sz[u]+sz[v];
		for(int i=sz[u];i;--i)
			x[i]=Mul(dp[u][i],sm);
		for(int i=sz[u]+1;i<=s;++i)
			x[i]=0;
		for(int i=sz[u];i;--i)
			for(int j=sz[v];j;--j)
				SU(x[i+j],Mul(dp[u][i],dp[v][j]));
		for(int i=s;i;--i)
			dp[u][i]=x[i];
		sz[u]=s;
	}
}

int main()
{
	scanf("%d",&n);
	for(int i=1,u,v;i<n;++i)
	{
		scanf("%d%d",&u,&v);
		G[u].emplace_back(v);
		G[v].emplace_back(u);
	}

	cm[0]=1;
	for(int i=2;i<=n;i+=2)
		cm[i]=Mul(cm[i-2],i-1);

	Dfs(1);

	int ans=0;
	for(int i=2;i<=n;i+=2)
		SU(ans,Mul(dp[1][i],cm[i]));
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 102528
#include <bits/stdc++.h>
using namespace std;
#define MAXN 100000

int h[MAXN];
int dp[MAXN];
int n;

int main() {
	int i;
	scanf("%d",&n);
	for (i=0; i<n;i++) {
		scanf("%d",&h[i]);
	}
	dp[n-1]=0;
	dp[n-2]=abs(h[n-1]-h[n-2]);
	for (i=n-3; i>=0; i--) {
		dp[i]=min(abs(h[i]-h[i+1])+dp[i+1], abs(h[i]-h[i+2])+dp[i+2]);
	}
	
	printf("%d\n",dp[0]);
	return 0;
}

Measured memory_bytes: 4568
#include <iostream>
#include <vector>
#include <unordered_map>
#include <sstream>

using namespace std;

// https://atcoder.jp/contests/abc049/tasks/arc065_b

class UnionFind {
public:
  UnionFind(int n) : _parentRoad(n, -1), _parentRail(n, -1) {
  }

  int rootRoad(int x) {
    if (_parentRoad[x] < 0) return x;
    return _parentRoad[x] = rootRoad(_parentRoad[x]);
  }

  int rootRail(int x) {
    if (_parentRail[x] < 0) return x;
    return _parentRail[x] = rootRail(_parentRail[x]);
  }

  void uniteRoad(int x, int y) {
    x = rootRoad(x);
    y = rootRoad(y);
    if (x == y) return;
    if (sizeRoad(x) < sizeRoad(y)) swap(x, y);
    _parentRoad[x] += _parentRoad[y];
    _parentRoad[y] = x;
  }

  void uniteRail(int x, int y) {
    x = rootRail(x);
    y = rootRail(y);
    if (x == y) return;
    if (sizeRail(x) < sizeRail(y)) swap(x, y);
    _parentRail[x] += _parentRail[y];
    _parentRail[y] = x;
  }

  int sizeRoad(int x) {
    return -_parentRoad[rootRoad(x)];
  }

  int sizeRail(int x) {
    return -_parentRail[rootRail(x)];
  }

  void makeMap() {
    for (int i = 0; i < _parentRoad.size(); ++i) {
      stringstream ss;
      ss << rootRoad(i) << "_" << rootRail(i);
      _map[ss.str()]++;
    }
  }

  int numConnections(int x) {
    stringstream ss;
    ss << rootRoad(x) << "_" << rootRail(x);
    return _map[ss.str()];
  }

private:
  vector<int> _parentRoad;
  vector<int> _parentRail;
  unordered_map<string, int> _map;
};

int main() {
  int n, k, l;
  cin >> n >> k >> l;
  UnionFind uf(n);
  for (int i = 0; i < k; ++i) {
    int p, q;
    cin >> p >> q;
    uf.uniteRoad(p-1, q-1);
  }
  for (int i = 0; i < l; ++i) {
    int r, s;
    cin >> r >> s;
    uf.uniteRail(r-1, s-1);
  }
  uf.makeMap();
  for (int i = 0; i < n; ++i) {
    cout << uf.numConnections(i) << endl;
  }
  return 0;
}

Measured memory_bytes: 18028
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
#include<functional>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define erep(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
const int mod = 1e9+7;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
  string s;
  cin >> s;
  map<char, int> mp;
  rep(i, 0, s.size()) {
    if(!mp.count(s[i])) mp[s[i]] = 0;
    mp[s[i]]++;
  }
  for(auto ite : mp) {
    if(ite.second % 2 != 0) {
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";
}


Measured memory_bytes: 764
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999

int main(){
    int n,m;
    bool data[1000][1000]={};
    
    while(cin>>n&&n){
        rep(i,1000)rep(j,1000)data[i][j]=false;
        rep(i,n){
            int a,b;
            cin>>a>>b;
            data[a][b]=true;
        }
        cin>>m;
        rep(i,m){
            int a,b;
            cin>>a>>b;
            data[a][b]=true;
        }
        
        
        int dp[1002][1002];
        rep(i,1002)rep(j,1002)dp[i][j]=0;
        
        
        int maxi = 0;
        for(int i=999;i>=0;i--){
            for(int j=999;j>=0;j--){
                dp[i][j] = max({dp[i][j+1],dp[i+1][j],dp[i+1][j+1]+data[i][j],dp[i][j]});
                //            cout<<dp[i][j]<<endl;
                maxi = max(maxi,dp[i][j]);
            }
        }
        cout<<maxi<<endl;
    }
}

Measured memory_bytes: 7980
from functools import *
N, X = list(map(int, input().split(" ")))
xs = list(map(int, input().split(" ")))
xs = list(map(lambda x: X-x if X>x else x-X, xs))
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b) 
r = reduce(gcd, xs)
print(r)


Measured memory_bytes: 14748
#include <stdio.h>

int main(){

    int n, q, i, j;
    int cnt = 0;
    int once = 0;

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

    scanf("%d", &q);
    int T[q];
    for(i = 0; i< q; i++) scanf("%d", &T[i]);

    for(i = 0; i < q; i++){
        for(j = 0; j < n; j++){
            if(once == 0 && T[i] == S[j]){
                cnt++;
                break;
            }
        }
    }

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

    return 0;
}


Measured memory_bytes: 2144
#include<iostream>
#include<cmath>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, x, n) for (int i = x; i < (n); ++i)

using namespace std;

int main() {
    const double PI = 4 * atan(1);
    int R;
    cin >> R;

    cout << 2 * PI * R << endl;
    return 0;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
#include <iostream>
#include<string>
#include<cmath>
#include<vector>
#include<set>
typedef long long ll;
#define ss ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
using namespace std;

int main()
{
ss
ll n,t=0;
    cin>>n;
    string s;
    cin>>s;
    ll i=0,j=n-1;
    while(i<j)
    {
        if(s[i]=='R')
            i++;
       else if(s[j]=='W')
            j--;
        else t++,j--,i++;
    }
    cout<<t;
	return 0;
}


Measured memory_bytes: 3756
#入力受け取り

n, m, x = map(int, input().split())

#指定した回数リストを取り込む

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

#最小値を更新するため、適当に大きな値を設定

ans = 91912922191

#総当たりする場合の試行回数

for buy in range(2 ** n):

#M長の空リストを作成する

    C = [0] * m

#値段の合計値の受け皿

    cost = 0
 
#？？？
 
    for i in range(n):

#購入した場合は加算する

        if (buy >> i) & 1:
            cost += X[i][0]

#１番目からM番目の要素を空リストに加算していく
#Cは0～Mをリストに、リストXから取得する

            for j in range(1, m + 1):
                C[j - 1] += X[i][j]

#すべての理解度から一番小さなものを取得し、それがxを超えているか確認

    if min(C) >= x:

#小さい方をansに代入

        ans = min(ans, cost)

#値が初期値よりも小さければ出力させる

if ans < 91912922191:
    print(ans)
else:
    print(-1)

Measured memory_bytes: 9156
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE BangPatterns #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust, fromMaybe )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.IntMap.Lazy            as IML
import qualified Data.Map.Strict               as M
import           Data.Char
import qualified Data.Array.IArray as A
import qualified Data.Array.Unboxed as UA
import Data.Bits
import Control.Monad.State.Strict
import qualified Data.Array.ST as STA
import qualified Data.Array.IO as IOA
import qualified Data.Array.MArray as MA
import Control.Monad.ST
import System.IO (stdin)
import Control.Arrow
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as UV
import qualified Data.Vector.Generic as GV
import Data.Ix

debug = False

ts :: Show a => a -> a
ts a = if debug then traceShowId a else a


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- readInts
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- readInts
    return (a, b, c)

readTuple4 :: IO (Int, Int, Int, Int)
readTuple4 = do
    [a, b, c, d] <- readInts
    return (a, b, c, d)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las

data Hand = R | P | S deriving (Show, Eq,Ord, Ix)

winHand :: Char -> Hand
winHand 'r' = P
winHand 'p' = S
winHand 's' = R

counter :: (Ord a) => [a] -> M.Map a Int
counter = foldl' (flip $ M.alter (Just . maybe 1 (+1))) M.empty 

solve :: Int -> [Int] -> Bool
solve n as
    | all (==0) $ ts as = True
    | n `mod` 3 /= 0 = False
    | M.lookup 0 count == Just (n `div` 3) && length countL == 2 = True
    | length countL /= 3 = False
    | ts (isOk a b c) && an == divt && bn == divt && cn == divt = True
    | otherwise = False where
        count = counter as
        countL = ts $ M.toList count
        [(a, an), (b, bn), (c, cn)] = countL
        divt = n `div` 3 
    
isOk :: Int -> Int -> Int -> Bool
isOk a b c = a `xor` b == c || b `xor` c == a|| c `xor` a == b

main = do
    n <- readInt
    as <- readInts
    putStrLn $ if solve n as then "Yes" else "No"



Measured memory_bytes: 18740
//#include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<numeric>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<ctype.h>
#include <fstream>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}
int dy[4]={0,1,0,-1};
//----------program from here----------

int main(){
  int a=0,b=0,h=0;

  cin >> a >> b >> h;
  cout << a*h + (b-a)*h/2 << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        long n = Long.parseLong(sc.next());

        long result = 0;

        // 素数の場合
        if (isPrime(n)) {
            result = n - 1;

        } else {

            // 平方根が整数の場合
            double sqrt = Math.sqrt(n);
            if (sqrt - (int) sqrt == 0) {
                result = (int) sqrt * 2 - 2;

            } else {

                long preNum = 0;
                for (long i = 2; i <= n / 2 && result == 0; i++) {
                    if (n % i == 0) {
                        if (isPrime(n / i)) {
                            result = n / i + i - 2;

                        } else if (preNum * i == n) {
                            result = preNum + i - 2;
                        }
                        preNum = i;
                    }
                }
            }
        }

        System.out.println(result);
        sc.close();
    }

    public static boolean isPrime(long num) {
        if (num == 2) {
            return true;
        } else if (num < 2 || num % 2 == 0) {
            return false;
        }
        double sqrtNum = Math.sqrt(num);
        for (long i = 3; i <= sqrtNum; i += 2) {
            if (num % i == 0) {
                return false;
            }
        }
        return true;
    }
}


Measured memory_bytes: 23764
def judge(x):
  a=0
  b=0
  c=0
  d=len(x)
  for i in range(d):
    if x[i]=='3':
      a=1
    elif x[i]=='5':
      b=1
    else:
      c=1
      
  if a+b+c==3:
    return True
  else:
    return False

N=int(input())

nums=[['3', '5', '7']]
for i in range(8):
  temp=[]
  lastnums=nums[-1]
  for j in lastnums:
    temp+=[j+'3', j+'5', j+'7']
    
  nums.append(temp)
  
counter=0
nums=nums[2:]
for i in nums:
  for j in i:
    if int(j)<=N and judge(j)==True:
      counter+=1
      
print(counter)

Measured memory_bytes: 5236
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
typedef struct node{
	int x;
	int l;
}Node;
bool cmp(Node &x,Node &y){
		return x.x+x.l<y.x+y.l;
}
int main(){
	int n,x,l;
	cin>>n;
	Node *b=new Node[n];
	for(int i=0;i<n;++i){
		cin>>x>>l;
		b[i].x=x;
		b[i].l=l;
	} 
	sort(b,b+n,cmp);
	int ans=0;
	bool ok;
	bool okk[n]={false};
	okk[0]=true;
	int cur=-10000000;
	for(int i=0;i<n;++i){
		if(b[i].x-b[i].l>=cur){
			ans++;
			cur=b[i].x+b[i].l;
		}
	}
	cout<<ans<<endl;
	return 0;
} 


Measured memory_bytes: 1152
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define abs(x) ((x) > 0 ? (x) : -(x))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9 + 7
#define endl printf("\n")
typedef long long ll;

typedef struct { int id; char x[3]; } card;

int
main(int argc, char *argv[])
{
  int n; card a[40], b[40];
  scanf("%d\n", &n);
  rep(i, n){
    scanf("%s", a[i].x);
    a[i].id = i;
    b[i] = a[i];
  }

  card temp;
  
  //bubble sort
  for(int i = 0; i < n; i++){
    for(int j = n - 1; j > i; j--){
      if(a[j - 1].x[1] > a[j].x[1]){
	temp = a[j - 1];
	a[j - 1] = a[j];
	a[j] = temp;
      }
    }
  }

  rep(i, n - 1) printf("%s ", a[i].x);
  printf("%s\n", a[n - 1].x);
  int flag = 0;
  for(int i = 0; i + 1 < n; i++){
    if(a[i].x[1] == a[i + 1].x[1]){
      if(a[i].id > a[i + 1].id){
	printf("Not stable\n");
	flag++;
        break;
      }
    }
  }
  if(flag == 0) printf("Stable\n");

  int min;
  for(int i = 0; i < n; i++){
    min = i;
    for(int j = i + 1; j < n; j++){
      if(b[min].x[1] > b[j].x[1]){
	min = j;
      }
    }
    temp = b[i];
    b[i] = b[min];
    b[min] = temp;
  }

  rep(i, n - 1) printf("%s ", b[i].x);
  printf("%s\n", b[n - 1].x);
  flag = 0;
  for(int i = 0; i + 1 < n; i++){
    if(b[i].x[1] == b[i + 1].x[1]){
      if(b[i].id > b[i + 1].id){
	printf("Not stable\n");
	flag++;
        break;
      }
    }
  }
  if(flag == 0) printf("Stable\n");
  return 0;
}



Measured memory_bytes: 2148
#include<iostream>
using namespace std;
int main(void)
{
	int x,y,i;
	for(int i=1;i<=3000;i++)
	{
		cin>>x>>y;



		if(x==0 && y==0)
		{
			break;
		}

		else if(x<y || x==y)
		{
			cout<<x<<" "<<y<<endl;
		}
		else if(x>y)
		{
			cout<<y<<" "<<x<<endl;
		}

	}
	return 0;
}




Measured memory_bytes: 3044
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int64_t x[100], y[100];

int main()
{
    int n;
    cin >> n;
    rep(i, n)
    {
        cin >> x[i] >> y[i];
    }

    double result = 0;
    rep(i, n)
    {
        rep(k, n)
        {
            int64_t dirx = x[i] + x[k], diry = y[i] + y[k];

            int64_t cx1 = 0, cy1 = 0, cx2 = 0, cy2 = 0;
            rep(j, n)
            {
                int64_t inner = dirx * x[j] + diry * y[j];
                if (inner > 0) {
                    cx1 += x[j];
                    cy1 += y[j];
                    cx2 += x[j];
                    cy2 += y[j];
                } else if (inner == 0) {
                    int64_t p = diry * x[j] - dirx * y[j];
                    if (p > 0) {
                        cx1 += x[j];
                        cy1 += y[j];
                    } else {
                        cx2 += x[j];
                        cy2 += y[j];
                    }
                }
            }
            double d1 = sqrt(cx1 * cx1 + cy1 * cy1);
            double d2 = sqrt(cx2 * cx2 + cy2 * cy2);
            result = max(result, max(d1, d2));
        }
    }

    cout << setprecision(40) << result << endl;
    return 0;
}

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

int main(void)
{
    float x=0,y=10000,highest;
    while(scanf("%f",&highest)!=EOF)
    {
        if(x<highest)
            x=highest;
        if(y>highest)
            y=highest;
    }
    printf("%f\n",x-y);
    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(void)
{
	int n, i; 
	scanf("%d",&n);
	int v[n+1], c[n+1];
	for(i=0;i<n;i++){
		scanf("%d",&v[i]);
	}
	for(i=0;i<n;i++){
		scanf("%d",&c[i]);
	}
	int add = 0;
	for(i=0;i<n;i++){
		if(v[i]>c[i]){
			add += v[i]-c[i];
		}
	}
	
	printf("%d",add);
	return 0;
}

Measured memory_bytes: 128
// #include <bits/stdc++.h>
// using namespace std;
// typedef long long int64;
// typedef vector<int> vec;
// typedef vector<int64> vec64;
// #define db(x) cout << "> " << #x << ": " << x << "\n";
// #define ss cout << " ";
// #define ct(x) cout << x;
// #define nn cout << "\n";
// #define cts(x) cout << x << " ";
// #define ctn(x) cout << x << "\n";
// #define qr queries();
// void solve();
// void YN(bool b){if (b){ctn("YES");}else{ctn ("NO");}};
// void yn(bool b){if (b){ctn("Yes");}else{ctn ("No");}};
// void queries(){int n;cin >> n;while (n--)solve();}
// // // // // // // // // // // // // // // // // // // // // // // 
// /*                  TEMPLATE - VANILLA                         */
// // // // // // // // // // // // // // // // // // // // // // //
// int64 q, n;

// void solve(){
//     int n;
//     cin >> n;
//     vec arr (n);
//     for (int i = 0; i < n; i++){
//         cin >> arr[i];
//     }
//     for (int i = 0; i < n; i++){
//         int mx = i+1;
//         int mxindex = i+1;
//         for (int j = i+2; j< n; j++){
//             if (arr[i] < mx && arr[j] < mx){
//                 ctn("YES");
//                 cout << i+1 << " " << mxindex+1<< " " << j+1 << "\n";
//                 return;
//             }
//             if (arr[j] > mx){
//                 mx = arr[j];
//                 mxindex = j;
//             }
//         }
//     }
//     ctn("NO");
//     return;
// }


// int main(){
//     ios_base::sync_with_stdio(0);cin.tie(0);
//     int n;
//     qr;
//     return 0;
// }

#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
typedef vector<int> vec;
typedef vector<int64> vec64;
#define db(x) cout << "> " << #x << ": " << x << "\n";
#define ss cout << " ";
#define ct(x) cout << x;
#define nn cout << "\n";
#define cts(x) cout << x << " ";
#define ctn(x) cout << x << "\n";
#define qr queries();
void solve();
void YN(bool b){if (b){ctn("YES");}else{ctn ("NO");}};
void yn(bool b){if (b){ctn("Yes");}else{ctn ("No");}};
void queries(){int n;cin >> n;while (n--)solve();}
// // // // // // // // // // // // // // // // // // // // // // 
/*                  TEMPLATE - VANILLA                         */
// // // // // // // // // // // // // // // // // // // // // //
int64 q, n;

void solve(){

    return;
}


int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int a1,a2;
    cin >> a1 >> a2;
    ctn(6 - (a1 + a2));
    return 0;
}



Measured memory_bytes: 3592
s = input()

s1 = int(s[0] + s[1])
s2 = int(s[2] + s[3])
if 1 <= s1 <= 12 and 1 <= s2 <= 12:
    print('AMBIGUOUS')
elif 1 <= s1 <= 12:
    print('MMYY')
elif 1 <= s2 <= 12:
    print('YYMM')
else:
    print('NA')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define all(v) v.begin(),v.end()
using namespace std;

signed main(){
    int n;
    cin>>n;
    vi a(n);
    rep(i,n)cin>>a[i];
    int m;
    cin>>m;
    vi b(m);
    rep(i,m)cin>>b[i];
    cout<<lexicographical_compare(all(a),all(b))<<endl;
    return 0;
}


Measured memory_bytes: 3080
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        
        int n = scan.nextInt();
        int m = scan.nextInt();
        
        int[] a = new int[m];
        int[] b = new int[m];
        
        for(int i=0;i<a.length;i++)
        {
            a[i] = scan.nextInt();
            b[i] = scan.nextInt();
        }
        
        int count=0;
        for(int i=0;i<n;i++)
        {
            count=0;
            for(int j=0;j<a.length;j++)
            {
                if(a[j]==i+1)
                {
                    count++;
                }
                if(b[j]==i+1)
                {
                    count++;
                }
            }
            System.out.println(count);
        }
    }
}

Measured memory_bytes: 23636
// #pragma GCC optimize(3,"Ofast","inline")
// #pragma GCC optimize(2)
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <string>
#include <iostream>
#include <list>
#include <cstdlib>
#include <bitset>
#include <assert.h>
#include <time.h>
#include <iomanip>
// #define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
// char buf[(1 << 21) + 1], * p1 = buf, * p2 = buf;
// #define int long long
#define lowbit(x) (x & (-x))
#define lson root << 1, l, mid
#define rson root << 1 | 1, mid + 1, r
#define pb push_back
typedef unsigned long long ull;
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;
typedef std::vector<ll> VI;
#define rep(i, a, n) for (int i = a; i < n; ++i)
#define SZ(x) ((int)((x).size()))
#define bug puts("BUG")
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
const double eps = 1e-6;
template <class T>
inline void read(T &x)
{
    int sign = 1;char c = getchar();x = 0;
    while (c > '9' || c < '0'){if (c == '-')sign = -1;c = getchar();}
    while (c >= '0' && c <= '9'){x = x * 10 + c - '0';c = getchar();}
    x *= sign;
}
#ifdef LOCAL
    FILE* _INPUT=freopen("input.txt", "r", stdin);
    // FILE* _OUTPUT=freopen("output.txt", "w", stdout);
#endif
using namespace std;
const int maxn = 2e5 + 10;
char s[maxn];
ll dp[2][2019];
int main()
{
    scanf("%s", s);
    int now = 0, pre = 1;
    ll res = 0;
    for (int i = 0; s[i]; ++i)
    {
        swap(now, pre);
        memset(dp[now], 0, sizeof(dp[now]));
        for (int j = 0; j < 2019; ++j)
        {
            dp[now][(j * 10 + s[i] - '0') % 2019] += dp[pre][j];
        }
        dp[now][s[i] - '0']++;
        res += dp[now][0];
    }
    printf("%lld\n", res);
}

Measured memory_bytes: 3988
n, x = map(int, input().split())
if 1 < x < 2 * n - 1:
	print("Yes")
	others = list(range(1, x - 1)) + list(range(x + 2, 2 * n))
	for i in range(n - 2):
		print(others[i])
	print(x - 1)
	print(x)
	print(x + 1)
	for i in range(n + 1, 2 * n - 1):
		print(others[i - 3])
else:
	print("No")

Measured memory_bytes: 12536
n=int(input())
A=[]
for i in range(n):
  a=input()
  A.append(a)
m=int(input())
B=[]
for i in range(m):
  b=input()
  B.append(b)
count=[]
for i in range(len(set(A))):
  count.append(A.count(list(set(A))[i])-B.count(list(set(A))[i]))
print(max(count) if max(count)>0 else '0')

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

bool solve(int A, int V, int B, int W, int T)
{
	if (V <= W) {
		return false;
	}
	int dv = V - W;
	int dx = abs(A - B);

	return dx <= (long long)dv * T;
}

int main()
{
	int A, V, B, W, T;
	cin >> A >> V >> B >> W >> T;
	if (solve(A, V, B, W, T)) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n)-1;(i)>=0;(i)--)
#define all(v) (v).begin(),(v).end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000


typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef vector<pint> vpint;



int main(){
    string str;
    cin>>str;
    sort(all(str));
    if(str[0]==str[1] && str[2]==str[3] && str[0]!=str[2]){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 764
#include <stdint.h>
#include <stdio.h>

int64_t gcd(const int64_t x, const int64_t y)
{
  if (y == 0) {
    return x;
  } else if (x >= y) {
    return gcd(y, x % y);
  } else {
    return gcd(y, x);
  }
}

#if !defined(TEST)
int main(void)
{
  int32_t a, b;
  scanf("%d", &a);
  scanf("%d", &b);

  int32_t c = gcd(a, b);
  printf("%d\n", c);

  return 0;
}
#endif

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

using namespace std;

#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                        \
	sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
	{
sim > struct rge
{
	c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug
{
#ifdef LOCAL
	~debug()
	{
		cerr << endl;
	}
	eni(!=) cerr << boolalpha << i;
	ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c &)
	{
		ris;
	}
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define forn(i, n) for (ll i = 0; i < int(n); i++)
#define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define M_PI 3.14159265358979323846
#define EPS 1e-7

void solve()
{	
	ll n, k; cin >> n >> k;
	vector<int> a(n);
	forn(i, n) cin >> a[i];
	n -= k;
	ll res = 1;
	if (n % (k - 1) == 0)
		cout << res + n / (k - 1);
	else cout << res + n / (k - 1) + 1;
}

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


Measured memory_bytes: 3704
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #文字列入力の時は上記はerrorとなる。
    #ここにコード
    #input
    n = int(input())
    A = list(map(int, input().split()))

    #output
    #Aは予め降順に並べておく。
    #n = 2の時
        #s = A[0]
    #n = 3の時
        #まずA[0]を入れる。次にA[1]が入ってA[0]が点になる。次にA[2]が入ってA[1]が点になる。
        #s = A[0] + A[1]
    #n = 4の時
        #A[0]とA[1]の間にA[3]を入れる。
        #s = A[0] + A[1] + A[1]
    #n = 5の時
    A = sorted(A, reverse = True)
    answer = 0
    for i in range(n-1):
        answer += A[(i+1)//2]
    print(answer)    

    #N = 1のときなどcorner caseを確認！
if __name__ == "__main__":
    main()


Measured memory_bytes: 31404
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>

int main()
{
	unsigned long long N, K;
	std::cin >> N >> K;

	int count = 0;
	while (0 < N) {
		N /= K;
		++count;
	}

	std::cout << count << std::endl;

	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 10 20:59:09 2019

@author: doppe
"""

A, B = map(int, input().split())

max = A + B
if (max < A- B):
    max = A - B
if (max < A * B):
    max = A * B

print(max)

Measured memory_bytes: 2940
A = []
for i in range(3):
    A.append(list(map(int,input().split())))

N = int(input())
B = []
for i in range(N):
    B.append(int(input()))


for i in range(3):
    A.append([A[0][i] ,A[1][i] ,A[2][i]])
A.append([A[0][0] ,A[1][1] ,A[2][2]])
A.append([A[0][2] ,A[1][1] ,A[2][0]])
#print(A)
cnt1 = 0
for i in range(8):
    cnt = 0
    for j in range(3):
        for k in range(N):
            if A[i][j] == B[k]:
                cnt += 1
            if cnt == 3:
                cnt1 = 100
if cnt1 != 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064