akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

//4Head

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(NULL));

ll const mod = 1e9 + 7;

namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}

	ll poww(ll a, ll b) {
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}

	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

ll const maxn = 3e5 + 5;

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll h, n; cin >> h >> n;
	ll sm = 0;
	for (ll i = 0; i < n; i++) {
		ll t; cin >> t; sm += t;
	}
	if (sm >= h) {
		cout << "Yes\n";
	} else {
		cout << "No\n";
	}
	return 0;
}

/*
3
0 1
3 0
1 0
*/

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
typedef double D;
typedef complex<D> P;
typedef vector<P>VP;
const D EPS = 1e-9;
#define X real()
#define Y imag()
#define EQ(n,m) (abs(n-m)<EPS)
D dot(P a,P b){return (conj(a)*b).X;}
D cross(P a,P b){return (conj(a)*b).Y;}
int ccw(P a,P b,P c){
  b-=a;c-=a;
  if(cross(b,c)>EPS)return 1;
  if(cross(b,c)< -EPS)return -1;
  if(dot(b,c)< -EPS)return 2;
  if(norm(b)<norm(c))return -2;
}
VP crosspointCC(P a, D ar, P b, D br) {
  VP ps;
  P ab=b-a;
  D d=abs(ab);
  D crL=(norm(ab)+ar*ar-br*br)/(2*d);
  if(EQ(d,0)||ar<abs(crL))return ps;
  P abN=ab*P(0,sqrt(ar*ar-crL*crL)/d);
  P cp=a+crL/d*ab;
  ps.push_back(cp + abN);
  if(!EQ(norm(abN),0)) ps.push_back(cp-abN);
  return ps;
}
namespace std {
  bool operator<(const P a,const P b) {
    return a.X!=b.X?a.X<b.X:a.Y<b.Y;
  }
}
VP convexHull(VP ps){
  int n=ps.size(),k=0;
  sort(ps.begin(),ps.end());
  VP ch(2*n);
  for(int i=0;i<n;ch[k++]=ps[i++])
    while(k>=2&&ccw(ch[k-2],ch[k-1],ps[i])<=0)--k;
  for(int i=n-2,t=k+1;i>=0;ch[k++]=ps[i--])
    while(k>=t&&ccw(ch[k-2],ch[k-1],ps[i])<=0)--k;
  ch.resize(k-1);
  return ch;
}

P rot(P p, double a,double x,double y){
  a=a*M_PI/180.0;
  P p1=P(x,y);
  p-=p1;
  return P(p.X*cos(a)+p.Y*(-sin(a))+x,p.X*sin(a)+p.Y*cos(a)+y);
}

int n,q;
D r;

int main(){
  //cout<<acos(cos(M_PI))/M_PI*180<<endl;
  while(cin>>n>>r>>q,n){
  VP v;
  r(i,n){
    double x,y;
    cin>>x>>y;
    v.push_back(P(x,y));
  }
  v=convexHull(v);
  int p;
  double t=1e9;
  double y,x;
  r(i,v.size()){
    if(v[i].Y<t){
      x=v[i].X;
      y=v[i].Y;
      t=v[i].Y;
      p=i;
    }
  }
  //for(int i=p,c=0;c<4;i=(i+1)%4,c++){
  //cout<<v[i].X<<' '<<v[i].Y<<endl;
  //}
  r(i,q){//cout<<p<<endl;
    int ppp=p;
    for(;;p=(p-1+v.size())%v.size()){//cout<<p<<endl;
      VP p1=crosspointCC( P(0,0) ,r , P(x,y) , abs(v[ppp]-v[(p-1+v.size())%v.size()]) );
      P pt;
      if(ccw(p1[0],P(x,y),P(0,0))==1)pt=p1[0];
      else pt=p1[1];
      // r(k,2){
      //cout<<pt.X<<' '<<pt.Y<<endl;
      //cout<<v[(p-1+v.size())%v.size()].X<<' '<<v[(p-1+v.size())%v.size()].Y<<endl;
      //}//cou
      D a=abs(v[ppp]-v[(p-1+v.size())%v.size()]);
      // D b=abs(v[p]-v[(p+1)%v.size()]);
      D c=abs(v[(p-1+v.size())%v.size()]-pt)*abs(v[(p-1+v.size())%v.size()]-pt);

      //cout<<sqrt(c)<<endl;
      //return 0;
      
      double radi=acos((a*a+a*a-c)/(2*a*a));

      // cout<<a<<endl;
      
      radi=radi/M_PI*180;
      //cout<<radi<<endl;
      
      VP vt=v;

      r(k,vt.size()){
	vt[k]=rot(vt[k],radi,x,y);
      }
      
      int flag=0;
      r(k,vt.size()){
	if(abs(vt[k]-P(0,0))-EPS>r)flag++;
      }
      if(flag)continue;
      v=vt;
      y=v[(p-1+v.size())%v.size()].Y;
      x=v[(p-1+v.size())%v.size()].X;
      printf("%.12f %.12f\n",x,y);
      p=(p-1+v.size())%v.size();
      break;
    }
  }
}
}

Measured memory_bytes: 3524
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
using namespace std;
int dp[100001];
int main()
{
int n;cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
	cin>>a[i];
}
dp[0]=0;
dp[1]=abs(a[1]-a[0]);
for(int i=2;i<n;i++)
{
	dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
}
cout<<dp[n-1];

}
 
 




Measured memory_bytes: 1024
N=int(input())
X=list(map(int,input().split()))
S1=0
S2=0
for i in range(N):
  S1+=(X[i])*(X[i])
  S2+=X[i]
mins=S1
for i in range(min(X),max(X)+1):
  if mins>N*i*i-2*S2*i+S1:
    mins=N*i*i-2*S2*i+S1
print(mins)

