akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args)throws Exception {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
        StringTokenizer tokenizer = new StringTokenizer(input.readLine());
        int k = Integer.parseInt(tokenizer.nextToken());
        int s = Integer.parseInt(tokenizer.nextToken());
        int count = 0;
        for (int i = 0; i <= k; i++) {
            for (int j = 0; j <= k; j++) {
                if (s >= i+j && s-(i+j) <= k){
                    count++;
                }
                if (s < i+j)
                    break;
            }
            if (s < i)
                break;
        }
        out.write(String.valueOf(count));
        out.write("\n");
        out.close();
    }
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, j) for(int i = 0; i < (int)(j); i++)
constexpr int INF = 1 << 28;
struct Edge{
    int to;
    ll cost;
    int from; // from ????????????????????¨?????????
    Edge(int to, ll cost, int from = -1):to(to), cost(cost), from(from) {}
};
using EdgeList = vector<vector<Edge>>;
using pil = pair<int, ll>;
// ??¨ E ?????´???????±???????
// ?????????????????????????????????u???u?????????????????????t??¨????????¨???u-t?????´???
// O(E)
ll diameter(const EdgeList &E) {
    // now ??????????????????????±???????DFS
    // -> (???, now??????????????¢)
    function<pil(int, int)> dfs = [&] (int now, int pre) {
        pil res = make_pair(now, 0);
        for(auto &e : E[now]) {
            if(e.to == pre) continue;
            pil tmp = dfs(e.to, now);
            tmp.second += e.cost;
            if(tmp.second > res.second) res = tmp;
        }
        return res;
    };         
    pil a = dfs(0, -1);
    pil b = dfs(a.first, -1);
    // (a.first , b.first) ???????????????
    return b.second;
}
int main() {
    int N; cin >> N;
    EdgeList E(N);
    rep(i, N - 1) {
        int s, t, w; cin >> s >> t >> w;
        E[s].emplace_back(t, w);
        E[t].emplace_back(s, w);
    }
    cout << diameter(E) << endl;
    return 0;
}

Measured memory_bytes: 20668
#include<iostream>
using namespace std;
int c[99],z,p;main(){string s,r,a="AIDUNYAN";cin>>s;r=s;for(char k:a)c[k]--;for(int i=0;i<s.size();i++){if(i>7){if(!c[p=s[i-8]]--)z--;if(!c[p])z++;}if(!c[p=s[i]]++)z--;if(!c[p])z++;if(z==6){for(p=0;p<8;p++)r[i-7+p]=a[p];r[i-5]='Z';}}cout<<r<<endl;}

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

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;


ll fac[100010];

void factrial(){
    fac[0] = 1;
    rep(i,100000){
        fac[i+1] = fac[i]*(i+1) % MOD;
    }
}
int main(){
   int N,M; cin >> N >> M;
   factrial();
   ll ans = 0;
   if(abs(N-M) >= 2){
       cout << 0 << endl;
       return 0;
   }
   else if(abs(N-M) == 0){
       ans = fac[N] * fac[M] * 2 % MOD;
   }
   else{
       ans = fac[N] * fac[M] % MOD;
    }
    cout << ans << endl;
}

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

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1e9+7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

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

template<class T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
///////////////////////////////////////////////
/*(._.)*/
int main() {
	ll ans = 0;
	int N, M;
	cin >> N >> M;
	vector<vector<ll> >AB(100002);
	REP(i,N){
	    ll A,B;
	    cin >> A >> B;
	    AB[A].PB(B);
	}

	priority_queue<ll> Q;
	FORq(i,1,M){
		REP(j,AB[i].size()){
			Q.push((AB[i])[j]);
		}

		if (Q.empty() == true) continue;
		ll nvalue = Q.top(); Q.pop();
		ans += nvalue;

	}

	cout << ans << "\n";
}


Measured memory_bytes: 5632
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int Max = 1000000;
int main(){
  	string S;
  	cin >> S;

  	int N = S.size();
  	int sub = N/2;
  	for(int i=0;i<sub;i++){
  		if(S[i]!=S[sub-1-i]){
  			cout << "No" <<endl;
  			return 0;
  		}
  	}
  	for(int i=sub+1;i<N;i++){
  		if(S[i]!=S[N-1-i]){
  			cout << "No" <<endl;
  			return 0;
  		}
  	}

  	cout << "Yes" <<endl;
    
  	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#include <algorithm>

int main(){
  int n;
  cin >> n;
  
  for(int i = 1; i <= 9; i++){
    if(111 * i >= n){
      cout << 111 * i << endl;
      break;
    }
  }
}

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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n; cin >> n;
  map<string, int> mp;
  REP(i,n){
    string s; cin >> s;
    mp[s]++;
  }
  cout << "AC x " << mp["AC"] << endl;
  cout << "WA x " << mp["WA"] << endl;
  cout << "TLE x " << mp["TLE"] << endl;
  cout << "RE x " << mp["RE"] << endl;
  return 0;
}


