akhauriyash/Code-Regression huggingface dataset:
#include<cmath>
#include<iostream>
#include <bits/stdc++.h>
#define REP(i,s,n) for(int i=0;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;
using ld = long double;

int main(){
  int a,b,c,d;
  int e,f,g,h;
  int a_ans, b_ans;
  while(cin>>a>>b>>c>>d, cin>>e>>f>>g>>h){
    // cout<<a<<b<<c<<d<<e<<f<<g<<h;
    a_ans=0;b_ans=0;
    if(a==e)a_ans+=1;
    else if(a==f|a==g|a==h)b_ans+=1;
    if(b==f)a_ans+=1;
    else if(b==e|b==g|b==h)b_ans+=1;
    if(c==g)a_ans+=1;
    else if(c==f|c==e|c==h)b_ans+=1;
    if(d==h)a_ans+=1;
    else if(d==f|d==g|d==e)b_ans+=1;
    cout << a_ans << " " << b_ans<<endl;
  }
}



Measured memory_bytes: 3016
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(void){
    int a,b,c,x;    cin >> a >> b >> c >> x;
    int cnt=0;
    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++){
                if(500*i + 100*j + 50*k == x) cnt++;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
a,b=map(int,input().split())
p=list(map(int,input().split()))
s=[]
c=0
d=0
e=0
for i in p:
  if i<=a:
    c+=1
  elif a+1<=i<=b:
    d+=1
  elif b+1<=i:
    e+=1
s.append(c)
s.append(d)
s.append(e)
print(min(s))

Measured memory_bytes: 3064
H, W = gets.chomp.split.map(&:to_i)
map = readlines.map(&:chomp)

dirs = [0, 1, -1].repeated_permutation(2).to_a
dirs.delete([0, 0])

H.times do |h|
  W.times do |w|
    next if map[h][w] != '.'
    c = 0
    dirs.each do |x, y|
      next if h + y < 0 || h + y >= map.length || w + x < 0 || w + x >= map[0].length
      c += 1 if map[h+y][w+x] == '#'
    end
    map[h][w] = c.to_s
  end
end

puts(map)

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>b;--i)
#define sq(a) (a)*(a)
#define nitro std::ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define debug(x) std::cerr<<#x<<"="<<x<<'\n'
#define text std::cerr<<"SacredCoupoid08\n"
#define endl '\n'
#define all(c) (c).begin(),(c).end()
#define U 1000000007
#define N 100005
#define sz(c) (int)c.size()
typedef long long ll;
typedef std::vector< int > vi;
typedef std::pair<int, int> pi;
#define cin std::cin
#define cout std::cout
#define vector std::vector
#define pb push_back
#define pv(x) for(auto y:x)    cerr<<y<<" ";    cerr<<'\n';
#define fr first
#define sc second
#define ppb pop_back
#define max(a,b) a=max(a,b)
#define min(a,b) a=min(a,b)
#define int ll
#define tr(c,it) for(typeof(c.begin()) it= c.begin();it != c.end();it++)
signed main()
{		
	nitro;
	int VASU=1;
	//cin>>VASU;
	while(VASU--)
	{
		int n;
		cin>>n;
		rep(i,-200,200)
		{
			rep(j,-200,200)
			{
				if(pow(i,5)-pow(j,5)==n)
				{
				cout<<i<<" " <<j <<endl;
				return 0;
			}
			}
		}
		
	}
	

	
	
	
	return 0;
}



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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

