akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#define MAX 10000
#define NIL -1

struct Node {
    int parent;
    int left;
    int right;
};

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d)
{
    if (u == NIL) return;
    D[u] = d;
    setDepth(T[u].left, d + 1);
    setDepth(T[u].right, d + 1);
}

int setHeight(int u)
{
    int h1 = 0, h2 = 0;
    if (T[u].left != NIL) {
        h1 = setHeight(T[u].left) + 1;
    }
    if (T[u].right != NIL) {
        h2 = setHeight(T[u].right) + 1;
    }
    return H[u] = ( h1 > h2 ? h1 : h2 );
}

int getSibling(int u)
{
    if (T[u].parent == NIL) return NIL;
    if (T[T[u].parent].left != u && T[T[u].parent].left != NIL) {
        return T[T[u].parent].left;
    }
    if (T[T[u].parent].right != u && T[T[u].parent].right != NIL) {
        return T[T[u].parent].right;
    }
    return NIL;
}

void print(int u)
{
    printf("node %d: ", u);
    printf("parent = %d, ", T[u].parent);
    printf("sibling = %d, ", getSibling(u));
    int deg = 0;
    if (T[u].left != NIL) deg++;
    if (T[u].right != NIL) deg++;
    printf("degree = %d, ", deg);
    printf("depth = %d, ", D[u]);
    printf("height = %d, ", H[u]);

    if (T[u].parent == NIL) {
        printf("root\n");
    } else if (T[u].left == NIL && T[u].right == NIL) {
        printf("leaf\n");
    } else {
        printf("internal node\n");
    }
}


int main(int argc, char const *argv[])
{
    int v, l, r, root = 0;
    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        T[i].parent = NIL;
    }

    for (int i = 0; i < n; i++) {
        scanf("%d %d %d", &v, &l, &r);
        T[v].left = l;
        T[v].right = r;
        if (l != NIL) T[l].parent = v;
        if (r != NIL) T[r].parent = v;
    }

    for (int i = 0; i < n; i++) {
        if (T[i].parent == NIL) {
            root = i;
        }
    }

    setDepth(root, 0);
    setHeight(root);

    for (int i = 0; i < n; i++) {
        print(i);
    }

    return 0;
}



Measured memory_bytes: 2748
import java.util.Scanner;
class Main{
public static void main (String[] args){
Scanner scan = new Scanner(System.in);
int a=scan.nextInt();
int b=scan.nextInt();
int c=scan.nextInt();
if(a==b||b==c||a==c){
System.out.println("No");
}else if(a>b||a>c){
System.out.println("No");
}else if(b>c){
System.out.println("No");
}else{
System.out.println("Yes");
}
}
}

Measured memory_bytes: 26144
#include <iostream>
#define LL long long
using namespace std;

LL x,y;

int main(){
    cin >> x >> y;

    LL res=(1LL<<50);
    if (y-x>=0) res=min(res,y-x);
    if (-x-y>=0) res=min(res,-y-x+1);
    if (x-y>=0) res=min(res,x-y+2);
    if (y+x>=0) res=min(res,x+y+1);
    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 384
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']
require 'prime'

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

a,b = inp
p a*b


Measured memory_bytes: 14388
N, K = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)

max = A.max

def _gcd(a, b)
  if a > b
    return a if b == 0

    _gcd(b, a % b)
  else
    return b if a == 0

    _gcd(a, b % a)
  end
end

def gcd(numbers)
  ans = numbers.first

  numbers[1..-1].each do |n|
    ans = _gcd(ans, n)
  end

  return ans
end

if K > max
  puts 'IMPOSSIBLE'
elsif K % gcd(A) == 0
  puts 'POSSIBLE'
else
  puts 'IMPOSSIBLE'
end


Measured memory_bytes: 8460
#include<set>
#include<map>
#include<ctime>
#include<queue>
#include<cmath>
#include<cstdio>
#include<vector>
#include<climits>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
int read(){
    int f=1,x=0;char s=getchar();   
    while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}  
    while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
    return x*f;
}
#define MAXN 100000
#define INF 0x3f3f3f3f
#define Mod int(1e9+7)
char A[MAXN+5],B[MAXN+5];
map<char,bool> Map;
int gcd(int a,int b){return !b?a:gcd(b,a%b);}
int main(){
	int n=read(),m=read(),f=0;
	scanf("%s",A);
	scanf("%s",B);
	LL tmp=gcd(n,m),L=1ll*n*m/tmp;
	for(int i=0;i<n;i++)
		if(1ll*m*i%n==0&&A[i]!=B[1ll*m*i/n]){
			f=1;
			break;
		}
	if(f)
		puts("-1");
	else
		printf("%lld\n",L);
	return 0;
}

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

