akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#include <iomanip>
//cout << fixed << setprecision(20) << *** << endl;
#define rep(i,N) for(int i=0;i<(int)N;++i)
typedef long long ll;
using namespace std;
int main()
{
	ll a,b;
	cin>>a>>b;
	if(a+b==15)cout<<"+"<<endl;
	else if(a*b==15)cout<<"*"<<endl;
	else cout<<"x"<<endl;
}

Measured memory_bytes: 256
import os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m=map(int,input().split())
uf=UnionFind(n)
for i in range(m):
  a,b=map(int,input().split())
  uf.union(a-1,b-1)
ans=0
for i in range(n):
  ans=max(ans,uf.size(i))
print(ans)

Measured memory_bytes: 85092
from collections import deque
 
h , w = map(int,input().split())
cou = 0
ma = []
for i in range(h):
    kar = list(input())
    cou += kar.count("#")
    ma.append(kar)
 
 
ans = [[-1 for i in range(w)] for j in range(h)]
ans[0][0] = 1
q = deque([(0,0)])
xy = [(1,0),(-1,0),(0,1),(0,-1)]
 
while q:
    x , y = q.popleft()
    for i in range(4):
        nx = x + xy[i][0]
        ny = y + xy[i][1]
        if 0 <= nx <= h-1 and 0 <= ny <= w-1 and ans[nx][ny] == -1:
            if ma[nx][ny] == ".":
                q.append((nx,ny))
                ans[nx][ny] = ans[x][y] + 1
        if nx == h-1 and ny == w-1:
            break
 
if ans[h-1][w-1] == -1:
    print(-1)
else:
    print(h*w - cou - ans[h-1][w-1])

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

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

	if (c >= a && c <= b)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}


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

const int64_t MOD = 1e9+7;

void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

int main() {
	// your code goes here
	int n, k;
	int64_t ans = 1;
	cin >> n >> k;
	vector<int64_t> a, b, A;
	for(int i = 0; i < n; ++i){
		int64_t l;
		cin >> l;
		A.push_back(abs(l));
		if(l < 0)b.push_back(abs(l));
		else if(l > 0) a.push_back(abs(l));
	}
	
	int szn = b.size(), szp = a.size();
	
	if((szp + szn/2*2 >= k) && (k%2 == 0 || szp > 0)){
		sort(a.rbegin(), a.rend());
        sort(b.rbegin(), b.rend());
		if(k%2)ans = a[0];
		vector<int64_t> V;
		for(int i=k%2; i+1<szp; i+=2) V.push_back(a[i]*a[i+1]);
        for(int i=0; i+1<szn; i+=2) V.push_back(b[i]*b[i+1]);
        sort(V.rbegin(), V.rend());
        for(int i=0; i<k/2; i++) mul(ans, V[i] % MOD);
	}
	else{
		sort(A.begin(), A.end());
        for(int i=0; i<k; i++) mul(ans, A[i]);
        ans = (MOD-ans) % MOD;
	}
	
	cout << ans << endl;
	return 0;
}

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

ll pow5[10000];

using namespace std;
int main(){
    long long x;cin >> x;
    for(int i= -4000;i<4000;i++){
        pow5[i+4000] = (long long)(pow(i,5));
        //cout << (long long)(pow(i,5)) << endl;
    }
    for(int i=-4000;i<4000;i++){
        for(int j=-4000;j<4000;j++){
            if(pow5[i+4000]-pow5[j+4000]==x){
                cout << i << " "<< j<<endl;
                return 0;
                }
        }
    }
    return 0;
}

Measured memory_bytes: 4288
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <cstring>
#include <sstream>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;

ll power(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) {
            res = res * a;
        }
        a = a * a;
        b >>= 1;
    }
    return res;
}

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
//#endif
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    for (int i = 0; i <= n - 3; i++) {
        if (a[i] == b[i] && a[i + 1] == b[i + 1] && a[i + 2] == b[i + 2]) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}







Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const ll M = 1e9 + 7;
int si[8] = {-1,0,1,-1,1,-1,0,1};
int sj[8] = {-1,-1,-1,0,0,1,1,1};

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

  vector<int> v(s.size(),1);
  int i = 0;
  bool b = false;
  int ri , li;
  int r = 0;
  int l = 0;
  vector<int> ans(s.size(),0);
  while(true){
    if (i >= s.size()) break;
    if (b == false && s[i] == 'R') {
      i++;
      r++;
      continue;
    } else if ( b == false && s[i] == 'L'){
      ri = i - 1;
      li = i;
      i++;
      l++;
      b = true;
      continue;
    }

    if (b == true && s[i] == 'L') {
      i++;
      l++;
      continue;
    } else if ( b == true && s[i] == 'R'){
      b = false;
      i++;
    }

    ans[ri] = 1;
    ans[ri] += (r-1)/2 + l/2;
    ans[li] = 1;
    ans[li] += r/2 + (l-1)/2;
    r = 1;
    l = 0;
  }
  ans[ri] = 1;
  ans[ri] += (r-1)/2 + l/2;
  ans[li] = 1;
  ans[li] += r/2 + (l-1)/2;

  rep(i,s.size()) cout << ans[i] << endl;


  return 0;
}


Measured memory_bytes: 4264
import java.util.Scanner;

 
public class Main {
 
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		String S = sc.nextLine();
		
