akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
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; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

int main(){
  ll N;
  ld A,B,C,D,X=0;
  cin >> N >> A >> B >> C >> D;
  ld T=(ld)(N-1)*(D-C)/2;
  ld M=(D+C)/2;
  ld K=fabs(A-B);
  rep(i,N-1){
    if(X<K){
      X+=M;
    }
    else{
      X-=M;
    }
  }
  if(X+T>=K && X-T<=K){
    cYES;
  }
  else{
    cNO;
  }
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 7;
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b, a%b);
}
int main(){
    ll a, b;
    cin >> a >> b;
    if(b>a) swap(a, b);
    cout << (a*b) / gcd(a, b);
}

Measured memory_bytes: 256
from functools import reduce
from operator import mul

def cmb(n,r):
  r = min(r, n-r)
  if r==0: return 1
  if r<0: return 0
  over = reduce(mul, range(n, n-r, -1))
  under = reduce(mul, range(1,r+1))
  return over//under

class UnionFind:
  def __init__(self, n):
    self.par = [i for i in range(n)]
    self.dic = {i:1 for i in range(n)}
    self.rank = [0]*n
  def find(self, x):
    if self.par[x]==x:
      return x
    else:
      self.par[x] = self.find(self.par[x])
      return self.par[x]
  def unit(self, x, y):
    x = self.find(x)
    y = self.find(y)
    if x==y:
      return
    elif self.rank[x]<self.rank[y]:
      self.par[x] = y
      self.dic[y] += self.dic.pop(x)
      
      return
    elif self.rank[y]<self.rank[x]:
      self.par[y] = x
      self.dic[x] += self.dic.pop(y)
    else:
      self.par[y] = x
      self.dic[x] += self.dic.pop(y)
      self.rank[x] += 1
  def same(self, x, y):
    return self.find(x)==self.find(y)


N, M = map(int, input().split())
bridge = []
u = UnionFind(N)
m = cmb(N,2)
ans = [m]

for i in range(M):
  A, B = map(int, input().split())
  bridge += [(A,B)]
  
for i in range(M-1,0,-1):
  a, b = bridge[i]
  if u.same(a-1,b-1):
    ans += [m]
    continue
  pa = u.find(a-1)
  pb = u.find(b-1)
  m -= u.dic[pa]*u.dic[pb]
  ans += [m]
  u.unit(a-1,b-1)

for i in range(M-1,-1,-1):
  print(ans[i])

Measured memory_bytes: 33140
import sys
input = sys.stdin.buffer.readline


def combination(k, r, MOD):
    """kCrを求める"""
    if k < r:
        return 0
    r = min(r, k - r)
    numer, denom = 1, 1
    for l in range(r):
        numer *= (k - l)
        numer %= MOD
        denom *= l + 1
        denom %= MOD
    return numer * pow(denom, MOD - 2, MOD) % MOD


n, a, b = map(int, input().split())
MOD = 10 ** 9 + 7


all_ptn = pow(2, n, MOD)
a_ptn = combination(n, a, MOD)
b_ptn = combination(n, b, MOD)

ans = (all_ptn - (a_ptn + b_ptn) - 1) % MOD
print(ans)

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i=0; i<N; ++i) cin >> vec[i];
  sort(vec.begin(), vec.end());
  
  int answer = 0;
  for(int i=0; i<N; ++i) {
    for(int j=0; j<i; ++j) {
      for(int k=0; k<j; ++k) {
        if(vec[k] != vec[j] && vec[i] != vec[j] && vec[k] + vec[j] > vec[i]) {
          answer++;
        }
      }
    }
  }
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 3632
import itertools
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N = int(sys.stdin.buffer.readline())
X, Y, H = list(zip(*[map(int, sys.stdin.buffer.readline().split()) for _ in range(N)]))
X = np.array(X, dtype=int)
Y = np.array(Y, dtype=int)
H = np.array(H, dtype=int)

# ゼロのやつ使いたくない
idx = np.where(H > 0)[0][0]

# 全探索して矛盾がないのを探す
for x, y in itertools.product(range(101), range(101)):
    height = H[idx] + abs(X[idx] - x) + abs(Y[idx] - y)
    ok = np.all(np.maximum(0, height - (np.abs(X - x) + np.abs(Y - y))) == H)
    if ok:
        print(x, y, height)
        exit()


Measured memory_bytes: 12520
#include <bits/stdc++.h>
using namespace std;
deque<int> dq;
int n,a;
int main(){
    cin.tie(0);  ios::sync_with_stdio(false);
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        if(i%2)dq.push_back(a);
        else dq.push_front(a);
    }
    
    if(n%2){
        for(auto it=dq.begin();it!=dq.end();it++)
            cout<<(it==dq.begin()?"":" ")<<*it;
    }else{
        for(auto it=dq.end()-1;it>=dq.begin();it--)
        cout<<(it==dq.end()-1?"":" ")<<*it;
    }
    cout<<"\n";
    
    
    return 0;
}


