akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <numeric>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<((x))<<endl
#define fi first
#define se second

#define INF 2147483600
#define long long long

int main(){
  int r0,w,c,r;
  while(cin>>r0>>w>>c>>r, r0){
    if(r0 >= w*c){ cout<<0<<endl; continue; }
    cout << (w*c-r0+r-1)/r << endl;
  }
  return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
 
int main(){
  int A,B,C;
  cin>>A>>B>>C;
  if (A < B){
    if (A < C && C < B){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }else{
    if (B<C && C < A) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(),(v).end())
typedef int64_t lint;
// lint mod = 998244353;

string app() {
  int a,b,c;
  cin>>a>>b>>c;

  return (a+b+c>=22)?"bust":"win";
}

int main(){cout<<app()<<endl;return 0;}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=200200;
int i,j,k,n,X,Y,x,y,ch,ff,ans;
bool z[N];
struct edge { int s,n;};
struct tree {
	int i,j,k,En;
	int h[N],dp[N],fa[N];
	edge E[N<<1];
	void add(int x,int y) {
		E[++En].s=y;E[En].n=h[x];h[x]=En;
		E[++En].s=x;E[En].n=h[y];h[y]=En;
	}
} A,B;
void R(int &x) {
	ff=x=0;ch=getchar();
	while (ch<'0' || '9'<ch) { if (ch=='-') ff=1;ch=getchar();}
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
	if (ff) x=-x;
}
void dfsB(int x,int F) {
	B.fa[x]=F;B.dp[x]=B.dp[F]+1;
	for (int k=B.h[x];k;k=B.E[k].n) if (B.E[k].s!=F) dfsB(B.E[k].s,x);
}
void dfsA(int x,int F) {
	A.fa[x]=F;A.dp[x]=A.dp[F]+1;
	z[x]=z[F] || A.dp[x]>=B.dp[x];
	for (int k=A.h[x];k;k=A.E[k].n) if (A.E[k].s!=F) dfsA(A.E[k].s,x);
}
bool check(int x,int y) {
	if (B.dp[x]<B.dp[y]) swap(x,y);
	if (B.dp[x]==B.dp[y] && B.fa[x]==B.fa[y]) return 0;
	if (B.fa[x]==y || B.fa[B.fa[x]]==y) return 0;
	return 1;
}
int main() {
	R(n);R(X);R(Y);
	for (i=1;i<n;i++) {
		R(x);R(y);
		A.add(x,y);
	}
	for (i=1;i<n;i++) {
		R(x);R(y);
		B.add(x,y);
	}
	A.dp[0]=B.dp[0]=-1;
	dfsB(Y,0);
	dfsA(X,0);
	for (i=1;i<=n;i++)
		for (k=A.h[i];k;k=A.E[k].n) if (A.E[k].s!=A.fa[i]) {
			j=A.E[k].s;
			if (z[i] && z[j]) continue;
			if (check(i,j)) return puts("-1"),0;
		}
	for (i=1;i<=n;i++) if (!z[i]) ans=max(ans,B.dp[i]);
	printf("%d\n",2*ans);
}

Measured memory_bytes: 16896
x,y = map(int,input().split())
x1=0
y1=0

if x==1:
  x1=300000
elif x==2:
  x1=200000
elif x==3:
  x1=100000

if y==1:
  y1=300000
elif y==2:
  y1=200000
elif y==3:
  y1=100000
  
if x==1 and y==1:
  print(x1+y1+400000)
else:
  print(x1+y1)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  int next[n];
  for(int i=0; i<n; ++i) cin >> next[i];
  int now = 1;
  bool canLight = false;
  int count = 0;
  for(int i=0; i<n; ++i){
    now = next[now-1];
    count++;
    if(now == 2){
      canLight = true;
      break;
    }
  }
  if(canLight) cout << count << endl;
  else cout << -1 << endl;
}

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

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

  bool alice[101];
  bool bob[101];
  for(int i=0; i<101; i++){
    alice[i] = false;
    bob[i] = false;
  }

  for(int i=a; i<=b; i++){
    alice[i] = true;
  }

  for(int i=c; i<=d; i++){
    bob[i] = true;
  }

  int sec = 0;
  for(int i=0; i<101; i++){
    if (alice[i] == true && bob[i] == true)
      sec++;
  }

  if (sec != 0) sec--;
  cout << sec;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int h,w;
    cin>>h>>w;
    char c[200][200];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>c[i][j];
        }
    }
    for(int i=0;i<h;i++){
        for(int k=0;k<2;k++){
        for(int j=0;j<w;j++){
            cout<<c[i][j];
        }
        cout<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
    uint64_t h, w;

    std::cin >> h >> w;

    if (h == 1 || w == 1) {
        std::cout << 1 << std::endl;
    } else {
        uint64_t first_line = w / 2 + w % 2;
        uint64_t second_line = w / 2;

        uint64_t ans = first_line * (h / 2) + second_line * (h / 2) + first_line * (h % 2);

        std::cout << ans << std::endl;
    }

    return 0;
}

Measured memory_bytes: 3668
#include <iostream>
//#include <math.h>
#include <set>
#include<iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define space ' '
#define pll pair<ll,ll>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

const int maxn = 1000;

int main(){
    
    int ans = 0;
    int ar[maxn+1][maxn+1];
    int ite[maxn+1];
    int n;
    int fin = 0;
    
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n-1;j++){
            //cin >> ar[i][j];
            scanf("%d",&ar[i][j]);
        }
        ar[i][n]=INF;
    }
    fill(ite,ite+(n+1),1);
    
    while(true){
        ans++;
        bool pos=false;
        bool done[maxn+1]={0};
        
        for(int i=1;i<=n;i++){
            int opp = ar[i][ite[i]];
            if(opp==INF||done[i]==true||done[opp]==true)continue;
            //cout << i<<space<<ar[opp][ite[opp]]<<endl;
            if(i == ar[opp][ite[opp]]&&!done[opp]&&!done[i]){
                done[opp]=done[i]=true;
                ite[i]++;ite[opp]++;
                pos = true;
                fin++;
            }
            
        }
        //cout <<endl;
        
        if(!pos){
            ans = -1;
            break;
        }
        if(fin==n*(n-1)/2)break;
    }
    
    cout << ans<<endl;


    
    return 0;
}