signed main(){
	string s;
	cin>>s;
	if(s[0]==s[1]||s[1]==s[2]||s[2]==s[3])cout<<"Bad"<<endl;
	else cout<<"Good"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 1000000000
#define MOD 1000000007
#define ll long long int
using namespace std;

int main(){
	int N; cin>>N;
	vector <ll> a; a.resize(N+1,0);
	map <ll,ll> box;
	for(int i=1;i<=N;i++) cin>>a[i];
	vector <ll> sum; sum = a;
	box[0]++;
	for(int i=1;i<=N;i++){
		sum[i] += sum[i-1];
		box[sum[i]]++;
	}

	ll ans = 0;
	for(auto itr = box.begin() ; itr != box.end();itr++){
		ll cnt= (*itr).second;
		ans += cnt * (cnt - 1) /2;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 15872
#include <stdio.h>
int main(void){
    int m,f,b;
    scanf("%d %d %d",&m,&f,&b);
    if(m>=b){
        printf("0\n");
    }else if(m+f<b){
        printf("NA\n");
    }else{
        f=b-m;
        printf("%d\n",f);
    }
    return 0;
}



Measured memory_bytes: 2112
#include<iostream>
#include<numeric>
#include<cmath>
#include<vector>
#include<string>

using namespace std;

int main() {
	int  a, b;

	cin >>a >>b;

    if((a*b)%2==0){
    cout<<"Even"<<endl;
    }else{
    cout<<"Odd"<<endl;
    
    }
    
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, a, b) for(int i = (a); i <= (b); i++)
#define PER(i, a, b) for(int i = (a); i >= (b); i--)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define all(S) (S).begin(), (S).end()
#define pb push_back
#define mk make_pair
#define S second
#define F first
typedef long long ll;
typedef long double lf;
typedef pair<int, int> ii;
stack<char> p;
int N, ans;
string s;

int main(int argc, char ** argv) {
	cin >> s;
	rep(i, 0, s.size()) {
		if(!p.empty() && p.top() != s[i]) p.pop();
		else p.push(s[i]);
	}
	printf("%d\n", s.size() - p.size());
	return 0;
}


Measured memory_bytes: 512
// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>
#include <regex>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(i, (q).size()) { cerr << (q)[i] << (i == i_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
#define CHOKUDAI_ const
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using cll = DANCE_ DANCE_ CHOKUDAI_;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    // インタラクティブ問題では除去した方がいいかも
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    string s; cin >> s;

    regex r("^A?KIHA?BA?RA?$");
    cout << YES(regex_match(s, r)) << endl;
    
}

Measured memory_bytes: 256
n = int(input())
P = [int(p) for p in input().split()]

count = 0
for i in range(1, n-1):
    if ((P[i-1] < P[i] and P[i] < P[i+1]) or
        (P[i-1] > P[i] and P[i] > P[i+1])):
        count += 1
print(count)


Measured memory_bytes: 3060
#include <iostream>
#define MAX 100000
typedef long long ll;

int n,k;
ll T[MAX];

int check(ll p) {
    int i = 0;
    for (int j=0; j<k; j++) {
        ll s = 0;
        while (s+T[i] <= p) {
            s += T[i];
            i++;
            if (i == n) return n;
        }
    }
    return i;
}

int solve() {
    ll left = 0;
    ll right = 100000 * 10000;
    ll mid;
    while (right - left > 1) {
        mid = (left+right)/2;
        int v = check(mid);
        if (v >= n) right = mid;
        else left = mid;
    }
    return right;
}

int main() {
    std::cin >> n >> k;
    for (int i = 0; i < n; i++) std::cin >> T[i];
    ll ans = solve();
    std::cout << ans << std::endl;
}


Measured memory_bytes: 3864
H,W = map(int, input().split())
S = [input() for _ in range(H)]

L = [[0]*W for _ in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j] == "." and j > 0:
            L[i][j] = L[i][j-1]+1
        elif S[i][j] == ".":
            L[i][j] = 1
    for j in range(W-1, 0, -1):
        if L[i][j-1] > 0:
            L[i][j-1] = max(L[i][j-1], L[i][j])
            
L2 = [[0]*W for _ in range(H)]
for j in range(W):
    for i in range(H):
        if S[i][j] == "." and i > 0:
            L2[i][j] = L2[i-1][j] + 1
        elif S[i][j] == ".":
            L2[i][j] = 1
    for i in range(H-1, 0, -1):
        if L2[i-1][j] > 0:
            L2[i-1][j] = max(L2[i-1][j], L2[i][j])
            
ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, L[i][j]+L2[i][j]-1)
        
print(ans)

Measured memory_bytes: 126680
#include <stdio.h>
int main(void) {
    int a, b, c;

    int cnt = 0;

    int hako[3];
    int max = 0;
    for (int i = 0; i < 3; i++) {
        scanf("%d", &hako[i]);
        if (max < hako[i]) {
            max = hako[i];
        }
    }
    int overcnt = 0;
    int anscnt = 0;
    int min_i;
    int min;
    while (1) {
        min = max;
        cnt = 0;
        for (int i = 0; i < 3; i++) {
            if (hako[i] != max) {
                if (min > hako[i]) {
                    min = hako[i];
                    min_i = i;
                }
                cnt++;
            }
        }
        // printf("cnt=%d\n", cnt);
        if (cnt == 0) {
            break;
        } else if (cnt == 1) {
            hako[min_i] += 2;

            if (hako[min_i] > max) {
                hako[min_i]--;
                overcnt++;
            }
            anscnt++;
        } else {
            for (int i = 0; i < 3; i++) {
                if (hako[i] != max) {
                    hako[i]++;
                }
            }
            anscnt++;
        }
        for (int i = 0; i < 3; i++) {
            // printf("hako=%d", hako[i]);
        }
        // printf("\n");
    }
    anscnt += overcnt;
    // printf("%d\n", overcnt);

    printf("%d\n", anscnt);
    return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define REP(i, k, n) for(auto i = k; i != n; i++)
#define rrep(i, n) RREP(i, n, 0)
#define RREP(i, n, k) for(auto i = n; i != k; i--)
#define all(x, r) (x), (x)+(r)
#define ALL(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " " << x << endl
#define exst(x, data) (data).find(x) != (data).end()
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define np next_permutation
#define b32 bitset<32>

using ll = long long;
using Pii = pair<int,int>;
using Tiii = tuple<int, int, int>;
template<class T>using V = vector<T>;
template<class T>using VV = vector<vector<T>>;
using Vi = vector<int>;
using VVi = vector<vector<int>>;

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

    int N, M; cin >> N >> M;
    V<Pii> ba = V<Pii>(M);
    rep(i,M){
        int a, b; cin >> a >> b; ba[i] = mp(b,a);
    }
    sort(ALL(ba));

    set<int> s;
    ll ans = 0;
    rep(i,M) {
        int b, a; tie(b,a) = ba[i];
        bool ok = false;
        REP(itr,s.begin(),s.end()) {
            if(a <= *itr && *itr < b) {
                ok = true; break;
            }
        }
        if(ok) continue;

        ans++; s.insert(b-1);
    }

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

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int main() {

	int N, M;
	cin >> N >> M;
	vector<int> A;
	float total = 0;
	int count = 0;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		A.push_back(a);
		total += a;
	}
	for (int i = 0; i < N; i++) {
		if (A[i] >= float(total) / float(4 * M)) {
			count++;
			
		}
		if (count == M) {
			cout << "Yes";
			return 0;
		}

	}
	cout << "No";
	return 0;

}

Measured memory_bytes: 256
li = input().split()
a = int(li[0])
b = int(li[1])
k = int(li[2])

if k >= a :
    k -= a
    a = 0
    if k >= b:
        b =0
    else:
        b -= k
else:
    a -= k
print("{} {}".format(str(a),str(b))) 

Measured memory_bytes: 3064
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long A = sc.nextLong();
    long B = sc.nextLong();
    long[] h = new long[N];
    for(int i = 0; i < N; i++) {
      h[i] = sc.nextLong();
    }
    long ans = 0;
    long left = 1;
    long right = (long)Math.pow(10, 9) + 1;
    while(left < right) {
      long med = (left + right) / 2;
      long count = 0;
      for(int i = 0; i < N; i++) {
        long k = Math.max(0, (h[i] - med * B + A - B - 1) / (A - B));
        count += k;
      }
      if(count <= med) {
        ans = med;
        right = med;
      } else {
        left = med + 1;
      }
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 50624
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <cmath>
#include <ios>
#include <ctype.h>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>
#include <functional>
#include <bitset>
#include <list>
#include <deque>
#include <time.h>
#include <random>
#include <iomanip>
#include <fstream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define pint pair<int,int>
const int INF = 1000000007;
const long double EPS = 1e-15;
const long double PI = acos(-1);
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
using Graph_weighted = vector<vector<pair<int,int>>>;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll ceil(const ll a, const ll b) { return (a + b - 1) / b; }
int main(){
  ll n,m;
  cin >> n >> m;
  map<ll,ll>cnt;
  vector<ll>v(n),sum(n + 1);
  rep(i,n)cin >> v[i];
  rep(i,n)sum[i + 1] = sum[i] + v[i];
  rep(i,n + 1){
    cnt[sum[i] % m]++;
  }
  ll ans = 0;
  for(auto i : cnt){
    if(i.second >= 2){
      ans += (i.second * (i.second - 1)) / 2;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back 
#define pf push_front 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i,n) for(int i=0;i<(n);i++)
#define All(v) v.begin(),v.end()
typedef pair<int, int> Pii; typedef pair<int, Pii> Pip;
typedef pair<string, string> Pss;
const int INF = 1107110711071107;


main()
{
  int N, F;
  map<Pss, int> m;

  cin >> N >> F;

  Rep(i, N) {
    int M;
    cin >> M;
    vector<string> v;
    
    Rep(i, M) {
      string s;
      cin >> s;
      v.pb( s );
    }
    
    sort( All(v) );
    for(int i=0; i<M-1; i++) {
      for(int j=i+1; j<M; j++) {
	m[Pss(v[i], v[j])] ++;
      }
    }
  }

  vector<Pss> ans;
  for(map<Pss, int>::iterator it = m.begin(); it != m.end(); it++) {
    if( (*it).sc >= F ) ans.pb( (*it).fr );
  }

  cout << ans.size() << endl;
  Rep(i, ans.size()) cout << ans[i].fr << " " << ans[i].sc << endl;
  
}

Measured memory_bytes: 3684
import numpy

N = int(input())
A, B = numpy.array([list(map(int, input().split())) for _ in range(N)]).T

A = A[::-1]
B = B[::-1]

ans = 0
for i in range(N):
    a, b = A[i], B[i]

    # need to do nothing
    if (a + ans) % b == 0:
        continue

    else:
        ans += b - (a + ans) % b

print(ans)

Measured memory_bytes: 46436
#include <iostream>

typedef struct//構造体の復習
{
  int w;
  int h;
}R;

int main()
{

  R tyou;
  int x,y,r,hata=1;
  
  std::cin>>tyou.w>>tyou.h>>x>>y>>r;

  /*判別*/
  if(x-r<0||x+r>tyou.w||y-r<0||y+r>tyou.h)
    {
      std::cout<<"No"<<std::endl;
    }
  else
    {
      std::cout<<"Yes"<<std::endl;
    }

  return 0;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    int n,m,A[100][100]={0},b[100]={0};
    long long int c;
    scanf("%d %d",&n,&m);
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            scanf("%d",&A[i][j]);
        }
        
    }
    for (int i = 0; i < m; i++)
    {
        scanf("%d",&b[i]);
    }
    for (int i = 0; i < n; i++)
    {   
        c=0;
        for (int j = 0; j < m; j++)
        {
            c+=A[i][j]*b[j];
        }
        printf("%lld\n",c);
    }
    
    
    
}


Measured memory_bytes: 3288
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < (n); i++)
#define Rep(i, n) for(int i = 1; i < n; i++)

const int mod = 1000000007;
const int inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

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

	cout << fixed << setprecision(10) << (double)r * r * acos(-1) << " " << (double)r * 2 * acos(-1) << endl;
}


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

using namespace std;

const int N = 1005;
const int dx[2] = {0, 1};
const int dy[2] = {1, 0};
const int MOD = 1000000007;

string grid[N];
int row, col, v[N][N], a[N][N];

bool boundary(int i, int j) {
  return (i >= 1 && i <= row) && (j >= 1 && j <= col);
}

int dfs(int i, int j) {
  v[i][j] = 1;
  if (i == row && j == col) return a[i][j] = 1;
  for (int k = 0; k < 2; k++) {
    int x = i + dx[k];
    int y = j + dy[k];
    if (boundary(x, y) && grid[x][y] != '#') {
      if (v[x][y] == 0) {
        a[i][j] += dfs(x, y);
        a[i][j] %= MOD;
      } else {
        a[i][j] += a[x][y];
        a[i][j] %= MOD;
      }
    }
  }
  return a[i][j];
}

int main() {
  scanf("%d %d", &row, &col);
  for (int i = 1; i <= row; i++) {
    string temp;
    cin >> temp;
    grid[i] = "/";
    grid[i] += temp;
  }
  printf("%d\n", dfs(1, 1));
  return 0;
}


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

struct edge {
    int from, to, cost;
    edge(int f, int t, int c) : from(f), to(t), cost(c) {}
};

int main() {
    int l; cin >> l;
    int n = 1;
    while((1 << n) <= l) n += 1;
    vector<edge> es;
    for(int i = 1; i <= n - 1; ++i) {
        es.emplace_back(i, i + 1, 1 << (n - i - 1));
        es.emplace_back(i, i + 1, 0);
    }
    if(l ^ (l & -l)) { // l != 2^i
        const int base_cost = 1 << (n - 1);
        int cur = l - 1;
        for(int i = 2; i <= n - 1; ++i) {
            if((l - (1 << (n - 1))) & (1 << (n - i))) {
                const int t = (1 << (n - i)) - 1;
                es.emplace_back(1, i, base_cost + cur - (1 << (n - 1)) - t);
                cur = (1 << (n - 1)) + es.back().cost - 1 - base_cost;
            }
        }
        if(es.back().cost != base_cost) {
            es.emplace_back(1, n, base_cost);
        }
    }

    cout << n << " " << es.size() << endl;
    for(const auto& e : es) {
        cout << e.from << " " << e.to << " " << e.cost << endl;
    }
    assert(n <= 20 && es.size() <= 60u);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N;
    cin >>N;
    vector<ll>A(N);
    map<ll,ll>m;
    rep(i,N){
        cin>>A[i];
        m[A[i]]++;
    }
    ll cnt=0;

    for (const auto& [key, value] : m){
        cnt+=value-1;
    }
    //cout<<cnt<<endl;
    cout<<N-((cnt+1)/2)*2<<endl;

    return 0;
    

}

Measured memory_bytes: 10272
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	ans := 0
	for i := 1; i*i < n; i++ {
		if n%i == 0 {
			if m := n/i - 1; m > i {
				ans += m
			}
		}
	}
	fmt.Println(ans)
}


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


