akhauriyash/Code-Regression huggingface dataset:
using System.Linq;
using System.Text;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Security.Cryptography.X509Certificates;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {

        const int BiggestMod = 1000000007;


        public static void Main()
        {

            int buf = int.Parse(Console.ReadLine());
            Console.WriteLine((buf % 1000 == 0 ? 0 : 1000 - (buf % 1000)));

        }
    }

}

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

class Program
{
    static void Main(string[] args)
    {
        var N = int.Parse(Console.ReadLine());

        var v = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

        v = v.OrderBy(x => x).ToArray();

        var ans = 0.0f;

        for (var i = 1; i < N; i++)
        {
            if(i == 1)
            {
                ans = (v[i - 1] + v[i]) / 2.0f;
                continue;
            }

            ans = (ans + v[i]) / 2;
        }

        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<=n;i++)
#define rep2(i,k,n) for(int i=k;i>=n;i--)
using namespace std;
const int N=2e5+7;
char s[N];
int main(){
	scanf("%s",s+1);
	int n=strlen(s+1);
	int now=0,cnt=0;
	rep(i,1,n){
		int op=s[i]=='S' ? 1 : -1;
		if(op==1)cnt++,now++;
		else{
			if(now)now--,cnt--;
			else cnt++;
		}
	} 
	printf("%d\n",cnt);
} 

Measured memory_bytes: 384
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		String str;
		Scanner stdIn = new Scanner(System.in);
		str = stdIn.nextLine();
		StringBuffer strbuf = new StringBuffer(str);
		String str_rev = strbuf.reverse().toString();

		if(str.equals(str_rev)){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 21972
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
			int count = 0;
			for (char c : br.readLine().toCharArray()) {
				if (c - '0' != 0) {
					count++;
				}
			}
			System.out.println(count);
		}
	}
}


Measured memory_bytes: 21460
arr = $stdin.gets.chomp.split("")
 
a = 0
b = 0
c = 0

for i in 0..2
  if arr[i] == "a"
    a += 1
  elsif
    arr[i] == "b"
    b += 1
  elsif
    arr[i] == "c"
    c += 1
  end
end
 
if a == 1 and b == 1 and c == 1
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 3836
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;


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

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<sstream>
using namespace std;

class Stack{
 private:
 int sp;
 int S[100];

 public:
 Stack()	{sp=0;}
 bool isFull() const 	{return(sp==100);}
 bool isEmpty() const	{return(sp==0);}
 void push(int d);
 int top();
 void pop();
};

void Stack::push(int d){
 if(isFull())
	return ;

 S[sp++]=d;
}
int Stack::top(){
 if(isEmpty())
	return -1;

 return S[sp-1];
}
void Stack::pop(){
 if(isEmpty())
	return;
 sp--;
}

