akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
const ll INF=1e9+7;
const ll N = 300003;

class comb{
	vector<ll> f,fr;
	ll MOD;
	public:
	//a^(p-1) = 1 (mod p)(p->Prime numbers)
	//a^(p-2) = a^(-1)
	ll calc(ll a,ll b,ll p){//a^(b) mod p   
		if(b==0)return 1;
		ll y = calc(a,b/2,p);y=(y*y)%p;
		if(b & 1) y = (y * a) % p;
		return y;
	}
	void init(ll n,ll mod){
		MOD = mod;
		f.resize(n+1);
		fr.resize(n+1);
		f[0]=fr[0]=1;
		for(ll i=1;i<n+1;i++){
			f[i] = (f[i-1] * i) % mod;
			fr[i] = calc(f[i],mod-2,mod);
		}
	}
	ll nCr(ll n,ll r){
		return f[n] * fr[r] % MOD * fr[n-r] % MOD;
	}
};
const ll so = 998244353;
ll n,a,b,k,ans=0;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>a>>b>>k;
	if(k==0){
		cout<<1<<endl;
		return 0;
	}
	comb c;
	c.init(n,so);
	FOR(i,0,n+1){//A i ko
		ll j = (k-i*a);
		if(j%b!=0)continue;
		if(j<0||j>n*b)continue;
		j = j / b;
		ans += c.nCr(n,i) * c.nCr(n,j) % so;
		ans = ans % so;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4992
n = int(input())
x = [0]*n
y = [0]*n

for i in range(n):
    x[i], y[i] = map(str, input().split())
ans = 0
for i in range(n):
    if y[i] == "JPY":
        ans += float(x[i])
    else:
        ans += float(x[i])*380000

print(ans)

Measured memory_bytes: 3064
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j,k;
  int A[N+1];
  scanf("%d", &n);

  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
  
  for(int j=1;j<=n;++j){
  	k=A[j];
  	i=j-1;
	while( i>=0 && A[i]>k){
		A[i+1] = A[i];
		--i;
		
		
	}
	
	A[i+1] = k;
	trace(A,n);
	
  }
  

  return 0;
}

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

int main(){

    int n;
    cin>>n;
   int r=n%10;
   if(r==2||r==4||r==5||r==7||r==9){
    cout<< "hon"<<endl;
   }
   else if(r==0||r==1||r==6||r==8){
    cout<< "pon"<<endl;
   }
   else if(r==3){
    cout<< "bon"<<endl;
   }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,m,n) for (int i = m; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
inline int popcount(const int x) { return __builtin_popcount(x);}
template<class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b;}
template<class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b;}
template<class T> void drop(const T &x) { std::cout<<x<<endl; exit(0);}
void debug_out() { std::cout << "\n";}
template<class T, class... Args> void debug_out(const T &x, const Args &... args) { std::cout<<x<< " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

struct InitIO{
  InitIO() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
  }
}init_io;

int main() {
  int l, r, d;
  cin >> l >> r >> d;
  int num1 = r/d;
  int num2 = (l-1)/d;
  cout << num1 - num2 << endl;
  return 0;
}

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

int main() {
  int N, Q;
  cin >> N >> Q;
  int a, b;
  vector< vector<int> > AB(N + 5, vector< int >());
  for (int i = 0; i < N - 1; i++) {
    cin >> a >> b;
    AB[a].push_back(b);
    AB[b].push_back(a);
  }
  int p, x;
  int Score[200005] = {};
  for (int j = 0; j < Q; j++) {
    cin >> p >> x;
    Score[p] += x;
  }
  
  vector<int> Now;
  vector<int> Next{1};
  bool Exists[200005] = {};
  Exists[1] = true;
  
  while (! Next.empty()) {
    Now = Next;
    Next.clear();
    for (int nw : Now) {
      for (int nxt : AB[nw]) {
        if (! Exists[nxt]) {
          Exists[nxt] = true;
          Score[nxt] += Score[nw];
          Next.push_back(nxt);
        }
      }
    }
  }
  
  for (int i = 1; i <= N; i++)
    cout << Score[i] << " ";
  cout << endl;
  return 0;
}