#define li			long long int
#define rep(i,to)	for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)	for(li i=(li)(start);i<((li)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)		idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)	for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)		idp p2((x).F, (x).S)
#define dump(x,n)	idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)	idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)	idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)	idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)	rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)	rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


int main(){
	li x,y;
	cin>>x>>y;
	li g=__gcd(x,y);

	cout<<(x/g-1)*3*g<<endl;



	return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i = 0; i < n; i++)

int main() {
	int n;
	cin >> n;
	int a = n % 10;
	if (a == 3) cout << "bon" << endl;
	else if (a == 0 || a == 1 || a == 6 || a == 8) cout << "pon" << endl;
	else cout << "hon" << endl;
	return 0;
}

Measured memory_bytes: 3636
N, T = map(int, input().split())


lst = []
for i in range(N):
    data = list(map(int, input().split()))
    if data[1] <= T:
        lst.append(data)


if lst == []:
    print("TLE")
else:
    lst.sort(key = lambda x: x[0])
    print(lst[0][0])


Measured memory_bytes: 2940
import java.util.Scanner;

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

        int A = sc.nextInt();
        int B = sc.nextInt();
        float T = Float.parseFloat(sc.next()) + 0.5F;

        int total = 0;
        int time = 0;
        while (true) {
            time += A;
            if (time > T) {
                break;
            } else {
                total += B;
            }
        }

        System.out.println(total);
        sc.close();
    }
}

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