Measured memory_bytes: 3064
/*
    問題をよく読もう！
    論理的に考えよう！
    サンプルを確認しよう!
    絶対に諦めるな！
    工夫をしろ！
    配列は少し多めにとっておく

    Twitterは終わるまでログアウト！
    （間違えて解法をツイートしてはいけないから）

*/
//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include<cstring>
//namespace
using namespace std;
//繰り返し
#define REP(i, m, n) for(int i=(int)m; i<(int)n; ++i)
#define rep(i, n) REP(i, 0, n)
//イテレータ
#define all_range(C) begin(C), end(C)
//簡略化
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
typedef pair<string,int> pst;

const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
//最大最小
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) {if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) {if(a<b) a=b;}

//関数

//最大公約数を求める
ll my_gcd(ll x, ll y) {
  ll r;

  while(y!=0) {
    r = x%y;
    x = y;
    y = r;
  }

  return x;
}

//最小公約数を求める
ll my_lcm(ll x, ll y) {

  return (x*y)/my_gcd(x,y);
}

//xのy乗を求める ※参考：10^18乗まで
ll my_pow(ll x, ll y) {
  ll sum = 1;

  while(y>0) {
    sum *= x;
    --y;
  }

  return sum;
}

/*考えを書くスペース

*/
//main.cpp----------------------------


void solve();

ll n, a, b;

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

  solve();

  return 0;
}

void solve() {
  ll x = 0;
  for(int i=a+1; i<b; ++i) ++x;

  if(x%2==0) {
    cout << "Borys" << endl;
  }else {
    cout << "Alice" << endl;
  }
}

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

namespace _0017
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string s = Console.ReadLine();
                if (string.IsNullOrEmpty(s)) break;
                while (true)
                {
                    string[] x = s.Split();
                    if (x.Contains("the") || x.Contains("this") || x.Contains("that"))
                    {
                        Console.WriteLine(s);
                        break;
                    }
                    string a = "";
                    for (int i = 0; i < s.Length; i++)
                    {
                        if ('a' <= s[i] && s[i] <= 'z') a += s[i] == 'z' ? 'a' : (char)(s[i] + 1);
                        else a += s[i];
                    }
                    s = a;
                }
            }
        }
    }
}


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

int nCr(int n)
{
	if(n==1||n==0)return 0;
	return (n*(n-1))/2;
}

int main()
{
	int N,M;
	cin>>N>>M;
	cout<<nCr(N)+nCr(M)<<'\n';
}


Measured memory_bytes: 256
#include<stdio.h>
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INFTY (1<<21)
#define N 100

int n,M[N][N];
int color[N],d[N],p[N];

int prim(){

  int u, mincost, i, v,sum = 0;

  for(i = 0; i < n; i++ ){
    color[i] = WHITE;
    d[i] = INFTY;
    p[i] = -1;
  }

  d[0] = 0;

  while(1){
    mincost = INFTY;
    u = -1;
    for(i = 0; i < n; i++){
      if(mincost > d[i] && color[i] != BLACK){
	u = i;
	mincost = d[i];
      }
    }
    if(u == -1)break;
    color[u] = BLACK;
    for( v = 0; v < n; v++){
      if(color[v] != BLACK && M[u][v] != INFTY){
	if(M[u][v] < d[v]){
	  d[v] = M[u][v]; 
	  p[v] = u;
	  color[v] = GRAY;
	}
      }
    }
  }
  for(i = 0; i < n; i++){
    if(p[i] != -1){
      sum += M[i][p[i]];
    }
  }
  return sum;

}


int main(){


  int i, j, sum=0;
  scanf("%d",&n);
  for(i = 0; i < n; i++ ){
    for(j = 0; j < n; j++){
      scanf("%d",&M[i][j]);
      if(M[i][j] == -1)M[i][j]=INFTY;
    }
  } 
  sum = prim(n);
  printf("%d\n",sum);

  return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
#define int long long
#define all(c) (c).begin(), (c).end()
#define cpresent(c,x) ((c).find(x) != (c).end()) // present in container?
#define vpresent(c,x) (find(all(c),x) != (c).end()) // present in vector?
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr), cout.tie(nullptr)
#define endl '\n'
using namespace std;

int n;

void solve(){   
    cin >> n; 
    int low = 169, high = -69;
    vector<int> ara(n);
    for(int i = 0; i < n; ++i){
        cin >> ara[i];
        low = min(ara[i], low);
        high = max(ara[i], high);
    }
    int out = 1e9 + 69;
    for(int i = low,sum; i <= high; ++i){
        sum = 0;
        for(int j = 0; j < n; ++j){
            sum += (ara[j] - i) * (ara[j] - i);
        }
        out = min(sum, out);
    }
    cout << out << endl;
}

signed main(){
	fastio;
	// int t; cin >> t;
	// while(t--)
		solve();
	return 0;
}


Measured memory_bytes: 256
n=int(input())
w=[]
for i in range(n):
    w.append(input())
result=True
for i in range(1,n):
    if w[i] in w[0:i]:
        result=False
    else:
        first=w[i]
        second=w[i-1]
        if first[0]!=second[-1]:
            result=False
if result==False:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main()
{
int A,B,X;
cin >> A >> B >> X ;
if(A>X) cout<<"NO";
if(A==X)cout<<"YES";
if(A<X){
if((A+B) >= X){
        cout<<"YES";
}
else cout<<"NO";
}
    return 0;
}


Measured memory_bytes: 256
def number(c):
    c = str(c)
    ans = 0
    s = "0123456789"
    for i in range(10):
        if c == s[i]:ans = 1
    return ans

A,B = map(int,input().split())
S = input()
flag = 1
for i in range(A):
    if(number(S[i]) != 1):flag = 0
if S[A] != "-":flag = 0
for j in range(B):
    if(number(S[A+1+j]) != 1):flag = 0
if flag:print("Yes")
else:print("No")

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

