akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


// パスカルの三角形を使った実装
ll C[55][55]; // C[n][k] -> nCk

void comb_table(int N){
    for(int i=0; i<=N; i++){
        for(int j=0; j<=i; j++){
            if(j==0 || j==i) C[i][j] = 1LL;
            else C[i][j] = (C[i-1][j-1]+C[i-1][j]);
        }
    }
}


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

    int N, A, B; cin >> N >> A >> B;
    vector<ll> v(N);
    rep(i, N) cin >> v[i];

    sort(v.begin(), v.end(), greater<ll>());
    comb_table(50);

    double ave = 0.0;
    rep(i, A) ave += v[i];
    ave /= A;
    cout << setprecision(15) << ave << endl;
    ll ans = 0;
    if(v[0] == v[A-1]){
        int cnt = 0;
        rep(i, N) if(v[i] == v[0]) ++cnt;
        for(int i=A; i<=min(cnt, B); ++i) ans += C[cnt][i];
        cout << ans << endl;
        return 0;
    }
    else{
        int left = 0, all = 0;
        rep(i, N) if(v[i] == v[A-1]){
            ++all;
            if(i <= A-1) ++left;
        }
        ans += C[all][left];
        cout << ans << endl;
        return 0;
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int i,j,a,b,c=0;
	while(c!=1)
	{
		scanf("%d %d", &a,&b);
		if(a==0 && b==0)
		{
			c=1;
			break;
		}
		
		for(j=0;j<b;j++)
		{
			printf("#");
		}
		printf("\n");
		
		for(i=1;i<a-1;i++)
		{
			printf("#");
			
			for(j=1;j<b-1;j++)
			{
				printf(".");
			}
			printf("#\n");
		}
		
		for(j=0;j<b;j++)
		{
			printf("#");
		}
		printf("\n\n");
	}
	return 0;
}


Measured memory_bytes: 2036
#include<bits/stdc++.h>
#include<iostream>
#include<fstream>
#define ll long long
using namespace std;

int main(){
    int N, K;  cin >> N >> K;
    vector<int> a(N,0);
    for(int i=0; i<N; i++) cin >> a[i];

    vector<vector<int>> dp(K+1, vector<int>(2, -1));

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

    for(int k=0; k<=K; k++) for(int p=0; p<2; p++){
        if(dp[k][p] != -1) continue;

        for(int i=0; i<N; i++){
            if(k>=a[i] && dp[k-a[i]][p^1] == p){
                dp[k][p] = p;
                break;
            }
            if(i==N-1) dp[k][p] = p^1;
        }
    }
    
    if(dp[K][0] == 0){
        cout << "First" << endl;
    }else{
        cout << "Second" << endl;
    }
}


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

typedef long long int ll;

const int sz = 200009;

vector<int>v[sz];

unordered_map<int,int>vis;

int dfs(int node){

    if(vis[node])return 0;

    vis[node]++;

    int res = 1;

    for(int child : v[node]){
        res += dfs(child);
    }

    return res;

}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n,m;
    cin>>n>>m;

    map<pair<int,int>,int>mp;

    for(int i = 1; i <= m; i++){
        int a,b;
        cin>>a>>b;

        if(mp[{a,b}] ||  mp[{b,a}])continue;
        mp[{a,b}]++;
        mp[{b,a}]++;

        v[a].push_back(b);
        v[b].push_back(a);

    }

    int ans = -1;

    for(int i = 1; i <= n; i++){
        if(vis[i])continue;
        ans = max(ans,dfs(i));
    }

    cout<<ans;

    return 0;

}


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

ll inv(ll a) {

	ll res = 1;
	int p = MOD - 2;
	while (p > 0) {
		if ((p & 1) == 1) { res *= a; res %= MOD; }
		a = a * a % MOD;
		p >>= 1;
	}
	return res;
}
int main(){

	ll n, a, b;
	cin >> n >> a >> b;

	ll res = 1;
	ll c = 2;
	int p = n;
	while (p > 0) {
		if ((p & 1) == 1) { res *= c; res %= MOD; }
		c = c * c % MOD;
		p >>= 1;
	}
	res--;
	ll res2 = 1;
	fx(a) {
		res2 *= n - x;
		res2 %= MOD;
	}
	fx(a) {
		res2 *=inv(x+1);
		res2 %= MOD;
	}
	if (res2>res) {
		res += MOD;
	}
	res -= res2;
	res2 = 1;
	fx(b) {
		res2 *= n - x;
		res2 %= MOD;
	}
	fx(b) {
		res2 *= inv(x + 1);
		res2 %= MOD;
	}
	if (res2 > res) {
		res += MOD;
	}
	res -= res2;
	ce(res%MOD)
    return 0;
}



Measured memory_bytes: 256
s = list(input())
n = len(s)

for i in range(2 ** (n - 1)):
    num = int(s[0])
    num_list = [str(s[0])]
    for j in range(n - 1):
        if (i >> j) & 1:
            num += int(s[j + 1])
            num_list.append("+" + str(s[j + 1]))
        else:
            num -= int(s[j + 1])
            num_list.append("-" + str(s[j + 1]))
    if num == 7:
        [print(t, end="") for t in num_list]
        print("=7")
        break