Measured memory_bytes: 16628
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int H, W;
bool dp[81][81][25700];
int cost[81][81];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> H >> W;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> cost[i][j];
        }
    }
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            int tmp;
            cin >> tmp;
            cost[i][j] -= tmp;
        }
    }

    int s = H + W - 1;
    dp[0][0][80 + cost[0][0]] = true;
    dp[0][0][80 - cost[0][0]] = true;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            for(int k = 0; k <= s * 160; k++){
                if(!dp[i][j][k]) continue;
                dp[i + 1][j][k + 80 + cost[i + 1][j]] = true;
                dp[i][j + 1][k + 80 + cost[i][j + 1]] = true;
                dp[i + 1][j][k + 80 - cost[i + 1][j]] = true;
                dp[i][j + 1][k + 80 - cost[i][j + 1]] = true;
            }
        }
    }

    int ans = inf;
    for(int i = 0; i <= s * 160; i++){
        if(!dp[H - 1][W - 1][i]) continue;
        chmin(ans, abs(i - s * 80));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 163712
def examA():
    x, y = LI()
    ans = 0
    if x<0 and y<0:
        if x<=y:
            ans = y-x
        else:
            ans = x-y+2
    elif x<0 and 0<=y:
        if -x<=y:
            ans = y+x+1
        else:
            ans = min(-(x+y)+1,y-x)
    elif y<=0:
        ans = abs(y+x)+1
    else:
        if x<=y:
            ans = y-x
        else:
            ans = x-y+2
    print(ans)
    return

def examB():
    B, K = LI()
    A = LI()
    cumA = [0]*(B+1); negA = [0]*(B+1)
    for i,a in enumerate(A):
        cumA[i+1] = cumA[i]
        negA[i+1] = negA[i]
        if a>0:
            cumA[i+1] +=a
        else:
            negA[i+1] +=a
    ans = 0
    for i in range(B-K+1):
        curC = cumA[K+i]-cumA[i]; curN = negA[K+i]-negA[i]
        now1 = cumA[B] + curN
        now2 = cumA[B] - curC
#        print(now1,now2)
        ans = max(ans,now1,now2)
    print(ans)
    return

def examC():
    Ai,Ao,At,Aj,Al,As,Az = LI()
    ans = 0
    ans += Ao
    ans += (Ai//2 + Aj//2 + Al//2)*2
    if Ai>=1 and Aj>=1 and Al>=1:
        if Ai%2 + Aj%2 + Al%2==3:
            ans += 3
        elif Ai%2 + Aj%2 + Al%2==2:
            ans +=1
    print(ans)
    return

def examD():
    N = I()
    X = LI()
    A = [0]*(N**2)
    que = deque()
    ans = "Yes"
    need = [0]*(N**2)
    for i in range(N):
        need[X[i]-1] = i
    for i in range(N):
        A[X[i]-1] = (i+1)
#    print(need); print(A)
    X.sort()
    k = 0
    for i in range(N):
        cur = need[X[i]-1]
        for j in range(cur):
            while(A[k]!=0):
                k +=1
            A[k] = A[X[i]-1]
        if k>=X[i]:
            ans = "No"
            break
        res = N-1-cur
        que.append((res,i))
#    print(que);  print(A)
    loop = 0
    if ans=="No":
        print(ans)
        return
    while(que and k<N**2 and loop<10**6):
        loop +=1
        cur,i = que.popleft()
        while (k<N**2 and A[k] != 0):
            k += 1
#        print(k,A[X[i]-1])
        if k<X[i] and cur>0:
            que.append((cur,i))
            continue
        for j in range(cur):
            while(k<N**2 and A[k]!=0):
                k +=1
            A[k] = A[X[i]-1]
    if que or loop>=10**6:
        ans = "No"
    if ans=="No":
        print(ans)
        return
    else:
        print(ans)
        print(" ".join(map(str,A)))
    return
"""
3
6 7 8
"""
import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18

if __name__ == '__main__':
    examD()


Measured memory_bytes: 24436
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define mem(a,b) memset((a),(b),sizeof(a))
#define MP make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) x.size()
#define all(x) x.begin(),x.end()
using namespace std;
#define _GLIBCXX_PERMIT_BACKWARD_HASH
#include <ext/hash_map>
using namespace __gnu_cxx;
struct str_hash{size_t operator()(const string& str)const{return __stl_hash_string(str.c_str());}};
typedef long long ll;
typedef unsigned long long ull;
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PDD pair<double,double>
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-6;
const int MAX=1e5+10;
const ll mod=1e9+7;
char s[MAX];
int main()
{
	int i,len,a[5];
	while(~scanf("%s",s))
	{
		len=strlen(s);
		mem(a,0);
		for(i=0;i<len;i++)
		{
			a[s[i]-'a']++;
		}
		sort(a,a+3);
		if(a[2]-a[0]>=2) puts("NO");
		else puts("YES");
	}
	return 0;
}

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

int main(){

    int H, W;
    cin >> H >> W;
    vector<vector<int> > a(H, vector<int>(W));
    for(int i = 0; i < H; i++) for(int j = 0; j < W; j++) cin >> a[i][j];

    using point = pair<int, int>;
    vector<pair<point, point> > ans;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(a[i][j] % 2 == 1){
                if((j + 1) != W){
                    a[i][j]--;
                    a[i][j + 1]++;
                    point p1 = make_pair(i + 1, j + 1);
                    point p2 = make_pair(i + 1, j + 2);
                    ans.push_back(make_pair(p1, p2));
                }else if((i + 1) != H){
                    a[i][j]--;
                    a[i + 1][j]++;
                    point p1 = make_pair(i + 1, j + 1);
                    point p2 = make_pair(i + 2, j + 1);
                    ans.push_back(make_pair(p1, p2));
                }
            }
        }
    }

    cout << ans.size() << endl;
    for(int i = 0; i < ans.size(); i++) cout << ans[i].first.first << " " << ans[i].first.second << " " << ans[i].second.first << " " << ans[i].second.second << endl; 

    return 0;
}



Measured memory_bytes: 5232
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll,pair<ll, ll>> lpll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;

#define deg_to_rad(deg) (((deg)/360)*2*PI)

const ll LINF = LLONG_MAX;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;

const ld PI = (acos(-1));
const ld EPS = 0.0000000001;
// cout << fixed << setprecision(10) << middle << endl;

