akhauriyash/Code-Regression huggingface dataset:
// Rasen Book p348

#include <iostream>
#include <vector>
#include <set>
#define MAXV 100000

using namespace std;

vector<int> G[MAXV];
bool visited[MAXV];
int prenum[MAXV], parent[MAXV], lowest[MAXV];
int N, timer;

void dfs(int current, int prev) {
    prenum[current] = lowest[current] = timer;
    timer++;

    visited[current] = true;

    int next;

    for (int i = 0; i < G[current].size(); i++) {
        next = G[current][i];
        if (!visited[next]) {
            parent[next] = current;

            dfs(next, current);

            lowest[current] = min(lowest[current], lowest[next]);
        }
        else if(next != prev) {
            lowest[current] = min(lowest[current], prenum[next]);
        }
    }
}

void art_points() {
    for (int i = 0; i < N; i++) { visited[i] = false; }
    timer = 1;

    dfs(0, -1);

    set<int> ap;
    int np = 0;

    for (int i = 1; i < N; i++) {
        int p = parent[i];
        if (p == 0) np++;
        else if (prenum[p] <= lowest[i]) ap.insert(p);
    }
    if (np > 1) ap.insert(0);

    for (set<int>::iterator it = ap.begin(); it != ap.end(); it++) {
        cout << *it << endl;
    }
}

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

    for (int i = 0; i < m; i++) {
        int s, t;
        cin >> s >> t;
        G[s].push_back(t);
        G[t].push_back(s);
    }
    art_points();

    return 0;
}

Measured memory_bytes: 6896
#include <iostream>

using namespace std;

int main()
{
    int x, y;
    int r;
    int W;
    int H;

    do {
        cin >> W >> H >> x >> y >> r;
    } while ((x < -100 || x > 100) || (y < -100 || y > 100) || 
             (W <= 0 || W > 100) || (H <= 0 || H > 100) || (r <= 0 || r > 100));

    if ((x - r >= 0 && x + r <= W) && (y - r >= 0 && y + r <= H)) {
         cout << "Yes" << endl;
    } else {
         cout << "No" << endl;
    }

    return (0);
}
            

Measured memory_bytes: 1160
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define mod 1000000007 //1e9+7
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 1001


int main(){
  int n,m;
  string u,t;
  set<string> dic;

  scanf("%d",&n);

  for(int i=0;i<n;i++){
    cin >> u;
    dic.insert(u);
  }

  scanf("%d",&m);


  bool f = false;
  for(int i=0;i<m;i++){
    cin >> t;

    if(dic.find(t)==dic.end()){
      cout << "Unknown " << t << endl;
    }else{
      if(f==false){
	cout << "Opened by " << t << endl;
      }else{
	cout << "Closed by " << t << endl;
      }

      f = !f;
    }
  }    

  return 0;
}

Measured memory_bytes: 3296
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}
const ll INF = 1LL << 60;

