akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
    詰まった時に、別の分野の問題として考え直す（これdpでは？、グラフとしてみればいいのでは？）
    多くの問題はパターンマッチだが、パターンに落とし込むまでが難しく、そのための訓練としてわからない問題をあれこれ色々な角度から考察してみるのではないか
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

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

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

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


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

    int n; cin >> n;
    vector<int> p(n+5, 0);
    repr(i, 1, n+1) cin >> p[i];

    int ans=0;
    repr(i, 1, n+1){
        if(p[i]==i){
            int r=i;
            while(p[r]==r) ++r;
            ans += max(1, (r-i+1)/2);
            i=r-1;
        }
    }
    cout << ans  << endl;


    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<map>
#include<string>
#include<stdio.h>
using namespace std;
int n;
bool flag;
string last,s;
map<string,int>a;
int main()
{
	cin>>n;
	cin>>last;
	a[last]=1;
	while(--n)
	{
		cin>>s;
		if(last[last.size()-1]!=s[0]||a[s])
			flag=true;
		a[s]=1;
		last=s;
	}
	if(flag)
		puts("No");
	else
		puts("Yes");
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var h, w, k int
	fmt.Scan(&h, &w, &k)
	cs := make([][]byte, h)
	for i := range cs {
		fmt.Scan(&cs[i])
	}
	var ans int
	for i := 0; i < 1<<uint(h+w); i++ {
		var cnt int
		for s := 0; s < h; s++ {
			for t := 0; t < w; t++ {
				if i&(1<<uint(s)) > 0 {
					continue
				}
				if i&(1<<uint(h+t)) > 0 {
					continue
				}
				if cs[s][t] == '#' {
					cnt++
				}
			}
		}
		if cnt == k {
			ans++
		}
	}
	fmt.Println(ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 1772
program poor
  implicit none
  integer :: a, b, c, x, y, z
  read(*,*) a, b, c
  x = min(a,b,c)
  z = max(a,b,c)
  if (x == z) then
    write(*,'(a)') "No"
    stop
  end if
  y = a+b+c-x-z
  if (y == x .or. y == z) then
    write(*,'(a)') "Yes"
  else
    write(*,'(a)') "No"
  end if
end program poor

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793238462
typedef long long ll;
typedef double db;
ll mod=998244353,p[3005][3005];
int main(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    p[a][b]=1;
    for(ll i=a+1;i<=c;i++){
        p[i][b]=(p[i-1][b]%mod*b%mod)%mod;
    }
    for(ll i=b+1;i<=d;i++){
        p[a][i]=(p[a][i-1]%mod*a%mod)%mod;
    }
    for(ll i=a+1;i<=c;i++){
        for(ll j=1+b;j<=d;j++){
            p[i][j]=((p[i-1][j]%mod*j%mod+p[i][j-1]%mod*i%mod-p[i-1][j-1]%mod*(i-1)%mod*(j-1)%mod)%mod+mod)%mod;
        }
    }
    cout<<(p[c][d]%mod+mod)%mod<<endl;
}

Measured memory_bytes: 73956
#include <iostream>
#include <cmath>

using namespace std;

int main() {
  int tax_old, tax_new, sum_old, sum_new, tmp_old, tmp_new;
  while(cin>>tax_old>>tax_new>>sum_old && !(tax_old==0 && tax_new==0)) {
    sum_new = 0;
    for(int i=1; i<sum_old; i++) {
      for(int j=1; j<sum_old; j++) {
	tmp_old = floor(i*(100+tax_old)/100)+floor(j*(100+tax_old)/100);
	if(tmp_old == sum_old) {
	  tmp_new = floor(i*(100+tax_new)/100)+floor(j*(100+tax_new)/100);
	  if(tmp_new > sum_new) {
	    sum_new = tmp_new;
	  }
	}
	else if(tmp_old > sum_old) {
	  break;
	}
      }
    }
    cout<<sum_new<<endl;
  }
}

Measured memory_bytes: 1160
#include <cstdio>
#include <algorithm>
using namespace std;
int p[10001];

int main()
{
    int n, sum, avg;
    for (;; ){
        scanf("%d", &n);
        if (n == 0) break;
        sum = 0;
        for (int i = 0; i < n; i++) { scanf("%d", &p[i]); sum+= p[i]; }
        avg = sum / n;
        sort(p, p+n);
        int left = int(upper_bound(p, p+n, avg)-p);
        printf("%d\n", left);
    }
    return 0;
}


Measured memory_bytes: 2748
using System;

namespace AOJ.Volume3
{
    public class Handsel
    {
        public static int Main()
        {
            var input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);

            Console.WriteLine((a + b) / 2);
            return 0;
        }
    }
}

Measured memory_bytes: 9192
/*
 * If you're not willing to make sacrifices yourself, you'll never be
 * able to change anything. In order to overcome monsters, you must
 * be willing to abandon your own humanity.
 * ~ Arlert
 */

#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> II;
typedef vector<II> VII;
typedef vector<int> VI;
typedef vector<VI> VVI;

typedef long long int LL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(), a.end()
#define SET(a, b) memset(a, b, sizeof(a))
#define si(n) scanf("%d", &n)
#define dout(n) printf("%d\n", n)
#define sll(n) scanf("%lld", &n)
#define lldout(n) printf("%lld\n", n)

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define fast_io                     \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL)