Measured memory_bytes: 3072
n=int(input())
s=[0]*n
s[:]=map(int,input().split())
import copy
s0=copy.copy(s)
s.sort()
a=[1 if s[ii]!=s0[ii] else 0 for ii in range(len(s))]
#print(s0)
#print(s)
if sum(a)<=2:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3444
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    int n;
    ll d;
    cin >> n >> d;
    ll dd = d * d;
    int ans = 0;
    rep(_, n) {
        ll x, y;
        cin >> x >> y;

        ll xx = x * x;
        ll yy = y * y;

        ll xxyy = xx + yy;

        bool b = xxyy <= dd;
        if (b) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> adj[2005];
ll n,cnt[2005],dist[2005][2005];
void bfs(ll src,ll dist[2005]){
    for(ll i=1;i<=n;i++)dist[i]=(1e13);
    dist[src]=0;
    queue< ll > q;
    q.push(src);
    while(!q.empty()){
        ll u = q.front();
        q.pop();
        for(auto &v:adj[u]){
            if(dist[v] > dist[u] + 1)dist[v]=dist[u]+1,q.push(v);
        }
    }
}
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll x,y;cin>>n>>x>>y;
    for(ll i=1;i<n;i++)adj[i].push_back(i+1),adj[i+1].push_back(i);
    adj[x].push_back(y);
    adj[y].push_back(x);
    for(ll i=1;i<=n;i++)bfs(i,dist[i]);
    for(ll i=1;i<=n;i++)for(ll j=1;j<=n;j++)cnt[dist[i][j]]++;
    for(ll i=1;i<=n-1;i++)cout<<cnt[i]/2<<"\n";
}


Measured memory_bytes: 31744
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextInt();
		long d = sc.nextInt();
		long gcd = gcd(c, d);
		long lcm = c * d / gcd;
		long divC = divider(a, b, c);
		long divD = divider(a, b, d);
		long divLcm = divider(a, b, lcm);
		long ans = b - a + 1 - divC - divD + divLcm;
		System.out.println(ans);
	}
	static long divider(long a, long b, long c){
		long divA = a / c;
		long divB = b / c;
		long modA = a % c;
		long modB = b % c;
		long ret = divB - divA;
		if(modA == 0){
			ret++;
		}
		return ret;
	}
	static long gcd(long c, long d){
		if(c > d){
			return gcd(d, c);
		}
		long mod = d % c;
		if(mod == 0){
			return c;
		}else{
			return gcd(mod, c);
		}
	}
}


Measured memory_bytes: 23124
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;

int main() {
  int h, w; cin >> h >> w;

  if (h % 3 == 0 || w % 3 == 0) {
    cout << 0 << endl;
    return 0;
  }

  auto f = [](ll a, ll b) {
    ll res = a * b;
    ll s = a / 2;
    ll t = a % 2 == 0 ? s : s + 1;
    ll l = 0;
    ll u = s * b, d = t * b;
    for (int i = 1; i < b; i++) {
      l += a;
      u -= s;
      d -= t;
      res = min(res, max({abs(l-u), abs(l-d), abs(u-d)}));
    }
    if (b > 2) {
      ll p1, p2, p3;
      p1 = p2 = p3 = b / 3 * a;
      if (b % 3 >= 1) p1 += a;
      if (b % 3 == 2) p2 += a;
      res = min(res, max({abs(p1-p2), abs(p2-p3), abs(p3-p1)}));
    }
    return res;
  };

  cout << min(f(h, w), f(w, h)) << endl;
}

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

int main(){
  int X;
  cin>>X;
  
  int max=0;
  
  for(int i=1;i<=X;i++){
    
    for(int j=2;j<=X+1;j++){
      if(pow(i,j)<=X&&max<pow(i,j)){
        max=pow(i,j);
      }
    }
  }
  
    
  
  cout<<max<<endl;
}

   

Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P) 
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }

const double EPS = 1e-10;
double error;
int main() {
    while (cin >> error) {
        if (error < EPS) break;
        
        int a[3];
        int res = -1;
        for (int i = 1; i <= 1000000; ++i) {
            double shi = acos(-1.0) * i;
            a[0] = (int)shi;
            a[1] = a[0]-1, a[2] = a[0]+1;
            
            bool ok = false;
            double Min = 1<<29;
            for (int j = 0; j < 3; ++j) {
                double er = abs( (double)(a[j])/i - acos(-1.0)) ;
                if (er <= error) ok = true;
                if ( chmin(Min, er) ) {
                    res = a[j];
                }
            }
            if (ok) {
                cout << res << "/" << i << endl;
                break;
            }
        }   
    }
    return 0;
}


Measured memory_bytes: 1228
//#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <set>

using namespace std;

//ifstream cin("tema.in");
//ofstream cout("tema.out");

const int MOD = 1000000007;
const int MAXN = 3000;

int dp[2][1 + MAXN][1 + MAXN];

void Add(int &x, int y) {
    x += y;
    if (x >= MOD)
        x -= MOD;
}

