akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define Rep(i,s,f) for(int i=(int)s;i<(int)f;i++)
using ll=long long;
using namespace std;


int main()
{
	int N,M;
	cin>>N>>M;
	vector<bool> boll(N,false);
	vector<ll> boll_cnt(N,1);
	boll[0]=true;
	rep(i,M)
	{
		int x,y;
		cin>>x>>y;
		x--;y--;
		if(boll[x])
		{
			boll[y]=true;
		}	
		boll_cnt[y]++;
		if(boll_cnt[x]==1) 
		{
			boll[x]=false;
		}
		boll_cnt[x]--;
	}
	ll ans=0;
	rep(i,N)
	{
		if(boll[i]) ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3988
#include <bits/stdc++.h>
#include <string>
#include <sstream>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define clr(a) memset(a, 0, sizeof(a))
#define set(a) memset(a, -1, sizeof(a))
#define pb push_back
#define sz(a) ((ll)a.size())
#define all(a) a.begin(), a.end()
#define mp make_pair
#define rep(i, a, y) for (ll i = a; i <= y; i++)
#define rep2(i, b) for (ll i = 0; i < b; i++)
#define repl(i, a, b) for (ll i = a; i <= b; i++)
#define ppi pair<int, int>
#define scl(x) scanf("%d", &x)
#define pcl(x) printf("%d", x)
#define FastRead                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0)
/*
 
     ██╗██╗   ██╗██╗  ██╗ █████╗ ███╗   ██╗
     ██║██║   ██║██║  ██║██╔══██╗████╗  ██║
     ██║██║   ██║███████║███████║██╔██╗ ██║
██   ██║██║   ██║██╔══██║██╔══██║██║╚██╗██║
╚█████╔╝╚██████╔╝██║  ██║██║  ██║██║ ╚████║
 ╚════╝  ╚═════╝ ╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═══╝
 
*/
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int x=(a+d-1)/d;
    int y=(b+c-1)/b;
    if(x>=y) cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll, ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define pdd pair<double, double>
#define f first
#define s second
#define MOD 1000000007
#define mkp make_pair
#define M_PI 3.14159265358979323846
#define FOR(i,l,r) for (int i=l;i<=r;i++)
#define LOR(i,l,r) for (ll i=l;i<=r;i++)
#define FORD(i,r,l) for (int i=r;i>=l;i--)
#define LORD(i,r,l) for (ll i=r;i>=l;i--)
#define INF 1000000000
#define CL(x) memset(x,0,sizeof(x))
#define DEB(x) cout << #x << " : " << x << '\n'
#define ALL(x) x.begin(), x.end()
#define SZ(x) x.size()
#define UI(x) (int)(x-'A')
#define LI(x) (int)(x-'a')
typedef long long ll;

#define MXN 100005
int N;
string str[MXN];
map< pil, ll > cnt;
ll ans;

pil cnvt(string& st)
{
    pil rtn = mkp(0,0);
    ll cn[26] = {};
    for( char ch : st )
    {
        rtn.f |= (1<<(ch-'a'));
        cn[ ch-'a' ]++;
    }
    ll po=1;
    FOR(i,0,25)if( cn[i] )
    {
        rtn.s+=cn[i]*po;
        po*=11;
    }
    return rtn;
}

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

    cin>>N;
    FOR(i,1,N)cin>>str[i];
    pil id;
    FOR(i,1,N)
    {
        id = cnvt(str[i]);
        ans += cnt[id];
        cnt[id]++;
    }
    cout<<ans<<'\n';

    return 0;
}



Measured memory_bytes: 12032
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ld long double
#define f first
#define mt make_tuple
#define s second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define time_bata cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
#define pb push_back
#define ppb pop_back
#define ppf pop_front
#define vec std::vector<int > v;
#define eps 1e-7
#define endl "\n"
#define mp make_pair
#define p_q priority queue


#define dbg(x) cout<<"#x"<<" = "<<x<<endl
#define dbg2(x,y) cout<<"#x"<<" = "<<x<<", "<<#y<<" = "<<y<<endl
#define dbg3(x,y,z) cout<<"#x"<<" = "<<x<<", "<<#y<<" = "<<y<<", "<<#z<<" = "<<z<<endl
#define dbg4(x,y,z,q) cout<<"#x"<<" = "<<x<<", "<<#y<<" = "<<y<<", "<<#z<<" = "<<z<<", "<<#q<<" = "<<q<<endl


#define FOR(i,n) for(int i=0;i<n;i++)
#define FOR_(i,a,b) for(int i=a;i<=b;i++)

using namespace std;
     
bool cmp(pair<ll,ll>a,pair<ll,ll>b){
    return a.f<b.f;
}


bool check(int a){
    int sum=0;
    while(a>0){
        sum+=(a%10);
        a/=10;
    }
    if(sum==10) return true;
    return false;
}
void solve()
{
   int n;
   cin>>n;
   string s[2];
   cin>>s[0]>>s[1];
   int row=0,i;
   for(i=0;i<n;i++)
   {
    if(s[row][i]>='3')
    {
        if(s[row^1][i]<'3')
        {
            break;
        }
        else
        {
            row=row^1;
        }
    }
   }
   if(row==1 && i==n)
   {
    cout<<"YES"<<endl;
   }
   else
   {
    cout<<"NO"<<endl;
   }
}
ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    else if (y % 2 == 0) 
        return power(x, y / 2) * power(x, y / 2); 
    else
        return x * power(x, y / 2) * power(x, y / 2); 
} 

