akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class T>
struct rbtree: tree<T,null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>{};
#define IN freopen("in.txt", "r", stdin);
#define endl '\n'
#define mp make_pair
#define pb push_back
#define lowb lower_bound
#define eb emplace_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define mem0(a) memset((a), 0, sizeof(a))
#define mem(a, b) memset((a), (b), sizeof(a))
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 0x3f3f3f3f;

const int N = 2e5+10;

int a[N];

int main(){
    IOS;
    int n; cin>>n;
    for(int i = 1; i <= n; i++)cin>>a[i];
    int cnt=1;
    for(int i = 1; i <= n; i++){
        if(a[i] == cnt){
            cnt++;
        }
    }
    if(cnt==1)cout<<-1;
    else cout<<n-cnt+1;


    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define pb push_back
#define pll pair<ll,ll> 
#define mll map<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0; i<n; i++)
#define All(x,v) for(auto x:v)
#define arrin(a,n) ll a[n]; rep(i,n) cin>>a[i]
#define vi vector<int>
#define nl "\n"
#define print(arr) All(x,arr) cout<<x<<" "; cout<<nl
#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define ing(m,ad) rep(i,m){ int u,v; cin>>u>>v; u--;v--; ad[u].pb(v); ad[v].pb(u);}
#define vdsort(v) sort(v.begin(),v.end(),greater<int>())
#define F first
#define S second
#define mod 1000000007
const int MAXN=100005;
int spf[MAXN];
ll fac1[MAXN],fac2[MAXN],inv[MAXN];
ll gcd(ll x, ll y){ return y?gcd(y,x%y):x; }

void sieve(){  
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++)  spf[i] = i; 
    for (int i=4; i<MAXN; i+=2) spf[i] = 2; 
    for (int i=3; i*i<MAXN; i++) { 
        if (spf[i] == i) 
            for (int j=i*i; j<MAXN; j+=i) 
                if (spf[j]==j)  spf[j] = i; 
    } 
} 
vector<int> getFactorization(int x){
    vector<int> ret; 
    while (x != 1) { 
        ret.push_back(spf[x]); 
        x = x / spf[x]; 
    } 
    return ret; 
}

ll exp(ll n, ll m){
    ll a = 1;
    while (m){
        if (m & 1) a = (a * n % mod) % mod;
        m /= 2;
        n = (n*n) % mod;
    }
    return a;
}

void pre(){
    fac1[0]=fac2[0]=inv[1]=1;
    for(int i=1;i<MAXN;i++){
        fac1[i]=(fac1[i-1]*i)%mod;
        if(i>1) inv[i]=( mod - ((ll)(mod/i)*inv[mod%i])%mod ) %mod;
    }
    for(int i=1;i<MAXN;i++) fac2[i]=(fac2[i-1]*inv[i])%mod;
}
ll C(int n,int k){
    if(n<k) return 0;
    return ((fac1[n]*fac2[n-k]%mod)*fac2[k]%mod);
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    int t=1;
    // cin>>t;
    while(t--){
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
        ll ans=max(a*c,max(a*d,max(b*c,b*d)));
        cout<<ans<<nl;
    }
    return 0;
}

Measured memory_bytes: 3200
#include <iomanip>
#include <iostream>
#include <limits>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main()
{
    int n, W;
    cin >> n >> W;
    const int maxV = 100001;
    vector<vector<int>> dp(n + 1, vector<int>(maxV + 1, int(1e9 + 10)));
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        int w, v;
        cin >> w >> v;
        for (int j = 0; j <= maxV; j++) {
            if (j < v) {
                dp[i + 1][j] = dp[i][j];
            } else {
                dp[i + 1][j] = min(dp[i][j - v] + w, dp[i][j]);
            }
        }
    }
    int ans = 0;
    for (int i = 0; i <= maxV; i++) {
        if (dp[n][i] <= W) { ans = i; }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 40192
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})
#define rep(i, a, b) for(int i = (a); (i) < (b); ++(i))
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) static_cast<int>(x.size())
#define mp make_pair
#define fi first
#define se second

using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio(false); cin.tie(nullptr); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod(ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b & 1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}

template<typename T> inline void remin(T& x, const T& y) { x = min(x, y); }
template<typename T> inline void remax(T& x, const T& y) { x = max(x, y); }

template<typename T> ostream& operator<<(ostream &os, const vector<T>& v) {
    os << "{"; string sep; for(const auto& x : v) os << sep << x, sep = ", "; return os << "}"; 
}

template<typename T, size_t size> ostream& operator<<(ostream& os, const array<T, size>& arr) {
    os << "{"; string sep; for(const auto& x : arr) os << sep << x, sep = ", "; return os << "}"; 
}

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { 
    return os << '(' << p.first << ", " << p.second << ')'; 
}

