akhauriyash/Code-Regression huggingface dataset:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
from collections import defaultdict
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)


def make_prime_list_2(num):
    if num < 2:
        return []

    # 0のものは素数じゃないとする
    prime_list = [i for i in range(num + 1)]
    prime_list[1] = 0 # 1は素数ではない
    num_sqrt = math.sqrt(num)

    for prime in prime_list:
        if prime == 0:
            continue
        if prime > num_sqrt:
            break

        for non_prime in range(2 * prime, num, prime):
            prime_list[non_prime] = 0

    return [prime for prime in prime_list if prime != 0]


def search_divisor_num_of_factorial_num(num):
    if num <= 0:
        return 0
    elif num == 1:
        return 1
    elif num == 2:
        return 2
    else:
        # 素数とその個数を入れていく
        dict_counter = defaultdict(int)
        # メモ用のdict
        dict_memo = defaultdict(list)

        for a_num in range(2, num + 1):
            num_sqrt = math.ceil(math.sqrt(a_num))
            prime_list = make_prime_list_2(num_sqrt)

            # メモ用のdictに入れるためのkeyを残しておく
            now_num = a_num

            for prime in prime_list:
                while a_num % prime == 0:
                    # メモ内にある場合、そこから全部移して、移し終わったらループを抜ける
                    if a_num in dict_memo:
                        for memo in dict_memo[a_num]:
                            dict_counter[memo] += 1
                            dict_memo[now_num].append(memo)

                        a_num = 1

                    else:
                        dict_counter[prime] += 1
                        dict_memo[now_num].append(prime)
                        a_num //= prime

            if a_num != 1:
                dict_counter[a_num] += 1
                dict_memo[now_num].append(a_num)

        divisor_num = 1
        dict_fact = dict(dict_counter)
        for value in dict_fact.values():
            divisor_num *= (value + 1)

        return divisor_num
print(search_divisor_num_of_factorial_num(_I())%mod)


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

int main(void) {
    char c;
    int a, b;

    cin >> a;
    while (cin >> c) {
        if (c == '=') break;

        cin >> b;
        switch (c) {
        case '+':
            a += b;
            break;
        case '-':
            a -= b;
            break;
        case '*':
            a *= b;
            break;
        case '/':
            a /= b;
            break;
        }
    }

    cout << a << endl;
    return 0;
}

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

#define REP(i,n) for(int i = 0 ; i < n ; ++i)
using namespace std;
typedef long long Int;


Int dp[10][10];
Int INF = 999999999;
int n ;

vector<int> edges;

int main() {
    while(cin >> n , n) {

        REP(i, 100) {
            dp[i / 10][i % 10] = INF;
        }

        REP(i, n) {
            int a, b, c;
            cin >> a >> b >> c;
            dp[a][b] = c;
            dp[b][a] = c;
            dp[a][a] = 0;
            dp[b][b] = 0;

        }


        REP(k, 10) {
            REP(i, 10) {
                REP(j, 10) {
                    dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
                }
            }
        }
        Int i_min(INF), v_min(INF);
        REP(i, 10) {
            Int sum(0);
            REP(j, 10) {
                if (dp[i][j] != INF)
                    sum += dp[i][j];
            }
            if (sum < v_min && sum) {
                v_min = sum;
                i_min = i;
            }
        }

        cout << i_min << " " << v_min << endl;
    }

    return 0;
}

Measured memory_bytes: 1156
import sys
input=sys.stdin.readline
n,m,l=map(int,input().split())
G=[[] for i in range(n)]
for _ in range(m):
    a,b,c=map(int,input().split())
    if c>l:
        pass
    else:
        G[a-1].append((b-1,c))
        G[b-1].append((a-1,c))
INF=10**9
ans=[]
for i in range(n):
    d=[(INF,INF)]*n
    used=[False]*n
    d[i]=(0,l)
    while True:
        v=-1
        for j in range(n):
            if not used[j]:
                if v==-1:
                    v=j
                else:
                    if d[j][0]<d[v][0]:
                        v=j
                    elif d[j][0]==d[v][0]:
                        if d[j][1]>d[v][1]:
                            v=j
        if v==-1:
            break
        used[v]=True
        for j in G[v]:
            if d[v][1]<j[1]:
                x=d[v][0]+1
                y=l-j[1]
            else:
                x=d[v][0]
                y=d[v][1]-j[1]
            if x<d[j[0]][0]:
                d[j[0]]=(x,y)
            elif x==d[j[0]][0]:
                if y>d[j[0]][1]:
                    d[j[0]]=(x,y)
    ans.append(d)
q=int(input())
for i in range(q):
    s,t=map(int,input().split())
    if ans[s-1][t-1]==(INF,INF):
        print(-1)
    else:
        print(ans[s-1][t-1][0])
    



Measured memory_bytes: 62340
#include <stdio.h>
#include <string.h>
#define LEN 100005
 
typedef struct pp {
  char name[100];
  int t;
} P;
 
P Q[LEN];
int head, tail, n;
 
void enqueue(P x) {
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}
 
P dequeue() {
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}
 
int min(int a,int b) {
  return a < b ? a : b; 
}
 
