akhauriyash/Code-Regression huggingface dataset:
// Marcin Knapik
#include<bits/stdc++.h>
// #pragma GCC optimize("O3")
using namespace std;

typedef long long               ll;
typedef unsigned long long      ull;
typedef pair<ll, ll>            pll;
typedef pair<int, int>          ii;
typedef vector<int>             vi;
typedef vector<ii>              vii;
typedef vector<vi>              vvi;
typedef vector<vector<ii>>      vvii;
typedef vector< ll >            vll;
typedef vector< pll >           vpll;
typedef long double             ld;

#define boost                   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define szy                     first
#define gi                      second
#define sz(a)                   (int)(a).size()
#define pb                      push_back
#define all(c)                  (c).begin(), (c).end()
#define rall(c)                 (c).rbegin(), (c).rend()
#define REP(i, a, b)            for (int i = (a); i <= (b); i++)
#define FOR(i, a)               for (int i = 0; i < (a); i++)
#define TRAV(i, n)              for(auto&i:n)
#define beg(x)                  (*(x.begin()))
#define re(x)                   int x; cin >>x;   
#define f                       first
#define s                       second

template <class T> inline bool setmin(T &a, T b){if (a > b)return a = b, 1;return 0;}
template <class T> inline bool setmax(T &a, T b){if (a < b)return a = b, 1;return 0;}

template<class T> inline T fast(T a,T b,T mod) {ll res = 1; while(b){if(b&1) res = (res*a)%mod;a = (a*a)%mod;b >>= 1;}return res;}
template<class T> inline T russian(T a, T b, T mod) {ll res = 0; while(b){if(b&1) res = (res + a)%mod; a = (a+a)%mod; b>>=1;}return res;}
template <class T> istream &operator>>(istream &os, vector<T> &container){for (auto &u : container)os >> u;return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &container){for (auto &u : container)os << u << " ";return os;}
template<typename T> inline T gcd(T a, T b) { while (b)swap(a %= b, b); return a; }

const ll T = 1 << 18;
const ll INF = 1e9 + 7;
const ll mod = 998244353;
const ll BIG_INF = 1e18 + 7;
const ll  N = (1<<21) + 7;
const int LOG = 21;

ll n, m, k;

signed main(){
    boost;

    cin >> n;
    vi A(n);
    cin >> A;
    vi B(n);
    cin >> B;
    vi C(n-1);
    cin >> C;
    ll ans = 0;
    for(int i =0; i <n-1; i++){
    	if(A[i] + 1 == A[i+1]){
    		ans += C[A[i]-1];
    	}
    }
    FOR(i, n)
    	ans+= B[i];
    cout << ans;
}

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

using namespace std;

int main() {
	int num;
	char blood[100];
	char row[1000];
	map<string, int> type;
	type.insert(make_pair("A", 0));
	type.insert(make_pair("B", 0));
	type.insert(make_pair("O", 0));
	type.insert(make_pair("AB", 0));
	while(cin>>row){
		if(cin.eof()) break;
		sscanf(row,"%d,%s", &num, &blood);
		type[blood]++;
	}
	cout<<type["A"]<<endl;
	cout<<type["B"]<<endl;
	cout<<type["AB"]<<endl;
	cout<<type["O"]<<endl;
	return 0;
}

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

int main(){
	bool p[100000];
	p[0]=p[1]=false;
	for(int i=2;i<100000;i++){
		p[i]=true;
	}
	for(int i=2;i*i<100000;i++){
		if(p[i])
			for(int j=i*i;j<100000;j+=i){
				p[j]=false;
			}
	}

	while(1){
		int count=0;
		int N;
		cin>>N;
		if(N==0)
			break;
		for(int i=2;i<(N/2)+1;i++){
			if(p[i]&&p[N-i])
				count++;
		}
		cout<<count<<endl;
	}
	return 0;
}

Measured memory_bytes: 3080
function main(input) {
    var n = input[0]-0;
    var lists = [];
    var ansmap = {};
    for(var i=1;i<=n;i++){
        var str = input[i];
        var map = {};
        for(var j=0;j<str.length;j++){
            map[str[j]] = map[str[j]]?map[str[j]]+1:1;
            ansmap[str[j]] = 60;
        }
        lists.push(map);
    }
    var keys = Object.keys(ansmap).sort((a,b)=>a>b?1:-1);
    for(var i=0;i<n;i++){
        var list = lists[i];
        for(var j=0;j<keys.length;j++){
            ansmap[keys[j]] = Math.min(ansmap[keys[j]], list[keys[j]]||0);
        }
    }
    var ans = "";
    keys.forEach(key=>{
        for(var i=0;i<ansmap[key];i++) ans += key;
    })
    console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


Measured memory_bytes: 7756
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long INF=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111





	void solve(){

		ini(n);
		vi morty(n);
		FOR(i,0,n){
			in(morty[i]);
		}
		int rick = INF;
		FOR(i,-100,101){
			int tmp = 0;
			FOR(i1,0,n){
				tmp+=pow((morty[i1]-i),2);
			}
			rick = min(rick,tmp);
		}		
		out(rick);












	}









































int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		int n = sc.nextInt(), k = sc.nextInt();
		int[] a = new int[n];
		int f = 1, b = 1;
		boolean c = false;
		int ans = 0;
		for(int i = 0; i < n; i++) {
			int x = sc.nextInt();
			if(x != 1 && !c) {
				f++;
			}else if(x == 1) {
				c = true;
			}else {
				b++;
			}
		}
		if(n == k) {
			ans = 1;
		}else if(f <= k || b <= k) {
			ans = num(n,k);
		}else {
			ans = num(f,k)+num(b,k);
		}
		int check = num(n,k);
		if(ans > check) {
			ans = check;
		}
		System.out.println(ans);
	}

	static int num(int n, int k) {
		int ans = (n-1)/(k-1);
		if((n-1)%(k-1) != 0) {
			ans++;
		}
		return ans;
	}

	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}


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

