akhauriyash/Code-Regression huggingface dataset:
import glob
import os

bn = os.path.basename(__file__).split('.')[0]
dn = os.path.dirname(__file__).split('/')

# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = dn[len(dn)-2] + '\\' + dn[len(dn)-1] + '\\' + bn

# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'

class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class Solver(Common):

    def resolve(self):

        N = int(self.input_data())
        A = list(map(int, self.input_data().split()))
        Q = int(self.input_data())
        B = [0]*Q
        C = [0]*Q
        for i in range(Q):
            B[i], C[i] = map(int, self.input_data().split())

        num_count = [0] * (100000+1)

        for i in range(N):
            num_count[A[i]] += 1

        result = 0
        for i in range(100000+1):
            result += num_count[i] * i

        for i in range(Q):
            result += (C[i] - B[i]) * num_count[B[i]]
            num_count[C[i]] += num_count[B[i]]
            num_count[B[i]] = 0
            print(str(result))

solver = Solver(REL_PATH)
solver.exec_resolve()


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

int main(){
  long n; std::cin>>n;long v =0;for(long i =0;i<n;i++){long f;std::cin >>f;if(f%2==0)v++;}
  long long dd = pow(3,n)-pow(2,v);
  std::cout<<dd;

return 0;
}


Measured memory_bytes: 256
import itertools
N, M = map(int, input().split())
D = {tuple(sorted(map(int, input().split()))) for x in range(M)}
cnt = 0
for i in itertools.permutations(range(2, N+1), N-1):
    l = [1]+list(i)
    cnt += sum(1 for x in zip(l,l[1:]) if tuple(sorted(x)) in D) == N-1
print(cnt)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include <iostream> 
#include <cmath>
#include <cstdlib>
#include <vector>
#include<algorithm>
#define N 320
#define M (N*N*6+100)
#define inf 999999999
#define INT_MAX1 (1<<30)
using namespace std;


int mk[M];
int n,m,s,t,num,adj[N],dis[N],q[N];
struct edge
{
	int v,w,pre;
}e[M];
void insert(int u,int v,int w)
{
	e[num]=(edge){v,w,adj[u]};
	adj[u]=num++;
	e[num]=(edge){u,w,adj[v]};
	adj[v]=num++;
}
int bfs()
{
	int i,x,v,tail=0,head=0;
	memset(dis,0,sizeof(dis));
	dis[s]=1;
	q[tail++]=s;
	while(head<tail)
	{
		x=q[head++];		
		for(i=adj[x];i!=-1;i=e[i].pre)
			if(e[i].w&&dis[v=e[i].v]==0)
			{
				dis[v]=dis[x]+1;
				if(v==t)
					return 1;
				q[tail++]=v;
			}
	}
	return 0;
}
int dfs(int s,int limit)
{
	if(s==t)
		return limit;
	int i,v,tmp,cost=0;
	for(i=adj[s];i!=-1;i=e[i].pre)
		if(e[i].w&&dis[s]==dis[v=e[i].v]-1)
		{
			tmp=dfs(v,min(limit-cost,e[i].w));
			if(tmp>0)
			{
				e[i].w-=tmp;
				e[i^1].w+=tmp;
				cost+=tmp;
				if(limit==cost)
					break;
			}
			else dis[v]=-1;
		}
	return cost;
}
int Dinic()
{
	int ans=0;
	while(bfs())
		ans+=dfs(s,INT_MAX1);
	return ans;
}
int main ()
{
	int n,m;
	scanf("%d%d",&n,&m);
	int t1,t2;
	num=0;
	int mm=2*n+1;
	memset(adj,-1,sizeof(adj));
	for (int i=0;i<m;i++)
	{
		scanf("%d%d",&t1,&t2);
		insert (t1,t2,1);
	//	insert(t2,++mm,1);
	///	insert(mm,t1,1);
	}
	scanf("%d%d",&s,&t);
	int res=Dinic();
	int cnt=0;
	for (int i=0;i<m;i++)
	{
		if (e[i*2+1].w==0)
		{
			mk[cnt++]=i+1;
		}
	}
	cout<<res<<endl;
	cout<<cnt<<endl;
	for (int i=0;i<cnt;i++)
		cout<<mk[i]<<endl;
	return 0;
}

Measured memory_bytes: 3284
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

string s;

