akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
  map<string,int> a;
  string s,maxs,maxms;
  while(cin>>s){
    a[s]++;
    if(a[maxs]<a[s])maxs=s;
    if(maxms.size()<s.size()) maxms=s;
  }
  cout<<maxs<<' '<<maxms<<endl;
}

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

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    loop {
        let h: usize = read();
        let w: usize = read();
        if h == 0 && w == 0 {
            break;
        }
        for _ in 0..h {
            println!("{}", "#".repeat(w));
        }
        println!{""};
    }
    
    
}



Measured memory_bytes: 5028
#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;
//参考http://kagamiz.hatenablog.com/entry/2013/02/16/193159 
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
int n,m;//チームの個数と与えられた勝敗の個数
vector<int> W[5000],L[5000],rank;
int visit[5000];
void dfs(int i){
  visit[i] = 1;
  for(int j = 0;j < W[i].size();j++){
    if(!visit[W[i][j]])
      dfs(W[i][j]);
  }
  rank.push_back(i);
}

int main()
{
  cin >>n;
  cin >>m;
  int a,b;
  for(int i = 0;i < m;i++){
    cin >>a>>b;
    a--;
    b--;
    W[a].push_back(b);
    L[b].push_back(a);
  }
  for(int i = 0;i < n;i++){
    if(L[i].size() ==0)
      dfs(i);
  }
  bool ans;
  for(int i = n-1; i >=0;i--){
    cout <<rank[i]+1<<endl;
    if(i){
      bool flag1 = true;
      for(int j = 0;j <W[rank[i]].size();j++){
	if(W[rank[i]][j] ==rank[i-1])
	  flag1 = false;
      }
	ans |= flag1;
    }
  }
  cout <<ans<<endl;
  
  return 0;
}

Measured memory_bytes: 2952
import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect

n=int(input())
c=0
for i in range(n):
    a=int(input())
    if a%2==0:
        c+=1

if c==n:
    print("second")
else:
    print("first")

Measured memory_bytes: 79988
i,j = [int(x) for x in input().split()]
a = [[0 for x in range(j)] for y in range(i)]
b = [0 for x in range(j)]
ans = [0 for x in range(i)]
for x in range(i):
    a[x] = [int(n) for n in input().split()]
for y in range(j):
    b[y] = int(input())