Measured memory_bytes: 4224
N = int(input())
S = ['']*N
for i in range(N):
    S[i] = input()
ac = 0
wa = 0
tle = 0
re = 0
for s in S:
    if s == 'AC':
        ac += 1
    elif s =='WA':
        wa +=1
    elif s =='TLE':
        tle +=1
    elif s =='RE':
        re +=1

print('AC x',ac)
print('WA x',wa)
print('TLE x',tle)
print('RE x',re)


Measured memory_bytes: 15812
package main

import (
	"fmt"
)

func main() {
	var n, yen int
	fmt.Scan(&n, &yen)

	var slice [3]int
	var judge bool
	for i := 0; i <= n; i++ {
		if judge {
			break
		}
		for j := 0; j <= n; j++ {
			if judge || i+j > n {
				break
			}
			k := n - i - j
			if 10000*i+5000*j+1000*k == yen && i+j+k == n {
				slice[0] = i
				slice[1] = j
				slice[2] = k
				judge = true
			}
		}
	}
	if !judge {
		slice[0] = -1
		slice[1] = -1
		slice[2] = -1
	}
	fmt.Println(slice[0], slice[1], slice[2])
}


Measured memory_bytes: 512
#include<stdio.h>

#define N 2000
int solve(int,int);

int A[N],n;
main(){
  int i,j,q,x,m[N];
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&m[i]);
  }
  for(i=0;i<q;i++){
    x= solve(0,m[i]);
   if(x==1){
     printf("yes\n");
     x=0;
   }
   else{
     printf("no\n");
   }
  }
  return 0;
}

int solve(int i,int m){
  int res;
  if(m==0){
    return 1;
  }
  if(i>n){
    return 0;
  }
  else{
    res = solve(i+1,m)||solve(i+1,m-A[i]);
    return res;
  }
}

Measured memory_bytes: 588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

bool g[50][50];
bool visited[50];
int n, m;

void dfs(int x) {
    visited[x] = true;
    rep(i, 0, n) {
        if (g[x][i] && !visited[i]) dfs(i);
    }
}

int main() {
    cin >> n >> m;
    int a[m], b[m];
    rep(i, 0, m) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        g[a[i]][b[i]] = true;
        g[b[i]][a[i]] = true;
    }

    int ans = 0;
    rep(i, 0, m) {
        g[a[i]][b[i]] = g[b[i]][a[i]] = false;
        rep(i, 0, n) visited[i] = false;
        dfs(0);
        rep(i, 0, n) {
            if (visited[i] == false) {
                ans++;
                break;
            }
        }
        g[a[i]][b[i]] = g[b[i]][a[i]] = true;
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const int mod=1e9+7;
const int maxn=2e6+16;
const ll INF=100000000000005;
const double eps=1e-11;
using namespace std;
ll n,m,p;
map<ll,ll>mp;
ll sum[maxn];
ll num[maxn];
int main()
{
    ll res=0;
    scanf("%lld%lld",&n,&m);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&num[i]);
        sum[i]=sum[i-1]+num[i];
    }
    for(int i=1;i<=n;i++)
        sum[i]=(sum[i]-i%m+m)%m;
    ll low=min(m-1,n);
    for(int i=0;i<=low;i++)
    {
        res+=mp[sum[i]];
        mp[sum[i]]++;
    }
    for(int i=low+1;i<=n;i++)
    {
        mp[sum[i-m]]--;
        res+=mp[sum[i]];
        mp[sum[i]]++;
    }
    printf("%lld\n",res);
    return 0;
}

Measured memory_bytes: 18432
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}



int main(){
  double L;cin>>L;
  double V=(L/3)*(L/3)*(L/3);
  pri(V);
  
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n, k; cin >> n >> k;
	int ans = 0;
	rep(i, 1, n)
	{
		int h; cin >> h;
		if (h >= k)++ans;
	}
	cout << ans << endl;
}

Measured memory_bytes: 764
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            while (true)
            {
                S = S.Substring(0, S.Length - 1);
                int len = S.Length;

                if(len % 2 != 0)
                {
                    continue;
                }

                if (S.Substring(0, len/2) == S.Substring(len/2))
                {
                    Console.WriteLine(len);
                    return;
                }            
            }
        }
    }
}
// 文字列の入力
//string s = Console.ReadLine();

// 整数の入力
//long n = long.Parse(Console.ReadLine());

// 文字列配列の入力
//string[] inputStrArray = Console.ReadLine().Split(' ');

// 整数配列の入力
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();


//Console.WriteLine(ans);

Measured memory_bytes: 25912
#include<iostream>
#include<cstring>
#include<cstdio>
#define md 1000000007
using namespace std;

int n,f[105][500],i,j,k,ok[505],ans;

int ya(int a,int b,int c,int d)
{
	return d+(c<<2)+(b<<4)+(a<<6);
}
void build_ok()
{
	for(int i=0;i<=3;i++)
	{
		ok[ya(i,1,2,3)]=1;
		ok[ya(i,1,3,2)]=1;
		ok[ya(i,2,1,3)]=1;
		ok[ya(1,i,2,3)]=1;
		ok[ya(1,2,i,3)]=1;
		ok[ya(1,2,3,i)]=1;
		ok[ya(1,3,2,i)]=1;
		ok[ya(2,1,3,i)]=1;
	}
}