int main() {
    // input, ready
    int X,Y;
    cin >> X >> Y;
    for (int i=0; i<=X; i++){
        if (Y== i*4+(X-i)*2) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    // output

    return 0;
}


Measured memory_bytes: 3644
#include <stdio.h>

int asc(const void *a, const void *b) {
  long long int *A = (long long int*)a;
  long long int *B = (long long int*)b;
  if (*A > *B) return 1;
  if (*A < *B) return -1;
  return 0;
}

int main() {

	int N, i;
	long long int *A;

	scanf("%d", &N);
	A = (long long int*)malloc(sizeof(long long int) * N);
	for(i = 0;i < N;i++) {
		scanf("%lld", &A[i]);
	}
	qsort(A, N, sizeof(long long int), asc);
	printf("%lld\n", A[N - 1] - A[0]);
	return 0;
}



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

#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;

int main(){
	int n;
	cin >> n;
	set<string> se;

	string s,t;
	cin >> t;
	se.insert(t);
	rep(i, n-1){
		cin >> s;
		if(t.back() != s.front()){
			cout <<"No" << endl;
			return 0;
		}
		t = s;
		se.insert(t);
	}
	cout << ((se.size()==n)?"Yes":"No")<< endl;
	
}




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

using namespace std;

#define all(v)   v.begin(), v.end()
#define pb       push_back
#define sz(x)    (int) (x.size())
#define endl "\n"
#define isOdd(n)    (n&1)
#define pow(n, m) (ll)powl(n, m)
#define clr(x, val)    memset(x, val, sizeof(x)) //be careful of value and TLE


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


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

    int a; cin >> a;
     cout << a + a*a + a*a*a;
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> L(N);
  rep(i,N) cin >> L[i];
  // sort(all(L));
  vector<int> counter(1010, 0);
  rep(i,N){
    counter[L[i]]++;
  }
  //rep(i,N+1) cout << counter[i] << endl;
  vector<int> sum(1010,0);
  rep(i,1009){
    if(i==0) continue;
    sum[i] = sum[i-1]+counter[i];
  }
  //rep(i,N+1) cout << sum[i] << endl;
  ll ans = 0;
  rep(i,N){
    rep(j,N){
       if(i==j)continue;
      int a = L[i];
      int b = L[j];
      int minlen = abs(a-b)+1;
      int maxlen = min(a+b-1, 1000);
      int usable = sum[maxlen] - sum[minlen-1];
       if(minlen <= a && a <= maxlen) usable--;
       if(minlen <= b && b <= maxlen) usable--;
      //if(1)cout << a << " " << b << " " << minlen << " " << maxlen << " " << usable << endl;
      ans += max(0,usable);
    }
  }
  cout << ans / 6<< endl;
  return 0;
}


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


int main() {
	int N, K;
    cin >> N >> K;
     int displayNumber = 1;
  
  for(int n = 0; n<N; n++){
  if(displayNumber > K){
  	displayNumber += K; 
  	}else{
	displayNumber *= 2;
  	}
    
  }
  cout << displayNumber << endl; 
}


Measured memory_bytes: 256
import sys


def solve(X):
    money = 100
    res = 0
    while (money < X):
        money *= 1.01
        money = int(money)
        res += 1
    return res


def main():
    input = sys.stdin.buffer.readline
    X: int = int(input())
    print(solve(X))


if __name__ == '__main__':
    main()


Measured memory_bytes: 63568
from math import factorial
def cmb(a,b):
    return factorial(a)//factorial(b)//factorial(a-b)
N,P = map(int,input().split())
A = list(map(int,input().split()))
Odd = 0 
Even = 0
for Ai in A:
    if Ai % 2 == 0:
        Even += 1
    else:
        Odd += 1
ans = 0
if P == 0:
    for i in range(Odd+1)[::2]:
        ans += cmb(Odd,i)
else:
    for i in range(Odd+1)[1::2]:
        ans += cmb(Odd,i)
ans *= pow(2,Even)
print(ans)

Measured memory_bytes: 62244
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define PI 3.14159265359
#define sz(c) (int)c.size()
#define len(c) (int)c.length()
#define hcf(a, b) __gcd(a, b)
#define all(c) c.begin(), c.end()
#define vint vector<int>
#define vll vector<ll>
#define vpint vector<pair<int, int>>
#define vpll vector<pair<ll, ll>>
#define fr(it, a, b) \
    for (int it = (a); it < (b); it++)
#define tr(con, it) \
    for (auto it = con.begin(); it != con.end(); it++)
#define present(con, ele) (con.find(ele) != con.end())
#define cpresent(con, ele) (find(all(con), ele) != con.end())
#define maximum(a, b, c) (a > b ? (a > c ? a : c) : (b > c ? b : c))
#define minimum(a, b, c) (a < b ? (a < c ? a : c) : (b < c ? b : c))
typedef long long ll;
typedef long double lf;
typedef pair<int, int> pi;
typedef unsigned long long lu;
const ll mod = 1e9 + 7;
int32_t main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, xo = 0;
    cin >> n;
    vint a(n);
    fr(i, 0, n)
    {
        cin >> a[i];
        xo ^= a[i];
    }
    fr(i, 0, n)
    {
        cout << (xo ^ a[i]) << " ";
    }
    cout << "\n";
    return 0;
}

Measured memory_bytes: 3972
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.FileStore;

public class Main {

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

      int n = Integer.parseInt(br.readLine());
      String[] order;
      StringBuilder result = new StringBuilder(n*4);
      Dictionary dict = new Dictionary(10_000_000);

      for(int i=0; i<n; i++) {
        order = br.readLine().split(" ");
        switch( order[0] ) {
          case "insert" :
            dict.insert(order[1]);
            break;
          case "find" :
            result.append( dict.find(order[1]) ).append("\n");
            break;
        }
      }

      System.out.print(result);
    }
  }
}

class Dictionary {
  boolean[] dict;

  public Dictionary(int size) {
    dict = new boolean[size];
  }

