akhauriyash/Code-Regression huggingface dataset:
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_D&lang=jp
#include<iostream>
#include<string>
#include<cstring>
using namespace std;



class CAREA
{
	public:
		CAREA();
		void CalcArea(string str);			//各水たまりの面積を計算する関数
		void DispArea(void);				//結果表示関数
		static const int INPUT_MAX = 20000;
		static const int INPUT_MIN = 1;
	private:
		int indexbackSlash;
		int indexPuddle;
		int backSlash[INPUT_MAX];			//＼が出た位置
		int cpy;							//水たまりの面積の計算用
		int area[INPUT_MAX/2];		//各水たまりの面積
		int areaPosition[INPUT_MAX/2];		//水たまりがある左端の位置
		int sumArea;						//水たまりの面積の合計
};

CAREA::CAREA() : indexbackSlash(0), indexPuddle(0), backSlash(), cpy(0),
				 area(), areaPosition(), sumArea(0){
}

/*
-------------------------------------
関数名：CalcArea
	入力：str(地域の断面図)
	return：なし
-------------------------------------
*/
void CAREA::CalcArea(string str){
	for(int i = 0; i < (int)str.size(); i++){
		if(str[i] == '\0'){
			break;
		}
		else if(str[i] == '\\'){
			//＼の位置を格納
			backSlash[indexbackSlash] = i;
			indexbackSlash++;
		}
		else if(str[i] == '_'){
			//処理なし
		}
		else if(str[i] == '/'){
			if(indexbackSlash == 0){
				//対になる＼がなければ処理なし
			}
			else{
				cpy = i - backSlash[indexbackSlash - 1];
				
				if(indexPuddle == 0){
					//水たまりの面積が1つも格納されていなければ面積と位置をそのまま格納
					areaPosition[indexPuddle] = backSlash[indexbackSlash - 1];
					area[indexPuddle] = cpy;
					indexPuddle++;
				}
				else{
					//すでに格納されている水たまりと合わせて1つの場合、水たまりを足し合わせる
					while(backSlash[indexbackSlash - 1] < areaPosition[indexPuddle - 1]){
						indexPuddle--;
						cpy += area[indexPuddle];
						area[indexPuddle] = 0;
						areaPosition[indexPuddle] = 0;
						
						if(indexPuddle == 0){
							break;
						}
					}
					
					area[indexPuddle] = cpy;
					areaPosition[indexPuddle] = backSlash[indexbackSlash - 1];
					indexPuddle++;
				}
				
				indexbackSlash--;
			}
		}
		else{
			//入ってくることはない
		}
	}
}


/*
-------------------------------------
関数名：DispArea
	入力：なし
	return：なし
-------------------------------------
*/
void CAREA::DispArea(void)
{
	for(int i = 0; i < indexPuddle; i++){
		sumArea += area[i];
	}
	//水たまりの面積の合計を表示
	cout << sumArea << endl;
	//水たまりの数を表示
	cout << indexPuddle;
	
	//各水たまりの面積を表示
	for(int i = 0; i < indexPuddle; i++){
		cout << ' ' << area[i];
	}
	cout << endl;
}


int main(void)
{
	CAREA* pArea = new CAREA;
	
	string str;
	cin >> str;
	
	pArea->CalcArea(str);
	pArea->DispArea();
	
	delete pArea;
	
	return 0;
}




Measured memory_bytes: 3232
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
int main()
{
	int a,b;cin>>a>>b;
	if((a*b)%2==0) cout<<"No"<<endl;else cout<<"Yes"<<endl;
}


Measured memory_bytes: 888
using System;

class Program
{
	static void Main()
	{
		bool[] A = new bool[52];
		int D = int.Parse(Console.ReadLine());
		for (int i = 0; i < D; i++)
		{
			string[] sD = Console.ReadLine().Split(' ');
			if (sD[0] == "S")
			{
				A[int.Parse(sD[1]) - 1] = true;
			}
			if (sD[0] == "H")
			{
				A[int.Parse(sD[1]) + 12] = true;
			}
			if (sD[0] == "C")
			{
				A[int.Parse(sD[1]) + 25] = true;
			}
			if (sD[0] == "D")
			{
				A[int.Parse(sD[1]) + 38] = true;
			}
		}
		for (int i = 0; i < A.Length; i++)
		{
			if (!A[i])
			{
				if (i < 13)
				{
					Console.WriteLine("{0} {1}", "S", i + 1);
				}
				else if (i < 26)
				{
					Console.WriteLine("{0} {1}", "H", i - 12);
				}
				else if (i < 39)
				{
					Console.WriteLine("{0} {1}", "C", i - 25);
				}
				else if (i < 52)
				{
					Console.WriteLine("{0} {1}", "D", i - 38);
				}
			}
		}
	}
}

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

using namespace std;

