akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
Int lim;
void fin(){
  cout<<"Error"<<endl;
  exit(0);
}

vector<Int> len({-1}), pos(26,0);
struct st{
  char c;
  Int v;
  st(char c):c(c),v(-1){}
};

const int D = 0;

st expr(string &s,Int &p);
st assign(string &s,Int &p);
st malloc(string &s,Int &p);
void free(string &s,Int &p);
st clone(string &s,Int &p);
st variable(string &s,Int &p);
Int number(string &s,Int &p);

void line(string &s,Int &p){
  if(s[0]=='f') free(s,p);
  else          expr(s,p);
}

st expr(string &s,Int &p){
  if(s[p]=='('){
    p++;
    st t=expr(s,p);
    if(D) assert(s[p]==')');
    p++;
    return t;
  }
  if(s[p]=='m'){
    return malloc(s,p);
  }
  if(s[p]=='c'){
    return clone(s,p);
  }
  if(p+1<(Int)s.size()&&isupper(s[p])&&s[p+1]=='='){
    return assign(s,p);
  }
  if(p+3<(Int)s.size()&&s[p]=='N'&&s[p+1]=='U'&&s[p+2]=='L'&&s[p+3]=='L'){
    return st('A'-1);
  }
  return variable(s,p);
}
st assign(string &s,Int &p){
  st t(s[p++]);
  if(D) assert(s[p]=='=');
  p++;
  t.v=expr(s,p).v;
  pos[t.c-'A']=t.v;
  return t;
}
st malloc(string &s,Int &p){
  if(D) assert(s[p]=='m');p++;
  if(D) assert(s[p]=='a');p++;
  if(D) assert(s[p]=='l');p++;
  if(D) assert(s[p]=='l');p++;
  if(D) assert(s[p]=='o');p++;
  if(D) assert(s[p]=='c');p++;
  if(D) assert(s[p]=='(');p++;
  Int res=number(s,p);
  if(D) assert(s[p]==')');p++;
  st t('A'-1);
  if(lim>=res){
    t.v=len.size();
    len.emplace_back(res);
    lim-=res;
  }else{
    t.v=-1;
  }
  return t;
}

void free(string &s,Int &p){
  if(D) assert(s[p]=='f');p++;
  if(D) assert(s[p]=='r');p++;
  if(D) assert(s[p]=='e');p++;
  if(D) assert(s[p]=='e');p++;
  if(D) assert(s[p]=='(');p++;
  st t=expr(s,p);
  if(D) assert(s[p]==')');p++;
  if(t.v<0) return;
  if(len[t.v]<0) fin();
  lim+=len[t.v];
  len[t.v]=-1;
}

st clone(string &s,Int &p){
  if(D) assert(s[p]=='c');p++;
  if(D) assert(s[p]=='l');p++;
  if(D) assert(s[p]=='o');p++;
  if(D) assert(s[p]=='n');p++;
  if(D) assert(s[p]=='e');p++;
  if(D) assert(s[p]=='(');p++;
  Int x=expr(s,p).v;
  if(D) assert(s[p]==')');p++;

  st t('A'-1);
  if(x<0) return t;
  Int res=len[x];
  if(res<0) fin();
  
  if(lim>=res){
    t.v=len.size();
    len.emplace_back(res);
    lim-=res;
  }else{
    t.v=-1;
  }
  
  return t;
  
}
st variable(string &s,Int &p){
  st t(s[p++]);
  t.v=pos[t.c-'A'];
  return t;
}
Int number(string &s,Int &p){
  Int res=0;
  while(isdigit(s[p]))
    res=res*10+(s[p++]-'0');
  return res;
}


signed main(){  
  cin.tie(0);
  ios::sync_with_stdio(0);
  cin>>lim;
  string s;
  while(cin>>s){
    Int p=0;
    line(s,p);
  }
  
  Int ans=0;
  for(Int i=0;i<26;i++) if(~pos[i]) len[pos[i]]=0;
  for(Int x:len) if(x>0) ans+=x;
  cout<<ans<<endl;
  return 0;
}




Measured memory_bytes: 3240
fun main(args: Array<String>) {
    abc116c()
}

fun abc116c() {
    // 愚直にやってみる 全体が1以上だったらその分引いて、1以上のところで左右に分割、それを再帰的に処理
    val n = readLine()!!.toInt()
    val heights = readLine()!!.split(" ").map { it.toInt() }
    
    println(calc(heights))
}

fun calc(heights: List<Int>): Int {
    if (heights.isEmpty()) return 0

    val max = heights.max()!!
    val min = heights.min()!!

    if (max == 0) return 0
    if (max == min) return max

    val remains = heights.map { it - min }

    val left = remains.subList(0, remains.indexOf(0))
    val right = remains.subList(remains.indexOf(0) + 1, remains.size)

    return calc(left) + calc(right) + min

}


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