int main() {
  int elaps = 0, c;
  int i, q;
  P u;
  char str[64];
  
  scanf("%d %d",&n ,&q);
  for(i=1; i<=n; i++) {
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1; tail = n + 1;
 
  while(head != tail) {
    u = dequeue();
    c = min(q, u.t);
    u.t -= c;
    elaps += c;
    if(u.t > 0) enqueue(u);
    else {
      printf("%s %d\n",u.name,elaps);
    }
  }
  return 0;
}



Measured memory_bytes: 11856
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
int main(){
    int N,ma=0;
    cin>>N;
    vector<string>v;
    map<string,int>m;
    string S;
    for(int i=0;i<N;i++){
        cin>>S;
        m[S]++;
    }
    for(auto x:m)ma=max(ma,x.second);
    for(auto x:m)if(x.second==ma)v.push_back(x.first);
    sort(v.begin(),v.end());
    for(auto x:v)cout<<x<<endl;
    return 0;
}

Measured memory_bytes: 26868
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

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

  cout << (n < 1000 ? "ABC" : "ABD") << endl;


  
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int mod = 1000000007;

int main(){
    ll n,m;
    cin>>n>>m;
    ll a[100009];
    ll s[100009];
    rep(i,m) cin>>a[i];
    rep(i,n+2){
        if(i==0) s[0]=1;
        else if(i==1) s[1]=1;
        else{
            s[i]=s[i-1]+s[i-2];
            s[i] %= mod;
        }
    }
    ll ans=1,st=0;
    if(m==0){
        ans *= s[n];
        ans %= mod;
    }else{
        rep(i,m+1){
            if(i==0){
                st=a[0]-1;
            }else if(i==m){
                st=n-(a[i-1]+1);
            }else{
                st=(a[i]-1)-(a[i-1]+1);
            }   
            if(st<0){
                ans =0;
                break;
            }else{
                ans *= s[st];
                ans %=mod;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(void){
    string s; cin >> s;
    set<char> C;
    for(char c='a'; c<='z'; c++) C.insert(c);
    
    for(int i=0; i<s.size(); i++){
        auto a=C.erase(s[i]);
    }

    vector<char> ans;
    for(auto itr = C.begin(); itr != C.end(); ++itr) {
        ans.push_back(*itr);
    }

    if(ans.size()==0){
        cout << "None" << endl;
        return 0;
    }

    sort(ans.begin(), ans.end());
    cout << ans[0] << endl;
    return 0;
    
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;

// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair

ll h[100005],ans[100005];

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

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

	ll n,i,j,k;
	cin >> n >> k;
	for(i=0;i<n;i++)
	{
		cin >> h[i];
		if(i>0)	ans[i]=1000000000;
	}
	
	for(i=1;i<n;i++)
		for(j=max((ll)(0),i-k);j<i;j++)
			ans[i]=min(ans[i],ans[j]+abs(h[i]-h[j]));
	cout << ans[n-1];

	return 0;
}


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

 
int main(){
    
    int n;
    ll ans=0;
    cin>>n;
    vector<int> a(n),b(n-1);
    rep(i,n-1)cin>>b.at(i);
    
    a.at(0)=b.at(0);
    a.at(n-1)=b.at(n-2);
    
    for(int i=1;i<n-1;i++){
        a.at(i)=min(b.at(i-1),b.at(i));
    }
    rep(i,n){
       // cout<<a.at(i)<<endl;
        ans+=a.at(i);
    }
    
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include "vector"
#include "set"
#include "map"
#include "unordered_set"
#include "unordered_map"
#include "string"
#include "iostream"
#include "algorithm"
#include "queue"

using namespace std;

#define ll long long
#define INF 2e9
#define INF2 4611686018427387904
//#define MOD 1000000007
#define MOD 998244353
#define MAX_SIZE 1000000000

typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) { bool first = true; for (const auto& j: v) { if (!first) { os << " "; } first = false; os <<j; } os << "\n"; return os; }
template<typename T>
istream& operator>>(istream& is, vector<T>& v) { for (auto& elem : v) { is >> elem; } return is; }

vector<ll> f;
void set_f(int n) { f.resize(n+1); f[0] = 1; for (int i=1; i<= n; i++) { f[i] = (f[i-1] * i) % MOD;} }
ll nod(ll a, ll b) { if (b == 0) { return a; } else { return nod(b, a % b); } }
ll pw(ll x, ll n, ll m=MOD) { if (n == 0) { return 1;} if (n%2 == 0) { return pw((x*x) % m, n/2, m); } return (pw(x, n-1, m) * x) % m; }
ll dv(ll a, ll b) { return (a * pw(b, MOD - 2)) % MOD; }
ll c_n_k(int n, int k) { if (k > n) { return 0; } if (k < 0) { return 0; } return dv(dv(f[n], f[k]), f[n-k]); }

void solve() {
    double x;
    cin >> x;
    printf("%.08f", (x/3) * (x/3) * (x/3));
}

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

    if (0) {
        int tests;
        cin >> tests;
        for (int t = 1; t <= tests; t++) {
            //cout << "Case #" << t << ": ";
            solve();
            //cout << "\n";
        }
    } else {
        solve();
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
const double INF=1e9;
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  vector<int>in(m);
  rep(i,m)cin>>in[i];
  sort(all(in));
  vector<int>out(n+1);
  rep(i,n+1)out[i]=INF;
  out[0]=0;
  rep(i,m){
    loop(j,in[i],n+1)
      out[j]=min(out[j],out[j-in[i]]+1);
  }
  cout<<out[n]<<endl;
}

Measured memory_bytes: 1292
import sys
input=sys.stdin.readline
n=int(input())
ll=[]
for i in range(n):
  a=int(input())
  for _ in range(a):
    x,y=map(int,input().split())
    ll+=[(i,x-1,y)]
c=0
for p in range(2**n):
  b=1
  for i,x,y in ll:
    if p>>i&1 and p>>x&1!=y:
      b=0
      break
  if b: c=max(c,sum(p>>i&1 for i in range(n)))
print(c)

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

using namespace std;

#define all(x) (x).begin(), (x).end()
typedef long double ld;
typedef long long ll;

const int M = 83;
const int T = 41;

int n;
bool a[M][M];
ll d[M][M][M];

void read() {
  cin >> n;
  n *= 2;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j) {
      char ch;
      cin >> ch;
      a[i][j] = ch == '1';
    }
}

bool fun(int x, int y) {
  x %= n;
  if (x < 0) x += n;
  y %= n;
  if (y < 0) y += n;
  return a[x][y];
}

ll calc(int l, int r, int x) {
  if (d[l + T][r + T][x + T] != -1)
    return d[l + T][r + T][x + T];

  ll &ans = d[l + T][r + T][x + T];
  ans = 0;

  if (!(l <= x && x < r)) return ans = 0;
  if (l + 1 == r) return ans = 1;

  for (int nl = l + 1; nl <= x; ++nl)
    for (int nr = x + 1; nr < r; ++nr)
      for (int a = l; a < nl; ++a)
        for (int b = nr; b < r; ++b)
          if (fun(a, b))
            ans += calc(l, nl, a) * calc(nr, r, b) * calc(nl, nr, x);
  return ans;
}

void kill() {
  for (int i = 0; i < M; ++i)
    for (int j = 0; j < M; ++j)
      for (int k = 0; k < M; ++k)
        d[i][j][k] = -1;

  ll ans = 0;
  for (int i = 1; i < n; ++i)
    if (fun(0, i))
      ans += calc(i + 1 - n, i, 0);

  cout << ans << "\n";
}

int main() {
#ifdef LOCAL
  assert(freopen("e.in", "r", stdin));
#endif

  ios_base::sync_with_stdio(false);

  read();
  kill();
}



Measured memory_bytes: 4736
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <tuple>
using namespace std;
using ll=long long;
using R=double;

int D[10]={0};

bool check(int N){
	vector<int> unko;
	while(N!=0){
		unko.push_back(N%10);
		N = N/10;
	}

	for(int i = 0; i < unko.size(); i++){
		if(D[unko[i]]==1){
			return true;
		}
	}

	return false;
}

int main(){
	int N,K;
	cin >> N >> K;
	for(int i = 0; i < K; i++){
		int x;
		cin >> x;
		D[x]++;
	}

	if(check(N)==false){
		cout << N << endl;
		return 0;
	}

	int count = 0;
	while(check(N)){
		//printf("N : %d\n",N);
		N++;
		count++;
	}

	cout << N << endl;
	return 0;

}


Measured memory_bytes: 256
while line = gets and line.chomp! != '.'
    stack = []
    ans = true
    line.each_char do |c|
        if ['(', '['].include? c
            stack.push c
        end
        if [')', ']'].include? c
            if stack.empty? or stack.pop != {')' => '(', ']' => '['}[c]
                ans = false
                break
            end
        end
    end
    puts (if ans and stack.empty?
            'yes'
        else
            'no'
        end)
end

Measured memory_bytes: 6136
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

int a[2000][2000];
vector<string> str;
signed main(){
	int h, w, ans = 1;
	scanf("%lld%lld", &w, &h);
	str.resize(h);
	rep(i,h)rep(j,w)scanf("%lld",&a[i][j]);
	rep(i,h)rep(j,w)str[i].pb('0'+a[i][j]);
	ZIP(str);
	if(str.size() != 2){printf("no\n");return 0;}
	int cnt[2] = {};
	rep(i,2)rep(j,w)if(str[i][j] == '1')cnt[i]++;
	if(llabs(cnt[0]-cnt[1]) > 1){printf("no\n");return 0;}
	rep(j,w)if(str[0][j] == str[1][j])ans = 0;
	printf("%s\n", ans == 1 ? "yes" : "no");
	rep(i,str.size()){
		//cout << str[i] << endl;
	}
	return 0;
}
/*
3 3
1 1 0
0 1 1
1 1 0
*/







Measured memory_bytes: 15792
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
//#define S set<int>
#define itn int
bool dbg = false;

int N;
int a[101010][5];
int dp[101010][5];


void solve() {
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N;
    FOR(N)
    cin >> a[i][0] >> a[i][1] >> a[i][2];
    itn ans = 0;

    FOR(N) {
        FOR(bfr, 0, 3) {
            FOR(nxt, 0, 3) {
                if (i == 0 || bfr != nxt) {
                    chmax(dp[i + 1][nxt], dp[i][bfr] + a[i][bfr]);
                    chmax(ans, dp[i + 1][nxt]);
                }
            }
        }
    }
    cout << ans << endl;


    solve();
    return 0;
}


Measured memory_bytes: 8064
import java.util.*;

class Main {
	Scanner sc = new Scanner(System.in);

	public void run() {
		int [] dp=new int[100];
		int prevsize=0;
		while(sc.hasNext()){
			String[] st=sc.next().split(",");
			if(st.length>prevsize){
				for(int i=st.length-1;i>=0;i--){
					dp[i]=(i>=1?Math.max(dp[i],dp[i-1]):dp[i])+Integer.parseInt(st[i]);
				}
			}else{
				for(int i=0;i<st.length;i++){
					dp[i]=Math.max(dp[i],dp[i+1])+Integer.parseInt(st[i]);
				}
			}
			prevsize=st.length;
		}
		ln(dp[0]);
	}

	public static void main(String[] args) {
		new Main().run();
	}

	public static void pr(Object o) {
		System.out.print(o);
	}

	public static void ln(Object o) {
		System.out.println(o);
	}

	public static void ln() {
		System.out.println();
	}
}

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

using namespace std;

const int N = 3005;

const int mod = (int) 1e9 + 7;

int dp[N][N][2];

void add(int& a, int b) {
  a += b;
  if (a >= mod) {
    a -= mod;
  }
}


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int j = 0; j <= n; j++) {
    dp[0][j][j == 0] = 1;
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 0; j <= n; j++) {
      if (j > 0) {
        if (j - 1 == 0) {
          // RR
          add(dp[i][j - 1][1], dp[i - 1][j][0]);
          // RB                 
          add(dp[i][j][1], dp[i - 1][j][0]);
        } else {
          // RR
          add(dp[i][j - 1][0], dp[i - 1][j][0]);
          // RB
          add(dp[i][j][0], dp[i - 1][j][0]);
        }
        // RR
        add(dp[i][j - 1][1], dp[i - 1][j][1]);
        // RB
        add(dp[i][j][1], dp[i - 1][j][1]);
      }
      if (j < n) {
        // BB
        add(dp[i][j + 1][0], dp[i - 1][j][0]);
        // BR
        add(dp[i][j][0], dp[i - 1][j][0]);
        // BB
        add(dp[i][j + 1][1], dp[i - 1][j][1]);
        // BR
        add(dp[i][j][1], dp[i - 1][j][1]);
      }
    }
  }
  int ans = 0;
  for (int j = 0; j <= n; j++) {
    add(ans, dp[m][j][1]);
  }
  cout << ans << '\n';
  return 0;
}

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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}






