akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
using namespace std;

string conv1(string str) {
  static map<char, string> d;
  d['A'] = "00000";
  d['B'] = "00001";
  d['C'] = "00010";
  d['D'] = "00011";
  d['E'] = "00100";
  d['F'] = "00101";
  d['G'] = "00110";
  d['H'] = "00111";
  d['I'] = "01000";
  d['J'] = "01001";
  d['K'] = "01010";
  d['L'] = "01011";
  d['M'] = "01100";
  d['N'] = "01101";
  d['O'] = "01110";
  d['P'] = "01111";
  d['Q'] = "10000";
  d['R'] = "10001";
  d['S'] = "10010";
  d['T'] = "10011";
  d['U'] = "10100";
  d['V'] = "10101";
  d['W'] = "10110";
  d['X'] = "10111";
  d['Y'] = "11000";
  d['Z'] = "11001";
  d[' '] = "11010";
  d['.'] = "11011";
  d[','] = "11100";
  d['-'] = "11101";
  d['\''] = "11110";
  d['?'] = "11111";

  string res = "";
  for(int i = 0; i < str.length(); ++i) {
    res += d[str[i]];
  }
  return res;
}

bool isAll0(string str) {
  if(str.empty()) return true;
  for(int i = 0; i < str.length(); ++i) if(str[i] != '0') return false;
  return true;
}

string conv2(string &base, int pos) {
  static map<string, char> d;
  d["101"] = ' ';
  d["000000"] = '\'';
  d["000011"] = ',';
  d["10010001"] = '-';
  d["010001"] = '.';
  d["000001"] = '?';
  d["100101"] = 'A';
  d["10011010"] = 'B';
  d["0101"] = 'C';
  d["0001"] = 'D';
  d["110"] = 'E';
  d["01001"] = 'F';
  d["10011011"] = 'G';
  d["010000"] = 'H';
  d["0111"] = 'I';
  d["10011000"] = 'J';
  d["0110"] = 'K';
  d["00100"] = 'L';
  d["10011001"] = 'M';
  d["10011110"] = 'N';
  d["00101"] = 'O';
  d["111"] = 'P';
  d["10011111"] = 'Q';
  d["1000"] = 'R';
  d["00110"] = 'S';
  d["00111"] = 'T';
  d["10011100"] = 'U';
  d["10011101"] = 'V';
  d["000010"] = 'W';
  d["10010010"] = 'X';
  d["10010011"] = 'Y';
  d["10010000"] = 'Z';

  string str = "";
  int s = 0;
  int e = 3;
  while(e <= base.length()) {
    string tmp = base.substr(s, e-s);
    if(d.find(tmp) != d.end()) {
      str += d[tmp];
      s = e;
      e += 3;
    } else {
      ++e;
    }
  }
  if(isAll0(base.substr(s))) return str;
  return "";
}

void solve(string &str) {
  string base = conv1(str);
  cout <<  conv2(base, 0) << endl;
}

main() {
  string str;
  while(getline(cin, str)) solve(str);
}

Measured memory_bytes: 0
#![allow(unused_imports)]
#![allow(dead_code)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]

use std::cmp::*;
use std::collections::*;
use std::ops::*;
use std::io::{Write, BufWriter};

// static MOD: usize = 998244353;
static MOD: usize = 1000000007;

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

macro_rules! println_stderr(
    ($($arg:tt)*) => { {
        let r = writeln!(&mut ::std::io::stderr(), $($arg)*);
        r.expect("failed printing to stderr");
    } }
);

fn solve() {
    input! {
        n: usize,
        m: usize,
        a: [[usize;m];n],
    }  
    let mut ans = n;
    let mut seen = vec![false;m];
    for i in 0..m {
        let mut v = vec![0;m];
        for j in 0..n {
            for k in 0..m {
                let b = a[j][k]-1;
                if seen[b] {continue;}
                v[b]+=1;
                break;
            }
        }
        let (id,&ma) = v.iter().enumerate().max_by(|x, y| x.1.cmp(y.1)).unwrap();
        // println!("{} {}", id, ma);
        seen[id] = true;
        ans = min(ans, ma);
    }
    println!("{}", ans);

}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
#include<iostream>
#include<string>
using namespace std;
int abs(int x) {
	if (x < 0) x *= (-1);
	return x;
}
int main() {
	string s;
	cin >> s;
	int min = 753;
	for (int i = 0; i + 2 <= s.length() - 1; ++i) {
		int x = 0;
		x += (s[i]-'0') * 100;
		x += (s[i + 1] - '0') * 10;
		x += s[i+2] - '0';
		int sub = abs(753 - x);
		if (sub < min) min = sub;
	}
	cout << min;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i, n) for (i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define ll long long
#define si(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define ss(s) scanf("%s", s)
#define pi(x) printf("%d\n", x)
#define pl(x) printf("%lld\n", x)
#define ps(s) printf("%s\n", s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<char> vc;
typedef vector<vc> vcc;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim)
{
    uniform_int_distribution<int> uid(0, lim - 1);
    return uid(rang);
}

int mpow(int base, int exp);
void ipgraph(int n, int m);
void dfs(int u, int par);

const int mod = 1'000'000'007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];

void solve()
{
    ll i, j, n, m;
    ll sum = 0;
    cin >> n;
    vi a(n);
    fo(i, n)
    {
        cin >> a[i];
        sum += a[i];
        sum %= mod;
    }
    ll ans = 0;
    fo(i, n)
    {
        sum -= a[i];
        if (sum < 0)
        {
            sum += mod;
        }
        ans += a[i] * sum;
        ans %= mod;
    }
    cout << ans << endl;
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }

    return 0;
}