int main() {
  int N,K;
  string S;
  cin >> N >> K >> S;
  
  if (S.at(K-1) == 'A') S.at(K-1) = 'a';
  else if (S.at(K-1) == 'B') S.at(K-1) = 'b';
  else  S.at(K-1) = 'c';
  
  cout << S << endl;
}

Measured memory_bytes: 256
#include <iostream>
int main() {
    size_t n, a, b; 
    std::cin >> n >> a >> b;
    if (n == 0) {
        std::cout << 0 << std::endl;
    } else if (n == 1) {
        if (a == b) {
            std::cout << 1 << std::endl;
        } else {
            std::cout << 0 << std::endl;
        }
    } else if (a > b) {
        std::cout << 0 << std::endl;
    } else {
        std::cout << (n - 2) * (b - a) + 1 << std::endl;
    }
    return 0;
}


Measured memory_bytes: 256
N,M = map(int, input().split())

H=list(map(int,input().split()))

ans=[1]*N
for i in range(M):
    a,b=map(int,input().split())
    if H[a-1]>H[b-1]:
        ans[b-1]=0
    elif H[a-1]<H[b-1]:
        ans[a-1]=0
    else:
        ans[a-1]=ans[b-1]=0
print(len([i for i in ans if i%2!=0]))

Measured memory_bytes: 20016
#include <bits/stdc++.h>
using namespace std;
int h,w;
int main(){
  cin >> h >> w;
  vector<string> s(h);
  for(int i=0;i<h;i++)cin >> s[i];
  vector<bool> vert(h),hori(w);
  for(int i=0;i<h;i++){
    bool f = true;
    for(int j=0;j<w;j++){
      f &= (s[i][j]=='.');
    }
    vert[i] = f;
  }
  for(int j=0;j<w;j++){
    bool f = true;
    for(int i=0;i<h;i++){
      f &= (s[i][j]=='.');
    }
    hori[j] = f;
  }
  for(int i=0;i<h;i++){
    if(vert[i])continue;
    for(int j=0;j<w;j++){
      if(hori[j])continue;
      cout << s[i][j];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 256
from operator import mul
from functools import reduce
def sml_cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

def main():
    n, p = map(int, input().split())
    a = list(map(int, input().split()))
    cnt_ev = 0
    cnt_od = 0
    for v in a:
        if v % 2 == 0:
            cnt_ev += 1
        else:
            cnt_od += 1
    if p == 0:
        x, y = 0, 0
        for i in range(cnt_ev+1):
            x += sml_cmb(cnt_ev, i)
        for i in range(0, cnt_od+1, 2):
            y += sml_cmb(cnt_od, i)
        print(x*y)
    else:
        x, y = 0, 0
        for i in range(cnt_ev+1):
            x += sml_cmb(cnt_ev, i)
        for i in range(1, cnt_od+1, 2):
            y += sml_cmb(cnt_od, i)
        print(x*y)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3572
open System

[<EntryPoint>]
let main argv =
    let abcd = stdin.ReadLine().Split() |> Array.map int
    let a = abcd.[0]
    let b = abcd.[1]
    let c = abcd.[2]
    let d = abcd.[3]
    if (min ([|a - b; b - c|] |> Array.map abs |> Array.max) (abs (a - c))) <= d then "Yes" else "No"
    |> stdout.WriteLine
    0


Measured memory_bytes: 13268
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.Vector;
//import javafx.util.Pair;
public class Main {

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub

		FastReader sc = new FastReader();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Scanner scn = new Scanner(System.in);
		
//	Vector<Vector<IntegerPai>>adj=new Vector<>();
	  long n=sc.nextLong();
	  System.out.println((n-2)*180); 
	  
	}}


Measured memory_bytes: 21716
#include<iostream>
#include<cstdio>
using namespace std;
 
int main()
{
    for(int i = 1 ; i <= 9 ; i++){
        for(int j = 1 ; j <= 9 ; j++){
            printf("%dx%d=%d\n",i,j,i*j);
        }
    }
    return 0;
}

Measured memory_bytes: 1096
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
int main()
{
	int n;
	scanf("%d", &n);
	pair<pair<string, int>, int> l[n];
	for(int i = 1; i <= n; i++) {
		string s; int p;
		cin >> s >> p;
		l[i - 1] = make_pair(make_pair(s, -p), i);
	}
	sort(l, l + n);
	rep(i, n) printf("%d\n", l[i].second);
	return 0;
}

Measured memory_bytes: 3780
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

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

	long long n, k, i, j, t, d, ans, kk;
	cin >> n >> k;
	vector<vector<long long>> plist(n + 1);
	for (i = 0; i < n; i++) {
		cin >> t >> d;
		plist[t].push_back(d);
	}

	priority_queue<long long> p1, p2;
	for (i = 1; i <= n; i++) {
		if (!plist[i].empty()) {
			sort(plist[i].rbegin(), plist[i].rend());
			p1.push(plist[i][0]);
			for (j = 1; j < plist[i].size(); j++) p2.push(plist[i][j]);
		}
	}

	ans = 0; kk = k;
	for (i = 0; i < k; i++) {
		if (!p1.empty() && ((i == 0) || (p2.empty()) || (p2.top() - (kk + kk - 1) <= p1.top()))) {
			ans += p1.top();
			p1.pop();
		}
		else {
			ans += p2.top();
			p2.pop();
			kk--;
		}
	}
	ans += kk * kk;
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 6904
n,d=map(int,input().split())
x,y=[],[]
for i in range(n):
    x1,y1=map(int,input().split())
    x.append(x1)
    y.append(y1)
t=0
for i in range(n):
    if x[i]**2+y[i]**2<=d**2:
        t+=1
print(t)

Measured memory_bytes: 96740
#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() {
	int n,sum=0;
	cin>>n;
	vector<int>v(n);
	for(int i=0;i<n;i++)cin>>v.at(i);
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			sum+=v.at(i)*v.at(j);
		}
	}
	cout<<sum<<endl;
	return 0;
}



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

