akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N, Q = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)

val = [0] * (N)
for _ in range(Q):
    p, x = map(int, input().split())
    p -= 1
    val[p] += x

used = [False]*N


def dfs(s):
    stack = []
    stack.append(s)
    while len(stack) > 0:
        now = stack[-1]
        used[now] = True
        stack.pop()
        for nxt in G[now]:
            if used[nxt]:
                continue
            val[nxt] += val[now]
            stack.append(nxt)


dfs(0)

answer = ' '.join(map(str, val[:]))
print(answer)


Measured memory_bytes: 121804
import java.io.BufferedReader
import java.io.InputStreamReader
import kotlin.math.min

fun main(omkar: Array<String>) {
    val jin = BufferedReader(InputStreamReader(System.`in`))
    val n = jin.readLine().toInt()
    val bracketLists = Array(2) { mutableListOf<Bracket>() }
    var overall = 0
    for (j in 1..n) {
        val s = jin.readLine()
        val delta = (2 * s.count { it == '(' }) - s.length
        overall += delta
        if (delta >= 0) {
            var m = 0
            var curr = 0
            for (chara in s) {
                when (chara) {
                    '(' -> curr++
                    ')' -> curr--
                }
                m = min(m, curr)
            }
            bracketLists[0].add(Bracket(delta, m))
        } else {
            var m = 0
            var curr = 0
            for (chara in s.reversed()) {
                when (chara) {
                    ')' -> curr++
                    '(' -> curr--
                }
                m = min(m, curr)
            }
            bracketLists[1].add(Bracket(-delta, m))
        }
    }
    if (overall != 0) {
        println("No")
        return
    }
    for (brackets in bracketLists) {
        brackets.sortByDescending { it.min }
        var curr = 0
        for (bracket in brackets) {
            if (curr + bracket.min < 0) {
                println("No")
                return
            }
            curr += bracket.delta
        }
    }
    println("Yes")
}

data class Bracket(val delta: Int, val min: Int)

Measured memory_bytes: 86372
#include <bits/stdc++.h>
#define Rep(i,j,n) for(int i=j; i<n; i++)
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100//000000000
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<int,P>
#define T tuple<int,int,int> 
using namespace std;

int main(){
  int h,w,k; cin >> h >> w >> k;
  vector<string> s(h);
  rep(i,h) cin >> s[i];

  int st[h];
  rep(i,h){
    int num=0;
    rep(j,w){
      if(s[i][j]=='#') num++;
    }
    st[i]=num;
  }

  int ans[h][w];
  int now=1;
  int cnt=0;
  int ind=0;
  while(st[ind++]==0) cnt++;

  Rep(i,cnt,h){
    if(st[i]==0){
      rep(j,w) ans[i][j]=ans[i-1][j];
    }
    else if(st[i]==1){
      rep(j,w) ans[i][j]=now;
      now++;
    }
    else{
      int pp;
      rep(j,w){
        ans[i][j]=now;
        if(s[i][j]=='#'){
          pp=j+1;
          break;
        }
      }
      for(int p=pp; p<w; p++){
        if(s[i][p]=='#') now++;
        ans[i][p]=now;
      }
      now++;
    }
  }

  rep(i,cnt){
    cout << endl;
    rep(j,w){
      printf("%d ",ans[cnt][j]);
    }
  }

  Rep(i,cnt,h){
    cout << endl;
    rep(j,w){
      printf("%d ",ans[i][j]);
    }
  }
  return 0;
}


Measured memory_bytes: 4236
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <math.h>
using namespace std;


int main() {

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

   }
  
  sort(a, a + 10, greater<int>()); 
  
   cout << a[0] << endl;
  cout << a[1] << endl;
  cout << a[2] << endl;
   
  return 0;
}


Measured memory_bytes: 3084
#include <stdio.h>
int main()
{
  int x = 0;
  int i = 0;
  
  while(1)
 {
    scanf("%d", &x);
    if( x == 0 ) break;
    i = i + 1;
    printf("Case %d: %d\n", i, x);
  }   
  return 0;
}

Measured memory_bytes: 600
#include <stdio.h>

int main(){
	int p[101],a,b,i;
	while(1){
		for(i = 0;i < 101;i++) p[i] = 0;
		p[1] = 1;
		p[2] = 1;
		while(1){
			if(scanf("%d %d",&a,&b) == EOF) return 0;
			if(!a && !b) break;
			p[a]++;
			p[b]++;
		}
		for(i = 1;i < 101;i++){
			if(p[i] % 2 == 1) {
				puts("NG");
				goto lend;
			}
		}
		puts("OK");
		lend:
		continue;
	}
	return 0;
}

Measured memory_bytes: 584
import java.util.Scanner;

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

    int cnt = 0;
    if (S.charAt(0) == '1')
      cnt++;
    if (S.charAt(1) == '1')
      cnt++;
    if (S.charAt(2) == '1')
      cnt++;

    System.out.println(cnt);

  }
}


Measured memory_bytes: 21716
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;

int DP[1500][1500] = {};

