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

using namespace std;
#define pb push_back
#define db(x) cerr << #x << " = " << x << endl;
#define INF 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second
#define vi vector<int>
#define vll vector<ll>
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vii vector<pii>
#define ll long long
#define ull unsigned long long
typedef long double ld;

#define MAXN 312

int n;
int freq[4];
double dp[MAXN][MAXN][MAXN];
int vis[MAXN][MAXN][MAXN];

double solve(int a, int b, int c)
{
    if (a == 0 && b == 0 && c == 0)
        return 0;

    if (vis[a][b][c])
        return dp[a][b][c];
    vis[a][b][c] = 1;

    // Waste
    double p_waste = (n - (a + b + c))/double(n);
    dp[a][b][c] = p_waste / (1 - p_waste);
 
    // I will use at least 1 movement in this current state
    dp[a][b][c] += 1;

    if (a)
    {
        double p = a/double(a+b+c);
        dp[a][b][c] += p * solve(a - 1, b, c);
    }
    if (b)
    {
        double p = b/double(a+b+c);
        dp[a][b][c] += p * solve(a + 1, b - 1, c);
    }
    if (c)
    {
        double p = c/double(a+b+c);
        dp[a][b][c] += p * solve(a, b + 1, c - 1);
    }

    return dp[a][b][c];
}

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        int v;
        scanf("%d", &v);
        freq[v]++;
    }
    solve(freq[1], freq[2], freq[3]);
    printf("%.10lf\n", dp[freq[1]][freq[2]][freq[3]]);
    
}