int main()
{
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n;
	build_ok();
	for(i=0;i<(1<<6);i++)
		f[3][i<<2]=i==27||i==30||i==39?0:1;
	for(i=4;i<=n;i++)
	{
		for(j=0;j<(1<<8);j++)
			if(!ok[j])
				for(k=0;k<=3;k++)
					f[i][j]=(f[i][j]+f[i-1][((j<<2)&((1<<8)-1))|k])%md;
	}
	for(i=0;i<(1<<8);i++)
		ans=(ans+f[n][i])%md;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>

int main() {

	int n;

	scanf("%d\n", &n);

	int value[n];
	int max = INT_MIN;
	int min = INT_MAX;
	long long int sum = 0;

	for(int i = 0; i < n; i++) {
		scanf("%d", &value[i]);
		if (max < value[i]) {
			max = value[i];
		}
		if (min > value[i]) {
			min = value[i];
		}
		sum += value[i];
	}

	printf("%d %d %lld\n", min, max, sum);

	return 0;
}

Measured memory_bytes: 1068
#include <bits/stdc++.h>
using namespace std;
int a[100000],n,l,r,ans;
int main()
{
  cin>>n;
  for(int i=1; i<=n; i++)
  {
    cin>>l>>r;
    for(int j=l; j<=r; j++)ans++;
  }
  cout<<ans;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
	using namespace std;
	int main() { 
	    
	    int a,b;
	    cin >> a >> b;

	    while(a && b){
	    	for(int i=0; i<a ;i++){
	    	for(int j=0 ;j <b;j++){
	    		if(i==0 || i== a-1)cout << "#";
	    		else{
	    			if(j==0 || j == b-1){
	    				cout << "#";
	    			}
	    			else {
	    				cout << ".";
	    			}
	    		}
	    	}
	    	cout << endl;
	    	}
	    	cout << endl;
	    	cin >> a >> b;	
	    }
	    


	    return 0;
	}


Measured memory_bytes: 3048
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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; }

int main(){
    int n; cin >> n;
    int res = INF;
    rep(i, n){
        int a; cin >> a;
        int cnt = 0;
        while(a%2==0){
            a /= 2;
            cnt++;
        }
        chmin(res, cnt);
    }
    cout << res << ln;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cmath>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

const double PI = acos(-1.0);

double deg2rad(double degree) {
    return degree * PI / 180.0;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    double A, B, H, M;
    cin >> A >> B >> H >> M;
    double deg1 = (H * 60 + M) * 0.5;
    double deg2 = M * 6.0;
    double diff = abs(deg1 - deg2);
    cout << fixed << setprecision(10) << sqrt(A * A + B * B - 2 * A * B * cos(deg2rad(diff))) << endl;
    return 0;
}

Measured memory_bytes: 4244
import numpy as np
N = int(input())
A = [int(x) for x in input().split(" ")]
Q = int(input())

S = 0

query = []
for _ in range(Q):
    query.append([int(x) for x in input().split(" ")])

array = np.zeros(10**5, dtype=int)
for a in A:
    S += a
    array[a-1] += 1

# print("Q: ", Q)
for B, C in query:
    # print(array)
    D = array[B-1]
    S += (C - B) * D
    print(S)
    array[C-1] += D
    array[B-1] = 0
# print(array)

Measured memory_bytes: 48376
// Akshit Awasthi
#include <bits/stdc++.h>
#define int long long
#define float long double
#define ar array
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define all(x) x.begin(), x.end()
#define deb(...) cerr << "[" << #__VA_ARGS__ << ": " << (__VA_ARGS__) << "]\n"
#define deb2(x, y) cerr << #x << " = " << x << "\t" << #y << " = " << y << endl
#define fastio                    \
    std::ios::sync_with_stdio(0); \
    std::cin.tie(NULL);           \
    std::cout.tie(NULL)
#define mod1 1000000007
#define mod2 998244353
#define mod mod1
#define MAX 200015
using namespace std;

template <class T>
istream& operator>>(istream& stream, vector<T>& v) {
    for (int i = 0; i < (int)v.size(); i++) stream >> v[i];
    return stream;
}
template <class T1, class T2>
istream& operator>>(istream& stream, pair<T1, T2>& p) {
    return stream >> p.first >> p.second;
}
template <class T>
ostream& operator<<(ostream& stream, const vector<T>& v) {
    for (int i = 0; i < (int)v.size(); i++) stream << v[i] << ' ';
    stream << '\n';
    return stream;
}
template <class T1, class T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& pair) {
    return stream << pair.first << ' ' << pair.second;
}
int pow(int a, int n) {
    if (n < 0) return 0;
    int ans = 1;
    while (n) {
        if (n & 1) ans = ans * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return ans;
}
int __lcm(int a, int b) { return (a / __gcd(a, b)) * b; }
int fact(int n) { return n == 0 ? 1LL : n * fact(n - 1) % mod; }
int inverse(int x, int p = mod) { return pow(x, p - 2); }
int nck(int n, int k, int p = mod) {
    return fact(n) * inverse(fact(k), p) % p * inverse(fact(n - k)) % p;
}

vector<int> arr;

void solve(void) {
    int n;
    cin >> n;
    int num = 7;
    int i = 1;
    for (i = 1; i < 1e7; i++) {
        if (num % n == 0) break;
        num *= 10;
        num += 7;
        num %= n;
    }
    if (i == 1e7) i = -1;
    cout << i << '\n';
}

int32_t main(void) {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
    fastio;
    // cout.setf(std::ios::unitbuf);
    int t = 1;
    // cin >> t;
    for (int i = 1; i <= t; i++) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>

using namespace std;
using LL = long long;

class Solution {
public:
	LL modsum(int n) {
		/*
		 * The optimal permutation is:
		 *    n    %    1    =    0
		 *    1    %    2    =    1
		 *    2    %    3    =    2
		 *    3    %    4    =    3
		 *    .         .         .
		 *    .         .         .
		 *    .         .         .
		 * (n - 3) % (n - 2) = (n - 3)
		 * (n - 2) % (n - 1) = (n - 2)
		 * (n - 1) %    n    = (n - 1)
		 */
		return (LL)n * (n - 1) / 2;
	}
};

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

	Solution sol;
	LL ans = sol.modsum(n);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
//
// Created by 伊東麻沙美 on 2019/10/22.
//

#include<iostream>
#include<algorithm>
using namespace std;


int main(){

    int a,b;
    cin>>a>>b;

    if(a>=13){
        cout<<b;
    }
    if(a>=6&&a<=12){
        cout<<b/2;
    }
    if(a<6){
        cout<<0;
    }
    //cin>>a>>b>>x;
    //scanf("%d%s%d",&i,&x,&j);


       // printf("%d",i+j);
       //cout<<i+j<<endl;

    return 0;
}

Measured memory_bytes: 256
import Foundation
func toTuple<T>(_ args: [T]) -> (T, T) { (args[0], args[1]) }
func readInts() -> [Int] { readLine()!.split(separator: " ").map { Int($0)! } }

let n = Int(readLine()!)!
var ans = 0
for _ in 0..<n {
  let (l, r) = toTuple(readInts())
  ans += r - l + 1
}
print(ans)

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

#define fec(i, x, y) (int i = head[x], y = g[i].to; i; i = g[i].ne, y = g[i].to)
#define dbg(...) fprintf(stderr, __VA_ARGS__)
#define File(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)
#define fi first
#define se second
#define pb push_back

template<typename A, typename B> inline char SMAX(A &a, const B &b) {return a < b ? a = b , 1 : 0;}
template<typename A, typename B> inline char SMIN(A &a, const B &b) {return b < a ? a = b , 1 : 0;}

typedef long long ll; typedef unsigned long long ull; typedef std::pair<int, int> pii;

template<typename I>
inline void read(I &x) {
	int f = 0, c;
	while (!isdigit(c = getchar())) c == '-' ? f = 1 : 0;
	x = c & 15;
	while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + (c & 15);
	f ? x = -x : 0;
}

const int N = 2e5 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
int n, a[N];
ll dp[N][5], ans = INF;

int main() {
	#ifdef hzhkk
	freopen("hkk.in", "r", stdin);
	#endif
	read(n);
	for (int i = 1; i <= n; ++i) read(a[i]);
	dp[0][1] = dp[0][2] = dp[0][3] = dp[0][4] = INF;
	for (int i = 1; i <= n; ++i) {
		dp[i][0] = dp[i - 1][0] + a[i];
		dp[i][1] = std::min(dp[i - 1][0], dp[i - 1][1]) + (a[i] ? (a[i] & 1) : 2);
		dp[i][2] = std::min(std::min(dp[i - 1][1], dp[i - 1][2]), dp[i - 1][0]) + (a[i] & 1 ^ 1);
		dp[i][3] = std::min(dp[i - 1][2], dp[i - 1][3]) + (a[i] ? (a[i] & 1) : 2);
		dp[i][4] = std::min(std::min(dp[i - 1][1], dp[i - 1][2]), std::min(dp[i - 1][3], dp[i - 1][4])) + a[i];
		// dbg("%d: %lld, %lld, %lld, %lld, %lld\n", i, dp[i][0], dp[i][1], dp[i][2], dp[i][3], dp[i][4]);
	}
	for (int i = 0; i < 5; ++i) SMIN(ans, dp[n][i]);
	printf("%lld\n", ans);
}

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

using namespace std;
int x[1080], y[1080];
int n, d, m;
int minx, miny, maxx, maxy;
int main(){
	while(cin >> m, m){
		x[0] = y[0] = 0;
		minx = miny = maxx = maxy = 0;
		for(int i = 1;i < m;i++){
			cin >> n >> d;
			switch(d){
				case 0:
					x[i] = x[n] - 1;
					y[i] = y[n];
					break;
				case 1:
					y[i] = y[n] - 1;
					x[i] = x[n];
					break;
				case 2:
					x[i] = x[n] + 1;
					y[i] = y[n];
					break;
				case 3:
					y[i] = y[n] + 1;
					x[i] = x[n];
					break;
			}
			maxx = max(maxx, x[i]);
			maxy = max(maxy, y[i]);
			minx = min(minx, x[i]);
			miny = min(miny, y[i]);
		}
		cout << maxx - minx + 1 << " " << maxy - miny + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
macro_rules! get {
    (Vec<$t:ty>) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (A, B, C, D, E, F) = get!(usize, usize, usize, usize, usize, usize);

    // 全探索により解を求める
    let mut ans = (100 * A, 0);
    for a in (0..(F / (100 * A) + 1)).map(|a| 100 * A * a) {
        for b in (0..((F - a) / (100 * B) + 1)).map(|b| 100 * B * b) {
            for c in (0..((F - a - b) / C + 1)).map(|c| C * c) {
                for d in (0..((F - a - b - c) / D + 1)).map(|d| D * d) {
                    let (u, v) = ans;
                    let (x, y) = (a + b + c + d, c + d);
                    if c + d <= E * (a + b) / 100 && u * y > v * x {
                        ans = (x, y);
                    }
                }
            }
        }
    }

    println!("{} {}", ans.0, ans.1);
}


Measured memory_bytes: 4352
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

int cnt = 0;

void MergeSort(vector<int> &A, int left, int right) {
    if (right - left == 1)
        return;
    int mid = (right + left) / 2;

    MergeSort(A, left, mid);
    MergeSort(A, mid, right);

    vector<int> buf;
    for (int i = left; i < mid; i++) {
        buf.push_back(A[i]);
    }

    // 逆順でコピー
    for (int i = right - 1; i >= mid; i--) {
        buf.push_back(A[i]);
    }

    //統合
    int itrl = 0;
    int itrr = buf.size() - 1;
    for (int i = left; i < right; i++) {
        if (buf[itrl] <= buf[itrr]) {
            A[i] = buf[itrl];
            itrl++;
        } else {
            A[i] = buf[itrr];
            itrr--;
        }
        cnt++;
    }
}

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

    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) { cin >> A[i]; }

    MergeSort(A, 0, N);
    rep(i, N - 1) { cout << A[i] << " "; }
    cout << A[N - 1] << endl;
    cout << cnt << endl;
}


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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<Edge>>;

int main()
{
    ll h;
    cin >> h;
    int p = 0;
    while(h >= 2) {
        h /= 2;
        p++;
    }
    // cout << pow << endl;
    ll ans = 2 * (pow(2, p) - 1) + 1;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int f[1<<18];
void ex(int &x,int a,int b){if(a!=b&&((x>>a)&1)!=((x>>b)&1))x^=(1<<a)^(1<<b);}
void build(int l,int r,int s,int e,int n)
{
	if(l+1==r){f[l]=s;f[r]=e;return;}
	int m=(l+r)/2;
	e^=s;
	int k=18;
	while(~e&(1<<k))k--;
	ex(e,k,n-1);
	build(l,m,0,e^(1<<(n-1))^1,n-1);
	build(m+1,r,e^(1<<(n-1))^1,e^(1<<(n-1)),n-1);
	for(int i=r;i>m;i--)f[i]^=(1<<(n-1));
	for(int i=l;i<=r;i++)ex(f[i],k,n-1),f[i]^=s;
}
int main()
{
	int n,a,b;
	cin>>n>>a>>b;
	if(__builtin_popcount(a^b)%2==0)cout<<"NO\n",exit(0);
	cout<<"YES\n";
	build(0,(1<<n)-1,a,b,n);
	for(int i=0;i<(1<<n);i++)cout<<f[i]<<' ';
	cout<<'\n';
}


Measured memory_bytes: 1536
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
a.sort()
mod = 10 ** 9 + 7
ans = 0

f = [1] * (n + 1)
inv = [1] * (n + 1)
for i in range(1, n + 1):
    f[i] = (f[i - 1] * i) % (mod)
inv[n] = pow(f[n], mod - 2, mod)
for i in range(n - 1, 0, -1):
    inv[i] = inv[i + 1] * (i + 1) % mod

def combination(n, r):
    if (n != 0) & (n >= r):
        return f[n] * inv[r] * inv[n - r] % mod
    return 0    
    
ans = 0
for index, value in enumerate(a):
    ans += (combination(index, k - 1) - combination(n - index - 1, k - 1)) * value
print(ans % mod)

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

int main() {
	int n; cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a.at(i);
	}
	int leave = 0, cur = 1;
	for (int i = 0; i < n; i++) {
		if (a.at(i) == cur) {
			leave++; cur++;
		}
	}
	if (leave == 0) cout << -1 << endl;
	else cout << n - leave << endl;
}

Measured memory_bytes: 1024
import java.io.PrintWriter
import java.util.*

val pw = PrintWriter(System.out)

fun main(args: Array<String>) {
    readInt()
    val a: List<Int> = readListOfInt()

    var cnt = Int.MAX_VALUE 
    a.forEach { ca ->
        var ca_ = ca
        var tmp = 0
        while(ca_ / 2 > 0 && ca_ % 2 == 0) {
            ca_ /= 2
            tmp++
        }
        cnt = listOf(cnt, tmp).min()!!
    }
    println(cnt)

    pw.flush()
}

fun inputList() = 
    readLine()!!.split(" ").map(String::toInt)

fun sum_digits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

/****** Decrared Functions ******/

// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }


fun println(value : Any) {
    pw.println(value)
}

fun gcd(a: Long, b: Long): Long = 
    if(b != 0L) a else gcd(b, a % b)

fun lcm(a: Long, b: Long) = 
    if(b==0L) a else gcd(b, a % b)


Measured memory_bytes: 37872
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int N, M;
vector<string> A, B;

int main(void) {
	cin >> N >> M;
	A.resize(N);
	B.resize(M);
	for (int j = 0; j < N; ++j)
		cin >> A[j];
	for (int j = 0; j < M; ++j)
		cin >> B[j];

	string ans = "No";
	for (int y = 0; y <= N - M; ++y) {
		for (int x = 0; x <= N - M; ++x) {
			ans = "Yes";
			for (int j = 0; j < M; ++j) {
				string subA = A[y + j].substr(x, M);
				if (B[j] != subA) {
					ans = "No";
					break;
				}
			}
			if (ans == "Yes")
				break;
		}
		if (ans == "Yes")
			break;
	}

	cout << ans << '\n';
	return 0;
}


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

int main() {

    int n; cin >> n;
    vector<int> odd,even,a;
    odd.push_back(INT_MAX); even.push_back(INT_MAX);
    for(int i=0; i<n; i++){
	int in; scanf("%d",&in);
	a.push_back(in);
	if(i%2==0)
	    even.push_back(in);
	else
	    odd.push_back(in);
    }
    sort(odd.begin(),odd.end());
    reverse(odd.begin(),odd.end());

    sort(even.begin(),even.end());
    reverse(even.begin(),even.end());

    sort(a.begin(),a.end());


    int val_even = 0,val_odd = 0;
    
    for(int i=0; i<n; i++) {
	int odd_min  = odd[odd.size()-1];
	int even_min = even[even.size()-1];
//	cout << a[i] << " " << odd_min << " " << even_min << endl;
	if( i%2 == 0 ) { // even に最小値があるはず
	    if( a[i] == odd_min )  { // だが odd にあった
		val_odd ++;
		odd.pop_back();
	    }
	    else
		even.pop_back();
	}
	else{ // odd にあるはず
	    if( a[i] == even_min ) {
		val_even ++;
		even.pop_back();
	    }
	    else
		odd.pop_back();
	}
    }
    cout << val_even << endl;

}


Measured memory_bytes: 1272
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;

int n, ans = 0;

void dfs(string s){
  if(s.size() == 10 || stoi(s) > n) return;

  if(s.find('3') != std::string::npos &&
     s.find('5') != std::string::npos &&
     s.find('7') != std::string::npos) ans++;

  dfs(s + '3');
  dfs(s + '5');
  dfs(s + '7');
}

int main()
{
  cin >> n;

  dfs("3");
  dfs("5");
  dfs("7");

  cout << ans << endl;

  return 0;

}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int mod = 1000000007;

int main(){
    ll n,k;
    double ans=0;
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        double s;
        if(i>=k) ans+=((double)1/n);
        else{
            s=log2((double)k/i);
            int ss=s;
            if(s!=ss) ss++;
            ans += 1/(pow(2,ss)*n);
        }
    }
    printf("%.16f\n",ans);
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	ll a,b,i;
	cin >> a >> b;
	for(i=1ll; i<=a; ++i){
		if(i*b%a){
			continue;
		}
		cout << i*b << endl;
		break;
	}
	return 0;
}


Measured memory_bytes: 256
#define S m[j]+f[j]
#include <stdio.h>

int main(void)
{
	int m[51],f[51],r[51],i,j;
	for(i=0;;i++){
		scanf("%d%d%d",&m[i],&f[i],&r[i]);
		if(m[i]==-1&&f[i]==-1&&r[i]==-1)break;
	}
	for(j=0;j<i;j++){
		if(m[j]==-1||f[j]==-1)puts("F");
		else if(S>=80)puts("A");
		else if(S>=65)puts("B");
		else if(S>=50)puts("C");
		else if(S>=30&&r[j]>=50)puts("C");
		else if(S>=30)puts("D");
		else puts("F");
	}
	return 0;
}


Measured memory_bytes: 2140
using System;
using System.Collections.Generic;
 
namespace ALDS1_3
{
    class Program
    {
        static int Calc(string[] a)
        {
            var stack = new List<int>();
            var symbol = "+-*/";
            foreach(var e in a)
            {
                if (symbol.Contains(e))
                {
                    var l = stack.Count - 1;
                    var x = stack[l - 1];
                    var y = stack[l];
                    stack.RemoveRange(l - 1, 2);
                    var aque = e == "+" ? x + y:
                               e == "-" ? x - y:
                               e == "*" ? x * y:
                                          x / y;
                    stack.Add(aque);
                }
                else
                    stack.Add(int.Parse(e));
            }
            return stack[0];
        }
        
        static void Main()
        {
            Console.WriteLine(Calc(Console.ReadLine().Split()));
        }
    }
}

Measured memory_bytes: 9832
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  int dp[n+1];
  for(int i=0;i<=n;i++) dp[i]=1000000;
  dp[0]=0;
  int a[12];
  a[0]=1;
  int p=1;
  for(int i=1;i<=6;i++){
    p*=6;
   a[i]=p;
  }
  p=1;
  for(int i=7;i<=11;i++){
    p*=9;
    a[i]=p;
  }
  for(int i=0;i<=n;i++){
    for(int j=0;j<12;j++){
      if(i-a[j]>=0){
        dp[i]=min(dp[i-a[j]]+1,dp[i]);
      }
    }
  }
  cout << dp[n]<<endl;
}


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

int main() {
 long long X;
  cin >> X;
long long A;
  A = 100;
long long i = 0; 
while (i < 4000 ) {
  A = A + (A/100);
  if (A >= X){
long long N;
 N= i + 1;
 cout << N << endl;
    break;  }
  i++; 
}
 
 }

Measured memory_bytes: 3636
N, X, Y = list(map(int,input().split()))
kyori = dict()
for j in range(N-1):
    kyori[j+1] = 0
for i in range(1,N,1):
    for j in range(i+1,N+1,1):
        k = min(abs(j-i),abs(X-i)+1+abs(j-Y),abs(Y-i)+1+abs(X-j))
        #print(i,j,abs(j-i),abs(X-i)+1+abs(j-Y),abs(Y-i)+1+abs(X-j))
        kyori[k] += 1
#print(kyori)

for i in kyori.values():
    print(i)

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100010
#define INF 10000000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000000;
const int MOD = 1000000007;
int main(){
    string s;
    cin>>s;
    map<char,int>m;
    REP(i,4){
        m[s[i]]++;
    }
    bool f=false;
    if(SZ(m)==2&&m[s[0]]==2)f=true;
    if(f)OUT("Yes");
    else OUT("No");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
 
  int A,B,plus,minus,times;
  
  cin >> A >> B;
  plus = A + B;
  minus = A - B;
  times = A * B;
  
  if(plus >= minus && plus >= times)
    cout << plus << endl;
  
  else if (minus >= plus && minus >= times)
    cout << minus << endl;
  
  else
    cout << times << endl;
  
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args)throws IOException{
		InputStreamReader isr=new InputStreamReader(System.in);
		BufferedReader br=new BufferedReader(isr);
		String s=br.readLine();
		StringTokenizer st=new StringTokenizer(s," ");
		
		int x=Integer.parseInt(st.nextToken());
		int y=Integer.parseInt(st.nextToken());
		System.out.print(x*y);
		System.out.print(" ");
		System.out.println(2*x+2*y);
		
		
	}

}

