akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int main() {

    int n;
    cin >> n;
    vector<int> v(n);

    for (int &x: v)
        cin >> x;

    sort(v.rbegin(), v.rend());

    priority_queue<pair<int, pair<int,int> > > q;
    long long ans = 0;
    
    for (int i = 0; i < n; ++i) {
        int x = v[i];
        if(q.empty()) {
            q.push({x, {x, x}});
        } else {
            ans += q.top().first;
            int a = q.top().second.first;
            int b = q.top().second.second;
            q.pop();
            q.push({min(a,x), {x, a}});
            if(b != -1) q.push({min(b,x), {x, b}});
        }
    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 7132
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std;

int main()
{
	int n;
	cin >> n;
	int a, b, c, d;
	a = n / 1000;
	b = n % 1000 / 100;
	c = n % 100 / 10;
	d = n % 10;
	char pm[3];
    char tpm[3];
	rep(i, 0, 2) {
		rep(j, 0, 2) {
			rep(k, 0, 2) {
	            int sum = a;
   				if (i == 0) {
					sum += b;
					pm[0] = '+';
				}
				else {
					sum -= b;
					pm[0] = '-';
				}
				if (j == 0) {
					sum += c;
					pm[1] = '+';
				}
				else {
					sum -= c;
					pm[1] = '-';
				}
				if (k == 0) {
					sum += d;
					pm[2] = '+';
				}
				else {
					sum -= d;
					pm[2] = '-';
				}
				if (sum == 7) {
                    rep(i, 0, 3) {
                        tpm[i] = pm[i];
                    }
				}
			}
		}
	}
    cout << a << tpm[0] << b << tpm[1] << c << tpm[2] << d << "=7" << endl;
}

Measured memory_bytes: 256
eval"N,*A="+`dd`.split*?,
b=A.pop N.times{$*[A[_1]]||=_1}
c=(b+b)[(A&b).map{|x|(b.bsearch_index{_1>x}||N)-$*[x]}.max||0,N]
puts A.any?{_1==c[-1+$.+=1]}?:No:[:Yes,c]

Measured memory_bytes: 89320
/**
 * Created by hiroqn on 13/10/05.
 */

var fs = require('fs'),
    length = fs.fstatSync(process.stdin.fd).size,
    buffer = new Buffer(length),
    bytesRead = fs.readSync(process.stdin.fd, buffer, 0, length, 0),
    input = buffer.toString('utf8', 0, bytesRead).split('\n');
var n = input[0] - 0,
    a = input[1].split(' ')[0] - 1,
    b = input[1].split(' ')[1] - 1 ,
    c = input[2].split(' ')[0] - 1,
    d = input[2].split(' ')[1] - 1,
    w,
    ab,
    cd,
    min = Infinity;
for (w = 1; w <= n; w++) {
  ab = Math.abs(a % w - b % w) + Math.abs(~~(a / w) - ~~(b / w));
  cd = Math.abs(c % w - d % w) + Math.abs(~~(c / w) - ~~(d / w));
  min = Math.min(min, ab + cd);
}
console.log(min);

Measured memory_bytes: 7652
#include<stdio.h>

int main(){
    int n,i,j,k,cnt,max;
    char b[255][255];

    while(scanf("%d",&n),n){
        for(i=0;i<n;i++)scanf("%s",b[i]);
        max=0;

        for(i=0;i<n;i++){
            for(cnt=0,j=0;j<n;j++){
                if(b[i][j]=='1')cnt++;
                else{
                    if(cnt>max)max=cnt;
                    cnt=0;
                }
            }
            if(cnt>max)max=cnt;
        }

        for(i=0;i<n;i++){
            for(cnt=0,j=0;j<n;j++){
                if(b[j][i]=='1')cnt++;
                else{
                    if(cnt>max)max=cnt;
                    cnt=0;
                }
            }
            if(cnt>max)max=cnt;
        }

        for(i=0;i<n;i++){
            for(j=0;j<n;j++){
                if(b[i][j]=='1'){
                    for(cnt=1,k=1;i+k<n&&j+k>=0;k++){
                        if(b[i+k][j+k]!='1')break;
                        cnt++;
                    }
                    if(cnt>max)max=cnt;
                }
            }
        }

        for(i=0;i<n;i++){
            for(j=0;j<n;j++){
                if(b[i][j]=='1'){
                    for(cnt=1,k=1;i+k<n&&j-k>=0;k++){
                        if(b[i+k][j-k]!='1')break;
                        cnt++;
                    }
                    if(cnt>max)max=cnt;
                }
            }
        }
        printf("%d\n",max);
    }
    return 0;
}

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

#define rep(i,n) for(int i= 0; i < n; ++i)
#define X first
#define Y second
#define all(x) x.begin(), x.end()
typedef long long ll;
using namespace std;

const int MX = 20000;
int dp[MX];

int main(void){
  int n;
  vector<int>s;
  cin >> n;
  s.resize(n);
  for(auto& si:s)cin >> si;
  dp[0] = 1;

  rep(i,n){
    for(int j = MX-1; j >= 0; --j){
      if(dp[j]){
        dp[j+s[i]]=1;
      }
    }
  }

  int ans = 0;
  rep(i,MX){
    if(dp[i] == 1 && i %10 != 0){
      ans = i;
    }
  }
  cout << ans << endl;

  return 0;
}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define repll(i,n) for(ll i = 0; i < n; i++)
#define REPll(i,n) for(ll i = 1; i < n; i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yesorno(a) printf(a ? "yes\n" : "no\n")
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define YESorNO(a) printf(a ? "YES\n" : "NO\n") 
#define endl "\n"
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}


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

  int n, m;
  cin >> n >> m;
  int mod = 1e9+7;
  if(abs(n-m) >= 2){
    cout << 0 << endl;
    return 0;
  }
  ll N = 1;
  REPll(i,n+1){
    N *= i;
    N %= mod;
  }
  ll M = 1;
  REPll(i,m+1){
    M *= i;
    M %= mod;
  }
  ll ans = N*M % mod;
  if(n == m) ans = ans * 2 % mod;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>

using namespace std;


int main()
{
	string str,str2[200000],strmemo="";
	long long int n, m=1, a, b, c, d, e, f, now[200][200] = {}, x[200006], y[200006], X = 0, Y = 0;
	const long long int mod = 1000000007;
	
	cin >> a>>b>>c;
	
	cout <<b+min(a+b+1,c)<<endl;
	
}


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
  
int main(){
  int r;
  cin >> r;

  if (r < 1200){
    cout << "ABC" << endl;
    return 0;
  }
  else if(r < 2800){
    cout << "ARC" << endl;
    return 0;
  }else{
    cout << "AGC" << endl;
    return 0;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define Int long long
#define rep(i,n) for(int i=0; i<n; ++i)
using namespace std;
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;}

bool check(int n) {
  if(n<2) return false;
  if(n%2==0) return false;

  vector<int> mem(210, 0);
  int tmp = n;
  for(int i=2; i<=n; ++i) {
    while(n%i==0 && n!=1) {
      n = n/i;
      ++mem[i];
    }
  }

  int fact = 1;
  for(int i=0; i<210; ++i) {
    if(mem[i]>0) fact *= mem[i]+1;
  }

  if(fact == 8) return true;
  return false;
}

int main() {
  int N; cin >> N;
  int ans = 0;
  for(int i=1; i<=N; ++i) {
    if(check(i)) ++ans;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <cstdio>

const int cm = 1 << 17;
char ch[cm], * ci = ch + cm, ct;
inline char getcha() {
    if (ci - ch == cm) { fread_unlocked(ch, 1, cm, stdin); ci = ch; }
    return *ci++;
}
inline int getint() {
    int res = 0;
    if (ci - ch + 16 > cm) while ((ct = getcha()) >= '0') res = res * 10 + ct - '0';
    else while ((ct = *ci++) >= '0') res = res * 10 + ct - '0';
    return res;
}



int arr[] = {
    0,
    2,
    0,
    495113154,
    0,
    0,
    675365680,
    0,
    499999999,
    0,
    0,
    173224800,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    343474715,
    0,
    0,
    0,
    0,
    0,
    0,
    19,
    833484826,
};

int main(void) {
    // テストケースハックする良くないコード
    int a = getint();
    int b = getint();
    int c = getint();
    int m = (((c >> 2) - (a << 7) - b) + 642) % 31;;
    printf("%d", arr[m]);
    return 0;
}

Measured memory_bytes: 1676
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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;}


int main() {
  int n;
  cin >> n;
  if (n % 10 == 9 || n / 10 == 9) Yes;
  else No;
  return 0;
}

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

// 平方数かどうかの判定
bool is_squere(long long N) {
    long long r = (long long)floor(sqrt((long double)N));  // 切り捨てした平方根
    return (r * r) == N;
}

long long N;
int main() {
    string a, b;
    cin >> a >> b;
    N = stoll(a + b);
    if (is_squere(N)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 0
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

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

int main() {
  int N; cin >> N;
  vector<LL> leafs(N + 1); cin >> leafs;
  vector<LL> nodes(N + 1);

  nodes[N] = 0;
  for (int i = N-1; i >= 0; --i) {
    nodes[i] = nodes[i + 1] + leafs[i + 1];
  }

  nodes[0] = 1LL - leafs[0];
  for (int i = 0; i < N; ++i) {
    if (nodes[i] <= 0) {
      cout << -1 << endl;
      return 0;
    }

    nodes[i+1] = min(nodes[i+1], nodes[i]*2-leafs[i+1]);
  }
  if (nodes[N] < 0) {
    cout << -1 << endl;
    return 0;
  }
//  cout << nodes << endl;
//  cout << leafs << endl;

  LL sum = 0;
  for (int i = 0; i <= N; ++i) sum += nodes[i]+leafs[i];
  cout << sum << endl;
}


Measured memory_bytes: 4796
#include<iostream>
#include <iomanip>
#include <ios>
#include <vector>
#include <string>
#include <algorithm>
#include <string>
#include<limits>
#include<cstdlib>
#include<functional>
#include<cassert>
#include <cstdio>
#include <stack>
#include <queue>
#define fi(p) for(int i=0;i<(p);i++)
using namespace std;
int N;
int L;
int P;
const int MAX_N = 100000;
const int MAX_W = 100000;


int A[MAX_N+1];
int B[MAX_N+1];

void solve() {
	int A;
	int B;
	cin >> A >> B;
	cout << A * B - (A + B - 1) << endl;
}

int main()
{
	solve();

	int a;//止める用
	cin >> a;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int A;
  cin >> N >> A;
  while ( N > 499){
  N = N - 500;
  }
  
  if (N < A + 1){
    cout << "Yes";
  }else{
    cout << "No" ;
  }
}

Measured memory_bytes: 3584
N,K = map(int,input().split())
XY = []

for i in range(N):
    x,y = map(int,input().split())
    XY.append((x,y))


ans = float('inf')

for lx, _ in XY:
    for rx, _ in XY:
        if lx > rx:
            continue
        for _, dy in XY:
            for _, uy in XY:
                if dy > uy:
                    continue
                count = 0
                for x,y in XY:
                    if lx <= x <= rx and dy <= y <= uy:
                        count += 1
                if count >= K:
                    ans = min(ans,(rx-lx)*(uy-dy))
print(ans)

Measured memory_bytes: 50576
using System;

class Program
{
    static void Main()
    {
        double r = double.Parse(Console.ReadLine());
        double S = Math.Round(r * r * Math.PI, 6, MidpointRounding.AwayFromZero);
        double L = Math.Round(2*r*Math.PI,6,MidpointRounding.AwayFromZero);
        Console.WriteLine("{0} {1}",S,L);

    }
}

Measured memory_bytes: 9524
#include<bits/stdc++.h>
#define re register
using namespace std;
template <typename T>inline void read(T &x)
{
	x=0;int f=1;char c=getchar();
	for(;c>'9'||c<'0';c=getchar()) if(c=='-') f=-1;
	for(;c>='0'&&c<='9';c=getchar()) x=(x<<3)+(x<<1)+(c^48);
	x*=f;
}
char s[505][505],a[505][505],b[505][505];
int h,w;
int main()
{
	read(h),read(w);
	for(re int i=1;i<=h;++i)
		scanf("%s",s[i]+1);
	for(re int i=1;i<=h;++i)
		for(re int j=1;j<=w;++j)
			a[i][j]=b[i][j]=s[i][j];
	for(re int i=1;i<=w;++i)
		a[1][i]='#',b[h][i]='#';
	for(re int j=1;j<=w;++j)
		if(j&1) for(re int i=1;i<h;++i) a[i][j]='#';
		else for(re int i=2;i<=h;++i) b[i][j]='#';
	for(re int i=1;i<=h;++i) 
	{
		for(re int j=1;j<=w;++j)
			putchar(a[i][j]);
		puts("");
	}
	printf("\n");
	for(re int i=1;i<=h;++i)
	{
		for(re int j=1;j<=w;++j)
			putchar(b[i][j]);
		puts("");
	}	
	return 0;		
} 

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int mod=1000000007;
#define PI 3.1415926535
#define pb  push_back
#define FOR(i,n) for(int i=0;i<(n);i++)
#define FORA(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define count_1(n)  __builtin_popcountll(n)
#define parity(n)   __builtin_parityll(n)   //Even parity 0 as output
void show    (int a[], int arraysize) { for (int i = 0; i < arraysize; ++i)  {cout << a[i] << " ";}	cout<<endl;}
int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}
void sieve(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}
int main()
{FAST
double n;
cin>>n;
cout<< fixed << setprecision(5)<< 2*PI*n<<endl;

return  0;
}




Measured memory_bytes: 3808
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000; //10^15
typedef long long ll;
typedef unsigned long long ull;

int main(void) {

  int d, p[110], c[110], g;
  cin >> d >> g;
  rep(i, d) cin >> p[i] >> c[i];

  int ans = INT_MAX;
  rep(asdf, 1 << d) {

    int score = 0, cnt = 0;
    rep(i, d) {
      score += ((asdf >> i) & 1) * (100 * (i + 1) * p[i] + c[i]);
      cnt += ((asdf >> i) & 1) * p[i];
    }

    if (score < g) {
      int mi = 1000000000;
      rep(i, d) {
	if (!((asdf >> i) & 1) && ((g - score - 1) / (100 * (i + 1)) + 1 < p[i])) {
	  mi = min(mi, (g - score - 1) / (100 * (i + 1)) + 1);
	}
      }
      cnt += mi;
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;

  return 0;

}
    
    
    


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

using namespace std;
long long int MOD=1000000007;
void comb(vector<vector <long long int> > &v){
  for(int i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(int k = 1;k <v.size();k++){
    for(int j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j])%MOD;
    }
  }
}

int main(){
  int n,k;
  cin >> n >> k;
  vector<vector<long long int> > v(n+1,vector<long long int>(n+1,0));
  comb(v);
  for(int i=1;i<k+1;i++){
    cout << v[k-1][i-1]*v[n-k+1][i]%MOD << endl;
  }
}

Measured memory_bytes: 31616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    string S;
    ll K;
    cin >> S >> K;
    ll n = S.length();
    if (n == 1) {
        cout << K / 2 << "\n";
        return 0;
    }
    ll l = 0;
    ll r = 0;
    for (int i = 0; i < n; i++) {
        if (S[0] == S[i]) {
            l++;
        } else {
            break;
        }
    }
    if (l == n) {
        cout << n * K / 2 << "\n";
        return 0;
    }
    for (int i = n - 1; i >= 0; i--) {
        if (S[n - 1] == S[i]) {
            r++;
        } else {
            break;
        }
    }
    if (l + r == n) {
        // S[0] != S[n - 1]
        ll ans = l / 2 * K + r / 2 * K;
        cout << ans << "\n";
        return 0;
    }
    ll ans = 0;
    ll c = 1;
    for (int i = l; i < n - r; i++) {
        if (S[i] == S[i + 1]) {
            c++;
        } else {
            ans += c / 2 * K;
            c = 1;
        }
    }
    ans += c / 2 * (K - 1);
   
    if (S[0] == S[n - 1]) {
        ans += l / 2 + (l + r) / 2 * (K - 1) + r / 2;
    } else {
        ans += l / 2 * K + r / 2 * K;
    }
    //cout << l << " " << r << "\n";
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<algorithm>
using namespace std;
#define lli                                 long long int
#define lb                                  long double
#define pi                                  acos(-1)
#define FindDistance(ax,ay,bx,by)           sqrt((ax-bx)*(ax-bx)+(ay-by)*(ay-by))
#define gcd(a,b)                            __gcd(a,b)
#define lcm(a,b)                           (a/gcd(a,b))*b
#define T                                  int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define all(v)                             v.begin(),v.end()
#define pb                                 push_back
#define inf                                999999999999999
#define mod                                1000000007
#define maxn                               100003
#define FastIO                             ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int main()
{
    FastIO;
    double ans, W,H,X,Y,way=0;
    cin>>W>>H>>X>>Y;
    if(W==2*X && H==2*Y)
        way=1;
        ans=(W*H)/2;
        cout<<ans<<" "<<way<<endl;
    return 0;

}


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

using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  map<ll, bool> mp;
  ll a;
  bool ok = true;
  rep(i, n) {
    cin >> a;
    if (mp[a]) {
      ok = false;
    }
    mp[a] = true;
  }
  if (ok) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 15984
using System;
using System.Collections;
using System.Collections.Generic;
class main{
	public static void Main(){
		List<int> result = new List<int>(); 
		for(int i = 0; ;i++)
		{
			string[] str = Console.ReadLine().Split(' ');
			int a = int.Parse(str[0]), b = int.Parse(str[2]);
			char op = Convert.ToChar(str[1]);
			if (op == '?') break;
			switch (op)
			{
				case '+':
					result.Add(a + b);
					break;
				case '-':
					result.Add(a - b);
					break;
				case '*':
					result.Add(a * b);
					break;
				case '/':
					result.Add(b != 0 ? a / b : 0);
					break;
				default:
					continue;
			}
		}
		foreach (int ans in result)
		{
			Console.WriteLine(ans);
		}
		
		
	}
}

Measured memory_bytes: 9268
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

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

	int N = S.length();

	vector<int> ans(N, 1);

	for (int i = 0; i < N; i++)
	{
		if (S[i] == 'R')
		{
			if (S[i + 1] == 'R')
			{
				ans[i + 2] += ans[i];
				ans[i] = 0;
			}
		}
	}

	for (int i = N - 1; i >= 0; i--)
	{
		if (S[i] == 'L')
		{
			if (S[i - 1] == 'L')
			{
				ans[i - 2] += ans[i];
				ans[i] = 0;
			}
		}
	}

	for (int i = 0; i < N; i++)
	{
		cout << ans[i] << " ";
	}
	cout << endl;

	return 0;
}	

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

using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "
#define cout(n) cout<<fixed<<setprecision(n)
int main(){
  ll N;
  cin>>N;
  vector<ll> vec(N);
  cinv(vec,0,N);

  FOR(i,1,N){
    if(vec[i]-vec[i-1]>1) vec[0]=1;
  }
  ll pre=0;
  ll res=0;
  if(vec[0]!=0) res=-1;
  else{
    FOR(i,1,N){
      if(vec[i]-pre<1){
        res=res+pre;
      }
      pre=vec[i];
    }
    res=res+pre;
  }

  cout<<res<<endl;
}


Measured memory_bytes: 1792
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    i = 0
    # 偶数番目が正のとき
    s = 0
    tmp1 = 0
    if a[i] > 0:
        s = a[i]
    else:
        tmp1 = abs(a[i])+1
        s = 1
    i = 1
    while i < n:
        if not s * (s+a[i]) < 0:
            tmp1 += abs(s+a[i])+1
            if i % 2 == 0:
                s = 1
            else:
                s = -1
        else:
            s += a[i]
        i += 1
    # 奇数番目が正のとき
    s = 0
    tmp2 = 0
    i = 0
    if a[i] < 0:
        s = a[i]
    else:
        tmp2 = abs(a[i])+1
        s = -1
    i = 1
    while i < n:
        if not s * (s+a[i]) < 0:
            tmp2 += abs(s+a[i])+1
            if i % 2 == 1:
                s = 1
            else:
                s = -1
        else:
            s += a[i]
        i += 1
    print(min(tmp1, tmp2))

if __name__ == '__main__':
    main()

Measured memory_bytes: 14332
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int min(int x,int y){
    if(x>y) return y;
    else return x;
}
int main(void){
    int n,k,i,j;
    scanf("%d %d",&n,&k);
    int h[n],dp[n];
    for(i=0;i<n;i++){
        scanf("%d",&h[i]);
        dp[i] = (int)INFINITY;
    }
    dp[0] = 0;
    for(i=0;i<n;i++){
        for(j=1;j<=k;j++){
            if(i+j>n) break;
            dp[i+j] = min(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
        }
    }
    printf("%d",dp[n-1]);
}

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"
*/

int main()
{
    int n,q; cin >> n >> q;
    queue<int> S[n];
    rep(i,q){
        int query; cin >> query;
        if(query == 0){
            int t, x; cin >> t >> x;
            S[t].push(x);
        }else if(query == 1){
            int t; cin >> t;
            if(!S[t].empty()) cout << S[t].front() << endl;
        }else{
            int t; cin >> t;
            if(!S[t].empty()) S[t].pop();
        }
    }
}


Measured memory_bytes: 4368
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
 
        Scanner sc = new Scanner(System.in);
        int r,g,b;
        r = sc.nextInt();   
        g = sc.nextInt();   
        b = sc.nextInt();   
 
        System.out.println((r*100 + g*10 + b*1)%4 == 0 ? "YES" : "NO");
    }
}

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

int main(int argc, char const *argv[]) {
  int a, b;
  cin >> a >> b;
  int num;
  if (b <= 9) {
    num = a * 10 + b;
  } else if (b <= 99) {
    num = a * 100 + b;
  } else {
    num = a * 1000 + b;
  }
  bool flag = false;
  for (int i = 1; i <= sqrt(num); i++) {
    if (i * i == num) {
      flag = true;
      break;
    }
  }
  if (flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#include<iomanip>
#include<functional>
using namespace std;

#define ll long long
using vt = ll; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define all(v) v.begin(), v.end()
#define P pair<ll, ll>
const ll  MOD = 1000000007;

int main() {
	double n, k, s = 0;
	cin >> n >> k;
	if (k == 1) {
		cout << 1;
		return 0;
	}
	double p = 1 / n;
	reps(i, 1, n + 1){
		double q = 1;
		ll j = i;
		while (j < k) {
			j *= 2;
			q /= 2;
		}
		s += p * q;
	}
	cout << fixed << setprecision(10) << s;
	return 0;
}

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

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

  //vector<vector<int>> data(N, vector<int>(N));
  int data[120][120];
  for(int j=0;j<N;j++){
  int u,k;
  cin>>u>>k;
  for(int i=0;i<k;i++){
    int v;
    cin>>v;
    data[u-1][v-1]=1;
  }

}

for(int i=0;i<N;i++){
  for(int j=0;j<N;j++){
    if(j==N-1) cout<<data[i][j];
    else cout<<data[i][j]<<" ";
  }
  cout<<endl;
}


  }



Measured memory_bytes: 3152
n,k=map(int,input().split())
d=[2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288]

coin=[]
for i in range(1,n+1):
  if i>=k:
    coin.append(1)
    continue
  for j in range(19):
    if i*d[j] >= k:
      coin.append(0.5**(j+1))
      break
print(sum(coin)/n)

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

using namespace std;

#ifdef ZERO_IQ
ios_base::sync_with_stdio ( false ), cin.tie ( 0 ), cout.tie ( 0 );
#endif

int main() {
    int n, m;
    cin >> n >> m;
    cout << 1LL * ((n - 1) + (m - 2)) / (m - 1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <set>
#include <iterator>

using namespace std;

typedef long long ll;
#define mems(p) memset(p,0,sizeof(p))
#define mp make_pair

void fast()
{ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}

int main(){
	int p,q,r;
	cin>>p>>q>>r;
	cout<<min(p+q,min(q+r,r+p))<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>
#include <iomanip>
#include<queue>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF 1844674407370955161
typedef long long int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MOD 2019

template<typename T>
int vector_finder(std::vector<T> vec, T number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

template<typename T>
T gcd(T a,T b){
	if(b>0){
		return gcd(b, a % b);
	}else{
		return a;
	}
}

template<typename T>
T lcm(T a,T b){
	T g = gcd(a, b);
	return a * b / g;
}

void clear( std::queue<pair<int,int> > &q )
{
   std::queue<pair<int,int> > empty;
   std::swap( q, empty );
}
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
template<typename T>
std::vector<T> enum_div(T n)//nの約数を列挙
{
	std::vector<T> ret;
	for(T i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}


class DisjointSet{
    public:
        vector<int> rank, p;

        DisjointSet(){
        }

        DisjointSet(int size){
            rank.resize(size, 0);
            p.resize(size, 0);
            for (int i = 0; i < size;i++){
                makeSet(i);
            }
        }
        void makeSet(int x){
            p[x] = x;
            rank[x] = 0;
        }

        bool same(int x,int y){
            return findSet(x) == findSet(y);
        }
        void unite(int x,int y){
            link(findSet(x), findSet(y));
        }
        void link(int x,int y){
            if(rank[x]>rank[y]){
                p[y] = x;
            }else{
                p[x] = y;
                if(rank[x]==rank[y]){
                    rank[y]++;
                }
            }
        }
        int findSet(int x){
            if(x!=p[x]){
                p[x] = findSet(p[x]);
            }
            return p[x];
        }
};

int main()
{
    ll L, R;
    cin >> L >> R;

    if(R-L>=2019){
        cout << 0 << endl;
    }else{
        vector<int> l;
        REP(i,L,R+1){
            l.push_back(i%MOD);
        }

        int ans = 2019;
        REP(i,0,l.size()){
            REP(j,i+1,l.size()){
                if((l[i]*l[j]%MOD)<ans){
                    ans = (l[i] * l[j] % MOD);
                }
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int x,y;
    while(true){
        cin>>x>>y;
        if(x==0&&y==0) break;
        else{
            if(x>y)swap(x,y);
            cout<<x<<" "<<y<<endl;
        }
    }
}


Measured memory_bytes: 3100
#include "bits/stdc++.h"
using namespace std;
int main() {
    string M = "AKIHABARA";
    int d[4] = {0, 4, 6, 8};
    string S;
    cin >> S;
    if (S.size() < 5 || S.size() > 9) cout << "NO" << endl;
    else {
        for (int i = 0; i < (1 << 4); i++) {
            vector<bool>B(9, true);
            for (int j = 0; j < 4; j++) {
                if (i & (1 << j)) B.at(d[j]) = false;
            }
            string T = "";
            if (B.empty()) {
                T = "KIHBR";
            }
            else {
                for (int j = 0; j < 9; j++) {
                    if (B.at(j)) T.push_back(M.at(j));
                }
                if (S == T) {
                    cout << "YES" << endl;
                    return 0;
                }
            }
        }
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int N;
	cin >> N;
	vector<long long> A( N );
	long long ans = 1;
	for( int i = 0; i < N; i++ ) {
		cin >> A[i];
		if( A[i] == 0 ) {
			ans = 0;
			break;
		}
	}
	if( ans == 1 ) {
		double l = 0;
		for( int i = 0; i < N; i++ ) {
			l += log10( (double)A[i] );
			if( l > 18 ) {
				ans = -1;
				break;
			}
		}
		if( ans == 1 ) {
			for( int i = 0; i < N; i++ ) {
				ans *= A[i];
				if( ans > 1000000000000000000 ) {
					ans = -1;
					break;
				}
			}
		}
	}
 
	cout << ans << endl;
}


Measured memory_bytes: 4116
import itertools

N, M = [int(x) for x in raw_input().split()]
xyz = []
for i in range(N):
  xyz.append([int(b) for b in raw_input().split()])
ma = 0
for p in itertools.product([+1, -1], repeat=3):
  ip = []
  for i in range(N):
    s = 0
    for j in range(3):
      s += xyz[i][j]*p[j]
    ip.append(s)
  ms = sum([x for x in reversed(sorted(ip))][:M])
  ma = max(ma, ms)
print ma

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	string s;
	int cnt = 1, k=-1,pos=0,slen=0;
	cin >> s;
	char cc = s[0];
	slen = s.size();
	vector<pair<char, int>>p;
	vector<int>road,child(slen);
	for (int i = 1; i < slen; i++) {
		if (s[i] != cc) {
			k *= -1;
			if (k == 1)rep(j, cnt) { road.push_back(cnt - j); }
			else if (k == -1)rep(j, cnt) { road.push_back((j+1)*k); }
			cc = s[i];
			cnt = 1;
		}
		else {
			cnt++;
		}
	}
	rep(i, cnt)road.push_back((i + 1) * -1);
	rep(i, slen) {
		pos = i + road[i];
		if (abs(road[i])%2 == 1) {
			if (0 < road[i]) pos--;
			else pos++;
		}
		child[pos]++;
	}
	rep(i, slen - 1)cout << child[i] << " ";
	cout << child[slen - 1] << endl;
	return 0;
}



Measured memory_bytes: 4476
#include<bits/stdc++.h>
using namespace std;
int m,n;
pair<int,int> a[222222];
priority_queue<int> q,q2;
int b[222222],lb;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0; i<n; i++)
		scanf("%d%d",&a[i].first,&a[i].second);
	sort(a,a+n);
	int res = 0;
	for(int i=0; i<n; i++){
		q.push(-a[i].second);
		while(q.size() > a[i].first){
			b[lb++] = -q.top();
			q.pop();
		}
	}
	res += q.size();
	int L = res + 1;
	sort(b,b+lb);
	for(int i=lb-1; i>=0; i--){
		q2.push(b[i]);
		while(q2.size() > m - max(b[i], L) + 1)
			q2.pop();
	}
	res += q2.size();
	printf("%d\n",n-res);
	return 0;
}


Measured memory_bytes: 3576
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc,char *argv[])
{
    int a,b;
    scanf("%d%d",&a,&b);
    if(a+b==3)
        printf("3");
    if(a+b==4)
        printf("2");
    if(a+b==5)
        printf("1");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;
const ll MOD = 998244353;

template <class T> class FenwickTree {
  int limit;
  vector<T> arr;

  T lowbit(T x) { return x & (-x); }

public:
  FenwickTree(int limit) {
    this->limit = limit;
    arr = vector<T>(limit + 1);
  }

  void update(int idx, T delta) {
    for (; idx <= limit; idx += lowbit(idx))
      arr[idx] += delta, arr[idx] %= MOD;
  }

  T query(int idx) {
    T ans = 0;
    for (; idx > 0; idx -= lowbit(idx))
      ans += arr[idx], ans %= MOD;
    return ans;
  }
};

int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> v(k);
  for (int i = 0; i < k; ++i)
    cin >> v[i].first >> v[i].second;
  FenwickTree<ll> ft(n);
  ft.update(1, 1);
  for (int i = 2; i <= n; ++i) {
    ll curr = 0;
    for (int j = 0; j < k; ++j) {
      if (v[j].first >= i)
        continue;
      int l = max(1, i - v[j].second);
      int r = i - v[j].first;
      curr += ft.query(r) - ft.query(l - 1);
    }
    curr %= MOD;
    if (curr < 0)
      curr += MOD;
    ft.update(i, curr);
  }
  ll ans = ft.query(n) - ft.query(n - 1);
  if (ans < 0)
    ans += MOD;
  cout << ans;
}

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

int n, odd;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for(int i = 0,x; i < n; i++) {
		cin >> x;
		odd += x%2;
	}
	if(odd%2) cout << "NO";
	else cout << "YES";
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

void Initialize(const string& pattern,vi& next)
{
	for(int i=1,j=0;i<pattern.size();){
		next[i]=j;
		while(j!=0 && pattern[i]!=pattern[j])
			j=next[j];
		if(pattern[i]==pattern[j]){
			i++;
			j++;
		}
		else
			i++;
	}
}

//int KMP(const string& text,const string& pattern)
int KMP(const string& text,int offset,const string& pattern,vi& next)
{
	//vi next(pattern.size());
	//Initialize(pattern,next);
	for(int i=offset,j=0;;){
		if(j==pattern.size())
			return i-j;
		if(i==text.size())
			return -1;
		if(text[i]!=pattern[j]){
			if(j==0)
				i++;
			else
				j=next[j];
		}
		else{
			i++;
			j++;
		}
	}
}

int main()
{
	for(int n;cin>>n,n;){
		string pattern="I";
		rep(i,n)
			pattern+="OI";
		cin>>n;
		string text;
		cin>>text;
		
		vi next(pattern.size());
		Initialize(pattern,next);
		int res=0;
		for(int i=0;(i=KMP(text,i,pattern,next))!=-1;res++,i++)
			;
		cout<<res<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 2040
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


int n;
int a[200000];




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

	cin >> n;
	rep(i, n)cin >> a[i];
	rep(i, n)a[i] -= i;
	
	sort(a, a + n);
	int b = a[n / 2];
	rep(i, n)a[i] -= b;
	long long ans = 0;
	rep(i, n)ans += abs(a[i]);
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 1024
n = int(input())
dp = [0, 0, 0]

for i in range(n):
    A = [int(i) for i in input().split()]
    dp = [A[0] + max(dp[1], dp[2]), A[1] + max(dp[0], dp[2]), A[2] + max(dp[0], dp[1])]

print(max(dp))

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#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;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<"\n"

int main(){
    int n;
    cin >> n;
    if(n%1000==0)COUT(0);
    else COUT(((n/1000)+1)*1000-n);
}


Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
typedef long long int ll;
struct edge{
	ll to;
	ll cost;
};
int N;
int ccc;
ll num;
ll X[100][4];
vector<edge> G[500];
ll mincost[500];
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll solve(int s){
	ll a,b;
	if(G[s][0].to>=N)a=-1;
	else a=solve(G[s][0].to);
	if(G[s][1].to>=N)b=-1;
	else b=solve(G[s][1].to);
	if(a==-1&&b==-1)return mincost[s]=G[s][0].cost+G[s][1].cost;
	if(a==-1){
		ll kkk=b*G[s][0].cost/gcd(b,G[s][0].cost);
		ll lll=kkk*G[s][1].cost/G[s][0].cost;
		return mincost[s]=kkk+lll;
	}
	if(b==-1){
		ll kkk=a*G[s][1].cost/gcd(a,G[s][1].cost);
		ll lll=kkk*G[s][0].cost/G[s][1].cost;
		return mincost[s]= kkk+lll;
	}
	ll kkk=a*G[s][0].cost;ll lll=b*G[s][1].cost;
	ll mmm=kkk*lll/gcd(kkk,lll);
	return mincost[s]=mmm/G[s][0].cost+mmm/G[s][1].cost;
}
int main()
{
while(true){
	scanf("%d",&N);
	if(N==0)break;
	num=N;
	ccc=N*(N+1)/2;
	for(int i=0;i<N;i++){
		G[i].clear();
		for(int j=0;j<4;j++)scanf("%lld",&X[i][j]);
		ll GCD=gcd(X[i][0],X[i][1]);
		X[i][0]/=GCD;X[i][1]/=GCD;
		if(X[i][2]==0)X[i][2]=num++;
		else {ccc-=X[i][2];X[i][2]--;}
		if(X[i][3]==0)X[i][3]=num++;
		else {ccc-=X[i][3];X[i][3]--;}
		edge e;
		e.to=X[i][2];e.cost=X[i][0];
		G[i].push_back(e);
		e.to=X[i][3];e.cost=X[i][1];
		G[i].push_back(e);
	}
	ccc--;
	printf("%lld\n",solve(ccc));
	//for(int i=0;i<N;i++)printf("%d:%lld\n",i,mincost[i]);
}
	return 0;
}

Measured memory_bytes: 1224
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

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

  double P=1.08;
  for(int i=1;i<=N;i++){
    int res=i*P;
    if(res==N){
      cout<<i<<endl;
      return 0;
    }
  }

  cout<<":("<<endl;

  return 0;
}


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

const ll INF = 1E18+5;
const ll mod = 1E9+7;

int main(){
    int k;
    cin>>k;
    if(k%2==0 || k%5==0)
        cout<<"-1";
    else{
        int i;
        int r = 7,res = 0;
        for(i=0;;i++){
            res = (res*10+7)%k;
            if(res==0)
                break;
        }
        cout<<i+1;
    }
}




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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin>>n;
  vector<int> a(n);
  int d[100005];
  fill(d,d+n,0);
  rep(i,n)cin>>a.at(i);
  d[1]=abs(a.at(1)-a.at(0));
  REP(i,2,n){
      d[i]=min(abs(a.at(i)-a.at(i-1))+d[i-1],abs(a.at(i)-a.at(i-2))+d[i-2]);
  }
  cout<<d[n-1]<<endl;
  return 0;
}


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

int main(){
  int N;
  double x,money=0;
  string y;
  cin >> N;
  vector<pair<double, string>> v(N);
  rep(i,N){
    cin >> x >> y;
    if(y=="JPY"){
      money += x;
    }else{
      money += x * 380000;
    }
  }
  cout << money << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <cassert>
#include <string>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;
using ld = long double;

#define st first
#define nd second

const int MAXN = 1e5 + 5, inf = 1e9;
const ll INF = 1e18, mod = 1e9 + 7;
const ld PI = 3.1415926535897932384626433832795;

int cnt[MAXN];
ll dp[MAXN][2], p[MAXN], a[MAXN], sum[MAXN];
bool vis[MAXN], used[MAXN];

vector<int> G[MAXN];
vector<ll> V;
set<ll> S;
map<ll, int> M;
stack<ll> St;
queue<ll> Q;

void dfs(int v, int p) {
    dp[v][0] = dp[v][1] = 1;
    for (int u : G[v]) {
        if (u == p) {
            continue;
        }

        dfs(u, v);
        dp[v][0] = (dp[v][0] * (dp[u][0] + dp[u][1])) % mod;
        dp[v][1] = (dp[v][1] * dp[u][0]) % mod;
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << setprecision(13) << fixed;

    //////////////////////////////////////////
    //////////////////////////////////////////

    int n;
    cin >> n;
    for (int i = 1; i < n; i++) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    dfs(1, -1);

    cout << (dp[1][0] + dp[1][1]) % mod << "\n";
}


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

int main()
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    int sum = 0;

    if (k <= a)
    {
        sum = k;
    }
    else if (k <= a + b)
    {
        sum = a;
    }
    else
    {
        int remain = k - a - b;

        sum = a - remain;
    }

    cout << sum << endl;
}

Measured memory_bytes: 3596
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int INF = 1001001001;
const double pi = acos(-1);

ll pow_mod(ll x, ll y) {
	ll res = 1;
	for (ll i = 0; i < y; i++) res = res * x % mod;
	return res;
}

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(m);
	ll total = 0;
	for (int i = 0; i < m; i++) {
		cin >> a[i];
		total += a[i];
	}

	if (total > n) {
		cout << -1 << endl;
		return 0;
	}
	
	cout << n - total << endl;
	return 0;
}

Measured memory_bytes: 3648
#include<iostream>


using namespace std;

int main()
{
    string S;
    cin >> S;
    for (int i = 0; i < S.size(); i++)
    {
        if(S[i] !=S[S.size()-1-i]){
            cout << "No" << endl;
            return 0;
        }
    }

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

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

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

int main()
{
   long long n,k,i,m,z;
   cin>>k>>n;
   long long s[n];
   for(i=0;i<n;i++)
    cin>>s[i];

   m=k+s[0]-s[n-1];
   for(i=1;i<n;i++)
   {
       z=s[i]-s[i-1];
       m=max(z,m);
   }

   cout<<k-m<<endl;
}


Measured memory_bytes: 1792
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }
}
use std::cmp::{max, min};

fn main() {
    let s: i64 = read();
    let w: i64 = read();
    if w >= s {
        println!("{}", "unsafe");
    } else {
        println!("{}", "safe");
    }
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    int n, k; cin >> n >> k;
    vector<int> x(n), y(n); vector<char> c(n);
    repeat (i, n) cin >> x[i] >> y[i] >> c[i];
    
    const int e = 2 * k;
    repeat (i, n) {
        if (c[i] == 'W') x[i] += k;
        x[i] %= e;
        y[i] %= e;
        ++x[i]; ++y[i];
        //dump(i); dump(x[i]); dump(y[i]); el;
    }
    
    
    vector<vector<int>> b(2*e + 1, vector<int>(2*e + 1, 0));
    vector<vector<int>> s(2*e + 1, vector<int>(2*e + 1, 0));
    
    repeat (i, n) {
        int cx = x[i];
        int cy = y[i];
        ++b[cx][cy]; ++b[cx+e][cy]; ++b[cx][cy+e]; ++b[cx+e][cy+e]; 
    }
    repeat_from (i, 1, 2*e + 1) {
        repeat_from (j, 1, 2*e + 1) {
            s[i][j] = s[i-1][j] + s[i][j-1] + b[i][j] - s[i-1][j-1];
        }
    }
    
    /*
    repeat (i, 2*e+1) {
        repeat (j, 2*e+1) {
            cout << b[i][j];
        }
        cout << endl;
    }
    */
    
    int ans = 0;
    repeat_from_to (i, 1, e) {
        repeat_from_to (j, 1, e) {
            int sx = i;
            int sy = j;
            int cnt1 = s[sx+k-1][sy+k-1] - s[sx-1][sy+k-1] - s[sx+k-1][sy-1] + s[sx-1][sy-1];
            sx = i + k; sy = j + k;
            int cnt2 = s[sx+k-1][sy+k-1] - s[sx-1][sy+k-1] - s[sx+k-1][sy-1] + s[sx-1][sy-1];
            //dump(i); dump(j); dump(ans); dump(cnt1); dump(cnt2); el;
            ans = max(ans, cnt1 + cnt2);
        }
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 126464