Measured memory_bytes: 3648
n,w = map(int,input().split())
wv = [[int(i) for i in input().split()] for j in range(n)]

wv.sort(key=lambda x:(x[0],-x[1]))
#print(wv)
#exit()
#wv.sort()
min_v = wv[0][0]
cnt = 0
num = [0]*4

for i in range(n):
    num[wv[i][0] - min_v] +=1
        
#dp = [[[0 for i in range(n)] for j in range(n)] for k in range(n)]

#print(wv)

t_num3 = [0]
tmp = 0
for i in range(num[3]):
    tmp += wv[n-num[3]+i][1]
    t_num3.append(tmp)

#print(t_num3)
#exit()

t_ans = 0
t_num0 = 0
ans = 0


for i in range(num[0]+1):
    if i != 0:
        t_num0 += wv[i-1][1]
    #print(t_ans,i)
    t_num1 = 0
    for j in range(num[1]+1):
        if j != 0:
            t_num1 += wv[num[0]+j-1][1]
        t_num2 = 0
        for k in range(num[2]+1):
            if k != 0:
                t_num2 += wv[num[0]+num[1]+k-1][1]
            ima_w = min_v*(i+j+k) + 1*j+2*k
            idx = (w - ima_w)//(min_v+3)
            if ima_w > w:
                break
            else:
                t_ans = t_num0+t_num1+t_num2 + t_num3[min(idx,num[3])]
        #print(t_ans)
            ans = max(t_ans,ans)

print(ans)

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列 -92
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}



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

    ll max = 0;
    for(auto a:mp){
        max+=ncr(a.second,2);
    }

    for(int i=0;i<n;i++){
        int x = a[i];
        cout << max-ncr(mp[a[i]],2)+ncr(mp[a[i]]-1,2) << endl;
    }
    return 0;
}

Measured memory_bytes: 8320
#include <cstdint>
#include <algorithm>
#include <array>
#include <iostream>

#if defined(__GNUC__) && !defined(__clang__)
#  pragma GCC optimize("Ofast")
#  pragma GCC target("sse4.2", "tune=native")
#endif


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

  std::int64_t n;
  std::cin >> n;

  std::array<std::int64_t, 5> capacities;
  for (auto&& e : capacities) {
    std::cin >> e;
  }

  auto min = *std::min_element(std::cbegin(capacities), std::cend(capacities));
  std::cout << (capacities.size() + ((n + min - 1) / min) - 1) << std::endl;
}


Measured memory_bytes: 256
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int main()
{
	int n,k;
	cin>>n>>k;
	if(n>=k*2-1) cout<<"YES"<<endl;else cout<<"NO"<<endl;
}


Measured memory_bytes: 764
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N = I()

if N % 1000 == 0:
    print(0)
else:
    print(1000-N%1000)

Measured memory_bytes: 61768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll n;
  cin >> n;
  priority_queue<ll> q;
  for(ll i=0;i<n;i++) {
    ll tmp;
    cin >> tmp;
    q.push(tmp);
  }
  ll cnt=0,a=0,b=0;
  while(q.size()) {
    cnt++;
    ll tmp=q.top();
    q.pop();
    if(cnt%2) {
      a+=tmp;
    }
    else {
      b+=tmp;
    }
  }
  cout << a-b << endl;
}

Measured memory_bytes: 256
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
inp = input()
a = inp.split()
b = int(a[0])//int(a[1])
c = int(a[0])%int(a[1])
d = Decimal(a[0])/Decimal(a[1])
d = d.quantize(Decimal('0.000001'),rounding=ROUND_HALF_UP)
print(b,c,d)


Measured memory_bytes: 6396
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>
#include <bitset>
#include <stack>

using namespace std;
typedef long long ll;