  public void insert(String str) {
    int no   = getKey(str);
    dict[no] = true;
  }
  public String find(String ref) {
    int no = getKey(ref);

    return isExist(no) ? "yes" : "no";
  }
  private int getKey(String str) {
    int len = str.length();
    long ret = 0;
    for(int i=0,d=10; i<len; i++ ) {
      ret = (ret * d) + str1ToInt(str.substring(i,i+1));
    }
    String encode = String.valueOf(ret);
    ret = Long.parseLong(encode, 5);

    return (int)ret;
  }
  private boolean isExist(int no) {

    return dict[no];
  }
  private int str1ToInt(String s1) {

    switch( s1 ) {
      case "A" :
        return 1;
      case "C" :
        return 2;
      case "G" :
        return 3;
      case "T" :
        return 4;
      default :
        return -1;
    }

  }
}


Measured memory_bytes: 180976
//file_name:ABC77_B.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // int scan
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // matrix scan
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // string scan
    /*
    string s;
    cin >> s;
    */


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

    double nn = sqrt(n);

    int nnn = (int)nn;



    ll ans = nnn * nnn;

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



Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
  int res;
  string s;
  cin >> s;
  if(s=="SSS")
    res=0;
  else if(s=="RRR")
    res=3;
  else if(s=="SRS"||s[1]=='S')
    res=1;
  else
    res=2;
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3564
fun main(args: Array<String>) {
    // var numberTests = readLine()!!.toInt()
    // var results = mutableListOf<String>()

    // for (i in 0..numberTests-1) {
    var tmpLine = readLine()

    
    val result = experiment(tmpLine!!.toInt())
    // results.add(result)
    // }

    // for (result in results) {
        println(result)
    // }
}

fun experiment(a: Int) : String {

    var result = a + a * a + a * a * a

    return result.toString()
}

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

int main() {
    string str;
    cin >> str;
    bool ret = true;
    char a;
    int count = 0;
    string capital;
    for (int i = 0; i < str.size();i++){
        a = str.at(i);
        if (i == 0 && a != 'A'){
            ret = false;
        }
        if ((i == 1) && (a < 'a' || a > 'z')){
            ret = false;
        }
        //if ((i > 1 && i < str.size() - 1) && (a >= 'a' && a <= 'z')){
        if ((i > 1 && i < str.size() - 1) && (a == 'C')){
            count++;
            capital += a;
        }
        else if ((i > 1 && i < str.size() - 1) && (a < 'a' || a > 'z')){
            ret = false;
        }
        if ( i == str.size() - 1 && (a < 'a' || a > 'z')){
            ret = false;
        }
    }

    if (count != 1){
        ret = false;
    }
    else if(capital.at(0) != 'C'){
        ret = false;
    }

    if (ret){
        cout << "AC" << endl;
    }
    else{
        cout << "WA" << endl;
    }
	
}

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

using namespace std;

int main() {
	int n;
	string s, t, st = "";
	cin >> n >> s >> t;
	
	for (int i = 0; i < n; i++) {
		st += s[i];
		st += t[i];
	}
	
	cout << st;
	
	return 0;
}

Measured memory_bytes: 256
def main():
  s = list(input())

  if s[0] != 'A':
    print('WA')
    return

  C_counter = 0
  for n in s[2:-1]:    
    if n == 'C':
      C_counter += 1

  if C_counter != 1:
    print('WA')
    return

  for n in s:
    if n == 'A' or n == 'C':
      continue
    if not n.islower():
      print('WA')
      return
  print('AC')
  return




main()

Measured memory_bytes: 3060
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define YY cout << "Yes" << endl;
#define NN cout << "No" << endl;
#define ve vector
#define pint pair<int,int>
const int INF = 1000000007;
const long double EPS = 1e-15;
const long double PI = acos(-1);
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
using Graph_weighted = vector<vector<pair<int,int>>>;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
int solve(){
  int a,b,x;
  cin >> a >> b >> x;
  if(a <= x && x <= a + b)cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16);
  solve();
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		// 入力値の取得
		int N = sc.nextInt();
		int[] L = new int[N];
		
		for (int i = 0; i < N; i++) {
			L[i] = sc.nextInt();
		}
		
		int count = 0;
		
		for (int i = 0; i < N - 2; i++) {
			for (int j = i + 1; j < N - 1; j++) {
				for (int k = j + 1; k < N; k++) {
					if (L[i] == L[j] || L[i] == L[k] || L[j] == L[k]) {
						continue;
					}
					if (L[i] + L[j] > L[k] && L[i] + L[k] > L[j] && L[j] + L[k] > L[i]) {
						count++;
					}
				}
			}
		}
		
		// 結果の出力
		System.out.println(count);
		
		sc.close();
	}
}


Measured memory_bytes: 27668
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
 
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

int main() {
    int n, g;
    cin >> n >> g;
    if(n * 500 >= g){
        cout << "Yes";
    } else{
        cout << "No";
    }
    return 0;
}

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