Measured memory_bytes: 9132
def solve(string):
    n, m, *xyz = map(int, string.split())
    t = [-1] * (n + 1)
    for x, y, z in zip(*[iter(xyz)] * 3):

        def update(x, y):
            r1, p1 = x
            r2, p2 = y
            new_root = min(r1, r2)
            if r1 != r2:
                p2.append(max(r1, r2))
            for p in p1:
                t[p] = new_root
            for p in p2:
                t[p] = new_root

        def get_root(x):
            path = [x]
            curr = t[x]
            while curr != -1:
                path.append(curr)
                curr = t[curr]
            root = path.pop()
            return root, path

        update(get_root(x), get_root(y))
    return str(t[1:].count(-1))


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(m)])))


Measured memory_bytes: 34868
n = int(input())
n_list = []
counter = 0
for i in range(3, n+1):
    if i%3 == 0:
      n_list.append(i)
      counter += 1
    else:
      x = i
      while x > 0:
        if x%10 == 3:
          n_list.append(i)
          counter += 1
          break
        x //= 10
for i in range(counter):
    print(' %d'%n_list[i], end='')
print('')


Measured memory_bytes: 6108
import java.util.Scanner;

// 単純に正解者以外を-1ポイントするとループが増えてTLEになるので、
// 正解に着目して敗退判定を工夫する
public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = Integer.parseInt(scanner.next());
        long K = Long.parseLong(scanner.next());
        int Q = Integer.parseInt(scanner.next());

        int[] A = new int[Q];

        for (int i = 0; i < Q; i++) {
            A[i] = Integer.parseInt(scanner.next());
        }
        scanner.close();

        long[] ansCount = new long[N];

        // 答えを処理していく
        for (int i = 0; i < Q; i++) {
            // 正解した人を++
            int correctIndex = A[i] - 1;
            ansCount[correctIndex]++;
        }

        // 0ポイント以下は敗退
        for (int i = 0; i < N; i++) {
            // 初期ポイント - 問題数 + 正解数 が 1以上であればOK
            boolean isWin = K - Q + ansCount[i] >= 1;
            System.out.println(isWin ? "Yes" : "No");
        }
    }
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a1(n), a2(n);
    for (auto& e : a1) cin >> e;
    for (auto& e : a2) cin >> e;
    partial_sum(begin(a1), end(a1), begin(a1));
    partial_sum(rbegin(a2), rend(a2), rbegin(a2));

    int ans = 0;
    for (int i = 0; i < n; i++) ans = max(ans, a1[i] + a2[i]);

    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int k = sc.nextInt();
		sc.close();

		int n = s.length();
		long[][][] dp = new long[n + 1][k + 1][2];
		dp[0][0][0] = 1;
//		int cnt = 0;
		for (int i = 0; i < n; i++) {
			int a = s.charAt(i) - '0';
//			if (a != 0) {
//				cnt++;
//			}
			for (int j = 0; j <= k; j++) {
				if (a == 0) {
					dp[i + 1][j][0] += dp[i][j][0];
					dp[i + 1][j][1] += dp[i][j][1];
				} else {
					dp[i + 1][j][1] += dp[i][j][0] + dp[i][j][1];
				}
				if (j < k) {
					if (a != 0) {
						dp[i + 1][j + 1][0] += dp[i][j][0];
						dp[i + 1][j + 1][1] += dp[i][j][0] * (a - 1);
					}
					dp[i + 1][j + 1][1] += dp[i][j][1] * 9;
				}
			}
		}
//		if (cnt < k) {
//			dp[n][k][0] = 0;
//		}
		System.out.println(dp[n][k][0] + dp[n][k][1]);
	}
}


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

const double inf = 1e10;

int main() {
  for(int W, H, N; cin >> W >> H >> N && (W|H|N); ) {
    N *= 2;
    vector<double> x(N), y(N);
    for(int i = 0; i < N; ++i) {
      cin >> x[i] >> y[i];
    }
    x.push_back(W);
    y.push_back(0);
    x.push_back(W);
    y.push_back(H);

    vector<double> ys = y;
    ys.push_back(0);
    ys.push_back(H);
    for(int i = 0; i < x.size(); ++i) {
      for(int j = i+1; j < x.size(); ++j) {
        if(x[i] == x[j]) continue;
        double a = (y[i] - y[j]) / (x[i] - x[j]);
        double b = y[i] - a * x[i];
        if(0 < b && b < H) ys.push_back(b);
      }
    }
    sort(ys.begin(), ys.end());
    double res = 0;
    for(int i = 0; i+1 < ys.size(); ++i) {
      double m = (ys[i] + ys[i+1]) / 2.0;
      vector<pair<double, int> > v;
      for(int j = 0; j < N; ++j) {
        double rad;
        if(x[j] == 0.0) {
          if(y[j] < m) rad = -inf;
          else rad = inf;
        } else {
          rad = atan2(y[j] - m, x[j]);
        }
        v.push_back(make_pair(rad, j));
      }
      sort(v.begin(), v.end());
      int s = v[N/2-1].second;
      int t = v[N/2].second;
      double y1, y2;
      if(x[s] == 0.0) {
        if(y[s] < m) y1 = -inf;
        else y1 = inf;
      } else {
        y1 = (y[s] - m) / x[s] * W + m;
      }
      if(x[t] == 0.0) {
        if(y[t] < m) y2 = -inf;
        else y2 = inf;
      } else {
        y2 = (y[t] - m) / x[t] * W + m;
      }
      double w = min((double)H, y2) - max(0.0, y1);
      if(w <= 0.0) continue;
      res += (ys[i+1] - ys[i]) * w / pow((double)H, 2.0);
    }
    printf("%.10f\n", res);
  }
  return 0;
}

