akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#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(){
    int n;
    cin >> n;
    vector <vector <int>> red(2*n),blue(2*n);
    int a,b,c,d;
    rep(i,n){
        cin >> a >> b;
        red[a].push_back(b);
    }
    rep(i,n){
        cin >> c >> d;
        blue[c].push_back(d);
    }

    vector <int> k(n+2,-1);
    k[n+1]=1000;
    int l;
    int r2,m2,l2;
    int ans=0;

    rep(i,2*n){
        sort(k.begin(),k.end());
        l=blue[i].size();
        rep(j,l){
            r2=n+1;
            l2=0;
            while(r2-l2>1){
                m2=(r2+l2)/2;
                if(k[m2]<blue[i][j]){
                    l2=m2;
                }
                else{
                    r2=m2;
                }
            }
            if(k[l2]!=-1){
                ++ans;
                k[l2]=-1;
                sort(k.begin(),k.end());
            }
        }

        l=red[i].size();
        rep(j,l){
            k[j]=red[i][j];
        }
        sort(k.begin(),k.end());
            
    }

    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back
 
typedef long long ll;
typedef pair<int, int> i_i;
 
const int MOD = 1e9 + 7;
const ll INF = LLONG_MAX / 2;
 
 
int main() {
	int N, M; cin >> N >> M;
	vector<int> a(M), b(M), c(M);
	rep(i, M) cin >> a[i] >> b[i] >> c[i], a[i]--, b[i]--;
	vector<vector<int> > adj(N, vector<int>(N));
	rep(i, M) adj[a[i]][b[i]] = adj[b[i]][a[i]] = c[i];
	
	vector<int> C(1<<N);
	rep(S, 1<<N) rep(i, M) if ((S>>a[i] & 1) && (S>>b[i] & 1)) C[S] += c[i];
	vector<vector<int> > dp(1<<N, vector<int>(N, -1));
	dp[1][0] = 0;
	rep(S, 1<<N) rep(u, N) if (dp[S][u] != -1) {
		int _S = (1<<N) - 1 - S;
		rep(v, N) if ((_S>>v & 1) && adj[u][v])
			dp[S | 1 << v][v] = max(dp[S | 1 << v][v], dp[S][u] + adj[u][v]);
		for (int T = _S; T; T = (T - 1) & _S)
			dp[S | T][u] = max(dp[S | T][u], dp[S][u] + C[T | 1<<u]);
	}
	int ans = -dp.back()[N - 1];
	rep(i, M) ans += c[i];
	cout << ans << endl;
}


Measured memory_bytes: 3840
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int a[103];

 int main()
 {
     long long a,b,c;
     cin>>a>>b>>c;
     a=abs(a);
     long long  x=a/c;
     if(x>=b)cout<<(a-c*b);
     else{a-=c*x;
        b-=x;
        if(b%2)cout<<(c-a);
        else cout<<a<<endl;


     }

 }


Measured memory_bytes: 3644
#include <stdio.h>

int main(){

  int a2,b2,d,r;
  double a,b,f;

  scanf("%lf %lf", &a, &b);

  a2 = a;

  b2 = b;

  d = a/b;

  r = a2%b2;

  f = a/b;

  printf("%d %d %.5lf\n",d,r,f);

  return 0;

}

Measured memory_bytes: 652
#include<bits/stdc++.h>
#define int long long
#define double long double
#define vi vector<int>
#define vpi vector<pair<int,int> >
#define mii map<int,int>
#define mpi map<pair<int,int>,int>
#define msi map<string,int>
#define set set<int>
#define u_set unordered_set<int>
#define pb push_back
#define endl "\n"
#define ll long long int
#define vll vector<long long int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define umap unordered_map 
#define mod 1000000007
#define fori(a,n) for(int i=a;i<n;i++)
#define forj(a,n) for(int j=a;j<n;j++)
#define MAX 300303
#define V vector
using namespace std;

vvi dp(3001,vi(3001,INT_MAX));
signed main()
{
    io
    int n;
    cin >> n;
    vi a(n);
    fori(0,n) cin >> a[i];
    fori(0,n){
        dp[i][i] = a[i];
    }
    fori(0,n-1){
        dp[i][i+1] = abs(a[i] -a[i+1]);
    }
    for(int i=n-3;i>=0;--i){
        for(int j=i+2;j<n;j++){
            dp[i][j] = max(a[i]-dp[i+1][j] ,a[j]- dp[i][j-1]);
        }
    }
    cout << dp[0][n-1] << endl;


} 

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

long long s[400][30]; 
const int Shurui=26;//今回は26種類
int Date;//今回は1年間なので365日
double Seigenjikan=1.8;//実行時間

int main() {
  clock_t start = clock();
  cin >>Date;
  vector<int>c(Shurui);
  vector<int>last(Date,0);//前回の日にち
  vector<int>t(Date,0);//開催する順番
  for(int i=0;i<Date;i++)t[i]=i%Shurui;//とりあえずの値
  long long wa=0;
  for(int i=0;i<Shurui;i++){
    cin>>c[i];
    wa+=c[i];
  }
  for(int i=0;i<Date;i++){
    for(int j=0;j<Shurui;j++){
      cin>>s[i][j];
    }
  }
  long long kotae=0;
  long long hikukazu=0;
  long long atai=0;
  for(int i=0;i<Date;i++){
    atai=0;
    atai=s[i][t[i]];
    hikukazu+=wa-c[t[i]]*(i+1-last[t[i]]);
    last[t[i]]=i+1;
    kotae+=atai-hikukazu;
  }  
  clock_t end = clock();
  double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
  while(time<Seigenjikan){
    int d=rand()%Date;
    int q=rand()%Shurui;
    int old=t[d];
    t[d]=q;
    long long new_kotae=0;
    hikukazu=0;
    for(int i=0;i<Date;i++){
      atai=0;
      atai=s[i][t[i]];
      hikukazu+=wa-c[t[i]]*(i+1-last[t[i]]);
      last[t[i]]=i+1;
      new_kotae+=atai-hikukazu;
    }
    if(new_kotae<kotae){
      t[d]=old;
    }else{
      kotae=new_kotae;
    }
    end = clock();
    time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
  }
  for(int i=0;i<Date;i++){
    cout<<t[i]+1<<endl;
  }
  return 0;
}

