akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>	
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
#define INF 2000000000
#define MOD 1000000007
#define sym cout<<"---------"<<endl;
#define ll long long
#define mk make_pair
#define en endl
#define RE return 0
#define int ll
#define P pair<int,int>
using namespace std;
int dx[5]={1,0,-1,0,0},dy[5]={0,1,0,-1,0};
int gcd(int a,int b){if(a%b==0){return b;}else return gcd(b,a%b);}
int lcm(int a,int b){if(a==0){return b;} return a/gcd(a,b)*b;}

int m,n; 
P hako[505];
int sum[20005];
int dp[20005];

signed main(){
	vector<int> man;
	cin>>m>>n;
	for(int i=0; i<m; i++){
		int a; cin>>a; 
		man.push_back(a);
	}
	sort(man.begin(), man.end(),greater<int>());
	for(int i=0; i<m; i++) sum[i+1]=sum[i]+man[i];
	for(int i=0; i<n; i++){
		cin>>hako[i].first>>hako[i].second;
	}
	for(int i=0; i<=20002; i++) dp[i]=INF;
	dp[0]=0;
	for(int i=0; i<n; i++){
		for(int j=20000; j>=hako[i].first; j--){
			dp[j]=min(dp[j], dp[j-hako[i].first]+hako[i].second);
		}
	}
	for(int i=0; i<=20000; i++){
		for(int j=i; j<=20000; j++){
			dp[i]=min(dp[i],dp[j]);
		}
	}
	int ans=0;
	for(int i=1; i<=m; i++){
		ans=max(ans,sum[i]-dp[i]);
	}
	cout<<ans<<en;
}
	
	


Measured memory_bytes: 3496
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#define vi vector<int>
#define vb vector<bool>
#define lli long long int
#define vvi vector<vector<int>>
#define loop(n) for (int i = 0; i < n; i++)
using namespace std;

auto SpeedUp = []() {
    std::ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    return 0;
}();

int arr[100005][3], dp[100005][3];
int n, k;

int maxTaro(int row, int lastIdx, int n)
{
    if (row == n)
        return 0;
    if (dp[row][lastIdx] != 0)
        return dp[row][lastIdx];
    int myans = -1;
    for (int i = 0; i < 3; i++)
        if (row == 0 || i != lastIdx)
            myans = max(myans, maxTaro(row + 1, i, n) + arr[row][i]);

    return dp[row][lastIdx] = myans;
}

int solve()
{
    memset(arr, 0, sizeof(arr));
    memset(dp, 0, sizeof(dp));
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> arr[i][0] >> arr[i][1] >> arr[i][2];

    return maxTaro(0, 0, n);
    // for(int ele :dp)
    //     cout << ele << " ";
    // return dp[0];
}

int main()
{
    cout << solve() << endl;
    return 0;
}

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

typedef long long ll;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	ll a[3] = {0}, b[3] = {0}, c[3][3] = {0};
  bool result = true;

  rep(i, 3) {
    rep(j, 3) {
      cin >> c[i][j];
    }
  }
  rep(i, 3) b[i] = c[0][i];
  a[1] = c[1][0] - b[0];
  a[2] = c[2][0] - b[0];
  rep(i, 3) {
    rep(j, 3) {
      result = (c[i][j] == a[i] + b[j]);
      if (!result) break;
    }
    if (!result) break;
  }
  if (result) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