int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  rep(i, n) cin >> x[i];
  int mx = 1000;
  rep(i, n) {
    mx = max(mx, x[i]);
  }
  int ans = 1000000000;
  for(int i = 1; i <= ((1+mx)/2)+1; i++) {
    int sum = 0;
    rep(j, n) {
      int t = abs(x[j] - i);
      sum += t*t;
    }
    ans = min(ans, sum);
  }
  cout << ans << endl;
  return 0;
} 

Measured memory_bytes: 3620
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<complex>
#include<stack>
#include<cmath>

using namespace std;

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

int main(){
	
	string s;
	
	while(cin>>s){
		
	vector<int> a;
		rep(i,s.size()){
			a.push_back(s[i]-'0');
		}
		
		
		while(a.size()!=1){
			vector<int> b;
			rep(i,a.size()-1){
				b.push_back((a[i]+a[i+1])%10);
			}
			//rep(i,b.size())printf("%d ",b[i]);puts("");
			a=b;
		}
		
		printf("%d\n",a[0]);
	}
	
	
}

Measured memory_bytes: 1196
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		List<Long> list = insu(n);
		Map<Long, Integer> map = new HashMap<>();
		for (Long key : list) {
    		Integer i = map.get(key);
    		map.put(key, i == null ? 1 : i + 1);
		}
		int ans = 0;
		for (Integer v: map.values()) {
			int hituyou = 1;
			int nokori = v;
			while(nokori >= hituyou){
				ans++;
				nokori -= hituyou;
				hituyou++;
			}
		}
		System.out.println(ans);
	}
	public static List<Long> insu(long n){
		List<Long> list = new ArrayList<>();
		if(n==1) return list;
		for(int i=2; i<=Math.sqrt(n); i++){
			if(n%i == 0){
				list.add((long)i);
				n = n/i;
				i = 1;
			}
		}
		list.add(n);
		return list;
	}
}


Measured memory_bytes: 27252
let readIntArray _ =
    stdin.ReadLine().Split(" ") |> Array.map int

let judge num =
    num
    |> string
    |> fun x -> x.ToCharArray()
    |> Array.rev
    |> System.String
    |> int
    |> (=) num