#include <set>
//#include <unordered_map>
#include <stack>

using namespace std;

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

#define max_n 100

long long N, M;
string S;

int extgcd(int a, int b, int& x, int& y) {
	int d = a;
	if (b != 0) {
		d = extgcd(b, a%b, y, x);
		y -= (a / b)*x;
	}
	else {
		x = 1; y = 0;

	}
	return d;
}

int mod_inverse(int a, int m) {
	int x, y;
	extgcd(a, m, x, y);
	return (m + x % m) % m;
}

int makefact(int a) {

	long long r = 1;
	rep(i, a)
	{
		r = r * (i + 1) % 1000000007;
	}
	return r;
}

int mod_fact(int n, int p, int& e) {
	e = 0;
	if (n == 0)return 1;
	int res = mod_fact(n / p, p, e);
	e += n / p;
	if (n / p % 2 != 0)return res * (p - makefact(n%p)) % p;
	return res * makefact(n%p) % p;
}

int mod_comb(int n, int k, int p) {
	if (n < 0 || k < 0 || n < k)return 0;
	int e1, e2, e3;
	long long a1 = mod_fact(n, p, e1), a2 = mod_fact(k, p, e2), a3 = mod_fact(n - k, p, e3);
	if (e1 > e2 + e3)return 0;
	return a1 * mod_inverse(a2*a3%p, p) % p;
}



int main() {

	cin >> N >> M;

	set<long long> A;

	int pow2 = 0;
	rep(i, N) {
		int p;
		cin >> p;
		if(pow2==0)
		{
			while (p%2==0)
			{
				p /= 2;
				pow2++;
			}
		}
		else
		{
			long long po = pow(2, pow2);
			if (p % po == 1) { cout << 0 << endl; return 0; }
			p /= po;
			if (p % 2 == 0) { cout << 0 << endl; return 0; }
		}
		A.insert(p);
	}
	
	auto itr = A.begin();
	long long lcm = *itr;
	rep(i, A.size()-1) {
		itr++;

		long long a, b, r;
		a = *itr;
		b = lcm;

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

		/* ユークリッドの互除法 */
		r = a % b;
		while (r != 0) {
			a = b;
			b = r;
			r = a % b;
		}
		lcm = lcm * *itr / b;

	}

	long long ans = M / pow(2, pow2 - 1) / lcm;
	if (ans % 2 == 1)ans = (ans + 1) / 2;
	else ans /= 2;
	cout << ans << endl;
	return 0;
}


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

typedef long long ll;

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

    string s; cin >> s;
    ll n = s.size();
    ll ans = 0;
    for(ll bit=0;bit<(1<<(n-1));bit++){
        string t = "";
        t += s[0];
        for(ll i=0;i<n-1;i++){
            if(bit&(1<<i)) t += "+";
            t += s[i+1];
        }
        ll pos=0,nextpos;
        while(t.find("+",pos) != string::npos){
            nextpos = t.find("+",pos);
            ans += stoll(t.substr(pos,nextpos-pos));
            pos = nextpos + 1;
        }
        ans += stoll(t.substr(pos));
    }
    cout << ans << endl;
    return 0;
}

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