int main(){
	
	int H, W;
	cin >> H >> W;
	
	int ans = 0;
	
	for(int i = 1; i <= H; i++){
		for(int j = 1; j <= W; j++){
			int num;
			cin >> num;
			if(num == 1){
				DP[i][j] = 0;
				continue;
			}
			DP[i][j] = min(min(DP[i - 1][j], DP[i][j - 1]), DP[i - 1][j - 1]) + 1;
			ans = max(ans, DP[i][j]);
		}
	}
	
	cout << ans * ans << endl;
	
	return 0;
}


Measured memory_bytes: 11284
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int DP[100000] = {}, S[100000] = {};

int main(){
	
	int N;
	cin >> N;
	
	int a[20][20];
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			cin >> a[i][j];
		}
	}
	
	for(int i = 0; i < (1 << N); i++){
		for(int j = 0; j < N; j++){
			if(i & (1 << j)){
				for(int k = j + 1; k < N; k++){
					if(i & (1 << k)){
						S[i] += a[j][k];
					}
				}
			}
		}
		DP[i] = S[i];
	}
	
	for(int i = 0; i < (1 << N); i++){
		vector<int> v;
		for(int j = 0; j < N; j++){
			if(i & (1 << j)){
				v.push_back(j);
			}
		}
		int sz = v.size();
		for(int j = 0; j < (1 << sz); j++){
			int hoge = 0;
			for(int k = 0; k < sz; k++){
				if(j & (1 << k)){
					hoge += (1 << v[k]);
				}
			}
			DP[i] = max(DP[i], DP[hoge] + DP[i - hoge]);
		}
	}
	
	cout << DP[(1 << N) - 1] << endl;
	
	return 0;
}


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

using lli = long long;
using pii = pair<int, int>;
using pll = pair<lli, lli>;
using Double = long double;
template<typename T>
using Vector = vector<vector<T>>;
template<typename T>
using Prior = priority_queue<T>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;

#define IOS() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define X first
#define Y second
#define Push push_back
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()

void solve() {
	lli n, L, sum = 0;
	cin >> n >> L;

	vector<lli> v(n);
	for (auto &x : v) cin >> x, sum += x;

	int tok = -1;
	for (int i = 1; i < n; ++i) {
		if (v[i] + v[i - 1] >= L) {
			tok = i;
			break;
		}
	}

	if (tok == -1) {
		cout << "Impossible\n";
		return;
	}

	cout << "Possible\n";
	for (int i = 1; i < tok; ++i) cout << i << "\n";
	for (int i = n-1; i >= tok; --i) cout << i << "\n";
}

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

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

int main() {
  string s;
  int sum=0;
  while(s!="-"){
    string copy;
    int n;
    sum=0;
    cin>>s>>n;
    if(s=="-")return 0;
    copy=s;
    for(int i=0;i<n;i++){
      int a;
      cin>>a;
      sum+=a;
    }
    for(int j=0;j<s.size();j++){
      if(sum==s.size()){
        break;
      }else if(sum%s.size()+j<s.size()){
        copy[j]=s[j+sum%s.size()];
      }else{
        copy[j]=s[j+sum%s.size()-s.size()];
      }
    }
    cout<<copy<<endl;
  }
  return 0;
}


Measured memory_bytes: 3216
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int cnt =1;
    bool flag = 0;
    cin>>s;
    for(int i=0; i<3; i++)
    {
        if(s[i] == s[i+1])
        {
            cnt++;
        }
        else
        {
            cnt =1;
        }
        if(cnt == 3)
        {
            flag = 1;
            break;
        }
    }
    if(flag) cout<<"Yes\n";
    else cout<<"No\n";

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		int n = Integer.parseInt(s);
		
		for(int i=0; i<n; i++){
			s = sc.nextLine();
			s = s.replaceAll("Hoshino", "Hoshina");
			System.out.println(s);
		}
				
	}
} 

Measured memory_bytes: 17264
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

struct Edge {
    int from, to, w;

    Edge() {}
    Edge(int f, int t, int c) : from(f), to(t), w(c) {}
};

vector<Edge> w(5050);
vll d(3000);
int V, E;

bool bellman_ford(int s) {
    REP(i, V) d[i] = INF;
    d[s] = 0;

    REP(i, V) {
        REP(j, E) {
            Edge e = w[j];
            if (d[e.from] != INF && d[e.to] > d[e.from] + e.w) {
                d[e.to] = d[e.from] + e.w;

                if (i == V - 1) {
                    return true; // detect negative loop.
                }
            }
        }
    }

    return false; // no negative loops.
}

vector<vector<int>> graph(3000);
vector<bool> used(3000);