#define endl '\n'

int main() {
  fast_io;
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  double dens = -1;
  int a1, b1;
  for (int ac = 0; ac <= 30; ac++)
    for (int bc = 0; bc <= 30; bc++) {
      for (int cc = 0; cc <= 3000; cc++) {
        int dcl = 0, dcr = 3000, dca = -1;
        while (dcl <= dcr) {
          int dc = (dcl + dcr) / 2;
          int twt = ac * a * 100 + bc * b * 100 + cc * c + dc * d;
          int wwt = ac * a + bc * b;
          int swt = cc * c + dc * d;
          if (twt <= f && wwt * e >= swt && wwt > 0)
            dcl = dc + 1, dca = dc;
          else
            dcr = dc - 1;
        }
        if (dca == -1) continue;
        int wwt = ac * a + bc * b;
        int swt = cc * c + dca * d;
        if (swt / (double)wwt > dens)
          dens = swt / (double)wwt, a1 = wwt * 100, b1 = swt;
      }
    }
  cout << a1 + b1 << " " << b1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, y, z, temp;
  cin >> x >> y >> z;
  temp = y;
  y = x;
  x = temp;
  x = z;
  z = temp;
  cout << x << " " << y << " " << z << endl;
}

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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}

signed main()
{   
    gearup;
    int a,b; cin >> a >>b;
    rep(i,100){
        if(a + (a-1)*(i-1) >= b){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

std::string s;
std::vector<int> vec;
int c = 0;
int main() {
    std::cin >> s;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'A' || s[i] == 'T' || s[i] == 'G' || s[i] == 'C') {
            c++;
        }
        else {
            vec.push_back(c);
            c = 0;
        }
    }
    vec.push_back(c);
    std::cout << *std::max_element(vec.begin(), vec.end()) << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <tuple>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <complex>
#include <bitset>
#include <numeric>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n) ;++(i))
#define REPN(i,a,n) FOR((i),(a),(a)+(n))
#define FOR(i,a,b) for(int (i)=(a); (i)<(b) ;++(i))
#define PB push_back
#define MP make_pair
#define SE second
#define FI first
#define DBG(a) cerr<<(a)<<endl;
#define ALL(v) (v).begin(),(v).end()
typedef long long LL;  typedef pair<LL, LL> PLL; typedef vector<LL> VLL;
const LL LINF=334ll<<53; const int INF=15<<26; const LL MOD=1E9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,x,ans[200002]={},used[200002]={};
    cin >> n >> x;
    if(x==1 || x==2*n-1){
        cout << "No" <<endl;
        return 0;
    }else if(n==2){
        REPN(i,1,3)ans[i]=i;
    }else{
        ans[n]=x;
        int t=(x==2*n-2?-1:1);
        ans[n-1]=x+t;
        ans[n+1]=x-t;
        ans[n+2]=x+2*t;
        REPN(i,-1,3)used[x+i]=1;
        used[x+2*t]=1;

        int j=1;
        REPN(i,1,n-2){
            while(used[j])j++;
            ans[i]=j;
            used[j]=1;
        }
        FOR(i,n+3,2*n){
            while(used[j])j++;
            ans[i]=j;
            used[j]=1;
        }
    }
    cout << "Yes" <<endl;
    REPN(i,1,2*n-1) cout << ans[i] <<endl;

    return 0;
}


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

const int mod = 1e9 + 7;
const int siz = (1 << 21) + 7;

int n;
int tab [27][27];
int dp [27][siz];
vector < int > maski [27];

int main(){
    scanf("%d",&n);
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            scanf("%d",&tab[i][j]);
        }
    }

    for(int mask = 0; mask < (1 << n); mask++){
        maski[ __builtin_popcount(mask) ].push_back(mask);
    }
    dp[0][0] = 1;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < n; j++){
            if(tab[i][j + 1] == 0) continue;

            for(auto mask : maski[i - 1]){
                if( (mask & (1 << j)) != 0 ) continue;
                int m = mask | (1 << j);
                dp[i][m] = (dp[i][m] + dp[i - 1][mask]) % mod;
            }
        }
    }
    printf("%d\n",dp[n][(1 << n) - 1]);
    return 0;
}


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

int a[4];

int main(){
    char s;
    for(int i = 0; i<4; i++){
        cin >> s;
        a[i] = s - '0';
    }

    int ans_bit;

    //bit全探索
    for(int bit = 0; bit < (1<<3); bit++){
        int ans = a[0];
        for(int i = 0; i<3; i++){
            
            if(bit & (1<<i)){
                ans -=a[i+1];
            }else{
                ans +=a[i+1];
            }
        }
        if(ans == 7){
            ans_bit = bit;
            break;
        }
    }

    for(int i = 0; i<3; i++){
            cout<< a[i];
        if(ans_bit & (1<<i)){
            cout << '-';
        }else{
            cout << '+';
        }
    }

    cout << a[3] << "=7" << endl;
}