for x in range(i):
    for y in range(j):
        ans[x] += a[x][y]*b[y]
    print(ans[x])



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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    a -= b;
    if(a == 0){
        cout << c << endl;
    }
    else if(c - a >= 0){
        cout << c - a << endl;
    }
    else {
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

typedef long long ll;

struct K {
  string s;
  int p;
  int i;
};

bool operator<(const K& k1, const K& k2) {
  if(k1.s != k2.s) return k1.s < k2.s;
  return k1.p > k2.p;
}

int main(void) {
  int n;
  cin >> n;
  vector<K> vs;
  REP(i, n) {
    string s;
    int p;
    cin >> s >> p;
    vs.push_back((K){s, p, i});
  }
  sort(vs.begin(), vs.end());
  REP(i, vs.size()) {
    cout << vs[i].i+1 << endl;
  }
    
  return 0;
}


Measured memory_bytes: 256
while(a,b,c=gets.split.map(&:to_i))!=[-1,-1,-1]
if 2.step(16).none?{|base|begin Integer(a.to_s(base))==b rescue nil end} then p -1;next end
(a+1).step(c){|i|b=2.step(16).map{|base|begin z=i.to_s(base).to_i;b<=z ? z : 1e9 rescue 1e9 end}.min}
p b
end

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

#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair()
#define FOR(i, a, b) for (int i=a; i<(b); i++)
int main()
{
    ios_base::sync_with_stdio (false) ;
    cin.tie(0) ; cout.tie(0) ;
    ll n;
    cin>>n;
    multiset<int,greater<int>>s;
    int arr[n];

   FOR(i,0,n)
   {
    int a; cin>>a; s.insert(a); arr[i]=a;
    }


     FOR(i,0,n)
     {
         int st=*s.begin();
         if(arr[i]!=*s.begin())
            cout<<*s.begin()<<endl;
         else
         {
             s.erase(s.begin());
             cout<<*s.begin()<<endl;
             s.insert(st);
         }
     }
}


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

//RSQ
struct SegmentTree{
private:
	int N;
	vector<long long> node, lazy;
	vector<bool> lazyFlg;
	const long long DEFAULT = 0LL;
public:
	void init(int n){ //初期化 O(N)
		node.clear();
		lazy.clear();
		lazyFlg.clear();
		N = 1;
		while(N < n) N = (N<<1);
		for(int i=0; i<2*N-1; i++){
			node.push_back(DEFAULT);
			lazy.push_back(0LL);
			lazyFlg.push_back(false);
		}
	}
	void eval(int k, int l, int r){ //遅延評価 O(1)
		if(lazyFlg[k]){ //RUQ：下に更新クエリが溜まっていても加算クエリが溜まっていても上書き
			node[k] = lazy[k];
			if(r-l > 1){
				lazy[2*k+1] = lazy[k] / 2;
				lazyFlg[2*k+1] = true;
				lazy[2*k+2] = lazy[k] / 2;
				lazyFlg[2*k+2] = true;
			}
			lazy[k] = 0LL;
			lazyFlg[k] = false;
		}
		else{ //RAQ：下に更新クエリが溜まっていても加算クエリが溜まっていても加算
			node[k] += lazy[k];
			if(r-l > 1){
				lazy[2*k+1] += lazy[k] / 2;
				lazy[2*k+2] += lazy[k] / 2;
			}
			lazy[k] = 0LL;
		}
	}
	void update(int a, long long x){ //[a,a+1)の値を変更 O(log N)
		update(a, a+1, x);
	}
	void update(int a, int b, long long x, int k=0, int l=0, int r=-1){ //[a,b)の値を変更 O(log N)
		if(r == -1) r = N;
		eval(k, l, r);
		if(b <= l || r <= a) return; //交差する場合
		if(a <= l && r <= b){ //完全に含む場合
			lazy[k] = x * (r-l);
			lazyFlg[k] = true;
			eval(k, l, r);
		}
		else{
			update(a, b, x, 2*k+1, l, (l+r)/2);
			update(a, b, x, 2*k+2, (l+r)/2, r);
			node[k] = node[2*k+1] + node[2*k+2];
		}
	}
	void add(int a, long long x){ //[a,a+1)の値に加算 O(log N)
		add(a, a+1, x);
	}
	void add(int a, int b, long long x, int k=0, int l=0, int r=-1){ //[a,b)の値に加算 O(log N)
		if(r == -1) r = N;
		eval(k, l, r);
		if(b <= l || r <= a) return; //交差する場合
		if(a <= l && r <= b){ //完全に含む場合
			lazy[k] += x * (r-l);
			eval(k, l, r);
		}
		else{
			add(a, b, x, 2*k+1, l, (l+r)/2);
			add(a, b, x, 2*k+2, (l+r)/2, r);
			node[k] = node[2*k+1] + node[2*k+2];
		}
	}
	long long sum(int a, int b, int k=0, int l=0, int r=-1){ //[a,b)の和 O(log N)
		if(r == -1) r = N;
		if(b <= l || r <= a) return DEFAULT; //交差する場合
		eval(k, l, r);
		if(a <= l && r <= b) return node[k]; //完全に含む場合
		return sum(a, b, k*2+1, l, (l+r)/2) + sum(a, b, k*2+2, (l+r)/2, r);
	}
};

int main(){
	int N, Q;
	cin >> N >> Q;
	SegmentTree st;
	st.init(N+1);
	for(int q=0; q<Q; q++){
		int c, x, y;
		cin >> c >> x >> y;
		if(c == 0) st.add(x, y);
		else cout << st.sum(x, y+1) << endl;
	}
}


Measured memory_bytes: 7160
#include <iostream>
#include <limits>
#include <algorithm>
using namespace std;

int c[100][100];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, t;
    int M[101];
    cin>>n;
    cin>>M[0]>>M[1];
    for(int i=2; i<=n; i++) {
        cin>>t>>M[i];
    }
    for(int l=1; l<n; l++) {
        for(int i=0; i+l<n; i++) {
            int cost=numeric_limits<int>::max();
            for(int j=i+1; j<=i+l; j++) {
                cost=min(cost, c[i][j-1]+M[i]*M[j]*M[i+l+1]+c[j][i+l]);
            }
            c[i][i+l]=cost;
        }
    }
    cout<<c[0][n-1]<<'\n';
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
typedef long long ll;

int gi() {
	int x=0,o=1;char ch=getchar();
	while(!isdigit(ch)&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x*o;
}

struct dat {
	int l,r;
	bool operator<(const dat &A) const {
		return r<A.r;
	}
} a[N];

int n,pre1[N],suf1[N],pre2[N],suf2[N],ans;

int len(int l,int r) {
	if(l>r) return 0;
	return r-l+1;
}

int main() {
	cin>>n;
	for(int i=1;i<=n;i++) a[i].l=gi(),a[i].r=gi();
	sort(a+1,a+n+1);
	pre2[0]=1e9;
	for(int i=1;i<=n;i++) {
		pre1[i]=max(pre1[i-1],a[i].l);
		pre2[i]=min(pre2[i-1],a[i].r);
	}
	suf2[n+1]=1e9;
	for(int i=n;i;i--) {
		suf1[i]=max(suf1[i+1],a[i].l);
		suf2[i]=min(suf2[i+1],a[i].r);
	}
	for(int i=1;i<=n;i++) {
		int L=max(pre1[i-1],suf1[i+1]);
		int R=min(pre2[i-1],suf2[i+1]);
		ans=max(ans,a[i].r-a[i].l+1+len(L,R));
		if(i^n) ans=max(ans,len(pre1[i],pre2[i])+len(suf1[i+1],suf2[i+1]));
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 2688
n = int(input())
s = [int(x) for x in input().split()]

q = int(input())
t = [int(x) for x in input().split()]

c = 0

for i in range(len(t)):
    for j in range(len(s)):
        if(s[j] == t[i]):
            c = c + 1
            break

print(c)


Measured memory_bytes: 6556
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {

		BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));

		int counter = 0;
		ArrayList<Integer[]> alResult = new ArrayList<Integer[]>();

		while((counter = Integer.parseInt(bufferedReader.readLine())) != 0){
			int playerA = 0;
			int playerB = 0;

			for(int i = 0; i < counter; i++) {
				String[] arrCard = bufferedReader.readLine().split(" ");

				int playerACard = Integer.parseInt(arrCard[0]);
				int playerBCard = Integer.parseInt(arrCard[1]);

				if(playerACard > playerBCard) playerA += playerACard + playerBCard;
				else if(playerACard < playerBCard) playerB += playerACard + playerBCard;
				else{
					playerA += playerACard;
					playerB += playerBCard;
				}
			}

			Integer[] arrResult = new Integer[2];
			arrResult[0] = playerA;
			arrResult[1] = playerB;

			alResult.add(arrResult);
		}

		for(int i = 0; i < alResult.size(); i++) System.out.println(alResult.get(i)[0] + " " + alResult.get(i)[1]);
	}
}

Measured memory_bytes: 35152
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.nextLine();
    int min = Integer.MAX_VALUE;

    for(int i = 0; i + 2 < s.length(); i++){
      String ss = s.substring(i, i+3);
      min = Math.min(Math.abs(753 - Integer.parseInt(ss)), min);
    }

    System.out.println(min);
  }
}

