akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;



int main(){
  int N;
  cin >> N;
  vector<int> vec(N, 0);

  for(int i = 0; i < N; i++){
    cin >> vec.at(i);
  }

  sort(vec.begin(), vec.end());

  int ans = 0;

  for(int i = 0; i < N; i++){
    for(int j = i+1; j < N; j++){
      for(int k = j+1; k < N; k++){
        if(vec[k] >  vec[j] - vec[i] && vec[k] < vec[j] +  vec[i]) ans += 1;
      }
    }
  }

  cout << ans << endl;
}




Measured memory_bytes: 256
#include<iostream>
#include<math.h>
using namespace std;
int main (){
    int n; 
    int i, j;
    int ans=1,tmp;
    cin >> n;
    for(j=2; j<=log2(n); j++){
        for(i=1; i<=sqrt(n); i++){
            tmp = 1;
            for(int k=0;k<j;k++){
                tmp *= i;
            }
            if(tmp <= n && ans < tmp){
                ans = tmp;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n,cnt=0;
  cin>> n;
  vector<int> a(n);
  vector<int> G(0);
  int r=1;
  while(r<=n){
    G.push_back(r);
    r*=2;
  }
  reverse(G.begin(),G.end());
  int m=G.size();
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=0;i<m;i++){
    int g=G[i];
    for(int j=g;j<n;j++){
      int v=a[j];
      int k=j-g;
      while(k>=0&&a[k]>v){
        a[k+g]=a[k];
        k-=g;
        cnt++;
      }
      a[k+g]=v;
    }
  }
  cout<<m<<endl;
  for(int i=0;i<m;i++){
    cout<<G[i];
    if(i!=m-1)cout<<' ';
  }
  cout << endl<< cnt<<endl;
  for(int i=0;i<n;i++){
    cout<<a[i]<<endl;
  }
  return 0;
}
      


Measured memory_bytes: 6648
N,Q = map(int,input().split())
S = input()
l,r = [],[]
index = []
for i in range(Q):
    tmp1,tmp2 = map(int,input().split())
    l.append(tmp1)
    r.append(tmp2)
counter = 0
index.append(counter)
for i in range(1,len(S)):
    if(S[i-1] == 'A' and S[i] == 'C'):
        counter += 1
    index.append(counter)
def f(l,r):
    return index[r-1] - index[l-1]
for i in range(Q):
    print(f(l[i],r[i]))

Measured memory_bytes: 14168
#include <cstdio>

#define MOD 1000000007

using namespace std;

int main(int argc, char const *argv[]) {
  long long n, k;
  scanf("%lld%lld", &n, &k);
  long long ans = 0;
  for (long long i = k; i <= n + 1; ++i) {
    long long low = (i - 1) * i / 2, high = (n * 2 - i + 1) * i / 2;
    ans += high - low + 1;
    ans %= MOD;
  }
  printf("%lld\n", ans % MOD);
  return 0;
}

Measured memory_bytes: 1736
// ALDS1_1_D.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <vector>
using namespace std;
int main()
{
	int n;
	cin >> n;
	vector<int>R(n);
	int min = 2000000000;
	int ans = -2000000000;
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &R.at(i));
		//scanf_s("%d", &R.at(i));
		if (R.at(i) - min>ans)
		{
		ans = R.at(i) - min;
		}
		if (R.at(i)<min)
		{
			min = R.at(i);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3572
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
int main() {
    int N; cin >> N;
    vector<int> A(N), P(N);
    for(int i=0; i<N; i++) {
        cin >> A[i];
        P[i] = i + 1;
    }

    vector<int> diff_idx;
    for(int i=0; i<N; i++) {
        if(i+1 != A[i]) {
            diff_idx.emplace_back(i);
        }
    }

    if(diff_idx.size() > 2) cout << "NO" << endl;
    else {
        if(diff_idx.size()) {
            int u = diff_idx[0], v = diff_idx[1];
            swap(A[u], A[v]);
        }

        if(A == P) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
def main():
    import sys
    from collections import defaultdict
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    D = defaultdict(int)
    H, W = [int(x) for x in input().strip().split()]
    four_pair = (H // 2) * (W // 2)
    two_pair = H % 2 * W // 2 + W % 2 * H // 2
    one = H % 2 * W % 2
    for h in range(H):
        for s in list(input().strip()):
            D[s] += 1
    
    for d, i in D.items():
        while four_pair and i >= 4:
            four_pair -= 1
            i -= 4
        D[d] = i
    if four_pair:
        print('No')
        return False

    for d, i in D.items():
        while two_pair and i >= 2:
            two_pair -= 1
            i -= 2
        D[d] = i
    if two_pair:
        print('No')
        return False
    
    if one == sum(D.values()):
        print('Yes')
        return True
    else:
        print('No')
        return False

if __name__ == '__main__':
    main()

Measured memory_bytes: 9356
a = [0 for i in range(9)]
c = [0 for i in range(9)]
a[0],a[1],a[2] = map(int,input().split())
a[3],a[4],a[5] = map(int,input().split())
a[6],a[7],a[8] = map(int,input().split())

n = int(input())
for i in range(n):
    b= int(input())
    for j in range(9):
        if a[j] == b:
            c[j] = 1



ans = 'No'
for i in range(3):
    if c[3*i]+c[3*i+1]+c[3*i+2] == 3:
        ans = 'Yes'

for i in range(3):
    if c[i]+c[3+i]+c[6+i] == 3:
        ans = 'Yes'

if c[0]+c[4]+c[8] == 3:
    ans = 'Yes'
if c[2]+c[4]+c[6] == 3:
    ans = 'Yes'

print(ans)

Measured memory_bytes: 3064
<?php

fscanf(STDIN, "%d", $n);
fscanf(STDIN, "%s", $s);
$s_arr = str_split($s);

$r_count = 0;
$g_count = 0;
$b_count = 0;
foreach ($s_arr as $s_char) {
    switch ($s_char) {
        case 'R':
            ++$r_count;
            break;
        case 'G':
            ++$g_count;
            break;
        case 'B':
            ++$b_count;
            break;
    }
}

$sum_count = $r_count * $g_count * $b_count;

$count = 0;
for ($i = 0; $i <= $n - 3; ++$i) {
    for ($j = $i + 1; $j <= $n - 2; ++$j) {
        $k = 2 * $j - $i;
        if ($k >= $n) {
            continue;
        }

        if (
            ($s[$i] !== $s[$j])
            && ($s[$i] !== $s[$k])
            && ($s[$j] !== $s[$k])
        ) {
            ++$count;
        }
    }
}

echo $sum_count - $count;


Measured memory_bytes: 16284
import java.util.*;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
      
      if(a%10==9||a/10==9){
        System.out.print("Yes");
      }else{
         System.out.print("No");
      }

      
    }
}

Measured memory_bytes: 21716
for i in range(10**5):
    h,w = map(int,input().split())
    if h == 0 and w == 0:
        break
    else:
        for i in range(h):
            if i == 0 or i == h-1:
                print("#"*w)
            else:
                print("#"+"."*(w-2)+"#")
        print("")


Measured memory_bytes: 5608
/*
#include <boost/multiprecision/cpp_int.hpp>
typedef boost::multiprecision::cpp_int mint; //*/
#include <bits/stdc++.h>
#define  rep(i,n) for(li i=0;i<(n);i++)
#define  red(i,n) for(li i=(n)-1;i>=0;i--)
#define  all(a) begin(a),end(a)
#define  pb(a) push_back(a)
using namespace std;
using li = long long;
using vi = vector<li>;
using vs = vector<string>;


int main()
{
    li n,a=0,i;
    cin>>n;
    for(i=1;a<n;i++) a+=i;
    cout<<i-1<<endl;

    return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque
input=sys.stdin.readline

N, M = map(int, input().split())
d = {i:[] for i in range(1, N+1)}
e = {i:[] for i in range(1, N+1)}

l = []
h = [0] * (N+1)

for _ in range(N+M-1):
    A, B = map(int, input().split())
    d[A].append(B)
    e[B].append(A)
    h[B] += 1

st = set()
for i in range(1, N+1):
    if h[i]==0:
        st.add(i)

l = []
while st:
    i = st.pop()
    l.append(i)
    for j in d[i]:
        h[j] -= 1
        if h[j] == 0:
            st.add(j)

tp = {j:i for i,j in enumerate(l, start=1)}
ans = [0] * (N+1)
for i in range(1, N+1):
    s, t = 0, 0
    for j in e[i]:
        if s < tp[j]:
            s = tp[j]
            t = j
    print(t)


Measured memory_bytes: 93156
#include<stdio.h>
#include<stdlib.h>
#pragma GCC optimize("O2")
#define swap(a,b) ((*a!=*b)&&(*a+=*b,*b=*a-*b,*a-=*b))
#define rep(i,N) for(int i=0;i<(int)N;i++)
const int IMIN=(1<<31);int A[200000],B[200000];long K=0,p=0,m=0,z=0;
static inline long IN(void)
{
  long x=0;int f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(long x){if(x<0)putchar('-'),x=-x;if(x>=10)OUT(x/10);putchar(x%10+48);}
static inline void Sort(unsigned *from,unsigned *to,unsigned bit)
{
  if(!bit||to<from+1)return;
  unsigned *left=from,*right=to-1;
  for(;;)
  {
    while(left<right&&!(*left&bit))left++;
    while(left<right&&(*right&bit))right--;
    if(left>=right)break;
    swap(left,right);
  }
  if(!(bit&*left)&&left<to)left++;
  bit>>=1;
  Sort(from,left,bit);
  Sort(left,to,bit);
}
static inline void Radix(int *array,const int len)
{
  unsigned *x=(unsigned*)array;
  rep(i,len)x[i]^=IMIN;
  Sort(x,x+len,IMIN);
  rep(i,len)x[i]^=IMIN;
}
static inline int check(long x)
{
  long count=0;
  if(x>=0)
  {
    int plus=p-1,minus=m-1;count+=z*(p+m)+z*(z-1)/2+p*m;
    rep(i,plus){while(1l*A[i]*A[plus]>x){plus--;}if(i>=plus){break;}count+=plus-i;}
    rep(i,minus){while(1l*B[i]*B[minus]>x){minus--;}if(i>=minus){break;}count+=minus-i;}
  }
  else{x=-x;int low=0;rep(i,m){while(1l*A[low]*B[m-1-i]<x&&low<p){low++;}count+=p-low;}}
  return count>=K;
}
int main(void)
{
  int N=IN(),x;long l=-2e18,r=-l,mid;K=IN();
  while(N--){x=IN();if(x>0)A[p++]=x;else if(x<0)B[m++]=-x;else z++;}
  Radix(A,p),Radix(B,m);
  while(l<=r){mid=(l+r)/2;if(check(mid))r=mid-1;else l=mid+1;}
  return OUT(l),0;
}

Measured memory_bytes: 2168
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        String str = new Scanner(System.in).nextLine();
        String[] strs = str.split(" ");
        int a = Integer.parseInt(strs[0]);
        int b = Integer.parseInt(strs[1]);
        int c = Integer.parseInt(strs[2]);
        if(a<b&&b<c){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


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

int main(){
  int ticket[]={6000,4000,3000,2000};
  int a,b;
  int ans[4]={0};
  for(int i=0;i<4;i++){
    cin >> a >> b;
    ans[i] = b * ticket[a-1];
  }
  for(int i=0;i<4;i++){
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

map<string, int> mp;

int molecule(string &s, int &i);
int atom(string &s, int &i);
int number(string &s, int &i);

int molecule(string &s, int &i){
    int ret;
    if(s[i] == '('){
        ++i;
        ret = molecule(s, i);
        if(ret < 0) return -1;
        ++i;
        int rhs = number(s, i);
        ret *= rhs;
    }
    else{
        ret = atom(s, i);
        if(ret < 0) return -1;
        if(i < (int)s.size() && isdigit(s[i])) ret *= number(s, i);
    }
    if(i < (int)s.size() && s[i] != ')'){
        int rhs = molecule(s, i);
        if(rhs < 0) return -1;
        ret += rhs;
    }
    return ret;
}

int atom(string &s, int &i){
    string a = s.substr(i, 1);
    ++i;
    if(i < (int)s.size() && 'a' <= s[i] && s[i] <= 'z'){
        a += s[i];
        ++i;
    }
    if(mp.find(a) == mp.end()){
        return -1;
    }
    return mp[a];
}

int number(string &s, int &i){
    int ret = 0;
    while(i < (int)s.size() && isdigit(s[i])){
        ret = ret * 10 + s[i] - '0';
        ++i;
    }
    return ret;
}

int main(){
    string a;
    while(cin >> a && a != "END_OF_FIRST_PART"){
        int w;
        cin >> w;
        mp[a] = w;
    }
    string s;
    while(cin >> s && s != "0"){
        int i = 0;
        int ans = molecule(s, i);
        if(ans < 0) puts("UNKNOWN");
        else printf("%d\n", ans);
    }
}


Measured memory_bytes: 3280
N, M = map(int, input().split())
n_list = [1 for i in range(N)]
bool_list = [True]
for i in range(N - 1):
    bool_list.append(False)

def move(n_bef, n_aft, bool_bef, bool_aft):
    n_bef -= 1
    n_aft += 1

    if bool_bef:
        bool_aft = True

        if n_bef == 0:
            bool_bef = False
    
    return [n_bef, n_aft, bool_bef, bool_aft]

for i in range(M):
    x, y = map(int, input().split())
    n_list[x - 1], n_list[y - 1], bool_list[x - 1], bool_list[y - 1] = move(n_list[x - 1], n_list[y - 1], bool_list[x - 1], bool_list[y - 1])

ans = 0
for bool_ in bool_list:
    if bool_:
        ans += 1

print(ans)


Measured memory_bytes: 4784
#include <bits/stdc++.h>
using namespace std;
int main()
{
   string x,y;
   cin>>x>>y;
   int cnt=0;
   int len=x.size();
   for(int i=0;i<len;i++)
   {
       if(x[i]!=y[i])
       {
           cnt++;
       }
   }
   cout<<cnt<<endl;
   return 0;
}


Measured memory_bytes: 3904
s=list(input())
t=[int(a) for a in s]
n=int(len(t))
ans=0
b=0
list1=[]
s=1000
for i in range(n-2):
    u=[t[i],t[i+1],t[i+2]]
    v="".join(map(str, u))
    w=int(v)-753
    list1.append(w)
u=int(len(list1))
for i in range(u):
    if abs(list1[i])-abs(s)<=0:
        s=list1[i]
    else :
        pass
print(abs(s))


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

#define ll long long
#define ull unsigned long long

#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))

bool isPalindrome(string s) {
    string t(s.rbegin(), s.rend());
    return s == t;
}

bool check(string *map, ll H, ll W, ll h, ll w) {
    if(h >= 0 && w >= 0 && h < H && w < W) {
        if(map[h][w] == '#') return true;
    }
    return false;
}

int main(void) {
    int H, W;
    string *map;
    cin >> H >> W;
    map = new string[H];
    for(ll h = 0;h < H;h++) cin >> map[h];
    for(ll h = 0;h < H;h++) {
        for(ll w = 0;w < W;w++) {
            ll count = 0;
            if(map[h][w] != '#') {
                if(check(map, H, W, h - 1, w - 1)) count += 1;
                if(check(map, H, W, h, w - 1)) count += 1;
                if(check(map, H, W, h + 1, w - 1)) count += 1;
                if(check(map, H, W, h - 1, w)) count += 1;
                if(check(map, H, W, h + 1, w)) count += 1;
                if(check(map, H, W, h - 1, w + 1)) count += 1;
                if(check(map, H, W, h, w + 1)) count += 1;
                if(check(map, H, W, h + 1, w + 1)) count += 1;
                map[h][w] = to_string(count)[0];
            }
        }
        cout << map[h] << endl;
    }
    return 0;
}


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

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


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main(void){
    
    int x,y;
    scanf("%d %d",&x,&y);
    
    
    if(x*2<=y&&y<=x*4&&y%2==0){
    printf("Yes");
}else{
    printf("No");
}
    return 0;
}

Measured memory_bytes: 1736
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;

void print(int x,int y,bool t){
  if(t){
    rep(i,y)cout<<"U";
    
    rep(i,x)cout<<"R";
  }
  else {
    rep(i,y)cout<<"D";
    rep(i,x)cout<<"L";
  }
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int sx,sy,tx,ty;cin>>sx>>sy>>tx>>ty;
  cout<<"U";
  print(tx-sx-1,ty-sy-1,1);
  cout<<"R";

  cout<<"D";
  print(tx-sx-1,ty-sy-1,0);
  cout<<"L";

  cout<<"L";
  print(tx-sx+1,ty-sy+1,1);
  cout<<"D";
  cout<<"R";


  print(tx-sx+1,ty-sy+1,0);
  cout<<"U";

  cout<<endl;



  return 0;

}


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

class mystring{
  public:
    string s;

    mystring(string s){
      this->s = s;
    }

    mystring substr(int i, int d){
      string result = s.substr(i, d);
      return mystring(result);
    }

    int length() const{
      return s.length();
    }

    bool operator<(const mystring& other) const{
      if(s == other.s) return false;
      int d = min(s.length(), other.s.length());
      if(s.substr(0, d) == other.s.substr(0, d))
        return s.length() < other.s.length();
      for(int i = 0; i < d; i++){
        if(s[i] < other.s[i]) return true;
      }
      return false;
    }

    bool operator==(const mystring& other) const{
      return s == other.s;
    }
};

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

  string ss;
  cin >> ss;
  mystring s(ss);
  int k;
  cin >> k;

  priority_queue< pair< mystring, int >, vector< pair< mystring, int > >, greater< pair< mystring, int > > > que;
  for(int i = 0; i + 1 <= s.length(); i++){
    que.push(make_pair(s.substr(i, 1), i));
  }

  set< mystring > subs;
  while(!que.empty()){
    pair< mystring, int > p = que.top();
    que.pop();
    subs.insert(p.first);
    if(subs.size() >= k) break;
    int len = p.first.length() + 1;
    if(p.second + len <= s.length())
      que.push(make_pair(s.substr(p.second, len), p.second));
  }

  string ans;
  int c = 0;
  for(mystring sub: subs){
    ++c;
    if(c == k){
      ans = sub.s;
      break;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<iostream>
#include<string>
using namespace std;

int main(){

string st;
int x,y,z=0;

for(int i=0;i<9;i++)
{
cin>>st;
cin>>x>>y;
z=x*200+y*300;
x=x+y;

cout<<st<<" "<<x<<" "<<z<<endl;
}
return 0;
}

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

int main() {
  int N,M,i,j;
  vector<int> vecA(N);
  cin>>N>>M;
  for(i=0;i<M;i++){
    vector<int> vec(2);
    cin>>vec.at(0)>>vec.at(1);
    for(j=0;j<N;j++){
    if(vec.at(0)==j+1)vecA.at(j)++;
    if(vec.at(1)==j+1)vecA.at(j)++;
  }
  }
  for(i=0;i<N;i++)cout<<vecA.at(i)<<endl;
}


Measured memory_bytes: 16640
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr long long LLINF = 1LL << 60;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
} initializer;

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    if (it != vec.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }

vector<vector<pair<int, long long>>> g(100010);
vector<long long> dists(100010, LLINF);

void bfs(int root) {
  queue<int> que;
  que.push(root);
  while (!que.empty()) {
    int x = que.front(); que.pop();
    for (auto e: g[x]) {
      int nx; long long cost;
      tie(nx, cost) = e;
      if (dists[nx] > dists[x] + cost) {
        dists[nx] = dists[x] + cost;
        que.push(nx);
      }
    }
  }
}

int main() {
  int n; cin>>n;
  rep(i, n-1) {
    int a, b, c; cin>>a>>b>>c;
    --a; --b;
    g[a].emplace_back(b, c);
    g[b].emplace_back(a, c);
  }
  int q, k; cin>>q>>k;
  --k;
  dists[k] = 0;
  bfs(k);
  rep(i, q) {
    int x, y; cin>>x>>y;
    --x; --y;
    print(dists[x]+dists[y]);
  }

  return 0;
}


Measured memory_bytes: 9984
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n,k;
  cin >> n >> k;
  map<int,int> m;
  rep(i,n){
    int a;
    cin >> a;
    m[a]++;
  }
  priority_queue<int,vector<int>,greater<int>> q;
  for(auto i:m) q.emplace(i.second);
  int ans = 0;
  while(q.size()>k){
    ans += q.top(); q.pop();
  }
  cout << ans << endl;
}


Measured memory_bytes: 10748
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    ll ans=0;
    if(k!=0){
        ll x=min(a,k);
        ans+=x;
        k-=x;
    }
    if(k!=0){
        ll x=min(b,k);
        k-=x;
    }
    if(k!=0){
        ll x=min(c,k);
        k-=x;
        ans-=x;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3612
const main = (input) => {
  const args = input.trim().split(" ");
  const x = parseInt(args[0], 10);
  const y = parseInt(args[1], 10);

  if (y % 2 !== 0 || y / 2 - x < 0 || 2 * x - y / 2 < 0) {
    console.log("No");
  } else {
    console.log("Yes");
  }
};

main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

#define PI 3.14159265359

int main(){
    int n, m, x;
    cin >> n >> m >> x;
    vector<vector<int>> a(n, vector<int>(m));
    vector<int> c(n);
    for(int i = 0; i < n; i++){
        cin >> c[i];
        for(int j = 0; j < m; j++)cin >> a[i][j];
    }
    int ans = 12345678;
    int all = 1<<n;
    for(int mask = 0; mask < all; mask++){
        vector<int> level(m);
        int cost = 0;
        for(int i = 0; i < n; i++){
            if((mask>>i)&1){
                cost += c[i];
                for(int j = 0; j < m; j++){
                    level[j] += a[i][j];
                }
            }
        }
        bool ok = true;
        for(int j = 0; j < m; j++){
            if(level[j] < x) ok = false;
        }
        if(ok) ans = min(ans,cost);
    }
    if(ans == 12345678) cout << -1 << endl;
    else cout << ans << endl;
}


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

bool hantei(string a, string b) {
    if (a.size()==b.size()) {
        for (int i=0; i<a.size(); i++) {
            if (a.at(i)!=b.at(i) && (int)a.at(i)+(int)'A'-(int)'a'!=(int)b.at(i)) {
                return false;break;
            }
            if (i==a.size()-1) return true;
        }
    }
    else return false;
}

int main() {
  string s;
  cin >> s;
  string S;
  int count=0;
  while(cin>>S) {
      if (S=="END_OF_TEXT") break;
      if (hantei(s,S)) count++;
  }
  cout << count << endl;
}


Measured memory_bytes: 3220
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new java.util.Scanner(System.in);
        int n = scan.nextInt();
        int r = scan.nextInt();
        int out;
        
        if(n >= 10){
            out = r;
            System.out.println(out);
        }else{
            out = r + 100 * (10 - n);
            System.out.println(out);
        }
    }
}

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

struct Node {
    int key;
    struct Node *right, *left, *parent;
};
typedef struct Node Node;

Node *root, *NIL;

void insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;
    
    z = (Node *)malloc(sizeof(Node));
    z->key   = k;
    z->left  = NIL;
    z->right = NIL;
    
    while(x != NIL) {
        y = x;
        if(z->key < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }
    
    z->parent = y;
    if(y == NIL) {
        root = z;
    } else {
        if( z->key < y->key) {
            y->left = z;
        } else {
            y->right = z;
        }
    }
}

Node * find(Node *u, int k) {
    while(u != NIL && k != u->key) {
        if(k < u->key) u = u->left;
        else u = u->right;
    }
    return u;
}

void inorder(Node *u) {
    if(u == NIL) return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}
void preorder(Node *u) {
    if(u == NIL) return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}
    
int main(void) {
    int n, i, x;
    char com[16];
    scanf("%d",&n);
    
    for(i=0;i<n;i++) {
        scanf("%s",com);
        if(com[0] == 'f') {
            scanf("%d",&x);
            Node *t = find(root,x);
            if(t != NIL) printf("yes\n");
            else printf("no\n");
        } else if(!strcmp(com,"insert")) {
            scanf("%d",&x);
            insert(x);
        } else if(!strcmp(com,"print")) {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }

    return 0;
}


Measured memory_bytes: 20496
#include <iostream>
#include <string>

using namespace std;

typedef long long int int64;

int N,C[100000][3];
string S;

int64 max(int64 a,int64 b)
{
	if(a > b)
		return a;
	else
		return b;
}

int main(void)
{
	cin >> N;
	cin >> S;
	int64 ci = 0;
	int64 cj = 0;
	for(int i = 0;i < N;i++)
	{
		if(S[i] == 'I')
			ci++;
		else if(S[i] == 'J')
			cj++;
	}
	int64 ja = 0;
	int64 oa = 0;
	int64 ia = 0;
	for(int i = 0;i < N;i++)
	{
		if(S[i] == 'O')
		{
			ja += ci;
		}
		else if(S[i] == 'I')
			ci--;
		C[i][2] = ci;
	}
	for(int i = N - 1;i >= 0;i--)
	{
		if(S[i] == 'O')
		{
			ia += cj;
		}
		else if(S[i] == 'J')
			cj--;
		C[i][0] = cj;
	}
	for(int i = 0;i < N - 1;i++)
	{
		oa = max(oa,C[i+1][0] * C[i][2]);
	}
	int64 initial = 0;
	int64 sumo = 0;
	for(int i = 0;i < N;i++)	
	{
		if(S[i] == 'O')
			sumo += C[i][2];
	}
	for(int i = 0;i < N;i++)
	{
		if(S[i] == 'J')
		{
			initial += sumo;
		}
		else if(S[i] == 'O')
		{
			sumo -= C[i][2];
		}
	}
	int64 res = initial + max(max(ja,ia),oa);
	cout << res << endl;
}

Measured memory_bytes: 4440
import math
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]

cnt = 0
for i in range(N):
    for j in range(i+1, N):
        yy = 0
        for y in ((X[i][k] - X[j][k])**2 for k in range(D)):
            yy += y
        yyy = math.sqrt(yy)
        if yyy == int(yyy):
            cnt+=1
print(cnt)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int h,n;
    cin>>h>>n;
    vi a(n);
    rep(i,n)cin>>a[i];
    Yes(accumulate(all(a),0ll)>=h);
}

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

int main() {
  
  int A,B,C;
  cin >>A>>B>>C;
  
if(A==B&&A==C&&B==C) {
  cout<<"No"<<endl;
}
  
  else if(A==B){
    cout<< "Yes"<<endl;
  }
  
  else if(A==C) {
    cout<<"Yes"<< endl;
  }
  
  else if(B==C){
    cout<<"Yes"<<endl;
  }
  
  else{
    cout<<"No"<<endl;
  }
  
}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP2(i, a, b) for(int i = a;i <= b;i++)
#define REPR(i, a, b) for(int i = a; i >= b; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define PI 3.14159265358979323846
#define vi vector<int>
#define vll vector<ll>
#define vi2 vector<vector<int>>
#define eb emplace_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
using P = pair<ll,ll>;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};
#define INT(name) int name;cin >> name;
#define VEC(type,name,n) vector<type> name(n);REP(i,n) cin >> name[i];

template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main()
{
  INT(H);
  INT(W);
  INT(K);
  vector<string> A(H);
  REP(i, H) cin >> A[i];
  
  int MIN = INF;
  REP(i,1<<H){
    bitset<10> bs(i);
    vector<int> cnt(H,0);
    int now = -1;
    int flag2 = 0;
    int cnt2=0;
    int cnt3=0;
    REP(j,H-1){
      if(bs[j]!=bs[j+1]){
        cnt3++;
      }
    }
    REP(j,W){
      REP(k,H){
        if(A[k][j]=='1'){
          cnt[k]++;
        }
      }

      int sum=0;
      int flag=0;
      REP(k,H-1){
        if(bs[k]==bs[k+1]){
          sum+=cnt[k];
        }else{
          sum+=cnt[k];
          if(sum>K){
            flag=1;
          }
          sum=0;
        }
        // if(i==3&&j==4){
        //   cout << sum << endl;
        // }
      }
      sum+=cnt[H-1];
      if(sum>K){
        flag=1;
      }

      if(flag==1){
        if(now==j-1){
          flag2=1;
        }else{
          cnt2++;
          // if(i==3){
          //   cout << j << endl;
          // }
          REP(k,H){
            cnt[k]=A[k][j]-'0';
          }
          now=j-1;
        }
      }
    }

    // if(i==3){
    //   cout << cnt2 << cnt3 << endl;
    // }

    if(flag2==0){
      MIN=min(MIN,cnt3+cnt2);
      // if(cnt3+cnt2==5){
      //   cout << cnt3 << cnt2 << bs << endl;
      // }
    }
  }

  cout << MIN << endl;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i_len=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back
#define mp make_pair

int main()
{
    ll N;
    cin >> N;
    mat G(N);
    ll a;
    REP(i,1,N) {
        cin >> a;
        --a;
        G[a].pb(i);
    }

    FORR(p,G) PR(SZ(p));

    return 0;
}

/*



*/

Measured memory_bytes: 13884
#include<bits/stdc++.h>
#define endl '\n'
#define int long long 
using namespace std;

const int N = 3e5+21;

vector<int> tree[N];
int value[N] = {0};
int ans[N] = {0};

void dfs(int node, int par, int to_add){

    ans[node] = to_add;

    for(auto child : tree[node]){
        if(child == par) continue;

        dfs(child,node,ans[node] + value[child]);

    }

}

int32_t main(){

    int n;  cin >> n;
    int q;  cin >> q;
    for(int x=0;x<n-1;x++){
        int a,b;    cin >> a >> b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }

    while(q--){
        int node , add; 
        cin >> node >> add;
        value[node] += add;
    }

    dfs(1,-1,value[1]);

    for(int x=1;x<=n;x++)
        cout << ans[x] << " ";  cout << endl;

    return 0;
}

Measured memory_bytes: 29312
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	ll a, b, c; cin >> a >> b >> c;
	if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) cout << 0 << endl;
	else cout << min({ a * b, b * c, c * a }) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main() {
    string s1, s2;
    cin >> s1 >> s2;

    for (int i = 0; i < s1.size(); ++i) {
        int j = 0;
        int k = i;
        while (j < s2.size() && k < s1.size()) {
            if (s1[k] != s2[j])
                break;
            j++; k++;
        }
        if (j >= s2.size()) {
            cout << i << endl;
        }
    }

    return 0;
}

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

ll factor(ll n){
  ll res=1;
  for(ll i=2;i*i<=n;i++){
    if(n%i==0)res=i;
  }
  return res;
}

int main(){
  ll n;
  cin >> n;
  
  ll a=factor(n);
  ll b=n/a;
  cout << a+b-2 << endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int mn = 1000;
    string s;

    cin >> s;

    for (int i = 0; i < s.size(); i++)
    {
        string str;

        str = s.substr(i, 3);
        if (str.size() == 3)
        {
            mn = min(mn, abs(stoi(str) - 753));
        }
    }

    cout << mn;

    return 0;
}

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

int main() {
  int x,y;
  cin>>x>>y;
  if(x==1||x==3||x==5||x==7||x==8||x==10||x==12)x=100;
  if(y==1||y==3||y==5||y==7||y==8||y==10||y==12)y=100;
  if(x==2)x=200;
  if(y==2)y=200;
  x=x/100;
  y=y/100;
  if(x==y)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
# 【考察】
# 最低限 abs(ai - aj) <= 1 じゃないとNG。（※）
# とはいえ、これだけでは不十分。
#     例：1 1 2（2・3と1・3が同じ種類で1・2が違う種類になることはない）
# ※の条件から、猫の発言内容は
# 1. 「n匹がk種類、N-n匹がk+1種類と発言」（0 < k < N - 1、0 < n < N）
# 2. 「N匹すべてk種類と発言」（0 < k < N）
# とまとめられる。
# （1. について）
# こうなるのは、猫全体の種類がk+1種類の場合に限られる。
# * 「k種類」と発言しているn匹の猫
#   これらの猫と同じ種類の猫は他に存在しない（自分を除外すると種類数が減る必要があるため）。
#   → 少なくともn+1種類存在することになるので k + 1 >= n + 1、つまりk >= nであればOK。
#   → n種類の割り当ては確定するので、割り当てが未確定な種類の残りは「k + 1 - n」種類。
# * 「k+1種類」と発言しているN-n匹の猫
#   これらの猫に残りの「k + 1 - n」種類を割り当てることになる。
#   これらの猫には、自分と同じ種類の猫が他にいないとNG（自分を除外した時に種類数が減ってしまう）。
#   各種類2匹以上確保できれば良いので
#   「2 * (k + 1 - n) <= N - n」が成り立てばOK。
# （2. について）
# 全体の種類がk種類の場合：
#   自分を除外して種類数が減らないようにしないといけない。
#   そのため、各種類2匹以上存在（2*k <= N）すればOK。
# 全体の種類がk+1種類の場合：
#   自分を除外して種類数が減るようにしないといけない。
#   そのため、各種類1匹ずつのみ存在（k + 1 == N）すればOK。
# 【解法まとめ】
# if max(a) - min(a) > 1
#   Noで終了。
# elif max(a) - min(a) == 1
#   猫の発言を「n匹がk種類、N-n匹がk+1種類と発言」（0 < k < N - 1、0 <= n < N）という形式に直す。
#   「k >= n and 2 * (k + 1 - n) <= N - n」ならYes、それ以外ならNoを出力。
# else (max(a) - min(a) == 0)
#   猫の発言を「N匹がk種類と発言」（0 < k < N）という形式に直す。
#  「2 * k <= N or k + 1 == N」ならYes、それ以外ならNoを出力。


def main():
    N = int(input())
    A = list(map(int, input().split()))
    max_a, min_a = max(A), min(A)
    if max_a - min_a > 1:
        print('No')
    elif max_a - min_a == 1:
        k = min_a
        n = len([a for a in A if a == k])
        if k >= n and 2 * (k + 1 - n) <= N - n:
            print('Yes')
        else:
            print('No')
    else:  # max_a - min_a == 0
        k = min_a
        if 2 * k <= N or k + 1 == N:
            print('Yes')
        else:
            print('No')


if __name__ == '__main__':
    main()

Measured memory_bytes: 20732
n = int(input())

out = ""

for i in range(1, n+1):
    x = i
    if i%3 == 0:
        out += " " + str(x)
        continue
    while True:
        if i%10 == 3:
            out += " " + str(x)
            break
        i //= 10 
        if i == 0:
            break

print(out)


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

int main(){
    int n;
    cin>>n;
    long double v,a[n];
    for(int i=0; i<n; i++){
        cin>>v;
        v = 1/v;
        a[i] = v;
    }
    long double sum = 0.0;
    for(int i=0; i<n; i++){
        sum = sum + a[i];
    }
    long double res = 1/sum;
    cout<<res<<endl;

return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	
	ll a, b, c, k, sum = 0;
	cin >> a >> b >> c >> k;
	
	if ( a <= k ){
		sum += a;
		k -= a;
	}
	else if ( a > k ){
		sum += k;
		k = 0;
	}
	if ( b <= k ){
		sum += b * 0;
		k -= b;
	}
	else if ( b > k ){
		sum += 0 * k;
		k = 0;
	}
	if ( c <= k ){
		sum += (c * -1);
		k -= c;
	}
	else if ( c > k ){
		sum += (k * -1);
		k = 0;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3644
// --https://kenkoooo.com/atcoder/#/table/soma62jp
#include <iostream>
#include <string>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstring>

using namespace std;

int calc(const string &str,const vector<string> &s,const vector<string> &t){

	int buf = 0;

	for (int i=0;i<s.size();i++) {
		if (s[i] == str){
			buf++;
		}
	}

	for (int i=0;i<t.size();i++) {
		if (t[i] == str){
			buf--;
        }
	}

	return buf;

}

int main(int argc, char* argv[]) {

	int N, M ,ans = 0;

	cin >> N;

	vector<string> s(N);

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

	cin >> M;

	vector<string> t(M);

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

	for (int i=0;i<s.size();i++) {
		ans = max(ans, calc(s[i],s,t));
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 256
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
c = Counter(A).most_common(1)[0][0]
B = []
mod = 10**9+7

for i in range(N+1):
    if A[i]==c:
        B.append(i)

F,I = [1],[1]
for i in range(1,N+2):
    F.append(F[i-1]*i%mod)
    I.append(pow(F[i],mod-2,mod))

def C(n,r):
    if n<r or n==0 or r==0:
        return 0
    else:
        return F[n]*I[r]*I[n-r]%mod

r0 = B[0]+N-B[1]

for i in range(1,N+2):
    Ans = (C(N+1,i) - C(r0,i-1))%mod
    print(Ans if i>1 else Ans-1)

Measured memory_bytes: 19936
n, d = gets.chomp.split(' ').map(&:to_i)
x = []
n.times do
  x << gets.chomp.split(' ').map(&:to_i)
end

c = 0
dist = 0
x.combination(2).to_a.each do |comb|
  d.times { |i| dist += (comb[0][i] - comb[1][i]) ** 2 }
  c += 1 if Math.sqrt(dist) % 1 == 0
  dist = 0
end

print(c)


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

typedef long long LL;
typedef pair<int,int> PII;

const int M=1e5+5;
int p[M],q[M],r[M];

priority_queue<PII> qu;

int main()
{
	int x,y,a,b,c;
	scanf("%d%d%d%d%d",&x,&y,&a,&b,&c);
	int nu;
	for(int i=0;i<a;i++)
	{
		scanf("%d",&nu);
		qu.emplace(nu,1);
	}
	for(int i=0;i<b;i++)
	{
		scanf("%d",&nu);
		qu.emplace(nu,2);
	}
	for(int i=0;i<c;i++)
	{
		scanf("%d",&nu);
		qu.emplace(nu,3);
	}
	LL ans=0;
	int cnt1=0,cnt2=0,cnt31=0,cnt32=0;
	while(cnt1<x||cnt2<y)
	{
		PII p=qu.top(); qu.pop();
		int v=p.first,id=p.second;
		ans+=v;
		if(id==1)
		{
			if(cnt1<x)
				cnt1++;
			else
			{
				if(cnt31)
				{
					cnt31--;
					cnt32++;
					cnt2++;
				}
				else
					ans-=v;
			}
		}
		else if(id==2)
		{
			if(cnt2<y)
				cnt2++;
			else
			{
				if(cnt32)
				{
					cnt32--;
					cnt31++;
					cnt1++;
				}
				else
					ans-=v;
			}
		}
		else
		{
			if(cnt1<x)
			{
				cnt1++;
				cnt31++;
			}
			else
			{
				cnt2++;
				cnt32++;
			}
		}
		//cout<<cnt1<<" "<<cnt2<<" "<<cnt31<<" "<<cnt32<<" "<<ans<<endl;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 6384
package main

import "fmt"

func main() {
	var a, b, c int
	fmt.Scanf("%d %d %d", &a, &b, &c)
	uniques := map[int]bool{}
	uniques[a] = true
	uniques[b] = true
	uniques[c] = true
	fmt.Println(len(uniques))
}


Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int A, B, cnt = 0; cin >> A >> B;
    for (int i = A; i <= B; ++i) {
        string str = to_string(i);
        int leg = str.length() / 2;
        bool T = true;
        for (int j = 0; j < leg; ++j) {
            if (str[j] != str[(str.length() - 1) - j]) {
                T = false; break;
            }
        }
        if (T) cnt++;
    }
    printf("%d\n", cnt);
}


Measured memory_bytes: 3716
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 7;
const double pi = acos(-1);
const int mod = 100007;
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
int vis[107];

int main(){
	memset(vis,0,sizeof(vis));
	int n,k;
	scanf("%d %d",&n,&k);
	while(k--){
		int d;
		scanf("%d",&d);
		while(d--){
			int x;
			scanf("%d",&x);
			vis[x] = 1;
		}
	}
	int sum = 0;
	for(int i = 1;i <= n;i++){
		if(!vis[i]) sum++;
	}
	printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2000 + 10, mod = 1e9 + 7;
int a[N],n,k;
ll f(ll x){
    return x * (x + 1) / 2 % mod;
}
int main(){
    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>a[i];
    ll ans = 0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++) if(a[i]<a[j]){
            if(i>j) ans += f(k);
            else ans += f(k-1);
        }
    }
    ans %= mod;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
N = gets.to_i
S = gets.chomp

def same(a, b)
    return ('a'..'z')
        .map {|i| a.include?(i) && b.include?(i) ? 1 : 0}
        .inject(:+)
end

puts (1..N-1).map {|i| same(S[0,i], S[i,N])}.max

Measured memory_bytes: 1788
import java.io.PrintWriter

fun main(args: Array<String>) {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val n = readInteger()
    val aTop = readIntegerList()
    val aBottom = readIntegerList()
    var max = aTop.first() + aBottom.sum()
    var tmp = max
    for (i in 1 until n) {
        tmp = tmp + aTop[i] - aBottom[i - 1]
        max = Math.max(max, tmp)
    }
    println(max)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 36040
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <memory>
#include <cstring>
#include <cassert>
#include <numeric>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define REP2(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(S) (S).begin(), (S).end()
typedef long long ll;

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

  const int INF = 1e9;
  int n, m, l, s, t;
  int dp[1 << 16][17];
  
  while (cin >> n >> m >> l >> s >> t && n ){
    vector<vector<pair<int, int> > > G(n);
    
    REP(i, m){
      int a, b, c;
      cin >> a >> b >> c; a--, b--;
      G[a].push_back(make_pair(b, c));
      G[b].push_back(make_pair(a, c));
    }
    
    vector<int> S(l + 1);
    vector<int> E(l + 1);
    vector<vector<int> >C(l + 1, vector<int>(l + 1));
    
    REP(i, l){
      cin >> S[i] >> E[i]; S[i]--;
    }
    
    S[l] = s - 1;
    E[l] = 0;

    REP(i, l + 1){
      typedef pair<int, int> P;
      
      vector<int> D(n, INF);
      priority_queue<P, vector<P>, greater<P>> que;
      
      que.push(P(0, S[i]));
      D[S[i]] = 0;

      while (!que.empty()){
        int v = que.top().second;
        int c = que.top().first;
        que.pop();

        if (D[v] < c) continue;

        REP(i, G[v].size()){
          int to = G[v][i].first;
          int nc = c + G[v][i].second;

          if (D[to] > nc){
            D[to] = nc;
            que.push(P(nc, to));
          }
        }
      }
      
      REP(j, l + 1) C[i][j] = D[S[j]];
    }

    fill(&dp[0][0], &dp[0][0] + 17 * (1 << 16), INF);
    dp[0][l] = 0;
    
    int res = 0;
    
    REP(mask, 1 << l) REP(u, l + 1) if (dp[mask][u] < INF){

      if (dp[mask][u] + C[u][l] <= t){
        res = max(res, __builtin_popcount(mask));
      } else {
        continue;
      }
      
      REP(v, l + 1){
        int nc = dp[mask][u] + C[u][v] + E[v];
        int nm = v == l ? mask : (mask | (1 << v));

        if (dp[nm][v] == -1 || dp[nm][v] > nc){
          dp[nm][v] = nc;
        }
      }
    }
    
    cout << res << endl;
  }
  
  return 0;
}

Measured memory_bytes: 5732
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    int n; cin >> n;
    vector<ll> a(n);
    for (ll &x : a) {
        cin >> x;
    }
    ll res = LONG_LONG_MAX;
    vector<ll> suf(n + 10, 0ll);
    for (int i = n - 2; i >= 0; i--) {
        suf[i] = suf[i + 1] + a[i + 1];
    }
    ll pref = 0;
    for (int i = 0; i < n; i++) {
        pref += a[i];
        res = min(res, abs(pref - suf[i]));
    }
    cout << res << "\n";
}


Measured memory_bytes: 3328
from collections import deque

N = int(input())

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

max_color = 0
for i in range(N):
    max_color = max(max_color, len(g[i]))

res = [-1] * (N-1)
d = [-1] * N
que = deque([])
que.append((0, -1))
d[0] = 0
while que:
    v, c = que.popleft()
    color = 1
    if color == c:
        color += 1
    for f, s in g[v]:
        if d[f] == -1:
            d[f] = d[v] + 1
            que.append((f, color))
            res[s] = color
            color += 1
            if color == c:
                color += 1

print(max_color)
for v in res:
    print(v)


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

int main()
{
    int n, a;
    string ans = "No";
    cin >> n >> a;
    if (n % 500 <= a)
        ans = "Yes";
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256