bool rec(int cur, int dst) {
    used[cur] = true;
    if (cur == dst) return true;

    bool ret = false;
    for (auto &e: graph[cur]) {
        if (used[e]) continue;
        ret |= rec(e, dst);
    }

    return ret;
}


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int P;
    cin >> V >> E >> P;

    vi A(E), B(E), C(E);
    REP(i, E) {
        cin >> A[i] >> B[i] >> C[i];
        A[i]--; B[i]--;
        graph[A[i]].pb(B[i]);
    }

    vector<bool> use(V, false);
    REP(i, V) {
        used.assign(V, false);

        if (rec(i, V - 1)) use[i] = true;
    }

    int j = 0;
    REP(i, E) {
        if (use[A[i]] && use[B[i]]) w[j++] = {A[i], B[i], P - C[i]};
    }

    if (!bellman_ford(0)) {
        print(max(0LL, -d[V - 1]));
    } else {
        print(-1);
    }


}


Measured memory_bytes: 3920
#include <bits/stdc++.h>
using namespace std;
#define maxx 100010
#define mp make_pair
typedef pair<long,long long> ii;
long long gas[310][310], dist[310][310];

long long n,m,l;
int main() {
	cin >> n >> m >> l;
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= n; j++){
			dist[i][j] = 1e11;
			gas[i][j] = 1e11;
		}
	}

	long long a,b,c;
	for(int i = 0; i < m; i++){
		cin >> a >> b >> c;
		gas[a][b] = c;
		gas[b][a] = c;
	}
	for(int k = 1; k <= n; k++){
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= n; j++){
				long long aux = min(gas[i][j],gas[i][k] + gas[k][j]);
				if(aux <= l) {dist[i][j] = 1; gas[i][j] = aux;}
			}
		}
	}
	for(int k = 1; k <= n; k++){
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= n; j++){
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);	
			}
		}
	}
	long long q;
	cin >> q;
	
	long long s,t;
	for(int i = 0; i < q; i++){
		cin >> s >> t;
		if(dist[s][t] == 1e11) cout << -1 << endl;
		else cout << dist[s][t]-1 << endl;
	}
	return 0;
}

Measured memory_bytes: 2048
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int[] a = new int[n];
		for(int i=0; i<n; i++){
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		int cnt = 0;
		while(x>0 && cnt<n){
			x -= a[cnt++];
		}
		System.out.println(x==0 ? cnt : cnt-1);
	}
}

Measured memory_bytes: 23892
s = input()

if (( s[0]==s[1] and s[2]==s[3] ) or ( s[1]==s[2] and s[0]==s[3] ) 
   or ( s[0]==s[2] and s[1]==s[3] )) :

    if ( s[0]==s[1] and s[1]==s[2] and s[2]==s[3] ) :

        print('No')

    else :

        print('Yes')
        
else :
    print('No')


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define RFOR(i,a,b) for(int i=(b-1); i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    int k; cin >> k;
    queue<ll> q;
    FOR(i,1,10) q.push((ll)i);
    rep(i,k-1){
        ll n = q.front(); q.pop();
        if(n % 10 != 0) q.push(10*n + n%10 - 1);
        q.push(10*n + n%10);
        if(n % 10 != 9) q.push(10*n + n%10 + 1);
    }
    cout << q.front() << endl;
}


Measured memory_bytes: 1792
/*
g++ -std=c++14 D.cpp && ./a.out <<< "3
1 2 3"
*/

#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for (int i = a; i < (b); i++)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

// Source: https://codeforces.com/blog/entry/62393
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);

    ll MOD = 1000000007LL;

    int n; cin >> n;
    vector<ll> A(n, 0);
    rep(i, 0, n) {
        ll x;
        cin >> x;
        A[i] = x;
    }

    ll ans = 0;

    rep(bi, 0, 61) {
        ll p = 0; ll q = 0;
        ll b = 1LL << bi;
        trav(a, A) {
            if ((a & b) == 0) q++; else p++;
        }

        ll curr = p * q % MOD;

        rep(bj, 0, bi)
            curr = (curr * 2LL) % MOD;

        ans += curr;
        ans %= MOD;
    }

    cout << ans << endl;
}

Measured memory_bytes: 2560
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n,k = mi()
p = li()
for i in range(n):
    p[i] = (p[i]+1) / 2
ans = 0
ima = 0
for i in range(k):
    ima += p[i]
ans = ima
for i in range(k,n):
    tmp1 = p[i]
    tmp2 = p[i-k]
    ima = ima +tmp1 -tmp2
    ans = max(ima,ans)
print(ans)


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

int main() {
  int N, K;
  scanf("%d%d", &N, &K);

  vector<int> buckets(N, 0);
  for (int i = 0; i < N; i++) {
    int A;
    scanf("%d", &A);
    buckets[A - 1]++;
  }

  sort(buckets.begin(), buckets.end(), greater<int>());

  int num = 0;
  for (int i = 0; i < K; i++) {
    // バケットから大きい順にK種類を取り出した際に、ボールが何個あるか
    num += buckets[i];
  }
  // 足りない分はボールの整数にかかわらず、書き換える
  int ans = N - num;
  printf("%d", ans);
  return 0;
}

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

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> a(M), b(M);
  vector<ll> bridge_num(N, 0);
  for (int i = 0; i < M; i++) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    bridge_num[a[i]]++;
    bridge_num[b[i]]++;
  }
  for (int i = 0; i < N; i++) {
    cout << bridge_num[i] << endl;
  }
  return 0;
}

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