Measured memory_bytes: 256
#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 rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
//cout << fixed << setprecision(10);

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

  int ans = 0;
  rep(i,s.size()) {
    int j = s.size()-i-1;
    if (s[i] != s[j] && i < j) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import sys

class BitFlag:
    ALL_ON  = 0xffffffffffffffff
    ALL_OFF = 0x0000000000000000

    def __init__(self):
        self.FLAGS = self.ALL_OFF
        self.Masks = [1 << i for i in range(64)]

    def _test(self, i):
        return self.FLAGS & self.Masks[i] != 0b00

    def _set(self, i):
        self.FLAGS |= self.Masks[i]

    def _clear(self, i):
        self.FLAGS &= ~self.Masks[i]

    def _flip(self, i):
        self.FLAGS ^= self.Masks[i]

    def _all(self):
        return self.FLAGS & self.ALL_ON == self.ALL_ON

    def _any(self):
        return self.FLAGS & self.ALL_ON != self.ALL_OFF

    def _none(self):
        return self.FLAGS & self.ALL_ON == self.ALL_OFF

    def _count(self):
        return bin(self.FLAGS).count('1')

    def _val(self):
        return self.FLAGS


bf = BitFlag()

commands = {'0': bf._test,
            '1': bf._set,
            '2': bf._clear,
            '3': bf._flip,
            '4': bf._all,
            '5': bf._any,
            '6': bf._none,
            '7': bf._count,
            '8': bf._val
            }

qn = int(input())
lines = sys.stdin.readlines()
ans = [None] * qn

for i in range(qn):
    q, *arg = lines[i].split()
    if len(arg):
        ans[i] = commands[q](int(arg[0]))
    else:
        ans[i] = commands[q]()

[print(int(x)) for x in ans if x is not None]


Measured memory_bytes: 22188
while True:
  n,r = tuple(map(int,input().split()))
  if n==0 and r==0:
    break
  l = [n-i for i in range(n)]
  for i in range(r):
    p,c = tuple(map(int,input().split()))
    l1 = [l[i] for i in range(p-1,p+c-1)]
    l2 = [l[i] for i in range(0,p-1)]
    l3 = l1+l2
    for i in range(p+c-1):
      l[i] = l3[i]
  print(l[0])

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

int main() {
  int N,K; cin >>N >>K;
  vector<int> sunuke(N);
  rep(i,0,K) {
    int d; cin >>d;
    rep(j,0,d) {
      int A; cin >>A;
      sunuke[A-1]++;
    }
  }
  int Ans=0;
  rep(i,0,N) {
    if (sunuke[i]==0) Ans++;
  }
  cout <<Ans <<endl;
  return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int bigmod(int a,int k,int m)
{
    int ans=1;
    while(k)
    {
        if(k%2) ans=(long long )ans*a%m;
        a=(long long) a*a%m;
        k/=2;
    }
    return ans;
}
int main()
{

    ll n,a,b,i,j=1,k,l=1,m;
    k=1e9+7;
    cin>>n>>a>>b;

    m=bigmod(2,n,k);
    m-=1;
    for(i=0;i<a;i++) {j=j*(n-i)%k;
                    l=l*(i+1)%k;
    }

    l=bigmod(l,k-2,k);
    a=j*l%k;
    j=l=1;
    for(i=0;i<b;i++) {j=j*(n-i)%k;
                    l=l*(i+1)%k;
    }

    l=bigmod(l,k-2,k);
    b=j*l%k;
    m-=a;
    if(m<0) m+=k;
    m-=b;
    if(m<0) m+=k;
    cout<<m<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
  int h,w;
  cin >> h >> w;
  
  bool f[h][w] = {};
  rep(i,0,h){
    string s;
    cin >> s;
    rep(j,0,w){
      if(s[j] == '#')
        f[i][j] = true;
      else
        f[i][j] = false;
    }
  }
  
  int ans[h][w] = {};

  rep(i,0,h){
    rep(j,0,w){
      int sum = 0;
      //printf("i:%d j:%d \n",i,j);

      if(!f[i][j]){
        
        if(i > 0){
          if(j > 0 )    
            if(f[i-1][j-1]){
              sum++;
              //cout << "done 1" << endl;
            }
              
          if(f[i-1][j]){
            sum++;
            //P("done 2");
          }

          if(j < w-1)
            if(f[i-1][j+1]){
              sum++;
              //P("done 3");
            }
        }
        
        if(j > 0){
          if(f[i][j-1]){
            sum++;
            //P("done 4");
          }
        }

        if(j < w-1){
          if(f[i][j+1]){
            sum++;
            //P("done 5");
          }
        }
        
        if(i < h-1){
          if(j > 0)
            if(f[i+1][j-1]){
              sum++;
              //P("done 6");
            }
        

          if(f[i+1][j]){
            sum++;
            //P("done 7");
          }

          if(j < w-1){
            if(f[i+1][j+1]){
              sum++;
              //P("done 8");
            }
          }
        }
      
      }

    ans[i][j] = sum;
    }
  }

  rep(i,0,h){
    rep(j,0,w){
      if(f[i][j])
        cout << "#";
      else
        cout << ans[i][j];
    }
    cout << endl;
  }
  ret 0;
}

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


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

    vector<int> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }

    int cntup = 1;
    int cntAns = 0;
    for (int i = 0; i < N; ++i) {
        if (A[i] != cntup) {
            ++cntAns;
        } else if (A[i] == cntup){
            ++cntup;
        }
    }

    bool ans1 = false;
    if (cntAns != N) ans1 = true;

    int ans = 0;
    if (ans1) ans = cntAns;
    else ans = -1;

    cout << ans << endl;
}