Measured memory_bytes: 21716
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        String s = sc.next();
        
        char c = s.charAt(0);
        int res = 0;
        
        for(int i = 1; i < n; i++){
            if(s.charAt(i) != c){
                res++;
                c = s.charAt(i);
            }
        }
        
        System.out.println(res+1);
    }
}


Measured memory_bytes: 25320
import itertools
from sys import stdin
input = stdin.readline


def main():
  N = int(input())
  P = tuple(map(int, input().split()))
  Q = tuple(map(int, input().split()))

  orders = list(itertools.permutations(range(1, N+1)))

  a = -1
  b = -1
  for i, seq in enumerate(orders):
    if seq == P:
      a = i
    if seq == Q:
      b = i

  print(abs(a-b))


if(__name__ == '__main__'):
  main()


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

int main()
{
  long n, k;
  cin >> n >> k;
  long m = 0;
  for(int i = k; i <= n+1; ++i){
    m += ((n - i + 1) * i + 1);
    m = m%1000000007;
  }
  cout << m << endl;
}


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

typedef long long ll;
typedef pair<ll, ll> pll;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define dump(x)  cout << #x << " = " << (x) << endl
#define vuni(v) v.erase(unique(v.begin(), v.end()), v.end());
#define mins(m, s) m.insert(make_pair(s, 1));
#define mfin(m, s) m.find(s) != m.end()