int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    if(n%2==1){
        cout << "No"<<endl;
        return 0;
    }
    
    for(int i=0;i<n/2;i++){
        if(s[i]!=s[n/2+i]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 3624
#include<iostream>
using namespace std;
int main(){
  int H, W, h, w;
  cin >> H >> W;
  cin >> h >> w;
  int grid[20][20] = {0};
  
  //init
  for (int i = 0; i < H; i++){
  	for (int j = 0; j < W; j++){
      grid[i][j]  = 1;
    } 
  }
  
   //fill      
   for (int i = 0; i < h; i++){
  	for (int j = 0; j < W; j++){
      grid[i][j]  = 0;
    } 
  }
  
  for (int j = 0; j < w; j++){
  	for (int i = 0; i < H; i++){
      grid[i][j]  = 0;
    } 
  }
    
  //sum
  int ans = 0;
  for (int i = 0; i < H; i++){
  	for (int j = 0; j < W; j++){
      ans+=grid[i][j];
    } 
  }
  
  
  	cout << ans << endl;
  
  return 0;
}

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

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433;

template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const deque<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> inline void chmax(T& a, const T b){a=max(a,b);}
template <class T> inline void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
	ll N,A,B; cin >> N >> A >> B;
	ll ans = (N/(A+B))*A;
	N %= (A+B);
	ans += min(A,N);
	cout << ans << endl;	
	
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef complex<double> P;
static const double EPS = 1e-8;
static const int INF = (int)1e8;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) for (int i=0; i<(int)(n); ++i)
#define FOREQ(i,k,n) for (int i=(k); i<=(int)(n); ++i)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FIND(m,w) ((m).find(w)!=(m).end())
bool grid[200][200];
bool syogai[200][200];
int dx[6] = {1,1,0,-1,-1,0};
int dy[6] = {0,1,1,0,-1,-1};
int t,n;
int memo[200][200];
void dfs(int turn,int x,int y){
  if(turn==t+1) return ;
  if(memo[y+100][x+100]<=turn) return;
  grid[y+100][x+100] = true;
  memo[y+100][x+100] = turn;
  REP(r,6){
    int nx = x+dx[r];
    int ny = y+dy[r];
    if(syogai[ny+100][nx+100]==false){
      dfs(turn+1,nx,ny);
    }
  }
}

int main(void){
  while(cin>>t>>n){
    memset(grid,0,sizeof(grid));
    memset(syogai,0,sizeof(syogai));
    REP(y,200)REP(x,200)memo[y][x]=INF;
    if(t==0&&n==0) break;
    REP(i,n){
      int x,y;
      cin>>x>>y;
      syogai[y+100][x+100] = true;
    }
    int sx,sy;
    cin>>sx>>sy;
    dfs(0,sx,sy);
    int ans = 0;
    REP(fy,200)REP(fx,200)if(grid[fy][fx]){
      ans++;
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1108
#include<iostream>
#include<string>
#include<math.h>

using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (b - a == c - b)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
N = int(input())
S = [input() for _ in range(N)]

def solve() :
  T = []
  for s in S :
    open = 0
    close = 0
    for c in s :
      if c == ')' :
        if open > 0 :
          open -= 1
        else :
          close += 1
      else :
        open += 1
    T.append((open, close))
  
  if sum(op - cl for op, cl in T) != 0 :
    return 'No'
  
  inc = []
  dec = []
  for op, cl in T :
    if op >= cl :
      inc.append((cl, op))
    else :
      dec.append((op, cl))
      
  inc.sort()
  open = 0
  for cl, op in inc :
    if open >= cl :
      open += op - cl
    else :
      return 'No'
  
  close = 0
  dec.sort()
  for op, cl in dec :
    if close >= op :
      close += cl - op
    else :
      return 'No'
      
  return 'Yes'
      
print(solve())

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

"""
参考：https://www.hamayanhamayan.com/entry/2018/03/18/085108
　　　http://vartkw.hatenablog.com/entry/2016/12/02/002703
　　　https://ikatakos.com/pot/programming_algorithm/graph_theory/maximum_flow
・二部最大マッチング
・最大流アルゴリズム(Dinic法)
・まだ理解不十分な点はあると思うけど、初めて見た時よりは見慣れた。
"""

from collections import deque

class BipartiteMatching:

	def __init__(self, n, m):
		self.n = n
		self.m = m
		# ペアとして有りうる相手を格納する
		self.E = [[] * (n+m+2) for i in range(n+m+2)]
		# 決まったペアを格納する
		self.match = [0] * (n+m+2)
		# 距離(付け替え候補を決める時の深さみたいなものが入ってる)
		self.dist = [0] * (n+m+2)
	
	def bfs(self):
		que = deque()
		for i in range(1, self.n+1):
			# マッチングの決まっていないノードをキューに詰める
			if not self.match[i]:
				self.dist[i] = 0
				que.append(i)
			else:
				self.dist[i] = float('inf')
		self.dist[0] = float('inf')
		while len(que) != 0:
			u = que.popleft()
			if u != 0:
				for v in self.E[u]:
					if self.dist[self.match[v]] == float('inf'):
						self.dist[self.match[v]] = self.dist[u] + 1
						# 付け替えの候補になりうるノードがここで追加されていく
						que.append(self.match[v])
		# フローを流せるエッジが存在しなければ、dist[0]がINFのまま(Falseを返して終了)
		return self.dist[0] != float('inf')

	def dfs(self, u):
		if u != 0:
			for v in self.E[u]:
				if self.dist[self.match[v]] == self.dist[u] + 1:
					if self.dfs(self.match[v]):
						# ペア確定(あとで変わることもある)
						self.match[v] = u
						self.match[u] = v
						return True
			# 今回決められなかったノード
			self.dist[u] = float('inf')
			return False
		return True
	
	def add(self, a, b):
		b += self.n
		self.E[a+1].append(b+1)
		self.E[b+1].append(a+1)

	def whois(self, x):
		return self.match[x+1]-1

	def solve(self):
		for i in range(self.n+self.m+1):
			self.match[i] = 0
		res = 0
		while self.bfs():
			for i in range(1, self.n+1):
				# 前から順に繋げる所は繋いでいって、
				# もっといいのがあれば後から付け替える
				if not self.match[i] and self.dfs(i):
					res += 1
		return res

N = int(input())
aN, bN, cN, dN = [0] * N, [0] * N, [0] * N, [0] * N
# 赤い点
for i in range(N):
	aN[i], bN[i] = map(int, input().split())
# 青い点
for i in range(N):
	cN[i], dN[i] = map(int, input().split())

# (赤い点の数, 青い点の数)
bm = BipartiteMatching(N, N)
for i in range(N):
	for j in range(N):
		if aN[i] < cN[j] and bN[i] < dN[j]:
			# ペア候補として適切な組を追加していく(0-indexed)
			bm.add(i, j)
print(bm.solve())


Measured memory_bytes: 3444
import java.io.*;class Main{public static void main(String[]g)throws Exception{int i,j;boolean f;float l[]=new float[8];BufferedReader B=new BufferedReader(new InputStreamReader(System.in));for(String s;(s=B.readLine())!=null;System.out.println(f?"NO":"YES")){g=s.split(",");f=false;for(j=0;j<2;j++){for(i=0;i<8;i++)l[i]=Float.valueOf(g[(4*j+i)%8]);f|=((l[0]-l[2])*(l[5]-l[1])+(l[1]-l[3])*(l[0]-l[4]))*((l[0]-l[2])*(l[7]-l[1])+(l[1]-l[3])*(l[0]-l[6]))<0;}}}}


Measured memory_bytes: 24180
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
    int a,b;
     cin >> a >> b;
    cout << max(a-2*b, 0) << endl;
}

Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))
now = 1
cnt = 0
flag = 2
if n == 1 and A[0] == 1:
    flag = 0
elif n == 1 and A[0] != 1:
    flag = 1
elif len(set(A)) == 1 and A[0] == 1:
    cnt = n -1
elif  len(set(A)) == 1 and A[0] != 1:
    flag = 1
elif 1 not in A:
    flag = 1
else:
    for a in A:
        if a == now:
            now += 1
        else:
            cnt += 1

if flag == 0:
    print(0)
elif flag == 1:
    print(-1)
else:
    print(cnt)

Measured memory_bytes: 28188
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        String[] elm = br.readLine().split(" ");
        int n = Integer.parseInt(elm[0]);
        int m = Integer.parseInt(elm[1]);
        int l = Integer.parseInt(elm[2]);
        int[][] mata = new int[n][m];
        int[][] matb = new int[m][l];
        long[][] ans = new long[n][l];
        for(int i = 0; i < n ; i++){
            String[] line = br.readLine().split(" ");
            for(int j = 0; j < m ; j++){
                mata[i][j] = Integer.parseInt(line[j]);
            }
        }
        for(int i = 0; i < m ; i++){
            String[] line = br.readLine().split(" ");
            for(int j = 0; j < l ; j++){
                matb[i][j] = Integer.parseInt(line[j]);
            }
        }
        for(int i = 0; i < n ; i++){
            for(int j = 0; j < l ; j++){
                for(int k = 0; k < m; k++){
                    ans[i][j] += mata[i][k] * matb[k][j];
                }
                sb.append(ans[i][j]);
                if( j != l-1) sb.append(" ");
                //System.out.print(ans[i][j]+" ");
            }
            sb.append("\n");
            //System.out.println();
        }
        System.out.print(sb);
    }
}