int main() {
    buff();
    int x;
    cin >> x;
    cout << !x << endl;
}



Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define gc getchar
using namespace std;
/*inline int read(){
	char c=gc();int x=0,y=1;while(c<'0'||c>'9'){if(c=='-') y=-1;c=gc();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+c-'0',c=gc();return x*y;
}*/
inline ll read(){
	char c=gc();ll x=0,y=1;while(c<'0'||c>'9'){if(c=='-') y=-1;c=gc();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+c-'0',c=gc();return x*y;
}

ll n,a,b;

int main(){
	//freopen("xxx.in","r",stdin);
	//freopen("xxx.out","w",stdout);
	n=read();a=read();b=read();
	if(abs(a-b)&1){
		if(a>b) swap(a,b);
		printf("%lld\n",min((b-a>>1)+a,(b-a-1>>1)+n-b+1));
	}
	else printf("%lld\n",abs(a-b)>>1);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#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 fs first
#define sc second
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)

int main(){
  int n;
  cin>>n;
  vector<long long>a(n+5);
  a[0]=2; a[1]=1;
  for(int i=2;i<=n;i++) a[i]=a[i-2]+a[i-1];
  cout<<a[n]<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {
    string o,e;
    cin >> o >> e;
    rep(i,min(o.length(),e.length()))cout << o[i] << e[i];
    if(o.length() - e.length() == 0){
        cout << "\n";
        return 0;
    }
    if(o.length() > e.length())cout << o[o.length()-1] << endl;
    else cout << e[e.length()-1] << endl;
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
import math
a,b,C = map(float,input().split())
print('{:.8f}'.format(a*b/2*math.sin(math.radians(C))))
print('{:.8f}'.format(a+b+(a**2+b**2-2*a*b*math.cos(math.radians(C)))**0.5))
print('{:.8f}'.format(b*math.sin(math.radians(C))))



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

#define ll long long



int main(){

    int N;
    cin >> N;
    ll ans = 0;
    for(int i=1;i<=N;i++){
        ll c = N/i;
        ans += c*(c+1)/2*i;
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 3612
#include<iostream>
using namespace std;
int main() {
    int h, w;
    cin >> h >> w;
    char a[101][101];
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            cin >> a[i][j];
        }
    }
    int cnt = 0;
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            if (a[i][j] == '.') {
                cnt++;
            }
        }
        if (cnt == w) {
            for (int j = 1; j <= w; j++) {
                a[i][j] = '+';
            }
        }
        cnt = 0;
    }
    for (int j = 1; j <= w; j++) {
        for (int i = 1; i <= h; i++) {
            if (a[i][j] == '.' || a[i][j] == '+') {
                cnt++;
            }
        }
        if (cnt == h) {
            for (int i = 1; i <= h; i++) {
                a[i][j] = '+';
            }
        }
        cnt = 0;
    }
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            if (a[i][j] != '+') {
                cout << a[i][j];
            }
        }
        cout << endl;
    }
}



Measured memory_bytes: 256
#include <stdio.h>

#define  N    150
#define INF   100000
#define NIL   -1
#define WHITE 1
#define BLACK 0


void prim(void);

int str[N][N];
int n;

int main(){

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

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

  prim();

  return 0;
}

void prim(void){

  int i;
  int u;
  int v;
  int min;
  int ans = 0;
  int color[N];
  int pi[N];
  int d[N];
  
  for(u=1;u<=n;u++){
       d[u] = INF;
      pi[u] = NIL;
   color[u] = WHITE;
  }
  
  d[1] = 0;

  while(1){

  min = INF;

  for(i=1;i<=n;i++){
    if(color[i]!=BLACK && d[i] < min){
    min = d[i];
    u = i;
    }
   }
    if(min==INF) break;
    color[u] = BLACK;
  
  for(v=1;v<=n;v++){
    if(color[v]!=BLACK && str[u][v] < d[v] && str[u][v]!=-1){
     pi[v] = u;
     d[v] = str[u][v];
    }
   }
  }

  for(i=1;i<=n;i++){
   ans += d[i];
   }

  printf("%d\n",ans);
  
}

Measured memory_bytes: 660
using System;

namespace ABC173_B
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine().Trim());
            int[] C = { 0, 0, 0, 0 };
            for(int i = 0; i < N; i++)
            {
                string S = Console.ReadLine().Trim();
                if(S == "AC")
                {
                    C[0]++;
                }else if(S == "WA")
                {
                    C[1]++;
                }else if(S == "TLE")
                {
                    C[2]++;
                }else if(S == "RE")
                {
                    C[3]++;
                }
            }
            Console.WriteLine("AC x "+ C[0]);
            Console.WriteLine("WA x " + C[1]);
            Console.WriteLine("TLE x " + C[2]);
            Console.WriteLine("RE x " + C[3]);
        }
    }
}

Measured memory_bytes: 30708
#include<bits/stdc++.h>
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y)
#define maxn 300010
#define ll long long int
#define inf 1000002014
#define infl 1000000000000020000ll
#define mod 1000000007
#define pi pair<int,int >
#define sz(x) (int) x.size()
using namespace std;
vector<pi>sortt;
int BIT[maxn/3];
int ans[maxn/3];
pi ord[maxn];
void update(int x,int y)
{
    while(x<=100000)
    {
        BIT[x]+=y;
        x+= x & -x;
    }
}
int query(int x)
{
    int ret = 0;
    while(x > 0)
    {
        ret+=BIT[x];
        x-= x & -x;                     
    }
    return ret;
}
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n,m,l,r;
    sd2(n,m);
    for (int i = 0; i < n; ++i)
    {
        sd2(l,r);
        ord[i].F = l;
        ord[i].S = r;
        int len = r-l+1;
        sortt.pb(mp(len,i));
    }
    sort(sortt.begin(), sortt.end());
    int prev = -1;
    for (int i = 1; i <= m; ++i)
    {
        int idx = lower_bound(sortt.begin(),sortt.end(),mp(i,0))-sortt.begin();
        ans[i]+=n-idx;
        idx--;
        for (int j = prev+1; j <= idx; ++j)
        {
        	update(ord[sortt[j].S].F,1);
            update(ord[sortt[j].S].S+1,-1);
        }
        prev = idx;
        for(int j=i;j<=100000;j+=i)
        	ans[i]+=query(j);
        printf("%d\n",ans[i]);
    }

    return 0;
}

