akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>
#include <bitset>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

constexpr ll LNF = 1LL<<60;

constexpr int INF = 1e9+7;

const double PI=3.14159265358979323846;


vector<int> dx = {-1,0,1,0,-1,1,-1,1};
vector<int> dy = {0,-1,0,1,1,-1,-1,1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    long double a,b,h,m; cin >> a >> b >> h >> m;
    long double d = abs(30*h+m/2-6*m);
    d = d*PI/180.0;
    long double c = sqrt(a*a+b*b-2*a*b*cos(d));
    debug(a,b,d);
    chmin(c,sqrt(a*a+b*b-2*a*b*cos(2*PI-d)));
    debug(d);
    cout << fixed << setprecision(15) << c << endl;
} 

Measured memory_bytes: 4208
// editorial見た。

#include <cstdio>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <iostream>
#include <vector>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
typedef long long ll;

long long inv(int a, int p) { return a==1 ? 1 : (1-p*inv(p%a,a))/a+p; }
int MODVAL;
struct mint {
  int val;
  mint():val(0){}
  mint(int x):val(x%MODVAL) { if(val<0) val+= MODVAL; }
  mint(size_t x):val(x%MODVAL) {}
  mint(long long x):val(x%MODVAL) { if(val<0) val+= MODVAL; }
  mint& operator+=(mint y) { val+=y.val; if(val>=MODVAL) val-=MODVAL; return *this; }
  mint& operator-=(mint y) { val-=y.val; if(val<0) val+= MODVAL; return *this; }
  mint& operator*=(mint y) { val=(val*(long long)y.val)%MODVAL; return *this; }
  mint& operator/=(mint y) { val=(val*inv(y.val,MODVAL))%MODVAL; return *this; }
};
inline mint operator+(mint x, mint y) { return x+=y; }
inline mint operator-(mint x, mint y) { return x-=y; }
inline mint operator*(mint x, mint y) { return x*=y; }
inline mint operator/(mint x, mint y) { return x/=y; }
mint POW(mint x, long long n) { mint r(1); for(;n;x*=x,n>>=1) if(n&1) r*=x; return r; }
mint FAC(int n) { static vector<mint> FAC_(1,1);
  while(int(FAC_.size())<=n) FAC_.push_back(FAC_.back()*FAC_.size()); return FAC_[n]; }
inline mint CMB(int n, int k) { return k<0||n<k ? 0 : FAC(n) / (FAC(k) * FAC(n-k)); }
inline ostream& operator<<(ostream& os, mint a) { return os << a.val; }


int as[3010];
mint ans[3010];

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

  int P;
  cin >> P;
  MODVAL = P;
  REP(i, P) {
    cin >> as[i];
    if(as[i] == 1) {
      ans[0] += 1;
      mint cur = 1;
      REP(j, P) {
        ans[P-1-j] -= CMB(P-1, j) * cur;
        cur *= -i;
      }
    }
  }
  REP(i, P) {
    cout << ans[i];
    if(i == P-1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }

  return 0;
}


Measured memory_bytes: 384
from collections import defaultdict
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

counts = defaultdict(int)
S = s()

for c in S:
    counts[c] += 1

if len(counts) == 2 and all([v == 2 for v in counts.values()]):
    print('Yes')
else:
    print('No')


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------
char tr(char c){
  int a = c - 'A';
  int b = c - 'a';
  if(0 <= a && a < 26) return (char)(a + 'a');
  return c;
}
//-----------------------------------------

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  string s;
  cin >> s;
  int n;
  cin >> n;
  REP(i,n){
    string com;
    cin >> com;
    if(com[0] == 'p'){
      int a, b;
      cin >> a >> b;
      for(int j=a;j<=b;j++) cout << s[j];
      cout <<endl;
    }
    else if(com == "reverse"){
      int a, b;
      cin >> a >> b;
      int j = 0;
      while(a+j <= b-j){
        char tmp = s[a+j];
        s[a+j] = s[b-j];
        s[b-j] = tmp;
        j++;
      }
    }
    else{
      int a, b;
      cin >> a >> b;
      int l = b - a + 1;
      string t;
      cin >> t;
      for(int j=0;j<l;j++){
        s[a+j] = t[j];
      }
    }
  }




  return 0;
}



Measured memory_bytes: 3236
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdio>
using namespace std;
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
class UnionFind{
public:
    //親の番号を格納する。親だった場合は-(その集合のサイズ)
    vector<int> Parent;
    //作る時はParentの値を全て-1にする
    //こうするとずべてバラバラになる
    UnionFind(int N){
      Parent = vector<int>(N,-1);
    }
    //Aがどのグループに属しているのか調べる
    int root(int A){
      if(Parent[A]<0) return A;
      return Parent[A] = root(Parent[A]);
    }
    //自分のいるグループの頂点数を調べる
    int size(int A){
      return -Parent[root(A)];//親を取ってきたい
    }
    //AとBをくっつける
    bool connect(int A,int B){
      //AとBを直すつつなぐのではなく、root(A)にroot(B)をくっつける)
      A = root(A);
      B = root(B);
      if(A==B){
        //すでにくっついているからくっつけない
        return false;
      }
      //大きい方(A)に小さい方(B)をくっつけたい
      //大小が逆だったらひっくり返しちゃう
      if(size(A)<size(B)) swap(A,B);
      //Aのサイズを更新する
      Parent[A] += Parent[B];
      //Bの親をAに変更する
      Parent[B] = A;
      return true;
    }
  };

