akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cmath>
#include<string>
#include<map>
#include<queue>

using namespace std;

#define N 3
#define M 9

struct Puzz{
  int f[M];
  int space;
  string path;

  bool operator < (const Puzz &p) const {
    for(int i=0;i<M;i++){
      if(f[i] == p.f[i]) continue;
      return f[i] > p.f[i];
    }
    return false;
  }
};

static const int dx[4] = {-1, 0, 1 ,0};
static const int dy[4] = {0, -1, 0, 1};
static const char dirc[4] = {'u','l','d','t'};

bool Tage(Puzz p){
  for(int i=0;i<M;i++)
  if(p.f[i] != (i+1)) return false;
  return true;
}

string afs(Puzz m){
  queue<Puzz> Q;
  map<Puzz, bool> V;
  Puzz u,v;
  m.path="";
  Q.push(m);
  V[m]=true;


  while(!Q.empty()){
    u=Q.front(); Q.pop();

    if(Tage(u)) return u.path;
    int mx=u.space/N;
    int my=u.space%N;

    for(int i=0;i<4;i++){
      int px=mx+dx[i];
      int py=my+dy[i];
      if(px<0 || py<0 || px>=N || py>=N) continue;
      v=u;
      swap(v.f[u.space],v.f[px*N+py]);
      v.space=px*N+py;

      if(!V[v]){
        V[v]=true;
        v.path+=dirc[i];
        Q.push(v);
      }
    }
  }
  return "unsolvable";
}

int main(){
  Puzz ln;

  for(int i=0;i<M;i++){
    cin >> ln.f[i];
    if(ln.f[i] ==0){
      ln.f[i]=M;
      ln.space =i;
    }
  }
  string answer = afs(ln);
  cout << answer.size() << endl;

  return 0;
}



Measured memory_bytes: 30620
n = int(input())
s = input()

count = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            ii = s.find(str(i))
            if ii != -1 and ii <= n-3 and str(j) in s[ii+1:]:
                ji = s.find(str(j), ii+1)
                if ji != -1 and ji <= n-2 and str(k) in s[ji+1:]:
                    count += 1

print(count)


Measured memory_bytes: 3060
import math
X, K ,D =map(int, input().split())
ansp =ansm = float('inf')
n = math.ceil(abs(X)/D)
r = K - n

# X>0だったとき
if r>0:
    if r%2 ==0:
        ansp = abs(X-D*n)
    else:
        ansp = abs(X-D*n+D)
else:
    ansp = abs(X-K*D)

# X<0だったとき
if r>0:
    if r%2 ==0:
        ansm = abs(X+D*n)
    else:
        ansm = abs(X+D*n-D)
else:
    ansm = abs(X+K*D)

print(min(ansp,ansm))

Measured memory_bytes: 9212
n = int(input())
a = [int(_) for _ in input().split()]
m = float('inf')
i = 0
total = 0
minus = 0
while i < n:
    if a[i] < 0:
        m = min(m, -a[i])
        total -= a[i]
        minus += 1
    else:
        m = min(m, a[i])
        total += a[i]
    i += 1
if minus % 2 == 1:
    ans = total - 2 * m
else:
    ans = total
print(ans)

Measured memory_bytes: 14412
n, m, x = map(int, input().split())
lst = []
for i in range(n):
  lst.append(list(map(int, input().split())))
pmin = 10 ** 10
for i in range(1, 2 ** n): # 選び方
  sbin = format(i, 'b')
  sbin = '0' * (n - len(sbin)) + sbin
  temp = [0] * m
  p = 0
  for j in range(n): # 選ぶ行
    if sbin[j] == '1':
      for k in range(m): # 足す
        temp[k] += lst[j][k + 1]
      p += lst[j][0]
  if min(temp) >= x:
    pmin = min(pmin, p)
if pmin == 10 ** 10:
  print(-1)
else:
  print(pmin)

Measured memory_bytes: 9228
n = int(input())
cmax = 0
imax = 1
for i in range(1,n+1):
  cnt = 0
  ig = i
  while i % 2 == 0:
    i /= 2
    cnt += 1

  if cnt > cmax:
    cmax = cnt
    imax = ig
print(imax)

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

int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	
	if(a==c&&a!=b)
	    cout<<"Yes"<<endl;
	else if(a==b&&a!=c)
	    cout<<"Yes"<<endl;
	else if(b==c&&b!=a)
	    cout<<"Yes"<<endl;
	else
	    cout<<"No"<<endl;
		     
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		int A,B,C,X;
		Scanner scan = new Scanner(System.in);
		A = scan.nextInt();
		B = scan.nextInt();
		C = scan.nextInt();
		X = scan.nextInt();
		int n = 0;

		for(int a = 0; a <= A; a++) {
			for(int b = 0; b <= B; b++) {
				for(int c = 0; c <= C; c++) {
					if((500 * a + 100 * b + 50 * c) == X) {
						n++;
					}
				}
			}
		}

		System.out.println(n);
	}
}

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

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    string s; cin >> s;

    if(s == "zyxwvutsrqponmlkjihgfedcba"){
        cout << -1 << endl;
        return 0;
    }

    map<char, int> mp;
    for(int i=0; i<s.size(); i++){
        mp[s[i]]++;
    }

    for(char c='a'; c<='z'; c++){
        if(mp[c] == 0){
            cout << s << c << endl;
            return 0;
        }
    }

    char ch = 'z';
    for(int i=s.size()-1; i>0; i--){
        if(s[i-1] < s[i]){
            for(int j=s.size()-1; j>=i-1; j--){
                if(s[j] > s[i-1]) ch = min(ch, s[j]);
            }
            s[i-1] = ch;
            cout << s.substr(0, i) << endl;
            return 0;
        }
    }
    
}

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

