akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:https://atcoder.jp/contests/abc131/tasks/abc131_f>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

struct UnionFind{
    vector<int> parent, rank;
    UnionFind(int n) : parent(n, -1), rank(n, 0) { }
    int find(int x){
        if(parent[x] == -1) return x;
        else return (parent[x] = find(parent[x]));
    }
    bool unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return false;
        if(rank[x] < rank[y])
            parent[x] = y;
        else
            parent[y] = x;
        if(rank[x] == rank[y]) rank[x]++;
        return true;
    }
    bool same(int x, int y){
        return find(x) == find(y);
    }
};

const int MAXN = 1e5+2;
template<class Type>
Type solve(Type res = Type()){
    ll N; cin >> N;
    UnionFind UF(2*MAXN);
    for(int i = 0; i < N;i++){
        int x,y; cin >> x >> y;
        UF.unite(x,y+MAXN);
    }
    map<int,ll> X,Y;
    for(int i = 0; i < MAXN;i++){
        X[UF.find(i)]++;
    }
    for(int i = MAXN; i < 2*MAXN;i++){
        Y[UF.find(i)]++;
    }
    res = -N;
    for(int i = 0; i < 2*MAXN;i++){
        res += X[i]*Y[i];
    }
    
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 26880
n,k,*h=map(int,open(0).read().split())
a=[0]*n
for i in range(1,n):
    j=max(0,i-k)
    e=h[i]
    a[i]=min(x+abs(e-y) for x,y in zip(a[j:i],h[j:i]))
print(a[-1])

Measured memory_bytes: 13876
//  LINK ZADATKA: http://abc070.contest.atcoder.jp/tasks/abc070_d

#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <complex>
#include <fstream>
#include <cstring>
#include <string>
#include <climits>

using namespace std;

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;


#define FOR(k,a,b) for(int k=(a); k<=(b); ++k)
#define REP(k,a) for(int k=0; k<(a);++k)
#define SZ(a) int((a).size())
#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define INF 999999999
#define INFLONG 1000000000000000000
#define MOD 1000000007
#define MAX 100
#define ITERS 100
#define MAXM 200000
#define MAXN 1000000
#define _gcd __gcd
#define eps 1e-9

const int maxn = 100100;

vector<vector<pair<ll,ll> > >mat;
ll suma, c1, c2, udalj1, udalj2;
ll nodes[maxn];

bool dfs1(ll roditelj, ll cvor){
	
	REP(k, mat[cvor].size()){
		if(mat[cvor][k].first != roditelj){
			nodes[mat[cvor][k].first] = nodes[cvor] + mat[cvor][k].second;
			dfs1(cvor, mat[cvor][k].first);
		}
	}
	return 0;
}

int main(){
	ll n;
	scanf("%lld", &n);
	
	vector<pair<ll,ll> > vii;
	
	mat.insert(mat.begin(), n, vii);
	
	ll a, b, c;
	REP(i, n-1){
		scanf("%lld %lld %lld", &a, &b, &c);
		a--; b--;
		mat[a].PB(MP(b,c));
		mat[b].PB(MP(a,c));
		suma += c;
	}
	
	ll q, k;
	
	scanf("%lld %lld", &q, &k);
	
	dfs1(-1, k-1);
	
	//REP(i, n) printf("%lld %d\n", nodes[i], i+1); 
	
	REP(i, q){
		scanf("%d %d", &c1, &c2);
		c1--; c2--;
		printf("%lld\n", nodes[c1]+nodes[c2]);
	}
	
	return 0;
}

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

class UnionFind {
  int N;
  vector<int> PS;
public:
  UnionFind() : N(0) {}
  UnionFind(int n) : N(n), PS(n, -1) {}
  int merge(int a, int b) {
    assert(0 <= a && a < N);
    assert(0 <= b && b < N);
    int x = leader(a), y = leader(b);
    if (x == y) return x;
    if (-PS.at(x) < -PS.at(y)) swap(x, y);
    PS.at(x) += PS.at(y);
    PS.at(y) = x;
    return x;
  }
  bool same(int a, int b) {
    assert(0 <= a && a < N);
    assert(0 <= b && b < N);
    return leader(a) == leader(b);
  }
  int leader(int a) {
    assert(0 <= a && a < N);
    if (PS.at(a) < 0) return a;
    return PS.at(a) = leader(PS.at(a));
  }
  int size(int a) {
    assert(0 <= a && a < N);
    return -PS.at(leader(a));
  }
  vector<vector<int>> groups() {
    vector<int> B(N), S(N);
    for (int i = 0; i < N; i++) {
      B.at(i) = leader(i);
      S.at(B.at(i))++;
    }
    vector<vector<int>> ret(N);
    for (int i = 0; i < N; i++) {
      ret.at(i).reserve(S.at(i));
    }
    for (int i = 0; i < N; i++) {
      ret.at(B.at(i)).push_back(i);
    }
    ret.erase(
      remove_if(ret.begin(), ret.end(), [&](const vector<int>& v) { return v.empty(); }),
      ret.end()
    );
    return ret;
  }
};

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int N, M, K;
  cin >> N >> M >> K;
  vector<int> NG(N, 1);
  UnionFind UF(N);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    NG.at(a)++, NG.at(b)++;
    UF.merge(a, b);
  }
  for (int i = 0; i < K; i++) {
    int c, d;
    cin >> c >> d;
    c--, d--;
    if (UF.same(c, d)) NG.at(c)++, NG.at(d)++;
  }
  for (int i = 0; i < N; i++) {
    cout << UF.size(i) - NG.at(i) << "\n";
  }
}