Measured memory_bytes: 1152
open Printf
open Scanf

let solve a b c =
  match List.sort compare [a; b; c] with
    [x; y; z] -> if x = z then 1
                 else if x = y then 2
                 else if y = z then 2
                 else 3
  | _ -> 0

let () =
  scanf "%d %d %d " solve |> printf "%d\n"


Measured memory_bytes: 384
#include<iostream>

using namespace std;

int main() {
    int X, A, B;
    cin >> X >> A >> B;

    if (A >= B) {
        cout << "delicious" << endl;
    }
    else if (A < B && X >= B - A) {
        cout << "safe" << endl;
    }
    else {
        cout << "dangerous" << endl;
    }
}

Measured memory_bytes: 256
#pragma region Macros
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep(i, n) for(i = 0; i < n; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; --i)
using namespace std;

// _________コーディングはここから！！___________

int n, m, k, i;
constexpr int N = 200010;
int a[N], b[N];
constexpr int sz = 5000000;
char reader[sz];
char *pos = reader;
int nn, now, ans;
int kk;
main() {
    reader[fread(reader, sizeof(char), sizeof(char) * sz, stdin)];
    while('0' <= *pos and *pos <= '9') n = n * 10 + *pos++ - '0';
    pos++;
    while('0' <= *pos and *pos <= '9') m = m * 10 + *pos++ - '0';
    pos++;
    while('0' <= *pos and *pos <= '9') k = k * 10 + *pos++ - '0';
    nn = n;
    pos++;
    rep(i, n) {
        while('0' <= *pos and *pos <= '9') a[i + 1] = a[i + 1] * 10 + *pos++ - '0';
        pos++;
        a[i + 1] += a[i];
        if(a[i + 1] > k) {
            nn = i;
            ++i;
            for(; i < n; ++i) {
                while('0' <= *pos and *pos <= '9') pos++;
                pos++;
            }
            break;
        }
    }
    while(*pos and *pos <= 32) pos++;
    rep(i, m) {
        while('0' <= *pos and *pos <= '9') b[i + 1] = b[i + 1] * 10 + *pos++ - '0';
        pos++;
        b[i + 1] += b[i];
        if(b[i + 1] > k) {
            m = i;
            break;
        }
    }
    now = ans = nn;
    for(i = 1; i <= m; i++) {
        kk = k - b[i];
        while(a[now] > kk) now--;
        ans = max(ans, i + now);
    }
    pos = reader;
    i = 0;
    do {
        *pos++ = ans % 10 + '0';
        ans /= 10;
        i++;
    } while(ans);
    reverse(reader, reader + i);
    fwrite(reader, sizeof(char), sizeof(char) * i, stdout);
}


Measured memory_bytes: 7784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lb;
typedef vector<int,vector<int>> vec;
typedef pair<int,int> P;
#define REP(i,j,n) for (int i=j;i<(n);i++)
#define RREP(i,n,j) for (int i = n; j<i;i--)
#define print(out) cout<< out  << "\n";
#define all(vec) vec.begin(),vec.end()
#define mod 1000000007
const int INF = 1e9;

int main(){
  ll N;cin>>N;
  vector<ll> C(N-1),S(N-1),F(N-1);

  REP(i,0,N-1){cin>>C[i]>>S[i]>>F[i];}
  REP(i,0,N-1){
    ll ans=C[i]+S[i];
    REP(j,i+1,N-1){
      if(ans<=S[j]){
        ans=S[j]+C[j];
      }
      else{
        if((ans-S[j])%F[j]==0){
          ans=ans+C[j];
        }
        else{
        ans=ans+(F[j]-(ans-S[j])%F[j])+C[j];
        }
      }
    }
    print(ans)
  }
  print(0)
}


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;