#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int ans = c - (a - b);
    if(ans >= 0) {
        cout << ans << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>

char s[200],p[200];

int main(void){
    int sl,pl,i,j;
    scanf("%s",s);
    scanf("%s",p);

    i = 0;
    while(s[i] != '\0')
        i++;
    sl = i;
    i = 0;
    while(p[i] != '\0')
        i++;
    pl = i;

    for(i = 0;i < sl;i++){
        for(j = 0;j < pl;j++){
            if(s[(i + j) % sl] != p[j])
                break;
        }
        if(j == pl){
            printf("Yes\n");return 0;
        }
    }
    printf("No\n");
    return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	string a,b;
	cin>>a>>b;
	if(a=="H"){
		if(b=="H"){
			cout<<"H"<<endl;
		}else {
			cout<<"D"<<endl;
		}
	}else{
		if(b=="H"){
			cout<<"D"<<endl;
		}else{
			cout<<"H"<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
S = list(input())

A = S[0] + S[1]
B = S[2] + S[3]

if A <= "12" and A > "00":
    if B <= "12" and B > "00":
        print("AMBIGUOUS")
    else:
        print("MMYY")
elif B <= "12" and B > "00":
    print("YYMM")
else:
    print("NA")


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

struct card{
    char ch;
    int a;
};

int main(void){
    int n;
    card c[36], bubc[36], selc[36];
    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> c[i].ch >> c[i].a;
        bubc[i] = c[i];
        selc[i] = c[i];
    }
    bool flag = true, stable = true;

    while(flag){
        flag = false;
        for(int i = n-1; i > 0; --i){
            if(bubc[i].a < bubc[i-1].a){
                swap(bubc[i], bubc[i-1]);
                flag = true;
            }
        }
    }
    for(int i = 0; i < n; ++i){
        for(int j = i+1; j < n; ++j){
            for(int k = 0; k < n; ++k){
                for(int l = k+1; l < n; ++l){
                    if((c[i].a == c[j].a) && (c[i].a == bubc[l].a) && (c[i].ch == bubc[l].ch) && (c[j].a == bubc[k].a) && (c[j].ch == bubc[k].ch)) stable = false;
                }
            }
        }
    }
    for(int i = 0; i < n-1; ++i) cout << bubc[i].ch <<  bubc[i].a << ' ';
    cout << bubc[n-1].ch << bubc[n-1].a << endl << ((stable)? "Stable" : "Not stable") << endl;

    stable = true;
    for(int i = 0; i < n; ++i){
        int minj = i;
        for(int j = i; j < n; ++j){
            if(selc[j].a < selc[minj].a) minj = j;
        }
        swap(selc[i], selc[minj]);
    }
    for(int i = 0; i < n; ++i){
        for(int j = i+1; j < n; ++j){
            for(int k = 0; k < n; ++k){
                for(int l = k+1; l < n; ++l){
                    if((c[i].a == c[j].a) && (c[i].a == selc[l].a) && (c[i].ch == selc[l].ch) && (c[j].a == selc[k].a) && (c[j].ch == selc[k].ch)) stable = false;
                }
            }
        }
    }
    for(int i = 0; i < n-1; ++i) cout << selc[i].ch << selc[i].a << ' ';
    cout << selc[n-1].ch << selc[n-1].a << endl << ((stable)? "Stable" : "Not stable") << endl;
    return 0;
}


Measured memory_bytes: 3120
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------


int main(){
ll a,b;
cin>>a>>b;
if((a*b)%2==0){
    cout<<"No"<<endl;
}else{
    cout<<"Yes"<<endl;
}
}









Measured memory_bytes: 256
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#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>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#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++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, K;
    cin >> N >> K;
    vint p(N);
    rep(i, N) cin >> p[i];
    
    vll S(1000 + 1, 0);
    REP(i, 1, 1001) {
        S[i] = S[i - 1] + i;
    }

    int max_i = 0;
    int max_p = 0;
    int su = 0;
    rep(i, K) {
        su += p[i];
    }
    max_p = su;
    REP(i, 1, N - K + 1) {
        su = su - p[i - 1] + p[i - 1 + K];
        if (max_p < su) {
            max_i = i;
            max_p = su;
        }
    }

    double ans = 0;
    REP(i, max_i, max_i + K) {
        ans += double(S[p[i]]) / double(p[i]);
    }

    //vector<double> E(N);
    //rep(i, N) {
    //    E[i] = double(S[p[i]]) / double(p[i]);
    //}

    printf("%20.10f\n", ans);
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

struct collide{
	int a,b;
	double time;
};

bool operator<(const collide &a, const collide &b) {
	return a.time < b.time;
}

int n;
double stars[200][8];

double check(int i, int j) {
	double x = stars[i][0]-stars[j][0];
	double y = stars[i][1]-stars[j][1];
	double z = stars[i][2]-stars[j][2];
	double vx = stars[i][3]-stars[j][3];
	double vy = stars[i][4]-stars[j][4];
	double vz = stars[i][5]-stars[j][5];
	double r = stars[i][6]+stars[j][6];
	double vr = stars[i][7]+stars[j][7];
	double a = vx*vx+vy*vy+vz*vz-vr*vr;
	double b = x*vx+y*vy+z*vz+r*vr;
	b*=2.0;
	double c = x*x+y*y+z*z-r*r;
	double rt = b*b-4.0*a*c;
	if(a==0.0) return -1.0;
	if(rt<0.0) return -1.0;
	//printf("i,j rt,a,b = %d,%d,%lf,%lf,%lf\n",i,j,rt,a,b);
	double ans1 = (-b-sqrt(rt))/2.0/a;
	double ans2 = (-b+sqrt(rt))/2.0/a;
	double ret = min(ans1,ans2);
	if(ret<0.0) ret = max(ans1,ans2);
	return ret;
}

int main() {
	while(true) {
		scanf("%d",&n);
		if(n<=0) break;
		vector<collide> cols;
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < 8; j++) {
				scanf("%lf",&stars[i][j]);
			}
		}

		//rintf("-----collide----\n");
		for(int i = 0; i < n; i++) {
			for(int j = i+1; j < n; j++) {
				double collide_time = check(i,j);
				//printf("%d,%d,%lf\n",i,j,collide_time);
				if(collide_time>0.0) {
					collide col{i,j,collide_time};
					cols.push_back(col);
				}
			}
			collide col{i,-1,stars[i][6]/stars[i][7]};
			cols.push_back(col);
		}

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

/*
		printf("-----vector----\n");
		for(int i = 0; i < cols.size(); i++) {
			printf("%d,%d,%lf\n",cols[i].a,cols[i].b,cols[i].time);
		}
		printf("-----calc----\n");
		*/
		double desp_times[200]{};
		for(int i = 0; i < cols.size(); i++) {
			int a = cols[i].a;
			int b = cols[i].b;
			double desp = cols[i].time;
			if(desp_times[a]==0.0) {
				if(b==-1||desp_times[b]==0.0) {
					desp_times[a] = desp;
					if(b!=-1) desp_times[b] = desp;
				}
			}
		}

		for(int i = 0; i < n; i++) {
			printf("%.10lf\n",desp_times[i]);
		}
	}
}



Measured memory_bytes: 3196
import java.util.*

fun main(args: Array<String>) {
    val (N, Q) = readLine()!!.split(" ").map { it.toInt() }
    val list = Array(N) { ArrayList<Int>() }
    repeat(N - 1) {
        val (ai, bi) = readLine()!!.split(" ").map { Integer.parseInt(it) }
        list[ai - 1].add(bi - 1)
        list[bi - 1].add(ai - 1)
    }
    val dist = Array(N) { -1 }
    val oya = Array(N) { -1 }
    val ko = Array(N) { ArrayList<Int>() }
    val pq = ArrayDeque<Int>()
    dist[0] = 0
    pq.add(0)
    while (pq.isNotEmpty()) {
        val node = pq.poll()
        for (v in list[node]) {
            if (dist[v] != -1) continue
            dist[v] = dist[node] + 1
            pq.add(v)
            oya[v] = node
            ko[node].add(v)
        }
    }

    val cost: Array<Int> = Array(N) { 0 }
    repeat(Q) {
        val (pi, xi) = readLine()!!.split(" ").map { Integer.parseInt(it) }
        cost[pi - 1] += xi
    }

    val pq2 = ArrayDeque<Node>()
    pq2.add(Node(0, cost[0]))
    while (pq2.isNotEmpty()) {
        val v = pq2.poll()
        ko[v.id].forEach {
            cost[it] += v.cost
            pq2.add(Node(it, cost[it]))
        }
    }
    println(cost.joinToString(" "))
}

data class Node(val id: Int, val cost: Int)

Measured memory_bytes: 173504
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;

int main()
{
    string S, T;
    cin >> S >> T;
    map<char, char> sigma, inv;
    int n = S.size();
    rep(i, n)
    {
        if (sigma.count(S[i]) == 0)
            sigma[S[i]] = T[i];
        else if (sigma[S[i]] != T[i])
        {
            cout << "No";
            return 0;
        }

        if (inv.count(T[i]) == 0)
            inv[T[i]] = S[i];
        else if (inv[T[i]] != S[i])
        {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}

Measured memory_bytes: 916
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<random>
#include<set>
#include<map>
#include<functional>
using namespace std;
#define int long long
#define inf 21000000145141919
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int>P;
struct edge { int to, cost; };
set<int>S;
signed main() {
	int a, b; cin >> a >> b;
	cout <<(b - a)*(b-a + 1) / 2 -b<< endl;
}

Measured memory_bytes: 256
while True:
    n = int(raw_input())
    if n == 0: break
    field = [raw_input() for i in range(n)]
    large = [[0]*(n + 1) for i in range(n + 1)]
    for i in range(n):
        for j in range(n):
            if field[i][j] == '.':
                large[i][j] = min(large[i][j - 1], large[i - 1][j], large[i - 1][j - 1]) + 1
    print max(map(max, large))

Measured memory_bytes: 32976
def ii2ss(n):
    ss = []
    for i in range(n):
        ss.append(input())
    return ss

def sp2nn(sp, sep=' '):
    return [int(s) for s in sp.split(sep)]

def ss2nn(ss):
    return [int(s) for s in list(ss)]

def tk(i, j, k):
    return '%d %d %d' % (i, j, k)

def tkr(key):
    return sp2nn(key)

def main(ss):
    X, Y, Z, K = sp2nn(ss[0])
    aa = sp2nn(ss[1])
    bb = sp2nn(ss[2])
    cc = sp2nn(ss[3])
    aa.sort()
    aa.reverse()
    bb.sort()
    bb.reverse()
    cc.sort()
    cc.reverse()
    
    d = {}
    st = set()
    key = tk(0, 0, 0)
    st.add(key)
    d[key] = aa[0] + bb[0] + cc[0]
    for _ in range(K):
        vmax = -1
        vk = ''
        for k, v in d.items():
            if vmax < v:
                vmax = v
                vk = k
        print(vmax)
        d.pop(vk)
        st.add(vk)
        i, j, k = tkr(vk)
        if i + 1 < len(aa):
            key = tk(i+1, j, k)
            if key not in st:
                d[key] = aa[i+1] + bb[j] + cc[k]
        if j + 1 < len(bb):
            key = tk(i, j+1, k)
            if key not in st:
                d[key] = aa[i] + bb[j+1] + cc[k]
        if k + 1 < len(cc):
            key = tk(i, j, k+1)
            if key not in st:
                d[key] = aa[i] + bb[j] + cc[k+1]
        
main(ii2ss(4))

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

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

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(a,n) for (int a = 0; a < (n); ++a)
using namespace std;
using ll = long long;
typedef pair<int,int> P;
typedef pair<ll,P> PP;
typedef vector<vector<int> > Graph;
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; }
const ll INF = numeric_limits<ll>::max();

/*トポロジカルソートを行う
DAGでない場合にはsize０のvectorを返す*/

struct TopologicalSort{
    int v;
    vector<vector<int> >g,g_len;
    vector<int>deg,res;//degは頂点に入ってくる辺の数
    TopologicalSort(int n) : v(n),g(v),deg(v,0),g_len(v){}
    void add_edge(int from,int to){
        g[from].push_back(to);
        g_len[to].push_back(from);
        deg[to]++;
    }
    vector<int> solve(){
        queue<int>que;
        rep(i,v){
            if(deg[i]==0){
                que.push(i);
            }
        }
        while(!que.empty()){
            int p = que.front();
            que.pop();
            res.push_back(p);
            for(int v:g[p]){
                if(--deg[v]==0){
                    que.push(v);
                }
            }
        }
        if(*max_element(deg.begin(),deg.end())==0){
            return res;
        }
        else{
            return vector<int>();
        }
    }
    bool unique(){//解の一意性を判定する
        for(int i=0;i<v-1;i++){
            int from = res[i];
            int to = res[i+1];
            bool flg = false;
            for(int x:g[from]){
                if(x==to)flg=true;
            }
            if(!flg){
                return false;
            }
        }
        return true;
    }
    vector<int> longest_len(){//DAGである時に最長経路を求める
        vector<int>dist(v,0);
        vector<int> par(v);
        for(int i=0;i<v;i++){
            int p = -1;
            for(int x:g_len[res[i]]){
                if(chmax(dist[res[i]],dist[x]+1)){
                    p = x;
                }
            }
            par[res[i]]=p;
        }
        return par;
    }
};

int main(){
    ll n,m;
    cin >> n >> m;
    TopologicalSort tps(n);
    rep(i,n+m-1){
        ll a,b;
        cin >> a >> b;
        a--;b--;
        tps.add_edge(a,b);
    }
    tps.solve();
    auto ans = tps.longest_len();
    rep(i,n){
        cout << ans[i]+1 << endl;
    }
    return 0;
}



Measured memory_bytes: 15688
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1000000007;
ll INF = 1ll << 60;

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

  ll lucas[90];
  for (int i = 0; i < 90; i++) lucas[i] = 0;
  lucas[0] = 2;
  lucas[1] = 1;
  for (int i = 2; i <= n; i++) lucas[i] = lucas[i - 1] + lucas[i - 2];
  cout << lucas[n] << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int a=0;
	int b=0;
	int c=0;
	
	printf("");
	scanf("%d %d %d",&a,&b,&c);
	
	while(1){
		if(a>=0 && a<=100 && b>=0 && b<=100 && c>=0 && c<=100){
			break;
		}else{
			printf("");
			scanf("%d %d",&a,&b);
			continue;
		}	
	}
	
	
	if(a<b && b<c){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	
	return 0;
}

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

#define INF 1e9

int main(void){
  int n, m;
  cin >> n >> m;

  vector<int> d(n + 1);
  vector<int> c(m + 1);
  for(int i = 1; i <= n; i++){ cin >> d[i]; }
  for(int i = 1; i <= m; i++){ cin >> c[i]; }

  vector<vector<int> > dp(n + 1, vector<int>(m + 1, INF));
  for(int i = 0; i <= m; i++){ dp[0][i] = 0; }
  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= m; j++){
      dp[i][j] = min(dp[i][j - 1],
                     dp[i - 1][j - 1] + d[i] * c[j]);
    }
  }
  cout << dp[n][m] << endl;

  return 0;
}

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