int main()
{
  



        
    fast;
    int t=1,x;
     // cin>>t;
   
    while(t--)
    {

        int n,x;
        cin>>n;
        vector< pair<int ,int > > v;
        for(int i=0;i<n;i++)
        {
            cin>>x;
            v.push_back({x,i});
        }
        int pos=0,ans=0;
        sort(v.begin(),v.end(),cmp);
       for(auto it:v)
       {
        if(it.s%2!=pos%2)
        {
            ans++;
        }
        pos++;
       }
       cout<<ans/2<<endl;
    }
    
    time_bata;
    return 0; 
  
}

Measured memory_bytes: 1400
n,k = gets.split.map &:to_i
a = gets.split.map &:to_i

#kは最大数
#f(X) = (X ^ a[0]) + (X ^ a[0]) ...

#ビットごとにやる
#上位からやっていく
#ビットごとに1を入れたときにkを超えるなら入れない
target = 0
sum = 0
l = [k.bit_length, a.max.bit_length].max
l.times do |i|
    t = l - i - 1

    m = 2 ** (t)

    count0 = a.count{|ai|ai[t] == 0}
    count1 = a.count{|ai|ai[t] == 1}

    if count0 < count1
        sum += m * count1
    else
        #count0を採用したいときにtargetの合計がkを超えるとダメ
        if target + m > k
            sum += m * count1
        else
            sum += m * count0
            target += m
        end
    end
end

puts sum


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

X = [[0]*N for _ in range(N)] 
for _ in range(M):
    l, r = map(int, input().split())
    X[l-1][r-1] += 1

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

ans = []
for _ in range(Q):
    p, q = map(int, input().split())
    p -= 1
    q -= 1
    num = 0
    for k in range(p, q+1):
        knum = X[k][q] - X[k][p-1] if p>=1 else X[k][q]
        num += knum
    ans.append(num)

print('\n'.join(map(str, ans)))

Measured memory_bytes: 92224
N,M = map(int,input().split())
H = list(map(int,input().split()))
AB = [set() for i in range(N)]
for i in range(M):
    A,B = map(int,input().split())
    AB[A-1].add(B-1)
    AB[B-1].add(A-1)
ans = 0
for i in range(N):
    res = True
    for x in AB[i]:
        if H[i]<=H[x]:
            res = False
            break
    if res:
        ans += 1
print(ans)

Measured memory_bytes: 45304
#define _USE_MATH_DEFINES
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	string A,B;
	cin>>A>>B;
	reverse(B.begin(),B.end());
	cout<<(A==B?"YES":"NO")<<endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAX 3003
#define inf 1<<29
#define linf 1e16
#define eps (1e-8)
#define mod 1000000007
#define pi acos(-1)
#define phi (1.0+sqrt(5))/2.0
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a)-1;(b)<=i;i--)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,double> pid;
typedef pair<double,int> pdi;
typedef vector<int> vi;
typedef vector<pii> vpi;
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

int n;
vector<pii> e[MAX]; 
int a[MAX],b[MAX];
string c[MAX];
bool used[MAX];

int dfs(int v){
  int res=1;
  used[v]=true;
  FOR(i,0,e[v].size()){
    int next=e[v][i].s;
    if(!used[next]){
      res+=dfs(next);
      break;
    }
  }
  return res;
}

int solve(){
  int res=0;
  FOR(i,0,n){
    FOR(j,0,n){
      if(i==j)continue;
      if(c[i]==">" && b[i]==b[j] && a[i]<a[j])e[i].pb(mp(a[j]-a[i],j));
      if(c[i]=="<" && b[i]==b[j] && a[j]<a[i])e[i].pb(mp(a[i]-a[j],j));
      if(c[i]=="v" && a[i]==a[j] && b[i]<b[j])e[i].pb(mp(b[j]-b[i],j));
      if(c[i]=="^" && a[i]==a[j] && b[j]<b[i])e[i].pb(mp(b[i]-b[j],j));
    }
    sort(all(e[i]));
  }
  FOR(i,0,n){
    fill(used,used+MAX,false);
    res=max(res,dfs(i));
  }
  return res;
}

int main()
{
  cin>>n;
  FOR(i,0,n)cin>>a[i]>>b[i]>>c[i];
  cout<<solve()<<endl;

  return 0;
}

Measured memory_bytes: 16536
#include<bits/stdc++.h>
#define int long long int
#define MP make_pair
#define PB push_back
#define F first
#define S second
using namespace std;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef vector<PII> VP;

int a, b, c, d, e, f;
signed main()
{
  cin >> a >> b >> c >> d >> e >> f;
  cout << a + b + c + d + e + f - min({a, b, c, d}) - min(e, f) << endl;
  return 0;
}

Measured memory_bytes: 3064
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
m = 0
d = -1.5
 
for i in range(n):
  m += b[a[i] - 1]
  if i > 0 and a[i] == a[i-1] + 1:
    m += c[a[i]-2]
  
print(m)

Measured memory_bytes: 3064
import java.util.*;

public class Main {

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

        int N = sc.nextInt();
        int L = sc.nextInt();
        
        int taste = 0;
        for (int i = 1; i <= N; i += 1) {
            taste += L + i - 1;
        }
        
        int i = 1 - L;
        if (i <= 1) {
            taste -= L;
        } else if (i >= N) {
            taste -= L + N - 1;
        }
        System.out.println(taste);
    }
}


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

using namespace std;

const int V = 1e3 + 3;

void printdp(vector<vector<long long>> & dp, int & N, int & MAXV){
	for(int v = 1; v <= 25; ++v){
		printf("%3llu", v);
	}
	printf("\n");
	for(int i = 1; i <= N; ++i){
		for(int v = 1; v <= 25; ++v){
			printf("%3llu", dp[i][v]);
		}
		printf("\n");
	}
	printf("\n");
}