/* typedef */
/* long系 */
typedef long long ll;   // long long
typedef long double ld; // long double
/* vector系 */
typedef vector<int> vi;                    // intのvector
typedef vector<double> vd;                 // doubleのvector
typedef vector<ll> vll;                    // llのvector
typedef vector<ld> vld;                    // ldのvector
typedef vector<vector<int>> vvi;           // intの2次元vector
typedef vector<vector<double>> vvd;        // doubleの2次元vector
typedef vector<vector<ll>> vvll;           // llの2次元vector
typedef vector<vector<ld>> vvld;           // ldの2次元vector
typedef vector<pair<int, int>> vi_i;       // i_iのvector
typedef vector<pair<double, double>> vd_d; // d_dのvector
typedef vector<pair<ll, ll>> vl_l;         // l_lのvector
typedef vector<pair<ld, ld>> vld_ld;       // ld_ldのvector
typedef vector<string> vs;                 // stringのvector
/* pair系 */
typedef pair<int, int> i_i;       // int同士のpair
typedef pair<double, double> d_d; // double同士のpair
typedef pair<ll, ll> l_l;         // ll同士のpair
typedef pair<ld, ld> ld_ld;       // ld同士のpair

/* define */
#define all(v) v.begin(), v.end() // コンテナ全体
#define PI (acos(-1))             // 円周率pi

/* stringstream */
stringstream ss;
stringstream init_ss; // save default formatting

/* upper, lower */
struct ToUpper
{
    char operator()(char c)
    {
        return toupper(c);
    }
};
struct ToLower
{
    char operator()(char c)
    {
        return tolower(c);
    }
};

/* main */
void Main(void)
{
    while (true)
    {
        string s;
        cin >> s;
        if (s == "-")
        {
            return;
        }
        int n;
        cin >> n;
        for (int i = 0; i < n; i++)
        {
            int h;
            cin >> h;
            s += s.substr(0, h);
            s.erase(s.begin(), s.begin() + h);
        }
        cout << s << endl;
    }
}

int main(int argc, char const *argv[])
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();

    return 0;
}



Measured memory_bytes: 3212
import java.io.*;

public class Main {

	final static long MOD = 1000000007;
	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String N = in.readLine();

		int r = Integer.parseInt(N);

		System.out.println(3*(long)Math.pow(r, 2));
	}
}


Measured memory_bytes: 23124
#include <cstdio>

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  if (n == 1) {
    puts("Hello World");
  } else {
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d\n", a + b);
  }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define P pair<ll, ll>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

////////////////////////////////////////////////////////


int main() {
    long double a, b; cin >> a >> b; 
    ll ans = ll(a*b);
    co(ans);

    return 0;
}


Measured memory_bytes: 3732
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
using namespace std;
int a[10000000] = {};
int main() {
	const long long int mod = 1000000007;
	map<long long int, long long int>mp;
	//cout << fixed << setprecision(10);
	long long int  n, m, b, c, d, k, sa, h, w, left = 1, right = 0;
	long long int sc, sr, num2, no[1005][1005] = {}, res = 999999999, count = 0, now = 0, mi = 9999999999;

	string str, t;

	cin >> m>>n;
	while (1) {
		res = 0;
		count = n;
		now = m;
		if (m == 0&&n==0) { return 0; }
		while (1) {
			if (count == 0 && a[now] == 0) {
				cout << now << endl;
				for (int i = 2; i < 7500000; i++) {
					a[i] = 0;
				}
				break;
			}
			if (a[now] == 0) {
				for (int i = 2; i * now < 7500000; i++) {
					a[i * now] = 1;
				}
				count--;
			}
			now++;
		}
		cin >> m >> n;
	}
	
}



Measured memory_bytes: 32372
from itertools import combinations

import numpy as np

n = int(input())
f = []
p = []

for i in range(n):
    f.append(np.array([int(i) for i in input().split()]))

for i in range(n):
    p.append(np.array([int(i) for i in input().split()]))

#######################

max_score = -1e10

for my_shop_count in range(1, 11, 1): #いくつ店を出すか、1から10までのcombination
    for comb in combinations(np.arange(10), my_shop_count):
        score = 0
        for shop_index in range(n):
            order = 0
            for j in range(my_shop_count):
                order += f[shop_index][comb[j]]
            score += p[shop_index][order]

        if(score > max_score):
            max_score = score

print(max_score)


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

using namespace std;

int main(){
    int n = 1 << 15;
    vector<int> mem(n, 0);
    for(int x=0; x*x < n - x; ++x){
        for(int y=x; x*x + y*y < n - x - y; ++y){
            for(int z=y; x*x + y*y + z*z < n - x - y - z; ++z){
                for(int w=z; x*x + y*y + z*z + w*w < n; ++w){
                    mem[x*x + y*y + z*z + w*w]++;
                }
            }
        }
    }
    while(cin >> n, n)cout << mem[n] << '\n';
    return 0;
}