Measured memory_bytes: 346368
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define inf LLONG_MAX>>2
#define MAX 1000000
#define mod 1000000007
#define pb push_back
#define f(i,a,n,x) for ((i)=(a);(i)<(n);(i)+=(x))
#define fd(i,a,n,x) for ((i)=(a);(i)>=(n);(i)-=(x))
#define fi first
#define se second
#define mk make_pair
#define pi pair
#define vt vector
#define ms multiset
using namespace std;
void read(vt<ll> &a,ll n){ll i,temp;f(i,0,n,1){cin>>temp;a.pb(temp);}}
ll fa[MAX];
ll power(ll p,ll q){
    ll res=1;
    p%=mod;
    while(q){
        if (q&1)
            res=(res*p)%mod;
        q>>=1;
        p=(p*p)%mod;
    }
    return res;
}
ll fact(ll n){
    if (n<=1)
        return fa[n]=1;
    if (fa[n])
        return fa[n];
    return fa[n]=(n*fact(n-1))%mod;
}
ll ncr(ll n,ll r){
    if (!r)
        return 1;
    return (((fact(n)*power(fact(n-r),mod-2))%mod)*power(fact(r),mod-2))%mod;
}
void solve(){
    ll n,i,r=0,w=0,p=0,mark=0;
    string a;
    cin>>n>>a;
    f(i,0,n,1)
        if (a[i]=='R')
            mark++;
    f(i,0,mark,1)
        if (a[i]=='R')
            r++;
    f(i,mark,n,1)
        if (a[i]=='W')
            w++;
    p=min(mark-r,n-mark-w);
    cout<<n-r-w-p<<endl;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 3716
/// Bismillahir Rahmanir Rahim
/* Mohammad Morsalin
   Dept of ICE, NSTU
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define int long long
#define f0(n) for(int i=0;i<n;i++)
#define ms(x) memset(x,0,sizeof(x))
#define ms2d(x,m,n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define uniq(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define pi pair<int,int>
#define tc(t) int t;cin>>t;while(t--)
#define bits(n) __builtin_popcount(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define ins insert
#define ALL(v) v.begin(),v.end()
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define fi first
#define se second
#define PI acos(-1)
#define sz(a) (int)a.size();
#define IOS ios::sync_with_stdio(false);
using namespace std;
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const long long MOD = 1000000007;
double sq(double x) {return x*x;}
template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}

bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}
signed main()
{
    IOS
    int a,v,b,w,t;
    cin>>a>>v>>b>>w>>t;
    if(a>b){
        if((a-(v*t))<=(b-(w*t))){
            cout << "YES\n";
        }
        else{
            cout << "NO\n";
        }
    }
    else if((a+(v*t))>=(b+(w*t))){
        cout << "YES\n";
    }
    else cout << "NO\n";
    return 0;
}
///Alhamdulillah


Measured memory_bytes: 3648
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <sstream>
#include <iomanip>
using namespace std;

int main(void){
    long long int n, k;
    cin >> n >> k;
    long long int h[n];
    for(long long int i = 0; i < n; i++)
        cin >> h[i];
    sort(h, h+n);
    long long int ans = 0;
    for(long long int i = 0; i < n-k; i++)
        ans += h[i];
    cout << ans << endl;
}

Measured memory_bytes: 1792
import math

def isPrime(x):
    if(x == 1 ):
        return False

    n = int(math.sqrt(x))

    for i in range(2,n+1):
        if(x % i == 0):
            return False
    return True

n = int(input())
dataset = []
while (n > 0):
     dataset.append(int(input()))
     n -=1

prime_number = 0
for x in dataset:
    if(isPrime(x)):
        prime_number += 1

print(prime_number)

Measured memory_bytes: 8036
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <climits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#define int long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
int mod = 1e9+7;

int32_t main(){
    FIO;
    int n;
    cin>>n;
    int a[n];
    map<int,int> m;
    for(int i = 0; i < n; i++){
        cin>>a[i];
        m[a[i]]++;
    }
    int cnt = 0;
    for(int i = 0; i < n; i++){
        int k = a[i];
        bool ans = true;
        for(int j = 1; j*j <= k; j++){
            if(k%j == 0){
                int op1 = j, op2 = k/j;

                if(op1 != k){
                    if(m.find(op1)!=m.end()){
                        ans = false;
                        break;
                    }
                }
                else{
                    if(m[op1]>1)
                        ans = false;
                }
                if(op2 != k){
                    if(m.find(op2)!=m.end()){
                        ans = false;
                        break;
                    }
                }
                else{
                    if(m[op2]>1)
                        ans = false;
                }


            }
        }

        if(ans)
            cnt++;
    }


    cout<<cnt<<"\n";

    return 0;
}

Measured memory_bytes: 17600
#include <stdio.h>
#define MAX 100
int MST(int);
int A[MAX][MAX],v[MAX],d[MAX],x;
int main(){
  int n,i,j;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&A[i][j]);
    }
  }
  x=MST(n); 
  printf("%d\n",x); 
  return 0;
}

int MST(int n){
  int min,k=1,i,j,minp,sum=0; 
  d[0]=0;
  v[0]=1; 
  for(i=1;i<n;i++){
    v[i]=0;
  }
  while(1){
    min=2000;
    for(i=0;i<k;i++){
      for(j=0;j<n;j++){
	if(A[d[i]][j]<min&&A[d[i]][j]!=-1&&v[j]!=1){
	  min=A[d[i]][j];
	  minp=j;
	}
      }
    }
    if(k==n) break;
    d[k]=minp;
    v[minp]=1;
    sum+=min;
    k++;
  }
  return sum;
}

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

typedef pair<ll, pair<int, int> > p;


long long gcd(long long a, long long b) {

   	if(a < b) {
       swap(a, b);
   	}

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

	return b;
}

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

    int N;
    cin >> N;

    ll ans = 1LL;

    for(int i = 0; i < N; i++) {
        ll A;
        cin >> A;

        ans = ans / gcd(ans, A) * A;
    }

    cout << ans << endl;
}

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

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let mut s: String = sc.next();
    let n: u32 = sc.next();

    for _ in 0..n {
        let cmd: String = sc.next();
        let a: usize = sc.next();
        let b: usize = sc.next::<usize>() + 1;

        let t = s.clone();

        match cmd.as_ref() {
            "print" => {
                println!("{}", &s[a..b]);
            }
            "reverse" => {
                let x = &t[..a];
                let y = &t[a..b].chars().rev().collect::<String>();
                let z = &t[b..];
                s = format!("{}{}{}", x, y, z);
            }
            "replace" => {
                let x = &t[..a];
                let y = sc.next::<String>();
                let z = &t[b..];
                s = format!("{}{}{}", x, y, z);
            }
            _ => {
                panic!();
            }
        }
    }
}

/* ========== Scanner ========== */

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn read<T: FromStr>(&mut self) -> Option<T> {
        let token = self
            .reader
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn next<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.read() {
            s
        } else {
            writeln!(stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.next()).collect()
    }

    fn char(&mut self) -> char {
        self.next::<String>().chars().next().unwrap()
    }
}



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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeSearch(Node u, int k){
  if(u == NIL || k == u->key)return u;
  if(k < u->key)return treeSearch(u->left, k);
  else return treeSearch(u->right, k);
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL)
    {
      y = x;
      if(z->key < x->key)x = x->left;
      else x = x->right;
    }

  z->parent = y;

  if(y == NIL)root = z;
  else if(z->key < y->key)y->left = z;
  else y->right = z;
}