int main() {
    int N;
    string S;
    cin >> N >> S;
    bool flg = true;
    if (N % 2 != 0)
    {
        flg = false;
    } else
    {
        cerr << S.substr(0, N / 2) << endl;
        cerr << S.substr(N / 2) << endl;
        if (S.substr(0, N / 2) != S.substr(N / 2))
        {
            flg = false;
        }
        
    }
    if (flg)
    {
        cout << "Yes" << endl;
    } else
    {
        cout << "No" << endl;
    }
    
    
    
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>

int find_lcs(std::string s1, std::string s2)
{
  // DP table
  int s1_len = s1.size();
  int s2_len = s2.size();

  int dp[s1_len+1][s2_len+1];
  std::memset(dp, 0, sizeof(dp));

  for ( int i = 0; i < s1_len; i++ ) {
    for ( int j = 0; j < s2_len; j++ ) {
      if ( s1[i] == s2[j] ) {
        dp[i+1][j+1] = dp[i][j] + 1;
      } else {
        dp[i+1][j+1] = std::max(dp[i][j+1], dp[i+1][j]);
      }
    }
  }

  return dp[s1_len][s2_len];
}

int main(void)
{
  int q;
  std::cin >> q;
  for ( int i = 0; i < q; i++ ) {
    std::string s1, s2;
    std::cin >> s1 >> s2;
    std::cout << find_lcs(s1, s2) << std::endl;
  }
  return 0;
}


Measured memory_bytes: 7100
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
  std::string S, T;
  std::cin >> S >> T;

  std::vector<std::vector<size_t>> si(26), ti(26);
  for (size_t i = 0; i < S.length(); ++i) {
    si[S[i]-'a'].push_back(i);
    ti[T[i]-'a'].push_back(i);
  }

  std::sort(si.begin(), si.end());
  std::sort(ti.begin(), ti.end());
  if (si == ti) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
}

Measured memory_bytes: 5372
# 入力
X = int(input())# 所持金
A = int(input())# ケーキの値段
B = int(input())# ドーナツの値段

# 処理
balance = X - A
donut_count = balance // B
total_balance = balance - donut_count * B

# 出力
print(total_balance)

Measured memory_bytes: 9084
#include<iostream>
#include<cstdio>
#include<algorithm>
#define MAX 100
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
typedef pair<int,int> P;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
int imap[MAX][MAX];
int h,w,ans;
P gp;

void Display(string s,P p){
  cout << s << " = P(" << p.first << "," << p.second << ")" << endl;
}

void dmap(){
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cout << imap[i][j] << " ";
    }
    cout << endl;
  }
}

P dir(P now,P dir){
  while(true){
    now.first += dir.first;
    now.second += dir.second;
 
    if(!(0<=now.first && now.first<w && 0<=now.second && now.second<h) && now != gp){
      return P(-1,-1);
    }
    else if(imap[now.second][now.first] == 1){
      imap[now.second][now.first] = 0;
      return P(now.first-dir.first,now.second-dir.second);
    }
    else if(now == gp){
      return P(999,999);
    }
  }
}

bool solve(P xy,int counter){
  if(counter > 10 || counter >= ans){
    return false;
  }
  if(xy == gp){
    ans = min(ans,counter);
    return true;
  }
  int cpymap[h][w];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++)cpymap[i][j] = imap[i][j];
  }

  for(int i=0;i<4;i++){
    if(imap[xy.second + dy[i]][xy.first + dx[i]] == 1){
      continue;
    }
    P nowP = dir(xy,P(dx[i],dy[i]));
    if(nowP == P(999,999)){
      ans = min(ans,counter);
    }
    else if(nowP != P(-1,-1)){
      solve(nowP,counter+1);
      for(int i=0;i<h;i++){
	for(int j=0;j<w;j++)imap[i][j] = cpymap[i][j];
      }
    }   
  }

  return false;
}

int main(){
  P sp;
  while(cin >> w >> h && h && w){
    ans = 1<<30;
    rep(i,h){
      rep(j,w){
	cin >> imap[i][j];
	if(imap[i][j] == 2){
	  sp.first = j;
	  sp.second = i;
	  imap[i][j] = 0;
	}
	else if(imap[i][j] == 3){
	  gp.first = j;
	  gp.second = i;
	  imap[i][j] = 0;
	}
      }
    }

    solve(sp,1);
    ans==(1<<30)?cout <<"-1"<<endl:cout <<ans<<endl;

  }

  return 0;
}

Measured memory_bytes: 896
import java.util.*;

public class Main {

	public static void main(String[] args) {
		new Main().run();
	}
	