int main(){
  int N,M;cin>>N>>M;
  int i,j,k,l;
  vector<int> A(M),B(M),C(M);
  rep(i,M){
    cin>>A[i]>>B[i]>>C[i];
    A[i]--;B[i]--;C[i]--;
  }
  int ans=N;
  UnionFind Uni(N);
  rep(i,M){
    //繋がってなかったのが繋がった時
    if(Uni.root(A[i]) != Uni.root(B[i])){
      ans--;
      Uni.connect(A[i],B[i]);
      }
    }
  cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include<string>
using namespace std;
int main(void){
    // Your code here!
    string moji;
    int a[3];
    
    int s=0;
    int& sum=s;
    
    cin>>a[0]>>a[1]>>a[2];

    for(int i=0;i<3;i++){
        if(a[i]==5)
        sum=sum+1;
        else if(a[i]==7)
        sum=sum+5;
    }    
    if(sum==7)
    cout<<"YES"<<endl;
    else
    cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int d,t,s;
    cin >> d >> t >> s;
    if(s*t >= d)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3656
#include<iostream>
using namespace std;
int main(){
    int a,b;
    char op;
    while(1){
        cin>>a>>op>>b;
        if(op=='?') break;
        else if(op=='+') cout<<a+b<<endl;
        else if(op=='-')    cout<<a-b<<endl;
        else if(op=='*')    cout<<a*b<<endl;
        else cout<<a/b<<endl;
    }
    return 0;
}


Measured memory_bytes: 3108
#include "bits/stdc++.h"
using namespace std;
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define PI acos(-1)

int main() {
    int N;
    cin >> N;
    vector<int64_t> numbers(N);
    Rep(i, N) {
        cin >> numbers[i];
        if (numbers[i] == 0) {
            puts("0");
            return 0;
        }
    }
    Sort(numbers);
    Reverse(numbers);
    int64_t ans = 1;
    int64_t rest = 1e18;
    Rep(i, N) {
        ans *= numbers[i];
        rest /= numbers[i];
        if (rest == 0) {
            puts("-1");
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    vector<int> n(3);
    for(int i = 0; i < 3; i++) cin >> n[i];
    sort(n.rbegin(), n.rend());
    cout << n[0]*10 + n[1] + n[2] << endl;
}

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

int main()
{
    char in;
    int count[26];

    for (int i = 0; i < 26; i++)
    {
        count[i] = 0;
    }

    while (scanf("%c", &in)!=EOF)
    {
        int temp = in;
        if ((temp >= 65) && (temp <= 90))
        {
            //printf("%c, %d\n", temp, temp - 65);
            temp = temp - 65;
            count[temp] += 1;
        }
        else if ((temp >= 97) && (temp <= 122))
        {
            //printf("%c, %d\n", temp, temp - 97);
            temp = temp - 97;
            count[temp] += 1;
        }
    }

    for (int i = 0; i < 26; i++)
    {
        printf("%c : %d\n", i + 97, count[i]);
    }

    return 0;
}


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

using namespace std;
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 all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

char *demangle(const char *demangle)
{
    int status;
    return abi::__cxa_demangle(demangle, 0, 0, &status);
}

ll eval(string S)
{
    ll res = 0, cur = 0;
    int n = S.size();
    for (int i = 0; i < n; i++)
    {
        if (S[i] == '+')
        {
            res += cur, cur = 0;
        }
        else
        {
            cur = cur * 10 + (S[i] - '0');
        }
    }
    res += cur;
    return res;
}

int main()
{
    string S;
    cin >> S;
    int n = S.size();

    ll ans = 0;
    for (int bit = 0; bit < (1 << (n - 1)); bit++)
    {
        string ex = "";
        for (int i = 0; i < (n - 1); i++)
        {
            ex += S[i];
            if ((bit >> i) & 1)
            {
                ex += '+';
            }
        }
        ex += S[n - 1];
        ans += eval(ex);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

int GCD(int a, int b) {if(b==0)return a; return GCD(b, a%b);}
int main() {
    int x; cin >> x;
    if (x == 1) {
        cout << "Hello World" << endl;
    } else {
        int A, B; cin >> A >> B;
        cout << (A+B) << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define     FAST            ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0);
int main()
{

        string s1,s2;
        cin>>s1>>s2;



    int c=0;
    for(int i=0;i<s1.size();i++)
    {
        if(s1[i]!=s2[i])
        {
            c++;
        }
    }


    cout<<c<<endl;





















    return 0;
}


Measured memory_bytes: 3912
N = input()
nums = list(map(int,input().split()))
index , pre= 0,0
max_num = 1
ans = 0
if not max_num in nums:
  print(-1)
  exit()
while 1:
  for i,n in enumerate(nums):
    if i < index:
      continue
    if n == max_num:
      index=i
      max_num+=1
      ans+=1
  if index == pre:
    if ans == 0:
      print(ans)
    else:
      print(len(nums)-ans)
    break
  pre=index

Measured memory_bytes: 24744
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n,a,b;
   cin >> n >> a >> b;
   int ans = (n/(a+b))*a;
   ans += min(n%(a+b),a);
   cout << ans << '\n';
   return 0;
}

Measured memory_bytes: 256
fn getline() -> String{
    let mut __ret = String::new();
    std::io::stdin().read_line(&mut __ret).ok();
    return __ret;
}

fn gcd(x: &i32, y: &i32) -> i32 {
    if *y == 0 {
        *x
    }else{
        gcd(y, &(*x % *y))
    }
}

fn main() {
    let s = getline();
    let inp:Vec<_> = s.trim().split(' ').collect();
    let a:i32 = inp[0].parse().unwrap();
    let b:i32 = inp[1].parse().unwrap();
    let c:i32 = inp[2].parse().unwrap();
    if c % gcd(&a,&b) == 0 {
        println!("YES");
    }else{
        println!("NO");
    }
}


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

int main() {
    long n, k, ans;
    string str;
    cin >> str >> k;
    n = str.length();
    if(k == 1) {
        ans = (str.at(0) - '0') + (n - 1) * 9;
    } else if(k == 2) {
        ans = (n - 1) * (n - 2) * 81 / 2;
        ans = max(ans, 0l);
        bool flag = true;
        rep(i, n - 1) {
            if(flag) ans += (str.at(0) - '1') * 9 + (str.at(i + 1) - '0');
            else ans += (str.at(0) - '0') * 9;
            if(str.at(i + 1) != '0') flag = false;
        }
        ans = max(ans, 0l);
    } else {
        ans = (n - 1) * (n - 2) * (n - 3) * 243 / 2;
        ans = max(ans, 0l);
        bool flag = true, fflag = true;
        rep(i, n - 2) {
            fflag = true;
            rep(j, n - 1) {
                if(i >= j) continue;
                if(flag) {
                    if(fflag) ans += (str.at(0) - '1') * 81 + max((long)((str.at(i + 1) - '1') * 9 + (str.at(j + 1) - '0')), 0l);
                    else ans += (str.at(0) - '1') * 81 + (str.at(i + 1) - '0') * 9;
                    if(str.at(j + 1) != '0') fflag = false;
                } else {
                    ans += (str.at(0) - '0') * 81;
                }
            }
            if(str.at(i + 1) != '0') flag = false;
        }
        ans = max(ans, 0l);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <set>
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <limits>
#include <map>
#include <numeric>

#define ll long long
using namespace std;
static ll imin = std::numeric_limits<ll>::min();
static ll imax = std::numeric_limits<ll>::max();
#define rep(i, n) for(int i = 0; i<n; ++i)
#define rep1(i, n) for(int i = 1; i<n; ++i)
#define debug(x) cout << #x << ":" << x << "\n";
template<class T>
std::ostream& operator << (std::ostream& os, std::vector<T>& vec){
  std::size_t n = vec.size();
  if(n == 0){
    return os;
  }
  for(int i = 0; i<n - 1; ++i){
    os << vec[i] << " ";
  }
  os << vec[n - 1];
  os << std::endl;
  return os;
}

template<class T>
std::istream& operator >> (std::istream& is, std::vector<T>& vec){
  T tmp;
  is >> tmp;
  vec.push_back(tmp);
  return is;
}
template <class T>
auto mkVec(unsigned int x){
  return std::vector<T>(x);
}

template <class T>
auto mkVec2(unsigned int x, unsigned int y){
  return std::vector<std::vector<T>>(x, std::vector<T>(y));
}

template <class T>
auto mkVec3(unsigned int x, unsigned int y, unsigned int z){
  return std::vector<std::vector<std::vector<T>>>(x, std::vector<std::vector<T>>(y, std::vector<T>(z)));
}


#ifndef BOOST_TEST_MAIN
int main(int const argc, char const** argv){
  ll N;
  cin >> N;
  vector<ll> v(N);
  rep(i, N){
    cin >> v[i];
  }

  cout << accumulate(v.begin(), v.end(), 0) - N;
}
#endif


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;

int main(void)
{
    IOS
    constexpr int N = 100000;
    constexpr int K = 50;
    ll n,k; cin >> n >> k;
    vector<bitset<N+10>> v(K,bitset<N+10>(0));
    REP(i,n) {
        ll x; cin >> x;
        int j = 0;
        while(x > 0) {
            v[j][i] = x % 2;
            x /= 2;
            j++;
        }
    }

    ll f = 0;
    ll ans = 0;
    for (auto i = K-1; i >= 0; i--) {
        ll x = 1LL << i;
        ll cnt = v[i].count();
        if ( f + x <= k ) {
            if (cnt < (n+1)/2) {
                cnt = n - cnt;
                f += x;
            }
        } 
        ans += cnt * x;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define int long long

struct edge{ int to,cost; };
const int N = 2e5+10;
vector< edge > G[N];

struct Diamiter_of_Tree{
  vector<int> d; //sから最も遠い距離
  const int INF = -1;

  int diamiter(){
    d.resize(N);
    //適当な節点sから最も遠い節点gを求める
    bfs(0);
    int max_dist = 0,g = 0;
    for(int i = 0; i < N; i++){
      if(d[i] == INF) continue;
      if(max_dist < d[i]){
        max_dist = d[i];
        g = i;
      }
    }
    //gから最も遠い節点との距離を求める
    bfs(g);
    int ret = 0;
    for(int i = 0; i < N; i++){
      if(d[i] == INF) continue;
      ret = max(ret,d[i]);
    }
    return ret;
  }

  void bfs(int s){
    for(int i = 0; i < N; i++) d[i] = INF;
    queue<int> q;
    d[s] = 0;
    q.push(s);
    while( !q.empty() ){
      int u = q.front(); q.pop();
      for(auto e : G[u]){
        if(d[e.to] == INF){
          d[e.to] = d[u] + e.cost;
          q.push(e.to);
        }
      }
    }
  }

}dia;


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

  int n; cin >> n;
  for(int i = 0; i < n-1; i++){
    int s,t,w; cin >> s >> t >> w;
    G[s].push_back({t,w});
    G[t].push_back({s,w});
  }
  cout << dia.diamiter() << endl;

  return 0;
}



Measured memory_bytes: 14792
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn pri(i: usize, j: usize, s: &Vec<char>, k: usize) -> String {
    let mut sub_string = String::new();
    let mut time = 0;
    for l in i..j+1 {
        sub_string.push(s[l]);
        time+=1;
        if time > k {
            break;
        }
    }
    sub_string
}

fn main() {
    input! {
        s: chars,
        k: usize,
    }
    let mut v = Vec::new();
    for i in 0..s.len() {
        let mut time = 0;
        for j in i..s.len() {
            v.push(pri(i, j, &s, k));
            time+=1;
            if time > k {
                break;
            }
        }
    }
    v.sort();
    v.dedup();
    println!("{}", v[k-1]);
}

Measured memory_bytes: 6396
word = input()
import re
dst = ""
if word[0] == "A":
    if len(re.findall("C", word[2:-1])) == 1:
        if len(re.findall(r"[a-z]", word)) == len(word) - 2:
            dst = "AC"
if not dst:
    dst = "WA"
print(dst)


Measured memory_bytes: 3188
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    String s=sc.next();
    NavigableSet<Integer>[] nsa=new NavigableSet[26];
    for(int i=0;i<26;i++){
      nsa[i]=new TreeSet<Integer>();
    }
    for(int i=0;i<n;i++){
      nsa[s.charAt(i)-'a'].add(i+1);
    }
    int q=sc.nextInt();
    for(int i=0;i<q;i++){
      if(sc.nextInt()==1){
        int idx=sc.nextInt();
        int ch=sc.next().charAt(0)-'a';
        for(int j=0;j<26;j++){
          if(ch==j){
            nsa[j].add(idx);
          }else{
            nsa[j].remove(idx);
          }
        }
      }else{
        int l=sc.nextInt();
        int r=sc.nextInt();
        int ans=0;
        for(int j=0;j<26;j++){
          Integer e=nsa[j].ceiling(l);
          if(e!=null&&e<=r){
            ans++;
          }
        }
        System.out.println(ans);
      }
    }
  }
}

Measured memory_bytes: 104736
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long llint;

llint a[1005],n;
void input(){
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
}

void solve(){
  input();
  string ans="APPROVED";
  for(llint x:a){
    if(x%2==0){
      if(x%3!=0 && x%5!=0){
        ans="DENIED";
      }
    }
  }
  cout << ans << endl;
}
int main(void){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
 
int main(void) {
	int n, m, x;
	cin >> n >> m >> x;
	vector<int> a(m);
	for(int i=0;i<m;i++) cin >> a.at(i);

	int cost0=0, costn=0;

	for(int i=1;i<x;i++) {
		for(int j=0;j<m;j++) {
			if(i == a.at(j)) cost0++;
		}
	}

	for(int i=x+1;i<n;i++) {
		for(int j=0;j<m;j++) {
			if(i == a.at(j)) costn++;
		}
	}

	cout << min(cost0, costn) << endl;
}

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

int main()
{
	int n;
	while (cin >> n, n) {
		vector<int> st(1, 0);
		int c, ch;
		cin >> c;
		for (int i = 1; i < n; i++) {
			cin >> ch;
			if (c != ch) {
				if (i % 2 == 1) {
					if ((int)st.size() >= 2) {
						st.pop_back();
					}
				}
				else {
					st.push_back(i);
				}
				c = ch;
			}
		}
		st.push_back(n);
		int res = 0;
		while (st.size() >= 2) {
			if (c == 0) {
				res += st[st.size() - 1] - st[st.size() - 2];
			}
			c = 1 - c;
			st.pop_back();
		}
		cout << res << endl;
	}
	return 0;
}



Measured memory_bytes: 3052
import java.util.*;
public class Main {
    
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();

        HashMap<Integer,Integer> ntoi = new HashMap<>();
        int in = 2;
        while(true){
            int combi = in*(in-1)/2;
            if(combi > 100000){
                break;
            }
            ntoi.put(combi, in);
            in ++;
        }

        if(ntoi.containsKey(N)){
            System.out.println("Yes");
            System.out.println(ntoi.get(N));
            int[][] table = new int[N+1][ntoi.get(N)+1];
            int i=1;
            int j=2;
            int k=1;
            while(k <= N) {
                table[k][i] = 1;
                table[k][j] = 1;
                if(j+1 <= ntoi.get(N)){
                    j++;
                }else{
                    i++;
                    j = i+1;
                }
                k++;
            }
            for (int c = 1; c <= ntoi.get(N); c++) {
                System.out.print(ntoi.get(N)-1);
                System.out.print(" ");
                for(int r=1; r<=N; r++){
                    if(table[r][c]==1){
                        System.out.print(r);
                        System.out.print(" ");
                    }
                }
                System.out.println("");
            }
        }else{
            System.out.println("No");
        }
    }
}


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

int a[100];

int main(){
	
	int n;
  	cin>>n;
  	for(int i=0;i<n;i++){
      	cin>>a[i];
    }
  	int ans = 0;
  	for(int i=0;i<n;i++){
      int x;
      cin>>x;
      if(x<a[i])ans+=(a[i]-x);
    }
  	cout<<ans;
    
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007


string a, b, ans;
int main() {
	cin >> a >> b;
	REP(i, b.size()) {
		ans.push_back(a[i]);
		ans.push_back(b[i]);
	}
	if (a.size() > b.size())ans.push_back(a[a.size() - 1]);
	cout << ans << endl;
}




Measured memory_bytes: 256
#include<stdio.h>

void insertionSort(int *,int);
int main(){
  int a[100],i,j,n;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(j=0;j<n;j++){
      printf("%d",a[j]);
      if(j!=n-1){
	printf(" ");
      }
    }
  printf("\n");
  insertionSort(a,n);
}

void insertionSort(int *A,int N){
  int i,j,v;
  for(i=1;i<=N-1;i++){
    v=A[i];
    j=i-1;
    while(j>=0 && A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
    for(j=0;j<N;j++){
      printf("%d",A[j]);
      if(j!=N-1){
	printf(" ");
      }
    }
    printf("\n");
  }
}
    
  
  



Measured memory_bytes: 2072
// 解説
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

int ans, n, m, s, t;
int d[100005*3];
vector<int> g[100005*3];

void bfs(int s) {
    queue<int> q;
    rep(i, 0, 100005*3) d[i] = -1;

    q.push(s);
    d[s] = 0;
    while (!q.empty()) {
        int u = q.front(); q.pop();
        for (int v : g[u]) {
          if (d[v]==-1) {
            d[v] = d[u]+1;
            q.push(v);
          }
        }
     }
}

int main(void) {

    cin >> n >> m;

    rep(i, 0, m) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        g[u*3].pb(v*3+1);
        g[u*3+1].pb(v*3+2);
        g[u*3+2].pb(v*3);
    }
    cin >> s >> t;
    s--; t--;

    bfs(s*3);
    
    
    cout << (d[t*3]==-1 ? -1 : d[t*3]/3) << "\n";
    return 0;
}



Measured memory_bytes: 21204
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        int[] a1 = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        int[] a2 = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        int[] a3 = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        int[][] a =
        {
            a1, a2, a3
        };
        int n = int.Parse(Console.ReadLine());
        for (int i = 0; i < n; i++)
        {
            int b = int.Parse(Console.ReadLine());
            if (a[0].Contains(b))
                a[0][Array.IndexOf(a[0], b)] = 0;
            else if (a[1].Contains(b))
                a[1][Array.IndexOf(a[1], b)] = 0;
            else if (a[2].Contains(b))
                a[2][Array.IndexOf(a[2], b)] = 0;
        }

        if (a[0][0] == a[1][1] && a[1][1] == a[2][2])
        {
            Console.WriteLine("Yes");
            return;
        }
        else if (a[2][0] == a[1][1] && a[1][1] == a[0][2])
        {
            Console.WriteLine("Yes");
            return;
        }

        for (int i = 0; i < 3; i++)
        {
            if (a[i][0] == a[i][1] && a[i][1] == a[i][2])
            {
                Console.WriteLine("Yes");
                return;
            }
            if (a[0][i] == a[1][i] && a[1][i] == a[2][i])
            {
                Console.WriteLine("Yes");
                return;
            }
        }
        Console.WriteLine("No");
    }
}


Measured memory_bytes: 13400
#include <bits/stdc++.h>
#include <random>
#include <unordered_map>

using namespace std;

const int MAX = 200001;

int cnt[MAX];

int main()
{
    int N, K;
    int a;
    cin >> N >> K;
    vector<int> x;    
    for(int i = 0; i < N; i++) {
        cin >> a;
        cnt[a]++;
    }
    
    for(int i = 0; i < MAX; i++) {
        if(cnt[i] > 0) {
        	x.emplace_back(cnt[i]);
        }
    }
    
    sort(x.begin(), x.end());
    int size = x.size();
    int ans = 0;
    int index = 0;
    while(size > K && index < x.size()) {
        ans += x[index];
        size--;
        index++;
    }
    
    cout << ans << endl;
    
    return 0;
}


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

int main(void) {
  string s;
  cin >> s;
  
  int topping = 0;
  for (int i = 0; i < 3; i++) {
    if (s.at(i) == 'o')
      topping += 100;
  }
  
  cout << 700 + topping << endl;
  
  return 0;
}
         

Measured memory_bytes: 256
//#pragma GCC target("avx2")
#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

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

void d_err() {
    cerr << endl;
}

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

template <typename T>
void print(T x) {
    cout << x << "\n";
}

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

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

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

struct UnionFind {
    vector<int> par;

    UnionFind(int n): par(n, -1) {}
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }

    int issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);

        if (x == y) return false;

        // merge by size
        // force size of x to be bigger than that of y
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;

        return true;
    }

    ll size(int x) {
        return -par[root(x)];
    }
};

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

    int n; cin >> n;

    vector<pair<ll, pair<ll, int>>> v;
    REP(i, n) {
        int x, y; cin >> x >> y;
        v.emplace_back(x, make_pair(y, i));
    }

    sort(ALL(v));

    UnionFind uf(n);

    set<pair<ll, int>> s;
    REP(i, n) {
        ll y = v[i].se.fi; int idx = v[i].se.se;

        auto it = s.lower_bound(make_pair(y, 0));

        if (it == s.begin() || s.empty()) {
            s.emplace(y, idx);
        } else {
            ll my = y;

            for(auto it2 = s.begin(); it2 != it; it2++) {
                uf.merge(idx, it2->se);
                my = min(my, it2->fi);
            }

            s.erase(s.begin(), it);
            s.emplace(my, idx);
        }
    }

    REP(i, n) {
        print(uf.size(i));
    }
}


Measured memory_bytes: 14716
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.nextInt();
            int M = in.nextInt();

            int[] count = new int[N + 1];
            for (int i = 0; i < M; i++) {
                int a = in.nextInt();
                int b = in.nextInt();
                count[a]++;
                count[b]++;
            }

            for (int n : count) {
                if (n % 2 != 0) {
                    out.println("NO");
                    return;
                }
            }
            out.println("YES");
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

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

    }
}



