akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
#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 REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    ll ans = 0; 
    ll a;
    bool r = false;
    REP(i, n) {
        cin >> a;
        if (r and a > 0) {
            ans++;
            a--;
        }
        ans += a / 2;
        r = (a % 2 == 1);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3628
O = list(input())
E = list(input())
str = ''

if(len(O) == len(E)):
  for i in range(len(O)):
    str += O[i]
    str += E[i]
  print(str)
else:
  for i in range(len(O)):
   if(i != len(O)-1):
    str += O[i]
    str += E[i]
   else:
    str += O[i]
  print(str)

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

typedef long long ll;

using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(0)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define YesNo(x)      cout << ((x) ? "Yes" : "No") << endl
#define YESNO(x)      cout << ((x) ? "YES" : "NO") << endl
#define absi(x)       ( ((x) >= 0) ? (x) : (-(x)) )

int main(int argc, const char* argv[]) {
	ll n, k;
	cin >> n >> k;

	if(k > (n - 2) * (n - 1) / 2) {
		cout << -1 << endl;
		return 0;
	}

	ll t = (n - 2) * (n - 1) / 2;
	cout << (n - 1) + t - k << endl;

	repd(i, 2, n + 1) {
		cout << "1 " << i << endl;
	}


	repd(i, 2, n) {
		repd(j, i + 1, n + 1) {
			if(t == k) return 0;
			cout << i << " " << j << endl;
			--t;
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 0;
vector<ll> v;
void dfs(ll a){
  if(a>3234566667)return;
  v.push_back(a);
  if(a%10!=9)dfs(a*10+a%10+1);
  if(a%10!=0)dfs(a*10+a%10-1);
  dfs(a*10+a%10);
}
int main()
{
  ll k ;
  cin >> k ;
  rep(i,9)dfs(1+i);
  sort(v.begin(),v.end());
  cout << v[k-1] << endl;
  return 0;
}


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

int N;
vector<int> C;

int main(void) {
	cin >> N;
	if (N == 1) {
		cout << "1\n";
		return 0;
	}

	C.resize(N + 1, 0);
	for (int x = 1; x <= N; ++x) {
		if (x % 2 != 0)
			continue;
		int y = x;
		while (y % 2 == 0) {
			y /= 2;
			++C[x];
		}
	}

	vector<int>::iterator it = max_element(C.begin(), C.end());
	size_t id = distance(C.begin(), it);

	cout << id << '\n';
	return 0;
}


Measured memory_bytes: 256
s = list(input())
judge = 0
n = len(s)
if s != s[-1::-1]:
    judge +=1

if s[0:(n-1)//2] != s[(n-3)//2::-1]:
    judge +=1

if s[(n+1)//2:n] != s[n-1:(n-1)//2:-1]:
    judge +=1

if judge >0:
    print("No")
else:
    print("Yes")

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

int main(){
	int n;
  	cin >> n;
  
  	if(n % 2 == 0){
      cout << n / 2 << endl; 
    } else {
      cout << n / 2 + 1 << endl;
    }
}

Measured memory_bytes: 256
def g_c_d(x, y):
    if y == 0:
        return x
    else:
        return g_c_d(y, x % y)


def l_c_d(x, y):
    return x * y // g_c_d(x, y)


a, b, c, d = map(int, input().split())
e = l_c_d(c, d)
print((b - a + 1) - (b // c - (a - 1) // c + b // d - (a - 1) // d - b // e + (a - 1) // e))


Measured memory_bytes: 3060
#include <iostream>
#include <map>

using namespace std;

long long acc[200001];

int main(){
  int n;
  long long prev = 0;
  long long total = 0;
  map<long long, int> m;
  m[0] = 1;
  cin >> n;
  for (int i=0;i<n;i++) {
    long long a;
    cin >> a;
    acc[i] = a + prev;
    if (m.find(acc[i]) == m.end()) {
      m[acc[i]] = 0;
    }


    total += m[acc[i]];
    m[acc[i]]++;
    prev = acc[i];

  }
  cout << total << endl;
  return(0);
}


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

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

			
     

         
            


Measured memory_bytes: 256
n = gets.to_i
yen = 0
bit = 0
n.times do
  x1,u1 = gets.strip.split
  x = x1.to_f
  u = u1.to_s
  if u == "JPY"
    yen += x
  else
    bit += x
  end
end
puts yen+bit*380000

Measured memory_bytes: 14244
#include<stdio.h>
int main(void)
{
	int x,y,i;
	for(i=1;i<3000;i++){
		scanf("%d %d",&x,&y);
		if(x<y){
			printf("%d %d\n",x,y);
		}
		if(x>y){
			printf("%d %d\n",y,x);
		}
		if(x==y&&x!=0){
			printf("%d %d\n",x,y);
		}
		if(x==0&&y==0){
			break ;
		}
	}
	return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a,b,i;
		String str1,str2;
		while(true){
			a=sc.nextInt();
			b=sc.nextInt();
			if(a==0&&b==0)System.exit(0);
			str1="";
			str2="";
			for(i=0;i<b;i++){
				str1=str1+"#";
				if(i==0 || i==b-1)
					str2=str2+"#";
				else
					str2=str2+".";
			}
			for(i=0;i<a;i++){
				if(i==0 || i==a-1)
					System.out.println(str1);
				else
					System.out.println(str2);
			}
			System.out.println();
		}
	}
}


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

//ABC 083 B-1
int main()
{
	int n,a,b,x=0;
	cin>>n>>a>>b;
	for(int i=1; i<=n; i++){
		int t=i,s=0;
		while(t!=0){
			s+=t%10;
			t=t/10;	
		}
		if(s>=a && s<=b){
			x+=i;
		}
	}
	cout<<x<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
struct magic{
    int a,b;
};

int main(){

    int A[1001],B[1001],h,n,ans=2147483647,y,minc=100000,mina=1000000;
    double x=0;
    cin>>h>>n;
    REP(i,n){
        cin>>A[i]>>B[i];
        minc=min(minc,B[i]);
        mina=min(mina,A[i]);
    }

	int table[h+1+mina];
	for(int i=0; i < h+1+mina; i++)table[i] = 1e9;
    table[0]=0;

	REP(i,n){
        REP(j,h) {
            int cc = min(h,j+A[i]);
            table[cc] = min(table[cc],table[j]+B[i]);
        }
    }

	printf("%d\n",table[h]);

	return 0;
}

Measured memory_bytes: 256
n = int(input())   
ab = [list(map(int, input().split())) for _ in range(n)] 

edge=[ab[0][0],ab[0][1],ab[0][0],ab[0][1],ab[0][0],ab[0][1],ab[0][0],ab[0][1]]
tate = 0
yoko = 0
summ = 10**10
sumn = 0

for i in range(n):
    x = ab[i][0]
    y = ab[i][1]
    if x+y <= summ :
        edge[0] = x
        edge[1] = y
        summ = x+y
    if x+y >= sumn :
        edge[2] = x
        edge[3] = y
        sumn = x+y
    if x-y <= tate:
        edge[4] =x
        edge[5] =y
        tate = x-y
    if y-x <= yoko:
        edge[6] =x
        edge[7] =y
        yoko = y-x

a = abs(edge[0]-edge[2]) +abs(edge[1]-edge[3])
b = abs(edge[0]-edge[4]) +abs(edge[1]-edge[5])
c = abs(edge[0]-edge[6]) +abs(edge[1]-edge[7])
d = abs(edge[2]-edge[4]) +abs(edge[3]-edge[5])
e = abs(edge[2]-edge[6]) +abs(edge[3]-edge[7])
f = abs(edge[4]-edge[6]) +abs(edge[5]-edge[7])

print(max(a,b,c,d,e,f))

Measured memory_bytes: 45460
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int>h(n);
	rep(i, n) {
		cin >> h[i];
	}
	int ans = 0;
	int now = 0;
	h[n] = 1e9 + 100;
	rep(i,n) {
		if (h[i]>=h[i+1]) {
			now++;
		}
		else {
			ans = max(ans, now);
			now = 0;
		}
	}
	cout << ans << endl;
	return 0;
}


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

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


Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define loop(i,a,b) for(ll i=a; i<b; i++)
#define revloop(i,a,b) for(ll i=a; i>=b; i--)
#define pb push_back
#define vl vector<ll>
#define vvl vector<vl>
#define pl pair<ll,ll>
#define vpl vector<pl>
#define all(c) (c).begin(), (c).end()
#define sz(a) ll((a).size())
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i!=(c).end(); i++))
#define mp make_pair
int main()
{
   ll n;
   cin>>n;
   vl a(n), b(n), c(n);
   loop(i,0,n)
   {
   	cin>>a[i]>>b[i]>>c[i];
   }
   ll dp[3][n];
   dp[0][0]=a[0];
   dp[1][0]=b[0];
   dp[2][0]=c[0];
   loop(i,1,n)
   {
   	dp[0][i] = a[i] + max(dp[1][i-1], dp[2][i-1]);
   	dp[1][i] = b[i] + max(dp[0][i-1], dp[2][i-1]);
   	dp[2][i] = c[i] + max(dp[0][i-1], dp[1][i-1]);
   }
   cout<<max(dp[0][n-1], max(dp[1][n-1], dp[2][n-1]));
	return 0;
}

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

ll MOD = 1e9+7;

ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        res %= MOD;
        a = a * a;
        a %= MOD;
        b >>= 1;
    }
    return res;
}

ll inverse(ll n) {
    return binpow(n, MOD-2);
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll N; cin >> N;
	vll arr (N);
	F0R(i, N) cin >> arr[i];
	
	ll onLeft = 0;
	ll ans = 0;
	FOR(i, 1, N) {
		onLeft = (onLeft + inverse(i)) % MOD;
		ans += (arr[i]-arr[i-1])*onLeft % MOD;
		ans %= MOD;
	}

	FOR(i, 1, N) ans = ans * i % MOD;
	print(ans);
}

Measured memory_bytes: 3992
#include<stdio.h>

int main(){
	
    int a,b,d,r;
    double f;
    
    scanf("%d %d",&a,&b);
    d=a/b;
    r=a%b;
    f=(double)a/(double)b;
    printf("%d %d %lf\n",d,r,f);
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	return 0;
}


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

using namespace std;

using intL = long long;

#define MOD_NUMBER 1000000007

template <class T> void vector_print(vector<T> vec) {
  for (unsigned int i = 0; i < vec.size(); i++) {
    cout << vec.at(i);
    if (i < vec.size()-1) {
      cout << " ";
    } else if (i == vec.size()-1) {
      cout << endl;
    }
  }
}

int main() {
  int n, ans = 0;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; i++) {
    cin >> d[i];
  }
  for (int i = 0; i < n-1; i++) {
    for (int j = i+1; j < n; j++) {
      ans += d[i]*d[j];
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main(void)
{
	int i,j,k,l;
	int n,s,x;
	int len;
	char card[403],T1[201],T2[201];

	while(1){
		scanf("%s",card);
		if(card[0] == '-')break;
		len = strlen(card);
		scanf("%d",&n);
		for(i = 0;i < n;i++){
			scanf("%d",&s);
                        for(j = 0;j < s;j++){
				T1[j] = card[j];
				T1[s] = 0;
			}
			for(k = 0;k < (len - s);k++){
				T2[k] = card[k + s];
				T2[len - s] = 0;
			}
			strcat(T2,T1);
			strcpy(card,T2);
		}
		printf("%s\n",card);
	}
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
using namespace std;

typedef long long ll;

int main()
{
    int N, D;
    cin >> N >> D;
    int ans=N/(2*D+1)+1;
    if(N%(2*D+1)==0) ans--;
    cout << ans << endl;

    
    return 0;
}

Measured memory_bytes: 256
while True:
    n = int(input())
    count = 0
    if n == 0:
        break
    
    while True:
        if n == 1:
            break
        elif n % 2 == 0:
            n = n / 2
            count += 1
        else:
            n = n * 3 + 1
            count += 1
    print(count)


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    ll K, N, sum = 0;
    cin >> K >> N;
    vll A(N), dist(N);
    rep(i, N)
    {
        cin >> A[i];
    }
    ll max = 0, midx;
    rep(i, N)
    {
        if (i != N - 1)
            dist[i] = A[i + 1] - A[i];
        else
        {
            dist[i] = A[0] - A[N - 1] + K;
        }
        if (max < dist[i])
        {
            max = dist[i];
            midx = i;
        }
        sum += dist[i];
    }
    cout << sum - max;
    return 0;
}

Measured memory_bytes: 3328
import Text.Printf

turn:: (Int,Int) -> (Int,Int)
turn (a,b)
        | a >  b = (a+b,0)
        | a == b = (a,b)
        | a <  b = (0,a+b)
        
acm:: [(Int,Int)] -> (Int,Int)
acm [] = (0,0)
acm ((a,b):xs) =
        let (c,d) = acm xs
        in
                (a+c,b+d)

play:: [[Int]] -> [(Int,Int)]
play ([0]:ns) = []
play (n:ns) =
    let i = take (n!!0) ns
        o = acm $ map turn $ map (\(x0:x1:xs) -> (x0,x1)) i
        os= play $ drop (n!!0) ns
    in
        (o:os)

main = do
    c <- getContents
    let t0= map words $ lines c
        t1= map (map read) t0 :: [[Int]]
        o = play t1
    mapM_ (\(a,b)-> printf "%d %d\n" a b) o

Measured memory_bytes: 9188
a, b, c, d = list(map(int, input().split()))
def euqlid(x,y):
    if x < y :
        temp = x
        x = y
        y = temp
    while x % y != 0:
        temp = x
        x = y
        y = temp % y
    return y
def searchCount(p,q,k):
    min = 0
    max = 0
    if p % k == 0:
        min = p // k
    else:
        min = p//k + 1
    max = q//k
    return max - min + 1
lcm = euqlid(c,d)
gcd = int((c * d) / lcm)
print((b - a + 1) - searchCount(a,b,c) - searchCount(a,b,d) + searchCount(a,b,gcd))

Measured memory_bytes: 3192
#![allow(non_snake_case)]
#![allow(unused_imports)]
 
use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::rational::Ratio;
use std::f64;

#[fastout]
fn main() {
    input!{
        A: f64,
        B: f64,
        H: f64,
        M: f64,
    }

    let H_theta = 0.5 * ((H * 60.0 + M) % (12.0 * 60.0));
    let M_theta = 6.0 * M;

    let theta = if (H_theta - M_theta).abs() > 180.0 {(H_theta - M_theta).abs()} else {360.0 - (H_theta - M_theta).abs()};

    let mut ans = (A * A + B * B - 2.0*A*B*theta.to_radians().cos()).sqrt();

    // if theta == 0.0 || theta == 180.0 {
    //     ans = 0.0;
    // }


    println!("{}", ans);
}


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

using namespace std;

template< class T >
struct BinaryIndexedTree
{
  vector< T > data;

  BinaryIndexedTree(int sz)
  {
    data.assign(++sz, 0);
  }

  T sum(int k)
  {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, T x)
  {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};


int main()
{
  int R, C, N;
  cin >> R >> C >> N;

  vector< pair< int, int > > row;
  vector< int > ss;
  for(int i = 0; i < N; i++) {
    int a, b, c, d;

    cin >> a >> b >> c >> d;

    bool iskabe1 = a == 0 || a == R || b == 0 || b == C;
    bool iskabe2 = c == 0 || c == R || d == 0 || d == C;

    auto get = [&](int x, int y)
    {
      if(x == 0) return (y);
      if(y == C) return (C + x);
      if(x == R) return (C + R + (C - y));
      return (C + R + C + (R - x));
    };

    if(iskabe1 && iskabe2) {
      int s = get(a, b), t = get(c, d);
      if(s > t) swap(s, t);

      ss.push_back(s);
      ss.push_back(t);
      ss.push_back(t + 1);
      row.emplace_back(s, t);
    }
  }


  sort(begin(ss), end(ss));
  ss.erase(unique(begin(ss), end(ss)), end(ss));
  BinaryIndexedTree< int > bit(ss.size());

  for(auto &p : row) {
    p.first = lower_bound(begin(ss), end(ss), p.first) - begin(ss);
    p.second = lower_bound(begin(ss), end(ss), p.second) - begin(ss);
    bit.add(p.first, 1);
    bit.add(p.second + 1, -1);
  }
  for(auto &p : row) {
    if(bit.sum(p.first) != bit.sum(p.second)) {
      cout << "NO" << endl;
      return (0);
    }
  }
  cout << "YES" << endl;

}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
//For ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define MOD 1000000007
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
#define init(arr, val) memset(arr, val, sizeof(arr))
#define loop(i, a, b) for (int i = a; i < b; i++)
#define loopr(i, a, b) for (int i = a; i >= b; i--)
#define loops(i, a, b, step) for (int i = a; i < b; i += step)
#define looprs(i, a, b, step) for (int i = a; i >= b; i -= step)
#define ull unsigned long long int
#define ll long long int
#define P pair
#define PLL pair<long long, long long>
#define PII pair<int, int>
#define PUU pair<unsigned long long int, unsigned long long int>
#define L list
#define V vector
#define D deque
#define ST set
#define MS multiset
#define M map
#define UM unordered_map
#define mp make_pair
#define pb push_back
#define pf push_front
#define MM multimap
#define F first
#define S second
#define IT iterator
#define RIT reverse_iterator
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie();                        \
    cout.tie();
#define FILE_READ_IN freopen("input.txt", "r", stdin);
#define FILE_READ_OUT freopen("output.txt", "w", stdout);
#define all(a) a.begin(), a.end()
using namespace std;
// For ordered_set
using namespace __gnu_pbds;
template <typename T>
using ord_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll maxn = 1e5;
const ll inf = 1e9;
const double pi = acos(-1);

void solve()
{
    string s, a;
    cin >> s >> a;
    ll cnt = 0;

    loop(i, 0, s.size())
    {
        if (s[i] != a[i])
        {
            cnt++;
        }
    }

    cout << cnt << "\n";
}

int main()
{
    int t = 1;
    //    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3912
import java.util.Scanner;

//Repeated Subsequences
public class Main{

	String lcs(String a, String b){
	int na = a.length();
	int nb = b.length();
	int dp[][] = new int[na+1][nb+1];
	for(int i=0;i<na;i++)dp[i][0] = 0;
	for(int i=0;i<nb;i++)dp[0][i] = 0;
	for(int i=1;i<=na;i++){
		for(int j=1;j<=nb;j++){
			if(a.charAt(i-1)==b.charAt(j-1)){
				dp[i][j] = dp[i-1][j-1] + 1;
			}
			else{
				dp[i][j] = Math.max(dp[i-1][j], dp[i][j-1]);
			}
		}
	}
	char[] r = new char[dp[na][nb]];
	int i = na;
	int j = nb;
	while(0<i&&0<j){
		if(dp[i][j]==dp[i-1][j])i--;
		else if(dp[i][j]==dp[i][j-1])j--;
		else{
			r[dp[i-1][j-1]] = a.charAt(i-1);
			i--;
			j--;
		}
	}
	return new String(r);
}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			String s = sc.next();
			if("#END".equals(s))break;
			String res = "";
			for(int i=1;i<s.length();i++){
				String l = lcs(s.substring(0, i), s.substring(i));
				if(res.length()<l.length())res = l;
			}
			System.out.println(res);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 16000
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		boolean ans = true;
		String s = sc.nextLine();
		char c[] = s.toCharArray();
		for (int i = 0; i < s.length(); i++) {
			if (i % 2 == 0) {
				// L
				if (c[i] == 'L') {
					ans = false;
				}
			} else {
				// R
				if (c[i] == 'R') {
					ans = false;
				}
			}

		}
		if (ans) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 22868
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=200005;

int n,cnt,last[N],p[N],sg[N],p1,p2,tim,arr[N];
bool vis[N];
struct edge{int to,next;bool del;}e[N];

int read()
{
    int x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

void addedge(int u,int v)
{
    e[++cnt].to=v;e[cnt].next=last[u];last[u]=cnt;
}

int get_mex(int x)
{
    int ans;
    for (int i=last[x];i;i=e[i].next) if (!e[i].del) vis[sg[e[i].to]]=1;
    for (int i=0;;i++) if (!vis[i]) {ans=i;break;}
    for (int i=last[x];i;i=e[i].next) if (!e[i].del) vis[sg[e[i].to]]=0;
    return ans;
}

void dfs(int x)
{
    arr[x]=tim;
    for (int i=last[x];i;i=e[i].next)
        if (!arr[e[i].to]) dfs(e[i].to);
        else if (arr[e[i].to]==tim) p1=x,p2=e[i].to,e[i].del=1;
    sg[x]=get_mex(x);
}

int main()
{
    n=read();
    for (int i=1;i<=n;i++) p[i]=read(),addedge(p[i],i);
    for (int i=1;i<=n;i++) if (!arr[i]) tim++,dfs(i);
    int s1=get_mex(p1);
    vis[s1]=1;
    int s2=get_mex(p1);
    vis[s1]=0;
    if (sg[p2]!=s1) {puts("POSSIBLE");return 0;}
    sg[p1]=s2;
    int x=p1;
    while (x!=p2) x=p[x],sg[x]=get_mex(x);
    if (sg[p2]==s1) puts("POSSIBLE");
    else puts("IMPOSSIBLE");
    return 0;
}

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

char chess (int h, int w) {
    if((h+w)%2==0){
        return '#';
    }
    return '.';
}
int main() 
{
    // Your code here!
    int H,W;
    while(true) {
        cin >> H >> W;
        if (H == 0 && W == 0) {
            break;
        }
        for(int j = 0; j < H; j++) {
            for(int i = 0; i < W; i++) {
                cout << chess(i,j);
            }
            cout << endl;
        }
        cout << endl;
    }
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
int main(){
 int A,B,C,K;
 cin>>A>>B>>C>>K;
 int count=0;
 if(K<=A){
cout<<K<<endl;
 }
 else{
count+=A;
K-=A;
if(K<=B){
cout<<count<<endl;
}
else{
K-=B;
count-=K;
  cout<<count<<endl;
}
 }
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++) cin >> a[i];
  sort(a.begin(), a.end());
  double ans = 0;
  for(int i=0;i<n;i++) {
    ans += 1/(double)a[i];
  }
  cout << setprecision(15) << 1/ans << endl;
}

Measured memory_bytes: 256
def count_section_by_zero(data):
  count = 0
  flg = False
  start = 0
  for i, d in enumerate(data):
    if flg is False and d != 0:
      count += 1
      flg = True
      
    if d == 0:
      flg = False
  return count

def input_list():
  return list(map(int, input().split()))

def input_list_str():
  return list(map(str, input().split()))

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

# 2で割り切れる回数
def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c

# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def main():
  s = input()
  if s[2] == s[3] and s[4] == s[5]:
    print('Yes')
  else:
    print('No')
  
import math
import fractions
import collections
import itertools
from functools import reduce
main()

Measured memory_bytes: 5048
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const int INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
template <typename T>
ostream& operator<<(ostream& os, vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, pair<T,T> &P){
    os << P.first;
    os << " ";
    os << P.second;
    os << endl;
    return os;
}
//fixed<<setprecision(10)<<ans<<endl;
int N,M;
set<int> ng_nodes;
vector<int> answer;
vector<vector<int>> edge;

vector<int> bfs(int s){ 
    vector<int> dist(N,INF),pre(N);//pre(N); pre[s]=-1; 経路復元するなら
    queue<int> q;
    q.push(s);
    dist[s]=0;
    pre[s]=-1;
    while(!q.empty()){
        int v = q.front(); q.pop();

        for(auto u:edge[v]){
            if(dist[u]!=INF) continue;
            q.push(u); dist[u] = dist[v]+1;
            pre[u] = v;
        }
    }

    //サイクル検出
    pair<int,int> best(INF,-1);
    REP(v,N){
        if(v==s) continue;
        for(auto u:edge[v]){
            if(u==s){
                chmin(best,mp(dist[v],v));
            }
        }
    }
    if(best.first == INF) return vector<int>(N+1); //サイクルなし
    //経路復元
    vector<int> res; int v = best.second;
    while(v!=-1){
        res.push_back(v+1);
        v=pre[v];
    }
    return res;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M;
    edge.resize(N);
    REP(i,M){
        int a,b;
        cin >> a >> b;
        a--;b--;
        edge[a].push_back(b);
    }
    vector<int> ans(N+2);
    REP(s,N){
        vi now = bfs(s);
        if(now.size() < ans.size()){
            ans = now;
        }
    }
    if(ans.size() > N)cout << -1 << endl;
    else{
        cout << ans.size() << endl;
        cout << ans;
    }
}


Measured memory_bytes: 384
#include <assert.h>
#include <stdio.h>
 
int n, p, i, t, y = 1, d[10000] = {1};
long long r;
char s[200002];
 
int main() {
  assert(scanf("%d%d%s", &n, &p, s + 1) == 3);
  if (10 % p == 0) {
    while(i++<n) {
      if((s[i] - '0') % p == 0)
        r += i;
    }
  }
  else {
    for(; n; n--) {
      t = (t + (s[n] - '0') * y) % p;
      d[t]++;
      y = y * 10 % p;
    }
    for(i = 0; i < p; i++)
      r += (long long) d[i] * (d[i] - 1);
    r /= 2;
  }
  printf("%lld\n", r);
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(I,0,n){cout<<(I ? " ":"")<<A[I]x;}cout<<endl;
#define pprint(A,y,m,n) rep(J,0,m){print(A[J],y,n);}
const long mod=1e9+7;
const int siz=2e5+1;
const long inf=1e9;
int main(){
	int N; cin>>N;
	string s; long y;
	int cnt[60][60] = {};
	long ans = 0;
	rep(_,0,N){
		cin>>s; y = 0;
        int k = 0;
        rep(i,0,s.size()){
            if(s[i] == '.') k = s.size() - i - 1;
            else (y *= 10) += s[i] - '0';
        }
        int a = -k,b = -k;
        while(y % 2 == 0){ y /= 2; a++; }
        while(y % 5 == 0){ y /= 5; b++; }
        ans += cnt[-a+30][-b+30];
        rep(i,-30,a+1)rep(j,-30,b+1) cnt[i+30][j+30]++;
	}cout<<ans<<endl;
}


Measured memory_bytes: 3620
#include <stdio.h>

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

        scanf("%d",&n);

        a=n/100;
        b=(n%100)/10;
        c=(n%100)%10;

        if(a==7 || b== 7 || c==7) printf("Yes");
        else printf("No");
        return 0;

}


Measured memory_bytes: 1732
import numpy as np
N=int(input())
S=str(input())
s_list = "abcdefghijklmnopqrstuvwxyz"
max_count = 0
for i in range(1,N-1): # N字目で切った場合
  count_list = np.zeros(26)
  for k in range(i):
#    print(i,k,S[k],S[i:len(S)])
    if S[k] in S[i:len(S)]:
      count_list[s_list.index(S[k])] = count_list[s_list.index(S[k])] + 1
  if max_count < len([1 for x in count_list if x>0]):
    max_count = len([1 for x in count_list if x>0])
#  print(count_list)
print(max_count)


Measured memory_bytes: 12440
#include <bits/stdc++.h>
using namespace std;
int turn(string S){
    long long count=0;
    if(S.size()==2){
        if(S.at(0)==S.at(1)){
            return 1;
        }else{
            return 0;
        }
    }else{
        for(int i=0;i<(S.size()-1)/2;i++){
            if(S.at(i)==S.at(S.size()-i-1)){
                count++;
            }else{
                break;
            }
        }
        if(count==(S.size()-1)/2){
            return 1;
        }else{
            return 0;
        }
    }
}
int main(void){
    string S;
    cin >> S;
    long long N=S.size();
    int count=0;
    if(turn(S)==1){
        count++;
    }
    string A=S.substr(0,(N-1)/2);
    if(turn(A)==1){
        count++;
    }
    string B=S.substr((N+3)/2-1,(N-1)/2);
    if(turn(B)==1){
        count++;
    }
    if(count==3){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

using namespace std;


int main() {
  int a;
 double b[55],c;
  
  cin >> a;
  
  for(int i=0;i<a;i++)
    cin >> b[i];
  
  
  sort(b,b+a);
  
  c =b[0];
  for(int i=1;i<a;i++){
    c = (c+b[i])/2;
  }
  
  cout << c << endl;
}
    
    


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll C[30];
ll dp[25][50005];

int main() {
    ll N, M;
    cin >> N >> M;
    REP(i, M) {
        cin >> C[i];
    }
    REP(i, M + 1) {
        REP(j, N + 1) {
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;
    REP(i, M) {
        REP(j, N + 1) {
            dp[i + 1][j] = std::min(dp[i + 1][j], dp[i][j]);
            if (j - C[i] >= 0) {
                dp[i + 1][j] = std::min(dp[i + 1][j], dp[i][j - C[i]] + 1);
                dp[i + 1][j] = std::min(dp[i + 1][j], dp[i + 1][j - C[i]] + 1);
            }
        }
    }
    cout << dp[M][N] << endl;
    return 0;
}


Measured memory_bytes: 11308
#include <bits/stdc++.h>
using namespace std;
int main () {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int a,b;
  cin >> a >> b;
  long long hsl;
  if((a+b)>(a*b)){
  	if((a+b)>(a-b)){
      hsl=a+b;
    } else {
      hsl=a-b;
    }
  } else {
    if(a*b>a-b){
      hsl=a*b;
    } else {
      hsl=a-b;
    }
  }
  cout << hsl << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <algorithm>
#include <numeric>
#include <queue>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <set>
#include <map>
#include <stack>

using namespace std;

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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repl(i, n) for(LL i = 0; i < (LL)(n); i++)

int n, m, x;
int min_total = INT_MAX;
bool found = false;

bool check_skill(vector<int> skill) {
  rep(i, m) {
    if (skill[i] < x) return false;
  }

  return true;
}

void check(vector<pair<int, vector<int> > > vec, vector<int> skill, int idx, int total) {
  for (int i = idx; i < n; i++) {
    rep(j, m) skill[j] += vec[i].second[j];
    total += vec[i].first;

    bool result = check_skill(skill);
    if (result) {
      min_total = min(min_total, total);
      found = true;
      return;
    } else {
      check(vec, skill, i+1, total);
    }

    rep(j, m) skill[j] -= vec[i].second[j];
    total -= vec[i].first;
  }
}

int main(void){
  cin >> n >> m >> x;

  vector<pair<int, vector<int> > > vec(n);

  rep(i, n) {
    cin >> vec[i].first;

    vector<int> a(m);
    rep(j, m) cin >> a[j];
    vec[i].second = a;
  }

  sort(vec.begin(), vec.end());
  vector<int> skill(m, 0);

  check(vec, skill, 0, 0);

  if (found) {
    cout << min_total << endl;
  } else {
    cout << "-1" << endl;
  }

  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
const ll mod = 1e9 + 7;
const ll INF = 1e9;
const ll LINF = 1LL << 60;

struct edge {
  ll to, cost;
};

struct graph {
  ll V;
  vector<vector<edge>> G;  //グラフを表す
  vector<ll> d;            //距離

  graph(ll n) { init(n); }

  void init(ll n) {
    V = n;
    G.resize(V);
    d.resize(V);
    rep(i, V) { d[i] = INF; }
  }

  void add_edge(ll s, ll t, ll cost) {
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }

  void dijkstra(ll s) {
    rep(i, V) { d[i] = INF; }
    d[s] = 0;
    priority_queue<P, vector<P>, greater<P>> que;
    que.push(P(0, s));
    while (!que.empty()) {
      P p = que.top();
      que.pop();
      ll v = p.second;
      if (d[v] < p.first) continue;
      for (auto e : G[v]) {
        if (d[e.to] > d[v] + e.cost) {
          d[e.to] = d[v] + e.cost;
          que.push(P(d[e.to], e.to));
        }
      }
    }
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //////////////////////////////////////
  int n, m, r;
  cin >> n >> m >> r;
  graph g(n);
  rep(i, m) {
    int s, t, d;
    cin >> s >> t >> d;
    g.add_edge(s, t, d);
  }
  g.dijkstra(r);
  rep(i, n) {
    if (g.d[i] == INF)
      cout << "INF" << endl;
    else
      cout << g.d[i] << endl;
  }
  return 0;
}



Measured memory_bytes: 19388
N, K = gets.chomp.split.map(&:to_i)
A = gets.chomp.split.map(&:to_i)
MOD = 10 ** 9 + 7

# p N, K
# p A
MAX_SIZE = 2005
d = Array.new(MAX_SIZE)
d.each.with_index do |_, i|
  d[i] = Array.new(MAX_SIZE, 0)
end

A.each.with_index do |a, i|
  1.upto(MAX_SIZE-1).each do |j|  # d[i]d[0] is ignored. They are always 0.
    if j < a  # j is larger than a
      d[i+1][j] = d[i][j] + 1
    else
      d[i+1][j] = d[i][j]
    end
  end
end

r = 0

# We use d[A.size] for the loop of k. If k = 2, then (d[i][i] + d[A.size][i]) should be added.
# If k, then (d[i][i] + (k-1) * d[A.size][i])) should be added.
# 0 + 1 + 2 + ... + (k-1) = k * (k-1) / 2

A.each.with_index do |a, i|
  # For Debug
  # p "d[last][#{a}]: #{d[A.size][a]}"
  r += (K * d[i][a]) % MOD
  r += (d[A.size][a] * K * (K-1) / 2) % MOD
  r = r % MOD
end

p r

Measured memory_bytes: 35324
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int X = sc.nextInt();
        int limit = X/100;
        
        if (X%100 <= limit * 5){
            System.out.println('1');
        }
        
        else{
            System.out.println('0');
        }
        
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    string w;
    cin >> w;

    vector<char> found;
    vector<bool> count;

    int size = w.size();

    for(int i = 0; i < size; i++){
        bool t = true;
        int fsize = found.size();
        for(int j = 0; j < fsize; j++){
            if(found.at(j) == w[i]){
                count.at(j) = !count.at(j);
                t = false;
                break;
            }
        }
        if(t){
            found.push_back(w[i]);
            count.push_back(false);
        }
    }

    int n = count.size();
    bool t = true;
    for(int i = 0; i < n; i++){
        t = t && count.at(i);
    } 
    
    if(t)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

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

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

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> l(n),r(n);
  for(Int i=0;i<n;i++) cin>>l[i]>>r[i];
  sort(l.begin(),l.end());
  sort(r.begin(),r.end());

  Int ans=0;
  {
    auto check=
      [&](Int x)->Int{
	Int res=0,pos=0;
	for(Int i=0;i<x;i++){
	  if(r[i]>pos) return -1;
	  res+=abs(pos-r[i]);
	  pos=r[i];
	  chmax(ans,res);
	  if(pos>l[n-(i+1)]) return -1;
	  res+=abs(l[n-(i+1)]-r[i]);
	  pos=l[n-(i+1)];
	  chmax(ans,res);
	}
	if(x<n&&r[x]<pos){
	  res+=abs(pos-r[x]);
	  pos=r[x];
	}
	res+=abs(pos);
	chmax(ans,res);
	return res;
      };
    
    Int low=0,high=n+1;
    while(low+1<high){
      Int mid=(low+high)>>1;
      if(check(mid)>=0) low=mid;
      else high=mid;
    }
  }
  {
    reverse(l.begin(),l.end());
    reverse(r.begin(),r.end());
    auto check=
      [&](Int x)->Int{
	Int res=0,pos=0;
	for(Int i=0;i<x;i++){
	  if(l[i]<pos) return -1;
	  res+=abs(pos-l[i]);
	  pos=l[i];
	  chmax(ans,res);
	  if(pos<r[n-(i+1)]) return -1;
	  res+=abs(r[n-(i+1)]-l[i]);
	  pos=r[n-(i+1)];
	  chmax(ans,res);
	}
	if(x<n&&l[x]>pos){
	  res+=abs(pos-l[x]);
	  pos=l[x];
	}
	res+=abs(pos);
	chmax(ans,res);
	return res;
      };
    
    Int low=0,high=n+1;
    while(low+1<high){
      Int mid=(low+high)>>1;
      if(check(mid)>=0) low=mid;
      else high=mid;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  int d;
  cin>>d;
  vector<int> c(26);
  for (int i = 0; i < 26; ++i)
  {
    cin>>c[i];
  }
  vector<vector<int>> s(d,vector<int>(26));
  for (int i = 0; i < d; ++i)
  {
    for (int j = 0; j < 26; ++j)
    {
      cin>>s[i][j];
    }
  }
  int ans=0;
  vector<int> last(26,0);
  for (int i = 0; i < d; ++i)
  {
    vector<int> diff(26,0);
    for (int tmp = 0; tmp < 26; ++tmp)
    {
      last[tmp]=i+1;
      diff[tmp]=s[i][tmp];
      for (int j = 0; j < 26; ++j)
      {
         diff[tmp]-=c[j]*(i+1-last[j]);
      }
    }
    cout<<1+(max_element(diff.begin(), diff.end())-diff.begin())<<endl;
  }
}

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

int main()
{
    ll n, a, b;
    cin >> n >> a >> b;
    //コーナーケースの処理
    if (n == 1 && a != b)
    {
        cout << 0 << endl;
    }
    else if (a == b)
    {
        cout << 1 << endl;
    }
    else if (a > b)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << (a + b * (n - 1)) - (a * (n - 1) + b) + 1 << endl;
    }
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<long long>> vvll;
typedef long double ld;
typedef std::vector<long double> vld;
typedef std::vector<std::vector<long double>> vvld;
using namespace std;
void yesno(bool state);

void Main(){
    ll H,W,K;
    cin >> H >> W >> K;
    vector<vector<bool>> c(H,vector<bool>(W));
    rep(i,H)
        rep(j,W){
            char c_;
            cin >> c_;
            if(c_ == '#')
                c[i][j] = true;
            else
                c[i][j] = false;
            // cout << c[i][j];
        }
    ll ans = 0;
    for (ll i = 0; i < (1<<H); ++i){
        for (ll j = 0; j < (1<<W); ++j)
        {
            ll memo = 0;
            for (ll h = 0; h < H; h++)
                for (ll w = 0; w < W; w++)
                {
                    if(((i >> h) & 1) && ((j >> w) & 1) && c[h][w]){
                        memo++;
                    }                        
                }
            if(memo == K){
                ans++;
                // cout << i << " "<< j << endl;
            }
        }
    }

    cout << ans <<endl;
    
    


}

int main(int argc, char const *argv[])
{
    Main();
    return 0;
}

void yesno(bool state){
    if(state)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 3632
import java.io.*;

class Main {
    public static void main(String[] args) throws NumberFormatException, IOException {
        int n;
        String[] token;
        int rank;
        boolean[] S = new boolean[13];
        boolean[] H = new boolean[13];
        boolean[] C = new boolean[13];
        boolean[] D = new boolean[13];

        for(int i = 0; i < 13; i++)
            S[i] = H[i] = C[i] = D[i] = false;

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        n = Integer.parseInt(br.readLine());

        for(int i = 0; i < n; i++){
            token = br.readLine().split(" ");
            rank = Integer.parseInt(token[1]);
            if(token[0].equals("S")){
                S[rank-1] = true;
            }else if(token[0].equals("H")){
                H[rank-1] = true;
            }else if(token[0].equals("C")){
                C[rank-1] = true;
            }else if(token[0].equals("D")){
                D[rank-1] = true;
            }
        }

        for(int i = 0; i < 13; i++){
            if(!S[i])    System.out.println("S " + (i + 1));
        }
        for(int i = 0; i < 13; i++){
            if(!H[i])    System.out.println("H " + (i + 1));
        }
        for(int i = 0; i < 13; i++){
            if(!C[i])    System.out.println("C " + (i + 1));
        }
        for(int i = 0; i < 13; i++){
            if(!D[i])    System.out.println("D " + (i + 1));
        }
    }
}

Measured memory_bytes: 24532
import numpy as np
from itertools import combinations

def main():
    k = int(input())
    res = 0
    memo = np.zeros((k+1, k+1), int)
    for i in range(1, k+1):
        for j in range(i, k+1):
            tmp = np.gcd(i,j)
            memo[i][j] = tmp
            memo[j][i] = tmp

    for i in range(1, k+1):
        res += i 

    for c in combinations(range(1,k+1),2):
        ab = memo[c[0], c[1]]
        res += ab * 6

    for c in combinations(range(1,k+1), 3):
        ab = memo[c[0], c[1]]
        abc = memo[ab, c[2]]
        res += abc * 6
    print(res)


if __name__ == '__main__':
    main()



Measured memory_bytes: 27336
#include<cstdio>
#include<cstring>
#define fo(i,a,b)for(int i=a;i<=b;i++)
#define min(a,b)(a<b?a:b)
using namespace std;
int n,g,p[105],c[105],f[2][105505],o,zs,ans;
int main(){
	scanf("%d%d",&n,&g);g/=100;
	fo(i,1,n)scanf("%d%d",&p[i],&c[i]),c[i]/=100;
	fo(i,0,105500)f[0][i]=f[1][i]=1e9;f[0][0]=0;
	fo(i,1,n){
		o^=1;
		fo(j,0,zs)f[o][j]=f[!o][j];
		fo(j,1,p[i]-1)
			fo(k,0,zs)f[o][k+i*j]=min(f[o][k+i*j],f[!o][k]+j);
		fo(k,0,zs)f[o][k+i*p[i]+c[i]]=min(f[o][k+i*p[i]+c[i]],f[!o][k]+p[i]);
		zs+=p[i]*i+c[i];
	}
	ans=1e9;
	fo(i,g,zs)ans=min(ans,f[o][i]);
	printf("%d",ans);
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
from sys import stdin
# import numpy as np
# import sys
# sys.setrecursionlimit(10**4)

def _li(): return list(map(int, stdin.readline().split()))
def _li_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def _lf(): return list(map(float, stdin.readline().split()))
def _ls(): return stdin.readline().split()
def _i(): return int(stdin.readline())
def _f(): return float(stdin.readline())
def _s(): return stdin.readline()[:-1]


N = _i()

print((N-1) * N // 2)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int a[401];
long long f[401][401],sum[401];
int main()
{
	int i,j,l,n,k;
	scanf("%d",&n);
	memset(f,0x3f,sizeof(f));
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		sum[i]=sum[i-1]+a[i];
		f[i][i]=0;
	}
	for(j=1;j<n;j++)
	{
		for(i=1;i<=n;i++)
		{
			if(i+j>n)
				continue;
			for(k=i;k<i+j;k++)
				f[i][i+j]=min(f[i][i+j],f[i][k]+f[k+1][i+j]+sum[i+j]-sum[i-1]);
		}
	}
	printf("%lld",f[1][n]);
	return 0;
}

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


using namespace std;
constexpr long long int mod = 1000000007, MOD = 998244353;
constexpr double PI = 3.14159265358979323846;

int main() {
	string S;
	cin >> S;
	for (size_t i = 0; i < S.size(); i++)
	{
		if (S.at(i)=='?')S.at(i)='D';
	}
	cout << S;
}

Measured memory_bytes: 3756