Measured memory_bytes: 32752
N = input()

result = 0
for i, n in enumerate(N[::-1]):
    idx = len(N) - i
    if idx % 2 == 0:
        continue
    else:
        if i == 0:
            result += int(N) - (10 ** (idx - 1)) + 1
        else:
            result += 9 * (10 ** (idx - 1))

print(result)

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

ll arr[100010],dp[100010][100],dp2[100010];

ll solve(ll r,ll n,ll k)
{
	if(dp2[r]!=1e18)return dp2[r];
	if(r==n)return 0;
	for(ll j=1;j<=k and r+j<=n;j++)
	{
		dp[r][j]=min(dp[r][j],abs(arr[r+j]-arr[r])+solve(r+j,n,k));
		dp2[r]=min(dp2[r],dp[r][j]);
	}
	return dp2[r];
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n,k;
	cin>>n>>k;
	for(ll i=1;i<=n;i++)cin>>arr[i],dp2[i]=1e18;
	for(ll i=1;i<=n;i++)for(ll j=1;j<=k;j++)dp[i][j]=1e18;
	cout<<solve(1,n,k)<<"\n";
	return 0;
}

Measured memory_bytes: 87808
#include <stdio.h>
 
void print(char s[], int x, int y)
{
    int i;
    for (i = x; i <= y; i++)
        putchar(s[i]);
    putchar('\n');
}
 
void reverse(char s[], int x, int y)
{
    int i;
    for (i = 0; i <= (y - x) / 2; i++) {
        char c;
        c = s[x + i];
        s[x + i] = s[y - i];
        s[y - i] = c;
    }
}
 