		if(S.equals("AAA") || S.equals("BBB")) {
			System.out.print("No");
		}else {
			System.out.print("Yes");
		}
		sc.close();
	}
	
}

Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<vector<int>> G(N);
    REP(i, 0, M) {
        int L, R;
        cin >> L >> R;
        L--;
        R--;
        G[L].push_back(R);
    }
    REP(i, 0, N) {
        sort(begin(G[i]), end(G[i]));
    }
    REP(i, 0, Q) {
        int p, q;
        cin >> p >> q;
        int ans = 0;
        p--;
        q--;
        REP(j, p, N) {
            ans += upper_bound(begin(G[j]), end(G[j]), q) - begin(G[j]);
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,K,S,T,a[55],i,j,ss,tt,b[55],m;
ll C[55][55],all,se[29][2],ans;
void dfs(int d,ll s,int v){
	if(d==m){
		b[__builtin_popcountll(s)]+=v;
		return;
	}
	dfs(d+1,s,v);
	dfs(d+1,s&se[d][0],-v);
	dfs(d+1,s&se[d][1],-v);
}
int main(){
	scanf("%d%d%d%d",&n,&K,&S,&T);
	for(i=**C=1;i<=n;++i)for(j=*C[i]=1;j<=i;++j)C[i][j]=C[i-1][j-1]+C[i-1][j];
	if((T&S)!=S){puts("0");return 0;}
	for(i=0;i<n;++i){
		scanf("%d",a+i);
		if((a[i]&S)==S && (a[i]&T)==a[i])all|=1ll<<i;
	}
	for(i=0;i<18;++i)if((S^T)>>i&1){
		for(j=0;j<n;++j)se[m][a[j]>>i&1]|=1ll<<j;
		se[m][0]&=all;se[m++][1]&=all;
	}
	dfs(0,all,1);
	for(i=1;i<=K;++i)for(j=i;j<=n;++j)ans+=b[j]*C[j][i];
	printf("%lld\n",ans);
}

Measured memory_bytes: 3720
/*
 * author :Sadik Hassan
 * 
*/
#include "bits/stdc++.h"
using namespace std;
#define ll            long long
#define nl            "\n"
#define PB            push_back
#define fi            first
#define se            second
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define rep(i,n)      for(int i=0;i<n;i++)
#define repn(i,n)     for(int i=1;i<=n;i++)
#define rrep(i,n)     for(int i=n-1;i>=0;i--)
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
#define TSFL(s)       transform(s.begin(),s.end(),s.begin(),::toupper);
#define TSFH(s)       transform(s.begin(),s.end(),s.begin(),::tolower);
/*---------------------------------------------------------------------*/
const int N = 2e5+10;
const int INF = (int)1e9+5;
const int MOD = 1e9+7;
ll vi[N];
ll nck(int n,int b)
{
	ll ans=1;
	for(int i=1;i<=b;i++)
	{
		ans=ans*(n-i+1)%MOD*vi[i]%MOD;
	}
	return ans;
}
ll powN(ll n,int p)
{
	ll r=1;
	for(;p;n=n*n%MOD,p/=2)
	{
		if(p&1)
		{
			r=r*n%MOD;
		}
	}
	return r;
}
int main()
{
    _SAD()
    vi[1]=1;
    for(int i=2;i<=2e5;i++)
    {
    	vi[i]=MOD-MOD/i*vi[MOD%i]%MOD;
    }
	int n,a,b;
	cin>>n>>a>>b;
	ll ans=powN(2,n);
	cout<<(ans+2*MOD-nck(n,a)-nck(n,b)+MOD-1)%MOD<<nl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)-1
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(b<a) { a=b; return 1; } return 0; }

int main(){
  int n; cin >> n;
  map<int,int> mp;
  rep(i,n){
    int a; cin >> a;
    mp[a]++;
  }
  int ans = INF;
  for(int i = -101; i < 101; i++){
    int res = 0;
    for(auto x : mp) res += (int)pow(x.first-i,2)*x.second;
    chmin(ans,res);
  }
  cout << ans;
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3564
import bisect

n = int(input())
s = input()
rgb = [[],[],[]]
for i in range(n):
  if s[i] == 'R':
    rgb[0].append(i)
  elif s[i] == 'G':
    rgb[1].append(i)
  else:
    rgb[2].append(i)
x = []
for i in range(3):
  x.append((len(rgb[i]),i))
x.sort()
y = []
for i in range(3):
  y.append(rgb[x[i][1]])
a = 0
for y0 in y[0]:
  for y1 in y[1]:
    b = (y0+y1)//2
    if abs(b-y0) == abs(b-y1):
      r = bisect.bisect_left(y[2],b)
      if r < len(y[2]) and y[2][r] == b:
        a += 1
    b = min(y0,y1)-abs(y0-y1)
    if b >= 0:
      r = bisect.bisect_left(y[2],b)
      if r < len(y[2]) and y[2][r] == b:
        a += 1
    b = max(y0,y1)+abs(y0-y1)
    if b < n:
      r = bisect.bisect_left(y[2],b)
      if r < len(y[2]) and y[2][r] == b:
        a += 1
print(len(y[0])*len(y[1])*len(y[2])-a)


Measured memory_bytes: 78176
n,a,b = map(int, input().split())
d = b - a
if d%2==0: ans = d//2 # AB間偶数
else: ans = min(a, n-b+1) + (d-1)//2 # 端寄せを一回多く行えば AB間が１つ詰まって偶数
print(ans)


Measured memory_bytes: 2940
#include <stdio.h>
#include <stdlib.h>

#define PI 3.14159265

struct Point {
  int _x;
  int _y;
};

typedef struct Point point;

int main(void) {
  int W, H, x, y, r;
  scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

  point p1, p2, p3, p4;
  p1._x = x - r;
  p1._y = y;
  p2._x = x + r;
  p2._y = y;
  p3._x = x;
  p3._y = y - r;
  p4._x = x;
  p4._y = y + r;

  int cnt = 0;

  if (0 <= p1._x && p1._x <= W) cnt++;
  if (0 <= p3._x && p3._x <= W) cnt++;
  if (0 <= p2._x && p2._x <= W) cnt++;
  if (0 <= p4._x && p4._x <= W) cnt++;
  if (0 <= p1._y && p1._y <= H) cnt++;
  if (0 <= p2._y && p2._y <= H) cnt++;
  if (0 <= p3._y && p3._y <= H) cnt++;
  if (0 <= p4._y && p4._y <= H) cnt++;

  if (cnt == 8) printf("Yes\n");
  else printf("No\n");

  return 0;
}



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

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main(int argc, char const *argv[]) {
	int a,b,c;
	std::cin >> a >> b >> c;
	int abcmax = max(a,max(b,c));
	if (((abcmax-a)+(abcmax-b)+(abcmax-c))%2 == 0) {
		std::cout << ((abcmax-a)+(abcmax-b)+(abcmax-c)) / 2 << '\n';
	}
	else {
		std::cout << ((abcmax-a)+(abcmax-b)+(abcmax-c)) / 2 + 2 << '\n';
	}
	return 0;
}


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

int main() {

    int N,maxans=0;
    cin>>N;
vector<vector<vector<int>>> A(N, vector<vector<int>>(15, vector<int>(2)));
    for(int i=0; i<N; i++){
      int k; cin>>k;
      for(int j=0; j<15-k; j++)A[i].pop_back();
      for(int j=0; j<k; j++){cin>>A[i][j][0]>>A[i][j][1];}}
  
  for(int i=0; i<(1<<N); i++){
    bitset<16> b(i);
    int ans=0;//cout<<b<<endl;
    for(int j=0; j<N; j++){
      for(int k=0; k<A[j].size(); k++){
        if(b[A[j][k][0]-1]!=A[j][k][1]&&b[j]==1){goto here;}   
        //if(b[A[j][k][0]-1]==A[j][k][1]&&b[j]==0){goto here;/*cout<<j<<" "<<k<<endl;*/}
        //cout<<b[j]<<" "<<b[A[j][k][0]-1]<<" "<<A[j][k][1]<<endl;
        //if(j==N-1&&k==A[j].size()-1){/*cout<<ans<<endl;*/}
     }}
    ans=b.count();
    maxans=max(maxans,ans);
    here: ans=0;}
    cout << maxans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
int main() {
//input
int a,b,c;
cin>>a>>b;
//compute
if(a<10&&b<10)c=a*b;
else c=-1;
//output
cout<<c<<endl;
	return 0;
}

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

bool prime(int n) {
	if (n < 4) {
		if (n == 2 || n == 3)return true;
		else return false;
	}
	for (int i = 2; i*i <= n; i++)
		if (n%i == 0)return false;
	return true;
}
int main() {
	int n;
	cin >> n;
	int ans = 0;
	while (n--) {
		int t;
		cin >> t;
		if (prime(t))ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
 
signed main(){
    int K,A,B;cin>>K>>A>>B;
    int bis=1;
    if(K<=A||B-A<=2)cout<<K+1<<endl;
    else{
        bis=A-1;
      	K-=(A-1-1);
      	K-=3;
      	bis=B;
      	int d=K/2;
      	bis+=d*(B-A);
      	if(K%2==1)bis++;
      	cout<<bis<<endl;
    }   
}

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

int main() {
	int n;
	int d[101];

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

	int num[101] = { 0 };
	for (int i = 0; i<n; i++) {
		num[d[i]]++;
	}
	int count = 0;
	for (int i = 0; i<101; i++) {
		if (num[i]>0)count++;
	}
	cout << count;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define mod 1000000007
#define lol 200005
#define debug(x) cout<<#x<<" is "<<x<<endl;
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=b;i>=a;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vp vector<pair<double,double>>
#define vpp vector<pair<int, pair<int,int>>>
#define pp pair<int,int>

int main()
{
   int n;
   cin>>n;
   double A[n];
   ffor(i,0,n) cin>>A[i];
   double dp[n+1][n+1];
   memset(dp,0.0,sizeof(dp));
   dp[0][0]=1.0;
   ffor(i,1,n+1)
   {
   	 ffor(j,0,i+1)
   	 {
   	 	if(j==0) //0 Number of Heads
   	 		dp[i][j]=dp[i-1][j]*(1.0-A[i-1]);
   	 	else
   	 		dp[i][j]=dp[i-1][j]*(1.0-A[i-1]) + dp[i-1][j-1]*A[i-1];
   	 }
   }
   double ans=0.0;
   ffor(i,(n+1)/2,n+1)
      ans+=dp[n][i];

    cout<<fixed<<setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 74136
#include<bits/stdc++.h>
namespace ZDY{
    #pragma GCC optimize(3)
    #define il __inline__ __attribute__ ((always_inline))
    #define rg register
    #define ll long long
    #define ull unsigned long long
    #define db double
    #define sht short
    #define MB template <class T>il
    #define Fur(i,x,y) for(int i=x;i<=y;i++)
    #define Fdr(i,x,y) for(int i=x;i>=y;i--)
    #define fl(i,x) for(int i=head[x],to;to=e[i].to,i;i=e[i].nxt)
    #define clr(x,y) memset(x,y,sizeof(x))
    #define cpy(x,y) memcpy(x,y,sizeof(x))
    #define fin(s) freopen(s".in","r",stdin)
    #define fout(s) freopen(s".out","w",stdout)
    #define fcin ios::sync_with_stdio(false)
    #define l2(n) ((int)(log2(n)))
    #define inf 0x3f3f3f3f
    MB T ABS(T x){return x>0?x:-x;}
    MB T MAX(T x,T y){return x>y?x:y;}
    MB T MIN(T x,T y){return x<y?x:y;}
    MB T GCD(T x,T y){return y?GCD(y,x%y):x;}
    MB void SWAP(T &x,T &y){T t=x;x=y;y=t;}
}using namespace ZDY;using namespace std;
namespace IO{const char* ln="\n";const int str=1<<20;struct IN{char buf[str],*s,*t;bool _;IN():s(buf),t(buf),_(0){}il char gc(){return s==t&&((t=(s=buf)+fread(buf,1,str,stdin))==s)?EOF:(*s++);}IN&operator>>(char&ch){if(_)return *this;char c;while((c=gc())!=EOF&&isspace(c));if(c==EOF)_=1;else ch=c;return *this;}IN& operator>>(char* ch){clr(ch,0);if(_)return *this;char c;while((c=gc())!=EOF&&isspace(c));if(c==EOF)return _=1,*this;*ch=c;ch++;while((c=gc())!=EOF&&!isspace(c))*ch=c,ch++;if(c==EOF)_=1;return *this;}IN& operator>>(string& ch){if(_)return *this;char c;while((c=gc())!=EOF&&isspace(c));if(c==EOF)return _=1,*this;ch+=c;while((c=gc())!=EOF&&!isspace(c))ch+=c;if(c==EOF)_=1;return *this;}template<typename T>IN&operator>>(T&x){if(_)return *this;char c=gc();bool ff=0;while(c!=EOF&&(c<'0'||c>'9'))ff^=(c=='-'),c=gc();if(c==EOF){_=1;return *this;}x=0;while(c!=EOF&&'0'<=c&&c<='9')x=(x<<3)+(x<<1)+c-48,c=gc();if(c==EOF)_=1;if(ff)x=-x;return *this;}}in;struct OUT{char buf[str],*s,*t;OUT():s(buf),t(buf+str){}~OUT(){fwrite(buf,1,s-buf,stdout);}void pt(char c){(s==t)?(fwrite(s=buf,1,str,stdout),*s++=c):(*s++=c);}OUT&operator<<(const char*s){while(*s)pt(*s++);return *this;}OUT&operator<<(char*s){while(*s)pt(*s++);return *this;}OUT&operator<<(string s){for(int i=0;s[i];i++)pt(s[i]);return *this;}template<typename T>OUT&operator<<(T x){if(!x)return pt('0'),*this;if(x<0)pt('-'),x=-x;char a[30],t=0;while(x)a[t++]=x%10,x/=10;while(t--)pt(a[t]+'0');return *this;}}out;}using namespace IO;
#define N 2222
int n,a[N];
int main(){
    in>>n;
    int ans=0;
    Fur(i,1,n)in>>a[i];
    sort(a+1,a+n+1);
    Fur(i,1,n-2){
        int x=i+2;
        Fur(j,i+1,n-1){
            while(x<=j)x++;
            while(x<n&&a[x+1]<a[i]+a[j])++x;
            if(a[x]<a[i]+a[j])ans+=(x-j);
        }
    }
    out<<ans<<ln;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int ans=0,n,k,a[1009];
    cin>>n;
    cin>>k;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]>(k-a[i]))
            ans=ans+(k-a[i])*2;
        else ans=ans+a[i]*2;
    }

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


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

using namespace std;

int main(void)
{
    int N,K;
    cin >> N;
    cin >> K;

    int num;
    vector<int> H;
    for(int i=0;i<N;i++){
        cin >> num;
        H.push_back(num);
    }

    vector<int> dp(N,0);

    dp[0]=0;
    dp[1]=abs(H[1]-H[0]);

    for(int i=2;i<N;i++){
        int begin = (i-K>0)?i-K:0;

        int min = -1;
        for(int j=begin;j<i;j++){
            int cost = dp[j]+abs(H[i]-H[j]);
            min = (cost<min || min == -1)? cost : min;
          
      //cout << cost<<" "<<dp[i-j]<<" "<<i<<" "<<j<< endl;
        }

        dp[i] = min;
      //cout <<dp[i]<<" "<<i<< endl;
    }

    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1144
//----------------------------------------------------------------------
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
//----------------------------------------------------------------------

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    int n, k; cin >> n >> k;
    int ans = 0;
    while(n>0) {
        n /= k;
        ans ++;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int e;
    while (true) {
        scanf("%d", &e); if (e == 0) break;
        int m = e;
        int vmin = -1;
        for (int z = 0; z*z*z <= e; ++z) {
            for (int y = 0; y*y+z*z*z <= e; ++y) {
                int x = e-z*z*z-y*y;
                if (m > x+y+z) m = x+y+z;
            }
        }
        cout << m << endl;
    }
}

Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll k,a,b;cin>>k>>a>>b;
  if(b<a+2){
    cout<<k+1<<endl;
    return 0;
  }
  ll ans=0;
  if(k<a+1){
    cout<<k+1<<endl;
    return 0;
  }
  ans+=b;
  k-=a+1;
  for(;;){
    if(k<2)break;
    k-=2;
    ans=ans-a+b;
  }
  if(k==1)ans++;
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, i, j, k, a[200005];
long long m;
int main(){
	scanf("%d", &n);
	for(i=1; i<=n; i++){
		scanf("%d", &a[i]);
	}
	sort(a+1, a+n+1);
	m += a[n], k = n-2;
	for(i=n-1; i>=1; i--){
		if(k) m += a[i], k--;
		if(k) m += a[i], k--;
	}
	printf("%lld\n", m);
	return 0;
}

Measured memory_bytes: 4596
#!/usr/bin/env python3

from heapq import heappush, heappop

HUGE = 10 ** 15

def main():
    n, m = map(int, input().split())
    dist_sets = [{} for i in range(n)]
    for i in range(m):
        a1, b1, c = map(int, input().split())
        dist_sets[a1 - 1][b1 - 1] = c
        dist_sets[b1 - 1][a1 - 1] = c
    shortest_path_mat = [dijkstra(i, dist_sets) for i in range(n)]
    res = 0
    for i in range(n):
        for j in dist_sets[i].keys():
            if i > j:
                continue
            if dist_sets[i][j] != HUGE and shortest_path_mat[i][j] < dist_sets[i][j]:
                res += 1
    print(res)

def dijkstra(root, dist_sets):
    # rootからの距離のリストを返す (TLE本 p302)
    n = len(dist_sets)
    sp = [(0 if i == root else HUGE) for i in range(n)]  # Shortest path from root
    color = [(2 if i == root else 0) for i in range(n)]  # 0: unknown. 1: one path is found. 2: shortest path is found
    pq = []
    heappush(pq, (sp[root], root))
    while len(pq) > 0:
        sp_i_when_queued, i = heappop(pq)
        color[i] = 2
        if sp[i] < sp_i_when_queued:
            continue
        for j in dist_sets[i].keys():
            if color[j] != 2 and sp[i] + dist_sets[i][j] < sp[j]:
                sp[j] = sp[i] + dist_sets[i][j]
                color[j] = 1
                heappush(pq, (sp[j], j))
    return sp

main()


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

using namespace std;

#define ll long long
#define vi  vector<int>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD int(1e9) + 7
#define PAI  3.1415
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i,n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

ll gcd(ll a,ll b){
  if(a < b)swap(a , b);
  if(a % b != 0) gcd(b, a%b);
  return b;
}

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a / gcd(a , b)) * b;
}

int main(){
  
  int a, b, q; cin >> a >> b >> q;
  vector<ll> s(a, 0), t(b, 0); // 神社s と 寺t の場所

  rep(i, a)
    cin >> s[i];

  rep(i, b)
    cin >> t[i];


  rep(i, q){

    ll pos; cin >> pos;
    ll ans = linf;
    vector<ll> arr(4, linf);

    auto itr_upps = upper_bound(all(s), pos);
    auto itr_lows = lower_bound(all(s), pos);
    int s_upp = itr_upps - s.begin();
    int s_low = itr_lows - s.begin();

    auto itr_uppt = upper_bound(all(t), pos);
    auto itr_lowt = lower_bound(all(t), pos);
    int t_upp = itr_uppt - t.begin();
    int t_low = itr_lowt - t.begin();

    if(s_low - 1 >= 0)
      arr[0] = s[s_low - 1];
    if(s_upp != a)
      arr[1] = s[s_upp];
    if(t_low - 1 >= 0)
      arr[2] = t[t_low - 1];     
    if(t_upp != b)
      arr[3] = t[t_upp];

    rep(k, 2){
      for(int j = 2; j < 4; j++){
        if((arr[k] < pos and arr[j] > pos) or (arr[j] < pos and arr[k] > pos)){
          chmin(ans, max(abs(arr[k] - pos), abs(arr[j] - pos)) + 2 * min(abs(arr[k] - pos), abs(arr[j] - pos)));
        }
        else{
          chmin(ans, max(abs(arr[k] - pos), abs(arr[j] - pos)));
        }
      }
    }

    pr(ans);
  }

  return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
//#define int long long
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define drep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define Maxe(x) *max_element(all(x))
#define Mine(x) *min_element(all(x))
#define Size(x) ((ll)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
#define Fi first
#define Se second
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

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

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo
//mint,dijkstra,gyakugen

    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
      ll k,x;
      cin>>k>>x;
      if(k*500>=x)cout<<"Yes"<<endl;
      else cout<<"No"<<endl;
    }

Measured memory_bytes: 256
#include <cstdio>
#include <array>
#include <bitset>
#include <string>

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

  char buf[500001];
  scanf("%s", buf);
  std::string s = buf;

  std::array<std::bitset<500000>, 26> b = {};
  for (size_t i = 0; i < n; ++i)
    b[s[i]-'a'].set(i);

  size_t q;
  scanf("%zu", &q);

  for (size_t i = 0; i < q; ++i) {
    int t;
    scanf("%d", &t);

    if (t == 1) {
      size_t j;
      char c;
      scanf("%zu %c", &j, &c);
      --j;
      b[s[j]-'a'].reset(j);
      b[c-'a'].set(j);
      s[j] = c;
    } else if (t == 2) {
      size_t l, r;
      scanf("%zu %zu", &l, &r);
      --l, --r;
      int res = 0;
      for (size_t j = 0; j < 26; ++j) {
        if (b[j][l] || b[j][r]) {
          ++res;
          continue;
        }
        b[j].set(r);
        if (b[j]._Find_next(l) < r) ++res;
        b[j].reset(r);
      }
      printf("%d\n", res);
    }
  }
}


Measured memory_bytes: 2816
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};
typedef struct {
    ll h;
    ll w;
    ll d;
} P;
ll imos[810][810] = {};
bool visit[810][810] = {};
int dist[810][810] = {};
string S[810];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H,W,K;
    cin >> H >> W >> K;
    rep(i,0,H) cin >> S[i];

    queue<P> que;
    ll dh[4] = {0,0,1,-1};
    ll dw[4] = {1,-1,0,0};
    rep(i,0,H){
        rep(j,0,W){
            dist[i][j] = -1;
        }
    }
    rep(i,0,H){
        rep(j,0,W){
            if(S[i][j] == 'S'){
                que.push((P){i, j, 0});
            }
        }
    }

    while(not que.empty()){
        P p1 = que.front();
        que.pop();
        if(visit[p1.h][p1.w]) continue;
        visit[p1.h][p1.w] = true;
        dist[p1.h][p1.w] = p1.d;
        rep(k,0,4){
            ll ah = p1.h + dh[k];
            ll aw = p1.w + dw[k];
            if(ah >= 0 && ah < H && aw >= 0 && aw < W){
                if((not visit[ah][aw]) && S[ah][aw] == '.'){
                    que.push((P){ah, aw, p1.d+1});
                }
            }
        }
    }

    ll lv = 0, rv = H*W;
    rep(i,0,H){
        rep(j,0,W){
            if(S[i][j] == '#') imos[i+1][j+1]++;
        }
    }
    rep(i,0,H+1){
        rep(j,0,W+1){
            imos[i][j+1] += imos[i][j];
        }
    }
    rep(j,0,W+1){
        rep(i,0,H+1){
            imos[i+1][j] += imos[i][j];
        } 
    }
    while(rv - lv > 1){
        ll mid = (rv + lv) / 2;
        bool ok = false;
        rep(i,0,H){
            rep(j,0,W){
                if(dist[i][j] >= 0){
                    if(dist[i][j] <= K){
                        ll kabe = 0, len = 0;
                        // up
                        if(i <= K * (mid-1)) ok = true;
                        if(H-i-1 <= K * (mid-1)) ok = true;
                        if(j <= K*(mid-1)) ok = true;
                        if(W-j-1 <= K*(mid-1)) ok = true;
                    }
                }
            }
        }

        if(ok){
            rv = mid;
        }else{
            lv = mid;
        }
    }
    print(rv);


}

Measured memory_bytes: 9344
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;

typedef long long ll;

ll fact(int x){
  ll res = 1;
  for(ll i = 2; i <= x; i++){
    res *= i;
  }
  return res;
}

int main(){
  string s;
  int cnt[128];

  while(cin >> s){
    memset(cnt, 0, sizeof(cnt));
    for(int i = 0; i < s.length(); i++){
      cnt[s[i]]++;
    }

    vector<int> v;
    int oddCnt = 0;

    for(int i = 'a'; i <= 'z'; i++){
      if(cnt[i] % 2 != 0){
        oddCnt++;
        cnt[i]--;
      }
      if(cnt[i] != 0){
        v.push_back(cnt[i] / 2);
      }
    }

    if(oddCnt > 1){
      cout << "0\n";
      continue;
    }

    ll ans = fact(s.length() / 2);

    for(int i = 0; i < (int)v.size(); i++){
      ans /= fact(v[i]);
    }

    cout << ans << endl;
  }
}

Measured memory_bytes: 0
#include <iostream>

//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

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

//math
//-------------------------------------------
template <class T>
inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

//repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0, sizeof(a))

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

int main()
{

    LL a, b, r, tmp;
    cin >> a >> b;

    LL A = a;
    LL B = b;

    if (a < b)
    {
        tmp = a;
        a = b;
        b = tmp;
    }

    r = a % b;
    while (r != 0)
    {
        a = b;
        b = r;
        r = a % b;
    }

    r = b;
    // cout << r << endl;

    LL res = 1;
    LL div = 2;
    LL upper_bound = sqrt(r);
    while (r != 1 && div <= upper_bound)
    {
        if (r % div == 0)
        {
            res++;
            r = r / div;
            while (r % div == 0)
            {
                r = r / div;
            }
        }
        div++;
        // cout << r << ' ' << div << endl;
    }

    if (r != 1)
        res++;

    cout << res << endl;
}

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) begin(v),end(v)
using ll = long long;