int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	if (A + B > C + D)cout << "Left" << endl;
	else if (A + B < C + D)cout << "Right" << endl;
	else cout << "Balanced" << endl;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

void solve(){
    i64 N,P,even=0,odd=0;
    cin >> N >> P;
    rep(i,0,N){
        i64 A;
        cin >> A;
        if(A%2==0) ++even;
        else ++odd;
    }

    if(P==1 and odd==0){
        cout << 0 << endl;
        return;
    }

    i64 ans=1;
    rep(i,0,even) ans=ans*2;
    rep(i,0,odd-1) ans=ans*2    ;
    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 256
program remainder_minimization_2019
  implicit none
  integer :: l, r, m, i, j
  m = 2020
  read(*,*) l, r
  if (r-l.ge.2018) then
    l = 0
    r = 2018
  end if
  l = mod(l,2019)
  r = mod(r,2019)
  if (l.gt.r) r = r+2019
  do i = l, r-1
    do j = i+1, r
      m = min(m,mod(i*j,2019))
    end do
  end do
  write(*,'(i0)') m
  stop
end program remainder_minimization_2019

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); i++)
#define itrep(type, it, t) for(type::iterator it=t.begin(); it!=t.end(); it++)
using namespace std;


int main(void) {

    string s;
    cin >> s;

    if(s[2] == s[3] && s[4] == s[5]) cout << "Yes";
    else cout << "No";

    

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

int main()
{
    int n;
    cin >> n;
    double t = 0;
    for (int i = 0; i < n; i++)
    {
        double a;
        cin >> a;
        t += (1 / a);
    }
    cout << fixed << setprecision(8) << (1 / t) << endl;

    return 0;
}


Measured memory_bytes: 256
fun main(args :Array<String>){
  var input : String? = readLine()
  var value = input!!.toLong()
  var view :Long = 0
  var num1 = value / 500
  var num2 = (value - num1*500)/5
  view = num1*1000 + num2 * 5
  println(view)
}

Measured memory_bytes: 31836
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <string>
#include <vector>
 
using namespace std;
typedef long long ll;
using gra = vector<vector<ll>>;
using gram = vector<unordered_map<ll,ll>>;
 
typedef unsigned long long ull;
 
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; }
 
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> T dup(T a, T b) { return (a + b - 1) / b; }
template <class T> T modpow(T x, T p, T m) { T a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
// template <class T> void prim(T a) { for(ll i=0;i<a.size();++i) { cout << a[i]; } cout << "\n"; }
 
#define mod 1000000007LL
#define INF 10000000000000000LL
 
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define rrep1(i, n) for (int i = n; i > 0; --i)
 
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
//#define modpow(x, p, m) { ll a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
 
#define m0(h) memset(h, 0, sizeof(h))
#define m1(h) memset(h, 1, sizeof(h))
#define m(h, n) memset(h, (n), sizeof(h))
#define all(n) (n).begin(),(n).end()
#define bit(n) (1LL << (n))
#define pb push_back
 
//#ifdef LOCAL
//
//#define dpri(...) fprintf(stderr, __VA_ARGS__)
//#define pria(g) rep(i,g.size()){ cout << i << "{"; rep(j,g[i].size()) cout << g[i][j] << " "; cout << "}" << "\n"; }
//#else
//#define dpri(...) 42
//#define pria(g) 42
//#endif
 
 
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ---------------------
  // コーディング開始
  // ---------------------
  ll a,b,c;
  cin >> a>>b;
  pri(a-b+1);

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int gcd(int a,int b){
  if(b==0)return a;
  return gcd(b,a%b);
}
int main() {
  int k=0;
  int ans=0;
  scanf("%d", &k);
  for(int a=1;a<k+1;a++){
    for(int b=1;b<k+1;b++){
      int t=gcd(a,b);
      for(int c=1;c<k+1;c++){
        ans+=gcd(t,c);
      }
    }
  }
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 1712
import sys
def call(n):	
	for i in xrange(1, n+1):
		if (i % 3) == 0:
			sys.stdout.write(" " + str(i))
		elif (i % 10) == 3:
			sys.stdout.write(" " + str(i))
		else:
			x = i
			x = x / 10
			while x > 0:
				if (x % 10) == 3:
					sys.stdout.write(" " + str(i))
					break
				x = x / 10
				
	print ""
	

n = int(raw_input())
call(n)

Measured memory_bytes: 4224
import java.util.Scanner;

public class Main {

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

		String s = sc.next();
		int ans = 700;
		
		for(int i = 0; i < 3; ++i) {
			char chr = s.charAt(i);
			
			if(chr == 'o') {
				ans += 100; 
			}
		}
		System.out.println(ans);
	}
}

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

int main(){
  
  int m1,d1,m2,d2;
  
  cin>>m1>>d1>>m2>>d2;
  
  if(d2-d1!=1){
    cout<<"1"<<endl;
  }else{
    cout<<"0"<<endl;
  }
  return 0;
}

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

int main() {
    int N;
    string S;
    cin >> N >> S;
    for (int i = 0; i < S.size(); ++i) {
        int k = S[i] - 'A';
        k = (k + N) % 26;
        S[i] = k + 'A';
        cout << S[i];
    }
    return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def intersection(a1, a2, b1, b2):
    x1,y1 = a1
    x2,y2 = a2
    x3,y3 = b1
    x4,y4 = b2

    ksi = (y4 - y3) * (x4 - x1) - (x4 - x3) * (y4 - y1)
    eta = (x2 - x1) * (y4 - y1) - (y2 - y1) * (x4 - x1)
    delta = (x2 - x1) * (y4 - y3) - (y2 - y1) * (x4 - x3)
    if delta == 0:
        return None
    ramda = ksi / delta;
    mu = eta / delta;
    if ramda >= 0 and ramda <= 1 and mu >= 0 and mu <= 1:
        return (x1 + ramda * (x2 - x1), y1 + ramda * (y2 - y1))

    return None

def main():
    rr = []

    n = I()
    ni = 0

    while ni < n:
        ni += 1
        xa,ya,xb,yb = LI()
        a1 = (xa,ya)
        a2 = (xb,yb)
        m = I()
        a = [LI() for _ in range(m)]
        t = []
        for xs,ys,xt,yt,o,l in a:
            k = intersection(a1,a2,(xs,ys),(xt,yt))
            if k is None:
                continue
            t.append((k,o^l))
        if len(t) == 0:
            rr.append(0)
            continue

        t.sort()
        c = t[0][1]
        r = 0
        for _,tc in t:
            if tc != c:
                r += 1
                c = tc

        rr.append(r)


    return '\n'.join(map(str, rr))



print(main())



Measured memory_bytes: 9120
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

const int MAX_V = 6e2;
vector<int> es[MAX_V];
ld memo[MAX_V];
int N;

ld dfs(int now){
    if(now == N-1) return 0;
    ld E = 0, n = es[now].size();
    for(auto &e: es[now]){
        if(memo[e] >= 0) E += memo[e];
        else E += dfs(e);
    }
    E = 1+(E/n);
    memo[now] = E;
    return E;
}

ld dfs2(int now, int s, int t){
    if(now == N-1) return 0;
    ld E = 0, n = es[now].size();
    for(auto &e: es[now]){
        if(now == s && e == t) n--;
      	elif(memo[e] >= 0) E += memo[e];
        else E += dfs2(e, s, t);
    }
    E = 1+(E/n);
  	memo[now] = E;
    return E;
}

int main(){
    int M;
    cin >> N >> M;
    fill(memo, memo+N, -1);
    memo[N-1] = 0;
    rep(i, M){
        int s, t; cin >> s >> t; s--, t--;
        es[s].pb(t);
    }
    rep(i, N) dfs(i);
    int del[N];
    fill(del, del+N, -1);
    rep(i, N){
        if(es[i].size() <= 1) continue;
        ld M = -1;
        for(auto &e: es[i]){
            if(memo[e] > M){
                del[i] = e;
                M = memo[e];
            }
        }
    }
    ld ans = INF;
    rep(i, N){
      	fill(memo, memo+N, -1);
        ans = min(ans, dfs2(0, i, del[i]));
    }
    cout << sp(10) << ans << endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

int n;
int coins[100];
int dp[51][10001];
const int INF=1000000000;

int dfs(int pos,int money){
	if(pos==n){
		if(money==0)return 0;
		return INF;
	}
	if(dp[pos][money]!=-1)return dp[pos][money];
	int res=INF;
	// ¥¦éÈçÎ¥¤
	if(money-coins[pos]>=0)res=min(res,dfs(pos,money-coins[pos])+1);
	// àzÏX
	res=min(res,dfs(pos+1,money));
	return dp[pos][money]=res;
}

int main(){
	int cnt=0;
	while(cin>>n&&n){
		bool con=false;
		cnt++;
		cout<<"Case #"<<cnt<<": ";
		for(int i=0;i<n;i++)cin>>coins[i];
		sort(coins,coins+n);
		memset(dp,-1,sizeof(dp));
		for(int j=1;j<=10000;j++)dfs(0,j);
		for(int i=1;i<=10000;i++){
			if(dp[0][i]==INF){
				cout<<"Cannot pay some amount"<<endl;
				con=true;
				break;
			}
		}
		if(con)continue;
		// »ê¼êÌàzðgreedyÅ¥¤
		for(int i=1;i<=10000;i++){
			int leftm=i;
			int allc=0;
			for(int j=n-1;j>=0;j--){
				int cnt=leftm/coins[j];
				leftm-=cnt*coins[j];
				allc+=cnt;
			}
			if(dp[0][i]!=allc){
				cout<<"Cannot use greedy algorithm"<<endl;
				con=true;
				break;
			}
		}
		if(con)continue;
		cout<<"OK"<<endl;
	}
	return 0;
}

Measured memory_bytes: 2860
n = int(input())
h = list(map(int, input().split()))

memo = [0] * n
memo[0] = 0
memo[1] = abs(h[0]-h[1])

for i in range(2,n):
    memo[i] += min(abs(h[i]-h[i-1])+memo[i-1],\
                    abs(h[i]-h[i-2])+memo[i-2])
print(memo[-1])


Measured memory_bytes: 13980
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  vector<int>A(N);
  for(int i=0;i<N;i++)
    cin>>A.at(i);
  int Max=0;
  for(int i=0;i<N;i++)
    if(Max<A.at(i))
      Max=A.at(i);
  int half=Max/2;
  int r=1000000000;
  for(int i=0;i<N;i++){
  if(abs(A.at(i)-half)<abs(r-half) && A.at(i)!=Max)
    r=A.at(i);
  }cout<<Max<<" "<<r<<endl;

   return 0;
}

Measured memory_bytes: 640
using System;
using System.Linq;

class MainClass
{
    public static void Main()
    {
        for (; ; )
        {
            string[] str = Console.ReadLine().Split(' ');
            int h = int.Parse(str[0]), w = int.Parse(str[1]);

            if (h == 0 && w == 0)
                break;

            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < w; j++)
                {
                    Console.Write('#');
                }
                Console.WriteLine();
            }
            Console.WriteLine();
        }
    }
}

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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353
#define Graph vector<vector<int>>