int mpow(int base, int exp)
{
    base %= mod;
    int result = 1;
    while (exp > 0)
    {
        if (exp & 1)
            result = ((ll)result * base) % mod;
        base = ((ll)base * base) % mod;
        exp >>= 1;
    }
    return result;
}

void ipgraph(int n, int m)
{
    int i, u, v;
    while (m--)
    {
        cin >> u >> v;
        u--, v--;
        g[u].pb(v);
        g[v].pb(u);
    }
}

void dfs(int u, int par)
{
    for (int v : g[u])
    {
        if (v == par)
            continue;
        dfs(v, u);
    }
}


Measured memory_bytes: 11144
/* ~ Programmer >> Tushar Mahajan */
#include <iostream>
#include <bits/stdc++.h> 
using namespace std;
#define ll long long int
#define ld long double
#define MOD 1000000007
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL); 

int main() {
	ios;
	ll n,d,count = 0;
	cin>>n>>d;
	while(n--)
	{
	    ll x,y;
	    cin>>x>>y;
	    ld dis = (ld)sqrt((x*x)+(y*y));
	    if(dis<=d)
	    {
	        count++;
	    }
	}
	cout<<count<<endl;
	return 0;
}


Measured memory_bytes: 3696
#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int inf = 1LL << 60;
signed main(void){
  int n,k; cin >> n >> k;
  vector<int>a(n);
  for(int i = 0; i < n; i++){ cin >> a[i];}
  int ans = inf;
  for(int bit = 0; bit < (1<<n); bit++){
    vector<bool> vec(n,false); int cnt = 0;
    for(int i = 0; i < n; i++){ 
      if( bit >> i & 1 ){ vec[i] = true; cnt++;}
    }
    if( cnt < k ){ continue;}
    int M = 0; int sum = 0;
    for(int i = 0; i < n; i++){
      if( vec[i] ){
        if( M >= a[i] ){ sum += M-a[i]+1;}
      }
      if( vec[i] ){ M = max(M+1,a[i]);}
      else{ M = max(M,a[i]);}
    }
    ans = min(ans,sum);
  }
  cout << ans << endl;
  return 0;
}
      

Measured memory_bytes: 256
'use strict';

function main(input) {
  const arr = input.trim().split(' ');
  let a = Number(arr[0]);
  const b = Number(arr[1]);
  let ans = '';

  for (let i = b - a + 1; i < a + b; i++) {
    ans = ans + i + ' ';
  }

  console.log(ans);

}

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

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define il inline
#define sz(x) x.size()
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;
ll max(ll a,ll b){if(a>b)return a;else return b;}
ll min(ll a,ll b){if(a<b)return a;else return b;}
ll lowbit(ll x){return x&(-x);}
ll prime(ll x){
   if(x<=1)return false;
   for(int i=2;i<=int(sqrt(x));i++){
       if(x%i==0)return false;
   }return true;
}bool cmp(ll a,ll b){return a>b;}
ll gcd(ll a,ll b){ll r;while(b>0){r=a%b;a=b;b=r;}return a;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
inline int readint() {
    int f=1,x=0; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch<='9'&&ch>='0') x=x*10+ch-'0',ch=getchar();
    return f*x;
}
inline ll readll() {
    ll f=1,x=0; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch<='9'&&ch>='0') x=x*10+ch-'0',ch=getchar();
    return f*x;
}
void fl(string name){
    freopen((name+".in").c_str(),"r",stdin);
    freopen((name+".out").c_str(),"w",stdout);
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
          dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};

int main(){
    ll x,k,d;
    cin>>x>>k>>d;
    x=abs(x);
    ll foo=x/d;
    if(k>foo){
        ll now=x-foo*d;
        ll cc=k-foo;
        cout<<min(abs(now-(cc%2)*d),abs(now-cc*d))<<endl;
    }
    else{
        cout<<abs(x-k*d)<<endl;
    }
    return 0;
}
/* stuff to remember
    * int overflow, array bounds
    * special cases (n=1? n=0?)
    * do something instead of nothing and stay organized
    * USE STATIC ARRAYS
    * DEFINING ARRAYS BEFORE main()
    * DO NOT DEFINE ARRAYS IN main()
    * USE INT INSTEAD OF LL,NOTICE THE MLE
*/

Measured memory_bytes: 3584
#include <stdio.h>
#define buf 100

int main(void){

	int i;
	double n,time,vel,high;
	char str[buf];
  
	for( ;fgets(str,sizeof(str),stdin)!=NULL; ){
		sscanf(str,"%lf",&vel);
		time=vel/9.8;
		high=4.9*time*time;
		n = (high+5.0)/5.0;
		for(i=1;i <n;i++);
			printf("%d\n",i);
	}		
	return 0;	
}