Measured memory_bytes: 6512
//ΔAGC022C
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 55;
int n,a[N],b[N],c[N];
int f(int x,int y,LL s){
	int i,j;
	memset(c,0,sizeof(c));
	c[x]=1;
	for(i=50;i;i=i-1)
		if(s&((LL)1<<i))
			for(j=i;j<=50;j=j+1)
				c[j%i]|=c[j];
	return c[y];
}
int g(LL s){
	int i;
	for(i=1;i<=n;i=i+1)
		if(!f(a[i],b[i],s))
			return 0;
	return 1;
}
int main()
{
	int i;
	LL l,r,m;
	cin>>n;
	for(i=1;i<=n;i=i+1)
		cin>>a[i];
	for(i=1;i<=n;i=i+1)
		cin>>b[i];
	l=0,r=(LL)1<<51;
	if(!g(r-1)){
		cout<<-1;
		return 0;
	}
	while(r-l>2){
		m=l+r>>1;
		if(g(m-1))
			r=m;
		else
			l=m;
	}
	cout<<l;
	return 0;
}

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

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) //vec.size()がnの時等の高速化
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define vint vector<int>
#define vvint vector<vector<int>>

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 gcd(int a,int b){return b?gcd(b,a%b):a;}


int main(){
  int k,ans; cin >> k;
  if(k%2==0) ans = (k/2)*(k/2);
  else ans = ((k/2)+1)*(k/2);
  cout << ans << endl;

  return 0;
}


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

const int MXN=305;

int n;
int ok[MXN][MXN][MXN];
double memo[MXN][MXN][MXN];

double dp(int a,int b,int c){
  if(!a&&!b&&!c)return 0;
  if(ok[a][b][c])return memo[a][b][c];
  ok[a][b][c]=1;
  double ret=n;
  if(a)ret+=dp(a-1,b,c)*a;
  if(b)ret+=dp(a+1,b-1,c)*b;
  if(c)ret+=dp(a,b+1,c-1)*c;
  return memo[a][b][c]=ret/(a+b+c);
}

int main(){
  scanf("%d",&n);
  int cnt[3]={};
  for(int i=0,a;i<n;++i){
    scanf("%d",&a);
    cnt[a-1]++;
  }
  printf("%.12lf\n",dp(cnt[0],cnt[1],cnt[2]));
}


Measured memory_bytes: 329984
def main():
    N, *s = map(int, open(0).read().split())
    ans = sum(s)
    if not ans % 10:
        s.sort()
        for si in s:
            tmp = ans - si
            if tmp % 10:
                ans -= si
                break
        else:
            ans = 0
    print(ans)
    return


main()


Measured memory_bytes: 2940
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
using namespace std;
const long long INF = 0x3f3f3f3f3f;

int main() {
	long long Ans = INF;
	long long w, h;
	scanf("%lld %lld", &w, &h);
	for(int i = 1; i < h; ++i) {
		long long s1 = w*i, s2 = w*(h-i);
		long long s3 = w/2*(h-i);
		long long s4 = s2 - s3;
		if(s1 <= s3) {
			Ans = min(Ans, s4-s1);
		}
		else if(s1 > s3 && s1 < s4){
			Ans = min(Ans, s4 - s3);
		}
		else {
			Ans = min(Ans, s1-s3);
		}

		if(h - i > 1) {
			s3 = (h-i)/2*w;
			s4 = s2 - s3;
			if(s1 <= s3) {
				Ans = min(Ans, s4-s1);
			}
			else if(s1 > s3 && s1 < s4){
				Ans = min(Ans, s4 - s3);
			}
			else {
				Ans = min(Ans, s1-s3);
			}
		}
	}

	for(int i = 1; i < w; ++i) {
		long long s1 = h*i, s2 = h*(w-i);
		long long s3 = h/2*(w-i);
		long long s4 = s2 - s3;
		if(s1 <= s3) {
			Ans = min(Ans, s4-s1);
		}
		else if(s1 > s3 && s1 < s4){
			Ans = min(Ans, s4 - s3);
		}
		else {
			Ans = min(Ans, s1-s3);
		}

		if(w - i > 1) {
			s3 = (w-i)/2*h;
			s4 = s2 - s3;
			if(s1 <= s3) {
				Ans = min(Ans, s4-s1);
			}
			else if(s1 > s3 && s1 < s4){
				Ans = min(Ans, s4 - s3);
			}
			else {
				Ans = min(Ans, s1-s3);
			}
		}
	}
	printf("%lld\n", Ans);
	return 0;
}

Measured memory_bytes: 256
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()
N=int(input())
#N=10**18

lst=defaultdict(int)