int main(){
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;

  int now = 1;
  int cnt = 0;
  vector<int> vec;
  for (int i = 0; i < N; i++) {
    if (S[i] == ('0' + now)) {
      cnt++;
    } else {
      vec.push_back(cnt);
      now ^= 1;
      cnt = 1;
    }
  }
  if (cnt > 0) {
    vec.push_back(cnt);
  }
  if (vec.size() % 2 == 0) {
    vec.push_back(0);
  }
  
  ll res = 0;
  int right = 0;
  ll sum = 0;
  for (int left = 0; left < vec.size(); left+=2) {
    while (right < vec.size() && right < left + 2 * K + 1) {
      sum += vec[right];
      ++right;
    }

    res = max(res, sum);

    if (right == left) ++right;
    else if(right >= vec.size()) break;
    else sum -= vec[left] + vec[left + 1];
  }
  
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 1020
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define int long long

signed main() {
  int a, b;
  cin >> a >> b;
  if (abs(a - b) <= 1) {
    cout << "Yay!" << endl;
  } else {
    cout << ":(" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		partB101();
	}


	public static void partB101() {
		Scanner scB = new Scanner(System.in);
		String N = scB.nextLine();
		int M = Integer.parseInt(N);
		int S = 0;

		for(int i = 0 ; i < N.length() ; i++) {
			S += Character.getNumericValue(N.charAt(i));
		}
    

		if(M % S == 0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 21844
#include<iostream>
using namespace std;
int main(){
int a,b,c;
cin>>a>>b>>c;
if (a>b)
swap(a,b);
if (b>c)
swap(b,c);
if (a>b)
swap(a,b);
cout<<a<<" "<<b<<" "<<c<<endl;
return 0;
}


Measured memory_bytes: 3104
#include<stdio.h>
int main(void){
    char C[1200]={};
    int i=0,sum=0;
    while(scanf("%s",C)==1){
        if((C[0]-48)==0) break;
       do{
           sum+=(C[i]-48);
           i++;
       }while(C[i]!='\0');
        printf("%d\n",sum);
        i=0;
        sum=0;
    }
    return 0;
}


Measured memory_bytes: 2052
import sys
h,w = map(int,input().split())
s =["."*(w+2)]+["."+input()+"." for i in range(h)]+["."*(w+2)]

for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j] =="#":
            a=s[i][j-1]+s[i][j+1]+s[i-1][j]+s[i+1][j]
            if a.count("#") == 0:
                print("No")
                sys.exit()
else:
    print("Yes")


Measured memory_bytes: 9196
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  int a;
  
  cin >> N;
  
  a = 1000 - N%1000;
  
    
  if(a==1000)
    cout << 0;
  else
 	 cout << 1000 - N%1000 ;
    
  
}

Measured memory_bytes: 3624
s = input()
n = len(s)
s += "ZZ"
def make(s,i):
    cnt = 0
    a,bc = [],[]
    while True:
        if s[i] == "A":
            a.append(cnt)
            i += 1
        elif s[i:(i+2)] == "BC":
            bc.append(cnt)
            i += 2
        else:
            while s[i] != "A":
                if s[i] == "Z":
                    break
                i += 1
            return a,bc,i
        cnt += 1

def cnt(bc):
    c = 0
    for i in range(len(bc)):
        c += bc[i]-i
    return c

i = 0
ans = 0
while i < n:
    a,bc,i = make(s,i)
    ans += cnt(bc)
print(ans)

Measured memory_bytes: 52816
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] tmpArray = br.readLine().split(" ");
		int n = Integer.parseInt(tmpArray[0]);
		int m = Integer.parseInt(tmpArray[1]);
		
		int[][] matrix = new int[n][m];
		
		for(int i = 0; i < n; i++){
			tmpArray = br.readLine().split(" ");
			for(int j = 0; j < m ; j++){
				matrix[i][j] = Integer.parseInt(tmpArray[j]);

			}
		}
		
		//そのスポーツをやるかどうか
		boolean[] hold = new boolean[m + 1];
		Arrays.fill(hold, true);
		hold[0] = false;
		
		System.out.println(calcMaxNum(matrix, hold));
	}
	
	static int calcMaxNum (int[][] matrix, boolean[] hold){
		int n = matrix.length;
		int m = matrix[0].length;
		
		//実施するスポーツがあるか
		int count = 0;
		for(int i = 0; i < hold.length ;i++){
			if(hold[i] == true){
				count++;
			}
		}
		
		if(count == 0){
			return Integer.MAX_VALUE;
		}
		//System.out.println(count+"sports will be held");
		
		int[] member = new int[m + 1];
		Arrays.fill(member, 0);
		
		for(int i = 0; i < n; i++){
			for(int j = 0; j < m ; j++){
				if(hold[matrix[i][j]]){
					member[matrix[i][j]]++;
					break;
				}
			}
		}
		
		int max = 0;
		int maxSport = 1;
		for(int i = 1; i <= m; i++){
			if(max < member[i]){
				max = member[i];
				maxSport = i;
			}
		}
		
		//参加者最大のスポーツを外して再帰
		hold[maxSport] = false;
		int max2 = calcMaxNum(matrix, hold);
		return Math.min(max, max2);
	}

}


Measured memory_bytes: 32748
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        String S = sc.next();
        char[] C = S.toCharArray();

        String ans = String.valueOf(C[0]) + (C.length - 2) + String.valueOf(C[(C.length - 1)]); 

        System.out.println(ans);
	}
}


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

int main() {
  int N;
  int sum = 0;
  cin >> N;
  
  for (int i = 0; i < N; i++){
    int l, r;
  	cin >> l >> r;
  	sum += r - l + 1;
  }

  cout << sum << endl;
  	
}