Measured memory_bytes: 640
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<map>
#include<cmath>
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define down(i,l,r) for (int i=l;i>=r;i--)
#define clr(x,y) memset(x,y,sizeof(x))
#define maxn 100050
#define ll long long
#define inf int(1e9)
#define mm 1000000007
#define low(x) x&(-x)
using namespace std;
ll read(){
    ll x=0,f=1; char ch=getchar();
    while (!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
    while (isdigit(ch)) {x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}
ll n,a,b,c,d;
int main(){
	n=read(); a=read(); b=read(); c=read(); d=read();	
  	for (ll i=0;i<=n-1;i++) {
		ll x1=d*i+a; 
		ll x2=c*i+a;
		ll y1=x1-c*(n-1-i);
		ll y2=x2-d*(n-1-i);
		if (y2<=b&&b<=y1) {puts("YES"); return 0;}
  	}
  	puts("NO");
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define N 200000

main(){
  int i,j,n,R[N],x,max,min;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&R[i]);
  }
  max=R[1]-R[0];
  min=R[0];
  for(j=1;j<=n-1;j++){  
    x=R[j]-min;
    if(max<x)
      max=x;
    if(min>R[j])
      min=R[j];
  }
  
  printf("%d\n",max);
  return 0;
  
}

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

int main(){
	int min=1000000,max=-1000000,n,tmp,i;
	long sum=0;
	
	cin>>n;
	for(i=0;i<n;i++){
		cin>>tmp;
		
		if(tmp<min){
			min=tmp;
		}
		if(tmp>max){
			max=tmp;
		}
		sum+=tmp;
	}
	cout<<min<<" "<<max<<" "<<sum<<endl;
	return 0;
}

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

#define F first
#define S second
#define mp make_pair
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define deg(x) cout<<x<<" "


using ll = long long;
using pll = pair<ll,ll>;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10;

int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//#ifndef ONLINE_JUDGE
	//	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);
	//#endif
	string s;
	cin >> s;
	int n1=(s[0]-'0')*10+(s[1]-'0'),n2=(s[2]-'0')*10+(s[3]-'0');
	if(n1<=12 and n2<=12 and n1>0 and n2>0){
		cout << "AMBIGUOUS\n";
	}
	else if(n1<=12 and n1>0){
		cout << "MMYY\n";
	}
	else if(n2<=12 and n2>0){
		cout << "YYMM\n";
	}
	else{
		cout << "NA\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll calc(ll x,ll y,ll z){
	return x*x+y*y+z*z+x*y+x*z+y*z;
}
int ans[100100];
int main(){
	ll n;
	scanf("%lld",&n);
	ll x,y,z;
	for(int i=1;i<=100;i++){
		for(int j=1;j<=100;j++){
			for(int k=1;k<=100;k++){
				x=i;y=j;z=k;
				ll tmp=calc(x,y,z);
				ans[tmp]++;
			}
		}
	}
	for(int i=1;i<=n;i++) printf("%d\n",ans[i]);
	return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

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

    rep(i, n)
    {
        int out_sum = 0, point = 0;
        vector<int> base(4, 0);
        string s;
        while (out_sum != 3)
        {
            cin >> s;
            if (s == "OUT")
                out_sum++;
            else if (s == "HOMERUN")
            {
                point += accumulate(ALL(base), 0) + 1;
                rep(i, 3) base[i] = 0;
            }
            else if (s == "HIT")
            {
                bool cnt[3] = {};
                rep(i, 3) if (base[i] == 1) cnt[i] = 1;
                rep(i, 4)
                {
                    if (cnt[i] == 1)
                    {
                        base[i + 1]++;
                        base[i]--;
                    }
                }
                base[0] = 1;
                if (base[3] == 1)
                {
                    point++;
                    base[3] = 0;
                }
            }
        }
        OP(point);
    }

    return 0;
}


Measured memory_bytes: 3152
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;

    vector<int> v[100001];
    int ct[100001];

    int par[100001];

    void bfs(int i)
    {
        //cout<<i<<endl;
        queue<int> q;
        q.push(i);
        int x;
        while(!q.empty())
        {
            x=q.front();
            //cout<<x<<endl;
            q.pop();
            for(int j=0;j<v[x].size();++j)
            {
                --ct[v[x][j]];
                //cout<<x<<" "<<v[x][j]<<" "<<ct[v[x][j]]<<endl;
                if(ct[v[x][j]]==0)
                {
                    par[v[x][j]]=x;
                    q.push(v[x][j]);
                }
            }
        }
    }

    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            int n,m,i,j,a,b;
            cin>>n>>m;
            int maxi=0;
            for(i=1;i<=n+m-1;++i)
            {
                cin>>a>>b;
                //maxi=max(maxi,max(a,b));
                v[a].pb(b);
                ++ct[b];
            }
            int rt=-1;
            for(i=1;i<=n;++i)
                if(ct[i]==0)
                    rt=i;
            bfs(rt);
            for(i=1;i<=n;++i)
                cout<<par[i]<<endl;
            cout<<endl;
        }
        return 0;
    }


Measured memory_bytes: 7040
n=gets.to_i
a=gets.split.map &:to_i
b=gets.split.map &:to_i

ans=0
n.times do |i|
    cnt1=[a[i],b[i]].min
    ans+=cnt1
    a[i]-=cnt1
    b[i]-=cnt1
    
    cnt2=[a[i+1],b[i]].min
    ans+=cnt2
    a[i+1]-=cnt2
    b[i]-=cnt2
end
p ans