int main()
{
  // int a,b,c,d,e; cin>>a>>b>>c>>d>>e;
  rep(i,5) {
    int x; cin >> x;
    if(x==0){
      cout << i+1 << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1000000007;
const double eps = 1e-9;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

int main () {
  int D, G; cin >> D >> G;
  vi p(D), c(D); rep(i,D) cin >> p[i] >> c[i];

  int ans = 1e9;
  rep(mask,1<<D) {
    int s = 0, num = 0, rest_max = -1;
    rep(i,D) {
      if (mask >> i & 1) {
        s += 100*(i+1)*p[i] + c[i];
        num += p[i];
      }
      else {
        rest_max = i;
      }
    }
    if (s < G) {
      int s1 = 100*(rest_max + 1);
      int need = (G - s + s1 - 1)/s1;
      if (need >= p[rest_max]) {
        continue;
      }
      num += need;
    }
    ans = min(ans, num);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<utility>//pair
#include<list>
#include<vector>//可変長配列
#include <assert.h>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define all(a) (a).begin(),(a).end()
#define mp make_pair
#define pb push_back
#define ll __int64
#define __int64 long long
#define P pair<int,int>
#define PP pair<ll,ll>
#define F first
#define S second
int dx[8] = { 1,0,-1,0,1,-1,-1,1 };
int dy[8] = { 0,1,0,-1,1,1,-1,-1 };

int n, m;
int h[111111];
bool t[111111];
int main() {
	cin >> n >> m;
	rep(i, n)cin >> h[i];
	rep(i, n)t[i] = 1;

	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		if (h[a] > h[b])t[b] = 0;
		else if (h[a] < h[b])t[a] = 0;
		else t[a] = t[b] = 0;
	}

	int cnt = 0;
	rep(i, n)if (t[i])cnt++;
	cout << cnt << endl;

	return 0;
}


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

#define MAXN 1000005

using namespace std;

int n;
char s[MAXN], t[MAXN];
int ans, head = 1, tail, q[MAXN];

int main() {
	scanf("%d", &n);
	scanf("%s%s", s + 1, t + 1);
	if (!strcmp(s + 1, t + 1)) {
		puts("0");
		return 0;
	}
	for (int i = n, j = n; i >= 1; --i) {
		if (t[i] == t[i - 1])
			continue;
		j = min(j, i);
		while (j && s[j] != t[i])
			--j;
		if (!j) {
			puts("-1");
			return 0;
		}
		while (head <= tail && q[head] - (tail - head + 1) + 1 > i)
			++head;
		q[++tail] = j; 
		if (i != j)
			ans = max(ans, tail - head + 1);
	}
	printf("%d\n", ans + 1);
}

Measured memory_bytes: 6144
def main():
    n, m = map(int, input().split())
    h = list(map(int, input().split()))
    a, b = [], []
    for _ in range(m):
        i, j = map(int, input().split())
        a.append(i)
        b.append(j)
    ans = solve(n, m, h, a, b)
    print(ans)


def solve(n, m, h, a, b):
    isgood = [True for _ in range(n)]
    for i, j in zip(a, b):
        i, j = i - 1, j - 1
        if h[i] > h[j]:
            isgood[j] = False
        elif h[i] < h[j]:
            isgood[i] = False
        else:
            isgood[i] = False
            isgood[j] = False
    ans = sum([1 for i in isgood if i])
    return ans


if __name__ == '__main__':
    main()

Measured memory_bytes: 22196
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_148
{
    class C
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            long[] ab = ReadLongs();
            WriteLine(LCM(ab[0], ab[1]));
        }

        static long GCD(long a, long b)
        {
            if (b > a)
            {
                long temp = b;
                b = a;
                a = temp;
            }
            long c = b;
            do
            {
                c = a % b;
                a = b;
                b = c;
            } while (c > 0);
            return a;
        }

        static long LCM(long a, long b)
        {
            long c = GCD(a, b);
            return a * b / c;
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11220
N, M = map(int, input().split())
A = list(map(int, input().split()))
m = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
l = min([m[a] for a in A])
dp = [0] * (N + 1)

for i in range(N):
    for a in A:
        if (i > 0) and dp[i] == 0:
            break
        if (i + m[a] <= N):
            dp[i + m[a]] = max(dp[i + m[a]], dp[i] * 10 + a)
print(dp[-1])

Measured memory_bytes: 14692
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  ll D,G;
  cin >> D >> G;
  vector<ll> P(D);
  vector<ll> c(D);
  rep(i,D) cin >> P[i] >> c[i];
  vector<vector<ll>> sum(D,vector<ll>(2));
  rep(i,D){
    sum[i][0] = (i+1)*100*(P[i]-1);
    sum[i][1] = (i+1)*100*P[i] + c[i];
  }
  int ans = 1e9;
  for(int i=0;i<=pow(2,D+1)-1;i++){
    int preans=0;
    ll score = 0;
    for(int j=0;j<D;j++){
      if((i>>j)%2==1){
        score += sum[j][1];
        preans += P[j];
      }
    }
    if(score>=G){}
    else{
      for(int j=D-1;j>=0;j--){
        if((i>>j)%2==0){
          for(int k=0;k<P[j]-1;k++){
            score += (j+1)*100;
            preans++;
            if(score>=G){
              j=-1;
              break;
            }
          }
        }
      }
    }

    if(score>=G) ans = min(ans,preans);
  }

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


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {

	x := nextInt()
	fh, mod := x/500, x%500
	h := fh * 1000
	h += (mod / 5) * 5

	fmt.Print(h)
}

func nextInt() int {
	i, _ := strconv.Atoi(nextText())
	return i
}

func nextText() string {
	sc.Scan()
	return sc.Text()
}


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

int main(){
  ll L,R;
  cin>>L>>R;
  int modl = L%2019;
  int modr = R%2019;
  if(L/2019!=R/2019){
    cout<<0<<endl;
    return 0;
  }
  else{
    int ans = 100000;
    for(int i=modl;i<=modr;++i){
      for(int j=modl;j<=modr;++j){
        if(i!=j)ans = min(ans,(i*j)%2019);
      }
    }
    cout<<ans<<endl;
  }
}

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

int main() {
  int s , h , j , i ;
  cin >> s ;
  h = s / 100 ;
  s = s % 100 ;
  j = s / 10 ;
  s = s % 10 ;
  i = s ;
  cout << h + j + i << endl ;
}

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

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

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

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

//ユークリッドの互除法
//最大公約数
ll gcd(ll x, ll y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}

//最小公倍数
ll lcm(ll x, ll y){
	ll g = gcd(x,y);
	return x/g*y;
}

int main() {
    int n;cin>>n;
    vector<int> a(n),b(n);
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    ll need = 0;
    rep(i,n){
        if(b[i] < a[i])need+=a[i]-b[i];
    }
    rep(i,n){
        if(a[i] < b[i]){
            need -= (b[i]-a[i])/2;
        }
    }
    
    cout << (need <= 0? "Yes": "No") << endl;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s1,s2,s3;
  cin>>s1>>s2>>s3;
  
  char D,B,C;
  
D=(s1.at(0)-'a')+'A';
  B=(s2.at(0)-'a')+'A';
  C=(s3.at(0)-'a')+'A';
  
  cout<<D<<B<<C;
}


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

int main(void) {

  char s[101];
  scanf("%s", s);
  long k;
  scanf("%ld", &k);
  int head1 = 0;
  char infinity = '0';
  for (int i = 0; i < strlen(s); i++) {
    if (s[i] == '1') {
      head1++;
    } else {
      infinity = s[i];
      break;
    }
  }
  if (head1 >= k) {
    printf("1\n");
  } else {
    printf("%c\n", infinity);
  }

  return 0;
}

Measured memory_bytes: 128
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, *A = map(int, read().split())

def f(A):
    low, high = 2, 2
    for x in A[::-1]:
        low += (-low) % x
        high -= (high) % x
        if low > high:
            print(-1)
            return
        low, high = low, high+(x-1)
    print(low, high)

f(A)

Measured memory_bytes: 18836
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n,sum1=0,sum2=0,ans1=0,ans2=0,a;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a;
        sum1+=a;
        if(i%2==0 and sum1<=0){
            ans1+=abs(sum1)+1;
            sum1=1;
        }
        if(i%2==1 and sum1>=0){
            ans1+=abs(sum1)+1;
            sum1=-1;
        }
        sum2+=a;
        if(i%2==0 and sum2>=0){
            ans2+=abs(sum2)+1;            
            sum2=-1;
        }
        if(i%2==1 and sum2<=0){
            ans2+=abs(sum2)+1;
            sum2=1;
        }
    }
    cout << min(ans1,ans2) << endl;
    return 0;
}


Measured memory_bytes: 256
// skip until line 65
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <istream>
#include <iterator>
#include <sstream>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

#define BR "\n"
#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a, b) ((((a) % (b) ) + (b)) % (b))
#define FEACH(it, cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it, cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define MAX(V, T) V=max(V,T)
#define MIN(V, T) V=min(V,T)

#define DumpArray(cont, from, to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i]<<")";} cout<<endl;

/*
 * ***_bound(6)
 * 5 6 6 6 6 6 7 7 7
 *   ^lower    ^upper
 * void reverse(c.begin(), c.end())
 *
 * graph
 * seg tree
 * dp
 * brute force
 */
struct Comparator{
    int operator()(int l, int r) const {
        return r<l;
    }
};
struct Vec;
//set<int, Comparator> S;

// solution below
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
int main() {

    cout.precision(10);
    cout<<fixed;
    string S;
    cin >> S;
    if (S[2]==S[3]&&S[4]==S[5])
        cout <<"Yes"<<endl;
    else
        cout << "No"<<endl;
}

struct Vec{
    double v[2];
    string to_s(){
        return "("+to_string(v[0])+","+to_string(v[1])+")";
    }
    double& operator[](int t){
        return v[t];
    }
    Vec operator+(Vec t) {
        return {v[0]+t[0],v[1]+t[1]};
    }
    Vec& operator+=(Vec t) {
        v[0]+=t[0];v[1]+=t[1];
        return *this;
    }
    Vec operator-(Vec t) {
        return {v[0]-t[0],v[1]-t[1]};
    }
    Vec& operator-=(Vec t) {
        v[0]-=t[0];v[1]-=t[1];
        return *this;
    }
    Vec operator*(double t) {
        return {v[0]*t,v[1]*t};
    }
    Vec& operator*=(double t) {
        v[0]*=t;v[1]*=t;
        return *this;
    }
    double operator*(Vec t) {
        return v[0]*t[0]+v[1]*t[1];
    }
    Vec operator-(){
        return {-v[0],-v[1]};
    }
    static Vec Z;
};
Vec Vec::Z={0,0};


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int n,flag=0;
    cin >> n;
   long long a[n],result=1;
    for(int i=0;i<n;i++){
        cin >> a[i];
        if(a[i]==0){
            flag=2;
            break;
        }
    }
    if(flag==2){
        cout << "0\n";
        return 0;
    }
    for(int i=0;i<n;i++){
        if(a[i]<=1000000000000000000/result){
            result *= a[i];
            if(result > 1000000000000000000){
                flag=1;
                break;
            }
        }
        else{
            flag=1;
            break;
        }
    }
    if(flag==1){
        cout << "-1";
    }
    else{
        cout << result << '\n';
    }
    return 0;
}


Measured memory_bytes: 4436
k = int(input())
list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(list[k-1])

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
  
struct Node{
  int key;
  Node *right,*left,*p;
};
  
Node *NIL,*root;
  
void insert(int k){
  Node *x=root;
  Node *y=NIL;
  Node *T;
    
  T=(Node *)malloc(sizeof(Node));
  T->key=k;
  T->left=NIL;
  T->right=NIL;
    
  while(x!=NIL){
    y=x;
    if(T->key<x->key) x=x->left;
    else x=x->right;  
  }
  T->p=y;
  if(y==NIL) root=T;
  else if(T->key<y->key) y->left=T;
  else y->right=T;
}
  
void in(Node *T){
  if(T!=NIL){
    in(T->left);
    cout<<' '<<T->key;
    in(T->right);
  }
} 
 
void pre(Node *T){
  if(T!=NIL){
    cout<<' '<<T->key;
    pre(T->left);
    pre(T->right);
  }
}
  
int main(){
  int m,k;
  string str;
  cin>>m;
  for(int i=0;i<m;i++){
    cin>>str;
    if(str[0]=='i'){
      cin>>k;
      insert(k);
    }
    else {
      in(root);
      cout<<endl;
      pre(root);
      cout<<endl;
    }
  }
  return 0;
}



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

const string YES = "Yes";
const string NO = "No";

void solve(long long N){
    double result = (double)N*2*PI;
    printf("%8.20f\n", result);
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 3828
#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[])
{
    for (;;) {
        int n, x;
        int ans = 0;

        scanf("%d %d\n", &n, &x);
        if ((n == 0) && (x == 0)) {
            break;
        }

        ans = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = i + 1; j <= n; j++) {
                int k = x - i - j;
                if ((k > j) && (k <= n)) {
                    ans++;
                }
            }
        }
        printf("%d\n", ans);
   }

    return 0;
}


Measured memory_bytes: 2040
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned int *A, *B;
  int C[VMAX+1];
  int n, i, j;
  int k = 0;

  scanf("%d", &n);

  A = malloc(sizeof(int)*n+1);
  B = malloc(sizeof(int)*n+1);

  for(i = 1;i < n + 1; i++){
     scanf("%d",&A[i]);
     if(k < A[i]) k = A[i];
   }
  for(i =0;i < k;i++) C[i] = 0;
  for(j =1;j <= n; j++) C[A[j]]++;
  for(i = 1;i <= k;i++) C[i] = C[i] + C[i-1];
  for(j =n;j >=1; j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
  for(i = 1;i <= n; i++){
     printf("%d",B[i]);
     if(i != n) printf(" ");
   }
  printf("\n");

  return 0;
}



Measured memory_bytes: 17388
n = gets.to_i
a = gets.split(' ').map{ |v| v.to_i }

max = a.max
#p max
count = 0

is_lcm = false
lcm = 0
while !is_lcm
  flag = true
  a.each { |v|
    if (max * count) % v != 0
      flag = false
      break
    end
  }

  if flag
    is_lcm = true
    lcm = max * count
  end

  #p max * count

  count += 1
end

#p lcm

f = 0
a.each { |v|
  f += (lcm - 1) % v
  #p (lcm -1) % v
}

puts f.to_i

Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
int main()
{int n;
cin>>n;
int y;
int sum=0;
int temp=n;
while(n>0)
{
y=n%10;
sum=sum+y;
n=n/10;
}
if(temp%sum==0)
{
cout<<"Yes"<<endl;
}
else
{
cout<<"No"<<endl;
}
return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.next());
        int[] a = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            a[i] = Integer.parseInt(scan.next());
        }
        scan.close();

        int range = 2 * 100000;

        // -rangeが起点
        int[] diff = new int[range * 10];
        int[] sum = new int[range * 10];
        for (int i = 1; i <= n; i++) {
            if (a[i] > 2 * 100000) {
                continue;
            }
            diff[i - a[i] + range]++;
            sum[i + a[i] + range]++;
        }

        long ans = 0;
        for (int i = 1; i <= n; i++) {
            if (a[i] > 2 * 100000) {
                continue;
            }
            ans += sum[i - a[i] + range];
        }

        System.out.println(ans);
    }
}


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