()
|> readIntArray
|> fun [| a; b |] -> seq { a .. b }
|> Seq.filter judge
|> Seq.length
|> printfn "%d"


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>>ab(2, vector<int>(N));
  vector<vector<int>>cd(2, vector<int>(M));
  for(int i=0; i<N; i++)cin >> ab.at(0).at(i) >> ab.at(1).at(i);
  for(int i=0; i<M; i++)cin >> cd.at(0).at(i) >> cd.at(1).at(i);
  
  
  for(int i=0; i<N; i++){
    int kyori = 1000000000;
    int kyori2;
    int tika = 0;
    int X = ab.at(0).at(i);
    int Y = ab.at(1).at(i);
    
    for(int j=0; j<M; j++){
      kyori2 = max(cd.at(0).at(j), X) - min(cd.at(0).at(j), X) + max(cd.at(1).at(j), Y) - min(cd.at(1).at(j), Y);
      if(kyori2<kyori){
        kyori = kyori2;
        tika = j+1;
      }
    }
    cout << tika << endl;
  }
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string s;
    cin >> s;
    int cnt = 0;
    int ans = 0;
    for(int i = 0; i < 3; i++){
        if(s[i] == 'R'){
            cnt++;
            ans = max(ans,cnt);
        }else{
            cnt = 0;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

const int N = 1e6 + 6;

int a[N], b[N];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d %d", a+i, b+i);
  }
  long long sum = 0;
  long long ans = 0;
  for (int i = n-1; i >= 0; i--) {
    long long now = a[i] + sum;
    int r = now % b[i];
    r = (b[i]-r) % b[i];
    ans += r;
    sum += r;
  }
  printf("%lld\n", ans);

  return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	Scanner sc = new Scanner(System.in);

	void run() {
		String a = sc.next();
		int cnt = 0;
		int A, B;
		int x, y;
		String res = "";
		for (int i = 0; i < a.length(); i++) {
			if (i == 0) {
				A = 0;
				B = Integer.valueOf(a);
				if ((A + B) % 2 == 0 && (A - B) % 2 == 0) {
					x = (A + B) / 2;
					y = -(A - B) / 2;
					if(x < 0 || y < 0) {
						continue;
					}
					B = x + y;
					res = B + "";
					if (res.equals(a)) {
						cnt++;
					}
				}
			} else {
				A = Integer.valueOf(a.substring(0, i));
				B = Integer.valueOf(a.substring(i, a.length()));
				if ((A + B) % 2 == 0 && (A - B) % 2 == 0) {
					x = (A + B) / 2;
					y = -(A - B) / 2;
					if(x < 0 || y < 0) {
						continue;
					}
					A = x - y;
					B = x + y;
					res = A + "" + B;
					if (res.equals(a)) {
						cnt++;
					}
				}
			}
		}
		System.out.println(cnt);
	}

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

Measured memory_bytes: 17324
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
   
int main() {
  double r;
  cin >> r;
   
  cout << fixed ;
  cout << setprecision(6) << (r * r) * M_PI << " ";
  cout << setprecision(6) << (2 * r) * M_PI << endl;
  return 0;
}


Measured memory_bytes: 3204
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    int n, k; cin >> n >> k;
    vector<char> v(k);
    rep(i,k) cin >> v[i];
    while(true){
        string s = to_string(n);
        bool flag = true;
        for(int i = 0; i < s.size(); i++){
            for(auto num : v){
                if(s[i]==num) flag = false;
            }
        }
        if(flag){
            cout << n << endl;
            return 0;
        }
        else n++;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define f first
#define  s second
#define pii pair<int,int>
#define pll pair<ll,l>
#define ull unsigned ll
#define mp make_pair
#define pb push_back

using namespace std;

ll n;
ll a[200001];
ll k;

bool check(ll len){
    ll cnt=0;
	for(int i=1;i<=n;i++){
		cnt+=a[i]/len-1;
		if(a[i]%len>0)cnt++;
	}
	if(cnt<=k){
		return true;
	}
	return false;
}



int main(){
	cin>>n>>k;
	for(ll i=1;i<=n;i++)cin>>a[i];
	ll mx=-1;
	for(ll i=1;i<=n;i++)mx=max(mx,a[i]);
	ll ans=mx;
	ll l,r;
	l=1,r=mx;
	while(l<r){
		ll m=(l+r)/2;
		if(check(m))ans=m,r=m;
		else l=m+1;
	}
	cout<<ans;
	return 0;
}

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

const int Max = 500005;
const int M = 1000000005;
int S[Max], Count = 0;
int a[Max/2], b[Max/2];
void Merge(int S[], int left, int right, int mid)
{
    int n1 = mid-left, n2 = right-mid;
    for(int i=0; i<n1; i++)
    {
        a[i] = S[i+left];
        //Count++;
    }
    for(int i=0; i<n2; i++)
    {
        b[i] = S[i+mid];
        //Count++;
    }
    a[n1] = M, b[n2] = M;//确保最后一个数较大，利于以下排序
    int k=left, ka=0, kb=0;
    //Count++;
    while(k<right)
    {
        if(a[ka]>b[kb])
        {
            S[k++] = b[kb++];
        }
        else
        {
            S[k++] = a[ka++];
        }
        Count++;
    }
}

void MergeSort(int S[], int left, int right)
{
    if(left+1<right)
    {
        int mid = (left+right)/2;
        MergeSort(S, left, mid);
        MergeSort(S, mid, right);
        Merge(S, left, right, mid);
    }
}

int main()
{
    int n;
    Count = 0;
    scanf("%d", &n);
    for(int i=0; i<n; i++)
        scanf("%d", &S[i]);
    MergeSort(S, 0, n);
    for(int i=0; i<n-1; i++)
        printf("%d ", S[i]);
    printf("%d\n", S[n-1]);
    printf("%d\n", Count);
    return 0;
}



Measured memory_bytes: 7108
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 5005;

void extgcd(int a,int b, int& x,int& y)
{
	if(b != 0){
		extgcd(b,a%b,y,x);
		y -= (a/b)*x;
	}else{
		x = 1;
		y = 0;
	}
}

int mod_inverse(int a,int m)
{
	int x,y;
	extgcd(a,m,x,y);
	return (m + x % m) % m;
}

ll mod_pow(ll a,ll b)
{
    a %= MOD;
    ll res = 1;
    while(b){
        if(b & 1){
            res = res * a % MOD;
        }
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}

ll add(ll x,ll y)
{
    return (x + y)%MOD;
}

ll sub(ll x,ll y)
{
    return (x+MOD-y)%MOD;
}

ll mul(ll x,ll y)
{
    return x*y%MOD;
}

int dp[2][MAX_N];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string s;
    cin >> s;
    int m = len(s);
    dp[0][0] = 1;
    rep(i,n){
        memset(dp[1],0,sizeof(dp[1]));
        rep(j,i+1){
            dp[1][j+1] = add(dp[1][j+1],mul(dp[0][j],2));
        }
        dp[1][0] = add(dp[1][0],dp[0][0]);
        srep(j,1,i+1){
            dp[1][j-1] = add(dp[1][j-1],dp[0][j]);
        }
        swap(dp[0],dp[1]);
    }
    cout << mul(dp[0][m],mod_pow(mod_inverse(2,MOD),m)) << "\n";
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <iomanip>

using namespace std;

double ETA = 1e-12;

int main() {
  int n, k;
  cin >> n >> k;

  double div1 = k;
  double div2 = div1 / 2;
  double prob = 0.5;
  double vsum = 0;

  while (1 <= div1 + ETA) {
    if (div2 <= n && div1 <= n)
      vsum += int(int(div1 + ETA) + 1 - div2 + ETA) * prob;
    else if (div2 <= n)
      vsum += int(n + 1 - div2 + ETA) * prob;

    if (div1 <= n && div1 - int(div1) <= ETA && -ETA<=div1 - int(div1))
      vsum -= prob;

    div1 = div2;
    div2 /= 2;
    prob /= 2;
  }

  double vsum2 = (double(n) - k + 1) / n;
  if (vsum2 < 0)
    cout << fixed << setprecision(15) << vsum / n << endl;
  else
    cout << fixed << setprecision(15) << vsum / n + vsum2 << endl;
}

Measured memory_bytes: 3724
A,B,K = map(int,input().split())
a = []

if B-A<=K:
    for i in range(A,B+1):
        print(i)
else:
    for i in range(A,A+K):
        a.append(i)
    for i in range(B-K+1,B+1):
        a.append(i)
    b =set(a)
    print(' '.join(map(str, sorted(b))))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;
#define ll long long
int dp[100100];
int cnt = 0;
signed main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> G(n);
  vector<int> deg(n,0);
  rep(i,m) {
    int x,y;
    cin >> x >> y;
    x--;y--;
    G[x].push_back(y);
    deg[y]++;
  }
  queue<int> q;
  rep(i,n) {
    if(deg[i]==0) {
      q.push(i);
    }
  }
  while(q.size()>0) {
    int now = q.front();
    q.pop();
    //cout << now <<" "<<from[now].size()<< endl;
    for(auto nv:G[now]) {
      deg[nv]--;
      if(deg[nv]==0) {
        q.push(nv);
        dp[nv] = max(dp[nv],dp[now]+1);
      }
    }
  }
  int ans = 0;
  rep(i,n) {
    ans = max(ans, dp[i]);
  }
  cout << ans << endl;


  return 0;
}

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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

int main() {
    Int n, k;
    cin >> n >> k;
    Int res = k;
    for (Int i = 1; i < n; i++) {
        res *= (k - 1);
    }
    dump(res);
    return 0;
}

Measured memory_bytes: 256
N, Y = map(int, input().split())

result = []
for a in range(N+1):
  for b in range(N+1):
    c = max(N - a - b, 0)
    total = a * 10000 + b * 5000 + c * 1000
    if (total == Y) and (a + b + c == N):
      result.append([a, b, c])

if len(result) == 0:
  print("-1 -1 -1")
else:
  print(" ".join(map(str, result[0])))

Measured memory_bytes: 67960
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

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

    string s;
    cin >> s;
    int q;
    cin >> q;

    string s1, s2;
    bool rev = false;
    while (q--) {
        int t;
        cin >> t;

        if (t == 1) {
            rev ^= 1;
        } else {
            int f;
            char c;
            cin >> f >> c;

            if (!rev && f == 1 || rev && f == 2) {
                s1 += c;
            } else {
                s2 += c;
            }
        }
    }

    reverse(s1.begin(), s1.end());
    string ans = s1 + s + s2;
    if (rev) {
        reverse(ans.begin(), ans.end());
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1300
using namespace std;
#include <iostream>
#include <string>
#include <set>
#include <functional>
#include <vector>
#include <algorithm>
#include <stdio.h>
void solve(){
	char ans;
	string s;
	int si,sj;
	while(true){
	bool fir=true;
		bool table[15][15]={};
		for(int i=0;i<8;i++){
			if(!(cin>>s))return;
			for(int j=0;j<8;j++){
				if(s[j]-'0'==1){
					if(fir){si=i;sj=j;fir=false;}
					table[i][j]=true;
				}
			}
		}
		if(table[si+3][sj]){ans='B';}
		else if(table[si][sj+3]){ans='C';}
		else if(table[si+1][sj+1]){//AEF
			if(!table[si+1][sj])ans='E';
			else if(table[si][sj+1])ans='A';
			else ans='F';
		}else if(table[si][sj+1]){ans='G';}else{ans='D';}
		//for(int i=0;i<8;i++)for(int j=0;j<8;j++)printf(j==7?"%d\n":"%d",(int)table[i][j]);
		//printf("%d,%d\n",si,sj);
		cout<<ans<<endl;
	}
}
int main()
{
	solve();
    return 0;
}

Measured memory_bytes: 1172
#include <cstdio>
#include <iostream>
#include <sstream>

#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>

#include <chrono>
#include <random>

using namespace std;
using i64 = int_fast64_t;
using ui64 = uint_fast64_t;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<i64>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<i64, i64>;

//////////////////////////////////////////////////

i64 calc(const vl &A, i64 b){
  i64 res = 0;
  for(auto&& x:A){
    res += abs(x-b);
  }
  return res;
}

i64 bisect(const vl &A, i64 l, i64 r){
  if(l + 1 == r)return l;
  i64 m = (l+r)/2;
  i64 lc = calc(A, l), rc = calc(A, r);
  i64 mc = calc(A, m);
  // cerr << l << " " << lc << " ";
  // cerr << m << " " << mc << " ";
  // cerr << r << " " << rc << " ";
  if(lc <= mc && mc <= rc){
    // cerr << "left" << endl;
    return bisect(A, l, m);
  }
  else if(lc >= mc && mc >= rc){
    // cerr << "right" << endl;
    return bisect(A, m, r);
  }
  else{
    // cerr << "mid" << endl;
    i64 l2 = bisect(A, l, m);
    i64 r2 = bisect(A, m, r);
    if(calc(A, l2) <= calc(A, r2))return l2;
    else return r2;
  }
}

int main() { 
  int n;
  cin >> n;
  vl A(n);
  for(int i=0;i<n;i++){
    cin >> A[i];
    A[i] -= i+1;
  }
  i64 b = bisect(A, (i64)-1e9, (i64)1e9+1);
  // cerr << b << endl;
  cout << calc(A, b) << endl;
  return 0;
}


Measured memory_bytes: 1792
import java.util.Arrays;
import java.util.Scanner;
class Main {

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

        for (int c = 0; c < 3; c++) {
            nums[c] = sc.nextInt();
        }

        for(int i = 0; i < nums.length - 1; i++) {
            for(int j = i + 1; j < nums.length; j++) {

                if(nums[i] > nums[j]) {
                    int temp = nums[i];
                    nums[i] = nums[j];
                    nums[j] = temp;
                }
            }
        }

        System.out.println(nums[0]+" "+nums[1]+" "+nums[2]);
        sc.close();
    }

}


Measured memory_bytes: 26220
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,mini;
    cin>>n;
    int a[n+1],cnt=0;
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n;i++)
    {
        mini=i;
        for(int j=i;j<n;j++)
        {
            if(a[j]<a[mini])
                mini=j;

        }
        swap(a[i],a[mini]);
        if(i!=mini)
            cnt++;

    }
    for(int i=0;i<n;i++)
    {
        cout<<a[i];
        if(i!=n-1)
            cout<<" ";

    }
    cout<<endl<<cnt<<endl;
}