int main(){
 Stack s;
 string expr;
 getline(cin,expr);
 istringstream is (expr);

 while(!is.eof()){
	string op;
	is>>op;

	int tmp1,tmp2;

	switch(op[0]){
	case'+':
		tmp1=s.top();s.pop();
		tmp2=s.top();s.pop();
		s.push(tmp2+tmp1);
		break;
	case'-':
		tmp1=s.top();s.pop();
		tmp2=s.top();s.pop();
		s.push(tmp2-tmp1);
		break;
	case'*':
		tmp1=s.top();s.pop();
		tmp2=s.top();s.pop();
		s.push(tmp2*tmp1);
		break;
	default:
		istringstream is2(op);
		is2>>tmp1;
		s.push(tmp1);
		break;
	}
 }
 cout<<s.top()<<endl;
 return 0;
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define N 200005
#define ll long long
using namespace std;
ifstream in("in.txt");
int main(){
    string s;
    cin>>s;
    if(s[2]==s[3] && s[4]==s[5]){
        cout<<"Yes";
    }
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
using System;

namespace MyProgram{
    class AtCoder{
        static void Main(string[] args){
            double[] input = Array.ConvertAll(Console.ReadLine().Split(' '),double.Parse);
            double N = input[0];
            double K = input[1];
            double sum = 0;
            double i,j;
            for(i = 1;i<=N;i++){
                j = 0;
                if(i<K){
                    while(Math.Pow(2,j)*i<K){
                        j+=1;
                    }
                }
                sum += 1/N *Math.Pow(0.5,j);
            }
            Console.WriteLine(sum);
        }
    }
}

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

const int nmax = 8;
bool graph[nmax][nmax];

int dfs(int v,int N,bool visited[nmax]){
	bool all_visited = true;
  for (int i=0;i<N;i++){
  	if(visited[i]==false)	all_visited =false;
  }
  if(all_visited) return 1;
  
  int ret=0;
  for(int i=0;i<N;i++){
  	if(graph[v][i]==false) continue;
    if(visited[i]) continue;
    
    visited[i] = true;
    ret += dfs(i,N,visited);
    visited[i] = false;
  }	
  return ret;
}

int main(){
  int N,M;
  cin>>N>>M;
  
  for(int i = 0;i<M;i++){
  	int A,B;
    cin>>A>>B;
    graph[A-1][B-1] = graph[B-1][A-1] = true;
  }
  
  bool visited[nmax];
  for(int i = 0;i<N;i++) visited[i] =false;
  
  visited[0] = true;
  cout<<dfs(0,N,visited)<<endl;
  return 0;
}

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


int main(){

    int a,b,k;
    int count=0;
    cin>>a>>b>>k;
    for(int i=min(a,b);i>0;i--){
        if(a%i==0&&b%i==0){
            count++;
            if(count==k){
                cout<<i<<endl;
                return 0;

            }
        }

    }


}


Measured memory_bytes: 3636
// C++ 14
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <math.h>

#define ll long long
#define Int ll
#define loop(__x, __start, __end) for(Int __x = __start; __x < __end; __x++)
#define loopdown(__x, __start, __end) for(Int __x = __start; __x > __end; __x--)
#define rep(__n) for(Int __x = 0; __x < __n; __x++)
#define span(__a,__x,__y) __a.begin()+__x,__a.begin()+__y
#define span_all(__a) __a.begin(),__a.end()
#define len(__x) (__x.size())
#define last(__x) (__x[__x.size()-1])

using namespace std;

struct Point {
  Int x, y;
  Point(Int x, Int y): x(x), y(y) {}
  Point(): x(0), y(0) {}

  Point operator + (Point v) { return Point(x + v.x, y + v.y); }
  Point operator - (Point v) { return Point(x - v.x, y - v.y); }
  bool operator == (const Point &v) const {
    return x == v.x && y == v.y;
  }
  bool operator< (const Point &p1) const {
    return x < p1.x && y < p1.y;
  }
};
ostream & operator << (ostream & out, Point const & v) {
  out << "Point(" << v.x << ", " << v.y << ')';
  return out;
}

istream & operator >> (istream & in, Point & v) {
  Int x, y;
  in >> x; in >> y; v.x = x; v.y = y;
  return in;
}

// Geometry

#define EPS 0.0000000001

class Vector2 {
public:
  double x, y;
  
  Vector2(double x = 0, double y = 0): x(x), y(y) {}
  
  Vector2 operator + (Vector2 v) { return Vector2(x + v.x, y + v.y); }
  Vector2 operator - (Vector2 v) { return Vector2(x - v.x, y - v.y); }
  Vector2 operator * (double k) { return Vector2(x * k, y * k); }
  Vector2 operator / (double k) { return Vector2(x / k, y / k); }
  
  double length() { return sqrt(norm()); }
  double norm() { return x * x + y * y; }
  double dot (Vector2 v) { return x * v.x + y * v.y; }
  double cross (Vector2 v) { return x * v.y - y * v.x; }
  
  bool operator < (const Vector2 &v) const {
    return x != v.x ? x < v.x : y < v.y;
  }
  
  bool operator == (const Vector2 &v) const {
    return fabs(x - v.x) < EPS && fabs(y - v.y) < EPS;
  }
};

ostream & operator << (ostream & out, Vector2 const & v) { 
  out<< "Vector2(" << v.x << ", " << v.y << ')';
  return out;
}

istream & operator >> (istream & in, Vector2 & v) { 
  double x, y;
  in >> x;
  in >> y;
  v.x = x;
  v.y = y;
  return in;
}

struct Item {Int v, w;};
ostream & operator << (ostream & out, Item const & v) {
  out << "Item(v=" << v.v << ", w=" << v.w << ')';
  return out;
}

Int N, W;
vector<Item> items;

void input() {
  cin >> N >> W;
  Int v, w;
  rep(N) {
    cin >> v >> w;
    items.push_back({ v, w });
  }
}

const Int MAX_N = 1001;
const Int MAX_W = 10001;
vector<vector<Int> > dp(MAX_N, vector<Int>(MAX_W, -1));

Int bit(Int n, Int cap) {
  if (n == N) return 0;
  if (cap <= 0) return 0;
  Int &cache = dp.at(n).at(cap);
  if (~cache) return cache;
  Int max_v = bit(n+1, cap);
  Item item = items.at(n);
  if (item.w <= cap) max_v = max(max_v, item.v + bit(n+1, cap-item.w));
  cache = max_v;
  return max_v;
}

void solve() {
  cout << bit(0, W) << endl;
}

int main() {
  input();
  solve();
  return 0;
}



Measured memory_bytes: 81140
import java.io.BufferedReader;
        import java.io.InputStreamReader;
        import java.util.Scanner;

public class Main {
    public static void main(String []args)
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
     /*   if(str.equals("2019/04/30"))
            System.out.println("Heisei");
        else
            System.out.println("TBD");*/
        int y = 2019;
        int m = 4;
        int d = 30;
        String words[]=str.split("/");
        int year  = Integer.valueOf(words[0]);
        int month = Integer.valueOf(words[1]);
        int day   = Integer.valueOf(words[2]);

            if(year<=y && month<=m && day <=d)
                System.out.println("Heisei");
            else
                System.out.println("TBD");

    }
}


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

using namespace std;

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

  long long a, b, x;
  cin >> a >> b >> x;

  long long res = b/x - a/x;
  cout << (a%x == 0 ? res + 1 : res) << endl;

  return 0;
}



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

using namespace std;
using ll = long long;
const int F = 26;
const int def = 1e6;


int n;
vector<int> c(F);
vector<vector<int>> a;


void init() {
    cin >> n;
    a.resize(n, vector<int>(F));
    for(int i = 0; i < F; i++)cin >> c[i];
    for(int i = 0; i < n; i++)for(int j = 0; j < F; j++)cin >> a[i][j];
}


