akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
 
int N, T, A, X,z,c;
 
int main(){
    scanf("%d%d%d",&N,&T,&A);
    int zz = 300000000;
    for (int i=1;i <= N;i++){
       scanf("%d",&X);
       int d=(T*1000-X*6)-1000*A;
      if(d<0)d=-d;
       if(zz >= d) zz=d, c=i;
 
    }
    printf("%d\n", c);
}
    

    

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

#define rep(i, N) for (int i = 0; i < (N); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

using ll = long long;
using i_i = tuple<int, int>;

int query(vector<int> a) {
    cout << '?';
    for (int x: a) cout << ' ' << x + 1;
    cout << endl;
    string s; cin >> s;
    if (s == "Red") return 0;
    if (s == "Blue") return 1;
    exit(1);
}

map<i_i, int> mp;

int query(int l, int r) {
    auto lr = i_i(l, r);
    if (mp.count(lr)) return mp[lr];
    vector<int> a(r - l);
    rep(i, r - l) a[i] = l + i;
    return mp[lr] = query(a);
}

int main() {
    int N; cin >> N;
    int l = 0, r = N;
    while (r - l > 1) {
        int m = (l + r) / 2;
        int x = query(l, l + N);
        int y = query(r, r + N);
        int z = query(m, m + N);
        if (z == x) l = m;
        if (z == y) r = m;
    }
    vector<int> ans(N * 2);
    rep(i, N * 2) {
        vector<int> a;
        if (l + 1 <= i && i < l + N) {
            for (int i = 0; i < l; i++) a.pb(i);
            for (int i = r + N; i < N * 2; i++) a.pb(i);
        }
        else {
            for (int i = l + 1; i < l + N; i++) a.pb(i);
        }
        a.pb(i);
        ans[i] = query(a);
    }
    string s(N * 2, ' ');
    rep(i, N * 2) s[i] = "RB"[ans[i]];
    cout << "! " << s << endl;
}


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

int main() {
  int n,m=0;
  cin >> n;
  for(int i = 1;i < 10;i++) {
    if(n%i==0){
      m = n/i;
    }
  }
  if(m<10&&m!=0) {
    cout << "Yes" << endl;
  }else {
    cout <<"No" <<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+5;
int n,a[N];ll l[N],r[N];
int main()
{
	cin>>n;
	for(int i=0;i<=n;i++)cin>>a[i];
	if(a[n]==0ll){
		cout<<"-1\n";
		return 0;
	}
	l[n]=r[n]=a[n];
	for(int i=n-1;i>=0;i--)
	{
		l[i]=(l[i+1]+1ll)/2;
		r[i]=r[i+1];
		l[i]+=a[i];
		r[i]+=a[i];
	}
	if(l[0]>1ll){
		cout<<"-1\n";
		return 0;
	}
	ll ans=1;
	r[0]=1;
	for(int i=1;i<=n;i++)
	{
		l[i]=max(l[i],l[i-1]-a[i-1]);
		r[i]=min(r[i],2ll*(r[i-1]-a[i-1]));
		if(r[i]<l[i])
		{
			cout<<"-1\n";
			return 0;
		}
		ans+=r[i];
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 5588
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
long long MOD = 1000000007LL;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647

int main() {
	long long H, W;
	cin >> H >> W;

	long long ans = 0;
	if (H == 1 || W == 1) {
		ans = 1;
	}
	else if (H % 2 == 1 && W % 2 == 1) {
		ans = (H - 1) * W / 2;
		ans += (W + 1) / 2;
	}
	else {
		ans = H * W / 2;
	}

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

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

using namespace std;
using ll = long long;

int main() {
	ll n, a, b;
	cin >> n >> a >> b;

	ll ans = n / (a + b) * a;
	n %= a + b;
	ans += min(a, n);
	printf("%lld\n", ans);

}


Measured memory_bytes: 3688
package main

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

var sc = bufio.NewScanner(os.Stdin)
var buff []byte

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buff, bufio.MaxScanTokenSize*1024)
	log.SetFlags(log.Lshortfile)
	H := nextInt()
	W := nextInt()
	dp := make([][]int, H)
	for i := 0; i < H; i++ {
		dp[i] = make([]int, W)
		for j := 0; j < W; j++ {
			dp[i][j] = 10000
		}
	}
	mapping := make([]string, H)
	colors := make([][]int, H)
	for i := 0; i < H; i++ {
		mapping[i] = nextString()
		colors[i] = make([]int, W)
		for j := 0; j < W; j++ {
			if mapping[i][j] == '#' {
				colors[i][j] = 1
			}
		}
		log.Println(mapping[i])
	}
	if mapping[0][0] == '#' {
		dp[0][0] = 1
	} else {
		dp[0][0] = 0
	}
	for i := 0; i < H; i++ {
		log.Println(colors[i])
		for j := 0; j < W; j++ {
			// right
			if j+1 < W {
				if colors[i][j+1] != colors[i][j] && colors[i][j+1] == 1 {
					dp[i][j+1] = min(dp[i][j+1], dp[i][j]+1)
				} else {
					dp[i][j+1] = min(dp[i][j+1], dp[i][j])
				}
			}
			// down
			if i+1 < H {
				if colors[i+1][j] != colors[i][j] && colors[i+1][j] == 1 {
					dp[i+1][j] = min(dp[i+1][j], dp[i][j]+1)
				} else {
					dp[i+1][j] = min(dp[i+1][j], dp[i][j])
				}
			}
		}
	}
	for i := 0; i < H; i++ {
		log.Println(dp[i])
	}
	ans := dp[H-1][W-1]
	fmt.Println(ans)
}

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

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

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
using namespace std;
int n,m,s[1111][1111];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			char ch;  cin>>ch;
			if(ch=='.') s[i][j]=0;
				else s[i][j]=-1;
		}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++)
			if(s[i][j]==-1) printf("#");
				else {
					int s1=s[i-1][j-1]+s[i-1][j]+s[i-1][j+1];
					int s2=s[i][j-1]+s[i][j]+s[i][j+1];
					int s3=s[i+1][j-1]+s[i+1][j]+s[i+1][j+1];
					printf("%d",abs(s1+s2+s3));
				}
		printf("\n");
	}
}