int main() {
    int n, m;
    cin >> n >> m;
    n--;
    m--;
    if (!n) {
        int answer = 4;
        for (int i = 1; i <= m; i++)
            Add(answer, answer);
        cout << answer << "\n";
        return 0;
    }
    int answer = 0;
    dp[1][0][m] = 1;
    for (int i = 1; i <= n; i++)
        dp[0][i][m] = 1;
    for (int j = m - 1; j >= 0; j--) {
        Add(dp[1][0][j], dp[1][0][j + 1]);
        Add(dp[1][0][j], dp[1][0][j + 1]);
        Add(dp[1][0][j], dp[1][1][j + 1]);
        Add(dp[1][0][j], dp[0][1][j + 1]);
        Add(dp[0][1][j], dp[0][1][j + 1]);
        Add(dp[0][1][j], dp[0][1][j + 1]);
        Add(dp[0][1][j], dp[0][2][j + 1]);
        Add(dp[1][1][j], dp[1][1][j + 1]);
        Add(dp[1][1][j], dp[1][1][j + 1]);
        Add(dp[1][1][j], dp[1][0][j + 1]);
        Add(dp[1][1][j], dp[1][2][j + 1]);
        for (int i = 2; i <= n; i++) {
            Add(dp[0][i][j], dp[0][i][j + 1]);
            Add(dp[0][i][j], dp[0][i][j + 1]);
            Add(dp[0][i][j], dp[0][i - 1][j + 1]);
            Add(dp[0][i][j], dp[0][i + 1][j + 1]);
            Add(dp[1][i][j], dp[1][i][j + 1]);
            Add(dp[1][i][j], dp[1][i][j + 1]);
            Add(dp[1][i][j], dp[1][i - 1][j + 1]);
            Add(dp[1][i][j], dp[1][i + 1][j + 1]);
        }
    }
    for (int i = 0; i <= n; i++)
        Add(answer, dp[1][i][0]);
    answer = (1LL * answer * 4) % MOD;
    cout << answer << "\n";
    return 0;
}


Measured memory_bytes: 70528
from itertools import permutations
import bisect

N = int(input())
P = input().replace(' ', '')
Q = input().replace(' ', '')

t = [''.join(list(map(str, i))) for i in permutations(range(1, N + 1))]
a = bisect.bisect_left(t, P)
b = bisect.bisect_left(t, Q)

print(abs(a-b))

Measured memory_bytes: 43484
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            out.println((n * (n + 1)) / 2);
        }

    }
}



Measured memory_bytes: 20948
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main() {
	int s;
	cin >> s;
	string k;
	cin >> k;
	if (s < k.length()) {
		
		k = k.substr(0, s) + "...";
	}
	cout << k;
	return 0;
}

Measured memory_bytes: 3612
import numpy as np
import math
def ncm(n,m):
    return math.factorial(n)/(math.factorial(m) * math.factorial(n-m))

N, A, B = map(int, input().split())
v = list(map(int, input().split()))
v.sort(reverse=True)
v = np.array(v)
##print(v)
ansarray = v[0:A]
##print(ansarray)
ave = np.mean(ansarray)
print(float(ave))
mi = min(ansarray)
ma = max(ansarray)
biggerarray = v[v>mi]
m = len(biggerarray)
numminarray = v[v==mi]
a = len(numminarray)
##print(nummin)
##print(num_kouho)
ans = 0
if ma == mi:
    if m+a <= B:
        for i in range(A-m,a+1):
            ans+=ncm(a,i)
    else:
        for i in range(A-m,B-m+1):
            ans+=ncm(a,i)

else:
    ans = ncm(a,A-m)
#print('a=',a)
#print('m=',m)
print(int(ans))
    


