akhauriyash/Code-Regression huggingface dataset:
/**
 * Created by Sakib on 06/16/2018.
 */
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define debug(args...) { dbg,args; cerr<<"\n"; }
template <typename T>
using orderset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
struct debugger{
template<typename T>debugger& operator,(const T& v){cerr<<v<<" ";return *this;}}dbg;

#define Fix( x ) setprecision( x ) << fixed
#define mem( a , x ) memset( a , x , sizeof( a ) )
#define bug( a , b ) cerr<< #a <<" = "<<a<<" , "<< #b <<" = "<<b<<"\n";
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define FOR( i , a , b ) for( int i = a; i <= b; i++ )
#define ROF( i , a , b ) for( int i = a; i >= b; i-- )
#define sz( V ) (int)V.size( )
#define all( V ) V.begin( ),V.end( )
#define Found( S , val ) S.find( val ) != S.end( )
#define Unique( V ) sort( all( V ) ), V.erase( unique( all( V ) ), V.end() )
typedef pair < int , int > ii;
typedef pair < int , ii > iii;
typedef long long int LL;
typedef unsigned long long uLL;
const int inf = (int)1e9;
const LL INF = (LL)1e18;
const int N = 100005;
const int mod = 1000000007;
const double eps = 1e-8;
const double pi = acos( -1.0 );

int d , n;
vector < LL > V;

bool ok( LL n , int t ) {
    int cnt = 0;
    while( n%100 == 0 ) n /= 100 , cnt++;
    return ( cnt == t );
}
int main( int argc, char const *argv[] ) {
    fast_io;
    cin >> d >> n;
    if( d == 0 ) {
        for( LL i = 1; i <= 10000000; i++ ) {
            if( i%100 != 0 ) V.pb( i );
            if( sz(V) >= 100 ) break;
        }
        cout << V[n-1] << endl;
    }
    if( d == 1 ) {
        for( LL i = 100; i <= 1000000000; i += 100 ) {
            if( ok(i,1) ) V.pb( i );
            if( sz(V) >= 100 ) break;
        }
        //for( auto x : V ) cout << x << " ";
        cout << V[n-1] << endl;
    }
    if( d == 2 ) {
        for( LL i = 1000; i <= 1000000000; i += 1000 ) {
            if( ok(i,2) ) V.pb( i );
            if( sz(V) >= 100 ) break;
        }
        //for( auto x : V ) cout << x << " ";
        cout << V[n-1] << endl;
    }
    return 0;
}








Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <cmath>
#include <tuple>
#include <cassert>
#include <array>
#include <iomanip>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using ti = tuple<int, int, int>;

#define REP(i,m,n) for(int i=(m); i<(n); i++)
#define RREP(i,n,m) for(int i=(n);i>=(m); i--)
#define pb push_back
#define mp make_pair
#define debug(x) cerr << #x << ": " << x << endl
// #define int long long 

const double eps=1e-14;
const int mod = 1e9 + 7;
const int inf = ((1<<30)-1);
const ll linf = (1LL<<60);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    bool ok = false;
    REP(i,1,10)
    {
      REP(j,1,10)
      {
        if(i*j == n) ok = true;
      }
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 2e3 + 5;
const ll LINF = 1e18 + 5;
int h, w;
char s[N][N];
int cnt[N][N]; 
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin >> h >> w;
 	for(int i=1; i<=h; i++)
 		cin >> (s[i]+1);
 	for(int i=1; i<=h; i++)
 	{
 		for(int j=1; j<=w; )
 		{
 			if(s[i][j]=='#') 
 				j++;
 			else
 			{
 				int k = j + 1;
 				while(k<=w && s[i][k]=='.') k++;
 				for(int t=j; t<k; t++) cnt[i][t] += k-j;
 				j = k;
 			}
 		}
 	}
 	for(int j=1; j<=w; j++)
 	{
 		for(int i=1; i<=h; )
 		{
 			if(s[i][j]=='#') 
 				i++;
 			else
 			{
 				int k = i + 1;
 				while(k<=h && s[k][j]=='.') k++;
 				for(int t=i; t<k; t++) cnt[t][j] += k-i;
 				i = k;
 			}
 		}
 	}
 	int ans = 0;
 	for(int i=1; i<=h; i++) for(int j=1; j<=w; j++) ans = max(ans, cnt[i][j]);
 	cout << max(0, ans-1);
	return 0;
}


Measured memory_bytes: 19840
import java.util.Scanner;

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

		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());

		int sum = 1;
		int count = 0;

		while(sum < b) {
			sum += (a-1);
			count++;
		}

		System.out.println(count);

	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    int n;
    cin >> n;
    vector<pair<int, int>> s(n);
    rep(i, n) cin >> s[i].first >> s[i].second;
    set<pair<int, int>> pq;
    rep(i, n) {
        rep(ii, n) {
            if (i == ii) continue;
            pq.emplace(s[ii].first - s[i].first, s[ii].second - s[i].second);
        }
    }
    int mx = 0;
    for (auto v : pq) {
        int p = v.first;
        int q = v.second;
        int tmp = 0;
        rep(i, n) {
            pair<int, int> s1 = s[i];
            rep(ii, n) {
                if (i == ii) continue;
                pair<int, int> s2 = s[ii];
                if (s1 == s2) continue;
                if (((s2.first - s1.first) == p) && ((s2.second - s1.second) == q)) tmp++;
            }
        }
        mx = max(tmp, mx);
    }
    cout << (n - mx) << endl;
    return 0;
}