int main() {
	cin >> s;
	rep(i, sz(s) / 2 + 1) {
		if (s[i] != s[sz(s) - i - 1]) {
			cout << "No" << endl;
			return 0;
		}
		if (i < (sz(s) - 1) / 2 && s[i] != s[(sz(s) - 1) / 2 - i - 1]) {
			cout << "No" << endl;
			return 0;
		}
		if (i >= (sz(s) + 3) / 2 - 1 && s[i] != s[sz(s) - (i - (sz(s) + 3) / 2 - 1) - 1]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
// #pragma GCC optimize("Ofast,unroll-all-loops")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define all(v) v.begin(), v.end()
#define len(v) ((int)(v).size())
#define pb push_back
#define kek pop_back
#define pii pair<int, int>
#define mp make_pair
#define int ll

#define debug(x) cout << #x << " = " << x << endl;

const int INF = (is_same<int, ll>::value ? 1e18 + 666 : 1e9 + 666);

// const int MEM_SIZE = 1e8;
// char mem[MEM_SIZE];
// int cur_mem_ptr = 0;

// void* operator new(size_t n) {
//     cur_mem_ptr += n;
//     return mem + cur_mem_ptr - n;
// }

// void operator delete(void*) noexcept {}
// void operator delete(void*, size_t) noexcept {}

template<class t1, class t2>
bool cmin(t1 &a, const t2 &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class t1, class t2>
bool cmax(t1 &a, const t2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

#ifndef LOCAL
void UseFiles(const string &s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}
#else
void UseFiles(const string&) {}
#endif

void run();

signed main() {
    // UseFiles("squads");
    iostream::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    run();
}

int n, m;
vector<int> arr;
vector<array<int, 4>> q;

int calc() {
    int sm = 0;
    for (auto &[a, b, c, d] : q) {
        if (arr[a] - arr[b] == -c) {
            sm += d;
        }
    }
    return sm;
}

int ans = 0;

void ret() {
    if (len(arr) == n) {
        cmax(ans, calc());
        return;
    }
    for (int j = (len(arr) ? arr.back() : 1); j <= m; ++j) {
        arr.pb(j);
        ret();
        arr.kek();
    }
}

void run() {
    int Q;
    cin >> n >> m >> Q;
    q.resize(Q);
    for (auto &[a, b, c, d] : q) {
        cin >> a >> b >> c >> d;
        --a, --b;
    }
    ret();
    cout << ans << endl;
}

Measured memory_bytes: 3656
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: i64,
        r: i64,
    }
    let ans = if n >= 10 {
        r
    }else{
        r + 100*(10 - n)
    };
    println!("{}", ans);
}

Measured memory_bytes: 4352
s = str(input())

cnt = 0
for i in range(len(s)):
    if i == 0:
        if s[i] == 'R':
            cnt += 1
    else:
        if s[i] == 'R':
            if s[i-1] == 'R':
                cnt += 1
            else:
                cnt = 1
print(cnt)


Measured memory_bytes: 9096
import sys

if __name__ == '__main__':
    H, W = (int(i) for i in input().split())
    arr = input()
    index = arr.rfind("#")
    for i in range(H-1):
        arr = input()
        if arr.find("#") != index:
            print("Impossible")
            sys.exit()

        if arr.rfind("#") == (W - 1) and index == (W - 1) and arr.find("#") != (W - 1):
            print("Impossible")
            sys.exit()

        index = arr.rfind("#")

    print("Possible")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll modpow(ll a, ll n){
  if(n==0)return 1;
  if(n%2==0){
    ll t=modpow(a,n/2);
    return t*t%MOD;
  }
  return a*modpow(a,n-1)%MOD;
}
ll modinv(ll a){
  return modpow(a,MOD-2);
}
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク

    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  ll h,w,n;
  cin >> h >> w >> n;
  int f[h][w]={};
  int nowx=-1,nowy=0;
  rep(i,n){
    int a;
    cin >> a;
    rep(j,a){
      if(nowy%2==0 && nowx+1<w){
        f[nowy][nowx+1]=i+1;
        nowx++;
      }
      else if(nowy%2==0 && nowx+1==w){
        nowy++;
        f[nowy][nowx]=i+1;
      }
      else if(nowy%2==1 && 0<=nowx-1){
        f[nowy][nowx-1]=i+1;
        nowx--;
      }
      else if(nowy%2==1 && nowx-1==-1){
        nowy++;
        f[nowy][nowx]=i+1;
      }
    }
  }
  rep(i,h){
    rep(j,w){
      if(j!=0)cout << " ";
      cout << f[i][j];
    }
    cout << endl;
  }
}


Measured memory_bytes: 384
import java.util.concurrent.LinkedBlockingDeque

fun main(args: Array<String>) {
    data class XY(val x: Int, val y: Int)
    val (h, w) = readLine()?.split(" ")?.map(String::toInt) ?: return
    val maze: List<MutableList<Char>> = 0.until(h).map {
        readLine()?.toMutableList() ?: return
    }
    val queue = LinkedBlockingDeque<List<XY>>()
    var max = 0
    0.until(h).forEach { y ->
        0.until(w).forEach { x ->
            if (maze[y][x] != '#') {
                val mazeCopy = maze.map { it.toMutableList() }
                mazeCopy[y][x] = '#'
                queue.offer(listOf(XY(x, y)))
                while (queue.isNotEmpty()) {
                    val xy = queue.poll()
                    val length = xy.size
                    if (max < length) {
                        max = length
                    }
                    val last = xy.last()
                    val xx = last.x
                    val yy = last.y
                    // 上
                    val up = yy - 1
                    if (up >= 0 && mazeCopy[up][xx] != '#') {
                        mazeCopy[up][xx] = '#'
                        queue.offer(xy + listOf(XY(xx, up)))
                    }
                    // 左
                    val left = xx - 1
                    if (left >= 0 && mazeCopy[yy][left] != '#') {
                        mazeCopy[yy][left] = '#'
                        queue.offer(xy + listOf(XY(left, yy)))
                    }
                    // 右
                    val right = xx + 1
                    if (right < w && mazeCopy[yy][right] != '#') {
                        mazeCopy[yy][right] = '#'
                        queue.offer(xy + listOf(XY(right, yy)))
                    }
                    // 下
                    val down = yy + 1
                    if (down < h && mazeCopy[down][xx] != '#') {
                        mazeCopy[down][xx] = '#'
                        queue.offer(xy + listOf(XY(xx, down)))
                    }
                }
            }
        }
    }
    println(max - 1)
}


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

namespace C
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var whxy = Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray();
            var max = whxy[0] * whxy[1] / 2.0;
            Console.WriteLine($"{max.ToString()} {(whxy[0] / 2.0 == whxy[2] && whxy[1] / 2.0 == whxy[3] ? 1 : 0)}");
        }
    }
}


