akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main(){
int x,y,d;
while(1){
scanf("%d %d",&x,&y);
if(x == 0 && y == 0){
break;
}
else{
if(x > y){
d = x;
x = y;
y = d;
}
printf("%d %d\n",x,y);
}
}
return 0;
}

Measured memory_bytes: 600
// https://atcoder.jp/contests/agc032/tasks/agc032_d
//
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::fmt::*;
use std::io::*;
use std::str::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

const INF: i64 = 1e18 as i64;

fn main() {
    input! {
        n: usize, a: i64, b: i64,
        p: [usize1; n]
    };

    let mut dp = vec![vec![INF; n + 1]; 2];
    dp[0][n] = 0;

    for i in 0..n {
        let mut upper = 0;
        let mut lower = 0;
        for j in 0..i {
            if p[i] < p[j] {
                upper += 1;
            } else {
                lower += 1;
            }
        }

        let fr = i % 2;
        let to = 1 - fr;
        for j in 0..n + 1 {
            dp[to][j] = INF;
        }

        for j in 0..n + 1 {
            if dp[fr][j] == INF {
                continue;
            }
            let base = dp[fr][j];
            if j == n {
                dp[to][i] = min(dp[to][i], base + upper * a + lower * b);
            } else {
                if p[j] < p[i] {
                    dp[to][i] = min(dp[to][i], base);
                }
            }
            if j == n {
                dp[to][j] = min(dp[to][j], base);
            } else {
                if p[i] > p[j] {
                    dp[to][j] = min(dp[to][j], base + a);
                } else {
                    dp[to][j] = min(dp[to][j], base + b);
                }
            }
        }
    }
    let mut ans = INF;
    for i in 0..n {
        ans = min(ans, dp[n % 2][i]);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
import scala.io._
object Main extends App {
  val n = StdIn.readLine.toInt
  val s = StdIn.readLine

  def checkMin(i: Int, changes: Int, min: Int): Int = {
    if (i == n) min
    else {
      val newChanges = changes + (if (s.charAt(i) == '#') 1 else -1)
      checkMin(i + 1, newChanges, min.min(newChanges))
    }
  }
  val ws = s.count(_ == '.')
  println(checkMin(0, ws, ws))
}

Measured memory_bytes: 29340
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <string.h>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

typedef int64_t int64;
typedef int64_t ll;

const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };

template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

using namespace std;


class D {
	int n, k;
	string s;
	vector<int> cum;
public:
	D()
	{
		cin >> n >> k;
		cin >> s;
		cum.resize(n);

		if (s[0] == 'L')
			cum[0] = 0;
		else if (s[1] == 'R')
			cum[0] = 1;
		else
			cum[0] = 0;

		for (int i{ 1 }; i <= n - 2; i++)
		{
			if (s[i] == 'L')
			{
				if (s[i - 1] == 'L')
					cum[i] = cum[i - 1] + 1;
				else
					cum[i] = cum[i - 1];
			}
			else
			{
				if (s[i + 1] == 'R')
					cum[i] = cum[i - 1] + 1;
				else
					cum[i] = cum[i - 1];
			}
		}

		if (s[n - 1] == 'R')
			cum[n - 1] = cum[n - 2];
		else
		{
			cum[n - 1] = cum[n - 2] ;
			if (s[n - 2] == 'L')
				cum[n - 1] += 1;
			}

	}

	void debug()
	{
		REP(i, n)
			cout << cum[i] << " ";
		cout << endl;
	}

	int calcleft(int left)
	{
		if (left == 0)
			return 0;
		else
			return cum[left -1];
	}

	int calcright(int right)
	{
		if (right == n)
			return 0;
		else
			return cum[n - 1] - cum[right - 1];
	}

	void solve()
	{
		int flip{ 0 };
		int left{ 0 };
		int right{ 1 };
		int ans{ cum[n - 1] };

		while (right < n)
		{

			bool flag{ false };
			while (right < n)
			{
				if (s[right] != s[left])
				{
					if (!flag)
					{
						if (flip >= k)
							break;
						else
						{
							++flip;
							flag = true;
						}
					}
				}
				else
					flag = false;

				++right;
			}
			right = min(right, n);

			chmax(ans, calcleft(left) + calcright(right) + (right - left - 1));

				//cout << left << " " << right << endl;

			++left;
			while (s[left - 1] == s[left] && left < right - 1)
				++left;
		}

		chmax(ans, calcleft(left) + calcright(right) + (right - left - 1));
		//	cout << left << " " << right << endl;

		cout << ans << endl;
	}
};


int main()
{
	D solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 896
Option Strict On

Module Module1
    Dim N As String
    Dim i, j, k As Int32

    Sub Main()
        N = Console.ReadLine()

        While i <= 9
            k = 0
            For j = 0 To 3
                k = (k + 1) * Convert.ToInt32(CInt(N(j) & "") = i)

                If k >= 3 Then Exit While
            Next
            i += 1
        End While

        Console.WriteLine(
            New String() {"No", "Yes"}(k \ 3)
        )

    End Sub
End Module

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(v, n) sort(v, v+n)
#define VSORT(v) sort(v.begin(), v.end())
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 999999999
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    string res="";
    REP(i,s.length()){
        char tmp = s.at(i)+n;
        if(tmp>90){
            tmp -= 26;
           
        }
        res += tmp;
    }
    cout << res <<endl;
    return 0;
}

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

int F[102][102];
int color,gx,gy;
bool maze;

void DFS1(int Y,int X){
    if(F[Y][X]!=color)return;
    if(Y==gy&&X==gx)maze=true;
    
    F[Y][X]=0;
    
    DFS1(Y-1,X  );
    DFS1(Y  ,X-1);
    DFS1(Y  ,X+1);
    DFS1(Y+1,X  );
}

int main(){
    int N,M,sx,sy,n;
    cin >> N >> M;
    while(N!=0&&M!=0){
        cin >> sx >> sy >> gx >> gy >> n;
        int c,d,nx,ny;
        for(int i=0;i<n;i++){
            cin >> c >> d >> nx >> ny;
            for(int y=ny;y<ny+2*(1+d);y++){
                for(int x=nx;x<nx+2*(2-d);x++){
                    F[y][x] = c;
                }
            }
        }

        color = F[sy][sx];
        maze = false;
        if(color!=0){
            DFS1(sy,sx);
        }
        cout << (maze?"OK":"NG") << endl;
        for(int y=0;y<102;y++){
            for(int x=0;x<102;x++){
                F[y][x] = 0;
            }
        }
        cin >> N >> M;
    }
    return 0; 
}

Measured memory_bytes: 3028
#include <bits/stdc++.h>
using namespace std;
const int INF=1e9;

using P=pair<pair<int,int>,int>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H,W,K; cin >> H >> W >> K;
    vector<int> s(2),t(2);
    for (int i=0;i<2;++i) cin >> s[i],--s[i];
    for (int i=0;i<2;++i) cin >> t[i],--t[i];
    vector<string> S(H);
    for (int i=0;i<H;++i) cin >> S[i];
    int N=H*W*4;
    struct edge{
        int u,c1,c2;
        edge(int u,int c1,int c2):u(u),c1(c1),c2(c2){}
    };
    vector<vector<edge>> G(N);
    for (int i=0;i<N;++i){
        int I=i;
        int id=I%4; (I-=id)/=4;
        int w=I%W; (I-=w)/=W;
        int h=I;
        if (S[h][w]=='@') continue;
        for (int j=0;j<4;++j) if (j%2!=id%2){
            G[i].emplace_back((h*W+w)*4+j,1,0);
        }
        if (id==0&&h<H-1&&S[h+1][w]!='@') G[i].emplace_back(((h+1)*W+w)*4+id,0,1);
        if (id==1&&w<W-1&&S[h][w+1]!='@') G[i].emplace_back((h*W+(w+1))*4+id,0,1);
        if (id==2&&h>0&&S[h-1][w]!='@') G[i].emplace_back(((h-1)*W+w)*4+id,0,1);
        if (id==3&&w>0&&S[h][w-1]!='@') G[i].emplace_back((h*W+(w-1))*4+id,0,1);
    }
    vector<pair<int,int>> d(N,{INF,INF});
    priority_queue<P,vector<P>,greater<P>> pq;
    for (int i=0;i<4;++i){
        d[(s[0]*W+s[1])*4+i]={1,0};
        pq.push({{1,0},(s[0]*W+s[1])*4+i});
    }
    while(!pq.empty()){
        auto p=pq.top(); pq.pop();
        int v=p.second;
        auto cost=p.first;
        if (d[v]<cost) continue;
        for (auto e:G[v]){
            int u=e.u;
            pair<int,int> ncost;
            if (e.c1==1) ncost={cost.first+1,0};
            else {
                ncost={cost.first,cost.second+e.c2};
            }
            if (ncost.second==K+1) ncost.first+=1,ncost.second=1;
            if (ncost<d[u]){
                d[u]=ncost;
                pq.push({d[u],u});
            }
        }
    }
    int ans=INF;
    for (int i=0;i<4;++i) ans=min(ans,d[(t[0]*W+t[1])*4+i].first);
    cout << (ans==INF?-1:ans) << '\n';
}