int main() {
    int N;
    vector<double> v;

    cin >> N;
    rep(i, N) {
        double val;
        cin >> val;
        v.push_back(val);
    }

    sort(v.begin(), v.end());
    double ans = (v[0] + v[1]) / 2;
    REP(i, 2, N) ans = (ans + v[i]) / 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>

#define int long long

using namespace std;

signed main()
{
    int l, r;
    map<int, bool> visited;
    bool allVisited = false;

    cin >> l >> r;

    r = min(r, l + 2019);

    for(int i = l; i <= r && visited.size() != 2019; ++i)
    {
        for(int j = i + 1; j <= r && visited.size() != 2019; ++j)
        {
            int mod2019 = (i * j) % 2019;
            if(visited.count(mod2019))
            {
                break;
            }
            visited[mod2019] = true;
        }
    }

    cout << (*visited.begin()).first << endl;
}

Measured memory_bytes: 384
a = int(input())
b = []
for n in range(a):
    aa = input()
    b.append(aa)
head = ['S','H','C','D']
body = [1,2,3,4,5,6,7,8,9,10,11,12,13]
card = []
for i in head:
    for j in body:
        k = i + ' ' + str(j)
        if k not in b:
            card.append(k)
for m in card:
    print(m)


Measured memory_bytes: 5592
#![allow(non_snake_case)]
#[allow(unused_imports)]
use std::io::{self, Write};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, char) => {
        read_value!($next, String).chars().collect::<Vec<char>>()[0]
     };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
     };
    ($next:expr, isize1) => {
        read_value!($next, isize) - 1
    };
     ($next:expr, $t:ty) => {
         $next().parse::<$t>().expect("Parse error")
    };
}
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}
#[allow(dead_code)]
const MOD: usize = 1000000007;
#[allow(dead_code)]
fn to_num(c: char) -> i64 {
    c as i64 - 48
}




fn main() {
    input!{
        N: usize,
        s: chars,
    }
    let mut flag = false;

    let animals: Vec<bool> = s.into_iter().map(|c| if c == 'o' {false} else {true}).collect();
    let mut ans: Vec<Vec<bool>> = vec![vec![false, false], vec![false, true], vec![true, false], vec![true, true]];

    for res in ans.iter_mut() {
        for i in 1..N-1 {
            let prev = res[i-1];
            let now = res[i];
            //今見ているところの一つ前 ^ 現在のiから得た情報 で次が確定する.
            //現在のiの暫定が羊なら0で反転させず,狼なら反転
            res.push(prev ^ animals[i] ^ now);
        }
        if res[N-2] ^ animals[N-1] ^ res[N-1] == res[0]  && res[N-1] ^ animals[0] ^ res[0] == res[1] {
            flag = true;
            for &mut c in res.into_iter() {
                print!("{}", if c {"W"} else {"S"});
            }
            println!("");
            break;
        }
    }

    if !flag {
        println!("-1");
    }

}

Measured memory_bytes: 4352
#include <stdio.h>

int main() {
	int x, y, i, xx, yy;
	for (i = 1; i > 0; i = 1)
	{
		scanf("%d%d", &x, &y);
		if ((x == 0) && (y == 0))
		{
			break;
		}
		else
		{
			if (x > y)
			{
				xx = y;
				yy = x;
			}
			else
			{
				xx = x;
				yy = y;
			}
			printf("%d %d\n", xx, yy);
		}
	}
	return 0;
}

Measured memory_bytes: 600
n, a, b, c, d = map(int, input().split())
s = input()

if '##' in s[b-1:d] or '##' in s[a-1:c]:
    print('No')
elif c > d and '...' not in s[b-2:d+1]:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
template<typename T> inline void read(T &x)
{
    x=0;char c=getchar();bool flag=false;
    while(!isdigit(c)){if(c=='-')flag=true;c=getchar();}
    while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
    if(flag)x=-x;
}
int n,m,d;
char c[3][3]=
{
    "RY",
    "GB"
};
int main()
{
    read(n),read(m),read(d);
    for(int i=1;i<=n;++i,puts(""))
        for(int j=1;j<=m;++j)
            putchar(c[((i+j+m)/d)&1][((i-j+m)/d)&1]);
    return 0;
}

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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using pii = pair<int,int>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back

int main() {
  int a; cin>>a;
  cout<<a+pow(a,2)+pow(a,3)<<endl;
}


Measured memory_bytes: 4100
#include<iostream>
#include<set>
#include<vector>
#include <algorithm>
#include<string>
#include<map>
using namespace std;

void Main()
{
	unsigned int n, max = 0;
	cin >> n;

    map<string, unsigned int> mp;

	for (int i = 0; i < n; i++)
	{
		string str;
		cin >> str;
		mp[str]++;
	}

	for (auto itr = mp.begin(); itr != mp.end(); itr++) 
	{
		unsigned int x = itr->second;
		if (x > max)max = x;
	}

	for (auto itr = mp.begin(); itr != mp.end(); itr++)
	{
		if (max == itr->second)
		{
			cout << itr->first << endl;
		}
	}
}

int main() {
	Main();
	return 0;
}