Measured memory_bytes: 13396
import java.util.*;
import java.io.PrintWriter;
public class Main{
	static double[][][] dp;
	static int n;
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		n=sc.nextInt();
		dp=new double[n+1][n+1][n+1];
		int[] t=new int[3];
		for(int i=0; i<n; i++){
			int a=sc.nextInt()-1;
			t[a]++;
		}
		System.out.println(dfs(t[0],t[1],t[2]));
	}
	static double dfs(int one,int two,int three){
		if(one==0 && two==0 && three==0){
			return 0;
		}
		if(dp[one][two][three]>0){
			return dp[one][two][three];
		}
		double re=n;
		if(one>0) re+=one*dfs(one-1,two,three);
		if(two>0) re+=two*dfs(one+1,two-1,three);
		if(three>0) re+=three*dfs(one,two+1,three-1);
		re/=(one+two+three);
		return dp[one][two][three]=re;
	}
}


Measured memory_bytes: 306632
#include <stdio.h>
int main()
{
	int A,P ;
	scanf("%d%d", &A,&P );
	A=3*A;//jumlah Apel berubah jadi jumlah potongan apel dari A
	P=P+A;//jumlah potongan apel dari input berubah jadi jumlah potongan apel secara keseluruhan dari Input dan A
	printf("%d\n",P/2);
	return 0;

}

Measured memory_bytes: 3240
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <cassert>

using namespace std;

vector < vector < int > > graph;
int n, A[100050], B[100050], d[100050];

int dfs(int node, int par)
{
    if(!graph[node].size())
        return 0;

    vector < int > x;
    for(int i = 0;i < graph[node].size();++i)
    {
        int to = graph[node][i];
        if(to != par)
            x.push_back(dfs(to, node));
    }
    sort(x.begin(), x.end());
    int ans = 0;
    for(int i = 0;i < x.size();++i)
        ans = max(ans + 1, x[i] + 1);

    return ans;
}

int main()
{
    scanf("%d", &n);
    graph.resize(n + 5);
    for(int i = 2;i < n + 1;++i)
    {
        scanf("%d", A + i);
        graph[A[i]].push_back(i);
    }

    int ans = dfs(1, -1);
    printf("%d\n", ans);

    return 0;
}

/* 9
1 1 2 4 2 2 7 7
 */



Measured memory_bytes: 15488
unittest
{
	assert( [ "1 0 1", "2 1 2", "1 0 1" ].parse.expand.solve == "Yes" );
	assert( [ "2 2 2", "2 1 2", "2 2 2" ].parse.expand.solve == "No" );
	assert( [ "0 8 8", "0 8 8", "0 8 8" ].parse.expand.solve == "Yes" );
	assert( [ "1 8 6", "2 9 7", "0 7 7" ].parse.expand.solve == "No" );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	long[ 3 ][ 3 ] css;
	foreach( ref cs; css )
	{
		cs = input.front.split.to!( long[] );
		input.popFront;
	}
	return tuple( css );
}