template<typename A,typename B> inline void chmin(A &a,B b){if(a>b) a=b;}
template<typename A,typename B> inline void chmax(A &a,B b){if(a<b) a=b;}
//-----------------------------------------------------------------------

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

    int d,e;
    while(cin>>d>>e,d|e)
    {
        double ans=1e9;
        for(int x=0;x<=d;x++){
            int y=d-x;
            double cost=sqrt(x*x+y*y);
            chmin(ans,abs(cost-e));
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3264
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <algorithm>
#include <set>
#include <string>
using namespace std;
int main(void)
{
	int a[1003] = { 0 };
	int n;
	int prime[1003] = {0};
	cin >> n;
	for (int i = 2; i <= 1000; i++) {
		int judge = 0;
		for (int j = 2; j < i; j++) {
			if (i%j == 0)judge = 1;
		}
		if (judge == 0)prime[i] = 1;
	}
	for (int i = 2; i <= n; i++) {
		for (int j = 2; j <= n; j++) {
			int tmp = j;
			while (tmp%i == 0) {
				tmp /= i;
				a[i] += 1;
			}
		}
	}
	long long ans = 1;
	for (int i = 2; i <= n; i++) {
		if (prime[i] == 1) { ans = ans % 1000000007 * (a[i] + 1) % 1000000007; }
	}
	cout << ans;
	return 0;
}

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

#define N 1000000
typedef long long ll;

ll a[N+1];
bool nonp[N+1] = {};
int val[N+1];

ll pow(ll a, ll k){
    ll ret = 1;
    while(k-- > 0)  ret *= a;
    return ret;
}

int main(){
    for(int i = 0; i < N+1; i++)    val[i] = i, a[i] = 1;
    for(int i = 2; i < N+1; i++){
        if(nonp[i]) continue;
        for(int j = i; j < N+1; j+=i){
            nonp[j] = true;
            int cnt = 0;
            while(val[j]%i == 0)    cnt++, val[j]/=i;
            a[j] *= (i-1)*pow(i, cnt-1);
        }
    }
    a[0] = 0, a[1] = 2;
    for(int i = 2; i < N+1; i++)    a[i] += a[i-1];

    int q;
    cin >> q;
    while(q-- > 0){
        int x;  cin >> x;
        cout << a[x] << endl;
    }

    return 0;
}


Measured memory_bytes: 15788
n,l=map(int,input().split())
absmin = 10**9
absmint = 10**9
sum_ = 0
for i in range(n):
    t = i+l
    sum_ += t
    #print(sum_)
    if absmin > abs(t):
        absmin = abs(t)
        absmint = t
        
sum_ -= absmint 
print(sum_)

Measured memory_bytes: 38384
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class A01Matrix {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int H, W, A, B;
	    in >> H >> W >> A >> B;

	    REP(i,0,H) {
	        REP(j,0,W) {
	            out << (i < H - B && j < A || i >= H - B && j >= A ? '1' : '0');
	            if (j == W-1) out << "\n";
	        }
	    }
	}
};


signed main() {
	A01Matrix solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 1280
# -*- coding: utf-8 -*-


def main():
    a = [input().split() for _ in range(3)]
    ans = [[0] * 3 for _ in range(3)]
    n = int(input())
    b = [input() for _ in range(n)]

    for bi in b:
        for y in range(3):
            for x in range(3):
                if bi == a[y][x]:
                    ans[y][x] = 1

    if ans[0][0] == ans[0][1] == ans[0][2] == 1:
        print('Yes')
    elif ans[1][0] == ans[1][1] == ans[1][2] == 1:
        print('Yes')
    elif ans[2][0] == ans[2][1] == ans[2][2] == 1:
        print('Yes')
    elif ans[0][0] == ans[1][0] == ans[2][0] == 1:
        print('Yes')
    elif ans[0][1] == ans[1][1] == ans[2][1] == 1:
        print('Yes')
    elif ans[0][2] == ans[1][2] == ans[2][2] == 1:
        print('Yes')
    elif ans[0][0] == ans[1][1] == ans[2][2] == 1:
        print('Yes')
    elif ans[0][2] == ans[1][1] == ans[2][0] == 1:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    ll n,k; cin>>n>>k;
    vector<ll>p(n);
    rep(i,n)cin>>p[i];
    sort(p.begin(),p.end());
    ll sum=0;
    rep(i,k){
        sum+=p[i];
    }
    cout<<sum<<endl;
}




























































































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

int main() {
  int D, N;
  cin >> D >> N;
  vector<int> T(D);
  for(auto& i: T) cin >> i;
  vector<int> A(N), B(N), C(N);
  for(int j = 0; j < N; ++j) cin >> A[j] >> B[j] >> C[j];

  vector<int> cur(N);
  for(int i = 0; i < D - 1; ++i) {
    vector<int> nex(N);
    for(int j = 0; j < N; ++j) if(A[j] <= T[i] && T[i] <= B[j])
      for(int nj = 0; nj < N; ++nj) if(A[nj] <= T[i + 1] && T[i + 1] <= B[nj])
        nex[nj] = max(nex[nj], cur[j] + abs(C[j] - C[nj]));
    cur = nex;
  }

  cout << *max_element(begin(cur), end(cur)) << endl;
}

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

public class Main{
    static MyReader in = new MyReader();
    static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    public static void main(String[] args){
        int N = in.i();
        String S = in.s();
        int[][] dp = new int[N+1][N+1];
        int max = 0;
        for(int i = 1; i < N+1; i++)
            for(int j = 1; j < N+1; j++)
                if(i != j && S.charAt(i-1) == S.charAt(j-1))
                    if((dp[i][j] = dp[i-1][j-1] + 1) > max && Math.abs(i-j+1) > dp[i][j])
                        max = dp[i][j];
        // for(int i = 1; i < N+1; i++){
        //     for(int j = 1; j < N+1; j++)
        //         out.printf("%d ", dp[i][j]);
        //     out.println();
        // }
        out.println(max);
        out.flush();
    }

    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s(){
            try{return readLine();}catch(IOException e){return "";}
        }

        String[] ss(){
            return s().split(" ");
        }

        int i(){
            return Integer.parseInt(s());
        }

        int[] ii(){
            String[] ss = ss();
            int[] ii = new int[ss.length];
            for(int j = 0; j < ss.length; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }

        long l(){
            return Long.parseLong(s());
        }

        long[] ll(){
            String[] ss = ss();
            long[] ll = new long[ss.length];
            for(int j = 0; j < ss.length; j++) ll[j] = Long.parseLong(ss[j]);
            return ll;
        }
    }
}


Measured memory_bytes: 166072
fun main(args : Array<String>) {
    val (N, L) = readLine()!!.split(" ").map { it.toInt() }
    val apples = (1..N).map { i ->
        L + i - 1
    }
    val tasteMadeFromN = apples.sum()


    var tasteDiff = Int.MAX_VALUE
    var tasteMadeFromNMinusOne = 0

    (0..(N-1)).forEach {i ->
        val tmp = tasteMadeFromN - apples[i]
        if (Math.abs(tasteMadeFromN - tmp) < tasteDiff) {
            tasteDiff = Math.abs(tasteMadeFromN - tmp)
            tasteMadeFromNMinusOne = tmp
        }
    }

    println(tasteMadeFromNMinusOne)
}

Measured memory_bytes: 38176
#include<stdio.h>
 
int main(){
	int m, d, h[11], i;
	h[0] = h[2] = h[4] = h[6] = h[7] = h[9] = 31;
	h[3] = h[5] = h[8] = h[10] = 30;
	h[1] = 29;
	while(scanf("%d %d", &m, &d) != 0){
		if(m == 0 || d == 0) break;
		for(i = 0; i < m - 1; i++) d += h[i];
		if(d % 7 == 1) printf("Thursday\n");
		else if(d % 7 == 2) printf("Friday\n");
		else if(d % 7 == 3) printf("Saturday\n");
		else if(d % 7 == 4) printf("Sunday\n");
		else if(d % 7 == 5) printf("Monday\n");
		else if(d % 7 == 6) printf("Tuesday\n");
		else if(d % 7 == 0) printf("Wednesday\n");
	}
	return 0;
}

Measured memory_bytes: 584
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define TRACE
#ifdef TRACE
#define tr(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define tr(...)
#endif

#define ll long long
#define ld long double 
#define endl "\n"
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (ll)(a.size())
#define all(a) a.begin(), a.end() 
#define fr(i,n) for(i=1;i<=n;i++)
#define rp(i,n) for(i=0;i<n;i++)
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the iterator to kth largest element.(0-based)
typedef pair<ll, ll> ii;
typedef vector<ll> vl;
typedef vector<vector<long long> > mat;
const ll N = 200010;
ll mod=1e9+7, n;

ll ffmod(ll x, ll y, ll mod)
{
    ll rt=1;
    while(y)
    {
        if(y&1ll) rt=(rt*x)%mod;
        x=(x*x)%mod, y/=2ll;
    }
    return rt;
}

mat mul(mat v4,mat v5)
{
    mat v6;
    vector<long long> v1;
    int i,j,l,cnt;
    for(i=0;i<n;i++)
    {
        v1.clear();
        for(j=0;j<n;j++)
        {
            cnt=0;
            for(l=0;l<n;l++)
            {
                cnt=(cnt+v4[i][l]*v5[l][j])%mod;
            }
            v1.push_back(cnt);
        }
        v6.push_back(v1);
    }
    return v6;
}

mat power(mat v, ll x)
{
    if(x==1)
        return v;
    mat tp=power(v, x/2);
    if(x%2==1)
        return mul(tp, mul(tp,v));
    return mul(tp,tp);
}

int main()
{
    FIO;
    ll k,x,i,j;
    cin>>n>>k;
    vl v1;
    mat v;
    rp(i,n)
    {
        v1.clear();
        rp(j,n) cin>>x, v1.PB(x);
        v.PB(v1);
    }
    v=power(v,k);
    x=0;
    rp(i,n) rp(j,n) x=(x+v[i][j])%mod;
    cout<<x<<endl;
    return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
map < int , int > a;
int main() {
    int n, ans = 0; scanf("%d", &n);
    for (int t; n--;)
        scanf("%d", &t), ++a[t];
    for (map < int , int > :: iterator it = a.begin(); it != a.end(); ++it)
	{
        if (it->second < it->first) ans += it->second;
        else if (it->second > it->first) ans += it->second - it->first;
    } printf("%d\n", ans);
    return 0;
}

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

int main() {
  int N,p,w,g,y,i;
  char mark;
  cin >> N;

  for (i=1;i<=N;i++){
    cin >> mark;
    if (mark == 'P'){
      p++;
    }
    if (mark == 'W'){
      w++;
    }
    if (mark == 'G'){
      g++;
    }
    if (mark == 'Y'){
      y++;
    }
  }
  if (p == 0 || w == 0 || g == 0 || y == 0){
    cout << "Three";
  }else{
    cout << "Four";
  }
}


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

int main(){
	double a[6];
	double x,y;
	while(cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4]>>a[5]){
		double b=a[0]*a[4]-a[1]*a[3];
		double c=a[0];
		a[0]=a[4];
		a[4]=c;
		a[1]*=-1.0;
		a[3]*=-1.0;
		x=(a[0]*a[2]+a[1]*a[5])/b;
		y=(a[3]*a[2]+a[4]*a[5])/b;
		if(x==-0.0)x=0.0;
		if(y==-0.0)y=0.0;
		printf("%.3f %.3f\n",x,y);
	}
	


	return 0;
}

Measured memory_bytes: 1228
#include<cstdio>
using namespace std;

long long int gcd(long long int a, long long int b){
    if (b == 0) return a;

    return gcd(b, a % b);
}

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

    long long int anst;
    scanf("%lld", &anst);
    for(int i = 2; i <= n; i++){
        long long int t;
        scanf("%lld", &t);
        long long int gcdt = gcd(anst, t);
        anst = (anst /gcdt) * t;
    }
    printf("%lld\n", anst);
    return 0;
}

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

