akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cassert>
using namespace std;
typedef long long lint;

lint f(lint b,lint n){
	if(n<b)return n;
	return f(b,n/b) + n%b;
}

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

	lint n,s;
	cin >> n >> s;

	if(s > n){
		cout << -1 << endl;
		return 0;
	}else if(s == n){
		cout << n+1 << endl;
		return 0;
	}

	lint b;
	for(b=2;b*b<=n;b++){
		if(f(b,n)==s){
			cout << b << endl;
			return 0;
		}
	}

	b--;
	if(b*b==n)b--;
	for(lint i=min(b,s);i>=1;i--){
		//n = b*i + s-i
		b = (n-s+i)/i;
		if((n-s+i)%i==0 && b > s-i){
			cout << b << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;	
}

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

typedef long long ll;

int N,M;
ll x[100010],y[100010];
ll res1 = 0,res2 = 0;
ll mod = 1000000007;

int main()
{
    scanf("%d%d",&N,&M);
    for(int i = 0; i < N; i++)scanf("%lld",&x[i]);
    for(int i = 0; i < M; i++)scanf("%lld",&y[i]);
    for(int i = 0; i < N; i++)
    {
        res1 += (i * x[i] - (N - 1 - i) * x[i]);
        res1 = (res1 + mod) % mod;
    }
    for(int i = 0; i < M; i++)
    {
        res2 += (i * y[i] - (M - 1 - i) * y[i]);
        res2 = (res2 + mod) % mod;
    }
    printf("%lld",res1 * res2 % mod);
    return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int a,n;
int main() {
	scanf("%d%d",&n,&a);
	n%=500;
	if(a>=n){
		printf("Yes\n");
	}
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define max(a, b)	(((a) > (b)) ? (a) : (b))		/* ２個の値の最大値 */
#define min(a, b)	(((a) < (b)) ? (a) : (b))		/* ２個の値の最小値 */
#define ENTER		printf("\n")					/* 改行プリント */
/********************************************************************************************************************************/
/* main *************************************************************************************************************************/
/********************************************************************************************************************************/
int DEBUG = 1;										/* デバッグプリント 提出時は0 */
int main()
{
	int		ans = 0, N;
	
	scanf("%d", &N);

	ans = 180*(N-2);
	printf("%d\n",ans);


	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#define N 100
int main(){
  int i,j,k=0,n,tmp;
  int A[N];
  scanf("%d",&n);
  for(j=0;j<=n-1;j++){
    scanf("%d",&A[j]);
  }
  for(i=0;i<=n-1;i++){
    for(j=n-1;j>i;j--){
      if(A[j]<A[j-1]){
	tmp=A[j-1];
	A[j-1]=A[j];
	A[j]=tmp;
	k++;
      }
    }
  }
  for(j=0;j<=n-1;j++){
    printf("%d",A[j]);
    if(j<n-1)
      printf(" ");
  }
  printf("\n");
  printf("%d\n",k);
  return 0;
}



Measured memory_bytes: 2048
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public final class Main {

    public static void main(String[] args) {
        final FastScanner fs = new FastScanner();
        final int n = fs.nextInt();
        final int k = fs.nextInt();
        System.out.println(n % k == 0 ? 0 : 1);
    }

    static final class Util {
        public static void shuffleSort(int[] x) {
            shuffle(x);
            Arrays.sort(x);
        }

        public static void shuffleSort(long[] x) {
            shuffle(x);
            Arrays.sort(x);
        }

        public static void shuffle(int[] x) {
            final Random r = new Random();

            for (int i = 0; i <= x.length - 2; i++) {
                final int j = i + r.nextInt(x.length - i);
                swap(x, i, j);
            }
        }

        public static void shuffle(long[] x) {
            final Random r = new Random();

            for (int i = 0; i <= x.length - 2; i++) {
                final int j = i + r.nextInt(x.length - i);
                swap(x, i, j);
            }
        }

        public static void swap(int[] x, int i, int j) {
            final int t = x[i];
            x[i] = x[j];
            x[j] = t;
        }

        public static void swap(long[] x, int i, int j) {
            final long t = x[i];
            x[i] = x[j];
            x[j] = t;
        }

        private Util() {}
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        private String next() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    //noinspection CallToPrintStackTrace
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int[] nextIntArray(int n) {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++) { a[i] = nextInt(); }
            return a;
        }

        long[] nextLongArray(int n) {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++) { a[i] = nextLong(); }
            return a;
        }
    }
}


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

using namespace std;

#define eb emplace_back

vector<int> path; 

void dfs(int v, vector<int> adj[], vector<bool> &visited) {
    visited[v] = true;
    for (int u : adj[v]) {
        if (!visited[u]) 
            dfs(u, adj, visited);
    }
    path.eb(v);
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> adj[n + 1];
    vector<bool> visited(n + 1);
    for (int i = 1; i <= n + m - 1; ++i) {
        int u, v;
        cin >> u >> v;
        adj[u].eb(v);
    }
    for (int i = 1; i <= n; ++i) {
        if (!visited[i]) 
            dfs(i, adj, visited);
    }
    reverse(path.begin(), path.end());
    vector<int> p(n + 1);
    for (int i = 0; i < n; ++i) {
        int v = path[i];
        for (int u : adj[v]) {
            p[u] = v;
        }
    }
    for (int i = 1; i <= n; ++i) {
        cout << p[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 11512
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ld long double
const int mod=1e9 +7;







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

  
  int a,b;
  cin>>a>>b;
  if(a>=1 && a<=9 && b<=9 &&b>=1)
  {
     cout<<a*b<<"\n";
  }

  else
  {
     cout<<-1;
  }
  

   
}

 

 
 
 
 
 


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int grid[21][21];
int nowx,nowy;
void init(){
  nowx = 10,nowy = 10;
  for(int i = 0 ; i <= 20 ; i++ ){
    for(int j = 0 ; j <= 20 ; j++ ){
      grid[j][i] = 0;
    }
  }
}

void serch(int a,int b,int f){
  if(a > b)swap(a,b);
  if(f == 1){
    for(int i = a ; i <= b ; i++ )grid[nowx][i] = 0;
  }else {
    for(int i = a ; i <= b ; i++ )grid[i][nowy] = 0;
  }
}

bool check(){
  bool flag = true; 
  for(int i = 0 ; i <= 20 ; i++ ){
    for(int j = 0 ; j <= 20 ; j++ ){
      if(grid[j][i] == 1){flag = false;goto N;}
    }
  }
 N:;
  if(flag)return true;
  else return false;
}

int main(){
  int n;
  while( cin >> n,n ){
    init();
    for(int i = 0 ; i < n ; i++ ){
      int x,y;
      cin >> x >> y;
      grid[x][y] = 1;
    }
    cin >> n;
    for(int i = 0 ; i < n ; i++ ){
      char c;
      int move,f = 0,past;
      cin >> c >> move;
      if(c == 'N'){
	f = 1;
	past = nowy;
	nowy+=move;
      }else if(c == 'S'){
	f = 1;
	past = nowy;
	nowy-=move;
      }else if(c == 'E'){
	past = nowx;
	nowx+=move;
      } else {
	past = nowx;
	nowx-=move;
      }
      if(f == 0)serch(past,nowx,f);
      else serch(past,nowy,f);
    }
    if( check() )cout << "Yes" << endl;
    else cout << "No" << endl; 
  }
  return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int bell,number;
  while(scanf("%d",&bell)!=EOF){
    number=0;
    while(bell!=0){
      if(bell>39){
	bell-=39;
      }
      else{
	bell--;
	number++;
      }
    }
    if(number<10){
      cout << "3C0" << number << endl;
    }
    else{
      cout << "3C" << number << endl;
    }
  }
}

Measured memory_bytes: 1208
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
	Scanner s = new Scanner(System.in);
	while(s.hasNext()) {
	    double[] out = new double[10];
	    out[0] = s.nextDouble();
	    double sum = out[0];
	    for(int i=1 ; i<10 ; i++) {
		if((i+1)%2==0) {
		    out[i] = out[i-1]*2;
		} else {
		    out[i] = out[i-1]/3;
		}
		sum+=out[i];
	    }
	    System.out.println(sum);
	}
    }
}

Measured memory_bytes: 11000
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

#define TRACE(x) cerr << #x << " = " << x << endl
#define REP(i, n) for (int i=0; i<n; i++)
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define _ << " " <<

typedef long long ll;
typedef pair<int, int> P;
#define X first
#define Y second

const int MAX = 1<<17;

vector <int> V[MAX];
int bio[MAX];

void go(int node, vector <int> &T) {
  if (bio[node]++) return;
  T.push_back(node);
  for (auto it : V[node]){
    if (!bio[it]) {
      go(it, T);
      break;
    }
  }
}

int main()
{
  int n, m;
  scanf("%d%d", &n, &m);

  REP(i, m) {
    int a, b;
    scanf("%d%d", &a, &b); a--; b--;
    V[a].push_back(b);
    V[b].push_back(a);
  }

  vector <int> R, L;
  go(0, R);
  for (auto it : V[0]) {
    if (!bio[it]) {
      go(it, L);
      reverse(L.begin(), L.end());
      for (auto it2 : R)
	L.push_back(it2);
      break;
    }
  }

  if (L.empty()) L = R;
  printf("%d\n", (int) L.size());
  for (auto it : L)
    printf("%d ", it+1);
  printf("\n");

  return 0;
}


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



int main(){
	bool flag = false;
	int a,b,c;
	cin >> a >> b >>c;
	for(int i = 1; i <= b; i++) {
		if (a * i % b == c){
			flag = true;
			break;
		}
	}
	if (flag){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}
	return 0;
}

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


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define w(x)  int x; cin>>x; while(x--)
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n"
#define watch4(x,y,z,q) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<" and "<<(#q)<<" is "<<(q)<<"\n"
#define MOD 1000000007
#define INF 1000000007;
#define F first
#define S second
#define pb(x) push_back(x);


#define ll  long long
#define all(c) (c).begin(),(c).end()
#define endl "\n"

typedef vector<int> vl;
typedef vector< vl > vvl;
typedef pair< int, int> pll;
typedef map< int, int> mll;


#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif





void c_p_c()
{
#ifndef ONLINE_JUDGE
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
void parray(int a[],int n){
    for(int i=0;i<n;i++){
    cout<<a[i]<<" ";
    }
    cout<<endl;
}

int main() {
    int i,n,m,k,c=0,sum=0;
    c_p_c();
  	cin>>n;
  	int a[n];
  	fo(i,n) cin>>a[i] ,sum+=a[i];
  	cin>>k;
  	while(k--){
  		int x,y;
  		cin>>x>>y;
  		cout<<sum-a[x-1]+y<<endl;




  	}

 	return 0;

   }

Measured memory_bytes: 3604
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a:String = read();
    let b:String = read();
    let x = format!("{}{}", a, b);
    let x = x.parse::<f64>().unwrap();
    let ans = x.sqrt();
    if ans.ceil() == ans {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2688
//最短経路長が短い経路に流せるだけ流す。
//ただし、順辺のコストをcとしたときに逆辺のコストは-cにする (フローを押し戻すとき、コストも押し戻すため）。
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

const int VMAX = 100;
struct Edge {
	int from, to, flow, cost, rev;
	Edge(int from, int to, int flow, int cost, int rev) {
		this->from = from;
		this->to   = to;
		this->flow = flow;
		this->cost = cost;
		this->rev  = rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph &g, int from, int to, int flow, int cost) {
	g[from].push_back(Edge(from, to, flow, cost, g[to].size()));
	g[to].push_back(Edge(to, from, 0, -cost, g[from].size() - 1));
}

int dfs(Graph &g, int s, int t, int flow, bool yet[], int level[]) {
	yet[s] = false;
	if (s == t) return flow;
	for (int i = 0; i < g[s].size(); i++) {
		int v = g[s][i].to;
		if (g[s][i].flow > 0 && yet[v] && level[v] == level[s] + g[s][i].cost) {
			int res = dfs(g, v, t, min(flow, g[s][i].flow), yet, level);
			if (res > 0) {
				int r = g[s][i].rev;
				g[s][i].flow -= res;
				g[v][r].flow += res;
				return res;
			}
		}
	}
	return 0;
}

int minCostflow(Graph &g, int s, int t, int flow) {
	const int INF_DIST = 11451419;
	const int INF_FLOW = 11451419;
	const int ERROR_RETURN = -1;
	int level[VMAX];
	bool yet[VMAX];
	queue<int> que;
	int i;
	int ret = 0;
	
	while (true) {
		for (i = 0; i < g.size(); i++) level[i] = INF_DIST;
		que.push(s); level[s] = 0;
		while (!que.empty()) {
			int v = que.front(); que.pop();
			for (i = 0; i < g[v].size(); i++) {
				int nv = g[v][i].to;
				if (g[v][i].flow > 0 && level[nv] > level[v] + g[v][i].cost) {
					level[nv] = level[v] + g[v][i].cost;
					que.push(nv);
				}
			}
		}
		if (level[t] >= INF_DIST) break;
		
		while (true) {
			for (i = 0; i < g.size(); i++) yet[i] = true;
			int f = dfs(g, s, t, INF_FLOW, yet, level);
			if (f == 0) break;
			flow -= f;
			ret += f * level[t];
			if (flow <= 0) {
				ret += flow * level[t];
				return ret;
			}
		}
	}
	return -1;
}

int n, m, f;
int u, v, c, d;
Graph g;

int main() {
	cin >> n >> m >> f;
	g.resize(n);
	for (int i = 0; i < m; i++) {
		cin >> u >> v >> c >> d;
		add_edge(g, u, v, c, d);
	}
	cout << minCostflow(g, 0, n - 1, f) << endl;
	return 0;
}


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

using namespace std;

const int INF = 0x0fffffff;

int N;
int K;

typedef pair<int, int> ii;

vector< vector<int> > M;
vector<bool> V; // visited

vector<ii> R; // range

const ii inf = make_pair(-INF, INF);
const ii fail = make_pair(INF, -INF);

ii dfs(int i) {
    V[i] = true;

    for (size_t j = 0; j < M[i].size(); ++j) {
        int ni = M[i][j]; // next i

        if (V[ni]) {
            continue;
        }

        ii rv = dfs(ni);

        if (rv == fail) {
            return fail;
        } else if (R[i] != inf && rv != inf && R[i].first % 2 != rv.first % 2) {
            return fail;
        } else {
            R[i].second = min(R[i].second, rv.second);
            R[i].first  = max(R[i].first, rv.first);
        }
    }

    if (R[i].second < R[i].first) {
        return fail;
    }

    if (R[i] == inf) {
        return inf;
    } else {
        return make_pair(R[i].first-1, R[i].second+1);
    }
}

void dfs2(int i) {
    V[i] = true;

    R[i] = make_pair(R[i].first, R[i].first);
    
    for (size_t j = 0; j < M[i].size(); ++j) {
        int ni = M[i][j]; // next i
        
        if (V[ni]) {
            continue;
        }

        R[ni] = make_pair(max(R[ni].first, R[i].first-1), min(R[ni].second, R[i].second+1));

        dfs2(ni);
    }
}

int main(int argc, char* argv[]) {
    // for cin
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> N;

    M.resize(N);

    for (int i = 0; i < N; ++i) {
        M[i].clear();
    }

    for (int i = 0; i < N-1; ++i) {
        int a;
        int b;

        cin >> a >> b;
        a--;
        b--;

        M[a].push_back(b);
        M[b].push_back(a);
    }

    V.resize(N);
    fill(V.begin(), V.end(), false);

    R.resize(N);
    fill(R.begin(), R.end(), inf);

    cin >> K;

    for (int i = 0; i < K; ++i) {
        int v;
        int p;

        cin >> v >> p;
        v--;

        R[v] = make_pair(p, p);
    }

    ii rv = dfs(0);

    if (rv == fail) {
        printf("No\n");
        return 0;
    }

    printf("Yes\n");
    fill(V.begin(), V.end(), false);

    dfs2(0);

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

    return 0;
}


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

using namespace std;
using ll = long long;

template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_V(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_M(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


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

    VV<int>dp(5005, V<int>(5005, 0));

    for (int i = n-1; i >= 0; i--)
    {
        for (int j = n-1; j >= 0; j--)
        {
            if(s[i]!=s[j])dp[i][j]=0;
            else dp[i][j] = dp[i+1][j+1]+1;
        }
    }

    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if(i>=j)continue;
            int now = min(dp[i][j], j-i);
            ans = max(ans, now);
        }
        
    }
    
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 98432
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <numeric>
#include <mutex>
#include <cmath>
#include <set>
#define lli long long int
#define ll long long
#define mod 1000000007
#define pii pair<int,int>
#define mp make_pair
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

int main(){
	int a, b;
	cin >> a >> b;
	if(a < b){
		cout << 0;
	}
	else{
		cout << 10;
	}
  	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>
#include<random>
#include<iostream>
using namespace std;

int main() {
	int M_1, D_1, M_2, D_2;
	cin >> M_1 >> D_1;
	cin >> M_2 >> D_2;
	if(M_1 == M_2){
		cout << 0;
	}
	else{
		cout << 1;
	}
}

Measured memory_bytes: 256
h, w, k  = map(int, input().split())

puyo_orig = [list(map(int, list(input()))) for _ in range(h)]

import copy
mx = 0
for i1 in range(h):
    for i2 in range(w):
        puyo = copy.deepcopy(puyo_orig)
        puyo[i1][i2] = -1
        p = 0
        fin = 0
        turn = 0
        while fin==0:
            #[print(*puyo[i]) for i in range(h)]
            fin = 1
            
            for i in range(w):
                d_fin = 0
                while d_fin==0:
                    d_fin = 1
                    for j in range(h-1, 0, -1):
                        if puyo[j][i]==-1 and puyo[j-1][i]>0:
                            puyo[j][i] = puyo[j-1][i]
                            puyo[j-1][i] = -1
                            d_fin = 0
                            
            for i in range(h):
                cnt = 1
                for j in range(1, w):
                    if puyo[i][j-1] == puyo[i][j] and puyo[i][j]>0:
                        cnt += 1
                    else:
                        if cnt>=k:
                            p += cnt * puyo[i][j-1] * 2**turn
                            for k2 in range(cnt):
                                puyo[i][j-k2-1] = -1
                                fin = 0
                        cnt = 1
                    if j==w-1:
                        if cnt>=k:
                            p += cnt * puyo[i][j-1] * 2**turn
                            for k2 in range(cnt):
                                puyo[i][j-k2] = -1
                                fin = 0
            turn += 1
        if p>mx:
            mx=p
            
print(mx)

Measured memory_bytes: 55516
#include<bits/stdc++.h>
using namespace std;
/**
********************************************************************
******************* Author:Bisnu sarkar ****************************
********************************************************************
**/
#define ull            unsigned long long
#define ll             long long
#define pii            pair<int,int>
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second
#define endl           '\n';

int set_1(int n,int pos){return n = (n | (1<<pos));}
int reset_0(int n,int pos){return n= n & ~(1<<pos);}
bool check_bit(int n,int pos){return n = n & (1<<pos);}

int dx[8]= {1,0,-1,0,-1,-1,1,1};
int dy[8]= {0,1,0,-1,-1,1,-1,1};
const int N = (int) 1e6 + 5;
const int M = (int) 1e9 + 7;
const double pi=2* acos(0.0);
const double eps=1e-9;


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

    int t=1,te=0;
    // cin>>t;
    while(t--){
        double x,y;
        cin>>x>>y;

        int r=ceil(x/y);

        printf("%d\n", r);


        //printf("Case %d: ",++te);
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <functional>
#include <math.h> 
#define enld '\n'
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
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; }
// ---------------------------------------------------------------------------

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  string S;
  cin >> S;
  int cnt = 0;
  for(int i=0; i<N; i++){
    string T;
    cin >> T;
    bool can = false;
    for(int j=0; j<T.size(); j++){
      for(int k=1; k<100; k++){
        int pos = 0;
        for(int l=j; l<T.size(); l+=k){
          if(S[pos] == T[l]) pos++;
          else break;
        }
        if(pos == S.size()) can = true;
      }
    }
    if(can) cnt++;
  }
  cout << cnt << "\n";
  return 0;
}


Measured memory_bytes: 3236
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
  vector<int>prime;
  prime.push_back(2);
  for(int i=3;i<10000;i+=2){
    int flag=1;
    for(int j=2;j<=sqrt(i);j++){
      if(i%j==0){
	flag=0;
	break;
      }
    }
    if(flag)
      prime.push_back(i);
  }
  int n;
  while(cin>>n,n){
    for(int i=prime.size();i>0;i--){
      if(prime[i]<=n&&(prime[i]-prime[i-1])==2){
	cout<<prime[i-1]<<" "<<prime[i]<<endl;
	break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3016
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  int a, b;
  int c=0,d=0;
  

  cin >> a >> b;

  c = a-1;
  d = b-1;
  
  if(a == b){
    cout << 1 << endl;
  }
  else if(d%c == 0){
    cout << d/c <<endl;
  }
  else{
    cout << (d/c)+1 <<endl;
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

#define rep(i, o) for (ll i = 0; i < (o);i++)
#define rep_s(i, o) for (int i = 1; i <= (o);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
#define NUM 1e5

typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }


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

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

const int MOD = 1000000007;
int main() {
    ll n; cin >> n;
    string stones = ""; cin >> stones;
    ll w = 0, r = 0;
    rep(i, n) if (stones[i] == 'R') r++;
    ll ans = max(w, r);
    rep(i, n) {
        if (stones[i] == 'R') r--;
        else w++;
        ll cur = max(w,r);
        ans = min(ans, cur);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3756
$s=<>;
$t=keyence;
foreach(0..7){
    $p=substr($t,0,7-$_);
    $q=substr($t,7-$_,$_);
    if($s=~/^\Q$p\E.*\Q$q\E$/){
        print"YES";
        exit;
    }
}
print"NO"

Measured memory_bytes: 384
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N, K;
    cin >> N >> K;
    N -= K;
    if (N == 0) {
        cout << 1 << endl;
        return 0;
    }
    cout << N / (K - 1) + (N % (K - 1) != 0 ? 1 : 0) + 1<< endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

char s[SIZE], t[SIZE];
ll dp[256] = {};

int main(){
  int n;

  scanf("%d%s%s", &n, s, t);

  dp[s[0]] = 1;

  for(int i=1;i<n-1;i++){
    dp[s[i]] = (dp[s[i]] + dp[t[i]])%mod;
  }

  printf("%lld\n", dp[t[n-1]]);
  
  return 0;
}



Measured memory_bytes: 3400
n, a, b = map(int, input().split())
ans = 0
for i in range(1, n + 1):
    tmp = 0
    num = i
    while num != 0:
        tmp += num % 10
        num = int(num / 10)
    if tmp >= a and tmp <= b:
        ans += i
    else:
        continue
print(ans)

Measured memory_bytes: 2940
while True:
    n = int(input())
    if n == 0:
        break
    S = list(map(int, input().split()))
    cnt = 0
    while S:
        cur = [S.count(s) for s in S]
        if cur == S:
            break
        cnt += 1
        S = cur[::]
    print(cnt)
    print(' '.join(map(str, cur)))

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

int main(void)
{
        char s[11];
        char r[] = "2019/04/30";
        scanf("%s", s);

         if (strcmp(s,r) <= 0) printf("Heisei\n");
         else                  printf("TBD\n");
         return 0;
}


Measured memory_bytes: 128
#最小全域木　クラスカル法
class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def find_root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            #経路圧縮
            self.root[x] = self.find_root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード
    def unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.find_root(x)
        y = self.find_root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断
    def isSame(self, x, y):
        return self.find_root(x) == self.find_root(y)

    # ノードxが属する木のサイズを返す
    def size(self, x):
        return -self.root[self.find_root(x)]

n=int(input())
xy=[]
for i in range(n):
    x,y=map(int,input().split())
    xy.append([x,y,i])

#今回の問題では,高々xが隣のやつとyが隣のやつを全部考えればよし
#（詳しくは解説pdfより）
x_sort = sorted(xy, key=lambda x: x[0])
y_sort = sorted(xy, key=lambda x: x[1])

edge = [] #edge=[i番目と,j番目が,コストk]
for i in range(n-1):
    edge.append([x_sort[i][2],x_sort[i+1][2],x_sort[i+1][0]-x_sort[i][0]])
    edge.append([y_sort[i][2],y_sort[i+1][2],y_sort[i+1][1]-y_sort[i][1]])

#クラスカル法では辺のコストを小さい順にみていき閉路ができなければ追加する。を繰り返す
#閉路ができるかどうかはUnionFindで効率的に判定できる
ans = 0
edge.sort(key=lambda x:x[2])
u=UnionFind(n)
for i,j,cost in edge:
    if u.isSame(i,j) == False:
        u.unite(i,j)
        ans+=cost

print(ans)

Measured memory_bytes: 54928
#include <bits/stdc++.h>
const int INF=1e9,MOD=1e9+7;
const long long LINF=1e18;
using namespace std;
#define int long long
//template
int dp[3000][3000][2];
//main
signed main(){
  int L,N;cin>>L>>N;
  std::vector<int> v(N),w(N);
  for(int i=0;i<N;i++)cin>>v[i];
  for(int i=0;i<N;i++)w[i]=L-v[i];
  reverse(w.begin(),w.end());
  std::vector<int> rs(N+1),ls(N+1);
  rs[0]=0;for(int i=0;i<N;i++)rs[i+1]=rs[i]+v[i];
  ls[0]=0;for(int i=0;i<N;i++)ls[i+1]=ls[i]+w[i];
  int ans=0;
  for(int i=1;i<=N;i++){
    int res=0;
    res+=rs[i+(N-i)/2]-rs[i-1];
    res+=rs[i+(N-i)/2-1]-rs[i-1];
    res+=ls[(N-i)/2]*2;
    if((N-i)%2)res+=v[i+(N-i)/2-1]+w[(N-i)/2+1-1];
    ans=max(ans,res);
  }
  for(int i=1;i<=N;i++){
    int res=0;
    res+=ls[i+(N-i)/2]-ls[i-1];
    res+=ls[i+(N-i)/2-1]-ls[i-1];
    res+=rs[(N-i)/2]*2;
    if((N-i)%2)res+=w[i+(N-i)/2-1]+v[(N-i)/2+1-1];
    ans=max(ans,res);
  }
  cout<<ans<<endl;
}


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

using namespace std;


int main(){
    int N;
    cin >> N;
    vector<int> A(N + 1);
    vector<int> B(N + 1);
    vector<int> C(N);
    for(int i = 0; i < N ; i++) cin >> A[i];
    for(int i = 0; i < N ; i++) cin >> B[i];
    for(int i = 0; i < N - 1; i++) cin >> C[i];
    int ans = 0;
    int count = 100;
    for(int i = 0; i < N; i++){
        ans += B[A[i] - 1];
    }
    for(int i = 0; i < N - 1; i++){
        if(A[i + 1] == A[i] + 1) ans += C[A[i] - 1];
    }
    cout << ans << endl;
}

Measured memory_bytes: 768
//A smooth sea never made a skilled sailor...
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll   long long  int
#define inf 1000000000
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define S second
#define F first
#define boost1 ios::sync_with_stdio(false);
#define boost2 cin.tie(0);
#define mem(a,val) memset(a,val,sizeof a)
#define endl "\n"
#define maxn 100005

ll a[1000];

int main()
{
	boost1;boost2;
	ll i,j,n,ans=0;
	cin>>n;
	for(i=1;i<=2*n;i++)
	cin>>a[i];
	sort(a+1,a+2*n+1);
	reverse(a+1,a+2*n+1);
	for(i=1;i<=2*n;i+=2)
	ans+=min(a[i],a[i+1]);
	cout<<ans;
	
	return 0;
}

Measured memory_bytes: 256
N, C = map(int, input().split())
X = [0] * N
V = [0] * N
for i in range(N):
    x, v = map(int, input().split())
    X[i] = x
    V[i] = v


answer = 0
R = [0] * N
score = 0
maxscore = 0
for i in range(N):
    score += V[i]
    R[i] = max(maxscore, score - X[i])
    maxscore = R[i]
    answer = max(answer, R[i])

L = [0] *N
score = 0
maxscore = 0
for i in range(N)[::-1]:
    score += V[i]
    L[i] = max(maxscore, score - (C - X[i]))
    maxscore = L[i]
    answer = max(answer, L[i])
L.append(0)

for i in range(N-1):
    answer = max(answer, R[i] - X[i] + L[i+1])

for i in range(1, N)[::-1]:
    answer = max(answer, L[i] - (C-X[i]) + R[i-1])

print(answer)


Measured memory_bytes: 18804
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b + 1; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template <class T>inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}

int main()
{
    ll a,b,c;ll k;
    cin >> a >> b >> c >> k;
    if(a+b<k){
        cout << a-(k-(a+b)) << endl;
    }
    else{
        cout << min(a,k) << endl;
    }
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#define to first
#define cost second
#define INF 1000000000
using namespace std;
typedef pair<int,int> P;
vector<P> e[100000];
vector<P> ge[100000];
vector<P> te[100000];
int d[100000];
int used[100000];
int bfr[100000];
int depth[100000];
int par[20][100000];
int cos[20][100000];
int n,m,k,q;
priority_queue< P,vector<P>,greater<P> > que;
int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}
void swap(int& a,int& b){int p=a;a=b;b=p;}
void dykstra(){
	int i;
	while(!que.empty()){
		P p=que.top();
		que.pop();
		int v=p.second;
		if(p.first>d[v])continue;
		for(i=0;i<e[v].size();i++){
			int u=e[v][i].to;
			int c=e[v][i].cost;
			if(d[u]>d[v]+c){
				d[u]=d[v]+c;
				que.push(P(d[u],u));
			}
		}
	}
}
void mt(){
	int i;
	for(i=0;i<n;i++){
		d[i]=INF;
		used[i]=false;
		bfr[i]=-1;
	}
	d[0]=0;
	que.push(P(0,0));
	while(!que.empty()){
		P p=que.top();
		que.pop();
		int v=p.second;
		if(p.first>d[v])continue;
		used[v]=true;
		if(bfr[v]!=-1){
			te[v].push_back(P(bfr[v],-d[v]));
			te[bfr[v]].push_back(P(v,-d[v]));
		}
		for(i=0;i<ge[v].size();i++){
			int u=ge[v][i].to;
			int c=ge[v][i].cost;
			if(!used[u]&&d[u]>c){
				d[u]=c;
				bfr[u]=v;
				que.push(P(d[u],u));
			}
		}
	}
}
void dfs(int v,int p,int d){
	int i;
	depth[v]=d;
	for(i=0;i<te[v].size();i++){
		if(te[v][i].to==p)continue;
		par[0][te[v][i].to]=v;
		cos[0][te[v][i].to]=te[v][i].cost;
		dfs(te[v][i].to,v,d+1);
	}
}
int lca(int a,int b){		
	if(depth[a]<depth[b])swap(a,b);
	int i;
	int diff=depth[a]-depth[b];
	int ans=INF;
	for(i=0;i<20;i++){
		if(diff>>i&1){
			ans=min(ans,cos[i][a]);
			a=par[i][a];
		}
	}
	if(a==b)return ans;
	for(i=19;i>=0;i--){
		if(par[i][a]!=par[i][b]){
			ans=min(ans,cos[i][a]);
			ans=min(ans,cos[i][b]);
			a=par[i][a];
			b=par[i][b];
		}
	}
	ans=min(ans,cos[0][a]);
	ans=min(ans,cos[0][b]);
	return ans;
}
int main(){
	scanf("%d %d %d %d",&n,&m,&k,&q);
	int i,j;
	for(i=0;i<m;i++){
		int a,b,c;
		scanf("%d %d %d",&a,&b,&c);
		a--;b--;
		e[a].push_back(P(b,c));
		e[b].push_back(P(a,c));
	}
	for(i=0;i<n;i++)d[i]=INF;
	for(i=0;i<k;i++){
		int s;
		scanf("%d",&s);
		d[s-1]=0;
		que.push(P(0,s-1));
	}
	dykstra();
	for(i=0;i<n;i++){
		for(j=0;j<e[i].size();j++){
			ge[i].push_back(P(e[i][j].to,-min(d[i],d[e[i][j].to])));
		}
	}
	mt();
	for(i=0;i<n;i++){
		for(j=0;j<20;j++){
			par[j][i]=-1;
			cos[j][i]=INF;
		}
	}
	dfs(0,-1,0);
	for(i=1;i<20;i++){
		for(j=0;j<n;j++){
			if(par[i-1][j]!=-1){
				par[i][j]=par[i-1][par[i-1][j]];
				cos[i][j]=min(cos[i-1][j],cos[i-1][par[i-1][j]]);
			}
		}
	}
	for(i=0;i<q;i++){
		int s,t;
		scanf("%d %d",&s,&t);
		s--;t--;
		printf("%d\n",lca(s,t));
	}
	return 0;
}

Measured memory_bytes: 40592
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn calculate_larger_group(s: &Vec<char>) -> (usize, usize){

    let mut i = 0;
    let mut num_of_r = 0;
    let mut num_of_l = 0;
    while i < s.len(){
        let mut prev_i = i;
        while i < s.len() && s[i] == 'L'{
            i += 1;
        }
        if prev_i != i{
            num_of_l += 1;
        }
        prev_i = i;
        while  i < s.len() && s[i] == 'R'{
            i += 1;
        }
        if prev_i != i{
            num_of_r += 1;
        }        
    }
    return (num_of_l, num_of_r);
}

fn get_sum_hapiness(s: &Vec<char>) -> usize{
    let (lg, rg) = calculate_larger_group(s);
    if lg == 0 || rg == 0{
        return s.len() - 1;
    }else{
        return s.len() - 1 - (lg + rg-1);
    }

}

fn get_larger_char(s: &Vec<char>) -> char{
    let s = calculate_larger_group(s);

    if s.0 >= s.1{
        return 'L';
    }else{
        return 'R';
    }
}

fn main(){
    let line: Vec<usize> = read_as_vec();
    let (n, mut k) = (line[0], line[1]);

    let mut s = read_as_string().chars().collect::<Vec<char>>();
    //println!("{:?}", s);
    //let larger_c: char = get_larger_char(&s);
    let larger_c: char = s[0];
    let mut i = 0;
    //replace
    while i < s.len() && k > 0{

        if s[i] != larger_c{
            k -= 1;
        }

        while i < s.len() && s[i] != larger_c{
            s[i] = larger_c;
            i += 1;
        }

        //just skip
        while i < s.len() && s[i] == larger_c{
            i += 1;
        }
    }

    println!("{}", get_sum_hapiness(&s));
    //println!("{:?}", s);
}


Measured memory_bytes: 4352
import java.io.*;
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;

public class Main
{	
	public static void main(String []args)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		//String []s=br.readLine().split(" ");
		
		long N=Long.parseLong(br.readLine());
		//long W=Long.parseLong(s[1]);
		
		HashSet<String> set = new HashSet<String>();
		for(int i=0;i<N;i++)
			set.add(br.readLine());
		
		out.println(set.size());
		
	}
	
	
}




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

using namespace std;

int main() {
	int n, a[100];

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

	int count = 0;

	for (int i = 0; i < n; i++) {
		int minj = i;
		for (int j = i; j < n; j++) {
			if (a[minj] > a[j]) {
				minj = j;
			}
		}
		if (minj != i) {
			count++;
			swap(a[minj], a[i]);
		}
	}

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

	return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;

#define rep(i, n) for (int i=0; i<int(n); i++)
#define all(c) (c).begin(), (c).end()
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

struct BIT {
  int n;
  vector<long long> xs;
  BIT (int n) : n(n) {
    xs.resize(n+1);
  }
  void add(int i, long long v) {
    for (int x=i+1; x<=n; x+=x&-x) xs[x] += v;
  }
  long long sum(int i) {
    long long s = 0;
    for (int x=i+1; x>0; x-=x&-x) s += xs[x];
    return s;
  }
  long long sum(int a, int b) {
    return sum(b) - sum(a-1);
  }
};

int N;
int P[20000];
int A[20000], B[20000];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  rep(i, N) {
    cin >> P[i];
    P[i]--;
  }
  BIT a(N), b(N);
  b.add(0, 1000000000);
  for (int i=0; i<N; i++) {
    a.add(i, 1);
    b.add(i, -1);
  }
  for (int i=1; i<N; i++) {
    int x = P[i];
    a.add(x, i);
    if (x<N-1) b.add(x+1, -i);
  }
  rep(i, N) cout << a.sum(i) << (i==N-1?'\n':' ');
  rep(i, N) cout << b.sum(i) << (i==N-1?'\n':' ');
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int A,B,C,K;
  cin>>A>>B>>C>>K;
  int X[3]={A,B,C};
  sort(X,X+3);
  int sum=X[2];
  for(int i=1;i<=K;i++){
    sum=sum*2;
      }
      cout<<sum+X[0]+X[1]<<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 all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;

int main() {
  int n; cin >> n;
  vi score(n);
  rep(i,n) cin >> score[i];
  sort(all(score));
  int ans = accumulate(all(score), 0);
  if (ans%10 == 0) {
    rep(i,n) {
      if (score[i]%10) {
        ans -= score[i];
        break;
      }
    }
  }
  if (ans%10 == 0) ans = 0;
  cout << ans << endl;
  return 0;
}


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

int main(){
    int n;
    long a[100010], b, c, m, s;
    cin >> n;
    m = 1e9;
    s = 0;
    c = 0;
    for (int i = 0; i < n; ++i){
        cin >> a[i];
        b = abs(a[i]);
        s += b;
        if (a[i] < 0) c++;
        if (m > b) m = b;
    }
    cout << (s - 2*m*(c%2));
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int left = A + B;
  int right = C + D;
 
  if(right < left) cout << "Left" << endl;
  else if(right == left) cout << "Balanced" << endl;
  else cout << "Right" << endl;
}


Measured memory_bytes: 256
n, k, q = gets.split.map(&:to_i)
p = Array.new(n, 0)

q.times do
  p[gets.to_i - 1] += 1
end

n.times do |i|
  if k - q + p[i] > 0
    puts 'Yes'
  else
    puts 'No'
  end
end


Measured memory_bytes: 3196
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Runtime.ExceptionServices;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = ReadInt();
            if (x == 0) WriteLine(1);
            if (x == 1) WriteLine(0);
        }

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

int main(){
	long long X;
	cin >> X;
	
	long long tmp=0;
	for(int i=1;;i++){
		tmp+=i;
		if(tmp>=X){
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long int ll;
#define forn(i,p,n); for(long long i=p;i<n;++i)
#define rofn(i,p,n); for(long long i=p;i>n;--i)
#define pb push_back
#define vi vector<ll>

void solve(){
	ll n;
	cin >> n;
	vi a(n);
	forn(i,0,n) cin >> a[i];
	if(is_sorted(a.begin(),a.end())){
		cout<<0;
		return ;
	}
	ll ans = 0;
	forn(i,1,n){
		if(a[i-1]>a[i]){
			ans += a[i-1]-a[i];
			a[i] = a[i-1];
		}
	}
	cout<<ans;
}
 
int main()
{
	fast;
	// int test;
	// cin >> test;
	// while(test--){
		solve();
	// 	cout<<"\n";
	// }
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    string s,t;
    cin >> s >> t;
    REP(i,n)cout << s[i] << t[i];
    cout << endl;
    return 0;
}

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

int main(void) {
	int a,b,x;
	cin >> a >> b >> x;
	for(int i = 0; i < b; i++){
		if(a+i == x){
			cout << "YES" << "\n";
			return 0;
		}
	}
	cout << "NO" << "\n";
	return 0;
}

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

int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,m;
    cin >> n >> m;
    
    vector<int> mid;
    
    rep(i,m){
        int a,b;
        cin >> a >> b;
        if(a==1) mid.push_back(b);
        if(b==n) mid.push_back(a);
    }
    
    bool flag = false;
    sort(mid.begin(), mid.end());
    rep(i,mid.size()-1){
        if(mid[i]==mid[i+1]){
            flag = true;
            break;
        }
    }
    if(flag) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 1400