int main() {
    int H, W; cin >> H >> W;
    vector<vector<char>> s(H, vector<char>(W));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> s.at(i).at(j);
        }
    }
    string ans = "Yes";
    bool judge;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (s.at(i).at(j) == '#') {
                judge = false;
                int ha = i - 1, hb = i + 1, wa = j - 1, wb = j + 1;
                if (ha > -1) {
                    if (s.at(ha).at(j) == '#') judge = true;
                }
                if (hb < H) {
                    if (s.at(hb).at(j) == '#') judge = true;
                }
                if (wa > -1) {
                    if (s.at(i).at(wa) == '#') judge = true;
                }
                if (wb < W) {
                    if (s.at(i).at(wb) == '#') judge = true;
                }
                if (judge == false) {
                    ans = "No";
                    break;
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N=int(input())
S=input()
ls=[0 for _ in range(N)]
for i in range(N):
  if S[i]=='W':
    ls[i]=1
ans=0
i=0
j=N-1
while True:
  if ls[i]==1 and ls[j]==0:
    ls[i]=0
    ls[j]=1
    i+=1
    j-=1
    ans+=1
  elif ls[i]==0 and ls[j]==0:
    i+=1
  elif ls[i]==1 and ls[j]==1:
    j-=1
  else:
    i+=1
    j-=1
  if i>=j:
    break
print(ans)

Measured memory_bytes: 10936
//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <map>
using namespace std;
#define ll  long long int
 
int main() {
	//freopen("test.txt", "r", stdin);
	ll n,k; cin>>n>>k;
	if(n>k){
		ll r=n%k, q=n/k;
		n-=k*q;
	}cout<<min(n,k-n)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) ll aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) string aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
		
	int N,K;
	string S;
	cin>>N>>K;
	cin>>S;
	pairs(ZERO)
	fx(N){
		if(S.at(x)=='0'){
			int start=x;
			while(x<N&&S.at(x)=='0'){
				x++;
			}
			pb(ZERO,make_pair(start,x-1))
		}
	}
	int ans=0;
  if(ZERO.size()==0){
    ce(N)
  }else{
	fx(ZERO.size()){

		int i=x;
		int k=1;
		while(i<ZERO.size()&&k<K){
			i++;
			k++;
		}
		if(k!=K||i>=ZERO.size()){i--;}
		int l=ZERO.at(i).second;
		while(l+1<N&&S.at(l+1)=='1'){l++;}
		
		
		int j=ZERO.at(x).first;
		while(j-1>=0&&S.at(j-1)=='1'){
			j--;
		}
		ans=max(ans,l-j+1);
		
	}
	ce(ans)
  }
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const int maxm = 1e6 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a * b / gcd(a,b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool isp(ll x){if(x <= 1) return 0; for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;}
int a,b;
int main(){
 	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> a >> b;
	if(a <= b){
		for(int i = 0;i < b;i++) cout << a;
		cout << endl;
	}
	else{
		for(int i = 0;i < a;i++) cout << b;
		cout << endl;
	}
	return 0;
}
//do smt instead of nothing! never give up!
//take care of long long!
//take care of upper or lower case e.g "yes" or "YES"?
//boundary condition! e.g. n = 0?
//brute force is always the first choice!
// print the ans to look for patterns in the data!

Measured memory_bytes: 256
def main
  n, m, x, y = gets.split.map(&:to_i)
  # pp [n, m, x, y]

  x_max = gets.split.map(&:to_i).max
  y_min = gets.split.map(&:to_i).min

  x_max = [x, x_max].max
  y_min = [y, y_min].min
  # pp [x_max, y_min]

  if x_max < y_min
    puts 'No War'
  else
    puts 'War'
  end

end

if __FILE__ == $0
  main
end


Measured memory_bytes: 1788
from collections import Counter
H, W = map(int, input().split())
counter = Counter()
for h in range(H):
    row = input()
    for a in row:
        counter[a] += 1
ans = True
if (H * W) % 2 == 0:
    for k, v in counter.items():
        if v % 2 == 0:
            continue
        ans = False
        break
    
else:
    odd_count = 0
    for k, v in counter.items():
        if v % 2 == 0:
            continue
        odd_count += 1
    if odd_count != 1:
        ans = False
if ans:
    g3 = (H // 2) * (W // 2)
    for k, v in counter.items():
        if v >= 4:
            g3 -= v // 4
    if g3 <= 0:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Measured memory_bytes: 38512
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N,Q;string S;cin>>N>>Q>>S;
	int L[Q],R[Q];
	int AC[N];AC[0]=0;int count=0;
	for(int i=1;i<N;i++){
		if(S.at(i-1)=='A'&&S.at(i)=='C'){
			count++;
		}AC[i]=count;
	}for(int j=0;j<Q;j++){
		cin>>L[j]>>R[j];
        L[j]--;R[j]--;
        if(L[j]==0){
            cout<<AC[R[j]]<<endl;
        }else if(S.at(L[j]-1)=='A'&&S.at(L[j])=='C'){
			cout<<AC[R[j]]-AC[L[j]-1]-1<<endl;
		}else{
			cout<<AC[R[j]]-AC[L[j]-1]<<endl;
		}
	}
}

Measured memory_bytes: 2176
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aryssoncf
 */



// Taken from: https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/templateShort.cpp

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ull> vul;
typedef vector<ll> vl;
typedef vector<pii> vpii;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i,0,a)
#define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i, a) ROF(i,0,a)
#define trav(a, x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

#define mp make_pair
#define pb push_back
#define f first
#define s second

const int MOD = 1e9 + 7; // 998244353; // = (119<<23)+1
const int MX = 2e5 + 5;

template<class T>
bool ckmin(T &a, const T &b) {
    return a > b ? a = b, 1 : 0;
}

template<class T>
bool ckmax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

mt19937 rng((uint32_t) chrono::steady_clock::now().time_since_epoch().count());


//
// Created by aryssoncf on 28/10/2019.
//

#include <type_traits>


#include <iterator>
#include <utility>

template<typename T>
constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) {
    return true;
}