	private void run() {
		Scanner scan = new Scanner(System.in);
		while (scan.hasNext()) {
			int n = scan.nextInt();
			int sum = 0;
			for (int i = 9; i >= 0; i--) {
				for (int j = 9; j >= 0; j--) {
					for (int k = 9; k >= 0; k--) {
						for (int l = 9; l >= 0; l--) {
							if (i + j + k + l == n) {
								sum++;
							}else if (i + j + k + l < n) {
								break;
							}
						}
					}
				}
			}
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 18840
import math

a, b, C = [int(x) for x in input().split()]
C = math.radians(C)
l = a + b + math.sqrt(a * a + b * b - 2 * a * b * math.cos(C))
h = b * math.sin(C)
s = a * h / 2
print(s)
print(l)
print(h)

Measured memory_bytes: 7896
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision

#if MYDEBUG
#include "lib/cp_debug.h"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;

struct Problem{
    string s;
    void solve(){
        cin >> s;
        vector<vector<int>> a (26);
        for(int i=0; i<26; ++i){
            a[i].push_back(0);
        }
        for(int i=0; i<(int)s.size(); ++i){
            a[s[i]-'a'].push_back(i+1);
        }
        for(int i=0; i<26; ++i){
            a[i].push_back((int)s.size()+1);
        }
        int ans=INF;
        for(int i=0; i<26; ++i){
            int tmp=0;
            for(int j=0; j<a[i].size()-1; ++j){
                tmp=max(tmp,a[i][j+1]-a[i][j]-1);
            }
            ans=min(ans,tmp);
        }
        cout<<ans<<"\n";
    }
};

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

    Problem p;
    p.solve();
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
//#include<string>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    vector<char> v_s;
    vector<char> v_t;
    
    int s_len = (int)s.length();
    int t_len = (int)t.length();

    for (int i=0; i<s_len; i++) {
        char c = s[i];
        v_s.push_back(c);
    }
    for (int i=0; i<t_len; i++) {
        char c = t[i];
        v_t.push_back(c);
    }
    sort(v_s.begin(), v_s.end());
    sort(v_t.begin(), v_t.end(), greater<char>());
    
    if (s < t) {
        cout << "Yes";
    }
    else if (t < s) {
        if (v_s < v_t) {
            cout << "Yes";
        }
        else {
            cout << "No";   
        }
    }
    else {
        cout << "No";
    }

/*
    cout << endl << endl;
    
    for (int i=0; i<s_len; i++) {
        cout << v_s[i];
    }
    
    cout << endl;
    
    for (int i=0; i<t_len; i++) {
        cout << v_t[i];
    }
*/
}

Measured memory_bytes: 3588
#include<stdio.h>
#include<math.h>
int main(){
  int n,d;
  double tmp=0;
  int x[10][10]={};
  int ans=0;
  scanf("%d %d",&n,&d);
  for(int i=0;i<n;i++){
    for(int j=0;j<d;j++){
      scanf("%d",&x[i][j]);
      //printf("%d\n",x[i][j]);
    }
  }
  for(int i=0;i<n;i++){
    for(int a=i+1;a<n;a++){
      tmp=0;
      for(int j=0;j<d;j++){
        //printf("i,a,j=%d,%d,%d\n",i,a,j);
        tmp=tmp+pow(abs(x[i][j]-x[a][j]),2.0);
      }
      for(int b=0;b<=tmp;b++){
        if(tmp==b*b){
          ans++;
        }
      }
    }
  }
printf("%d\n",ans);
return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int>A(N);
	for (int i = 0; i < N; i++) {
		cin >> A.at(i);
	}
	sort(A.begin(), A.end());
	int ans = A.at(N - 1) - A.at(0);
	cout << ans << endl;
}

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

int main(){
	int N;
	string S;
	cin >> N >> S;
	int loop;
	string T;
	if(N%2){
		cout << "No" << endl;
	}else{
		for(loop=0;loop<N/2;loop++){
			T += S[0];
			S.erase(S.begin());
		}
		if(S==T){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    vector<ll> mp(n+1,0);
    rep(i,n) {
        cin >> a[i];
        mp[a[i]]++;
    }
    ll all = 0;
    reps(i,n){
        all += mp[i] * (mp[i]-1) / 2;
    }
    // debug(all);
    rep(i,n){
        ll temp = all;
        ll num = mp[a[i]];
        assert(num > 0);
        cout << temp - num + 1 << "\n";
    }
}

Measured memory_bytes: 5760
#include <stdio.h>
void solve(void)
{
	int a,b,c;
	int x[11]={0};
	scanf("%d %d %d", &a, &b, &c);
	++x[a];
	++x[b];
	++x[c];
	if(x[5]==2 && x[7]==1){
		printf("YES\n");
	} else {
		printf("NO\n");
	}
}
int main(int argc, char **argv)
{
	solve();
	return 0;
}


Measured memory_bytes: 128
main = do
  s <- getContents
  let ss = filter (not . null) . lines $ s
  mapM_ (print . length . solve . read) ss

solve :: Integer -> [Integer]
solve x = takeWhile (<= x) primeNumbers 

primeNumbers :: [Integer]
primeNumbers = 2:f [3] [3,5..]
  where f (x:xs) ys = let (ps, qs) = span (< x^2) ys
                      in  ps ++ f (xs ++ ps) [z | z <- qs, mod z x /= 0]

Measured memory_bytes: 18728
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long h;cin>>h;
    long long ans=1;
    long long jou=0;
    while(h/2!=0){
        jou++;
        h=h/2;
        ans+=pow(2,jou);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

H, W, D = MAP()
A = [LIST() for _ in range(H)]
Q = INT()
LR = [LIST() for _ in range(Q)]

dic = [[] for _ in range(D)]

for y in range(H):
	for x in range(W):
		#print(dic)
		dic[A[y][x]%D].append([A[y][x], y, x])

for lis in dic:
	lis.sort(key = lambda x:x[0])

for lis in dic:
	lis[0][0] = 0
	for i in range(len(lis)):
		if i == len(lis)-1:
			break
		point = (lis[i][1], lis[i][2])
		dist_point = (lis[i+1][1], lis[i+1][2])
		lis[i+1][0] = lis[i][0] + abs(point[0] - dist_point[0]) + abs(point[1]-dist_point[1])

#print(dic)
for L, R in LR:
	print(dic[R%D][ceil(R/D)-1][0] - dic[R%D][ceil(L/D)-1][0])



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

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> V(M);
  for (int i = 0, a, b; cin >> a >> b; i++) V.at(i) = {b, a};
  sort(V.begin(), V.end());
  int cut = 0, ans = 0;
  for (auto [a, b] : V) if (b > cut) ans++, cut = --a;
  cout << ans << "\n";
}

Measured memory_bytes: 4044
n,m = [int(i) for i in input().split()]
a = [input().split() for i in range(m)]

WAcounter = [0]*(n+1)
ans = 0
p = 0
for c in a:
    i = int(c[0])
    s = c[1]
    if s=="WA":
        WAcounter[i]+=1
    else:
        p += max(0,WAcounter[i])
        ans += 1 if WAcounter[i]>=0 else 0
        WAcounter[i]=-1000000
print(ans,p)

Measured memory_bytes: 32908
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);
int main()
{
    ll N;
    cin >> N;
    vector<ll> t(5);
    rep(i, 5) cin >> t[i];
    sort(t.begin(), t.end());
    ll ans = N / t[0] + (N % t[0] == 0 ? 0 : 1);
    ans += 4;
    cout << ans << endl;

    return 0;
}


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

int main() {
  int a,k;
  cin >>k;
  string s;
  cin >>s;
  a = s.size();
  if(a<=k){
    cout <<s <<endl;
  }
  else{
    for(int i=0;i<k;i++){
      cout <<s.at(i);
    }
  cout <<"..." <<endl;
  }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, q, k;
  cin >> n;
  vector<vector<pair<int, long long>>> tree(n);
  for(int i=0; i<n-1; i++){
    int a, b, c;
    cin >> a >> b >> c;
    tree[--a].push_back({--b, c});
    tree[b].push_back({a, c});
  }
  cin >> q >> k;
  k--;
  vector<long long> dist(n, 1e18);
  dist[k] = 0;
  queue<int> que;
  que.push(k);
  while(!que.empty()){
    int now = que.front();
    que.pop();
    for(auto to: tree[now]){
      if(dist[to.first] == 1e18){
        dist[to.first] = dist[now] + to.second;
        que.push(to.first);
      }
    }
  }
  for(int i=0; i<q; i++){
    int x, y;
    cin >> x >> y;
    cout << dist[--x] + dist[--y] << endl;
  }
}

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

typedef long long int ll;
typedef string str;

int main ()
{
	ll t,n,m=0,k,i,j,a,b;
	cin >> k >> a >> b;
	for(i=a;i<=b;i++)
		if(i%k==0)
		{
			m=1;
			break;
		}
	if(m)
	cout << "OK\n";
	else
	cout << "NG\n"; 
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define reg register
#define maxn 200001
using namespace std;
int nt[maxn << 1], fi[maxn], go[maxn], d[maxn], rt;
int dp[maxn], n, sum, sumx, siz[maxn], ans, cnt;
char s[maxn];
vector<int> Q[maxn];
inline int  read() {
    reg int s = 0, t = 0; reg char ch = getchar();
    while(ch > '9' || ch < '0') t |= ch == '-', ch = getchar();
    while(ch >= '0' && ch <= '9') s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return t ? -s : s;
}
void add(int u, int v){
	nt[++cnt] = fi[u]; fi[u] = cnt; go[cnt] = v;
}
void dfs(int u, int fa){
	siz[u] = (s[u] == 'W'); 
	for(int i = fi[u]; i; i = nt[i]){
		int v = go[i]; if(v == fa) continue;
		dfs(v, u); siz[u] += siz[v];
		if(siz[v] != ans && siz[v] != 0){
			Q[u].push_back(v); Q[v].push_back(u);
		}
	}
}
void find(int x, int fa){
	sum += 2;  d[x] = 0;
	if(s[x] == 'W' && Q[x].size() % 2 == 0) sum += 1, d[x] = 2;
	if(s[x] == 'B' && Q[x].size() % 2 == 1) sum += 1, d[x] = 2;
	for(int i = 0; i < Q[x].size(); i++){
		int v = Q[x][i]; if(v == fa) continue;
		find(v, x);
	}
}
void solve(int x, int fa){
	dp[x] = d[x]; int maxx = 0, cmaxx = 0;
	for(int i = 0; i < Q[x].size(); i++){
		int v = Q[x][i]; if(v == fa) continue;
		solve(v, x); 
		if(dp[v] > maxx) cmaxx = maxx, maxx = dp[v];
		else if(dp[v] > cmaxx) cmaxx = dp[v];
		
	}
	sumx = max(sumx, maxx + cmaxx + d[x]);
	dp[x] += maxx;
}
int main()
{
	n = read();
	for(int i = 1; i < n; i++){
		int x = read(), y = read();
		add(x, y); add(y, x);
	}
	scanf("%s", s + 1);
	for(int i = 1; i <= n; i++) {
		ans += ((s[i] == 'W') ? 1 : 0);
		if(s[i] == 'W') rt = i;
	}
	if(ans == 0) {puts("0\n"); return 0;}
	if(ans == 1) {printf("1\n"); return 0;}
	dfs(1, 0);  find(rt, 0);
	sum = sum - 2; 	solve(rt, 0);
	cout << sum - sumx << endl;
	return 0;
}

Measured memory_bytes: 22960
n=int(input())
data=list(map(int,input().split()))

sorted_data=sorted(data)
mindata=sorted_data[0]

data_dict={}
for i in range(n):
    data_dict[data[i]]=i#key：データに含まれる要素　value:そのデータのインデックス

sorted_data_dict={}
for i in range(n):
    sorted_data_dict[sorted_data[i]]=i


swap_cost=0


for x in sorted_data:
    if(sorted_data_dict[x]!=data_dict[x]):
        tmp_cost=0
        swap_num=0

        while(sorted_data_dict[x]!=data_dict[x]):
            ind1=data_dict[x]
            ind2=data_dict[sorted_data[ind1]]
            data_dict[x]=ind2
            data_dict[sorted_data[ind1]]=ind1
            tmp_cost+=x+sorted_data[ind1]
            swap_num+=1
        if( (x+mindata)*2 < swap_num*(x-mindata) ):
            tmp_cost+=(x+mindata)*2 - swap_num*(x-mindata)
        swap_cost+=tmp_cost

print(swap_cost)


Measured memory_bytes: 5788
import math

# inputList=[]
# for i in range(6):
#     inputNum = input()
#     inputList.append(inputNum)
inputa = input().split()
inputb = input().split()

a = int(inputa[0])
# b = int(inputa[1])
# c = int(inputa[2])

# x = int(inputb[0])
# y = int(inputb[1])

# inputa = list(inputa[0])
inputbList = []
inputbList = list(inputb)

# inputaint = [int(n) for n in inputa]
inputbint = []
inputbint = [int(n) for n in inputbList]

# inputa.sort()
# inputb.sort()

cnt = 0
for i in range(a):
    if inputbint[i] != i+1:
        cnt += 1

if cnt == 0 or cnt ==2:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 38384
import sys
sys.setrecursionlimit(10**6)

N = int(input())
h = list(map(int,input().split()))

memo = [-1]*N

def func(i):
  # メモのロード
  if memo[i]!=-1:
    return memo[i]
  # 初期値の部分
  if i==0:
    return 0
  elif i==1: 
    return abs(h[1]-h[0])
  # 二択の部分
  a = func(i-1)+abs(h[i]-h[i-1])
  b = func(i-2)+abs(h[i]-h[i-2])
  memo[i] = min(a,b) # メモのセーブ
  return memo[i]

print(func(N-1))


Measured memory_bytes: 119672
#include<cstdio>
int a[5],n,t;
double dp[305][305][305];
double dfs(int a,int b,int c){
	if (!a&&!b&&!c)return 0;
	if (a<0||b<0||c<0)return 0; 
	if (dp[a][b][c])return dp[a][b][c];
	double &ret=dp[a][b][c];
	int t=a+b+c;
	return ret=a*1.0/t*dfs(a-1,b,c)+b*1.0/t*dfs(a+1,b-1,c)+c*1.0/t*dfs(a,b+1,c-1)+n*1.0/t; 
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		scanf("%d",&t);
		a[t]++;
	}
	printf("%.10lf",dfs(a[1],a[2],a[3]));
} 

Measured memory_bytes: 219392
#include <bits/stdc++.h>
using namespace std;
typedef string::const_iterator State;
const int MOD=1000000007;
const int INF=1000000000;
typedef long long ll;
typedef vector<int> vi;
const double eps=1e-9;
const int inf=1e9;
typedef pair<int,int> P;
int d,w;
int H,W;
int board[15][15];
int ans=0;
bool ok;
int tmp=0;
int mxinner=0;
int miwall=20;
bool wallout(int y,int x,int wall)
{
  if(board[y][x]<wall) return true;
  else return false;
}
void inner(int uly,int ulx,int lry,int lrx)
{
  for(int y=uly;y<=lry;y++)
    {
      for(int x=ulx;x<=lrx;x++)
	{
	  mxinner=max(mxinner,board[y][x]);
	}
    }
}
int waterfell(int uly,int ulx,int lry,int lrx,int water)
{
  int tmp=0;
  for(int y=uly;y<=lry;y++)
    {
      for(int x=ulx;x<=lrx;x++)
	{
	  tmp+=(water-board[y][x]);
	}
    }
  return tmp;
}
void outer(int uly,int ulx,int lry,int lrx)
{
  uly--,ulx--,lry++,lrx++;
  for(int y=uly;y<=lry;y++)
    {
      miwall=min(miwall,board[y][ulx]);
    }
  for(int x=ulx;x<=lrx;x++)
    {
      miwall=min(miwall,board[uly][x]);
    }
  for(int y=uly;y<=lry;y++)
    {
      miwall=min(miwall,board[y][lrx]);
    }
  for(int x=ulx;x<=lrx;x++)
    {
      miwall=min(miwall,board[lry][x]);
    }
}
int main(int argc,char const* argv[])
{
  while(cin >> d >> w && d)
    {
      for(int i=0;i<d;i++)
	{
	  for(int j=0;j<w;j++)
	    {
	      cin >> board[i][j];
	    }
	}
      ans=0;
      for(int uly=1;uly<d-1;uly++)
	{
	  for(int ulx=1;ulx<w-1;ulx++)
	    {
	      for(int lry=uly;lry<d-1;lry++)
		{
		  for(int lrx=ulx;lrx<w-1;lrx++)
		    {
		      miwall=20;
		      mxinner=0;
		      inner(uly,ulx,lry,lrx);
		      outer(uly,ulx,lry,lrx);
		      int water=miwall;
		      if(miwall<=mxinner) continue;
		      else
			{
			  ans=max(ans,waterfell(uly,ulx,lry,lrx,water));
			}
		    }
		}
	    }
	}
      cout << ans << endl;
    }
  return 0;
}



Measured memory_bytes: 3084
from sys import stdin

def main():
    N, *LR = map(int, stdin.buffer.read().split())
    L, R = LR[::2], LR[1::2]

    max_l = max(L)
    min_r = min(R)

    ab = [(max(0, r - max_l + 1), -max(0, min_r - l + 1)) for l, r in zip(L, R)]
    ab.sort()

    mi = float("inf")
    ma = max(r - l + 1 for l, r in zip(L, R)) + max(0, min_r - max_l + 1)

    for (_, r), (l, _) in zip(ab, ab[1:]):
        mi = min(mi, -r)
        ma = max(ma, mi + l)

    print(ma)

main()


Measured memory_bytes: 27440