using namespace std;
typedef long long ll;


int main(){
    
    int N,W;
    cin >> N >> W;
    vector<int> w(N),v(N);
    int V = N*1000;
    
    rep(i,N) cin >> w[i] >> v[i];
    
    /*
    vector<vector<int>> dp(N+1, vector<int>(W+1, 0));
    
    rep(i, N) rep(j, W+1){
        if(j+w[i] <= W) dp[i+1][j+w[i]] = max(dp[i+1][j+w[i]], dp[i][j]+v[i]);
        dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
    }
    
    cout << dp[N][W] << endl;
    */
    
    vector<vector<ll>> dp(N+1, vector<ll>(V+1, 10000000000000));
    dp[0][0] = 0;
    rep(i, N) rep(j, V+1){
        if(j+v[i] <= V) dp[i+1][j+v[i]] = min(dp[i][j]+w[i], dp[i+1][j+v[i]]);
        //if(j-v[i] >= 0) dp[i+1][j] = min(dp[i][j-v[i]]+w[i], dp[i+1][j]);
        dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
    }
    
    
    
    ll res = 0;
    rep(i, V+1){
        if(dp[N][i] <= W) res = i;
    }
    
    cout << res << endl;
    
    
    
    return 0;
}


Measured memory_bytes: 80256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