Measured memory_bytes: 41596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);

    int T;
    // cin >> T;
    T = 1;

    while (T--) solve();
}

struct Edge { int to, c; ll t; Edge(int to, int c, ll t) : to(to), c(c), t(t) {} };
void solve() {
  int n, m, s;
  cin >> n >> m >> s;
  chmin(s, 2500);
  ll dp[n][2501];
  rep(i, n) rep(j, 2501) dp[i][j] = INF;
  dp[0][s] = 0;
  vector<vector<Edge> > G(n);
  rep(i, m) {
    int u, v, c, t;
    cin >> u >> v >> c >> t;
    u--; v--;
    G[u].eb(v, c, t);
    G[v].eb(u, c, t);
  }
  vector<int> C(n), T(n);
  rep(i, n) cin >> C[i] >> T[i];

  using p = pair<ll, pii>;
  priority_queue<p, vector<p>, greater<p> > q;
  q.push(p(0, pii(0, s))); // t, v, c
  while (!q.empty()) {
    ll t = q.top().F;
    int v, c;
    tie(v, c) = q.top().S;
    q.pop();
    int nc = min(2500, c + C[v]);
    if (chmin(dp[v][nc], t + T[v])) { // 補充
      q.push(p(t + T[v], pii(v, nc)));
    }
    for (auto ne : G[v]) {
      if (c - ne.c >= 0 && chmin(dp[ne.to][c - ne.c], t + ne.t)) {
        q.push({t + ne.t, {ne.to, c - ne.c}});
      }
    }
  }
  rep3(i, 1, n) {
    ll ans = INF;
    rep(j, 2501) chmin(ans, dp[i][j]);
    cout << ans << endl;
  }
}