Measured memory_bytes: 3044
#include<bits/stdc++.h>
using namespace std;
typedef struct {
  int a1;
  int a2;
  int a3;
  int a4;
  int a5;
  int a6;
}dice_t;
int main(){
  int a[6];
  for(int i=0;i<6;i++){
    cin>>a[i];
  }
  dice_t p = {a[0],a[1],a[2],a[3],a[4],a[5]};

  string s;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(s[i]=='S'){
      int tmp=p.a1;
      p.a1 = p.a5;
      p.a5 = p.a6;
      p.a6 = p.a2;
      p.a2 = tmp;
    }
    else if(s[i]=='N'){
      int tmp=p.a1;
      p.a1 = p.a2;
      p.a2 = p.a6;
      p.a6 = p.a5;
      p.a5 = tmp;
    }
    else if(s[i]=='W'){
      int tmp=p.a1;
      p.a1 = p.a3;
      p.a3 = p.a6;
      p.a6 = p.a4;
      p.a4 = tmp;
    }
    else{
      int tmp=p.a1;
      p.a1 = p.a4;
      p.a4 = p.a6;
      p.a6 = p.a3;
      p.a3 = tmp;
    }
  }

  cout<<p.a1<<endl;

  return 0;
}



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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String number = sc.next();
        int[] digits = new int[number.length()+1];

        for(int i = 0 ; i < number.length() ; i++){
            digits[i] = number.charAt(number.length()-1-i) - '0';
        }

        int bills = 0;
        for(int i = 0 ; i <= number.length() ; i++){
            if(digits[i] == 10){
                digits[i+1]++;
                digits[i] = 0;
            }

            if(digits[i] < 5){
                bills += digits[i];
            }else if(digits[i] == 5){
                if(digits[i+1] >= 5){
                    digits[i+1]++;
                }
                bills += 5;
            }else{
                digits[i+1]++;
                bills += 10 - digits[i];
            }
        }

        System.out.println(bills);
    }
}