#define ARC(i, a, b) for(int i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for(int i = (a) - 1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)

template<class T> T ant(const T &a, const T &b){ return a > b ? a : b; }
template<class T> T ont(const T &a, const T &b){ return a < b ? a : b; }
template<class T> T rng(const T &a, const T &b){ return a > b ? a - b : b - a; }
template<class T> T &anth(T &a, const T &b){ return a = ant(a, b); }
template<class T> T &onth(T &a, const T &b){ return a = ont(a, b); }

int main(){
	int n, m, c;
	int b[30];
	int count = 0;
	scanf("%d%d%d", &n, &m, &c);
	RC(i, m) scanf("%d", b + i);
	RC(i, n){
		int l = c;
		RC(i, m){
			int a;
			scanf("%d", &a);
			l += a * b[i];
		}
		if(l > 0) ++count;
	}
	printf("%d\n", count);
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<set>
#include<bitset>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
char ch[100005];
ll cnt[50];
int main(){
    int n;
    cin>>n;
    scanf("%s",ch);
    for(int i=0;i<n;i++)cnt[ch[i]-'a']++;
    ll ans=1;
    for(int i=0;i<26;i++){
        ans=ans*((cnt[i]+1)%mod);
        ans%=mod;
    }
    cout<<(ans-1+mod)%mod<<endl;
    return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner scn = new Scanner(System.in);
        int k = scn.nextInt();
        String s = scn.next();

        if(s.length()>k){
            System.out.println(s.substring(0,k)+"...");
        }else{
            System.out.println(s);
        }

            scn.close();
    }
}

Measured memory_bytes: 27068
import java.util.Scanner;

public class Main{
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int M = sc.nextInt();
		int C = sc.nextInt();
		
		int[] listB = new int[M];
		int[][] listA = new int[N][M];
		
		for(int i = 0 ; i < M; i++) {
			listB[i] = sc.nextInt();
		}
		
		for(int i = 0 ; i < N; i++) {
			for(int j = 0; j < M; j++) {
				listA[i][j] = sc.nextInt();
			}
		}
		
		int res = 0;
		
		for(int sources = 0; sources < N; sources++) {
			int count = 0;
			for(int i = 0; i < M; i++) {
				count+=listA[sources][i]*listB[i];
			}
			if((count + C) > 0) {
				res++;
			}
		}
		System.out.println(res);
	}
}

Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define tc() int t; cin>>t; while(t--)
#define print(n) cout<<n<<"\n"
#define inp(n) int n; cin>>n
#define all(cont) cont.begin(), cont.end()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define mp make_pair
#define pb push_back
#define maxn 1000010
#define f  first
#define s  second
#define fora(var, start, end) for(int var = start; var < end; var++)
int main()
{
    inp(n);
    vector<int> v(n);
    fora(i,0,n)cin>>v[i];
    sort(all(v)); int res=0,num,sum;
    fora(i,0,n-2)
    {
        fora(j,i+1,n)
       { 
         sum=v[i]+v[j];
         num= lower_bound(all(v),sum)-(v.begin()+j-1);
         if(num>2) res+=(num-2);
        // res+= ((num*(num-1)*(num-2))/6);
         //cout<<num<<" ";
}
//cout<<endl;

    }
    print(res);

    return 0;
}

Measured memory_bytes: 256
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    token.parse().ok().unwrap()
}

fn main() {
    let n = input::<i64>();
    let k = input::<i64>();

    println!("{}", if n % k == 0 { 0 } else { 1 });
}


Measured memory_bytes: 4352
# -*- coding: utf-8 -*-
import sys 
from collections import defaultdict
sys.setrecursionlimit(10**6)
MOD = 10**9+7 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
K = int(readline())
cnt = 0
N = 7
for i in range(K+1):
    if N % K == 0:
        print(i+1)
        sys.exit()
    N = (N*10+7) % K
print(-1)

Measured memory_bytes: 66160
#include <bits/stdc++.h> 
#define ll long long
#define F first
#define FF first.first
#define FS first.second
#define S second
#define pb push_back
using namespace std;
const int N=1000006, INF=1e16;
 
ll n, q=1, m, a[N], b[N], f[N], o, k, t, x, y, z, u, h, mx, mn, ans, Ans;
pair<ll,ll> p[N];
string s, S;
vector<int> v[N], V;
 
main(){ios_base::sync_with_stdio(false), cin.tie(0);
   	
//	cin>>q;
   	
   	while(q--){ans=o=0;
   		cin>>s>>S;
   		
   		
   		if((s+S[S.size()-1])==S){
			cout<<"Yes"<<endl;
		}else{
			cout<<"No"<<endl;
		}
	}
	
}

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

using namespace std;

typedef long long ll;
typedef vector<int> pi;
typedef pair<int,int> vi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(vi c, vi d){
	return c.S < d.S;
}