Measured memory_bytes: 26112
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL w[30]={1};
LL calc(LL x1,LL y1,LL x2,LL y2,int d){
	if(d==-1)return abs(y2-y1);
	LL a=x1/w[d],b=y1/w[d],c=x2/w[d],d1=y2/w[d];
	if(a!=c)return abs(x2-x1)+abs(y2-y1);
	else if(a==1&&abs(b-d1)>=2){
		x1-=w[d],x2-=w[d];
		return abs(y2-y1)+min(x1+x2+2,w[d]*2-x1-x2);
	}
	x1-=w[d]*a,x2-=w[d]*a;
	return calc(x1,y1,x2,y2,d-1);
}
LL work(){
	LL a,b,c,d;scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	a--,b--,c--,d--;if(abs(a-c)>abs(b-d))swap(a,b),swap(c,d);
	return calc(a,b,c,d,29);
}
int main(){
	for(int i=1;i<30;i++)w[i]=w[i-1]*3;
	int t;scanf("%d",&t);
	while(t--)printf("%lld\n",work());
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()

struct UnionFind {
  vector<int> par;

  UnionFind(int n) : par(n, -1) { }
  void init(int n) { par.assign(n, -1); }

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

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

  bool merge(int x, int y) {
    x = root(x); y = root(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[root(x)];
  }
};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,M;
  cin>>N>>M;
  vector<int> p(N);
  for(int i=0;i<N;i++){
    int tmp;
    cin>>tmp;
    tmp--;
    p[i]=tmp;
  }

  UnionFind uf(N);

  for(int i=0;i<M;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    uf.merge(a,b);
  }

  int ans=0;
  for(int i=0;i<N;i++){
    if(uf.issame(i,p[i]))ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
typedef long long  ll ;
#pragma GCC optimize "trapv"
#define     endl                        '\n'
#define     fi                          first
#define     sec                         second
#define     pb                          push_back
#define 	fio 						ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define 	sz(x) 						(int)x.size()
void solve(){
    fio;
   int n;
   cin>>n;
   ll arr[n];
   for(int i=0;i<n;i++){cin>>arr[i];}
   ll ans=0;
   for(int i=0;i<n-1;i++){
	   if(arr[i+1]<arr[i]){
		   ans+=arr[i]-arr[i+1];
		   arr[i+1]=arr[i];
	   }
   }
   cout<<ans<<endl;return;
   

}
int main(){
    fio;
    
    int test;
    // cin>>test;
    test=1;
    while(test--){
        solve();
    }
    return 0;
}
 


Measured memory_bytes: 5208
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Program
{
    internal static void Main(string[] args)
    {
        var inp = ReadLine().Split(' ').Select(s => int.Parse(s)).ToList();
        var N = inp[0];
        var A = inp[1];
        var B = inp[2];
        var ans = 0;

        for (int i = 1; i <= N; i++) {
            var sum = 0;
            foreach (var c in i.ToString()) {
                sum += int.Parse(c.ToString());
            }
            if (A <= sum && sum <= B) {
                ans += i;
            }
        }
        WriteLine(ans);
    }
}


Measured memory_bytes: 11348
S = gets.chomp!

case S
  when "SUN"
    puts 7
  when "MON"
    puts 6
  when "TUE"
    puts 5
  when "WED"
    puts 4
  when "THU"
    puts 3
  when "FRI"
    puts 2
  when "SAT"
    puts 1
end

Measured memory_bytes: 1788
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

def check(cir,num):
    ans = -10**20
    l = len(cir)
    for start in range(l):
        a = 0
        for i in range(num):
            if start+i == l:
                start = -i
            a += cir[start + i]
            ans = max(ans,a)
    return ans

n,k = readints()
p = [x-1 for x in readints()]
c = readints()

circles = []
used = [0]*n

for i in range(n):
    if not used[i]:
        circles.append([c[i]])
        used[i] = 1
        j = p[i]
        while not used[j]:
            circles[-1].append(c[j])
            used[j] = 1
            j = p[j]

score = -10**20

for cir in circles:
    m = len(cir)
    a = sum(cir)
    if k>m:
        if a>0:
            score = max(score, (k//m)*a + check(cir,k%m), (k//m-1)*a + check(cir,m))
        else:
            score = max(score,check(cir,m))
    else:
        score = max(score,check(cir,k))

print(score)










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

// @@ !! LIM()

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

  ll n, l; cin >> n >> l;
  vector<string> s(n);
  for (ll i = 0; i < n; i++) cin >> s[i];
  sort(s.begin(), s.end());
  for (ll i = 0; i < n; i++) {
    cout << s[i];
  }
  cout << endl;

  return 0;
}



Measured memory_bytes: 3656
H, W = map(int, input().split())
cam = [input() for i in range(H)]
ans = 'Yes'
for i in range(1, H-1):
	for j in range(1, W-1):
		if cam[i][j] == "#":
			if cam[i-1][j] == cam[i+1][j] == cam[i][j-1] == cam[i][j+1] == ".":
				ans = 'No'
				break
print(ans)


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

int main() {
  int n, i, j;
  cin >> n;
  vector<string> s(n);
  for (i = 0; i < n; ++i) {
    cin >> s[i];
  }
  vector<vector<int>> cnt(n, vector<int>(26, 0));
  for (i = 0; i < n; ++i) {
    for (j = 0; j < s[i].size(); ++j) {
      ++cnt[i][s[i][j] - 'a'];
    }
  }
  string ans;
  vector<int> tmp(26, 51);
  for (i = 0; i < n; ++i) {
    for (j = 0; j < 26; ++j) {
      tmp[j] = min(tmp[j], cnt[i][j]);
    }
  }
  for (char c = 'a'; c <= 'z'; ++c) {
    if (tmp[c - 'a'] != 0) {
      for (i = 0; i < tmp[c - 'a']; ++i) {
        ans.push_back(c);
      }
    }
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <functional>
#include <map>
#include <set>
#include <cmath>
using namespace std;

#define INT_MAX 2147483647
#define ll long long 

// DP !!
int main() {
    int n, W;
    cin >> n >> W;

    vector<ll> w(n);
    vector<ll> v(n);

    for (int i = 0; i < n; i++) {
        cin >> w[i] >> v[i];
    }

    vector<ll> dp(W + 1);

    for (int i = 1; i <= n; i++) {
        for (int j = W; j >= w[i - 1]; j--) {
            dp[j] = max(dp[j], dp[j - w[i - 1]] + v[i - 1]);
        }
    }

    cout << dp[W] << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

int main(){
    int A, B, K;
    cin >> A >> B >> K;
    for(int i = A; i <= B; i++){
        if((i >= A && i < A + K) || (i <= B && i > B - K)){
            cout << i << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define rep(i,m,n) for(int i = (m);i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
#define Vec(a) vector <int> a
const int INF = 1 << 20;
const int MOD = 1e9+7;





int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(abs(a-c) <= d){
    cout << "Yes" << endl;
  }
  else if(abs(a-b) <= d && abs(b-c) <= d)
    cout << "Yes" << endl;
  else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using static System.Math;

class D
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var a = new int[n].Select(_ => long.Parse(Console.ReadLine())).ToArray();

		// 0L, 2L, 1, 2R, 0R
		var dp = new int[n + 1].Select(_ => Enumerable.Repeat(1L << 60, 5).ToArray()).ToArray();
		dp[0][0] = 0;

		for (int i = 0, j = 1; i < n; i++, j++)
		{
			var even = a[i] == 0 ? 2 : a[i] % 2;
			var odd = (a[i] + 1) % 2;

			dp[j][0] = Min(dp[j][0], dp[i][0] + a[i]);
			dp[j][1] = Min(dp[j][1], Min(dp[i][0], dp[i][1]) + even);
			dp[j][2] = Min(dp[j][2], Min(dp[i][0], Min(dp[i][1], dp[i][2])) + odd);
			dp[j][3] = Min(dp[j][3], Min(dp[i][0], Min(dp[i][2], dp[i][3])) + even);
			dp[j][4] = Min(dp[j][4], Min(dp[i][1], dp[i][2]) + a[i]);
			dp[j][4] = Min(dp[j][4], Min(dp[i][3], dp[i][4]) + a[i]);
		}
		Console.WriteLine(dp[n].Min());
	}
}


Measured memory_bytes: 57672
n = int(input())
h = list(map(int, input().split()))

dp = [float('inf') for _ in range(n+1)]

dp[0] = dp[1] = 0
dp[2] = abs(h[1]-h[0])

for i in range(3,n+1):
    dp[i] = min(dp[i-1]+abs(h[i-1]-h[i-2]),dp[i-2]+abs(h[i-1]-h[i-3]))

print(dp[n])

Measured memory_bytes: 52728
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
const int N=100005;

int n,k,h[N];
int dp[N];

int main() {
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n>>k;
	memset(dp,0x3f,sizeof dp), dp[1]=0;
	for (int i=1;i<=n;++i) cin>>h[i];
	for (int i=2;i<=n;++i)
		for (int j=1;j<=k;++j)
		    if (i-j>0) dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
	cout<<dp[n]<<'\n';
}

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

using namespace std;

long long gcd(long long a, long long b) {
	return b ? gcd(b, a % b) : a;
}

int main() {
	int n;
	cin >> n;
	unsigned long long ans = 1;
	for (int i = 0; i < n; i++) {
		unsigned long long t;
		cin >> t;
		ans /= gcd(ans, t);
		ans *= t;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll n;
  cin >> n;
  vl x(n+1);
  rep(i, n+1) cin >> x[i];
  sort(all(x));
  ll ans=x[1]-x[0];
  rep2(i, n-1) ans = gcd(ans, x[i+1]-x[i]);
  cout << ans << newl;
  return 0;
}

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

int main() 
{
	int a;
	while (cin >> a, a)
	{
		vector<vector<int>>l(a);
		for (int b = 0; b < a; b++) 
		{
			vector<int>r(4);
			cin >> r[0] >> r[1] >> r[2] >> r[3];
			l[b] = r;
		}
		vector<int>o(4);
		cin >> o[0] >> o[1] >> o[2] >> o[3];
		vector<int>s(0);
		for (int c = 0; c < a; c++) {
			if (l[c][1] <= o[0] && l[c][2] <= o[1] && l[c][3] <= o[2] && (l[c][1] + l[c][3]) * 4 + l[c][2] *9<= o[3])s.push_back(l[c][0]);
		}
		if (s.size() == 0)cout << "NA" << endl;
		else {
			for (int j : s)cout << j << endl;
		}
	}
}

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


struct Edge
{
    long long from;
    long long to;
    long long cost;
}edge[1000000];
long long dis[1010];
long long vertex,edge_num;
#define inf 10000000000000
bool flag[1010];
void Bellman_fold(long long s)
{
    memset(flag,0,sizeof(0));
    for(long long i=1;i<=vertex;++i)
    {
        dis[i]=inf;
    }
    dis[s]=0;
    for(long long i=1;i<vertex;++i)
    {
        for(int j=0;j<edge_num;++j)
        {
            if(dis[edge[j].from]!=inf&&dis[edge[j].from]+edge[j].cost<dis[edge[j].to])
                {
                    dis[edge[j].to]=dis[edge[j].from]+edge[j].cost;
                }
        }
    }
    for(long long i=1;i<=vertex;++i)
    {
        for(int j=0;j<edge_num;++j)
        {
            if(flag[edge[j].from]==true)
            {
                flag[edge[j].to]=true;
            }
            if(dis[edge[j].from]!=inf&&dis[edge[j].from]+edge[j].cost<dis[edge[j].to])
                {
                    dis[edge[j].to]=dis[edge[j].from]+edge[j].cost;
                    flag[edge[j].to]=true;
                }
        }
    }
}

int main(void)
{

//    ios::sync_with_stdio(0);
//    cin.tie(0);
//    cout.tie(0);
    scanf("%lld%lld",&vertex,&edge_num);
    long long from,to,weight;
    for (int i=0;i<edge_num;++i)
    {
        scanf("%lld %lld %lld",&edge[i].from,&edge[i].to,&weight);
        edge[i].cost=weight*(-1);
    }
    Bellman_fold(1);
    if(!flag[vertex])
    {
        printf("%lld\n",dis[vertex]*(-1));
    }
    else
    {
        printf("inf\n");
    }


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) ((a)<<(b))
#define Rshift(a,b) ((a)>>(b))
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define sz(a) int(a.size())
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;


int used[100100];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    ll n, m;
    cin >> n >> m;
    if (n % 2 == 1) {
        int i;
        rep(i, m) {
            cout << i + 1 << ' ' << n - i << endl;
        }
    } else {
        ll st = n / 2; 
        ll ed = st + 1;
        while (m--) {
            ll x = ed - st;
            x = min(x, n - x - 2);
            if (used[x]) {
                cout << st << ' ' << ed + 1 << endl;
            } else {
                cout << st << ' ' << ed << endl;
            }
            used[x] = 1;
            st--;
            ed++;
        }
    }
}


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


void solve(std::string s){
    string ans;
    ll n = s.length();
    for(ll i=0; i< n; i++){
        if(s.at(i)=='0') ans.push_back('0');
        if(s.at(i)=='1') ans.push_back('1');
        if(s.at(i)=='B'&& !ans.empty()) ans.pop_back();
    }
    cout << ans << endl;
}

int main(){
    std::string s;
    std::cin >> s;
    solve(s);
    return 0;
}


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


int main(void){
   int W,H,x,y,r,f;
   cin>>W>>H>>x>>y>>r;
   
   f = 0;
   if(x + r > W || y+ r > H  || r > x || r > y)
   f = 1;
   
   
   if(f == 0)
   cout  << "Yes" << endl;
   else
   cout << "No" << endl;
   
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using i64 = int64_t;
using ll = long long;
int main() {
  double T,X;
  cin >> T >> X;
  cout << fixed << setprecision(7);
  cout << T/X << endl;
  return 0;
}

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

using namespace std;

#define ll long long int
#define vi vector<int>
#define prec fixed<<precision(10)
#define mod 1000000007
#define set(x) __builtin_popcount(x)
#define ffs(x) __builtin_ffs(x)

int main(){
	int k;
	cin >> k;
	queue<long long int> q;
	vector<long long int> v(0);
	for(long long int i=1;i<=9;i++)q.push(i),v.push_back(i);
  	long long int num;
	while(v.size()<100000){
		num = q.front();
		q.pop();
		long long int lastdig = num%10;
		ll c= lastdig;
		long long int numa = num*10LL + (lastdig-1LL);
		long long int numb = num*10LL + (lastdig+1LL);
		long long int numc = num*10LL + lastdig;
	   if(c!=0){
	   	 q.push(numa);
	   	 v.push_back(numa);
	   }
		q.push(numc);
		v.push_back(numc);
		if(c!=9){
			q.push(numb);
			v.push_back(numb);
		}
	}
		cout << v[k-1];
	//for(int i=0;i<v.size();i++)if(i==k-1)cout << v[i];
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/10/06  Problem: abc112 B / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */


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

	int N, T; cin >> N >> T;
	int ans = INF;
	FOR(i, 0, N) {
		int a, b; cin >> a >> b;
		if (b <= T) {
			ans = min(ans, a);
		}
	}
	if (ans == INF) {
		cout << "TLE" << endl;
	}
	else {
		cout << ans << "\n";
	}


	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    t=(N+1000-1)//1000
    print(t*1000-N)

main()


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

#define MAX_N 1000

#define MAX_LOG 30

using namespace std;

typedef long long lint;

const int dl[] = {-1, 1, 0 , 0};
const int dc[] = {0, 0, -1, 1};
const char chr[] = {'L', 'R', 'D', 'U'};

int n;

struct elem
{
    lint x, y;
};

elem v[MAX_N + 1];

int ap[2];

lint p[MAX_LOG + 2 + 1];
int k;

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i ++)
    {
        cin >> v[i].x >> v[i].y;
        ap[(v[i].x + v[i].y) & 1] ++;
    }

    if((ap[0] ^ ap[1]) != max(ap[0], ap[1]))
    {
        cout << "-1\n";

        exit(0);
    }

    if(ap[0] != 0)
        p[++ k] = 1;

    for(int i = 0; i <= MAX_LOG; i ++)
        p[++ k] = (1 << i);

    cout << k << "\n";
    for(int i = 1; i <= k; i ++)
        cout << p[i] << " " ;
    cout << "\n";

    for(int i = 1; i <= n; i ++)
    {
        lint cx = 0;
        lint cy = 0;
        string rez;
        rez.clear();
        rez.resize(k);

      //  cout << "SUNTEM " << i <<  " KK " << k << "\n";

        for(int d = k; d >= 1; d --)
        {
           // cout << "SUNTEM " << cx << " Y " << cy << "\n";

            lint dx = 0;
            lint dy = 0;
            lint cr = -1;
            lint mn = (1LL << 60);
            for(int dir = 0; dir < 4; dir ++)
            {
                lint ux = cx + dl[dir] * p[d];
                lint uy = cy + dc[dir] * p[d];

                lint dist = abs(v[i].x - ux) + abs(v[i].y - uy);

               // if(i == 2 && d == k)
              //      cout << ux << " *** " << uy << " DIST TOT " << dist << "\n";

                if(dist < mn)
                {
                    mn = dist;

                    cr = dir;
                    dx = dl[dir];
                    dy = dc[dir];
                }
            }

            rez[d - 1] = chr[cr];
            cx = cx + dx * p[d];
            cy = cy + dy * p[d];
        }
       // cout << "SUNTEM FINAL " << cx << " Y " << cy << "\n";

        cout << rez << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
  using namespace std;
  #define ll long long

  int main()
  {
    ios::sync_with_stdio(0);
      cin.tie(0);
      cout.tie(0);
    
    ll n;
    cin >> n;
    string ans="";
    while(n>0) {
      ll d = n%26;
      n/=26;
      if(d==0) {n--; d = 26;}
      ans = (char)(d+96) + ans;
    }
    cout << ans;

    return 0;
  }

Measured memory_bytes: 3644
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list sep conv);
  arr

let rec powerset e =
  match Enum.get e with
  | None -> Enum.singleton @@ Enum.empty ()
  | Some v ->
    let f = powerset e in
    let g = Enum.clone f in
    EnumL.map f ~f:(fun x -> let y = Enum.clone x in push y v; y)
    |>  Enum.append g

let permutations l =
  let rec aux l =
    let rec interleave x = function
      | [] -> [[x]]
      | (hd::tl) as lst ->
        (x::lst) ::
        (ListL.map ~f:(List.cons hd)  @@ interleave x tl)
    in
    match l with
    | [] -> [[]]
    | hd::tl -> List.concat @@ List.map (interleave hd) @@ aux tl in
  let l = List.sort (List.compare Int.compare) @@ aux @@ List.of_enum l in
  List.enum % ListL.map ~f:List.enum @@ l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let x = scan "%d" id

let () =
  ListL.fold_left ~init:(0, false, 100)
    ~f:(fun (a, b, v) i ->
        let w = Int.of_float @@ 1.01 *. Float.of_int v in
        ((if b = false then i else a), b || w >= x , w)) (1++4000)
  |> Tuple3.first
  |> Printf.printf "%d\n"


Measured memory_bytes: 5764
import sys
input = sys.stdin.readline
import numpy as np
from numba import njit


def read():
    D = int(input().strip())
    C = np.fromstring(input().strip(), dtype=np.int32, sep=" ")
    S = np.empty((D, 26), dtype=np.int32)
    for i in range(D):
        s = np.fromstring(input().strip(), dtype=np.int32, sep=" ")
        S[i, :] = s[:]
    return D, C, S


@njit
def solve(D, C, S):
    last = [-1 for i in range(26)]
    idx = np.argmax(C)
    for d in range(D):
        print(idx+1)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


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

int main() {
    ll X,Y,Z,K;
    cin >> X >> Y >>Z >>K;
    vector<ll> A(X),B(Y),C(Z);
    for(int i=0;i<X;i++){
        cin >> A[i];
    }
    for(int i=0;i<Y;i++){
        cin >> B[i];
    }
    for(int i=0;i<Z;i++){
        cin >> C[i];
    }
    vector<ll> AB;
    for(int i=0;i<X;i++){
        for(int j=0;j<Y;j++){
            AB.push_back(A[i]+B[j]);
        }
    }
    sort(AB.rbegin(),AB.rend());
    sort(C.rbegin(),C.rend());
    vector<ll> ABK;
    for(int i=0;i<AB.size();i++){
        if(i>=K){
            break;
        }
        ABK.push_back(AB[i]);
    }
    vector<ll> ABC;
    for(int i=0;i<ABK.size();i++){
        for(int j=0;j<Z;j++){
            ABC.push_back(ABK[i] +C[j]);
        }
    }
    sort(ABC.rbegin(),ABC.rend());
    for(int i=0;i<K;i++){
        cout <<ABC[i] <<endl;
    }

    return 0;
}

Measured memory_bytes: 43272
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

using namespace std;
ll func(ll H){
    // 体力がHの敵を倒すのに必要な攻撃回数

}
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll H;
    cin >> H;
    if(H==1){
        cout << 1 << endl;
        return 0;
    }
    ll cnt = 0;
    while(H>0){
        H/=2;
        cnt++;
    }
    ll ans = 1;
    rep(i,cnt-1){
        ans = (2*ans + 1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<random>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();
	
	ll N, A, B; cin >> N >> A >> B;
	vector<ll>X(N);
	rep(i, 0, N)cin >> X[i];
	ll ans = 0;
	rep(i, 0, N - 1) {
		ans += min((X[i+1] - X[i]) * A, B);
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 1024
n = int(input())
xyh = [tuple(map(int, input().split())) for _ in range(n)]
xyh = sorted(xyh, key=lambda x: x[2], reverse=True)

ans = False
for cy in range(101):
    for cx in range(101):
        x0, y0, h0 = xyh[0]
        H = abs(x0-cx) + abs(y0-cy) + h0
        # 全てのクエリについて高さを計算する
        for x, y, h in xyh[1:]:
            hh = max(H-abs(x-cx)-abs(y-cy), 0)
            if h != hh:
                break
        else:
            # 回り切ったら答え
            ans = True
            print(cx, cy, H)
            break
        if ans:
            break
    if ans:
        break


Measured memory_bytes: 68324
#include <bits/stdc++.h>
//#include <mylib.h>
using namespace std;
//cin.sync_with_stdio(false);

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FOR_EQ(i,a,b) for(int i = (a); i <= (b); ++i)
#define FOR_RE(i,a,b) for(int i = (a); i > (b); --i)
#define rep(i,n) FOR(i,0,n)
#define rep_eq(i,n) FOR_EQ(i,0,n)
#define rep_re(i,n) FOR_RE(i,n,0)

#define WHITE 1//（未訪問）
#define GRAY 2//（訪問）未だに訪問していない頂点への辺を持っている。スタックに退避。
#define BLACK 3//（訪問完了）未訪問への頂点への辺を持たない
#define N 100
#define INFTY (1 << 21) //10^21
int M[N][N];//隣接行列
int color[N];

//1個上から時計周り
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//上右下左
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
static const int NIL = -1;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector>	DVector;
ll n;

//配列の表示
void printArray(int array[], int n){
    rep(i, n){
        if(i)   cout << " ";
        cout << array[i];
    }
    cout << endl;
}

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

    ll m;
    cin >> n >> m;
    
    ll res, re_c;
    re_c = m - 2 * n;
    
    if(re_c < 0){
        res = m / 2;
    }else{
        ll add = re_c / 4;
        res = n + add;
    }
    cout << res << endl;
    return 0;
}

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

int h, w, cnt = 0;
char c[55][55];
int ans[55][55], flag[55][55];

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
queue<P> que;

int main() {
    cin >> h >> w;
    rep(i,h){
        rep(j,w){
            cin >> c[i][j];
            if (c[i][j] == '.') cnt ++ ;
        }
    }
    flag[0][0] = 1;
    que.push(P(0,0));
    while (!que.empty()){
        P p = que.front();
        que.pop();
        rep(i,4){
            int x = p.second + dx[i];
            int y = p.first + dy[i];
            if (0 <= x && x <= w && 0 <= y && y <= h && !flag[y][x] && c[y][x] == '.'){
                flag[y][x] = 1;
                ans[y][x] = ans[p.first][p.second] + 1;
                que.push(P(y,x));
            }
        }
    }
    if (ans[h-1][w-1]) cout << cnt - ans[h-1][w-1] - 1 << endl;
    else cout << -1 << endl;
}

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

int main(){
    int a,b,c;
    cin>>a>>b>>c;

    int tim=0;
    while(true){
        if((tim%60<=c&&tim%60+a>=c)||(tim%60>=c&&(tim+a)%60)>=c&&tim%60>(tim+a)%60){
            while(tim%60!=c)tim++;
            cout<<tim<<endl;
            break;
        }
        tim+=a+b;
        if(tim%60==0){
            cout<<-1<<endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 1164
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>
#include<functional>
#include<numeric>
#include <tuple>

using namespace std;
using ll = long long;
using ld = long double;
#define int long long
#define all(a) (a).begin(),(a).end()
#define EPS (1e-7)
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define H pair<int, int>
#define P pair<int, pair<int, int>>
#define Q(i,j,k) mkp(i,mkp(j,k))
#define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
#define reo(i,n) for(int (i) = 1 ; (i) <= (n) ; (i)++)
#define rng(i,s,n) for(int (i) = (s) ; (i) < (n) ; (i)++)
#define req(n,i) for(int (i) = (n) - 1 ; (i) >= 0 ; (i)--)
#define mkp make_pair
#define mem0(x) memset(x,0,sizeof(x))
#define vec vector
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end())
#define ssp(i,n) (i==n-1?"\n":" ")
#define ctoi(c) (int)(c-'a')
#define itoc(c) (char)(c+'a')
#define itn int
#define pri_que priority_queue
#define pp(x,y) pb(H{x,y})
#define ppp(x,y,z) pb(Q(x,y,z))
#define cyes cout<<"Yes\n"
#define cno cout<<"No\n"
const int mod = 1e9 + 7;
const int Mod = 998244353;
const ll inf = 3 * 1e18;
const int Inf = 15 * 1e8;
const vec<int>dx{ 0,0,-1,1 }, dy{ 1,-1,0,0 };
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
ll read() { ll u, k = scanf("%lld", &u); return u; }
string reads() { string s; cin >> s; return s; }
ll gcd(ll i, ll j) { return j ? gcd(j, i % j) : i; }
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
ll bitcount(ll x) {
	int sum = 0; for (int i = 0; i < 60; i++)if ((1ll << i) & x) sum++;
	return sum;
}
const int fn_ = 600000;
ll fact_[fn_], comp_[fn_];
ll comb(ll x, ll y, ll Mod = mod) {
	if (!fact_[0]) {
		fact_[0] = 1; comp_[0] = 1;
		for (int i = 1; i < fn_; i++) {
			fact_[i] = fact_[i - 1] * i % Mod;
			comp_[i] = mod_pow(fact_[i], Mod - 2, Mod);
		}
	}
	if (x < y) return 0;
	return fact_[x] * comp_[x - y] % Mod * comp_[y] % Mod;
}
//---------------------------------------------------------------
signed main() {
	int h;
	cin >> h;
	int sum = 0, res = 1;
	while (h > 0) {
		sum += res;
		res *= 2;
		h /= 2;
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <stdint.h>
#include <vector>
using namespace std;

bool check(const vector<vector<int>>& M, int border)
{
    int h = M.size();
    int w = M[0].size();

    vector<int> ixs(h, 0);
    vector<bool> use(w, false);

    for (;;) {
        // for (int i = 0; i < h; i++) {
        //     cout << i << ", " << ixs[i] << endl;
        // }

        map<int, int> mm;
        for (int i = 0; i < h; i++) {
            if (ixs[i] < 0)
                continue;
            mm[M[i][ixs[i]]]++;
        }

        int maxc = 0, maxv = -1;
        for (auto& p : mm) {
            if (maxc < p.second) {
                maxv = p.first;
                maxc = p.second;
            }
        }

        if (maxc <= border)
            return true;

        if (maxv < 0)
            return false;

        // cout << "* " << maxc << ", " << maxv << endl;

        use[maxv] = true;

        for (int i = 0; i < h; i++) {
            if (ixs[i] < 0)
                continue;

            if (M[i][ixs[i]] != maxv)
                continue;

            while (ixs[i] < w && use[M[i][ixs[i]]])
                ixs[i]++;

            if (ixs[i] == w)
                return false;
        }
    }

    return false;
}

int solve()
{
    int h, w;
    cin >> h >> w;

    vector<vector<int>> M(h, vector<int>(w));

    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            cin >> M[y][x];
            M[y][x]--;
        }
    }

    int lo = 0, hi = h;

    while (hi - lo > 1) {
        int mi = (lo + hi) / 2;

        if (check(M, mi))
            hi = mi;
        else
            lo = mi;
    }

    return lo + 1;
}

int main()
{
    cin.tie(0);
    cout << solve() << endl;
    return 0;
}

Measured memory_bytes: 640
import numpy as np

N, W = map(int, input().split())
items = []
for _ in range(N):
    items.append(tuple(map(int, input().split())))
v_max = sum([i[1] for i in items])
INF = 10**12
dp = np.array([[INF for j in range(v_max+1)] for _ in range(N+1)])
dp[0, 0] = 0
for i in range(1, N+1):
    w, v = items[i-1]
    dp[i, :v] = dp[i-1, :v]
    dp[i, v:] = np.minimum(dp[i-1, :-v] + w, dp[i-1, v:])
ans = 0
for v in range(v_max, -1, -1):
    if dp[N][v] <= W:
        ans = v
        break
print(ans)

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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD=1e9+7;

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

  string right="yuiophjklnm";
  string s;
  while(true){
      cin>>s;
      if(s=="#") break;
      int res=0,side=0; //???????????????????????????
      for(int i=0;i<11;i++) if(s[0]==right[i]) side=1;
      for(int i=1;i<(int)s.length();i++){
          int tmp=0;
          for(int j=0;j<11;j++) if(s[i]==right[j]) tmp=1;
          if(side==tmp) continue;
          else{
              res++;
              side=tmp;
          }
      }
      cout<<res<<endl;
  }
  return 0;
}

Measured memory_bytes: 3116
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
long int idx[100001];
long long int power(long long int x,long long int y,long long int z)
{
    long long int res=1;
    x%=z;
    while(y>0)
    {
        if(y&1)
        res=(res*x)%z;
        x=(x*x)%z;
        y/=2;
    }
    return res;
}

long long int power1(long long int x,long long int y)
{
    long long int res=1;
    while(y>0)
    {
        if(y&1)
        res=(res*x);
        x=(x*x);
        y/=2;
    }
    return res;
}

long int root(long int x)
{
    while(idx[x]!=x)
    x=idx[x];
    return x;
}

void union1(long int x,long int y)
{
    idx[root(x)]=root(y);
}
int main() {
	
	
long int n;
cin>>n;
long int a[n][3];
	for(long int i=0;i<n;i++)
	{
	    for(long int j=0;j<3;j++)
	    cin>>a[i][j];
	}
	for(long int i=1;i<n;i++)
	{
	    for(long int j=0;j<3;j++)
	    {
	        a[i][j]=a[i][j]+max(a[i-1][(j+1)%3],a[i-1][(j+2)%3]);
	    }
	}
	long int ans=max({a[n-1][0],a[n-1][1],a[n-1][2]});
	cout<<ans;
	
	
	
	
	
	
	
	return 0;
}

Measured memory_bytes: 2560
import numpy as np

HN=np.array(input().split(" "),dtype=np.int32)
H=HN[0]
N=HN[1]

A=np.array(input().split(" "),dtype=np.int32)

damage=np.sum(A)

if(H<=damage):
    print("Yes")
else:
    print("No")

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

int main(){
    int N;
    string s;
    cin>>N>>s;
    
    int rcnt=count(s.cbegin(),s.cend(),'R');
    int wcnt=count(s.cbegin(),s.cbegin()+rcnt,'W');
    cout<<wcnt<<endl;
}


Measured memory_bytes: 3708
def main():
    N = int(input())
    cnt = [[0] * 19 for _ in range(44)]
    ans = 0
    for _ in range(N):
        a = input()
        if "." in a:
            b = int(a.replace(".", "")) * 10 ** (10 - (len(a) - a.index(".")))
        else:
            b = int(a) * 10 ** 9
        d2 = 0
        d5 = 0
        while b % 2 == 0:
            d2 += 1
            b //= 2
        while b % 5 == 0:
            d5 += 1
            b //= 5
        for i in range(max(0, 18-d2), 44):
            for j in range(max(0, 18-d5), 19):
                ans += cnt[i][j]
        cnt[d2][d5] += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 76868