constexpr bool hasBegin(...) {
    return false;
}

template<typename T>
using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>;


#ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP
#define JHELPER_EXAMPLE_PROJECT_IO_HPP

#endif //JHELPER_EXAMPLE_PROJECT_IO_HPP

template<typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
    for (T &element: vec) {
        is >> element;
    }
    return is;
}

template<typename T, typename U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    is >> p.first;
    is >> p.second;
    return is;
}

template<class X, class Y>
std::ostream &operator<<(std::ostream &os, std::pair<X, Y> const &p) {
    return os << p.first << " " << p.second;
}

template<class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) {
    bool first = true;
    for (auto &y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

using namespace std;

class BBreakNumber {
public:
    void solve(std::istream &in, std::ostream &out) {
        int n;
        in >> n;
        int res = 1 << __lg(n);
        out << res << '\n';
    }

    void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
    BBreakNumber solver;
    solver.setup();
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 3656
import java.util.*;

public class Main{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);     
        String s1=sc.next();
        String s2=sc.next();
        long a1=sc.nextLong();
        long a2=sc.nextLong();
        String s3=sc.next();
        if(s3.equals(s1))
        {
        	a1=a1-1;
        	System.out.println(a1);
        	System.out.println(a2);
        	
        }
        else
        {

        	a2=a2-1;
        	System.out.println(a1);
        	System.out.println(a2);
        


        }
        sc.close();
       



        }
    
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int n;
  cin >> n;
  vector<LL> a(n),b(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=0;i<n;i++){
    cin >> b[i];
  }
  priority_queue<int> que;
  LL total=0,count=0;
  for(int i=0;i<n;i++){
    if(a[i]>=b[i]){
      que.push(a[i]-b[i]);
    }else{
      total+=b[i]-a[i];
      count++;
    }
  }
  LL tmp=0;
  LL ans=count;
  while(tmp<total){
    if(que.empty()){
      cout << -1 << endl;
      return 0;
    }
    ans++;
    tmp+=que.top();
    que.pop();
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2428
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S; cin >> S;
  int N=S.size();
  for(int i=0; i<N-1; i++) {
    for(int j=1; j<N; j++) {
      if(i!=j && i<j) {
        if(S[i]=='C' && S[j]=='F') {
          cout << "Yes" << endl;
          return 0;
          break;
        }
      }
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n+1];
    r(i,n)cin>>a[i];
    a[n]=0;
    int sum=0;
    r(i,n){
        if(a[i]==1){
            int pre=i;
            while(a[i])i++;
            sum=max(sum,i-pre);
        }
    }
    cout<<sum+1<<endl;
}



Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>

#define Rep(i,a,b) for(ll i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using namespace std;

using ll = long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

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

    void Cout(long long x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const T& x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; i++) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }

    // 標準入出力
    struct inp {
        std::size_t sz;
        inp(std::size_t _sz = 1) : sz(_sz) {}
        template <typename T> operator T () const { T a; std::cin >> a; return a; }
        template <typename T> operator std::vector<T>() const { std::vector<T> a(sz); for (std::size_t i = 0; i < sz; i++) std::cin >> a[i]; return a; }
    };

    // 2次元用の標準入出力
    template<typename T>
    struct inpn {
        std::size_t szi, szj;
        inpn(std::size_t _szi, std::size_t _szj) : szi(_szi), szj(_szj) {}
        operator std::vector<std::vector<T>>() const {
            std::vector<std::vector<T>> a(szi, std::vector<T>(szj));
            for (std::size_t i = 0; i < szi; ++i)
                for (std::size_t j = 0; j < szj; ++j) cin >> a[i][j];
            return a;
        }
    };

    inp inp1; // input one
}


int main() {

    ll n, W;
    cin >> n >> W;
    vector<ll> w(n), v(n);
    rep(i, n) cin >> w[i] >> v[i];

    vector<vector<ll>> dp(n + 1, vector<ll>(W + 1, 0LL));

    rep(i, n) {
        rep(j, W + 1) {
            // 入れない
            chmax(dp[i + 1][j], dp[i][j]);
            // 入れる
            if (j - w[i] >= 0)
                chmax(dp[i + 1][j], dp[i][j - w[i]] + v[i]);
        }
    }

    ll ans = 0LL;
    rep(j, W + 1) {
        chmax(ans, dp[n][j]);
    }
    Cout(ans);

    return 0;
}

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

int main() {
    int N;
    cin >> N;
    string S, T;
    cin >> S >> T;
    vector<char> vec_S(N);
    vector<char> vec_T(N);
    for (int i=0; i<N; i++) {
        vec_S.at(i) = S.at(i);
        vec_T.at(i) = T.at(i);
    }
    vector<char> vec(2*N);
    for (int i=0; i<2*N; i++) {
        if (i%2 == 0) {
            vec.at(i) = vec_S.at(i/2);
        }
        else {
            vec.at(i) = vec_T.at(i/2);
        }
    }
    string answer = "aa";
    for (int i=1; i<N; i++) {
        answer+="aa";
    }
    for (int i=0; i<2*N; i++) {
        answer.at(i) = vec.at(i);
    }
    cout << answer << endl;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  if (n % 1000 == 0)
    cout << 0 << '\n';
  else
    cout << 1000 - (n % 1000) << '\n';
  return 0;
}

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

int main() {

    int P, Q, R;

    std::cin >> P >> Q >> R;

    int calc[3] = {(P+Q), (Q+R), (R+P)};

    int ans = 1000;

    for(int i=0; i< 3; i++){
        if(calc[i] <= ans){
            ans = calc[i];
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
#define INF 100000000


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

    int N, K;
    cin >> N >> K;
    int temp;
    int place;
    int ans = 1000000;
    for(int i = 0; i < N; ++i) {
        cin >> temp;
        if(temp == 1) place = i;
    }
    int Atemp = 0;
    rep(p, K) {
        Atemp = 0;
        temp = place - p;

        for(int i = 0;; ++i) {
            if(temp == 0 && i == 0) break;
            temp -= (K - 1);
            //cout << temp << endl;
            if(temp <= 0) {
                Atemp += (i + 1);
                break;
            }
        }

        temp = place - p;

        for(int i = 0;; ++i) {
            if(temp == N - 1 && i == 0) break;
            temp += (K - 1);
            //cout << temp << endl;
            if(temp >= N - 1) {
                Atemp += (i + 1);
                break;
            }
        }

        ans = min(ans, Atemp);
    }

    rep(p, K) {
        Atemp = 0;
        temp = place + p;

        for(int i = 0;; ++i) {
            if(temp == 0 && i == 0) break;
            temp -= (K - 1);
            //cout << temp << endl;
            if(temp <= 0) {
                Atemp += (i + 1);
                break;
            }
        }

        temp = place + p;

        for(int i = 0;; ++i) {
            if(temp == N - 1 && i == 0) break;
            temp += (K - 1);
            //cout << temp << endl;
            if(temp >= N - 1) {
                Atemp += (i + 1);
                break;
            }
        }

        ans = min(ans, Atemp);
    }

    cout << ans << endl;

}


Measured memory_bytes: 256
#include <stdio.h>

int num[45];

int fib(int n){
  if((n==0)||(n==1)){
    return num[n] = 1;
  }
  if(num[n]>0){
    return num[n];
  }
  return num[n] = fib(n-1)+fib(n-2);
}

int main(){
  int n;

  scanf("%d",&n);
  printf("%d\n",fib(n));

  return 0;
}



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

vector< pair< string, pair<int, int > > > v;

signed main() {

    int n;
    cin >> n;
    for ( int i = 0; i < n; i++ ) {
        string s;
        int p;
        cin >> s >> p;
        v.push_back ( make_pair ( s, make_pair ( -p, i+1 ) ) );
    }
    sort ( v.begin(), v.end() );
    for ( int i = 0; i < n; i++ ) {
        cout << v[i].second.second << endl;
    }

    return 0;
}

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

bool exist[100001];
int n, k;
bool zero = false;

int main(){
    while(cin >> n >> k){
        if(n + k == 0)  break;

        for(int i = 0; i < 100001; i++) exist[i] = false;

        int x;
        for(int i = 0; i < k; i++){
            cin >> x;
            exist[x] = true;
        }

        int beforeEnd = -2, beforeLength = 0;
        int ans = 0;
        for(int i = 1; i < 100001; i++){
            if(exist[i]){
                int start = i;
                while(i+1 < 100001 && exist[i+1]){
                    i++;
                }
                int tmpans = i-start+1;
                
                if(start-2 == beforeEnd && exist[0]){
                    tmpans += beforeLength+1; 
                }

                ans = max(ans, tmpans);
                beforeEnd = i;
                beforeLength = i-start+1;
            }
        }

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


Measured memory_bytes: 3184
N = int(input())
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
C = [int(_) for _ in input().split()]
ans = 0
cnt = 0
for a in A:
    ans += B[a - 1]
    if cnt + 1 == a and cnt != 0:
        ans += C[a - 2]

    cnt = a

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define alphanso                      \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    if ((abs(a - b) + 1) % 2 == 0)
        cout << "Borys";
    else
        cout << "Alice";
    return 0;
}

Measured memory_bytes: 3620
//おまじないc++
#include <iostream>
#include<cmath>
#include<vector>
#include <algorithm>
using namespace std;
 
 int main() {
  long  int n;
  cin>>n;
  vector<long int> v(n);
  long int length=0;
  
 for(int i=0;i<n;i++){
  cin>> v.at(i);
  length+=v.at(i);
 }
   
   vector<long int> w(n);
   long int front =0;
   for(int i=0;i<n;i++){
     front+=v.at(i);
     w.at(i)=labs(2*front-length);
   }
   
   sort(w.begin(), w.end());
     
   cout<<w.at(0)<<endl;
 }
  
  
  

  

Measured memory_bytes: 3328
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int N = sc.nextInt();
      	int sum = 0;
		for(int i=0;i<N;i++){
		sum += sc.nextInt();
		}
  		if(H - sum <= 0){
		System.out.println("Yes");
		}else{
		System.out.println("No");
        }
	}
}

Measured memory_bytes: 49120
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n; cin >> n;
	int a[n];
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}

	int i = 0;
	int j = 1, res = 0;;
	while (i < n)
	{
		if(a[i] == j) {
			j++;
			res++;
		}
		i++;
	}

	if(res == 0) cout << "-1" << endl;
	else cout << n - res << endl;

	return 0;
}