int main() {
#ifdef HOME
	freopen("agc10a.in", "r", stdin);
	freopen("agc10a.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int n, t, e, o;

	e = o = 0;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> t;
		if (t % 2)
			o+= 1; }

	if (o % 2)
		cout << "NO\n";
	else
		cout << "YES\n";

	return 0; }


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<map>
using lint=int64_t;
using namespace std;
const lint mod=1e9+7;
int main()
{
	int N;
	string s;
	map<char,lint> m;

	cin >> N >> s;
	for(int i=0;i<s.size();i++)
	{
		m[s[i]]++;
	}

	lint ans=1;
	for(auto&& i:m)
	{
		ans*=(i.second+1);
		ans%=mod;
	}

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



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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    for(int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    for(int i = 0; i < N; ++i) {
        B[i] = 0;
        while(A[i] % 2 == 0){
            ++B[i];
            A[i] = A[i] / 2;
            }
    }
    int pos = 0;
    for(int i = 0; i < N; ++i) {
        if(B[pos] > B[i]){
            pos = i;
        }
    }
    cout << B[pos];
}

Measured memory_bytes: 256
#include <cassert>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " <<"LINE:"<<__LINE__<<"  "<< #i <<":"<< i << std::endl

 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  long long x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P = std::pair<ll, ll>;

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

  ll n;
  std::cin>>n;

  std::vector<long double> p(n);
  rep(i,0,n)std::cin>>p[i];

  std::vector<long double> prv(4000,0),now=prv;

  ll mid=2000;

  prv[mid]=p[0];
  prv[mid-1]=1.0l-p[0];

  std::cout<<std::setprecision(10)<<std::fixed;

  rep(i,0,(n-1)/2){
    long double first=p[2*i+1],second=p[2*i+2];

    rep(j,0,4000){
      now[j]=((1.0l-first)*second+(1.0l-second)*first)*prv[j];
      if(j>0){
        now[j]+=prv[j-1]*first*second;
      }
      if(j<3999){
        now[j]+=prv[j+1]*(1.0l-first)*(1.0l-second);
      }
    }

    prv=now;
  }

  long double ans=0;

  rep(i,mid,4000)ans+=prv[i];

  std::cout<<ans<<"\n";

  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;



int main() {
//    cout << setprecision(100);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

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


    map<int, int> d;
    d[a[0]] = 1;

    for (int i = 1; i < n; i++) {
        auto it = d.lower_bound(a[i]);
        if (it != d.begin()) {
            it--;
            it->second--;
            if (it->second == 0) {
                d.erase(it);
            }

            d[a[i]]++;
        }

        else {
            d[a[i]]++;
        }
    }

    int ans = 0;
    for (auto e : d) ans += e.second;
    cout << ans;

    
}




Measured memory_bytes: 5248
class DisjointSet:
    def __init__(self,size):
        self.rank = [None]*size
        self.p = [None]*size
        for i in range(size):
            self.make_set(i)
        return
    
    def make_set(self,x):
        self.p[x] = x
        self.rank[x] = 0
        return
    
    def same(self,x,y):
        return self.find_set(x) == self.find_set(y)
        
    def unite(self,x,y):
        self.link(self.find_set(x),self.find_set(y))
        return
    
    def link(self,x,y):
        if self.rank[x]>self.rank[y]:
            self.p[y] = x
        else:
            self.p[x] = y
            if self.rank[x]==self.rank[y]:
                self.rank[y] += 1
                
    def find_set(self,x):
        if x != self.p[x]:
            self.p[x] = self.find_set(self.p[x])
        return self.p[x]
    
class Edge:
    def __init__(self,source,target,cost):
        self.source = source
        self.target = target
        self.cost = cost
        
def kruskal(edges):
    edges.sort(key=lambda x: x.cost)
    
    S = DisjointSet(n)
    K = []
    
    for i in range(m):
        if S.find_set(edges[i].source) != S.find_set(edges[i].target):
            K.append(edges[i])
            S.unite(edges[i].source,edges[i].target)
    return K

n,m = map(int,input().split())
edges = []

for i in range(m):
    s,t,w = map(int,input().split())
    edges.append(Edge(s,t,w))
    
K = kruskal(edges)

cost = 0
while K:
    edge = K.pop()
    cost += edge.cost
print(cost)


Measured memory_bytes: 33740
<?php
$s = trim(fgets(STDIN));
$array = str_split($s);

for($i=0; $i<count($array); $i++){
    if($i % 2 == 0){
        if($array[$i] == 'R' || $array[$i] == 'U' || $array[$i] == 'D'){

        }else{
            echo 'No';
            exit;
        }
    }else{
        if($array[$i] == 'L' || $array[$i] == 'U' || $array[$i] == 'D'){

        }else{
            echo 'No';
            exit;
        }
    }
}
echo 'Yes';
?>

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

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

	for (int i=0;i<N;i++){
		if (S[i] != S[K-1]){
			S[i] = '*';
		}
	}
	cout << S;

	return 0;
}

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

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