using namespace std;


#define PI 3.14159265



main(){

	int a, b, x; cin >> a >> b >> x;




	if(a * a * b  / 2 > x){
		double d = 2.0 * x / (a * b);

		cout << fixed << setprecision(8) << atan(1.0 * b / d) * 180 / PI << endl;


	}else{

		double d = 2.0 * x / (a * a) - b;


		double y = (d * a) / (b - d);


		cout << fixed << setprecision(8) << atan(1.0 * b / (a + y)) * 180 / PI << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <set>

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

using namespace std;
typedef long long ll;

string same(string s,string t) {
    string ret = s;
    rep(i,s.size()) {
        if(s[i] == t[i]) continue;
        else ret[i] = 'X';
    }

    return ret;
}

string Xor(string s,string t) {
    string ret = s;
    rep(i,s.size()) {
        if(s[i] == t[i]) ret[i] = '0';
        else ret[i] = '1';
    }
    
    return ret;
}

int main() {

    int n,m,q;
    while(cin >> n >> m >> q) {
        if(n == 0 && m == 0 && q == 0) break;

        vector<string> s(q),b(q);
        rep(i,q) {
            cin >> s[i] >> b[i];
        }

        string ori = "";
        rep(i,n) ori += "0";

        vector<string> ins;
        string pre = ori;
        rep(i,q) {
            pre = Xor(pre,s[i]);
            ins.push_back(pre);
        }

        vector<int> v(n);
        rep(i,n) v[i] = i;

        stringstream ans;

        rep(i,m) {
            vector<string> a0,b1;

            rep(j,q) {
                if(b[j][i] == '0') {
                    a0.push_back(ins[j]);
                }
                else {
                    b1.push_back(ins[j]);
                }
            }

            string res;
            if(a0.size() == 0)  res = ori;
            else res = a0[0];

            rep(j,a0.size()) {
                res = same(res,a0[j]);
            }

            string res2;
            if(b1.size() == 0) res2 = ori;
            else res2 = b1[0];

            rep(j,b1.size()) {
                res2 = same(res2,b1[j]);
            }

            set<int> st;
            rep(j,n) {
                if(res[j] == 'X' || res2[j] == 'X') continue;
                if(res[j] == '0' && res2[j] == '1') {
                    st.insert(j);
                }
            }

            if(st.size() == 1) {
                set<int>::iterator ite = st.begin();
                if(0 <= *ite && *ite <= 9) {
                    ans << *ite;
                }
                else {
                    int id = *ite - 10;
                    ans << char('A' + id);
                }
    
                v.erase(remove(v.begin(),v.end(),*ite),v.end());
            }
            else ans << "?";

        }
        
        string res = ans.str();
        if(v.size() == 1) {
            rep(i,res.size()) {
                if(res[i] == '?') {
                    if(0 <= v[0] && v[0] <= 9) {
                        cout << v[0];
                    }
                    else {
                        int id = v[0] - 10;
                        cout << char('A' + id);
                    }
                }
                else cout << res[i];
            }
            cout << endl;
        }
        else cout << res << endl;


    }

    return 0;
}

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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PI acos(-1.0)
#define sq(n) ((n)*(n))

using namespace std;
using ll = long long;
const int INF = 2e9;

#define N 100005
int a[N][3], dp[N][3];

int main() {
    FAST;

    int n, i, j, k, ans;
    cin >> n;

    for (i = 0; i < n; ++i) {
        for (j = 0; j < 3; ++j) cin >> a[i][j];
    }

    for (i = 0; i < 3; ++i) dp[0][i] = a[0][i];

    for (i = 1; i < n; ++i) {
        for (j = 0; j < 3; ++j) {
            for (k = 0; k < 3; ++k) {
                if (j == k) continue;
                dp[i][k] = max(dp[i][k], a[i][k]+dp[i-1][j]);
            }
        }
    }

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

    cout << ans << "\n";

    return 0;
}


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

sugar = []
for i in range(f):
    for j in range(f):
        y = i*c + j*d
        if y <= f:
            sugar.append(y)

water = []
for i in range(0, f//100+1):
    for j in range(0, f//100+1):
        x = i*a*100 + j*b*100
        if x <= f:
            water.append(x)
max_concentration = 0
ans1, ans2 = 0, 0
for x in water:
    for y in sugar:
        if x == 0 and y == 0:
            continue
        elif e * (x // 100) < y:
            continue
        elif x + y > f:
            continue
        else:
            concentration = (100 * y) / (x+y)
            if max_concentration <= concentration:
                max_concentration = concentration
                ans1 = x+y
                ans2 = y
print("{} {}".format(ans1, ans2))


Measured memory_bytes: 12440
//
// Created by wulang on 10/1/16.
//

#include <iostream>
#include <algorithm>
#include <list>
using namespace std;

void solve();
int main(int argc, char *argv[]) {
    if (argc == 2) {
        freopen(argv[1], "r", stdin);
    } else if (argc == 3) {
        freopen(argv[1], "r", stdin);
        freopen(argv[2], "w", stdout);
    }
    solve();
    return 0;
}

const int N=200000+10;
int n, a[N], pre[N], nxt[N];
void solve(){
    while(cin>>n){
        for(int i=1;i<=n;i++) cin>>a[i];
        a[0]=a[n+1]=0;
        for(int i=1;i<=n;i++) {
            int k=i-1;
            while(a[k]>a[i]) k=pre[k];
            pre[i]=k;
        }

        for(int i=n;i>=1;i--) {
            int k=i+1;
            while(a[k]>a[i]) k=nxt[k];
            nxt[i]=k;
        }

        long long ans=0;
        for(int i=1;i<=n;i++) ans+= (long long)(i-pre[i])*(nxt[i]-i)*a[i];
        cout<<ans<<endl;
    }

}




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

using i64 = int64_t;

string dp[10004]={};

int match[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

string compare(string s1, string s2){
    if(s1.size() > s2.size())return s1;
    else if(s1.size() < s2.size())return s2;
    for(int i=0;i<s1.size();++i){
        if(s1[i] > s2[i])return s1;
        else if(s1[i] < s2[i])return s2;
    }
    return s1;
}

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> v;
    for(int i=0;i<m;++i){
        int a;
        cin >> a;
        v.push_back(a);
    }

    for(auto e: v){
        if(n >= match[e]){
            dp[n-match[e]] = max(dp[n-match[e]], to_string(e));
        }
    }
    for(int i=n;i>0;--i){
        if(dp[i] == "")continue;
        for(auto e: v){
            if(i < match[e])continue;
            string s = dp[i];
            if(dp[i][0] > e+'0'){
                s.push_back(e+'0');
            }else{
                s.insert(0, 1, e+'0');
            }
            dp[i-match[e]] = compare(dp[i-match[e]], s);
        }
    }

    cout << dp[0] << endl;

    return 0;
}


Measured memory_bytes: 28416
#include<cstdio>
using namespace std;
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
int a[maxn], sum[maxn], n, nsum, tot, ans;
int step[maxn], inv[maxn], side_sum;
void Add(int &x, const int &a) {
	x += a;
	if(x >= mod) x -= mod;
}
int mul(const int &a, const int &b) {
	return 1ll * a * b % mod;
}
int dec(const int &a, const int &b) {
	return a - b < 0 ? a - b + mod : a - b;
}
int fpow(int a, int b) {
	int ans = 1;
	while(b) {
		if(b & 1) ans = mul(ans, a);
		b >>= 1, a = mul(a, a);
	}
	return ans;
}
void pre(int n) {
	step[0] = inv[0] = 1;
	for(register int i = 1; i <= n; ++i)
		step[i] = mul(step[i - 1], i);
	inv[n] = fpow(step[n], mod - 2);
	for(register int i = n - 1; i >= 1; --i)
		inv[i] = mul(inv[i + 1], (i + 1));
}
int C(int n, int m) {
	return mul(mul(step[n], inv[n - m]), inv[m]);
}
int main() {
	scanf("%d", &n), pre(n + 3);
	for(register int i = 1; i <= n; ++i)
		scanf("%d", &a[i]), sum[i] = sum[i - 1], Add(sum[i], a[i]);
	for(register int i = 1; i < n; ++i) {
		Add(nsum, dec(sum[n - i], sum[i]));
		Add(side_sum, a[n - i + 1]);
		Add(side_sum, a[i]);
		Add(ans, mul(mul(side_sum, step[i]), mul(C(n, i + 1), step[n - i - 1])));
		Add(ans, mul(mul(nsum, mul(2, step[i])), mul(C(n, i + 2), step[n - i - 2])));
	}
	Add(ans, mul(sum[n], step[n]));
	printf("%d", ans);
	return 0;
} 

Measured memory_bytes: 1664
#include <iostream>
#include <cstdio>
using namespace std;
int Gcd(int a,int b){
    int r=-1;
    int temp;
    if(a<b){
        temp = a;
        a = b;
        b = temp;
    }
    while(r!=0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}

int main(){
    int a,b;
    int gcd;


    while(cin>>a>>b){
        gcd = Gcd(a,b);
        a=a/gcd;
        b=b/gcd;

        printf("%d %d\n",gcd,gcd*a*b);
    }

    return 0;
}

Measured memory_bytes: 1144
#include <iostream>
#include <vector>
#include <limits.h>
using namespace std;
int main()
{
	int n, k, p, m;
	bool isPlus = true;
	while (cin >> n){
		if (0 == n) break;
		vector<int> A(n, 0);
		m = INT_MIN;
		p = 0;
		for (int i = 0; i < n; ++i){
			cin >> k;
			if (m < k) m = k;
			if (0 == i){
				A[p] = k;
				isPlus = (k > 0);
			}
			else {
				if (isPlus == (k > 0)){
					A[p] += k;
				}else{
					++p;
					A[p] = k;
					isPlus = !isPlus;
				}
			}
		}
		int sum = 0;
		for (int i = 0; i <= p; ++i){
			sum += A[i];
			if (sum > m) m = sum;
			if (sum < 0) sum = 0;
		}
		cout << m << "\n";
	}
	return 0;
}

Measured memory_bytes: 1204
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>

#include <numeric>
#include <memory>
#include <cassert>

#include <map>
#include <vector>
#include <queue>


using namespace std;

typedef long long LL;

float C, T, best;
int ans, n;

float temp(float x) {
    return T - x * 0.006f;
}

int main() {
    
    best = 1e9f;
    cin >> n >> T >> C;

    for (int i = 1; i <= n; ++i) {
        float k; cin >> k;
        if (abs(temp(k) - C) < best) ans = i, best = abs(temp(k) - C);
    }
    cout<< ans << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
#define modbig (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  string s;
  cin>>s;
  int l=s.length(),block=0;
  rep(i,l-1){
    if(s[i]!=s[i+1])
      block++;
  }
  cout<<block;
}

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

struct edge{
  int to;
  int cost;
};

using P = pair<int,int>;

const int MAX_N = 1e3*2;
const int INF = 1e9;
vector<edge> G[MAX_N];
vector<int> dist(MAX_N);

void dijkstra(int s, int n){
  priority_queue<P,vector<P>,greater<P>> PQ;
  for(int i=0; i<n; i++){
    dist[i] = INF;
  }
  dist[s] = 0;
  PQ.push(P(0,s));
  
  while(PQ.size()){
    P p = PQ.top();
    PQ.pop();
    int v = p.second; //from
    if(dist[v] < p.first){ //現在わかっている距離が更新できない
      continue;
    }
    for(int i=0; i<G[v].size(); i++){
      edge e = G[v][i];
      if(dist[e.to] > dist[v] + e.cost){
        dist[e.to] = dist[v] + e.cost;
        PQ.push(P(dist[e.to], e.to));
      }
    }
  }
}

int main(){
  int N, X, Y;
  cin >> N >> X >> Y;
  X--; Y--;
  for(int i=0; i<N-1; i++){
    edge add;
    add.to = i+1;
    add.cost = 1;
    G[i].push_back(add);
    add.to = i;
    G[i+1].push_back(add);
  }
  edge add;
  add.to = Y;
  add.cost = 1;
  G[X].push_back(add);
  vector<int> ans(N);
  for(int i=0; i<N; i++){
    dijkstra(i,N);
    for(int j=i+1; j<N; j++){
      ans.at(dist[j])++;
    }
  }
  for(int i=1; i<N; i++){
    cout << ans.at(i) << endl;
  }
}
  

Measured memory_bytes: 384
using System;

class Test
{
    public static void Main()
    {
        string s = Console.ReadLine();
        string[] ss = s.Split(' ');
        
        int a = int.Parse(ss[0]);
        int b = int.Parse(ss[1]);
        int c = int.Parse(ss[2]);
        
        if(a < b && b < c)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
        
    }
}


Measured memory_bytes: 17920
import sys
mod = 10**9+7
def main():
    n,m=map(int,input().split(' '))
    if m > 0:
        aaa = set(map(int,sys.stdin))
    else:
        aaa = set()

    dp = [0] * (n+1)
    dp[0] = 1
    dp[1] = 1 if 1 not in aaa else 0
    for i in range(2,n+1):
        if i in aaa:
            continue
        dp[i] = (dp[i-1]+dp[i-2])%mod

    print(dp[n])

main()


Measured memory_bytes: 11884
def solve(string):
    n, m, *sc = map(int, string.split())
    v = [0] * n
    for s, c in zip(*[iter(sc)] * 2):
        if (v[s - 1] > 0 and v[s - 1] != c) or (n > 1 and s == 1 and c == 0):
            return "-1"
        v[s - 1] = c
    if n > 1 and v[0] == 0:
        v[0] += 1
    return "".join(map(str, v))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


Measured memory_bytes: 3064
a=input()
x = list(map(int, input().split()))
x.sort(reverse=True)
if x[-1]==0:
  print(0)
else:
  sum=1
  for i in x:
    sum*=i
    if sum>10**18:
      print(-1)
      break
  if sum<=10**18: print(sum)

Measured memory_bytes: 21616
N, W = gets.split.map &:to_i
dp = Array.new(W + 1, 0)
N.times do
  w, v = gets.split.map &:to_i
  w.upto(W) do |i|
    res = dp[W - i] + v
    dp[W - i + w] = res if res > dp[W - i + w]
  end
end
puts dp[-1]

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

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  vector<vector<int>> idx(2e5 + 1);
  vector<long long> ft(n, -1), next(n);
  for (int i = 0; i < n; ++i) {
    idx[a[i]].push_back(i);
  }
  for (int i = 1; i <= 2e5; ++i) {
    for (int j = 0; j < int(idx[i].size()) - 1; ++j) {
      next[idx[i][j]] = idx[i][j + 1];
    }
    if (!idx[i].empty()) {
      next[idx[i].back()] = idx[i].front() + n;
    }
  }
  int i = 0;
  do {
    int ni = next[i] + 1;
    ft[ni % n] = ft[i] + (ni - i);
    i = ni % n;
  } while (i != 0);
  vector<pair<long long, int>> t;
  t.emplace_back(-1, 0);
  for (int i = 0; i < n; ++i) {
    if (ft[i] != -1) {
      t.emplace_back(ft[i], i);
    }
  }
  sort(t.begin() + 1, t.end());
  long long mod = (n * k - 1) % (ft[0] + 1);
  vector<int> ans;
  for (int i = 0; i < int(t.size()) - 1; ++i) {
    if (mod < t[i + 1].first) {
      vector<bool> there(200001);
      for (long long j = t[i].second; j < t[i].second + (mod - t[i].first); ++j) {
        if (there[a[j % n]]) {
          while (!ans.empty() && ans.back() != a[j % n]) {
            there[ans.back()] = false;
            ans.pop_back();
          }
          there[ans.back()] = false;
          ans.pop_back();
        } else {
          ans.push_back(a[j % n]);
          there[a[j % n]] = true;
        }
      }
      break;
    }
  }
  for (int i : ans) {
    cout << i << ' ';
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 21872
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  ll ans = 1e18;
  rep2(i, 1, sqrt(n) + 2) {
    if(n % i) continue;
    ll now = i + n / i - 2;
    ans = min(ans, now);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<math.h>
#include<iomanip>
using namespace std;

int partition(int *A, int p, int r){
  int x = A[r];
  int i = p - 1;
  for(int j = p; j < r; j++){
    if(x >= A[j]){
      i++;
      int temp = A[j];
      A[j] = A[i];
      A[i] = temp;
    }
  }
  A[r] = A[++i];
  A[i] = x;
  return i;
}


int main(){

  int n;

  cin >> n;
  int *A = new int[n];

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

  int index = partition(A, 0, n - 1);


  for(int i = 0; i < n; i++){
    if(i == n - 1){
      if(i == index){
        cout << '[' << A[i] << ']' << endl;
      }
      else{cout << A[i] << endl;}
    }
    else{
      if(index == i){
        cout << '[' << A[i] << ']' << ' ';
      }
      else{cout << A[i] << ' ';}
    }
  }


  delete[] A;
  return 0;
}



Measured memory_bytes: 3100
#include <iostream>

int main()
{
    while(true)
    {
        int n,x;
        std::cin >> n >> x;
        
        if(n==0 && x==0)    break;
        
        int ans=0;
        for(int i=1;i<=n;i++)
            for(int j=i+1;j<=n;j++)
                for(int k=j+1;k<=n;k++)
                    if(i+j+k == x)
                        ans++;
        std::cout << ans << std::endl;
    }
}


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

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<unsigned long long int>;

int main(void) {
    Int x, a, b;
    cin >> x >> a >> b;
    x -= a;
    x -= (b * (x / b));
    cout << x << endl;
    return 0;
}


Measured memory_bytes: 3600
import math
a,b,x = map(int,input().split())
ans = 0
if (a*a*b)/2>=x :
    t = x*2/b/a/b
    ans = 90-math.degrees(math.atan(t))
elif (a*a*b)==x:
    ans = 0.0
else :
    x = (a*a*b) - x
    t = x*2/a/a
    ans = 90-math.degrees(math.atan(a/t))
print(ans)

Measured memory_bytes: 3060
unittest
{
	assert( [ "contest", "son" ].solve == 10 );
	assert( [ "contest", "programming" ].solve == -1 );
	assert( [ "contest", "sentence" ].solve == 33 );
}



import std.conv;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto s = input.front.to!( dchar[] );
	input.popFront;
	auto t = input.front.to!( dchar[] );
	
	// 現在位置から何の文字が何文字後にあるかのテーブルを作成
	auto css = new long[][]( s.length * 2 + 1, 26 );
	foreach_reverse( i, c; s ~ s )
	{
		foreach( j; 0 .. 26 )
		{
			auto ci = c - 'a';
			css[ i ][ j ] = ( j == ci ) ? 1 : css[ i + 1 ][ j ] + 1;
		}
	}
	
	// 部分列の長さを判定
	auto ans = 0L;
	foreach( c; t )
	{
		auto ci = c - 'a';
		if( s.length < css[ 0 ][ ci ] ) return -1;
		ans += css[ ans % s.length ][ ci ];
	}
	return ans;
}


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

using namespace std;

const int N = 190;

char a[N][N];
int f[N][N][N];
int nf[N][N][N];

int main() {
   int n, m;
   scanf("%d %d", &n, &m);
   for (int i = 1; i <= n; ++i) {
      scanf("%s", a[i] + 1);
   }

   for (int u = n; u > 0; --u) {
      for (int d = u; d <= n; ++d) {
         for (int l = m; l > 0; --l) {
            if (u == d || (a[u][l] == a[u + 1][l] && f[u + 1][d][l] > l)) {
               if (l + 1 <= m && a[u][l] == a[u][l + 1]) {
                  f[u][d][l] = f[u][d][l + 1];
               } else f[u][d][l] = l + 1;
            } else f[u][d][l] = l;
         }
      }
   }

   int ans = 0;
   while (f[1][n][1] <= m) {

      for (int u = n; u > 0; --u) {
         for (int d = u; d <= n; ++d) {
            for (int l = m; l > 0; --l) {
               nf[u][d][l] = f[u][d][l] <= m ? f[u][d][f[u][d][l]] : m + 1;
               if (u < d) {
                  int low = u, high = d - 1;
                  while (low <= high) {
                     int mid = (low + high) >> 1;
                     nf[u][d][l] = max(nf[u][d][l], min(f[u][mid][l], f[mid + 1][d][l]));
                     if (f[u][mid][l] > f[mid + 1][d][l]) low = mid + 1;
                     else high = mid - 1;
                   }
               }
            }
         }
      }

      for (int u = n; u > 0; --u) {
         for (int d = u; d <= n; ++d) {
            for (int l = m; l > 0; --l) {
               f[u][d][l] = nf[u][d][l];
            }
         }
      }
      ++ans;
   }

   printf("%d\n", ans);
}


Measured memory_bytes: 53376
#include <bits/stdc++.h>
#define pb push_back
#define S second
#define F first
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int,int> pii;
const int maxn = 1e5 + 10;

int32_t main(){
    int n;
    cin >> n;
    int lx = 0,ly = 0   ;
    int lt = 0;
    int x,y,t;
    for (int i = 0;i < n;i++){
        cin >> t>> x >> y  ;
        int dist = abs(x - lx) + abs(y - ly);
        int ct = t - lt;
        if (ct >= dist && ct % 2 == dist % 2){
            lt = t,ly = y,lx = x;
            continue;
        }else {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <cmath>

typedef long long ll;

using namespace std;

ll gcd(ll a, ll b)
{
    if((a%b) == 0) return b;
    else return gcd(b, a%b);
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    if(s == "SUN") cout << 7;
    if(s == "MON") cout << 6;
    if(s == "TUE") cout << 5;
    if(s == "WED") cout << 4;
    if(s == "THU") cout << 3;
    if(s == "FRI") cout << 2;
    if(s == "SAT") cout << 1;
}


Measured memory_bytes: 256
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func main() {
	sc.Split(bufio.ScanWords)
	c := [4][4]int{}
	for i := 1; i <= 3; i++ {
		for j := 1; j <= 3; j++ {
			c[i][j] = getInt()
		}
	}
	ans := true
	if c[1][1]-c[1][2] != c[2][1]-c[2][2] {
		ans = false
	}
	// out(ans)
	if c[1][1]-c[1][2] != c[3][1]-c[3][2] {
		ans = false
	}
	// out(ans)

	if c[1][2]-c[1][3] != c[2][2]-c[2][3] {
		ans = false
	}
	// out(ans)
	if c[1][2]-c[1][3] != c[3][2]-c[3][3] {
		ans = false
	}
	// out(ans)

	if c[1][1]-c[2][1] != c[1][2]-c[2][2] {
		ans = false
	}
	// out(ans)
	if c[1][1]-c[2][1] != c[1][3]-c[2][3] {
		ans = false
	}
	// out(ans)

	if c[2][1]-c[3][1] != c[2][2]-c[3][2] {
		ans = false
	}
	// out(ans)
	if c[2][1]-c[3][1] != c[2][3]-c[3][3] {
		ans = false
	}
	// out(ans)

	if ans == true {
		out("Yes")
	} else {
		out("No")
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
 
#define barsik ios::sync_with_stdio(false)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair <int, int> pii;
typedef std::unordered_set <int> u_si;
const double PI = acos(-1);
const long double EPS = 1e-9;
using namespace std;


void solve(){
    int n;
    cin >> n;
    int a[1050];
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    int ans = 0;
    for(int i = 0; i < n - 1; i++) ans += (a[i + 1] - a[i]);
    cout << ans;
}
int main(){
    int q = 1;
    //cin >> q;}
    while(q--) solve();
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import sys
input = sys.stdin.readline
 
 
def main():
    n = int(input())
    l = list(map(int, input().split()))
    l = sorted(l)
 
    result = 0
    for i in range(n-2):
        for j in range(i + 1, n - 1):
            result += bisect.bisect_left(l[j+1:], l[i] + l[j])
 
    print(result)
 
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 50268