void replace(char s1[], int x, int y, char s2[])
{
    int i;
    for (i = x; i <= y; i++) {
        s1[i] = s2[i - x];
    }
}
 
 
int main(void)
{
    char str[1001];
    scanf("%s", str);
 
    int q;
    scanf("%d", &q);
 
    int i;
    for (i = 0; i < q; i++) {
        char command[8];
        scanf("%s", command);
 
        int a, b;
        scanf("%d", &a);
        scanf("%d", &b);
 
        if (command[0] == 'p')
            print(str, a, b);
        else if (command[2] == 'v')
            reverse(str, a, b);
        else if (command[2] == 'p') {
                char p[1000];
                scanf("%s", p);
                replace(str, a, b, p);
        }
    }
        return 0;
}

Measured memory_bytes: 576
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    cout << (N+1)/2<<endl;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;
#define MOD 1000000007
#define MSG(a) cout << #a << " " << a << endl;
#define print(a) cout << a << endl;
template <class T, class C>
void chmax(T &a, C b)
{
    a > b ?: a = b;
}
template <class T, class C>
void chmin(T &a, C b) { a < b ?: a = b; }

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

// vector の出力
template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v)
{
    size_t last = v.size() - 1;
    for (size_t i = 0; i < v.size(); ++i)
    {
        out << v[i];
        if (i != last)
            out << " ";
    }
    return out;
}

struct UnionFind
{
    // data 中の負数の要素が根となる
    // 根は集合のデータ数を負数でもつ
    vector<int> data;
    UnionFind(int size) : data(size, -1) {}

    // マージする. すでに同じ集合なら false を返す
    bool merge(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        if (data[y] < data[x])
            swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }

    int root(int x)
    {
        return data[x] < 0 ? x : (data[x] = root(data[x]));
    }

    int size(int x)
    {
        return -data[root(x)];
    }
    bool issame(int x, int y)
    {
        return root(x) == root(y);
    }
};

struct edge
{
    int u, v, cost;
};

bool comp(const edge &e1, const edge &e2)
{
    return e1.cost < e2.cost;
}

int main()
{
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //////////////////////////////////////////
    // 参考: https://drken1215.hatenablog.com/entry/2019/02/14/124300
    int N;
    cin >> N;
    vector<int> x(N), y(N);
    rep(i, N)
    {
        cin >> x[i] >> y[i];
    }

    vector<edge> es;

    // x 方向で隣接しているノードを記録する
    vector<int> ids(N);
    iota(ids.begin(), ids.end(), 0); // range(0, N)

    // https://cpprefjp.github.io/lang/cpp11/lambda_expressions.html
    // [] は キャプチャ欄参照. lambda 式で x を参照できるようにしてる.
    sort(ids.begin(), ids.end(), [&](int i, int j) { return x[i] < x[j]; });
    rep(i, N - 1)
    {
        int u = ids[i], v = ids[i + 1];
        edge e = {u, v, x[v] - x[u]};
        es.push_back(e);
    }

    // y 方向で隣接しているノードを記録する
    // vector<int> ids(N);
    iota(ids.begin(), ids.end(), 0); // range(0, N)
    sort(ids.begin(), ids.end(), [&](int i, int j) { return y[i] < y[j]; });
    rep(i, N - 1)
    {
        int u = ids[i], v = ids[i + 1];
        edge e = {u, v, y[v] - y[u]};
        es.push_back(e);
    }
    sort(es.begin(), es.end(), comp);
    // クラスカル法
    // 閉路ができなければ追加していく.
    UnionFind uf(N);
    ll res = 0;
    rep(i, es.size())
    {
        edge e = es[i];
        // まだ接続されてないなら追加
        if (!uf.issame(e.u, e.v))
        {
            uf.merge(e.u, e.v);
            res += e.cost;
        }
    }
    print(res);

    return 0;
}


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

int main() {
    int N, R;
    cin >> N >> R;
    if(N < 10){
        R += 100 * (10 - N);
    }
    cout << R << endl;
    
    return 0;
}


Measured memory_bytes: 256
//url:
//problem name: Brick Break

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int f(int x) {
    if(x%10 == 0) return x;
    else return (x/10+1)*10;
} 

int main() {
    veci res(5);
    veci num(5);
    REP(i,5) {
        cin >> res[i];
        num[i] = i;
    }
    /*
    REP(i,5) {
        cout << f(res[i]) << endl;
    }
    */
    int ans = 10000;
    do {
        int tmp = 0;
        REP(i,4) tmp += f(res[num[i]]);
        tmp += res[num[4]];
        chmin(ans,tmp);  
    } while(next_permutation(num.begin(),num.end()));
    cout << ans << endl;
}

Measured memory_bytes: 256
T1,T2=[int(i) for i in input().split()]
A1,A2=[int(i) for i in input().split()]
B1,B2=[int(i) for i in input().split()]
if((B1-A1)*((B1-A1)*T1+(B2-A2)*T2)>0):
  print(0);
  exit();
if((B1-A1)*T1+(B2-A2)*T2==0):
  print("infinity")
  exit();