void inorder(Node u){
  if(u == NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u == NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}



Measured memory_bytes: 20472
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int ans=0;
	for(int i=1;i<=n;i++){
		int x;
		if(n%i==0)
			x=n/i-1;
		else
			x=n/i;
		for(int j=1;j<=x;j++)
			ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3608
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

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

//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
int sum;
int main()
{
  int x;
  while(cin >>sum,sum){
    for(int i = 0;i < 9;i++){
      cin >>x;
      sum -=x;
    }
    cout <<sum<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<deque<int>> as(N);

    for(int i = 0; i < N; ++i)
    {
        deque<int> ai(N - 1);
        for(int j = 0; j < N- 1; ++j)
        {
            cin >> ai[j];
            --ai[j];
        }
        as[i] = ai;
    }

    int rest = N * (N- 1) / 2;
    int count = 0;

    // mark
    set<int> mark;

    for(int i = 0; i < N; ++i)
    {
        int index = as[i].front();
        if(as[index].front() == i)
        {
            mark.insert(min(i, index));
        }
    }

    while(rest > 0)
    {
        if(mark.empty())
        {
            cout << -1;
            return 0;
        }

        rest -= mark.size();
        set<int> next;
        for(int i : mark)
        {
            auto pairIndex = as[i].front();
            as[i].pop_front();
            as[pairIndex].pop_front();
            for(auto j : {i, pairIndex})
            {
                if(!as[j].empty() && as[as[j].front()].front() == j)
                {
                    next.insert(min(j, as[j].front()));
                }
            }
        }
        swap(mark, next);
        ++count;
    }

    cout << count;
}


Measured memory_bytes: 4352
text = input()
if text == 'SSS':
    print(0)
elif text == 'RSS':
    print(1)
elif text == 'SRS':
    print(1)
elif text == 'SSR':
    print(1)
elif text == 'RRS':
    print(2)
elif text == 'RSR':
    print(1)
elif text == 'SRR':
    print(2)
elif text == 'RRR':
    print(3)
else:
    print('that is invalid. ')

Measured memory_bytes: 8988
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
const int INT_INF = 500000000;
const long long LONG_LONG_INF = (long long)pow(10, 18);
const int MOD = pow(10, 9) + 7;
/* contest template */
int A, B, C, X, Y;
int ans;

int main() {
  cin >> A >> B >> C >> X >> Y;
  if (C * 2 >= A + B) {
    ans = X * A + Y * B;
  } else {
    if (X >= Y) {
      ans += C * 2 * Y;
      if (C * 2 < A) {
        ans += C * 2 * (X - Y);
      } else {
        ans += A * (X - Y);
      }
    } else {
      ans += C * 2 * X;
      if (C * 2 < B) {
        ans += C * 2 * (Y - X);
      } else {
        ans += B * (Y - X);
      }
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
  var N string 
  fmt.Scanf("%s", &N)
  
  ans := "No"
  diff := 0
  for i := 0; i < 3; i++ {
    if N[i] != N[i+1] {
      diff++
    }
  }
  
  if diff <= 1 && N[1] == N[2] {
    ans = "Yes"
  }

  fmt.Printf("%s\n", ans)
}

Measured memory_bytes: 1832
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int

def get_z(y, x): # y/x (mod 1000000007)
    inv_x = pow(x, MOD - 2, MOD)
    return y * inv_x % MOD

def _get_z(y, x): # y / x
    #inv_x = pow(x, MOD - 2, MOD)
    #return y * inv_x % MOD
    while y % x > 0:
        y += MOD
    return y // x

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

def reduce(y, x):
    tmp = gcd(x, y)
    return (y // tmp, x // tmp)

def make_comb(n, k):
    fact = [1] * (n + 1)
    for i in range(2, n + 1):
        fact[i] = (fact[i - 1] * i) % MOD

    ret = [0] * (n + 1)
    for i in range(k, n + 1):
        a = fact[i]
        b = (fact[k] * fact[i - k]) % MOD
        ret[i] = get_z(a, b)
    return ret

def _make_comb(n, k):
    ret = [0] * n
    ret[k] = 1
    for i in range(k + 1, n):
        ret[i] = (ret[i - 1] * i) // (i - k)
        ret[i] %= MOD
    return ret

def solve(b: int, w: int):
    n = b + w
    bb = 0
    ww = 0
    b_comb = make_comb(n, b - 1)
    w_comb = make_comb(n, w - 1)
    par = 1
    for i in range(1, n + 1):
        #print(' ======== i: %d ==============' % i)
        other = par - bb - ww
        x = (par * 2) % MOD
        y = (other + bb * 2) % MOD
        #x = (par * 2)
        #y = other + bb * 2
        #print("bb : %d, ww : %d, other : %d" % (bb, ww, other))
        #print(y, ' / ', x)
        #y, x = reduce(y, x)
        ret = get_z(y, x)
        print(ret)
        #bb = (bb * 2 + w_comb[i - 1])
        #ww = (ww * 2 + b_comb[i - 1])
        #par = (par * 2)
        bb = (bb * 2 + w_comb[i - 1]) % MOD
        ww = (ww * 2 + b_comb[i - 1]) % MOD
        par = (par * 2) % MOD
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    B = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    solve(B, W)

if __name__ == '__main__':
    main()


Measured memory_bytes: 20408
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <new>

using namespace std;

typedef long long ll;

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

int main(){
    int  N,K;
    cin >>N>>K;
    int  a[N];
    rep(i,N){
        cin>>a[i];
    }
     ll f=0;
    rep(i,K){
        f+=a[i];
    }
    ll mx =f;
    rep(i,N-K){
        f += a[K+i]-a[i];
        mx=max(mx,f);
    }
    cout<<(mx+K)/2<<'.';
    if((mx+K)%2==0)cout<<"00000000000"<<endl;
    else cout<<"50000000000"<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <time.h>
#include <stdlib.h>
using namespace std;

int main(){
	int cir=0,sum=15;
	char scr[16];
	scanf("%s",scr);
	for(int i=0;scr[i]!='\0';i++){
		if(scr[i]=='o') cir++;
		sum--;
	}
	if(sum+cir>=8) printf("YES\n");
	else printf("NO\n");
	
		
	return 0;
}

Measured memory_bytes: 256
import math

n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

ans1 = 0
ans2 = 0
ans3 = 0
ans4 = 0

for i in range(n):
	a = math.fabs(x[i] - y[i])
	ans1 += a
	ans2 += a**2
	ans3 += a**3
	ans4 = max(ans4, a) 

print(ans1)
print(ans2**(1./2.))
print(ans3**(1./3.))
print(ans4)


Measured memory_bytes: 5720
n,m = map(int,input().split())
mise = []
for i in range(n):
    a,b = map(int,input().split())
    mise.append([a,b])
mise.sort(key=lambda x:x[0])
ans = 0
for i in range(n):
    now = mise[i]
    if now[1] >= m:
        ans += now[0]*m
        break
    else:
        ans += now[0] * now[1]
        m = m-now[1]
print(ans)

Measured memory_bytes: 21224
#include <iostream>

using namespace std;

int calc(int fromx, int fromy, int tox, int toy)
{
    int cnt = 0;

    while (fromx != tox || fromy != toy) {
        if (fromx < tox && fromy < toy) {
            fromx++; fromy++;
        } else if (fromx > tox && fromy > toy) {
            fromx--; fromy--;
        } else if (fromx > tox && fromy < toy) {
            fromx--;
        } else if (fromx < tox && fromy > toy) {
            fromx++;
        } else if (fromx == tox) {
            if (fromy < toy) fromy++;
            else fromy--;
        } else if (fromy == toy) {
            if (fromx < tox) fromx++;
            else fromx--;
        }
        
        cnt++;
    }

    return cnt;
}

int main()
{
    int w, h, n; cin >> w >> h >> n;

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

    int cnt = 0;

    for(int i = 1; i < n; ++i) {
        int x, y; cin >> x >> y;
        
        cnt += calc(a, b, x, y);  
        
        a = x, b = y;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937 mt32(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt32);
}
/*--------Library Zone!--------*/

struct Segtree {
	int size = 1;
	vector<int>dat, lazy;
	Segtree(int x) {
		while (size < x)size *= 2;
		dat.resize(size * 2 - 1, inf);
		lazy.resize(size * 2 - 1, inf);
	}
	void eval(int k, int l, int r) {
		chmin(dat[k], lazy[k]);
		if (r - l > 1) {
			chmin(lazy[k * 2 + 1], lazy[k]);
			chmin(lazy[k * 2 + 2], lazy[k]);
		}
		lazy[k] = inf;
	}
	void update(int a, int b, int x, int k = 0, int l = 0, int r = -1) {
		if (r == -1)r = size;
		eval(k, l, r);
		if (r <= a || b <= l)return;
		if (a <= l && r <= b) {
			chmin(lazy[k], x);
			eval(k, l, r); return;
		}
		update(a, b, x, k * 2 + 1, l, (l + r) / 2);
		update(a, b, x, k * 2 + 2, (l + r) / 2, r);
		dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
	}
	int query(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r == -1)r = size;
		eval(k, l, r);
		if (r <= a || b <= l)return inf;
		if (a <= l && r <= b)return dat[k];
		int lval = query(a, b, k * 2 + 1, l, (l + r) / 2);
		int rval = query(a, b, k * 2 + 2, (l + r) / 2, r);
		return min(lval, rval);
	}
};
int n, m;
vector<pair<P, int>>v;
signed main() {
	cin >> n >> m;
	Segtree S(n);
	rep(i, m) {
		int a, b, c; cin >> a >> b >> c; a--; b--;
		v.push_back({ {a,b},c });
	}
	sort(all(v));
	S.update(0, 1, 0);
	rep(i, m) {
		int mi = S.query(v[i].first.first, v[i].first.second + 1);
		S.update(v[i].first.first, v[i].first.second + 1, mi + v[i].second);
	}
	int ans = S.query(n - 1, n);
	if (ans != inf)cout << ans << endl;
	else cout << -1 << endl;
}

Measured memory_bytes: 9076
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 //Compiler version g++ 6.3.0

 int main()
 {
 	ll n,x;
 	cin >> n >> x;
 	ll m = x/1000-n;
 	if(m<0){
 		cout << "-1 -1 -1 " << endl;
 		return 0;
 	}
 	for (int i = 0; i <= n; i++){
 		for (int j = 0; j <= n-i; j++){
 			if(i*9+j*4==m){
 				cout << i <<" "<< j <<" "<< n-j-i << endl;
 				return 0;
 			}
 		}
 	}cout << "-1 -1 -1" << endl;
 }

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
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; }
#define MOD7 1000000007
#define LL_INF 1LL << 60
#define LL_MINF -1LL << 60
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const long double PI = (acos(-1));



int main(){
    vector<pair<int,int>> HW;
    while(true){
        int H, W;
        cin >> H >> W;
        if(H == 0 and W == 0) break;
        HW.emplace_back(H, W);
    }
    for(auto p : HW){
        int H = p.fi, W = p.se;
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                if((i + j) % 2) cout << '.';
                else cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
char a[100005];
int x=0,y=0,ans=0;
int main()
{
    cin>>a;
    for (int i=0;i<sizeof(a);i++)
     if (x==y)
     {
         x++; 
         if(a[i]=='p') 
         ans--;
         
     } 
     else
     {
         y++; 
     if(a[i]=='g') 
     ans++;
         
     }   
    printf("%d\n",ans);                 
    return 0;
}

Measured memory_bytes: 384
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int m = stdIn.nextInt();
		int l = stdIn.nextInt();
		int[][] A = new int[n][m];
		int[][] B = new int[m][l];
		long[][] C = new long[n][l];

		for (int i=0; i<n; i++) {
			for (int j=0; j<m; j++) {
				A[i][j] = stdIn.nextInt();
			}
		}

		for (int i=0; i<m; i++) {
			for (int j=0; j<l; j++) {
				B[i][j] = stdIn.nextInt();
			}
		}

		for (int i=0; i<n; i++) {
			for (int j=0; j<l; j++) {
				for (int k=0; k<m; k++) {
					C[i][j] += A[i][k] * B[k][j];
				}
			}
		}

		for (int i=0; i<n; i++) {
			for (int j=0; j<l; j++) {
				System.out.print(C[i][j]);
				if(j<l-1)
					System.out.print(" ");
			}
			System.out.println();
		}
 	}
}

Measured memory_bytes: 45520
package main

import "fmt"

func main() {
	var n, change, count int
	var a [100]int

	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	for i := 0; i < n; i++ {
		minj := i
		for j := i; j < n; j++ {
			if a[j] < a[minj] {
				minj = j
			}
		}
		change = a[i]
		a[i] = a[minj]
		a[minj] = change
		if i != minj {
			count++
		}
	}
	for i := 0; i < n-1; i++ {
		fmt.Printf("%d ", a[i])
	}
	fmt.Println(a[n-1])
	fmt.Println(count)
}



Measured memory_bytes: 1156
s = input()
s_dict = dict()
for i in s:
    if i not in s_dict:
        s_dict[i] = 1
    else:
        s_dict[i] += 1
for i in s_dict:
    if s_dict[i] != 2:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

// Fenwick Tree
int n;
int bit[100000]; 

void add( int a, int x ){
	for( int i = a; i <= n; i += ( i & -i ) ) bit[i] += x;
}

int sum( int a ){
	int res = 0;
	for( int i = a; i > 0; i -= ( i & -i ) ) res += bit[i];
	return res;
}

struct abschnitt{
	int link;
	int recht;
	bool art; // query wenn true, zug wenn false
	int nummer;
};
	
int main(){
    // freopen("/Users/xuzijian/codeforces/522/in", "r", stdin);
	vector<abschnitt> v;
	map<int, int> karte;
	int m, q; cin >> n >> m >> q;
	
	for( int i = 0; i < m; ++i ){
		int l, r; cin >> l >> r;
		v.push_back( (abschnitt){ l, r, false, 0 } );
	}
	for( int i = 0; i < q; ++i ){
		int l, r; cin >> l >> r;
		v.push_back( (abschnitt){ l, r, true, i } );
	}

    // cout << "hoge" << endl;
	
	sort(
		v.begin(), v.end(),
		[]( const abschnitt& x, const abschnitt& y ){
			return ( x.recht == y.recht ) ? ( x.art ? false : y.art ) : ( x.recht < y.recht );
		}
	);

    // cout << "fuga" << endl;
	
	for( int i = 0; i < m+q; ++i ){
		// cout << v[i].link << " " << v[i].recht << " " << v[i].art <<  " " << v[i].nummer << endl;
		if( v[i].art ) karte.emplace( v[i].nummer, sum( v[i].recht ) - sum( v[i].link - 1 ) );
		else add( v[i].link, 1 );
	}
	
	for ( int i = 0; i < q; ++i ) cout << karte.at(i) << endl;
	return 0;
}


Measured memory_bytes: 12264
from math import sqrt
while True:
  n = int(input())
  if n == 0:
    break
  else:
    score = list(map(int, input().split()))
    ave = sum(score) / n
    diviation = [(ave-i)**2 for i in score]
    variance = sum(diviation) / n
    standard_diviation = sqrt(variance)
  print(standard_diviation)


Measured memory_bytes: 5712
H,W = list(map(int,input().split()))
S = []
for i in range(H):
    S.append(input())

DP = [[0]*W for i in range(H)]

DP[0][0] = 1

mod = 10**9 + 7

for i in range(H):
    for j in range(W):
        if S[i][j]==".":
            if i>0:
                DP[i][j] += DP[i-1][j]
            if j>0:
                DP[i][j] += DP[i][j-1]
    DP[i][j]%=mod
print(DP[H-1][W-1])

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

int main(){
	int H,W;
	scanf("%d %d",&H,&W);
	char S[50][50];
	for(int i=0; i<H; i++){
		scanf("%s",S[i]);
	}
	int count[50][50] = {0};
	for(int i=0; i<H; i++){
		for(int j=0; j<W; j++){
			if(S[i][j] == '.'){
				if(i == 0){
					if(j == 0){
						if(S[i][j+1] == '#'){
							count[i][j]++;
						}
						if(S[i+1][j] == '#'){
							count[i][j]++;
						}
						if(S[i+1][j+1] == '#'){
							count[i][j]++;
						}
					}
					else if(j == W-1){
						if(S[i][j-1] == '#'){
							count[i][j]++;
						}
						if(S[i+1][j] == '#'){
							count[i][j]++;
						}
						if(S[i+1][j-1] == '#'){
							count[i][j]++;
						}
					}
					else{
						if(S[i][j+1] == '#'){
							count[i][j]++;
						}
						if(S[i+1][j] == '#'){
							count[i][j]++;
						}
						if(S[i+1][j+1] == '#'){
							count[i][j]++;
						}
						if(S[i][j-1] == '#'){
							count[i][j]++;
						}
						if(S[i+1][j-1] == '#'){
							count[i][j]++;
						}
					}
				}
				else if(i == H-1){
					if(j == 0){
						if(S[i][j+1] == '#'){
							count[i][j]++;
						}
						if(S[i-1][j] == '#'){
							count[i][j]++;
						}
						if(S[i-1][j+1] == '#'){
							count[i][j]++;
						}
					}
					else if(j == W-1){
						if(S[i][j-1] == '#'){
							count[i][j]++;
						}
						if(S[i-1][j] == '#'){
							count[i][j]++;
						}
						if(S[i-1][j-1] == '#'){
							count[i][j]++;
						}
					}
					else{
						if(S[i][j+1] == '#'){
							count[i][j]++;
						}
						if(S[i-1][j] == '#'){
							count[i][j]++;
						}
						if(S[i-1][j+1] == '#'){
							count[i][j]++;
						}
						if(S[i][j-1] == '#'){
							count[i][j]++;
						}
						if(S[i-1][j-1] == '#'){
							count[i][j]++;
						}
					}
				}
				else {
					if(j == 0){
						if(S[i][j+1] == '#'){
							count[i][j]++;
						}
						if(S[i-1][j] == '#'){
							count[i][j]++;
						}
						if(S[i-1][j+1] == '#'){
							count[i][j]++;
						}
						if(S[i+1][j] == '#'){
							count[i][j]++;
						}
						if(S[i+1][j+1] == '#'){
							count[i][j]++;
						}
					}
					else if(j == W-1){
						if(S[i][j-1] == '#'){
							count[i][j]++;
						}
						if(S[i-1][j] == '#'){
							count[i][j]++;
						}
						if(S[i-1][j-1] == '#'){
							count[i][j]++;
						}
						if(S[i+1][j] == '#'){
							count[i][j]++;
						}
						if(S[i+1][j-1] == '#'){
							count[i][j]++;
						}
					}
					else{
						if(S[i][j+1] == '#'){
							count[i][j]++;
						}
						if(S[i-1][j] == '#'){
							count[i][j]++;
						}
						if(S[i-1][j+1] == '#'){
							count[i][j]++;
						}
						if(S[i-1][j-1] == '#'){
							count[i][j]++;
						}
						if(S[i][j-1] == '#'){
							count[i][j]++;
						}
						if(S[i+1][j] == '#'){
							count[i][j]++;
						}
						if(S[i+1][j-1] == '#'){
							count[i][j]++;
						}
						if(S[i+1][j+1] == '#'){
							count[i][j]++;
						}
					}
				}
			}
		}
	}
	for(int i=0; i<H; i++){
		for(int j=0; j<W; j++){
			if(S[i][j] != '#'){
				printf("%d",count[i][j]);
			}
			else{
				printf("%c",S[i][j]);
			}
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() {
long N,AC=0,WA=0,TLE=0,RE=0;
string jud;
cin >> N;
for(int i=0;i<N;i++){
cin >> jud;
if(jud=="AC"){
AC++;
}else if(jud=="WA"){
WA++;
}else if(jud=="TLE"){
TLE++;
}else if(jud=="RE"){
RE++;
}
}
cout << "AC x "<<AC<<"\n";
cout << "WA x "<<WA<<"\n";
cout << "TLE x "<<TLE<<"\n";
cout << "RE x "<<RE<<"\n";


}

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

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;

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()
{
    ll n;
    cin >> n;
    vector <ll> a(n), ans(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    ans[0] = 0;
    ans[1] = abs(a[1] - a[0]);

    for (int i = 2; i < n; i++) {
        ll tmp = min(ans[i-2] + abs(a[i-2] - a[i]), ans[i-1] + abs(a[i-1] - a[i]));
        //cout << tmp << endl;
        ans[i] = tmp;
    }
    cout << ans[n-1] << endl;
    return 0;
}



Measured memory_bytes: 1792
#include<stdio.h>


int main(void)
{
    int n,m,x,i,c,min=100,j;
    int a[100];
    scanf("%d%d%d",&n,&m,&x);
    for(i=0;i<m;i++){
        scanf("%d",&a[i]);
    }   
    for(i=0;i<x;i++){
        for(j=0;j<m;j++){
            if(a[j]==i) c++;
        }
    }   
    min=c;
    c=0;
    for(i=x;i<n;i++){
        for(j=0;j<m;j++){
            if(a[j]==i) c++;
        }
    }   
    if(min>c) min=c;
    printf("%d\n",min);

    return 0;
}


Measured memory_bytes: 128
class Queue:
    def __init__(self) -> None:
        self.queue = list()

    def _is_empty(self):
        if len(self.queue) == 0:
            return True
        return False

    def enqueue(self, obj):
        self.queue.append(obj)

    def dequeue(self):
        if self._is_empty():
            return None
        else:
            return self.queue.pop(0)

    def __len__(self):
        return len(self.queue)


def main():
    n, q = map(int, input().split(' '))
    queue = Queue()
    for i in range(n):
        name, num = input().split(' ')
        queue.enqueue({'name': name, 'num': int(num)})
    time = 0
    while True:
        if len(queue) == 0:
            break
        task = queue.dequeue()
        task['num'] -= q
        if task['num'] > 0:
            queue.enqueue(task)
            time += q
        else:
            time += q+task['num']
            print(task['name'], time)


if __name__ == "__main__":
    main()



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

int main(void){
  int a,b;
  double cAng;
  
  cin >> a >> b >> cAng;
  cAng *= 3.14159265/180; // deg -> rad
  cout << setprecision(10);
  cout << (a*b*sin(cAng))/2 << endl; // S
  cout << a+b+sqrt(a*a+b*b-2*a*b*cos(cAng)) << endl; // L
  cout << (b*sin(cAng)) << endl; // h
   
  return 0;
}



Measured memory_bytes: 3492
import itertools

n, m, k = map(int, input().split())


def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p


p = 998244353
N = n   # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

ans = 0

l2 = m*(m-1)**(n-k-1)
for _k in range(k, -1, -1):
    # print(_k)

    ncr = cmb(n - 1, _k, p)
    ans += ncr * l2
    ans %= p

    l2 %= p
    l2 *= (m - 1)
    l2 %= p


print(ans)


Measured memory_bytes: 34388
import java.util.*;
public class Main{
 public static void main(String[] args){
  Scanner scan = new Scanner(System.in);
  int h = scan.nextInt();
  int w = scan.nextInt();
  int hDelete = scan.nextInt();
  int wDelete = scan.nextInt();
   
  System.out.println((h - hDelete)*(w - wDelete));
 }
}

Measured memory_bytes: 22996
type tree = Nil | Node of int * tree * tree

let create () = Nil

let insert x t =
  let rec doit = function
    | Nil -> Node (x, Nil, Nil)
    | Node (y, l, r) ->
      if x < y then Node (y, doit l, r)
      else Node (y, l, doit r) in
  doit t

let preorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> f x; doit l; doit r in
  doit t

let inorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> doit l; f x; doit r in
  doit t

let print t =
  inorder (fun e -> print_string " "; print_int e) t;
  print_newline ();
  preorder (fun e -> print_string " "; print_int e) t;
  print_newline ()

let find x t =
  let rec doit = function
    | Nil -> false
    | Node (y, _, _) when x = y -> true
    | Node (y, l, _) when x < y -> doit l
    | Node (_, _, r) -> doit r in
  doit t

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let m = read_int () in
  let rec read i t =
    if i < m then
      match read_line () |> split_on_char ' ' with
      | ["insert"; n] -> read (i + 1) (insert (int_of_string n) t)
      | ["find"; n] -> print_endline (if find (int_of_string n) t then "yes" else "no"); read (i + 1) t
      | _ -> print t; read (i + 1) t in
  read 0 (create ())

Measured memory_bytes: 27156
N = int(input())

order=0
num=0

while True:
  if N // 10**order >=1:
    order += 1
  else:
    break
    
if order%2==1:
  order-=1
  num += N-(10**order)+1

while True:
  if order<=0: break
  if order%2==1:
    num += 9*(10**(order-1))
  order-=1
  
print(num)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,m;cin >> n >> m;
	ll ans = min(n, m / 2);
	m -= ans * 2;
	if(m > 0) ans += m / 4;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

class info {
public:
  i64 A, B;
};

namespace std {
  std::istream& operator>>(std::istream& is, info& self) {
    return is >> self.A >> self.B;
  }
}

int main() {
  i64 N;
  std::cin >> N;
  std::vector<info> info_list;
  tools::read(info_list, N);

  const auto it = std::max_element(info_list.begin(), info_list.end(), [](const info& x, const info& y) { return x.A < y.A; });
  std::cout << it->A + it->B << std::endl;

  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>
#include <limits>
#include <cmath>
#include <iomanip>
#include <sstream>
 
#define ALL(a)  (a).begin(),(a).end()
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

bool isMM(ll n) {
    if (n > 0 && n <= 12) return true;
    else return false;
}

int main() {
    ll ans = 0;

    string s;

    cin >> s;

    ll pre = atoi(s.substr(0, 2).c_str());
    ll suf = atoi(s.substr(2, 4).c_str());

    if (isMM(pre) && isMM(suf)) s = "AMBIGUOUS";
    else if (isMM(pre)) s = "MMYY";
    else if (isMM(suf)) s = "YYMM";
    else s = "NA";

    cout << s << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
    
signed main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    cout << fixed << setprecision(20);
 
    int n;
    cin>>n;
    int a[n],b[n],c[n-1];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int ans = 0;

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

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

int mod = 1000000007;
int64_t large = 9223372036854775807;
#define PI 3.14159265359

int64_t gcd(int64_t p, int64_t q)
{
    if (p < q)
        swap(p, q);

    if (p % q == 0)
        return q;
    else
        return gcd(q, p % q);
}

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

    int zero_zero = 0; //(0,0)のイワシ
    map<pair<int64_t, int64_t>, pair<int64_t, int64_t>> list;

    vector<int64_t> p2(200000);
    p2[0] = 1;
    for (int64_t i = 0; i < 200000; i++)
        p2[i + 1] = p2[i] * 2 % mod;

    for (int64_t i = 0; i < N; i++)
    {
        int64_t p, q;
        cin >> p >> q;
        if (p == 0 && q == 0)
            zero_zero++;
        else if (p == 0)
            list[{0, 0}].first++;
        else if (q == 0)
            list[{0, 0}].second++;
        else
        {
            if (q < 0)
                p = -p, q = -q;
            int64_t tmp = gcd(abs(p), abs(q));
            p /= tmp, q /= tmp;
            if (p < 0)
                list[{q, -p}].first++;
            else
                list[{p, q}].second++;
        }
    }
    int64_t ans = 1;
    for (auto m : list)
    {
        int64_t tmp = p2[m.second.first] + p2[m.second.second] - 1;
        ans = ans * tmp % mod;
    }
    cout << (ans + zero_zero - 1 + mod) % mod;
}

Measured memory_bytes: 20308
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define N (300000+1000)
using namespace std;

int sum1[N],sum2[N],n,ans=0x7fffffff;
char s[N];

int main()
{
	scanf("%d",&n);
	scanf("%s",s+1);
	for (int i=1; i<=n; ++i)
	{
		sum1[i]=sum1[i-1]+(s[i]=='W');
		sum2[i]=sum2[i-1]+(s[i]=='E');
	}
	for (int i=1; i<=n; ++i)
	{
		int sum=sum1[i-1]+sum2[n]-sum2[i];
		ans=min(ans,sum);
	}
	cout<<ans;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

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

  vector<ll> table(n+1);

  for(ll i=1; i<=n; ++i) {
    for(ll j=1; i*j<=n; ++j)
        table[i*j]++;
  }
  ll ans = 0;
  reps1(i, n+1) ans += (i * table[i]);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 81404
#include <stdio.h>
int main()
{
    long long int r, d, x, i;
    scanf("%lld %lld %lld", &r, &d, &x);
    for (i = 1; i < 11; i++)
    {
        x = r * x - d;
        printf("%lld\n", x);
    }
    return 0;
}


Measured memory_bytes: 128
#include <stdlib.h>
#include<iostream>
#include<bits/stdc++.h>
#include<cmath>
#define ll long long
const int INF=0x3f3f3f3f;
#define mod 1000000007
using namespace std;

int main()
{

    int a,b;
    cin>>a>>b;
    if(a<b)cout<<0<<endl;
    else cout<<10<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll a,i,temp,j,c=0,m;
    cin>>a;
    ll b[a];
    for(i=0;i<a;i++)
    {
        cin>>b[i];
    }
    for(i=0;i<a;i++)
    {
        m=i;
        for(j=i;j<a;j++)
        {
            if(b[j]<b[m])
            {
                m=j;
            }
        }
        if(m!=i)
        {
            c++;
            temp = b[i];
            b[i]=b[m];
            b[m]=temp;
        }
    }
    for(i=0;i<a;i++)
    {
        if(i==a-1)
            cout<<b[i]<<endl;
        else
        cout<<b[i]<<" ";
    }
    cout<<c<<endl;
}



Measured memory_bytes: 3088
X, t = map(int, input().split())

# X秒を測れる砂時計があります。はじめ上のパーツに砂が X[g] あり、1秒間に 1[g] 砂が落ちます
# t秒後に上のパーツに残っている砂は何gかを出力
if X > t:
    print(X - t)
else:
    print(0)

Measured memory_bytes: 9084
from collections import Counter
N = int(input())
A = map(int, input().split())
Q = int(input())
ops = []
for _ in range(Q):
  b, c = map(int, input().split())
  ops.append((b,c))

cnt = Counter(A)
s = sum(k*v for k, v in cnt.items())
for b, c in ops:
  s -= b * cnt[b]
  s += c * cnt[b]
  cnt[c] += cnt[b]
  cnt[b] = 0
  print(s)

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

#define  __  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define  int  long long
#define  endl  '\n'
const double pi = acos(-1);
const int mod = 1e9 + 7;
//______________________


const int N = 1e5+5;    
vector<int> d[N];

int32_t main()
{ 
  __
 
  
  int n, m, ans = 0;
  cin >> n >> m;
   
  for(int i = 0; i < n; i++)
  {
    int a, b;
    cin >> a >> b;
    d[a].push_back(b);
  }
 
  multiset<int> s;

  for(int i = 1; i <= m; i++)
  {
    for(int val : d[i])
        s.insert(val);

    if(!s.empty())
    {
        ans += *s.rbegin();
        s.erase(prev(s.end()));
    }
  }

  cout << ans;

 return 0;
}

Measured memory_bytes: 8320
#include <iostream>

int main() {
	int a = 0, b = 0, c = 0, d = 0, in, temp = 0;
	for (int i = 0; i < 4; i++) {
		std::cin >> in;
		if (a <= in) {
			c = b;
			b = a;
			a = in;
		}
		else if (b <= in) {
			c = b;
			b = in;
		}
		else if (c <= in) {
			c = in;
		}
	}

	for (int i = 0; i < 2; i++) {
		std::cin >> in;
		if (in > temp) temp = in;
	}

	std::cout << a + b + c + temp << std::endl;

	return 0;
} 


Measured memory_bytes: 3076
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    MOD = 10 ** 9 + 7
    cnt = 0
    for i in range(N - 1):
        for j in range(i + 1, N):
            if A[i] > A[j]:
                cnt += 1
    cnt_1 = 0
    for i in range(N):
        for j in range(N):
            if A[i] > A[j]:
                cnt_1 += 1
    a = cnt * K % MOD
    b = (cnt_1 * K * (K - 1) // 2) % MOD
    answer = (a + b) % MOD
    print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3188