Measured memory_bytes: 19588
import static java.lang.System.*;
import java.util.*;
import java.io.*;
import java.awt.*;
import java.awt.geom.Point2D;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc=new Scanner(in);
        int n = sc.nextInt(), k = sc.nextInt(), l = sc.nextInt();
        road.Init(n + 1);
        rail.Init(n + 1);
        int[] ans = new int[n + 1];

        for (int i = 0; i < k; i++) {
            int a = sc.nextInt(), b = sc.nextInt();
            road.unite(a, b);
        }

        for (int i = 0; i < l; i++) {
            int a = sc.nextInt(), b = sc.nextInt();
            rail.unite(a, b);
        }

        int[] d1=new int[n+1];
        int[] d2=new int[n+1];
        HashMap<Point,ArrayDeque<Integer>> map=new HashMap<>();

        for (int i = 1; i < n + 1; i++) {
            d1[i]=road.find(i);
            d2[i]=rail.find(i);
            Point p=new Point(d1[i],d2[i]);
            if(map.get(p)==null){
                ArrayDeque<Integer> temp=new ArrayDeque<>();
                temp.add(i);
                map.put(p,temp);
            }else {
                ArrayDeque<Integer> temp=map.get(p);
                temp.add(i);
                map.put(p,temp);
            }
        }

        for (Point p:map.keySet()){
            ArrayDeque<Integer> temp=map.get(p);
            int size=temp.size();
            while (!temp.isEmpty()){
                ans[temp.poll()]=size;
            }
        }

        for (int i = 1; i < n + 1; i++) {
            out.print(ans[i]);
            if (i < n) out.print(" ");
        }
        out.println();
    }

    static class road {
        static int[] d;

        static void Init(int size) {
            d = new int[size];
            for (int i = 0; i < size; i++) {
                d[i] = -1;
            }
        }

        static boolean unite(int x, int y) {
            x = find(x);
            y = find(y);
            if (x == y) return false;
            if (d[x] > d[y]) {
                int t = d[y];
                d[y] = d[x];
                d[x] = t;
            }
            d[x] += d[y];
            d[y] = x;
            return true;
        }

        static boolean same(int x, int y) {
            return find(x) == find(y);
        }

        static int find(int k) {
            return d[k] < 0 ? k : (d[k] = find(d[k]));
        }

    }

    static class rail {
        static int[] d;

        static void Init(int size) {
            d = new int[size];
            for (int i = 0; i < size; i++) {
                d[i] = -1;
            }
        }

        static boolean unite(int x, int y) {
            x = find(x);
            y = find(y);
            if (x == y) return false;
            if (d[x] > d[y]) {
                int t = d[y];
                d[y] = d[x];
                d[x] = t;
            }
            d[x] += d[y];
            d[y] = x;
            return true;
        }

        static boolean same(int x, int y) {
            return find(x) == find(y);
        }

        static int find(int k) {
            return d[k] < 0 ? k : (d[k] = find(d[k]));
        }

    }
}

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

def main():
    while 1:
        n, r = list(map(int,input().split()))
        l = list(range(n, 0, -1))
        if n == 0 and r == 0:
            return 0
        for _ in range(r):
            p, c = list(map(int, input().split()))
            l_ = l[p-1:p+c-1]
            l_.extend(l[:p-1])
            l_.extend(l[p+c-1:])
            l = l_
        print(l[0])


if __name__ == "__main__":
    main()


Measured memory_bytes: 5624
#include <stdio.h>

void insertionSort(int A[],int N){
  int i,j,v;
  for(i=1;i<N;i++){
    v=A[i];
    j=i-1;
    while(j>=0&&A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;

    for(j=0;j<N;j++){
      printf("%d",A[j]);
      if(j!=N-1) printf(" ");
    }
    printf("\n");
  }
}

int main(void){
  int N,i;
  scanf("%d",&N);
  int A[N];
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<N;i++){
    printf("%d",A[i]);
    if(i!=N-1) printf(" ");
  }
  printf("\n");
  insertionSort(A,N);
  return 0;
}


Measured memory_bytes: 2056
def decide_hand2(T, hand, i, K, N):
    if T[i] == "r":
        if i <= K - 1:
            hand[i] = "p"
        else:
            if hand[i - K] == "p":
                hand[i] = "-"
            else:
                hand[i] = "p"

    elif T[i] == "p":
        if i <= K - 1:
            hand[i] = "s"
        else:
            if hand[i - K] == "s":
                hand[i] = "-"
            else:
                hand[i] = "s"

    elif T[i] == "s":
        if i <= K - 1:
            hand[i] = "r"
        else:
            if hand[i - K] == "r":
                hand[i] = "-"
            else:
                hand[i] = "r"

def main():
    N, K = map(int, input().split())
    R, S, P = map(int, input().split())
    T = input()
    hand = ["" for _ in range(N)]

    for i in range(N):
        decide_hand2(T, hand, i, K, N)

    ans = 0
    for i in range(N):
        if hand[i] == "r":
            ans += R
        elif hand[i] == "s":
            ans += S
        elif hand[i] == "p":
            ans += P

    print(ans)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 10180
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        a: usize,
        b: usize,
        c: usize,
        d: usize,
    }

    if a+b>c+d {
        println!("Left");
    } else if a+b==c+d {
        println!("Balanced");
    } else {
        println!("Right");
    }

}


Measured memory_bytes: 2196
#include<bits/stdc++.h>
using namespace std;
 
const int mod=1000000007;
vector<pair<int,int> > v[1010];
int n,fa[1010],m,t[2010],tn,ans,mi[2010];
struct edg{int x,y,v;}e[2010];
long long X,nw;
 
int ask(int x) {return fa[x]==x?x:fa[x]=ask(fa[x]);}
bool cmp(edg a,edg b) {return a.v<b.v;}
 
int dfs(int x,int y,int la)
{
	if (x==y) return 0;
	for (int i=0,sz=v[x].size(); i<sz; i++)
		if (v[x][i].first!=la) 
		{
			int nw=dfs(v[x][i].first,y,x);
			if (nw!=-1) return max(nw,v[x][i].second);
		}
	return -1;
}
 