int main(){
    int s, t;
    int n;
    s = 0;
    t = 0;
    for(int i=0;i<4;i++){
        cin >> n;
        s += n;
    }
    for(int i=0;i<4;i++){
        cin >> n;
        t += n;
    }
    if(s > t){
        cout << s << endl;
    }else{
        cout << t << endl;
    }
}

Measured memory_bytes: 0
import java.util.*;
import java.lang.*;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long[] a = new long[5];
        
        
//        for(int i=0; i<5 ; i++){
//            System.out.println(a[i]);
//        }

        for (int q = 0; q < 5; q++) {
            a[q] = sc.nextLong();
        }
        Arrays.sort(a);
        long ans =0;
        if(n % a[0]==0){
            ans = (n/a[0]) +4;

        }else {
//            System.out.println(a[0]);
            ans = (n/a[0]) +5;
        }
        System.out.println(ans);
//        long[] city = new long[6];
//        //初期の配置
//        city[0] = n;
//        for (int i = 1 ; i < 6; i++) {
//            city[i] = 0;
//        }
//        int count = 0;
//        //移動
//        for(int j =0; j < n + 5; j++) {
//            for (int i = 4; i >= 0; i--) {
//                if (city[i] < a[i]) {
//                    city[i+1] += city[i];
//                    city[i] = 0;
//                } else if(city[i] >= a[i]){
//                    city[i+1] += a[i];
//                    city[i] -= a[i];
//                }
//
//            }
//            count++;
//            if (city[5] == n) {
//                System.out.println(count);
//                break;
//            }
//        }

        }
    }

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string a,b;
    cin >> a >> b;
    if(a==b.substr(0,a.length()))
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}

Measured memory_bytes: 3652
//Created Time:2019年10月27日 星期日 20时09分40秒
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#define db double
#define N 602

using namespace std;

int n, m;
db mat[N][N], deg[N], ans[N], tmp[N];
bool mp[N][N];

int main(){
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; ++i){
		int u, v; scanf("%d%d", &u, &v);
		mp[u][v] = true; deg[u] += 1.0;
	}
	for(int i = 1; i <= n; ++i){
		for(int j = 1; j <= n; ++j)
			if(mp[i][j])
				mat[i][j] = -1.0 / deg[i];
		mat[i][i] = 1.0; mat[i][n + 1] = 1.0;
	}
	mat[n][n + 1] = 0;
	for(int i = 1; i <= n; ++i){
		int mx = i;
		for(int j = i + 1; j <= n; ++j)
			if(fabs(mat[j][i]) > fabs(mat[mx][i])) mx = i;
		if(i != mx) swap(mat[i], mat[mx]);
		db div = mat[i][i];
		for(int j = i; j <= n + 1; ++j) mat[i][j] /= div;
		for(int j = i + 1; j <= n; ++j){
			div = mat[j][i];
			for(int k = i; k <= n + 1; ++k) mat[j][k] -= mat[i][k] * div;
		}
	}	
	for(int i = n; i; --i){
		ans[i] = mat[i][n + 1];
		for(int j = n; j > i; --j) ans[i] -= ans[j] * mat[i][j];
	}
	
	memcpy(tmp, ans, sizeof tmp);
	db res = ans[1];
	for(int i = 1; i <= n; ++i)
		if(deg[i] > 1.0){
			double mx = 0.0, sum = 0.0;
			for(int j = i + 1; j <= n; ++j)
				if(mp[i][j]) sum += ans[j], mx = max(mx, ans[j]);
			ans[i] = (sum - mx) / (deg[i] - 1) + 1;
			for(int j = i - 1; j; --j){
				ans[j] = 0.0;
				for(int k = j + 1; k <= n; ++k)
					if(mp[j][k]) ans[j] += ans[k];
				ans[j] /= deg[j]; ans[j] += 1.0;
			}
			res = min(res, ans[1]); memcpy(ans, tmp, sizeof ans);
		}
	printf("%.10lf", res);
	return 0;
}


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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;


const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


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

  LL N,M;
  cin >> N >> M;
  LL K;
  cin >> K;

  vector<LL> hoge(510000, 0);

  FOR(i,1,500000){
    hoge[i] += i + hoge[i-1];
  }

  LL sum = 0;

  REP(i,N){
    sum += (hoge[N - i - 1]) * (M * M)%mod;
    sum %= mod;
  }
  REP(j,M){
    sum += (hoge[M - j - 1]) * (N*N)%mod;
    sum %= mod;
  }

  COMinit();


  sum*=COM(N * M - 2, K - 2);
  sum %= mod;

  cout << sum << endl;
}


Measured memory_bytes: 16256
#include <iostream>
#include <string>
using namespace std;
int main(){
  string a,b;
  cin >> a >> b;
  
  auto lt = [](auto a,auto b){
    if(a.size()-b.size())
      return a.size() < b.size();
    return a < b;
  };
  
  if(lt(a, b))
    cout << "LESS" << endl;
  else if(lt(b, a))
    cout << "GREATER" << endl;
  else
    cout << "EQUAL" << endl;
    
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i, s, e) for (int i = s; i < e; i++)
#define endl '\n'
int main()
{
    lli a, b, c, d;
    cin >> a >> b >> c >> d;
    lli ac = a * c;
    lli ad = a * d;
    lli bc = b * c;
    lli bd = b * d;
    lli res = max(ac, max(bc, max(ad, bd)));
    cout << res << endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <math.h>
using namespace std;

void solve(){
  char N, M;
  cin >> N >> M ;
  long tmp1,tmp2;
  if(N==M ){
    std::cout <<"H";
  }else{
    std::cout << "D";
  }
  
}

int main() {
  solve();
}

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

int main()
{
	int k;
	string s;
	cin >> k >> s;
	if(s.size() <= k){
		cout << s << endl;
	}else{
		cout << s.substr(0, k) << "..." << endl;
	}

	return 0;
}

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

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

    if (n % 2 == 0)
        cout << n << endl;
    else
    {
        cout << n * 2 << endl;
    }
}


