akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <vector>
#include <queue>
#include <math.h>
#include <string> 
#include <bits/stdc++.h>
using namespace std;

const int INF = 1001001001; 

int main(){
    int n,x,y;
    cin >> n >> x >> y;
    x=x-1;
    y=y-1;
    vector<int> ans(n);
    for(int i=0;i<n;i++){
        vector<int> dis(n,INF);
        queue<int> q;
        q.push(i);
        dis[i]=0;
        //ここの＆はINFを参照するために必要？
        auto push = [&] (int v,int d){
            if(dis[v]!=INF){
                return;
            }else{
                dis[v]=d;
                q.push(v);
            }
        };
        while(!q.empty()){
            int v,d;
            v = q.front();
            q.pop();
            d = dis[v];
            if(v>0){
                push(v-1,d+1);
            }
            if(v<n-1){
                push(v+1,d+1);
            }
            if(v==x){
                push(y,d+1);
            }
            if(v==y){
                push(x,d+1);
            }
        }
        for(int i=0;i<n;i++){
            ans[dis[i]]=ans[dis[i]]+1;
        }
    }
    for(int i=0;i<n;i++){
        ans[i] = ans[i]/2;
    }
    for(int i=1;i<n;i++){
        cout << ans[i] << endl;
    }
}

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

int diffplus(int n){
    int sum = 0; 
    while (n > 0){
        sum += n%10;
        n /= 10;
    }
    return sum;
}

int main(void){
    int n;
    cin >> n;
    int j = 0,sum = 1000000;
    int temp = 0;
    rep(i,n){
        j = n - i;
        int a = diffplus(i);
        int b = diffplus(j);
        temp =  a+b;
        if(sum > temp) sum = temp;          
    }
    cout << sum << endl;

}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli, lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout << (bool x ? "Yes" : "No") << endl;
#define out(s) cout << s << endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define all(s) s.begin(), s.end()
void vout(vi v)
{
    for (int i = 0; i < v.size(); i++)
        cout << v.at(i) << endl;
}
int main()
{
    lli n;
    cin >> n;
    vi ans(n,0);
    for (lli x = 1; x <= n; x++)
    {
        if (x * x > n)
        {
            break;
        }
        else
        {
            for (lli y = 1; y <= n; y++)
            {
                if (y * y > n)
                {
                    break;
                }
                else
                {
                    for (lli z = 1; z <= n; z++)
                    {
                        if (z * z > n)
                        {
                            break;
                        }
                        else
                        {
                            lli now = x * x + y * y + z * z + x * y + y * z + z * x;
                            if(now<=n){
                                ans[now - 1]++;
                            }
                        }
                    }
                }
            }
        }
    }
    vout(ans);
}

Measured memory_bytes: 3656
import java.util.*;
import java.io.*;

public class Main{
    public static void main(String[] args){
        FastScanner fsc=new FastScanner();
        int N =fsc.nextInt();
        int T =fsc.nextInt();

        int ans = 1000000000;
        for (int i = 0; i < N; i++) {
        	int c = fsc.nextInt();
        	int t = fsc.nextInt();
        	if (T>=t) {
        		ans = Math.min(ans, c);
        	}	
        }
        fsc.close();
        if (ans > 1000) {
        	System.out.println("TLE");
        } else {
        	System.out.println(ans);
        }
    }
    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte(){
            if(ptr<buflen) return true;
            else{
                ptr = 0;
                try{
                    buflen = in.read(buffer);
                }
                catch(IOException e){
                    e.printStackTrace();
                }
                if(buflen<=0) return false;
            }
        return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }
                else if(b == -1 || !isPrintableChar(b)) return minus ? -n : n;
                else throw new NumberFormatException();
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
        public void close(){
            try{in.close();}
            catch(IOException e){e.printStackTrace();}
        }
    }
}


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

using namespace std;

#define MAX 10050

struct P{
  int dist,cost,v;
  bool operator < (const P &p)const{
    if(dist != p.dist){
      return dist > p.dist;
    }
    return cost > p.cost;
  }
};