int main() {
	int N, L;
	cin >> N >> L;
	
	string a;
	vector<string> s;
	REP(i, 0, N){
		cin >> a;
		s.PB(a);
	}
	sort(s.begin(), s.end());
	
	string end = "";
	REP(i, 0, N) end += s[i];
	
	cout << end;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = Integer.parseInt(sc.next());
        // String s = sc.next();
        // int[] a = new int[n];
        // for (int i = 0; i < n; i++) {
        // a[i] = Integer.parseInt(sc.next());
        // }
        long ans = 0;
        for (int x = 1; x <= k; x++) {
            for (int y = 1; y <= k; y++) {
                for (int z = 1; z <= k; z++) {
                    int tmp = gcd(x, y);
                    tmp = gcd(tmp, z);
                    ans += tmp;
                }
            }
        }

        System.out.println(ans);
        sc.close();
    }

    static int gcd(int a, int b) {
        int temp;
        while ((temp = a % b) != 0) {
            a = b;
            b = temp;
        }
        return b;
    }
}

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

LL mod = 1000000007;

int main()
{
	LL n, m;
	cin >> n >> m;

	if (m < n) {
		cout << "No\n";
	}
	else {
		cout << "Yes\n";
	}

	
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



const int N = 2e5+10;
int n, b[N], s[2][N];
vector<int> g[N];
int c0[N<<2],c1[N<<2],pos[N<<2];
void build(int o, int l, int r) {
	c0[o] = c1[o] = INF;
	if (l==r) pos[l] = o;
	else build(ls),build(rs);
}
int qry(int *c, int o, int l, int r, int ql, int qr) {
	if (ql<=l&&r<=qr) return c[o];
	if (mid>=qr) return qry(c,ls,ql,qr);
	if (mid<ql) return qry(c,rs,ql,qr);
	return min(qry(c,ls,ql,qr),qry(c,rs,ql,qr));
}
void upd(int *c, int o, int v) {
	o = pos[o];
	c[o] = min(c[o], v);
	while (o>>=1) c[o] = min(c[lc],c[rc]);
}
int main() {
	scanf("%d",&n);
	REP(i,1,n) { 
		scanf("%d",b+i);
		s[0][i]=s[0][i-1];
		s[1][i]=s[1][i-1];
		++s[b[i]][i];
	}
	build(1,0,n),upd(c0,0,0),upd(c1,0,0);
	int q;
	scanf("%d",&q);
	while (q--) {
		int l, r;
		scanf("%d%d", &l, &r);
		g[l].pb(r);
	}
	int ans = s[1][n];
	REP(l,1,n) for (int r:g[l]) {
		int x = qry(c0,1,0,n,l,r)+s[0][r];
		x = min(x, qry(c1,1,0,n,0,l-1)+s[0][r]-s[0][l-1]+s[1][l-1]);
		upd(c0,r,x-s[0][r]);
		upd(c1,r,x-s[1][r]);
		ans = min(ans, x+s[1][n]-s[1][r]);
	}
	printf("%d\n", ans);
}








Measured memory_bytes: 19328
#include<iostream>
#include<algorithm>
#define fi        first
#define se        second
#define pb        push_back
#define PI        acos(-1)
#define LC(a)     ((a<<1))
#define RC(a)     ((a<<1)+1)
#define MID(a,b)  ((a+b)>>1)
#define mem(a, b) memset(a, b, sizeof(a))
#define IOS()     std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<ll,ll>   PLL;
typedef pair<ll,int>  PLI;
const int INF = 0X3F3F3F3F;
const int MIN = -(1<<30);
const ll N = 1e5+7;
int a[N],b[N];
inline void solve()
{
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=m;i++) cin>>b[i];
	int ans = INF;
	while(k--)
	{
		int x,y,c;
		cin>>x>>y>>c;
		ans = min(ans,a[x]+b[y]-c); 
	//	cout<<ans<<endl; 
	}
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	ans = min(ans,a[1]+b[1]);
	cout<<ans<<endl;
}
int main()
{
	IOS();
	solve();
	return 0;
}




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

typedef long long ll;
const ll QAQ=1000000007;

ll f[100005],b[100005],n,m,a;

int main()
{
    ios::sync_with_stdio(false);
    cin >> n >> m;
    for (ll i=0;i<m;++i)
    {
        cin >> a;
        b[a]=1;
    }
    f[0]=1;
    if (!b[1]) f[1]=1;
    for (ll i=2;i<=n;++i)
    {
        if (b[i]) f[i]=0;
        else f[i]=(f[i-1]+f[i-2])%QAQ;
    }
    cout << f[n] << endl;
    system("PAUSE");
    return 0;
}

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