int main() {
  ll n;cin>>n;
  string s;
  while(n){
    n--;
    s+=(char)('a'+n%26);
    n/=26;
  }
  reverse(all(s));
  cout<<s<<endl;
}

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

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

 if (a + b == 15){
   cout << "+" << endl;
 }
 else if (a * b == 15){
   cout << "*" << endl;
 }
 else{
   cout << "x" << endl;
 }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define fi first
#define se second
using namespace std;
typedef pair<int,int> P;
#define int long long
main(){
	int a[4],n,c=3,x[4],sum=0;
	r(i,4)cin>>x[i];
	x[3]=min(x[3],min(x[2]*2,min(x[1]*4,x[0]*8)));
	x[2]=min(x[2],min(x[1]*2,x[0]*4));
	x[1]=min(x[1],x[0]*2);
	cin>>n;
	sum+=x[3]*(n/2);
	if(n%2)sum+=x[2];
	cout<<sum<<endl;
}

Measured memory_bytes: 256
def main():
    n,k = map(int,input().split())
    h = list(map(int,input().rstrip().split(' ')))

    ans = [-1]*n
    ans[0] = 0
    ans[1] = abs(h[1] - h[0])

    #candidate = [-1]*(k-1)
    
    '''
    def cost(place, step):
        if(ans[place] != -1):
            return ans[place]
        else:
            #for j in range(max(0,place - step),place):
            #    candidate[j] = ans[j] + abs(h[place] - h[j])
            ans[place] = min(abs(h[place]-h[j]) + cost(j,step) for j in range(max(0,place-k),place))
            return ans[place]
    for i in range(2,n):
        cost(i,k)
    print(ans[-1])
    '''
    '''
    for place in range(1,n-1):
        #ans[place] = min(abs(h[place+1]-h[j-1]) + ans[j] for j in range(max(0,place-k),place))
        ans[place] = min(abs(h[place+1] - h[j]) + ans[j-1] for j in range(max(0,place-k), place-1))
    print(ans)
    '''
    for i in range(2,n):
        ans[i] = min(abs(h[i] - h[j]) + ans[j] for j in range(max(0,i-k),i))
    print(ans[n-1])