int main(){
  int N,M;
  while(cin >> N >> M, N){
    int u,v,d,c,res = 0;
    vector<P> G[MAX];
    for(int i = 0 ; i < M ; i++){
      cin >> u >> v >> d >> c;
      u--; v--;
      G[u].push_back((P){d,c,v});
      G[v].push_back((P){d,c,u});
    }
    bool visited[MAX] = {0};
    priority_queue<P> Q;
    Q.push((P){0,0,0});

    while(!Q.empty()){
      P p = Q.top(); Q.pop();
      int v = p.v;
      if(visited[v]) continue;
      visited[v] = 1;
      res += p.cost;
      for(int i = 0 ; i < (int)G[v].size() ; i++){
        P e = G[v][i];
        Q.push((P){p.dist+e.dist,e.cost,e.v});
      }
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 3028
import Data.Array
import Control.Monad
check_lonely::Array (Int,Int) Char->Bool
check_lonely ar = let ((x_i,y_i),(x_f,y_f)) = bounds ar in
                  let neigh_coods (x,y) = filter (\(a,b)-> (a>=x_i)&&(a<=x_f)&&(b>=y_i)&&(b<=y_f)) [(x+1,y),(x,y+1),(x-1,y),(x,y-1)]in
                  []==[(x,y)|x<-[x_i..x_f],y<-[y_i..y_f],ar!(x,y)=='#',and (map (\p->(ar!p)=='.') (neigh_coods (x,y))) ]

main::IO()
main=do
  hwc<-getLine
  let h:w:[]= map read (words hwc)
  ss<-forM [1..h] (\_ -> getLine)
  let dat = listArray ((1,1),(h,w)) (concat ss)
  putStr (if check_lonely dat then "Yes\n" else "No\n")

Measured memory_bytes: 1020
program CADDiB2018C
    implicit none
    integer(8)::N,P,Ps,i,i_cnt,ans=1
    read*,N,P
    Ps=int(sqrt(real(P)))+1
    do i=2,Ps
        if(mod(P,i)==0)then
            i_cnt=0
            do
                if(mod(P,i)/=0)exit
                P=P/i
                i_cnt=i_cnt+1
            end do
            ans=ans*(i**(i_cnt/N))
        end if
    end do
    ans=ans*(P**(1/N))
    print'(i0)',ans
end program CADDiB2018C

Measured memory_bytes: 2964
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;
constexpr long long INF = std::numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, q, last, cnt, sum[2000000], ans, dp[2000000];
Pll a[2000000],b[2000000];
string str,ss;
bool f;
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ -1,0 } ,{ 0,-1 } };
struct Edge { LL to, cost; };
vector<Edge>vec[1000000];
vector<Pll>v;
map<string, LL>ma;
set<LL>st;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i].fir >> a[i].sec;
		if (i == 0)
			h = a[0].fir, w = a[0].sec;
		cnt=max(h / a[i].fir+(h%a[i].fir==0?0:1), w / a[i].sec + (w%a[i].sec == 0 ? 0 : 1));
		h = cnt * a[i].fir, w = cnt * a[i].sec;
	}
	cout << h + w << endl;
	return 0;
}


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