Measured memory_bytes: 1272
#include<bits/stdc++.h>
using namespace std;
int b[200005];
int main()
{
    int n,m,i;
    scanf("%d",&n);

    for(i=0; i<n-1; i++)
    {
        scanf("%d",&m);
        b[m]++;
    }
    for(i=1; i<=n; i++)
        printf("%d\n",b[i]);

    return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<double> shokuzai(N);
    rep(i,N) cin >> shokuzai[i];
    sort(shokuzai.begin(),shokuzai.end(),greater<double>());
    double ans = 0.0;
    double wari = 1;
    rep(i,N){
        if(i != N-1){
            wari *= 2;
            ans += (shokuzai[i] / wari);
        }
        else{
            ans += (shokuzai[i] / wari);
        }
    }
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 256
import sys

def solve():
    n = int(input())
    a = [int(i) for i in input().split()]

    ans1 = 0 if a[0] > 0 else abs(a[0] - 1)
    v = a[0] if a[0] > 0 else 1

    for i in range(1, n):
        if v * (v + a[i]) < 0:
            v += a[i]
        else:
            if v > 0:
                ans1 += abs(v + a[i] + 1)
                v = -1
            else:
                ans1 += abs(v + a[i] - 1)
                v = 1

    ans2 = 0 if a[0] < 0 else abs(a[0] + 1)
    v = a[0] if a[0] < 0 else -1

    for i in range(1, n):
        if v * (v + a[i]) < 0:
            v += a[i]
        else:
            if v > 0:
                ans2 += abs(v + a[i] + 1)
                v = -1
            else:
                ans2 += abs(v + a[i] - 1)
                v = 1

    ans = min(ans1, ans2)

    print(ans)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 14468
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  vector<vector<int> >out(n,vector<int>(m));
  rep(i,n)rep(j,m){
    char c;
    cin>>c;
    if(c=='c')
      for(int k=j;k<m;k++)out[i][k]=k-j;
    else if(out[i][j]==0)out[i][j]=-1;
  }
  rep(i,n){
    rep(j,m-1)cout<<out[i][j]<<" ";
    cout<<out[i][m-1]<<endl;
  }
}

Measured memory_bytes: 1256
import java.io.*;
import java.util.*;
class Main{
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int[] a = new int[n+1];
		for(int i = 1;i <= n;i++){
			a[saori.saori_hayami()] = i;
		}
		for(int i = 1;i <= n;i++){
			System.out.print(a[i] + " ");
		}
		System.out.println("");
		
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 41892
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<bitset>
#include<queue>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;

int main(){
  string S;
  cin >> S;

  int cnt=0;
  for (int i=0; i<(int)S.size()-1; i++){
    if (S.at(i)!=S.at(i+1)){
      cnt++;
    }
  }
  cout << cnt << endl;
}


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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=0;i<n;i++){
    if(a[i]%2){
      cout << "first" << endl;
      return 0;
    }
  }
  cout << "second" << endl;
  return 0;
}


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

int main()
{
  int L, R;
  cin >> L >> R;
  if (0 == L%2019 || L/2019 < R/2019)
  {
    cout << 0;
    return 0;
  }
  auto l = L%2019;
  auto r = R%2019;
  int ans = 2019;
  for (int i = l; i < r; ++i)
    for (int j = i + 1; j <= r; ++j)
      if ((i*j)%2019 < ans)
        ans = (i*j)%2019;
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<set>
#include<queue>
#include<bitset>
#define rep(i,j,n) for(int i=j;i<n;i++)
using namespace std;
#define int long long
int mul[214514];
int divi[214514];
#define inf 1000000007
int bit[114514],n;
struct edge{int u,v,cost;};
edge es[214514];
int zero=0;
int dp[55][55][3000];
string alph("abcdefghijklmnopqrstuvwxyz");


signed main(){
    int n;cin>>n;
    int key=1;
    int num[114514];
    rep(i,0,n){
        cin>>num[i];
    }
    int count=0;
    int ans1=0;
    rep(i,0,n){
        key*=-1;key++;
        count+=num[i];
        if(key&&count<1){
            ans1+=(1-count);
            count+=1-count;
        }else if(!key&&count>-1){
            ans1+=1+count;count+=-1-count;
        }
    }
    count=0;
    int ans2=0;
    key=0;
    rep(i,0,n){
        key*=-1;key++;
        count+=num[i];
        if(key&&count<1){
           ans2+=1-count; count+=1-count;
        }else if(!key&&count>-1){
            ans2+=1+count;count+=-1-count;
        }
    }
    int ans;ans=min(ans1,ans2);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
    string a;
    cin>>a;
    int flag=false;
    for(int i=0;i<a.size();i++)
    {
        if(a[i]=='C')
        flag=true;  
        if(a[i]=='F'&&flag==true) 
        {
            cout<<"Yes";
            return 0;
        }
    } 
    cout<<"No"<<endl;  
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


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

Measured memory_bytes: 3636
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        int[] a = Console.ReadLine().Split(' ').Select(int.Parse).OrderByDescending(x => x).ToArray();
        int scoreA = 0;
        int scoreB = 0;
        for(int i = 0; i < N; i++)
        {
            if (i % 2 == 0)
                scoreA += a[i];
            else
               scoreB += a[i];
        }
        Console.WriteLine(scoreA - scoreB);
    }
}


