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

using dbl=double;
using ll=long long;
using pii=pair<int, int>;
using pll=pair<ll, ll>;

#define sz(a) ((int)a.size())
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define forse(i,s,e) for(int i=(int)s;i<(int)e;i++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second

const dbl PI=3.141592653589793;


void solve(){
	int n;
	cin >> n;
	vector<int> cnt(1e4+1,0);
	forse(x,1,101){
		forse(y,1,101){
			forse(z,1,101){
				int val=x*x+y*y+z*z+x*y+y*z+z*x;
				if(val<sz(cnt)) cnt[val]++;
			}
		}
	}
	forn(i,n) cout << cnt[i+1] << '\n';
}

int main() {
//	ios::sync_with_stdio(0);
//	cin.tie(0); 
	int T=1;
//	cin >> T;
	for(int c=1;c<=T;c++){
		solve();
	}
}

Measured memory_bytes: 3628
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#solve
def solve():
    t = S()
    for i in t:
        if i == "?":
            print("D", end="")
        else:
            print(i, end="")
    print()
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 89316
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int k;
    cin >> k;
    vector<ll> a(k);
    for(int i = 0; i < k; ++i)  cin >> a[i];
    ll lb = 2, ub = 2;
    for(int i = k - 1; i >= 0; --i){
        ll foo = a[i];
        if(lb % a[i] == 0)  foo *= lb / a[i];
        else    foo *= lb / a[i] + 1;
        if(foo > ub){
            cout << -1 << endl;
            return 0;
        }
        ll bar = a[i] * (ub / a[i]);
        bar += a[i] - 1;
        lb = foo, ub = bar;
    }
    cout << lb << " " << ub << endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

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

  int X, Y;
  cin >> X >> Y;
  cout << (X+Y/2) << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;


void solve(){
  long double n;
  cin >> n;
  long nn = (long)n;
  long double tmp = sqrt(n);
  tmp = floor(tmp);
  long i = (long)tmp;
  while(true){
    if(nn%i==0){
      cout << i+(nn/i)-2 << endl;
      break;
    }
    else{
      i--;
    }
  }
}

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


Measured memory_bytes: 384
#include <cstdio>
using namespace std;
const int maxn = 2*1e5+5;
int n,k,ans;
int main() {
	scanf("%d%d",&n,&k);
	long long c1 = 0;
	long long c2 = 0;
	c1 = n/k;
	if (k%2 == 0) {
		for (int i = k/2; i <= n; i+=k) {
			c2++;
		}
	}
	long long ans = c1*c1*c1+c2*c2*c2;
	printf ("%lld\n",ans);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
const int maxn = 1e9 + 5;
#define INF 1000000000
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;



int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio
	string a,b;
	cin >> a >> b;
	cout << b+a << endl;
} 






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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

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

    string s; cin >> s;
    cout << count(all(s), '2') << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin >> n;
    int retu[10000];
    int count = 0;
    for(int i = 0;i < n;i++){
        cin >> retu[i];
        while(retu[i]%2 == 0){
            count++;
            retu[i] = retu[i]/2;
        }
    }
    cout << count << endl;
    return 0;
    
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var Q = Sarray()[0];
            var rui = new long[100002];
            for (var i = 1; i < 100001; ++i)
            {
                var like2017 = eratos.isPrime(i - 1) && eratos.isPrime(i / 2);
                rui[i] = rui[i - 1] + (like2017 ? 1 : 0);
            }
            for(var i=0;i<Q;++i)
            {
                var lr = Sarray();
                var l = lr[0];
                var r = lr[1];
                var ans = rui[r + 1] - rui[l];
                WriteLine(ans);
            }
            //Out.Flush();
        }

        public static class eratos
        {
            const long Max = 100010;
            static readonly bool[] isntprime = new bool[Max / 2 + 1];
            static eratos()
            {
                isntprime[0] = true;
                long sqrt = ((long)Math.Ceiling(Math.Sqrt(Max) + 0.1)) / 2;
                for (long i = 1; i < sqrt; ++i)
                    if (!isntprime[i])
                    {
                        long p = 2 * i + 1;
                        for (long j = 2 * i * (i + 1); j < isntprime.Length; j += p)
                            isntprime[j] = true;
                    }
            }
            static public bool isPrime(long x)
            {
                if (2 == x) return true;
                return x % 2 == 0 ? false : !isntprime[x / 2];
            }
        }
    }
}

Measured memory_bytes: 16684
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>
#include <set>

//#define DEBUG

#ifdef DEBUG

#define printd printf

#else

#define printd(...)

#endif

using triple = std::tuple<int, int, int>;

int main() {
    int n;
    std::string s;

    std::cin >> n;
    std::cin >> s;

    std::vector<int> rs, gs, bs;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == 'R') {
            rs.push_back(i);
        } else if (s[i] == 'G') {
            gs.push_back(i);
        } else if (s[i] == 'B') {
            bs.push_back(i);
        }
    }

    std::set<triple> to_remove;
    auto ans = rs.size() * gs.size() * bs.size();
    for (auto &&r : rs) {
        for (auto &&g : gs) {
            auto right = (r > g) ? r : g;
            auto left = (r > g) ? g : r;
            std::vector<int> pos = {
                right - left + right,    // rgb / grb
                left - (right - left)    // brg / bgr
            };
            // rbg / gbr
            if (right - left > 0 && (right - left - 1) % 2 == 1) {
                pos.push_back((right + left) / 2);
            };

            for (auto &&p : pos) {
                if (p < 0 || p >= n) {
                    continue;
                }
                if (s[p] == 'B') {
                    printd("removed: (r: %d, g: %d, b:%d)\n", r, g, p);
                    ans -= 1;
                    #ifdef DEBUG
                    std::vector<int> is = {r, g, p};
                    std::sort(is.begin(), is.end());
                    to_remove.insert(triple(is[0], is[1], is[2]));
                    #endif
                }
            }
        }
    }