Measured memory_bytes: 12448
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for (int i = 0; i < (int)c; i++)
#define all(v) v.begin(), v.end()
const int inf = 1000000000; //10^9
using ll = long long;
using P = pair<int,int>;
//加算代入演算子は+=！！！！！
//int 2^31 10^9まで
int main() {
    char c;
    cin >> c;
    if(c == 'a' || c == 'e' ||  c == 'i' || c == 'o' || c == 'u') {
        cout << "vowel" << endl;
    }
    else cout << "consonant" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define INF 1000000007
using namespace std;

int main(void) {
	int n,d,x,a,sum=0;
	cin >> n >> d >> x;
	for(int i=0; i<n; i++){
		cin >> a;
		for(int i=0; i*a<d; i++)sum++;
	}
	cout << sum+x << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define pp pair<ll,ll>
#define vi vector<pair<pp,pp> >
#define pq_min priority_queue<ll,vector<ll>,greater<ll>>
#define pq_max priority_queue<ll>
#define f(i,a,b) for(ll i=a;i<b;i++)
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define fill(a,b) memset((a),(b),sizeof((a)))
#define ld long double
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef pair<pp,pp> ppll;
const ll mod=1e9+7;
ll lookup[101][501];

ll power(ll a,ll b)
{
    ll res=1;
    a%=mod;
    while(b>0)
    {
        if(b%2==1)
        {
            res = (res * a)%mod;
        }
        b/=2;
        a = (a*a)%mod;
    }
    return res;
}

 

int main()
{
    fast;
    ll n,m;
    cin>>n>>m;
    ll x=n%m;
    cout<<min(x,m-x);
    
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <bitset>
#include <string>
#include <time.h>
using namespace std;
long double esp=1e-11;
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define cle(a) while(!a.empty())a.pop()
#define mem(p,c) memset(p,c,sizeof(p))
#define mp(A, B) make_pair(A, B)
#define pb push_back
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
typedef long long int LL;
const long double PI = acos((long double)-1);
const LL INF=0x3f3f3f3fll;
const int MOD =1000000007ll;
const int maxn=500;
int f[10][10];
int d[5],g[5];
int cal()
{
    int t=0;
    for(int x=0;x<5;x++)
        t=f[t][g[x]];
    return t;
}
int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("in1.txt", "w", stdout);
    //::iterator iter;                  %I64d
    //for(int x=1;x<=n;x++)
    //for(int y=1;y<=n;y++)
    //scanf("%d",&a);
    //printf("%d\n",ans);
    for(int x=0;x<10;x++)
        for(int y=0;y<10;y++)
            scanf("%d",&f[x][y]);
    int ans=0;
    for(int x=0;x<10000;x++)
    {
        int t=x;
        for(int z=0;z<4;z++)
        {
            d[3-z]=t%10;
            t/=10;
        }
        t=0;
        for(int y=0;y<4;y++)
            t=f[t][d[y]];
        d[4]=t;
        int flag=0;
        for(int y=0;y<=3;y++)
        if(d[y]!=d[y+1])
        {
            for(int z=0;z<5;z++)g[z]=d[z];
            swap(g[y],g[y+1]);
            if(cal()==0)flag=1;
        }
        for(int y=0;y<=4;y++)
        for(int k=0;k<10;k++)
        if(k!=d[y])
        {
            for(int z=0;z<5;z++)g[z]=d[z];
            g[y]=k;
            if(cal()==0)flag=1;
        }
        ans+=flag;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 3204
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n;
	cin >> n;
	
	deque<int> dq;
	for(int i = 0; i < n; ++i) {
		int a;
		cin >> a;
		
		if( i % 2 == 0 ) dq.push_front(a);
		else dq.push_back(a);
	}
	
	if( n % 2 == 0 ) reverse(dq.begin(), dq.end());
	
	for(auto& ans : dq) {
		cout << ans << " ";
	}
	
	cout << endl;
	
	return 0;
}


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

int main() {
	char a;
	cin >> a;
	if(a>='a' && a<='z') cout << "a" << endl;
	else cout << "A" << endl;
	return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	string S; cin >> S; 
	if(S == "SSS") cout << 0 << "\n"; 
	if(S == "SSR") cout << 1 << "\n"; 
	if(S == "SRS") cout << 1 << "\n"; 
	if(S == "SRR") cout << 2 << "\n"; 
	if(S == "RSS") cout << 1 << "\n"; 
	if(S == "RSR") cout << 1 << "\n"; 
	if(S == "RRS") cout << 2 << "\n"; 
	if(S == "RRR") cout << 3 << "\n"; 
}

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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	set<int> edge[n];
	char a;
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			cin>>a;
			if (a=='1')
			{
				edge[i].insert(j);
				edge[j].insert(i);
			}
		}
	}
	for (int i = 0; i < n; ++i)
	{
		for (auto j:edge[i])
		{
			if (j<i)
			{
				continue;
			}
			queue<int> que;
			int memo[n];
			for (int k = 0; k < n; ++k)
			{
				memo[k]=-1;
			}
			memo[i]=1;
			que.push(i);
			while (!que.empty())
			{
				int now=que.front();que.pop();
				for (auto v:edge[now])
				{
					if (v==j)
					{
						if (now==i)
						{
							continue;
						}
						memo[j]=memo[now]+1;
						break;
					}
					else if (memo[v]==-1)
					{
						memo[v]=memo[now]+1;
						que.push(v);
					}
				}
				if (memo[j]!=-1)
				{
					break;
				}
			}
			if (memo[j]%2==1)
			{
				cout<<"-1\n";
				return 0;
			}
		}
	}
	int dist[n][n]={};
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			if (i==j)
			{
				continue;
			}
			dist[i][j]=(1<<20);
		}
	}
	for (int i = 0; i < n; ++i)
	{
		for (auto j:edge[i])
		{
			dist[i][j]=1;
			dist[j][i]=1;
		}
	}
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			for (int k = 0; k < n; ++k)
			{
				dist[j][k]=min(dist[j][k],dist[j][i]+dist[i][k]);
			}
		}
	}
	int ans=0;
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			if (dist[i][j]!=(1<<20))
			{
				ans=max(ans,dist[i][j]);
			}
		}
	}
	cout<<ans+1<<endl;
	return 0;
}