vector<int> calc(int rng) {
    vector<int> last(F, -1);
    vector<int> ans;
    for(int i = 0; i < n; i++){ 
        vector<int> cur = a[i];
        for(int j = 0; j < F; j++)cur[j] += ((i - last[j]) * (c[j] + rng) * (rand() % 10 + 1));
        int ind =  max_element(cur.begin(), cur.end()) - cur.begin();
        last[ind] = i;
        ans.emplace_back(ind);
    }
    return ans;
}

int chack(vector<int> p) {
    int sum = 0;
    vector<int> last(F, -1);
    for(int i = 0; i < n; i++) {
        sum += a[i][p[i]];
        last[p[i]] = i;
        for(int j = 0; j < F; j++)sum -= (i - last[j]) * c[j];
    }
    return sum;
}


int main()
{
    srand((unsigned)time(NULL));   
    init();


    vector<int> ans;
    int M = 1.5 * 1e4, nax = -1e9;
    for(int I = 1; I <= M; I++) {
        int sed = rand() % (rand() % ((I/50) + 1) + 1) * ((rand() % 2)? 1 : -1);
        vector<int> cur = calc(sed);
        int k = chack(cur);
        if(k > nax) {
            nax = k;
            ans = cur;
        }
    }

    for(auto i : ans)cout << i + 1 << endl;
}

/*
satisfaction: 424801
score: 1424801
*/


Measured memory_bytes: 3692
#include <iostream>
#include <cstdio>
using namespace std;
int n,sum;
signed main()
{
        scanf("%d",&n);
        for (int i=1; i<=n; i++) {
                int x=0,y=0; scanf("%d %d",&x,&y);
                if (x==y) sum++;
                else sum=0;
                if (sum==3) {cout<<"Yes\n"; return 0;}
        }
        cout<<"No\n";
        return 0;
}


Measured memory_bytes: 3684
#include<iostream>
using namespace std;
int main(){
	int n;
	int b,f,r,v;
	int count[4][3][10];
	//initialize
	for(int i=0;i<4;i++)for(int j=0;j<3;j++)for(int k=0;k<10;k++)count[i][j][k]=0;
	//input n
	cin >> n;
	//loop n times
	for(;n!=0;n--){
		//input b,f,r,v
		cin >> b >> f >> r >> v;
		//do with input
		count[b-1][f-1][r-1]+=v;
	}
	//output
	for(int i=0;i<4;i++){
		for(int j=0;j<3;j++){
			for(int k=0;k<10;k++){
				cout<< " " << count[i][j][k];
			}
			cout<< endl;
		}
		if(i==3)break;
		for(int j=0;j<20;j++)
			cout<< "#";
		cout<< endl;
	}
	//return
	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>

#define GOAL_N 20
typedef long long ll;

ll pow2[30];
int sn[60];
int gn[60];
ll  w[60];

ll power2(int k){
        if(k == 0) return 1;
        ll ans = 1;
        for(int i = 0; i < k; i++) ans *= 2;
        return ans;
}
int main(){
        for(int i = 0; i < 30; i++) pow2[i] = power2(i);

        ll L;
        scanf("%lld",&L);

        int edge = 0;

        ll tmpL = L-1 ;
        int s = 1;
        for(int i = 1; i < GOAL_N-1; i++){
                sn[edge]=i; gn[edge]=i+1; w[edge]=0; edge++;
        }
        ll k = 0;
        char done = 0;
        while(tmpL >= 0){
                if(tmpL < k+pow2[s-1]){
                        sn[edge]=s; gn[edge]=GOAL_N; w[edge]=tmpL-k; edge++;
                        tmpL = tmpL-k-1;
                        s = 1;
                        k = 0;
                        done=1;
                }else{
                        if(!done){
                                sn[edge]=s; gn[edge]=s+1; w[edge]=pow2[s-1]; edge++;
                        }
                        //tmpL -= pow2[s-1];
                        k += pow2[s-1];
                        s += 1;
                        if(s == GOAL_N-1){
                                sn[edge]=s; gn[edge]=GOAL_N; w[edge]=tmpL-k; edge++;
                                tmpL = tmpL-k-1;
                                s = 1;
                                k = 0;
                                done=1;
                        }
                }
        }
        printf("%d %d\n",GOAL_N,edge);
        for(int i = 0; i < edge; i++) printf("%d %d %lld\n", sn[i],gn[i],w[i]);
}

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

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  int x,y;
  cin >> x >> y;
  if(x % y == 0){
    cout << "-1\n";
  }else{
    cout << x;
  }
}


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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair< int, int > pii;
typedef vector< int > vi;

vi graph[100001];

void solve() {
    int N, M; cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int A, B; cin >> A >> B;
        graph[A].push_back(B);
        graph[B].push_back(A);
    }
    vi par(N+1, 0), visited(N+1, 0);
    deque<int> q;
    q.push_back(1);
    visited[1] = 1;
    while (!q.empty()) {
        int curr = q.front(); q.pop_front();
        for (int next : graph[curr]) {
            if (!visited[next]) {
                visited[next] = 1;
                par[next] = curr;
                q.push_back(next);
            }
        }
    }
    cout << "Yes\n";
    for (int i = 2; i <= N; i++) cout << par[i] << "\n";
}
int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);
    solve();
}


Measured memory_bytes: 10224
#include <bits/stdc++.h>
using namespace std;
#define what_is(x) cerr << #x << " is " << x << endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
const int N = 1e5+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int n;
int main()
{
	IOS
	//freopen("input.txt", "r", stdin);
	cin >> n;
	cout << n*n*n << endl;

	return 0;
}