int gcd(int a,int b)
{
 
  int r, tmp;
 
  
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
 
 
  return b;
}







int fac(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  return m;
}

int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}
///////////////////////////
int main() {
  int h,w;
  cin>>h>>w;
  vector<string> v(h);
  rep(i,h) cin>>v[i];
  rep(i,h){
    cout<<v[i]<<endl;
    cout<<v[i]<<endl;
  }
}
///////////////////////////

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N; cin>>N;
  vi A(N);
  rep(i,0,N) cin>>A[i];
  int ans=INF;
  REP(i,1,100){
    int sum=0;
    rep(j,0,N){
      sum+=(A[j]-i)*(A[j]-i);
    }
    ans=min(ans,sum);
  }
  cout<<ans<<endl;
  }


Measured memory_bytes: 256
n = int(input())
data = []

for i in range(n):
    a, b = map(int, input().split())
    data.append([a, b])
data = sorted(data, key = lambda x: x[1])
time = 0
ans = "Yes"
for i in range(n):
    if time + data[i][0] > data[i][1]:
        ans = "No"
    time += data[i][0]
print(ans)

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

int main() {
  string S;
  int Q;
  cin>>S>>Q;
  
  bool jun=true;
  vector<char> migi;
  vector<char> hidari;
  for(int i=0;i<Q;i++){
    int a;
    cin>>a;
    if(a==1){
      if(jun) jun=false;
      else jun=true;
    }
    else{
      int b;
      char c;
      cin>>b>>c;
      if(b==1){
        if(jun) hidari.push_back(c);
        else migi.push_back(c);
      }
      else{
        if(jun) migi.push_back(c);
        else hidari.push_back(c);
      }
    }
  }
  if(jun){
    for(int i=hidari.size()-1;i>=0;i--){
      cout<<hidari.at(i);
    }
    cout<<S;
    for(int i=0;i<migi.size();i++){
      cout<<migi.at(i);
    }
    cout<<endl;
  }
  else{
    for(int i=migi.size()-1;i>=0;i--){
      cout<<migi.at(i);
    }
    reverse(S.begin(),S.end());
    cout<<S;
    for(int i=0;i<hidari.size();i++){
      cout<<hidari.at(i);
    }
    cout<<endl;
  }
}