main()

Measured memory_bytes: 13980
'use strict'

function main(s) {
  s = s.split('\n');

  const n = Number(s[0].split(' ')[0]);
  const m = Number(s[0].split(' ')[0]);

  const a = s.slice(1, 1 + n).map(n => n.split(' ').map(l => Number(l)));
  const c = s.slice(1 + n,-1).map(n => n.split(' ').map(l => Number(l)));

  const ans = [];

  for (let i = 0; i < a.length; i++) {
    const distList = [];
    for (let j = 0; j < c.length; j++) {
      const dist = Math.abs(a[i][0] - c[j][0]) + Math.abs(a[i][1] - c[j][1]);
      distList.push({point: j + 1, dist: dist});
    }
    distList.sort((a, b) => {
      if (a.dist < b.dist) return -1;
      if (a.dist > b.dist) return 1;
      if (a.point < b.point) return -1;
      if (a.point > b.point) return 1;
      return 0;
    });
    ans.push(distList[0].point);
  }

  console.log(ans.join('\n'));
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7752
#include "bits/stdc++.h"
using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int64_t> L(N + 1, 0);
	L.at(0) = 2;
	L.at(1) = 1;
	for (int i = 2; i < N + 1; i++)
	{
		L.at(i) = L.at(i - 1) + L.at(i - 2);
	}
	cout << L.at(N) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
int main(){
    ll n,k;
    cin >> n >> k;

    ll mod = n%k;
    cout << min(mod,abs(mod-k));

    return 0;
}

Measured memory_bytes: 3592
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Map<Integer,Integer> hash = new TreeMap<Integer,Integer>();
		for(int i=0;i<n;i++) {
			int a = sc.nextInt();
			int b =sc.nextInt();
			if(hash.containsKey(b)) {
				hash.put(b, hash.get(b)+a);
			}else {
				hash.put(b, a);
			}
		}
		long nowVal = 0;
		for(Integer key:hash.keySet()) {
			nowVal += hash.get(key);
			if(nowVal>key) {
				System.out.println("No");
				System.exit(0);
			}
		}
		System.out.println("Yes");
	}
}