Measured memory_bytes: 1480
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String args[]) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while(true){
			Deque<Integer> stack = new ArrayDeque<Integer>();
			String N = br.readLine();
			char[] P = N.toCharArray();
			if(P[0] == '.')break;
			for(int i = 0;i < P.length;i++){
				if(P[i] == ('(')){
					stack.push(1);
				}else if(P[i] == ('[')){
					stack.push(2);
				}else if(P[i] == (')')){
					if(stack.isEmpty() == false){
						if(stack.pop() == 1){
							stack.peek();
						}else{
							System.out.println("no");
							break;
						}
					}else{
						System.out.println("no");
						break;
					}
				}else if(P[i] == (']')){
					if(stack.isEmpty() == false){
						if(stack.pop() == 2){
							stack.peek();
						}else{
							System.out.println("no");
							break;
						}
					}else{
						System.out.println("no");
						break;
					}
				}
				if(i == P.length-1 && stack.isEmpty() == false){
					System.out.println("no");
					break;
				}
				if(i == P.length-1) System.out.println("yes");
			}
		}
	}
}

Measured memory_bytes: 25116
#include<stdio.h>
int main()
{
    int i,n,h=0,a[110000],t;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);

    }
    for(i=1;i<n;i++)
    {
        if(a[i]==i)
        {
            t=a[i];
            a[i]=a[i+1];
            a[i+1]=t;
            h++;
        }
    }
    if(a[n]==n)
    {
        h++;
    }
    printf("%d\n",h);
    return 0;
}




Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
double n;
int main()
{
	cin>>n;
	int m;
	m=n;
	if(m%2==0)
		printf("%lf\n",(n/2)/n);
	else	printf("%lf\n",((n+1)/2)/n);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  string s;std::cin >> s;
  string t = "";
  for(int i=0;i<s.size();){
    if(s[i]=='d'){
      t+="dream", i+=5;
      if(i+2==s.size()||(i+3<s.size()&&s[i]=='e'&&s[i+1]=='r'&&(s[i+2]=='e'||s[i+2]=='d'))){
        t+="er", i+=2;
      }
    }else{
      t+="erase", i+=5;
      if(i<s.size()&&s[i]=='r') t+='r', i++;
    }
  }
  std::cout << (s==t?"YES":"NO") << '\n';
  return 0;
}


Measured memory_bytes: 888
import java.util.Scanner;
import java.util.Arrays;
class Main{
  public static void main(String[] args){
    
    //入力処理
    Scanner scanner = new Scanner(System.in);
    int eat_red = scanner.nextInt();
    int eat_green = scanner.nextInt();
    int red_sum = scanner.nextInt();
    int green_sum = scanner.nextInt();
    int colorless_sum = scanner.nextInt();
    int[] red_apples = new int[red_sum];
    int[] green_apples = new int[green_sum];
    int[] candidate_apples = new int[colorless_sum+red_sum+green_sum];
    initialize(red_apples,scanner);
    initialize(green_apples,scanner);
    for(int i=0;i < colorless_sum;i++){
      candidate_apples[i] = scanner.nextInt();
    }
     
    
    Arrays.sort(red_apples);
    Arrays.sort(green_apples);
    
    for(int i=0;i < eat_red;i++){
      candidate_apples[colorless_sum+i] = red_apples[red_apples.length-i-1];
    }
    for(int i=0;i < eat_green;i++){
      candidate_apples[colorless_sum+eat_red+i] = green_apples[green_apples.length-i-1];
    }
    
    Arrays.sort(candidate_apples);
    int eat_sum = eat_red + eat_green;
    
    long sum = 0;
    for(int i=0;i < eat_sum;i++){
      sum += candidate_apples[candidate_apples.length-1-i];
    }
    
    System.out.println(sum);
    
      
  }
  
  static void initialize(int[] apples,Scanner scanner){
    for(int i=0;i < apples.length;i++){
      apples[i] = scanner.nextInt();
    }
  }
}

Measured memory_bytes: 97152
Imports System.Collections.Generic
Imports System.Console
Module Program
    Function f(N As Integer) As String
        For i4 As Integer = 0 to N
            For i7 As Integer = 0 to N
                If i4 * 4 + i7 * 7 = N Then
                    Return "Yes"
                End If
            Next i7
        Next i4
        Return "No"
    End Function
 	
 	Sub Main()
        Dim tmp As String() = Split(Console.ReadLine())
	    Dim N As Integer = tmp(0)
        Console.WriteLine(f(N))
    End Sub
End Module


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