Measured memory_bytes: 16856
#!/usr/bin/env fsharpi

open System;

let ParseIntN ( str : string ) =
    str.Split(' ')
    |> Array.map System.Int32.Parse

let ParseInt1 ( str : string ) =
    ParseIntN str |> fun arr -> arr.[0]

let ParseInt2 ( str : string ) =
    ParseIntN str |> fun arr -> (arr.[0],arr.[1])

let ParseInt3 ( str : string ) =
    ParseIntN str |> fun arr -> (arr.[0],arr.[1],arr.[2])

let ReadLinesN ( n : int ) =
    fun _ -> Console.ReadLine()
    |> Seq.initInfinite
    |> Seq.take n

let ReadLines =
    fun _ -> Console.ReadLine()
    |> Seq.initInfinite
    |> Seq.takeWhile ((<>) null)

let n = ParseInt1 <| Console.ReadLine()
let k = ParseInt1 <| Console.ReadLine()
let x = ParseInt1 <| Console.ReadLine()
let y = ParseInt1 <| Console.ReadLine()
let res = x * (min n k) + y * (max 0 (n-k))
printfn "%d" res


Measured memory_bytes: 14044
#include<stdio.h>
#define N 10000
#define Q 500

int search(int);
int S[N];
int n;

int main() {
  int q,T[N],i,j,x,count=0;
  scanf("%d",&n);
  for(i = 0; i< n; i++) {
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i = 0; i < q; i++) {
    scanf("%d",&T[i]);
  }
  for(i = 0; i < q; i++) {
    x = search(T[i]);
    if(x >= 0 && x < n ) {
      count++;
    }
  }

  printf("%d\n",count);
  return 0;
}