using namespace std;
string st;
int cs[90+5],s,P;
int main()
{
	cin>>st;
	for(int i=0;i<st.length();i++)
	{
		cs[st[i]]++;
		if(s==0)
		{
			if(st[i]==67)P=1;
			else if(P==1&&st[i]==70)P=3,s=1;
			else if(st[i]==70)P=2;
		}
		else break;
	}
	if(cs[67]>=1&&cs[70]>=1&&P==3)cout<<"Yes\n";
	else cout<<"No\n";
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main()
{
    int n;
    scanf("%d", &n);
    int ans;
    if (n % 2 == 0) ans = n;
    else ans = n*2;
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
     
    using namespace std;
     
    long long ab(long long x){ return (x < 0)?-x:x; }
     
    int main() {
      int n;
      cin >> n;
     
      long long arr[200200];
      long long mini = -1000000001, maxi = 1000000001;
     
      for (int i = 0; i < n; i++) {
        scanf("%lld", &arr[i]);
      }
     
     
      long long ans = -1;
     
      while (mini < maxi) {
        // cout << mini << " " << maxi << endl;
        long long l = (2*mini + maxi) / 3;
        long long r = (mini + 2*maxi) / 3;
     
        long long suml = 0, sumr = 0;
     
        for (int i = 0; i < n; i++) {
          suml += ab(arr[i] - i - l);
          sumr += ab(arr[i] - i - r);
        }
     
        // cout <<  "suml: " << suml << endl;
        // cout << "sumr: " << sumr << endl;
     
        if (suml < sumr) {
          if (maxi == r) break;
          maxi = r;
          ans = suml;
        } else {
          if (mini == l) break;
          mini = l;
          ans = sumr;
        }
      }
      printf("%lld\n", ans);
     
     
      return 0;
    }

Measured memory_bytes: 1792
class Dice:
    def __init__(self,dim=list(range(1,7))):
        self.dim = dim

    def roll(self,direction):
        if direction == "N":
            buff = self.dim[0]
            self.dim[0] = self.dim[1]
            self.dim[1] = self.dim[5]
            self.dim[5] = self.dim[4]
            self.dim[4] = buff

        if direction == "E":
            buff = self.dim[3]
            self.dim[3] = self.dim[5]
            self.dim[5] = self.dim[2]
            self.dim[2] = self.dim[0]
            self.dim[0] = buff

        if direction == "W":
            buff = self.dim[0]
            self.dim[0] = self.dim[2]
            self.dim[2] = self.dim[5]
            self.dim[5] = self.dim[3]
            self.dim[3] = buff

        if direction == "S":
            buff = self.dim[0]
            self.dim[0] = self.dim[4]
            self.dim[4] = self.dim[5]
            self.dim[5] = self.dim[1]
            self.dim[1] = buff

lst = list(map(int,input().split()))

D = Dice(lst)
code = input()
for i in code:
    D.roll(i)

print(D.dim[0])


Measured memory_bytes: 5612
#include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < (N); i++)
#define swap(a, b) (a += b, b = a - b, a -= b)
using namespace std;
int main()
{
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, N)
    {
        cin >> a[i];
    }
    int i = 0, j = 1, sum = 0, count = 1;
    while (j < N)
    {
        if (a[i] == a[j])
        {
            count++;
            j++;
        }
        else
        {
            sum += (count / 2);
            count = 1;
            i = j;
            j = i + 1;
        }
    }
    sum += count / 2;
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long
constexpr int ctoi(char c) {
    if ('0' <= c && c <= '9') return c - '0';
    return -1;
}

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

    unsigned long long a, b;
    string sb;
    cin >> a >> sb;
    b = stoi(sb.erase(1, 1));

    const unsigned long long ans = (a * b) / 100;

    cout << ans << endl;
}


Measured memory_bytes: 3656
from sys import stdin
input = stdin.readline
N, D = map(int, input().split())

X=[0]*N
Y=[0]*N
c=0
for i in range(N):
    X[i], Y[i] = map(int, input().split())
    if D**2>=X[i]**2+Y[i]**2:c=c+1 

print(c)

Measured memory_bytes: 24464
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int,int,int,int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
int ddx[]={2,2,-2,-2,1,1,-1,-1},ddy[]={1,-1,1,-1,2,-2,2,-2};

int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	if(a>b)swap(a,b);
	if((b-a)&1)return !printf("IMPOSSIBLE");
	printf("%d",(b+a)>>1);
}

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

typedef pair<int,int> P;

int main() {
  for(int N, Q; cin >> N >> Q, N || Q; ) {
    map<string, P> database;
    for(int i = 0; i < N; i++) {
      string ename; int eyear, wyear;
      cin >> ename >> eyear >> wyear;
      if(database.count(ename)) {
        database[ename] = P(wyear - eyear + 1, max(database[ename].second, wyear));
      }
      else {
        database[ename] = P(wyear - eyear + 1, wyear);
      }
    }
    while(Q--) {
      int y; cin >> y;
      bool ok = false;
      for(pair<string, P> item : database) {
        if(item.second.first <= y && y <= item.second.second) {
          ok = true;
          cout << item.first << ' ' << (y - item.second.first + 1) << endl;
        }
      }
      
      if(!ok) {
        cout << "Unknown" << endl;
      }
    }
  }
}