for i in list(range(2,int(N**.5)+100)):
    while N>1 and N%i==0:
        N//=i
        lst[i]+=1
c=0
if N!=1:
    lst[N]+=1
#print(lst)
for s in lst:
    l=lst[s]
    i=1
    while l>=i:
        l-=i
        c+=1
        i+=1
print(c)


Measured memory_bytes: 81308
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <map>
#include <functional>
#include <cmath>
#include <cstdio>
using namespace std;

int n, m;
int a[10000];
int b[10000];

int main(){
  while(cin >> n >> m, n || m){
    bool I[500][500] = {}, ans[500] = {};
    int cnt = 0;
    for(int i = 0; i < m; i++){
      cin >> a[i] >> b[i];
      a[i]--;b[i]--;
      I[a[i]][b[i]] = true;
      I[b[i]][a[i]] = true;
    }
    for(int i = 1; i < n; i++){
      if(I[0][i] == true){
        ans[i] = true;
        for(int j = 1; j < n; j++){
          if(I[i][j]){
            ans[j] = true;
          }
        }
      }
    }
    for(int i = 0; i < n; i++){
      if(ans[i])cnt++;
    }
    cout << cnt << endl;
  }
}

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

int a[105];

int main() {
  int n; cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; i++) cin >> a[i], ans += a[i];
  int maxsaving = -1000000000;
  int m; cin >> m;
  for (int i = 1; i <= m; i++) {
    int p, q; cin >> p >> q;
    cout << (ans + q - a[p]) << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (1E9+7)
#define PI 3.1415926535897932384

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int main() {
	string s;
	cin >> s;
	cout << (s[0] == s[2] ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
// Problem : A - Study Scheduling
// Contest : AtCoder - NOMURA Programming Competition 2020
// URL : https://atcoder.jp/contests/nomura2020/tasks/nomura2020_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;	

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const ll maxN = 1e6 + 5;
const ll MOD = 1e9 + 7;

// sprawdz MODULO!
int main() {
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	int ile1 = h1 * 60 + m1;
	int ile2 = h2 * 60 + m2;
	//cout << ile2 << " "
	if (ile2 - ile1 >= k) {
		cout << (ile2 - ile1 - k);
	} else {
		cout << 0;
	}
	return 0;
}
 


Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
int n,h[100005],dp[100005];
int solve(int idx){
    if(idx > n - 1)
        return 1e9;
    if(idx == n - 1)
        return 0;
    int &ans = dp[idx];
    if(ans != -1)
        return ans;
    ans = 1e9;
    ans = min(ans, abs(h[idx] - h[idx + 1]) + solve(idx + 1));
    ans = min(ans, abs(h[idx] - h[idx + 2]) + solve(idx + 2));
    return ans;
}
int main()
{
    ios::sync_with_stdio(0);
    memset(dp , -1 ,sizeof dp);
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> h[i];
    cout << solve(0) << endl;
}
	

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

int main() {
  int a, b, c, x, y;
  cin >>a >> b >> c >> x >> y;
  int sum = 0;
  int num1 = min(x, y);
  int price1 = min((a+b), c*2);
  sum += price1 * num1;

  int price2 = x < y ? b : a;
  price2 = price2 < c*2 ? price2 : c*2;
  int num2 = max(x, y) - min(x, y);
  sum += price2*num2;

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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
string alphabet = "abcdefghijklmnopqrstuvwxyz";
string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(){
 string s;
 cin >> s;
 for(int i = 0;i < 3;i++){
     if(s[i] == '1')s[i] = '9';
     else if(s[i] == '9')s[i] = '1';
 }
 cout << s << endl;
}

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

using namespace std;
int main()
{
	int n, temp, ans;
	string s, x, y, all[26] = { "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z" };

	ans = 0;
	cin >> n;
	cin >> s;
	for (int i = 1; i < n; i++) {
		temp = 0;
		x = s.substr(0, i);
		y = s.substr(i, n - i);

		for (int j = 0; j < 26; j++) {
			if (x.find(all[j]) != std::string::npos && y.find(all[j]) != std::string::npos) {
				temp += 1;
			}
		}
		if (ans < temp)ans = temp;
	}
	// 出力
	cout << ans;

	return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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

using ll = long long;

ll N;
ll a[100010];
ll mi = 1ll<<60, ma = 0;

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

  rep( i, N )
  {
    std::cin >> a[i];
    chmin( mi, a[i] );
    chmax( ma, a[i] );
  }

  ll cnt = 0;

  rep( i, N )
    cnt += a[i] == ma;

  if( ma == mi && (mi == N-1 || 2*mi <= N) )
  {
    std::cout << "Yes" << std::endl;

    return 0;
  }

  ll x = N-cnt, y = cnt;
  ll A = ma;

  std::cout << (x < A && 2*(A-x) <= y && ma-mi == 1 ? "Yes" : "No") << std::endl;

  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define fr(i,n) for(i=0;i<n;i++)
#define F first
#define S second
#define fast std::ios_base::sync_with_stdio(false)
#define mod 1000000007
#define pi 3.14159265
int main() {
    fast;
    string s;
    cin>>s;
    lli i,sum=0;
    fr(i,s.length())
    {
        sum+=(s[i]-'0');
        sum%=9;
    }
    if(sum%9==0)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    
    return 0;
}

Measured memory_bytes: 3724
#include <stdio.h>

int main(){
	int a=0,b=0,i,F;
		
	while(scanf("%d%d",&a,&b)!=EOF){
	F=1;
	if ((a+b)/10>=1) F=2;
	if ((a+b)/100>=1) F=3;
	if ((a+b)/1000>=1) F=4;
	if ((a+b)/10000>=1) F=5;
	if ((a+b)/100000>=1) F=6;
	if ((a+b)/1000000>=1) F=7;
	
	printf("%d\n",F);
	}
	return 0;
}

Measured memory_bytes: 600
# 入力
K, A, B = map(int, input().split())

# 貪欲的にビスケットの枚数を最大化する
n = max(0, (K - A + 1))
ans = (
     min(K, A) + (B - A) * (n // 2) + n % 2 if B >= A + 3 else
     K + 1
)

# 出力
print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
 
int n, m, i, j, k;
typedef long long ll;
 
ll ans; 
 
inline ll qp3(ll a) {
  return 1ll * a * a * a;  
}
 
int main() {
  scanf("%d %d", &n, &k);
  int x = n / k;  
  ans = qp3(x);
  if (!(k & 1)) {
    x += (n % k) >= (k / 2);  
    ans += qp3(x);
  }
  printf("%lld\n", ans);
  return 0;       
}

Measured memory_bytes: 3736
var
 n,a,b,s,p,i:longint;
 sum:int64;
 y:string;
begin
 readln(n,a,b);
 while s<n do
  begin
   inc(s);
   str(s,y);
   p:=0;
   for i:=1 to length(y) do
    p:=p+ord(y[i])-48;
   if (p>=a) and (p<=b) then
    sum:=sum+s;
  end;
 writeln(sum);
end.

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;
using boost::sort;
using boost::adaptors::reversed;

int main() {
    int n;
    cin >> n;
    list<int> b;
    for (int i = 0; i < n; i++) {
        int bi;
        cin >> bi;
        b.push_front(bi);
    }

    deque<int> ans;
    while (n) {
        int i = n--;
        bool erased = false;
        for (auto it = b.begin(); it != b.end(); it++, i--) {
            if (*it == i) {
                b.erase(it);
                ans.push_front(i);
                erased = true;
                break;
            }
        }
        if (!erased) {
            ans.clear();
            ans.push_front(-1);
            break;
        }
    }

    for (int a : ans) cout << a << endl;
}


Measured memory_bytes: 256
s=input()
n=len(s)
t=n-1
for i in range(n):
    if t>=4 and s[t-4:t+1]=="dream":
        t-=5
    elif t>=6 and s[t-6:t+1]=="dreamer":
        t-=7
    elif t>=4 and s[t-4:t+1]=="erase":
        t-=5
    elif t>=5 and s[t-5:t+1]=="eraser":
        t-=6
    else:
        break
    if t<0:
        break
if t==-1:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 9196
// 

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <stack>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;

int main(){
  long long n, h, w;
  int cnt = 0;
  cin >> n >> h >> w;
  for(long long i = 0; i < n; i++){
    long long a, b;
    cin >> a >> b;
    if(a >= h && b >= w) cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int w = sc.nextInt();
        int h = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int r = sc.nextInt();

        if (x + r > w || y + r > h || x - r < 0 || y - r < 0) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }

    }

}


Measured memory_bytes: 26268
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
    ll n,m;
    cin >> n>>m;
    vector<pair<ll,ll>> student(n);
    vector<pair<ll,ll>> check(m);
    rep(i,0,n){
        cin >> student[i].first;
        cin >> student[i].second;
    }
    rep(i,0,m){
        cin>>check[i].first;
        cin>>check[i].second;
    }
    vector<int> ans(n);
    //cout<<check[0].first<<endl;
    rep(i,0,n){
        ll k = 1000000000;
        rep(j,0,m){
            ll now = abs(student[i].first-check[j].first)+abs(student[i].second-check[j].second);
            if(now<k){
                k = now;
                ans[i]=j;
                
            }
        }
    }
    rep(i,0,n){
        cout<<ans[i]+1<<endl;
    }
  return 0;
}

Measured memory_bytes: 3636
n, x = map(int, input().split())
a = list(map(int, input().split()))
counter = 0
pointer = 1
if a[0] > x:
    counter += a[0] - x
    a[0] = x
while pointer <= n - 1:
    if a[pointer - 1] + a[pointer] > x:
        eat = a[pointer - 1] + a[pointer] - x
        counter += eat
        a[pointer] -= eat
    pointer += 1
print(counter)


Measured memory_bytes: 14152
n, q = gets.split.map(&:to_i)
words = (1..n).map { gets.chomp }.sort
index1 = {}
(0..n-1).each do |i|
  index1[words[i]] = i
end
reversed = words.map(&:reverse).sort
index2 = {}
(0..n-1).each do |i|
  index2[reversed[i].reverse] = i
end

l = Math.sqrt(n).ceil
buckets = Array.new(l).map { Array.new(l).map { Array.new } }
words.each do |word|
  i = index1[word]
  j = index2[word]
  buckets[i / l][j / l] << [i, j]
end

q.times do
  prefix, suffix = gets.chomp.split(" ")
  suffix.reverse!
  i1 = (0..n-1).bsearch {|i| words[i] >= prefix }
  if i1 == nil or words[i1] !~ /^#{prefix}/
    puts 0
    next
  end
  prefix = prefix[0..-2] + (prefix[-1..-1].ord + 1).chr
  i2 = (i1..n-1).bsearch {|i| words[i] >= prefix }
  i2 = i2 ? i2 - 1 : n - 1
  j1 = (0..n-1).bsearch {|j| reversed[j] >= suffix }
  if j1 == nil or reversed[j1] !~ /^#{suffix}/
    puts 0
    next
  end
  suffix = suffix[0..-2] + (suffix[-1..-1].ord + 1).chr
  j2 = (j1..n-1).bsearch {|j| reversed[j] >= suffix }
  j2 = j2 ? j2 - 1 : n - 1
  answer = 0
  (i1/l..i2/l).each do |x|
    (j1/l..j2/l).each do |y|
      buckets[x][y].each do |u, v|
        answer += 1 if i1 <= u && u <= i2 && j1 <= v && v <= j2
      end
    end
  end
  p answer
end


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

#define rep(i,n) for(ll i=0;i<(n);++i)
#define reps(i,n) for(ll i=1;i<=(n);++i)
using ll = long long;
using str = string;
constexpr long long INF = (1LL<<60);
constexpr long long MOD = (1e9+7);
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
inline void dump(){cout<<endl;}
template<class Head,class... Tail>inline void dump(Head&& head, Tail&&... tail){cout<<head<<", ";dump(forward<Tail>(tail)...);}
template<typename T>inline istream &operator>>(istream&input,vector<T>&v){for(auto &elemnt:v)input>>elemnt;return input;}

main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout<<fixed<<setprecision(10);
  
  ll n,m;
  cin>>n>>m;
  vector<ll> a(n);
  cin>>a;

  priority_queue<ll,vector<ll>,less<>> que;
  rep(i,n)que.push(a[i]);
  rep(i,m){
    ll mx=que.top();
    que.pop();
    mx/=2;
    que.push(mx);
  }

  ll ans=0;
  while(!que.empty()){
    ans+=que.top();
    que.pop();
  }
  cout<<(ans)<<endl;


}


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

using namespace std;

typedef long long ll;

int main()
{ 
   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
ll n,i=1,temp=10,count=0;
cin>>n;
if(n%2!=0)cout<<0<<endl;
else
{
  
  while(temp<=n)
  {
    count+=(n/temp);
    temp*=5;
  }
  cout<<count<<endl;
}


return 0;
}
     


    

    

Measured memory_bytes: 256
m=0
def merge(a,left,mid,right):
    n1=mid-left
    n2=right-mid
    el=range(0,n1+1)
    ar=range(0,n2+1)
    for i in range(n1):
        el[i]=a[left+i]
    for i in range(n2):
        ar[i]=a[mid+i]
    el[n1]=float("inf")
    ar[n2]=float("inf")
    i=0
    j=0
    for k in range(left,right):
        global m
        m+=1
        if(el[i] <= ar[j]):
            a[k] = el[i]
            i=i+1
        else:
            a[k]=ar[j]
            j=j+1

def merge_sort(a,left,right):
    if(left+1<right):
        mid=(left+right)//2
        merge_sort(a,left,mid)
        merge_sort(a,mid,right)
        merge(a,left,mid,right)
    else:
        if(a[left]>a[right-1]):
            a[left],a[right-1]=a[right],a[left]



n=int(input())
s=raw_input()
a=list(map(int,s.split()))
merge_sort(a,0,n)
a=map(str,a)
print(" ".join(list(a)))
print(m)

Measured memory_bytes: 83332
N, K = map(int, input().split())
S = input()

l = 0
alt = 0; cnt = 0

for r in range(N):
    if S[r] == '0' and ( r == 0 or S[r-1] == '1'):
        alt += 1
    if alt > K:
        while S[l] == '1':
            l += 1
        while S[l] == '0':
            l += 1
        alt -= 1
    cnt = max(cnt, r-l+1)
print(cnt)

Measured memory_bytes: 42096
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<vector>
 
using namespace std;
 
int main() {
  int S=0,N=0,E=0,W=0;
  bool ans=false;
  string A;
  cin >> A;
  for(int i=0; i<A.size(); i++){
    if(A[i]=='S') S=1;
    if(A[i]=='N') N=1;
    if(A[i]=='E') E=1;
    if(A[i]=='W') W=1;
  }
  if(N==1 && S==1 && E==1 && W==1) ans=true;
  if(N==1 && S==1 && E==0 && W==0) ans=true;
  if(N==0 && S==0 && E==1 && W==1) ans=true;
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;
bool chk(ll d, ll n)
{
	while(n % d == 0)
	n /= d;
	return(n % d == 1);
}
int main()
{
	boost;
	ll n;
	cin >> n;
	if(n == 2) cout << 1;
	else {
		ll ans = 2;
		for(ll i = 2; i <= sqrt(n); i++) {
			if(chk(i, n))
				++ans;
			if(i != n / i && chk(n / i, n))
				++ans;
		}
		cout << ans;
	}
}


Measured memory_bytes: 256
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *
from heapq import *
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from bisect import *				# bisect_left(arr,x,start,end)  => start and end parameters are temporary
from sys import stdin				# bisect_left return leftmost position where x should be inserted to keep sorted
from sys import maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''

'''

def solve(l,n):
	zz = n - sum(l)
	if(zz < 0):
		return -1
	return n - sum(l)

N,M = list(map(int, stdin.readline().rstrip().split()))
l = list(map(int, stdin.readline().rstrip().split()))
ans = solve(l,N)
print(ans)



Measured memory_bytes: 78112
#include "bits/stdc++.h"
using namespace std;
const int N = 1e5 + 5;
int n;
vector < int > v[N];
int dfs(int node , int parent){
	int tot = 0;
	for(int next : v[node]){
		if(next != parent){
			tot += dfs(next , node);
		}
	}
	if(tot > 1){
		printf("First\n");
		exit(0);
	}
	return !tot;
}
int main(){
	scanf("%d" , &n);
	for(int i = 1 ; i < n ; ++i){
		int a , b;
		scanf("%d %d" , &a , &b);
		v[a].emplace_back(b);
		v[b].emplace_back(a);
	}
	if(dfs(1 , 0)){
		printf("First\n");
	}
	else{
		printf("Second\n");
	}
}

Measured memory_bytes: 5888
#include<cstdio>
#include<cstring>
#include<vector>
#include<cstring>
#include<iostream>
using namespace std;
char s[5];
int main()
{
	cin>>s[1];
	int a=s[1]-'0';
	a++;
	s[2]=a+'0';
	cout<<s[2]<<endl;
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  bool can = false;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; j < s.size(); j++) {
      if (s.at(i) == 'A' && s.at(j) == 'C' && j == i + 1) {
        can = true;
      }
    }
  }
  if (can) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
import numpy as np

H, W = map(int, input().split())
A = tuple(input() for _ in range(H))

INF = H * W

dp = np.full((H, W), INF, dtype=np.int)

for i in range(H):
	for j in range(W):
		dp[i, j] = 0 if A[i][j] == '#' else dp[i, j]

for i in range(1, H):
	dp[i, :] = np.minimum(dp[i, :], dp[i-1, :] + 1)
for i in range(0, H-1)[::-1]:
	dp[i, :] = np.minimum(dp[i, :], dp[i+1, :] + 1)
for j in range(1, W):
	dp[:, j] = np.minimum(dp[:, j], dp[:, j-1] + 1)
for j in range(0, W-1)[::-1]:
	dp[:, j] = np.minimum(dp[:, j], dp[:, j+1] + 1)

print(np.max(dp))


Measured memory_bytes: 32040
import sys

def get_minimun_val(n, rule_dict):
  max_val = 10**n
  min_val = 10**(n-1)
  if min_val == 1:
    min_val=0
  for i in range(min_val, max_val):
    str_i = str(i)
    flg = True
    for s, c in rule_dict.items():
      if str_i[s-1] == str(c):
        continue
      else:
        flg = False
        break
    if flg:
      return i
  return -1


rule_dict = {}

n, m = map(int, input().split())
res = -1
for i in range(m):
  s, c = map(int, input().split())
  if c == 0 and s == 1 and n > 1:
    print(-1)
    sys.exit()
  if s not in rule_dict:
    rule_dict[s] = c
    continue
  current_c = rule_dict[s]
  if c != current_c:
    print(-1)
    sys.exit()

print(get_minimun_val(n, rule_dict))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long ll; 

using namespace std;

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

	char res = '1';
	for (int i = 0; i < K; i++) {
		if (s[i] == '1') continue;

		res = s[i];
		break;
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std; 
#define ll long long int
#define v vector<ll>
#define vv vector<v>
#define MAX 15000001
#define p pair<int,int>
#define speed ios::sync_with_stdio(false); cin.tie(0) ; cout.tie(0)

int main()
{
	int n;
	cin>>n;
	if(n==3 || n==5 || n==7)
		cout<<"YES";
	else
		cout<<"NO";
}

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

using namespace std;

int main(void){

    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    int temp;
    if(X < Y){
        temp = X;
        X = Y;
        Y = temp;
        temp = A;
        A = B;
        B = temp;
    }
    
    int total = X * A + Y * B;
    if(total > X * C * 2){
        total = X * C * 2;
    }
    if(total > Y * C * 2 + (X - Y) * A){
        total = Y * C * 2 + (X - Y) * A;
    }
    cout << total << endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2　//1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) (max(x,y)-min(x,y))
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;


int gcd(int x, int y){
  if(x < y){
    swap(x, y);
  }
  int r = x%y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

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

  int k, nasu;
  lol ans = 0;
  cin >> k;
  reps(i, k){
    reps(j, k){
      reps(z, k){
	nasu = gcd(i, j);
	ans += gcd(nasu, z);
      }
    }
  }
  cout <<ans << '\n';
  return 0;
}


Measured memory_bytes: 3604
S = gets.chomp
n = S.length
ans = Array.new(S.length, 0)
cnt = 0
n.times do |i|
  if S[i] == 'R'
    cnt += 1
  else
    ans[i] += cnt/2
    ans[i-1] += (cnt+1)/2
    cnt = 0
  end
end
cnt = 0
(n-1).downto(0) do |i|
  if S[i] == 'L'
    cnt += 1
  else
    ans[i] += cnt/2
    ans[i+1] += (cnt+1)/2
    cnt = 0
  end
end

puts ans.join(' ')



Measured memory_bytes: 3196
//https://atcoder.jp/contests/abc158/tasks/abc158_a
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
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() {
    string S; cin>>S;
    if(S[0]==S[1]&&S[1]==S[2]) {
        cout<<"No"<<endl;
    }    else{
        cout<<"Yes"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] H = new int[N];

        for (int i = 0; i < N; i++) H[i] = sc.nextInt();

        int longest = 0;
        int current = 0;

        for (int i = 1; i < N; i++) {
            if (H[i] > H[i - 1]) {
                current = 0;
            } else {
                current++;
            }
            longest = Math.max(current, longest);
        }

        System.out.println(longest);
    }
}

Measured memory_bytes: 49892
#include <iostream>

int main() {
  int k, s;
  std::cin >> k >> s;
  long long result = 0;
  for (int x = 0; x <= k; x++) {
    if (s - x > 2 * k || x > s) continue;
    if (s - x > k) result += 2 * k - (s - x) + 1;
    else result += s - x + 1;
  }
  std::cout << result << std::endl;
}


Measured memory_bytes: 256
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = input()

print(chr(ord(n[0])+1))























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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << "\n";
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define endl "\n"
// gcj print用
#define Case(x) printf("Case #%d: ", x);

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

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

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

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

  int N;
  cin >> N;
  map<string, int> mp;
  string S;
  rep(i, 0, N) {
    cin >> S;
    mp[S]++;
  }

  int ma = 0;
  for (auto pi: mp) {
    chmax(ma, pi.second);
  }

  vector<string> ans;
  for (auto pi: mp) {
    if (pi.second == ma) ans.pb(pi.first);
  }

  sort(All(ans));

  for (auto s: ans) {
    cout << s << endl;
  }


  return 0;
};


Measured memory_bytes: 25584
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;
#define MAX_N 50
#define MAX 1e9 + 1
int d[MAX_N][MAX_N];
int n;

void floyd(int n) {
	for(int k=0; k<=n; k++) {
		for(int i=0; i<=n; i++) {
			for(int j=0; j<=n; j++) {
				d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
				
			}
		}

	}
}

int main() {
	int a,b,c;
	int sum;
	int s;
	int max_s;
	while(scanf("%d",&n)&&n!=0) {
		sum = MAX;
		max_s = 0;
		for(int i=0; i<10; i++) {
			for(int j=0; j<10; j++) {
				d[i][j] = MAX;
			}
		}
		for(int i=0; i<10; i++) d[i][i] = 0;

		for(int i=0; i<n; i++) {
			scanf("%d%d%d",&a,&b,&c);
			max_s = max(max_s,max(a,b));
			d[a][b] = d[b][a] = c;
		}
		
		floyd(max_s);
		for(int i=0;i<=max_s;i++){
			int x =0;
			for(int j=0;j<=max_s;j++){
				x+=d[i][j];
			}
			if(sum>x){
				sum = x;
				s = i;
			} 
		}
		printf("%d %d\n",s,sum);
	}
}

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

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

int main() {
    int n; cin >> n;
    string s; cin >> s;
    vector<ll> w(n + 1, 0);
    vector<ll> e(n + 1, 0);
    if(s[0] == 'W') w[0]++;
    else s[0]++;
    for(int i = 0; i < n; i++){
        if(s[i] == 'W'){
            w[i + 1] = w[i] + 1;
            e[i + 1] = e[i];
        }else{
            e[i + 1] = e[i] + 1;
            w[i + 1] = w[i];
        }
    }
    ll ans = 1LL << 60;
    for(int i = 0; i < n; i++){
        ll l = 0, r = 0;
        if(i > 0) l = w[i] - w[0];
        if(i < n - 1) r = e[n] - e[i + 1];
        ans = min(ans, l + r);
    }
    cout << ans << endl;
}


Measured memory_bytes: 5380
package main

import (
	"bufio"
	"fmt"
	"math/big"
	"os"
	"strconv"
)

var stdin = bufio.NewScanner(os.Stdin)

func main() {
	stdin.Split(bufio.ScanWords)
	var N int
	N = nextInt()
	A := make([]int64, N)
	for i := 0; i < N; i++ {
		A[i] = nextInt64()
		if A[i] == 0 {
			fmt.Println(0)
			os.Exit(0)
		}
	}
	ANS := big.NewInt(1)
	max := big.NewInt(1e18)
	for i := 0; i < N; i++ {
		ANS = ANS.Mul(big.NewInt(A[i]), ANS)
		if ANS.Cmp(max) == 1 {
			fmt.Println(-1)
			os.Exit(0)
		}
	}
	fmt.Println(ANS)
}

func nextInt() int {
	stdin.Scan()
	i, err := strconv.Atoi(stdin.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextInt64() int64 {
	stdin.Scan()
	i, err := strconv.ParseInt(stdin.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func nextFloat64() float64 {
	stdin.Scan()
	i, err := strconv.ParseFloat(stdin.Text(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func nextStr() string {
	stdin.Scan()
	i := stdin.Text()
	return i
}


Measured memory_bytes: 5916