Measured memory_bytes: 4396
class UnionFind:
    def __init__(self, size):
        self.parent = [-1 for i in range(size)]#非負なら親ノード，負ならグループの要素数

    def root(self, x): #root(x): xの根ノードを返す．
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.root(self.parent[x]) #xをxの根に直接つなぐ
            return self.parent[x]

    def merge(self, x, y): #merge(x,y): xのいるグループと$y$のいるグループをまとめる
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        if self.parent[x] > self.parent[y]: #xの要素数がyの要素数より「小さい」とき入れ替える
            x,y=y,x
        self.parent[x] += self.parent[y] #xの要素数を更新
        self.parent[y] = x #yをxにつなぐ
        return True

    def issame(self, x, y): #same(x,y): xとyが同じグループにあるならTrue
        return self.root(x) == self.root(y)
        
    def size(self,x): #size(x): xのいるグループの要素数を返す
        return -self.parent[self.root(x)]


n,m=[int(i) for i in input().split()]

A=[[int(i)-1 for i in input().split()] for _ in range(m)]

ans = [0]*(m+1)
a = n*(n-1)//2
ans[0] = a

uf = UnionFind(n)
for i in range(m):
    j = m-i-1
    v1 = A[j][0]
    v2 = A[j][1]
#    print(v1,v2)
    if not uf.issame(v1,v2):