int debug = 1;
int test = 1;

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

#define ll long long

long double pi = 3.14159265358979323846;

#define binf 10000000000050000
#define llinf 1000000000005000000
#define inf 1000050000
#define MOD 1000000007
#define abs llabs

#define prDouble(x) cout << fixed << setprecision(10) << x
//-----------------------------------------//
#define test() int tt=1; if(test){cin>>tt;}  while(tt--)

//###########################################//
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
//###########################################//
void filereader() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif
}
//###########################################//

 double dp[3001][3001];

// I
 double solve(double a[], int i, int x)
{
    if (x == 0)
    {
        return 1;
    }

    if (i == 0)
    {
        return 0;
    }

    if (dp[i][x] > -0.9)
        return dp[i][x];

    return dp[i][x] = a[i] * (solve(a, i - 1, x - 1)) + (1 - a[i]) * (solve(a, i - 1, x ));

}

int main() {

    debug = 0;
    test = 0;

    test() {

        int n;
        cin>>n;
        double a[n + 1];

       memset(dp,-1,sizeof dp);

        REP(i, n)
        {
            cin >> a[i];
        }

        prDouble(solve(a, n, (n + 1) / 2));

    }
}
/*
Maximum Circular Sum CodeChef Qn
Wildcard Matching

// F

*/