int n;
int a[200200];
map<int,int> m;

int main(){
#ifdef LZT
	freopen("in","r",stdin);
#endif
	n=read();
	for(int i=1;i<=n;i++) a[i]=read()-i;
	ll ans=0;
	sort(a+1,a+n+1);
	int mx=a[(n+1)/2];
	for(int i=1;i<=n;i++) ans+=abs(a[i]-mx);
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1024
#include<cstdio>

int abs(int x){
    return x>0?x:-x;
}

int main(){
    int A,B;
    scanf("%d%d",&A,&B);
    if(A<=B){
        if((A<0&&B<=0)||(A>=0))
            printf("%d",B-A);
        else//-10 11
            printf("%d",abs(abs(A)-abs(B))+1);
    }
    else{
        if((A<0)||(A>0&&B>0))//-10 -20 20 10
            printf("%d",A-B+2);
        else//10 -20  20 -10
            printf("%d",abs(abs(B)-abs(A))+1);
    }
}


Measured memory_bytes: 256
n=int(input())
a,b=map(int, input().split())
p=list(map(int, input().split()))
c,d,e=0,0,0
for i in p:
 if(i<=a):
  c+=1
 elif(i<=b):
  d+=1
 else:
  e+=1
print(min(c,d,e))

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main() {
    int n; cin >> n;
    vector<string> s(n);
    for(int i = 0; i < n; i++) cin >> s[i];

    vector<map<char, int> > m(n);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < s[i].size(); j++){
            m[i][s[i][j]]++;
        }
    }

    vector<pair<char, int> > m2;
    for(char c = 'a'; c <= 'z'; c++){
        bool flag = true;
        int cnt = 50;
        for(int i = 0; i < m.size(); i++){
            if(m[i][c]){
                cnt = min(cnt, m[i][c]);
            }else{
                flag = false;
                break;
            }
        }
        if(flag) m2.push_back(make_pair(c, cnt));
    }

    sort(all(m2));
    for(int i = 0; i < m2.size(); i++){
        for(int j = 0; j < m2[i].second; j++){
            cout << m2[i].first;
        }
    }
    cout << endl;
}