Measured memory_bytes: 13396
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

int main() {
    fastio();

    int x, y;
    cin >> x >> y;

    for (int i = 0; i <= x; i++) {
        if (y == i * 2 + (x - i) * 4) {
            cout << "Yes\n";
            return 0;
        }
    }

    cout << "No\n";

    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#include <math.h>
#include <float.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
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; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

const int MOD = 1000000007;

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

    int ans = 0;
    for (int i = N-2; i > 0; i--){
        if (i % 2 == 0) continue;
        for (int j = 0; j <= i/2; j++){
            if (S[i/2-j] != S[i-j]){
                break;
            }
            if (j == i/2) ans = max(ans, i+1);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3608
#include<stdio.h>
int main(){
  int n;
  scanf("%d",&n);
  int a[n],m = n;
  for(int i = 0;i < n;i++){
    scanf("%d",&a[i]);
  }
  for(int i = 0;i < n - 1;i++){
    for(int j = i + 1;j < n;j++){
      if(a[i] == a[j]){
        m--;
        break;
      }
    }
  }
  printf("%d",m);
  return 0;
}

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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;



int main() {

	ll n, k;
	cin >> n >> k;

	VLL a(n);
	REP(i, n) {
		cin >> a[i];
		a[i]--;
	}
	VLL s(n + 1);
	s[0] = 0;
	REP(i, n)s[i + 1] = (s[i] + a[i]) % k;

	ll ans = 0;
	map<int, int> m;
	m[0]++;
	FOR(i, 1, n + 1) {
		if (i >= k) {
			m[s[i - k]]--;
		}
		ans += m[s[i]];
		m[s[i]]++;
	}
	cout << ans << endl;
	
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
const int maxm = 1e6 + 10, maxn = 2e5 + 10;
const int mod = 998244353, inv2 = (mod + 1) >> 1;

int a[maxn], n;
int f[maxm], c[maxm];

int sqr(int x) {
	return 1ll * x * x % mod;
}
void solve() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", a + i);
		++c[a[i]];
	}
	f[1] = 1;
	for (int i = 2; i < maxm; ++i) {
		f[i] = 1ll * (mod - mod / i) * f[mod % i] % mod;
		//cerr << f[i] << endl;
	}
	for (int i = 1; i < maxm; ++i) {
		f[i] %= mod;
		if (f[i] < 0)f[i] += mod;
		for (int j = i + i; j < maxm; j += i) {
			f[j] -= f[i];
			if (f[j] < 0)f[j] += mod;
		}
	}
	//cerr << c[12] << endl;
	int ret, tmp, ans = 0;
	for (int i = 1; i < maxm; ++i) {
		ret = 0; tmp = 0;
		for (int j = i; j < maxm; j += i) if (c[j] != 0) {
				ret = (ret + 1ll * j * c[j] % mod) % mod;
				tmp = (tmp + 1ll * c[j] * sqr(j) % mod) % mod; //*j*c[j]
			}
		ret = (1ll * ret * ret % mod - tmp + mod) * inv2 % mod;
		ret = 1ll * f[i] * ret % mod;
		ans = (ret + ans) % mod;
	}
	cout << ans << endl;
	//记得和家里人反应C语言的书要不要退了。。。
}
int main() {
	solve();
	return 0;
}

Measured memory_bytes: 8960
#include<iostream>
using namespace std;
int main()
{
long long sum=0;
long long a,b,c,k;
cin>>a>>b>>c>>k;
if(a>=k)
sum+=k;
else
{
    if(a<k && k<=a+b)
    {sum=a;}
    else
    {sum=a-(k-a-b);}
    
}
cout <<sum; 

    
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)
#define all(v) (v).begin(),(v).end()

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

const int INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

struct UnionFind{
private:
    vector<int> par;

public:
    UnionFind(int n=0): par(n,-1){ }

    int find(int x){
        if(par[x]<0) return x;
        else return par[x] = find(par[x]);
    }

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

    bool unite(int x, int y){
        x = find(x); y = find(y);
        if(x==y) return false;
        if(par[x]>par[y]) swap(x,y);
        par[x]+=par[y];
        par[y] = x;
        return true;
    }

    int size(int x){
        return -par[find(x)];
    }

    int count_group(){
        int c = 0;
        rep(i,par.size()){
            if(par[i]<0) c++; 
        }
        return c;
    }
};



int kruskal(edges es,int v){
    sort(all(es),[](const edge &a, const edge &b){
        return (a.weight<b.weight);
    });
    UnionFind uf(v);
    int ret = 0;
    for(const auto& e: es){
        if(!uf.same(e.from,e.to)){
            uf.unite(e.from,e.to);
            ret += e.weight;
        }
    }
    return ret;
}

int main(){
    int v,e;
    cin >> v >> e;
    edges es;
    rep(_,e){
        int s,t,w;
        cin >> s >> t >> w;
        es.emplace_back(edge(s,t,w));
    }
    cout << kruskal(es,v) << endl;
}


Measured memory_bytes: 5500
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	void run() {
		for (;;) {
			int n = sc.nextInt();
			int l = sc.nextInt();

			if(n ==0 && l==0){
				break;
			}
			int[] map = new int[86500];

			int[] s = new int[n];
			int[] t = new int[n];
			int[] u = new int[n];
			for (int i = 0; i < n; i++) {
				s[i] = sc.nextInt();
				t[i] = sc.nextInt();
				u[i] = sc.nextInt();
			}

			for (int i = 0; i < n; i++) {
				for (int j = s[i]; j < t[i]; j++) {
					map[j] = u[i];
				}
			}
//			System.out.println(Arrays.toString(map));
			double min = 0;
			double max = 1e7;
			for (; ;) {
				
				if(Math.abs(max - min) < 1e-8 ){
					break;
				}
//			min = max = 0.999;
				double med = (max+ min)/2;
				double f = l;
				boolean ok = true;
				double f1 = 0;
				for (int i = 0; i < 86400; i++) {
					
					f -= map[i];
					f += med;
					if(f > l){
						f =l;
					}
//					System.out.println(med+":"+i + " " + f);
					if(f < 0 ){
						ok = false;
						break;
					}
				}
				f1 = f;
				for (int i = 0; i < 86400; i++) {
					
					f -= map[i];
					f += med;
					if(f > l){
						f =l;
					}
//					System.out.println(med+":"+i + " " + f);
					if(f < 0 ){
						ok = false;
						break;
					}
				}
				if(f < f1){
					ok = false;
				}

				if(ok){
//					System.out.println("ok "  + med);
					max = med;
				}else{
//					System.out.println("ng " + med);
					min = med;
				}
			}
			System.out.printf("%.7f\n",max);
		}

	}

	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}
}