Measured memory_bytes: 3888
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1148&lang=jp

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

int main() {
  int N, M;
  while(scanf("%d%d", &N, &M) != EOF && N) {
    vector<int> V[10010]; // 学生mが利用中のコンピュータを管理
    int start[10010]; // 利用開始時刻
    fill(start, start+10010, 0);
    vector<pair<int, int>> T[10010]; // 利用時刻の記録
    int r;
    scanf("%d", &r);
    int t, m, n, s;
    for (int i=0; i<r; i++) {
      scanf("%d%d%d%d", &t, &n, &m, &s);
      if (s) { // ログイン
	V[m].push_back(n);
	if (start[m] == 0) { // 1台もログインしていない場合
	  start[m] = t;
	}
      } else { // ログアウト
	V[m].erase(find(V[m].begin(), V[m].end(), n));
	if (V[m].empty()) { // 1台もログインしていない場合
	  // cerr << "Student " << m << " logs from " << start[m] << " until " << t << endl;
	  T[m].push_back(make_pair(start[m], t));
	  start[m] = 0;
	}
      }
    }
    int q;
    scanf("%d", &q);
    for (int i=0; i<q; i++) {
      int ts, te;
      scanf("%d%d%d", &ts, &te, &m);
      int ans = 0;
      for (unsigned int j=0; j<T[m].size(); j++) {
	int temp = min(te, T[m][j].second) - max(ts, T[m][j].first);
	if (temp > 0) ans+= temp;
      }
      printf("%d\n", ans);
    }
  }
}