Measured memory_bytes: 384
import sys
N = input()
array_hon = [2,4,5,7,9]
array_pon = [0,1,6,8]
array_bon = [3]

if not ( int(N) <= 999 ): sys.exit()

if int(N[-1]) in array_hon: print('hon')
if int(N[-1]) in array_pon: print('pon')
if int(N[-1]) in array_bon: print('bon')


Measured memory_bytes: 9056
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif

    int n, k;
    cin >> n >> k;

    if (k == 1)
        cout << 0 << endl;
    else
        cout << n - k << endl;

}

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

int main()
{
    int plugNum, need;
    cin >> plugNum >> need;
    if (2 <= plugNum && plugNum <= 20)
    {
        if (1 <= need && need <= 20)
        {
            if (need <= 1) {
                cout << 0 << endl;
                return 0;
            }
            int ans = 0;
            for(ans = 1; ;ans++) {
                int counter = (plugNum - 1) * ans + 1;
                if(counter >= need) {
                    break;
                }
            }
            cout << ans << endl;
        }
    }
}

Measured memory_bytes: 256
def main():
    N, A = map(int, input().split())
    x = [0]
    x.extend(list(map(int, input().split())))

    dp = [[[0] * (N * A + 1) for _ in range(N + 1)] for _ in range(N + 1)]
    for i in range(N + 1):
        dp[i][0][0] = 1

    for i in range(1, N + 1):
        for j in range(1, i + 1):
            for k in range(1, N * A + 1):
                if k < x[i]:
                    dp[i][j][k] = dp[i - 1][j][k]
                else:
                    dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - x[i]]

    ans = 0
    for j in range(1, N + 1):
        ans += dp[N][j][A * j]

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 91484
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<stdbool.h>
#include<set>
#define N 1000000007
using namespace std;
typedef long long ll;
int num[100001];
int main(void) {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a + b == c + d)cout << "Balanced" << endl;
	if (a + b > c + d)cout << "Left" << endl;
	if (a + b < c + d)cout << "Right" << endl;
	return 0;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()

day = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]

for i in range(7):
	if day[i] == S:
		print(7-i)
		sys.exit()


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

int main(){

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

    rep(i,n){
        cin >> a[i];
    }

    vector<int> c;
    int ans=0;

    int id=0;
    while(id<n){
        if(a[id]==c.size()+1){
            c.push_back(a[id]);
        }
        id++;
    }

    if(c.size()==0){
        cout << -1 << endl;
        return 0;
    }

    cout << (int)a.size()-c.size() << endl;

    return 0;
}

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