Measured memory_bytes: 6116
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 2000000010;
constexpr ll INF= 2000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

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 mod(ll val, ll M) {
    ll res = val % M;
    if(res < 0) {
        res += M;
    }
    return res;
}

// N^P mod M（ただしM == -1の時はmodを取らない）
template<typename T>
T RS(T N, T P, T M){
    if(P == 0) {
        return 1;
    }
    if(P < 0) {
        return 0;
    }
    if(P % 2 == 0){
        ll t = RS(N, P/2, M);
        if(M == -1) return t * t;
        return t * t % M;
    }
    if(M == -1) {
        return N * RS(N,P - 1,M);
    }
    return N * RS(N, P-1, M) % M;
}

int main() {
    int N,X,T;
    cin >> N >> X >> T;
    cout << (N + X - 1) / X * T << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;


template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}

//INSERT ABOVE HERE
signed main(){
  int n;
  cin>>n;
  if(n==2) drop(-1);

  vector<string> st(n,string(n,'.'));
  vector<string> b3(3),b4(4),b5(5),b7(7);

  b3[0]="aab";
  b3[1]="d.b";
  b3[2]="dcc";

  b4[0]="aacd";
  b4[1]="bbcd";
  b4[2]="dcaa";
  b4[3]="dcbb";

  b5[0]="aa.cd";
  b5[1]=".bbcd";
  b5[2]="ffggh";
  b5[3]="e.j.h";
  b5[4]="e.jii";

  b7[0]="aa...ji";
  b7[1]=".bb..ji";
  b7[2]="mncc...";
  b7[3]="mn.dd..";
  b7[4]="..lleef";
  b7[5]="k...h.f";
  b7[6]="k...hgg";

  if(n==7){
    st=b7;
  }else if(n==11){
    int s=0;
    for(int i=0;i<4;i++)
      for(int j=0;j<4;j++)
        st[s+i][s+j]=b4[i][j];
    s+=4;
    for(int i=0;i<7;i++)
      for(int j=0;j<7;j++)
        st[s+i][s+j]=b7[i][j];
    s+=7;
  }else if(n%3==0){
    for(int s=0;s<n;s+=3)
      for(int i=0;i<3;i++)
        for(int j=0;j<3;j++)
          st[s+i][s+j]=b3[i][j];
  }else if(n%4==0){
    for(int s=0;s<n;s+=4)
      for(int i=0;i<4;i++)
        for(int j=0;j<4;j++)
          st[s+i][s+j]=b4[i][j];
  }else if(n%5==0){
    for(int s=0;s<n;s+=5)
      for(int i=0;i<5;i++)
        for(int j=0;j<5;j++)
          st[s+i][s+j]=b5[i][j];
  }else{
    int s=0;
    while((n-s)%5){
      for(int i=0;i<4;i++)
        for(int j=0;j<4;j++)
          st[s+i][s+j]=b4[i][j];
      s+=4;
    }
    while(s<n){
      for(int i=0;i<5;i++)
        for(int j=0;j<5;j++)
          st[s+i][s+j]=b5[i][j];
      s+=5;
    }
  }
  for(int i=0;i<n;i++) cout<<st[i]<<endl;
  return 0;
}


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

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

	sort(array, array + n);
	int answer = abs(array[0] - array[n-1]);
	cout << answer;


	return 0;
}

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