int main() {
    
    int a, b, c, d; cin >> a >> b >> c >> d;
    int l = a + b;
    int r = c + d;
    string ans = "Balanced";
    if (l < r) ans = "Right";
    if (l > r) ans = "Left";    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
import java.util.*;
import java.io.*;

/*
   AtCoder contest code
   coder : yoichidon
 */
class Counter<T> extends HashMap<T,Integer>{
    public Counter(){
        super();
    }
    public Integer get(Object elm){
        return getOrDefault(elm,0);
    }
    public void add(T elm, int amount){
        if(!this.containsKey(elm)) put(elm, amount);
        else replace(elm, get(elm)+amount);
    }
    public void addOne(T elm){
        add(elm, 1);
    }
    public void remove(T elm, int amount){
        replace(elm, Math.max(get(elm)-amount, 0));
    }
    public void removeOne(T elm){
        remove(elm, 1);
    }
}

public class Main {

    public static Counter<Long> fact(long N){
        Counter<Long> divisors = new Counter<>();
        long d = 2;
        while(d*d <= N){
            if(N%d==0) {
                divisors.addOne(d);
                N /= d;
            }
            else d++;
        }
        if(N>1) divisors.addOne(N);
        return divisors;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        for(int n=0; n<N; n++){
            int a = sc.nextInt();
            if(a%2!=0){
                System.out.println("first");
                return;
            }
        }
        System.out.println("second");
        return;
    }
}


Measured memory_bytes: 48396
#include<stdio.h>

void gotocall( int n )
{
	int i=1;
	int x;

    while(  ++i <= n ) {
        x=i;
        if( 0==(x%3) ) {
            printf( " %d", i );
        } else {
            while( x ) {
                if( 3==(x%10) ) {
                    printf( " %d", i );
                    break;
                }
                x /= 10;
            }
        }
    }	
	
	printf( "\n");
	return;
}

int main( void ) 
{
	int n;

	scanf( "%d", &n ); 
	gotocall( n );

	return 0;
}

Measured memory_bytes: 600
import numpy as np

N = int(input())
A = np.array(input().split(), dtype=np.int32)
B = np.array(input().split(), dtype=np.int32)

ans = 0
pow = 1
for digit in range(30) :
    mask = pow*2 - 1
    maskedA = A & mask
    maskedB = B & mask

    maskedA.sort()
    maskedB.sort()

    sum1, sum2, sum3 = (np.searchsorted(maskedB, bound - maskedA).sum() for bound in [pow, pow*2, pow*3])
    count = sum1 + (sum3 - sum2)

    if (N - count) % 2 == 1 :
        ans += pow
    pow *= 2

print(ans)


Measured memory_bytes: 35904
#!/usr/bin/env python3
import sys
from itertools import chain


def solve(S: str, T: str):
    answer = T + S
    return answer


def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    answer = solve(S, T)
    print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 8984
n,m=map(int,input().split())
k=0
if n%2==1:
  for i in range(m):
    print(i+1,end=" ")
    print(n-i)
elif n%4==0:
  for i in range((n+2)//4):
    if k>=m:
      break
    print(i+1,end=" ")
    print(n-i)
    k+=1
  for i in range((n+2)//4,n//2):
    if k>=m:
      break
    print(i+1,end=" ")
    print(n-i-1)
    k+=1
else:
  for i in range((n+2)//4-1):
    if k>=m:
      break
    print(i+1,end=" ")
    print(n-i)
    k+=1
  for i in range((n+2)//4-1,n//2):
    if k>=m:
      break
    print(i+1,end=" ")
    print(n-i-1)
    k+=1

Measured memory_bytes: 9168
#include<stdio.h>
int main(){
  int n,k;
  long long int max=0,min=0,i;
  long long int count=0;
  scanf("%d%d",&n,&k);
  for(i=0;i<k;i++){
    max+=n-i;
    min+=i;
  }
  count+=max-min+1;
  for(i=k;i<=n;i++){
    max+=n-i;
    min+=i;
    count+=max-min+1;
    count%=1000000007;
  }
  printf("%d\n",count);
  return 0;
}


Measured memory_bytes: 1692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)

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

    ll s = 0;
    ll g = max(a,b)-min(a,b);
    ll small = min(c,d);
    ll big = max(c,d);

    for(int i = 0; i < n; i++){
        ll l = small*(n-1-i)-big*i;
        ll r = big*(n-1-i)-small*i;

        if(l<=g && g<=r){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;

template <typename T>
istream &operator>>(istream &is, vector<T> &v)
{
    for (int i = 0; i < v.size(); ++i)
    {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    for (int i = 0; i < v.size() - 1; ++i)
    {
        os << v[i] << " ";
    }
    if (v.size() > 0)
    {
        os << v[v.size() - 1] << endl;
    }
    return os;
}

int main()
{
    int a, b;
    cin >> a >> b;
    cout << a * b << endl;
}


Measured memory_bytes: 3520
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	constexpr int M = 1e4+7;
	int n;
	string s;
	cin >> n >> s;
	vector<vector<int>> dp(n+1, vector<int>(1<<3));
	dp[0][1] = 1;
	vector<int> admin(n+1);
	transform(begin(s), end(s), begin(admin)+1, [](char c) {
			return string("JOI").find(c);
			}
		 );
	for (auto i = 0; i < n; i++) {
		for (auto j = 1; j < (1<<3); j++) {
			if (!(j & (1<<admin[i]))) continue;
			for (auto k = 1; k < (1<<3); k++) {
				if (!(j & k) || !(k & (1<<admin[i+1]))) continue;
				dp[i+1][k] += dp[i][j];
				dp[i+1][k] %= M;
			}
		}
	}
	int res = 0;
	for (auto& i : dp[n]) {
		res += i;
		res %= M;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 1304
totalNum, totalFoot = map(int, input().split())

if totalFoot <= totalNum * 4:
    flg = False
    for i in range(totalNum + 1):
        craneNum = i
        turtleNum = totalNum - i
        foot = (craneNum * 2) + (turtleNum * 4)

        if foot == totalFoot:
            flg = True
            print("Yes")
            break
    
    if not flg:
        print("No")
else:
    print("No")

Measured memory_bytes: 9184
#pragma GCC optimize "O3"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int mod = 1e9 + 7;
int dp[101][4][4][4];
int ng[4][4][4][4];

int main() {
  int n;
  cin >> n;
  memset(dp, 0, sizeof(dp));
  dp[0][0][0][0] = 1;
  memset(ng, 0, sizeof(ng));
  {
    int A = 1;
    int G = 2;
    int C = 3;
    for (int i = 0; i < 4; ++i) {
      ng[A][G][C][i] = 1;
      ng[A][C][G][i] = 1;
      ng[G][A][C][i] = 1;
      ng[i][A][G][C] = 1;
      ng[i][A][C][G] = 1;
      ng[i][G][A][C] = 1;
      ng[A][i][G][C] = 1;
      ng[A][G][i][C] = 1;
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int a = 0; a < 4; ++a) {
      for (int b = 0; b < 4; ++b) {
        for (int c = 0; c < 4; ++c) {
          for (int d = 0; d < 4; ++d) {
            if (ng[a][b][c][d]) continue;
            dp[i + 1][b][c][d] += dp[i][a][b][c];
            dp[i + 1][b][c][d] %= mod;
          }
        }
      }
    }
  }
  int x = 0;
  for (int a = 0; a < 4; ++a) {
    for (int b = 0; b < 4; ++b) {
      for (int c = 0; c < 4; ++c) {
        x += dp[n][a][b][c];
        x %= mod;
      }
    }
  }
  cout << x << endl;
}

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

int main() {
  int a,b;
  cin >> a >> b;
  if(a>b){
    cout << a-1 << endl;
  }else{
    cout << a << endl;
  }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

int main(){

    ll N, K;
    cin >> N >> K;
    ll ans = K;
    rep(i, N - 1)ans *= (K - 1);
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pi acos(-1)
#define sc(n) scanf("%d",&n)
#define sc2(n,x) scanf("%d%d",&n,&x)
#define pr(n) printf("%d",n)
#define scl(n) scanf("%I64d",&n)
#define scl2(n,m) scanf("%I64d%I64d",&n,&m)
#define prl(n) printf("%I64d",n)
#define mp make_pair
#define pb push_back
#define nl printf("\n")
#define mod 1000000007
int main()
{
    ll t,n,a[25];
    memset(a,0,sizeof(a));
    cin>>n;
    int l=0;
    while(n>0)
    {
        int x=n%26;
        if(x==0){n-=26;a[l]=26;}
        else {n-=x;a[l]=x;}
        n/=26;
        l++;
    }
    for(int i=l-1;i>=0;i--)
    {
        char c=(a[i]-1)+'a';
        cout<<c;
    }
    cout<<endl;
}


Measured memory_bytes: 3624
#include<stdio.h>
#define MAX 50

int main(){
    int m[MAX], f[MAX], r[MAX], i;
    for(i = 0; i < MAX; i++){
        scanf("%d %d %d", &m[i], &f[i], &r[i]);
        if((m[i] == -1 && f[i] == -1) &&r[i] == -1) break;
    }

    for(i = 0; i < MAX; i++){
        if((m[i] == -1 && f[i] == -1) && r[i] == -1) break;
        else if(m[i] == -1 || f[i] == -1) printf("F\n");
        else if(m[i] + f[i] >= 80) printf("A\n");
        else if(m[i] + f[i] >= 65 && m[i] + f[i] < 80) printf("B\n");
        else if(m[i] + f[i] >= 50 && m[i] + f[i] < 65) printf("C\n");
        else if((m[i] + f[i] >= 30 && m[i] + f[i] < 50) && r[i] >= 50) printf("C\n");
        else if((m[i] + f[i] >= 30 && m[i] + f[i] < 50) && r[i] < 50) printf("D\n");
        else if(m[i] + f[i] < 30) printf("F\n"); 
    }

    return 0;
}


Measured memory_bytes: 2048
#include <iostream>

using namespace std;

// const int INF = 1 << 30;

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

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

    int y = sum / N;
    int low = 0;
    for (int i = 0; i < N; ++i) {
        low += (y - a[i]) * (y - a[i]);
    }

    ++y;
    int high = 0;
    for (int i = 0; i < N; ++i) {
        high += (y - a[i]) * (y - a[i]);
    }

    cout << min(high, low) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define fo(i,n)         for(int i=0;i<n;i++)
#define Fo(i,k,n)       for(int i=k;i<n;i++) 
#define endl            "\n"
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define vec(x)          vector<x>
#define matrix(x)       vector<vector<x>>
#define mem(a,b)        memset(a, b, sizeof a)
#define vii             vector<pair<int,int>>
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define MOD             998244353
#define deb(x)          cerr <<#x<<" = "<<x<<"\n"
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(v)          v.begin(),v.end()
#define rep(i,a,b)      for (int i = a; i<b; ++i)
#define len(s)          s.length()
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
 
int power(int a,int b,int m=mod)
{int ans=1;while(b>0){if(b&1)ans=(ans*a)%m;a=(a*a)%m;b>>=1;}
return ans;}

void angshuGod()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

const int N = 1e5+1;
const double pi = acos(-1);

void solve(){    

    int n,k;
    cin>>n>>k;

    n %= k;
    cout<<min(n,k-n);  

}

 
int32_t main()
{
    angshuGod();

    int t;

    t = 1;
    //cin>>t;

    while(t--){
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 3656
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 10????????? cout << setprecision(10) << double;
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;

#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//for gcc (???test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// ??\??????push_back(d)???array[d]???????????????1?????§?????????
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN(){T d;cin>>d;return d;}
// ?????§??¬?´???°???Greatest Common Divisor???
LL gcd(LL a, LL b){ return (b > 0) ? gcd(b, a%b) : a; }
// ????°???¬?????°???Least Common Multiple???
LL lcm(LL a, LL b){ return a / gcd(a, b) * b; }

// ------------------- include, typedef, define END. -------------------

int UsedWater(int w){
	int ret=1150;

	FOR(i,0,w){
		if(i<10)	ret += 0;
		else if(i<20)	ret += 125;
		else if(i<30)	ret += 140;
		else ret +=160;
	}

	return ret;
}

int main(){
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = false;
	
	//??????????????????????????????.
	int w=0;
	while(cin>>w,w!=-1){
		int kongetsu = UsedWater(w);
		D_OUT("?????????",kongetsu);
		cout << (4280 - kongetsu) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1192
x, y = map(int, input().split())
ans = 10 ** 10
for i in range(2):
    for j in range(2):
        a = x
        b = y
        cnt = 0
        if i == 1:
            a *= -1
            cnt = 1
        if j == 1:
            b *= -1
            cnt += 1
        if a > b:
            continue
        cnt += b - a
        a += b - a
        #print(cnt, a, b)
        if a == b:
            ans = min(ans, cnt)

print(ans)


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



int main() {

  int N, M;
  cin >> N >> M;

  vector<int> broken(N+1, 0);
  for(int i=1; i<N+1; i++){
    int a;
    cin >> a;
    broken.at(a) = -1;
  }

  vector<int64_t> count(N+1, 0);
  count.at(0) = 1;
  if(broken.at(1) != -1) count.at(1) = 1;
  for(int i=2; i<N+1; i++){
    if(broken.at(i) != -1) count.at(i) = (count.at(i-2) + count.at(i-1)) % 1000000007;
    
  }

  cout << count.at(N) << endl;


}


Measured memory_bytes: 1408
#include <iostream>

using namespace std;

int main() {
	int N, M, X;
	cin >> N >> M >> X;
	int A[100];
	for (int i = 0; i < M; i++) {
		cin >> A[i];
	}
	int sum_zero = 0;
	int sum_N = 0;

	// 0からMまで
	for (int i = 0; i < M; i++) {
		// A[i]がX未満なら
		if (A[i] < X) sum_zero++;
		// A[i]がX以上なら
		else sum_N++;
	}
	cout << min(sum_N, sum_zero) << "\n";
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define maxs(x,y) x = max(x, y)
#define mins(x,y) x = min(x, y)
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    ll N;
    cin >> N;

    if (N % 2 == 1) { 
        cout << 0 << endl;
        return 0;
    }

    ll ans = 0;
    ll n = 1;

    while (n <= 1e18) {
        n *= 5;
        ans += N / n / 2;
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define itn int
static const int MAX = 200000;
signed main() {
	int R[MAX], n;
	cin >> n;
	for (int i = 0; i < n; i++)cin >> R[i];
		int maxv = -2000000000;
		int minv = R[0];
	for (int i = 1; i < n; i++) {
		maxv = max(maxv, R[i] - minv);
		minv = min(minv, R[i]);
	}
	cout << maxv << endl;
	return 0;
}


Measured memory_bytes: 3860
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
#define fi first
#define se second
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define pb push_back
#define mk make_pair
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin >> n;
	map<string, int>m;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		m[s]++;
	}
	cout << "AC" << " " << "x" << " " << m["AC"] << endl;
	cout << "WA" << " " << "x" << " " << m["WA"] << endl;
	cout << "TLE" << " " << "x" << " " << m["TLE"] << endl;
	cout << "RE" << " " << "x" << " " << m["RE"] << endl;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define loop(i, a, b) for(li i=a; i<=b; i++)
#define stuff ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long li;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<li, li> lii;
typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<ii> vii;
typedef vector<lii> vlii;
li mod = 1e9+7;
li expo(li base, li exponent)
{
	li ans=1;
	while(exponent)
	{
		if(exponent&1) ans = (ans*base)%mod;
		base = (base*base)%mod;
		exponent >>= 1;
	}
	return ans;
}
li gcd(li x, li y)
{
	if(y==0) return x;
	return gcd(y, x%y);
}


typedef tree<li, null_type, less<li>,
rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int main()
{
	stuff;
	// #ifndef ONLINE_JUDGE 
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// freopen("error.txt", "w", stderr);
	// #endif

	li r;
	cin >> r;
	double pi = 3.14159265358979;
	double ans = 2*(pi)*r;
	cout << fixed << setprecision(8) << ans;
	return 0;
}


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

const double PI=acos(-1);

int main() {
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    double dh=(double)(60*h+m)/720*2*PI;
    double dm=(double)m/60*2*PI;
    double hx=(double)a*cos(dh), hy=(double)a*sin(dh);
    double mx=(double)b*cos(dm), my=(double)b*sin(dm);
    double dx=hx-mx, dy=hy-my;
    double ans=sqrt(dx*dx+dy*dy);
    cout << setprecision(10) << ans << endl;
}

Measured memory_bytes: 4084
#define _CRT_SECURE_NO_WARNINGS
/*                   وتزودوا فإن خير الزاد التقوى                    */
/*       وما تدري نفس ماذا تکسب غدا وما تدري نفس باي ارض تموت      */
#include <bits/stdc++.h>
#include<unordered_map>
#include<iomanip>
#include<fstream>
using namespace std;
#include<iostream>
#define endl '\n'
#define ll long long
#define ull unsigned long long
#define dll double
#define PI acos(-1)
#define watch(x) cout<<#x<<" = { "<<x<<" }\n"
#define sz(n) n.size()
#define M_Sayed fast() 
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define RT(v) return cout<<v,0
int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };
int dy[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
const double EPS = (1e-7);
ll Ceil(ll x, ll y) { return (x + y - 1) / y; }
void run() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#else
#endif
}
ll gcd(ll a, ll b) { return !b ? abs(a) : gcd(b, a % b); }
ll lcm(ll a, ll b) { return abs(a / gcd(a, b)) * b; }
ll power(ll x, ll y, ll mod) {
	if (y == 0) return 1;
	if (y == 1) return x % mod;
	ll r = power(x, y >> 1, mod);
	return (((r * r) % mod) * power(x, y & 1, mod)) % mod;
}
void fast() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); }
ll n, m, t = 1, k;
int main()
{
	//run();
	M_Sayed;
	cin >> t;
	ll a, b, c, d;
	set<string>st;
	//bool b=1
	while (t--) {
		string s;
		cin >> s;
		st.insert(s);
	}
	RT(sz(st));

}


Measured memory_bytes: 19252
#include <stdio.h>

int prime[2000000];

int main(void)
{
    int n;
    int i, j;

    prime[2] = 1;
    for (i = 3; i < 1000000; i += 2){
        for (j = 3; j * j <= i; j += 2){
            if (i % j == 0){
                break;
            }
        }
        prime[i] = prime[i - 1];
        prime[i + 1] = prime[i - 1];
        if (j * j > i){
            prime[i]++;
            prime[i + 1]++;
        }
    }
    while (~scanf("%d", &n)){
        printf("%d\n", prime[n]);
    }

    return (0);
}

Measured memory_bytes: 4688
import java.util.*;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k=sc.nextInt();
		int n=sc.nextInt();
		int[] a=new int[n];
		int sum=0;
		ArrayList<Integer> aa = new ArrayList<>();
		
		for(int i=0;i<n;i++) {
			int w =sc.nextInt();
			aa.add(w);
		}

		for(int i=0;i<n-1;i++) {
			a[i]=aa.get(i+1)-aa.get(i);
		}
		a[a.length-1]=aa.get(0)+k-aa.get(aa.size()-1);
		Arrays.sort(a);
		
		for(int i=0;i<n-1;i++) {
			sum+=a[i];
		}
		
		System.out.println(sum);
		sc.close();
	}
}


Measured memory_bytes: 67476
import java.util.Scanner;

public class Main {
	final static boolean DEBUG = false;
	final static int INF = Integer.MAX_VALUE;
	class Pair {
		int r, c;
		Pair(int r, int c) {
			this.r = r;
			this.c = c;
		}
	}
	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		Pair[] pairs = new Pair[n];
		for (int i = 0; i < n; i++) {
			int r = scan.nextInt();
			int c = scan.nextInt();
			pairs[i] = new Pair(r, c);
		}
		int[][] dp = new int[n][n];
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				dp[i][j] = INF;

		for (int i = 0; i < n; i++)
				dp[i][i] = 0;

		for (int j = 1; j < n; j++) {
			for (int i = 0; i < n - j; i++) {
				for (int k = i; k < i + j; k++) {
					dp[i][i + j] = Math.min(dp[i][i + j], dp[i][k] + dp[k + 1][i + j] + (pairs[i].r * pairs[k].c * pairs[i + j].c));
				}
			}
		}
		if (DEBUG) {
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++)
					System.out.print((dp[i][j] == INF ? "X" : dp[i][j]) + " ");
				System.out.println();
			}
			System.out.println();
		}
		System.out.println(dp[0][n - 1]);
	}
	public static void main(String[] args) {
		new Main().run();
	}
}



Measured memory_bytes: 26740
#include<stdio.h>
#include<string.h>
int main()
{
    char c1[]="SAT",c2[]="SUN",c3[]="MON",c4[]="TUE",c5[]="WED",c6[]="THU",c7[]="FRI";
    char ch[20];

    scanf("%s",ch);
    if(0==strcmp(ch,c1))
        printf("1\n");
    else if(0==strcmp(ch,c2))
        printf("7\n");
    else if(0==strcmp(ch,c3))
        printf("6\n");
    else if(0==strcmp(ch,c4))
        printf("5\n");
    else if(0==strcmp(ch,c5))
        printf("4\n");
    else if(0==strcmp(ch,c6))
        printf("3\n");
    else if(0==strcmp(ch,c7))
        printf("2\n");
    return 0;
}


Measured memory_bytes: 128
from operator import itemgetter
n = int(input())
a = list(map(int,input().split()))
number = [0]*n
for i in range(n):
    number[i] = i+1
go = list(map(list,zip(a,number)))
go.sort()
junban = []
for i in range(n):
    junban.append(go[i][1])
ans = ' '.join(map(str,junban))
print(ans)

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

using namespace std;

int const MAXN = 15;

int points[MAXN][MAXN];
int D,N;

bool is_int(int pos1, int pos2){
	int val = 0;
	for(int i=0; i<D;++i){
		val += (points[pos1][i] - points[pos2][i])*(points[pos1][i] - points[pos2][i]);
	}
	int sq = (int)sqrt(val);
	if(sq*sq == val) return true;
	return false;
}

int main() {
	cin >> N >> D;
	int num;
	for(int i=0; i<N;++i){
		for(int j=0; j<D;++j){
			cin >> points[i][j];
		}
	}

	int ans = 0;
	for(int i=0; i<N; ++i){
		for(int j=i+1; j<N; ++j){
			if(is_int(i,j)) ans+=1;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int x = sc.nextInt();
        List<Integer> a = new ArrayList<>();
        IntStream.range(0, n).forEach(i -> a.add(sc.nextInt()));

        int sum = 0;
        for (int i = 1; i <= d; i++) {
            for (int j = 0; j < n; j++) {
                if (a.get(j) == 1 || i % a.get(j) == 1) {
                    sum++;
                }
            }
        }
        System.out.println(sum + x);
    }


}


Measured memory_bytes: 26836
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt(), result = 0, combo = 0, color = 0;
        for (int i = 0; i < n; i++) {
            int j = scanner.nextInt();
            combo++;

            if (j != color) {
                result += combo / 2;
                combo = 0;
                color = j;
            }
        }
        System.out.println(result + ++combo / 2);
    }
}

Measured memory_bytes: 21844
N,M = map(int,input().split())

def fact(i):
    count = 1
    for p in range(2,i+1):
        count *= p
        count = count % (10**9+7)
    return count
if N+1 < M or N > M+1:
    print(0)
else:
    if (N+M) % 2 == 0:
        print(fact(N)*fact(M)*2 % (10**9 + 7))
    else:
        print(fact(N)*fact(M)%(10**9 + 7))

Measured memory_bytes: 3060
def cake(n, w, d):
  piece = [0] * (n + 1)
  piece[0] = [w, d, w * d]
  ps = [0] * n
  for i in range(n):#100
    #print(piece)
    p, s = map(int, input().split())
    now = piece[p - 1]#切るケーキ
    nw, nd = now[0], now[1]
    s = s % (nw + nd)
    if p != i + 1:
      for j in range(p, i + 2):
        piece[j - 1] = piece[j]
    if s < nw:
      a, b = s, nw - s
      if a > b:
        piece[i + 1] = [a, nd, a * nd]
        piece[i] = [b, nd, b * nd]
      else:
        piece[i] = [a, nd, a * nd]
        piece[i + 1] = [b, nd, b * nd]   
        
    elif s < nw + nd:
      a, b = s - nw, nw + nd - s
      if a > b:
        piece[i] = [nw, b, b * nw]
        piece[i + 1] = [nw, a, a * nw]
      else:
        piece[i + 1] = [nw, b, b * nw]
        piece[i] = [nw, a, a * nw]
        
    elif s < 2 * nw + nd:
      a, b = s - nw - nd, 2 * nw + nd - s
      if a > b:
        piece[i + 1] = [a, nd, a * nd]
        piece[i] = [b, nd, b * nd]
      else:
        piece[i] = [a, nd, a * nd]
        piece[i + 1] = [b, nd, b * nd]   
        
    else:
      a, b = s - nw, nw + nd - s
      if a > b:
        piece[i] = [nw, b, b * nw]
        piece[i + 1] = [nw, a, a * nw]
      else:
        piece[i + 1] = [nw, b, b * nw]
        piece[i] = [nw, a, a * nw]
  return piece

p = True
while p:
  n, w, d = map(int, input().split())
  if (n, w, d) == (0, 0, 0):
    p = False
    quit()
  else:
    ans = cake(n, w, d)
    ans = sorted(ans, key = lambda x:x[2])
    for i in range(n + 1):
      if i!= n:
        print(ans[i][2], end = " ")
      else:
        print(ans[i][2])


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

int main() {
    int N;
    cin >> N;
    vector<int> P(N);
    for(int i = 0; i < N; i++) {
        cin >> P.at(i);
    }

    vector<int> mins(N, 0);
    mins.at(0) = P.at(0);
    for(int i = 1; i < N; i++) {
        mins.at(i) = min(mins.at(i - 1), P.at(i));
    }

    int cnt = 0;
    for(int i = 0; i < N; i++) {
        if(mins.at(i) >= P.at(i)) {
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1792
print([1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51][int(input())-1])

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define ld long double
#define int long long
using namespace std;
const int N = 2e5 + 50;
const int mod = 1e9 + 7;
const int inf = 1e17;
int dx[] = {0, 1, -1, 0, -1, 1, 1, -1};
int dy[] = {1, 0, 0, -1, -1, 1, -1, 1};
int B[100];
int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  int n, m, c, ans = 0;
  cin >> n >> m >> c;
  for(int i = 0; i < m; i++){
  	cin >> B[i];
  }
  for(int i = 0; i < n; i++){
  	int tot = c;
  	for(int j = 0; j < m; j++){
  		int num;
  		cin >> num;
  		tot += num * B[j];
  	}
  	if(tot > 0){
  		ans++;
  	}
  }
  cout << ans;
}

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

using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    int H[N];
    for(int i=0; i<N; i++){
        cin >> H[i] ;
    }
    sort(H, H+N, greater<int>() );
    long ans = 0;
    for(int i=K; i<N; i++){
        ans += H[i];
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int alphabet[26];

int main(){
    string input;
    cin >> input;
    for (char i : input) {
        alphabet[i -'a'] += 1;
    }

    for(auto i:alphabet){
        if(i%2 != 0){
            cout << "No";
            return 0;
        }
    }

    cout << "Yes";

}






Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
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; }
ll mod= 1e9 + 7;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

};

int main() {
  int n,m;
  cin >> n >>m;
  int ans=0;
  pair<int,int> k[m];
  rep(i,m){
    int a,b;
    cin >> a >>b;
    a--;b--;
    k[i].first=a;
    k[i].second=b;
  }
  rep(i,m){
    UnionFind tree(n);
    rep(j,m){
      if(i!=j)tree.unite(k[j].first,k[j].second);
    }
    ans+= !tree.same(k[i].first,k[i].second);
  }
  cout  << ans <<endl;
}

Measured memory_bytes: 3612
#include <stdio.h>

// int a[200001]
int main() {
  int k, n;
  scanf("%d %d", &k, &n);

  int last;
  scanf("%d", &last);
  int first = last;
  int max = last;
  for (int i = 1; i < n + 1; i++) {
    int a;
    scanf("%d", &a);
    int d = (i == n) ? (k - a + first) : (a - last);
    max = d > max ? d : max;
    last = a;
  }
  printf("%d", k - max);
  return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public void Solve()
        {
            var items = Console.ReadLine().Split().Select(elem => long.Parse(elem)).ToArray();
            var A = items[0];
            var B = items[1];
            var C = items[2];
            var K = items[3];
            var countA = 0L;
            var countB = 0L;
            var countC = 0L;

            countA = Math.Min(A, K);
            K -= countA;

            countB = Math.Min(B, K);
            K -= countB;

            countC = Math.Min(C, K);
            K -= countC;
            
            Console.WriteLine(countA - countC);
        }
    }
}


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

struct Card { char suit; int value; };

void bubble(struct Card A[], int N) {
  for (auto i = 0; i < N - 1; i++) {
    for (auto j = N - 1; j > i; j--) {
      if (A[j-1].value > A[j].value) {
        Card temp = A[j]; A[j] = A[j-1]; A[j-1] = temp;
      }
    }
  }
}

void selection(struct Card A[], int N) {
  for (auto i = 0; i < N - 1; i++) {
    auto mini = i;
    for (auto j = i + 1; j < N; j++) {
      if (A[mini].value > A[j].value) {
        mini = j;
      }
    }
    if (mini != i) {
      auto temp = A[i]; A[i] = A[mini]; A[mini] = temp;
    }
  }
}

void print(struct Card A[], int N) {
  for (auto i = 0; i < N; i++) {
    if (i != 0) cout << " ";
    cout << A[i].suit << A[i].value;
  }
  cout << endl;
}

bool isStable(struct Card A[], struct Card B[], int N) {
  for (auto i = 0; i < N; i++) {
    if (A[i].suit != B[i].suit) return false;
  }
  return true;
}

int main(void){
  int N;
  string str;
  Card C1[36], C2[36];;
  
  cin >> N;
  for (auto i = 0; i < N; i++) {
    cin >> C1[i].suit >> C1[i].value;
  }
  
  for (auto i = 0; i < N; i++) C2[i] = C1[i];
  
  bubble(C1, N);
  selection(C2, N);
  
  print(C1, N);
  cout << "Stable" << endl;
  print(C2, N);
  if (isStable(C1, C2, N)) {
    cout << "Stable" << endl;
  } else {
    cout << "Not stable" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3104
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 10e+10
#define DEKA 1000000007

using namespace std;
long gcd(long a,long b){
    if (a<b) return gcd(b,a);
    else {
        if (b==1) return 1;
        else if (b==0) return a;
        else return gcd(b,a%b);
    }
}

int main(){
    long n,x;
    cin >> n >> x;
    long ans;
    long b;
    cin >> b;
    ans=abs(x-b);
    for(long i=1;i<n;i++){
        long a;
        cin >> a;
        ans=gcd(abs(x-a),ans);
        
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
use std::io::Read;
use std::cmp::Reverse;
use std::collections::BinaryHeap;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let c: Vec<char> = iterator.next().unwrap().chars().collect();
    let mut r: BinaryHeap<usize> = BinaryHeap::new();
    let mut w: BinaryHeap<Reverse<usize>> = BinaryHeap::new();
    for i in 0..n {
        if c[i] == 'R' {
            r.push(i);
        } else {
            w.push(Reverse(i));
        }
    }

    if r.is_empty() || w.is_empty() {
        return "0".to_string();
    }

    let mut ans: usize = 0;
    loop {
        let r_max = r.pop().unwrap();
        let w_min = w.pop().unwrap().0;
        if r_max > w_min {
            r.push(w_min);
            w.push(Reverse(r_max));
            ans += 1;
        } else {
            break;
        }
    }
    ans.to_string()
}


Measured memory_bytes: 4780
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
    int a,b,m;cin>>a>>b>>m;
    vector<int> A(a);
    vector<int> B(b);
    int a_min = INF;
    int b_min = INF;
    for(int i = 0; i < a; i++) {
        cin>>A[i];
        a_min = min(a_min,A[i]);
    }
    for(int i = 0; i < b; i++) {
        cin>>B[i];
        b_min = min(b_min,B[i]);
    }
    int ans = a_min + b_min;
    for(int i = 0; i < m; i++) {
        int x,y,c;cin>>x>>y>>c;
        ans = min(ans,A[x - 1] + B[y - 1] - c);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024