Measured memory_bytes: 315624
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
int n;




int32_t main()
{
	#ifndef ONLINE_JUDGE
		freopen("in","r",stdin);
		freopen("out","w",stdout);
	#endif
	
	string s,t;
	cin>>s>>t;

	int n=s.length();int k=t.length();
	string ans=string(n,'{');
	string mx=ans;
	for(int i=0;i<=n-k;i++)
	{
		bool placed=1;string test="";
		for(int j=0;j<i;j++)test+=s[j];
		for(int j=i;j<i+k;j++)
		{
			if(s[j]=='?' or s[j]==t[j-i]){test+=t[j-i];}
			else {placed=0;;break;};
		}

		//cout<<test<<"\n";
		if(!placed)continue;
		for(int j=i+k;j<n;j++)test+=s[j];
		
		for(int j=0;j<n;j++)
		{
			if(test[j]=='?')test[j]='a';
		}
		ans=min(ans,test);
	}
	if(ans==mx)puts("UNRESTORABLE");
	else cout<<ans;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;

template<typename T1,typename T2>
ostream &operator<<(ostream &os,const pair<T1,T2>&p){
    os<<p.first<<" "<<p.second;
    return os;
}

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


signed main(){
    int n;cin>>n;
    int cnt[4]={};
    rep(i,n){
        string s;cin>>s;
        if(s[0]=='A') cnt[0]++;
        else if(s[0]=='W') cnt[1]++;
        else if(s[0]=='T') cnt[2]++;
        else cnt[3]++;
    }
    cout<<"AC x "<<cnt[0]<<endl;
    cout<<"WA x "<<cnt[1]<<endl;
    cout<<"TLE x "<<cnt[2]<<endl;
    cout<<"RE x "<<cnt[3]<<endl;
    return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
//#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1000000000000000000;
const int mod = 1000000007;
int test[345678], aa[345678][2];
signed main() {
	int n, m, cnt = 0, ans = 0; string s, t; 
	cin >> n >> m;
    for (int h = m; h <= n + 1; h++) {
        int sum = 0, num = 0;
        sum = (h - 1) * h / 2;
        num = (n + n - h + 1) * h / 2;
        ans += num - sum + 1; ans %= mod;
    }
    cout << ans % mod << endl;
	return 0;
}

Measured memory_bytes: 3624
#include<cstdio>
#include<iostream>
using namespace std;
int s[5];
int main()
{
	int i,j,a,b,q;
	for(i=1;i<=4;i++)cin>>s[i];
	cin>>a>>b;
	for(i=1;i<=4;i++)
	{
		for(j=i+1;j<=4;j++)
		{
			if(s[i]<s[j])
			{
				q=s[i];s[i]=s[j];s[j]=q;
			}
		}
	}
	if(a>b)cout<<s[1]+s[2]+s[3]+a<<endl;
	else cout<<s[1]+s[2]+s[3]+b<<endl;
	return 0;
}

Measured memory_bytes: 3072
// CODE by Kazhybay Askar

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

using namespace std;
using namespace __gnu_pbds;

/*
find_by_order(k);
order_of_key(k);
ordered_set(int) s;
*/

/*
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
rng();
shuffle(permutation.begin(), permutation.end(), rng);
*/

/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC    optimize("Ofast")
#pragma GCC    target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

#define F      first
#define S      second
#define pb     push_back
#define pf     push_front
#define ppb    pop_back
#define ppf    pop_front
#define Speed  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define sz     size()
#define all(x) x.begin(),x.end()
#define cont   continue
#define r0     return 0
#define nl     '\n'
#define ordered_set(T) tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>

typedef unsigned long long ull;
typedef long long ll;
typedef long double   ld;
typedef pair<ll,ll>   pll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;

const int MAXN  = 5e5  + 7;
const int MOD   = 1e9  + 7;
const int INF   = 1e9  + 7;
const ll  MINF  = 1e18 + 7;
const int EPS   = 1e-6;
const int dx[]  = {0, 0, 1, -1, -1, -1, 1, 1};
const int dy[]  = {1, -1, 0, 0, -1, 1, -1, 1};
const double pi = acos(-1.0);

ll n,a[MAXN],m;

void solve(){
    string s;
    cin>>s;
    n=s.sz;
    bool y=1;
    for(int i=0;i<s.sz;i++){
        if(s[i]!=s[n-i-1])y=0;
    }
 //  cout<<y<<" ";
    for(int i=0;i<(n-1)/2;i++){
        if(s[i]!=s[(n-1)/2-i-1])y=0;
    }
  //  cout<<y<<" ";
    ll cnt=1;
    for(int i=(n+3)/2-1;i<s.sz;i++){
        if(s[i]!=s[s.sz-cnt])y=0;
        cnt++;
    }
   // cout<<y<<" ";
    if(y==1)cout<<"Yes";
    else cout<<"No";
}



int main(){
    //freopen("A.in","r",stdin);
    //freopen("A.out","w",stdout);
    Speed;
    ll T=1;
    //cin>>T;
    while(T--){
        solve();
    }
    r0;
}


Measured memory_bytes: 256
N,K = map(int,input().split())
A = list(map(int,input().split()))
dp = [0 for _ in range(K+1)]
for i in range(K+1):
    if i<A[0]:
        dp[i] = 0
    else:
        dp[i] = not dp[i-A[0]]
        for j in range(1,N):
            if i>=A[j]:
                dp[i] = dp[i] or not dp[i-A[j]]
if dp[K]==True:
    print("First")
else:
    print("Second")

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

int main() {
  int A, B;
  string op;
  cin >> A >> B;

  if ((A * B) % 2 == 0) {
    cout << "Even" << endl;
  }
  /*else if (op == "-") {
    cout << A - B << endl;
  }
  else if (op == "*") {
    cout << A * B << endl;
  }
  else if (op == "?" || op == "=" || op == "!" || op == "=" || B == 0 ) {
    cout << "error" << endl;
  }*/
  else {
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
#define rep(i, n) for(ll i=0; i < n; i++)
#define reps(i, n) for(ll i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

int main() {
  int n;cin >> n;
  int mx;cin>> mx;

  if(n==1){cout << "Yes";return 0;}
  rep(i,n-1){
    int h;cin >> h;
    if(h<mx-1){cout << "No";return 0;}
    mx=max(mx,h);
  }
  cout << "Yes";

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>
#include <numeric>
#include <queue>
 
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
 
using namespace std;
 
typedef long long ll;

int main(int argc, char const *argv[])
{
  ll a,b,c;
  cin >> a >> b >> c;
  if (a <= c && c <= b) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
using System;

namespace AOJ
{
  class Program
  {
    static void Main(string[] args)
    {
      string[] ary = Console.ReadLine().Split(' ');

      int a = int.Parse(ary[0]);
      int b = int.Parse(ary[1]);
      int c = int.Parse(ary[2]);
      int ans = 0;

      for (int i = a; i <= b; i++)
      {
        if (c % i == 0) ans++;
      }

      Console.WriteLine(ans);
    }
  }
}

Measured memory_bytes: 9228
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

ll MOD = 1000000007;

int main(){
  ll N;
  cin >> N;
  string s;
  vvc ss(2, vc(N));
  rep(i, 2){
    cin >> s;

    rep(j, N) ss[i][j] = s[j];
  }
  
  ll h = 0, w = 0;
  ll ans = 1;
  
  while(w < N){
    if(w == 0){
      if(ss[0][0] == ss[1][0]){
        ans *= 3;
        ans %= MOD;
      } else{
        ans *= 6;
        ans %= MOD;
      }
    } else{
      if(ss[0][w - 1] == ss[1][w - 1]){
		ans *= 2;
		ans %= MOD;
      } else if(ss[0][w] != ss[1][w]){
        ans *= 3;
        ans %= MOD;
      }
    }

    if(ss[0][w] == ss[1][w])
      w++;
    else
      w += 2;
  }
  
  cout << ans << endl;
    
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <queue>
using namespace std;
int n, a[200000], b[200000];
long long ans = 0;
void func(int x){
    int left  = (x + n - 1) % n;
    int right = (x + n + 1) % n;
    int res = b[x] - a[x];
    int am = b[left] + b[right];
    ans += res / am;
    b[x] -= (res/am) * am;
}
int main(void){
    set<int> cand;
    queue<int> q;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=0;i<n;i++){
        cin >> b[i];
    }

    // exception
    bool same = true;
    for(int i=0;i<n;i++){
        if(b[i] < a[i]){
            puts("-1");
            return 0;
        }else if(b[i] > a[i]){
            same = false;
        }
    }
    if(same){
        puts("0");
        return 0;
    }



    for(int i=0;i<n;i++){
        if(b[i] > a[i] && b[i] > b[(i+n-1)%n] && b[i] > b[(i+1)%n]){
            q.push(i);
        }
    }
    while(!q.empty()){
        int mid = q.front(), left, right;
        left  = (mid + n - 1) % n;
        right = (mid + n + 1) % n;
        q.pop();
        if(b[mid] == a[mid])continue;
        func(mid);
        if(b[left] > b[(left+n-1)%n] && b[left] > b[(left+1)%n]){
            q.push(left);
        }
        if(b[right] > b[(right+n-1)%n] && b[right] > b[(right+1)%n]){
            q.push(right);
        }
    }
    /*
    for(int i=0;i<n;i++){
        cout << b[i] << " ";
    }
    cout << endl;*/
    for(int i=0;i<n;i++){
        if(a[i] != b[i]){
            puts("-1");
            return 0;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 2176
#![allow(non_snake_case)]
#![allow(unused_imports)]
use proconio::input;
use std::cmp::max;
use std::cmp::min;
use std::collections::HashMap;
use std::collections::VecDeque;

fn main() {
    input! {
        S: String,
    }

    let mut ans = 700;
    for i in 0..3 {
        if &S[i..=i] == "o" {
            ans += 100;
        }
    }

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


Measured memory_bytes: 2096
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;

class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String strNum = br.readLine();
		String[] strNumArrays = strNum.split(" ");
		ArrayList<Integer> numList = new ArrayList<Integer>();
		for (int i = 0; i < strNumArrays.length; i++) {
			numList.add(Integer.parseInt(strNumArrays[i]));
		}
		Collections.sort(numList);
		String out = String.valueOf(numList.get(0));
		for (int i = 1; i < numList.size(); i++) {
			out += " " + numList.get(i);
		}
		System.out.println(out);
	}

}

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

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

    int ac = 0, wa = 0, tle = 0, re = 0;
    for (int i = 0; i < n;i++){
        string s;
        cin >> s;

        if(s == "AC"){
            ac++;
        }
        else if(s == "WA"){
            wa++;
        }
        else if(s == "TLE"){
            tle++;
        }
        else{
            re++;
        }
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <math.h>
#include <iomanip>

using namespace std;

int main()
{
    long double A, B, H, M;
    long double h, m, a, pi, c, ans2, ans;
    cin >> A >> B >> H >> M;
    h = 30.0 * H + M / 2.0;
    m = 6.0 * M;
    a = (h < m) ? m - h : h - m;
    if(a > 180){
        a = 360.0 - a;
    }
    pi = 2.0 * asin(1.0);
    a = pi / (180.0 / a);
    c = cos(a);
    ans2 = A * A + B * B - 2.0 * A * B * c;
    ans = sqrt(ans2);
    cout << fixed << setprecision(15);
    cout << ans << endl;


}

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}

//char->int
int ctoi(char c){
    return c-'0';
}



int main(){
    int n,m;
    cin >> n >> m;
    int a[m];
    int b[m];
    int ans[n];
    rep(i,n) ans[i] = 0;

    rep(i,m) cin >> a[i] >> b[i];


    for(int i=0;i<m;i++){
        int x = a[i];
        int y = b[i];
        ans[x-1]++;
        ans[y-1]++;
    }

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

Measured memory_bytes: 256
// 2011/07/12 Tazoe

#include <iostream>
#include <string>
using namespace std;

int main()
{
	char bal = 'A';

	while(true){
		string str;
		cin >> str;
		if(cin.eof())
			break;

		if(str[0]==bal)
			bal = str[2];
		else if(str[2]==bal)
			bal = str[0];
	}

	cout << bal << endl;

	return 0;
}

Measured memory_bytes: 0
//コンパイラ最適化用
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<chrono>//実行時間計測
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm,accumulate
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;
typedef pair<ll, ld> pld;
typedef pair<pii, int> ppiii;
typedef pair<pii, ll> ppiill;
typedef pair<pll, ll> ppllll;
typedef pair<pli, int> pplii;
typedef map<int, int> mii;
typedef deque<ll> dll;
typedef queue<ll> qll;
typedef priority_queue<ll> pqll;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqrll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<int>> vvint;
typedef vector<vector<pll>> vvpll;

//マクロ
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define cin(x) cin >> x
//最大化問題最小化問題
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

signed main(){
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    //入力
    ll N =0;
    cin >> N;

    vll h(N);
    REP(i,N) cin >> h[i];


    //本文
    // 無限大の値

// DP テーブル
long long dp[100010];

// DP テーブル全体を初期化 (最小化問題なので INF に初期化)
for (int i = 0; i < 100010; ++i) dp[i] = INF;

// 初期条件
dp[0] = 0;
    //出力
    for(int i = 1;i<N;i++){
        chmin(dp[i],dp[i-1]+abs(h[i]-h[i-1]));
        if(i>1) chmin(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout << dp[N-1] << endl;
    //REP(i,N) cout << ans.at(i) <<endl;
  return 0;
}

Measured memory_bytes: 4740
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define fi first
#define se second
#define All(x) (x).begin(),(x).end()
int main(){
	int N;
	cin>>N;
	if(N%10==7||N/100==7||(N%100)/10==7) {
		cout<<"Yes";
	}
	else cout<<"No";
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
long long mod = 1e9+7;


int main(){
    int n,ans;
    cin>>n;
    cin>>ans;
    n--;
    while(n--){
        int a;
        cin>>a;
        ans = __gcd(a,ans);
    }
    cout<<ans;
}

Measured memory_bytes: 3548
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    n = gete(int)
    a = list(geta(int))

    a.sort(reverse=True)

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

    if n & 1 == 1:
        ans -= a[(n+1)//2-1]

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 29596
#include <bits/stdc++.h>
struct Fast {Fast(){std::cin.tie(0);std::ios::sync_with_stdio(false);}} fast;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define repR(i, n) for(ll i = n; i >= 0; i--)
#define For(i, m, n) for(ll i = m; i < n; i++)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) v.begin(), v.end()

using namespace std;

ll mod = 1e9+7;
inline ll gcd(ll a, ll b){
    ll r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

inline ll lcm(ll x, ll y)
{
    if(x == 0 || y == 0) {
        return -1;
    }
    
    return (x * y / gcd(x, y));
}

inline ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

inline ll nCr(ll n, ll r) {
    if ( r * 2 > n ) r = n - r;
    ll dividend = 1;
    ll divisor  = 1;
    for ( ll i = 1; i <= r; ++i ) {
        dividend *= (n-i+1);
        divisor  *= i;
    }
    return (dividend / divisor);
}

// 因数分解
inline vector<pair<ll, int>>factorize(ll n){
    vector<pair<ll, int>> res;
    for(ll i = 2; i * i <= n; ++i){
        if(n % i) continue;
        res.emplace_back(i, 0);
        while(n % i == 0){
            n /= i;
            res.back().second++;
        }
    }
    if(n != 1) res.emplace_back(n, 1);
    return res;
}

inline bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

//階乗
inline ll factorialMethod(ll k){
    ll sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

inline ll vector_finder(std::vector<ll> vec, ll number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
    if (index != vec.size()) { // 発見できたとき
        return 1;
        
        
    }
    else { // 発見できなかったとき
        return 0;
    }
}

void recursive_comb(ll *indexes, ll s, ll rest, std::function<void(ll *)> f) {
    if (rest == 0) {
        f(indexes);
    } else {
        if (s < 0) return;
        recursive_comb(indexes, s - 1, rest, f);
        indexes[rest - 1] = s;
        recursive_comb(indexes, s - 1, rest - 1, f);
    }
}

void foreach_permutation(int n, std::function<void(int *)> f) {
    int indexes[n];
    for (int i = 0; i < n; i++) indexes[i] = i;
    do {
        f(indexes);
    } while (std::next_permutation(indexes, indexes + n));
}

int main(){
    ll ans = 0;
    string s, t, u;
    ll a, b;
    cin >> s >> t >> a >> b >> u;
    
    if(u == s){
        a --;
    }else if(u == t){
        b --;
    }
    
    cout << a << " " << b << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
int clr[100005];
int vis[100005];
int dist[100005];
vector<pair<int,int> >adj[100005];
void dfs(int ele)
{
    vis[ele] = 1;
    for(int i=0;i<adj[ele].size();i++)
    {
        if(!vis[adj[ele][i].first])
        {
            vis[adj[ele][i].first]=1;
            dist[adj[ele][i].first] = dist[ele]+adj[ele][i].second;
            dfs(adj[ele][i].first);
        }
    }
}
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) clr[i] = -1;
    for(int i=0;i<n-1;i++)
    {
        int x,y,w;
        cin>>x>>y>>w;
        adj[x].pb({y,w});
        adj[y].pb({x,w});
    }
    clr[1] = 0;

    dfs(1);

    for(int i=1;i<=n;i++)
    {
   //     cout<<dist[i]<<" ";
    }
    for(int i=1;i<=n;i++)
    {
        if(dist[i]%2)
        cout<<1<<endl;
        else cout<<0<<endl;
    }
}


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

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

        public static void Solve()
        {
            var WHN = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var (W, H, N) = (WHN[0], WHN[1], WHN[2]);
            var xMin = 0;
            var xMax = W;
            var yMin = 0;
            var yMax = H;
            for (var i = 0; i < N; i++)
            {
                var ABC = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
                var (A, B, C) = (ABC[0], ABC[1], ABC[2]);
                switch (C)
                {
                    case 1:
                        xMin = Math.Max(xMin, A);
                        break;
                    case 2:
                        xMax = Math.Min(xMax, A);
                        break;
                    case 3:
                        yMin = Math.Max(yMin, B);
                        break;
                    case 4:
                        yMax = Math.Min(yMax, B);
                        break;
                    default:
                        break;
                }
            }
            var answer = Math.Max(0, (xMax - xMin)) * Math.Max(0, (yMax - yMin));
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 28212
h, w = map(int, input().split())
 
a = [''] * h
 
for i in range(h):
    a[i] = input()
    
row = [False] * h
col = [False] * w
 
for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            row[i] = True
            col[j] = True
 
for i in range(h):
    if row[i]:
        for j in range(w):
            if col[j]:
                print(a[i][j], end='')
        print()

Measured memory_bytes: 4468
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    ll N,M,K;
    cin>>N>>M>>K;
    vector<ll> A(N),B(M),sumA(N+1),sumB(M+1);
    rep(i,N){cin>>A.at(i);}
    rep(i,M){cin>>B.at(i);}
    rep(i,N){
        sumA.at(i+1)=sumA.at(i)+A.at(i);
    }
    rep(i,M){
        sumB.at(i+1)=sumB.at(i)+B.at(i);
    }
    int pA=0,pB=M;//AをpA冊、BをpB冊
    int ans=0;
    while(pA<=N && pB>=0){
        ll now=sumA.at(pA)+sumB.at(pB);
        if(now>K){
            pB--;
        }
        else{
            ans=max(ans,pA+pB);
            pA++;
        }
    }
    cout<<ans<<endl;
}

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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	auto toNum = [&](string S) {
		int res = 0;
		for (int c : S) {
			res = 10 * res + c - '0';
		}
		return res;
	};
	auto valid = [&](string S) {
		int num = toNum(S);
		return 1 <= num && num <= 12;
	};

	string S; cin >> S;
	bool l = valid(S.substr(0, 2));
	bool r = valid(S.substr(2, 2));
	if (l && r) {
		cout << "AMBIGUOUS" << endl;
	} else if (l) {
		cout << "MMYY" << endl;
	} else if (r) {
		cout << "YYMM" << endl;
	} else {
		cout << "NA" << endl;
	}

	return 0;
}


Measured memory_bytes: 636
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

static constexpr ld expected(ld x) { return (x + 1.0) * x * 0.5 / x; }

int main() {
  ll N, K;
  cin >> N >> K;
  vec<ll> p(N), acc(N);
  ll t = 0;
  REP(i, N) {
    cin >> p[i];
    t += p[i];
    if (i >= K) {
      t -= p[i - K];
    }
    acc[i] = t;
  }
  ll vmax = 0, upper = 0;
  for (ll i = 0; i < N; i++) {
    if (acc[i] > vmax) {
      vmax = acc[i];
      upper = i;
    }
  }
  ld ans = 0;
  for (ll i = upper - K + 1; i <= upper; i++) {
    if (i >= 0 && i < N) {
      ans += expected(p[i]);
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main()
{
  int n, m; cin >> n >> m;
  int a[n][m] = {0};
  int b[m] = {0};
  int c[n] = {0};

  rep(i, n){
    rep(j, m) {
      cin >> a[i][j];
    }
  }
  rep(i, m){
    cin >> b[i];
  }

  rep(i, n){
    rep(j, m){
      c[i] += a[i][j] * b[j];
    }
  }

  rep(i, n) {
    cout << c[i] << endl;
  }
  return 0;
}


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

int main(){
	string s;
	cin>>s;
	int k;
	if(s[1]==s[2]&&s[1]==s[3])
		cout<<"Yes";
	else if(s[0]==s[1]&&s[0]==s[2])
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
} 






Measured memory_bytes: 256
#pragma GCC optimize("trapv")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pi = pair<ll, ll>;
const int maxn = 3555;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int a, b;
	cin >> a >> b;
	cout << (a^b);
}


Measured memory_bytes: 256
#ifdef _MSC_VER
#  define _CRT_SECURE_NO_WARNINGS
#  define _USE_MATH_DEFINES
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

#include <bits/stdc++.h>
using namespace std;
using i32 = int; using i64 = long long int; using f64 = double;
using u32 = unsigned int; using u64 = unsigned long long int; using str = string;
template <typename T> using vec = vector<T>; void in() { }
template <typename T, typename...TS> void in(T &&x, TS &&...xs) { cin >> x; in(move(xs)...); }
template <typename T> void out(T &&x) { cout << x << "\n"; }
template <typename T, typename...TS> void out(T &&x, TS &&...xs) { cout << x << " "; out(move(xs)...); }
#define indef(t, ...) t __VA_ARGS__; in(__VA_ARGS__)
#define get(t) []{ t x; cin >> x; return x; }()
#define times(n, i) for (i32 i = 0; i < (n); ++i)
#define range(a, b, i) for (i32 i = (a); i < (b); ++i)
#define upto(a, b, i) for (i32 i = (a); i <= (b); ++i)
#define downto(a, b, i) for (i32 i = (a); i >= (b); --i)
#define all(xs) (xs).begin(), (xs).end()
#define sortall(xs) sort(all(xs))
#define reverseall(xs) reverse(all(xs))
#define even(x) ((abs(x) & 1) == 0)
#define odd(x) ((abs(x) & 1) == 1)
#define bit(x, i) (((x) >> i) & 1)
#define append emplace_back
#define bisect_left lower_bound
#define bisect_right upper_bound
#define bound(a, x, b) (a <= x && x <= b)
const i64 MOD = 1000000007ll;
const f64 EPS = 1e-10;

struct unionfind {
    vec<i32> data;
    unionfind(i32 size) : data(size, -1) { }
    void unite(i32 x, i32 y) {
        x = find(x); y = find(y); if (x == y) return;
        if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x;
    }
    i32 find(i32 x) { return data[x] < 0 ? x : data[x] = find(data[x]); }
    i32 size(i32 x) { return -data[find(x)]; }
    bool same(i32 x, i32 y) { return find(x) == find(y); }
};

i32 n;
vec<pair<i32, i32>> xs, ys;
vec<tuple<i32, i32, i32>> es;

i64 solve() {
    in(n);
    times(n, ni) {
        indef(i32, x, y);
        xs.append(make_pair(x, ni));
        ys.append(make_pair(y, ni));
    }
    sortall(xs); sortall(ys);
    times(n-1, ni) {
        es.append(make_tuple(xs[ni+1].first - xs[ni].first, xs[ni].second, xs[ni+1].second));
        es.append(make_tuple(ys[ni+1].first - ys[ni].first, ys[ni].second, ys[ni+1].second));
    }
    sortall(es);
    i64 ans = 0;
    unionfind uf(n);
    times(2*(n-1), ei) {
        i32 c, a, b;
        tie(c, a, b) = es[ei];
        if (uf.same(a, b)) continue;
        uf.unite(a, b);
        ans += c;
    }
    return ans;
}

i32 main()
{
    ios::sync_with_stdio(false);

#ifdef _MSC_VER
    /**
    ifstream fin("input.txt"); cin.rdbuf(fin.rdbuf()); assert(fin);
    ofstream fout("output.txt"); cout.rdbuf(fout.rdbuf()); assert(fout);
    /**/
#endif

    cout << fixed << setprecision(9);
    out(solve());

    return 0;
}

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

ll num[101010];

int main() {
    ll N, K, Q;
    cin >> N >> K >> Q;


    rep(i, Q) {
        ll A;
        cin >> A;
        A--;
        num[A]++;
    }

    rep(i, N) {
        ll tmp = K - (Q - num[i]);
        if (tmp <= 0) {
            cout << "No" << endl;
        }
        else {
            cout << "Yes" << endl;
        }

    }
}


Measured memory_bytes: 1408
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef vector<ll> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
unsigned long long inf = (1LL << 62);
ll mod = 1000000007;

//bool operator< (pint a, pint b) {
	//return a.second < b.second;

//}



ll gcd(ll a, ll b) {

	if (b == 0)
		return a;

	return gcd(b, a % b);


}

ll max(ll a, ll b) {
	if (a < b) {
		return b;
	}
	else
		return a;

}

ll min(ll a, ll b) {
	if (a < b)
		return a;

	return b;
}




pint dx[4] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };

vector<pint> list;










void floyd(int N, ll** d) {

	rep(k, N+1){
		rep(i, N+1) {
			if (d[i+1][k+1] == inf) continue;
			rep(j, N+1) {
				if (d[j+1][k+1] == inf) continue;

				d[i+1][j+1] = min(d[i+1][j+1], d[i+1][k+1] + d[j+1][k+1]);

			}

		}
	}




}


ll d[100005];
vector<ll> M[100005];
vector<ll> anslist;


stack<int> to_1;






string S;


ll num[30];

int main() {
	ll N;


	cin >> N;

	cin >> S;

	ll all_num = 1;
	
	rep(i, N) {
		num[S[i] - 'a'] += 1;

	}


	rep(i, 30) {


		all_num = (all_num * (num[i] + 1)) % mod;

	}

	all_num -= 1;

	cout << all_num % mod << endl;

	return 0;
}

Measured memory_bytes: 2816
object Main extends App {
  val n:Int = io.StdIn.readInt()

  val deck = Array.ofDim[Int](4, 13)
  val suit = Array[String]("S", "H", "C", "D")

  for (i <- 1 to n) {
    val card = io.StdIn.readLine().split(" ")
    card(0) match {
      case "S" => deck(0)(card(1).toInt - 1) = card(1).toInt
      case "H" => deck(1)(card(1).toInt - 1) = card(1).toInt
      case "C" => deck(2)(card(1).toInt - 1) = card(1).toInt
      case "D" => deck(3)(card(1).toInt - 1) = card(1).toInt
    }
  }

  for (j <- 0 to 3; k <- 0 to 12) {
    if (deck(j)(k) == 0) {
      println(suit(j) + " " + (k + 1))
    }
  }
}

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

int main ()
{
    int x, a,b,s=0,t=0;
    cin >> x ;
    cin >> a;
    cin >> b;
    s = a-x;
    s = s*s;
    t = b-x;
    t = t*t;
    if (s>t)
        cout << "B" << endl;
    else
        cout << "A" << endl;
    return 0;
}


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

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]) {
  ll n, k;
  cin >> n >> k;
  vector<ll> va(n);
  for (int i = 0; i < n; ++i) {
    cin >> va[i];
  }

  ll left = 1, right = *max_element(va.begin(), va.end());
  auto check = [](vector<ll> &va, ll mid, ll k) {
    ll cnt = 0;
    for (int i = 0; i < va.size(); ++i) {
      ll a = va[i];
      cnt += a / mid - (a % mid == 0);
    }

    return cnt <= k;
  };

  while (left < right) {
    ll mid = (left + right) / 2;
    if (check(va, mid, k)) {
      right = mid;
    } else {
      left = mid + 1;
    }
  }

  cout << right << '\n';

  return 0;
}

Measured memory_bytes: 4764
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }



int n;
string str;

int main() {
    scanf("%d\n", &n);
    for (int id = 0; id < n; ++id) {
        getline(cin, str);
        for (int i = 0; i < (int)str.size()-6; ++i) {
            string sub = str.substr(i, 7);
            if (sub == "Hoshino") { str[i+6] = 'a'; }
        }
        puts(str.c_str());
    }
    return 0;
}


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

typedef long long ll;
const ll MOD = 1000000007;

using namespace std;

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

    int n;
    cin >> n;
    string s;
    cin >> s;

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

    dp[1][1] = 1;
    pre[1][1] = 1LL;

    for (int m = 2; m <= n; m++) {
        for (int d = 1; d <= m; d++) {
            if (s[n - m] == '<') {
                dp[m][d] = (pre[m - 1][m - 1] - pre[m - 1][d - 1]) % MOD;
            } else {
                dp[m][d] = (pre[m - 1][d - 1] - pre[m - 1][0]) % MOD;
            }
        }
        // calculate prefix sum for m-th row of dp
        for (int i = 1; i <= m; i++) pre[m][i] = pre[m][i - 1] + dp[m][i];
    }

    int ans = (pre[n][n] - pre[n][0]) % MOD;

    cout << ans;

    return 0;
}

Measured memory_bytes: 106112