int main(){
    ll ans;
    int n, m; cin >> n >> m;
    vector<int> a(m); rep(i,m) cin >> a.at(i);

    ans = n - accumulate(a.begin(),a.end(),0);

    if(ans < 0){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
}

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

#define ll long long int
#define LD long double

const int N = 100010;

int inf = 1e9;
int mod = 1e9 + 7;

signed main()
{
    //freopen("IN.txt", "r", stdin);
    //freopen("OUT.txt", "w", stdout);

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(10);


    int n; cin >> n;

    int x = (n + 1) / 2;

    cout << (LD)x / (LD)n << "\n";
    return 0;
}


Measured memory_bytes: 256
from operator import itemgetter

n, m = [int(i) for i in input().split()]
A, B = zip(*[[int(i) for i in input().split()] for j in range(m)])

A, B = zip(*sorted(zip(A, B), key=itemgetter(1, 0)))

last = -1
ans = 0

for a, b in zip(A, B):
    if last <= a:
        ans += 1
        last = b

print(ans)

Measured memory_bytes: 29964
import java.util.*
import java.math.*

fun main(args: Array<String>) {
//    var (R, G, B, N) = readLine()!!.split(" ").map { it.toInt() }
//    var N = readLine()!!.toInt()
    val S = readLine()!!.toInt()
//    val D = readLine()!!.split(" ").map { it.toLong() }
//    val A = readLine()!!.split(" ").map { it.toInt() }.toIntArray()

    var YYMM = false
    var MMYY = false
    if (S in 100 until 1300) MMYY = true
    if (S%100 in 1 until 13) YYMM = true

    println(if (MMYY && YYMM) "AMBIGUOUS" else if (MMYY) "MMYY" else if(YYMM) "YYMM" else "NA")
}


Measured memory_bytes: 33644
// AOJ 2476: Strange Currency System
// 2018.3.5 bal4u

#include <stdio.h>
#include <stdlib.h>

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int a[10002];
int cmp(int *a, int *b) { return *a - *b; }

int main()
{
	int n, i;
	long long ans;
	
	n = in();
	for (i = 0; i < n; i++) a[i] = in();
	qsort(a, n, sizeof(int), cmp);
 
	ans = 1; for (i = 0 ; i < n ; i++) {
		if (a[i] > ans) break;
		ans += a[i];
	}
	printf("%lld\n", ans);
	return 0;
}


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

ll gcd(ll x, ll y);
int fac(ll n, vector<int> num);

const int INF = 1001001001;

//mint�p�̒萔 (10��9��)
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

int main() {
    string s;
    cin >> s;
    string ans = "";

    rep(i, s.size()) {
        if (i % 2 == 0) ans += s[i];
    }

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

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
ll gcd(ll x, ll y) {
    ll num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

/*�f��������*/
//���색�C�u����
int fac(ll n, vector<int> num) {
    ll kazu = n;
    for (int i = 2; i <= sqrt(n); i++) {
        while (1) {
            if (kazu % i != 0) break;

            kazu /= i;
            num[i]++;
        }
    }
    if (kazu == n && n != 1) return 1;
    int ans = 0;
    if (kazu != 1) ans++;
    for (int i = 2; i <= sqrt(n); i++) {
        for (int j = 1; j <= num[i]; j++) {
            num[i] -= j;
            ans++;
        }
    }
    return ans;
}

Measured memory_bytes: 3848
import java.util.*

fun rangesum(n: Int, m: Int): Int {
    return n * (n + 1) / 2 - m * (m + 1) / 2
}

fun main(args: Array<String>){
	val cin = Scanner(System.`in`)
    val n = cin.nextInt()
    val a = cin.nextLong()
    val b = cin.nextLong()
    val x = Array<Long>(n, { cin.nextLong() })

    var ans: Long = 0

    for (i in 0..n-2) {
        if (a*(x[i+1] - x[i]) > b) {
            ans += b
        } else {
            ans += a*(x[i+1] - x[i])
        }
    }
    println(ans)
}

Measured memory_bytes: 55672
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int n, k;
int a[50];

int main(){
	cin >> n >> k;
	for(int i=0;i<n;i++) cin >> a[i];
	sort(a,a+n);
	reverse(a,a+n);
	int s=0;
	for(int i=0;i<k;i++) s+=a[i];
	
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
#define ll long long
#define pr(x) cerr << #x << ' ' << x << ' '
#define prln(x) cerr << #x << ' ' << x << endl
const int maxn = 2e5 + 5;
char s[maxn], t[maxn];
int a[27], b[27];

int main() {
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
    #endif // LOCAL
    scanf("%s %s", s, t);
    int len = strlen(s);
    for (int i = 0; i < len; ++i) {
        if (i == 0) {
            a[s[i] - 'a']++;
            b[t[i] - 'a']++;
        }else {
            if (a[s[i- 1] - 'a'] != b[t[i - 1] - 'a']) {
                puts("No");
                return 0;
            }
            a[s[i] - 'a']++;
            b[t[i] - 'a']++;
        }
    }
    if (a[s[len - 1] - 'a'] != b[t[len - 1] - 'a']) {
        puts("No");
        return 0;
    }
    puts("Yes");
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int dis[20][100][100];
int g[100][100];
int p[20];
int q[20][52];
int r[20][52];

int func(int a, int d) {
  int now = 0;
  REP(i,p[a]) {
    if (q[a][i+1] >= d) {
      now += (d-q[a][i]) * r[a][i];
      //cout << now << " " << a << " "  << d << endl;
      return now;
    }
    now += (q[a][i+1]-q[a][i]) * r[a][i];
    //cout << now << " " << q[a][i] << endl;
  }
}

int main() {
  int n,m,c,s,t;
  while(cin>>n>>m>>c>>s>>t,n) {
    REP(i,c)REP(j,n)REP(k,n)dis[i][j][k]=INF;
    REP(i,c)REP(j,n)dis[i][j][j]=0;
    REP(i,m) {
      int x,y,d,c;
      cin>>x>>y>>d>>c;
      x--;y--;c--;
      dis[c][y][x] = dis[c][x][y] = min(dis[c][x][y], d);
    }
    REP(l,c) REP(k,n)REP(i,n)REP(j,n)
      dis[l][i][j] = min(dis[l][i][j], dis[l][i][k]+dis[l][k][j]);
    REP(i,c)cin>>p[i];
    REP(i,c) {
      REP(j,p[i]-1)cin>>q[i][j+1];
      q[i][p[i]] = INF;
      REP(j,p[i])cin>>r[i][j];
    }
    REP(i,n)REP(j,n)g[i][j]=INF;
    REP(i,n)g[i][i]=0;
    REP(i,c) {
      REP(j,n) {
        REP(k,n) {
          if (dis[i][j][k] == INF) continue;
          g[j][k] = min(g[j][k], func(i,dis[i][j][k]));
        }
      }
    }
    REP(k,n)REP(i,n)REP(j,n)g[i][j]=min(g[i][j],g[i][k]+g[k][j]);
    if (g[s-1][t-1] == INF) cout << -1 << endl;
    else cout << g[s-1][t-1] << endl;
  }
}

Measured memory_bytes: 1696
from itertools import permutations
n = int(input())
p = list(map(int,input().split()))
q = list(map(int,input().split()))

x = permutations(sorted(p))
t =0
s = 0;
c =0;
for i,j in enumerate(x):
	if p == list(j):
		s = i+1
	if q== list(j):
		c = i+1;
		
		
		
print(abs(s-c))


Measured memory_bytes: 9188
s=input()
ans=[0,0]
n=0
S=0
w=0
e=0
for i in range(len(s)):
    if s[i]=="N":
        n=1
    elif s[i]=="S":
        S=1
    elif s[i]=="W":
        w=1
    elif s[i]=="E":
        e=1
print("Yes" if n*S==1 and (w+e==2 or w+e==0) or w*e==1 and (n+S==2 or n+S==0) else "No")

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

const long long MOD = 2019;

int main() {
    long long L, R;
    cin >> L >> R;
    if (R - L >= 2019) {
        cout << 0 << endl;
        return 0;
    }

    long long res = 1LL << 60;
    for (int i = L % MOD; i <= R % MOD; i++) {
        for (int j = i + 1; j <= R % MOD; j++) {
            res = min(res, i * j % MOD);
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  
int main(){
	int N, ns, nh, nt;
  	cin >> N;
  	ns = N / 1000;
  	nh = N / 100 - ns * 10;
  	nt = N / 10 - ( N / 100 )* 10;
  
  	if(ns == nh){
      	if(nh == nt)	
	      	cout << "Yes" << endl;
	  	else 
      		cout << "No" << endl;
    }
  	else if(nh == nt){
    	if(nt == N % 10)
	      	cout << "Yes" << endl;
	  	else 
      		cout << "No" << endl;
    }
  	else
      	cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int a[200050];

int main(){
  int n,k; cin >> n >> k;
  for(int i=0;i<n;i++){
    int b; cin >> b; a[b-1]++;
  }
  sort(a,a+n);
  int ans=n;
  for(int i=0;i<k;i++) ans -= a[n-1-i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
n = int(raw_input())
solvetime = map(int, raw_input().split())
solvesum = 0
for i in range(0, n):
	solvesum = solvesum + solvetime[i]

m = int(raw_input())
for i in range(0, m):
	inpt = map(int, raw_input().split())
	print solvesum - solvetime[inpt[0]-1] + inpt[1]

Measured memory_bytes: 2568
#include<iostream>
#include<iomanip>
#include<limits>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>


using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define big ((ll)(1e9)+7)


// double c(double x)
// {
//   double X = x;
//   X = int(X) % 10;
//   return X;
// }

int main()
{
  int x;
  cin >> x;
  int ans = x;
  bool flag = false;
  while(true)
  {
    flag = false;
    for(int i = 2;i < ans;i++)
    {
      if(ans%i == 0)
      {
        ans++;
        flag = true;
        break;
      }
    }
    if(!flag)
    {
      cout << ans << endl;
      break;
    }
  }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	ll a[2], c[2];
	cin >> a[0] >> a[1] >> c[0] >> c[1];

	ll max = a[0] * c[0];
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 2; j++) {
			max = (max < a[i] * c[j] ? a[i] * c[j] : max);
		}
	}

	cout << max << '\n';

	return 0;
}


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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

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

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

template <typename T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<typename T, size_t size> void fill(T (&ary)[size], const T& val){
    fill_n((T*)ary, size, val);
}

void solve() {
    //const i64 mod = 1'000'000'007;
    i64 N;
    cin >> N;

    map<string,vector<pair<int,int>>> mp;
    rep(i,0,N){
        string S;
        int P;
        cin >> S >> P;
        mp[S].emplace_back(make_pair(P,i));
    }
    
    for(auto &tmp:mp){
        auto &ps=tmp.second;
        sort(rbegin(ps),rend(ps));
        for(auto& p:ps){
            cout << p.second+1 << endl;
        }
    }
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 256
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>
#include <stack>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repr(i, n) for(int i = n - 1; i >= 0; i--)

using namespace std;
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

ll mod = 1e9 + 7;

ll mypow(ll a, ll n){
  ll x = 1;
  while(n > 0)
  {
    if(n & 1ll)
    {
      x = (x * a) % mod;
    }
    a = (a * a) % mod;
    n >>= 1;
  }
  return x;
}


template <typename number>
pair<number, number> extended_euclid(number a, number b)
{
  number r0, r1, a0, a1, b0, b1;
  r0 = a; r1 = b;
  a0 = 1; a1 = 0;
  b0 = 0; b1 = 1;
  while (r1>0) {
    number q1 = r0 / r1;
    number r2 = r0 % r1;
    number a2 = a0 - q1 * a1;
    number b2 = b0 - q1 * b1;
    r0 = r1 ; r1 = r2;
    a0 = a1 ; a1 = a2;
    b0 = b1 ; b1 = b2;
  }
  number c = r0;
  a = a0; //x
  b = b0; //y
  return  {a, c};
}

int main()
{
  ll n, k;
  cin >> n >> k;
  vl memo(k + 1, 0);
  ll result = 0;
  for(ll i = k; i > 0; i--)
  {
    ll cand = k / i;
    memo[i] = mypow(cand, n);
    for(ll j = i + i; j <= k; j += i) memo[i] = (memo[i] - memo[j] + mod) % mod;
    ll temp = (memo[i] * i) % mod;
    result = (result + temp) % mod;
  }
  cout << result << endl;
}


Measured memory_bytes: 3984
while true
    n = gets.to_i
    break if n == 0
    arr = []
    n.times{arr << gets.chomp.split}
    k = gets.chomp
    h = Hash.new(0)
    arr.each{|ar| ar.each{|word| h[word] += 1 if word[0] == k}}
    answer = []
    h.sort_by{|k, v| [-v, k]}[0, 5].each{|k, v| answer << k}
    puts (answer.length == 0 ? "NA" : answer.join(" "))
end



Measured memory_bytes: 7148
#include<cstdio>
#include<iostream>
#include<ctype.h>
#include<string>
using namespace std;
int main(){
	string S;
	cin >> S;
	int a = 0, b = 0, c = 0;
	for(int i = 0; i <= 2; i++){
		if(S[i] == 'a'){
			a++;
		}
		else if(S[i] == 'b'){
			b++;
		}
		else if(S[i] =- 'c'){
			c++;
		}
	}
	if(a == 1 && b == 1 && c == 1){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}

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

int main(void){
  int n, x;
  int fx = 0;
  scanf("%d", &n);
  x = n;
  while(x){
    fx += (x % 10);
    x/= 10;
  }
  if(n % fx == 0){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  
  return 0;
}

Measured memory_bytes: 128
def main():
    temp = list(map(int,input().split(' ')))
    H = temp[0]
    W = temp[1]

    if H == 1 or W ==1:
        print(1)
        return 

    # if H % 2 == 1:
    #     h = int(H/2) + 1
    #     h1 = int(H/2)
    # else:
    #     h = int(H/2)
    #     h1 = int(H/2)
    #
    # if W % 2 == 1:
    #     w = int(W/2) + 1
    #     w1 = int(W/2)
    # else:
    #     w = int(W/2)
    #     w1 = int(W/2)

    if (H*W) % 2 == 0:
        print(int(H*W/2))
    else:
        print(int((H*W-1)/2+1))

    #print(w*h + w1*h1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
let quick_sort (a : (int * char * int) array) n cmp =
  let swap i j = let tmp = a.(i) in a.(i) <- a.(j); a.(j) <- tmp in
  let partition p r =
    let i = ref p in
    for j = p to r - 1 do
      if cmp a.(j) a.(r) <= 0 then begin
        swap !i j;
        incr i;
      end
    done;
    swap !i r;
    !i in
  let rec doit p r =
    if p < r then begin
      let q = partition p r in
      doit p (q - 1);
      doit q r
    end in
  doit 0 (n - 1)

let stable_p (a : (int * char * int) array) n =
  let rec doit i =
    if i = n then true
    else if (fun (xi, _, xd) (yi, _, yd) -> xd = yd && xi > yi) a.(i-1) a.(i) then false
    else doit (i + 1) in
  doit 1

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let n = read_int () in
  let a = Array.init n (fun i ->
    match read_line () |> split_on_char ' ' with
    | [c; d] -> (i, c.[0], int_of_string d)
    | _ -> assert false) in
  quick_sort a n (fun (_, _, x) (_, _, y) -> compare x y);
  print_endline (if stable_p a n then "Stable" else "Not stable");
  Array.iter (fun (_, c, d) -> Printf.printf "%c %d\n" c d) a

Measured memory_bytes: 9936
#include "bits/stdc++.h"
using namespace std;
int a[28]={0};
int main()
{
    char s[5]={0};
    int i;
    int count=0;
    scanf("%s",s);
    for(i=0;i<4;i++)
    {
        if(a[s[i]-'A']==1)
        {
            count++;
        }
        a[s[i]-'A']++;
    }
    if(count==2)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
} 

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, u: "List[int]", v: "List[int]", w: "List[int]"):
    A = [0] * N
    G = [[] for _ in range(N)]
    for i in range(N-1):
        G[u[i]-1].append((v[i]-1, w[i]))
        G[v[i]-1].append((u[i]-1, w[i]))
    stack = [0]
    visited = [0] * N
    while(len(stack) > 0):
        vv = stack.pop()
        visited[vv] = 1
        for k in G[vv]:
            if visited[k[0]] == 0:
                if k[1] % 2 == 0:
                    A[k[0]] = A[vv]
                else:
                    A[k[0]] = abs(A[vv] - 1)
                stack.append(k[0])
    for a in A:
        print(a)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    u = [int()] * (N-1)  # type: "List[int]" 
    v = [int()] * (N-1)  # type: "List[int]" 
    w = [int()] * (N-1)  # type: "List[int]" 
    for i in range(N-1):
        u[i] = int(next(tokens))
        v[i] = int(next(tokens))
        w[i] = int(next(tokens))
    solve(N, u, v, w)

if __name__ == '__main__':
    main()


Measured memory_bytes: 48276
#include <stdio.h>

int min(int a,int b)
{
	if(a > b){
		return b;
	}else{
		return a;
	}
}

int main(void)
{
	int a,b,k;
	
	scanf("%d %d %d",&a,&b,&k);
	
	int i,count = 0;
	
	for(i = min(a,b); i > 1; i--){
		if(a % i == 0 && b % i == 0){
			count = count + 1;
		}
		if(count == k){
			break;
		}
	}
	
	printf("%d\n",i);
	
	return 0;
	
}
		
		
	
	

Measured memory_bytes: 128
//Created Time:2020年03月20日 星期五 15时31分03秒
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 300005

using namespace std;

const int mod = 1e9 + 7;

int n;
int ch[10][2], f[N][10];
char s[N];

int main(){
	ch[1][0] = 2; ch[1][1] = 3; ch[2][0] = 5; ch[2][1] = 6;
	ch[3][0] = 7; ch[3][1] = 4; ch[4][0] = 4; ch[4][1] = 4;
	ch[5][0] = 2; ch[5][1] = 2; ch[6][0] = 2; ch[6][1] = 3;
	ch[7][0] = 8; ch[7][1] = 3; ch[8][0] = 7; ch[8][1] = 7;
	scanf("%s", s + 1); int len = strlen(s + 1); f[0][1] = 1;
	for(int i = 1; i <= len; ++i)
		for(int j = 1; j <= 8; ++j){
			int w = f[i - 1][j]; if(!w) continue;
			if(s[i] == '?') (f[i][ch[j][0]] += w) %= mod, (f[i][ch[j][1]] += w) %= mod;
			else (f[i][ch[j][s[i] - '0']] += w) %= mod;
		}
	cout << (f[len][3] + f[len][4]) % mod << endl;
	return 0;
}

Measured memory_bytes: 12288
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef double db;
//mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
//int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
int n,m,k,cnt=0; 
int main() {
	scanf("%d%d%d",&n,&m,&k);
	int h=n/k;
	if(n%k!=0)h++;
	while(h*k<=m){
		h++; 
		cnt++; 
	}
	cout<<cnt;
} 

Measured memory_bytes: 3624
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n,m,k=n1()

def cmb(n, k, mod, fac, ifac):
    """
    nCkを計算する
    """
    k = min(k, n-k)
    return fac[n] * ifac[k] * ifac[n-k] % mod


def make_tables(mod, n):
    """
    階乗テーブル、逆元の階乗テーブルを作成する
    """
    fac = [1, 1] # 階乗テーブル・・・(1)
    ifac = [1, 1] #逆元の階乗テーブル・・・(2)
    inverse = [0, 1] #逆元テーブル・・・(3)

    for i in range(2, n+1):
        fac.append((fac[-1] * i) % mod)
        inverse.append((-inverse[mod % i] * (mod//i)) % mod)
        ifac.append((ifac[-1] * inverse[-1]) % mod)
    return fac, ifac

ans=0
a=1
MOD=998244353
fac, ifac = make_tables(MOD, n-1)
        
for i in range(k+1):
    ans+=m*pow(m-1,n-1-i,998244353)*cmb(n-1, i, MOD, fac, ifac)
print(ans%998244353)

Measured memory_bytes: 32840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define RI(a) scanf("%d",&a)
#define RII(a,b) scanf("%d%d",&a,&b)
#define RIII(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define F first
#define S second
#define REP(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
//}}}
const ll maxn=100005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=2000000000;

int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<max(0,min(b,d)-max(a,c));
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A_list = [int(e) for e in input().split()]

even_cnt = 0
odd_cnt = 0

for A in A_list:
    if A%2 == 0:
        even_cnt += 1
    else:
        odd_cnt += 1
        
#偶数の和は偶数
#奇数の和は偶数
#∴奇数の個数が偶数→偶数1個に縮まる→偶数は何個あっても最終的に偶数1個になるのでYES
#∴奇数の個数が奇数→奇数1個偶数1個に縮まる→NG(ただし1個かつ偶数0個なら特例OK)

if (odd_cnt == 1 and even_cnt == 0)or(odd_cnt%2==0):
    print("YES")
else:
    print("NO")

Measured memory_bytes: 20012
while True:
    a,op,b=(input().split())
    a = int(a)
    b = int(b)
    if op =="?":
        break
    elif op =="+":
        print(int(a+b))
    elif op =="-":
        print(int(a-b))
    elif op =="*":
        print(int(a*b))
    elif op =="/":
        print(int(a//b))


Measured memory_bytes: 5596
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>

#define fo(i,j,l) for(int i=j;i<=l;++i)
#define fd(i,j,l) for(int i=j;i>=l;--i)

using namespace std;
typedef long long ll;
const ll N=2020,mo=1e9+7;

ll f[N][N][2];

int n,k,l,o,p;

int main()
{
	cin>>n>>k;
	f[n][0][1]=f[n][1][2]=1;
	fd(i,n-1,1){
		fd(l,n,0)f[i+1][l][1]=(f[i+1][l][1]+f[i+1][l+1][1])%mo;
		fo(l,0,n){
			f[i][l+1][2]=(f[i][l+1][2]+f[i+1][l][2]+f[i+1][l][1])%mo;
			f[i][l][1]=(f[i][l][1]+f[i+1][l][1]+f[i+1][l][2])%mo;
		}
	}
	ll ans=f[1][n-k][1];
	fo(i,1,n-k-1)ans=ans*2%mo;
	cout<<ans;
}

Measured memory_bytes: 63744
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;
lint x[100000];
bool v[100000]={false};
vector<pair<int,int> > c[100000];

int main(){
  bool f=true;
  int N,M;
  cin>>N>>M;
  REP(i,M){
    int L,R,D;
    cin>>L>>R>>D;
    L--;R--;
    c[L].push_back(make_pair(R,D));
    c[R].push_back(make_pair(L,-D));
  }
  queue<int> q;
  REP(r,N){
    if(v[r])continue;
    v[r]=true;
    lint ma=0;
    lint mi=0;
    x[r]=0;
    q.push(r);
    while(!q.empty()){
      int p=q.front();
      q.pop();
      for(auto e:c[p]){
        int pi=e.first;
        int di=e.second;
        if(v[pi]){
          if(x[pi]!=x[p]+di)f=false;
          continue;
        }
        q.push(pi);
        x[pi]=x[p]+di;
        ma=max(ma,x[pi]);
        mi=min(mi,x[pi]);
        v[pi]=true;
      }
    }
    if((ma-mi)>1e9)f=false;
  }
  // REP(i,N)cerr<<x[i]<<endl;
  cout<<(f?"Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 9856
#include<bits/stdc++.h>
using namespace std;
char a[17]={'C','O','D','E','F','E','S','T','I','V','A','L','2','0','1','6'};
string b;
int main()
{
	int bj=0;
    cin>>b;
    for(int i=0;i<16;i++)if(b[i]==a[i])bj++;
    cout<<16-bj<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    //ios_base::sync_with_stdio(0);
    int a,b;
    while(cin>>a>>b){
        if(a>=1 && a<=9 && b>=1 && b<=9) cout<<a*b<<endl;
        else cout<<-1<<endl;
    }
}


Measured memory_bytes: 256
s = input()
t = input()
len_s = len(s)
len_t = len(t)
min = len_t
for i in range(len_s-len_t+1):
    text = s[i:i+len_t]
    kaisu = 0
    for j in range(len(text)):
        if text[j] != t[j]:
            kaisu += 1
    if kaisu < min:
        min = kaisu
print(min)


Measured memory_bytes: 9056
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
#define int long long

main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, x, s;
    cin >> n >> x;
    
    vector <int> c, u, l, zysk;
    vector <pair <int,int> > ds;
    c.resize(n);
    l.resize(n);
    u.resize(n);
    s = 0;
    zysk.resize(n);
    ds.resize(n);
    for(int i = 0; i <n; ++i){
        cin >>c[i] >>  l[i] >> u[i];
        s -= l[i]*c[i];
    }
    for(int i = 0; i < n; ++i){
        zysk[i] = u[i]*x + l[i]*c[i] - u[i]*c[i];
        ds[i] = {zysk[i], i};
    }
    sort(ds.begin(), ds.end());
    reverse(ds.begin(), ds.end());
    int beg = 0, end = n*x;
    while(end - beg > 0)
    {
        int mid = end + beg;
        mid /= 2;
        int k = mid/x;
        int reszta = mid % x;
        int wynik = s;
        int ans = -1000000;
        for(int j = 0; j < k; ++j){
            wynik += ds[j].first;
        }
        ans = max(ans, wynik);
        if(reszta){
            
            for(int j = 0; j < n; ++j){
                int w = ds[j].second;
                int r = ds[k].second;
                int cop_wyn = wynik;

                if(j < k) {
                    cop_wyn += zysk[r];
                    cop_wyn -= zysk[w];
                }
                if(reszta > c[w]){
                    cop_wyn += reszta*u[w] + l[w]*c[w] - u[w]*c[w];
                }
                else {
                    cop_wyn += reszta*l[w];
                }
                ans = max(ans, cop_wyn);
            }
        }
        if(ans >= 0){
            end = mid;
        }
        else {
            beg = mid + 1;
        }
    }
    cout << beg << '\n';
}

Measured memory_bytes: 4992
S=`dd`
n=S.size
c=0
a=0
(n-1).downto(0){|i|
(S[i]=="A"&&a+=c)||(i>0&&S[i-1]=="B"&&S[i]=="C"&&c+=1)||(S[i]=="B"&&S[i+1]=="C"||c=0)
}
p a

Measured memory_bytes: 2296
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string S;
    cin >> S;

    bool b = true;

    for (int i = 0; i < S.size(); i++) {
        if (i % 2 == 0) {
            if (!(S.at(i) != 'L')) {
                b = false;
                break;
            }
        } else {
            if (!(S.at(i) != 'R')) {
                b = false;
                break;
            }
        }
    }

    cout << (b ? "Yes" : "No") << endl;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  while(1) {
    int w, d; cin >> w >> d;
    if(w == 0 && d == 0) break;
    map<int, int> mf, ms;
    int tmp = 0;
    REP(i, w) {
      cin >> tmp;
      mf[tmp]++;
    }
    REP(i, d) {
      cin >> tmp;
      ms[tmp]++;
    }
    int ans = 0;
    MFOR(i, mf) {
      ans += i->first * max(i->second, ms[i->first]);
    }
    MFOR(i, ms) {
      if(mf[i->first] == 0) ans += i->first * i->second;
    }
    cout << ans << endl;
  }
}



Measured memory_bytes: 2992