akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

class UnionFind
{
    std::vector<int> data;
  public:
    UnionFind(int size) : data(size, -1) {}
    bool unite(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x != y)
        {
        if (data[y] < data[x])
                std::swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool find(int x, int y)
    {
        return root(x) == root(y);
    }
    int root(int x)
    {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x)
    {
        return -data[root(x)];
    }
};

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

    ll n, m, k;
    cin >> n >> m >> k;

    UnionFind uf(n);

    vll mem(n);
    ll a, b;
    REP(i, m) {
        cin >> a >> b;
        a--, b--;
        mem[a]++, mem[b]++;
        uf.unite(a, b);
    }
    ll c, d;
    REP(i, k) {
        cin >> c >> d;
        c--, d--;
        if (uf.find(c, d)) {
            mem[c]++, mem[d]++;
        }
    }
    REP(i, n) {
        ll res = uf.size(i) - mem[i] - 1;
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 2048
n = int(input())

a, b = [], []
for _ in range(n):
    aa, bb = map(int, input().split())
    a.append(aa)
    b.append(bb)

a.sort()
b.sort()

n2 = n//2
if n % 2 == 1:
    print(b[n2]-a[n2]+1)
else:
    print(b[n2-1]+b[n2]-a[n2-1]-a[n2]+1)


Measured memory_bytes: 25552
#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,y;
    cin>>n>>y;
    rep(i,n+1) for(ll j = i;j<=n;j++){
        if((i*1000+(j-i)*5000+(n-j)*10000) == y){
            cout<<(n-j)<<" "<<(j-i)<<" "<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<" "<<-1<<" "<<-1<<endl;
	return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

int main(void) {
    VI n(4);
    for (Int i = 0; i < 4; ++i) {
        cin >> n[i];
    }
    sort(n.begin(), n.end());
    if (n[0] == 1 && n[1] == 4 && n[2] == 7 && n[3] == 9) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 3624
while true
    n, k = gets.chomp.split.map(&:to_i)
    break if [n, k] == [0, 0]
    arr = []
    n.times{arr << gets.to_i}
    cum = [0]
    n.times{|i| cum[i + 1] = cum[i] + arr[i]}
    max = cum[k] - cum[0]
    (k + 1).upto(n){|i| max = cum[i] - cum[i - k] if max < cum[i] - cum[i - k]}
    puts max
end


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


int main(){
    string S;
    cin >> S;
    int n = S.size();
    for(int i= 2; i <= n; i+=2){
        string before = "", after = "";
        for(int j = 0; j < (n - i)/2; j++){
            before.push_back(S[j]);
        }
        for(int j = (n - i)/2; j < n - i; j++){
            after.push_back(S[j]);
        }
        if(before == after){
            cout << n - i << endl;
            return 0;
        }
    }

}


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

#define ee5 100005

bool has[ee5];
int cnt[ee5];
int main(){
	//freopen("in.txt","r",stdin);
	cout<<setprecision(17);
	int n,m;cin>>n>>m;
	has[0]=true;
	for(int i=0;i<n;i++)cnt[i]=1;
	for(int i=0;i<m;i++){
		int x,y;cin>>x>>y;x--;y--;
		if(has[x]==true)has[y]=true;		
		cnt[x]--;
		if(cnt[x]==0)has[x]=false;
		cnt[y]++;

	//for(int i=0;i<n;i++)cout<<has[i];cout<<"\n";
	}
	int ans=0;
	for(int i=0;i<n;i++){
		ans+=has[i];
	}
	cout<<ans;
}	

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

int main(){
    int a, b, c; cin >> a >> b >> c;
    if(a == b && b != c) cout << "Yes" << endl;
    else if(a == c && c != b) cout << "Yes" << endl;
    else if(b == c && a != b) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

const int MAXN = 2e5+5;

int p[MAXN], r[MAXN], l[MAXN], n;
ll ans = 0;

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

    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> p[i];

    vector<int> v;
    for (int i = 0; i < n; ++i) {
        while (!v.empty() && v.back() > p[i]) {
            int x = v.back();
            r[x] = i-1;
            v.pop_back();
        }

        v.push_back(p[i]);
    }

    while (!v.empty()) {
        int x = v.back();
        r[x] = n-1;
        v.pop_back();
    }

    for (int i = n-1; i >= 0; --i) {
        while (!v.empty() && v.back() > p[i]) {
            int x = v.back();
            l[x] = i+1;
            v.pop_back();
        }

        v.push_back(p[i]);        
    }

    while (!v.empty()) {
        int x = v.back();
        l[x] = 0;
        v.pop_back();
    }

    for (int i = 0; i < n; ++i) {
        ans += 1LL*p[i]*(i-l[p[i]]+1)*(r[p[i]]-i+1);
    }

    cout << ans << endl;
}

Measured memory_bytes: 3572
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		String s = scan.nextLine();
		String p = scan.nextLine();
		s = s + s;

		if(s.indexOf(p) != -1){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}

}

Measured memory_bytes: 17316
#include"bits/stdc++.h"
using namespace std;
const int N=1e6+4;
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("in","r",stdin);
	freopen("out","w",stdout);
	#endif

	int n;
	cin>>n;string s;
	cin>>s;
	vector<int> w(n+1),r(n-1);

	for(int i=1;i<=n;i++)
	{
		r[i]=r[i-1];w[i]=w[i-1];
		if(s[i-1]=='R')r[i]++;
		else w[i]++;
	}

	int x,y;int ans=1e9;
	for(int red=0;red<=n;red++)
	{
		x=w[red];y=r[n]-r[red];
		ans=min(ans,x+y-min(x,y));
	}
	cout<<ans;



	
}

Measured memory_bytes: 5232
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int>PA;
using namespace std;
#define MAX 1000
int main(){
	int n; cin >> n; 
	vi y(1000,0); vi m(1000,0); vi d(1000,0);
	rep(i,n) {cin >> y[i] >> m[i] >> d[i];}
	rep(i,n){
		int sy = y[i],sm = m[i],sd = d[i];
		int ans = 0;
		while(true){
			if(sy % 3 != 0){
				if(sm %2 == 1){
					if(sd == 20){sd = 1; sm++;}
					else sd++;

				}else if(sm % 2 == 0){
					if(sd == 19){sd = 1;sm++;}
					else sd++;
				}
			}if(sy%3 == 0){
				if(sd == 20){sd=1;sm++;}
				else 
					sd++;
			}
			if(sm == 11){sm =1; sy++;}
			if(sy == 1000 && sm == 1 && sd ==1)
				break;
			else
				ans++;
		}
		cout << ans+1 << endl;
	}

}

Measured memory_bytes: 3068
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int m = Integer.parseInt(sc.next());
    int s[] = new int[m];
    int c[] = new int[m];
    int d[] = new int[n];
    boolean out = false;
    
    for(int i=0; i<m; i++){
      s[i] = Integer.parseInt(sc.next());
      c[i] = Integer.parseInt(sc.next());
      d[s[i]-1]++;
    }
    
    int temp = -1;
    for(int i=0; i<n; i++){
      temp = -1;
      if(d[i] > 0){
        for(int j=0; j<m; j++){
          if(s[j] == i+1 && temp == -1) { temp = c[j]; }
          if(s[j] == i+1 && temp != -1) { 
            if(temp != c[j]) { out = true; }
          }
        }
      }
    }
    
    if(out) { System.out.println("-1"); return; }
    
    for(int i=0; i<n; i++){
      d[i] = -1;
    }
    
    switch(n){
      case 1:
        temp = 0;
        for(int i=0; i<m; i++){
          if(s[i] == 1 && c[i] != 0) { 
            temp = c[i]; 
          } else {
            temp = 0;
          }
        }
        System.out.println(temp);
        return;
      case 2:
        for(int i=0; i<m; i++){
          d[s[i]-1] = c[i];
        }
        if(d[0]==0) {
          System.out.println("-1");
          return;
        }
        for(int i=0; i<n; i++){
          if(d[i]==-1){
            d[i] = 0;
            if(i==0) { d[0] = 1 ; }
          }
        }
        System.out.println(d[0]*10 + d[1]);
        return;
      case 3:
        for(int i=0; i<m; i++){
          d[s[i]-1] = c[i];
        }
        if(d[0]==0) {
          System.out.println("-1");
          return;
        }
        for(int i=0; i<n; i++){
          if(d[i]==-1){
            d[i] = 0;
            if(i==0) { d[0] = 1 ; }
          }
        }
        System.out.println(d[0]*100 + d[1]*10 + d[2]);
        return;
    }
    
  }
  
}


Measured memory_bytes: 23892
while True:
    n, m = map(int, input().split())
    if n == 0:break
    minp = [0] * (n + 1)
    minp[0] = 1e10
    maxp = [0] * (n + 1)
    for _ in range(m):
        s, k, *c =  map(int, input().split())
        if k == 1:
            minp[c[0]] += s
        for i in range(k):
            maxp[c[i]] += s
    p = list(zip(maxp, minp))
    p.sort(key = lambda x:x[1])
    p.sort(key = lambda x:x[0], reverse = True)
    p.pop()
    s = 0
    for i in range(n - 1):
        if p[i][0] <= s:break
        for j in range(i + 1, n):
            s = max(s, p[i][0] - p[j][1])
    print(s + 1)


Measured memory_bytes: 7844
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;
 
int main(void){
    lint X,Y;
    cin >> X >> Y;
    int ans=0;
    while(X<=Y){
        X*=2;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
typedef long long LL;

int main() {
  char c; std::cin >> c;
  switch(c) {
    case 'A':
      std::cout << 'T' << std::endl;
      break;
    case 'T':
      std::cout << 'A' << std::endl;
      break;
    case 'G':
      std::cout << 'C' << std::endl;
      break;
    case 'C':
      std::cout << 'G' << std::endl;
      break;
  }
}


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

using namespace std;

int main() {
  vector<int> v(3);
  for (int i = 0; i < 3; i++) cin>>v[i];
  sort(v.rbegin(),v.rend());
  int ans = v[0] * 10 + v[1] + v[2];
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, [ $t:tt ]) => {{
    let len = read_value!($iter, usize);
    (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  }};

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    n: i64,
    k: i64,
  }
  let p = 2 * n + 2 * k - 1 - (n - 1) / 2;
  let q = 2 * n + k;
  if p > q {
    puts!("-1\n");
    return;
  }
  for i in 0 .. n {
    let c = q + i;
    let b = if i > n / 2 {
      2 * n + k + n / 2 - i
    } else {
      n + k + n / 2 - i
    };
    let a = if n % 2 == 0 && i >= n / 2 {
      p + i - b - 1
    } else {
      p + i - b
    };
    puts!("{} {} {}\n", a, b, c);
  }
}


Measured memory_bytes: 6268
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int p[10], q[10], a[10], b[10];

bool check(int *x, int *y, int n) {
    for (int i=0;i<n;i++) {
        if (x[i]!=y[i]) return false;
    }
    return true;
}

int main() {
    ios_base::sync_with_stdio(0);
    int n; cin >> n;
    for (int i=0;i<n;i++) cin >> p[i];
    for (int i=0;i<n;i++) cin >> q[i];
    for (int i=0;i<n;i++) {
        a[i] = i+1;
        b[i] = i+1;
    }

    int cntA = 0, cntB = 0;
    while (!check(a, p, n)) next_permutation(a, a+n), cntA++;
    while (!check(b, q, n)) next_permutation(b, b+n), cntB++;
    cout << abs(cntA-cntB) << endl;
}


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

int main() {
	// your code goes here
	int a,bb,cc,d;
	cin>>a>>bb>>cc>>d;
	  int arc=0;
  if(cc%bb==0) arc=cc/bb;
  else arc=(cc/bb)+1;
    if(a>d*(arc-1))
	 cout<<"Yes";
	 else cout<<"No";
	return 0;
}


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

int main(){
  int m,n;
  cin >> m >> n;
  char c[m+2][n+2];
  int flag[m+2][n+2];
  rep(i,m+2) rep(j,n+2) flag[i][j] = 0;
  repp(i,m){
    repp(j,n){
      cin >> c[i][j];
      if(c[i][j]=='o'){
	flag[i][j]=1;
	flag[i][j+1]=1;
	flag[i][j-1]=1;
      }
      if(c[i][j]=='x'){
	for(int x=i-1; x<i+2; x++){
	  for(int y=j-1; y<j+2; y++){
	    flag[x][y] = 1;
	  }
	}
      }
    }
  }
  repp(i,n) flag[1][i] = 1;
  /*rep(i,m+2){
    rep(j,n+2){
      cout << flag[i][j] << " ";
    }
    cout << endl;
  }*/
  int count=0;
  repp(i,m){
    repp(j,n){
      if(flag[i][j]==0) count++;
    }
  }
  cout << count << endl;
  
  return 0;
}



Measured memory_bytes: 3072
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
using namespace std;
typedef long long ll;
ll mod = 1000000007;

int main() {
    ll a,b,k; cin >> a >> b >> k;
    ll c = min(a-k+b,b);
    if (c < 0) c = 0;
    cout << max(a-k,0LL) << " " << c << "\n"; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long N,K;
  cin >> N >> K;
  vector<long> vec(N,0);
  int A;
  for(int i=0;i<N;i++){
    cin >> A;
    vec[A-1]++;
  }
  VSORT(vec);
  int sum=0;
  for(int i=0;i<N;i++){
    if(vec[i] > 0) sum++;
  }
  int i=0,kaisu=0;
  while(sum > K){
    if(vec[i]!=0){
      kaisu += vec[i];
      sum--;
    }
    i++;
  }
  cout << kaisu << endl;
    
}


Measured memory_bytes: 1792
require 'prime'
require 'set'

n = gets.to_i
f = n.prime_division

res = 0
f.each do |a, b|
  c = 1
  loop {
    if b - c >= 0
      b -= c
      res += 1
    else
      break
    end
    c += 1
  }
end

puts res



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

int main(void){
    string S;
    cin >> S;
    vector<int> con(4, 0);
    for(int i = 0; i < 3; i++){
        if(S[i] == 'R') con[i + 1] = con[i] + 1;
    }
    cout << *max_element(con.begin(), con.end()) << endl;
    return 0;
}


Measured memory_bytes: 3592
import Control.Monad
import Data.List

main = do
  n <- read <$> getLine
  a <- map read . words <$> getLine
  forM_ (solve n a) $ \t ->
    putStrLn . show $ t

solve :: Int -> [Int] -> [Int]
solve n a = 
  let (sorted, sortnum) = unzip $ sort $ zip a [1..]
      med = sorted !! (n `div` 2)
      medPrev = sorted !! ((n `div` 2) - 1)
  in map (\x -> if x <= medPrev then med else medPrev) a
  
      


Measured memory_bytes: 111996
x,y = map(int, input().split())
if x > 0 and y > 0:
    if abs(x) < abs(y):
        print(y-x)
    else:
        print(x-y + 2)
elif x < 0 and y > 0:
    if abs(x) <= abs(y):
        print(y-abs(x) + 1)
    else:
        print(abs(x) - y + 1)
elif x > 0 and y < 0:
    if abs(x) < abs(y):
        print(abs(y) - x + 1)
    else:
        print(x - abs(y) + 1)
elif x == 0 and y > 0:
    print(y)
elif x == 0 and y < 0:
    print(abs(y) + 1)
elif x > 0 and y == 0:
    print(x + 1)
elif x < 0 and y == 0:
    print(abs(x)) 
else:
    if abs(x) <= abs(y):
        print(abs(y) - abs(x) + 2)
    else:
        print(abs(x) - abs(y))


Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#define SIZE 2000010
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define ll long long
#define mp make_pair
#define pi acos(-1.0)
#define eps 1e-6
using namespace std;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
const ll mod = 1e9 + 7;
ll r1, c1, r2, c2;
ll pre[SIZE] = { 1,1 }, inv[SIZE];
ll qpow(ll a, ll b, ll mod) { //快速幂 a ^ b % mod
	ll ans = 1;
	while (b) {
		if (b & 1) ans = (ans * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return ans;
}

ll C(ll n, ll m) {
	return pre[n] * inv[n - m] % mod * inv[m] % mod;
}

void init(int n) {
	pre[0] = pre[1] = 1;
	rep(i, 2, n) pre[i] = 1ll * i * pre[i - 1] % mod;
	inv[n] = qpow(pre[n], mod - 2ll, mod) % mod; inv[0] = 1;
	for (ll i = n; i; --i) inv[i - 1] = inv[i] * i % mod;
}

ll solve(ll r, ll c) {
	ll ans = 0;
	rep(i, 0, r) ans = (ans + C(i + c + 1ll, c)) % mod;
	return ans % mod;
}

int main() {
	io(); cin >> r1 >> c1 >> r2 >> c2;
	init(r2 + c2 + 1);
	cout << (solve(r2, c2) - solve(r1 - 1, c2) - solve(r2, c1 - 1) + solve(r1 - 1, c1 - 1) + mod) % mod;
}

Measured memory_bytes: 31488
import java.util.*;
import java.util.Map.Entry;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Map<String,Integer> map = new HashMap<>();
        for(int i = 0;i < n;i++){
            String str = sc.next();
            if(map.containsKey(str)){
                map.replace(str,map.get(str)+1);
            }else{
                map.put(str, 1);
            }
        }
        List<Entry<String, Integer>> list_entries = new ArrayList<Entry<String, Integer>>(map.entrySet());
            Collections.sort(list_entries, new Comparator<Entry<String, Integer>>() {
                public int compare(Entry<String, Integer> obj1, Entry<String, Integer> obj2) {
                    if(obj2.getValue() != obj1.getValue()){
                        return obj2.getValue().compareTo(obj1.getValue());
                    }else{
                        return obj1.getKey().compareTo(obj2.getKey());
                    }
                    
                }
            });
        int max =list_entries.get(0).getValue();
        
        list_entries.stream().filter(e -> e.getValue() >= max).forEach(e -> System.out.println(e.getKey()));
    }
}


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

int n, W;
int weight[110], value[110];

int dp[110][10010];

int main(){
    cin >> n >> W;
    for (int i = 0; i < n; i++) cin >> value[i] >> weight[i];
    
    // inital condition
    for (int w = 0; w <= W; w++) dp[0][w] = 0;
    
    // DP loop
    for (int i = 0; i < n; i++){
        for (int w = 0; w <= W; w++){
            if (w >= weight[i]) dp[i+1][w] = max(dp[i][w-weight[i]] + value[i], dp[i][w]);
            else dp[i+1][w] = dp[i][w];
        }
    }
    
    cout << dp[n][W] << endl;
    return 0;
}



Measured memory_bytes: 7032
#include <bits/stdc++.h>
#define MOD 1000000007
#define inf INT_MAX
#define ll long long int
#define db double
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define endl "\n"
#define mp make_pair
#define f first
#define s second
ll power(ll x, ll y, long long int mod = 1000000007){ ll ans = 1;x %= mod;while(y){if(y&1)ans = (x * ans) % mod;x = (x * x) % mod;y >>= 1;}return ans;}
ll modInverse(ll a, ll m){ll m0 = m;ll y = 0, x = 1;if (m == 1) return 0;while (a > 1){ ll q = a / m;ll t = m;m = a % m,a = t;t = y;y = x - q * y;x = t;}if(x < 0) x += m0;return x;}
using namespace std;

int main() {
    fastio;
    string s, t;
    cin >> s >> t;
    int m = s.length(), n = t.length();
    
    string dp[2][n + 1];
    
    for(int i = 0; i <= 1; i++) 
        for(int j = 0; j <= n; j++)
            dp[i][j] = "";
    bool curr = 1;
    for(int i = 1; i <= m; i++) {
        curr = i & 1;
        for(int j = 1; j <= n; j++) {
            if(s[i - 1] == t[j - 1]) {
                dp[curr][j] = dp[1 - curr][j - 1] + s[i - 1];
                //cout << s[i - 1] << endl;
            }
            string temp = ((dp[1 - curr][j]).length() > (dp[curr][j - 1]).length()) ? dp[1 - curr][j] : dp[curr][j - 1];
            dp[curr][j] = ((dp[curr][j].length() > temp.length()) ? dp[curr][j] : temp);
        }
    }
    cout << dp[curr][n] << endl;
}

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

int main()
{
    int a,b;
    char op;
    for(int i=0;;i++){
        cin>>a>>op>>b;
        if(op=='?')break;
        if(op=='+'){
            cout<<a+b<<endl;
        }else if(op=='-'){
            cout<<a-b<<endl;
        }else if(op=='*'){
            cout<<a*b<<endl;
        }else{
            cout<<a/b<<endl;
        }
    }

}


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

int main(){
	int n, m;
	cin >> n >> m;
	int freq[110000];
	for(int i = 0; i < 110000; i++) freq[i] = 0;
	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		freq[a]++;
	}
	int s[m];
	int p[m];
	for(int i = 0; i < m; i++) s[i] = p[i] = 0;
	for(int i = 0; i < 110000; i++){
		p[i%m] += freq[i]/2;
		s[i%m] += freq[i]%2;
	}
	int ans = 0;
	for(int i = 0; i < m; i++){
		if((i+i) % m == 0){
			ans += (p[i]*2+s[i])/2;
			p[i] = 0;
			s[i] = 0;
		} else {
			//cout << s[i] << " " << s[m-i] << endl;
			while(1){
				if(s[i] > 0 && s[m-i] > 0){
					s[i]--;
					s[m-i]--;
					ans++;
					continue;
				}
				if(s[i] > 0 && p[m-i] > 0){
					s[i]--;
					p[m-i]--;
					s[m-i]++;
					ans++;
					continue;
				}
				if(s[m-i] > 0 && p[i] > 0){
					s[m-i]--;
					p[i]--;
					s[i]++;
					ans++;
					continue;
				}
				if(p[i] > 0){
					p[i]--;
					ans++;
					continue;
				}
				if(p[m-i] > 0){
					p[m-i]--;
					ans++;
					continue;
				}
				break;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
static const int64_t INFL = 0x3F3F3F3F3F3F3F3FLL;
typedef int64_t ll;
struct Solution {
    void solve(std::istream& in, std::ostream& out) {
        ll x, y;
        in >> x >> y;
        ll a, b, c, d;
        a = x - y + 2;
        a = a < 0 ? INFL : a;
        b = -x - y + 1;
        b = b < 0 ? INFL : b;
        c = x + y + 1;
        c = c < 0 ? INFL : c;
        d = -x + y;
        d = d < 0 ? INFL : d;
        out << min(a, min(b, min(c, d))) << '\n';
    }
};
void solve(std::istream& in, std::ostream& out) {
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> maze;
    for(int i = 0; i < H; i++) {
        string s;
        cin >> s;
        maze.push_back(s);
    }

    vector<vector<ll>> dp(H+1, vector<ll>(W+1, 0));
    dp[0][0] = 1;
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            if(j+1 < W && maze[i][j+1] != '#') {
                dp[i][j+1] += dp[i][j];
                dp[i][j+1] %= MOD;
            }
            if(i+1 < H && maze[i+1][j] != '#') {
                dp[i+1][j] += dp[i][j];
                dp[i+1][j] %= MOD;
            }
        }
    }

    cout << dp[H-1][W-1] << endl;

    return 0;
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
int main(){
    long double n,k;
    long double ans=0;
    long double cnt=0;
    cin >> n >> k;
    rep2(i,1,n+1){
        cnt=0;
        int now = i;
        while(now<k){
            //if(i>=k)break;
            now*=2;
            cnt++;
        }
        ans+=pow(0.5,cnt);
    }

    cout << fixed << setprecision(16) << ans*(1/n);

    return 0;
}

Measured memory_bytes: 3896
n,k=map(int,input().split())
a=[]
cnt=0
for i in range(k):
    d=int(input())
    x=[int(e) for e in input().split()]
    for j in x:

        a.append(j)
a.sort()
for j in range(len(a)-1):
    if a[j]!=a[j+1]:
        cnt+=1
print(n-cnt-1)


Measured memory_bytes: 67924
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <complex>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
const int INF = 1<<28;

string input;

int find(int a, int p) {
	int btn[2] = {};
	FOR(i, p, input.size()) {
		if(a) {
			if(input[i] == '[')
				btn[0]++;
			if(input[i] == ']')
				btn[0]--;
				if(btn[0] < 0) return 1;
			if(input[i] == '(')
				btn[1]++;
			if(input[i] == ')') {
				btn[1]--;
				if(!btn[0] && !btn[1])
					return 0;
			}
		}
		else {
			if(input[i] == '(')
				btn[0]++;
			if(input[i] == ')')
				btn[0]--;
				if(btn[0] < 0) return 1;
			if(input[i] == '[')
				btn[1]++;
			if(input[i] == ']') {
				btn[1]--;
				if(!btn[0] && !btn[1])
					return 0;
			}
		}
	}
	return 1;
}


int main() {
	while(getline(cin, input)) {
		if(input == ".") break;
		int cnt = 0;
		int chk[2] = {};
		REP(i, input.size()) {
			if(input[i] == '(') {
				cnt += find(1, i);
				chk[1]++;
			}
			if(input[i] == '[') {
				cnt += find(0, i);
				chk[0]++;
			}
			if(input[i] == ')') {
				chk[1]--;
				if(chk[1] < 0) cnt++;
			}
			if(input[i] == ']') {
				chk[0]--;
				if(chk[0] < 0) cnt++;
			}
		}
		if(chk[0] || chk[1]) cnt++;
		cout << (cnt ? "no" : "yes") << endl;
	}
	return 0;
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    vector<pair<pair<int, int>, int>> p(n);
    for(auto& x : p) cin >> x.fi.fi >> x.fi.se >> x.se;
    sort(p.begin(), p.end(), [](auto& x, auto& y) { return x.se > y.se; });
    for(int i = 0; i <= 100; ++i) {
        for(int j = 0; j <= 100; ++j) {
            int H = p[0].se + abs(p[0].fi.fi - i) + abs(p[0].fi.se - j);
            bool ok = true;
            for(auto& x : p) {
                if(max(H - abs(x.fi.fi - i) - abs(x.fi.se - j), 0) != x.se) ok = false;
            }
            if(ok) {
                cout << i << ' ' << j << ' ' << H << endl;
                return 0;
            }
        }
    }
    assert(1 == 2);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, x, count = 0;
  
  cin >> n >> x;
  while(n != 0 || x != 0){
  for(int i = 1; i < n - 1; i++){
    for(int j = i + 1; j < n; j++){
      for(int k = j + 1;  k < n + 1 ; k++){
        if (i + j + k == x) count++;
      }
    }
  }
  cout << count << endl;
    count = 0;
    cin >> n >> x;
  }
}


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

int main() {
  	int N, res=0;
  	cin >> N;
  	vector<int> B(N-1);
  
  	for(int i=0; i<N-1; i++){
    	cin >> B[i];
    }
  
  	for(int i=0; i<N; i++){
    	if(i==0){
        	res+=B[i];
        }else if(i==N-1){
        	res+=B[i-1];
        }else{
        	res+=min(B[i],B[i-1]);
        }
    }
  
  	cout << res << endl;
  
	return 0;
}

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

using namespace std;
using ll = long long int;

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

	queue<ll> q;

	for (int i = 1; i <= 9; i++)
	{
		q.push(i);
	}

	for (int i = 0; i < k - 1; i++)
	{
		ll n = q.front();
		q.pop();

		ll digit = n % 10;
		ll next = n * 10;

		if (digit >= 1)
		{
			q.push(next + (digit - 1));
		}

		q.push(next + digit);

		if (digit <= 8)
		{
			q.push(next + (digit + 1));
		}
	}

	ll ans = q.front();
	cout << ans << endl;
}

Measured memory_bytes: 1792
package main

import "fmt"

func main() {
	var N, M int
	fmt.Scan(&N, &M)
	A := make([]float64, N)
	tot := 0.0
	for i := range A {
		fmt.Scan(&A[i])
		tot += A[i]
	}
	sum := 0
	for i := range A {
		if A[i] >= tot/(4.0*float64(M)) {
			sum++
		}
	}
	if sum >= M {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

using namespace std;

int main(){
  int n;
  string target;
  string str;
  int ans=0;
  cin>>target;
  cin>>n;

  for(int i=0;i<n;i++){
    cin>>str;
    for(int j=0;j<target.size();j++){
      if(str.find(target,0)!=string::npos){
	ans++;
	break;
      }
      char temp;
      temp=str.at(0);
      str.erase(0,1);
      str.append(1,temp);
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1224
using System;

namespace ITP_1_2_C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            int c = int.Parse(input[2]);
            if (a > b)
            {
                int tmp = b;
                b = a;
                a = tmp;
            }
            if (b > c)
            {
                int tmp = c;
                c = b;
                b = tmp;
            }
            if (a > b)
            {
                int tmp = b;
                b = a;
                a = tmp;
            }
            Console.WriteLine("{0} {1} {2}", a, b, c);
        }
    }
}



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

int main() {
    int inf = 1001001001;
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i = 0; i < n; ++i) {
        cin >> h.at(i);
    }
    vector<int> dp(n, inf);
    dp.at(0) = 0;
    dp.at(1) = abs(h.at(1) - h.at(0));
    for (int j = 2; j < n; ++j) {
        dp.at(j) = min(dp.at(j - 1) + abs(h.at(j) - h.at(j - 1)), dp.at(j - 2) + abs(h.at(j - 2) - h.at(j)));
    }
    cout << dp.at(n - 1) << endl;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#include <random>
#include <functional>
#include <assert.h>

using namespace std;

using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;

bitset<4000001> sums;

int main()
{
    sums[0] = 1;

    int n;
    scanf("%d", &n);

    int sum = 0;

    for (int i = 0; i < n; i++)
    {
        int k;
        scanf("%d", &k);
        sum += k;
        
        sums |= sums << k;
    }

    for (int i = (sum+1) / 2;; i++)
    {
        if (sums[i])
        {
            printf("%d", i);
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 1664
import java.util.*;
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int keta=0;
		int ans=0;
		for(int i=1;i<=N;i++){
			keta = String.valueOf( i ).length();
			if ((keta%2)==1) {
				ans=ans+1;
			}
		}
		System.out.println(ans);
    }
}

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

int main(){
  int n;
  string s;
  cin >> n >> s;
  
  int ans = s.size();
  
  for(int i = 0; i < s.size()-1; i++){
  
  	if(s[i]==s[i+1]) ans--;
  
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 512
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""
def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# a^n
def power(a,n,mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod

# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n-1
    while(tmp >= l):
        a = a*tmp%mod
        tmp -= 1
    return a

inf = 10**18
mod = 10**9+7

n = ir()
a = lr()
total = 0
for i,num in enumerate(a):
    a[i]=(num-(i+1))
a.sort()
if n%2 == 0:
    mean = (a[n//2-1]+a[n//2])//2
else:
    mean = a[n//2]
ans = [0,0]
for i in range(mean, mean+2):
    tmp = i%2
    for num in a:
        ans[tmp]+=abs(num-i)
print(min(ans))

Measured memory_bytes: 113848
#include<iostream>
using namespace std;
 
int main(){
 
  int N,coin_500,coin_5;
  cin >> N;
  coin_500 = int(N/500);
  coin_5 = int((N%500)/5);
  
  cout << 1000*coin_500 + 5*coin_5 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <cstring>
#include <bitset>
#include <map>

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using PP = pair<ll, pair<ll,ll>>;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define MOD 998244353
//           123456789

ll n, cnt = 0;

int main() {
    cin >> n;
    for (ll i = 1; i <= n; ++i){
        cnt+=(n-1)/i;
    }
    cout << cnt << endl;
    return 0;
}

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

int main(void){
  ll n,b,r;
  cin >> n >> b >>r;
  ll ans=0;
  ans = min(b,n%(b+r));
  ans+=(n/(b+r))*b;
  cout << ans;
return 0;
}


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

int main() {
  int a, b, c, d, l, r;
  cin >> a >> b >> c >> d;
  l = a + b;
  r = c + d;
  if (l < r) {
    cout << "Right" << endl;
  }
  else if (l == r) {
    cout << "Balanced" << endl;
  }
  else if (r < l) {
    cout << "Left" << endl;
  }
}

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

int main()
{
    int n;
    cin >> n;
    int b[n-1];
    for(int i = 0; i < n-1; i++)
        cin >> b[i];
    
    int a[n];
    int left = 1;
    int right = n-2;

    a[0] = b[0];
    a[n-1] = b[n-2];

    long long int ans = a[0]+a[n-1];

    while(left <= right) {
        a[left] = min(b[left-1],b[left]);

        if (left == right) {
            ans += a[left];
            break;
        }
        
        a[right] = min(b[right],b[right-1]);
  
        ans += a[left];
        ans += a[right];
      
        left++;
        right--;
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define clr(x,y) memset(x,y,sizeof(x))
#define FOR(x,l,r) for(int x=l,x##_=r;x<=x##_;x++)
#define FR(x,l,r) for(int x=l,x##_=r;x<x##_;x++)
#define DOR(x,r,l) for(int x=r,x##_=l;x>=x##_;x--)
using namespace std;
const int N=300005;
LL n,d;
int main() {
	cin>>n>>d;
	n+=2*d;
	cout<<n/(2*d+1);
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
typedef long long int64;
static const int MAXN = 1e5 + 4;

int n, l, t;
int x[MAXN], w[MAXN];
int p[MAXN];

int main()
{
    scanf("%d%d%d", &n, &l, &t);
    for (int i = 0; i < n; ++i) {
        scanf("%d%d", &x[i], &w[i]), --w[i];
        p[i] = ((x[i] + (w[i] ? -1 : 1) * t) % l + l) % l;
    }

    int64 id0 = 0;
    int p0 = p[0];
    int cycles = t / l;
    for (int i = 1; i < n; ++i) if (w[i] ^ w[0]) {
        id0 += cycles * 2;
        int dist;
        if (w[0]) { // Counter-clockwise
            dist = (x[0] + l - x[i]) % l;
        } else {    // Clockwise
            dist = (x[i] + l - x[0]) % l;
        }
        if (t % l * 2 > dist) id0++;
        if (t % l * 2 > dist + l) id0++;
        //printf("Ant #0 - #%d: Cyc = %d Dist = %d Hold = %d\n", i, cycles, dist, (int)id0);
    }
    id0 %= n;
    if (w[0]) id0 = (n - id0) % n;
    //printf("Ant #0, Pos = %d, Hold = %d\n", p[0], (int)id0);

    std::sort(p, p + n);
    int id0_pos;
    if (w[0]) { // Counter-clockwise
        id0_pos = std::distance(&p[0], std::upper_bound(p, p + n, p0) - 1);
    } else {
        id0_pos = std::distance(&p[0], std::lower_bound(p, p + n, p0));
    }
    int offset = id0_pos - id0;
    for (int i = 0; i < n; ++i) printf("%d\n", p[((i + offset) % n + n) % n]);

    return 0;
}


Measured memory_bytes: 2304
s = input()

#回文2
m = int((len(s)-1)/2)

#回文3
n = int((len(s)+3)/2)

s1 = s[:m]

s2 = s[n-1:]

if s == s[::-1] and s1 == s1[::-1] and s2 == s2[::-1]:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
#include <stdio.h>
int main(){
    long long int a,b,c,x,result;
    scanf("%lld %lld %lld",&a,&b,&x);
    if (a%x==0){
        c=a/x-1;
    }
    else{
        c=a/x;
    }
    result=b/x-c;
    printf("%lld",result);
    return 0;
}

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

int main() {
    string s;
    cin >> s;
    vector<int> number(s.length());
    rep(i, s.length()) {
        number.at(i) = s.at(i) - '0';
    }
    int ans, temp = number.at(0) * 100 + number.at(1) * 10 + number.at(2);
    ans = abs(temp - 753);
    rep(i, s.length() - 3) {
        temp -= number.at(i) * 100;
        temp *= 10;
        temp += number.at(i + 3);
        ans = min(ans, abs(temp - 753));
    }
    cout << ans << endl;
}

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

using namespace std;
#define MOD 1000000007
#define LL long long

long long f(int t)
{
    long long ans=1;
    for(int i=1;i<=t;i++)
    {
        ans=ans*26;
    }
    return ans;
}
int main()
{
   //freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  int n,m,l,i,j,te=1;
  long long ans=0;
 cin>>n>>m>>l;
 for( i=1;i<=m;i++)
 {
     ans+=n;
     if(ans%m==l)
     {
         cout<<"YES\n";
         return 0;
     }
 }
 cout<<"NO\n";
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



class UnionFind:
    def __init__(self, n):
        # 負  : 根であることを示す。絶対値はランクを示す
        # 非負: 根でないことを示す。値は親を示す
        self.table = [-1] * n


    def root(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self.root(self.table[x])
            return self.table[x]


    def is_same(self, x, y):
        if self.root(x) == self.root(y):
            return True
        else:
            return False


    def union(self, x, y):
        r1 = self.root(x)
        r2 = self.root(y)
        if r1 == r2:
            return
        # ランクの取得
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            if d1 == d2:
                self.table[r1] -= 1
        else:
            self.table[r1] = r2




n, m = LI()
L = LIR(m)
cnt = 0
for i in range(m):
    U = UnionFind(n)
    for j in range(m):
        if j == i:
            continue
        a, b = L[j]
        U.union(a - 1, b - 1)
    if all([U.is_same(0, k) for k in range(n)]):
        continue
    else:
        cnt += 1



print(cnt)

Measured memory_bytes: 46168
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
  vector<int>time={a,b,c,d,e};
  int n=5;
  vector<int>nexttime(n);
  for(int i=0;i<n;i++){
    if(time.at(i)%10==0){
      nexttime.at(i)=time.at(i);
    }
    else{
      nexttime.at(i)=time.at(i)-time.at(i)%10+10;
    }
  }
 
    
  int besttime=99999999;
  for(int i=0;i<n;i++){
    int sumtime=0;
    for(int j=0;j<n;j++){
      if(i==j){
        sumtime+=time.at(j);
      }
      else{
        sumtime+=nexttime.at(j);
      }
    }
    besttime=min(besttime,sumtime);
  }
  cout<<besttime<<endl;
}


Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<map>
#include<math.h>
#include<queue>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
const int mod = 1000000007;
const int INF = 1000000001;
const long long LINF = 1e18;
const int MAX = 510000;

int main() {
	int n,ans=1;
	int mi = 1;
	int e = 0, o = 0;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a.at(i);
		ans *= 3;
	}
	for (int i = 0; i < n; i++) {
		if (a.at(i) % 2 == 0)e++;
		else o++;
	}
	for(int i=0;i<e;i++){
		mi *= 2;
	}
	cout << ans - mi << endl;
		return 0;
	}


Measured memory_bytes: 3556
#include <iostream>


long long dif(long long n, long long x)
{
  return (n >=0) ? n/x + 1 : 0;
}
int main()
{
  long long a, b, x;

  std::cin >> a >> b >> x;

  long long ans = dif(b, x) - dif(a-1, x);

  std::cout << ans << '\n';
}


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

void print(bitset<32> b) {
	for (int i = 0; i < 32; i++) {
		if (b.test(i)) {
			cout << " " << i;
		}
	}
}

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

	bitset<32> b1, b2;
	vector<int> vec;

	int n; cin >> n;
	int k; cin >> k;
	int max = 1 << k;
	for (int i = 0; i < k; i++) {
		int x; cin >> x;
		vec.push_back(x);
	}
	for (int i = 0; i < max; i++) {
		b1 = i;
		b2.reset();
		for (int j = 0; j < vec.size(); j++) {
			if (b1.test(j) == 1) {
				b2.set(vec[j]);
			}
		}
		cout << b2.to_ulong() << ":";
		print(b2);
		cout << endl;
	}
}


Measured memory_bytes: 3176
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<stack>
using namespace std;
#define ll long long
#define ull unsigned long long
#define up(i,a,b) for(register int i=(a);i<=(b);i++)
#define down(i,a,b) for(register int i=(a);i>=(b);i--)
#define mem(x,y) memset(x,(y),sizeof x)
#define ff first
#define ss second
#define mp(x,y) make_pair(x,y)
#define pb(x) emplace_back(x)
#define sc(a) scanf("%d",&a)
#define scl(a) scanf("%lld",&a)
#define scs(a) scanf("%s",a)
#define pr(a,b) printf("%d%c",a,b)
#define prl(a,b) printf("%lld%c",a,b)
#define PQ priority_queue
#define ld long double
#define all(v) v.begin(),v.end()
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)

typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef vector<int> V;

pii a[100010];
int main() {
	IOS;
	int n,m;
	cin>>m>>n;
	up(i,1,n)cin>>a[i].ff>>a[i].ss;
	sort(a+1,a+1+n);
	int l=0,r=1e9;
	up(i,1,n)l=max(l,a[i].ff),r=min(r,a[i].ss);
	cout<<max(0,r-l+1)<<"\n";
}

Measured memory_bytes: 1024