Measured memory_bytes: 3984
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl
#define int ll

using namespace std;

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

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;
	
	int a, b, c, k, tt;
	cin >> a >> b >> c >> k;
	int ans = 0;
	tt = min(a, k);
	ans += tt;
	k -= tt;

	tt = min(b, k);
	ans += tt * 0;
	k -= tt;

	tt = min(c, k);
	ans += tt * -1;
	k -= tt;
	cout << ans << endl;
}





Measured memory_bytes: 3652
import java.util.*;
public class Main {
    public static void main(String[] ano) throws java.io.IOException{
        Scanner scan = new Scanner(System.in);
        while(true){
        	int x =scan.nextInt();
        	int h =scan.nextInt();
        	if(x==0&&h==0)break;
        	System.out.println(Math.pow(x, 2)+Math.sqrt(Math.pow((double)x/2, 2)+Math.pow(h, 2))*x*2);
        }
}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin>>a.at(i);}
    sort(a.begin(),a.end());
    int x=a.at(0);
    int y=a.at(n-1);
    cout<<y-x<<endl;
    return 0;}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
 int a, b;
 scanf("%d%d",&a,&b);
 if(a == b) {
 printf("a == b\n");
 } else if(a > b) {
 printf("a > b\n");
 } else if(a < b) {
 printf("a < b\n");
 }
 return 0;
}

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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int, V, greater<int>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
const ll NMAX = 1e2;
ll fac[NMAX + 1], inv[NMAX + 1], finv[NMAX + 1];