Measured memory_bytes: 74288
package main

// Solution for https://atcoder.jp/contests/abc068/tasks/arc079_a

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var n, m int
	con.Scan(&n, &m)
	x := make([]bool, n+1)
	y := make([]bool, n+1)
	for i := 0; i < m; i++ {
		var a, b int
		var z bool
		con.Scan(&a, &b)
		if a == 1 {
			x[b] = true
			z = y[b]
		}
		if a == n {
			y[b] = true
			z = x[b]
		}
		if b == 1 {
			x[a] = true
			z = y[a]
		}
		if b == n {
			y[a] = true
			z = x[a]
		}
		if z {
			con.Println("POSSIBLE")
			return nil
		}
	}
	con.Println("IMPOSSIBLE")
	return nil
}


Measured memory_bytes: 5504
// #pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vecll>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define endl "\n"
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
#define MM " "
using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
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 T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}


vector<vec> G;
vecll d;
int dfs(int x,int p,ll t){
    ll s=t;
    t+=d[x];
    d[x]+=s;
    for(auto e:G[x]){
        if(e!=p){
            dfs(e,x,t);
        }
    }
}
            
        
main(){
    ios
    int n=in();
    int q=in();
    G.resize(n);
    d.resize(n);
    rep(i,n-1){
        int a=in()-1,b=in()-1;
        G[a].pb(b);G[b].pb(a);
    }
    rep(i,q){
        int p=in(),x=in();
        d[p-1]+=x;
    }
    dfs(0,-1,0);
    rep(i,n){
        cout<<d[i]<<" ";
    }
}