Measured memory_bytes: 36920
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;


int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(),a.end());
  int ans = a[n/2] - a[n/2-1];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
sx, sy, tx, ty=map(int,input().split())

dx=tx-sx
dy=ty-sy
d={0:'R', 1:'U', 2:'L', 3:'D'}
dirc=[dx,dy,dx,dy]

def path(sign,x,y,z,w):
  return d[sign+1]*abs(z-x) + d[sign+2]*abs(y-w)

s=''
s+='R'
s+=path(-1, sx+1, sy, tx, ty-1)
s+='UU'
s+=path(1, tx,ty+1,sx-1,sy)
s+='RD'
s+=path(-1, sx,sy-1,tx+1,ty)
s+='LL'
s+=path(1, tx-1,ty,sx,sy+1)
s+='D'
print(s)


Measured memory_bytes: 9200
#include<bits/stdc++.h>
using namespace std;
int main(){
	string S, T;
	int i, count=0;
	cin >> S >> T;
	for (i = 0; i < S.size(); i++){
		if (S[i] != T[i]){
			count++;
		}
	}

	cout << count << endl;
	return 0;
}

Measured memory_bytes: 3764
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int f=-1;
  for(int i=1;i<1000;i++){
    if(n==i*(i+1)/2){
      f=i;
    }
  }
  if(f==-1){
    cout << "No" << endl;
    return 0;
  }
  else{
    cout << "Yes" << endl;
    cout << f+1 << endl;
    int cnt=0;
    vector<vector<int>> c(f,vector<int>(f));
    int sum=0,s=0;
    for(int i=1;i<=n;i++){
      c[cnt][i-sum-1]=i;
      s++;
      if((cnt+1)*(cnt+2)/2==i){
        cnt++;
        sum=s;
      }
    }
    for(int i=0;i<f;i++){
      cout << f << " ";
      for(int j=0;j<=i;j++){
        cout << c[i][j] << " ";
      }
      for(int j=i+1;j<f;j++){
        cout << c[j][i] << " ";
      }
      cout << endl;
    }
    cout << f <<" ";
    for(int i=0;i<f;i++){
      cout << c[i][i] << " ";
    }
    cout << endl;
  }
}

Measured memory_bytes: 2176
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>

using namespace std;

int n, cnt;
vector<int> v1[1005][1005], v2[1005][1005], v3[1005][1005], v4[1005][1005];
vector<int> ve1, ve2;
int a[1005][1005];
queue<int> q1, q2;

int main()
{
//    freopen("input.txt", "r", stdin);
    scanf("%d", &n);
    for(int i = 1; i <= n; i++)
    {
        int t1, t2;
        scanf("%d", &t1);
        for(int j = 1; j < n - 1; j++)
        {
            t2 = t1;
            scanf("%d", &t1);
            v1[min(i, t1)][max(i, t1)].push_back(min(i, t2)), v2[min(i, t1)][max(i, t1)].push_back(max(i, t2));
            v3[min(i, t2)][max(i, t2)].push_back(min(i, t1)), v4[min(i, t2)][max(i, t2)].push_back(max(i, t1));
            a[min(i, t1)][max(i, t1)]++;
        }
    }
    for(int i = 1; i <= n; i++)
    {
        for(int j = i + 1; j <= n; j++)
        {
            if(a[i][j] == 0) q1.push(i), q2.push(j);
        }
    }
    while(!q1.empty())
    {
        ve1.clear(), ve2.clear();
        while(!q1.empty())
        {
            ve1.push_back(q1.front()), ve2.push_back(q2.front());
            q1.pop(), q2.pop();
        }
        for(int i = 0; i < ve1.size(); i++)
        {
            for(int j = 0; j < v3[ve1[i]][ve2[i]].size(); j++)
            {
                int t1 = v3[ve1[i]][ve2[i]][j];
                int t2 = v4[ve1[i]][ve2[i]][j];
                a[v3[ve1[i]][ve2[i]][j]][v4[ve1[i]][ve2[i]][j]]--;
                if(a[v3[ve1[i]][ve2[i]][j]][v4[ve1[i]][ve2[i]][j]] == 0) q1.push(v3[ve1[i]][ve2[i]][j]), q2.push(v4[ve1[i]][ve2[i]][j]);
            }
        }
        cnt++;
    }
    for(int i = 1; i <= n; i++)
    {
        for(int j = i + 1; j <= n; j++)
        {
            if(a[i][j] != 0)
            {
                printf("-1");
                return 0;
            }
        }
    }
    printf("%d", cnt);
    return 0;
}


Measured memory_bytes: 161280
#include<cstdio>
#include<iostream>
#define in inline
#define re register
using namespace std;
in int read(){
	re int t=0;
	re char v=getchar();
	while(v<'0'||v>'9')v=getchar();
	while(v>='0'&&v<='9'){
		t=(t<<3)+(t<<1)+(v^48);
		v=getchar();
	}
	return t;
}

int main(){
	if(read()+read()+read()<=21)puts("win");
	else puts("bust");
}

Measured memory_bytes: 256
from collections import Counter
N=int(input())
A = list(map(int,input().split()))

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