Measured memory_bytes: 3616
#include <stdio.h>
int func(int a,int b,int c){
  int min = a>b?b:a;
  int array[99];
  int count = 0;
  for(int i = 1 ; i <= min ; i ++){
    if ((a % i == 0) && (b % i == 0)){
      array[count] = i;
      count ++;
    }
  }
  return array[count - c];

}
int main(){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    printf("%d\n",func(a,b,c));
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <bitset>
#define DIVCEIL(A,B) ((A+(B-1))/B)
using namespace std;


void solve(vector<long long> abcd){
    for(unsigned int i=0; i<pow(2, 3); i++){
        bitset<3> bit(i);
        auto tmp = abcd[0];
        for(int j=0; j<3; j++){
            tmp = tmp + (bit[j]==1 ? abcd[1+j] : -abcd[1+j]);
        }

        if(tmp==7){
            cout << abcd[0];
            for(int j=0; j<3; j++){
                if(bit[j]==1)cout<<"+";else cout<<"-";
                cout<<abcd[1+j];
            }
            cout << "=7" << endl;
            return;
        }
    }
}

int main(){
    long long ABCD;
    scanf("%lld",&ABCD);
    vector<long long> abcd(4, 0);
    int i=3;
    while(ABCD>0){
        abcd[i] = ABCD%10;
        ABCD/=10;
        i--;
    }
    solve(abcd);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define takeline cin.ignore();
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){
	
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	string s;
	cin>>s;
	ll i,j,k,l,n=s.length();
	k=1;
	for(i=0;i<n;i++){
		j=i+1;
		if(j%2){
			if(s[i]=='L'){
				k=0;break;
			}
		}
		else{
			if(s[i]=='R'){
				k=0;break;
			}
		}
	}
	if(k){
		cout<<"Yes";
	}
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <utility>
#include <map>
#include <set>
#include <algorithm>
#include<cmath>

#define rep(i, a, b) for (int i=a; i <b; i++)
#define F first
#define S second

using namespace std;

typedef long long ll;
typedef vector< int > vi;

bool pairCompare(const pair<ll, ll>& firstElof, const pair<ll, ll>& secondElof)
{
    return firstElof.second < secondElof.second;
}

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

    vector<pair<ll, ll>> a(n);

    int b, c;
    for(int i=0; i<n; i++) {
        cin >> b >> c;
        a[i].first = b;
        a[i].second = c;
    }
    sort(a.begin(), a.end(), pairCompare);
    ll sum = 0;
    bool ans = true;
    for (int i=0; i<n; i++) {
        sum += a[i].first;
        //printf("sum is %d at %d\n", sum, i);
        if (sum > a[i].second) {
            ans = false;
            break;
            //printf("falsed at %d\n", i);
        } else {
            ans = true;
        }
    }
    if(ans == true) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    
    return 0;
}

Measured memory_bytes: 3328
#C - Prison(ABC127)
N,M=map(int, input().split())
l,r=map(int, input().split())
for i in range(M-1):
    L,R=map(int,input().split())
    if l<L:
        l=L
    if r>R:
        r=R
if r-l+1>0:
    print(r-l+1)
else:
    print(0)

Measured memory_bytes: 3060
N,A,B=map(int,input().split())
print
if abs(A-B)%2==0:
  print(abs(A-B)//2)
else:
  C=min([A-1,B-1,N-A,N-B])
  if C==A-1 or C==B-1:
    print((A+B-1)//2)
  else:
    print((N-A+N-B+1)//2)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}


signed main(void) {
    string s;
    cin>>s;
    int n=s.size();
    stack<int>st;
    rep(i,n){
       if(st.size()!=0&&s[i]!=st.top())
           st.pop();
        else
            st.push(s[i]);
    }
    cout<<n-st.size();
}


Measured memory_bytes: 1152
<?php
fscanf(STDIN, '%d', $w);
fscanf(STDIN, '%d', $n);

// 初期化
for ($i=1; $i<=$w; $i++){
	$line[$i] = $i;
}

// スワップ
for ($i=1; $i<=$n; $i++){
	fscanf(STDIN, '%d,%d', $a,$b);
	$tmp = $line[$a];
	$line[$a] = $line[$b];
	$line[$b] = $tmp;
}

// 出力
foreach($line as $l){
	echo $l.PHP_EOL;
}

Measured memory_bytes: 6568
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;
const int mod = 2019;

int main(void){
    int L, R;
    cin >> L >> R;
    
    if(R - L + 1 >= 2019){
        cout << 0 << endl;
        return 0;
    }
    for(int i = L; i <= R; ++i){
        if(i % mod == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    
    int ans = 2020;
    for(int i = L; i < R; ++i){
        for(ll j = i + 1; j <= R; ++j){
            ll temp = (ll)((i * j)) % mod;
            ans = min(ans, (int)temp);
        }
    }
    
    cout << ans << endl;
}


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

int main()
{
  string s, ans = "Yes";
  int n, half;

  cin >> s;
  n = s.length();
  half = (n - 1) / 2;
  for (int i = 0; i < half; i++)
  {
    if (s[i] != s[n - i - 1])
      ans = "No";
    if (i < half / 2)
    {
      if (s[i] != s[half - i - 1] || s[half + 1 + i] != s[n - i - 1])
        ans = "No";
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main () {
  int len,i,j,tmp,k=0;
  int ar[1000];
  scanf("%d",&len);
  for(i=0;i<len;i++){
    scanf("%d",&ar[i]);
  }
  for (i = len - 2; i >= 0; i--)
    for (j = 0; j <= i; j++)
      if (ar[j] > ar[j + 1]) {
        tmp = ar[j]; ar[j] = ar[j + 1]; ar[j + 1] = tmp;
        k++;
      }
  for (i = 0; i < len-1; i++) {
    printf("%d ", ar[i]);
  }
  printf("%d",ar[len-1]);
  printf("\n");
  printf("%d\n",k);

  return 0;
}


Measured memory_bytes: 2108
#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>;

const int INF = 100001;

int main() {
  int N, M;
  cin >> N >> M;

  vector<vector<int> > adjacant(N);
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    adjacant[a].push_back(b);
    adjacant[b].push_back(a);
  }

  vector<int> depth(N, INF);
  depth[0] = 0;
  vector<int> ans(N, -1);

  queue<P> que;
  que.push(make_pair(0, 0));

  int r = N - 1;
  while (que.size() != 0) {
    P now = que.front();  // 現在の状態
    que.pop();
    int v = now.first;
    int d = now.second;
    for (auto w : adjacant[v]) {
      if (depth[w] == INF) {
        depth[w] = d + 1;
        ans[w] = v + 1;
        que.push(make_pair(w, d + 1));
        r--;
      }
    }
  }


  // rep(i, N) cout << depth[i] << endl;
  // rep(i, N) cout << ans[i] << endl;
  if (r == 0) {
    cout << "Yes" << endl;
    for (int i = 1; i < N; i++) {
      cout << ans[i] << endl;
    }
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 10760
N = int(input())
*A, = map(int, input().split())
C = sum(A)
if C % (N*(N+1)//2) == 0:
    k = C // (N*(N+1) // 2)
    B = [A[i-1] - A[i] + k for i in range(N)]
    ok = 1
    for b in B:
        if b < 0 or b % N > 0:
            ok = 0
            break
    if ok:
        print('YES')
        exit(0)
print('NO')


Measured memory_bytes: 14260
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,0,-1}, dy[4]={1,0,-1,0};
long double eps = 1e-9;
long double pi = acos(-1);




signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int a,b,c,d,k;
    cin>>a>>b>>c>>d>>k;
    int t = a*60  +b;
    int s = c*60 + d;
    s -= k;
    cout << s-t << endl;
}

Measured memory_bytes: 3652
x, k, d = map(int, input().split(" "))

x = abs(x)
mov = x // d
ans = 0
if mov >= k:
    ans = x - k * d
else:
    if (k - mov) % 2 == 0:
        ans = x % d
    else:
        ans = abs(x%d - d)
print(ans)

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

long long n, w;
long long w1;
vector<long long> v[4];
long long ans;

int main(){
        //      cin.tie(0);
        //      ios::sync_with_stdio(false);
        cin >> n >> w;
        for(int i=0; i<4; ++i)
                v[i].push_back(0);
        for(int i=0; i<n; ++i){
                long long t;
                if(i == 0){
                        cin >> w1 >> t;
                        v[0].push_back(t);
                }else{
                        long long s;
                        cin >> s >> t;
                        v[s-w1].push_back(t);
                }
        }
        for(int i=0; i<4; ++i){
                sort(v[i].begin(), v[i].end(), greater<long long>());
        }
//      for(int i=0; i<4; ++i)
//              for(int j=0; j<v[i].size(); ++j)
//                      cout << v[i][j] << (j == v[i].size()-1 ? "\n" : " ");
        for(int i=0; i<4; ++i)
                for(int j=1; j<v[i].size(); ++j)
                        v[i][j] += v[i][j-1];
        for(int i0=0; i0<v[0].size(); ++i0)
                for(int i1=0; i1<v[1].size(); ++i1)
                        for(int i2=0; i2<v[2].size(); ++i2)
                                for(int i3=0; i3<v[3].size(); ++i3){
                                        long long wt = 0;
                                        wt += (long long)w1 * (i0+i1+i2+i3);
                                        wt += i1;
                                        wt += 2 * i2;
                                        wt += 3 * i3;
                                        if(w < wt) continue;
                                        long long tmp = 0;
                                        if(i0>0)tmp+=v[0][i0-1];
                                        if(i1>0)tmp+=v[1][i1-1];
                                        if(i2>0)tmp+=v[2][i2-1];
                                        if(i3>0)tmp+=v[3][i3-1];
                                        ans = max(ans, tmp);
                                }
        cout << ans << "\n";
}

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

int main(void)
{
    int P, Q, R;
    cin >> P >> Q >> R;

    int A = P + Q;
    int B = Q + R;
    int C = R + P;

    int D = min(A, B);
    int ans = min(D, C);
    cout << ans << endl;
    return (0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<ll, ll> pl;
typedef pair<int, int> pi;
typedef vector<int> V;

int main() {
  ll n, m;
  cin >> n >> m;
  dump(abs((n-2)*(m-2)));
  return 0;
}


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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

// const int INF = 1001001001;
// long long max => LLONG_MAX

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int h, w; cin >> h >> w;
    int n; cin >> n;
    vector<vector<int>> ans(h, vector<int>(w,0));
    int r = 0; int c = 0;
    for(int i = 0; i < n; i++){
        int a; cin >> a;
        while(a > 0){
            ans[r][c] = i+1;
            if(c%2 == 0){
                if(r == h-1) c++;
                else r++;
            } else{
                if(r == 0) c++;
                else r--;
            }
            a--;
        }
    }

    for(int i = 0; i < h; i++){
        cout << ans[i][0];
        for(int j = 1; j < w; j++) cout << " " << ans[i][j];
        cout << endl;
    }

    return 0;
}


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

int main(){
    char letter[6];
    cin >> letter;
    if(letter[2]==letter[3]&&letter[4]==letter[5]){
        cout << "Yes"<< endl;
    } else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int n, k;
    cin >> n >> k;
    int p[n];
    for(int s = 0; s < n; s++){
        cin >> p[s];
    }
    int count = 0;
    sort(p, p+n);
    
    for (int i = 0; i < k; i++){
        count += p[i];
    }
    cout << count << endl;
}

Measured memory_bytes: 3152
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


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


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(S, T):
    ans = []
    for a, b in zip(S, T):
        ans.append(a)
        ans.append(b)

    return ''.join(ans)


def main():
    N = read_int()
    S, T = read_str_n()
    print(slv(S, T))


if __name__ == '__main__':
    main()


Measured memory_bytes: 7620
#include<stdio.h>

int main()
{

	int l,i,a,b[10000],c,d,e;
	scanf("%d",&a);
	for(i=0;i<a;i++)
	{
		scanf("%d%d%d",&c,&d,&e);
			if(c<d)
			{
				l=c;
				c=d;
				d=l;
			}
			if(c<e)
			{
				l=c;
				c=e;
				e=l;
			}
		if(c*c==d*d+e*e)						
			b[i]=0;
		else
			b[i]=1;
	}
	for(i=0;i<a;i++)
	{
		if(b[i]==0)
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 0
S = list(input())
T = list(input())
s_appeared = [0] * 26
t_appeared = [0] * 26
for i in range(len(S)):
    if S[i] != T[i]:
        s_temp = s_appeared[ord(S[i])-97]
        if s_temp == 0:
            s_appeared[ord(S[i])-97] = T[i]
        else:
            if T[i] != s_temp:
                print('No')
                break

        t_temp = t_appeared[ord(T[i])-97]
        if t_temp == 0:
            t_appeared[ord(T[i])-97] = S[i]
        else:
            if S[i] != t_temp:
                print('No')
                break
    else:
        s_appeared[ord(S[i])-97] = T[i]
        t_appeared[ord(T[i])-97] = S[i]
else:
    print('Yes')

Measured memory_bytes: 70732
num, max_num = map(int, input().split())
x = []
y = []
count = 0

for i in range(num):
  x1,y1 = map(int, input().split())
  x.append(x1)
  y.append(y1)

for i in range(len(x)):
  temp = (x[i]**2 +y[i]**2)**(1/2)
  if temp <= max_num:
    count += 1

print(count)



Measured memory_bytes: 24764
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
typedef pair<int, int> p;
 
int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    ll A, B;
    cin >> N >> A >> B;

    vector<ll> X(N);

    for(int i = 0; i < N; i++) cin >> X[i];

    ll ans = 0;

    for(int i = 1; i < N; i++) {
        ans += min(A * (X[i] - X[i - 1]), B);
    }

    cout << ans << endl;    
}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

int N, A, B, C;
string Q[100010];
set<int> NG[100010];
string ans;

bool dfs(int t, int a, int b, int c)
{
	if (t == N)
	{
		cout << "Yes" << endl;
		rep(i, 0, N)
		{
			cout << ans[i] << endl;
		}
		return true;
	}

	if (NG[t].find(100 * a + 10 * b + c) != NG[t].end())return false;

	bool res = false;
	if (Q[t] == "AB")
	{
		if (b != 0)
		{
			ans[t] = 'A';
			res=res||dfs(t + 1, min(a + 1, 2LL), min(b - 1, 2LL), min(c, 2LL));
		}
		if (res)return res;
		if (a != 0)
		{
			ans[t] = 'B';
			res = res || dfs(t + 1, min(a - 1, 2LL), min(b + 1, 2LL), min(c, 2LL));

		}	
	}
	if (Q[t] == "AC")
	{
		if (c != 0)
		{
			ans[t] = 'A';
			res = res || dfs(t + 1, min(a + 1, 2LL), min(b, 2LL), min(c-1, 2LL));
		}
		if (res)return res;
		if (a != 0)
		{
			ans[t] = 'C';
			res = res || dfs(t + 1, min(a - 1, 2LL), min(b, 2LL), min(c+1, 2LL));

		}
	}
	if (Q[t] == "BC")
	{
		if (c != 0)
		{
			ans[t] = 'B';
			res = res || dfs(t + 1, min(a, 2LL), min(b + 1, 2LL), min(c-1, 2LL));
		}
		if (res)return res;
		if (b != 0)
		{
			ans[t] = 'C';
			res = res || dfs(t + 1, min(a, 2LL), min(b - 1, 2LL), min(c+1, 2LL));

		}
	}

	if (!res)NG[t].insert(100 * a + 10 * b + c);
	return res;
}

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

	ans.resize(100010);

	cin >> N >> A >> B >> C;
	A = min(2LL, A);
	B = min(2LL, B);
	C = min(2LL, C);

	rep(i, 0, N)
	{
		cin >> Q[i];
	}

	if (!dfs(0, A, B, C))
	{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 22860
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		System.out.println("0 0");
		kock(n, 0, 0, 100, 0);
		System.out.println("100 0");
	}

	public static void kock(double n, double p1x, double p1y, double p2x,
			double p2y) {
		if (n == 0) {
			return;
		}

		double sx = (2 * p1x + p2x) / 3;
		double sy = (2 * p1y + p2y) / 3;
		double tx = (p1x + 2 * p2x) / 3;
		double ty = (p1y + 2 * p2y) / 3;

		double z = Math.toRadians(60);

		double ux = (tx - sx) * Math.cos(z) - (ty - sy) * Math.sin(z) + sx;
		double uy = (tx - sx) * Math.sin(z) + (ty - sy) * Math.cos(z) + sy;

		kock(n - 1, p1x, p1y, sx, sy);
		System.out.print(sx);
		System.out.print(" ");
		System.out.println(sy);

		kock(n - 1, sx, sy, ux, uy);
		System.out.print(ux);
		System.out.print(" ");
		System.out.println(uy);

		kock(n - 1, ux, uy, tx, ty);
		System.out.print(tx);
		System.out.print(" ");
		System.out.println(ty);

		kock(n - 1, tx, ty, p2x, p2y);
	}
}

Measured memory_bytes: 32980
///Ok @ridwanul
#include<bits/stdc++.h>

using namespace std;

/*****************MACRO*****/

#define input freopen("in.txt","r",stdin)
#define output freopen("out.txt","w",stdout)

#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))


#define int long long
#define ll long long
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

/*******CONSTANT***********/
#define INF (1<<30) //infinity value
#define EPS 1e-9

#define SIZ 1005
#define PI (acos(-1));
const int MOD = 1000000007;



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

	int n;
	cin>>n;
	int k;
	cin>>k;
	int *a = new int[n];


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


	}
    int inv1=0;
    int inv2=0;

    for(int i=0; i<n-1; ++i){ ///*****ETA i<N-1 porjonto nile no problem; actually OK
        for(int j=i+1; j<n; ++j){ ///focus j=i+1
            if(a[i]>a[j])++inv1;
        }
    }



    for(int i=0; i<n; ++i){
        ///****but this i<n hotei hobe ; na hole A1 er last element porer A1 er
        ///shathe compare hosse na
        for(int j=0; j<n; ++j){ ///focus j=0 karon arekta A1 er shathe comparing
            if(a[i]>a[j])++inv2;
        }
    }


	//cout<<"inv1="<<inv1<<"\tinv2="<<inv2<<"\n";

    inv1 = (inv1*k)%MOD;
	int y = k * (k-1) / 2;///k*(k-1)/2 keo mod kora lagbe
	y%=MOD;
	inv2= (inv2*y)%MOD;
	int res = (inv1+inv2)%MOD;
	cout<<res<<"\n";

	return 0;
}

/*****
b[i]= a[i];
b[i+n]= a[i];

int inv2= mergeSort(b,t2, 0, 2*n-1); this is wrong ;
karon focus: A1 A1 2ta pashapashi rakhar por ami chaitesi
A1 theke arekta A1 er inversion count but MERGESORT e kintu ekekta A1 er internal inversion o
count hoy

so simply use brute force

*/


/************
Focus:
int ans= (inv1*k)+(1.0*inv2*k*(k-1))/2;
    cout<<ans%MOD<<"\n";


this is entirely wrong


Even k can be large 10^9 ; so k*(k-1)/2 keo mod kora lagbe
then (a%mod+b%mod)%mod formula
	int x = cnta*k;
	int y = k * (k-1) / 2; y%=MOD;
	int res = (x%MOD+cntb*y)%MOD;
	return cout<<res%MOD<<endl,0;
*/




Measured memory_bytes: 256
class Card {
  constructor(mark, value) {
    this.mark = String(mark);
    this.value = Number(value);
  }

  equals(other) { return this.value === other.value && this.mark === other.mark; }

  compareTo(other) {
    if (this.value === other.value) return 0;
    else if (this.value < other.value) return -1;
    else return 1;
  }

  toString() { return `${this.mark} ${this.value}` }
}

(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  const arr = lines.map(r => r.split(' ')).map(c => new Card(c[0], c[1]));
  const quick_arr = Array.from(arr);

  quickSort(quick_arr, 0, n - 1);
  const isStable = arr.map((e, idx) => ({val: e, idx: idx}))
      .sort((a, b) => a.val.compareTo(b.val) || a.idx - b.idx)
      .every((card, i) => card.val.equals(quick_arr[i]));

  console.log(isStable ? 'Stable' : 'Not stable');
  console.log(quick_arr.join('\n'));
})();

function quickSort(arr, p, r) {
  const partition = function(arr, p, r) {
     let x  = arr[r];
     let i = p - 1;
     for (let j = p; j < r; j++) {
       if (arr[j].compareTo(x) <= 0) {
         i++;
         [arr[i], arr[j]] = [arr[j], arr[i]];
       }
     }
     [arr[i + 1], arr[r]] = [arr[r], arr[i + 1]];
     return i + 1;
  }

  quickSort = function(arr, p, r) {
    if (p < r) {
      let q = partition(arr, p, r);
      quickSort(arr, p, q - 1);
      quickSort(arr, q + 1, r);
    }
  }
  quickSort(arr, p, r);
}



Measured memory_bytes: 75248
#include <iostream>
#include <string>
#include <math.h>

using namespace std;

int main() {
    string str;
    cin >> str;
    
    long long int sum=0, num=0;
    for(int bit=0; bit<(1<<(str.length()-1)); bit++) {
        for(int i=0; i<str.length(); i++) {
            num *= 10;
            num += atoll(&str[i])/pow(10, str.length()-1-i);
            // cout << "string:" << str[i] << " number:" << num << endl;
            if(bit&(1<<i)) {
                // cout << "reset num" << endl;
                sum += num;
                num = 0;
            }
        }
        // cout << "reset num" << endl;
        sum += num;
        num = 0;
    }

    cout << sum << endl;
    
    return 0;
    
}

Measured memory_bytes: 384
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x.size())
#define pb push_back
#define mp make_pair
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define int long long
#define endl "\n"

using namespace std;

const int N = 500510;
const int inf = (int)(1e18) + 123;
const int mod = 998244353;
const double eps = 1e-9;

signed main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    int cnt = (n + 1) / 2;
    cout << setprecision(6) << fixed << (1.0 * cnt / n) << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

ll modpow(ll a, ll b){
    if(b == 0) return 1;
    else if(b % 2 == 0){
        ll d = modpow(a, b/2) % MOD;
        return (d * d) % MOD;
    }
    else{
        return (a * modpow(a, b-1)) % MOD;
    }
}

const int MAX_N = 1000011;

ll fact[MAX_N], finv[MAX_N];
ll comb(int n, int r){
    if(n < r || r < 0) return 0;
    return fact[n] * finv[n-r] % MOD * finv[r] % MOD;
}

void calc(int n){
    fact[0] = finv[0] = 1;
    for(int i=1; i<=n; i++){
        fact[i] = (fact[i-1] * i) % MOD;
        finv[i] = modpow(fact[i], MOD-2);
    }
}

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

    calc(1000010);

    int x, y; cin>>x>>y;

    int minnum = -1, maxnum = -1;
    for(int i=0; i<=1000000; i++){
        int X = x, Y = y;
        X -= i;
        Y -= i * 2;

        if(0 <= X && 0 <= Y && Y * 2 == X){
            minnum = i;
            maxnum = i + Y;
            break;
        }
    }

    //cout << maxnum << endl;

    cout << comb(maxnum, minnum) << endl;

    return 0;
}

Measured memory_bytes: 16000
def main():
    X = int(input())
    if X >= 1800:
        print(1)
    elif X >= 1600:
        print(2)
    elif X >= 1400:
        print(3)
    elif X >= 1200:
        print(4)
    elif X >= 1000:
        print(5)
    elif X >= 800:
        print(6)
    elif X >= 600:
        print(7)
    elif X >= 400:
        print(8)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9172
N, K = map(int, input().split())
a = list(map(int, input().split()))

dp = [False] * (K+1)

for i in range(1, K+1):
    for j in range(N):
        if 0 <= i - a[j] and not dp[i-a[j]]:
            dp[i] = True
            break

print("First" if dp[K] else "Second")

Measured memory_bytes: 42220
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

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

    for (int i = 0; i <= N; i += 4) {
        if ((N - i) % 7 == 0) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
 
typedef struct {
  char name[10];
  int t;
} P;
 
P Q[100000], _Q;
int head = 0, tail = 0, n,q,i,c=0,t=0,s;
 
void enqueue(P x){
  if(tail == n){
    tail = 0;
  }
  Q[tail++]=x;
}
 
P dequeue(void){
  if(head == n){
    head = 0;
  }
  return Q[head++];
}
 
int main(){
 
  scanf("%d %d",&n,&q);
  for(i=0;i<n;i++){
    scanf("%s%d",Q[i].name,&Q[i].t);
  }
 
  while(c!=n){
    _Q=dequeue();
    if(_Q.t<=q){
      t += _Q.t;
      c++;
      printf("%s %d\n",_Q.name,t);
    }else{
      t+=q;
      _Q.t-=q;
      enqueue(_Q);
    }
  }
  return 0;
}

Measured memory_bytes: 3512