#ifdef DEBUG
    int w = 0;
    for (auto &&r : rs) {
        for (auto &&g : gs) {
            for (auto &&b : bs) {
                std::vector<int> is = {r, g, b};
                std::sort(is.begin(), is.end());
                if (is[2] - is[1] == is[1] - is[0]) {
                    if (to_remove.count(triple(is[0], is[1], is[2])) == 0) {
                        std::cout << "is[2], is[1], is[0]: " << is[2] << ", " << is[1] << ", " << is[0] << std::endl;
                    }
                    w++;
                }
            }
        }
    }
    std::cout << "w: " << w << std::endl;
#endif

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 3272
import java.util.Scanner;
public class Main
{
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in); 
    int a  = sc.nextInt();
    int r = a % 1000;
    int s = 1000 - r;
    if(s == 1000)
    {
    System.out.println("0");
    }
    else
    {
    System.out.println(s);
    }
  }
}                          


Measured memory_bytes: 35656
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    while(true){
      int a = sc.nextInt();
      String op = sc.next();
      int b = sc.nextInt();

      if(op.equals("?")) break;

      switch (op) {
        case "+": System.out.println(a + b); break;
        case "-": System.out.println(a - b); break;
        case "*": System.out.println(a * b); break;
        case "/": System.out.println(a / b); break;
      }
    }
    sc.close();
  }
}


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

static long long int MOD = 1000000007;

int main(){
  string s;
  int s_num;
  int n;
  long long int **dp = new long long int*[100005];
  for(int i=0; i<100005; i++){
      dp[i] = new long long int[13];
  }
  cin >> s;
  n = s.size();
  dp[0][0] = 1;
  for(int i=0; i<n; i++){
      if(s.at(i)=='?'){
          s_num = -1;
      }else{
          s_num = s.at(i) - '0';
      }
      for(int j=0; j<10; j++){
          if(s_num != -1 && s_num !=j)continue;
          for(int k=0; k<13; k++){
              dp[i+1][((k*10)+j)%13] += dp[i][k]; 
          }
      }
      for (int k=0; k<13; k++) dp[i+1][k] %= MOD;
  }

  cout << dp[n][5] << endl;

  for(int i=0; i<100005; i++){
      delete[] dp[i];
  }
  delete[] dp;
}

Measured memory_bytes: 12160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    string s,t;
    cin>>s;
    cin>>t;
    ll ns=s.length(),nt=t.length();
    if(nt>ns){
        cout<<"UNRESTORABLE";
        return 0;
    }
    vector<ll>ans;
    rep(0,i,ns-nt+1){
        bool T=true;
        rep(0,j,nt){
            ll x=i+j;
            string s0=s.substr(x,1);
            string t0=t.substr(j,1);
            //cout<<s0<<" "<<t0<<endl;
            if(s0=="?")continue;
            else if(s0!=t0)T=false;
        }
        if(T){
            ans.push_back(i);
        }
    }
    ll nans=ans.size();
    vector<string>anss(nans);
    if(nans==0){
        cout<<"UNRESTORABLE";
        return 0;
    }
    rep(0,i,nans){
        anss[i]=s.substr(0,ans[i])+t+s.substr(ans[i]+nt,ns-nt-ans[i]);
        rep(0,j,ns){
            if(anss[i].substr(j,1)=="?"){
                anss[i]=anss[i].substr(0,j)+"a"+anss[i].substr(j+1,ns-j-1);
            }
        }
    }
    sort(anss.begin(),anss.end());
    cout<<anss[0];
}

Measured memory_bytes: 256
/*
author: Apoorv Singh
*/

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

typedef vector <long long> vi;
typedef pair <long long, long long> pii;
#define pb push_back   
#define aint(c) c.begin(), c.end()
#define watch(x) cout << (#x) << " " << (x) << endl;
#define FOR(i, a, b) for (long long i = a; i < b; ++i)
#define FORR(i, a, b) for (long long i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second
#define int long long
#define inf LLONG_MAX

int modulo = 1e9 + 7;

template <class X>

void printarr(X arr[], int n)
{
    for (int i = 0; i < n; ++i)
        cout << arr[i] << " ";
    cout << endl;
}

int fpow(int a, int n)
{
    int ans = 1;
    while (n)
    {
        if (n&1)
            ans = (ans * a)%modulo;
        a = (a*a)%modulo;
        n = n >> 1;
    }
    return ans;
}

/*
const int M = 1e6 + 10;
int composite[M] = {0};

void sieve()
{
    FOR(i,2,M)
    {
        if (!composite[i])
        {
            for (int j = 2*i; j < M; j += i)
                composite[j] = max(composite[j], i);
        }
    }
}
*/

const int M = 1e5 + 10;
int parent[M], size[M];

int find(int x)
{
	while (x != parent[x])
		x = parent[x];
	return x;
}