Measured memory_bytes: 16000
#include <cstdio>
#include <cstdint>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <unordered_map>

int main()
{
    int N, i;
    std::cin >> N >> i;

    std::cout << N - i + 1 << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n;
    cin >> n;
    int A[n] = {};
    long long int counter[n+1] = {};
    for(int i = 0; i < n; i++){
        cin >> A[i];
        counter[A[i]] += 1;
    }
    long long int sum = 0;
    for(int i = 0; i < n+1; i++){
        long long int x = counter[i];
        sum += x * (x-1) / 2; 
    }
    for(int i = 0; i < n; i++){
        int a = counter[A[i]];
        if(a > 1){
            cout << sum - (a-1) << endl;
        }else{
            cout << sum << endl;
        }
    }
    

    return 0;
}


Measured memory_bytes: 4864
#include <iostream>
#include <math.h>
#include <iomanip>
#include <bits/stdc++.h>
#include <string.h>
#include <string>
#include <algorithm>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define N 100005
#define inf 1e18
#define mem(a,b) memset(a,b,sizeof(a))
#define debug(x) cout << (#x) << " = " << x << endl;
#define debug2(i,j) cout << (#i) << "=" << i << " , " << (#j) << "=" << j << endl;

using namespace std;

ll binomialCoeff(ll n,ll k)
{
    ll res = 1;
    if(k >n - k)
        k = n - k;
    for(int i = 0; i < k; ++i)
    {
        res *= (n - i);
        res /= (i + 1);
    }
    return res;
}

ll mod = 1e9+7;

ll power(ll x,ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return (temp*temp)%mod;
    else
        return (((x*temp)%mod)*temp)%mod;
}


/* nCr % mod
ll fact[6*N];
ll inv[6*N],invfac[6*N];
ll mod = 998244353;

void factorial()
{
    fact[0] = invfac[0] = fact[1] = invfac[1] = 1;
    inv[1] = 1;
    for(int i=2;i<=5*N + 10;i++)
    {
        fact[i] = (fact[i-1]*i)%mod;
        inv[i] = (inv[mod%i]*(mod - mod/i))%mod;
        invfac[i] = (invfac[i-1]*inv[i])%mod;
    }
}*/