int main()
{
	mi[0]=1;
	for (int i=1; i<=2000; i++) mi[i]=2ll*mi[i-1]%mod;
	scanf("%d%d%lld",&n,&m,&X);
	if (n==1) return puts("0"),0;
	for (int i=1; i<=m; i++) scanf("%d%d%d",&e[i].x,&e[i].y,&e[i].v);
	sort(e+1,e+1+m,cmp),tn=0,nw=0;
	for (int i=1; i<=n; i++) fa[i]=i,v[i].clear();
	for (int i=1; i<=m; i++) 
	{
		if (ask(e[i].x)!=ask(e[i].y))
		{
			fa[ask(e[i].x)]=ask(e[i].y),nw+=e[i].v;
			v[e[i].x].push_back(make_pair(e[i].y,e[i].v));
			v[e[i].y].push_back(make_pair(e[i].x,e[i].v));
		} else t[++tn]=e[i].v-dfs(e[i].x,e[i].y,0);
	}
	sort(t+1,t+1+tn);
	if (nw>X) return puts("0"),0;
	if (nw==X) ans=1ll*(mi[n-1]+mod-2)*mi[m-n+1]%mod; else ans=0;
	for (int i=1; i<=tn; i++)
	{
		if (t[i]+nw<X) continue;
		if (t[i]+nw>X) break;
		ans=(ans+2ll*mi[tn-i])%mod; 
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
class UnionFind {
private:
  int siz;
  vector<int> a;

public:
  UnionFind(int x) : siz(x), a(x, -1) {}

  int root(int x) {
    return a[x] < 0 ? x : a[x] = root(a[x]);
  }

  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    siz--;
    if (a[x] > a[y]) swap(x, y);
    a[x] += a[y];
    a[y] =x;
    return true;
  }

  bool same(int x, int y) {
    return root(x) == root(y);
  }

  int size(int x) {
    return -a[root(x)];
  }
  
  int connected_component() {
  	return siz;
  }
};
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    uf.unite(a, b);
  }
  vector<int> done(n);
  int zero = uf.size(0);
  int one = uf.size(1);
  int rem = n - zero - one;
  int mi = min(zero, one);
  int mx = max(zero, one);
  cout << 1LL * mi * (mi - 1) / 2 + 1LL * (rem + mx) * (rem + mx - 1) / 2 - m << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int main() {
    char s[51];
    cin >> s;

    char *t = "AKIHABARA";

    int n = strlen(s), m = strlen(t);

    int b = 1;
    int j = 0;
    for (int i = 0;;) {
        if (j >= m) {
            if (i < n) b = 0;
            break;
        }
        if (i >= n) {
            if (j < 8) b = 0;
            break;
        }
        if (s[i] == t[j]) {
            i++;
            j++;
            continue;
        }
        if (t[j] == 'A') {
            j++;
            continue;
        }
        b = 0;
        break;
    }

    cout << (b ? "YES" : "NO") << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int answer = 0;
		for(int i = a;i <= b; i++) {
			if(i % 10 ==0) {
				continue;
			}
			String[] hoge = String.valueOf(i).split("");
			if(hoge[0].equals(hoge[4])
					&& hoge[1].equals(hoge[3])){
				answer++;
			}
		}
		System.out.println(answer);
	}

}

Measured memory_bytes: 57588
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<bitset>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
ll fact(ll x, ll k, ll p) {//最大値、個数、あまり
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x%p;
		x = x * x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
short ctos(char a) {
	return (int)(a - '0');
}
#define int long long
const long long Inf = 4523372036854775807;
const int inf = 15000000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++

signed main() {
	int n;
	cin >> n;
	if (n == 1) {
		cout << "Hello World" << endl;
	}
	else {
		int a, b;
		cin >> a >> b;
		cout << a + b << endl;
	}
}


Measured memory_bytes: 256
#include <cstdio>
using namespace std;
typedef long long ll;
const int N=300010;
const int MOD=998244353;
int n;
ll a,b,k;
int fact[N],iact[N];
void readData(){
	scanf("%d%lld%lld%lld",&n,&a,&b,&k);
}
int fmi(int x,int y){
	int res=1;
	for(;y;x=1ll*x*x%MOD,y>>=1)
		if(y&1)
			res=1ll*res*x%MOD;
	return res;
}	
void init(){
	fact[0]=fact[1]=1;
	for(int i=2;i<=n;i++) fact[i]=1ll*fact[i-1]*i%MOD;
	iact[0]=iact[1]=1;
	iact[n]=fmi(fact[n],MOD-2);
	for(int i=n-1;i>=2;i--) iact[i]=1ll*iact[i+1]*(i+1)%MOD;
}
inline int C(ll n,ll m){
	return m<=n?1ll*fact[n]*iact[m]%MOD*iact[n-m]%MOD:0;
}
void solve(){
	int ans=0;
	for(ll x=0,y;x<=n&&a*x<=k;x++)
		if((k-a*x)%b==0){
			y=(k-a*x)/b;
			(ans+=1ll*C(n,x)*C(n,y)%MOD)%=MOD;
		}
	printf("%d\n",ans<0?ans+MOD:ans);
}
int main(){
	readData();
	init();
	solve();
	return 0;
}

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

int main()
{
	int ara[55],n,k,i=0,j;
	long sum=0;
	cin>>n>>k;
	for(i=0; i<n; i++) {
		cin>>ara[i];
		//sort(ara,ara[]);

	}
	sort(ara,ara+i);
	for(int i=1;i<=k;++i){
		sum+=ara[n-i];
	}
	cout<<sum<<endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;


int n, a[101010], m;
i64 dp[101010];

int main(){
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		int d;
		cin >> d;
		a[d] = 1;
	}
	
	dp[0] = 1; dp[1] = 1;
	for(int i = 2; i <= n; i++){
		if(!a[i-1]) dp[i] += dp[i-1];
		if(!a[i-2]) dp[i] += dp[i-2];
		dp[i] %= INF;
	}
	cout << dp[n] << endl;
	
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
const int N=4e5+5;
int n,m,ty,now,b[N],v[N],vi[N],nex[N],head[N];
void addedges(int x,int y){
	nex[++now]=head[x];
	head[x]=now,v[now]=y;
}
long long c,one,two;
void dfs(int x,int y){
	vi[x]=y;
	for(int i=head[x];i;i=nex[i])
		if(!vi[v[i]])	dfs(v[i],y^1);
		else	if(vi[v[i]]==y)	ty=1;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		addedges(x,y),++b[x];
		addedges(y,x),++b[y];
	}
	for(int i=1;i<=n;i++)
		if(!vi[i]){
			if(!b[i])	++c;
			else{
				ty=0,dfs(i,2);
				if(ty)	++one;
				else	++two;
			}
		}
	printf("%lld\n",c*n*2-c*c+2*two*(two+one)+one*one);
	return 0;
}


Measured memory_bytes: 7552
#include <iostream>
#include <cstdio>
#include <string>
#include <map>

using namespace std;

int main() {
	int num;
	char blood[2];
	char row[1000];
	map<string, int> type;
	while(cin>>row){
		if(cin.eof()) break;
		sscanf(row,"%d,%s", &num, &blood);
		type[blood]++;
	}
	cout<<type["A"]<<endl;
	cout<<type["B"]<<endl;
	cout<<type["AB"]<<endl;
	cout<<type["O"]<<endl;
	return 0;
}

Measured memory_bytes: 1252
import collections

N=int(input())
S=[]
for i in range(N):
	S.append(input())
M=collections.Counter(S)
A=max(M.values())
tmp=[]
for i,j in M.items():
	if j==A:
		tmp.append(i)
ans=sorted(tmp)
for i in range(len(ans)):
	print(ans[i])

Measured memory_bytes: 35568
N,Y = list(map(int,input().split()))
f = True

for i in range(N+1):
  for j in range(N-i+1):
    k = N-i-j
    if 10000*i+5000*j+1000*k==Y:
      f = False
      print(i,j,k)
      exit()

if f:
  print(-1,-1,-1)

Measured memory_bytes: 3188
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String strArr[] = br.readLine().split(" ");
            long x = Long.parseLong(strArr[0]);
            long y = Long.parseLong(strArr[1]);
            if (x > 0) {
                if (y > 0) {
                    if (y >= x) {
                        System.out.println(y - x);
                    } else {
                        System.out.println((-1 * y) - (-1 * x) + 2);
                    }
                } else if (y < 0) {
                    if (x > Math.abs(y)) {
                        System.out.println(y - (-1 * x) + 1);
                    } else {
                        long diff = Math.abs(y) - x;
                        System.out.println(diff + 1);
                    }
                } else {
                    System.out.println(y - (-1 * x) + 1);
                }
            } else if (x < 0) {
                if (y > 0) {
                    if (Math.abs(x) > y) {
                        System.out.println((-1 * y) - x + 1);
                    } else {
                        long diff = y - (-1 * x);
                        System.out.println(diff + 1);
                    }
                } else if (y < 0){
                    if (Math.abs(x) >= Math.abs(y)) {
                        System.out.println(y - x);
                    } else {
                        long diff = (-1 * y) - (-1 * x);
                        System.out.println(diff + 2);
                    }
                } else {
                    System.out.println(y - x);
                }
            } else {
                if (y > 0) {
                    System.out.println(y - x);
                } else if (y < 0) {
                    System.out.println(Math.abs(y) - x + 1);
                } else {
                    System.out.println(0);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
           }
    }
}


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

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES puts("YES\n")
#define Yes puts("Yes\n")
#define NO  puts("NO\n")
#define No  puts("No\n")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }



signed main() {

	int a, b, c;
	cin >> a >> b >> c;
	set<int> s;
	s.insert(a);
	s.insert(b);
	s.insert(c);

	cout << s.size() << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>

typedef long long ll;

#define rep(i,n) for(int i = 0; i < n; i++)
#define debug(x) cerr << #x << ": " << x << "\n";

using namespace std;
 
const ll INF = ll(1e18)+1;
const double PI=3.14159265358979323846;

int main(){
  ll n, ans=0;
  cin >> n;
  string tmp;
  for(int i=1; i<=n; i++){
    if(i%3==0 && i%5==0) tmp = "FizzBuzz";
    else if(i%3==0) tmp = "Fizz";
    else if(i%5==0) tmp = "Buzz";
    else ans += i;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3628
require 'pp'
# IS_DEBUG = true
IS_DEBUG = false
def dputs str
	if(IS_DEBUG)
		puts str
	end
end
def dpp str
	if(IS_DEBUG)
		pp str
	end
end

MAX_INT = 9999999999999999

N,_=gets.chomp.split(' ').map{|n| n.to_i}
A=gets.chomp.split(' ').map{|n| n.to_i}
prv = -1
cnt = 0
0.upto(N-1){|i|
	cur = A[i]
	if(prv == cur)
		cnt += 1
		prv = -1
	else
		prv = cur
	end
}
puts cnt


Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
int cnt = 0;

void printVec(vector<int> vec) {
  for (auto e : vec) {
    cout << e << endl;
  }
}

vector<int> insertionSort(vector<int> A, int g) {
  auto N = A.size();
  for (int i = g; i < N; i++) {
    for (int j = i - g; 0 <= j; j -= g) {
      if (A[j] > A[j + g]) {
        auto tmp = A[j];
        A[j] = A[j + g];
        A[j + g] = tmp;
        cnt++;
      } else {
        break;
      }
    }
  }
  return A;
}

vector<int> shellSort(vector<int> A) {
  vector<int> G = {1};
  while (true) {
    auto g_next = 3 * G[G.size() - 1] + 1;
    if (g_next < A.size())
      G.push_back(g_next);
    else {
      break;
    }
  }
  reverse(G.begin(), G.end());
  auto m = G.size();

  for (auto g : G) {
    A = insertionSort(A, g);
  }
  cout << m << endl;
  for (size_t i = 0; i < m; i++) {
    if (i == m - 1) {
      cout << G[i] << endl;
    } else {
      cout << G[i] << " ";
    }
  }

  cout << cnt << endl;

  printVec(A);
  return A;
}

int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  for (size_t i = 0; i < n; i++) {
    cin >> A[i];
  }

  shellSort(A);
}


Measured memory_bytes: 14528
/*
 *
 *   Author     : Amit Kumar
 *   Date 	: June 22, 2019
 * 
 */

#include <bits/stdc++.h>

//#define MORE_THAN_ONE_TESTCASE // COMMENT IT

#define vi vector<int>
#define vl vector<long long>
#define mii map<int , int>
#define mll map<long long , long long>
#define msi map<string , i>
#define msl map<string , long long>
#define si set<int>
#define sl set<long long>
#define pii pair<int , int >
#define psi pair<string,int>
#define psl pair<string , long > 
#define pll pair<long long , long long>
#define vpii vector<pii>
#define vpll vector<pll>
#define vpsi vector<psi>
#define vpsl vector<psl>
#define _ub upper_bound
#define _lb lower_bound
#define bint long long int
#define _in(x) scanf("%lld",&x)
#define _f first
#define _s second
#define _all(x) x.begin(),x.end()
#define _pb push_back
#define _eb emplace_back
#define _mp make_pair
#define _iv(v) for(auto &i:v){cin>>i;}
#define _ov(v) for(auto i:v){cout<<i<<" ";}cout<<endl;
#define _ovn(v) for(auto i:v){cout<<i<<endl;}
#define _euv(v) for(auto i:v){cerr<<i<<" ";}cerr<<endl;
#define _eovn(v) for(auto i:v){cerr<<i<<endl;}
#define _os(s) for(auto itr:s){cout<<itr<<" ";}cout<<endl;
#define _osn(s) for(auto itr:s){cout<<itr<<endl;}
#define _eos(s) for(auto itr:s){cerr<<itr<<" ";}cerr<<endl;
#define _eosn(s) for(auto itr:s){cerr<<itr<<endl;}
#define _rep(x) for(auto i=0 ; i<(x); ++i)
#define _repe(x) for(auto i=0; i<=(x); ++i)
#define _irep(a,b) for(auto i=(a); i<(b); ++i)
#define _irepe(a,b) for(auto i=(a); i<=(b); ++i)
#define _crep(a,b,c) for(auto i=(a); i<(b); i+=(c))
#define _crepe(a,b,c) for(auto i=(a); i<=(b); i+=(c))
#define _min(x,y) ((y) ^ (((x) ^ (y)) & (-((x) < (y)))))
#define _max(x,y) ((x) ^ (((x) ^ (y)) & (-((x) < (y)))))
#define endl '\n'
using namespace std;




auto SOLUTION_FUNCTION( void ) ->void {

    // your solution goes here 
    
    int n , l;
    cin>>n>>l;
    bint ans = INT_MAX;
    bint sum =0;
    for(int i=1; i<=n;  ++i){
        sum+= l+i-1;
//        cout<<l+i-1<<" ";
        if(abs(l+i-1) < abs(ans))
            ans = l+i-1;
    }
  //  cout<<"ans = "<<ans<<endl;
   // cout<<"sum = "<<sum<<endl;
    if(ans > 0)
        cout<<sum-ans<<endl;
    else 
        cout<<sum+abs(ans)<<endl;
    return ;
}




int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout<<setprecision(10);
    cout<<fixed;
    cout<<boolalpha;
#ifdef MY_LOCAL_PROJECT
    freopen("input","r",stdin);
    freopen("output","w",stdout);
#endif
    int testcase = 1;


#ifdef MORE_THAN_ONE_TESTCASE
    cin>>testcase;
#endif
    
    while(testcase--){
        SOLUTION_FUNCTION();
    }

#ifdef MY_LOCAL_PROJECT
    cout<<"Time : "<<1.0*(double)clock()/CLOCKS_PER_SEC<<endl;
#endif
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define all(in) in.begin(),in.end()

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

using ll = long long;
using namespace std;
const ll INF = 100100100100100;

int main(){
    // 入力
    ll n; cin >> n;
    vector<ll> x(n), y(n), p(n), ans(n+1,INF);
    rep(i,n) cin >> x[i] >> y[i] >> p[i];
    // 前処理
    vector<vector<ll>> prex(1<<n,vector<ll>(n)), prey(1<<n,vector<ll>(n));
    rep(i,1<<n){
        rep(j,n) { prex[i][j] = abs(x[j]); prey[i][j] = abs(y[j]); }
        rep(j,n) if(i & 1<<j) rep(k,n) { chmin(prex[i][k],abs(x[k]-x[j])); chmin(prey[i][k],abs(y[k]-y[j])); }
    }
    // 本処理
    ll count = 1; rep(i,n) count *= 3;
    rep(i,count){
        vector<ll> dist(n,INF);
        ll xnum = 0, ynum = 0;
        ll num = 1, bit = n, save = i;
        rep(j,n){
            if(save % 3 == 0) bit--;
            else if(save % 3 == 1) xnum += num;
            else if(save % 3 == 2) ynum += num;
            num *= 2; save /= 3;
        }
        rep(j,n){ chmin(dist[j],prex[xnum][j]); chmin(dist[j],prey[ynum][j]); }
        ll change = 0; rep(j,n) change += dist[j] * p[j];
        chmin(ans[bit],change);
    }
    rep(i,n+1) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 12960
S=input()
if (S[0]==S[1] and S[2]==S[3] and S[0]!=S[2]) or (S[0]==S[2] and S[1]==S[3] and S[0]!=S[1]) or (S[0]==S[3] and S[1]==S[2] and S[0]!=S[1]):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	vector<int> vec(2);
	while (1) {
		cin >> vec[0] >> vec[1];
		if (vec[0] == 0 && vec[1] == 0) break;
		sort(vec.begin(), vec.end());
		cout << vec[0] << " " << vec[1] << endl;
	}
	return 0;
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);    
#define f(i,j,k)  for(int i=j;i<k;i++)
#define fr(i,j,k) for(int i<=k-1;i>=j;i--)
#define ll long long
#define ld long double
#define pb push_back
#define all(x) x.begin(),x.end()
#define MOD 2019
using namespace std;

int main()
{
	fio
	string s;
	cin>>s;
	int n = s.size();
	int hash[MOD]={0};
	ll val=0,pot=1;
	hash[val]=1;
	int ans=0;
	for(int i=n-1;i>=0;i--)
	{
		val = (val + (s[i]-'0')*pot)%MOD;
		pot = (pot*10)%MOD;
		ans+=hash[val];
		hash[val]++;
	}
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;

int N,x,a[2010],mi[2010][2010];
typedef long long LL;
LL ans = 1e18;

int main() {
    scanf("%d%d",&N,&x);
    for (int i=1;i<=N;i++) {
        scanf("%d",&a[i]);
    }
    for (int i=1;i<=N;i++) {
        mi[i][i] = a[i];
        for (int j=i+1;j<=N;j++) {
            mi[i][j] = min(mi[i][j-1], a[j]);
        }
    }

    for (int t=0;t<=N;t++) {
        LL tmp = 1LL * t * x;
        for (int i=1;i<=N;i++) {
            if (i - t <= 0) {
                tmp += min(mi[1][i], mi[N - t + i][N]);
            } else {
                tmp += mi[i - t][i];
            }
        }
        ans = min(ans, tmp);
    }
    printf("%lld\n",ans);
}

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

string s;

int main() {
	int n,T;
	cin >> n >> T;
	cin >> s;
	for(int i = 0 ; i < s.size() ; i++)
		if( s[i] == '+' ) s[i] = ' ';
	{
		stringstream ss(s);
		string t;
		double sum = 0;
		while( ss >> t ){
			for(int i = 0 ; i < t.size() ; i++)
				if( t[i] == '^' || t[i] == 'n') t[i] = ' ';
			stringstream ss2(t);
			double b;
			ss2 >> b;
			sum += pow(n,b);
		
		}
	
		if( sum*T > 1e10 ){
			cout << "TLE" << endl;
			return 0;
		}
	}

	
	{
		stringstream ss(s);
		string t;
		long long sum = 0;
		while( ss >> t ){
			for(int i = 0 ; i < t.size() ; i++)
				if( t[i] == '^' || t[i] == 'n') t[i] = ' ';
			stringstream ss2(t);
			long long b;
			ss2 >> b;
			sum += (long long)(pow(n,b)+1e-9);
		
		}
		if( sum*T > 1000000000 ){
			cout << "TLE" << endl;
			return 0;
		}
		cout << sum*T << endl;
	}
	
	
}

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

using namespace std;
using i64 = int64_t;

int main(){
    int N;
    cin >> N;
    map<char, i64> m;
    for(int i=0;i<N;i++){
        string s;
        cin >> s;
        m[s[0]]++;
    }
    i64 ans = 0;
    ans += m['M'] * m['A'] * m['R'];
    ans += m['M'] * m['A'] * m['C'];
    ans += m['M'] * m['A'] * m['H'];
    ans += m['C'] * m['A'] * m['R'];
    ans += m['H'] * m['A'] * m['R'];
    ans += m['M'] * m['C'] * m['R'];
    ans += m['M'] * m['H'] * m['R'];
    ans += m['C'] * m['A'] * m['H'];
    ans += m['H'] * m['C'] * m['R'];
    ans += m['M'] * m['C'] * m['H'];
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int f(string s) {
    int result = 0;
    for (int i = 0; i < s.size(); i++) {
        result += s[i] - '0';
    }
    return result;
}

int main() {

    string s;
    cin >> s;

    int result = f(s);
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        
        if(a<b){
            if(b<c) System.out.println(a + " " + b + " " + c);
            else if(c<a) System.out.println(c + " " + a + " " + b);
            else System.out.println(a + " " + c + " " + b);
        }
        if(b<a){
            if(a<c) System.out.println(b + " " + a + " " + c);
            else if(c<b) System.out.println(c + " " + b + " " + a);
            else System.out.println(b + " " + c + " " + a);
        }
    }
}


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

using namespace std;

int main() {
  int N;
  cin >> N;
  
  vector<int> costs(N);
  
  for (int n = 0; n < N; ++n) {
    cin >> costs[n];
  }
  
  std::vector<int> dp(N);
  dp[1] = abs(costs[1] - costs[0]);
  for (int n = 2; n < N; ++n) {
    dp[n] = min(dp[n-2] + abs(costs[n] - costs[n-2]), dp[n-1] + abs(costs[n] - costs[n-1]));
  }
  cout << dp[N-1] << endl;
  
  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
#include <ctype.h>

void to_lower_str(char *str);

int main(void)
{
  char word[11], pw[1001];
  int wlen,count=0;

  scanf("%s", word);
  scanf("%s", pw);
  to_lower_str(word);
  wlen=strlen(word);

  while (strcmp(pw, "END_OF_TEXT")!=0) {
    to_lower_str(pw);
    if (strstr(pw, word)==pw && pw[wlen]=='\0')
      count++;
    scanf("%s", pw);
  }

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

  return 0;
}

void to_lower_str(char *str) {
  while(*str!='\0') {
    *str=tolower(*str);
    str++;
  }
}

Measured memory_bytes: 2736
n, m, k = gets.chomp.split(" ").map(&:to_i)

ans = 0
for i in 0..n
    for j in 0..m
        if (i * m + j * n - 2 * i * j) == k
            ans = 1
        end
    end
end

if ans == 1
    puts "Yes"
else
    puts "No"
end


Measured memory_bytes: 1788