void cominit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    FOR(i, 2, NMAX + 1) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll comb(ll n, ll k) {
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll mod_pow(ll base, ll index, ll mod) {
    if(index == 0) return 1LL;
    ll res = mod_pow((base * base) % mod, index / 2, mod);
    if(index & 1) (res *= base) %= mod;
    return res;
}

string s;
vector<char> sv;
map<char, int> dic;

int main() {
    cin >> s;
    int N = s.length();
    sv.resize(N);
    REP(i, N) { dic[s[i]]++; }
    int ans = INF;
    FOREACH(d, dic) {
        char c = d.first;
        int num = d.second;
        int changed = 0;
        REP(i, N) sv[i] = s[i];
        while(num != N - changed) {
            REP(i, N - changed - 1) {
                if(sv[i + 1] == c) {
                    if(sv[i] != c) num++;
                    sv[i] = c;
                }
            }
            if(sv[N - changed - 1] == c) num--;
            changed++;
        }
        ans = min(ans, changed);
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
n = int(input())
dic = {}
for i in range(n):
    a = input()
    if a not in dic.keys():
        dic[a] = 1
    else:
        dic[a] += 1
maxer = max(dic.values())
keys = [k for k, v in dic.items() if v == maxer]
keys.sort()
for i in range(len(keys)):
    print(keys[i])


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll a, b;
  cin >> a >> b;
  if ((a + b) % 2 == 1) cout << "IMPOSSIBLE" << endl;
  else cout << (a + b) / 2 << endl;
  return 0;
}


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

#ifdef LOCAL
	#define D(a) cerr << #a << " = " << a << endl
#else
	#define D(a)
	#define cerr false && cerr
#endif
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define dforsn(i,s,n) for(int i=int(n-1);i>=int(s);i--)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define dforn(i,n) dforsn(i,0,n)
#define forn(i,n) forsn(i,0,n)
#define all(a) a.begin(),a.end()
#define si(a) int((a).size())
#define pb emplace_back
#define mp make_pair
#define snd second
#define fst first
#define endl '\n'
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

int main() {
	fastio;
	
	int a,b;
    cin >> a >> b;

    cout << (a*b%2? "Yes":"No") << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define KK 500
#define MXN 200005
int main(){
    int n;
    scanf("%d",&n);
    int a[300005];
    for(int i = 0;i<3*n;i++){
        scanf("%d",&a[i]);
    }
    sort(a,a+3*n);
    reverse(a,a+3*n);
    LL ans=0;
    for(int i = 1;i<2*n;i+=2){
        ans+=a[i];
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    string s;
    cin>>s;
    bool flg1 = 0;
    if(s[0]=='A')
        flg1=1;
    bool flg2 = 0;
    if(count(s.begin()+2,s.end()-1,'C')==1)
        flg2=1;
    int cnt = 0;
    for(int i=0;i<s.size();++i)
        if(isupper(s[i]))
            cnt++;
    bool flg3 = 0;
    if(cnt==2)
        flg3=1;
 
    (flg1 && flg2 && flg3 )?cout<<"AC":cout<<"WA";
    return 0;
}   

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    vector<short> vec;
    short n, sum = 0;
    for (size_t i = 0; i < 3; i++)
    {
        cin >> n;
        vec.push_back(n);
    }
    sort(vec.begin(), vec.end());

    if (vec[0] == 5 && vec[1] == 5 && vec[2] == 7)
    {
        cout << "YES";
    }
    else
    {
        cout << "NO";
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL gcd(LL a,LL b){
    if(a == 0) return b;
    return gcd(b % a,a);
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL a, b, c, d, cnt = 0, g;
    cin >> a >> b >> c >> d;
    if(c < d) g = c / gcd(c, d) * d;
    else g = c / gcd(d, c) * d;
    cnt = b / c - (a - 1) / c + b / d - (a - 1) / d - b / g + (a - 1) / g;
    LL re = b-a+1-cnt;
    cout<< re <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
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; }
int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    if(n==0) {cout << 1 << endl;}
    else {cout << 0 << endl;}
}


Measured memory_bytes: 3636
N = int(input())
S = input()
f = [-1]*10
l = [-1]*10
c = 0

for i in range(N):
  if f[int(S[i])] == -1:
    f[int(S[i])] = i
  l[int(S[i])] = i

for i in range(10):
  p = f[i]
  if p == -1:
    continue
  for j in range(10):
    q = l[j]
    if q == -1:
      continue
    for k in range(10):
      for h in range(p+1,q):
        if int(S[h]) == k:
          c += 1
          break
      
print(c)

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

int main(){
  int N,L;
  cin >> N >> L;
  int x;
  cin >> x;
  bool flug=false;
  int ans;
  for(int i=1;i<N;i++){
    int y;cin >> y;
    if(x+y>=L){
      flug=true;
      ans=i;
      break;
    }
    x=y;
  }
  if(flug){
    cout << "Possible";
    for(int i=1;i<ans;i++)
      cout << endl << i;
    for(int i=N-1;i>=ans;i--)
      cout << endl << i;
  }else
    cout << "Impossible";
}

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

int main()
{
    int m,n,i;
    char aw[1010][1010];
    scanf("%d %d",&m,&n);
    getchar();
    for(i=0; i<m; i++)
    {
        gets(aw[i]);
    }
    for(i=0; i<m; i++)
    {
        printf("%s\n",aw[i]);
        printf("%s\n",aw[i]);
    }

    return 0;
}


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

using namespace std;

using int64 = long long;
const int INF = 1 << 29;


int main() {
  int N, X, sum = 0, small = INF;
  cin >> N >> X;
  for(int i = 0; i < N; i++) {
    int x;
    cin >> x;
    sum += x;
    small = min(small, x);
  }
  cout << N + (X - sum) / small << endl;
}



Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main 
{

	public static void main(String[] args) 
	{
		Scanner scan = new Scanner(System.in);
		
		while(true)
		{
			int n = scan.nextInt();
			int sum = 0;
			
			if(n == 0) {break;}
				
			List<Integer> l = new ArrayList<Integer>();
			
			for(int i = 0; i < n; i++)
			{
				int input = scan.nextInt();
				l.add(input);
				sum += input;
			}
			
			int ans = 0;
			for(int x : l)
			{
				if(x <= (sum/n))
				{
					ans += 1;
				}
			}
			System.out.println(ans);
		}
		
	}

}



Measured memory_bytes: 59756
N,M = map(int,input().split())
a = [0]*M
for i in range(M):
    a[i] = int(input())

step = [0]*(N+1)
step[0] = 1

for i in range(M):
    step[a[i]] = -1

if 1 in a:
    step[1] = 0
else:
    step[1] = 1

for i in range(2,N+1):
    if step[i] == -1:
        step[i] = 0
    else:
        step[i] = (step[i-1] + step[i-2])%(10**9+7)

print(step[N])

#再起関数供養
def count_step(a,n):
    if n == 0:
        return 1
    if n == 1 and 1 not in a:
        return 1
    if n in a:
        return 0
    return (count_step(a,n-1)+count_step(a,n-2))%(10**9+7)

Measured memory_bytes: 47704
#include <stdio.h>
int main(void) {
    int n;
    int i;
    char s[101];
    char t[101];
    char st[202];
    scanf("%d", &n);
    scanf("%s", s);
    scanf("%s", t);
    for (i=0; i<n; i++) {
        st[i*2] = s[i];
        st[i*2+1] = t[i];
    }
    st[n*2] = '\0';
    printf("%s", st);
    return 0; 
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int (i) = 0, i_len = n; (i) < (i_len); ++(i))
#define repp(i,n) for(int (i) = 1, i_len = n; (i) <= (i_len); ++(i))
#define per(i,n) for(int (i) = n-1; (i) >= 0; --(i))
#define perr(i,n) for(int (i) = n; (i) > 0; --(i))
#define sz(x) ((int)(x).size())
#define popcnt __builtin_popcount
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define Pi 3.1415926535
#define MOD = 1e9+7;
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
template<class T,class S> inline bool chmax(T& a, S b){if(a<b){a = b; return true;} return false;}
template<class T,class S> inline bool chmin(T& a, S b){if(a>b){a = b; return true;} return false;}
template<class T> T gcd(T a, T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/gcd(a,b);}

int solve(){
    int n, m; cin >> n >> m;
    vector<ll> x(m); rep(i,m) cin >> x[i];
    sort(all(x));
    vector<ll> diff(m-1); rep(i,m-1) diff[i] = x[i+1] - x[i];
    sort(all(diff));
    reverse(all(diff));

    if(n>=m){
        cout << 0 << endl;
        return 0;
    }


    ll ans = x.back() - x.front();

    rep(i,n-1){
        ans -= diff[i];
    }
    cout << ans << endl;

    return 0;
}

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


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

using namespace std;

int main()
{
    int N, A, B, sum, tmp;
    cin >> N >> A >> B;
    int cnt = 0;
    for (int i = 1; i <= N; i++)
    {
        sum = i % 10;
        tmp = i / 10;
        while (tmp != 0)
        {
            sum += tmp % 10;
            tmp /= 10;
        }
        if (sum >= A && sum <= B)
            cnt += i;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import Counter
n = int(input())
coor = []
for i in range(n):
  x,y = map(int, input().split())
  coor.append([x,y])
  
if n == 1:
  print(1)
  exit()

dif = []
for i in range(n):
  for j in range(n):
    if i != j:
      dif.append((coor[i][0] - coor[j][0], coor[i][1] - coor[j][1]))
      
S = Counter(dif)
way = max(S.values())
print(n-way)

Measured memory_bytes: 3828
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;

int r[7][7];

void setr(void)
{
	r[1][2] = 3;
	r[1][3] = 5;
	r[1][5] = 4;
	r[1][4] = 2;

	r[2][1] = 4;
	r[2][3] = 1;
	r[2][4] = 6;
	r[2][6] = 3;

	r[3][1] = 2;
	r[3][2] = 6;
	r[3][5] = 1;
	r[3][6] = 5;

	r[4][1] = 5;
	r[4][2] = 1;
	r[4][5] = 6;
	r[4][6] = 2;

	r[5][1] = 3;
	r[5][3] = 6;
	r[5][4] = 1;
	r[5][6] = 4;

	r[6][2] = 4;
	r[6][3] = 2;
	r[6][4] = 5;
	r[6][5] = 3;
}

class dice {
public:
	int f, l, d;
	int v[7];

	dice(void) {
		f = 1;
		l = 4;
		d = 2;
	}
	void rot(char c)
	{
		int pf = f, pl = l, pd = d;

		if (c == 'W') set(7 - pl, pf, pd);
		else if (c == 'S') set(7 - pd, pl, pf);
		else if (c == 'E') set(pl, 7 - pf, pd);
		else set(pd, pl, 7 - pf);
	}
	int front(void)
	{
		return v[f];
	}
private:
	void set(int fv, int lv, int dv) {
		f = fv;
		l = lv;
		d = dv;
	}
};

bool same(dice& d1, dice& d2)
{
	bool ret = false;

	repc(u, 1, 6) repc(f, 1, 6) {
		if (f == u) continue;
		if (f == 7 - u) continue;
		if (d1.v[1] == d2.v[u] &&
			d1.v[2] == d2.v[f] &&
			d1.v[3] == d2.v[r[u][f]]) {
			if (d1.v[6] == d2.v[7 - u] &&
				d1.v[5] == d2.v[7 - f] &&
				d1.v[4] == d2.v[7 - r[u][f]]) ret = true;
			}
	}

	return ret;
}

int main()
{
	dice d1, d2;

	setr();
	
	repc(i, 1, 6) cin >> d1.v[i];
	repc(i, 1, 6) cin >> d2.v[i];

	if (same(d1, d2)) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}



Measured memory_bytes: 3096
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

const int nmax=8;
bool graph[nmax][nmax];

int dfs(int v,int n,bool visited[nmax])
{
  bool all=true;

  rep(i,n)
  {
    if(!visited[i]) all=false;
  }

  if(all) return 1;

  int ret=0;
  rep(i,n)
  {
      if(!graph[v][i]) continue;
      if(visited[i]) continue;

      visited[i]=true;
      ret+=dfs(i,n,visited);
      visited[i]=false;
  }
  return ret;
}

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

  rep(i,m)
  {
    int a,b;
    cin>>a>>b;
    graph[a-1][b-1]=graph[b-1][a-1]=true;
  }

  bool visited[nmax];
  rep(i,n) visited[i]=false;

  visited[0]=true;
  cout<<dfs(0,n,visited)<<endl;

}

Measured memory_bytes: 256
let S = readLine()!.characters.map{"\($0)"}
let N = S.count
let K = Int(readLine()!)!
var sub = Set<String>()
for i in 0..<N {
    var s = ""
    for j in i..<min(i+K, N) {
        s += S[j]
        sub.insert(s)
    }
}
print(Array(sub).sort()[K-1])

Measured memory_bytes: 6128
n = int(input())
b = list(map(int, input().split()))
for i in range(n):
  if b[i] > i+1:
    print(-1)
    break
else:
  ans = []
  while len(b) > 0:
    f = b[0]
    for i in range(len(b))[::-1]:
      if b[i] == i + 1:
        ans.append(b.pop(i))
        break

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

Measured memory_bytes: 38768
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
int N;
char S[6005];
char P[6005][6005];
int p;
int Pair[6005];
int Ind[6005];
int Right[6005];
char W[6005], Sol[6005], DP[6005][6005];
vector <int> V[2];
void Read()
{
    cin >> N;
    cin.get();
    cin.getline(S + 1, 6005);
    for(int i = 1; i <= N * 2; i++)
    {
        if(S[i] == 'a')
            V[0].push_back(i);
        else
            V[1].push_back(i);
    }
    for(int i = 0; i < V[0].size(); i++)
    {
        Pair[V[0][i]] = V[1][i];
        Pair[V[1][i]] = V[0][i];
    }
}
void fillP(int pos)
{
    int left = Right[pos - 1] + 1, right = Right[pos];
    if(S[left] == 'a')
    {
        int curr = Pair[left], ind = 0;
        P[pos][++Ind[pos]] = 'a';
        P[pos][++Ind[pos]] = 'b';
        ++curr;
        while(curr >= left && curr <= right)
        {
            if(S[curr] == 'b')
            {
                ++curr;
                continue;
            }
            P[pos][++Ind[pos]] = 'a';
            P[pos][++Ind[pos]] = 'b';
            curr = Pair[curr] + 1;
        }
    }
    else
    {
        int ind = 0;
        for(int i = left; i <= right; i++)
            Sol[++ind] = S[i];
        Sol[ind + 1] = 0;
        ind = 0;
        for(int i = left + 1; i <= right; i++)
        {
            ind = 0;
            for(int j = i; j <= right; j++)
            {
                if(S[j] == 'b')
                    W[++ind] = S[j];
                else
                    if(Pair[j] >= i && Pair[j] <= right)
                        W[++ind] = S[j];
            }
            W[ind + 1] = 0;
            if(strcmp(Sol + 1, W + 1) < 0)
            {
                for(int j = 1; j <= ind; j++)
                    Sol[j] = W[j];
                Sol[ind + 1] = 0;
            }
        }
        ind = 0;
        for(int j = 1; Sol[j] != 0; j++)
            P[pos][++ind] = Sol[j];
    }
}
void Parts()
{
    int cnt = 0;
    for(int i = 1; i <= N * 2; i++)
    {
        if(S[i] == 'a')
            ++cnt;
        else
            --cnt;
        if(cnt == 0)
        {
            ++p;
            Right[p] = i;
            fillP(p);
        }
    }
}

void precalcDP()
{
    strcpy(DP[p] + 1, P[p] + 1);
    for(int i = p - 1; i >= 1; i--)
    {
        strcpy(DP[i] + 1, DP[i + 1] + 1);
        strcpy(W + 1, P[i] + 1);
        if(strcmp(DP[i] + 1, W + 1) < 0)
            strcpy(DP[i] + 1, W + 1);
        strcat(W + 1, DP[i + 1] + 1);
        if(strcmp(DP[i] + 1, W + 1) < 0)
            strcpy(DP[i] + 1, W + 1);
    }
    cout << (DP[1] + 1) << "\n";
}
int main()
{
    Read();
    Parts();
    precalcDP();
    return 0;
}


Measured memory_bytes: 37120
/*
 It's better to sleep happy and tired rather than disappointed and frustrated
 There's only 1 thing that's impossible and that is defeating a man who doesn't give up
*/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mx2 102
#define mx3 1003
#define mx4 10004
#define mx5 100005
#define mx6 1000006
#define mod 1000000007
#define PI 3.14159265
#define deb(x) cout << #x << " " << x << endl;
#define fo(i,n) for(int i=0 ; i<n ; i++)
#define Fo(i,k,n) for(int i=k ; i<n ; i++)
 
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<pair<int,int>,int> piii;

const int inf=0x3f3f3f3f;
int n ,k, ans , sum , a , b ,arr[mx5],dp[mx5];
string str;

int solve(int i)
{
	if(i==n-1)
	{
		return 0;
	}
	if(i>n)
	{
		return inf;
	}
	if(dp[i]!=-1)
	{
		return dp[i];
	}
	int tmp=inf;
	Fo(j,1,k+1)
	{
		if(i+j<n)
			tmp=min(tmp,solve(i+j)+abs(arr[i]-arr[i+j]));
	}
	return dp[i]=tmp;
}
 
int main() {
	ios::sync_with_stdio(false);
	//int t;cin>>t;while(t--)
	{
		cin>>n>>k;
		fo(i,n)cin>>arr[i];
		memset(dp,-1,sizeof(dp));
		cout<<solve(0);
	}
	return 0;
}


Measured memory_bytes: 5760
//  main.cpp
//  CppTest

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

int main(int argc, const char * argv[]) {
    // input from txt （提出時にこの箇所は削除すること）
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
    
    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    /////////////////////
    // Write code below /
    /////////////////////

    int N;
    cin>>N;
    vector<int>A(N);
    for(int i=0;i<N;i++){
        cin>>A.at(i);
    }
    int output=0;
    for(int i=0;i<N;i++){
        int max=0;
        for(int j=0;j<N;j++){
            if(A.at(j)>max){
                max=A.at(j);
            }
        }
        for(int k=0;k<N;k++){
            if(max==A.at(k)){
                A.at(k)=0;
                break;
            }
        }
        if(i%2==0){
            output+=max;
        }
        else if(i%2==1){
            output-=max;
        }
    }
    cout<<output<<endl;
    
        return 0;
}


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

using namespace std;

int main()
{
    int N;
    cin >> N;
    double value, sum=0;
    string S;
    for(int i=0;i<N;i++){
        cin >> value >> S;
        if(S == "JPY"){
            sum += value;
        }
        else{
            sum += value * 380000;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
i,f,d[5],*p;main(n){for(;i>4||~scanf("%d",p=d+i);i=++i%10,f*=!!i)n=!(d[i%5]*2&f)+49|(f/2^f/4^f/8)&3,i<5?f|=*p=9<<*p:puts(&n);}

Measured memory_bytes: 0
import numpy as np
import bisect

# N = 2
# ARR = [1, 5]
# BRR = [2, 4]
# CRR = [3, 6]

# N = 3
# ARR = [1, 1, 1]
# BRR = [2, 2, 2]
# CRR = [3, 3, 3]

# N = 6
# ARR = [3, 14, 159, 2, 6, 53]
# BRR = [58, 9, 79, 323, 84, 6]
# CRR = [2643, 383, 2, 79, 50, 288]

N = int(input())
ARR = [int(s) for s in input().split(" ")]
BRR = [int(s) for s in input().split(" ")]
CRR = [int(s) for s in input().split(" ")]


def calculate(n, arr, brr, crr):
    arr = sorted(arr)
    crr = sorted(crr)


    sum = 0
    for b in brr:
        s1 = bisect.bisect_right(arr,b-1)
        s2 = n - bisect.bisect_left(crr,b+1)
        sum = sum + s1 * s2

    print(sum)

calculate(N,ARR,BRR,CRR)

Measured memory_bytes: 31396
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
// const lint MOD = 998244353;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
char upper(char c){
	return c-0x20;
}
char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
	string s;cin>>s;
	vector<int> v(30);
	rep(i,s.size()){
		v[s[i]-'A'] += 1;
	}
	rep(i,30){
		if(v[i]!=2 && v[i]!=0){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <complex>
#include <cstdio>
#include <utility>
#include <vector>
using namespace std;
typedef complex<double> P;
typedef pair<P,P> L;
typedef pair<P,double> C;
typedef vector<P> Poly;
#define X real()
#define Y imag()
const double EPS = (1e-10), pi = acos(-1);

double dot(P a, P b){ return a.X * b.X + a.Y * b.Y;}
double cross(P a, P b){ return a.X * b.Y - a.Y * b.X;}

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if(cross(b,c) > EPS) return +1;
  if(cross(b,c) < -EPS) return -1;
  if(dot(b,c) < 0) return +2;
  if(abs(b) + EPS < abs(c)) return -2;
  return 0;
}

P intersection(L a, L b){
  P af = a.first, as = a.second, bf = b.first, bs = b.second;
  return af + cross(bs-bf,af-bf)/(-cross(bs-bf,as-bf)+cross(bs-bf,af-bf))*(as-af);
}

Poly convex_cut(Poly p, L l){
  Poly ret;
  int n = p.size();
  for(int i = 0; i < n; ++i){
    if(ccw(l.first, l.second, p[i]) != -1)
      ret.push_back(p[i]);
    if((ccw(l.first, l.second, p[i]) != -1) ^
       (ccw(l.first, l.second, p[(i+1)%n]) != -1))
      ret.push_back(intersection(L(p[i], p[(i+1)%n]), l));
  }
  return ret;
}

double poly_area(Poly p){
  int n = p.size();
  double ret = 0;
  for(int i = 0; i < n; ++i){
    ret += 0.5*(cross(p[i],p[(i+1)%n]));
  }
  return ret;
}

int main(){
  int g;
  cin >> g;
  Poly p;
  for(int i = 0; i < g; ++i){
    double x, y;
    cin >> x >> y;
    p.emplace_back(x,y);
  }
  int q;
  cin >> q;
  while(q--){
    double x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    printf("%.12f\n",poly_area(convex_cut(p,L(P(x1,y1),P(x2,y2)))));
  }
}



Measured memory_bytes: 3344
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner input = new Scanner(System.in);
		int int1 = input.nextInt();
		int int2 = input.nextInt();
		int gcd = 1;
		
		if(int2 > int1) {
			int temp = int1;
			int1 = int2;
			int2 = temp;
		}
		while(int1 >= int2) {
			int temp = int2;
			int2 = int1 % int2;
			if(int2 == 0) {
				gcd = temp;
				break;
			}
			int1 = temp;
		}
		System.out.println(gcd);
	}
}


Measured memory_bytes: 26320
N = int(input())
S = input()
r = []
g = []
b = []
for i in range(N):
  if S[i] == 'R':
    r.append(i)
  elif S[i] == 'G':
    g.append(i)
  else:
    b.append(i)
ans = len(r) * len(g) * len(b)
sub = 0
for i in range(1,N//2+1):
  if 2 * i == N:
    break
  for k in range(N):
    if S[sub] != S[sub + i] and S[sub + i] != S[sub + 2 * i] and S[sub + 2 * i] != S[sub]:
      ans -= 1
    if sub + 2 * i + 1< N:
      sub += 1
    else:
      sub = 0
      break
print(ans)
    

Measured memory_bytes: 9308
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1LL << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	int n = s.size();
	int ans = 0;
	rep(i, n - 1) {
		if (s[i] != s[i + 1]) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<list>
#include <cstring>
#include <functional>
//#include<unordered_map>
//#include<unordered_set>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF ((Int)1<<60)
#define EPS (1e-10)
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
typedef long long Int;
typedef pair<Int, Int> P; 
typedef vector<double> vec;
typedef vector<vec> mat;
const int N = 200005;
//////////////////////////////

Int dp[2200][2200];

void solve()
{
	int n;
	cin >> n;
	vector<int> a(n);
	REP(i, n) cin >> a[i];

	vector<P> ai(n);
	REP(i, n) ai[i] = P(a[i], i);
	sort(ai.rbegin(), ai.rend());


	REP(i, n) {
		for (int j = 0; j <= i; ++j) {
			int l = 0, r = n - 1;
			l += j; r -= (i - j);
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + 1LL * ai[i].first * (r - ai[i].second));
			if (j + 1 <= n) dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1LL * ai[i].first * (ai[i].second - l));
		}
	}

	Int ans = 0;
	REP(j, n + 1) ans = max(ans, dp[n][j]);
	cout << ans << endl;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(13);
	solve();
	return 0;
}


Measured memory_bytes: 26916
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const string nl="\n";
const ll MOD=1000000007;

int main(){
    ll n;cin>>n;
    string s[n];
    string nw[n];
    for(ll i=0;i<n;i++) cin>>s[i];
    // vector<int> val(n,0);
    for(ll i=0;i<n;i++){
        ll tmp[10];
        for(ll j=0;j<10;j++){
            tmp[j]=s[i][j]-'a';
        }
        sort(tmp,tmp+10);
        string x="";
        for(ll j=0;j<10;j++){
            x+=(char)('a'+tmp[j]);
        }
        nw[i]=x;
    }
    sort(nw,nw+n);
    ll prev=0,cnt=0;
    // cout<<nw[0]<<nl;
    for(ll i=1;i<n;i++){
        if(nw[i]!=nw[i-1]){
            cnt+=((i-prev)*(i-prev-1))/2;
            prev=i;
        }
        // cout<<nw[i]<<nl;
    }
    cnt+=((n-prev)*(n-prev-1))/2;
    cout<<cnt;
    return 0;
}

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

signed main(){
	int n,l;cin>>n>>l;
	vector<int>a(n);
	for(auto&& u:a)cin>>u;
	int tmp=-1;
	rep(i,n-1)if(a[i]+a[i+1]>=l){tmp=i;break;}
if(tmp==-1){
	cout<<"Impossible"<<endl;
}else{
	cout<<"Possible"<<endl;
	for(int i=0;i<tmp;i++)cout<<i+1<<endl;
	for(int i=n-2;i>tmp;i--)cout<<i+1<<endl;
	cout<<tmp+1<<endl; 
}

}


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

int main() {
	long long n,i,j,k,sum=0,count=0,ans=0;
	cin>>n>>k;
	if(n==1 || k==1)
	{
	    cout<<1; return 0;
	}
	n=n*k;
	cout<<(n+1)/2;
	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
hs = gets.split.map(&:to_i)

h = {}
count = 0

hs.each.with_index(1) do |he,i|
  diff = i - he
  if h[diff]
    count += h[diff]
  end
  sum = he + i

  if h[sum]
    h[sum] += 1
  else
    h[sum] = 1
  end
end

puts count


Measured memory_bytes: 37100
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template
#pragma region uft 1.0
struct uft
{
    vi p;
    vi s;

    uft() {}

    uft(ll n)
    {
        p.assign(n + 1, 0);
        REP1(i, n)
        {
            p[i] = i;
        }
        s.assign(n + 1, 1);
    }

    ll find(ll i)
    {
        if (p[i] == i)
        {
            return i;
        }
        p[i] = find(p[i]);
        return p[i];
    }

    void unite(ll i, ll j)
    {
        i = find(i);
        j = find(j);
        if (i == j)
        {
            return;
        }
        if (s[i] < s[j])
        {
            p[i] = j;
        }
        else
        {
            p[j] = i;
        }
        s[j] += s[i];
        s[i] = s[j];
    }

    bool same(ll i, ll j)
    {
        return find(i) == find(j);
    }

    ll size(ll i)
    {
        return s[find(i)];
    }
};
#pragma endregion uft

int main()
{
    IN(ll, N);
    A2IN(ll, A, ll, B, N);
    vii C(N);
    REP(i, N)
    {
        C[i] = {A[i] + B[i], i};
    }
    RSORT(C);
    ll ans = 0;
    REP(i, N)
    {
        auto [_, j] = C[i];
        if (i & 1)
        {
            ans -= B[j];
        }
        else
        {
            ans += A[j];
        }
    }
    OUT(ans);
}

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

typedef long long ll;
const int mod=1e9+7;
const int maxn=2e5+10;


ll bnt[maxn];

ll mod_pow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n & 1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res%mod;
}

void exgcd(ll a,ll b,ll& d,ll& x,ll& y){
    if(!b) { d = a; x = 1; y = 0; }
    else{ exgcd(b, a%b, d, y, x); y -= x*(a/b); }
}
ll inv(ll a, ll p){
    ll d,x,y;
    exgcd(a,p,d,x,y);
    return d == 1 ? (x+p)%p : -1;
}


ll C(ll n,ll m){
	ll ans=1;
	m=min(m,n-m);
	for(int i=1;i<=m;i++) ans=ans*(n-m+i)%mod*inv(i,mod)%mod;
	return ans;
}

int main(){
	ll n,a,b;
	cin>>n>>a>>b;
	ll ans=(mod_pow(2,n)-1+mod)%mod;
	
	ll cna=C(n,a);

	ll cnb=C(n,b);

	ans=(ans-cna+mod-cnb+mod)%mod;
	cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const ll max_co = 3234600000;
vl ans;
int main(){
    ll n;
    cin>>n;
    ll ans =0;
    for(ll i =2;i<=sqrt(n-1);i++){
        if((n-1)%i==0){
            ans++;
            if((n-1)/i!=i)ans++;
        }
    }
    vl yakusuu;
    for(ll i =2;i<=sqrt(n);i++){
        if(n%i==0){
            ll N=n;
        while(N%i==0)N/=i;
        if(N%i==1)ans++;
        ll j = n/i;
        N=n;
        if(j==i)continue;
        while(N%j)N/=j;
        if(N%j==1)ans++;
    }
    }
    if(n==2)ans--;
    cout<<ans+2<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define all(cont) cont.begin(), cont.end()
#define unique(a)  sort(all(a)) , (a).erase(unique((a).begin(), (a).end()),(a).end())
#define rall(cont) cont.rbegin(), cont.rend()
#define sz(x) (int)(x).size()
#define fastio          ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define PB push_back
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
const int N = 2e5 + 5;
#define PI acos(-1.0)
typedef long long ll;
#define int long long
typedef long double ld;
typedef vector<int> VI;
#define pqll_max priority_queue<ll> // max heap. push(),pop(),top(),size(),empty()
#define pqll_min priority_queue<ll,vector<ll>,greater<ll> >
#define lb(v,val)   lower_bound(v.begin(),v.end(),val) //first equal to or lower than [------------
#define ub(v,val)   upper_bound(v.begin(),v.end(),val) //first greater than ------------)
#define bs(v,x) binary_search(v.begin(),v.end(),x)
inline ll add(ll x, ll y) { x += y; if (x >= mod) x -= mod; return x; }
inline ll sub(ll a, ll b) { if (a < b)swap(a, b); return (((a%mod) - (b%mod) + mod) % mod); }
inline ll mul(ll x, ll y) { return (x%mod * 1ll * y%mod) % mod; }
inline ll pwr(ll a, ll b) { ll x = 1 % mod; while (b) { if (b & 1) x = mul(x, a); a = mul(a, a); b >>= 1; }return x % mod; }
inline ll inv(ll a) { return pwr(a, mod - 2) % mod; }
ll gcd(ll a, ll b) { if (!a)return b % mod; return gcd(b%a, a) % mod; }
#define debug(x) cout << #x << " = " << x << endl;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#define in(container) for (auto &it : container) cin>>it;
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
signed main()
{
	fastio;
	int n, k;
	cin >> n >> k;
	cout << min({ n,n%k,abs(n%k - k) }) << endl;


}

Measured memory_bytes: 256
class uft():
    def __init__(self,n):
        self.p=[ -1 for i in range(n)]
        self.r=[ 1 for i in range(n)]
        
    def find(self,x):
        if(self.p[x]==-1):
            return x
        else:
            self.p[x]=self.find(self.p[x])
            return self.find(self.p[x])
        
    def unite(self,x,y):
        x=self.find(x)
        y=self.find(y)
        if(self.r[x]>self.r[y]):
            tmp=x
            x=y
            y=tmp
            
        if(self.r[x]==self.r[y]):
            self.r[y]+=1
            
        if(x!=y):
            self.p[x]=y
        return
    
n,m=map(int,input().split())
p=list(map(int,input().split()))
for i in range(n):
  p[i]-=1
uf=uft(n)
for i in range(m):
    x,y=map(int,input().split())
    x-=1
    y-=1
    uf.unite(x,y)
ans=0
for i in range(n):
    if(uf.find(i)==uf.find(p[i])):
        ans+=1
        
print(ans)

Measured memory_bytes: 20384
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = (a);i < (n);i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main(){
	int grid[3][3] = {0},a[3],b[3],memo = 1000,memo_i = 0,memo_j = 0;
	bool flag = false;
	
	rep(i,0,3){
		rep(j,0,3){
			cin >> grid[i][j];
			if(memo > grid[i][j]){
				memo = grid[i][j];
				memo_i = i;
				memo_j = j;
			}
		}
	}
	
	rep(i,0,grid[memo_i][memo_j]+1){
		a[memo_i] = i;
		b[memo_j] = grid[memo_i][memo_j] - a[memo_i];
		
		switch(memo_i){
			case 0:
				a[1] = grid[1][memo_j] - b[memo_j];
				a[2] = grid[2][memo_j] - b[memo_j];
				break;
			case 1:
				a[0] = grid[0][memo_j] - b[memo_j];
				a[2] = grid[2][memo_j] - b[memo_j];
				break;
			case 2:
				a[1] = grid[1][memo_j] - b[memo_j];
				a[0] = grid[0][memo_j] - b[memo_j];
				break;
		}
		
		switch(memo_j){
			case 0:
				b[1] = grid[memo_i][1] - a[memo_i];
				b[2] = grid[memo_i][2] - a[memo_i];
				break;
			case 1:
				b[0] = grid[memo_i][0] - a[memo_i];
				b[2] = grid[memo_i][2] - a[memo_i];
				break;
			case 2:
				b[1] = grid[memo_i][1] - a[memo_i];
				b[0] = grid[memo_i][0] - a[memo_i];
				break;
		}
		
		flag = false;
		
		rep(i,0,3){
			rep(j,0,3){
				if(a[i]+b[j] != grid[i][j]){
					flag = true;
				}
			}
			if(flag){
				break;
			}
		}
		
		if(!flag){
				cout << "Yes" << endl;
				return 0;
		}
		
		
		
	}
	
	cout << "No" << endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/lazysegtree>
#include <atcoder/modint>
using mint = atcoder::modint998244353;

struct S {
    mint n = 1;
    int size = 1;
};

S op(S a, S b) {
    S res;
    res.size = a.size + b.size;
    res.n = a.n * mint(10).pow(b.size) + b.n;
    return res;
}

S e() {
    return S{0, 0};
}

vector<mint> precomp;
S mapping(int a, S b) {
    if (a == 0) return b;
    b.n = mint(a) * precomp[b.size];
    return b;
}

int composition(int a, int b) {
    return a == 0 ? b : a;
}

int id() {
    return 0;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    precomp.resize(n + 1);
    precomp[1] = 1;
    for (int i = 2; i <= n; i++) {
        precomp[i] = precomp[i - 1] * 10 + 1;
    }
    vector<S> a(n);
    atcoder::lazy_segtree<S, op, e, int, mapping, composition, id> st(a);
    for (int i = 0; i < m; i++) {
        int l, r, d;
        cin >> l >> r >> d;
        st.apply(l - 1, r, d);
        cout << st.prod(0, n).n.val() << '\n';
    }
    return 0;
}

Measured memory_bytes: 10596