Measured memory_bytes: 1340
class Node:
    def __init__(self, key, parent=None, left=None, right=None):
        self.key = key
        self.parent = parent
        self.left = left
        self.right = right

class Tree:
    root = None
    preorder_list = []
    inorder_list = []
    def __init__(self):
        pass
    def insert(self, node):
        y = None
        x = self.root

        while x is not None:
            y = x
            if node.key < x.key:
                x = x.left
            else:
                x = x.right
        node.parent = y

        if y == None:
            self.root = node
        elif node.key < y.key:
            y.left = node
        else:
            y.right = node

    def display(self):
        #print(self.root, self.root.key, self.root.parent, self.root.left, self.root.right)
        self.inorder(self.root)
        self.preorder(self.root)
        print(' '+' '.join(map(str, self.inorder_list)))
        print(' '+' '.join(map(str, self.preorder_list)))
        pass

    def preorder(self, node):
        if node == None:
            return
        self.preorder_list.append(node.key)
        if node.left is not None:
            self.preorder(node.left)
        if node.right is not None:
            self.preorder(node.right)

    def inorder(self, node):
        if node == None:
            return
        if node.left is not None:
            self.inorder(node.left)
        self.inorder_list.append(node.key)
        if node.right is not None:
            self.inorder(node.right)

n = int(input())
command_list = [list(input().split()) for _ in range(n)]

tree = Tree()
for command in command_list:
    if command[0] == 'insert':
        node = Node(int(command[1]))
        tree.insert(node)
        #print(node, node.key, node.parent, node.left, node.right)
    if command[0] == 'print':
        tree.display()
        tree.preorder_list = []
        tree.inorder_list = []






Measured memory_bytes: 258788
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

ll dist(ll x1, ll y1, ll x2, ll y2) {  // (x1, y1) と (x2, y2) のマンハッタン距離
    return abs(x1 - x2) + abs(y1 - y2);
}

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

    vector<P> p(n);
    rep(i, n) {
        ll a, b;
        cin >> a >> b;
        p[i] = make_pair(a, b); 
    }
    
    vector<P> q(m);
    rep(i, m) {
        ll a, b;
        cin >> a >> b;
        q[i] = make_pair(a, b); 
    }

    rep(i, n) {
        ll id = 0;  // i番目の学生が訪れるチェックポイント番号
        ll len = INF;
        ll x1 = p[i].first;
        ll y1 = p[i].second;
        rep(j, m) {
            ll x2 = q[j].first;
            ll y2 = q[j].second;
            if(dist(x1, y1, x2, y2) < len) {
                len = dist(x1, y1, x2, y2);
                id = j+1;
            }   
        }
        out(id);
    }

    re0;
}

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

int main()
{
	
	int n;
	cin >> n;
	vector<ll> A(n+2);
	for(int i = 0;i<n;i++)cin >> A[i+1];

	ll ans = 0;
	for(int i = 0 ;i<n+1;i++)
	{
		ans += abs(A[i]-A[i+1]);
	}

	for(int i = 0;i<n;i++)
	{
		ll a = abs(A[i]-A[i+1])+abs(A[i+1]-A[i+2]);
		ll b = abs(A[i]-A[i+2]);
		cout<<ans+b-a<<endl;
	}
	return 0;
}


Measured memory_bytes: 2048
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define l long
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<int,int>
#define maxn 100005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace std;
using namespace __gnu_pbds;

signed main()
{
    fast;
    
    ll k , n;
    cin>>n>>k;
    ll dig = (ll)(floor( log(n) /  
                         log(k)) + 1); 
    cout<<dig;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int gcd(int a, int b)
{
  if (a%b == 0)
  {
    return(b);
  }
  else
  {
    return(gcd(b, a%b));
  }
}
int lcm(int a, int b)
{
  return a * b / gcd(a, b);
}

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

  vector<int> A(N);
  REP(i, N) cin >> A[i];
  
  int ans = gcd(A[0],A[1]);
  REP(i,N){
    ans = gcd(ans,A[i]);
  }

  cout << ans << endl;
}

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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int h, w;
	cin >> h >> w;

	vector<string> g(h);
	for (int i = 0; i < h; i++) {
		cin >> g[i];
	}

	ll ans = 0;

	vector<vector<bool>> used(h, vector<bool>(w));
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (used[i][j]) {
				continue;
			}

			queue<pair<int, int>> que;
			que.emplace(i, j);
			used[i][j] = true;

			ll wCnt = 0, bCnt = 0;
			while (!que.empty()) {
				pair<int, int> now = que.front(); que.pop();
				int y = now.first, x = now.second;
				if (g[y][x] == '.') {
					wCnt++;
				} else {
					bCnt++;
				}

				for (int k = 0; k < 4; k++) {
					int ny = y + dy[k];
					int nx = x + dx[k];

					if (ny < 0 || ny >= h || nx < 0 || nx >= w) {
						continue;
					}
					if (used[ny][nx] || g[y][x] == g[ny][nx]) {
						continue;
					}

					used[ny][nx] = true;
					que.emplace(ny, nx);
				}
			}

			ans += wCnt * bCnt;
		}
	}

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


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
const int SIZE=205;
//int arr[SIZE]={};
//ここまでテンプレ
int main(){
	int X,t;
	cin>>X>>t;
	cout<<max(X-t,0)<<endl;
    return 0;
}