Measured memory_bytes: 24320
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define rep0(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)
#define test(a) cout << "*" << a << endl;
static const int NMAX = 100;
int main (){
  int i,j,k;
  int N;
  int A[NMAX+1];
  int v;
  
  cin >> N;
  for(i=0;i<N;i++){
    cin >> A[i];
  }
  
  for(k=0;k<N;k++){
      if(k==N-1)
        cout << A[k];
      else
        cout << A[k] << " ";
  }
  cout << endl;
  
  for(i=1;i<N;i++){
    v = A[i];
    j = i-1;
    while(j>=0&&A[j]>v){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    
    for(k=0;k<N;k++){
      if(k==N-1)
        cout << A[k];
      else
        cout << A[k] << " ";
    }
    cout << endl;
  }
    
  
  
}
    
  
  



Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define ll long long
#define lf double
#define E complex<lf>
#define inf 0x3f3f3f3f
#define eps 1e-8
#define pa pair<int,int>
#define pb push_back
#define ms(x,y) memset(x,y,sizeof(x))
#define l(x) (x<<1)
#define r(x) (x<<1|1)
#define mod 1000000007
#define N 100010
using namespace std;
inline ll read() {
	ll x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}
int n,m;
ll x,t[N],a[N],r[N];
int main() {
	x=read(),n=read();
	for (int i=1; i<=n; i++) r[i]=read();
	m=read();
	for (int i=1; i<=m; i++) t[i]=read(),a[i]=read();
	ll h=0,k=1,opt=-1,mx=x,mn=0;
	for (int i=1; i<=m; i++) {
		while (k<=n&&t[i]>=r[k]) {
			ll v=(r[k]-r[k-1])*opt;
			mx+=v,mn+=v,h+=v;
			mx=min(mx,x),mx=max(mx,0ll);
			mn=min(mn,x),mn=max(mn,0ll);
			k++,opt*=-1;
		}
		ll now=a[i]+h,d=(t[i]-r[k-1])*opt;
		now=max(now,mn),now=min(now,mx);
		now+=d,now=max(now,0ll),now=min(now,x);
		printf("%lld\n",now);
	}
}

Measured memory_bytes: 3584
#include<iostream>
using namespace std;
int main(){
    int n,i,k,j;
    char s;
    int a[4][13];
    for(i=0;i<4;i++){
        for(j=0;j<13;j++){
            a[i][j]=0;
        }
    }
    cin >> n;
    for(i=0;i<n;i++){
        cin >> s >> k;
        if(s == 'S') a[0][k-1] =1;
        if(s == 'H') a[1][k-1] =1;
        if(s == 'C') a[2][k-1] =1;
        if(s == 'D') a[3][k-1] =1;
    }
    for(i=0;i<4;i++){
        for(j=0;j<13;j++){
            if(a[i][j]==0){
                if(i==0) cout << "S ";
                if(i==1) cout << "H ";
                if(i==2) cout << "C ";
                if(i==3) cout << "D ";
                cout << j+1 << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b); for(int i=(a); i<=(b); i++) 
#define rep(i,n) for(int i = 0; i < (n); i++)
const int MOD = 1e9+7;
int gcd(int a, int b){ //a>=0,b>=0,￢(a=b=0)
  while(min(a,b)>0){if(a<b)swap(a,b);a=a%b;}return max(a,b);
}
vector<vector<int>> g(200005);
vector<int> ans;

void dfs(int v,int p){//v：見る場所　p：vの親
  rep(i,g[v].size()){
    int u=g[v][i];
    if(u==p) continue;
    ans[u] += ans[v];
    dfs(u,v);
  }
}


signed main(){
  int n, q;
  cin>>n>>q;
  g.resize(n-1);
  ans.resize(n);
  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    --a;--b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  rep(i,q){
    int p,x;
    cin>>p>>x;
    --p;
    ans[p]+=x;
  }  
  dfs(0,-1);
  rep(i,n){
    cout<<ans[i]<<" ";
  }
  cout<<endl;
  return 0;
}


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

int main() {
  ll N, K;
  cin >> N >> K;
  
  ll x = N/K;
  x *= K;
  x = N-x;
  x = min(x, abs(x-K));
  cout << x << endl;
  return 0;
}




Measured memory_bytes: 3620
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1000003 ;

struct edge{int to,cost;};
int V;
vector<edge> G[100010];
ll d[100010];

void dijkstra(int s){
  priority_queue<pint,vector<pint>,greater<pint>> que;
  fill(d,d+V,longinf);
  d[s]=0;
  que.push(pint(0,s));
  
  while(!que.empty()){
    pint p=que.top(); que.pop();
    int v=p.second;
    if(d[v]<p.first)continue;
    rep(i,G[v].size()){
      edge e=G[v][i];
      if(d[e.to]>d[v]+e.cost){
        d[e.to]=d[v]+e.cost;
        que.push(pint(d[e.to],e.to));
      }
    }
  }
}

int main(){
  cin >> V;
  rep(i,V-1){
    int a,b,c;
    cin >> a >> b >> c;
    a--,b--; //due to the index of G
    G[a].push_back({b,c});
    G[b].push_back({a,c});
  }
  int q,k;
  cin >> q >> k;
  k--;
  dijkstra(k);
  rep(i,q){
    int x,y;
    cin >> x >> y;
    x--,y--;
    cout << d[x]+d[y] << endl;
  }
return 0;}

Measured memory_bytes: 8820
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,p;
string s;
int dp[200001];
int val[200001];

int main(void){
	scanf("%d%d",&n,&p);
	
	cin >> s;
	ll ans=0;
	if(p==2 || p==5){
		for(int i=0;i<n;i++){
			if((s[i]-'0')%p==0){
				ans+=(i+1);
			}
		}
		printf("%lld\n",ans);
		return 0;
	}
	int vi=1;
	for(int i=n-1;i>=0;i--){
		val[i]=val[i+1];
		val[i]+=vi*(s[i]-'0');
		vi=vi*10%p;
		val[i]%=p;
		dp[val[i]]++;
	}
	dp[0]++;
	for(int i=0;i<n;i++){
		dp[val[i]]--;
		ans+=dp[val[i]];
	}
	printf("%lld\n",ans);
	return 0;
}


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

typedef long long ll;
typedef long double ld;

const double EPS = 1e-9;
const int INF = (int)1e9 + 41;
const int N = (int)1e6 + 34;

void solve() {
    string s;
    cin >> s;
    int sum = 0;
    int num1 = 0, num0 = 0;
    int n = s.length();
    for (int i = 0; i < (int)s.length(); i++) {
        sum += s[i] - '0';
        if (s[i] == '0') num0++;
    }
    if (sum == 1 && num0 + 1 == n) cout << "10\n";
    else cout << sum << "\n";
}

int main() {
#ifdef FIRE_MIND
    freopen("a.in", "r", stdin);
    ///freopen("a.out", "w", stdout);
    solve();
    solve();
#endif
	solve();
    return 0;
}



Measured memory_bytes: 256
def print_list(numlist):
    n = len(numlist)
    for i in range(n):
        if i == n - 1:
            print(numlist[i])
        else:
            print(numlist[i], end=' ')
        
if __name__ == '__main__':
    n = int(input())
    numlist = [int(num) for num in input().split(' ')]
    
    print_list(numlist)
    for i in range(1, n):
        key_value = numlist[i]
        j = i - 1
        while j >= 0 and numlist[j] > key_value:
            numlist[j + 1] = numlist[j]
            j -= 1
        numlist[j + 1] = key_value
        print_list(numlist)


Measured memory_bytes: 5980
#include "bits/stdc++.h"

using namespace std;

void Main() {
    long long N;
    cin >> N;
    if (N == 1) {
        cout << 1 << endl;
        return;
    }

    vector<long long> L(N + 1, 0LL);
    L[0] = 2;
    L[1] = 1;
    for (long long i = 2; i < N + 1; ++i) {
        L[i] = L[i - 1] + L[i - 2];
    }
    cout << L[N] << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3640
n=int(input())
arr=[(int(input()),i//n) for i in range(2*n)]
arr=sorted(arr,key=lambda x:x[0])
mod=10**9+7
ans=1
cnta=0
cntb=0
for pos,flag in arr:
  if flag==0:
    if cntb==0:
      cnta+=1
    else:
      ans*=cntb
      ans%=mod
      cntb-=1
  else:
    if cnta==0:
      cntb+=1
    else:
      ans*=cnta
      ans%=mod
      cnta-=1
print(ans)

Measured memory_bytes: 28628
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
using namespace std;

int main() {
    
    int N;
    vector<long long> A,B;
    long long ans = 0;
    
    cin >> N;
    
    for ( int i = 0; i < N; i++ ) {
        long long a, b;
        cin >> a;
        cin >> b;
        
        A.push_back(a);
        B.push_back(b);
    }
    
    reverse( A.begin(), A.end() );
    reverse( B.begin(), B.end() );
    
    for ( int i = 0; i < N; i++ ) {
        
        A[i] += ans;
        
        if ( !A[i] ) { continue; }
        if ( B[i] == 1 ) { continue; }        
        if ( A[i] % B[i] == 0 ) { continue; }
        
        // cout << "A[i]: " << A[i] << endl;
        // cout << "B[i]: " << B[i] << endl;
        
        
        long long dif;
        if ( A[i] <= B[i] ) {
            dif = B[i] - A[i];
        }
        else {
            dif = B[i] - (A[i] % B[i]);
        }
        
        // cout << "dif: " << dif << endl;
        
        ans += dif;
        
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 2036
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  cin>>h>>w;
  char maps[101][101];
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      cin>>maps[i][j];
    }
  }
  for(int i=0;i<=h+1;i++){
    for(int j=0;j<=w+1;j++){
      if(i==0||j==0||i==h+1||j==w+1)cout<<'#';
      else cout<<maps[i][j];
    }
    cout<<endl;
  }
}

Measured memory_bytes: 256
from operator import itemgetter
n,k = map(int,input().split())
count = 0
ans = 0
a = [list(map(int,input().split())) for i in range(n)]
number = sorted(a, key = lambda x: x[0])

for i in range(n):
    count += number[i][1]
    if count >= k:
        ans = number[i][0]
        break
    
print(ans)

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

using namespace std;

#define INF 2000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;


int main()
{
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;

	int w = abs(tx-sx);
	int h = abs(ty-sy);

	string s = "";
	for (int i = 0; i < w; i++) {
		s += "R";
	}
	for (int i = 0; i < h; i++) {
		s += "U";
	}
	for (int i = 0; i < w; i++) {
		s += "L";
	}
	for (int i = 0; i < h; i++) {
		s += "D";
	}

//
	s += "D";
	for (int i = 0; i < w; i++) {
		s += "R";
	}
	s += "R";
	s += "U";
	for (int i = 0; i < h; i++) {
		s += "U";
	}
	s += "L";
	s += "U";
	for (int i = 0; i < w; i++) {
		s += "L";
	}
	s += "L";
	s += "D";
	for (int i = 0; i < h; i++) {
		s += "D";
	}
	s += "R";
	cout << s << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <string>
#include <cstdlib>
#include <bitset>
#include <vector>

using namespace std;
using Graph = vector<vector<long long>>;

vector<long long> color;

long long N, M;

long long black = 0;
long long white = 0;

bool dfs(const Graph &G, long long v, long long cur = 0) {
  color[v] = cur;

  for (auto next_v : G[v]) {
    if (color[next_v] != -1) {
      if (color[next_v] == cur) {
        return false;
      } else {
        continue;
      }
    }
    if (!dfs(G, next_v, 1 - cur)) return false;
  }
  return true;
}

int main() {
  cin >> N >> M;

  Graph G(N);

  for (long long i = 0; i < M; i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  color.assign(N, -1);
  bool is_bipartite = true;
  for (long long v = 0; v < N; v++) {
    if (color[v] != -1) continue;
    if (!dfs(G, v)) is_bipartite = false;
  }

  if (is_bipartite) {
    for (auto i : color) {
      black = (i == 0) ? black + 1 : black;
      white = (i == 1) ? white + 1 : white;
    }
    cout << black * white - M << endl;
  } else {
    cout << (N * (N -1)) / 2 - M << endl;
  }
  
}


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

const int mod = 1000000007;
class mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
    mint choose(int n, int a){
        mint x = 1 ,y = 1;
        for(int i = 0; i < a; ++i){
            x *= n-i;
            y *= i+1;
        }
        return x / y;
    }
    friend istream& operator>>(istream& is, mint& m){
        is >> m.x;
        return is;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

mint dp[100010][15];

int main(){
  string s;
  cin>>s;
  int n=s.size();
  dp[0][0]=1;
  for(int i=0; i<n; ++i){
    int D=s[i]-'0';
    for(int j=0; j<=12; ++j){
      for(int d=0; d<=9; ++d){
        if(D=='?'-'0'){
          dp[i+1][(j*10+d)%13]+=dp[i][j];
        }
        else{
          dp[i+1][(j*10+D)%13]=dp[i][j];
        }
      }
    }
  }
  cout<<dp[n][5]<<endl;
}

Measured memory_bytes: 15440
#include<bits/stdc++.h>
#define ll long long
#define all(v) v.begin(),v.end()
#define PB push_back
#define PI 3.1415926535897932384626433832795
#define what(x) cout<<#x<<" is "<<x<<endl;
using namespace std;


template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

ll powmod(ll a,ll b,ll mod) {
    ll res=1;a%=mod;
    //assert(b>=0);
    for(;b;b>>=1){
        if(b&1)res=res*a%mod;a=a*a%mod;
    }
    return res;
}
const ll M=1e9+7;
void solve(){
	int n;
	cin>>n;
	ll ans=powmod(10,n,M);
	ll temp=2*powmod(9,n,M)-powmod(8,n,M);
	ans-=temp;
	ans%=M;
	cout<<(ans+M)%M<<'\n';
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    #endif
    int tc=1;
    // cin>>tc;
    while(tc--)solve();
}


Measured memory_bytes: 3592