#        print(uf.parent)
        a -= uf.size(v1) * uf.size(v2)
        uf.merge(v1,v2)

    ans[i+1]=a

for i in range(m):
    print(ans[m-i-1])
    
    
    
    
    
    





Measured memory_bytes: 27196
#include<stdio.h>
int main(void){
int i,n;
int number;
long long int sum=0;
int min=0;
int max=0;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&number);
if(i==0){

min=number;
max=number;
}
if(number<min)min=number;
if(number>max)max=number;
sum+=number;
}
printf("%d %d %lld\n",min,max,sum);
return 0;
}

Measured memory_bytes: 1028
import math
from functools import reduce

def gcd(*numbers) :
    return reduce(math.gcd , numbers)

K = int(input())
ans = 0
for i in range(1,K+1) :
    ans += i
for i in range(1,K) :
    for j in range(i+1,K+1) :
        ans += math.gcd(i,j) * 6
if K >= 3 :
    for i in range(1,K-1) :
        for j in range(i+1,K) :
            for k in range(j+1,K+1) :
                ans += gcd(i,j,k) * 6
print(ans)

Measured memory_bytes: 9252
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  ll a; cin >>a;
  string s; cin >>s;
  rep(i, s.size()){
    if (s[i] == '.'){
      s.erase(i,1);
      // cout <<s <<endl;
      break;
    }
  }
  ll b = stoi(s);

  ll res = a * b;
  res /= 100;
  cout <<res <<endl;
}


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