int main(){
	ios_base::sync_with_stdio (false);
	cout << fixed;
	cout.precision(10);
	if(fopen("joke.in", "r")){
		freopen ("joke.in","r",stdin);
		freopen ("joke.out","w",stdout);
	}

	int N, W;
	cin >> N >> W;

	vector<long long> weight(N + 1), value(N + 1);

	int MAXV = 0;
	for(int i = 1; i <= N; ++i){
		cin >> weight[i] >> value[i];
		MAXV += value[i];
	}

	vector<vector<long long>> dp(N + 1, vector<long long>(MAXV + 1, 1e18));
	
	dp[1][value[1]] = weight[1];
	for(int v = value[1] - 1; v >= 1; --v){
		dp[1][v] = min(dp[1][v], dp[1][v + 1]); 
	}
	//printdp(dp, N, MAXV);

	
	for(int i = 2; i <= N; ++i){
		dp[i][value[i]] = min(dp[i][value[i]], weight[i]);
		for(int v = value[i] - 1; v >= 1; --v){
			dp[i][v] = min(dp[i][v], dp[i][v + 1]); 		
		}
		for(int v = 1; v <= MAXV; ++v){
			dp[i][v] = min(dp[i][v], dp[i - 1][v]);
			if(v - value[i] < 1) continue;
			dp[i][v] = min(dp[i][v], dp[i - 1][v - value[i]] + weight[i]);
		
		}
		//printdp(dp, N, W);
	}
	

	long long res = 0;
	for(long long v = MAXV; v >= 1; --v){
		if(dp[N][v] <= W){
			res = max(res, v);
		}
	}
	//printf("%llu", res);
	cout << res;
    return 0;
}

Measured memory_bytes: 80256
#include <iostream>
#include <vector>

using namespace std;

constexpr int kMaxN = 100000;

int p[kMaxN];
int bitarray[kMaxN] = {0};  // Used for comparing connected components
bool visited[kMaxN] = {false};