ans=(abs((B1-A1)*T1)//abs((B1-A1)*T1+(B2-A2)*T2))*2+1
if(abs((B1-A1)*T1)%abs((B1-A1)*T1+(B2-A2)*T2)==0):
  ans-=1
print(ans)



Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>

int main() {
  int D;
  std::cin >> D;

  switch(D-22) {
    case 0: std::cout << "Christmas Eve Eve Eve";
            break;
    case 1: std::cout << "Christmas Eve Eve";
            break;
    case 2: std::cout << "Christmas Eve";
            break;
    case 3: std::cout << "Christmas";
            break;
  }

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
	int x1=0, x2=0,k;
	scanf("%d", &x1);
	scanf("%d", &x2);
	k = x1 - x2;
	if (k > 0) {
		printf("%d\n", k);
	}
	else {
		printf("%d\n", -k);
	}
	return 0;
}


Measured memory_bytes: 2104
#include<iostream>
#define rep(i, n) for(int i=0; i<=n; i++)
#define print(c)  cout << c << endl;
using namespace std;

int main(void){
  int a, b, c, x;  cin>>a>>b>>c>>x;
  int ans=0;
  rep(i, a) rep(j, b) rep(k, c){
    if(500*i+100*j+50*k==x) ans++;
  }
  print(ans);
  return 0;
}


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

n = int(input())
G = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    a,b = a-1,b-1
    G[a].append([b,i])
ans = [None]*(n-1)

def rec(cur,color):
    count = 1
    for (to,j) in G[cur]:
        if count == color:
            count += 1
        ans[j] = count
        rec(to,count)
        count += 1
rec(0,0)
print(max(ans))
print(*ans,sep="\n")

Measured memory_bytes: 71048
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(bf.readLine());
		char[] k1 = "this".toCharArray();
		char[] k2 = "that".toCharArray();
		for(int i=0;i<4;i++){k1[i]=(char) (k1[i]-'a');k2[i]=(char) (k2[i]-'a');}
		while(n-->0){
			String k = bf.readLine();
			int a=0,b=0;
			for(a=1;a<26;a++){
				boolean f=false;
				if(a%2==0||a%13==0)continue;
				for(b=0;b<26;b++){
					char[] ka = new char[4];
					char[] kb = new char[4];
					for(int i=0;i<4;i++){ka[i]=(char)((k1[i]*a+b)%26+'a');kb[i]=(char)((k2[i]*a+b)%26+'a');}
					if(k.indexOf(String.valueOf(ka))>=0||k.indexOf(String.valueOf(kb))>=0){
						f=true;
						break;
					}
				}
				if(f)break;
			}
			int p = 0;
			while((26*p+1)%a>0)p++;
			int x = (26*p+1)/a;
			char[] c = k.toCharArray();
			for(int i=0;i<c.length;i++)if(c[i]>='a'&&c[i]<='z')c[i]=(char)((x*(c[i]-'a'+26-b))%26+'a');
			System.out.println(String.valueOf(c));
		}
	}
}

Measured memory_bytes: 9360
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
using namespace std;

const long long mod=1e9+7;

int main() {
  int N;
  cin >> N;
  vector<int> an(N);
  REP(n,N) cin >> an.at(n);

  vector<int> x(N);
  x.at(0) = an.at(0);
  REP(n,N-1) x.at(0) = x.at(0) + pow(-1,n+1)*an.at(n+1);

  REP(n,N-1) x.at(n+1) = an.at(n)*2 - x.at(n);
  x.at(N-1) = an.at(N-1)*2 - x.at(0);

  REP(n,N) cout << x.at(n) << " ";
  cout << endl;
}

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

int main() {
  string s;
  vector<int> count(26, 0);
  while (getline(cin, s)) {
    for (int i = 0; i < s.size(); ++i) {
      if (s.at(i) >= 'a' && s.at(i) <= 'z') count.at(s.at(i) - 'a')++;
      else if (s.at(i) >= 'A' && s.at(i) <= 'Z') count.at(s.at(i) - 'A')++;
    }
  }

  for (int i = 0; i < count.size(); ++i) {
    char c = 'a' + i;
    cout << c << " : " << count.at(i) << endl;
  }

  return 0;
}