Measured memory_bytes: 1712
#include<bits/stdc++.h>
#define ll long long
#define pii_ pair<int,int>
#define mp_ make_pair
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define show1(a) cout<<#a<<" = "<<a<<endl
#define show2(a,b) cout<<#a<<" = "<<a<<"; "<<#b<<" = "<<b<<endl
using namespace std;
const ll INF = 1LL<<60;
const int inf = 1<<30;
const int maxn = 2e5+5;
inline void fastio() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}

int n,x,a,has[maxn];

int main()
{
    fastio();
    cin>>x>>n;
    int mi = inf,ans;
    rep(i,1,n){
        cin>>a;has[a]=1;
    }
    rep(i,0,105){
        if(!has[i]){
            if(abs(x-i)<mi){
                mi = abs(x-i);
                ans = i;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  string s ;
  cin >> s ;
  int T = (s.size()-1)/2;
  int t = (s.size()+3)/2 ;
  bool ans = true ;
  
 
  
  rep(i,s.size()){
    if(s.at(i) != s.at(s.size()-1-i))
      ans = false ;
  }
   rep(i,T){
    if(s.at(i) != s.at(T-1-i))
      ans = false ;
  }
  
  for(int i=t;i<s.size();i++){
    if(s.at(i-1) != s.at(s.size()-(i-t+1))){
      ans = false ;
    }
  }
 
  
  if(ans) cout << "Yes";
  else cout << "No";
     
    
    
  
  


}


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

ll solve(vector<P> p, ll n) {
  ll ans = n;
  if(p.size() == 1) {
    ans = n/p[0].first*p[0].second +  n % p[0].first; 
  } else if(p.size() == 2) {
    for(ll i = 0; i <= n; i++) {
      ll d = n - p[0].first*i;
      if(d < 0) break;
      ans = max(ans,p[0].second*i + d/p[1].first*p[1].second + d % p[1].first);
    }
  } else if(p.size() == 3) {
    for(ll i = 0; i <= n; i++) {
      for(ll j = 0; j <= n; j++) {
      ll d = n - p[0].first*i - p[1].first*j;
      if(d < 0) continue;
      ans = max(ans,p[0].second*i + p[1].second*j + d/p[2].first*p[2].second + d % p[2].first);
      }
    } 
  }
  return ans;
}

int main(){
  ll n;
  cin >> n;
  ll a[3], b[3];
  rep(i,3) cin >> a[i];
  rep(i,3) cin >> b[i];
  vector<P> p, q;
  rep(i,3) {
    if(a[i] < b[i]) p.push_back(P(a[i],b[i]));
    else if(b[i] < a[i]) q.push_back(P(b[i],a[i]));
  }
  n = solve(p,n); n = solve(q,n);
  cout << n << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=1e9+7;
int dy[]={1,-1,0,0};
int dx[]={0,0,1,-1};

ll calc(bool bbegin, bool bend,ll x, ll y){
  ll times=0;
  if(bbegin){
    times++;
    x*=-1;
  }
  if(bend){
    times++;
    y*=-1;
  }
  if(y>=x){
    times+=(y-x);
    return times;
  }else{
    times=1e12;
    return times;
  }
}


int main(){
  ll x, y;
  cin>>x>>y;

  ll ans=1e12;
  for(int i=0;i<2;i++)
    for(int j=0;j<2;j++) ans=min(ans,calc(i,j,x,y));
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 256
<?php
$sc = new Scanner();

$in_num = $sc->nextInt();
$in_greater = $sc->nextInt();
$in_less = $sc->nextInt();

$num_arr = array();
for ($i = 1; $in_num >= $i; $i++) {
    $sum = sum_digit(strval($i));
    if ($sum >= $in_greater && $sum <= $in_less) {
        array_push($num_arr, $i);
    }
}

$total = 0;
foreach ($num_arr as $k => $v) {
    $total += $v;
}

out::println($total);

function sum_digit($num)
{
    $num_arr = str_split($num);
    $sum = 0;
    foreach ($num_arr as $k => $v) {
        $sum += $v;
    }
    return $sum;
}


class Scanner
{
    private $arr = [];
    private $count = 0;
    private $pointer = 0;

    public function next()
    {
        if ($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }

    public function hasNext()
    {
        return $this->pointer < $this->count;
    }

    public function nextInt()
    {
        return (int)$this->next();
    }

    public function nextDouble()
    {
        return (double)$this->next();
    }
}

class out
{
    public static function println($str = "")
    {
        echo $str . PHP_EOL;
    }
}

Measured memory_bytes: 4728
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;
// const int MOD = 998244353;

bool check(vector<P> s) {
   int h = 0;
   for (P p : s) {
      int b = h + p.first;
      if (b < 0) return false;
      h += p.second;
   }
   return true;
}
int main() {
   cin.tie(0);
   ios_base::sync_with_stdio(0);

   int n;
   cin >> n;
   vector<P> ls, rs;
   int total = 0;
   rep(i, 0, n) {
      string s;
      cin >> s;
      int h = 0, b = 0;
      for (char c : s) {
         if (c == '(')
            h++;
         else
            h--;
         b = min(b, h);
      }
      if (h > 0)
         ls.emplace_back(b, h);
      else
         rs.emplace_back(b - h, -h);
      total += h;
   }
   sort(ls.rbegin(), ls.rend());
   sort(rs.rbegin(), rs.rend());
   if (check(ls) && check(rs) && total == 0) {
      cout << "Yes" << endl;
   } else {
      cout << "No" << endl;
   }
   return 0;
}

Measured memory_bytes: 18868
#![allow(non_snake_case)]
use std::io::*;
use std::str::FromStr;
use std::cmp::*;

#[allow(dead_code)]
fn read<T : FromStr>() -> T {
  let token: String = stdin().lock()
    .bytes()
    .map(|c| c.expect("failed reading char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed parse")
}

#[allow(dead_code)]
fn read2<T : std::str::FromStr>() -> (T, T) {
  (read::<T>(), read::<T>())
}

#[allow(dead_code)]
fn read3<T : std::str::FromStr>() -> (T, T, T) {
  (read::<T>(), read::<T>(), read::<T>())
}

#[allow(dead_code)]
fn reads<T : std::str::FromStr>() -> Vec<T> {
  let mut line = String::new();
  stdin().read_line(&mut line).ok();
  line.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

struct SegTree {
  n: usize,
  data: Vec<i64>,
  zero: i64,
  op: fn(i64, i64) -> i64
}

impl SegTree {
  fn new(data_: &[i64], zero: i64, op: fn(i64,i64) -> i64) -> Self {
    let m = data_.len();
    let mut n = 1;
    while n < m { n *= 2; }

    let mut data = vec![zero; 2*n];

    for i in 0..m {
      data[i + n - 1] = data_[i];
    }

    for ri in 0..n-2 {
      let i = n - 2 - ri; // [n-2 .. 0]
      data[i] = op(data[i*2+1], data[i*2+2]);
    }

    Self {
      n,
      data,
      zero,
      op
    }
  }

  #[allow(dead_code)]
  fn update(&mut self, i: usize, val: i64) {
    let mut i = self.n - 1 + i;
    self.data[i] = val;
    while i > 0 {
      i = (i - 1) / 2;
      self.data[i] = (self.op)(self.data[i*2+1], self.data[i*2+2]);
    }
  }

  #[allow(dead_code)]
  fn query(&self, l: usize, r: usize) -> i64 {
    let mut l = l + self.n - 1;
    let mut r = r + self.n - 1;

    let mut res = self.zero;
    while l < r {
      if (l & 1) == 0 {
        res = (self.op)(res, self.data[l]);
      }
      if (r & 1) == 0 {
        res = (self.op)(res, self.data[r - 1]);
      }
      l = l / 2;
      r = (r - 1) / 2;
    }

    res
  }
}

fn main() {
  let n: usize = read();
  let k: usize = read();
  let mut xs: Vec<usize> = Vec::with_capacity(n);
  for _ in 0..n {
    let x = read();
    xs.push(x);
  }

  const LIMIT: usize = 300000 + 10;
  let mut seg = SegTree::new(
    &vec![0; LIMIT],
    std::i64::MIN,
    |x,y| max(x, y)
  );
  let mut res = 1;
  for x in xs {
    let l = if x >= k { x - k } else { 0 };
    let r = if x + k + 1 <= LIMIT { x + k + 1 } else { LIMIT };
    let head = seg.query(l, r);

    seg.update(x, head + 1);
    res = max(res, head + 1);
  }

  let res = seg.query(0, LIMIT);
  println!("{}", res);
}

Measured memory_bytes: 12572
#include<iostream>
#include<string>
#include<string.h>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
using namespace std;
int main()
{
    int a,b;
    cin >> a >> b;
    cout << a-b+1 << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static program.Input;
using static program.MyMath;
using static System.Console;

namespace program {
  class Program {
    static string Alp = "abcdefghijklmnopqrstuvwxyz";
    static void Main()
    {
      var s = ScanStr().ToCharArray();
      int count =0;
      for(int i=1; i<s.Length; i++){
        if(s[i]==s[i-1]){
          s[i] = s[i]=='0' ? '1' : '0';
          count++;
        }
      }
      
      WriteLine(count);
    }
  }
  
  static class Input {
    static public int ScanInt() { return int.Parse(Console.ReadLine()); }
    static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
    static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
    static public long ScanLong() { return long.Parse(Console.ReadLine()); }
    static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
    static public int[] ScanIntArray() { return Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); }
    static public uint[] ScanUintArray() { return Console.ReadLine().Split().Select(x => uint.Parse(x)).ToArray(); }
    static public double[] ScanDoubleArray() { return Console.ReadLine().Split().Select(x => double.Parse(x)).ToArray(); }
    static public long[] ScanLongArray() { return Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray(); }
    static public ulong[] ScanUlongArray() { return Console.ReadLine().Split().Select(x => ulong.Parse(x)).ToArray(); }

    static public string ScanStr() { return Console.ReadLine(); }
    static public string[] ScanStrArray() { return ScanStr().Split(); }
  }
  
  static class MyMath {
    public static int GCD(int a, int b) {
        Func<int, int, int> gcd = null;
        gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
        return a > b ? gcd(a, b) : gcd(b, a);
    }
    public static long GCD(long a, long b) {
        Func<long, long, long> gcd = null;
        gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
        return a > b ? gcd(a, b) : gcd(b, a);
    }
    public static ulong extGCD(ulong a, ulong b, ref ulong x, ref ulong y) {
      if(b==0) {
        x=1; 
        y=0;
        return a;
      }
      var d = extGCD(b, a%b, ref y, ref x);
      y -= a/b *x;
      return d;
    }
    public static int LCM(int a, int b) { return a * b / GCD(a, b); }
    public static long LCM(long a, long b) { return a * b / GCD(a, b); }
  }
}


Measured memory_bytes: 13176
import sys
from collections import Counter
readline = sys.stdin.readline

S = list(map(int, readline().strip()))
N = len(S)
C = Counter()
C[0] = 1
ans = 0
MOD = 2019
res = 0
for i in range(N):
    s = S[N-1-i]
    res = (res+s*pow(10, i, MOD))%MOD
    ans += C[res]
    C[res] += 1
print(ans)

Measured memory_bytes: 85780
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

double cross (double x1, double y1, double x2, double y2 )
{
	return (x1*y2 - x2*y1 );
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.convex", "r", stdin );
	string str = "";
	while (getline (cin, str ) ){
		if (str.empty() ){
			break;
		} // end if
		while (str.find(',') != string::npos ){
			str = str.replace(str.find(','), 1, " ");
		} // end while
		stringstream ss(str);
		vector<double> x(4, 0.0 ), y (4, 0.0 );
		rep (i, 4 ){
			ss >> x[i] >> y[i];
		} // end rep

		vector<double> res (4, 0 );
		rep (i, 4 ){
			res[i] = cross (	x[(i+2)%4] - x[i], y[(i+2)%4] - y[i],
								x[(i+1)%4] - x[i], y[(i+1)%4] - y[i] );
		} // end rep
		int pl = 0, ng = 0; 
		rep (i, 4 ){
			if (res[i] > 0. ) pl++;
			else
				ng++;
		} // end rep
		if (pl == 4 || ng == 4 ){
			printf ("YES\n" );
		}else{
			printf ("NO\n" );
		} // end if
	} // end loop

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

Measured memory_bytes: 1232
#include <stdio.h>
#include <math.h>
int main()

{
  int n, i, j, flag=0, count=0, num;
  
  scanf("%d", &n);
  
  for(i=0; i<n; i++){
    scanf("%d", &num);
    

    for(j=2; j<=sqrt(num); j++){
      if(num % j == 0){
	flag=1;
      }
    }

    if(flag==0) count++;
    flag=0;
  }

  printf("%d\n", count);

  return 0;
}

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

#define REP(i, n) for(int i = 0; i != n; ++i)
#define REPR(i, n) for(int i = n - 1; i != -1; --i)
#define FOR(i, a, b) for(int i = a; i != b; ++i)
#define IN(n) (cin >> n)
#define OUT(n) (cout << n << endl)

using namespace std;
using ll = unsigned long long;

int gcd(int a, int b) {
	int r;
	do {
		r = a%b;
		a = b;
		b = r;
	} while(r != 0);
	
	return a;
}

template<typename T>
int gcd(T v) {
	int g = 0;
	for(int i = 1; i < v.size(); i++) {
		g = gcd(v[0], v[i]);
		v[0] = g;
	}
	
	return v[0];
}

int main() {
	int N, X;
	IN(N);
	IN(X);
	vector<int> x(N), d(N);
	int i, j;
	for(i = 0; i < N; i++) {
		IN(x[i]);
		d[i] = abs(x[i] - X);
	}
	
	sort(d.begin(), d.end());
	
	int result = gcd(d);
	
	OUT(result);
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n;
    cin>>n;
    vector<ll>arr(n);
    ll sum1=0,sum2=0;
    for(int i=0; i<n; i++){
        cin>>arr[i];
        sum1=(sum1+arr[i])%mod;
        sum2=(sum2+arr[i]*arr[i]%mod)%mod;
    }
    sum1=sum1*sum1%mod;
    ll ans=(sum1-sum2+mod)%mod;
    ans=(ans*500000004%mod)%mod;
    cout<<ans;

    return 0;

    
}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
#define ll  long long
#define ull unsigned long long  
using namespace std;
#define  inf 1e18+18
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define mod 1000000007
#define  f1(i,n) for(i=1;i<=n;i++)
#define f0(i,n)  for(i=0;i<n;i++)
#define w(x)   while(x--)
const int maxn=40000;
#define  pq priority_queue
#define  ff first
#define  ss second 
#define pb  push_back
#define lb lower_bound
int main()
{
	ll i,j,k,l,d,m,n,x;
	string s;
	cin>>x>>k>>d;
	if(x<0)
		x=-x;
	ll ans=k;
	j=x/d;
	if(k<=j)
	{
		cout<<x-k*d;
	}
	else
	{
		ll ans1;
		ans=x-j*d;
		ans1=ans;
		k=k-j;
		if(k%2==1)
		{
			ans1=ans+d;
		}
		k--;
		l=ans-d;
		if(k%2==1)
		{
			ans1=min(ans1,l+d);
		}
		else
			ans1=min(ans1,abs(l));
		cout<<ans1;
	}

	//cout<<l;
}

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

int main(int argc,char** argv){
  int a[3];
  for(int i = 0; i < 3 ; i++){
    cin >> a[i];
  }
  sort(a,a+3);
  
  cout << a[2] - a[0] << endl;
    
  return 0;
}


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

int main() {
	int pqrs;cin>>pqrs;
	string s;cin>>s;
	for(int i=0;i<pqrs-1;i++){
		if(s[i]=='x'&&s[i+1]=='x'){
			cout<<i+1<<endl;
			return 0;
		}
	}
	cout<<pqrs<<endl;
	return 0;
}


Measured memory_bytes: 3352
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

//--------------------------------------------

int n,k;
vi acum;

signed main(){
    I(n); I(k);
    acum.resize(n);
    REP(i,n) {
        I(acum[i]);
        acum[i]--;
        acum[i] %= k;
    }
    map<int, vi> rem;
    rem[0].pb(-1);
    rem[acum[0]].pb(0);
    REP(i,n-1) {
        acum[i+1] = (acum[i] + acum[i+1]) % k;
        rem[acum[i+1]].pb(i+1);
    }
    REP(i,n) cerr << acum[i] << " "; cerr << endl;
    int ret = 0;
    for(auto p: rem){
        auto tgt = p.second;
        
        int lent = sz(tgt);
        REP(i,lent){
            int iplus = lower_bound(all(tgt), tgt[i] + k) - tgt.begin() - i - 1;
            // cerr << tgt[i] << ": " << iplus << endl;
            ret += iplus;
        }
    }
    cout << ret << endl;
}


Measured memory_bytes: 23680
#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;

int dir[9][2]={{-2,-2},{-2,-1},{-2,0},{-1,-2},{-1,-1},{-1,0},{0,-2},{0,-1},{0,0}};
ll x,y,n;
bool isok(int a,int b){
    return a>=0 && b>=0 && a+2<x && b+2<y;
}

ll rez[10];

int main()
{
    ios::sync_with_stdio(false);

    cin>>x>>y>>n;
    map<ii,int> mp;
    int nx,ny;
    for(int ctr1=0;ctr1<n;ctr1++){
        cin>>nx>>ny;
        nx--,ny--;
        for(int ctr2=0;ctr2<9;ctr2++)
            if(isok(nx+dir[ctr2][0],ny+dir[ctr2][1]))
                mp[{nx+dir[ctr2][0],ny+dir[ctr2][1]}]++;
    }
    for(auto it:mp){
        //cout<<it.first.first<<" "<<it.first.second<<" "<<it.second<<"\n";
        rez[it.second]++;
    }
    ll sum=0;
    for(int ctr1=0;ctr1<10;ctr1++)
        sum+=rez[ctr1];
    cout<<(x-2)*(y-2)-sum<<" ";
    for(int ctr1=1;ctr1<10;ctr1++){
        cout<<rez[ctr1]<<" ";
    }
    cout<<"\n";
    return 0;
}


Measured memory_bytes: 56576
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    static final Scanner     sc = new Scanner(System.in);
    static final PrintStream so = System.out;

    public static void main(String[] args) {
        int N = ni();
        String s = ns();
        String t = ns();
        
        int i_max = 0;
        for (int i = 1; i <= N; i++)
            if (s.substring(N-i, N).equals(t.substring(0, i)))
                i_max = i;
        
        so.println(N*2 - i_max);
    }

    private static int ni() {
        return sc.nextInt();
    }

    private static String ns() {
        return sc.next();
    }
}


Measured memory_bytes: 21204
# AOJ 1005: Advanced Algorithm Class
# Python3 2018.7.5 bal4u

import sys
from sys import stdin
input = stdin.readline

while True:
	n = int(input())
	if n == 0: break
	a = [list(map(int, input().split())) for r in range(n)]
	b = [[0 for c in range(n)] for r in range(n)]
	for r in range(n):
		mi = min(a[r])
		for c in range(n):
			if a[r][c] == mi: b[r][c] |= 1
	for c in range(n):
		ma = max([a[r][c] for r in range(n)])
		for r in range(n):
			if a[r][c] == ma: b[r][c] |= 2
	ans = 0
	for r in range(n):
		for c in range(n):
			if b[r][c] == 3: ans = a[r][c]
	print(ans)


Measured memory_bytes: 5616
import java.util.*;

public class Main {
    public static final long INF = 1 << 60;
    public static long[] dp = new long[100010];
    public static void main(String[] args) throws Exception {
    for(int i=0;i<100010;++i)dp[i] = INF;
       Scanner sc = new Scanner(System.in);
       int N = sc.nextInt();
       int K = sc.nextInt();
       long[] steps = new long[N + 10];
       for(int i=0;i<N;i++){
           steps[i] = sc.nextLong();
       }
       for(int i=0;i<N;i++){
           if(i == 0){
               dp[i] = 0;
           }else if(i == 1){
               dp[i] = height(steps[0],steps[1]);
           }else{
               if(K == 1){
                   dp[i] = dp[i - 1] + height(steps[i],steps[i-1]);
               }else{
                for(int j=1;j<=i && j<=K;j++){
                dp[i] = chmin(dp[i] ,dp[i-j] + height(steps[i],steps[i-j]));
                }
               }
           }
       }
       System.out.println(dp[N - 1]);
    }
    
    public static long height(long h1,long h2){
        return Math.abs(h1 - h2);
    }
    
    public static long chmin(long a , long b){
        return Math.min(a,b);
    }
}


Measured memory_bytes: 61432
#include <bits/stdc++.h>
using namespace std;
string a;
int main()
{
    cin>>a;
    bool f=false;
    for(int i=0;i<a.size();i++)
    {
        if(a[i]=='C')
            f=true;
        if(a[i]=='F')
            if(f)
            {
                cout<<"Yes";
                exit(0);
            }
            else
            continue;
    } 
    cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mov(i,a,b) for(int i = a; i < b; i++)
typedef long long ll;
using namespace std;
int main(){
	ll n; 
	cin>>n;
	vector<int> h(n);
	mov(i,0,n) cin>>h[i];
	vector<int> dp(n,INT_MAX);
	dp[0] = 0;
	for(int i = 1; i < n; i++){
		if(i >= 1) dp[i] = min(dp[i],dp[i-1]+abs(h[i-1]-h[i]));
		if(i >= 2) dp[i] = min(dp[i],dp[i-2]+abs(h[i-2]-h[i]));
	}
	cout<<dp[n-1]<<"\n";
	return 0;
}


Measured memory_bytes: 1024