void DFS(const vector<vector<int>>& adj, int u, vector<int>& a,
         vector<int>& b) {
  if (visited[u]) return;
  visited[u] = true;
  a.push_back(u);
  b.push_back(p[u]);
  for (auto v : adj[u]) DFS(adj, v, a, b);
}

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

  for (int i = 0; i < N; ++i) {
    cin >> p[i];
    p[i]--;
  }
  vector<vector<int>> adj(N);
  int x, y;
  for (int i = 0; i < M; ++i) {
    cin >> x >> y;
    x--;
    y--;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }

  vector<int> a, b;
  auto Count = [&]() {
    int res = 0;
    for (auto e : a) bitarray[e] = 1;
    for (auto e : b) res += bitarray[e];
    // Clear for the next round.
    for (auto e : a) bitarray[e] = 0;
    return res;
  };
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    if (visited[i]) continue;
    a.clear();
    b.clear();
    DFS(adj, i, a, b);
    ans += Count();
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
	int h,w;
	cin >> h >> w;
	char p[h][w];
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin >>  p[i][j];
		}
	}

	for(int i=0;i<h*2;i++){
		for(int j=0;j<w;j++){
			cout << p[i/2][j];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
ab = []
d = [0 for _ in range(M)]
for i in range(M):
  ab.append(list(map(int, input().split())))
  for k in list(map(int, input().split())):
    d[i] += 2**(k-1)
  
infty = 10**8
  
dp = [infty for j in range(2**N)]
#i番目の鍵まで使って状態jにできる最小のコスト
dp[0] = 0

for i in range(M):
  for j in range(2**N):
    if dp[j|d[i]] > dp[j] + ab[i][0]:
      dp[j | d[i]] =  dp[j] + ab[i][0]

ans = dp[2**N-1] if dp[2**N-1] != infty else -1
print(ans)

Measured memory_bytes: 3316
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------

ll N, X;
ll a[100], p[100];

ll cnt_p(int n, ll x)
{
    if (n == 0)
    {
        return 1;
    }
    if (x <= 1)
    {
        return 0;
    }
    else if (x <= 1 + a[n - 1])
    {
        return cnt_p(n - 1, x - 1);
    }
    else if (x == 2 + a[n - 1])
    {
        return p[n - 1] + 1;
    }
    else if (x <= 2 + 2 * a[n - 1])
    {
        return p[n - 1] + 1 + cnt_p(n - 1, x - a[n - 1] - 2);
    }
    else
    {
        return 2 * p[n - 1] + 1;
    }
}

int main()
{
    cin >> N >> X;
    a[0] = 1;
    p[0] = 1;
    for (ll i = 1; i <= 50; i++)
    {
        a[i] = 3 + 2 * a[i - 1];
        p[i] = 2 * p[i - 1] + 1;
    }
    cout << cnt_p(N, X) << endl;
}


Measured memory_bytes: 256
let inf = 1_000_000_000_000_000_000L

let n = int64(stdin.ReadLine())
let a = stdin.ReadLine().Split() |> Array.map(int64)

for x in a do
    if x = 0L then
        printfn "0"
        exit(0)

let mutable accum = 1L

for x in a do
    if accum > inf / x then
        printfn "-1"
        exit(0)

    accum <- accum * x

printfn "%i" accum


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

using namespace std;

int main(){
  int N, K, C;
  cin >> N >> K >> C;
  
  string S;
  cin >> S;
  
  vector<int> left(K, 0);
  vector<int> right(K, 0);
  
  for(int k = 0, i = 0; k < K; k++){
    while(i < N && S[i] == 'x') i++;
    left[k] = i;
    i += C + 1;
    if(i > N) i = N;
  }
  
  for(int k = K - 1, i = N - 1; k >= 0; k--){
    while(i >= 0 && S[i] == 'x') i--;
    right[k] = i;
    i -= C + 1;
    if(i < -1) i = -1;
  }
  
  for(int i = 0; i < K; i++){
    if(left[i] == right[i]) cout << left[i] + 1 << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3332
a = int(input())
ar = input()
n = ar.count("E")
if ar[0] == "E":
    n -= 1
mi = n
for i in range(1,a):
    if ar[i] == "E":
        n -= 1
    if ar[i-1] == "W":
        n += 1
    if n < mi:
        mi = n
print(mi)

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

int main(){
    int N, M, R;  cin >> N >> M >> R;
    vector<int> r(R);
    for(int i=0; i<R; i++) cin >> r[i];

    vector<vector<int>> d;
    int inf = 1e9;
    d = vector<vector<int>>(N+1, vector<int>(N+1, inf));
    for(int i=1; i<=N; i++) d[i][i] = 0;
    for(int i=1; i<=M; i++){
        int a, b, c;  cin >> a >> b >> c;
        d[a][b] = c;
        d[b][a] = c;
    }

    for(int k=1; k<=N; k++){
        for(int i=1; i<=N; i++){
            for(int j=1; j<=N; j++){
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    int ans = 1e9;
    sort(r.begin(), r.end());
    do{
        int dsum = 0;
        for(int i=0; i<R-1; i++){
            dsum += d[r[i]][r[i+1]];
        }
        ans = min(ans, dsum);
    }while(next_permutation(r.begin(), r.end()));

    cout << ans << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int dp[999],a[999],l[999],r[999],m[999],N,Q,i,j,k,OK;
main(){
	cin>>N;
	for(i=0;i<N;i++)cin>>l[i]>>r[i]>>m[i];
	for(i=0;i<N;i++)
		for(j=0;j<400;j++)
			for(k=l[i];k<=r[i];k++)
				dp[j+k]=max(dp[j+k],dp[j]+m[i]);
	cin>>Q;
	for(i=0;i<Q;i++){
		cin>>a[i]; 
		if(!dp[a[i]])OK=1;
	}
	if(OK)cout<<"-1"<<endl;
	else for(i=0;i<Q;i++)cout<<dp[a[i]]<<endl;
}

Measured memory_bytes: 1180
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}


void Main()
{
    int p,q,r;cin>>p>>q>>r;

    cout<<min(min(p+q,q+r),r+p)<<endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 256
s=input()

cntr=0
for i in range(3):
    if s[i]=="R":
        cntr+=1
    if cntr==0 or cntr==1:
        ans=cntr
    elif cntr==2:
        if s[1]=="R":
            ans=2
        else:
            ans=1
    else:
        ans=3
print(ans)

Measured memory_bytes: 9040
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

#i - j == a[i] + a[j]
#=> i - a[i] == j + a[j]
#j - i == a[i] + a[j]
#=> i + a[i] == j - a[j]
n = INT()
a = LIST()
c = [0]*(2*n+1)
for i in range(n):
    if i - a[i] >= 0:
        c[i-a[i]] += 1
ans = 0
for i in range(n):
    if i + a[i] <= 2*n:
        ans += c[i+a[i]]
print(ans)

Measured memory_bytes: 34224
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 * Graph I - Graph
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int n = Integer.parseInt(line);
			int[][] g = new int[n][n];

			int k, p, q;
			StringTokenizer st;
			for (int i = 0; i < n; i++) {
				st = new StringTokenizer(br.readLine());
				p = Integer.parseInt(st.nextToken());
				p--;
				k = Integer.parseInt(st.nextToken());
				for (int j = 0; j < k; j++) {
					q = Integer.parseInt(st.nextToken());
					q--;
					g[p][q] = 1;
				}
			}
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					if (j < n - 1) {
						System.out.print(g[i][j] + " ");
					} else {
						System.out.print(g[i][j] + "\n");
					}
				}
			}
		}
	}
}

Measured memory_bytes: 23284
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
    while(1){
        int a,b;
        cin >> a >> b;
        if(a == 0 && b == 0) break;
        cout << min(a,b) << " " << max(a,b) << endl;
    }
}


Measured memory_bytes: 3084
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <cstring>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int maxn = 100005;

int n,m;
vector<int>e[maxn];
bool vis[maxn];
vector<int>path1,path2;
void dfs(int u,int fa,vector<int>& path){
  for(int i=0;i<e[u].size();i++){
    int v=e[u][i];
    if(v==fa||v==1||vis[v])continue;
    vis[v]=1;
    path.push_back(v);
    dfs(v,u,path);
    break;
  }
}

int main() {
//  freopen("in.cpp","r",stdin);
  cin>>n>>m;
  for(int i=0;i<m;i++){
    int x,y;
    cin>>x>>y;
    e[x].push_back(y);
    e[y].push_back(x);
  }
  dfs(1,0,path1);
  dfs(1,0,path2);
  int n=path1.size()+path2.size()+1;
  cout<<n<<endl;
  for(int i=path2.size()-1;i>=0;i--)cout<<path2[i]<<" ";
  cout<<1;
  for(int i=0;i<path1.size();i++)cout<<" "<<path1[i];
  cout<<endl;
  return 0;
}


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

ll digits(ll n) {
    ll d = 0;
    while(n > 0) {
        n /= 10;
        d++;
    }
    return d;
}

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

    ll j, minimum = INT32_MAX;
    for (ll i = floor(sqrt(n)); i >= 1; i--) {
        if (n % i != 0) continue;
        j = n / i;
        minimum = min(minimum, max(digits(i), digits(j)));
    }
    cout << minimum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unistd.h>
#include <cctype>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 1 << 30
#define LLINF LLONG_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
using ll = long long;
using Pll = pair<ll,ll>;
using Pii = pair<int,int>;
using Pdd = pair<double,double>;
using dcomplex = complex<double>;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
ll gcd(ll a,ll b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll fact(ll a){ll b=1;FOR(i,1,a)b*=i;return b;}
ll power(ll x,ll n){ll a=1;REP(i,n)a*=x;return a;}
double inf() {return std::numeric_limits<double>::infinity();}

template<typename T> class P
{
public:
  T x,y;
  P(){};P(T x,T y):x(x),y(y){};
  T dist(const P&q) {return abs(x-q.x)+abs(y-q.y);}
};

int main(int argc, char const *argv[]) {
  int N; cin >> N;
  vector<Pii> red, blue;
  REP(i,N){
    int a, b; cin >> a >> b;
    red.push_back(make_pair(a,b));
  }
  REP(i,N){
    int a, b; cin >> a >> b;
    blue.push_back(make_pair(a,b));
  }
  sort(red.begin(), red.end(), greater<Pii>());
  sort(blue.begin(), blue.end());
  int cnt = 0;
  vector<int> f1(N,0),f2(N,0) ;
  REP(j,N) {
    int ymax=-1;
    int yid=-1;
    REP(i,N) {
      if((red[i].first < blue[j].first)
        && (red[i].second < blue[j].second)
        && f1[i]==0 && f2[j]==0) {
          if(red[i].second > ymax) {
            ymax = red[i].second;
            yid = i;
          }
      }
    }
    if(ymax >= 0) {
      f1[yid] = 1;
      f2[j] = 1;
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;

int main(){
    
    ios_base::sync_with_stdio(0);
    int a,b,c;
    cin>>a>>b>>c;
    int sum=0,cnt=0;
    while(sum<c){
        sum += a;
        cnt++;
        if(cnt%7==0)    sum+=b;
    }
    cout<<cnt<<endl;
    return 0;
}




Measured memory_bytes: 3216
def main
  a, b, c, d = ARGF.gets.split.map(&:to_i)

  lower = [a, c].max
  upper = [b, d].min

  intersect = upper - lower
  if 0 <= intersect
    puts intersect
  else
    puts 0
  end
end

if __FILE__ == $0
  main
end


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


void solve(long long N, long long K, std::vector<long long> H){
    sort(H.begin(), H.end(), greater<long long>());
    ll ans = 0;
    for(int i = K;i < N;i++){
        ans += H[i];
    }
    cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> H(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&H[i]);
    }
    solve(N, K, std::move(H));
    return 0;
}


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

int main(){
    int s,w;
    cin >> s >> w;
    if(s <= w)cout << "unsafe" << endl;
    else cout << "safe" << endl;
}

Measured memory_bytes: 3584
package main

import "fmt"

var H, W int

func main() {
	fmt.Scan(&H, &W)
	m := min(search(H, W), search(W, H))
	fmt.Println(m)
}
func search(h, w int) int {
	m := 1 << 60
	var s1, s2, s3 int
	for i := 1; i <= h; i++ {
		s1 = i * w
		s2 = ((h - i) / 2) * w
		s3 = h*w - s1 - s2
		a := max(s1, s2, s3) - min(s1, s2, s3)
		m = min(m, a)
	}
	for i := 1; i <= h; i++ {
		s1 = i * w
		s2 = (h - i) * (w / 2)
		s3 = h*w - s1 - s2
		a := max(s1, s2, s3) - min(s1, s2, s3)
		m = min(m, a)
	}
	return m
}

func min(as ...int) (m int) {
	m = as[0]
	for i := range as {
		if m > as[i] {
			m = as[i]
		}
	}
	return
}
func max(as ...int) (m int) {
	m = as[0]
	for i := range as {
		if m < as[i] {
			m = as[i]
		}
	}
	return
}
func abs(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ll long long

using namespace std;

int main(){
  string s;cin>>s;
  int result=0;
  rep(i, s.size())if(s[i]=='2')result++;
  cout<<result<<endl;

  return 0;
}

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

int main(){
    ll n,k;
    cin>>n>>k;
    ll tmp=n/k;
    ll Min=n-tmp*k;
    int flag=0;
    while(true){
        if(Min-k<0){
            flag++;
            if(flag==2)break;
        }
        Min=min(Min,abs(Min-k));
    }
    cout<<Min<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long int
#define nl cout << endl
#define pb push_back
#define ff first
#define ss second
#define all(ar) ar.begin(), ar.end()
#define Sort(x) sort(all(x))
#define print_vector(my_vector_name) for(int i=0; i<my_vector_name.size(); i++) cout << my_vector_name[i] << " ";nl
//debugger
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#define hang while (1)

int main() {
	fast;
	char c;
	cin >> c;
	cout << char(c+1);nl;
	return 0;
}

//notes
/*
 value of INT_MAX and INT_MIN is fixed and they are
 INT_MAX = 2147483647
 INT_MIN = -2147483648
 use these format of input when number of inputs not provided
 *while(scanf("%lld",&n)!=EOF)
 *while using getline(cin,s) for taking input of a string which is 
 having white space characters just write cin>>ws; before geline(cin,s)
 to make it work properly
*/

/*
 use 2-D vector for representing the pair<int,pair<int,int> > kind of things
*/

Measured memory_bytes: 256
#include <cstdio>
#include <cassert>
#include <cstring>
#include <algorithm>
#define meow(args...) fprintf(stderr, args)
template<class T1, class T2> inline bool cmin(T1 &a, const T2 &b) {return b<a?(a=b, true):false;}
template<class T1, class T2> inline bool cmax(T1 &a, const T2 &b) {return a<b?(a=b, true):false;}
template<class Type> Type read() {
	Type a;
	bool b;
	unsigned char c;
	while(c=getchar()-'0', (c>9)&(c!=253));
	for(a=(b=c==253)?0:c; (c=getchar()-'0')<=9; a=a*10+c);
	return b?-a:a;
}
int (*rd)()=read<int>;
int n;
char a[40][41];
long long f[40][40][40], g[40][40][40];
int main() {
	assert(scanf("%d", &n)==1);
	for(int i=0; i<2*n; ++i) assert(scanf("%s", a[i])==1);
	for(int i=2*n; --i; ) {
		f[i][i][i]=1;
		for(int j=1; j<2*n; ++j) if(a[i][j]=='1') g[i][i][j]=1;
		for(int j=i+2; j<2*n; j+=2) {
			for(int l=i; l<=j; ++l)
				for(int r=l+2; r<=j; ++r) {
					long long s=0;
					for(int q=r; q<=j; ++q) s+=g[i][l][q]*f[r][j][q];
					for(int k=l; k<=r; ++k) f[i][j][k]+=f[l+1][r-1][k]*s;
				}
			for(int k=i+1; k<j; ++k) {
				for(int q=0; q<i; ++q) if(a[k][q]=='1') g[i][j][q]+=f[i][j][k];
				for(int q=2*n; q-->j; ) if(a[k][q]=='1') g[i][j][q]+=f[i][j][k];
			}
		}
	}
	long long ans=0;
	for(int i=1; i<2*n; ++i) if(a[0][i]=='1') ans+=f[1][2*n-1][i];
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 896
#pragma region head
    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    using vi = vector<int>;
    using vll = vector<ll>;
    using pi = pair<int, int>;
    using pll = pair<ll,ll>;
    template <class T> using vv = vector<vector<T>>;
    #define rep(i,n) for(int i = 0; i < (int)(n); i++)
    #define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
    #define rrep(i,n) for(int i = (int)(n)-1; i >= 0; i--)
    #define rrepi(i,a,b) for(int i = (int)(b)-1; i >= (int)(a); i--)
    #define all(x) (x).begin(), (x).end()
    #define rall(x) (x).rbegin(), (x).rend()    
    #define bit(n) (1LL<<(n))
    template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
    template<class T> inline bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
    const int INF = 1002003004;
    const ll LINF = 1002003004005006007ll;
    struct preprocess{preprocess()
    {cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}}____;
#pragma endregion head

#pragma region library
#pragma endregion library

int main(){
    string s;  cin >> s;
    int n  = s.length();
    ll now = 0;
    rep(i,n){
        now += s[i]-'0';
    }
    if(now%9==0) cout << "Yes" << '\n';
    else cout << "No" << '\n';
    
}


Measured memory_bytes: 3780
#include <stdio.h>
#include <string.h>
int main(void){
	char s[11];
	scanf("%s",s);
	int len = strlen(s);
	int i;
	int count = 0;
	int x=0;
	if(s[0] =='A'){
		for(i=2;i<len-1;i++){
			if(s[i]=='C'){
				count++;
			}
		}
		if(count==1){
			for(i=0;i<len;i++){
				if((s[i]>='a')&&(s[i]<='z')){
					x++;
				}
			}
			if(x+2==len){
				printf("AC");
				return 0;
			}
		}
	}
	printf("WA");
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

int main(void) {

	int n;
	int a[200000];

	scanf("%d", &n);

	for (int i = 0; i < n; i++)scanf("%d", &a[i]);

	int k = 1;
	for (int i = 0; i < n; i++) {
		if (a[i] == k)k++;
	}

	if (k != 1)printf("%d\n", n - k + 1);
	else printf("-1\n");

	return 0;
}

Measured memory_bytes: 896
s = input()
n = len(s)-1
nums = [s[0]]
box = []
for i in range(2**n):
  for j in range(n):
    if (i>>j)&1:
      nums.append("+")
      nums.append(s[j+1])
    else:
      nums.append(s[j+1])
  num = 0
  now = 0
  for k in nums:
    if k == "+":
      num += now
      now = 0
    else:
      now = 10*now + int(k)
  num += now
  box.append(num)
  nums = [s[0]]
print(sum(box))

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

int multiply0(int, int); // プロトタイプ宣言

// APG4b-G
int main() {
  int N,A,B;
  cin >> N >> A >> B;
  
  int x = multiply0(N, A);
  if (x > B) x = B;
  cout << x << endl;
  
}
int multiply0(int n, int a) {
  if (n == 1) return a;
  return multiply0(n - 1, a) + a;
}


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

int main()
{
ll n , m , v , p ;
cin >> n >> m >> v >> p ;
vector<ll> a(n);
rep(i, n){
  cin >> a[i];
}
sort(a.rbegin(),a.rend());
ans=n;
ll sum=0;
rep(i,n-p){
  sum+=(a[i+p-1]-a[i+p])*(i+1);
  if(max(a[p-1]-a[i+p],(sum+n-v-1)/(n-v))>m){
    ans=i+p;
    break;
  }
}
cout << ans << endl;
return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>

int main(void){
	int a,b,d,r;
	double f;
	scanf("%d %d",&a,&b);
	d=a/b;
	r=a%b;
	f=(double)a/b;
	printf("%d %d %lf\n",d,r,f);
	
	return 0;
}


Measured memory_bytes: 2036
#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 s, w;
    cin >> s >> w;

    if(w >= s){
        cout << "unsafe" << endl;
    }
    else{
        cout << "safe" << endl;
    }


    return 0;
}

Measured memory_bytes: 3636
n = int(input())
list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(list[n-1])

Measured memory_bytes: 3060
import numpy as np
 
MOD = 10 ** 9 + 7
 
N = int(input())
A = np.array(list(map(int, input().split())),np.int64)
 
answer = 0
for n in range(63):
    B = (A >> n) & 1
    x = np.count_nonzero(B)
    y = N - x
    x *= y
    for _ in range(n):
        x *= 2
        x %= MOD
    answer += x
answer %= MOD
print(answer)

Measured memory_bytes: 48840
x=input()

n=len(x)-1
ans=0
for i in range(2**n):	
	cal=[]
	for j in range(n):
		cal.append(x[j])
		if (i >> j) & 1:
			cal.append('+')
	cal.append(x[n])
	y=''.join(cal)
	ans += eval(y)
print(ans)

Measured memory_bytes: 3064
// https://atcoder.jp/contests/abc156/tasks/abc156_d
// AtCoder Beginner Contest 156
// D - Bouquet

/*
Problem.
整数n, a, bが与えられて、2^n - nCa - nCbを出力せよ。
2 <= n <= 10^9, 1 <= a, b <= 2*10^5

Point.
nCaは、1/a!を逆元から求めることで、簡単に求められる。
1/a! = (a!)^(mod_prime - 2)
繰り返し自乗法で累乗を効率的に求めることが必要。
*/

#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>

using namespace std;

using ll = long long;

#define MOD 1000000007

ll self_suare(ll a, ll b){
  if(b == 0) return 1;
  if(b%2 == 0){
    ll t = self_suare(a, b/2);
    return t * t % MOD;
  }
  return a * self_suare(a, b-1) % MOD;
}

int main(){
  ll n, a, b;
  cin >> n >> a >> b;
  if(n == 2 && a+b == 3){
    cout << 0 << endl;
    return 0;
  }
  ll all = self_suare(2, n);
  ll nca = 1;
  ll inv_nca = 1;
  for(ll i = 0; i < a; i++){
    nca *= n-i;
    nca %= MOD;
    inv_nca *= i+1;
    inv_nca %= MOD;
  }
  inv_nca = self_suare(inv_nca, MOD-2);
  nca = nca * inv_nca % MOD;

  ll ncb = 1;
  ll inv_ncb = 1;
  for(ll i = 0; i < b; i++){
    ncb *= n-i;
    ncb %= MOD;
    inv_ncb *= i+1;
    inv_ncb %= MOD;
  }
  inv_ncb = self_suare(inv_ncb, MOD-2);
  ncb = ncb * inv_ncb % MOD;

  cout << (all - 1 + MOD * 2 - nca - ncb) % MOD << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
bool used[10005];
vector<int> G[10005];
int indeg[10005];
int N;
int board[105][105];
void firstdfs(int s,int now)
{
    used[s]=true;
    board[0][now-1]=s;
    if(now==N) return;
    for(int i=0;i<int(G[s].size());i++)
    {
        int to=G[s][i];
        if(now<N-1 && !used[to] && indeg[to]==3)
        {
            firstdfs(to,now+1);
            return;
        }
        else if(now==N-1 && !used[to] && indeg[to]==2)
        {
            firstdfs(to,now+1);
            return;
        }
    }
}

int main(void)
{
    cin >> N;
    memset(used,false,sizeof(used));
    memset(board,0,sizeof(board));
    memset(indeg,0,sizeof(indeg));
    for(int i=0;i<2*N*N-2*N;i++)
    {
        int a,b;
        cin >> a >> b;
        a--,b--;
        G[a].push_back(b);
        G[b].push_back(a);
        indeg[a]++;
        indeg[b]++;
    }
    int start;
    for(int i=0;i<N*N;i++) 
    {
        if(indeg[i]==2) 
        {
            start=i;
            break;
        }
    }
    board[0][0]=start;
    used[start]=true;
    firstdfs(start,1);
    for(int y=0;y<N-1;y++)
    {
        for(int x=0;x<N;x++)
        {
            int now=board[y][x];
            if(y!=N-2)
            {          
                for(int i=0;i<int(G[now].size());i++)
                {
                    int to=G[now][i];
                    if(x==0 || x==N-1)
                    {
                        if(!used[to] && indeg[to]==3)
                        {
                            board[y+1][x]=to;
                            used[to]=true;
                            break;
                        }
                    }
                    else
                    {
                        if(!used[to] && indeg[to]==4)
                        {
                            board[y+1][x]=to;
                            used[to]=true;
                            break;
                        }
                    }
                }
            }
            else
            {
                for(int i=0;i<int(G[now].size());i++)
                {
                    int to=G[now][i];
                    if(x==0 || x==N-1)
                    {
                        if(!used[to] && indeg[to]==2)
                        {
                            board[y+1][x]=to;
                            used[to]=true;
                            break;
                        }
                    }
                    else
                    {
                        if(!used[to] && indeg[to]==3)
                        {
                            board[y+1][x]=to;
                            used[to]=true;
                            break;
                        }
                    }
                }
            }
            
        }
    }
    for(int y=0;y<N;y++)
    {
        for(int x=0;x<N;x++)
        {
            if(x!=N-1) cout << board[y][x]+1 << ' ';
            else cout << board[y][x]+1 << endl;
        }
    }
return 0;   

}


Measured memory_bytes: 3776
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

struct Enemy{
  int X,H;
  Enemy(int in_X,int in_H){
    X=in_X;H=in_H;
  }
};
long long damages[200001];

bool comp(const Enemy &a,const Enemy &b){
  return a.X < b.X;
}

int main(){
  int N,D,A;
  vector<Enemy> enemies;
  int X,H;
  long long ct = 0;
  cin >> N >> D >> A;
  for(int i = 0;i < N;i++){
    cin >> X >> H;
    enemies.push_back(Enemy(X,H));
  }
  sort(enemies.begin(),enemies.end(),comp);
  
  long long damage = 0;int index = 0;
  for(auto i : enemies){
    auto iter = upper_bound(enemies.begin(),enemies.end(),Enemy(i.X+2*D,0),comp);
    damage -= damages[index];
    if(damage < i.H){
      long long ct2 = (long long)((i.H-damage+A-1)/A);
      ct += ct2;
      damages[distance(enemies.begin(),iter)] += ct2*(long long)A;
      damage += ct2*(long long)A;
    }index++;
  }
  cout << ct << endl;
}

Measured memory_bytes: 3440
#include <stdio.h>

int main(void) {
	int n,i,j;
	scanf("%d",&n);
	int A[n],tmp;
	double B;
	for(i=0;i<n;i++){
		scanf("%d",&A[i]);
	}
	for(i=0;i<n;i++){
		for(j=0;j<n-1;j++){
			if(A[j]>A[j+1]){
				tmp=A[j+1];
				A[j+1]=A[j];
				A[j]=tmp;
			}
		}
	}
	B=A[0];
	for(i=1;i<n;i++){
		B=(double)(B+A[i])/2.0;
	}
	printf("%lf",B);


}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	string s, t; cin >> s >> t;
	int ans = 0;
	rep(i, s.size()) ans += s[i] == t[i];
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
// Aizu Vol0 0001: List of Top 3 Hills
// 2017.7.28

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>

char *gets(char *s);

int main()
{
	int a, b, c;
	int n, i;
	char buf[100];

	a = b = c = 0;
	for (i = 0; i < 10; i++) {
		gets(buf); n = atoi(buf);
		if (n >= a) c = b, b = a, a = n;
		else if (n >= b) c = b, b = n;
		else if (n > c) c = n;
	}
	printf("%d\n", a);
	printf("%d\n", b);
	printf("%d\n", c);
	return 0;
}

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

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

	rep(i,100000)
		if((int)((i+1)*0.08)==A && (int)((i+1)*0.1)==B) {
			cout << i+1 << endl;
			return 0;
		}

	cout << -1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {

	string s;
	cin >> s;

	int x = 753;
	int ans = 999;

	stringstream ss;

	for (int i = 2; i < s.size(); i++) {
		ss.clear();
		ss << s.substr(i - 2, 3);
		int a;
		ss >> a;
		ans = min(ans, abs(x - a));
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>

int main()
{
    int N;

    scanf("%d", &N);

    std::vector<int> I;
    I.resize(N);

    int C = 0;
    for (int i = 1; i <= N; ++i)
    {
        int T;
        scanf("%d", &T);
        I[T - 1] = i;
    }

    printf("%d", I[0]);
    for (int i = 1; i < N; ++i) {
        printf(" %d", I[i]);
    }
    printf("\n");
}


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

int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> h(n);
	for (ll i = 0; i < n; ++i)cin >> h[i];
	sort(h.begin(), h.end());
	ll ans = 0;
	for (ll i = 0; i < n - k; ++i) {
		ans += h[i];
	}
	cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int p[n];
  rep(i,n) cin >> p[i];
  int min_p=INT_MAX;
  int ans=0;
  rep(i,n){
    if(min_p>=p[i]){
      min_p=p[i];
      ans++;
    }
  }
  cout << ans << endl;

  
  return 0;
    

}


Measured memory_bytes: 1024
import sys
from itertools import product
from collections import deque
read = sys.stdin.read
def enc(S:str, p:int):
    return chr((ord(S) + p - ord("A")) % 26  + ord("A")) 
def f(S:str):
    res = []
    plus_minus = 0
    # q = deque()
    stack = []
    for s in S:
        if("A" <= s <= "Z"):
            s = enc(s, plus_minus)
            plus_minus = 0
            res.append(s)
        elif s=="-":
            plus_minus-=1
        elif s=="+":
            plus_minus+=1
        elif s=="[":
            stack.append(len(res))
        else:
            if not stack:
                return None
            rev_i = stack.pop()
            res[rev_i:] = res[rev_i:][::-1]

    if(stack or plus_minus):
        raise Exception
        return None
    return "".join(res)
def solve(S:str):
    ans = "Z"*len(S)
    L = [chr(ord("A") + i) for i in range(26)]
    for it in product(L, repeat=S.count("?")):
        *it, = it
        # print(it)
        idx = 0
        T = ""
        for s in S:
            if(s == "?"):
                T += it[idx]
                idx += 1
            else:
                T += s
        res = f(T)
        if(res is None):
            continue
        # print(res)
        # if(S == "[[++-+--?[--++-?++-+++L]][-+-----+-O]]++++---+L"):
        #     print(res)
        ans = min(ans, res)
    print(ans)
def main():
    
    S = read()
    for s in S.split("\n"):
        if(s=="."):
            break
        solve(s)



if __name__ == "__main__":
    main()


Measured memory_bytes: 6100
#include <iostream>
#include <utility>
#include <functional>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)
#define rem(i,n,x) for(int i=n;i>x;i--)
#define SORT(x) sort(x.begin(),x.end())
#define REV(x) reverse(x.begin(),x.end())
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define setp(x) setprecision(x)
using LL = long long;
using ULL = unsigned long long;

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

	SORT(d);
	REV(d);
	int count = 0;
	rep(i, 0, n) {
		if (d[i - 1] == d[i]) continue;
		count++;
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define rep(i,n) for(i=0; i<n; i++)
int main(void){

	int n, i;
	scanf("%d", &n);
	char s[n];
	scanf("%s", s);
	if(n%2 != 0){
		puts("No");
		return 0;
	}
	rep(i,n/2){
		if(s[i] != s[(n/2)+i]){
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}


Measured memory_bytes: 256