Measured memory_bytes: 3028
#include<iostream>
#include<algorithm>
using namespace std;
main(){
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;

  int X = (n/a + (n%a>0?1:0))*b;
  int Y = (n/c + (n%c>0?1:0))*d;
  cout << min(X, Y) << endl;
}




Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+100;
const int mod = 1e9+7;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll llINF = 0x3f3f3f3f3f3f3f3f;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define fep(i,a,b) for(int i=(a);i>=(b);i--)
inline bool read(ll &num) {
    char in;bool IsN=false;
    in=getchar();
    if(in==EOF) return false;
    while(in!='-'&&(in<'0'||in>'9')) in=getchar();
    if(in=='-'){ IsN=true;num=0;}
    else num=in-'0';    
    while(in=getchar(),in>='0'&&in<='9'){
            num*=10,num+=in-'0';
    } 
    if(IsN) num=-num;
    return true;
}
int main(){
    //freopen("1.in", "r", stdin);
    string a,b;
    cin>>a>>b;
    int ans=0;
    for(int i=0;i<3;i++){
        if(a[i]==b[i]) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int i,j,A[101],a,swap=0,N;

  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<N;i++){
    for(j=N-1;j>i;j--){
      if(A[j]<A[j-1]){
	a=A[j];
	A[j]=A[j-1];
	A[j-1]=a;
	swap++;
      }
    }
  }
  for(i=0;i<N;i++){
    if(i>0){
      printf(" ");
    }
    printf("%d",A[i]);
  }
  printf("\n%d\n",swap);
  return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

vector<vector<ll>> xy(100001, vector<ll>());

bool used[100001];
ll costs[100001];

ll dfs(ll s){
  if(used[s])return costs[s];
  used[s]=true;

  ll t = 0;
  for(auto n:xy[s]){
    t = max(t, dfs(n)+1);
  }
  return costs[s]=t;
}

int main(){
  ll n, m;cin>>n>>m;
  xy.resize(n+1);
  rep(i, m){
    int x,y;cin>>x>>y;
    xy[x].push_back(y);
  }

  ll result=0;
  rep1(i, n) result = max(result, dfs(i));

  cout<<result<<endl;

  return 0;
}

Measured memory_bytes: 8576
N,Y=map(int,input().split())
for x in range(N+1):
    for y in range(N-x+1):
        if 10000*x+5000*y+1000*(N-x-y)==Y:
            print(x,y,N-x-y,sep=' ')
            break
    else:
        continue
    break
else:
    print('-1 -1 -1')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#pragma region
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << (#x) << "] = [", _print(x)
#else
#define debug(x...)
#endif
#pragma endregion
typedef long long ll;
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define sz(v) int((v).size())
#define int ll
#pragma region
#define f first
#define s second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#pragma endregion


string s, t;
unordered_map<char, set<int>> inv;
void solve()
{
    cin>>s>>t;
    for (int i = 0; i < sz (s); ++i)
    {
        inv[s[i]].insert(i);
    }

    int bf = -1;
    int ans = 0;
    int adding = 0;
    for (int i = 0; i <sz(t); ++i)
    {
        char tar = t[i];
        auto nxt = inv[tar].upper_bound(bf);
        if (nxt == inv[tar].end())
        {
            ans += sz(s);
            auto ad = inv[tar].upper_bound(-1);
            if (ad == inv[tar].end())
            {
                cout << "-1\n";
                return;
            }
            adding = *ad + 1;
            bf = *ad;
        }
        else
        {
            adding = *nxt + 1;
            bf = *nxt;
        }
    }
    cout << ans + adding << '\n';
}

signed main()
{
    int T = 1;
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << fixed << setprecision(22);
    // cin >> T;
    for(int i=1;i<=T;++i)
    {
        //cout << "Case #" << i << '\n';
        solve();
    }
    return 0;
}

Measured memory_bytes: 8488
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
typedef complex<double> cmplx;
const double pi = 3.14159265358979323846;
const int inf = (int)2e+9 + 2;
const int mod = (int)1e+9 + 7;
const double eps = 1e-8;
const int N = 200'000;

int n, m, k;
int a[N];
int b[N];
vector<int> g[N];
int was[N];
string s;

int dfs(int v, int mask)
{
    was[v] = 1;
    if (s[v] == 'A')
        mask |= 1;
    else
        mask |= 2;
    for (auto to : g[v]) {
        if (!was[to]) {
            mask |= dfs(to, mask);
        }
    }
    return mask;
}

void solve()
{
    cin >> n >> m >> s;
    for (int i = 0; i < m; ++i) {
        int x, y;
        cin >> x >> y;
        --x; --y;
        g[x].push_back(y);
        g[y].push_back(x);
        if (s[x] == 'A') ++a[y];
        else ++b[y];
        if (s[y] == 'A') ++a[x];
        else ++b[x];
    }
    queue<int> q;
    for (int i = 0; i < n; ++i) {
        if (!a[i] || !b[i]) {
            was[i] = -1;
            q.push(i);
        }
    }
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (auto to : g[v]) {
            if (s[v] == 'A') {
                --a[to];
                if (!a[to] && !was[to]) {
                    was[to] = -1;
                    q.push(to);
                }
            }
            else {
                --b[to];
                if (!b[to] && !was[to]) {
                    was[to] = -1;
                    q.push(to);
                }
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        if (!was[i] && dfs(i, 0) == 3) {
            cout << "Yes";
            return;
        }
    }
    cout << "No";
}

void precalc()
{
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    precalc();
    int test = 1;
    //cin >> test;
    for (; test; --test)
        solve();
    return 0;
}


Measured memory_bytes: 14544
LI = lambda: list(map(int, input().split()))

N, X, D = LI()


def sumeq(n):
    return n * (n + 1) // 2


def main():
    if D == 0:
        if X == 0:
            ans = 1
        else:
            ans = N + 1
        print(ans)
        return
    
    d = {}
    for i in range(N + 1):
        a = i * X + sumeq(i - 1) * D
        b = sumeq(N - 1) - sumeq(N - i - 1) - sumeq(i - 1)
        v = (a - a % D) // D
        if a % D in d:
            d[a % D].append((v, b))
        else:
            d[a % D] = [(v, b)]
    
    ans = 0
    for w in d.values():
        w.sort()
        ans += w[0][1] + 1
        x = w[0][0] + w[0][1]
        n = len(w)
        for i in range(1, n):
            r = w[i][0] + w[i][1]
            if x < w[i][0]:
                ans += w[i][1] + 1
            elif x < r:
                ans += r - x
            x = max(x, r)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 67636
def examA():
    A, B, C = LS()
    if A[-1]==B[0] and B[-1]==C[0]:
        ans = "YES"
    else:
        ans = "NO"
    print(ans)

import sys
import copy
import bisect
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examA()


Measured memory_bytes: 3444
from itertools import combinations


def main():
    N = int(input())

    max_x = (float("-inf"), 0)
    min_x = (float("inf"), 0)

    max_y = (0, float("-inf"))
    min_y = (0, float("inf"))

    max_xy = (float("-inf"), 0)
    min_xy = (float("inf"), 0)

    max_yx = (0, float("-inf"))
    min_yx = (0, float("inf"))

    for _ in range(N):
        x, y = map(int, input().split())

        if x > max_x[0]:
            max_x = (x, y)
        if x < min_x[0]:
            min_x = (x, y)
        if y > max_y[1]:
            max_y = (x, y)
        if y < min_y[1]:
            min_y = (x, y)
        if x + y > max_xy[0] + max_xy[1]:
            max_xy = (x, y)
        if x + y < min_xy[0] + min_xy[1]:
            min_xy = (x, y)
        if y - x > max_yx[1] - max_yx[0]:
            max_yx = (x, y)
        if y - x < min_yx[1] - min_yx[0]:
            min_yx = (x, y)

    ans = 0
    for a, b in combinations(
        (max_x, min_x, max_y, min_y, max_xy, min_xy, max_yx, min_yx), 2):
        ans = max(ans, abs(a[0] - b[0]) + abs(a[1] - b[1]))

    print(ans)


main()


Measured memory_bytes: 9272
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools
from collections import Counter

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

    q = int(input())
    primes_num, is_primes = primes(10**5+5)
    sums = []
    cnt = 0

    for i in range(0, 10**5+4):
        if i%2!=0:
            a = (i+1)//2
            if is_primes[i] and is_primes[a]:
                cnt += 1
        sums.append(cnt)

    for i in range(q):
        l,r = map(int, input().split())
        print(sums[r] - sums[l-1])

if __name__=="__main__":
    main()


Measured memory_bytes: 79416
#C
n,m=map(int,input().split())
L=[]
R=[]
for i in range(m):
    l,r=map(int,input().split())
    L.append(l)
    R.append(r)
L.sort()
R.sort()
if R[0]>=L[m-1]:
    print(R[0]-L[m-1]+1)
else:
    print(0)

Measured memory_bytes: 57432
import java.io.PrintWriter;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		String[] s = sc.next().split("");
		for (int i = 0; i < s.length; i += 2)
			out.print(s[i]);
		out.flush();
	}
}

Measured memory_bytes: 32176
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W; cin >> H >> W;
    rep(i, W+2) cout << "#";
    cout << endl;
    rep(i, H){
        string s; cin >> s;
        cout << "#" << s << "#" << endl;
    }
    rep(i, W+2) cout << "#";
    cout << endl;
    return 0;
}