Measured memory_bytes: 512
using System;
using System.Linq;
using System.Collections.Generic;

namespace program
{
    class Program
    {
        static void Main()
        {
            int[] a = Input.ScanIntArray();
          Console.WriteLine($"{Math.Max(a[0]*a[1],a[2]*a[3])}");
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


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

// boost
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll n;
  cin >> n;

  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }

  ll l2 = 3, l1 = 1, l0 = 2;
  n -= 2;
  while (n) {
    l0 = l1;
    l1 = l2;
    l2 = l0 + l1;
    n--;
  }

  cout << l2 << endl;

  return 0;
}


Measured memory_bytes: 3648
n=int(input())
l=sorted([int(x) for x in input().split()])
a=0
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if l[i]<l[j]<l[k] and l[i]+l[j]>l[k]:
        a+=1
print(a)

Measured memory_bytes: 9040
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <queue>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

// #define FL fflush(stdout)

#define MOD 1000000007
#define INF 1000000000000000000
#define MAXN 1010

int GLL(LL& x) {
  return scanf("%lld", &x);
}

int GI(int& x) {
  return scanf("%d", &x);
}


LL v, e, v1, v2, w;
vector < vector<LL> > edgelist;
vector< LL > dist;

bool update(vector<LL > edge) {
    LL v = edge[1], u = edge[0], w = edge[2];

    if (dist[v] > dist[u] + w && dist[u] < INF){
      dist[v] = dist[u] + w;
//      cout << u+1 << "->" << v+1 << ", " << -w << endl;
      return true;
    }
    return false;
}

int main() {

  scanf("%lld%lld", &v, &e);
  dist.resize(v, INF);

  FORN(i, e) {
    scanf("%lld %lld %lld", &v1, &v2, &w);
    v1--; v2--; w = -w;
//    printf("%lld, %lld, %lld\n", v1, v2, w);
    edgelist.PB({v1, v2, w});
  }

//  FORN(i, edgelist.size()) { printf("%lld, %lld, %lld\n", edgelist[i][0], edgelist[i][1], edgelist[i][2]); }
//  printf("end edgelist----------------------------------------\n");
    
  dist[0] = 0;
  bool flag = false;

  FORN(i, v - 1) {
    for (auto edge : edgelist) {
        bool upd = update(edge);
        flag = flag || upd;
    }
    if (! flag){ break;}
  }

  // extra round
  LL lastdist = -dist[v-1];
  for (auto edge : edgelist) {
    update(edge);
  }
  bool neg_cycle = false;
  if (-dist[v-1] != lastdist) neg_cycle = true;

  if (neg_cycle) {
    printf("inf\n");
  } else {
    printf("%lld\n", lastdist);
  }
//  for (auto d : dist) {
//    cout << d << " ";
//  }  cout << endl;

  return 0;
}

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

using namespace std;

#define LL long long

int main() {
    LL n, m;
    cin >> n >> m;

    /*
     * まずS:n個，C:m個のピースをそのまま使う。
     * x個のSCCを作るとS:n-x個，C:m-2x個が残る。
     * これらが0以上なのでx<=min(n,m/2)
     */
    LL ans = min(n, m / 2);
    n -= ans;
    m -= ans * 2;

    /*
     * Sが0個，またはCが1個以下になっている。
     * 後者の場合は何もできない。
     */
    if (n == 0) ans += m / 4;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    string s;
    cin >> s;
    int n = sz(s);
    int ans = 0;
    REP(i, 1 << n) {
        int c = 0;
        bool start = false;
        bool ok = true;
        REP(j, n) {
            if ((i & (1 << j)) > 0) {
                start = true;
                c++;
                if (s[j] != 'A' && s[j] != 'C' && s[j] != 'G' && s[j] != 'T') {
                    ok = false;
                    break;
                }
            } else {
                if (start) break;
            }
        }
        if (ok) chmax(ans, c);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const ll INF = 1e18;
#define pu push
#define pb push_back
#define mp make_pair
#define print(x) cout << (x) << endl;
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define SORT(x) sort(x.begin(),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define fi first
#define sc second

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // cout << fixed << setprecision(10);
    int N, M;
    cin >> N >> M;
    cout << N*(N-1)/2 + M*(M-1)/2 << endl;
}

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

using namespace std;
using ll = long long;

int main() {
	ll A, B;
	cin >> A >> B;

	--A;
	int ak = 0;
	while (pow(2LL, ak) <= A) { ++ak; }
	int bk = 0;
	while (pow(2LL, bk) <= B) { ++bk; }
	--ak, --bk;

	vector<ll> da(bk + 1, 0);
	vector<ll> db(bk + 1, 0);
	for (int i = ak; i >= 0; --i) {
		ll k = 1LL<<i;
		if (k > A) { continue; }
		da[i] += (A - k + 1);
		for (int j = i - 1; j >= 0; --j) {
			da[j] += (1LL<<(i - 1));
		}
		A -= k;
	}
	for (int i = bk; i >= 0; --i) {
		ll k = 1LL<<i;
		if (k > B) { continue; }
		db[i] += (B - k + 1);
		for (int j = i - 1; j >= 0; --j) {
			db[j] += (1LL<<(i - 1));
		}
		B -= k;
	}

	ll res = 0;
	for (int i = 0; i <= bk; ++i) {
		if ((db[i] - da[i]) % 2 == 1) {
			res += (1LL<<i);
		}
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define arep(i, x, n) for (int i = int(x); i < (int)(n); i++)
#define rep(i, n) for (long long i = 0; i < n; ++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9 + 7
using ll = long long;

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

    int cnt = 0;
    for(int i = 0; i < N; i++){

        
        if(i % 2 == 0 && a[i] % 2 == 1){
            cnt++;
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define rep1(i,n) Rep(i,1,n)
#define rep(i,n) Rep(i,0,n-1)
int ans[20]={9},key=1,sum,n;
bool flag=0;
int main(){
	cin>>n;
	if(n<10){
		cout<<n;
		return 0;
	}
	n-=9;
	rep(j,n){
		for(int i=key-1;i>=0;i--){
			if(ans[i]==9){
				sum++;
				ans[i]=0;
			}
			else
				break;
		}
		if(sum==key){
			ans[0]=1;
			key++;
			flag=1;
		}
		if(sum<key&&flag==0){
			ans[key-1-sum]++;
			for(;;){
				int bug=-1;
				for(int i=0;i<key-1;i++)
					if(max(ans[i],ans[i+1])-min(ans[i],ans[i+1])>1){
						bug=i;
						break;
					}
				if(bug==-1)
					break;
				if(ans[bug]<ans[bug+1])
					ans[bug]++;
				for(int i=bug+1;i<key;i++)
					ans[i]=max(ans[i-1]-1,0);
			}
		}
		sum=0;
		flag=0;
	}
	rep(i,key)
		cout<<ans[i];
	cout<<endl;
	return 0;
}

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

#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__() for(long blockTime=NULL;(blockTime==NULL?(blockTime=clock())!=NULL:false); debug("Time:%.4fs\n",(double)(clock()-blockTime)/CLOCKS_PER_SEC))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.14159265358979323846264338327
#define INF 2e9
#define MOD 998244353
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef unsigned long long ull;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	string k="keyence";
	string s,a,b;	cin>>s;
	int n=s.length();
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			a=s.substr(0,i);
			b=s.substr(n-j,j);
		if(a+b==k){
			cout<<"YES\n";
			return 0;
		}
		}
	}
	cout<<"NO\n";
	
	return 0;
}


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

struct City
{
    int name; // city index
    long long year;
    string ID;
};

struct Prefecure
{
    vector<City> city;
};


bool cmp_year(const City a, const City b){
    return a.year < b.year;
};

bool cmp_ind(const City a, const City b){
    return a.name < b.name;
};


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

    int city_to_pre[N];

    int p;
    City city;
    vector<Prefecure> prefectures(N);
    for(int i = 0; i < M; i++){
        cin >> p; // 県番号
        cin >> city.year;
        city.name = i;
        prefectures[p-1].city.push_back(city);
    }

    for(int i = 0; i < N; i++){
        //cout << prefectures[i].city.size() << endl;
        sort(prefectures[i].city.begin(), prefectures[i].city.end(), cmp_year);
    }

    for(int i = 0; i < N; i++){
        for(int c = 0; c < prefectures[i].city.size(); c++ ){
            //cout << "i" << i << "c" << c << endl;
            ostringstream sout;
            sout << setfill('0') << setw(6) << (i+1)  << setfill('0') << setw(6) << (c+1);
            prefectures[i].city[c].ID = sout.str();
        }
    }

    vector<City> ans(M);
    int id = 0;
    for(int i = 0; i < N; i++){
        for(int c = 0; c < prefectures[i].city.size(); c++ ){
            ans[id] = prefectures[i].city[c];
            id ++;
        }
    }

    sort(ans.begin(), ans.end(), cmp_ind );

    for(int i = 0; i < M; i++){
        cout << ans[i].ID << endl; 
    }

}



Measured memory_bytes: 14080
import java.util.Scanner;
class Main
{
    public static void main(String args[])
    {
	Scanner scan=new Scanner(System.in);
	while(true)
	    {
		int n=scan.nextInt();
		if(n==0)break;
		int s[]=new int[n];
		char x[]=new char[100];
		int f=0;
		String str=scan.next();
		for(int i=0;i<100;i++)
		    {
			x[i]=str.charAt(i);
			if(x[i]=='S')
			    {
				f+=s[i%n]+1;
				s[i%n]=0;
			    }
			else if(x[i]=='M')s[i%n]++;
			else 
			    {
				s[i%n]+=f+1;
				f=0;
			    }
		    }
		for(int i=0;i<n;i++)
		    {
			for(int j=n-1;j>i;j--)
			    {
				if(s[j]<s[j-1])
				    {
				int t=s[j];
				s[j]=s[j-1];
				s[j-1]=t;
				    }
			    }
		    }
		for(int i=0;i<n;i++)
		    {
			System.out.print((i!=n)?s[i]+" ":"");
		    }
		System.out.print(f);
		System.out.println();
	    }
    }
}

Measured memory_bytes: 21656
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>


#define int  long long
#define rep(i,begin,end) for(__typeof(end)i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
// rep(i,1,10) is from 1 to 9 and rep(I,10,1) is from 9 to 1
#define F first
#define S second
#define sz(x) ((int)x.size())
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define pf push_front
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define mi multiset<int>
#define mii multiset<pii>
#define what_is(x) cerr << #x << " is " << x <<"\n";
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.rbegin(), v.rend())
#define PI 3.14159265358979323846
#define vout(a) for(auto x:a) cout<<x<<" ";

// #define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>


// using namespace __gnu_pbds;
using namespace std;

int lcm(int a,int b) {return (a*(b/__gcd(a,b)));}

int modp(int a,int n)
{
    if(n==0) return 1;
    if(n==1) return a;
    int res=modp(a,n/2);
    if(n%2==0) return (res*res);
    else return (a*res*res);
}

vi adj[1000005],ans;
vector<bool> vis(1000005,false);
map<pii,int> problem,elected;
int check=0;

bool dfs(int s)
{
    bool y=0;
    vis[s]=true;
    for(int u:adj[s])
    {
        if(!vis[u])
        {
            vis[u]=true;
            if(problem[{u,s}]||problem[{s,u}])
            {
                y=1;
                if(!dfs(u))
                {
                    ans.pb(u);
                }
            }
            else
            {
                if(dfs(u))
                {
                    y=1;
                }
            }
        }
    }
    return y;
}

void solve()
{
    int t,n,m,i,k,r,l,u,v,w,j,s,sum=0,pos,flag=0,count=0;
    string S,T,U;
    // int a,b,c;
    cin>>n>>w;
    vi weight(n),value(n),dp(w+1,0);
    rep(i,0,n) cin>>weight[i]>>value[i];
    dp[0]=0;
    // rep(i,1,w+1)
    // {
    //     rep(j,0,n)
    //     {
    //         if(i-weight[j]>=0) dp[i]=max(value[j]+dp[i-weight[j]],dp[i]);
    //     }
    //     // vout(dp) cout<<"\n";
    // }
    rep(i,0,n)
    {
        rep(j,w+1,weight[i])
        {
            dp[j]=max(value[i]+dp[j-weight[i]],dp[j]);
        }
    }
    cout<<dp[w];
}


signed main()
{
//    #ifndef ONLINE_JUDGE 
 //      freopen("input.txt","r",stdin);
  //     freopen("output.txt","w",stdout);
    //#endif
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve();
        cout<<"\n";
    }
    return 0;
}


Measured memory_bytes: 24576
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <queue>
#include <iomanip>
#include <cmath>
#include <map>
#include <cstring>

#define MAX
#define INF
#define MOD 1000000007
#define MP make_pair
#define AA first
#define BB second
#define IS(X) cout << #X << " = " << X << endl;
using namespace std;
int n;
char str[505][505];
bool b[505],w[505];
int cnt[505];
int main() {
    scanf("%d",&n);
    for(int i = 0;i < n;i++) {
        scanf("%s",str[i]);
        b[i] = true;w[i] = true;cnt[i] = 0;
    }
    int cntb = 0,cntw = 0;
    for(int i = 0;i < n;i++) {
        for(int j = 0;j < n;j++) {
            if(str[j][i] == '#') {
                cntb++;
                w[i] = false;
            }
            else {
                cntw++;
                cnt[j] ++;
                b[i] = false;
            }
        }
    }
    if(cntb == n * n) {
        puts("0");
    } else if(cntw == n*n) {
        puts("-1");
    } else {
        int ans = 501;
        for(int i = 0;i < n;i++) {
            //IS(cnt[i]);
            if(w[i]) ans = min(ans,cnt[i] + 1);
            else ans = min(ans,cnt[i]);
        }
        //cout << ans << endl;
        ans += n;
        for(int i = 0;i < n;i++) {
            if(b[i]) ans --;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 512
import java.util.*;

public class Main{

    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        String S = sc.next();
        sc.close();
    
        int count = 0;
        int idx = 0;
        while(idx < S.length()-1){
            if(S.charAt(idx) != S.charAt(idx+1)){
                count++;
            }
            idx++;
        }

        System.out.println(count);
    }
}

Measured memory_bytes: 26136
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int s, w;
    cin >> s >> w;
    if(w >= s) cout << "unsafe" << endl;
    else cout << "safe" << endl;
	return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  int n,k;
  cin >> n >> k;
  string s;
  cin >> s;
  int outc=0;
  int inc=0;
  int ohasi=0;
  int ihasi=0;
  if(s[0]=='L') ohasi++;
  else ihasi++;
  if(s[n-1]=='R') ohasi++;
  else ihasi++;
  int ans=0;
  
  rep(i,n-1){
    if(s[i]=='L' && s[i+1]=='R') outc++;
    else if(s[i]=='R' && s[i+1]=='L') inc++;
    else ans++;
  }
  if(outc<inc){
    swap(outc,inc);
    swap(ohasi,ihasi);
  }
  //    cout << ans << endl;
  //    cout << outc << endl;
  //    cout << inc << endl;
  if(k>= outc) ans +=inc*2+min(outc-inc,ohasi);
  else if(outc > k && k>=inc) ans+=2*inc+min(k-inc, ohasi);
  else if(inc>k) ans+=2*k;

  cout << ans << endl;


  
  return 0;
    

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long int
#define inv(name,Type,size) vector<Type> name(size);for(int index=0;index<n;index++) cin>>name[index];
#define F(a,n,i) for(int i=a;i<n;i++)
#define pb push_back
#define endl "\n"
#define mod 10000000007
#define modpro 99824435
using namespace std;

void solve(){
	int a;
	cin>>a;
	cout<<pow(a,2)+pow(a,3)+a;
}
int main()
{
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  
  //int t;cin>>t;while(t--) solve(),cout<<endl;
  solve();
}


Measured memory_bytes: 4304
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, string
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**7)
inf = float('inf')
mod = 10**9+7
ans = inf ;count = 0 ;pro = 1

a,b,c=map(int,input().split())
print(c//a*b)

Measured memory_bytes: 38512
import java.util.Scanner;

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

		if (A <= 9 && B <= 9) {
			System.out.println(A * B);
		} else {
			System.out.println(-1);
		}
	}
}

Measured memory_bytes: 21844
#include "bits/stdc++.h"
using namespace std;


int main()
{
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> ab(n);
	for (int i = 0; i < n; i++) {
		int a_in, b_in;
		cin >> a_in >> b_in;
		ab.at(i) = make_pair(a_in, b_in);
	}

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

	int ans = 0;
	int pos = 0;
	priority_queue<int> money;
	for (int i = 1; i <= m; i++) {
		while (pos < n && ab.at(pos).first <= i) {
			money.push(ab.at(pos).second);
			pos++;
		}
		if (!money.empty()) {
			ans += money.top();
			money.pop();
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 1660
#include <iostream>
using namespace std;
int main() 
{
	long i,j,n,ans=0,m=0,a=0,r=0,c=0,h=0;
	string s[100001];
  	cin >> n;

	for(i=0;i<n;i++){
		cin >> s[i];
	} 
	for(i=0;i<n;i++){
		if(s[i][0]=='M'){
			m++;
		}
		if(s[i][0]=='A'){
			a++;
		}
		if(s[i][0]=='R'){
			r++;
		}
		if(s[i][0]=='C'){
			c++;
		}
		if(s[i][0]=='H'){
			h++;
		}
	} 
	ans=(m*a*r)+(m*a*c)+(m*a*h)+(m*r*c)+(m*r*h)+(m*c*h)+(a*r*c)+(a*r*h)+(a*c*h)+(r*c*h);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6144
import math
x, k, d = map(int, input().split())

if(abs(x) - k*d >= 0):
    print(abs(x) - k*d)
else:
    num = abs(x) // d
    rest = abs(x) % d

    if(num % 2 == 0):
        if(k%2==0): print(rest)
        else: print(d-rest)
    else:
        if(k%2==1): print(rest)
        else: print(d-rest)

Measured memory_bytes: 9168
n = int(input())
cnt = 0
for i in range(1, n + 1, 2):
    j = 1
    temp = 0
    while j * j <= i:
        if i % j == 0:
            temp += 1
            if j != i // j:
               temp += 1
        j += 1
    if temp == 8:
        cnt += 1
print(cnt)

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

const long long INF=1e18l+5;
int main(){
	int n,w;
	cin>>n>>w;
  vector<int>weights(n);
  vector<int>values(n);
  int sum_ans=0;
  for(int i=0;i<n;i++) {
    cin>>weights[i]>>values[i];
    sum_ans+=values[i];
  }
  vector<long long>dp(sum_ans+1,INF);
  dp[0]=0;
  for(int i=0;i<n;i++){
    for(int j=sum_ans-values[i];j>=0;j--){
      dp[j+values[i]]=min(dp[j+values[i]],dp[j]+weights[i]);
    }}

  int ans=0;
  for(int i=0;i<=sum_ans;i++){
    if(dp[i]<=w) ans=max(ans,i);
  }
  cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4024
#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<cfloat>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#include<random>
#include<stdlib.h>
#define rip(i,n) for(int i=0;i<n;i++)
#define Rip(i,n) for(int i=1;i<=n;i++)
#define RIP(i,a,b) for(int i=a;i<b;i++)
#define all(V) V.begin(),V.end()
#define sec  setprecision;
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops");
constexpr double eps = 1e-9;
constexpr double pi = 3.141592653589793238462643383279;
using namespace std;
using ll = long long;
using ld = long double;
using Pa = pair<int, int>;
ll mod = 1000000007;
ll MOD = 998244353;
ll gcd(ll a, ll b)
{
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
ll pow(ll x, ll n) {
	x %= mod;
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return (pow((x * x) % mod, n / 2) % mod);
	else
		return (x * pow(x, n - 1)) % mod;
}
signed main() {
	int a, b, c, d; cin >> a >> b >> c >> d;
	if (a != c)cout << 1 << endl;
	else cout << 0 << endl;
}

Measured memory_bytes: 3636
#include<cstdio>
#define MAXN 20
#define INF -2147483647
using namespace std;
int n,m,x;
struct node{
	int price;
	int upvalue[MAXN];
}book[MAXN];
int level[MAXN];
int min = -2147483647;
bool check(){

	for(int i = 1;i <= m;i++){
		if(level[i] < x)return 0;
	}
	return 1;
}
void dfs(int now, int pri){
	if(check()){
		if(min == INF) min = pri;
		min = min > pri ?pri : min;
		return ;
	}
	if(now > n)return ;
	
	for(int i = 1;i <= m;i++)
		level[i] += book[now].upvalue[i];
	dfs(now + 1, pri + book[now].price);
	for(int i = 1;i <= m;i++)
		level[i] -= book[now].upvalue[i];
		
	dfs(now + 1, pri);
}
int main(){
	scanf("%d%d%d",&n,&m,&x);
	for(int i = 1;i <= n;i++){
		scanf("%d",&book[i].price);
		for(int j = 1;j <= m;j++){
			scanf("%d",&book[i].upvalue[j]);
		}
	}
	dfs(1, 0);
	
	if(min == INF)printf("-1");
	else printf("%d",min);
} 

Measured memory_bytes: 1728
#include <stdio.h>
int main(void){
  int n,i;
  long y=100000;
  scanf("%d\n",&n);
  for(i=0;i<n;i++){
    y=y*1.05;
    if(y%1000)
      y=((y/1000)+1)*1000;
  }
  printf("%ld\n",y);

  return 0;
}

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

//Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

//Type Definitions:
typedef long long ll;
typedef unsigned long long ull;

//Constants:
const int INF = 2e9;
const int MOD = 1e9 + 7;

//Global Variables:

//Prototype Declarations:
int gcd(int, int);

//================ Main Loop ================
int main() {
    int n;
    cin >> n;
    vector<int> x(n);
    rep(i, n) {
        cin >> x[i];
    }
    int p, ans = INF;
    for(p = 1; p <= 100; p++) {
        int cost = 0;
        rep(i, n) {
            cost += (x[i] - p) * (x[i] - p);
        }
        ans = min(ans, cost);
    }
    cout << ans << endl;
    return 0;
}
//===========================================

//Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpT, *szpFpA;
#endif

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	char lc1Buf[1024], lc1Out[1024];

	// テストファイルオープン
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpT = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#endif

	// 範囲取得
	long long llSVal, llEVal;
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
	fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif
	sscanf(lc1Buf, "%lld%lld", &llSVal, &llEVal);

	// 範囲縮小
	llEVal /= llSVal;

	// 長さ取得
	int liLen = 1;
	long long llVal = 2;
	while (llEVal >= llVal) {
		llVal *= 2;
		liLen++;
	}

	// 結果セット
	sprintf(lc1Out, "%d\n", liLen);

	// 結果表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpT);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <string.h>

using namespace std;

int main(int argc, char* argv[]) {
  int N, W;
  cin >> N >> W;

  int v[N];
  int w[N];
  for (int i = 0; i < N; ++i)
    cin >> v[i] >> w[i];

  int dp[N + 1][W + 1];
  memset(dp, 0, sizeof(int) * (N + 1) * (W + 1));
  dp[0][0] = 0;

  for (int i = 0; i < N; ++i) {
    for (int j = 0; j <= W; ++j) {
      if (w[i] > j)
        dp[i + 1][j] = dp[i][j];
      else
        dp[i + 1][j] = max(v[i] + dp[i][j - w[i]], dp[i][j]);
    }
  }

  cout << dp[N][W] << endl;

  return 0;
}


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

int main(){
    int n;
    while(true){
        cin>>n;
        if(n==0){break;}
        int table[26]={0};
        char chara[n+1];
        int maxi1=0;
        int maxi2=0;
        char max_chara[2];
        for(int i=0;i<n;i++)cin>>chara[i];
        for(int t=0;t<n;t++){
            table[chara[t]-'A']++;
            if(table[chara[t]-'A']>maxi1){
                maxi1=table[chara[t]-'A'];
                max_chara[0]=chara[t];
            }
            else if(table[chara[t]-'A']>maxi2)maxi2=table[chara[t]-'A'];
            if(maxi1-maxi2 >= n-t){
                cout<<max_chara[0]<<" "<<t+1<<endl;
                break;
            }
            if(t==n-1)
                if(maxi1==maxi2)
                    cout<<"TIE"<<endl;
        }
    }
}


Measured memory_bytes: 3092
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>

using namespace std;

int main() {
    bool dp[2][16001] = {{0}};
    dp[0][8000] = dp[1][8000] = true;
    int fcnt=0, tcnt=0;
    string s; cin >> s;
    s += 'T';
    for (auto c:s) {
        if (c == 'F') fcnt++;
        else {
            bool buf[16001] = {0};
            for (int i=0; i<=16000; i++) {
                if (dp[tcnt%2][i]) {
                    if (tcnt > 0) 
                        buf[i - fcnt] = true;
                    buf[i + fcnt] = true;
                }
            }
            memcpy(dp[tcnt % 2], buf, 16001);
            tcnt++;
            fcnt = 0;
        }
    }
    int x, y;
    cin >> x >> y;
    cout << (dp[0][8000+x] && dp[1][8000+y] ? "Yes" : "No") << '\n';
    return 0;
}

Measured memory_bytes: 384
#include<cmath>
#include<iostream>
#include<vector>
#include<string>
#include<sstream>
#include<chrono>
#include<algorithm>
#include<functional>
#include<cstdlib>
#include<numeric>
#include<omp.h>
#include<queue>
#include<stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
constexpr double PI = 3.14159265358979323846;
int main()
{
	double R;
	cin >> R;
	std::cout << 2 * PI * R << std::endl;

}

Measured memory_bytes: 3784
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if(n%2==0) {
			System.out.println(n/2);
		}else {
			System.out.println(n/2+1);
		}
		sc.close();
	}
}


Measured memory_bytes: 21844
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int n=sc.nextInt(),f=1;
    HashMap<String,Integer> map=new HashMap<String,Integer>();
    List<String> list=new ArrayList<String>();
    for(int i=0;i<n;i++){
      String s=sc.next();
      if(map.get(s)==null){
        map.put(s,1);
      }else{
        map.put(s,map.get(s)+1);
        if(map.get(s)>f){
          f=map.get(s);
        }
      }
    }
    for(String key:map.keySet()){
      if(map.get(key)==f){
        list.add(key);
      }
    }
    Collections.sort(list);
    for(int i=0;i<list.size();i++){
      System.out.println(list.get(i));
    }
  }
}


Measured memory_bytes: 84412
n,m = [int(i) for i in input().split()]

l = []
m = []
for j in range(n):
    k,*a = [int(i) for i in input().split()]
    l.append(a)
    m.append(k)

count = 0
for i in l[0]:
    flag = 0
    for j in range(len(l)):
        if i not in l[j]:
            flag = 1

    if flag == 0:
        count += 1
print(count)


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<set>
#include<cmath>
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
typedef ll int__;
#define rep(i,j) for(int__ i=0;i<(int__)(j);i++)
#define repeat(i,j,k) for(int__ i=(j);i<(int__)(k);i++)
#define all(v) v.begin(),v.end()

struct UnionFind{
    int n;
    vector<int> p;
    UnionFind(int nn) : n(nn+1){
        p.resize(n);
        rep(i, n) p[i] = i;
    }
    int root(int x){
        if(p[x] == x) return x;
        else return p[x] = root(p[x]);
    }
    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if(x != y) p[y] = x;
    }
    bool query(int x, int y){
        return root(x) == root(y);
    }
};


int main(){
    int N, M; cin >> N >> M;
    UnionFind ut(N);
    set<int> absorbed;
    rep(i, M){
        int a, b; cin >> a >> b;
        a--; b--;
        absorbed.insert(a);
        absorbed.insert(b);
        ut.unite(a, b);
    }
    set<int> city;
    rep(i, N){
        if(ut.root(i) != i) city.insert(ut.root(i));
    }
    int villedge = N - absorbed.size();
    cout << abs(villedge - (int)city.size()) << endl;

    return 0;
}

Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
#define repe(i,a,n) for( int i = a ; i < n ; i++ )
typedef long long ll;
int main(){
  
  int N ,counter = 0 , ans = 0 ;
  cin  >> N ;
  repe(i,1,8) if( N >= pow(10,i) ) counter++ ;
  //cout <<counter << endl;
  repe(i,1,4){
  //cout << i << endl ;
  if( counter >= i*2 - 1 ) ans = ans +  9*pow(10,2*(i-1));
  else {
  if( counter == 1 || counter == 3 ) break; 
  ans = ans + N + 1 - pow( 10,2*(i-1) );
  break;
  }
  }

  cout << ans << endl;
  
  
}


  

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

const double PI = acos(-1);

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000
#define LLINF 1e18

// 素数判定
bool is_prime(ll n) {
	if (n == 1) return false;
	for (int i = 2; i * i <= n; ++i) {
		if (n % i == 0) return false;
	}
	return true;
}

void solve_abc_c() {
	ll n, m;
	ll k;
	ll h, w;
	//ll x;
	//ll a;
	string s;
	string s_ans;
	ll l_ans = 0;
	double d_ans = 0;

	cin >> n;

	rep2(i, n, n * 2) {
		if (is_prime(i)) {
			cout << i << "\n";
			return;
		}
	}
}

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed;
	cout << setprecision(15);

	solve_abc_c();

	return 0;
}


Measured memory_bytes: 3612
#include <iostream>
using namespace std;
int main()
{
    int a[3],b[3],c[9];
    for(int i=0;i<3;i++)
    {
        cin>>c[i];
        b[i]=c[i];
    }
    cin>>c[3];
    a[1]=c[3]-b[0];
    cin>>c[4]>>c[5];
    if(a[1]+b[1]==c[4]&&a[1]+b[2]==c[5]){}
    else
    {
        cout<<"No"<<endl;
        return 0;
    }
    cin>>c[6]>>c[7]>>c[8];
    a[2]=c[6]-b[0];
    if(a[2]+b[1]==c[7]&&a[2]+b[2]==c[8]){}
    else
    {
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
def solve():
    N = int(input())
    C = []
    S = []
    F = []
    for i in range(N-1):
        c, s, f = map(int,input().split())
        C.append(c)
        S.append(s)
        F.append(f)
    
    for fr in range(N-1):
        t = S[fr]
        for to in range(fr+1,N):
            t += C[to-1]
            if to != N-1:
                waittime = 0
                if t < S[to]:
                    waittime = S[to] - t
                elif t % F[to] == 0:
                    waittime = 0
                else:
                    waittime = F[to] - (t%F[to])
                t += waittime
        print(t)
            
    print(0)

if __name__ == '__main__':
    solve()

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

using namespace std;

int main(void)
{	
	string s;
	cin >> s;
	if (s[0] != 'A') {
		cout << "WA" << endl;
		return 0;
	}

	int c = 0;
	bool f = false;
	for (int i = 2; i < s.length() - 1; i++) {
		if (s[i] == 'C') {
			if (f) {
				cout << "WA" << endl;
				return 0;
			}
			else {
				c = i;
				f = true;
			}
		}
	}
	if (c == 0) {
		cout << "WA" << endl;
		return 0;
	}

	for (int i = 1; i < s.length(); i++) {
		if (i == c) {
			continue;
		}
		if (s[i] < 'a' || s[i] > 'z') {
			cout << "WA" << endl;
			return 0;
		}
	}
	cout << "AC" << endl;
	
	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

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

	d := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&d[i])
	}

	var sum int
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			sum += d[i] * d[j]
		}
	}
	fmt.Println(sum)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