int main() {
    int x, n;
    cin >> x >> n;
    set<int> ps;
    for (int i = 0; i < n; i++) {
        int tmp; cin >> tmp;
        ps.insert(tmp);
    }
    int minDiff = 1000;
    int ans = 0;
    for(int i = 0; i <= 101; i++) {
        if (ps.find(i) != ps.end()) {
            continue;
        }
        int diff = abs(i - x);
        if (diff < minDiff) {
            ans = i;
            minDiff = diff;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep2(i, m, n) for(int i=(int)m; i<(int)n; i++)
#define ALL(vec) vec.begin(), vec.end()
typedef long long ll;
typedef long double ld;

int binom(int64_t N, int64_t K) {
    if(K < 0 || N < K) return 0;
    int ret = 1;
    for(int i = 1; i <= K; ++i) {
        ret *= N--;
        ret /= i;
    }
    return ret;
}

int main(){
    string s;
    int k;
    cin >> s >> k;
    int l = s.size();
    reverse(ALL(s));

    vector<vector<ll>> dp(l, vector<ll>(k+1));
    dp[0][0] = 1;
    dp[0][1] = s[0] - '0';

    rep(i, l-1){
        dp[i+1][0] = 1;
        rep(j, k){
            int a = s[i+1] - '0';
            if(a > 0){
                dp[i+1][j+1] = dp[i][j] + (a - 1) * pow(9, j) * binom(i+1, j)
                                + pow(9, j+1) * binom(i+1, j+1);
            }
            else dp[i+1][j+1] = dp[i][j+1];
        }
    }
    cout << dp[l-1][k] << endl;
}

Measured memory_bytes: 256
//Let's play once again :)
#include<bits/stdc++.h>
using namespace std;

#define tarzan ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long 

int rr[] = {0, 1, 1, 1, 0, -1, -1, -1};
int cc[] = {1, 1, 0, -1, -1, -1, 0, 1};

const int mod = 1e9 + 7;
const int N = 300050;

signed main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	tarzan;
	int test = 1;
	//cin >> test;
	while(test--) {
		int n;
		cin >> n;

		n %= 1000;
		cout << (n ? 1000 - n : 0) << '\n';
	}
	return 0;
}

Measured memory_bytes: 3636
/*
https://atcoder.jp/contests/agc015/tasks/agc015_c

2*2にマスを拡張

#.
..

青がつながってる場合、右と下につける
あとは2次元累積和
*/


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

#define rep(i,n,m) for(ll (i)=(n);(i)<(m);(i)++)
#define rrep(i,n,m) for(ll (i)=(n);(i)>(m);(i)--)
using ll = long long;
const ll mod = 998244353;

int main(){

    int N,M,Q;
    cin >> N >> M >> Q;

    vector<vector<int>> V(N*2+1 , vector<int> (M*2+1,0));
    vector<vector<int>> L(N*2+1 , vector<int> (M*2+1,0));

    vector<string> S(N);
    rep(i,0,N){
        cin >> S[i];
    }

    rep(i,0,N){
        rep(j,0,M){
            if (S[i][j] == '1') V[i*2+1][j*2+1] = 1;
            if (i != N-1 && S[i][j] == '1' && S[i+1][j] == '1') L[i*2+2][j*2+1] = 1;
            if (j != M-1 && S[i][j] == '1' && S[i][j+1] == '1') L[i*2+1][j*2+2] = 1;
        }
    }

    rep(i,0,2*N+1){
        rep(j,0,2*M){
            V[i][j+1] += V[i][j];
            L[i][j+1] += L[i][j];
        }
    }

    rep(j,0,2*M+1){
        rep(i,0,2*N){
            V[i+1][j] += V[i][j];
            L[i+1][j] += L[i][j];
        }
    }

    int x1,x2,y1,y2,nv,nl;
    rep(loop , 0, Q){
        scanf ("%d %d %d %d" , &x1 , &y1 , &x2 , &y2);
        x1--;
        x2--;
        y1--;
        y2--;

        nv = V[x2*2+1][y2*2+1] - V[x1*2][y2*2+1] - V[x2*2+1][y1*2] + V[x1*2][y1*2];
        nl = L[x2*2+1][y2*2+1] - L[x1*2][y2*2+1] - L[x2*2+1][y1*2] + L[x1*2][y1*2];

        printf ("%d\n" , nv - nl);
    }
}

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

int main(){
  int a,b,c,d,p[100001],n,k;
  vector<int> e[100001];
  cin>>a;
  for(int i=0;i<=a;i++)p[i]=-1;
  for(int i=0;i<a;i++){
    cin>>b>>c;
    for(int j=0;j<c;j++){
      cin>>d;
      p[d]=b;
      e[b].push_back(d);
    }
  }
  //cout<<"ttttttt";///////
  for(int i=0;i<a;i++){
    n=i;
    k=0;
    while(p[n]!=-1){
      n=p[n];
      k++;
    }
    cout<<"node "<<i<<": parent = "<<p[i];
    cout<<", depth = "<<k;
    if(p[i]==-1)cout<<", root, [";
    else if(e[i].size()==0)cout<<", leaf, [";
    else cout<<", internal node, [";

    for(int j=0;j<e[i].size();j++){
      cout<<e[i][j];
      if(e[i].size()-j==1);
      else cout<<", ";
    }
    cout<<"]\n";
    
  }
  return 0;
}

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

struct Node{
    int key;
    Node *prev, *next;
};

Node *nil;

void init(){
    nil = (Node *)malloc(sizeof(Node));
    nil -> next = nil;
    nil -> prev = nil;
}

void insert(int key){
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;

    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
    
}

Node* listSearch(int key){
    Node *x = nil->next;
    while(x != nil && x->key != key){
        x = x->next;
    }
    return x; //あればそのポインタを返すなければNilを返す．
}

void deleteNode(Node *t){
    if(t == nil) return; //tが番兵の場合は処理しない
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst(){
    deleteNode(nil->next);
}

void deleteLast(){
    deleteNode(nil->prev);
}

void deleteKey(int key){
    deleteNode(listSearch(key));
}

int main(){
    int n; 
    scanf("%d",&n);
    init();
    char com[20];
    int key;
    rep(i,n){
        scanf("%s%d",com, &key);
        if(com[0] == 'i') insert(key);
        else{
            if(strlen(com) > 6){
                if(com[6] == 'F'){
                    deleteFirst();
                }else if(com[6] == 'L'){
                    deleteLast();
                }
            }else{
                deleteKey(key);
            }
        }
    }
    //出力
    Node *y = nil->next;
    while(y != nil){
        if(y != nil->next) printf(" ");
        printf("%d",y->key);
        y = y->next;
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 34364