Measured memory_bytes: 256
/*
ABHIJEET BISWAS
CSE 4th SEM 
MNNIT ALLAHBAD
https://atcoder.jp/contests/dp/tasks/dp_p
*/

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1e18
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pli pair<long long,int>
#define pll pair<long long,long long>
#define MAX 1000009
#define pb push_back
#define mp map<int,int>
#define f first
#define s second
#define popi __builtin_popcount
#define popll __builtin_popcountll
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ld pi=2.0*acos(0.0);
int dp[100008][2];
vector<int> graph[100008]; 
int n;
void dfs(int v,int p)
{
	for(int u:graph[v])
	{
		if(u!=p)
		dfs(u,v);
	}
	dp[v][0]=dp[v][1]=1;
	for(int u:graph[v])
	{
		if(p!=u)
		{
			dp[v][0]=(1LL*dp[v][0]*((dp[u][1]+dp[u][0])%MOD))%MOD;
			dp[v][1]=((1LL*dp[v][1]*dp[u][0]))%MOD;
		}
	}
}
int main() {
	fastIO
	cin>>n;
	for(int i=0;i<n-1;i++)
	{
		int x,y;
		cin>>x>>y;
		graph[x].pb(y);
		graph[y].pb(x);
	}
	dfs(1,-1);
	cout<<(dp[1][0]+dp[1][1])%MOD<<endl;
	return 0;
}

Measured memory_bytes: 13440
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

//Main
const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

var n int
var s string

func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()
	s = nextStr()

	fmt.Println(strings.Count(s, "ABC"))

}


Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
int main()
{
    int n,num[1100],i=0,j,k;
    memset(num,0,sizeof(num));
    cin>>n;
    if(!n)
    {
        cout<<0<<endl;
        return 0;
    }
    while(n!=0)
    {
        num[i]=n%(-2);
        n/=(-2);
        i++;
    }
    k=i;
    for(j=0;j<i;j++)
    {
        if(num[j]==-1)
        {
            if(j==i-1)
                i++;
            num[j]=1;
            num[j+1]++;
        }
        if(num[j]==2)
        {
            if(j==i-1)
                i++;
            num[j]=0;
            num[j+1]--;
        }
        if(num[j]==-2)
        {
            if(j==i-1)
                i++;
            num[j]=0;
            num[j+1]++;
        }
    }
    for(j=i-1;j>=0;j--)
        cout<<num[j];
    cout<<endl;
    return 0;
}


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

a = input()

if a.upper() == a:
	print("A")
else:
	print("a")

Measured memory_bytes: 9968
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI acos(-1.0)
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  string s;cin>>s;
  int l=s.size();
  string T;
  REP(i,l){
    if(s[i]=='0')T+='0';
    if(s[i]=='1')T+='1';
    if(s[i]=='B' && T.size()>=1)T=T.substr(0,T.size()-1);
  }
  P(T);
  return 0;
}


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

using namespace std;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 2e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define debug(x) cout << #x << ":" << x << endl;
#define debug2(x) for(auto a : x) cout << a << " "; cout << endl;

vector<pii> around = {MP(1, 0), MP(-1, 0), MP(0, 1), MP(0, -1)};

//------------------------------------------------------

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

    ll n;
    cin >> n;
    ll mount[n]; //確定したときは山の高さ、不確定のときは（最大値）+INF を入れる
    ll t[n], a[n];
    rep(i, n) cin >> t[i];
    rep(i, n) cin >> a[i];

    ll before = -1, cnt = 0;

    rep(i, n) {
        if (before < t[i]) { //更新
            mount[i] = t[i];
            before = t[i];
        } else {
            mount[i] = t[i] + INF;
        }
    }

    before = -1;
    for (int i = n - 1; i >= 0; --i) {
        if (before < a[i]) { //更新
            if (mount[i] > INF) { //まだ未確定
                ll m = mount[i] - INF;
                if (a[i] <= m) mount[i] = a[i];
                else goto finish;
            } else {
                if (a[i] != mount[i]) goto finish;
            }
            before = a[i];
        } else {
            if (mount[i] > INF) { //まだ未確定
                ll m = mount[i] - INF;
                mount[i] = min(m, a[i]) + INF;
            } else {
                if (mount[i] > a[i]) goto finish;
            }
        }
    }

    cnt = 1;

    rep(i, n) {
        if (mount[i] < INF) continue;
        ll m = mount[i] - INF;
        cnt = cnt * m % MOD;
    }

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



Measured memory_bytes: 2560
program abc68
 implicit none
 integer(8)::N,ia,ib,c=0
 integer(8),allocatable::a(:),b(:)
 read(*,*)N
 allocate(a(N),b(N))
 do ia=1,N
  read(*,*)a(ia),b(ia)
 end do
 do ib=1,N-2
  if(a(ib)==b(ib).and.a(ib+1)==b(ib+1).and.a(ib+2)==b(ib+2))then
   c=1
   exit
  end if
 end do
 if(c==1)then
  print'(a)',"Yes"
 else
  print'(a)',"No"
 end if
 deallocate(a,b)
end program abc68