Measured memory_bytes: 256
sx,sy , tx , ty = map(int,input().split())
ans = ''
ans += 'R'*(tx - sx)
ans += 'U'*(ty - sy)
ans += 'L'*(tx - sx)
ans += 'D'*(ty - sy)

ans += 'D'
ans += 'R'*(tx - sx+1) 
ans += 'U'*(ty - sy+1)
ans += 'L'


ans += 'U'
ans += 'L'*(tx - sx+1) 
ans += 'D'*(ty - sy+1)
ans += 'R'
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<typename T> using rev_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class S, class T> void map_init(map<S, T> &m, S k, T v){if(!m.count(k)) m[k] = v;}
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }
int main() {
    int N;
    cin >> N;
    vector<i64> A(N);
    for(auto &x : A) cin >> x;
    i64 ans = 0;
    for(int i = 0; i < N; i++) {
        if(i && A[i - 1] && A[i]) {
            A[i]--;
            ans++;
        }
        ans += A[i] / 2;
        A[i] %= 2;
    }
    cout << ans << endl;
    return 0;
}


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


int main(){
  int j,i,n,*A,count,swap,oldcount;
  scanf("%d",&n);
  A=malloc(n*sizeof(int));
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  for(i=0;i<n-1;i++){
    oldcount=count;
    for(j=n-1;j>=i+1;j--){
      if(A[j]<A[j-1]){
        swap=A[j];
        A[j]=A[j-1];
        A[j-1]=swap;
        count+=1;
      }
    }
    if(oldcount==count) break;
  }
  for(i=0;i<n-1;i++) printf("%d ",A[i]);
  printf("%d\n",A[n-1]);
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
//#include<iostream>
//#include<cstdio>
//#include<cstring>
//#include<cstdlib>
//#include<algorithm>
//#include<vector>
//#include<queue>
//#include<stack>
//#include<map>
//#include<set>
using namespace std;
#define SC scanf
#define PR printf
#define pb push_back
#define mp make_pair
#define SZ(v) ((int)(v).size())
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define uint unsigned
#define ll long long
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef pair<pii,pii> ppp;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef map<int,int> mii;
const int INF=0x3f3f3f3f;
const ll LL_INF=0x3f3f3f3f3f3f3f3f;
const int xx[4]={1,-1,0,0};
const int yy[4]={0,0,1,-1};
int inline in(){
	int x=0,c;
	for(;(uint)((c=getchar())-'0')>=10;){
		if(c=='-')return -in();
		if(!~c)throw ~0;
	}
	do{
		x=(x<<3)+(x<<1)+(c-'0');
	}while((uint)((c=getchar())-'0')<10);
	return x;
}
int main(){
    ios::sync_with_stdio(false);
	int n,d;
	cin>>n>>d;
	cout<<(n+2*d)/(2*d+1)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define     ll      long long
ll v[400001];


int main()
{
    string x;
    ll n,a,b,c,d,sum=0,sum2=0;
    cin>>n;
    set<string>s;
    set<string>it;
    for(int i=0;i<n;i++){
        cin>>x;
        s.insert(x);
    }
    cout<<s.size()<<endl;
    return 0;
}


Measured memory_bytes: 19212
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef double dbl;
typedef vector<bool> Vb;
typedef vector<char> Vc;
typedef vector<double> Vd;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<string> Vs;
typedef vector<vector<int>> VVi;
typedef vector<vector<ll>> VVl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;

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 (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }
inline void YES() { cout << "YES" << endl; } inline void Yes() { cout << "Yes" << endl; }
inline void NO() { cout << "NO" << endl; } inline void No() { cout << "No" << endl; }

const int inf = 1 << 30;
const ll linf = 1LL << 60;
const int MOD = 1000000007;

int n;
Vi vh;


void init()
{
	cin >> n;
	vh.resize(n + 1, 0);
	REP1C(i, n) cin >> vh[i];
}

void print()
{
	REP(i, n + 1) cout << vh[i] << " ";
	cout << endl;
}

int main()
{
	init();

	REP1C(i, n)
	{
		if (vh[i - 1] < vh[i])
		{
			if (vh[i] <= vh[i + 1] + 1)
				--vh[i];
		}

		if (vh[i - 1] > vh[i])
		{
			No();
			return 0;
		}

	}

	Yes();
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,ans=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        int a,b;
        cin>>a>>b;
        ans+=b-a+1;
    }
    cout<<ans<<endl;
    return 0;
}

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

int main()
{
   /// BISMILLAHIR RAHMANIR RAHIM
    ll a;
    long double b,ans;
    cin>>a>>b;
    ans=a*b;
    ll bns=ans;
    cout<<bns<<endl;


    /// ALHAMDULILLAH
}


Measured memory_bytes: 3720