vector<ll> primes;

void Sieve(int n)
{
    vector<bool> prime(n+1,true);
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          primes.push_back(p);
}

//******************************************************    CHECK CONSTRAINTS   ***************************************************************//

const int Nmax = 1e6 + 6;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    int d;
    cin >> d;
    int ans = 0;
    for(int i=0;i<n;i++)
    {
        ll x,y;
        cin >> x >> y;
        ll val = x*x + y*y;
        long double t = sqrt(val);
        if(t<=d)
            ans ++;
    }
    cout << ans;
}


Measured memory_bytes: 3672
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int main(){
	int a,b,month[]={0,31,29,31,30,31,30,31,31,30,31,30,31};
	string week[]={"Wednesday","Thursday","Friday","Saturday","Sunday","Monday","Tuesday"};
	while(cin>>a>>b){
		if(a==0 && b==0)break;
		for(int i=1;i<a;i++){
			b+=month[i];
		}
		cout<<week[b%7]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1196
require "scanf"

n, k = gets.scanf("%d %d")

a = []

str = gets.split(" ")
str.each do |l|
    a << l.to_i
end


min = a.min
min_ix = a.find_index(min)

r = min_ix
l = n-min_ix-1

cnt = 0

while r > 0 do
    r -= (k-1)
    cnt += 1
end

l += r

while l > 0 do
    l -= (k-1)
    cnt += 1
end

puts cnt


Measured memory_bytes: 8720
#include <iostream>
#include <algorithm>
#include <functional>

int main(){
	int a[10];

	for (int i = 0; i != 10; i++)
		std::cin >> a[i];
	std::sort(a, a + 10, std::greater<int>());
	for (int j = 0; j != 3; j++)
		std::cout << a[j] << std::endl;
	return 0;
}

Measured memory_bytes: 1176
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

#define mod 1000000007

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;

int main()
{
	int n;
	string s;
	cin >> n >> s;
	int mx = 0;
	bool used[26] = {};
	for (int i = 1; i < n; i++) {
		int cnt = 0;
		for (int j = 0; j < i; j++) {
			for (int k = i; k < n; k++) {
				if (s[j] == s[k] && !used[s[j] - 'a']) {
					cnt++;
					used[s[j] - 'a'] = true;
					break;
				}
			}
		}
		mx = max(mx, cnt);
		memset(used, false, sizeof(used));
	}
	cout << mx << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
  int d;
  cin >> d;
  vector<int> c(26),tmp(26);
  vector<vector<int>> s;
  for(int i=0;i<26;i++){
    cin >> c[i];
  }
  for(int i=0;i<d;i++){
    for(int j=0;j<26;j++){
      cin >> tmp[j];
    }
    s.push_back(tmp);
  }
  vector<int> t(d,1);
  
  vector<int> v(d+1,0),last(26,0);
  for(int i=1;i<d+1;i++){
    for(int j=1;j<=26;j++){
      int v_tmp = v[i-1] + s[i-1][j-1];
      for(int k=0;k<26;k++){
        if(k!=j-1){
          v_tmp -= c[k] * (i - last[k]);
        }
      }
      if(v_tmp>v[i]){
        v[i] = v_tmp;
        t[i-1] = j;
      }
    }
  }
  
  for(int i=0;i<d;i++){
    cout << t[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 3664
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<numeric>
#include<cmath>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
int main() {
	string str, ans;
	llong num;
	cin >> str;
	cin >> num;
	const int tmp = 500000000000000 - 1;
	REP(i, str.size()) {
		num -= pow(static_cast<int>(str[i] - '0'), tmp);
		if (num <= 0) {
			cout << str[i] << endl;
			break;
		}
	}
	return 0;
}

	

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

def iterate_tokens():
    for line in sys.stdin:
        for word in line.split():
            yield word


def solve(N: int, x: int):
    tokens = iterate_tokens()
    a = int(next(tokens))
    s = 0
    for _ in range(N-1):
        new = int(next(tokens))
        if a + new > x:
            s += a + new - x
            new -= min(new, a + new - x)
        a = new
    print(s)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = int(next(tokens))  # type: int
    solve(N, x)

if __name__ == '__main__':
    main()


Measured memory_bytes: 11796
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		String postCode = sc.next();
		Pattern p = Pattern.compile("^[0-9]{" + a + "}-[0-9]{" + b + "}");
		Matcher m = p.matcher(postCode);
		if(m.find()){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> a(n);
  ll cnt = 0, sum = 0;
  REP(i, n) {
    cin >> a[i];
    sum += a[i];
  }

  REP(i, n) {
    if (4 * m * a[i] >= sum) {
      cnt++;
    }
  }
  cout << (cnt >= m ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256