Measured memory_bytes: 256
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = {False: 'No', True: 'Yes'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


# show_flg = True
show_flg = False


def main():
    N, K = MI()
    p = LI()

    ans = 0
    cur = 0
    right = 0
    ans_arr = []
    for left in range(N):

        while right < len(p) and right - left < K:
            cur += p[right]
            right += 1

        if ans <= cur:
            ans = cur
            ans_arr = p[left:right]
        cur -= p[left]
        # print(ans, cur, cur + p[left], left, right)

    # print(ans, ans_arr)
    p = 0

    for a in ans_arr:
        t = (a * (a + 1)) // 2
        # print(a, t)
        p += t / a

    print(p)



if __name__ == '__main__':
    main()


Measured memory_bytes: 137548
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    int n;
    cin >> n;
    vector<tuple<int, int, int>> csf(n);
    rep(i, n-1){
        int c, s, f; cin >> c >> s >> f;
        csf[i] = tie(c, s, f);
    }

    rep(st, n){
        int time = 0;
        for (int i = st; i < n-1; i++)
        {
            int c, s, f;
            tie(c, s, f) = csf[i];
            if (time <= s){
                time = s;
            } else {
                time += (time%f != 0) ? (f-time%f) : 0; 
            }
            time += c;            
        }
        cout << time << endl;    
    }
}



Measured memory_bytes: 256
use strict;
use warnings;
use utf8;
 
use feature qw/say/;
 
my $n = <>;
my @a = split(/\s+/, <>);
 
my %cnt; $cnt{$_} = ($cnt{$_} // 0) + 1 for (@a);
my ($first, $second) = sort { $b <=> $a } grep { $cnt{$_} >= 2 } (keys %cnt);
 
say !defined $first   ? 0
  : $cnt{$first} >= 4 ? $first * $first
  :                     $first * ($second // 0);

Measured memory_bytes: 28012
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		long[]A = new long[N];
		long[]B = new long[N];
		string[] str = Console.ReadLine().Split();
		string[] str2 = Console.ReadLine().Split();
		long Asum = 0;
		long Bsum = 0;
		long C = 0;
		int ct = 0;
		int[][]D = new int[N][];
		for(var i=0;i<N;i++){
			A[i] = long.Parse(str[i]);
			Asum += A[i];
			B[i] = long.Parse(str2[i]);
			Bsum += B[i];
			if(B[i]>A[i]){
				C += B[i]-A[i];
				ct++;
			}
			D[i] = new int[2]{(int)(A[i]-B[i]),i};
		}
		if(Asum>=Bsum){
			Array.Sort(D,(x,y)=>y[0]-x[0]);
			int cct = 0;
			while(C>0){
				C -= D[cct][0];
				ct++;
				if(C<=0){
					break;
				}
				cct++;
			}
          	Console.WriteLine(ct);
		} else {
          Console.WriteLine("-1");
        }
	}
}

Measured memory_bytes: 33844
#include <iostream>

using namespace std;

int main()
{
    int x{}, y{}, price{};
    cin >> x >> y;
    if (x <= 3)
    {
        price += (4 - x) * 100000;
    }
    if (y <= 3)
    {
        price += (4 - y) * 100000;
    }
    if (x + y == 2)
    {
        price += 400000;
    }
    cout << price << endl;
    return 0;
}

Measured memory_bytes: 256