typedef vector<ll> vl;

const int MN = 200012;
const ll mod = 998244353;
ll f[MN], f_inv[MN];

ll modpow (ll a, ll b, ll m = mod) {
  ll res = 1;
  while (b) {
    if (b&1) res = res*a%m;
    a = a*a%m;
    b >>= 1;
  }
  return res;
}

ll add (ll a, ll b, ll m = mod) { return (a+b)%m; }
ll mul (ll a, ll b, ll m = mod) { return a*b%m; }
ll ncr (ll n, ll r) { return f[n]*f_inv[n-r]%mod*f_inv[r]%mod; }

void init () {
  f[0] = f_inv[0] = 1;
  for (ll i = 1; i < MN; i++) {
    f[i] = mul(f[i-1], i);
    f_inv[i] = modpow(f[i], mod-2, mod);
  }
}

int main (void) {
  ios::sync_with_stdio(false);cin.tie(0);
  cout << fixed << setprecision(15);
  init();
  ll n, m, k;
  cin >> n >> m >> k;
  ll ans = 0;
  for (ll i = n-k; i <= n; i++) {
    ans = add(ans, mul(ncr(n-1, i-1), mul(m, modpow(m-1, i-1))));
  }
  cout << ans << '\n';
  return 0;
}



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

int main() {
  int N;
  cin >> N;
  
  vector<int> mochi(N);
  for(int i = 0; i < N; i++){
    cin >> mochi.at(i);
  }
  
  sort(mochi.begin(), mochi.end());
  
  vector<int> exist(N);
  exist.at(0) = 1;
  int sum = exist.at(0);
  
  for(int i = 1; i < N; i++){
    if(mochi.at(i) == mochi.at(i - 1))
       exist.at(i) = 0;
    else
       exist.at(i) = 1;
    
    sum += exist.at(i);
  }
      
  cout << sum << endl;
  
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>  
using namespace std;
#define mod 1e9+7
typedef long long ll;
 
int main()
{
   	int n,m,temp;
   	cin>>n>>m;

   	int ans=(n*(n-1))/2;
   	ans+=(m*(m-1))/2;

  	cout<<ans;
    return 0;
}
     

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <tuple>
#include <vector>
#include <bitset>
#include <stack>
#include <iomanip>
#include <set>
typedef long long ll;
typedef unsigned long long ull;
#define mk make_pair
#define mkt make_tuple

using namespace std;

int main()
{
    ll n;
    cin >> n;
    ll temp = n;
    ll diff = 0;
    ll k = 1;
    while (temp != 1) {
        if (temp % 2 == 0) diff += k;
        temp >>= 1;
        k <<= 1;
    }
    cout << n + diff;
}



Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
const ll mod=1e+9;
typedef pair<int,int> P;
#define fi first
#define se second
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
ll a;
cin>>a;
ll ans=3*a*a;
cout<<ans<<endl;
}


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