int main()
{
    int N;
    int maxV[] = {0, 0};
    int maxCt[] = {0, 0};
    vector<int> A;
    cin >> N;
    for (int i=1; i<N+1; i++) {
        int a;
        cin >> a;
        if (a == maxV[0]) {
            maxCt[0]++;
        } else if (a == maxV[1]) {
            maxCt[1]++;
        } else if (a > maxV[0]) {
            maxV[1] = maxV[0];
            maxCt[1] = maxCt[0];

            maxV[0] = a;
            maxCt[0] = 1;
        } else if (a > maxV[1]) {
            maxV[1] = a;
            maxCt[1] = 1;
        }
        A.push_back(a);
    }

    // cout << maxV[0] << ", " << maxV[1] << endl;
    // cout << maxCt[0] << ", " << maxCt[1] << endl;
    
    for (int i=0; i<N; i++) {
        if (A[i] == maxV[0]) {
            if (maxCt[0] > 1) {
                cout << maxV[0] << endl;
            } else {
                cout << maxV[1] << endl;
            }
        } else {
            cout << maxV[0] << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 2548
#include <bits/stdc++.h>
 
using namespace std;
#define int long long
const int MAX = 2001;
const int MOD = 1000000007;
 
 

 
signed main(){
    int n,a,b;
    cin>>n>>a>>b;
    cout<<min(b,a*n);
    
  
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) ((a).begin(), (a).end())
typedef long long ll;
// const long long INF = 1LL << 60;
const int INF = 1010101010;
using Graph = vector<vector<int>>;
const int MOD = 1000000007;

int main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<ll> p(a);
  vector<ll> q(b);
  vector<ll> r(c);
  rep(i, a) cin >> p[i];
  rep(i, b) cin >> q[i];
  rep(i, c) cin >> r[i];
  SORT(p);
  RSORT(p);
  SORT(q);
  RSORT(q);
  vector<ll> k;
  for (int i = 0; i < x; i++) {
    r.push_back(p[i]);
  }
  for (int i = 0; i < y; i++) {
    r.push_back(q[i]);
  }
  ll ans = 0;
  SORT(r);
  RSORT(r);
  rep(i, x + y) { ans += r[i]; }
  cout << ans << endl;
}

Measured memory_bytes: 6512
struct Scanner {
    handle: std::io::Stdin,
    buffer: std::collections::VecDeque<String>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner {
            handle: std::io::stdin(),
            buffer: std::collections::VecDeque::new(),
        }
    }
    fn next<T: std::str::FromStr>(&mut self) -> Result<T, T::Err> {
        if self.buffer.len() == 0 {
            loop {
                let mut available = String::new();
                self.handle.read_line(&mut available).unwrap();
                self.buffer = available.split_whitespace().map(String::from).collect();
                if self.buffer.len() > 0 {
                    break;
                }
            }
        }
        T::from_str(&self.buffer.pop_front().unwrap())
    }
}

fn main() {
    let mut scanner = Scanner::new();
    let n: usize = scanner.next().unwrap();
    let mut av = Vec::<i32>::new();
    let mut bv = Vec::<i32>::new();
    for _ in 0..n {
        av.push(scanner.next().unwrap());
        bv.push(scanner.next().unwrap());
    }
    av.sort();
	bv.sort();
	#[cfg(debug_assertions)] dbg!(&av, &bv);
    let total;
    if n % 2 == 1 {
        let min = av[(n - 1) / 2];
        let max = bv[(n - 1) / 2];
        total = max - (min - 1);
    } else {
        let min = av[(n - 1) / 2] + av[n / 2];
        let max = bv[(n - 1) / 2] + bv[n / 2];
        total = max - (min - 1);
    }
    println!("{}", total);
}


Measured memory_bytes: 4096
# coding: utf-8
# Your code here!
def main():
    N = int(input())
    A_array = tuple(map(int, input().split()))
    
    if 0 in A_array:
        print("0")
        return 0
        
    ans = 1
    for A in A_array:
        ans *= A
        if ans > 10 ** 18:
            print("-1")
            return 0
            
    print(ans)

main()

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

using vi = vector<int>;
using vl = vector<long long int>;
using vii = vector<vector<int>>;
using vll = vector<vector<long long int>>;
#define pb push_back;
#define mp make_pair;
ll powM(ll a,ll b,ll m)
{
    ll ans=1;
    a%=m;
    while(b)
        {
            if(b&1)ans=ans*a%m;
            a=a*a%m;
            b>>=1;
        }
        return ans;
}



int main(){
      ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.precision(2);
cout<<fixed;
string s;cin>>s;
int n=s.length();
vi store(n+1);
for(int i=0;i<n;i++)
{
     store[i+1]=powM(10,n-i-1,2019);
     store[i+1]=(store[i+1]*(s[i]-'0'))%2019;
    // if(store[i]>=1015)store[i]-=2019;
}
vi cum(n+1);
for(int i=1;i<=n;i++)
{
  cum[i]=(cum[i-1]+store[i])%2019;
}
/*unordered_set<int>se;
se.insert(0);
int cnt=0;
for(int i=1;i<=n;i++)
{
  if(se.count(cum[i]))cnt++;
  else se.insert(cum[i]);
  
}

cout<<cnt<<"\n";*/
map<int,int>m;
int cnt=0;
for(int i=0;i<=n;i++)m[cum[i]]++;
  for(auto x:m)
  {
    cnt +=(x.second)*(x.second-1)/2;
  }
  cout<<cnt<<"\n";

return 0;


}


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

using namespace std;
int main(){
    int A, B;
    cin >> A >> B;

    if(A >= 13)cout << B;
    else if(A > 5)cout << B/2;
    else cout << 0;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+5;
const long long mod=1e9+7;
long long Sort[maxn];
long long ans[maxn];
int dir[9][2]={{-2,-2},{-1,-2},{0,-2},{-2,-1},
         {-1,-1},{0,-1},{-2,0},{-1,0},{0,0}};
int tot;
int main(){
	long long H,W,N;
	scanf("%lld%lld%lld",&H,&W,&N);
	long long Ans=(long long)(H-2)*(long long)(W-2);
	for(int i=0;i<N;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		for(int j=0;j<9;j++)
		{
			int xx=x+dir[j][0];
			int yy=y+dir[j][1];
			if(xx>=1 && xx<=H-2 && yy>=1 && yy<=W-2)
			   Sort[tot++]=xx*mod+yy;
		}
	}
	sort(Sort,Sort+tot);
	int cnt=1;
	for(int i=0;i<tot;i++)
	{
		if(Sort[i]==Sort[i+1])cnt++;
		else
		   ans[cnt]++,cnt=1,Ans--;
	 } 
	printf("%lld\n",Ans);
	for(int i=1;i<=9;i++) 
	  printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 8960
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int N;
  	char c;
  	
  	cin >> N;
  	bool flag = false;
  
  	for(int i = 0; i < N; i++) {
    	cin >> c;
      	if ( c == 'Y' ) flag = true;
    }
  
  	if (flag) {
       	cout << "Four" << endl;
    } else {
        cout << "Three" << endl;
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
//const int N = 1e5 + 5;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    int n,m;
    cin>>n>>m;
    string ans;
    if(n<m)
    while(m--){
        ans+=to_string(n);
    }
    else
    while(n--){
        ans+=to_string(m);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n,w = readline() |> split |> parseMap
	a = Tuple{Int,Int}[(0,0) for i in 1:n]
	s = 0
	for i in 1:n
		p,q = readline() |> split |> parseMap
		a[i] = (p,q)
		s += q
	end
	dp = 10^18*ones(Int,n+1,s+1)
	dp[1,1] = 0
	for i in 1:n
		for j in 1:s+1
			if dp[i,j] >= 0
				dp[i+1,j] = min(dp[i+1,j],dp[i,j])
				if j+a[i][2]<=s+1
					dp[i+1,j+a[i][2]] = min(dp[i+1,j+a[i][2]],dp[i,j+a[i][2]],dp[i,j]+a[i][1])
				end
			end
		end
	end
	o = 0
	for i in 1:n+1
		for j in 1:s+1
			if dp[i,j]<=w
				o = max(o,j-1)
			end
		end
	end
	println(o)
end

main()

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

int main()
{
	int n,d;
	cin>>n>>d;
	int a[n+1]={0};
	while(d--)
	{
		int b,c;
		cin>>b;
		while(b--){
		cin>>c;
		a[c]++;}
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]==0)
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3636
#include<cstdio>
#include<list>
#include<algorithm>
using namespace std;

int main(){
    int q,x;
    char com[20];
    list<int>v;
    scanf("%d",&q);
    for(int i=0;i<q;i++){
        scanf("%s",com);
        if(com[0]=='i'){
            scanf("%d",&x);
            v.push_front(x);
        }else if(com[6]=='L'){
            v.pop_back();
        }else if(com[6]=='F'){
            v.pop_front();
        }else if(com[0]=='d'){
            scanf("%d",&x);
            for(list<int>::iterator it=v.begin(); it !=v.end();it++){
                if(*it==x){
                    v.erase(it);
                    break;
                }
            }
        }
    }
    int i=0;
    for(list<int>::iterator it=v.begin(); it!=v.end();it++){
        if(i++)printf(" ");
        printf("%d",*it);
    }
    printf("\n");
    return 0;
}



Measured memory_bytes: 33980
#include <iostream>
#include <stack>
using namespace std;
string s;
stack<char> st;
int main() {
	cin>>s;
	for(int i=0; s[i]; i++) {
		if(st.empty() || s[i]==st.top()) st.push(s[i]);
		else st.pop();
	}
	cout<<(int)s.size() - (int)st.size();
	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<string>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<bitset>

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int main(){
    int n;
    int u,v;
    long long int w;
    scanf("%d",&n);
    vector<pair<int,long long int>> list[100005];
    REP(i,n){
        scanf("%d%d%lld",&u,&v,&w);
        list[u-1].push_back(make_pair(v-1,w));
        list[v-1].push_back(make_pair(u-1,w));
    }
    int visited[100005]={};
    REP(i,100005)visited[i]=-1;
    int node[100005]={};
    queue<int> que;
    node[0]=0;
    que.push(0);
    while(!que.empty()){
        int now=que.front();
        que.pop();
        visited[now]=1;
        for(pair<int,long long int> pair : list[now]){
            if(visited[pair.first]==-1){
                if(pair.second%2==0){
                    node[pair.first]=node[now];
                }
                else{
                    node[pair.first]=1-node[now];
                }
                que.push(pair.first);
            }
        }
    }
    REP(i,n){
        printf("%d\n",node[i]);
    }
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll n, m, diff, ans;
  cin >> n >> m;

  if (2 * n < m) {
    diff = (m / 2 - n) / 2;
    ans = n + diff;
  } else {
    ans = m / 2;
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char str[10];
int main() {
    int sum;
    scanf("%s", str);
    for (int i = 0; i < 8; i++) {
        sum = str[0] - '0';
        for (int j = 0; j < 3; j++) {
            if ((i >> j) & 1) sum += str[j + 1] - '0';
            else sum -= str[j + 1] - '0';
        }
        if (sum == 7) {
            for (int j = 0; j < 3; j++) {
                printf("%c", str[j]);
                if ((i >> j) & 1) printf("+");
                else printf("-");
            }
            printf("%c=7\n", str[3]);
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define Pint pair<int, int>
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int main() {
    int N; cin >> N;
    int a[N]; rep(i, N) cin >> a[i];
    sort(a, a + N);
    map<int, int>m;
    rep(i, N) {
        m[a[i]] = i;
    }
    if(m.size() > 2) {
        cout << "No" << endl;
        return 0;
    }
    if(m.size() == 1) {
        if(a[0] == N - 1 || N % a[0] == 0) {
            cout << "Yes" << endl;
        }else {
            cout << "No" << endl;
        }
    }else {
        int colorNum = m[a[0]] + 1;
        int nokori = a[N - 1] - colorNum;
        if(nokori <= 0) {
            cout << "No" << endl;
        }else if(a[0] + 1 == a[N - 1] && (N - m[a[0]] - 1) % nokori == 0) {
            cout << "Yes" << endl;
        }else {
            cout << "No" << endl;
        }
    }
}


Measured memory_bytes: 5376
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int n;
    cin >> n;
    int a;
    map<int, int> m;
    rep (i, n)
    {
        cin >> a;
        ++m[a];
    }

    int ans = 0;
    for (auto x : m)
    {
        if (x.second & 1) ++ans;
    }

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



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

using namespace std;
//using namespace std::chrono;

#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vll vector<long long>

typedef long long ll;

void print(vi v){
    cout<<"Contents of vector:\n";
    for(auto x : v) cout<<x<<" ";
    cout<<endl<<endl;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); //cout.tie(nullptr);
    //ifstream cin("lmio_1991_3e1_seka_01.in"); ofstream cout("lmio_1991_3e1_seka_01.out");///cia failai

    //int T; cin>>T;
    int T = 1;

    for(int it = 1; it<=T; it++){
        int n; cin>>n;
        string s; cin>>s;
        int cnt = count(s.begin(), s.end(), 'W');
        if(n - cnt == 0){
            cout<<"0"<<endl;
            return 0;
        }
        //cout<<"Count "<<cnt<<endl;
        int t = cnt;
        for(int i = 1; i<=t; i++){
            int it = n-i;
            //cout<<"s at "<<it<<" : "<<s[it]<<endl;
            if(s[it] == 'W') cnt--;
        }
        cout<<cnt<<endl;

    }
}


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

int main(){
    int n;
    cin >> n;
    while(n!=0){
        int s, sum = 0, large = 0, small = 1000;
        for(int i=0;i<n;++i){
            cin >> s;
            sum+=s;
            if(large<s) large=s;
            if(small>s) small=s;
        }

        cout<<(sum-large-small)/(n-2)<<"\n";

        cin >> n;
    }
}

Measured memory_bytes: 3060
//dice and coin
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <stdio.h>
using namespace std;
int main(int argc, char const *argv[])
{
	int n,k;
	cin>>n>>k;
 	double ans = 0;
	// if(n>k){
	// 	ans += double((n-k)/n);
	// }
 	vector<int> s;
 	int max_s;
	for(int i=1;i<=n;i++){
		int tmp=i;
		int shisu;
		for(int j=0;true;j++){
			if(k<=tmp){
				shisu=j;
				break;
			}
			tmp*=2;
		}
		if(i==1) max_s=shisu;
		s.push_back(shisu);
	}
	int bunshi = 0;
	for (int i = 0; i < n; ++i)
	{
		bunshi+=pow(2,(max_s-s[i]));
	}
	ans = double(bunshi/(n*pow(2,max_s)));
	printf("%.12f",ans);

	return 0;
}

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

using namespace std;

int* bubbleSort(int* N, int len){
  int i,j;
  int ans = 0;

  for(i=0; i<len; i++){
    for(j=len-1; j>i; j--){
      if(N[j] < N[j-1]){
        int temp = N[j];
        N[j] = N[j-1];
        N[j-1] = temp;
        ans++;
      }
    }
  }

  cout << ans << endl;

  return N;
}

int main(void){
    string s;
    long long int ans = 0;
    // int _ans = 0;
    int WCount = 0;
    int a[200000] = {0};
    cin >> s;
    /*
    for(int i = 0; i < s.length(); i++){
        if(s[i] == 'B'){
            a[i]++;
        }
    }
    */
    
    for(int i = 0; i < s.length(); i++){
        if(s[i] == 'W'){
            ans += i - WCount;
            // cout << ans << endl;
            WCount++;
        }
    }

    // bubbleSort(a, s.length());

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include<string>
#include<iostream>
using namespace std;
int x[7];

void swap(int* x, int* y){
    *x += *y;
    *y = *x - *y;
    *x -= *y;
}
void roll(int* a, int* b){
    swap(x+1, a);
    swap(a, x+6);
    swap(x+6, b);
}
int main(){
    string str;
    for(int i=1; i<7; i++)
        cin >> x[i];
    cin >> str;
    for (int i = 0; i < str.length(); i++)
    {
        switch(str[i]){
            case 'E': roll(x+4, x+3); break;
            case 'N': roll(x+2, x+5); break;
            case 'S': roll(x+5, x+2); break;
            case 'W': roll(x+3, x+4); break;
        }
    }
    cout << x[1] <<endl;
}


Measured memory_bytes: 3224
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct GuideData {
	int index;
	char S[11];
	int  point;
};

int GuidSort(const void *a, const void *b) {
  int a_cmp, b_cmp;
  GuideData *A, *B;
  A =  (GuideData *)a;
  B =  (GuideData *)b;
  a_cmp = strcmp(A->S, B->S);
  if (a_cmp != 0) {
	  return a_cmp;
  }
  b_cmp = B->point - A->point;
  return  b_cmp;
}

int main(void)
{
     GuideData *data;
	 int N, i;

	 scanf("%d", &N);

	 data = (GuideData *)malloc(sizeof(GuideData)*N);

	 for (i = 0; i < N; i++) {
		 scanf("%s %d", data[i].S, &(data[i].point));
		 data[i].index = i + 1;
	 }

    qsort(data, N, sizeof(GuideData),  GuidSort);

	 for (i = 0; i < N; i++) {
		 printf("%d\n", data[i].index);
	 }
	free(data);

	return 0;

}


Measured memory_bytes: 128
using System;

namespace atcoderA
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int m = int.Parse(input[1]);
            Console.WriteLine((n - 1) * (m - 1));
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <stdio.h>
using namespace std;

typedef long long LL;

int main () {
	LL n,m;
	while (scanf("%lld %lld",&n,&m) != EOF) {
		LL L=0,R=1e12 + 1;
		while (R-L!=1) {
			LL mid=(L+R)>>1;
			LL need_n = mid-n;
			LL tmp=m;
			if (need_n > 0) {
				tmp -= 2*need_n;
			}
			if (tmp >= mid*2) L=mid;
			else R=mid;
		}
		printf("%lld\n",L);
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    for(;;){
        long long int n[114514]={0},l=0,sa=0,p=0,a,b,c,d,flg=0,nsa=0;
        cin>>l;
        if(l==0)break;
        for(int i=0;i<l+1;i++){
            cin>>n[i];
        }
        for(int i=0;i<l+1;i++){
            if(i==0)sa=n[2]-n[1];
            else if(i==l)sa=n[1]-n[0];
            else sa=n[i+1]-n[i-1];
            for(int j=0;j<l;j++){
                if(i==l-1&&j==l-1){
                    cout<<n[i]<<endl;
                    flg=1;
                    break;
                }
                if(i==0&&j==0)continue;
                if((j==i-1||j==i)&&i!=0)continue;
                nsa=n[j+1]-n[j];
                if(j==i)nsa=n[j+1]-n[j-1];
                if(nsa!=sa)break;
                if(i==l&&j==l-2){
                    cout<<n[i]<<endl;
                    flg=1;
                    break;
                }
                if(j==l-1){
                    cout<<n[i]<<endl;
                    flg=1;
                    break;
                }
            }
            if(flg)break;
        }
    }
return 0;
}

Measured memory_bytes: 2060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll n;
  cin >> n;
  vec a(n);
  for(ll i=0;i<n;i++) cin >> a[i];
  ll cnt=0;
  for(ll i=0;i<n;i++) {
    while(a[i]%2==0) {
      a[i]/=2;
      cnt++;
    }
  }
  cout << cnt << endl;
}

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

int n, m, q;
vector<long long> a, b, c, d;
long long answer = 0;

long long ans(vector<int> A) {
  long long res = 0;
  for (int i = 0; i < q; i++) {
    if (A[b[i]] - A[a[i]] == c[i]) {
      res += d[i];
    }
  }

  return res;
}

long long dfs(vector<int> &A) {
  if (A.size() == n) {
    ans(A);
    return ans(A);
  }
  long long res = 0;
  int pre_value = (A.empty() ? 0 : A.back());

  for (int i = pre_value; i < m; i++) {
    A.push_back(i);
    res = max(res, dfs(A));
    A.pop_back();
  }
  return res;
}
int main() {
  cin >> n >> m >> q;
  a.resize(q);
  b.resize(q);
  c.resize(q);
  d.resize(q);
  for (int i = 0; i < q; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    --a[i];
    --b[i];
  }
  vector<int> A;

  cout << dfs(A) << endl;

  return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)
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;}

signed main() {
  INIT;
  VAR(int,n);
  VEC(int,p,n);

  vector<int> a(n,20001);
  REP(i,n){
    if(i>0)a[i] = a[i-1] + 20000;
    //debug(a[i]);
    --p[i];
  }

  vector<int> b(n,1e9);
  REP(i,n){
    if(i>0)b[i] = b[i-1] - 20000;
  }

  REP(i,n){
    a[p[i]] -= 20000-i;
  }

  bool isFirst = true;
  REP(i,n){
    if (!isFirst)cout<<" ";
    isFirst = false;
    cout<<a[i];
  }
  cout<<endl;

  isFirst = true;
  REP(i,n){
    if (!isFirst)cout<<" ";
    isFirst = false;
    cout<<b[i];
  }

  BR;

  
  return 0;
}


Measured memory_bytes: 1152
s = input()

for i in ['+', '-']:
    for j in ['+', '-']:
        for k in ['+', '-']:
            if eval(s[0] + i + s[1] + j + s[2] + k + s[3]) == 7:
                print(s[0] + i + s[1] + j + s[2] + k + s[3] + '=7')
                quit()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
#define F(i,L,R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define INF 2000000000
#define PI 3.1415926535897932384626
const ll MOD=1e9+7;
int main(){
        int h,w,n;
        while(~getIII(h,w,n)){
                int ans=n/max(h,w);
                printf("%d\n",ans+(n%max(h,w)!=0));
        }
}

Measured memory_bytes: 256
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix

# strlist = "abcdefghijklmnopqrstuvwxyz"

rows = [int(input()) for _ in range(6)]
k = rows.pop()

ans = "Yay!"
for i,v in enumerate(rows):
    for j in range(i+1,5):
        if rows[j] - v > k:
            ans = ":("
            break

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


Measured memory_bytes: 2940
//https://onlinejudge.u-aizu.ac.jp/challenges/sources/JOI/Prelim/0577?year=2013

#include <bits/stdc++.h>

using namespace std;

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

    int a[n], b[n], c[n];//a[i]:人iの1回目の回答
    vector<int> vta, vtb, vtc;//集計用
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i] >> c[i];
        vta.emplace_back(a[i]);
        vtb.emplace_back(b[i]);
        vtc.emplace_back(c[i]);
    }

    for (int i = 0; i < n; ++i) {
        int ans = 0;
        if (count(vta.begin(), vta.end(), a[i]) == 1) {
            ans += a[i];
        }
        if (count(vtb.begin(), vtb.end(), b[i]) == 1) {
            ans += b[i];
        }
        if (count(vtc.begin(), vtc.end(), c[i]) == 1) {
            ans += c[i];
        }
        cout << ans << endl;
    }

    return 0;
}

/*
 * 二重ループにすると混乱しそうなので愚直に書いた。
 * 
 */



Measured memory_bytes: 3148
#include<bits/stdc++.h>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define print(x) cout << (x) << endl;
#define printa(x, n) for(ll i = 0; i < n; i++) {cout << (x[i]) << " ";} cout << endl;
using namespace std;
using ll = long long;

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

    ll ans = 0;
    int n = s.size();

    
    int cntA = 0;
    bool len = false;
    for (int i = 0; i < n; i++) {   

        if (s[i] == 'A') {
            cntA++;

        }
        else if (i < n - 1) if (s[i] == 'B' && s[i + 1] == 'C') {
            ans += cntA;
            i += 1;
            len = true;
        }
        else {
            cntA = 0;
        }
        
        
        
    }

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

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

#define MAXN 200010
typedef long long ll;

const int INF = 1e9;
int b[MAXN];
vector<int> R[MAXN];

int tag[MAXN << 2], mi[MAXN << 2];

void maintain(int x)
{
	mi[x] = min(mi[x << 1], mi[x << 1 | 1]); 
}

void build(int x, int l, int r)
{
	if (l == r)
	{
		if (l == 0) mi[x] = 0;
		else mi[x] = INF;
		return;
	}
	int mid = (l + r) >> 1;
	build(x << 1, l, mid);
	build(x << 1 | 1, mid + 1, r);
	maintain(x);
}

void pushdown(int x)
{
	tag[x << 1] += tag[x];
	tag[x << 1 | 1] += tag[x];
	mi[x << 1] += tag[x];
	mi[x << 1 | 1] += tag[x];
	tag[x] = 0; 
}


void add(int x, int L, int R, int l, int r, int v)
{
	if (l <= L && r >= R)
	{
		tag[x] += v;
		mi[x] += v;
		return;
	}
	if (l > R || r < L) return;
	pushdown(x);
	int Mid = (L + R) >> 1;
	add(x << 1, L, Mid, l, r, v);
	add(x << 1 | 1, Mid + 1, R, l, r, v);
	maintain(x);
}

int querymin(int x, int L, int R, int l, int r)
{
	if (l <= L && r >= R) return mi[x];
	if (l > R || r < L) return INF;
	pushdown(x);
	int Mid = (L + R) >> 1;
	return min(querymin(x << 1, L, Mid, l, r), querymin(x << 1 | 1, Mid + 1, R, l, r));
}


void modify(int x, int l, int r, int pos, int v)
{
	if (l == r)
	{
		mi[x] = v;
		return;
	}
	pushdown(x);
	int mid = (l + r) >> 1;
	if (pos <= mid) modify(x << 1, l, mid, pos, v);
	else modify(x << 1 | 1, mid + 1, r, pos, v);
	maintain(x); 
}

int main()
{
 	//freopen("input", "r", stdin);
	//freopen("output", "w", stdout);
	
	int n, Q, l, r, ans = 0;
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
	{
		scanf("%d", &b[i]);
		if (b[i] == 0) b[i] = -1, ++ans;
		else b[i] = 1;
	}
	build(1, 0, n);
	scanf("%d", &Q);
	
	while (Q--)
	{
        scanf("%d %d", &l, &r);
		R[l].push_back(r); 	
    } 
    for (int i = 1; i <= n; ++i)
        sort(R[i].begin(), R[i].end());
    
  
    for (int i = 1; i <= n; ++i)
    {
    	for (int j = R[i].size() - 1; j >= 0; --j)
    	{
    		r = R[i][j];
    		modify(1, 0, n, r, querymin(1, 0, n, i - 1, r));
		}
		int tmp = querymin(1, 0, n, i - 1, i - 1) + b[i];
		tmp = min(tmp, querymin(1, 0, n, i, i));
		modify(1, 0, n, i, tmp);
	}
	cout << ans + querymin(1, 0, n, n, n) << endl;
    
 	return 0;
} 

Measured memory_bytes: 15872
<?php
	while(true) {
		$stdin = explode(" ", trim(fgets(STDIN)));
		$a = $stdin[0];
		$b = $stdin[2];
		$op = $stdin[1];

		switch($op) {
			case '+' : 
				echo $a + $b . PHP_EOL;
				break;
			case '-' :
				echo $a - $b . PHP_EOL;
				break;
			case '*' :
			   	echo $a * $b . PHP_EOL;
				break;
			case '/' :
			   	echo floor($a / $b) . PHP_EOL;
				break;
			case '?' :
				exit;
			default :
				break;
		}	
	}

Measured memory_bytes: 15304
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(ll i=0;i<N;i++)
typedef long long ll;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H,W;
    cin>>H>>W;
    vector<vector<int>>a(H,vector<int>(W));
    int A;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>A;
            if(A%2==0)a[i][j]=1;
            else a[i][j]=-1;
        }
    }
    vector<tuple<int,int,int,int>>sub;
    for(int i=0;i<H;i++){
        for(int j=0;j<W-1;j++){
            if(a[i][j]==-1){
                a[i][j]*=-1;
                a[i][j+1]*=-1;
                sub.pb(make_tuple(i+1,j+1,i+1,j+1+1));
            }
        }
    }
    for(int i=0;i<H-1;i++){
        if(a[i][W-1]==-1){
            a[i][W-1]*=-1;
            a[i+1][W-1]*=-1;
            sub.pb(make_tuple(i+1,W,i+2,W));
        }
    }
    cout<<sub.size()<<endl;
    for(int i=0;i<sub.size();i++){
        printf("%d %d %d %d\n",get<0>(sub[i]),get<1>(sub[i]),get<2>(sub[i]),get<3>(sub[i]));
    }
}

Measured memory_bytes: 5236
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
using P = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int Inf = (1 << 30);
ll inf = (1LL << 60);
const int MOD = 1e9 + 7;
ll souwa(ll x) {
	return x * (x - 1) / 2;
}
int main() {
	int n;
	cin >> n;
	V a(n + 1);
	VL sum(n + 1, 0);
	map<ll, int> mp;
	mp[0]++;
	int i;
	for (i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (i = 1; i <= n; i++) {
		sum[i] = sum[i - 1] + a[i];
		mp[sum[i]]++;
	}
	ll ans = 0;
	for (auto c : mp) {
		ans += souwa(c.second);
	}
	cout << ans << endl;
	return 0;
}

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

#define ll long long
#define eb emplace_back
#define nl '\n'
#define deb(x) cerr << #x" = " << x << nl
#define in() ( { int a ; scanf("%d", &a); a; } )

const int N = 3e5 + 9;
const int mod = 1e9 + 7;


int32_t main()
{
    double x; cin >> x;
    cout << fixed << setprecision(10) << x * x * x / 27.0 << nl;
    return 0;
}


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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e5 + 5);

int n;
ll h[MAX_N];

int memo[MAX_N];

int solve(int index) {
  if (memo[index] != -1) {
    return memo[index];
  }

  if (index == n - 1) {
    return memo[index] = 0;
  }

  if (h[index] >= h[index + 1]) {
    return memo[index] = solve(index + 1) + 1;
  }

  return memo[index] = 0;
}

int main(void) {
  // Here your code !
  scanf("%d", &n);
  
  for (int i = 0; i < n; ++i) {
    scanf("%lld", &(h[i]));
  }

  for (int i = 0; i < n; ++i) {
    memo[i] = -1;
  }

  int ans = -1;

  for (int i = 0; i < n; ++i) {
    ans = max(ans, solve(i));
  }

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

  return 0;
}


Measured memory_bytes: 2944
#include<iostream>
#include<cmath>
#include<numeric>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define int64 long long
#define modbig (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  int64 n,m;
  cin>>n>>m;
  int64 ans=0,a[n],sum[n];
  rep(i,n){
    cin>>a[i];
  }
  sum[0]=a[0]%m;
  rep1(i,n){
    sum[i]=(a[i]+sum[i-1])%m;
  }
  map<int64,int64> mp;
  mp[0]++;
  rep(i,n){
    mp[sum[i]]++;
  }
  for(auto p:mp){
    ans+=p.second*(p.second-1)/2;
  }
  cout<<ans;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll A[600][600];
ll B[600][600];
int main()
{
    ll k,i,j;
    string s;
    cin>>k>>s;
    if(s.length()<=k)
    {
        cout<<s<<endl;
    }
    else if(s.length()>k)
    {
        string a=s.substr(0,k);
        cout<<a<<"..."<<endl;
    }
    return 0;


}


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

int main(){
  int64_t H;
  cin >> H;

  int64_t ans = 0;

  int64_t cnt = 0;
  while(H > 0){
    H /= 2; 
    ans += pow(2,cnt);
    cnt++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
    int x,y,z; cin >> x >> y >> z;
    cout << z << " " << x << " " << y << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int n,m,i,s,c;
  int digit[3]={0},check[3]={0};
  int result=0;
  
  scanf("%d %d",&n,&m);
  
  /*
  if(n==1 && m>0){
    scanf("%d %d",&s,&c);
    printf("%d",c);
    return 0;
  } else if(n==1 && m==0){
    printf("0");
    return 0;
  }
  */
  
  for(i=0;i<m;i++){
    scanf("%d %d",&s,&c);
    if(n!=1&&s==1&&c==0 || check[s-1]!=0 && digit[s-1]!=c){
      result=-1;
      break;
    }
    
    digit[s-1]=c;
    check[s-1]=1;
  }
  
  if(result!=-1){
    if(n==1){
      result=digit[0];
    }
    
    if(n==2){
      if(check[0]==0){
        result=10+digit[1];
      } else {
        result=digit[0]*10+digit[1];
      }
    }
    
    if(n==3){
      if(check[0]==0){
        result=100+digit[1]*10+digit[2];
      } else {
        result=digit[0]*100+digit[1]*10+digit[2];
      }
    }
  }
  
  if(result!=-1){
	  printf("%d",result);
  } else {
    printf("-1");
  }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f

using namespace std;
typedef long long LL;


int main()
{
    int n,k;
    LL a[100005];
    while(scanf("%d%d",&n,&k)==2){
        for(int i=1;i<=n;i++){
            scanf("%lld",&a[i]);
        }
        LL l,r,ans=inf;
        for(int i=1;i+k-1<=n;i++){
            l=a[i],r=a[i+k-1];
            if(l*r>0){
                ans=min(ans,max(abs(l),abs(r)));
            }
            else{
                ans=min(ans,r-l+min(abs(l),abs(r)));
            }
        }
        printf("%lld\n",ans);
    }
    return 0;
}


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

using namespace std;

int main()
{
    int W, H, N;
    while (cin >> W >> H, W) {
        cin >> N;
        int x, y;
        vector<vector<int>> a(H, vector<int>(W, 1));
        for (int i = 0; i < N; i++) {
            cin >> x >> y;
            x--; y--;
            a[y][x] = 0;
        }

        int dp[25][25] = {{}};
        dp[0][0] = 1;
        for (int i = 1; i < H; i++) {
            if (a[i][0] == 1) {
                dp[i][0] += dp[i-1][0];
            } else {
                break;
            }
        }

        for (int i = 1; i < W; i++) {
            if (a[0][i] == 1) {
                dp[0][i] += dp[0][i-1];
            } else {
                break;
            }
        }
            
        for (int i = 1; i < H; i++) {
            for (int j = 1; j < W; j++) {
                if (a[i][j] == 0) continue;
                dp[i][j] = dp[i][j-1] + dp[i-1][j];
            }
        }
        cout << dp[H-1][W-1] << endl;
    }
    return 0;
}

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


def main():
    s = input()

    if s == "SUN":
        print(7)
    elif s == "MON":
        print(6)
    elif s == "TUE":
        print(5)
    elif s == "WED":
        print(4)
    elif s == "THU":
        print(3)
    elif s == "FRI":
        print(2)
    elif s == "SAT":
        print(1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

N = int(input())
K = int(input())
X = int(input())
Y = int(input())

if N <= K:
  print(N*X)
else:
  print(K*X + (N-K)*Y)



Measured memory_bytes: 38256