Measured memory_bytes: 3756
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

typedef pair<string, int> P;

int main()
{
	int n, q;
	cin >> n >> q;
	queue<P> Q;
	REP(i, n)
	{
		P p;
		cin >> p.first >> p.second;
		Q.push(p);
	}

	int t = 0;
	while (!Q.empty())
	{
		P f = Q.front(); Q.pop();
		int s = std::min(f.second, q);
		f.second -= s;
		t += s;
		if (f.second == 0)
		{
			cout << f.first << " " << t << endl;
		}
		else
		{
			Q.push(f);
		}
	}
	return 0;
}


Measured memory_bytes: 6412
// Hail god Yato
 
#include <bits/stdc++.h> 
using namespace std;
 
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const ll mod = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
//
//
ll val(ll num){
    return num*num*num*num*num;
}
void solve(){
    ll x;
    cin>>x;
    for(ll i = -200; i < 200; i++)
        for(ll j = -200; j < 200; j++){
            if(val(i) - val(j) == x){
                cout<<i<<" "<<j<<"\n";
                return ;
            }
        }
}
int main(){ 
        hs;
        ll t;
        t=1;
        // cin>>t;
        for (int i=1; i<=t; i++){
                //cout<<"Case #"<<i<<": ";
                solve();
         }
        return 0; 
}

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

int main(){
  ll n; cin>>n;
  vector<string> A(n+1);
  for(ll i=1; i<=n; i++) cin>>A[i];
  if(n%2==0){
    for(ll i=n; i>=2; i-=2) cout<<A[i]<<" ";
    for(ll i=1; i<n-1; i+=2){
      cout<<A[i]<<" ";
    }
    cout<<A[n-1]<<endl;
  }
  if(n%2==1){
    for(ll i=n; i>=1; i-=2) cout<<A[i]<<" ";
    for(ll i=2; i<n-1; i+=2){
      cout<<A[i]<<" ";
    }
    cout<<A[n-1]<<endl;
  }
}

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