void unite(int a, int b)
{
	int x = find(a), y = find(b);
	if (x == y)
		return;
	int p,q;
	(size[x] > size[y]) ? (p = x, q = y) : (p = y, q = x);
	size[p] += size[q];
	size[q] = 0;
	parent[q] = p;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m; cin >> n >> m;
    FOR(i,1,n+1)
    {
    	size[i] = 1;
    	parent[i] = i;
    }
    FOR(i,0,m)
    {
    	int x,y,z; cin >> x >> y >> z;
    	unite(x,y); 
    }
    int ans = 0;
    FOR(i,1,n+1)
    {
    	if (size[i])
    		++ans;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
n,m = gets.split.map(&:to_i)
kaijo = {}
if (n-m).abs > 1
  puts 0
elsif n == m
  d = 1
  (1..n).each do |i|
    d *= i
    d %= (10**9 + 7)
  end
  puts (d**2 * 2) % (10**9 + 7)
else
  d = 1
  t = [n,m].max
  (1..t).each do |i|
    d *= i
    d %= (10**9 + 7)
    kaijo[i] = d
  end
  ans = kaijo[n] * kaijo[m]
  puts ans % (10**9 + 7)
end

Measured memory_bytes: 8316
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    int F[N][10],P[N][11];
    for(int i = 0;i < N;i++){
        for(int j = 0;j < 10;j++)cin >> F[i][j];
    }
    for(int i = 0;i < N;i++){
        for(int j = 0;j <= 10;j++)cin >> P[i][j];
    }
    ll maxi = -INF;
    for(int i = 1;i < (1 << 10);i++){
        ll sum = 0;
        for(int j = 0;j < N;j++){
            int cnt = 0;
            for(int k = 0;k < 10;k++){
                if((i & (1 << k)) && F[j][k])cnt++;
            }
            sum += P[j][cnt];
        }
        maxi = max(maxi, sum);
    }
    cout << maxi << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back

using namespace std;

ll n;
ll a[100005];
int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL); cout.tie(NULL);
        cin >> n;
        for(ll i=1;i<=n;i++) {
                cin >> a[i];
        }
        sort(a+1, a+n+1);
        for(ll i=1;i<n;i++) {
                if(a[i] < 0 && a[i+1] < 0) {
                        a[i] *= -1;
                        a[i+1] *= -1;
                        i += 1;
                }else if(a[i] < 0 && a[i+1] >= 0) {
                        if(a[i] + a[i+1] > -a[i] -a[i+1]) {
                                i += 1;
                        }else {
                                a[i] *= -1;
                                a[i+1] *= -1;
                                i += 1;
                        }
                }
        }
        ll sum = 0;
        for(ll i=1;i<=n;i++) sum += a[i];
        cout << sum << endl;
        return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define ll long long
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define fi first
#define se second
#define pr(x) cerr<<#x<<"="<<(x)<<endl
#define pri(x,lo) {cerr<<#x<<"={";for (int ol=0;ol<=lo;ol++)cerr<<x[ol]<<("},"[ol<lo]);cerr<<endl;}
#define inf 100000000
#define N 11000
char ch[N];
int a[N],b[N],f[2010][2010],g[2010][2010],dp[4010][2010],i,j,n,pos[3][2010];
int main()
{
	scanf("%d",&n);
	for (i=1;i<=2*n;i++)
	{
		scanf("%s",ch);
		a[i]=ch[0]=='W'?0:1;
		scanf("%d",&b[i]);
		pos[a[i]][b[i]]=i;
	}
	for (i=1;i<=n;i++)
	{
		for (j=1;j<=2*n;j++) 
		{
			if (a[j]==0&&b[j]==i) break;
			if (a[j]==0&&b[j]<i) continue;else f[i][0]++;
		}
		for (j=1;j<=n;j++)
			f[i][j]=f[i][j-1]-(pos[1][j]<pos[0][i]);
	}
	for (j=1;j<=n;j++)
	{
		for (i=1;i<=2*n;i++) 
		{
			if (a[i]==1&&b[i]==j) break;
			if (a[i]==1&&b[i]<j) continue;else g[0][j]++;
		}
		for (i=1;i<=n;i++)
			g[i][j]=g[i-1][j]-(pos[0][i]<pos[1][j]);
	}
//	for (i=1;i<=n;i++) pri(f[i],n);
//	for (i=1;i<=n;i++) pri(g[i],n);
	memset(dp,0x7f,sizeof(dp));
	dp[0][0]=0;
	for (i=0;i<=n;i++) for (j=0;j<=n;j++)
	{
		if (i!=0) dp[i][j]=min(dp[i][j],dp[i-1][j]+f[i][j]);
		if (j!=0) dp[i][j]=min(dp[i][j],dp[i][j-1]+g[i][j]);
	}
	printf("%d\n",dp[n][n]);
}
	
		

Measured memory_bytes: 63232
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		System.out.println(func(n));
	}
	
	public static long func(int n) {
		if (n == 1) return 1;
		return n * func(n - 1);
	}

}

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

int main(){
  
  int N;
  cin >> N;
  
  if(N == 1)
    cout << "Hello World" << endl;
  
  else if(N == 2){
    int A,B;
    cin >> A >> B;
    
    cout << A+B << endl;
  }
}

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