auto solve( long[ 3 ][ 3 ] css )
{
	// 各行の合計の差を検証（各行で同じ値を足しているはずなので行数で割り切れるはず）
	auto ys = new long[ 3 ];
	foreach( i, ref y; ys )
	{
		y = css[ i ][ 0 ] + css[ i ][ 1 ] + css[ i ][ 2 ];
	}
	auto ym = ys.reduce!min;
	if( ( ys[ 0 ] - ym ) % 3 != 0 || ( ys[ 1 ] - ym ) % 3 != 0 || ( ys[ 2 ] - ym ) % 3 != 0 ) return "No";
	
	// 各列の合計の差を検証（各列で同じ値を足しているはずなので列数で割り切れるはず）
	auto xs = new long[ 3 ];
	foreach( i, ref x; xs )
	{
		x = css[ 0 ][ i ] + css[ 1 ][ i ] + css[ 2 ][ i ];
	}
	auto xm = xs.reduce!min;
	if( ( xs[ 0 ] - xm ) % 3 != 0 || ( xs[ 1 ] - xm ) % 3 != 0 || ( xs[ 2 ] - xm ) % 3 != 0 ) return "No";
	
	return "Yes";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long m,n;
	cin >> m >> n;
	long long  ans=ceil(n*m*1.0/2);
	if(n==1||m==1)
	cout << 1 << endl;
	else
	cout << ans << endl;
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define nl cout<<"\n"
#define db(x) cout<<x<<" "
#define fi(a,b) for(int i=a;i<b;i++)
#define fj(a,b) for(int j=a;j<b;j++)
#define fk(a,b) for(int k=a;k<b;k++)
#define F first
#define S second
#define UM unordered_map<int,int>
#define MP map<int,int>
void fun(){
	ll ans=0;
	string s,t;
	cin>>s>>t;
	fi(0,s.size())
		if(s[i]!=t[i])
			ans++;
	cout<<ans<<"\n";
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t=1;
	// cin>>t;
	while(t--){
		fun();
	}
}

Measured memory_bytes: 3796
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <bitset>
#include <assert.h>
using namespace std;

typedef long long ll;
#define free  freopen ("input.txt", "r", stdin);freopen ("output.txt", "w", stdout);
#define Fast  ios::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define F first
#define S second
const int mod = 998244353;

ll pw(ll a, ll b){ll ans = 1;while (b){if (b%2 == 1){ans *= a;ans %= mod;}b /= 2;a*= a;}return ans;}

bool vowel(char che)
{
    if (che == 'A' || che == 'E' || che == 'I' || che == 'O' || che == 'U' || che == 'Y')
        return true;
    else
        return false;
}

const int N = 3e5+5;
pair <ll, ll> p;
stack <int> st;
string s, s1;
char o;
bool mark[N], h;
vector <ll> vt[N], vm, vs;
ll a[N], b[N], c, d, dp, dis;

void dfs(ll v)
{
    mark[v] = true;
    for (int i = 0; i < vt[v].size(); i++){
        if (!mark[vt[v][i]])
            dfs(vt[v][i]);
    }
}
int main()
{
    ll t = 0, n, m = 0, k = 0, f = 0, sum = 0, ans = 0;
    cin >> n >> m;
    for (int i = 0; i < m; i++){
        ll u, v;
        cin >> u >> v;
        vt[u].pb(v);
        vt[v].pb(u);
    }
    for (int i = 1; i <= n; i++){
        if (!mark[i]){
            dfs(i);
            ans++;
        }
    }
    cout << ans-1 << endl;
}


Measured memory_bytes: 15104
#include<bits/stdc++.h>
#include<cmath>
#define endl '\n'
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define check system("pause")
#define all(x) (x).begin(),(x).end()
#define de(a) cout<<#a<<" = "<<a<<endl
#define dd(a) cout<<#a<<" = "<<a<<" "
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 0x3f3f3f3f
const ll mod = 1e9+7;
const int N = 1e6+20;
#define dep(i,a,b) for(int i=(a);i>=(b);i--)
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define mes(p,b) memset(p,b,sizeof(p))
#define sz(x) int(x.size())
ll x,a,b;
inline ll ff(ll x){
	return x*x*x*x*x;
}
bool isint(db x){
	return (x==(ll)x);
}
int main()
{
  	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  	cin>>x;
  	//rep(x,1,1e9){
  	rep(a,-5000,5000){ 
	rep(b,-5000,5000){
		if(ff(a)-ff(b)==x){
			cout<<a<<' '<<b;return 0;
		} 
	}} 
		
//	}
  	return 0;
}



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

long long int H, W, h, w, a[514][514], b, c = 1000000000;

int main(){
    scanf("%lld%lld%lld%lld", &H, &W, &h, &w);
    if(!((H % h) | (W % w)))return puts("No") & 0;
    fill(a[0], a[H], 1);
    b = W * H;
    for(int i = 1; i * h - 1 < H; ++i){
        for(int j = 1; j * w - 1 < W; ++j){
            b -= c + 1;
            a[i * h - 1][j * w - 1] = - c;
        }
    }
    for(int i = 0; i * h < H; ++i){
        for(int j = 0; j * w < W; ++j){
            b += c - h * w;
            a[i * h][j * w] = c - h * w + 1;
        }
    }
    if(b <= 0)return puts("No") & 0;
    puts("Yes");
    for(int i = 0; i < H; ++i){
        for(int j = 0; j < W; ++j){
            cout << a[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h> 
using namespace std;
char s[15], t[15];
int main(){
	int n;
	scanf("%s", s);
	scanf("%s", t);
	n=strlen(s);
	if(strncmp(s, t, n)==0){
		printf("Yes");
	}
	else{
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 3824
// -*- coding:utf-8-unix -*-

use proconio::{fastout, input};
use std::cmp::Reverse;

// ABC086C - Traveling
// https://atcoder.jp/contests/abs/fasks/arc089_a

#[fastout]
fn main() {
    input! {
        n: usize,
        w: usize,
        wv: [(usize, usize); n],
    }

    let w1 = wv[0].0;
    let mut wv2: Vec<Vec<usize>> = vec![Vec::new(); 4];
    for (ww, v) in wv {
        wv2[ww - w1].push(v);
    }
    for i in 0..4 {
        wv2[i].sort_unstable_by_key(|&x| Reverse(x));
    }
    // precompute sums
    let mut wv3: Vec<Vec<usize>> = vec![Vec::new(); 4];
    for i in 0..4 {
        wv3[i].push(0);
        for &v in &wv2[i] {
            if let Some(&x) = &wv3[i].last() {
                wv3[i].push(x + v);
            }
        }
    }
    let mut maxval = 0;
    for n0 in 0..=wv2[0].len() {
        if n0 * w1 > w {
            break;
        }
        for n1 in 0..=wv2[1].len() {
            if n0 * w1 + n1 * (w1 + 1) > w {
                break;
            }
            for n2 in 0..=wv2[2].len() {
                if n0 * w1 + n1 * (w1 + 1) + n2 * (w1 + 2) > w {
                    break;
                }
                let wroom = w - n0 * w1 - n1 * (w1 + 1) - n2 * (w1 + 2);
                let n3 = (wroom / (w1 + 3)).min(wv2[3].len());
                let val = wv3[0][n0] + wv3[1][n1] + wv3[2][n2] + wv3[3][n3];
                maxval = maxval.max(val);
            }
        }
    }
    println!("{}", maxval);
}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  
  if (a + b == c || b + c == a || c + a == b) {
    cout << "Yes" << endl;
  }
  
  else {
    cout << "No" << endl;
  }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>Fac,Rac;void setF(int n,int mod){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%mod;Rac[n-1]=modInv(Fac[n-1],mod);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%mod;}
//ll comb(int a,int b,int m){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

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

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7; //998244353;
const int N = 1e7;
ll n, a, DP[N+1];
ll get(ll a){
  return a<N ? DP[a] : a;
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> a;
  iota(DP, DP+N+1, 0);
  FOR(i, 2, N){
    ll t = DP[i]+a+2;
    for(int j=i*2; j<N; j+=i) mins(DP[j], t++);
    mins(DP[N], t);
  }
  FORR(i, N, 1) mins(DP[i-1], DP[i]);
  ll ans = n;
  FOR(i, 1, N+1){
    mins(ans, DP[i]+a+get((n+i-1)/i));
    ll m = (n+i-1)/i, q=sqrt(m);
    q=max(q-1, 1ll);
    FOR(_, 0, 3){
      mins(ans, get(i)+a+get(q)+a+get((m+q-1)/q));
      q++;
    }
  }
  cout << ans << endl;
}

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

const int N = 100005;
int n, m, p[N][62]; ll k, a[N], d[N], tmp[N];

int main () {
	cin >> n;
	for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
	for (int i = 1; i < n; ++i) d[i] = a[i + 1] - a[i];
	cin >> m >> k;
	for (int i = 1; i < n; ++i) p[i][0] = i;
	for (int i = 1, x; i <= m; ++i) {
		scanf("%d", &x);
		swap(p[x][0], p[x - 1][0]);
	}
	for (int l = 1; l <= 60; ++l)
		for (int i = 1; i <= n; ++i) p[i][l] = p[p[i][l - 1]][l - 1];
	for (int l = 60; ~l; --l) if (k >> l & 1) {
		for (int i = 1; i <= n; ++i) tmp[i] = d[i];
		for (int i = 1; i <= n; ++i) d[i] = tmp[p[i][l]];
	}
	for (int i = 2; i < n; ++i) a[i] = a[i - 1] + d[i - 1];
	for (int i = 1; i <= n; ++i) printf("%lld.0\n", a[i]);
	return 0;
}

Measured memory_bytes: 28032
#include<stdio.h>
int main(){
	int n,k,x;
	while(scanf("%d%d",&n,&k),n!=0||k!=0){
		if(n>k){
			x=n;
			n=k;
			k=x;
		}
		printf("%d %d\n",n,k);
	}
	return 0;
}


Measured memory_bytes: 1912
import sys
from collections import defaultdict
from bisect import bisect_left

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

S = sr()
T = sr()
S_set = set(S)
T_set = set(T)
if len(T_set - S_set) > 0:
    print(-1); exit()

#これ以降は必ず部分列が出来る
dict_S = defaultdict(list)
for i, s in enumerate(S):
    dict_S[s].append(i)

cur = -1
lenS = len(S)
answer = 0
for t in T:
    cur += 1
    answer += 1
    L = dict_S[t]
    i = bisect_left(L, cur)
    if i == len(L):
        answer += lenS - cur + L[0]
        cur = L[0]
    else:
        answer += L[i] - cur
        cur = L[i]

print(answer)
# 07


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

int main()
{int N; 
 ll ans=0;
 cin >> N;
 map<string, int>nums;
 rep(i, N){
   string s;
   cin >> s;
   sort(s.begin(), s.end());
   nums[s]++;}
 for(auto p: nums){
   int a = p.second;
   ans += (ll)a*(a-1)/2;
      
 }
  cout << ans << endl; 
   
 }


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

int main(){
  int a,b; cin>>a>>b;
  if (a%2==1 && b%2==1) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int n,m,a[3];
vector<int> rG[50];

int d[50],c[50];
bool dp[101][50][50];

void init(int si){
  dp[0][si][si]=true;
  for(int i=0;i<100;i++){
    for(int j=0;j<n;j++){
      if(!dp[i][si][j])continue;
      for(int k=0;k<(int)rG[j].size();k++){
        int w=rG[j][k];
        dp[i+1][si][w]=true;
      }
    }
  }
}

void solve(){
  memset(c,0,sizeof(c));
  memset(d,-1,sizeof(d));
  queue<int> Q;
  Q.push(n-1);
  d[n-1]=0;
  while(!Q.empty()){
    int pos=Q.front();Q.pop();
    if(pos==0){
      cout<<d[pos]<<endl;
      return;
    }
    for(int i=0;i<3;i++){
      for(int to=0;to<n;to++){
        if(!dp[a[i]][pos][to])continue;
        c[to]|=(1<<i);
        if(c[to]==7&&d[to]==-1){
          d[to]=d[pos]+1;
          Q.push(to);
        }
      }
    }
  }
  cout<<"IMPOSSIBLE"<<endl;
}

int main(){
  cin>>n>>m;
  for(int i=0;i<3;i++)cin>>a[i];
  for(int i=0;i<m;i++){
    int from,to;
    cin>>from>>to;
    from--,to--;
    rG[to].push_back(from);
  }
  for(int i=0;i<n;i++)init(i);

  solve();
  return 0;
}

Measured memory_bytes: 1488
// Template begins
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <math.h>
#include <iomanip>
#include <queue> 
#include <string.h>
#include <string>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define fo(i,a,b) for(i=a;i<=b;i++)
#define all(v) (v).begin(),(v).end()
#define sort0(v) sort(all(v))
#define lbb(a,b,arr,x) lower_bound(arr+a,arr+b+1,x)-arr
#define ubb(a,b,arr,x) upper_bound(arr+a,arr+b+1,x)-arr
#define freq(a,b,arr,x) upper_bound(arr+a,arr+b+1,x)-lower_bound(arr+a,arr+b+1,x)
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define d0(x) cout<<(x)<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define d5(a,b,c,d,e) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<endl
#define d6(a,b,c,d,e,f) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<" "<<(f)<<endl
#define max3(a,b,c) max(max((a),(b)),(c))
#define max4(a,b,c,d) max(max((a),(b)),max((c),(d)))
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
#define printp(x) cout << x.ff << " " << x.ss << endl
 
const ll mod=998244353;
#define inf 9999999999999
#define MAXN   100001 
  
// stores smallest prime factor for every number 
 
 
ll inv(ll i){if(i==1) return 1;return (mod-((mod/i)*inv(mod%i))%mod)%mod;}
 
ll gcd(ll a,ll b){if(a==0) return b;return gcd(b,b%a);}
inline void fastio(){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
// Template ends
const int MN = 2e5+7;

void solve(){
    int n; cin>>n; ll ans=0;
    for(int i=1;i<n;i++){
        if(n%i==0){
            ans+=n/i-1;
        }else{
            ans+=n/i;
        }
    }
    cout<<ans<<endl;
}
int main(){
    fastio();
    //write code
    int t; t=1;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3196
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	int a = scan.nextInt();
	if (a % 2 == 0) {
	    a = a - 1;
	}
	System.out.println((a-1)/2);
	scan.close();
    }

}

Measured memory_bytes: 21844
n,a,b=map(int,input().split())
c=min(a,b)
d=max(a,b)
e=min(2*n-a-b,a+b-2)
f=min(c-1,n-d)
if d-c==1:
  print(f+1)
elif (d-c)%2==0:
  print((d-c)//2)
else:
  print((e+1)//2)


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);

ll modmul(ll a,ll b,ll mod){
    return a%mod * (b%mod) %mod;
}

ll modpow(ll a,ll b,ll mod){
    if(b==0) return 1;
    else if(b%2==0) return modpow(modmul(a,a,mod),b/2,mod);
    else return modmul(modpow(a,b-1,mod),a,mod);
}

ll moddiv(ll a,ll b,ll mod){
    return a%mod * modpow(b,mod-2,mod) %mod;
}

int main(void)
{
    ll n; cin >> n;
    vector<ll> a(n);
    rep(i,n){
        int x; cin>>x;
        x--;
        a[i]=x;
    }
    ll cnt=0,tmp=0;
    while(true){
        if(tmp==1){
            cout<<cnt<<endl;
            break;
        }
        if(cnt>=n){
            cout<<"-1"<<endl;
            break;
        }
        cnt++;
        tmp=a[tmp];
    }
    return 0;
}


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

int main(){
  int n, m;
  cin >> n >> m;
  
  int i = 0;
  int k = n % 2 ? (n + 1) / 2: n / 2;
  while (i++ < k - 1) cout << 0 << " ";
  while (i++ < n ) cout << m << " ";
  if (i != n - 1) cout << m << endl;

return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include<iomanip>
#include<functional>
using namespace std;
typedef long long ll;


long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}


int main() {
    int N;
    cin >> N;
    map<string, ll> s;
    for (int i = 0; i < N; i++) {
        string S;
        cin >> S;
        sort(S.begin(), S.end());
        s[S]++;
    }
    ll ans = 0;
    for (auto x : s) {
        ll n = x.second;
        ans += n * (n - 1) / 2;
    }
    cout << ans << endl;
}


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

#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

#define vint(v, n) vector<int> v(n); REP(i,n) cin >> v[i];
#define vints(v, v1, n) vector<int> v(n), v1(n); REP(i,n) cin >> v[i] >> v1[i];

int main(void){

  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, M;
  cin >> N >> M;
  vints(a, b, M);

  vector<int> c(51);
  REP(i, M) c[a[i]]++;
  REP(i, M) c[b[i]]++;

  REP(i, N) cout << c[i+1] <<endl; 

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>

#define FOR(i, a, b) for (int i = a; i < b; i++)
#define FORN(i, a, b) for (int i = a; i <= b; i++)
#define P(s) cout << s << endl
#define PC(condition, _true, _false) if (condition) _true; else _false;
#define toInt(_char) _char - '0'

using namespace std;
//
// Created by karayuu on 2018-12-18.
//

int main() {
    int n, a;
    cin >> n;
    cin >> a;
    
    P(n * n - a);
}


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

int main()
{
  char str[13];
  scanf("%s",str);

  int len = strlen(str);
  long long ans = 0;
  for(int t=0;t<(1<<(len-1));t++)
  {
    long long num = str[0]-'0';
    for(int i=0;i<len-1;i++)
    {
      if(t&(1<<i))
      {
        ans += num;
        num = 0;
      }
      num = num*10 + str[i+1] - '0';
    }
    ans += num;
  }
  cout << ans << endl;
  return 0;
}


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

int n;
int y;
int m;
int d;

int main(){
  cin >> n;
  for(int i=0;i<n;i++){
    int days = 0;
    cin >> y >> m >> d;
    if(d!=1){
      if(m%2==1||y%3==0){
        days += 21 - d;
      }else{
        days += 20 - d;
      }
      m++;
    }
    while(m<11){
      if(m%2==1||y%3==0){
        days += 20;
      }else{
        days += 19;
      }
      m++;
    }
    y++;
    while(y<1000){
      if(y%3==0){
        days += 20 * 10;
      }else{
        days += 20*5 + 19*5;
      }
      y++;
    }
    cout << days << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1160
a = int(input())
b = int(input())
if a > b:
    if a-1 == b and b > 1:
        print(a-b)
    elif a-1 == b:
        print(a+1)
    else:
        print(a-1)
else:
    if b-1 == a and a > 1:
        print(b-a)
    elif b-1 == a:
        print(b+1)
    else:
        print(b-1)

Measured memory_bytes: 3060
import sys

sys.setrecursionlimit(10**7)


def dfs(s, to, color):
    for next_v, step in to[s]:
        if color[next_v] == -1:
            if step % 2 == 0:
                color[next_v] = color[s]
            else:
                color[next_v] = color[s] ^ 1
            dfs(next_v, to, color)


def solve():
    N = int(input())
    to = [[] for _ in range(N)]
    for _ in range(N - 1):
        u, v, w = map(int, input().split())
        u, v = u - 1, v - 1
        to[u].append([v, w])
        to[v].append([u, w])

    color = [-1] * N #-1: 未探索、0: 白、1: 黒
    color[0] = 0
    dfs(0, to, color)
    print(*color, sep='\n')


if __name__ == "__main__":
    solve()

Measured memory_bytes: 87132
#include<stdio.h>
int main(void){
    int b1,b2,b3;
    scanf("%d %d %d",&b1,&b2,&b3);
    if(b1==0 && b2==0 && b3==0){
        printf("Close\n");
    }else if(b1==1 && b2==0 && b3==0){
        printf("Close\n");
    }else if(b1==0 && b2==1 && b3==0){
        printf("Close\n");
    }else if(b1==0 && b2==0 && b3==1){
        printf("Open\n");
    }else if(b1==1 && b2==1 && b3==0){
        printf("Open\n");
    }
    return 0;
}


Measured memory_bytes: 2144
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        int out = b - a;
        if (out > x) {
            System.out.println("dangerous");
        } else if (a >= b) {
            System.out.println("delicious");
        } else {
            System.out.println("safe");
        }
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main(){
  int n, k;
  cin >> n >> k;
  mint ans = 0;
  rep2(i, k-1, n+1){
    ll l = (ll)i*(i+1)/2;
    ll r = (ll)n*(n+1)/2 - (ll)(n-i-1)*(n-i)/2;
    ans += r - l + 1;
  }
  cout << ans.x << endl;
  return 0;
}

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

string S; int N, cnt;

int main() {
	cin >> N >> S;
	for (int i = 0; i < 1000; i++) {
		int c[3] = {i / 100, (i / 10) % 10, i % 10};
		int f = 0;
		for (int j = 0; j < N; j++) {
			if (S[j] == ('0' + c[f])) f++;
			if (f == 3) break;
		}
		if (f == 3) cnt++;
	}
	cout << cnt << endl;
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<char,int>;

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

int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    int r;
    cin >> r;

    cout << r * 2 * 3.141592  << endl;


    return 0;
}


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

int main(){
    int n; cin >> n;
    vector<int64_t> a(n);
    for(auto i = 0; i < n; i++) cin >> a[i];
    int64_t m = 1000, s = 0;
    if(a[1] >= a[0]) s += m / a[0], m -= s * a[0];
    for (auto i = 0; i < n - 1; i++) {
//        cout << i << " " << a[i] << " " << a[i + 1] << endl;
        if(a[i] > a[i + 1]) {
            m += s * a[i], s = 0;
//            cout << m << " " << s << endl;
            s += m / a[i + 1], m -= s * a[i + 1];
        }
//        cout << m << " " << s << endl;
    }
    cout << m + s * a[n - 1] << endl;
    return 0;
}

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

string s[55];
int n,a,b,c;

int main(){
	scanf("%d%d%d",&a,&b,&c);
	while(a--)s[++n]="a";
	while(b--)s[++n]="b";
	while(c--)s[++n]="c";
	s[51]="cgz ak ioi";
	s[52]="ABS ak ioi";
	while(n>1){
		int mi=51,mx=52;
		for(int i=1;i<=n;++i){
			if(s[i]<s[mi])mi=i;
			if(s[i]>=s[mx])mx=i;
		}
		s[mi]+=s[mx];
		swap(s[mx],s[n--]);
	}
	cout << s[1] << endl;
	return 0;
}

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

int main()
{
	int n;
	cin>>n;
	long long a[n];
	long long sm=0; 
	for(int i=0;i<n;i++)
	{cin>>a[i];
	sm=sm^a[i];
	}
	for(int i=0;i<n;i++)
	{
		long long tmp=sm;
		sm^=a[i];
		cout<<sm<<" ";
		sm=tmp;
			}
    return 0;
}


Measured memory_bytes: 5052
#include<bits/stdc++.h>
using namespace std;
#define     debug       printf("\n<<CameHere<<\n")
#define     mem(x,y)    memset(x, y, sizeof(x))
#define     all(qz)     qz.begin(),qz.end()
#define     rall(qz)    qz.rbegin(),qz.rend()
#define     inf         LLONG_MIN
#define     INF         LLONG_MAX
#define     mod         1000000007
#define     Sqr(x)      ((x)*(x))
#define     ll          long long
#define     mk          make_pair
#define     pb          push_back
#define     pi          acos(-1.0)
#define     cos(a)      cos(a*pi/180)
#define     sin(a)      sin(a*pi/180)
#define     tan(a)      tan(a*pi/180)

ll pow(ll c,ll d){return d==0?:c*pow(c,d-1);}
ll gcd(ll a,ll b) {return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b) {return ((a*b)/gcd(a,b));}
/*---------AL ASAD NUR RIYAD------------*/


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    string s,t;
    cin>>s>>t;
    ll cnt=0;
    for(ll i=0;i<s.size();i++){
        if(s[i]!=t[i]) cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}



















Measured memory_bytes: 3820
/*

結果:
*/
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>  
#include <stdbool.h>   
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define PI 3.14159265358979323846;
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
/*
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r)
*/
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r)
#define TYPE long long
#define ll long long
#define MEMSET(a) memset(a,0,sizeof(a))
#define MEMSET_U(a) memset(a,-1,sizeof(a))
const int mod = (int)1e09 + 7;

//#define DEBUG1
//#define DEBUG2
//#define DEBUGF
#define DUMMY

int in(void) { int i; scanf("%d", &i); return i; }
long long llin(void) { long long i; scanf("%lld", &i); return i; }
double din(void) { double i; scanf("%lf", &i); return i; }
void chin(char s[]) { scanf("%s", s); }

void print(int a) { printf("%d\n", a); }
void llprint(long long a) { printf("%lld\n", a); }
void dprint(double a) { printf("%.10f\n", a); }
void print2(int a, int b) { printf("%d %d\n", a, b); }
int Max(int a, int b) { if (a > b) { return a; }return b; }
int Min(int a, int b) { if (a < b) { return a; }return b; }
long long llmax(long long a, long long b) { return a > b ? a : b; }
long long llmin(long long a, long long b) { return a < b ? a : b; }
double dmax(double a, double b) { return a > b ? a : b; }
double dmin(double a, double b) { return a < b ? a : b; }
//long long llmax(long long a, long long b) { return a > b ? a : b; }
//long long llmin(long long a, long long b) { return a < b ? a : b; }
//double dmax(double a, double b) { return a > b ? a : b; }
int cmp(const void *a, const void *b) { return *(TYPE *)a - *(TYPE *)b; }
int cmp_r(const void *a, const void *b) { return *(TYPE *)b - *(TYPE *)a; }
int char_cmp(const void *a, const void *b) { return strcmp((char *)a, (char *)b); }
int char_cmp_r(const void *a, const void *b) { return strcmp((char *)b, (char *)a); }
void swap(int *a, int *b) { int t = *a; *a = *b; *b = t; }




int main() {
	int N, M;
	scanf("%d%d", &N, &M);
	int *A = (int*)malloc(sizeof(int)*M);
	int *B = (int*)malloc(sizeof(int)*M);
	int *F = (int*)malloc(sizeof(int)*N);
	for (int i = 0; i < N; i++) {
		F[i] = 0;
	}
	for (int i = 0; i < M; i++) {
		scanf("%d%d", &A[i], &B[i]);
		F[A[i] - 1]++;
		F[B[i] - 1]++;
	}

	for (int i = 0; i < N; i++) {
		printf("%d\n", F[i]);
	}


#ifdef DEBUGF
	getch();
#endif
	return 0;
}

Measured memory_bytes: 128
use strict;
use warnings;
package Scc;
sub new{
	return bless[map[],1..$_[1]],$_[0];
}
sub add_edge{
	my$self=shift;
	push@{$self->[$_[0]]},$_[1];
}
sub scc{
	my$self=shift;
	my$now_ord=0;
	my$group_num=0;
	my@low;
	my@ord=(-1)x@{$self};
	my@ids;
	my@visited;
	my$dfs;
	$dfs=sub{
		my$v=shift;
		$low[$v]=$ord[$v]=$now_ord++;
		push@visited,$v;
		for my$to(@{$self->[$v]}){
			if($ord[$to]==-1){
				$dfs->($to);
				$low[$v]=$low[$to]if$low[$v]>$low[$to];
			}
			else{
				$low[$v]=$ord[$to]if$low[$v]>$ord[$to];
			}
		}
		if($low[$v]==$ord[$v]){
			my$u=-1;
			while($u!=$v){
				$u=pop@visited;
				$ord[$u]=@{$self};
				$ids[$u]=$group_num;
			}
			$group_num++;
		}
	};
	for(0..$#ord){
		$dfs->($_)if$ord[$_]==-1;
	}
	$_=$group_num-1-$_ for@ids;
	my@groups=map[],1..$group_num;
	for(0..$#ids){
		push@{$groups[$ids[$_]]},$_;
	}
	return\@groups;
}
package main;
my($N,$M)=split$",<>;
my$scc=Scc->new($N);
for(1..$M){
	my($a,$b)=split$",<>;
	$scc->add_edge($a,$b);
}
my$groups=$scc->scc();
print scalar(@{$groups}),$/;
for(@{$groups}){
	print scalar(@{$_}),$","@{$_}",$/;
}


Measured memory_bytes: 290032