Measured memory_bytes: 256
from collections import Counter
n = int(input())

x = [0] * n
y = [0] * n
for i in range(n):
    x[i], y[i] = map(int, input().split())

l = []
for i in range(n):
    pre = [x[i], y[i]]
    for j in range(n):
        if i == j:
            continue
        l.append("{}_{}".format(x[j] - pre[0], y[j] - pre[1]))

if len(l) > 0:
    c = Counter(l)
    a = int(c.most_common()[0][1])
    print(n - a)
else:
    print(1)


Measured memory_bytes: 3820
'use strict';
    (function(stdin) {
      //declare function

      //declare variable
      var inputs = stdin.toString().trim().split('\n').map(Number);
      inputs = inputs.slice(0, inputs.indexOf(0));
      //main
      for (var i = 0, len = inputs.length; i < len; i++) {
        console.log('Case ' + (i + 1) + ': ' + inputs[i]);
      }
      //display
      //console.log(inputs);
    })(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 20584
#include <bits/stdc++.h>
#include <cstring>
#include <map>
#include <set>
#define int long long int
using namespace std;
const int cons = 1000000007;

int dp[100003];

signed main() {
 
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    #ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    //  freopen("output.txt", "w", stdout);
    #endif
    
    int n, i, k, j;
    cin>>n>>k;
    int h[n];
    for(i=0;i<n;i++){
        cin>>h[i];
    }
    memset(dp, 10, sizeof(dp));
    for(i=0;i<=100000;i++){
        dp[i]=100000000000;
    }
    dp[0]=0;
    for(i=1;i<n;i++){
        for(j=1;j<=k;j++){
            if(i-j>=0)
                dp[i]=min(dp[i], dp[i-j]+abs(h[i-j]-h[i]));
        }
    }
    cout<<dp[n-1]<<endl;
}


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

signed main(void)
{
	ll a, v, b, w, t;
	cin >> a >> v >> b >> w >> t;
	if (v > w)
	{
		if (abs(a - b) <= abs(v - w) * t)
		{
			cout << "YES" << endl;
			return 0;
		}
	}	
	cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include<iostream>
using namespace std;
 
int main() {
   string s;
   cin >>s;
   bool a,b;
   a = true;
   int ans,A,Z(0);

   for(int i=0;i < s.length();i++){
       if(s.at(i)== 'A' && a){
           a = false;
           A = i;
       }
       if(s.at(i) == 'Z'){
           Z = i;
       }

   }
   cout << abs(A - Z)+1;
}
   

Measured memory_bytes: 3716
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0

for i in range(n):
    if i >= 1 and a[i] == a[i-1] + 1:
        ans += c[a[i-1]-1]
    ans += b[a[i]-1]
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <numeric>
#include <queue>
#include <cstdio>
#include <cstring>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define all(a) (a).begin(),(a).end()
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define pl pair<ll,ll>
#define inf 1001001001001001000
//#define mod 1000000007
#define mod 998244353
#define pi 3.1415926535
using namespace std;
struct __INIT{
    __INIT(){
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout<<fixed<<setprecision(15);
    }
}__init;
/*
int main(void){
    ll n,m,q;
    cin>>n>>m>>q;
    vvl quer(q,vl(4));
    rep(i,q){
        cin>>quer[i][0]>>quer[i][1]>>quer[i][2]>>quer[i][3];
    }
    rep(i,(1<<n)){
        vl pitsu(n,-);
        rep(j,n){
            if(i&(1<<j) == 1){
                ll now = pitsu[quer[j][1]-1]-pitsu[quer[j][0]-1];
                if(now == pitsu[quer[j][2]]) continue;
                else if(now < pitsu[quer[j][2]])
            }
        }
    }
}
*/

int main(void){
    ll n,m;
    cin>>n>>m;
    vb a(n,false);
    ll cnt = 0;
    ll hue = 1;
    if(m%2 == 0){
        rep(i,m/2){
            cout<<i+1<<" "<<m-i+1<<endl;
        }
        rep(i,m/2){
            cout<<m+1+i+1<<" "<<2*m-i+1<<endl;
        }
    }
    else{
        rep(i,m/2+1){
            cout<<i+1<<" "<<m+1-i<<endl;
        }
        rep(i,m/2){
            cout<<i+m+2<<" "<<2*m+1-i<<endl;
        }
    }
}

Measured memory_bytes: 3656
#include <stdio.h>

int main(void)
{
    
    int n,m,a,b,i;
    int city[200]={};
    scanf("%d %d",&n,&m);
    
    for(i=0;i<m;i++){
        scanf("%d %d",&a,&b);
        city[a]++;
        city[b]++;
    }
    for(i=1;i<=n;i++)printf("%d\n",city[i]);
    
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<set>
#include<map>
using namespace std;

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

typedef int i32;
typedef long long int i64;
typedef unsigned long long int ui64;
typedef float f32;
typedef double f64;
typedef long double f128;
typedef pair<int,int> Pi;

constexpr int INF = 1e9 + 7;
constexpr int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int main() {
    int N,K; cin>>N>>K;
    int A[N]; REP(i,N) A[i]=0;
    REP(i,N) {
        int tmp;
        cin>>tmp;
        A[tmp-1]++;
    }
    sort(A,A+N);
    int cnt=0;
    int ans=0;
    REP(i,N) if (A[i]>0) cnt++;
    if (cnt>K) FOR(i,N-cnt-1,N-K) ans += A[i];
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    int a = s[0] - '0', b = s[1] - '0', c = s[2] - '0', d = s[3] - '0';
    int x,y,z;
    for(int i = -1; i <= 1; i += 2){
        for(int j = -1; j <= 1; j += 2){
            for(int k = -1; k <= 1; k += 2){
                if(a + b * i + c * j + d * k == 7){
                    x = i, y = j, z = k;
                    break; 
                }
            }
        }
    } 
    cout << a;
    if(x == -1) cout << '-';
    else        cout << '+';
    cout << b;
    if(y == -1) cout << '-';
    else        cout << '+';
    cout << c;
    if(z == -1) cout << '-';
    else        cout << '+';
    cout << d;
    cout << "=7";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll s;
bool use[1000008];

int main(){
	cin >> s;
	memset(use, 0, sizeof(use));	
    
    ll m = 1;
    while(use[s] != true){
    	use[s] = true;
    	s = (s%2)? 3*s+1 : s/2;
    	m++;
    }
	cout << m;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int > pi;
typedef vector<ll> vi;

#define x first
#define y second
#define pb push_back
#define mp make_pair
#define FOR(a ,b) for(int i = a; i < b; i++) 
#define e "\n"
const int INF = 1e9 + 5;

int main(){
	int n;
	cin >> n;
	vector<int> h (n);
	for(int &x : h) cin >> x;
	
	vector<int> dp (n,INF);
	dp[0] = 0;
	for(int i = 0; i <n;i++){
		for(int j : {i+1, i+2}){
			if(j < n) dp[j] = min(dp[j], dp[i]+abs(h[i]-h[j]));
		}
	}
	cout << dp[n-1] << e;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main() {
    int n, a[100001], i,d,dmin=1000000000,p;
    scanf("%d", &n);
    int max=0;
    for (i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        if (a[i] > max)
            max = a[i];
    }
    for (i = 0; i < n; i++) {
        d = a[i] * 2 - max;
        if (d < 0)
            d = -d;
        if (dmin >= d) {
            dmin = d;
            p = a[i];
        }
    }
    printf("%d %d\n", max, p);
    return 0;
}

Measured memory_bytes: 512
N=int(input())
ans=0
turn=0
AB=[]

#先手は同数以下の要素をひたすらデクリメントすることでアメと余裕分のターン数を稼げる。
#ABには先手が余裕ターン数を消費してアメを稼ぐ必要のある要素を入れる（＝後手の方が少ない要素を入れる）
for i in range(N):
  a,b=map(int,input().split())
  if a<=b:
    ans+=a
    turn+=(b-a)
  else:
    #AB.append([a,a-b]) <-間違い
    AB.append([a,b])
    

#turn=0で終了。AB[i][1]を選ぶ場合turn-=AB[i][1],その時turn>0ならばans+=AB[i][0],そうでなければans+=turnで終了。
#定義よりAB[i][1]の総和=turn,つまり、最後に選ぶべきもっとも小さなAB[i][0]を探せば良いか？
#つまり、ABの第１数を昇順、第２数を降順にして、AB[0]のみans+=AB[0][1],そこからans+=AB[i][0]か。

#いや、違うか（WAだった）。上の行コメントを噛み砕くと、「１つだけ-bしたa,残りは全てaを足す」ってこと。
#つまり、aの総和から１度だけbを引くってこと。１回だけなら最小のbを選べば良いんだ！

if turn==0:
  print(0)
else:
  AB=sorted(AB,key=lambda x:x[1])
  for i in range(len(AB)):
    if i==0:
      ans+=(AB[i][0]-AB[i][1])
    else:
      ans+=AB[i][0]
  print(ans)


Measured memory_bytes: 4940
import java.util.Scanner;
class UnionFind{
    private int[] p, rank;
    public UnionFind(int n){
        p = new int[n];
        rank = new int[n];
        for(int i = 0; i < n; i++)
            p[i] = i;
    }
    public int findSet(int i){
        if(p[i] == i)
            return i;
        else
            return findSet(p[i]);
    }
    public boolean isSameSet(int i, int j){
        return findSet(i) == findSet(j);
    }
    public void unionSet(int i, int j){
        if(!isSameSet(i, j)){
            int x = findSet(i), y = findSet(j);
            if(rank[x] > rank[y])
                p[y] = x;
            else{
                p[x] = y;
                if(rank[x] == rank[y])
                    rank[y]++;
            }
        }
    }
}
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        UnionFind union = new UnionFind(n);
        int a, b, z;
        boolean[] know = new boolean[n];
        for (int i = 0; i < m; i++) {
            a = sc.nextInt();
            b = sc.nextInt();
            z = sc.nextInt();
            union.unionSet(a - 1, b - 1);
        }
        int total = 0;
        for(int i = 0; i < n; i++){
            int rank = union.findSet(i);
            if(!know[rank]){
                total += 1;
                know[rank] = true;
            }
        }
        System.out.println(total);
    }
}

Measured memory_bytes: 92940
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    long long int n, x, m;
    cin >> n >> x >> m;
    long long int res = 0;
    unordered_map<long long int, int> um;
    long long int index = 1;
    vector<long long int> v(1, 0);
    while (index <= n) {
        if (um.find(x) == um.end()) {
            um[x] = index;
            index++;
            v.push_back(x);
        } else {
            long long int cir = (n - index + 1) / (index - um[x]);
            long long int loop = index - um[x];
            long long int loop_sum = 0;
            for (int i = 0; i < loop; i++) {
                loop_sum += v[v.size() - 1 - i];
            }
            res += loop_sum * cir;
            index = cir * loop + index;
            break;
        }
        res += x;
        x = x * x % m;
    }
    while (index <= n) {
        res += x;
        index++;
        x = x * x % m;
    }
    cout << res << endl;
}






Measured memory_bytes: 5584
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

#ifdef DEBUG
mt19937 mrand(300); 
#else
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count()); 
#endif

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 1e6 + 5;
char tmp[maxn];
int n;
string s;

bool read() {
  if (scanf("%s", tmp) < 1) {
    return false;
  }
  s = tmp;
  n = sz(s);
  return true;
}

bool check(int len) {
  int l = 0, r = len;
  bool odd = false;
  for (int i = 0; i < n; i++) {
    if (s[i] == '0') {
      l--;
      r--;
    } else if (s[i] == '1') {
      l++;
      r++;
    } else {
      l--;
      r++;
    }
    if (l < 0) {
      l += 1 + (int) odd;
    }
    if (r > len) {
      r -= 1 + (int) odd;
    }
    if (l > r) {
      return false;
    }
    if (l == r) {
      odd = true;
    }
  }
  return true;
}

void solve() {
  int l = 0, r = n;
  while (l < r - 1) {
    int m = (l + r) / 2;
    if (check(m)) {
      r = m;
    } else {
      l = m;
    }
  }
  printf("%d\n", r);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 5448
/* segment_tree.cpp
    任意のモノイドに対してセグメント木を構築する。

    モノイドXに対するセグメント木を構築するために、
        ・X上の二項演算 fx
        ・Xの単位元 ex
    を与える

    RMQ:
        auto fx = [](int x1, int x2) -> int { return min(x1, x2); };
        int ex = numeric_limits<int>::max();
        SegTree<int> rmq(n, fx, ex);
    区間gcd:
        using X = int;
        X ex = numeric_limits<int>::max();
        auto fx = [ex](X x1, X x2) -> X { return (x1 == ex) ? x2 : ((x2 == ex) ? x1 : gcd(x1, x2)); };
        SegTree<X> segGcd(n, fx, ex);
    bitで表した集合とor:
        using X = int;
        auto fx = [](X x1, X x2) -> X { return x1 | x2; };
        X ex = 0;
        SegTree<X> seg(N, fx, ex);

    unverified: AOJ DSL_2_A
        http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_A&lang=jp
 */

#include <bits/stdc++.h>
using namespace std;

/* SegTree<X>(n,fx,ex): モノイド(集合X, 二項演算fx, 単位元ex)についてサイズnで構築
    set(int i, X x), build(): i番目の要素をxにセット。まとめてセグ木を構築する。O(n)
    update(i,x): i 番目の要素を x に更新。O(log(n))
    query(a,b):  [a,b) 全てにfxを作用させた値を取得。O(log(n))
*/
template <typename X>
struct SegTree {
    using FX = function<X(X, X)>;
    int n;
    FX fx;
    const X ex;
    vector<X> dat;
    SegTree(int n_, FX fx_, X ex_) : n(), fx(fx_), ex(ex_), dat(n_ * 4, ex_) {
        int x = 1;
        while (n_ > x) {
            x *= 2;
        }
        n = x;
    }

    void set(int i, X x) { dat[i + n - 1] = x; }
    void build() {
        for (int k = n - 2; k >= 0; k--) dat[k] = fx(dat[2 * k + 1], dat[2 * k + 2]);
    }

    void update(int i, X x) {
        i += n - 1;
        dat[i] = x;
        while (i > 0) {
            i = (i - 1) / 2;  // parent
            dat[i] = fx(dat[i * 2 + 1], dat[i * 2 + 2]);
        }
    }

    // the minimum element of [a,b)
    X query(int a, int b) { return query_sub(a, b, 0, 0, n); }
    X query_sub(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) {
            return ex;
        } else if (a <= l && r <= b) {
            return dat[k];
        } else {
            X vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
            X vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
            return fx(vl, vr);
        }
    }
    /* debug */
    inline X operator[](int a) { return query(a, a + 1); }
    void print() {
        for (int i = 0; i < n; ++i) {
            cout << (*this)[i];
            if (i != n) cout << ",";
        }
        cout << endl;
    }
};

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

    using X = int;
    X ex = numeric_limits<int>::max();
    auto fx = [ex](X x1, X x2) -> X { return (x1 == ex) ? x2 : ((x2 == ex) ? x1 : __gcd(x1, x2)); };
    SegTree<X> segGcd(n, fx, ex);

    vector<int> A(n);
    for (int i = 0; i < n; i++) {
        cin >> A.at(i);
        segGcd.update(i, A[i]);
    }

    int ans = max(segGcd.query(0, n - 1), segGcd.query(1, n));
    for (int i = 1; i < n - 1; i++) {
        ans = max(ans, __gcd(segGcd.query(0, i), segGcd.query(i + 1, n)));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2176
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#define maxn 100009
using namespace std;
const int MOD = 1e9 + 7;
int n;
int a[maxn], cnt[maxn];
long long fact[maxn], rfact[maxn];
long long mgml(long long a, int b){
	long long res = 1;
	while(b){
		if(b & 1)
			res = res * a % MOD;
		a = a * a % MOD;
		b >>= 1;
	}
	return res;
}
long long C(int n, int m){
	if(n < 0 || m < 0) return 0;
	if(n < m)	return 0;
	return fact[n] * rfact[m] % MOD * rfact[n - m] % MOD;
}
int main(){
	int num = 0;
	cin >> n;
	fact[0] = 1;
	for(int i = 1; i < maxn; i++)
		fact[i] = fact[i - 1] * i % MOD;
	for(int i = 0; i < maxn; i++)
		rfact[i] = mgml(fact[i], MOD - 2);
	int p1, p2;
	for(int i = 1; i <= n + 1; i++){
		scanf("%d", &a[i]);
		cnt[a[i]]++;
	}
	for(int i = 1; i <= n; i++){
		if(cnt[i] > 1){
			num = i;
			break;
		}
	}
	for(int i = 1; i <= n + 1; i++){
		if(a[i] == num){
			p1 = i;
			break;
		}
	}
	for(int i = n + 1; i >= 1; i--){
		if(a[i] == num){
			p2 = i;
			break;
		}
	}
	int tot = p1 - 1 + n + 1 - p2;
	for(int i = 1; i <= n + 1; i++){
		long long ans = C(n + 1, i);
		long long cur = C(tot, i - 1);
		ans = ans - cur;
		ans %= MOD;
		ans += MOD;
		ans %= MOD;
		printf("%lld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define F first
#define S second

using namespace std;

int a,b,c,d;

int main()
{
    cin >> a >> b >> c >> d;
    for (int i=0;i<1000;i++)
    {
        if (a<=0||c<=0)break;
        if (i&1)
        {
            a-=d;
        }
        else
        {
            c-=b;
        }
    }
    if (a<=0)cout << "No\n";
    else cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 3624
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
//max_element

int N;
int A[16];
int X[16][16];
int Y[16][16];

int ma = 0;
int cnt = 0;
bool flg[16];

bool check()
{
	bool is_valid = true;
	for (int i = 1; i <= N; i++)
	{
		if (flg[i])
		{
			for (int j = 0; j < A[i]; j++)
			{
				if (Y[i][j] == 1 && !flg[X[i][j]])
				{
					is_valid = false;
				}
				if (Y[i][j] == 0 && flg[X[i][j]])
				{
					is_valid = false;
				}
			}
		}
	}
	return is_valid;
}

void func(int depth)
{
	if (depth > N)
	{
		if (check())
		{
			ma = max(ma, cnt);
		}
		return;
	}

	flg[depth] = false;
	func(depth + 1);
	cnt++;
	flg[depth] = true;
	func(depth + 1);
	cnt--;
}

signed main()
{
	cin >> N;
	for (int i = 1; i <= N; i++)
	{
		cin >> A[i];
		REP(j, A[i])
		{
			cin >> X[i][j] >> Y[i][j];
		}
	}
	func(1);
	cout << ma << endl;
}



Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int n,m,i,c[100005],a,b,v,k,t[100005];
set<int> g[100005];
vector<int>first_half;
vector<int>second_half;
vector<int>total;
int par[209],group[209];
int arra[150000];
vector<int>arr;
map<char,int>cp;
map<int,int>mp;
deque<char>stp1;
deque<char>stp2;
map<int,int>pos;
map<string,int>check;
map<string,string>server;
vector<string>ans1;
vector<string>ans2;
vector<string>ans3;
string server1[1009];
string ip1[1009];
string server2[1009];
string ip2[1009];
ll cashier[109];
ll fir[10009];
ll sec[100009];
ll dice[109];
vector<ll>emoties;
map<ll,ll>skysc;
map<string,ll>iteams;
int main() {
  ll i,j,k,l,p=0,q,t,n,r;
  string item;
  cin>>n;
  for(i=1;i<=n;i++)
  {
    cin>>item;
    iteams[item]++;
    if(iteams[item]==1)
      p++;	
  }
  cout<<p;
  
  
}
  
  
  
  	


Measured memory_bytes: 23980
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;

const int MXN = 12;

int n, m, cap;
vector<vector<int>> a(MXN, vector<int>(MXN));
vector<int> c(MXN);
vector<int> lvl(MXN, 0);
int ans = INT_MAX;

void f(int idx, int prc) {
	if (idx == n) {
		for (int i=0; i<m; i++) {
			if (lvl[i] < cap) {
				return;
			}
		}
		ans = min(ans, prc);
		return;
	}
	f(idx+1, prc);
	for (int j=0; j<m; j++) lvl[j] += a[idx][j];
	f(idx+1, prc+c[idx]);
	for (int j=0; j<m; j++) lvl[j] -= a[idx][j];
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m >> cap;
	for (int i=0; i<n; i++) {
		cin >> c[i];
		for (int j=0; j<m; j++) {
			cin >> a[i][j];
		}
	}
	f(0, 0);
	if (ans == INT_MAX) cout << -1;
	else cout << ans;
}

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    string s, t; cin >> s;
    for(int i = 0; i < s.size(); i++){
        if(i % 2 == 0) t.push_back(s[i]);
    }
    cout << t << endl;
}

Measured memory_bytes: 592
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
struct Point { long double px, py; };
long double crs(const Point& a, const Point& b) { 
	return a.px * b.py - a.py * b.px; 
}
Point crp(Point a1, Point a2, Point b1, Point b2) { 
	Point c; c.px = b2.px - b1.px; c.py = b2.py - b1.py; 
	Point d; d.px = a1.px - b1.px; d.py = a1.py - b1.py;
	Point e; e.px = a2.px - b1.px; e.py = a2.py - b1.py;
	Point f; f.px = a2.px - a1.px; f.py = a2.py - a1.py;
	long double d1 = abs(crs(c, d));
	long double d2 = abs(crs(c, e));
	f.px *= (d1 / (d1 + d2));
	f.py *= (d1 / (d1 + d2));
	Point g; g.px = a1.px + f.px; g.py = a1.py + f.py;
	return g;
}
int main() {
	int N;
	Point A1, A2, B1, B2;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A1.px >> A1.py >> A2.px >> A2.py;
		cin >> B1.px >> B1.py >> B2.px >> B2.py;
		Point G = crp(A1, A2, B1, B2);
		printf("%.1919Lf %.1919Lf\n", G.px, G.py);
	}
	return 0;
}

Measured memory_bytes: 1264
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N,M = II()
X = III()

if N>=M:
    print(0)
    exit()

X.sort()
d = []
for i in range(M-1):
    d.append(X[i+1]-X[i])

d.sort(reverse=True)
print(X[M-1]-X[0]-sum(d[:N-1]))

Measured memory_bytes: 57256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
template <typename T>
inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}

int main(){
    ll a,b;cin>>a>>b;
    bool ex=false;
    rep(c,3){
        if((a*b*c)%2==1){
            ex=true;
            break;
        }
    }

    if(ex) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3544
import bisect
n=int(input())
a=list(map(int,input().split()))
c=max(a)
ct=[[0] for _ in range(c+1)]
for i in range(n):
	ct[a[i]].append(i+1)
ans = -1
memo = -1
for j in range(c+1):
	if max(ct[j])>memo:
		ans += 1
		memo = ct[j][bisect.bisect_right(ct[j], memo)]
	else:
		break
if ct[1]==[0]:
	print(-1)
else:
	print(n-ans)

Measured memory_bytes: 105676
import java.util.*;
public class Main{
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();
      if(c<=a+b)System.out.println(b+c);
      else System.out.println(2*b+a+1);
    }
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

int32_t main(){

        IOS;
     //    int t;
     //    cin >> t;
     //    while(t--){
          string x,y;
          cin >> x >> y;
          int ans=0;
          for(int i=0;i<3;i++){
               if(x[i] == y[i])
                    ans++;
          }
          cout << ans << endl;
     //    }
        
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
import java.util.*;
import java.lang.*; 
import java.util.regex.Pattern;
import java.text.DecimalFormat;
import java.util.stream.IntStream;
public class Main{ 
static int isOn(int S, int j) { return S & (1 << j); }
static int a,b,c;
static int[] dp=new int[4010];
static final int INF=1000000;
static boolean[] prime=new boolean[1000100]; 
public static void main(String[] args)
{ 
Scanner scanner=new Scanner(System.in);
int n=scanner.nextInt();
int m=scanner.nextInt();
int count=0;
int flg=1;
int x=-1,y=Integer.MAX_VALUE;
int[] a=new int[n+1];
for(int i=0;i<m;i++)
{
    int l=scanner.nextInt();
    int r=scanner.nextInt();
    if(l<x && r<x){flg=0;break;}
    if(l>y && r>y){flg=0;break;}
    if(l>x)x=l;
    if(r<y)y=r;
}
if(flg==0)System.out.print(0);
else {
    System.out.print(y-x+1);
}
}
}


Measured memory_bytes: 87540
import itertools

n, m, q = map(int, input().split())
a = [0] * q
b = [0] * q
c = [0] * q
d = [0] * q

for i in range(q):
    a[i], b[i], c[i], d[i] = map(int, input().split())

A = list(itertools.combinations_with_replacement(range(1, m + 1), n))

cnt = 0

for i in range(len(A)):
    tmp = 0
    for j in range(q):
        if(A[i][b[j]-1] - A[i][a[j]-1]) == c[j]:
            tmp = tmp + d[j]
    cnt = max(cnt, tmp)
print(cnt)

Measured memory_bytes: 21616
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,m=map(int,input().split())
half=n//2
lst=[]
tmp=0
if n%2==0:
    for i in range(m):
        if i%2==1:
            lst.append([half-i//2,half+i//2+2])
        else:
            lst.append([1+i//2,n-i//2])

else:
    for i in range(m):
        lst.append([half-i,half+i+1])

for i in range(m):
    print(*lst[i])

# dic=defaultdict(int)
# for i in range(m):
#     tmp=lst[i]
#     dic[tmp[1]-tmp[0]]+=1
#     dic[n-tmp[1]+tmp[0]]+=1
# print(dic)

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

int main() {
	int N, W;
	cin >> N >> W;
	vector<long long> w(N);
	vector<long long> v(N);
	for (int i = 0; i < N; i++) cin >> w[i] >> v[i];

	vector<vector <long long>> dp(N + 1, vector<long long>(W + 1));
	for (int i = 1; i < N + 1; i++) {
		for (int j = 1; j < W + 1; j++) {
			dp[i][j] = max(dp[i][j], dp[i - 1][j]);
			if (j >= w[i - 1])
				dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i - 1]] + v[i - 1]);
		}
	}
	cout << dp[N][W] << endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<vector<int> > v(n);
  for(int i=0; i<n; i++) {
    vector<int> a(2);
    cin >> a[1] >> a[0];
    v[i]=a;
  }
  sort(v.begin(),v.end());
  for(int i=0; i<n; i++) swap(v[i][0],v[i][1]);
  bool u[n];
  memset(u,0,sizeof(u));
  int ans=0;
  for(int i=1; i<=31; i++) {
    int x=50;
    for(int j=0; j<n; j++) {
      if(v[j][0]<=i&&i<=v[j][1]&&!u[j]) {
        u[j]=1;
        x=100;
        break;
      }
    }
    ans+=x;
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int64_t x;
  cin>>x;
  if(x<=6) cout<<1<<endl;
  else if(x<=11) cout<<2<<endl;
  else{
    int64_t S=x/11;
    int64_t A=x%11;
    if(A==0) cout<<S*2<<endl;
    else if(A<=6) cout<<S*2+1<<endl;
    else cout<<S*2+2<<endl;
  }
  
}

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

int main() {
  int a,b;
  string op;

  while(true) {
    cin >> a >> op >> b;
    if (op == "?") {
      break;
    }
    if (op == "+") {
      cout << a + b << endl;
    }
    if (op == "-") {
      cout << a - b << endl;
    }
    if (op == "*") {
      cout << a * b << endl;
    }
    if (op == "/") {
      cout << a / b << endl;
    }
  }
}



Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

#define int long long int

signed main(){

ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t=1;
//cin>>t;
while(t--){


int n;
cin>>n;
map<string,int>m;int ans=0;
for(int i=0;i<n;i++){
    string s;
    cin>>s;
    if(m.count(s)==0){
        ans++;m[s]++;
    }
}
cout<<ans<<endl;

}


}



Measured memory_bytes: 19180
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int a[51];
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	int sum=0;
	for(int i=n-1;i>=n-m;i--) sum+=a[i];
	cout<<sum;
	return 0;
}

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

#define irep(i,n)  for(int i=0;i<(n);i++)
#define irepy(i,n) for(int i=1;i<=(n);i++)
#define jrep(j,n)  for(int j=0;i<(n);j++)
#define jrepy(j,n) for(int j=1;i<=(n);j++)

int main(){

  string s;
  cin >> s;

  if(s=="Sunny") cout <<"Cloudy";
  else if(s=="Cloudy") cout <<"Rainy";
  else if (s=="Rainy") cout <<"Sunny";

  cout << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define li long long
#define itn int
 
using namespace std;
 
inline int nxt(){
	int n;
	scanf("%d", &n);
	return n;
}

template <typename T>
ostream& operator <<(ostream& ostr, const vector<T>& a) {
	ostr << "(";
	for (size_t i = 0; i < a.size(); ++i) {
		if (i) {
			ostr << ", ";
		}
		ostr << a[i];
	}
	ostr << ")";
	return ostr;
}

const int mod = 1000000007;

long long pw(long long a, long long b) {
	long long res = 1;
	while (b) {
		if (b & 1ll) {
			res = res * a % mod;
		}
		b >>= 1;
		a = a * a % mod;
	}
	return res;
}

int f(int x, int len) {
	if (x % len == len - 1) {
		return -(len - 1) * 1000 - 1;
	} else {
		return 1000;
	}
}

int main() {
	int H = nxt(), W = nxt(), h = nxt(), w = nxt();
	if (H % h) {
		puts("Yes");
		for (int i = 0; i < H; ++i) {
			for (int j = 0; j < W; ++j) {
				printf("%d ", f(i, h));
			}
			printf("\n");
		}
	} else if (W % w) {
		puts("Yes");
		for (int i = 0; i < H; ++i) {
			for (int j = 0; j < W; ++j) {
				printf("%d ", f(j, w));
			}
			printf("\n");
		}
	} else {
		puts("No");
	}

	return 0;
}

Measured memory_bytes: 1536
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

typedef long long ll;

const int N=2e5+5,Mo=998244353;

int n,pw[N],c[N],d[N],m;
char x[N];

bool chk(int l) {
	fo(i,l+1,n) {
		int c=(x[i-l]-'0')^1,a=x[i]-'0';
		if (c>a) return 0;
		if (c<a) return 1;
	}
	return 1;
}

void inc(int &x,int y) {x=x+y>=Mo?x+y-Mo:x+y;}
void dec(int &x,int y) {x=x-y<0?x-y+Mo:x-y;}

int main() {
	scanf("%d",&n);
	scanf("%s",x+1);
	pw[0]=0;fo(i,1,n) pw[i]=(pw[i-1]<<1|(x[i]-'0'))%Mo;
	fo(i,1,n-1) if (!(n%i)&&((n/i)&1)) d[++m]=i,c[m]=pw[i]+chk(i);
	fo(i,1,m) fo(j,1,i-1) if (!(d[i]%d[j])&&((d[i]/d[j])&1)) dec(c[i],c[j]);
	int cnt=pw[n]+1,ans=0;
	fo(i,1,m) dec(cnt,c[i]),inc(ans,(ll)(d[i]<<1)*c[i]%Mo);
	inc(ans,(ll)(n<<1)*cnt%Mo);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>

using namespace std;
int sub(const string& s, char c) {
  stringstream ss(c + s + c);
  int mx = 0;
  string buf;
  while(getline(ss, buf, c)) {
    mx = max(mx, (int)buf.size());
  }
  return mx;
}


int main() {
  string s;
  cin >> s;
  
  int mn = 1e9;
  for(char c = 'a'; c <= 'z'; ++c) {
    mn = min(mn, sub(s, c));
  }
  cout << mn << endl;
  return 0;
}


Measured memory_bytes: 256
N,T=map(int,input().split())
A=[int(i) for i in input().split()]
B=[0 for i in range(N)]
B[0]=A[0]
for i in range(1,N):
    B[i]=min([B[i-1],A[i]])
C=[A[i]-B[i] for i in range(N)]
M=max(C)
ans=0
for i in range(N):
    if C[i]==M:
        ans+=1
print(ans)


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

using namespace std;

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

    int ans = 0;
    for (int i = 0; i < N; ++i) {
        map<char, int> counter;
        counter[A[i]]++;
        counter[B[i]]++;
        counter[C[i]]++;
        switch (counter.size()) {
            case 1:
                break;
            case 2:
                ans++;
                break;
            case 3:
                ans += 2;
                break;
            default:
                break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256