using namespace std;
using ll = long long;
using vl = vector<ll>;
using pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

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

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
constexpr ll mod = 1000000007;

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

    vector<int> A(N);
    unordered_map<int, int> m;
    m.reserve(N);
    ll ans = 0;
    for (int i = 0; i < N; ++i) {
        ll t;
        cin >> t;
        int x = i + 1 - t;

        if (m.find(x) != m.end()) {
            ans += m[x];
        }

        if (m.find(i + 1 + t) == m.end()) {
            m.emplace(i + 1 + t, 1);
        } else {
            ++m[i + 1 + t];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 11856
N, M = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
BC_list = []
for _ in range(M):
    B, C = map(int, input().split(' '))
    BC_list.append((B, C))
BC_list = sorted(BC_list, key= lambda x: x[1], reverse=True)

for b, c in BC_list:
    A.extend([c]*b)
    if len(A) > 2*N:
        break
print(sum(sorted(A)[-N:]))

Measured memory_bytes: 26696
#include<vector>
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<limits.h>
#include<cmath>
#include<iomanip>
using namespace std;

int main(){
  
  cout << fixed << setprecision(10);
  
  int n,k; cin >> n >> k;
  double p=0;
  
  for (int i=1; i<=n; i++){
    double a = max(ceil(log((double)k/i)/log(2.0)),0.0);
    p += (1.0/n)*pow(1.0/2.0, a);
  }
  
  cout << p;
 
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 300005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N,M;
int tr[MAXN],ans[MAXN];
pii p[MAXN];
int lowbit(int x) {return x & (-x);}
void insert(int x,int v) {
    ++x;
    while(x <= M + 1) {
	tr[x] += v;
	x += lowbit(x);
    }
}
int query(int x) {
    int v = 0;++x;
    while(x > 0) {
	v += tr[x];
	x -= lowbit(x);
    }
    return v;
}
void Solve() {
    read(N);read(M);
    for(int i = 1 ; i <= N ; ++i) {
	read(p[i].fi);read(p[i].se);
	--p[i].fi;
	insert(p[i].fi,1);insert(p[i].se,-1);
    }
    sort(p + 1,p + N + 1,[](pii a,pii b){return a.se - a.fi < b.se - b.fi;});
    int id = N;
    int cnt = 0;
    for(int i = M ; i >= 1 ; --i) {
	while(id >= 1 && p[id].se - p[id].fi >= i) {
	    insert(p[id].fi,-1);insert(p[id].se,1);
	    ++cnt;--id;
	}
	ans[i] = cnt;
	int t = i;
	while(t <= M) {
	    ans[i] += query(t - 1);
	    t += i;
	}
    }
    for(int i = 1 ; i <= M ; ++i) {out(ans[i]);enter;}
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl;
#define CNO cout<<"No"<<endl;

typedef long long LL;
typedef long double LD;

map<LL,LL> mp;
vector<vector<int>> e;

LL dfs(int x, int p){
  LL hs=0;
  for(auto nx:e[x]){
    if(nx==p) continue;
    hs=(hs+dfs(nx, x))%MOD;
  }
  hs=(1007*hs+1)%MOD;
  mp[hs]++;
  return hs;
}

int main(){
  int n;
  cin >> n;
  e=vector<vector<int>>(n);
  int a,b;
  rep(i,n-1){
    cin >> a >> b;
    e[a-1].push_back(b-1);
    e[b-1].push_back(a-1);
  }
  dfs(0, -1);
  LL ans=0;
  for(auto x:mp){
    ans += x.second*(x.second-1)/2;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 22316
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int n,m,f[N],siz[N];
inline int Find(int x)
{
    if(x==f[x]) return x;
    int gt=Find(f[x]);
    siz[x]+=siz[f[x]];
    return f[x]=gt;
}
inline int Merge(int u,int v,int w)
{
    int fx=Find(u), fy=Find(v);
    if(fx==fy) return (w==siz[v]-siz[u]);
    f[fy]=fx;
    siz[fy]=w+siz[u]-siz[v];
    return 1;
}
signed main()
{
    n=read(), m=read();
    for(ri int i=1;i<=n;i++) f[i]=i;
    int flg=1;
    for(ri int i=1;i<=m;i++)
    {
        int u,v,w;
        u=read(), v=read(), w=read();
        if(!flg) continue;
        flg=Merge(u,v,w);
    }
    (flg)?puts("Yes"):puts("No");
    return 0;
}

Measured memory_bytes: 5168
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

def ceil(a,b):
    return a//b + int(a%b != 0)

N,H = LI()
a,b = LIR(N,2)

x = []
for i in range(N):
    x.append((a[i],0))
    x.append((b[i],1))

x.sort(key=lambda x: (-x[0],x[1]))

val = 0
count = 0
for x0 in x:
    if x0[1] == 0:
        use_a = x0[0]
        break
    else:
        val += x0[0]
        count += 1
        if val >= H:
            print(count)
            exit()

H -= val
ans = count + ceil(H,use_a)
print(ans)

Measured memory_bytes: 82396
n = int(input())
h = list(map(int,input().split()))
dp = [1<<30]*n
dp[0] = 0 

for i in range(1,n):
    dp[i] = min(dp[i],dp[i-1]+abs(h[i]-h[i-1]))
    if i > 1:
       dp[i] = min(dp[i], dp[i-2]+abs(h[i]-h[i-2]))
        
print(dp[n-1])


Measured memory_bytes: 13924
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,ans=0;
	cin>>n;
	char pre=0;
	char s;
	for(int i=1;i<=n;i++)
	{
		while((s=getchar())>'z'||s<'a');
		if(s!=pre) ans++;
		pre=s;
	}
	printf("%d\n",ans);
}

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

int main(){
  int n,d;
  cin >> n >> d;
  vector<vector<int>> a(n,vector<int>(d));
  for(int i=0;i<n;i++){
    for(int j=0;j<d;j++){
      cin >> a.at(i).at(j);
    }
  }
  
  int k=0;
  
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      double x=0;
      for(int l=0;l<d;l++){
        x+=(a.at(i).at(l)-a.at(j).at(l))*(a.at(i).at(l)-a.at(j).at(l));
      }
      int y=sqrt(x);
      if(sqrt(x)-y==0){
        k++;
      }
    }
  }
  cout << k << endl;
}

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

int main()
{
  int x, a, b;
  cin >> x >> a >> b;
  x -= a;
  while(x >= b){
    x -= b;
  }
  cout << x << endl;
  system("pause");
}


Measured memory_bytes: 504
#include "stdio.h"
#include "stdlib.h"
#include "iostream"
#include "math.h"
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include "algorithm"


using namespace std;
#define fori0(G) for(int i=0;i<G;i++)
#define fori1(G) for(int i=1;i<=G;i++)
#define forj0(G) for(int j=0;j<G;j++)
#define forj1(G) for(int j=1;j<=G;j++)
#define fork0(G) for(int k=0;k<G;k++)
#define fork1(G) for(int k=1;k<=G;k++)
int dx[] = { -1,0,1,0 ,0 }, dy[] = { 0,1,0,-1,0 };
#define nxnycon (0<=nx&&nx<h&&0<=ny&&ny<w) 
#define lo long long int
#define  NN cout << "No"<<endl;
#define  YY cout << "Yes"<<endl;

lo d,g,p[10],c[10],a,s,b[10],t,ib,sd,en;
//string s;



int main() {
	cin >> d>>g;
	fori0(d) {
		cin >> p[i] >> c[i];
		b[i] = (100)*(i+1)*p[i] + c[i];
		//cout << p[i] << endl;

	}
	



	while (a==0) {
		s++;
		/*int jj = d - 1;
		sd = s;
		en = 0;
		ib = 0;
		while(en==0){
			if (sd >= p[jj]) {
				ib =ib+b[jj];
				sd -= p[jj];

			}
			else {
				ib += sd * 100 * (jj + 1);
				en = 1;
			}
			jj--;
		}*/
		//cout << ib<<endl;
		
		fori0(1024) {
			int sv = 0,hih=d-1;
			int h = 0;
			int tb =0;
			int ck = 0;
			for(int j=d-1 ;j>=0;j--){
				if (i&(int)(pow(2, j))) { 
					h += p[j]; 
					tb += b[j];
				}
				else {
					if (sv == 0) { hih = j;sv = 1; }
				}
				
			}
			if (h <= s && s - h<p[hih]) {
				ck = 1;
				tb += (s - h) * 100 * (hih + 1);
				//printf("(%d,%d,%d)", tb, h, hih);
			}
			if (ck == 1 && tb >= g) { 
				//printf("(%d)", tb);
				//cout << s;
				a = 1; }

		}
		


	}
	cout << s;
	
	//system("pause");
	return 0;

}



Measured memory_bytes: 512
a,b,c,d,e,f=map(int, input().split())

indxmax=0.0
wmax=0
emax=0
elimit=(100*e)/(100+e)
c31=int(f/c)+1
for ai in range(0,f+1,100*a):
    for bi in range(0,f-ai+1,100*b):
        w=ai+bi
#        print("a,b:",ai,bi,w)
        if w<=f and w>0:
            c31=(w*e)//100+c
            for ci in range(0,c31,c):
#                di=(max(0,(c31-ci-1))//d)*d
#                di=min(di,((e*w/100-ci)//d)*d)
                di=int(max(0,(min(f-w-ci,e*w/100-ci)//d)*d))
#                di=int(max(0,(min(f-w-ci-1,e*w/100-ci)//d)*d))
                indx=(ci+di)*100/w
                if indxmax<indx and e-indx>=0.0 and w+ci+di<=f:
                    wmax=w+ci+di
                    indxmax=indx 
                    emax=ci+di
#                    print("c,d",ci,di,emax,wmax,diii)
if wmax>0:
    print(wmax,emax)
else:
    print(100*a,emax)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#include<map>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>
#include<set>

#define ll long long

using namespace std;

string S;

int main(){
    
    cin >> S;
    
    ll A_cnt;
    ll BC_cnt;
    ll ans=0;
    
    for(ll i=0;i<S.size();i++){
        A_cnt=0;
        BC_cnt=0;
        if(S[i]=='A'){
            while(S[i]=='A'){
                A_cnt++;
                i++;
            }
            while(S[i]=='B'&&S[i+1]=='C'){
                BC_cnt++;
                i+=2;
            }
            if(A_cnt>0&&BC_cnt>0){
                for(ll j=i-A_cnt;j<i;j++){
                    S[j]='A';
                }
                i-=A_cnt+1;
            }
        }
        ans+=A_cnt*BC_cnt;
    }
    
    cout << ans << endl;
    
    // A BC BC BC BC BC A BC BC BC
    
    return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#define MOD 1000000007

using namespace std;
typedef long long int ll;

ll solve(vector <int> vx)
{
	ll ret=0;
	for(int i=0;i<vx.size();i++) ret+=(ll) (2*i-(int) vx.size()+1)*(ll) vx[i];
	return ret%MOD;
}
int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	ll ret=1;
	vector <int> vx;
	for(int i=0;i<n;i++)
	{
		int x;
		scanf("%d",&x);
		vx.push_back(x);
	}
	ret=ret*solve(vx)%MOD;
	vx.clear();
	for(int i=0;i<m;i++)
	{
		int x;
		scanf("%d",&x);
		vx.push_back(x);
	}
	ret=ret*solve(vx)%MOD;
	printf("%lld\n",ret);
	return 0;
}


Measured memory_bytes: 1144
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
const int mod = 1e9+7;
const int mx = 1e15;
const long double pi = 4*atan((long double)1);
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
#define file "03"
const int mxN = 1e5+5;
int n,m,ss,t;
vii G[mxN];
int cnt1[mxN], cnt2[mxN];
int dist1[mxN], dist2[mxN];
bool visited[mxN];
int Pow(int val)
{
	return val*val%mod;
}
void djikstra(int s, int* dist, int* cnt)
{
	priority_queue<pii,vii,greater<pii>> pq;
	pq.push(mp(0,s));
	for(int i=0;i<=n;i++)
	{
		dist[i]=mx;
		visited[i]=false;
	}
	cnt[s]=1;
	dist[s]=0;
	while(!pq.empty())
	{
		int u=pq.top().se;
		int d=pq.top().fi;
		pq.pop();
		if(visited[u] or d!=dist[u])
			continue;
		visited[u]=true;
		for(auto v:G[u])
		{
			if(!visited[v.fi] and dist[v.fi]>dist[u]+v.se)
			{
				cnt[v.fi]=cnt[u];
				dist[v.fi]=dist[u]+v.se;
				pq.push(mp(dist[v.fi],v.fi));
			}
			else if(dist[v.fi]==dist[u]+v.se)
			{
				cnt[v.fi]+=cnt[u];
				cnt[v.fi]%=mod;
			}
		}
	}
}
signed main()
{
//    freopen(file".inp","r",stdin);
//    freopen(file".out","w",stdout);
//    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>n>>m>>ss>>t;
    for(int i=0,u,v,w;i<m;i++)
	{
		cin>>u>>v>>w;
		G[u].eb(v,w);
		G[v].eb(u,w);
	}
//	cout<<"here";
	djikstra(ss,dist1,cnt1);
	djikstra(t,dist2,cnt2);
//	cout<<"here";
//	cout<<cnt1[t]<<" "<<cnt2[s]<<endl;
	int Dist=dist1[t], ans=cnt1[t]*cnt2[ss]%mod;
	if(Dist%2==0)
		for(int i=1;i<=n;i++)
			if(dist1[i]*2==Dist and dist1[i]+dist2[i]==Dist)
				ans = (ans-Pow(cnt1[i]*cnt2[i]%mod)%mod+mod)%mod;
	for(int u=1;u<=n;u++)
		for(auto v:G[u])
			if(dist1[u]+dist2[v.fi]+v.se==Dist and dist1[u]*2<Dist and dist2[v.fi]*2<Dist)
//				cout<<u<<" "<<v.fi<<endl;
				ans = (ans-Pow(cnt1[u]*cnt2[v.fi]%mod)%mod+mod)%mod;
	//while(ans<0) ans+=mod;
	cout<<ans%mod;
}


Measured memory_bytes: 21920
# sys.stdin.readline()
import sys
input = sys.stdin.readline

h, w = map(int, input().split())
M = [list(input()) for _ in range(h)]#[[x,x,x], [y,y,y], ..., [z,z,z]]

#wh = '.'
bk = '#'

for i in range(h):
    flg = True
    for j in range(w):
        if M[i][j] == bk:
            flg = False
            break
    if flg:
        for j in range(w):
            M[i][j] = ''

for j in range(w):
    flg = True
    for i in range(h):
        if M[i][j] == bk:
            flg = False
            break
    if flg:
        for i in range(h):
            M[i][j] = ''     

for i in range(h):
    res = ''
    for j in range(w):
        if M[i][j] != '':
            res += M[i][j]
    if res != '':
        print(res)

Measured memory_bytes: 3188
#include<iostream>
#define MAX_K 110
using namespace std;

int main(){
    int n, k;
    while(cin >>n >>k){
        if(n == 0 && k == 0) break;
        int dx[MAX_K] = {0}, max[MAX_K] = {0};
        for(int i = 0; i < k; i++){
            cin >>max[i];
        }
        for(int i = 0; i < n; i++){
            for(int j = 0; j < k; j++){
                int tmp;
                cin >>tmp;
                dx[j] += tmp;
            }
        }
        bool flag = false;
        for(int i = 0; i < k; i++){
            if(dx[i] > max[i]){
                flag = true;
                break;
            }
        }
        if(flag) cout <<"No";
        else cout <<"Yes";
        cout <<endl;
    }
    return 0;
}

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

using ll = long long;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}

int main() {
  int A, B, C, D; cin >> A >> B >> C >> D;

  string str = "No";
  while(true) {
    C = C - B;
    if(C <= 0) {
      str = "Yes";
      break;
    }

    A = A - D;
    if(A <= 0) {
      str = "No";
      break;
    }
  }

  cout << str << endl;
}

Measured memory_bytes: 3632
from random import random, randint

K = 26
d = int(input())

c = list(map(int, input().split()))

s = []
for i in range(d):
    q = list(map(int, input().split()))
    s.append(q)

ans = []
last = [-1 for i in range(K)]
for i in range(d):
    x = []
    for j in range(K):
        x.append(pow(s[i][j] * c[j] * (i - last[j]), 3))

    sum = 0
    for j in range(K):
        sum += x[j]

    for j in range(K):
        x[j] /= sum

    prob = random()
    cur = 0
    for j in range(K):
        if cur + x[j] <= prob:
            cur += x[j]
            continue
        ans.append(j)
        last[j] = i
        break


def get_result():
    res = 0
    last = [-1 for i in range(K)]
    for i in range(d):
        res += s[i][ans[i]]
        last[ans[i]] = i
        for j in range(K):
            res -= c[j] * (i - last[j])
    return res


# print(get_result())
for qq in range(100):
    i = randint(0, d - 1)
    nw = randint(0, K - 1)

    old = ans[i]
    old_res = get_result()

    ans[i] = nw
    res = get_result()

    if res < old_res:
        ans[i] = old

    # print(get_result())

for u in ans:
    print(u + 1)

Measured memory_bytes: 9668
#include<iostream>
#include<string>
using namespace std;
int g[60][60]; 
int val[60][60];
int main(){
	
	
	
	int h,w;
	cin>>h>>w;
	string sx;
	getline(cin,sx);
	for(int a=1;a<=h;++a){
	
		string s;
		getline(cin,s);
		for(int b=1;b<=w;++b){
			
			if(s[b-1]=='.'){
				g[a][b]=1;
			}else g[a][b]=2;
		}
		
	}
	for(int a=1;a<=h;++a){
		for(int b=1;b<=w;++b){
			if(g[a][b]==2){
				
				val[a+1][b+1]++;
				val[a-1][b+1]++;
				val[a+1][b-1]++;
				val[a-1][b-1]++;
				val[a+1][b]++;
				val[a][b+1]++;
				val[a-1][b]++;
				val[a][b-1]++;
				
			}
		}
	}
	for(int a=1;a<=h;++a){
		for(int b=1;b<=w;++b){
		if(g[a][b]==2)cout<<"#";
		else cout<<val[a][b];
		
		}
		if(a!=h)cout<<endl;
		}
		
		return 0;
}

Measured memory_bytes: 256
/*
    Problem 14
    https://atcoder.jp/contests/s8pc-4/tasks/s8pc_4_b
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    ll ans = LINF;
    // 一番前は絶対見えるので
    // 2番目以降からK - 1個選んで見えるようにする
    for (int b = 0; b < (1 << (n - 1)); b++) {
        if (__builtin_popcount(b) != k - 1) continue;
        ll maxH = a[0], sum = 0;
        for (int i = 1; i < n; i++) {
            if ((b >> (i - 1)) & 1) {
                if (maxH >= a[i]) {  // 低ければmaxH+1まで増築
                    maxH += 1;
                    sum += maxH - a[i];
                }
            }
            maxH = max(a[i], maxH);  // 高さの更新
        }
        ans = min(sum, ans);
    }
    cout << ans << '\n';
}

Measured memory_bytes: 3572
#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 <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>

using namespace std;
using ull = unsigned long long;
using ll = long long;
using lli = long long int;
using ld = long double;
using pa = pair<int,int>;
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define GRESORT(v) sort(v.begin(),v.end(),greater<int>())
#define REVERSE(v) reverse(v.begin(),v.end())
#define overlap(v) v.erase(unique(v.begin(),v.end()),v.end())
#define debug(x) cout << #x << ": " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i = (b-1); i >= a; i--)
#define rrep(i,n) RFOR(i,0,n)
#define INF 999999999
#define mins(a,b) a = min(a,b)
#define maxs(a,b) a = max(a,b)

//4??????
//int dy[]={0, 0, 1, -1};
//int dx[]={1, -1, 0, 0};

//8??????
int dy[]={0,0,1,-1,1,1,-1,-1};
int dx[]={1,-1,0,0,1,-1,1,-1};

ll mod = (ll)1e9+7;
int a,b,c,d;

void solve() {
    while(cin >> a){
        if(a == 0) break;
        int sum = 0;
        cin >> b;
        rep(j,b){
            cin >> c >> d;
            sum += d - c;
        }
        if(sum >= a) cout << "OK" << endl;
        else cout << a - sum << endl;
    }
}

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

    solve();

    return 0;
}

Measured memory_bytes: 3104
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>
#include<limits.h>
#define SIZE 200002
int main(){
    int N;
    scanf("%d",&N);
    int a[SIZE];
    int ans[SIZE];
    for(int i=0;i<N;i++)
        scanf("%d",a+i);
    //if(N%2==0){
        int all=0;
        for(int i=0;i<N;i++)
            all ^= a[i];
        for(int i=0;i<N;i++)
            ans[i] = all ^ a[i];
    //}
    /*
    else{
        for(int i=0;i<N;i++)
            ans[i] = 15 ^ a[i];
    }
    */
    for(int i=0;i<N;i++)
        printf("%d ",ans[i]);
}


Measured memory_bytes: 3968
#abc119d
import bisect

a,b,q=map(int,raw_input().split())
inf=2<<60
s=[-inf]+[int(raw_input()) for i in xrange(a)]+[inf]
t=[-inf]+[int(raw_input()) for i in xrange(b)]+[inf]
s.sort()
t.sort()
for i in xrange(q):
 x=int(raw_input())
 b=bisect.bisect(s,x)
 d=bisect.bisect(t,x)
 res=inf
 for ss in [s[b-1],s[b]]:
  for tt in [t[d-1],t[d]]:
   d1=abs(ss-x)+abs(tt-ss)
   d2=abs(tt-x)+abs(ss-tt)
   res=min(res,d1,d2)
 print res


Measured memory_bytes: 11360
import java.util.Scanner;

public class Main {

	public static void main(final String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt(), a = sc.nextInt(), b = sc.nextInt();
		boolean f = false;
		for(int i=a;i<=b;i++) {
			if (i % k == 0) {
				System.out.println("OK");
				f = true;
				break;
			}
		}
		if (!f)
		System.out.println("NG");
	}
}


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

int main() {
    string N;
    cin >> N;
    ll sum = 0;
    rep(i, N.size()) {
        int n = N[i] - '0';
        sum += n;
    }

    if (sum%9 == 0) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 3732
// https://atcoder.jp/contests/abc171/tasks/abc171_b
#include "bits/stdc++.h"
constexpr auto MAX = 10E9+1;
using namespace std;
using ll = long long;
using VI = vector<int>;

int main()
{
    int n, k; cin >> n >> k;
    VI p(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    sort(p.begin(), p.end());
    int ans = 0;
    for (int i = 0; i < k; i++) {
        ans += p[i];
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 3576
#include<iostream>
#include<bits/stdc++.h>
#include<climits>
#include<math.h>

#define forn(x,n,s) for(int i = x; i < n; i += s )
#define forr(x,n,s) for(int i = x; i>=n; i -= s)
#define PI 3.14159265358979323846264338327950L

using namespace std;

void go(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  #ifndef ONLINE_JUDGE
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
  #endif
} 
long long int mod = 1e9+7;

int main(){
    go(); 

    // code here
    int n,m;cin>>n>>m;
    long long height[n],mh[n];
    forn(0,n,1){
       cin>>height[i];
       mh[i] = 0;
    }
    forn(0,m,1){
        int a,b;cin>>a>>b;
        mh[a-1] = max(mh[a-1],height[b-1]);
        mh[b-1] = max(mh[b-1],height[a-1]);
    }
    int cnt = 0;
    forn(0,n,1){
        cnt += (height[i]>mh[i]);
    }
    cout<<cnt;
}





Measured memory_bytes: 5192
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
	int N;
	string S;
	int ans=99999999;
	cin >> N >> S;
	vector<int> b(N+1,0),w(N+1,0);
	for (int i = 1; i < N+1; i++){
		if (S[i-1] == '#'){
			b[i] = b[i - 1] + 1;
			w[i] = w[i - 1];
		}
		else {
			w[i] = w[i - 1] + 1;
			b[i] = b[i - 1];
		}

	}
	
	for (int i = 0; i < N + 1; i++){
		int L = b[i] - b[0];
		int R = w[N] - w[i];
		ans = min(ans, L + R);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2180
n=int(input())
if n==3:
  print(2,5,63)
elif n==4:
  print(2,5,20,63)
elif n==5:
  print(2,5,20,30,63)
else:
  l=set()
  cnt=0
  e=0
  for i in range(2,30001):
    if i%2==0 or i%3==0:
      l.add(i)
      cnt+=1
      if cnt==n:
        m=sum(l)
        if m%6==2:
          l.discard(8)
          l.add((i//6+1)*6)
        elif m%6==3:
          l.discard(9)
          l.add((i//6+1)*6)
        elif m%6==5:
          l.discard(8)
          l.add((i+3)//6*6+3)
        break
  print(' '.join(map(str,l)))

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

int main(void){
    
    int n; cin >> n;
    
    vector <int> number (n);
    
    for(int i = 0;i < n; i++){
        cin >> number[i];
        
        //cout << number[i] << endl;
    }
    
    int count = 0;
    
    for(int s = 0; s < (n - 2); s++){
        
        if(number[s] < number[s + 1] && number[s + 1] < number[s + 2]){
            
            count = count + 1;
            
            //cout << count << endl;
            
        }else if(number[s] > number[s + 1] && number[s + 1] > number[s + 2]){
            
             count = count + 1;
            
            
        }else{
            //cout << count << endl;
        }
        
        
        
    }
    
    cout << count << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

int main(){
	vector<int> h;
	for(int i=0; i<10; ++i){
		int input;
		scanf("%d", &input);

		h.push_back (input);	
	}

	std::sort(h.begin(), h.end(),std::greater<int>());

	for(int i=0; i<3; ++i) printf("%d\n", h[i]);

	return 0;
}

Measured memory_bytes: 2652
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define PI acos(-1)
#define sz 18500000
#define RUN_FAST ios::sync_with_stdio(false);
using namespace std;

int main()
{
    RUN_FAST; cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    if (n!=m) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}


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

int main()
{
    int n;
    cin>>n;
    vector<int>A(n,0);

    for(int i=0;i<n-1;i++)
    {
       int a;
       cin>>a;
       a--;
       A.at(a)++;
    }

    for(int a:A)
    {
      cout<<a<<endl;
    }
  
   return 0;
}


Measured memory_bytes: 3948