Measured memory_bytes: 256
//Catchharsh
#include<bits/stdc++.h>
#define ll long long int 
#define ld long double
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define F first
#define S second
#define sz(x) x.size()
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define see(x) cout<<#x<<" = "<<x<<endl
const ll MOD = 1e9+7;
const ll INF = 1011111111;
const ll LLINF = 1000111000111000111LL;
const ld EPS = 1e-10;
const ld PI = 3.14159265358979323;
using namespace std;
ll power (ll base,ll exponent)
{
    ll ans=1;
    //base%=MOD;
    //exponent%=(MOD-1);
    while(exponent!=0)
    {
      if(exponent&1) ans=(1LL*ans*base);
      base=(1LL*base*base);
      exponent>>=1;
    }
    return ans;
}
ll dis[2005][2005];
ll f[2005];
int32_t main()
{   
     IOS;
     
     ll n,m,i,j,k;
     ll x,y;
     cin>>n>>x>>y;
     for(i=1;i<=x;i++)
     {
       for(j=i+1;j<=x;j++)
       {
         dis[i][j]=j-i;
       }
       for(j=x+1;j<=y;j++)
       {
         dis[i][j]=min(j-i,x-i+1+y-j);
       }
       for(j=y+1;j<=n;j++)
       {
         dis[i][j]=x-i+1+j-y;
       }
     }
     for(i=x+1;i<=y;i++)
     {
       for(j=i+1;j<=y;j++)
       {
         dis[i][j]=min(j-i,i-x+1+y-j);
       }
       for(j=y+1;j<=n;j++)
       {
        dis[i][j]=min(j-i,i-x+1+j-y);
       }
     }
     for(i=y+1;i<=n;i++)
     {
       for(j=i+1;j<=n;j++) dis[i][j]=j-i;
     }
   for(i=1;i<=n;i++)
   {
    for(j=1;j<=n;j++)
    {
       if(i==j) continue;
       else f[dis[i][j]]++;
    }
   }
   for(i=1;i<=n-1;i++)
    cout<<f[i]<<endl;

     
     cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';             
}