int main(){
    string S;
    cin >> S;
    if(S.at(2)==S.at(3) && S.at(4) == S.at(5)) cout << "Yes" << endl;
    else cout << "No" << endl;
}   

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

alias R = Tuple!(int, "w", int, "d");

void solve(int n, int w, int d)
{
    auto rs = [R(w, d)];
    foreach (_; 0..n) {
        auto ps = readln.split.to!(int[]);
        auto p = ps[0]-1;
        auto s = ps[1];
        auto r = rs[p];
        foreach (i; p..rs.length-1) rs[i] = rs[i+1];
        rs = rs[0..$-1];

        while (s > r.w*2 + r.d*2) s -= r.w*2 + r.d*2;
        if (s < r.w) {
            auto w1 = s;
            auto w2 = r.w - s;
            if (w1 > w2) swap(w1, w2);
            rs ~= [R(w1, r.d), R(w2, r.d)];
        } else if (r.w < s && s < r.w + r.d) {
            s -= r.w;
            auto d1 = s;
            auto d2 = r.d - s;
            if (d1 > d2) swap(d1, d2);
            rs ~= [R(r.w, d1), R(r.w, d2)];
        } else if (r.w + r.d < s && s < r.w*2 + r.d) {
            s -= r.w + r.d;
            auto w1 = s;
            auto w2 = r.w - s;
            if (w1 > w2) swap(w1, w2);
            rs ~= [R(w1, r.d), R(w2, r.d)];
        } else {
            s -= r.w*2 + r.d;
            auto d1 = s;
            auto d2 = r.d - s;
            if (d1 > d2) swap(d1, d2);
            rs ~= [R(r.w, d1), R(r.w, d2)];
        }
    }
    auto nd = rs.map!(r => r.w * r.d).array;
    sort(nd);
    writeln(nd.to!(string[]).join(" "));
}