Measured memory_bytes: 2176
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main implements Runnable {

	public static void main(String[] args) {

		new Thread(null, new Main(), "", 16 * 1024 * 1024).start();

	}

	@Override
	public void run() {
		exec();
	}

	private void exec() {

		FastScanner sc = new FastScanner(System.in);
		String s = sc.next();
		long ans = 0;
		// bit全検索
		for(int i = 0 ; i < 1 << s.length() - 1 ; i++) {
			StringBuilder sb = new StringBuilder();
			for(int j = 0 ; j < s.length() ; j++) {
				sb.append(s.charAt(j));
				if((1 & i >> j) == 1) {
					sb.append("a");
				}
			}
			String[] array = sb.toString().split("a");
			ans += Arrays.stream(array).mapToLong(Long::parseLong).sum();
		}
		System.out.println(ans);
	}

}

class FastScanner {

	private final InputStream in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	public FastScanner(InputStream in) {
		this.in = in;
	}

	private boolean hasNextByte() {
		if(ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if(buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if(hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while(hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
		return hasNextByte();
	}

	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while(isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			}else if(b == -1 || !isPrintableChar(b)){
				return minus ? -n : n;
			}else{
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

}


Measured memory_bytes: 27604
n = gets.to_i
cnt = 0
n.times do
  d1, d2 = gets.split.map(&:to_i)
  if d1 == d2
    cnt += 1
    if cnt >= 3
      puts 'Yes'
      exit
    end
  else
    cnt = 0
  end
end
puts 'No'

Measured memory_bytes: 14296
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <memory.h>
#include <memory>
using namespace std;

typedef long long ll;

ll dp[20][20];
bool g[20][20][20][20];

int main(){
  int n;
  cin >> n;
  for(int i = 0; i < n; i++){
    memset(g, true, sizeof(g));
    memset(dp, 0, sizeof(dp));
    int gx, gy;
    int p;
    cin >> gx >> gy;
    cin >> p;
    for(int j = 0; j < p; j++){
      int ax, ay, bx, by;
      cin >> ax >> ay >> bx >> by;
      g[ax][ay][bx][by] = false;
      g[bx][by][ax][ay] = false;
    }
    dp[0][0] = 1;
    for(int j = 0; j <= gx; j++){
      for(int k = 0; k <= gy; k++){
	if(g[j][k][j+1][k]) dp[j+1][k] += dp[j][k];
	if(g[j][k][j][k+1]) dp[j][k+1] += dp[j][k];
      }
    }
    if(dp[gx][gy] == 0) cout << "Miserable Hokusai!" << endl;
    else cout << dp[gx][gy] << endl;
  }
  return 0;
}
    

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

int h, w; lint k;

struct node{
    int i, j, dr;
    lint cost;
};

bool operator<(const node &l, const node& r){
    return l.cost > r.cost;
}

node next(node x){
    node y = x; y.cost += 1;
    if(x.dr == 0) y.i++;
    else if(x.dr == 1) y.j++;
    else if(x.dr == 2) y.i--;
    else y.j--;
    return y; 
}

bool isok(node x){
    if(x.i<0 || x.i>=h || x.j<0 || x.j>=w) return false;
    return true;
}

int id(node x){
    return x.i*w + x.j + h*w*x.dr;
}

int main(){
    cin>>h>>w>>k;
    int x1, y1, x2, y2; cin>>x1>>y1>>x2>>y2;
    x1--; y1--; x2--; y2--;

    vector<string> c(h);
    rep(i, h) cin >> c[i];

    vector<lint> d(h*w*4, INF);
    priority_queue<node> que;
    rep(l, 4){
        node e = {x1, y1, l, 0};
        que.push(e);
        d[id(e)] = 0;
    }

    while(!que.empty()){
        node p = que.top(); que.pop();
        if(d[id(p)] < p.cost) continue;
        node q = next(p);
        if(isok(q) && c[q.i][q.j] == '.'){
            if(d[id(q)] > q.cost){
                d[id(q)] = q.cost;
                que.push(q);
            }
        }
        rep(l, 2){
            node q = p;
            q.dr = (q.dr+l*2+1)%4;
            q.cost = ((p.cost+k-1)/k)*k;
            if(d[id(q)] > q.cost){
                d[id(q)] = q.cost;
                que.push(q);
            }
        }
    }

    lint ans = INF;
    rep(l, 4){
        node p = {x2, y2, l, 0};
        if(d[id(p)] != INF) ans = min(ans, (d[id(p)]+k-1)/k);
    }
    if(ans > 1e8) ans = -1;
    out(ans);
}

Measured memory_bytes: 42120
N, K = [int(i) for i in input().split()]
H = [int(i) for i in input().split()]

dp = [0] * (N+1)

for i in range(1, N):
    dp[i] = min([
        dp[i-k] + abs(H[i]-H[i-k])
        for k in range(1, 1+min(i, K))
    ])

print(dp[N-1])


Measured memory_bytes: 52448
import fractions
A, B, C, D = map(int, input().split())
G = C * D // fractions.gcd(C, D)
ag = (A - 1) // G
ac = (A - 1) // C
ad = (A - 1) // D
bg = B // G
bc = B // C
bd = B // D
print((B - A + 1) - ((bc + bd - bg) - (ac + ad - ag)))


Measured memory_bytes: 5048
#include <iostream>
#include <iomanip>
#include <vector>

int main() {
    int n;
    std::cin >> n;
    std::vector<double> p(n+1);
    for(int i = 1; i < n+1; ++i) {
        std::cin >> p[i];
    }
    
    // dp[i][j] -> probability of getting j heads after tossing the first i coins
    std::vector<std::vector<double>> dp(n+1, std::vector<double>(n+1, 0.0));
    
    for(int i = 0; i < n+1; ++i) {
        dp[0][i] = 0.0;
    }
    dp[1][0] = (1-p[1]);
    dp[1][1] = p[1];
    double ans = 0.0;
    for(int coins = 2; coins < n+1; ++coins) {
        for(int heads = 0; heads <= coins; ++heads) {
            if(heads == 0) {
                dp[coins][heads] = dp[coins-1][heads]*(1-p[coins]);
                continue;
            }
            if(heads == coins) {
                dp[coins][heads] = dp[coins-1][heads-1]*p[coins];
                if(heads == n) {
                    ans += dp[coins][heads];
                }
                continue;
            }
            dp[coins][heads] = dp[coins-1][heads]*(1-p[coins]) + dp[coins-1][heads-1]*p[coins];
            if(coins == n && heads > n/2) {
                ans += dp[coins][heads];
            }
        }
    }
    if(n == 1) {
        ans += p[1];
    }
    std::cout << std::fixed << std::setprecision(9) << ans << "\n";
}

Measured memory_bytes: 73764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef set<ll> sl;
typedef pair<int,int> pii;
#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 all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

ll n;
vl a;
vl psum;
map<ll, ll> cnt;


int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("in.txt", "r", stdin);
	cin >> n;
	a.resize(n+1);
	rep(i,1,n+1) {
		cin >> a[i];
	}
	psum.resize(n+1);
	rep(i,1,n+1) {
		psum[i] = psum[i-1] + a[i];
	}
	rep(i,1,n+1) {
		if(cnt.find(psum[i]) != cnt.end()) {
			cnt[psum[i]]++;
		} else {
			cnt[psum[i]] = 1;
		}
	}
	ll ret = 0;
	rep(i,1,n+1) {
		if(cnt.find(psum[i-1]) != cnt.end()) {
			ret += cnt[psum[i-1]];
		}
		cnt[psum[i]]--;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 15872
//Har Har Mahadev
using namespace std;
#include <bits/stdc++.h>
#define booga cout << "booga" << endl
#define ll long long int
#define pb push_back
#define mp make_pair
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " -> " << a << endl;
	err(++it, args...);
}

void testcase(){
	int n;
	cin >> n;
	ll ans = 0;
	for(int a{1};a < n;a++){
		ans += (n-1)/a;
	}
	cout << ans;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	while(t--){
		testcase();
	}
	return 0;
}


Measured memory_bytes: 3648
import java.util.*;
import java.io.*;

public class Main {
    static final int MOD = 1000000007;
	public static void main (String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] dp = new int[n + 1];
		dp[0] = 1;
		HashMap<Integer, Integer> map = new HashMap<>();
		for (int i = 1; i <= n; i++) {
		    dp[i] = dp[i - 1];
		    int x = Integer.parseInt(br.readLine());
		    if (map.containsKey(x)) {
		        int y = map.get(x);
		        if (y + 1 < i) {
		            dp[i] += dp[y];
		            dp[i] %= MOD;
		        }
		    }
		    map.put(x, i);
		}
		System.out.println(dp[n]);
    }
}



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

int main(){
    int S[10010], n, q, x, ans = 0;
    cin >> n;
    for(int i = 0; i < n; i++) cin >> S[i];
    cin >> q;
    for(int i = 0; i < q; i++){
        cin >> x;
        for(int j = 0 ; j < n; j++){
            if(S[j] == x){
                ans++;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3132
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

struct Node {
	int type; // 0:normal, 1:or, 2:alt
	bool op; //true:option, false:normal
	
	Node() {}
	Node(int type, bool op)  :type(type), op(op) {}
};

int mod = 1000000007;
vector<int> g[1000];
Node node[1000];
int n;
int memo[1000];

int dfs(int pos) {
	if (memo[pos] != -1) return memo[pos];
	
	Node &now = node[pos];
	
	int res = 0;
	if (g[pos].size() == 0) memo[pos] = 1 + now.op;
	
	if (now.type == 0) {
		int plus = 1;
		REP(i, g[pos].size()) {
			plus = ((long long)plus * dfs(g[pos][i])) % mod;
		}
		res = (res + plus) % mod;
	}
	
	if (now.type == 1) {
		FOR(bit, 1, 1<<g[pos].size()) {
			int plus = 1;
			REP(i, g[pos].size()) {
				if ((bit >> i) & 1) {
					plus = ((long long)plus * dfs(g[pos][i])) % mod;
				}
			}
			res = (res + plus) % mod;
		}
	}
	
	if (now.type == 2) {
		REP(i, g[pos].size()) res = (res + dfs(g[pos][i])) % mod;
	}
	
	res = (res + now.op) % mod;
	
	return memo[pos] = res;
}

int main() {
	cin >> n;
	REP(i, n) {
		string str;
		cin >> str;
		int type = 0;
		if (str[0] == 'R') type = 1;
		if (str[0] == 'A') type = 2;
		
		node[i] = Node(type, str.size() == 2);
	}
	
	REP(i, n - 1) {
		int a, b;
		scanf("%d %d", &a, &b);
		a--; b--;
		g[a].push_back(b);
	}
	
	int st;
	bool done[1000] = {};
	REP(i, n) REP(j, g[i].size()) done[g[i][j]] = true;
	REP(i, n) if (!done[i]) st = i;
	
	fill(memo, memo + n, -1);
	cout << dfs(st) << endl;
	
	return 0;
}

// 1:54

Measured memory_bytes: 3280
# coding: utf-8
 
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1) # 木の高さ
        self.n = [1] * (n+1)    # グループメンバー数
        
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    
    def find_n(self, x):
        return self.n[self.find(x)]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.n[y] = self.n[x] + self.n[y]
        else:
            self.par[y] = x
            self.n[x] = self.n[x] + self.n[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
    
    def is_same(self, x, y):
        return self.find(x) == self.find(y)
    
# -------------------------------------------------------------------

N, M = [int(i) for i in input().split()]

bridges = [tuple(int(i) for i in input().split()) for j in range(M)]

bridges = bridges[::-1]

result = []

now = int(N * (N-1) / 2) #最終不便さ

uf = UnionFind(N)

for i in range(M):
    result.append(now)
    a = bridges[i][0]
    b = bridges[i][1]
    if uf.is_same(a, b): # 既に同じグループ
        pass
    else:
        now -= uf.find_n(a) * uf.find_n(b)
        uf.union(uf.find(a), uf.find(b))

result = result[::-1]

for i in result:
    print(i)

Measured memory_bytes: 25300
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


using namespace std;


int d[101][101];
int N, M;

void warshall_floyd() {
    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
        }
    }
}

int main(){
    cin >> N >> M;
    int a[M], b[M], c[M];
    rep(i, N){
        rep(j, N){
            if (i != j) {
                d[i][j] = 50000000;
            } else {
                d[i][j] = 0;
            }
        }

    }

    rep(i, M) {
        cin >> a[i] >> b[i] >> c[i];
        d[a[i]-1][b[i]-1] = c[i];
        d[b[i]-1][a[i]-1] = c[i];
    }

    warshall_floyd();


    int ans = 0;

//    rep(i, N){
//        rep(j, N){
//            cout << i << " " << j << " " << d[i][j] << endl;
//        }
//    }

    rep(i, M){
        if (d[a[i]-1][b[i]-1] != c[i]) {
            ans++;
        }
    }



    cout << ans << endl;




}

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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
 
Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

int main() {
    Int n, q;
    cin >> n >> q;
    vector<tuple<Int, Int, Int>> v(n);
    for (Int i = 0; i < n; i++) {
        Int s, t, x;
        cin >> s >> t >> x;
        v[i] = make_tuple(s, t, x);
    }
    vector<Int> d(q);
    for (Int i = 0; i < q; i++) {
        cin >> d[i];
    }
    vector<tuple<Int, Int, Int>> query;
    for (Int i = 0; i < n; i++) {
        Int s = get<0>(v[i]);
        Int t = get<1>(v[i]);
        Int x = get<2>(v[i]);
        query.emplace_back(s - x, x, 1);
        query.emplace_back(t - x, x, 0);
        //cout<< s - x << " " << t - x << endl;
    }
    sort(all(query));
    set<Int> st;
    st.insert(INF);
    Int cur = 0;
    for (Int i = 0; i < q; i++) {
        while (cur < (Int)query.size() and get<0>(query[cur]) <= d[i]) {
            //cout << get<0>(query[cur]) << " " << d[i] << endl;
            Int x = get<1>(query[cur]);
            Int mode = get<2>(query[cur]);
            if (mode == 1) {
                st.insert(x);
            } else {
                st.erase(x);
            }
            cur++;
        }
        if (cur == (Int)query.size()) {
            dump(-1);
        } else {
            Int mi = *st.begin();
            dump(mi == INF ? -1 : mi);
        }
    }
    return 0;
}

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

int X[11][11];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, D;
    cin >> N >> D;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < D; j++) cin >> X[i][j];
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            int dist = 0;
            for (int k = 0; k < D; k++) dist += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
            for (int i = 1; i * i <= dist; i++) {
                if (i * i == dist) ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int n,k;cin>>n>>k;
  vector<int>h(n);
  rep(i,n)cin>>h[i];
  sort(all(h));
  ll cnt=0;
  rep(i,n-k){
    cnt+=h[i];
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int n, k; cin >> n >> k;
    vector<int> p(n), c(n);
    rep(i,n) {
        cin >> p[i], p[i]--;
    }
    rep(i,n) cin >> c[i];
    ll ans = -1e18;
    rep(si, n){
        int x = si;
        ll loop = 0;
        vector<int> s;
        while(true){
            x = p[x];
            loop += c[x];
            s.push_back(c[x]);
            if(x == si) break;
        }
        int len = s.size();
        ll tot = 0;
        rep(i,len){
            tot += s[i];
            if(i+1 > k) break;//
            ll now = tot;
            if(loop > 0) now += loop * ((k - (i+1))/ len);
            ans = max(ans, now);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3720
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
using namespace std;
int T;
long n, k;
long house[100002];
long dis[100002];

int main()
{
    cin >> T;
    while (T--)
    {
        cin >> n >> k;
        for (long i = 0; i < n; ++i)
        {
            cin >> house[i];
        }
        memset(dis, 0, sizeof(dis));
        for (long i = 0; i < n - 1; ++i)
        {
            dis[i] = house[i + 1] - house[i];
        }
        long ans = house[n - 1] - house[0];
        sort(dis, dis + n - 1);
        for (long i = 0; i < k -1; ++i)
        {
            ans -= dis[n-2-i];
        }
        if (ans < 0)
            ans = 0;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 4736
from fractions import gcd
N = int(input())
a = list(map(int,input().split()))

def lcm(x,y):
  return x*y//gcd(x,y)

l = a[0]
for i in range(1,N):
  temp = lcm(l,a[i])
  l = temp

l -= 1
ans = 0
for i in range(N):
  ans += (l % a[i])
print(ans)

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

using namespace std;

#define DB( x ) cout << #x << " = " << x << endl;
#define LEFT(n) (2 * (n))
#define RIGHT(n) (2 * (n) + 1)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> node;
//typedef vector <vector <ll>> matrix;

const ll INF = 1e16;
const double EPS = 1e-9;
const ll MOD = (ll)(1e9 + 7);
const ll MAXV = (ll)(2e5 + 10);
const ll MAXE = (ll)(1e6 + 10);

ll dp[MAXV];
ll n;
vector<pair<ll, int>> G;
ll A[MAXV], B[MAXV];
ll cnt[MAXV];

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

	cin >> n;

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

	ll aux = 1;
	for(int i = 1;i < n;i ++){
		if(A[i] == A[i - 1])
			aux ++;
		else{
			cnt[(int)G.size()] = aux;
			B[(int)G.size()] = A[i - 1];
			G.push_back(make_pair(A[i - 1], (int)G.size()));
			aux = 1;
		}
	}
	cnt[(int)G.size()] = aux;
	B[(int)G.size()] = A[n - 1];
	G.push_back(make_pair(A[n - 1], (int)G.size()));


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

	ll ans = 0;

	for(int i = 0;i < G.size();i ++)
		dp[i] = cnt[i] - 1;

	for(int i = G.size() - 1;i >= 0;i --){
		int p = G[i].second;

		if(p - 1 >= 0 && B[p] <= B[p - 1])
			dp[p - 1] = max(dp[p - 1], dp[p] + cnt[p - 1]);
		if(p + 1 < n && B[p] <= B[p - 1])
			dp[p + 1] = max(dp[p + 1], dp[p] + cnt[p + 1]);
	}

	for(int i = 0;i < n;i ++)
		ans = max(ans, dp[i]);

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 7540
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[])
{
    ll a, b, c;
    cin >> a >> b >> c;
    if (a == 7)
    {
        if (b == 5 && b == c)
        {
            cout << "YES" << endl;
        }
        else
        {
            cout << "NO" << endl;
        }
    }
    else if (b == 7)
    {
        if (a == 5 && a == c)
        {
            cout << "YES" << endl;
        }
        else
        {
            cout << "NO" << endl;
        }
    }
    else if (c == 7)
    {
        if (a == 5 && b == a)
        {
            cout << "YES" << endl;
        }
        else
        {
            cout << "NO" << endl;
        }
    }
    else
    {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int n,a[100],ans;
    cin>>n;
    
    for(int i=0;i<n;i++) cin>>a[i]; //n?????\???
     
    for(int i=0;i<n;i++){
        int m=i;
        for(int j=i+1;j<n;j++){
            if(a[j]<a[m]) m=j;
        }
        if(m!=i) ans++;
        swap(a[m],a[i]);
    }

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

Measured memory_bytes: 3008
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	slice := make([]string, n)
	for i := 1; i <= n; i++ {
		sc.Scan()
		a, _ := strconv.Atoi(sc.Text())
		b := strconv.Itoa(i)
		slice[a-1] = b
	}
	fmt.Print(strings.Join(slice, " "))
	fmt.Println("")
}


Measured memory_bytes: 5760
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>



#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))

using namespace std;
vector<int> s;
int n;
int main(){
  cin >> n;
  REP(i,n){
    int k;
    cin >> k;
    s.push_back(k);
  }
  sort(s.begin(),s.end());
  cout << s[n-1]-s[0] <<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 163577857
#define w(t) int t; cin>>t;while(t--)
int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);


    int x;
    cin >> x;
    int yen = 100;
    int y = 0;
    while (yen < x) {
        y++;
        if (yen / 100 > 1) {
            yen = yen + yen / 100;
        }
        else {
            yen = yen + 1;
        }
    }
    cout << y << "\n";
    return 0;

}





Measured memory_bytes: 3652