Measured memory_bytes: 31104
from itertools import accumulate
s = list(input().replace("A","1").replace("B","2"))
t = list(input().replace("A","1").replace("B","2"))
s = list(map(int,s))
t = list(map(int,t))
accs = [0]+list(accumulate(s))
acct = [0]+list(accumulate(t))
q = int(input())
abcd = [list(map(int,input().split())) for i in range(q)]
for a,b,c,d in abcd:
  if (accs[b]-accs[a-1])%3 == (acct[d]-acct[c-1])%3:
    print("YES")
  else:
    print("NO")

Measured memory_bytes: 81356
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(30);
#define ll long long
#define pi 3.14159265359
using namespace std;

int main()
{
    IOS;
    string s,t;
    cin>>s>>t;
    int c=0;
    for(int i=0;i<s.size();i++){
        if (s[i]!=t[i])
        c++;
    }
    cout<<c;
    return 0;
}


Measured memory_bytes: 3780
import java.util.*;

class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);

	int n = sc.nextInt();
	while(n!=0){

	    int[] num = new int[3];
	    int max = 0;
	    for(int i=0; i<3; i++){
		num[i] = sc.nextInt();
		if(num[i]>max){max = num[i];}
	    }

	    //String ans = "NO";
	    int sum = 0;
	    for(int i=0; i<3; i++){
		if(num[i]!=max){
		    sum += num[i]*num[i];
		}
	    }
	    String ans = "NO";
	    if(max*max==sum){ans = "YES";}



	    //int[] num2 = new int[3];
	    //num2[0] = num[0]*num[0];
	    //num2[1] = num[1]*num[1];
	    //num2[2] = num[2]*num[2];
	    //if(num2[0]==(num[1]+num[2])){ans="YES";}
	    //if(num2[1]==(num[0]+num[2])){ans="YES";}
	    //if(num2[2]==(num[0]+num[1])){ans="YES";}

	    System.out.println(ans);
	    n--;
	}
    }
}

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

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

    string s,alp="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    int n;
    cin>>n;
    cin>>s;
    map<char,char> mp;
    for(int i=0;i<alp.size();i++){
        mp[alp[i]]=alp[(i+n)%26];
    }
    for(int i=0;i<s.size();i++){
        s[i]=mp[s[i]];
    }
    cout<<s<<endl;
    return 0;
}

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

int main() {

    int n; string s; int k;
    cin >> n >> s >> k;
    char x = s[k - 1];
    for (int i = 0; i < n; i++) {
        if (s[i] != x) s[i] = '*';
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
const int INF = numeric_limits<int>::max();
const ll INFL = numeric_limits<ll>::max();


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

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

ll factorial(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) {
        res *= i;
    }
    return res;
}

int main()
{
    string s; cin >> s;
    int ans;
    if (s == "SAT")
        ans = 1;
    if (s == "MON")
        ans = 6;
    if (s == "TUE")
        ans = 5;
    if (s == "WED")
        ans = 4;
    if (s == "THU")
        ans = 3;
    if (s == "FRI")
        ans = 2;
    if (s == "SUN")
        ans = 7;
    cout << ans << endl;
    return 0;
}


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

namespace AtCoder
{

    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine().ToCharArray().ToList();
            var i = 0;
            var result = 0;
            while (i < S.Count - 1)
            {
                if ((S[i] == '0' && S[i + 1] == '1') || (S[i] == '1' && S[i + 1] == '0'))
                {
                    S.RemoveRange(i, 2);
                    i = Math.Max(0, i - 1);
                    result += 2;
                }
                else
                {
                    i++;
                }
            }
            Console.WriteLine(result);
        }

    }
}
//C

Measured memory_bytes: 13792
-- | Main entry point to the application.
module Main where
 
import Control.Applicative
import Control.Monad
import Data.List
import Data.Maybe

swap list a another
  | a == another = list
  | otherwise = list1 ++ [list !! another] ++ list2 ++ [list !! a] ++ list3 where
    list1 = take a list
    list2 = drop (succ a) $ take another list
    list3 = drop (succ another) list

moveminforward [] = []
moveminforward [a] = [a]
moveminforward list = swap list 0 $ fromJust $ elemIndex (minimum list) list

iter :: [Int] -> [Int] -> Int -> ([Int], Int)
iter [] sofar cnt = (sofar, cnt)
iter list@(x:xs) sofar cnt = iter (moveminforward xs) (x:sofar) (if xs /= (moveminforward xs) then succ cnt else cnt)

selsort ns = let (sortedlist, count) = iter (moveminforward ns) [] (if ns /= (moveminforward ns) then 1 else 0) in
    (reverse sortedlist, count)

-- | The main entry point.
main :: IO ()
main = do
    _ <- getLine
    ns <- concatMap (fmap (read :: String -> Int) . words) . lines <$> getContents
    -- let ns = [5,6,4,2,1,3]
    -- let ns = [5,2,4,6,1,3]
    -- let ns = [1,2,3,4,5]
    let (sortedlist, count) = selsort ns
    -- let (sortedlist, count) = selsort ns
    putStrLn $ unwords $ map show sortedlist
    print count

Measured memory_bytes: 4116
package main

import "fmt"

func main() {
	var K int
	fmt.Scan(&K)

	ans := 0
	for i := 1; i <= K; i++ {
		for j := 1; j <= K; j++ {
			for k := 1; k <= K; k++ {
				ans += GCD(i, GCD(j, k))
			}
		}
	}

	fmt.Println(ans)
}

func GCD(a, b int) int {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}


Measured memory_bytes: 1776