using namespace std;

typedef long long int ll;

ll M=1e9+7;

int main(){
    string s,t;
    cin>>s>>t;
    ll ans=INT_MAX;
    for(int i=0;i+t.size()<=s.size();i++){
        ll temp=0;
        for(int j=0;j<t.size();j++){
            if(s[i+j]!=t[j]) temp++;
        }
        ans=min(ans,temp);
    }
    cout<<ans<<"\n";
    return 0;
}


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

typedef long long ll;
const int INF = 1e9;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin>>n;
	int work = 0;
	int temp;
	int m;
	cin>>m;
	for (int i = 0; i < m; i++) {
		cin>>temp;
		work+=temp;
	}
	cout<<(work>n?-1:n-work)<<'\n';
	return 0;
}

Measured memory_bytes: 3616
A = int(input()) # 500円
B = int(input()) # 100円
C = int(input()) # 50円
X = int(input()) # 合計

price = [500, 100, 50]
count = 0

for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if price[0]*i + price[1]*j + price[2]*k == X:
                count+= 1
print(count)

Measured memory_bytes: 3064
S = str(input())
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])
E = ["-", "+"]
ans = []
for i in range(0, 2):
    for j in range(0, 2):
        for k in range(0, 2):
            tmp = A
            if i & 1:
                tmp += B
            else:
                tmp -= B
            if j & 1:
                tmp += C
            else:
                tmp -= C
            if k & 1:
                tmp += D
            else:
                tmp -= D
            if tmp == 7:
                ans.append(i)
                ans.append(j)
                ans.append(k)
print("{0}{1}{2}{3}{4}{5}{6}=7".format(
    A, E[ans[0]], B, E[ans[1]], C, E[ans[2]], D))


Measured memory_bytes: 3064