void main()
{
    for (;;) {
        auto nwd = readln.split.to!(int[]);
        if (nwd == [0, 0, 0]) return;
        solve(nwd[0], nwd[1], nwd[2]);
    }
}


Measured memory_bytes: 3200
#include <stdio.h>
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <vector>

using namespace std;

#define MAX_N 10010

int P[10010];
int A[1001];
int B[1001];
int COST[1001];
int N;
int M;
pair<int,int> bridge[1001];

void init(int N) { // 初期化 はじめは全ての頂点はバラバラ
	for (int i=0; i<N; ++i) P[i] = i;
}

int root(int a) { // a の root(代表元) を求める
	if (P[a] == a) return a; // aはroot
	return (P[a] = root(P[a])); // a の親の root を求め,a の親とする
	
}

bool is_same_set(int a, int b) { // a と b が同じグループに属するか?
	return root(a) == root(b);
}

void unite(int a, int b) { // a と b を同一グループにまとめる
	P[root(a)] = root(b);
}

int main()
{
	while(cin >> N >> M && N){
		init(1001);
		for(int i=0; i<M; ++i)
		{
			cin >> A[i] >> B[i] >> COST[i];
			bridge[i].first = COST[i];
			bridge[i].second = i;
		}
		
		sort(bridge, bridge+M);
		for(int i=0; i<M; ++i)
		{
			int cost = bridge[i].first;
			int a = A[bridge[i].second];
			int b = B[bridge[i].second];
			//cout << a << "から" << b << "に" << cost << "コスト橋が架かっている" << endl;
		}
		
		int total = 0;
		for(int i=0; i<M; ++i)
		{
			int a = A[bridge[i].second];
			int b = B[bridge[i].second];
			if(is_same_set(a,b)) continue;
			unite(a,b);
			total += bridge[i].first;
		}
		cout << total << endl;
	}

}

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

int main(){

int N,T,A;
int X,temp,min=100000,ans=0;
scanf("%d",&N);
scanf("%d%d",&T,&A);
X = 1000*(T-A)/6;

int H;
for (int i = 0; i < N; i++)
{
  scanf("%d",&H);
  temp = abs(X-H);
  if (min>temp)
  {
    min = temp;
    ans = i;
  }
}

printf("%d",ans+1);

return 0;

}

Measured memory_bytes: 1684
import 'dart:io';

void main() {
  String s = stdin.readLineSync();
  int count;
  count = 0;
  int sum;
  sum = 1;
  if (s[0] == 'R') {
    count = 1;
    sum = 1;
  } else if (s[0] == 'S') {
    count = 0;
    sum = 0;
  }
  for (int i = 1; i < 3; i++) {
    if (count == 0 && s[i] == "R") sum = 1;
    if (s[i - 1] == "R" && s[i] == "R") {
      sum++;
    }
  }
  print(sum);
}


Measured memory_bytes: 13160
//ABC81_B

import java.util.Scanner;

public class Main{

	public static void main(String[] args){

		Scanner scan = new Scanner(System.in);

		int C11 = scan.nextInt();
		int C12 = scan.nextInt();
		int C13 = scan.nextInt();
		scan.nextLine();

		int C21 = scan.nextInt();
		int C22 = scan.nextInt();
		int C23 = scan.nextInt();
		scan.nextLine();

		int C31 = scan.nextInt();
		int C32 = scan.nextInt();
		int C33 = scan.nextInt();
		scan.nextLine();


		if(((C12-C11)==(C22-C21)&&(C22-C21)==(C32-C31))
			&& ((C13-C12)==(C23-C22)&&(C23-C22)==(C33-C32))
			&& ((C31-C21)==(C32-C22)&&(C32-C22)==(C33-C23))
			&& ((C21-C11)==(C22-C12)&&(C22-C12)==(C23-C13)))
			{System.out.println("Yes");	}
		else
			{System.out.println("No"); }

	}
}

Measured memory_bytes: 23508