int main() {

    int N;
    int A[100001];
    cin >> N;
    for (int i = 0; i < N + 1; i++) cin >> A[i];
    //今の深さの点の数
    long long now = 1;
    //int mae = 0;
    long long ans = 0;
    //末端の数
    long long sum = 0;
    //分岐した回数
    long long route = 1;
    
    for (int i = 0; i < N + 1; i++)
    {
        sum += A[i];
    }
    long long s = sum;
    //cout << sum << endl;
    for (int i = 0; i < N + 1; i++)
    {
        /*
        //cout << now <<route<< endl;
        ans += now;
        //cout << now<< " ";
        now -= A[i];
        sum -= A[i];
        now = min(now * 2, sum);

        //cout << now << endl;
        if (i != N && now <= 0)
        {
            cout << -1 << endl;
            return 0;
        }
        else if (i == N && now != 0)
        {
            cout << -1 << endl;
            return 0;
        }*/

        
        ans += now;
        now -= A[i];
        s -= A[i];
        //できるだけ早く分岐しておく
        long long a = now;
        /*
        //now 2倍ルート
        if (route + a < sum)
        {
            //新しい分岐はa個
            now += a;
            route += a;
        }
        //nowがそれ以降の和になるルート
        else
        {
            //基本的にrouteは1+枝の数
            //ある瞬間のroute-1がそれまでの葉の数と等しければいい
            //分岐した数だけ葉が増える、route+=nはA[i]=nを意味する
            //つまりrouteはそれまでのA[i]の和、route= sum-sumA[i]
            //now-A[i]（分岐＝葉の数）=葉以外の数、
            //葉の枚数＋全部の和-分岐の数（）

            //now=sum-sumA[i-1]なら、

            //新しい分岐はsum-route個
            //（最終的な道の数）ー（今の道の数）をnow（今の道の数）に足して（最終的な道の数）にする
            //now += sum - route;
            now = s;
            route += sum - route;
        }*/
        now = min(a * 2, s);

        if (i != N && now <= 0)
        {
            cout << -1 << endl;
            return 0;
        }
        else if (i == N && now != 0)
        {
            cout << -1 << endl;
            return 0;
        }


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

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

int main()
{
    ll  sum =0;
    string n;
    cin>>n;

    for (int i = 0; i < n.length(); i++)
        sum =sum + n[i] - '0';
    if (sum%9==0)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout << "No" << endl;
    }   
}

Measured memory_bytes: 3704
#include<iostream>
using namespace std;
int main(){
  int array[10],tmp;
  for(int i = 0;i<10;i++)
    cin >> array[i];
  for(int i=0;i<10;i++){
    for(int k=0;k<9;k++){
      if(array[k] < array[k+1]){
	tmp = array[k]; array[k] = array[k+1]; array[k+1] = tmp;
      }
    }
  }
  for(int i =0 ;i< 3;i++){
    cout << array[i] << endl;
} 
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ll  long long

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, "\e[31;1m"); fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\e[0m")
#else
    #define eprintf(...) 42
#endif

ll solve(ll N, ll X, std::vector<ll>& A)
{
    int m = 0;
    ll a = 0;
    for (int i = 0; i < N; i++)
    {
        int k = std::max(0LL, m + A[i] - X);
        a += k;
        m = A[i] - k;
    }
    return a;
}

int main(void)
{
    ll N, X;
    std::cin >> N >> X;

    std::vector<ll> A(N);
    for (int i = 0; i < N; i++)
    {
        std::cin >> A[i];
    }
    std::cout << solve(N, X, A) << std::endl;

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int main()
{
	int n;
	while (cin>>n)
	{
		int combo = 0;
		for (int a=0;a<10;++a)
		{
			for (int b=0;b<10;++b)
		{
			for (int c=0;c<10;++c)
		{
			for (int d=0;d<10;++d)
			{
				if(a+b+c+d==n)
					++combo;
			}
			}
			}
		}
		cout<<combo<<endl;
	}
	return 0;

}

Measured memory_bytes: 1160
#include <cstdio>

int main(){
	int a[8];
	for(int i = 0; i < 8; i++){
		scanf("%d",&a[i]);
	}
	int h,k;
	h = a[0]*a[4]+a[0]/10*a[6] + a[1]*a[5] + a[1]/20*a[7];
	k = a[2]*a[4]+a[2]/10*a[6] + a[3]*a[5] + a[3]/20*a[7];
	printf("%s\n", h == k ? "even" : h > k ? "hiroshi" : "kenjiro");
	return 0;
}

Measured memory_bytes: 2668
#include<stdio.h>
#include<cstring>

bool isOk(char s[100]){
  int a;
  sscanf(s,"%d",&a);
  if(s[0]=='0'){
    if(s[1]=='\0')
      return true;
    else
      return false;
  }
  if(0<=a&&a<=255)
    return true;
  else
    return false;
}

bool judge(char s[100],int i,int j,int k){
  char s1[4][100]={};
  int ind;
  int m[4]={};
  int n=strlen(s);
  for(ind=0;ind<n;ind++){
    if(ind<i){
      s1[0][m[0]]=s[ind];
      m[0]++;
    }
    else if(ind<j){
      s1[1][m[1]]=s[ind];
      m[1]++;
    }
    else if(ind<k){
      s1[2][m[2]]=s[ind];
      m[2]++;
    }
    else{
      s1[3][m[3]]=s[ind];
      m[3]++;
    }
  }
  if(!isOk(s1[0]))return false;
  if(!isOk(s1[1]))return false;
  if(!isOk(s1[2]))return false;
  if(!isOk(s1[3]))return false;
  return true;
}

int main(){
  char s[100];
  scanf("%s",s);
  int len=strlen(s);
  int i,j,k;
  int sum=0;
  for(i=1;i<len-2;i++)
    for(j=i+1;j<len-1;j++)
      for(k=j+1;k<len;k++){
        if(judge(s,i,j,k))
          sum++;
      }
  printf("%d\n",sum);
}



Measured memory_bytes: 2768
import math

A, B, H, M = list(map(int, input().split()))
pi = 3.141592653589793
angle_M = M * pi / 30
angle_H = H * pi / 6 + angle_M / 12
angle = abs(angle_H - angle_M)
angle = min(angle, 2 * pi - angle)
print(math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(angle)))


Measured memory_bytes: 9524
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int a = x/1000;
		int b = x/100 -a*10;
		int c = x/10 -a*100 - b*10;
		int d = x-a*1000-b*100-c*10;

		if(a+b+c+d==7)
			System.out.print(a+"+"+b+"+"+c+"+"+d+"=7");
		else {
			if(a+b+c-d==7)
				System.out.print(a+"+"+b+"+"+c+"-"+d+"=7");
			else {
				if(a+b-c+d==7)
					System.out.print(a+"+"+b+"-"+c+"+"+d+"=7");
				else {
					if(a-b+c+d==7)
						System.out.print(a+"-"+b+"+"+c+"+"+d+"=7");
					else {
						if(a+b-c-d==7)
							System.out.print(a+"+"+b+"-"+c+"-"+d+"=7");
						else {
							if(a-b+c-d==7)
								System.out.print(a+"-"+b+"+"+c+"-"+d+"=7");
							else {
								if(a-b-c+d==7)
									System.out.print(a+"-"+b+"-"+c+"+"+d+"=7");
								else
									System.out.print(a+"-"+b+"-"+c+"-"+d+"=7");
							}
						}
					}
				}
			}
		}
	}

}


Measured memory_bytes: 23764
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input!{
      s: chars,
    }


    let mut g = 0;
    let mut p = 0;
    let mut ans = 0;
    for c in s {
        if c == 'p' {
            if p < g {
                p += 1;
            } else {
                g += 1;
                ans -= 1;
            }
        } else {
            if p < g {
                p += 1;
                ans += 1;
            } else {
                g += 1;
            }
        }
    }
    puts!("{}\n", ans);
}