int main(void){
    string S,T;
    cin >> S >> T;
    int N=S.length();
    int ans=0;
    rep(i,N) if(S[i]!=T[i]) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 3780
#include<iostream>
using namespace std;
int main(){
  int a,b;
  int ans=0,c=0,h=0;
  while(cin>>a>>b){
    if(a==0&&b==0) break;
    if(c!=0) cout << endl;
    for(int i=a;i<=b;i++){
      if(i%4==0){
	if(i%100==0){
	  if(i%400==0) ans = i;
	  if(ans!=i) continue;
	}
	  ans = i;
	}
	else continue;
	cout << ans << endl;    
      }
      if(ans==0) cout << "NA" << endl;
      ans = 0;
      c++;
    }
    return 0;
  }

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define int         long long
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
 
using namespace std;
int gcd(int a, int b) {  if (a == 0)  return b; return gcd(b % a, a); } 
int lcm(int a, int b) { return (a*b)/gcd(a,b); } 
signed main(){
    tezz   
    
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    int c=0,k=1;
    for(int i=0; i<n; i++){
        if(a[i]!=k){
            c++;
        }
        else{
            k++;
        }
    }
    if(c==n)cout << -1 << endl;
    else cout << c << endl;
    
    
    return 0;
}   


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

using namespace std;

int main() {
	int S, left, right;
	cin >> S;
	left = S / 100;
	right = S % 100;

	string ans = "NA";
	if ((left > 0 && left < 13) && (right > 0 && right < 13)){
		ans = "AMBIGUOUS";
	}
	else if (right >= 0 && (left > 0 && left < 13)) {
		ans = "MMYY";
	}
	else if (left >= 0 && (right > 0 && right < 13)) {
		ans = "YYMM";
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
pair<int, int> p;

int main(){
    int n; cin >> n;
    vector<ll> h(n);
    for(int i=0; i<n; ++i){cin >> h[i];}
    reverse(h.begin(), h.end());
    for(int i=0; i+1<n; ++i){
        if(h[i+1]<0){cout << "No" << endl; return 0;}
        if(h[i+1]>h[i]){h[i+1]--;}
    }
   //for(int i=0; i<n; ++i){cout << h[i] << ",";} cout << endl;
  	for(int i=0; i+1<n; ++i){if(h[i+1]>h[i]){cout << "No" << endl; return 0;}}
    cout << "Yes" << endl; return 0;
    return 0;
}

Measured memory_bytes: 4000
import math

n=int(input())
xy=[[int(x) for x in input().split()]for j in range(n)]
ans=0
for i in range(n):
  for j in range(i,n):
    ans+=math.sqrt((xy[i][0]-xy[j][0])**2+(xy[i][1]-xy[j][1])**2)
   # print(ans)
print(ans*2/n)

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

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

int n;cin>>n;
map<string, int> mp;
int mx=0;
while(n--){
  string s;cin>>s;
  mp[s]++;
  mx = max(mx,mp[s]);
}
for(auto &kv : mp){
  if(kv.second==mx){
    cout<<(kv.first)<<endl;
  }
}
  
  return 0;
}


Measured memory_bytes: 23808
a = gets.chomp.split('')
l = a.length

hash = {}
a.each do |c|
    hash[c] ||= 0
    hash[c] += 1
end

sum = l * (l - 1) / 2

hash.values.each do |v|
    next if v < 2
    sum -= v * (v - 1) / 2
end

puts sum + 1

Measured memory_bytes: 12796
n = int(input())
a = list(map(int, input().split()))

ans = [0]*n
tmp = 0
for j in range(n):
    tmp += (-1)**(j) * a[j]
ans[0] = tmp
for i in range(1,n):
    tmp -= a[i-1]
    tmp = -tmp
    tmp += a[i-1]
    ans[i] = tmp
print(" ".join(map(str, ans)))


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

using namespace std;
int main() {
  string s;
  int n, k;
  cin >> n >> k >> s;

  for (int i = 0; i < s.length(); i++) {
    if (i == k - 1) {
      if (s.substr(i, 1) == "A") {
        cout << "a";
      } else if (s.substr(i, 1) == "B") {
        cout << "b";
      } else if (s.substr(i, 1) == "C") {
        cout << "c";
      }
    } else {
      cout << s.substr(i, 1);
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define PI 3.14159265359

int main(){
    iostream::sync_with_stdio(false);

    int N, K;
    cin >> N >> K;
    long long answer = K;
    for(int i=1; i<N; i++){
        answer *= K-1;
    }
    cout << answer << endl;
    
    return 0;
}

Measured memory_bytes: 256
import sys
import heapq


# \n
def input():
    return sys.stdin.readline().rstrip()


def main():
    X, Y, Z, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    A.sort(reverse=True)
    B.sort(reverse=True)
    C.sort(reverse=True)

    Q = []
    S = set()
    heapq.heapify(Q)
    heapq.heappush(Q, (-A[0] - B[0] - C[0], 0, 0, 0))
    for i in range(K):
        m, a, b, c = heapq.heappop(Q)
        print(-m)
        if (a + 1, b, c) not in S and a + 1 < X:
            heapq.heappush(Q, (-A[a + 1] - B[b] - C[c], a + 1, b, c))
            S.add((a + 1, b, c))
        if (a, b + 1, c) not in S and b + 1 < Y:
            heapq.heappush(Q, (-A[a] - B[b + 1] - C[c], a, b + 1, c))
            S.add((a, b + 1, c))
        if (a, b, c + 1) not in S and c + 1 < Z:
            heapq.heappush(Q, (-A[a ] - B[b] - C[c+1], a, b, c + 1))
            S.add((a, b, c + 1))


if __name__ == "__main__":
    main()


Measured memory_bytes: 72796
#include<cstdio>
#include<iostream>
#include<cctype>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

#define ll long long
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define MD 1000000007

char sep[3] = " \n";
int i, j, k, l, m, n;
double PI = acos(-1);


class Dice{
  int t;
 public:
  int s[6];

  Dice() {
    rep(i,6) cin >> s[i];
  }

  void N() { t=s[0], s[0]=s[1], s[1]=s[5], s[5]=s[4], s[4]=t; }
  void S() { t=s[0], s[0]=s[4], s[4]=s[5], s[5]=s[1], s[1]=t; }
  void E() { t=s[0], s[0]=s[3], s[3]=s[5], s[5]=s[2], s[2]=t; }
  void W() { t=s[0], s[0]=s[2], s[2]=s[5], s[5]=s[3], s[3]=t; }
};

int main() {
  int init[6];
  Dice* d = new Dice();
  string move;
  cin >> move;
  for (char c: move) {
    if (c == 'N') d->N();
    else if (c == 'E') d->E();
    else if (c == 'W') d->W();
    else if (c == 'S') d->S();
  }
  cout << d->s[0] << endl;
  
  return 0;
}
  

Measured memory_bytes: 1208
import java.util.Scanner;

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

    while (in.hasNext()) {
      String S = in.next();
      boolean isGood = true;
   
      for (int i = 1; i < S.length(); ++i) {
        if (S.charAt(i) == S.charAt(i - 1)) {
          isGood = false;
        }
      }
      
      if (isGood) {
        System.out.println("Good");
      } else {
        System.out.println("Bad");
      }
    }
  }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007

 int gcd(int a,int b){

   if(a%b == 0)
    return b;
   else
    return gcd(b,a%b);
 }

 long long numbers[500005];


 int main(){

  long long n,Y;
  cin>>n>>Y;

  for(int x=0;x<=n;x++)
  {
      for(int y=0;y<=n;y++)
      {
         if(10000*x+5000*y+1000*(n-x-y) == Y && n-x-y>=0){
            cout<<x<<" "<<y<<" "<<n-x-y<<endl;
         return 0; }
      }
  }

  cout<<"-1 -1 -1"<<endl;

return 0;
 }

Measured memory_bytes: 3600
#include<iostream>
#include<string>
#include<math.h>
using namespace std;

int main() {
	char S[20];
	string T;
	string p;
	string Q;
	double m;
	int a = 0;
	int A = 0;
	int b = 0;
	int B = 0;
	int c = 0;
	int C = 0;
	int q, w, z;
	int n = 0;
	int x = 0;
	int y = 0;
	int ans = 0;
	cin >> a >> b >> c >> n;
	if (a + b < c + n) {
		cout << "Right";
	}
	else if (a + b > c + n) {
		cout << "Left";
	}
	else {
		cout << "Balanced";
	}
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 2e3, inf = 1e6; int n, x, y;
int dist[maxN][maxN], cnt[maxN];

vector<int> graph[maxN];
void addEdge(int u, int v)
{
  graph[u].push_back(v);
  graph[v].push_back(u);
}

void bfs(int source)
{
  queue<int> q; q.push(source);
  dist[source][source] = 0;
  while (!q.empty())
  {
    int u = q.front(); q.pop();
    for (int v: graph[u])
      if (dist[source][u] + 1 < dist[source][v])
        q.push(v), dist[source][v] = dist[source][u] + 1;
  }
  for (int i = 0; i < n; i++)
    cnt[dist[source][i]]++;
}

int main()
{
  int t = 0;
  while (scanf("%d %d %d", &n, &x, &y) != EOF)
  {
    if (t++) printf("------------\n");
    for (int i = 0; i < n; i++) graph[i].clear();

    for (int i = 0; i < n - 1; i++) addEdge(i, i + 1);
    addEdge(x - 1, y - 1);

    memset(cnt, 0, sizeof(cnt));
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        dist[i][j] = inf;
    for (int i = 0; i < n; i++)
      bfs(i);

    for (int i = 1; i < n; i++)
      printf("%d\n", cnt[i] >> 1LL);
  }
  return 0;
}

Measured memory_bytes: 16000
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n,t,a;
  cin>>n>>t>>a;
  double h;
  double min=99999;
  int ans;
  rep(i,n){
    cin>>h;
    h=t-h*0.006;
    if(chmin(min,abs(a-h))){
      ans=i+1;
    }
  }
  cout<<ans<<'\n';
  return(0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll int64_t
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

ll dp[101][4][4];
int d[101];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,K;
    cin>>N>>K;
    REP(i,K){
        int a,b;
        cin>>a>>b;
        d[a-1] = b;
    }
    if(d[0]!=0) dp[0][0][d[0]]=1;
    else{
        dp[0][0][1]=1;
        dp[0][0][2]=1;
        dp[0][0][3]=1;
    }
    for(int i=1;i<N;i++){
        for(int j=0;j<4;j++){
            for(int l=1;l<4;l++){
                if(d[i]!=0){
                    if(!(j==l && l==d[i])) dp[i][l][d[i]] += dp[i-1][j][l] % 10000;
                }
                else{
                    for(int m=1;m<4;m++){
                        if(j==l && l==m) continue;
                        dp[i][l][m] += dp[i-1][j][l] % 10000;
                    }
                }
            }
        }
    }
    int ans = 0;
    for(int j=0;j<4;j++){
        for(int l=0;l<4;l++) ans += dp[N-1][j][l];
    }
    cout<<ans%10000<<endl;
}


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

const int inf = 1e8;

int building[2][1000];
bool visited[2][1000];
int n;
int solve(int t){
    memset(visited, false, sizeof(visited));
    queue<pair<pair<int, int>, int> > q;
    q.push(make_pair(make_pair(t, 0), 0));
    while(!q.empty()){
        pair<pair<int, int>, int> p = q.front(); q.pop();
        int x = p.first.first, y = p.first.second, count = p.second;
        if(visited[x][y]) continue;
        visited[x][y] = true;

        if(building[x][y] == 2) while(building[x][y] == 2) y--;
        if(building[x][y] == 1) while(building[x][y] == 1 && building[x][y+1] == 1) y++;

        if(y == n-1) return count;
        for(int i=0; i < 3; i++){
            if(y+i < n) q.push(make_pair(make_pair(!x, y+i), count+1));
        }
    }
    return inf;
}

int main(){
    while(cin >> n, n){
        memset(building, 0, sizeof(building));
        for(int i=0; i< 2; i++) for(int j=0; j < n; j++) cin >> building[i][j];
        int ret = min(inf, min(solve(0), solve(1)));
        if(ret == inf) cout << "NA" << endl;
        else cout << ret << endl;
    }
    return 0;
}

Measured memory_bytes: 1224
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		sc.close();
		int train = 0;
		if (a > b) {
			train = b;
		} else {
			train = a;
		}
		int buss = 0;
		if (c > d) {
			buss = d;
		} else {
			buss = c;
		}
		System.out.println(train + buss);
	}
}


Measured memory_bytes: 23764