int search(int key) {
  int i = 0;
  S[n] = key;
  while(S[i] != key) {
    i++;
    if(i ==n) {
      return n;
    }
  }
  return i;
} 

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

int main(void){
    ll a,b,c,x,y,price=0; cin >> a >> b >> c >> x >> y;
    if(2*c < a+b){
        int min_xy = min(x,y);
        price += min_xy*c*2;
        x -= min_xy, y -= min_xy;
    }
    if(2*c < a) price += 2*c*x;
    else price += a * x;
    if(2*c < b) price += 2*c*y;
    else price += b * y;    

    cout << price << endl;

    return 0;
}

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


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

    // solution comes here
    ll N, Q;    string S;
    cin >> N >> Q >> S;
    vl l(Q), r(Q);
    rep(i, Q) cin >> l[i] >> r[i];

    vl SUM(N);
    SUM[0] = 0;
    for(ll i=1; i<N; i++)
        SUM[i] = SUM[i-1] + ('A'==S[i-1]&&'C'==S[i]);
    
    rep(i, Q) cout << SUM[--r[i]] - SUM[--l[i]] << nl;
}

Measured memory_bytes: 3408
#include <iostream>

using namespace std;

void solve()
{
	int a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;
	int minPasta = a;
	if(minPasta > b)
	{
		minPasta = b;
	}
	if(minPasta > c)
	{
		minPasta = c;
	}
	int minJuice = d;
	if(minJuice > e)
	{
		minJuice = e;
	}
	cout << minPasta + minJuice - 50 << endl;
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1160
/*
  I_🧡🧡🧡_QMsh
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using namespace __gnu_pbds; // gp_hash_table<int, int> table;

template <typename T> void smin(T &a, const T &b) { a = (a < b ? a : b); }
template <typename T> void smax(T &a, const T &b) { a = (a > b ? a : b); }

typedef long long ll;
typedef long double ld;

signed main()
{
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m, a, b;
  cin >> n >> m >> a >> b;
  vector <vector <int>> mt(n, vector <int> (m));
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < m; j++)
    {
      mt[i][j] = 1 ^ (i >= b) ^ (j < a); 
    }
  }

  for (int i = 0; i < m; i++)
  {
    int sum = 0;
    for (int j = 0; j < n; j++)
      sum += mt[j][i];
    if (min(sum, n - sum) != b)
      return cout << -1, 0;
  }

  for (auto i : mt)
  {
    for (int j : i)
      cout << j;
    cout << '\n';
  }



  return 0;
}

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

using namespace std;


int main(){
    ll n;
    cin >> n;
    
    ll max = 100000000000000000;
    for(ll i = 1; i <= (ll)sqrt(n); i++){
        if((n%i) == 0) {
            ll path = ((i)+(n/i));
            if(max > path) {
                max = path-2;
            }
        }
    }
    
    cout << max << endl;
}


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

const int K = 10000;
bool XC[3*K], YC[3*K], XCN[3*K], YCN[3*K];

int main() {
    string S; int N, X, Y;
    cin >> S >> X >> Y;
    N = S.size();

    bool mode = 0;
    vector<int> xs, ys;
    int x = N, cnt = 0;
    for(int i=0; i<N; i++) {
        if(S[i] == 'T') {x = i; break;}
        ++cnt;
    }
    XC[cnt + K] = YC[K] = 1;
    for(int i=x, c=0; i<N; i++) {
        if(S[i] == 'T') {
            if(c) {
                if(mode) ys.push_back(c);
                else xs.push_back(c);
                c = 0;
            }
            mode = !mode;
        }
        else {
            ++c;
            if(i == N-1 && c) {
                if(mode) ys.push_back(c);
                else xs.push_back(c);
            }
        }
    }
    for(auto& it: xs) {
        for(int i=-8000; i<=8000; i++) if(XC[i + K]) XCN[i - it + K] = XCN[i + it + K] = 1;
        for(int i=-8000; i<=8000; i++) XC[i + K] = XCN[i + K], XCN[i + K] = 0;
    }
    for(auto& it: ys) {
        for(int i=-8000; i<=8000; i++) if(YC[i + K]) YCN[i - it + K] = YCN[i + it + K] = 1;
        for(int i=-8000; i<=8000; i++) YC[i + K] = YCN[i + K], YCN[i + K] = 0;
    }
    if(XC[X + K] && YC[Y + K]) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>

static const int MAX=100;
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

using namespace std;

int adj[MAX+1][MAX+1];
int color[MAX+1],d[MAX+1],f[MAX+1];
int n;
int t=0;

void dfs(int u){
  color[u]=GRAY;
  d[u]=++t;
  for(int i=1;i<=n;i++){
    if(adj[u][i]==1 && color[i]==WHITE) dfs(i);
  }
  color[u]=BLACK;
  f[u]=++t;
}

void dfs_init(){
  for(int i=1;i<=n;i++) color[i]=WHITE;
  for(int i=1;i<=n;i++){
    if(color[i]==WHITE) dfs(i);
  }
}

int main(){
  cin >> n;
  for(int i=1;i<=n;i++){
    int u,k; cin >> u >> k;
    for(int i=1;i<=n;i++) adj[u][i]=0;
    for(int i=0;i<k;i++){
      int v; cin >> v;
      adj[u][v]=1;
    }
  }
  dfs_init();
  for(int id=1;id<=n;id++){
    printf("%d %d %d\n",id,d[id],f[id]);
  }
}

Measured memory_bytes: 3232
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as MV
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Data.Char
import Data.IORef
import Data.List
import Data.Maybe

main = do
  n <- getInt
  as <- getIntVec n
  v <- MV.replicate (10^5+1) 0 :: IO (MV.IOVector Int)
  s <- newIORef 0
  V.forM_ as $ \i -> do
    modifyIORef s (+i)
    MV.modify v (+1) i
  q <- getInt
  replicateM_ q $ do
    (b, c) <- getIntPair
    m <- MV.read v b
    modifyIORef s (+ ((c - b) * m))
    MV.write v b 0
    MV.modify v (+m) c
    print =<< readIORef s

  
getInt :: IO Int
getInt = readLn

second :: (b -> c) -> (a, b) -> (a, c)
second f (a, b) = (a, f b)

readInt :: BS.ByteString -> Maybe (Int, BS.ByteString)
readInt = fmap (second BS.tail) . BS.readInt

getIntVec :: Int -> IO (V.Vector Int)
getIntVec n = V.unfoldrN n readInt <$> BS.getLine

getIntList :: IO [Int]
getIntList = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

getIntPair :: IO (Int, Int)
getIntPair = do
  v <- getIntVec 2
  return (v V.! 0, v V.! 1)


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

using namespace std;

class UnionFind {
    vector<int> data;
public:
    UnionFind(int n):data(n, -1){}
    int root(int x){
        return data[x] < 0? x: data[x] = root(data[x]);
    }
    bool unite(int x, int y){
        x = root(x); y = root(y);
        if(x == y)return false;
        if(data[y] < data[x])swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }
    bool same(int x, int y){
        return root(x) == root(y);
    }
};

int main(){
    int n, q;
    cin >> n >> q;
    UnionFind uf(n);
    while(q--){
        int com, x, y;
        cin >> com >> x >> y;
        if(com)cout << uf.same(x, y) << '\n'; else uf.unite(x, y);
    }
    return 0;
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
int main()
{
    ll n,k,i,sum;
    while(cin>>n>>k)
    {
        ll a[n+5];
        for(i=0;i<n;i++)
        {
            cin>>a[i];
        }
        sort(a,a+n);
        sum=0;
        for(i=0;i<k;i++)
        {
            sum+=a[i];
        }
        cout<<sum<<endl;
    }
    return 0;
}


Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;

namespace College
{
    class Program
    {
        static string Join(int[] input)
        {
            string result = "";
            foreach(int i in input)
                result += (" " + i.ToString());
            return result;
        }

        static void Main(string[] args)
        {
            List<List<int[]>> college = new List<List<int[]>>();

            for(int i = 0; i < 4; i++)
            {
                college.Add(new List<int[]>());
                for(int j = 0; j < 3; j++)
                {
                  college[i].Add(new int[10]);
                  for(int k = 0; k < 10; k++)
                      college[i][j][k] = 0;
                }          
            }

            int limit = int.Parse(Console.ReadLine());

            for(int i = 0; i < limit; i++)
            {
                int[] _c = Console.ReadLine().Split(' ').Select(e => int.Parse(e)).ToArray();
                college[_c[0] - 1][_c[1] - 1][_c[2] - 1] = college[_c[0] - 1][_c[1] - 1][_c[2] - 1] + _c[3];
            }

            for(int j = 0; j < college.Count; j++)
            {
                List<int[]> b = college[j];
                foreach(int[] r in b)
                    Console.WriteLine(Join(r));
                if(j != college.Count - 1)
                    Console.WriteLine(new string('#', 20));
            }
        }
    }
}

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

int main() {

	int64_t H, W;
	cin >> H >> W;

	if (H == 1 || W == 1)
		cout << 1;

	else if (H % 2 == 0 || W % 2 == 0)
		cout << (H * W) / 2;

	else if (H % 2 != 0 && H % 2 != 0)
		cout << ((H * W) +1) / 2;


	}


Measured memory_bytes: 256
from collections import deque
import sys
sys.setrecursionlimit(10 ** 9)

h, w = map(int, input().split())
maze = [[-1 for i in range(w)] for j in range(h)]

ans = 0
for i in range(h):
    maze[i] = list( map(int, input().split()))


queue = deque()

ansN = 0
ans = []

for i in range(h):
    for j in range(w):
        if maze[i][j] % 2 != 0:
            if j+1 < w:
                maze[i][j] -= 1
                maze[i][j+1] += 1
                ansN+=1
                ans.append([i+1, j+1, i+1, j+2])

            elif i+1 < h:
                maze[i][j] -= 1
                maze[i+1][j] += 1
                ansN+=1
                ans.append([i+1, j+1, i+2, j+1])

print(ansN)

for i in range(ansN):
    print(*ans[i], sep =' ')



Measured memory_bytes: 75356