Measured memory_bytes: 4352
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
int main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<P> v(a + b + c);
  rep(i, a) {
    int p;
    cin >> p;
    v[i] = make_pair(p, 0);
  }
  rep(i, b) {
    int q;
    cin >> q;
    v[a + i] = make_pair(q, 1);
  }
  rep(i, c) {
    int r;
    cin >> r;
    v[a + b + i] = make_pair(r, 2);
  }
  sort(all(v));
  reverse(all(v));
  int cnt[3] = {0, 0, 0};
  int n = v.size();
  ll ans = 0;
  rep(i, n) {
    if(0 == v[i].second && x == cnt[0]) continue;
    if(1 == v[i].second && y == cnt[1]) continue;
    ++cnt[v[i].second];
    ans += (ll)v[i].first;
    if(cnt[0] + cnt[1] + cnt[2] >= x + y) break;
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
  	long long int N, M, X;
  	cin >> N >> M >> X;
  	long long int C[N], A[N][M];
  	for (int i = 0; i < N; i++){
      	cin >> C[i];
      	for (int j = 0; j < M; j++){
          	cin >> A[i][j];
        }
    }
  
  	int n = N;
  	int res = 10000000;
  
  	for (int bit = 0; bit < (1<<n); ++bit) {
        vector<int> S;
      	int count[M];
      	for (int i = 0; i < M; i++) count[i] = 0;
      	int count2 = 0;
        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i)) {
                S.push_back(i);
            }
        }

        for (int i = 0; i < (int)S.size(); ++i) {
          	for (int j = 0; j < M; j++){
              	count[j] += A[S[i]][j];
            }
          	count2 += C[S[i]];
        }
      	bool flag = true;
      	for (int i = 0; i < M; i++) if (X > count[i]) flag = false;
      	if (flag == true) res = min(count2, res);
    }
  
  	if (res != 10000000) cout << res << endl;
  	else cout << -1 << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int n;