int main() {
    int a, b, c, x, y; cin >> a >> b >> c >> x >> y;
    if(a + b <= 2*c) {
        cout << a*x + b*y << endl;
        return 0;
    }
    ll ans = min(x, y) * 2 * c;
    if(x > y) ans += (x - y) * min(a, 2*c);
    else ans += (y - x) * min(b, 2*c);
    cout << ans << endl; 
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){ 
  ll a, v, b, w, t; cin >> a >> v >> b >> w >> t;
  bool fg = true;
  if(v <= w) fg = false;
  else{
    ll x = v-w;
    if(x*t<abs(a-b))fg = false;
  }
  if(fg) cout << "YES" << ln;
  else cout << "NO" << ln;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(){
	string a,b,c;
	cin >> a >> b >>c;
	if(a[a.size()-1]==b[0] && b[b.size()-1]==c[0]){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int f(int x, int y, int z) {
	return x * x + y * y + z * z + x * y + y * z + z * x;
}

int main() {
	string s,tmp;
	cin >> s;
	int n, tmpans = 0;
	bool flag = 1;
	n = s.size();
	vector<int> ans(n + 1);
	for (int i = 0; i < n; i++) {
		tmpans = 0;
		for (int j = 0; j < n - i; j++) {
			tmp = s.substr(j, i+1);
			flag = 1;
			for (char c : tmp) {
				if (c != 'A' && c != 'T' && c != 'G' && c != 'C') {
					flag = 0;
					break;
				}
			}
			if (flag == 1) {
				tmpans++;
			}
		}
		ans.at(i) = tmpans;
	}
	for (int i = 0; i < n; i++) {
		if (ans.at(i) != 0) {
			tmpans = i + 1;
		}
	}
	cout << tmpans << endl;
}

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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

const int dx[4] = {+1, 0, -1, 0};
const int dy[4] = {0, -1, 0, +1};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int a, b, c; cin >> a >> b >> c;
    if(a == b && b != c){
        cout << "Yes" << endl;
    }else if(b == c && c != a){
        cout << "Yes" << endl;
    }else if(c == a && a != b){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


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

public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc  = new Scanner(System.in);
		String S = sc.next();
		int count = 0;
		for(int i = 0; i < S.length(); i++) {
			count += (int)S.charAt(i) % 48;
		}
		
		if(S.length() - count < count) {
			count = S.length() - count;
		}
		System.out.println(count*2);
		sc.close();
	}
}


Measured memory_bytes: 24904
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define PER(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9+5)
#define INFLL ((LL)4e18)
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1LL << (x))
using namespace std;

bool operator>(const PLL &a, const PLL &b){
	return a.second > b.second;
}

bool operator<(const PLL &a, const PLL &b){
	return a.second > b.second;
}

bool compare(const PLL &a, const PLL &b){
	return a.first < b.first;
}

int main(){
	int N;
	int M;
	cin >> N >> M;
	vector<PLL> line(N);
	foreach(i, line)cin>>i.first>>i.second;
	sort(ALL(line), compare);
	priority_queue<int> que;
	LL ans = 0;
	int place=0;
	REPA(i, M+1){
		while(place < N && line[place].first <= i){
			que.push(line[place].second);
			++place;
		}
		if(que.empty())continue;
		ans += que.top();
		que.pop();
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2428
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
struct node
{
    int x, y;
} nd[20010];

int main()
{
    int h,n,dp[20010],s=0,k;
    scanf("%d %d",&h,&n);
    k = h;
    for(int i = 1; i <= n; i++)
    {
        scanf("%d %d",&nd[i].x,&nd[i].y);
    }
    for(int i = 1; i <= 10010; i++)
        dp[i] = INF;
    for(int i = 1; i <= n; i++)
        for(int j = nd[i].x; j <= 10010; j++)
            dp[j] = min(dp[j], dp[j-nd[i].x] + nd[i].y);;
    s = dp[h];
    for(int i = h+1; i <= 10010; i++)
    {
        if(s >= dp[i])
        {
            s = dp[i];
            k = i;
        }
    }
    printf("%d\n",s);
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,fruit[1001];
    while(cin>>n>>k)
    {
        long long sum=0;
        for(auto i=0; i<n; i++)
            cin>>fruit[i];
        sort(fruit,fruit+n);
        for(auto i=0; i<k; i++)
            sum+=fruit[i];
        cout<<sum<<'\n';
    }
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int main()
{   
    int n=5;
    int A[n];
    for(int i=0;i<n;i++)
    {
       cin>>A[i];
    }
    int c;
    for(int i=0;i<n;i++)
    {
        if(A[i]==0)
        {
           c=i+1;
        }   
    }
    cout<<c;
}


Measured memory_bytes: 3572
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int A = scan.nextInt();
        int B = scan.nextInt();
        boolean answer = (A * B % 2) != 0 ? true : false;
        System.out.println(answer ? "Yes" : "No");
    }
}


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

/* macros */
#define inf 1e9
#define int long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define vi vector<int>
#define vc vector<char>
#define vb vector<bool>
#define vt vector
#define pb push_back
#define fi first
#define se second
#define pi pair<int,int>
#define tc int t;cin>>t;while (t--){solve();}
#define gtc int t;cin>>t;int TC=1;while (t--) {cout << "Case #" << TC << ": " << solve() << "\n";TC++;}
#define gvtc int t;cin>>t;int TC=1;while (t--) {cout << "Case #" << TC << ": "; vsolve(); TC++;}
#define notc solve();
#define newline cout << "\n";
#define mod 1000000007
#define ret return 0;
#define sz(x) (int)x.size();
#define rep(i,a,b) for(int i=a;i<b;i++)
#define srt(x) sort(x.begin(), x.end())
#define rsrt(x) sort(x.rbegin(), x.rend())

string s,t;
int m,n;

int dp[3001][3001];

int lcs(string X,string Y,int m,int n) {
    if (m == 0 || n == 0) {
        return 0;
    }
    
    if (dp[m][n] != -1) {
        return dp[m][n];
    }
    
    if (X[m-1] == Y[n-1]) {
        return lcs(X,Y,m-1,n-1) + 1;
    }
    
    int op1 = lcs(X,Y,m-1,n);
    int op2 = lcs(X,Y,m,n-1);
    
    int ans = max(op1, op2);
    
    return dp[m][n] = ans;
}

string lcsstr() {
    memset(dp, 0, sizeof dp);
    for (int i=1;i<=m;i++) {
        for (int j=1;j<=n;j++) {
            if (s[i-1] == t[j-1]) {
                dp[i][j] = dp[i-1][j-1] + 1;
            }else {
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }
    int index = dp[m][n];
    string ans = string(index, 'a');
    int i=m,j=n;
    while (i>0 && j>0) {
        if (s[i-1] == t[j-1]) {
            ans[--index] = s[i-1];
            i--;
            j--;
        }else if (dp[i-1][j] > dp[i][j-1]) {
            i--;
        }else {
            j--;
        }
    }
    
    return ans;
}

void solve() {
    cin>>s>>t;
    m = sz(s);
    n = sz(t);
    memset(dp, -1, sizeof dp);
    string ans = lcsstr();
    cout << ans << "\n";
}

int32_t main(){
    fastio
    notc
    ret
}


Measured memory_bytes: 74024
def main():
  N=int(input())
  for h in range(1,3501):
    for n in range(1,3501):
      if 4*h*n>N*(h+n) and (N*h*n)%(4*h*n-N*(h+n))==0:
        print(h,n,(N*h*n)//(4*h*n-N*(h+n)))
        return
main()

Measured memory_bytes: 3060
n,a,b=map(int,input().split())
total=0
def sum_each(c):
    c=int(c)
    c2=list(str(c))
    total=0
    for i in range(len(c2)):
        total+=int(c2[i])
    return total

for i in range(1,n+1):
    if a<=sum_each(i)<=b:
        total+=i
print(total)

Measured memory_bytes: 3064
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
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 I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  a,b,c,d,e,f=LI()

  ans_n=-inf
  ans_pair=[0,0]
  xf=100*e/(100+e)
  for i in range(31):
    for j in range(31):
      for k in range(101):
        for l in range(101):
          xa=100*a*i+100*b*j
          xb=c*k+d*l

          # print(xa,xb)
          if xa+xb>f:
            break

          if xa+xb==0:
            continue

          xc=100*xb/(xa+xb)
          if xc>xf:
            continue

          if ans_n<xc:
            ans_n=xc
            ans_pair=[xa+xb,xb]

  return str(ans_pair[0])+' '+str(ans_pair[1])

# main()
print(main())


Measured memory_bytes: 5464
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

int main(void) {
    int n, m, ans;
    cin >> n;
    vector<int> t;
    for(int i = 0; i < n; i++) {
        int in;
        cin >> in;
        t.push_back(in);
    }
    cin >> m;
    vector<P> p;
    for(int i = 0; i < m; i++) {
        int l, r;
        cin >> l >> r;
        p.push_back(P(l, r));
    }

    for(int i = 0; i < m; i++) {
        ans = 0;
        for(int j = 0; j < n; j++) {
            if(j+1 == p[i].first) ans += p[i].second;
            else                ans += t[j];
        }
        cout << ans << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
//int -> ll
//http://web.mit.edu/~ecprice/acm/acm08/notebook.html#file12
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include<bits/stdc++.h>
typedef long long ll;
#define x first
#define y second
#define all(aaa) (aaa).begin(),(aaa).end()
#define REP(i,sss,eee) for(int i=sss;i<=eee;++i)
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
#define N 1000000007
using namespace __gnu_pbds;
using namespace std;
template <class T>
T MAX(T a, T b){return ((a>b)?a:b);}
template <class T>
T MIN(T a, T b){return ((a<b)?a:b);}
template <class T>
T MOD(T a){return ((a>=0)?a:(-1*a));}
template <class T>
void SWAP(T &a,T &b){T temp=a;a=b;b=temp;}

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

long long ex(long long a, long long b){
	if(b==0||a==1){return 1;}
	if(a==0||b==1){return a;}
	long long tmp=ex(a,(b/2));
	if(b%2){return ((((tmp*tmp)%N)*a)%N);}
	else{return ((tmp*tmp)%N);}
}
long long inv(long long k){
	if(k==1){return 1;}
	else{return ex(k,N-2);}
}
/*****************default********************/
int solve()
{
	std::vector<pii> v(3);
	std::vector<int> inp(4,0);
	REP(i,0,2)
	{
		cin>>v[i].x>>v[i].y;--v[i].x;--v[i].y;
		++inp[v[i].x];++inp[v[i].y];
	}
	if((inp[0]%2==1)&&(inp[1]%2==1)&&(inp[2]%2==1)){cout<<"NO\n";return 0;}
	cout<<"YES\n";
}
signed main(){
	speed
	int tt=1;
	//cin>>tt;
	while(tt--)
	{
		solve();
	}
	return 0;
}

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

#define ll long long
#define pb push_back
#define pii pair<ll, ll>
#define sz size()

// make sure :
// 1. pii is set to <ll, ll> 
// 2. n = 1 is taken care of
vector<pii> factorize(ll n) 
{
	vector<pii> ret;
	int count = 0;
	while(n % 2LL == 0)
	{ 
		n /= 2LL;
		count++; 
	}

	if(count) ret.pb({2, count});

	for(ll i=3;i*i<=n;i+=2)
	{ 
		count = 0; 
		while(n % i == 0)
		{ 
			count++; 
			n /= i; 
		}
		
		if(count) ret.pb({i, count});
	}
	if(n > 2) ret.pb({n, 1});
	return ret;
}

int main()
{
	ios::sync_with_stdio(0);
	int i, j, k;

	ll n;
	cin >> n;

	if(n == 1)
	{
		cout << '0';
		return 0;
	}

	vector<pii> fac = factorize(n);

	ll ans = 0;
	for(auto x : fac)
	{
		for(i=1;i<=42;++i)
			if(i * (i + 1) / 2 <= x.second)
				ans++;
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 3612
import java.util.Arrays;
import java.util.Scanner;

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

		int N = scan.nextInt();
		int X = scan.nextInt();
		int[]x = new int[N];
		for(int i = 0; i < N; i++) {
			x[i] = scan.nextInt();
		}
		scan.close();
		if(N == 1) {
			int ans = Math.abs(X - x[0]);
			System.out.println(ans);
			System.exit(0);
		}else if(N == 2) {
			int l = Math.abs(x[0] - x[1]);
			int l1 = Math.abs(x[0] - X);
			int l2 = Math.abs(x[1] - X);
			if(l1 % l != 0 && l2 % l != 0) {
				System.out.println(1);
			}else {
				System.out.println(l);
			}
			System.exit(0);
		}
		Arrays.sort(x);
		int[] k = new int[N - 1];
		for(int i = 0; i < N - 1; i++) {
			k[i] = x[i + 1] - x[i];
		}
		int g = gcd(k[0], k[1]);
		for(int i = 2; i < N - 1; i++) {
			g = gcd(g, k[i]);
		}

		int m = g;
		int []r = new int[N];
		for(int i = 0; i < N; i++) {
			r[i] = Math.abs(X - x[i]);
		}

		for(int i = 0; i < N; i++) {
			if(r[i] % m != 0) {
				System.out.println(1);
				System.exit(0);
			}
		}
		System.out.println(m);


	}
	static int gcd(int m, int n) {
	    if(m < n) return gcd(n, m);
	    if(n == 0) return m;
	    return gcd(n, m % n);
	}
}

Measured memory_bytes: 51100
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

ll n,q;
vector<ll>V,W,v,L;
ll dp[1100][100010];

int main(){
    cin >> n;
    V.resize(n);
    W.resize(n);
    rep(i,n)cin>>V[i]>>W[i];
    cin >> q;
    v.resize(q);
    L.resize(q);
    rep(i,q){
        cin>>v[i]>>L[i];
        v[i]--;
    }
    rep(i,min(n,1024LL)){
        if(i==0){
            rep(j,100010){
                if(j-W[0]<0)continue;
                dp[0][j]=V[0];
            }
        }
        else{
            ll p = (i-1)/2;
            rep(j,100010){
                dp[i][j]=dp[p][j];
                if(j-W[i]<0)continue;
                chmax(dp[i][j],dp[p][j-W[i]]+V[i]);
            }
        }
    }
    rep(i,q){
        if(v[i]<1024){
            ll ans = dp[v[i]][L[i]];
            cout << ans << endl;
        }
        else{
            ll now = v[i];
            ll ans = 0;
            int d = 0;
            ll tmp = now;
            while(tmp>0){
                tmp--;
                tmp/=2;
                d++;
            }
            d -= 9;
            for(int bit = 0;bit<(1<<d);bit++){
                ll weight=0,value=0;
                ll cd = now;
                rep(j,d){
                    if((bit>>j)&1){
                        weight += W[cd];
                        value += V[cd];
                        cd = (cd-1)/2;
                    }
                    else{
                        cd = (cd-1)/2;
                    }
                }
                if(L[i]-weight<0)continue;
                chmax(ans,dp[cd][L[i]-weight]+value);
            }
            cout << ans << endl;
        }
    }


    return 0;
}


Measured memory_bytes: 808868
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let a: Vec<i32> = (0..n).map(|_| read()).collect();
    println!("{}", a.iter().max().unwrap() - a.iter().min().unwrap());
}

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


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

#define REP(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define REPS(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define RREP(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define RREPS(i, n) for (int i = ((int)(n)); i > 0; i--)
#define IREP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define IREPS(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVISORT(v) sort(v.begin(), v.end(), greater<int>());
#define ALL(v) v.begin(), v.end()

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using ll = long long;

typedef long long ll;

template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

const ll mod=1e9+7;

int main()
{
    cin.tie( 0 );
    ios::sync_with_stdio( false );
	
	int n;
	cin>>n;
	VI v;
	REP(i,n){
		int p;cin>>p;
		v.push_back(p);
	}
	VSORT(v);

	int ans=v[n/2]-v[n/2-1];
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <queue>
#include "math.h"
#include <complex>
#include <iomanip>
#include <map>
#define ifor(i,a,b) for (int i=(a);i<(b);i++)
#define rfor(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define rep(i,n) for (int i=0;i<(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
using namespace std;
typedef long double ld;
typedef long long int  lli;
const double eps = 1e-11;
lli MOD=1000000007;
//Ax=bをとくAは正方行列
//rankA<=min(m,n)ならば配列０のvecが帰る

lli fact[10050],factinv[10050];
lli powm(lli a,lli p,lli mod){
  lli ans =1;
  while(p>0){
    if(p&1)ans=(ans*a) % mod;
    a=(a*a)%mod;
    p >>=1;
  }
  return ans%mod;
}

lli inv(lli a){
  return  powm(a,MOD-2,MOD);
}
lli gcd(lli A,lli B){
  if(A%B==0)return B;
  else return gcd(B,A%B);
}

lli cmb(lli a,lli b ){
  lli ans =1;
  rep(i,b){
    ans = ans %MOD* (a-i)%MOD*inv(b-i)%MOD;
  }
  return ans ;
}
lli comb(lli a,lli b){
    return fact[a]%MOD*factinv[b]%MOD*factinv[a-b]%MOD;
}


int main(){
        int N;
        int a[200005],b[200005];
        cin >> N;
        factinv[0]=fact[0]=1;

        rep(i,10020) {
            fact[i+1]=fact[i]*(i+1);
            fact[i+1]%=MOD;
            factinv[i+1]=factinv[i]%MOD*inv(i+1)%MOD;
            factinv[i+1]%=MOD;
        }

        rep(i,N)cin >> a[i]>>b[i];
        lli g[4040][4040];
        rep(i,N){
          g[2010-a[i]][2010-b[i]]++;
        }
        rep(i,4030)rep(j,4030){
          g[i+1][j+1]+=g[i][j+1]%MOD+g[i+1][j]%MOD;
          g[i+1][j+1]%=MOD;
        }
        lli ans =0;
        rep(i,N){
          ans+= g[2010+a[i]][2010+b[i]]%MOD;
          ans%=MOD;
        }

        rep(i,N){
          ans += MOD-comb(2*a[i]+2*b[i],2*a[i])%MOD;
          ans %=MOD;
        }
    if(ans&1)ans+=MOD;
        cout << ans/2 << endl;
}


Measured memory_bytes: 129280
#include<stdio.h>
#define MAX 100000

int parent(int i) { return i/2;}
int left(int i) { return 2*i;}
int right(int i){ return 2*i+1;}

int main(){
    int H,i,A[MAX+1];
    scanf("%d",&H);
    for(i=1;i<=H;i++) {
        scanf("%d",&A[i]);
    }
    
    for(i=1;i<=H;i++) {
        printf("node %d: key = %d, ",i,A[i]);
        if(parent(i) >= 1) printf("parent key = %d, ",A[parent(i)]);
        if((left(i) <= H) && (A[left(i)]!=0)) printf("left key = %d, ",A[left(i)]);
        if((right(i) <= H) && (A[right(i)]!=0)) printf("right key = %d, ",A[right(i)]);
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2056
#include <iostream>
#include <iomanip>
using namespace std;
double dp[3005][3005];
int main()
{
    int n;
    double p[3005],rez=0.0;
    cin >> n;
    for (int i=1;i<=n;i++)
    {
        cin >> p[i];
    }
    dp[0][0]=1;
    for (int i=1;i<=n;i++)
    {
        for (int j=0;j<=i;j++)
        {
            if (j!=0) dp[i][j]=dp[i-1][j-1]*p[i];
            dp[i][j]+=dp[i-1][j]*(1-p[i]);
        }
    }
    for (int i=1;i<=n;i++)
    {
        if (i>n-i) rez+=dp[n][i];
    }
    cout << fixed << setprecision(10) << rez;
}


Measured memory_bytes: 68992
fn run() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let n: u64 = s.trim().parse().unwrap();
    let mut ans = n - 1;
    for k in 2.. {
        if k * k > n {
            break;
        }
        if n % k == 0 {
            ans = n / k + k - 2;
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}

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

int main(){
  int N;
  cin >> N;
  
  int M = N;
  int ketaSum = 0;
  
  while(M > 0){
    ketaSum += M % 10;
    M /= 10;
  }
  
  if(N % ketaSum == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

int main() {
    int x,n; cin >> x >> n;
    map<int,bool> c;
    for(int i=0; i<n; ++i) {
        int p; cin >> p;
        c[p] = true;
    }

    for(int i=x, j=x; ; --i, ++j) {
        if(c.count(i) == 0) {
            cout << i << '\n';
            return 0;
        }
        if(c.count(j) == 0) {
            cout << j << '\n';
            return 0;
        }
    }
}

Measured memory_bytes: 3636
//package cp;
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
	BigInteger bi1=new BigInteger("2");//initialize as string
//	1.BigInteger bi=new BigInteger(Readers.next());- take input as biginteger
	StringBuilder sb=new StringBuilder();
//	2.StringBuilder temp=new StringBuilder(str[i-1]);
//	3.String rev=temp.reverse().toString(); convert sb to string
//	4.if(str[i].compareTo(rev)>=0)minn=0;-compare two Strings
//  5.(Initialize as string) - (a.add(b)) - (array initialized with null and not 0)
	Integer[] ARRE=new Integer[5];//Integer sort-TLE-Initialize object elements i.e a[0].
	static final int mod1 = 1000000007;//or 1e9+7
//	6.System.exit(0); to exit from code....esp in recur 
	long gcd(long a,long b) {if(b==0)return a;else return gcd(b,a%b);}
	long ceil(double d) {return (long)Math.ceil(1.0*d);}
	int ch_int(char c) {return Integer.parseInt(String.valueOf(c));}//change char to Integer
	String ch_str(char c) {return String.valueOf(c);}
	String int_str(int num) {return Integer.toString(num);}
	void divisor(long n,int start) {
		int cnt=0;for(int i=start;i<=Math.sqrt(n);i++) {
		if(n%i==0) {if(i==n/i)cnt++;else cnt+=2;}}}
	public static void main(String[] args) throws IOException {	
		PrintWriter out = new PrintWriter(System.out);
		Readers.init(System.in);
		Main obj=new Main();
		long x=Readers.nextLong();
		long k=Readers.nextLong();
		long d=Readers.nextLong();
		if(x>=0) {
			if(k<=x/d) {
				System.out.println(x-1L*k*d);
			}
			else {
				long ans=x%d;
				long cnt=x/d;
				if(k%2==cnt%2) {
					System.out.println(ans);
				}
				else {
//					System.out.println("yep");
					System.out.println(Math.abs(ans-d));
				}
			}
		}
		else {
			if(k<=-x/d) {
				System.out.println(Math.abs(x+1L*k*d));
			}
			else {
				long ans=-x%d;
				long cnt=-x/d;
				if(k%2==Math.abs(cnt%2)) {
					System.out.println(Math.abs(ans));
				}
				else {
//					System.out.println("oh");
					System.out.println(Math.abs(Math.abs(ans)-d));
				}
			}
		}
		out.flush();
	}
}
class Readers {
 
    static BufferedReader reader;
 
    static StringTokenizer tokenizer;
 
 
 
    /** call this method to initialize reader for InputStream */
 
    static void init(InputStream input) {
 
        reader = new BufferedReader(
 
                     new InputStreamReader(input) );
 
        tokenizer = new StringTokenizer("");
 
    }
 
 
 
    /** get next word */
 
    static String next() throws IOException {
 
        while ( ! tokenizer.hasMoreTokens() ) {
 
            //TODO add check for eof if necessary
 
            tokenizer = new StringTokenizer(
 
                   reader.readLine() );
 
        }
 
        return tokenizer.nextToken();
 
    }
 
 
 
    static int nextInt() throws IOException {
 
        return Integer.parseInt( next() );
 
    }
 
	
 
    static double nextDouble() throws IOException {
 
        return Double.parseDouble( next() );
 
    }
    
    
    static long nextLong() throws IOException{
    	
		return Long.parseLong(next());
	}
 
}


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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;

//===




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

	int L; cin >> L;
	
	int r = 0;
	while (L >= (1 << r)) ++r;
	--r;

	vector<pair<Pii, int>> edges;
	for (int i = 0; i < r; ++i) {
		edges.emplace_back(make_pair(i + 1, i + 2), 0);
		edges.emplace_back(make_pair(i + 1, i + 2), (1 << i));
	}

	int R = (1 << r);
	for (int i = r - 1; i >= 0; --i) {
		int s = L - (1 << i);
		if (s >= R) {
			edges.emplace_back(make_pair(i + 1, r + 1), s);
			L = s;
		}
	}

	cout << r + 1 << " " << edges.size() << "\n";
	for (const auto& e : edges) {
		cout << e.first.first << " " << e.first.second << " " << e.second << "\n";
	}

	return 0;
}

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

#define M 1000000007
#define MM 998244353 
#define ll long long 
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define PI 3.1415926536
#define INF 2e18
#define endl "\n"

ll power(ll b,ll e,ll m)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b%m,e/2,m)%m;
	return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b,e/2);
	return power(b*b,e/2);
}
ll ansfunc(string n,int k)
{
	if(n.length()<k)return 0;
	if(k==1)
	{
		string t=n;t.erase(t.begin());
		if(n[0]!='0')
			return (n[0]-'0')+(n.length()-1)*9;
		else return ansfunc(t,1);
	}
	if(k==2)
	{
		ll ans=0;
		string t=n;t.erase(t.begin());
		if(n[0]!='0')
		{
			ans+=(n[0]-'0'-1)*(n.length()-1)*9;ans+=(n.length()-2)*(n.length()-1)/2*81;
			ans+=ansfunc(t,1);
		}
		else
		ans+=ansfunc(t,2);
		return ans;
	}
	if(k==3)
	{
		ll ans=0,len=n.length();
		string t=n;t.erase(t.begin());
		if(n[0]!='0')
		{
			ans+=(n[0]-'0'-1)*(len-1)*(len-2)/2*81;ans+=(n.length()-1)*(n.length()-2)*(n.length()-3)/6*9*9*9;
			ans+=ansfunc(t,2);
		}
		else
		ans+=ansfunc(t,3);
		return ans;
	}
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string n;
	int k;
	cin>>n>>k;
	cout<<ansfunc(n,k);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
  
int main(void) {
  int r, D, before_weight, after_weight;
  
  cin >> r;
  cin >> D;
  cin >> before_weight;
  
  for(int loop=0; loop < 10; loop++) {
    after_weight = r * before_weight - D;
    cout << after_weight << "\n";
    before_weight = after_weight;
  }
  
  return 0;
}

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


/// File input & output /////
#define fRead(x)        freopen("x.txt","r",stdin)
#define fWrite(x)       freopen ("x.txt","w",stdout)


#define ld              long double
#define ll              long long
#define ull             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())


#define FASTIO        ios_base::sync_with_stdio(0);cin.tie(nullptr);




///..................Sort by second element in a pair in decending order............. ///
bool SortbySecDesc(const pair<long long,long long > &a, const pair<long long,long long > &b)
{
    return a.second>b.second;
}

///.........................first element of pair in descending order..........................//////
bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
    return (a.first > b.first);
}



///.............................................................TEMPLATE................................................./////

int main()
{
    FASTIO;
    ll n, m;

    cin >> n >> m;


    ll a[n+1];

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

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

    sort(a,a+n);


    ll sum = 0;

    for(int i=0; i<n-m; i++)
    {
        sum += a[i];
    }





    cout << sum << endl;










    return 0;
}



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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define dbg(x) cout<<#x" = "<<(x)<<ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

ll n, u, l;

int main() {
	cin >> n;
	repst(i,1,3500) {
		repst(j,1,3500) {
			u = n*i*j;
			l = 4*i*j - n*(i+j);
			if (l>0 && u%l==0 && u/l>0) {
				cout << i << " " << j << " " << u/l << ln;
				return 0;
			}
		}
	}
}

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

//def
#define debug(x) cout << #x << ": " << x << '\n'
#define out(x) cout << x << '\n'
#define repeat(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revrepeat(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(all(a), greater<int>());
    auto comPair = [](const P &firstElof, const P &secondElof) {
        int m1 = min(firstElof.first, firstElof.second);
        int m2 = min(secondElof.first, secondElof.second);
        return m1 < m2;
    };
    priority_queue<P, vector<P>, decltype(comPair)> que(comPair);

    ll ans = a[0];
    que.emplace(a[0], a[1]);
    que.emplace(a[0], a[1]);
    repeat(i, 2, n) {
        auto p = que.top();
        que.pop();

        ans += min(p.first, p.second);

        que.emplace(p.first, a[i]);
        que.emplace(p.second, a[i]);
    }
    out(ans);
    return 0;
}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, p;
  while (cin >> n >> p) {
    vector<int> a(n);
    each (i, a) cin >> i;

    const int N = n + 1;
    lli dp[N][2];
    fill(&dp[0][0], &dp[N - 1][2 - 1] + 1, 0);
    dp[0][0] = 1;

    for (int i = 0; i < n; ++i) {
      dp[i + 1][(0 + a[i]) % 2] += dp[i][0];
      dp[i + 1][(1 + a[i]) % 2] += dp[i][1];

      dp[i + 1][0] += dp[i][0];
      dp[i + 1][1] += dp[i][1];
    }

    cout << dp[n][p] << endl;
  }
  
  return 0;
}


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

#define times(n, i)      uptil(0, n, i)
#define upto(f, t, i)    for(decltype(t) _##i = (t), i = (f); i <= _##i; i++)
#define uptil(f, t, i)   for(decltype(t) _##i = (t), i = (f); i < _##i; i++)
#define downto(f, t, i)  for(decltype(t) _##i = (t), i = (f); i >= _##i; i--)
#define downtil(f, t, i) for(decltype(t) _##i = (t), i = (f); i > _##i; i--)
#define unless(c) if(!(c))
#define until(c) while(!(c))
#define loop while(true)

#define all(v) v.begin(), v.end()
#define ln << "\n"

struct line{};

template<class T> istream& operator>>(istream& in, vector<T>& v) {
    times(v.capacity(), i) in >> v[i];
    return in;
}

template<class T> const ostream& operator<<(ostream& out, const vector<T>& v) {
    times(v.size(), i) out << (i ? " " : "") << v[i];
    return out;
}

template<class T, class...U> typename enable_if<is_same<T, line>::value, string>::type next(istream& in, const U&... args) {
    string s;
    getline(in, s, args...);
    return move(s);
}

template<class T, class...U> typename enable_if<!is_same<T, line>::value, T>::type next(istream& in, const U&... args) {
    T t(args...);
    in >> t;
    return move(t);
}
template<class T, class...U> auto next(const U&... args) -> decltype(next<T>(cin)) {
    return next<T>(cin, args...);
}

template<class T> T sum(const vector<T>& v) {
    T ans = T();
    for(const T& t : v) ans += t;
    return ans;
}

template<class T> T sum(const typename vector<T>::iterator& begin, const typename vector<T>::iterator& end) {
    T ans = T();
    for(typename vector<T>::iterator t = begin; t != end; t++) ans += *t;
    return ans;
}

template<class T> T min(const vector<T>& v) {
    return *min_element(v.begin(), v.end());
}

template<class T> T min(const typename vector<T>::iterator& begin, const typename vector<T>::iterator& end) {
    return *min_element(begin, end);
}

template<class T> T max(const vector<T>& v) {
    return *max_element(v.begin(), v.end());
}

template<class T> T max(const typename vector<T>::iterator& begin, const typename vector<T>::iterator& end) {
    return *max_element(begin, end);
}

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

    auto S = next<string>();
    auto N = next<int>();
    int ans = 0;
    times(N, i) {
        auto R = next<string>();
        ans += (R + R).find(S, 0) != string::npos;
    }
    cout << ans ln;

    return 0;
}

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

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

using namespace std;

typedef long long ll;
typedef long double ld;

#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(),v.end()

const int maxn = 1e5 + 100;
const ll inf = 2e18, mod = 1e9 + 7;

int n, b[maxn], seg[4 * maxn];
ll k, a[maxn], l[maxn], r[maxn], dp[maxn];
vector<ll> compress;

void update(int u, int l, int r, int b, int e, int val) { 
	if (b >= compress.size() || b >= e) {
		return;
	}
	
	if (b <= l && r <= e) {
		seg[u] = min(seg[u], val);
		return;
	}

	int mid = (l + r) / 2;

	if (b < mid) {
		update(2 * u, l, mid, b, e, val);
	}
	if (e > mid) {
		update(2 * u + 1, mid, r, b, e, val);
	}
}

int query(int u, int l, int r, int x) {
	if (r - l == 1) {
		return seg[u];
	}

	int mid = (l + r) / 2;
	if (x < mid) {
		return min(seg[u], query(2 * u, l, mid, x));
	}
	else {
		return min(seg[u], query(2 * u + 1, mid, r, x));
	}
}

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

	fill(seg, seg + 4 * maxn, mod);

	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
		if (b[i] == 1 && 2 * a[i] > k) {
			cout << "-1" << endl;
			return 0;
		}

		if (i) {
			a[i] += a[i - 1];
		}
		if (b[i] == 1) {
			l[i] = (-2 * (i ? a[i - 1] : 0) % k + k) % k;
			r[i] = (-2 * a[i] % k + k) % k;
		}
		else {
			l[i] = 0;
			r[i] = k - 1;
		}
		compress.pb(l[i]);
		compress.pb(r[i]);
	}
	sort(all(compress));
	compress.resize(unique(all(compress)) - compress.begin());

	for (int i = 0; i < n; i++) {
		l[i] = lower_bound(all(compress), l[i]) - compress.begin();
		r[i] = lower_bound(all(compress), r[i]) - compress.begin();
	}

	for (int i = n - 1; i >= 0; i--) {
		int pos = query(1, 0, compress.size(), l[i]);
		if (pos < n) {
			dp[i] = dp[pos] + (compress[l[pos]] - compress[l[i]] + k) % k;
		}
		else {
			dp[i] = 0;
		}

		if (l[i] <= r[i]) {
			update(1, 0, compress.size(), r[i] + 1, compress.size(), i);
			update(1, 0, compress.size(), 0, l[i], i);
		}
		else {
			update(1, 0, compress.size(), r[i] + 1, l[i], i);
		}
	}

	ll ans = inf;
	for (int i = 0; i < compress.size(); i++) {
		int val = query(1, 0, compress.size(), i);
		if (val >= n) {
			ans = 0;
		}
		else {
			ans = min(ans, dp[val] + (compress[l[val]] - compress[i] + k) % k);
		}
	}

	cout << ans + (2 * a[n - 1]) << endl;
}



Measured memory_bytes: 9980
-- Ball
import Control.Monad

main = readLn
  >>= (\ n -> replicateM n getLine)
  >>= putStr . solve

solve :: [String] -> String
solve = unlines . map(tellYesNo . dfs 0 0. map read . words)

dfs :: Int -> Int -> [Int] -> Bool
dfs _ _ [] = True
dfs l r (x:xs)
  | l < x && r < x = dfs x r xs || dfs l x xs
  | l < x = dfs x r xs
  | r < x = dfs l x xs
  | otherwise = False

tellYesNo :: Bool -> String
tellYesNo b
  | b == True = "YES"
  | otherwise = "NO"

Measured memory_bytes: 4012
#include <iostream>
#include <vector>
#define ll long long
using namespace std;
int main()
{
int n;
cin>>n;
n=n%10;
if(n==2 ||n==4 || n==5 ||n==7 || n==9)cout <<"hon";
else if(n==0 ||n==1 || n==6 ||n==8)cout <<"pon";
else if(n==3)cout <<"bon";


}

Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putbd cout << "---------------------------------------------" << endl;
#define putln(x) cout << x << endl;
#define debug(x) cerr << #x << "=" << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef complex<double> comp;
typedef vector <int> vec;
typedef vector <ll> vecll;
typedef vector <double> vecd;
typedef vector <vec> mat;
typedef vector <vecll> matll;
typedef vector <vecd> matd;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 200020;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const ll INFL = 1e18;
const ll MOD = 1000000007;

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

//********************************template END****************************************//

void solve(void)
{

	int N, M, Q;
	cin >> N >> M >> Q;

	mat dp(N+2, vec(N+2, 0));

	while(M--)
	{
		int l, r;
		cin >> l >> r;
		dp[l][r]++;
	}

	rep(N+2, j) rep(N+1, i)
	{
		dp[i+1][j] += dp[i][j];
	}
	rep(N+2, i) rep(N+1, j)
	{
		dp[i][j+1] += dp[i][j];
	}

	while(Q--)
	{
		int p, q;
		cin >> p >> q;
		cout << dp[q][q] - dp[p-1][q] - dp[q][p-1] + dp[p-1][p-1] << endl;
	}


}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


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

using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long

int main()
{
  IOS;
  int n;
  cin >> n;
  int freq[n];
  map<string, int> arr;
  for (int i=0; i<n; i++)
    {
      string s;
      cin >> s;
      arr[s]+=1;
    }
  int mx=0;
  for (const auto& x: arr)
    {
      int q=x.second;
      if (q>mx)
	mx=q;
    }
  for (auto it=arr.begin(); it!=arr.end(); it++)
    {
      if (it->second==mx)
	cout << it->first << endl;
    }
  return 0;
}


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
const ul mod = 1000000007;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    ll n = s.length();
    if (s[n - 1] != 's') {
        cout << s << "s" << endl;
    } else {
        cout << s << "es" << endl;
    }
    return 0;
}



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

using namespace std;

int a[3][100];
int dp[3][100];

int n;

int main()
{
    cin >> n;

    int i, j;
    for(i = 1; i <= 2; i ++)
    {
        for(j = 1; j <= n; j ++)
            cin >> a[i][j];
    }

    for(i = 1; i <= 2; i ++)
    {
        for(j = 1; j <= n; j ++)
        {
            dp[i][j] = a[i][j];

            if(j - 1 > 0)
                dp[i][j] = max(dp[i][j], dp[i][j - 1] + a[i][j]);

            if(i - 1 > 0)
                dp[i][j] = max(dp[i][j], dp[i - 1][j]  + a[i][j]);
        }
    }

    cout << dp[2][n] << "\n";

    return 0;
}


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

using namespace std;

int main(){
    int A, B; cin >> A >> B;
    string S; cin >> S;

    bool f = true;
    for (int i = 0; i < S.length(); i++){
        if (i == A){
            if (S[i] != '-'){
                f = false;
            }
        }else{
            int a = S[i] - '0';
            if (a < 0 || a > 9){
                f = false;
            }
        }
        
        if (f == false){
            cout << "No" << endl;
            break;
        }
    }
    
    if (f == true){
        cout << "Yes" << endl;
    }
    

    return 0;
}

Measured memory_bytes: 256