Measured memory_bytes: 2932
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
	int n,m,k,nn,u=0,t,i; int a[10000];
	scanf("%d%d%d",&n,&m,&k);
	if(n>m)
	{
		t=n;
		n=m;
		m=t;
	}
	for(i=m;i>=1;i--)
	{
		if(n%i==0&&m%i==0)
		a[u++]=i;
	}
	printf("%d\n",a[k-1]); 
	
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int ans = 0;
  REP(i, N) {
    lli p;
    cin >> p;
    while (p % 2 == 0) {
      p /= 2;
      ans++;
    }
  }
  cout << ans << "\n";
}

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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    for (int i = 0; i < N; i++)
        cin >> h[i];
    sort(h.begin(), h.end());

    int res = 1000000000;
    for (int i = 0; i < N - K + 1; i++)
        res = min(res, h[i + K -1] - h[i]);

    cout << res << endl;
    return 0;
}

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

void addEdge(vector<int> g[],int x,int y)
{
	g[x].push_back(y);
	g[y].push_back(x);
}
void bfs(vector<int> g[],int val,int visited[],int output[])
{
	queue<int> q;
	
	q.push(val);
	visited[val]=1;
	
	while(!q.empty())
	{
		val=q.front();
		q.pop();
		for(int i=0;i<g[val].size();i++)
		{
			int p=g[val][i];
			if(visited[p]==0)
			{
				if(output[p]==0)
				output[p]=val;
				q.push(g[val][i]);
				visited[p]=1;
			}
		}
	}
}

int main()
{
	int n,m,a,b;
	int flag=1;
	cin>>n>>m;
	vector<int> g[n+1];
	int visited[n+1]={0};
	for(int i=1;i<=m;i++)
	{
		cin>>a>>b;
		addEdge(g,a,b);
	}
	int output[n+1]={0};
	bfs(g,1,visited,output);
	for(int i=2;i<=n;i++)
	{
		if(output[i]==0)
		{
			flag=0;
			break;
		}
//		cout<<output[i]<<endl;
	}
	if(flag!=0)
	{
		cout<<"Yes"<<endl;
		for(int i=2;i<=n;i++)
		cout<<output[i]<<endl;
		
	}
	else cout<<"NO"<<endl;
	
}

Measured memory_bytes: 10860
import sys
from collections import defaultdict
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

N, M = map(int, input().split())
AB = [[int(x) for x in input().split()] for _ in range(M)]
PATH = [[] for _ in range(N+1)]

for a, b in AB:
    PATH[a].append(b)
    PATH[b].append(a)

color = [None] * (N+1)
color[1] = 0
q = deque([1])

while q:
    x = q.popleft()
    for y in PATH[x]:
        if color[y] is None:
            color[y] = 1 - color[x]
            q.append(y)

bl = all([color[a] != color[b] for a, b in AB])

ans = 0
if bl:
    x = sum(color[1:])
    y = N - x
    ans = x * y - M
else:
    ans = (N * (N-1) // 2) - M

print(ans)


Measured memory_bytes: 35124
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> PII;
typedef pair<ll,ll> Pll;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef pair<ll,ll>P;
#define N  1000000+10
#define M  4000000+10
#define INF 1e9
#define fi first
#define se second
#define MP make_pair
#define pb push_back
#define pi acos(-1)
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define per(i,a,b) for(int i=(int)a;i>=(int)b;i--)
#define lowbit(x) x&(-x)
#define Rand (rand()*(1<<16)+rand())
#define id(x) ((x)<=B?(x):m-n/(x)+1)
#define ls p<<1
#define rs p<<1|1
#define fors(i) for(auto i:e[x]) if(i!=p)

const int MOD=1e9+7,inv2=(MOD+1)/2;
int dx[4]= {-1,1,0,0};
int dy[4]= {0,0,-1,1};



int read()
{
  int v=0,f=1;
  char c=getchar();
  while(c<48||57<c)
  {
    if(c=='-') f=-1;
    c=getchar();
  }
  while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
  return v*f;
}

ll readll()
{
  ll v=0,f=1;
  char c=getchar();
  while(c<48||57<c)
  {
    if(c=='-') f=-1;
    c=getchar();
  }
  while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
  return v*f;
}

int main()
{


  ll a=readll();
  ll b=readll();
  ll x=readll();
  ll s=0;
  if(a==0&&b==0)
    s=1;
  else if(a==0)
    s=b/x+1;
  else s=b/x-(a-1)/x;

  printf("%lld\n",s);
  return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
	Scanner s = new Scanner(System.in);
	while(s.hasNext()) {
	    int N = s.nextInt();
	    if(N == 0) break;
	    int[] a = new int[N];
	    int[] b = new int[N];
	    String message = s.next();
	    char[] str = message.toCharArray();
	    for(int i = 0; i < N; ++i) {
		a[i] = s.nextInt(); b[i] = s.nextInt();
		--a[i]; --b[i];
	    }
	    for(int i = N-1; i >= 0; --i) {
		int d = Math.abs(a[i]-b[i]);
		str[a[i]] = (char)((str[a[i]]-'a'+d)%26+'a');
		str[b[i]] = (char)((str[b[i]]-'a'+d)%26+'a');
		char t = str[a[i]];
		str[a[i]] = str[b[i]];
		str[b[i]] = t;
	    }
	    System.out.println(String.valueOf(str));
	}
    }
}