int v[100010];
int a[100010], b[100010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    if (i % 2 == 0) a[v[i]]++;
    else b[v[i]]++;
  }  
  vector<pii> va, vb;
  for (int i = 0; i < 100010; i++) {
    va.emplace_back(a[i], i);
    vb.emplace_back(b[i], i);
  }
  sort(va.rbegin(), va.rend());
  sort(vb.rbegin(), vb.rend());
  int na = n - n % 2, nb = n % 2;
  if (va[0].second != vb[0].second) {
    cout << (na - va[0].first) + (nb - vb[0].first) << endl;
  } else {
    cout << min((na - va[0].first) + (nb - vb[1].first), (na - va[1].first) + (nb - vb[0].first)) << endl;
  }

  return 0;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  int cntl=0, cntr=0;
  vector<pair<int, int>> pp, pm, mp, mm;
  rep(i, N) {
    int diffMin=0, diffAll=0;
    cin >> S[i];
    for(char c: S[i]) {
      if(c == '(') {
        cntl++;
        diffAll++;
      } else {
        cntr++;
        diffAll--;
      }
      diffMin = min(diffAll, diffMin);
    }
    if(diffAll >= 0) {
      if(diffMin >= 0) pp.emplace_back(diffMin, diffAll);
      else             pm.emplace_back(diffMin, diffAll);
    } else {
      diffMin -= diffAll;
      diffAll *= -1;
      if(diffMin >= 0) mp.emplace_back(diffMin, diffAll);
      else             mm.emplace_back(diffMin, diffAll);
    }
  }

  if(cntl != cntr) {
    cout << "No" << endl;
    return 0;
  }

  {
    ll tmp = 0;
    for(auto p: pp) tmp += p.second;
    sort(all(pm), greater<pair<int, int>>());
    for(auto p: pm) {
      if(tmp + p.first < 0) {
        cout << "No" << endl;
        return 0;
      }
      tmp += p.second;
    }
  }
  {
    ll tmp = 0;
    for(auto p: mp) tmp += p.second;
    sort(all(mm), greater<pair<int, int>>());
    for(auto p: mm) {
      if(tmp + p.first < 0) {
        cout << "No" << endl;
        return 0;
      }
      tmp += p.second;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 42520
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(void){
    int n;
    cin>>n;
    if(n%10==3){
        cout<<"bon"<<endl;
    }else if(n%10==1||n%10==0||n%10==6||n%10==8){
        cout<<"pon"<<endl;
    }else{
        cout<<"hon"<<endl;
    }
    
    
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

typedef long long ll;

const int MAXN = 200005;

int n,k,top,ans;
int a[MAXN];
int S[MAXN];

bool ok[MAXN];
bool instack[MAXN];

int main()
{
	scanf("%d%d",&n,&k);
	for (int i = 1;i <= n;i++)
	{
		scanf("%d",&a[i]);
		a[i]++;
		if (i + k <= n)
			ok[i] = 1;
	}
	int cnt = 0,cnt2 = 0;
	for (int i = 1;i < n;i++)
	{
		if (a[i] < a[i + 1])
			cnt++;
		else
		{
			if (cnt >= k - 1)
				cnt2++;
			cnt = 0;
		}
	}
	if (cnt >= k - 1)
		cnt2++;
	top = 0;
	for (int i = 1;i <= n;i++)
	{
		while (top >= 1 && a[S[top]] > a[i])
			instack[S[top--]] = 0;
		instack[S[++top] = i] = 1;
		if (i - k >= 1 && !instack[i - k])
			ok[i - k] = 0;
	}
	top = 0;
	memset(instack,0,sizeof(instack));
	for (int i = n;i >= 1;i--)
	{
		while (top >= 1 && a[S[top]] < a[i])
			instack[S[top--]] = 0;
		instack[S[++top] = i] = 1;
		if (i + k <= n && !instack[i + k])
			ok[i] = 0;
	}
	ans = n - k + 1;
	for (int i = 1;i <= n;i++)
		ans -= ok[i];
	printf("%d\n",ans + 1 - cnt2 - (!cnt2));
	return 0;
}

Measured memory_bytes: 2176
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

H, W, D = mapint()
As = [list(mapint()) for _ in range(H)]

points = [0]*(H*W)
for i in range(H):
    for j in range(W):
        points[As[i][j]-1] = (i, j)
from collections import defaultdict
from itertools import accumulate
dic = defaultdict(list)

for i in range(1, D+1):
    h, w = points[i-1]
    cnt = 0
    while i+cnt*D<=H*W:
        h2, w2 = points[i+cnt*D-1]
        dic[i].append(abs(h2-h)+abs(w2-w))
        h, w = h2, w2
        cnt += 1
    dic[i] = list(accumulate(dic[i]))

Q = int(input())
for _ in range(Q):
    L, R = mapint()
    base = L%D
    if base==0:
        base = D
    l = (L-base)//D
    r = (R-base)//D
    print(dic[base][r]-dic[base][l])

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

#define ll long long
#define ld long double
#define ii pair<int ,int >
#define S second
#define F first
#define PI 3.1415926535897932384626
#define SPEED std::ios_base::sync_with_stdio(false);
const int N = 1e5+7;
int n,w[107],W;
ll v[107],mem[107][N];

ll dp(int i,int weight){
    if(i==n)return 0;

    ll &ret = mem[i][weight];
    if(ret != -1)return ret;

    ll p1=0,p2=0;

    if(w[i]+weight<=W){
        p1 = v[i]+dp(i+1,weight+w[i]);
    }
    p2 = dp(i+1,weight);

    return ret = max(p1,p2);

}

int main(){
    SPEED
    scanf("%d%d",&n,&W);
    for(int i=0;i<n;i++){
        scanf("%d%d",&w[i],&v[i]);
    }
    memset(mem,-1,sizeof mem);
    printf("%lld",dp(0,0));

}


Measured memory_bytes: 83840
using System;

class Problem
{
  public static void Main()
  {
    var inputs = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    int A = inputs[0], B = inputs[1], C = inputs[2], D = inputs[3];
    var start = Math.Max(A, C);
    var end = Math.Min(B, D);
    Console.WriteLine($"{Math.Max(0, end - start)}");
  }
}


Measured memory_bytes: 13268
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef unsigned long long ul;
int r, s, p;
int d[1 << 20];
int main() {
	cin >> r >> s >> p;
	rep(i,p){
		int x, y; cin >> x >> y; x--; y--;
		int dis = 0; dis += r - x;
		if (y < s) {
			dis += s - y;
		}
		else {
			dis += y - s + 1;
		}
		d[dis]++;
		//cout << dis << endl;
	}
	rep(i, (1 << 20)) {
		if (d[i]>1) {
			d[i + 1] += d[i] - 1; d[i] = 1;
		}
	}
	int out = 0;
	rep(i, 1 << 20) {
		if (d[i])out = i;
	}
	cout << out << endl;
	return 0;
}



Measured memory_bytes: 5020
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
typedef long long int ll;
typedef long double ld;
using namespace std;

vvl G = vv(100001, 0, 0, ll);
vll toa(100001), tob(100001), ans(100001, 0);
void dfs(ll now, ll from, ll d, ll mode){
  (mode==0?toa[now]:tob[now]) = d;
  for(int i=0;i<G[now].size();i++){
    if(G[now][i]==from) continue;
    dfs(G[now][i], now, d+1, mode);
  }
}

void check(ll now, ll from){
  if(toa[now]>tob[now]) return;
  if(toa[now]==tob[now]) {
    ans[now] = toa[now];
    return;
  }
  ans[now] = (G[now].size()==1?tob[now] - 1:tob[now]);
  for(int i=0;i<G[now].size();i++){
    if(G[now][i]==from) continue;
    check(G[now][i], now);
  }
}
int main(int argc, char const *argv[]) {
  ll x, y, n, a, b;std::cin >> n >> a >> b;
  re(i, n-1){
    std::cin >> x >> y;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  dfs(a, -1, 0, 0);
  dfs(b, -1, 0, 1);
  check(a, -1);
  ll t=0;
  for(int i=1;i<=n;i++) t = max(t, ans[i]);
  std::cout << t << '\n';
  return 0;
}


Measured memory_bytes: 13312
#include<iostream>
#include<complex>
using namespace std;
#define R real()
#define I imag() 
int n,q;
int x[51],y[51],z[51],r[51],sx,sy,sz,dx,dy,dz;
long long l[51],an;
bool check(int i){
  complex<double>s,t;
  s.R=x[i]-sx, s.I=y[i]-sy;
  t.R=dx-sx, t.I=dy-sy;
  s*=conj(t),s/=abs(t);
  t.R=abs(t);
  double ay=s.I,nd;
  t.I=dz-sz;
  s.I=z[i]-sz;
  nd=abs(t);
  s*=conj(t),s/=nd;
  if(0<=s.R&&s.R<=nd&&ay*ay+s.I*s.I<=r[i]*r[i])return true;
  if(min(ay*ay+s.I*s.I+s.R*s.R,ay*ay+s.I*s.I+(s.R-nd)*(s.R-nd))<=r[i]*r[i])return true;
  return false;
  }
int main(){
  cin>>n>>q;
  for(int i=0;i<n;i++)cin>>x[i]>>y[i]>>z[i]>>r[i]>>l[i];
  for(int i=0;i<q;i++){
    cin>>sx>>sy>>sz>>dx>>dy>>dz;
    an=0;
    for(int j=0;j<n;j++)if(check(j))an+=l[j];
    cout<<an<<endl;
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

#define mt make_tuple
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sqr(x) ((ll)(x) * (x))

int main()
{
    int n;
    cin >> n;
    vi v(n), dp(n);
    for(auto &z : v)cin >> z;

    dp[0] = 0;
    dp[1] = abs(v[0] - v[1]);

    for(int i = 2; i < n; i++)
    {
        dp[i] = min(dp[i - 2] + abs(v[i-2] - v[i]), dp[i - 1] + abs(v[i-1]-v[i]));
    }

    cout << dp[n - 1] << '\n';

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb push_back
#define sc second
#define fr first
#define mk make_pair
#define ll long long
#define ii pair<intt,intt>
#define mp make_pair
typedef long long intt;
using namespace std;
int main()
{
    int n;
    cin>>n;
    intt a[n];
    int i;
    for(i=0;i<n;i++)
        cin>>a[i];
        intt mn=1e18;
    for(i=0;i<=100;i++)
    {
        int j;
        intt ans=0;
        for(j=0;j<n;j++)
        {
            ans+=(abs(a[j]-i)*abs(a[j]-i));
        }
        mn=min(mn,ans);
    }
    cout<<mn<<endl;
      return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define INF 1e9
#define all(v) v.begin(), v.end()
typedef long long ll;

int main(){
  int n;
  cin >> n;
  vector<int> v(n), c(n);
  rep(i, n) cin >> v[i];
  rep(i, n) cin >> c[i];

  int ans = - INF;
  rep(tmp, 1<<n){
    bitset<20> s(tmp);
    int x = 0;
    int y = 0;
    rep(i, n){
      if(s.test(i)){
        x += v[i];
        y += c[i];
      }
    }
    ans = max(ans, x-y);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
#define MAX_H 10000
#define MAX_A 10000
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;

int ceil(int x, int y) { return (x % y == 0) ? x / y : x / y + 1; }

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }

int lcm(int x, int y) { return x / gcd(x, y) * y; }

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

  int h, n;
  cin >> h >> n;
  vector< int > a(n), b(n);
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    cin >> b[i];
  }

  int dp[MAX_H + MAX_A + 1];
  fill(dp, dp + MAX_H + MAX_A + 1, INF_INT);

  dp[0] = 0;
  for(int i = 1; i <= MAX_H + MAX_A; i++) {
    for(int j = 0; j < n; j++) {
      if(i - a[j] >= 0) {
        dp[i] = min(dp[i], dp[i - a[j]] + b[j]);
      }
    }
  }

  int ans = INF_INT;
  for(int i = h; i <= h + MAX_A; i++) {
    ans = min(ans, dp[i]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3688
#include<stdio.h>
int main()
{
	int n, i;
	char a[5];
	scanf("%s", a);
	for (i=0, n=0; i<strlen(a); i++)
	{
		if (a[i]=='+')
		{
			n++;
		}
		else if (a[i]=='-')
		{
			n--;
		}
	}
	printf("%d\n", n);
	return 0;
}

Measured memory_bytes: 128
import math

class vector():

    def __init__(self, x):
        self.x = x

def minkowski_p(x, y, p):
    s = 0

    for xi, yi in zip(x, y):
        s += abs(xi - yi) ** p

    s = s ** (1 / p)

    return s

def minkowski_infty(x, y):
    return max([abs(xi - yi) for xi, yi in zip(x, y)])

_ = int(input())
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]

print(minkowski_p(x, y, 1))
print(minkowski_p(x, y, 2))
print(minkowski_p(x, y, 3))
print(minkowski_infty(x, y))


Measured memory_bytes: 5704
class CombinationFermat:

    def __init__(self):
        """O(MAX)で前計算しておく→以降comb(a,b)はO(1)で取得可能
        """
        MOD = 10**9 + 7
        MAX = 2*10**5

        self.fac = [0]*MAX   # self.fac[n]:  (n!) mod p
        self.finv = [0]*MAX  # self.finv[n]: (n!)^-1 mod p
        self.inv = [0]*MAX   # inv[n]:  (n)^-1 mod -p
        self.fac[0] = self.fac[1] = 1
        self.finv[0] = self.finv[1] = 1
        self.inv[1] = 1
        for i in range(2, MAX):
            self.fac[i] = self.fac[i-1] * i % MOD
            self.inv[i] = MOD - self.inv[MOD % i] * (MOD//i) % MOD
            self.finv[i] = self.finv[i-1] * self.inv[i] % MOD

    def comb(self, n: int, r: int) -> int:
        MOD = 10**9 + 7
        if n < r:
            return 0
        if n < 0 or r < 0:
            return 0
        return self.fac[n] * (self.finv[r] * self.finv[n-r] % MOD) % MOD


H, W, A, B = map(int, input().split())
c = CombinationFermat()
ans = 0
MOD = 10**9 + 7

for i in range(H-A):
    x = c.comb(B-1+i, i)
    a = H-1-i
    b = W-1-B
    x *= c.comb(a+b, a)
    x %= MOD
    ans += x
ans %= MOD
print(ans)


Measured memory_bytes: 26740
import scala.io.StdIn._
import scala.collection._

object Main {

  class Sieve(val n: Int){
    private[this] val top = (n - 3) / 2 + 1
    private[this] val sqrtLimit = (Math.sqrt(n).toInt - 3) / 2

    private[this] val cmpsts = new Array[Int]((top >>> 5) + 1)
    def isPrime(ci: Int): Boolean = (cmpsts(ci >>> 5) & (1 << (ci & 31))) == 0
    def notPrime(ci: Int): Unit = cmpsts(ci >>> 5) |= 1 << (ci & 31)

    def next(i: Int): Int = if((i > top) || isPrime(i)) 2 * i + 3 else next(i + 1)

    def exec: Iterator[Int] = {

      for{
        i <- 0 to sqrtLimit
        if isPrime(i)
        p = 2 * i + 3
        j <- Range((p * p - 3)/2, top, p)
      } notPrime(j)

      if(n==2)Iterator.single(2)
      else Iterator.single(2) ++ Iterator.iterate(3)(p => next((p - 1) / 2)).takeWhile(_ <= n)
    }
  }

  def loop(s: String){
    if(s != null){
       val Array(n,_*) = s.split(" ").map(_.toInt)
       if(n<2) println(0)
       else println(new Sieve(n).exec.size)
       loop(readLine)
    }
  }

  def main(args: Array[String]): Unit = loop(readLine)
}

Measured memory_bytes: 68536
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "

int main(){
    int r,g,b,n;cin>>r>>g>>b>>n;
    int rmax=n/r,gmax=n/g;
    ll ans = 0;
    for(int i=0;i<=rmax;i++){
        for(int j=0;j<=gmax;j++){
            if((n-r*i-g*j)>=0&&((n-r*i-g*j)%b==0))ans++;
        }
    }
    co(ans);
}


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


int main() {
    string a[3];
    cin >> a[0] >> a[1] >> a[2];
    cout << 'A' << a[1][0] << 'C' << endl;
  
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <set>
using namespace std;
int main(){
    long long n;
    cin >> n;
    long long ans=0;
    multiset<long long> s;
    long long num;
    for(long long i=0;i<n;i++){
        long long x;
        cin >> x;
        s.insert(x);
    }
    
    while(s.size()>0){
        multiset<long long>::reverse_iterator i = s.rbegin();
        num = *i;
        long long y = 1;
        while(num>=y){
            y=y*2;
            if(y>num){
                auto itrx = s.find(num);
                if(itrx != s.end()){
                    s.erase(itrx);
                }
                if(s.count(y-num)>0){
                    ans++;
                    auto itry = s.find(y-num);
                    if(itry != s.end()){
                        s.erase(itry);
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 9600
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;
ll const N_MAX = 3010;
ll dp[N_MAX][N_MAX];

ll solve(ll l, ll r, vector<ll>& a) {
  if (dp[l][r] != -INF) {
    return dp[l][r];
  }
  if (l == r) return dp[l][r] = a[l];
  return dp[l][r] = max(a[l] - solve(l + 1, r, a), a[r] - solve(l, r - 1, a));
}

int main() {
  ll N;
  cin >> N;
  vector<ll> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < N_MAX; i++) {
    for (int j = 0; j < N_MAX; j++) {
      dp[i][j] = -INF;
    }
  }
  ll ans = solve(0, N - 1, a);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 71296
#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 <unordered_set>

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)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  string s;
  cin >> s;
  int n=s.size();
  ll ans=0;
  string prev="";
  for(int i=0;i<n;i++){
    if(i>=n-5){
      bool flag=true;
      if(i!=n-5)flag=false;
      for(int j=i;j<n;j++){
        if(s[j]!=s[i])flag=false;
      }
      if(flag){
        ans+=3;
        break;
      }
    }
    string temp="";
    temp+=s[i];
    if(temp==prev && i+1<n){
      temp+=s[i+1];
      i++;
    }
    else if(temp==prev){
      break;
    }
    ans++;
    prev=temp;
//    cout << i << ' ' << prev << ' ' << ans << endl;
  }
  
  cout << ans << endl;
return 0;}

Measured memory_bytes: 640
using System;

class MainClass
{
    public static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var count = 0;
        for (var i = 0; i < n; i++)
        {
            var num = int.Parse(Console.ReadLine());
            if (IsPrime(num)) count++;
        }
        Console.WriteLine("{0}", count);
    }

    static bool IsPrime(int n)
    {
        if (n < 2) return false;
        for (var i = 2; i * i <= n; i++)
        {
            if (n % i == 0) return false;
        }
        return true;
    }
}


Measured memory_bytes: 9216
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())

ans = 0
for i in range(N):
    a = As[i]
    if a%2==1 and (i+1)%2==1:
        ans += 1

print(ans)

Measured memory_bytes: 9160
import java.awt.geom.Point2D;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt(); // 要素の個数
		Point2D.Double p1 = new Point2D.Double();
		Point2D.Double p2 = new Point2D.Double();
		p1.setLocation(0, 0);
		p2.setLocation(100, 0);
		System.out.println(p1.getX() + " " + p1.getY());
		kock(n, p1, p2);
		System.out.println(p2.getX() + " " + p2.getY());
	}

	/**
	 * コッホ曲線の各頂点座標を出力する
	 * @param n　	コッホ曲線の数
	 * @param p1　	始点座標
	 * @param p2　	終点座標
	 */
	public static void kock(int n, Point2D.Double p1, Point2D.Double p2) {
		if (n == 0) {
			return;
		}
		Point2D.Double s = new Point2D.Double();
		s.setLocation((2 * p1.x + 1 * p2.x) / 3, (2 * p1.y + 1 * p2.y) / 3);
		Point2D.Double t = new Point2D.Double();
		t.setLocation((1 * p1.x + 2 * p2.x) / 3, (1 * p1.y + 2 * p2.y) / 3);
		double u_x = (t.x - s.x) * Math.cos(60 * (Math.PI / 180)) - (t.y - s.y) * Math.sin(60 * (Math.PI / 180)) + s.x;
		double u_y = (t.x - s.x) * Math.sin(60 * (Math.PI / 180)) + (t.y - s.y) * Math.cos(60 * (Math.PI / 180)) + s.y;
		Point2D.Double u = new Point2D.Double();
		u.setLocation(u_x, u_y);

		kock(n - 1, p1, s);
		System.out.println(s.getX() + " " + s.getY());
		kock(n - 1, s, u);
		System.out.println(u.getX() + " " + u.getY());
		kock(n - 1, u, t);
		System.out.println(t.getX() + " " + t.getY());
		kock(n - 1, t, p2);

	}
}



Measured memory_bytes: 31932
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define nl cout<<endl
 
#define pii pair<ll,ll>
#define vi  vector<ll>
#define vii vector<pii>
#define mi  map<ll,ll>
#define all(a)  (a).begin(),(a).end()

#define pb push_back
#define ff first
#define ss second
#define mod 1000000007

#define yes cout<<"Yes"<<endl;
#define no cout<<"No"<<endl;
#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;

int main(){
	ios_base::sync_with_stdio(false);
     	cin.tie(NULL);
    	cout.tie(NULL);    
    ll n,k;cin>>n>>k;
    ll ar[k];
    rep(i,0,n){
        cin>>ar[i];
    }
    ll total=0;
    ll s=0;
    rep(i,1,k){
        if(total< ar[i]-ar[i-1] ){
           s=i;
           total= ar[i]-ar[i-1];
        }
    }
    if(ar[0]==0){
        if(total< n-ar[k-1]){
            s=1;
            total= n-ar[k-1];
        }
    }else{
        if(total< n-ar[k-1]+ar[0]){
            s=1;
            total= n-ar[k-1]+ar[0];
        }
    }
    ll h=0;
    rep(i,1,k){
        h+= ar[i]-ar[i-1];
    }
    // ll ans=0;
    // for(i,0,k){
        
    // }
//     ll ans=0;
//     rep(i,s,k-1){
//         ans+= ar[i+1]-ar[i];
//     }
//     ans+= n-ar[k-1];
//   // test1(ans);
//     rep(i,0,s-1){
//         ans+= ar[i+1]-ar[i];
//     }
    //cout<<total<<" "<<s<<" "<<ans<<endl;
    cout<<min(h , n-total)<<endl;
    
    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
void ssort(int*, int);
main()
{
    int *a, n, i;
    scanf("%d", &n);
    a = (int*)malloc(sizeof(int) * n);
    for(i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    ssort(a, n);
    for(i = 0; i < n; i++){
        printf("%d\n", a[i]);
    }
    free(a);
}
void ssort(int *a, int n)
{
    int i,j, temp, gap[100] = {1}, size = 0, cnt = 0;
    do{
        gap[size + 1] = gap[size] * 3 + 1;
        size++;
    }while(gap[size] < n);
    printf("%d\n", size);
    for(i = size - 1; i >= 1; i--){
        printf("%d ", gap[i]);
    }
    printf("%d\n", gap[i]);
    do{
        size--;
        for(i = gap[size]; i < n; i++){
            temp = a[i];
            j = i - gap[size];
            while(j >= 0 && a[j] > temp){
                a[j + gap[size]] = a[j];
                j -= gap[size];
                cnt++;
            }
            a[j + gap[size]] = temp;
        }
    }while(size);
    printf("%d\n", cnt);
}

Measured memory_bytes: 5448
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int nax=1000*1007;

int n;
char wcz[nax];

int main()
{
	scanf("%s", wcz+1);
	n=strlen(wcz+1);
	for (int i=1; i<=n; i++)
	{
		if (wcz[i]=='A')
		{
			
		}
		if (wcz[i]=='B')
		{
			if (wcz[i+1]!='C')
				wcz[i]='G';
		}
		if (wcz[i]=='C')
		{
			if (wcz[i-1]!='B')
				wcz[i]='G';
		}
	}
	ll wyn=0;
	ll ile=0;
	for (int i=1; i<=n; i++)
	{
		if (wcz[i]=='A')
		{
			ile++;
		}
		if (wcz[i]=='B')
		{
			wyn+=ile;
		}
		if (wcz[i]=='G')
		{
			ile=0;
		}
	}
	printf("%lld\n", wyn);
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <stack>
using namespace std;
int main(int argc, char* argv[])
{
	string s;
	cin>>s;
	stack<char> st;
	int i=0;
	while (s[i]!='\0'){
		if (s[i]=='S'){
			st.push(s[i]);
		}else{
			if (st.empty()){
				st.push(s[i]);
			}else{
				if (st.top()=='S'){
					st.pop();
				}else{
					st.push(s[i]);
				}
			}
		}
		i++;
	}
	cout<<st.size()<<endl;

	return 0;
}

Measured memory_bytes: 644
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
import java.util.Scanner;

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

		int max = 0;
		for(int i = 0; i < q; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();

			max = Math.max(max, l[i]);
			max = Math.max(max, r[i]);
		}

		boolean[] pnums = new boolean[max+1];
		for(int i = 2; i <= max; i++) {
			if(pnums[i] != false);
			for(int j = i+i; j <= max; j+=i) {
				pnums[j] = true;
			}
		}

		int cnt = 0;
		int[] cnts = new int[max+1];
		cnts[0] = 1;
		cnts[1] = 1;
		for(int i = 2; i <= max; i++) {
			if( pnums[i] == false && pnums[(i+1)/2] == false )
				cnt++;
			cnts[i] = cnt;
		}

		for(int i = 0; i < q; i++) {
			System.out.println(cnts[r[i]] - cnts[l[i]-1]);
		}
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


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

int main() {
  int n,m; cin>>n>>m;
  priority_queue<int> a;
  rep(i, n) {
    int x;
    cin>>x;
    a.push(x);
  }

  int cnt = m;
  while (cnt > 0) {
    int tmp = a.top()/2;
    a.pop();
    a.push(tmp);
    cnt--;
  }
  ll sum=0;
  while (!a.empty()) {
    sum+=a.top();
    a.pop();
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 892