Measured memory_bytes: 118596
A,B,C,D = map(int,input().split())
import fractions
cnum = B//C - (A-1)//C
dnum = B//D - (A-1)//D
cd = C*D//fractions.gcd(C,D)
cdnum = B//(cd) - (A-1)//(cd)
print((B-A+1)-cnum-dnum+cdnum)

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

int main() {
  ll n,k;
  cin >> n >> k;

  vector<ll> a(n), f(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> f[i];

  sort(a.begin(),a.end());
  sort(f.rbegin(),f.rend());

  ll ng = -1, ok = 1e12 + 1;
  while(ok - ng > 1) {
    ll mid = (ok + ng) / 2;
    ll tot = 0;

    for (int i = 0; i < n; i++) {
      ll tmpa = mid / f[i];
      if(a[i] > tmpa) {
        tot += (a[i] - tmpa);
      }
    }
    if(tot <= k) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  cout << ok << '\n';
  return 0;
}


Measured memory_bytes: 6376
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string S, T;
  cin >> S >> T;
  ll N = S.size();
  bool ok = true;
  REP(i, N) if (S[i] != T[i]) ok = false;
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#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 rrep(i,n) for(int i=((int)(n)-1);i>=0;(i)--)
#define rrep1(i,n) for(int i=((int)(n));i>0;(i)--)
#define sz(c) ((int)(c).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<int, pair<int, int> > PP;
const int MAX=1e5+10;
const ll INF=1e18+7;

int N, W, V;
ll w[MAX];
int v[MAX];
void input(){
	cin>>N>>W;
	rep1(i,N){
      cin>>w[i]>>v[i];
      V+=v[i];
  }
}

ll dp[105][MAX];
void solve(){
  	rep(i,N+1)rep(va, V+1)dp[i][va]=INF;
  	dp[0][0]=0;
	rep(i,N)rep(va,V+1){
    dp[i+1][va]=min(dp[i+1][va], dp[i][va]);
    if(va+v[i+1]<=V) dp[i+1][va+v[i+1]]=min(dp[i+1][va+v[i+1]], dp[i][va]+w[i+1]);
  }
}

void output(){
	int ans=0;
	rep(va, V+1)if(dp[N][va]<=W)ans=va;
	cout<<ans<<endl;
}

int main(){
  input();
  solve();
  output();
}

Measured memory_bytes: 80128
def solver(array):
    for index in range(1, n+1):
        if index == n:
            index = 0
        if array[index] == "S" and s[index]:
            if index == n - 1:
                if array[index-1] != array[0]:
                    return False
                else:
                    continue
            if index == 0:
                if array[-1] != array[1]:
                    return False
                else:
                    continue
            array[index + 1] = array[index - 1]
        elif array[index] == "S" and not s[index]:
            if index == n - 1:
                if array[index-1] == array[0]:
                    return False
                else:
                    continue
            if index == 0:
                if array[-1] == array[1]:
                    return False
                else:
                    continue
            if array[index - 1] == "W":
                array[index + 1] = "S"
            else:
                array[index + 1] = "W"
        elif array[index] == "W" and s[index]:
            if index == n - 1:
                if array[index-1] == array[0]:
                    return False
                else:
                    continue
            if index == 0:
                if array[-1] == array[1]:
                    return False
                else:
                    continue
            if array[index - 1] == "W":
                array[index + 1] = "S"
            else:
                array[index + 1] = "W"
        elif array[index] == "W" and not s[index]:
            if index == n - 1:
                if array[index-1] != array[0]:
                    return False
                else:
                    continue
            if index == 0:
                if array[-1] != array[1]:
                    return False
                else:
                    continue
            array[index + 1] = array[index - 1]
    return array


n = int(input())
s = [True if x == "o" else False for x in list(input())]
ws = ["W", "S"] + ["*" for x in range(n - 2)]
sw = ["S", "W"] + ["*" for x in range(n - 2)]
ss = ["S", "S"] + ["*" for x in range(n - 2)]
ww = ["W", "W"] + ["*" for x in range(n - 2)]

for array in [ws, sw, ss, ww]:
    res = solver(array)
    if not res:
        continue
    else:
        print("".join(res))
        exit()
else:
    print(-1)


Measured memory_bytes: 7964
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    
    long long a,b,c,d,ans;
    
    cin >> a >> b >> c >> d;
    
    if(a>0&&b>0){
        if(c>0&&d>0){
            cout << b*d;
        }else if(c<=0&&d>0){
            cout << b*d;
        }else{
            //c,d両方ともマイナス"
            cout << a*d;
        };
    }else if(a<=0&&b>0){
        if(c>0&&d>0){
            cout << b*d;
        }else if(c<=0&&d>0){
            if(a*c > b*d){
                cout << a*c;
            }else{
                cout << b*d;   
            }
        }else{
            //c,d両方ともマイナス"
            cout << a*c;
        };
    }else{
        //a,b両方マイナス"
         if(c>0&&d>0){
            cout << c*b;
        }else if(c<=0&&d>0){
            cout << a*c;
        }else{
            //c,d両方ともマイナス"
            cout << a*c;
        };
    }
    cout << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using mii = map<int, int>;
using mll = map<ll, ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vpi = vector<pii>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpl = vector<pll>;
using vs = vector<string>;

int main()
{
    int n, k;
    cin >> n >> k;
    vi ps(n);
    for(int i=0; i<n; i++) cin >> ps.at(i);

    vector<double> skis;
    skis.push_back(0.0);
    for(int i=0; i<n; i++)
    {
        double kitai = (ps.at(i)+1) / 2.0;
        skis.push_back(skis.at(i) + kitai);
    }

    double nax = 0;
    for(int i=1; i<=n; i++)
    {
        if(i+k-1 <= n && nax < skis.at(i+k-1) - skis.at(i-1))
        {
            nax = skis.at(i+k-1) - skis.at(i-1);
        }
    }
    cout << fixed << setprecision(7) << nax << endl;
    return 0;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int judge(int q1,int q2,int N){
    int count =0;
    int s1count;
    int s2count;
    vector<int> Junretsu(N);
    for(int i=0;i<N;i++){
        Junretsu[i]= i+1;
    }
    do {
        int nowans = 0;
        count++;
        for(int i=0;i<N;i++){
            nowans += Junretsu[i]*pow(10,N-1-i);
        }
        if(nowans == q1){
            s1count = count;
        }
        if(nowans == q2){
            s2count = count;
        }
    }while (next_permutation(Junretsu.begin(), Junretsu.end()));
    return abs(s1count-s2count);
}
int main(){
    int N,q1,q2;
    cin >> N;
    q1 = q2 = 0;
    vector<int> Sequence1(N);
    for(int i=0;i<N;i++){
        cin >> Sequence1[i];
        q1 += Sequence1[i]*pow(10,N-1-i);
    }
    vector<int> Sequence2(N);
    for(int j=0;j<N;j++){
        cin >> Sequence2[j];
        q2 += Sequence2[j]*pow(10,N-1-j);
    }
    cout << judge(q1,q2,N);
}

Measured memory_bytes: 512
import java.util.*;

public class Main {

	static long gcd(long x,long y) {
		if (x<y)gcd(y,x);
		if (y%x==0)return x;		
		return gcd(y,x%y);
	}
	
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		long a=Long.parseLong(scan.next());
		long b=Long.parseLong(scan.next());
		long c=Long.parseLong(scan.next());
		long d=Long.parseLong(scan.next());
		
		long lcm=c*d/gcd(c,d);
		
		//a未満でｃでもｂでも割れない数
		--a;
		long ans1=a/c+a/d-a/lcm;
		ans1=a-ans1;
		//b以下でｃでもｂでも割れない数		
		long ans2=b/c+b/d-b/lcm;
		ans2=b-ans2;		
	
		System.out.print(ans2-ans1);
} 	
}
//end

Measured memory_bytes: 23892