# ave1=sum(A)//len(A)
# ave2=-(-sum(A)//len(A))
# median=Counter(A).most_common(1)[0][0]

B=A[:]
C=A[:]

B.sort()
# 偶数の場合
if N % 2 == 0:
    median1 = N/2
    median2 = N/2 + 1
    median1 = int(median1) - 1
    median2 = int(median2) - 1
    median = (B[median1] + B[median2]) / 2

    # 奇数の場合
else:
    median = (N + 1) / 2
    median = int(median) - 1
    median = B[median]

median=int(median)

for i in range(0,N):
    C[i]-=median
    C[i]=abs(C[i])

print(sum(C))


Measured memory_bytes: 26764
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <typeinfo>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    string s;

    cin >> s;
    bool flag = s[0] == '7' || s[1] == '7' || s[2] == '7';
    cout << (flag ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3640
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#define memcle(a) memset(a, 0, sizeof(a))
#define fo(i, a, b) for (i = a; i <= b; i++)
#define fd(i, a, b) for (i = a; i >= b; i--)
#define debug(x) cerr << #x << '=' << x << endl;
using namespace std;

const int N = 510;
int b[N][N], c[N][N], d[N][N], n, ans = 100000;
char a[N][N];

int main()
{
    //freopen("b.in", "r", stdin);
    //freopen("b.out", "w", stdout);

    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%s", a[i] + 1);
    bool ok = 0;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
        {
            b[i][j] = a[i][j] == '#';
            ok |= b[i][j];
            c[i][j] = c[i - 1][j] + b[i][j];
            d[i][j] = d[i][j - 1] + b[i][j];
        }
    int sum = 0;
    for (int i = 1; i <= n; i++) 
    {
        if (c[n][i] != n) sum++;
    }
    if (!ok) {puts("-1"); return 0;}
    
    for (int i = 1; i <= n; i++)
    {
        bool ok = 0;
        for (int j = 1; j <= n; j++) 
            if (b[j][i]) 
            {
                ok = 1;
                break;
            }
        int cnt = n - d[i][n]; 
        {
            ans = min(ans, sum + cnt + (ok ^ 1));
        }
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 3456
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

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

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}

int main() {
	long long int a;
	long long int b;
	cin >> a >> b;
	long long int x;
	cin >> x;
	if (a == 0) {
		cout << b / x + 1;
		return 0;
	}
	cout << b / x - (a - 1) / x;
}

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

int main() {
    long long int n;
    long long int sum = 0;
    cin >> n;
    for (long long int i = 1; i <= n; i++) {
        if ((i%3)==0 || (i%5)==0) {
            continue;
        }
        sum += i;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3620
let split str delim =
  let open String in
  let rec doit s acc =
    match
      try Some (rindex s delim) with _ -> None
    with
    | None -> s :: acc
    | Some i -> doit (sub s 0 i) (sub s (i + 1) (length s - i - 1) :: acc) in
  doit str []

let find_set s x =
  let rec doit x =
    if x <> fst s.(x) then s.(x) <- (doit (fst s.(x)), snd s.(x));
    fst s.(x) in
  doit x

let unite s x y =
  let (a, b) = (find_set s x, find_set s y) in
  if snd s.(a) > snd s.(b) then s.(b) <- (a, snd s.(b))
  else begin
    s.(a) <- (b, snd s.(a));
    if snd s.(a) = snd s.(b) then s.(b) <- (fst s.(b), snd s.(b) + 1)
  end

let same_p s x y = find_set s x = find_set s y

let solve n q =
  let s = Array.init n (fun i -> (i, 0)) in
  let rec doit i =
    if i < q then begin
      begin match List.map int_of_string (split (read_line ()) ' ') with
      | 0 :: x :: y :: _ -> unite s x y
      | 1 :: x :: y :: _ -> print_endline (if same_p s x y then "1" else "0")
      | _ -> ()
      end;
      doit (i + 1)
    end in
  doit 0

let () =
  match List.map int_of_string (split (read_line ()) ' ') with
  | [n; q] -> solve n q
  | _ -> ()

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

int main()

{
    ll n,r=0,a=0;
    cin>>n;
    string s;
    cin>>s;
    
    for(ll i=0;i<n;i++)
    {
        if(s[i]=='R')
        {
            r++;
        }
    }
    
    for(ll i=0;i<r;i++)
    {
        if(s[i]=='W')
          a++;
    }
    
    cout<<a;
    return 0;
}

Measured memory_bytes: 3696
from collections import defaultdict
from sys import stdin

def main():
    N = int(input())
    XY = [tuple(map(int, input().split())) for _ in [0] * N]

    if N == 1:
        print(1)
        return

    XY.sort()
    cnt = defaultdict(int)
    for i in range(N):
        x1, y1 = XY[i]
        for j in range(i + 1, N):
            x2, y2 = XY[j]
            p = x2 - x1
            q = y2 - y1
            cnt[(p, q)] += 1
    print(N - max(cnt.values()))

input = lambda: stdin.readline()
main()


Measured memory_bytes: 3564
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    else:
        for i in range(H):
            if i == 0:
                print('#' * W)
            elif i == H - 1:
                print('#' * W + '\n')
            else:
                print('#'+ '.'* (W-2) + '#')


Measured memory_bytes: 5616
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;

void solve(){
  int n; cin >> n;
  vector<int> a(n);
  int maxa = 0, mina = 1000000000;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    maxa = max(a[i], maxa);
    mina = min(a[i], mina);
  }
  cout << maxa - mina << endl;
  return;
}
int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var (
		n, alice, bob int
	)
	a := make([]int, 101)
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	sort.Sort(sort.Reverse(sort.IntSlice(a)))

	for k, v := range a {
		if k % 2 == 0 {
			alice += v
		} else {
			bob += v
		}
	}
	fmt.Println(alice - bob)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

struct Edge {
    ll to, cost;
};

// 特定のルートまでに閉路があるか調べたいならこう
// https://atcoder.jp/contests/abc061/submissions/12926139
// https://atcoder.jp/contests/abc137/submissions/13373201
vector<ll> bellman_ford(int n, int s, vector<vector<Edge> > &graph) { // nは頂点数、sは開始頂点
    vector<ll> dist(n, INF);
    dist[s] = 0; // 開始点の距離は0
    for (int i = 0; i < n; i++) {
        for (int v = 0; v < n; v++) {
            for (int k = 0; k < graph[v].size(); k++) {
                Edge e = graph[v][k];
                if (dist[v] != INF && dist[e.to] > dist[v] + e.cost) {
                    dist[e.to] = dist[v] + e.cost;
                }
            }
        }
    }

    for (int i = 0; i < n; i++) {
        for (int v = 0; v < n; v++) {
            for (int k = 0; k < graph[v].size(); k++) {
                Edge e = graph[v][k];
                if (dist[v] != INF && dist[e.to] > dist[v] + e.cost) {
                    dist[e.to] = -INF;
                }
            }
        }
    }

    return dist;
}


int main() {
    int n, m;
    cin >> n >> m;
    struct E {
        int from, to;
        ll cost;
    };
    vector<E> v(m);
    for (E &e : v) cin >> e.from >> e.to >> e.cost, e.from--, e.to--;

    vector<vector<Edge>> g(n);
    for (E e : v) g[e.from].push_back(Edge{e.to, -e.cost});

    vector<ll> a1 = bellman_ford(n, 0, g);
    if (a1.back() <= -INF) {
        cout << "inf" << endl;
    } else {
        cout << -a1.back() << endl;

    }

}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define clr(a) memset(a, 0, sizeof(a))
#define deb(x) cout << #x << "=" << x << endl
#define si(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define ss(s) scanf("%s", &s)
#define pi(x) printf("%d\n", x)
#define pl(x) printf("%lld\n", x)
#define ps(s) printf("%s\n", s)
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define sz(x) x.size()
#define rep(n) for (int i = 0; i < n; i++)
#define repc(i, n) for (int i = 0; i < n; i++)
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a + n
using namespace std;

// Some typedef's
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> ii;
typedef vector<int> vi;
typedef vector<ll> vlli;
typedef vector<ii> vii;

template <typename T>
T modpow(T base, T exp, T modulus)
{
    base %= modulus;
    T result = 1;
    while (exp > 0)
    {
        if (exp & 1)
        result = (result * base) % modulus;
        base = (base * base) % modulus;
        exp >>= 1;
    }
    return result;
}

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

// Some contants
const ll inf = 1e12 + 7;
const double eps = 1e-9;
const long double pi = 1.00 * acos(-1.00);

int n;
vlli inp, pre;

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    /*
    #ifndef ONLINE_JUDGE
        freopen("./input.txt", "r", stdin);
        freopen("./output.txt", "w", stdout);
    #endif

    */
    const ll MOD = 1e9 + 7;
    cin >> n;
    repc(i, n){
        ll tmp;
        cin >> tmp;
        inp.pb(tmp);
    }
    ll curr = 0;
    repc(i, n)
    {
        curr += inp[i];
        pre.pb(curr);
    }

    ll ans = 0;

    FOR(i, 0, n-1){
        ll tmp = (curr - pre[i]) % MOD;
        ans = (ans % MOD + ((inp[i] % MOD) * (tmp)) % MOD) % MOD;
        ans = ans % MOD;
    }

    cout << ans % MOD << endl;

    return 0;
}


Measured memory_bytes: 7936
#include <bits/stdc++.h>
#define show(x) std::cerr << #x << " = " << (x) << std::endl
using ll = long long;
using ld = long double;
constexpr ll MOD = 1000000007LL;
template <typename T>
constexpr T INF() { return std::numeric_limits<T>::max() / 16; }
std::mt19937 mt{std::random_device{}()};
int main()
{
    std::string S;
    std::cin >> S;
    const int N = S.size();
    for (int i = 0; i < N; i++) {
        for (int j = i; j < N; j++) {
            const auto T = S.substr(0, i) + S.substr(j, N);
            if (T == "keyence") { return std::cout << "YES" << std::endl, 0; }
        }
    }
    std::cout << "NO" << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N;
  cin >> N;
  string s,t;
  cin >> s >> t;
  string ans = "";
  rep(i,N) {
    ans += s[i];
    ans += t[i];
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
  string S;
  cin >> S;
  int ans=0;
  for(int i=0; i<S.size(); i++){
    if(S[i]=='+') ans+=1;
    if(S[i]=='-') ans-=1;
  }
  cout << ans << endl;
  return 0;
}

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


int main() {
  int N;cin>>N;
  string S;cin>>S;
  long r=0,g=0,b=0;
  for(int i=0;i<N;i++){
    if(S[i]=='R'){r++;}
    if(S[i]=='G'){g++;}
    if(S[i]=='B'){b++;}
  }
  long cnt=0;
  int kankaku=1;
  int s=0;
  while(true){
    if(s+kankaku*2>=N){
      s=0;kankaku++;
      if(kankaku*2>=N)break;
    }
    if(S[s]=='R'&&S[s+kankaku]=='G'&&S[s+kankaku*2]=='B')cnt++;
    if(S[s]=='R'&&S[s+kankaku]=='B'&&S[s+kankaku*2]=='G')cnt++;
    if(S[s]=='G'&&S[s+kankaku]=='R'&&S[s+kankaku*2]=='B')cnt++;
    if(S[s]=='G'&&S[s+kankaku]=='B'&&S[s+kankaku*2]=='R')cnt++;
    if(S[s]=='B'&&S[s+kankaku]=='R'&&S[s+kankaku*2]=='G')cnt++;
    if(S[s]=='B'&&S[s+kankaku]=='G'&&S[s+kankaku*2]=='R')cnt++;
    s++;
  }
  //cout<<cnt<<endl;
  cout<<r*g*b-cnt<<endl;
}

Measured memory_bytes: 3612