Measured memory_bytes: 0
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	for (int n; cin >> n&&n;) {
		vector<int> a(n);
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		vector<int> M(n);
		for (int i = 0; i < n; i++) {
			M[i] = a[i];
			int temp = a[i];
			for (int j = i + 1; j < n; j++) {
				temp += a[j];
				M[i] = max(M[i], temp);
			}
		}
		cout << *max_element(ALL(M)) << endl;
	}
	return 0;
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  for(int i=1;i<s.size();i++){
    string ans=s.substr(0,s.size()-i);
    bool ok=true;
    if((ans.size())%2==0){
      for(int i=0;i<(ans.size())/2;i++){
        if(ans.at(i)!=ans.at(i+(ans.size())/2)){
          ok=false;
        }
      }
      if(ok){
        cout<<ans.size()<<endl;
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_map>
#define lol(i,n) for(ll i=0;i<n;i++)
#define mod 1000000007
#define mul(a,b) a=(a*b)%mod;
typedef long long ll;

using namespace std;
ll po(ll x){
    ll res=1;
    for(ll y=2;x;x>>=1,y=y*y%mod){
	if(x&1)res=res*y%mod;
    }
    return res;
}
ll mo(ll x){
    x%=mod;
    if(x<0)x+=mod;
    return x;
}
typedef pair<ll,ll> P;
#define N 110
vector<ll> v[N];
ll n,f[N],g[N],l[N],r[N],w[N],u[N],h[N],m;
ll ans;
void func(ll x){
    ll len=r[x]-l[x]-1;
    if(len==1){
	mul(ans,po(w[x]));
	f[x]=g[x]=0;
	return;
    }
    ll fm=1,gm=1,sum=0;
    for(auto c:v[x]){
	func(c);
	if(r[c]-l[c]-1==1)continue;
	sum+=r[c]-l[c]-1;
	fm=mo(fm*f[c]);
	gm=mo(gm*(2*f[c]+g[c]));
    }
    if(sum==0){
	f[x]=mo(po(w[x]));
	g[x]=mo(po(len)-2);
	return;
    }
    f[x]=mo(fm*po(w[x]));
    g[x]=mo(gm*po(len-sum));
    g[x]=mo(g[x]-2*fm);
}
int main(){
    cin>>n;
    if(n==1){
	cin>>n;
	cout<<po(n)<<endl;
	return 0;
    }
    lol(i,n)cin>>h[i];
    unordered_map<ll,vector<ll> >mas;
    lol(i,n){
	mas[h[i]].push_back(i);
    }
    sort(h,h+n);
    set<ll> st; st.insert(-1); st.insert(n);
    m=1,l[0]=-1,r[0]=n,w[0]=u[0]=h[0];
    lol(i,n){
	if(i&&h[i-1]==h[i])continue;
	for(auto x:mas[h[i]]){
	    auto il=st.lower_bound(x); il--;
	    ll L=*il;
	    auto ir=st.upper_bound(x);
	    ll R=*ir;
	    if(l[m-1]==L&&r[m-1]==R)continue;
	    l[m]=L,r[m]=R,u[m]=w[m]=h[i],m++;
	}
	for(auto x:mas[h[i]])st.insert(x);
    }
    lol(i,m){
	for(ll j=i-1;~j;j--){
	    if(l[j]<=l[i]&&r[i]<=r[j]){
		v[j].push_back(i);
		w[i]=u[i]-u[j];
		break;
	    }
	}
    }
    ans=1;
    func(0);
    cout<<mo(ans*(f[0]+g[0]))<<endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = a;i < n;i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main(){
	ll n,a,b,memo = 0;
  	cin >> n >> a >> b;
  	ll d[n];
  
  	rep(i,0,n){
    	cin >> d[i];
      	if(i > 0){
         	memo += min((d[i]-d[i-1])*a,b);
        }
    }
  
  	cout << memo << endl;
  
  
	return 0; 
}


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

const int N = 1010;

int n;
char c[N][N];

void NO() {
	cout << -1;
	exit(0);
}

void color(int x, int y) {
	c[x][y] = c[x][y + 1] = char('a');
	c[x][y + 2] = c[x + 1][y + 2] = char('b');
	c[x + 2][y + 1] = c[x + 2][y + 2] = char('c');
	c[x + 1][y] = c[x + 2][y] = char('d');
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	if (n == 2)
		NO();
	for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				c[i][j] = '.';
	if (n % 3 == 0) {
		for (int i = 0; i * 3 < n; i++)
			color(i * 3, i * 3);
		for (int i = 0; i < n; i++, cout << '\n')
			for (int j = 0; j < n; j++)
				cout << c[i][j];
		return 0;
	}
	for (int i = 0; i <= n; i++)
		for (int j = 0; j <= n; j++)
			for (int k = 0; k <= 1; k++)
				if ((i * 4 + j * 5 + k * 7) == n) {
					int now = 0;
					for (int x = 0; x < i; x++) {
						c[now][now] = c[now + 1][now] = 'a';
						c[now][now + 1] = c[now + 1][now + 1] = 'b';
						c[now][now + 2] = c[now][now + 3] = 'c';
						c[now + 1][now + 2] = c[now + 1][now + 3] = 'd';
						c[now + 2][now] = c[now + 2][now + 1] = 'e';
						c[now + 2][now + 2] = c[now + 3][now + 2] = 'f';
						c[now + 2][now + 3] = c[now + 3][now + 3] = 'g';
						c[now + 3][now] = c[now + 3][now + 1] = 'h';
						now += 4;
					}
					for (int x = 0; x < j; x++) {
						c[now][now] = c[now + 1][now] = 'a';
						c[now][now + 1] = c[now + 1][now + 1] = 'b';
						c[now][now + 2] = c[now + 1][now + 2] = 'c';
						c[now + 2][now] = c[now + 3][now] = 'd';
						c[now + 2][now + 1] = c[now + 2][now + 2] = 'e';
						c[now + 2][now + 3] = c[now + 2][now + 4] = 'f';
						c[now + 3][now + 2] = c[now + 4][now + 2] = 'g';
						c[now + 3][now + 3] = c[now + 3][now + 4] = 'h';
						c[now + 4][now] = c[now + 4][now + 1] = 'i';
						c[now + 4][now + 3] = c[now + 4][now + 4] = 'j';
						now += 5;
					}
					for (int x = 0; x < k; x++) {
						c[now][now] = c[now + 1][now] = 'a';
						c[now][now + 1] = c[now + 1][now + 1] = 'b';
						c[now][now + 2] = c[now + 1][now + 2] = 'c';
						
						c[now + 2][now] = c[now + 3][now] = 'd';
						c[now + 2][now + 1] = c[now + 3][now + 1] = 'e';
						c[now + 2][now + 2] = c[now + 3][now + 2] = 'f';

						c[now + 4][now] = c[now + 5][now] = 'g';

						c[now + 4][now + 3] = c[now + 4][now + 4] = 'h';
						c[now + 4][now + 5] = c[now + 4][now + 6] = 'i';

						c[now + 5][now + 3] = c[now + 5][now + 4] = 'j';
						c[now + 5][now + 5] = c[now + 5][now + 6] = 'k';

						c[now + 6][now + 1] = c[now + 6][now + 2] = 'l';
						c[now + 6][now + 3] = c[now + 6][now + 4] = 'm';
						c[now + 6][now + 5] = c[now + 6][now + 6] = 'n';
						
						now += 7;
					}
						
					for (int x = 0; x < n; x++, cout << '\n')
						for (int y = 0; y < n; y++)
							cout << c[x][y];
					return 0;
				}
}


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

int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    vector<int> ws(n);
    cin >> ws[0];
    for (size_t i = 1; i < n; i++) {
        cin >> ws[i];
        ws[i] += ws[i-1];
    }

    int ans = 100000000;
    for (size_t i = 0; i < n-1; i++) {
        ans = min(ans, abs(ws[n-1] - 2 * ws[i]));
    }

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


Measured memory_bytes: 3584
void solve();

int main() {
	solve();
	return 0;
}

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;
typedef pair<int, int> pii;

void solve() {
	int N, L;
	cin >> N >> L;
	int sum = (L + N - 1) * (L + N) / 2 - L*(L-1)/2;
	if (L > 0)cout << sum - L << endl;
	else if (L + N - 1 >= 0)cout << sum << endl;
	else cout << sum - (L + N - 1) << endl;
	return;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    
    public static void main (String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	int x = sc.nextInt();
    	int t = sc.nextInt();
      	sc.close();
    	
    	int total = n % x == 0 ? n / x : n / x + 1;
    	
    	System.out.println(total * t);
    	
    	
    	
    }

}

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

//素集合データ構造
// ref:https://ei1333.github.io/luzhiled/snippets/structure/union-find.html
struct union_find {
    // parent[v]==w(>=0):vの親はw
    // parent[v]==k(<0):vは根&&vの属するグループの要素数は-k
    vector<long long int> parent;
    //コンストラクタ
    union_find(long long int n) {
        parent.assign(n, -1);
    }
    // vの根を求める
    //求めると同時に親を根に置き換える(木の圧縮)
    long long int root(long long int v) {
        if (parent[v] < 0) {
            return v;
        } else {
            parent[v] = root(parent[v]);
            return parent[v];
        }
    }
    // vが属するグループの要素数を求める
    long long int size(long long int v) {
        return -parent[root(v)];
    }
    // vとwを繋げる
    void unite(long long int v, long long int w) {
        v = root(v);
        w = root(w);
        if (v == w) return;
        if (parent[v] < parent[w]) swap(v, w);
        parent[w] += parent[v];
        parent[v] = w;
    }
    // vとwが同値か判定
    bool isSame(long long int v, long long int w) {
        return root(v) == root(w);
    }
};

int main() {
    int n;
    cin >> n;
    vector<pair<int, pair<int, int>>> city(n);
    for (int i = 0; i < n; i++) {
        cin >> city[i].second.first >> city[i].second.second;
        city[i].first = i;
    }
    vector<pair<int, pair<int, int>>> edges;
    union_find uf(n);
    sort(city.begin(), city.end(),
         [](const pair<int, pair<int, int>> x,
            const pair<int, pair<int, int>> y) {
             return x.second.first < y.second.first;
         });
    for (int i = 0; i < n - 1; i++) {
        pair<int, pair<int, int>> c1 = city[i];
        pair<int, pair<int, int>> c2 = city[i + 1];
        edges.push_back(make_pair(c2.second.first - c1.second.first,
                                  make_pair(c1.first, c2.first)));
    }
    sort(city.begin(), city.end(),
         [](const pair<int, pair<int, int>> x,
            const pair<int, pair<int, int>> y) {
             return x.second.second < y.second.second;
         });
    for (int i = 0; i < n - 1; i++) {
        pair<int, pair<int, int>> c1 = city[i];
        pair<int, pair<int, int>> c2 = city[i + 1];
        edges.push_back(make_pair(c2.second.second - c1.second.second,
                                  make_pair(c1.first, c2.first)));
    }
    sort(edges.begin(), edges.end(),
         [](const pair<int, pair<int, int>> x,
            const pair<int, pair<int, int>> y) { return x.first < y.first; });
    int connected = 1;
    int ans = 0;
    auto itr = edges.begin();
    while (connected < n && itr != edges.end()) {
        if (!uf.isSame((*itr).second.first, (*itr).second.second)) {
            ans += (*itr).first;
            uf.unite((*itr).second.first, (*itr).second.second);
            connected++;
        }
        itr++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6900
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

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


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

int main() {
    string s[3];
    cin >> s[0] >> s[1] >> s[2];

    int now = 0; // 誰のターンであるか
    int pos[3] = {0}; // それそれのカードがどの位置か
    while (1) {
        if (pos[ now ] == s[ now ].length()) {
            cout << char('A' + now) << endl;
            return 0;
        }
        int next = s[now][ pos[now] ] - 'a'; // 次に読み込まれるもの
        pos[now]++;
        now = next;
    }

    return 0;
}

Measured memory_bytes: 256
require 'prime'
io = STDIN
N=io.gets.to_i

PD= (1..N).inject(:*).prime_division.select{|k,v|v>=2}.to_h
def gt_cnt(n)
  PD.values.count{|i|i>=n.pred}
end
#75
#3*25
#3*5*5
#5*15
cnt=0
ar= [[75],[25,3],[5,5,3],[15,5]].map do |nums|
  dup=nums.size-nums.uniq.size
  nums.map.with_index do |n,i|
    (gt_cnt(n)-i)
  end.inject(:*)/(dup+1)
end
puts ar.inject(:+)


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

const int N = 2005, mod = 924844033;

int n, k, fac[N], dp[N], sum[N], mx[N], f[N][N][2][2], m, ans;

inline void add(int &a, int b) {
	(a += b) >= mod && (a -= mod);
}
inline int Add(int a, int b) {
	return add(a, b), a;
}
inline void sub(int &a, int b) {
	(a -= b) < 0 && (a += mod);
}
inline int Sub(int a, int b) {
	return sub(a, b), a;
}
inline void mul(int &a, int b) {
	a = 1ll * a * b % mod;
}
inline int Mul(int a, int b) {
	return 1ll * a * b % mod;
}

int main() {
	cin >> n >> k; 
 	fac[0] = 1; for(int i = 1; i <= n; ++i) fac[i] = Mul(fac[i - 1], i);
 	for(int i = 1; i <= k; ++i) for(int j = i; j <= n; j += k, ++mx[i]); 
 	f[1][0][0][0] = f[1][1][0][1] = 1;
 	for(int i = 2; i <= mx[1]; ++i) {
 		f[i][0][0][0] = 1;
 		for(int j = 1; j <= i; ++j) {
 			f[i][j][0][0] = Add(Add(f[i - 1][j][0][0], f[i - 1][j][1][0]), f[i - 1][j - 1][0][0]); 
 			f[i][j][0][1] = Add(f[i - 1][j - 1][0][0], f[i - 1][j - 1][1][0]);
 			f[i][j][1][0] = Add(Add(f[i - 1][j][0][1], f[i - 1][j][1][1]), f[i - 1][j - 1][0][1]);
 			f[i][j][1][1] = Add(f[i - 1][j - 1][0][1], f[i - 1][j - 1][1][1]);
		}
	}
	dp[0] = 1;
 	for(int t = 1; t <= k; ++t) 
		for(int i = n; i; --i) 
			for(int j = 1; j <= min(i, mx[t]); ++j)
				add(dp[i], Mul(dp[i - j], Add(f[mx[t]][j][0][0], f[mx[t]][j][1][0])));
 	for(int i = 0; i <= n; ++i) {
 		if(i & 1) sub(ans, Mul(fac[n - i], dp[i]));
 		else add(ans, Mul(fac[n - i], dp[i]));
	}
	return cout << ans, 0;
}


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

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

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

const int mod = 998244353;

int main() {
  int n, k;
  cin >> n >> k;
  vector<P> ran(k);
  rep(i, k) cin >> ran[i].first >> ran[i].second;

  vector<ll> dp(n + 1);
  vector<ll> s(n + 2);
  dp[0] = 1;
  s[1] = 1;
  for (int i = 1; i <= n; ++i) {
    rep(j, k) {
      int li = i - ran[j].second;
      int ri = i - ran[j].first;
      if (ri < 0) continue;
      li = max(li, 0);
      (dp[i] += s[ri + 1] - s[li] + mod) %= mod;
    }
    s[i + 1] = (s[i] + dp[i]) % mod;
  }

  cout << dp[n - 1] % mod << endl;
  return 0;
}


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int rs = 0;
            int[] tmp = { 0, 0, 0, 0, 0, 0 };
            bool flg = false;
            tmp[0] = int.Parse(Console.ReadLine());
            tmp[1] = int.Parse(Console.ReadLine());
            tmp[2] = int.Parse(Console.ReadLine());
            tmp[3] = int.Parse(Console.ReadLine());
            tmp[4] = int.Parse(Console.ReadLine());


            for (int i = 1; i <= 10; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    if (tmp[j].ToString().Substring(tmp[j].ToString().Length - 1, 1) == i.ToString().Substring(i.ToString().Length-1,1))
                    {
                        if (!flg)
                        {
                            flg = true;
                            rs += tmp[j];
                        }
                        else
                        {
                            rs += tmp[j]+(10-i);
                        }
                    }
                }
            }

            Console.WriteLine(rs);
            

        }
        
    }
}


Measured memory_bytes: 11092