akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int main(){
    int h,w,k;
    cin>>h>>w>>k;
    string str[h];
    rep(i,h)cin>>str[i];
    int cnt[h+1][w+1]={};
    rep(i,h){
        rep(j,w){
            cnt[i+1][j+1]=str[i][j]-'0';
        }
    }
    rep(i,h){
        rep(j,w){
            cnt[i+1][j+1]+=cnt[i][j+1]+cnt[i+1][j]-cnt[i][j];
        }
    }
    int ans=inf;
    for(int s=0;s<1<<(h-1);++s){
        vector<int> cut{0};
        rep(i,h-1){
            if(s&(1<<i))cut.push_back(i+1);
        }
        cut.push_back(h);
        int sz=cut.size();
        int l=0;
        int tate=0;
        for(int j=1;j<=w;++j){
            bool flag=false;
            for(int i=0;i<sz-1;++i){
                int u=cut[i];
                int d=cut[i+1];
                if(!flag&&cnt[d][j]-cnt[u][j]-cnt[d][l]+cnt[u][l]>k){
                    ++tate;
                    l=j-1;
                    flag=true;
                }
                if(flag&&cnt[d][j]-cnt[u][j]-cnt[d][l]+cnt[u][l]>k){
                    tate=inf;
                    j=w;
                    break;
                }
            }
        }
        ans=min(tate+sz-2,ans);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
S = str(input())
T = str(input())
s_list = [[] for i in range(26)]
t_list = [[] for i in range(26)]
#各アルファベットがどこにあるか？
for i in range(len(S)):
    s_list[ord(S[i])-97].append(i)
for i in range(len(T)):
    t_list[ord(T[i])-97].append(i)
ok = True
for s in s_list:
    if s != []:
        if s in t_list:
            continue
        else:
            ok = False
            break

if ok:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 20528
from collections import defaultdict
n=int(input())
al=[chr(ord('a') + i) for i in range(26)]
norm=defaultdict(list)
def max_al(s):
  tmp=0
  for i in range(len(s)):
    tmp2=al.index(s[i])
    tmp=max(tmp,tmp2)
  return tmp

for i in range(11):
  if i==0:
    norm[1]=['a']
  else:
    for char in norm[i-1]:
      range_digit=max_al(char)+2
      for s in al[0:range_digit]:
        norm[i].append(char+s)

for char in norm[n]:
  print(char)

Measured memory_bytes: 14872
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const ll INF = 1LL << 58;
const ll MOD = 1000000007;
typedef vector<pii> vpii;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

signed main()
{
    //  以降 cin の入力元が 'input.txt' になる
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int n, k;
    cin >> n >> k;
    vi vin(n);
    REP(i, n)
    {
        cin >> vin[i];
    }
    REP(i, n - k)
    {
        if (vin[i] < vin[i + k])
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 4840
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int r = sc.nextInt();
		int s = sc.nextInt();
		int p = sc.nextInt();
		char[] t = sc.next().toCharArray();
		sc.close();

		int ans = 0;
		boolean[] win = new boolean[n];
		for (int i = 0; i < n; i++) {
			if (i < k || t[i - k] != t[i] || !win[i - k]) {
				if (t[i] == 'r') {
					ans += p;
				} else if (t[i] == 's') {
					ans += r;
				} else {
					ans += s;
				}
				win[i] = true;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 27348
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<stack>
#include<map>
#include<cstdint>
#include<unordered_map>
//#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second


//namespace mp = boost::multiprecision;

//using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

int main() {
	int N, A, B, C;
	cin >> N >> A >> B >> C;
	vector<int>len(N);
	rep(i, N) {
		scanf("%d", &len[i]);
	}
	int ans = 1e6;
	int i = 0;
	while (i < pow(4, N)) {
		stack<int>base4;
		vector<int>abc(3);
		int tmpi = i;
		while (tmpi > 0) {
			base4.push(tmpi % 4);
			tmpi /= 4;
		}
		while (base4.size() < N) {
			base4.push(0);
		}
		int count = 0;
		rep(j, N) {
			rep(k, 3) {
				if (base4.top() == k+1) {
					if (abc[k] != 0) {
						count++;
					}
					abc[k]+=len[j];
				}
			}
			base4.pop();
		}
		bool flag = true;
		rep(k, 3) {
			if (!abc[k]) {
				flag = false;
				break;
			}
		}
		if (flag) {
			int a = abs(A - abc[0]);
			int b = abs(B - abc[1]);
			int c = abs(C - abc[2]);
			ans = min(ans, a + b + c + count * 10);
		}
		i++;
	}
	cout << ans << endl;


}


Measured memory_bytes: 512
"""
Writer: SPD_9X2
https://atcoder.jp/contests/cf16-final-open/tasks/codefestival_2016_final_f

街を、初めて訪れる順に順番つけすると街の順列を考えずに済むようになる

まだ未訪問を状態0
訪問したが、町1に戻れない街を、状態1
街0にたどり着くことが出来る街を、状態2 とする

出来ることは高々3つ。
未訪問の街に行く→状態0の街が一つ減り、1の街が1つ増える
状態1の街に行く→なにも変化なし
状態2の街に行く→状態1の街が全て2に変わる

あとはこれでdpしてあげて、順列を掛けてあげれば終わり!
→べつにdp推移中に計算すればokだった

dp推移は、dp[未訪問の街の数][状態1の街の数] = 移動の数
でおｋ O(N**3)で解ける。

"""

N,M = map(int,input().split())

dp = [ [0] * N for i in range(N) ]
dp[N-1][0] = 1
mod = 10**9+7

for loop in range(M):

    ndp = [ [0] * N for i in range(N) ]

    for i in range(N):

        for j in range(N):

            #未訪問に行く
            if i != 0 and j != N-1:
                ndp[i-1][j+1] += dp[i][j] * i
                ndp[i-1][j+1] %= mod

            #状態1の街に行く(少なくとも1つある場合)

            if j > 0:
                ndp[i][j] += dp[i][j] * j
                ndp[i][j] %= mod

            #状態2の街に行く

            ndp[i][0] += dp[i][j] * (N-i-j)
            ndp[i][0] %= mod

    dp = ndp

print (dp[0][0] % mod)

Measured memory_bytes: 121564
#include <iostream>
#include <vector>
using namespace std;
int n,m,u,v,s;
vector<int> a[9];
bool z[9];

void f(int p, int q, int r) {
	if(r==n) {s++; return;}
	for(int i=0; i<a[p].size(); i++) {
		if(!z[a[p][i]] && a[p][i]!=q) {
			z[a[p][i]] = 1;
			f(a[p][i], p, r+1);
			z[a[p][i]] = 0;
		}
	}
}

int main() {
	cin>>n>>m;
	while(m--) {
		cin>>u>>v;
		a[u].push_back(v);
		a[v].push_back(u);
	}
	z[1] = 1;
	f(1,0,1);
	cout<<s;
	return 0;
}

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

int main() {
  int N,K,L;
  cin >> N >> K;
  vector<int> h(N);
  L = 0;
  for(int i = 0;i < N;i++){
    cin >> h[i];
  }
  for(int i = 0;i < N;i++){
    if(h[i] >= K){
      L++;
    }
  }
  cout << L <<endl;
}

Measured memory_bytes: 3696
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<ctype.h>
 
 
 
int main()
 
{
    int count=0;
    char s[250000],t[250000];
    scanf("%s %s",s,t);
    int len=strlen(t);
    for(int i=0;i<len;i++)
    {
        if(s[i]!=t[i])
        {
            s[i]=t[i];
            count++;
        }
    }
    printf("%d\n",count);
 
 
    return 0;
}

Measured memory_bytes: 2104
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;

int main() {
	string s;
	cin >> s;
	bool flag = true;
	if (s[0] != 'A') flag = false;
	int cnt = 0;
	for (int i = 2; i <= sz(s) - 2; i++) {
		if (s[i] == 'C') cnt++;
	}
	if (cnt != 1) flag = false;
    cnt=0;
	rep(i, sz(s)) {
      if(s[i]-'A'<26) cnt++;
	}
    if(cnt!=2) flag=false;
	if (flag) {
		cout << "AC" << endl;
	}
	else {
		cout << "WA" << endl;
	}
}


Measured memory_bytes: 256
val = input()
val2 = input()

res = ""
for i in range(0, min(len(val), len(val2))):
    res += val[i]
    res += val2[i]

if len(val) == len(val2):
    pass
elif len(val) > len(val2):
    res += val[-1]
else:
    res += val2[-1]
print(res)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
//macros
using namespace std;
typedef long long ll;
typedef pair<int, int > P;
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<=(b); i++)
const long long int mod = 1e9 + 7;

int main()
{
  int N; ll Y;
  ll sum = 0;
  cin >> N >> Y;
  rep(i, 0, N){
    rep(j,0,N-i){
      sum = 10000*(N-i-j)+5000*j+1000*i;
      if(sum == Y){
	cout << N-i-j << " "<< j <<" " <<i << endl;
	return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>
#include <set>
#include <map>
#include <type_traits>
#include <cstdint>
#include <queue>
#define _USE_MATH_DEFINES
#include <math.h>
#include <sstream> // std::stringstream
#include <bitset>  // std::bitset<N>

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

//素因数分解
void factoring(ll n, map<ll, ll>& mp) {
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			mp[i]++;
			n /= i;
		}
	}
	if (n != 1) mp[n]++;
}

//絶対値
template<class T, class U = std::make_unsigned_t<T>>
U SafeAbs( T x ) {
    return x < 0 ? -static_cast<uintmax_t>(x) : x;
}

//最大・最小
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;
}

//xのn乗
ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
//xの逆元
ll mod_inv(ll x, ll mod) {//O(log(mod))
    return mod_pow(x, mod - 2, mod);
}

//nCr
ll ncr(ll n, ll r, ll mod){
	ll res=1;
	ll num=1,den=1;
	for(ll i=n;i>=n-r+1;i--){
		(den*=i)%=mod;
	}
	for(ll i=1;i<=r;i++){
		(num*=i)%=mod;
	}
	
	res=den*mod_inv(num,mod);

	return res%mod;
}


//二分探索
bool isOk(ll index, ll key,vector<ll> &a){
	
	if(a[index]>key){
		return true;
	}
	
	return false;
}

ll bin_search(ll key, vector<ll> &a){
	
	ll l=-1;
	ll r=a.size();

	while(abs(r-l)>1){
		ll mid = (l+r)/2;
		if(isOk(mid, key, a)){
			r=mid;
		}
		else{
			l=mid;
		}
	}
	return r;
}

/*
//深さ優先探索
void dfs(vector<vector<ll>> &gra,vector<bool> &seen, ll v){

	seen[v]=true;

	for(auto next : gra[v]){
		if(seen[next]){
			continue;
		}

		dfs(gra,seen,next);
	}
	
}
*/

const ll MOD=1000000007;

ll min(ll a, ll b){
	if(a>=b){
		return b;
	}
	else{
		return a;
	}
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

ll Factorial(ll n)
{
	ll a=1;
	for (ll i = 1; i <= n; i++)
	{
		a *= i;
		a %= MOD;
	}
	return a;
}
void solve()
{
	ll n;
	cin >> n;
	vector<pair<ll, ll>> d(n);
	for (ll i = 0; i < n;i++){
		cin >> d[i].first >> d[i].second;
	}
	ll check = 0;
	bool ans = false;
	for (ll i = 0; i < n; i++)
	{
		if(d[i].first==d[i].second){
			check++;
		}
		else{
			check = 0;
		}

		if(check==3){
			ans = true;
			break;
		}
	}

	if(ans){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}

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

Measured memory_bytes: 3628
//
// Created by in on 20/7/25.
//

#include<bits/stdc++.h>

using namespace std;

const int MAX = 200000;

int main ()
{
	int R[MAX], n;
	cin >> n;

	for(int i = 0; i < n; ++i)
	{
		cin >> R[i];
	}
	int maxV = -2e10;
	int minV = R[0];

	for(int i = 1; i < n; ++i)
	{
		maxV = max(maxV, R[i] - minV);
		minV = min(minV, R[i]);
	}
	cout << maxV << endl;
	return 0;
}


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

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

  cout << (x/11)*2 + ((x%11)+5)/6 << 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;
using ll = long long;

int main() {
	cin.tie(0)->sync_with_stdio(false);

	string s;
	cin >> s;
	int n = s.size();

	ll res = 0;
	REP(bit, 1 << (n - 1)) {
		ll tmp = 0;
		REP(i, n) {
			tmp += s[i] - '0';
			if ((bit >> i) & 1 || i == n - 1) {
				res += tmp;
				tmp = 0;
			} else
				tmp *= 10;
		}
	}

	cout << res << '\n';
	return 0;
}


Measured memory_bytes: 3676
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)
	n := scanInt()
	a := scanInts(n)
	count := make(map[int]int, n)
	for i := 0; i < n; i++ {
		count[a[i]]++
	}

	sum := make(map[int]int, n)
	sumPrev := make(map[int]int, n)
	sumAll := 0
	for i := 0; i < n; i++ {
		num := a[i]
		if _, ok := sum[num]; !ok {
			sum[num] = calculateSum(count[num])
			sumAll += sum[num]

			sumPrev[num-1] = calculateSum(count[num] - 1)
		}
	}

	for k := 0; k < n; k++ {
		sub := sum[a[k]] - sumPrev[a[k]-1]
		fmt.Println(sumAll - sub)
	}
}

func calculateSum(n int) int {
	return (n * (n - 1)) / 2
}

func scanInt() int {
	i, _ := strconv.Atoi(scanText())
	return i
}

func scanInts(size int) []int {
	ints := make([]int, size)
	for i := 0; i < size; i++ {
		ints[i] = scanInt()
	}
	return ints
}

func scanText() string {
	scanner.Scan()
	return scanner.Text()
}

func abs(n int) int {
	return int(math.Abs(float64(n)))
}


Measured memory_bytes: 19840
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;

int a;
int num[3000003];
vector<int>vec;
int main(){
	memset(num, -1, sizeof(num));
	for (int i=1;7*i+1<=300000;i++){
		int fi = 7 * i - 1;
		if (num[fi] == -1){
			num[fi] = 1;
			for (int j=fi*2;j<=300000;j+=fi)num[j] = 0;
		}
		int se = 7 * i + 1;
		if (num[se] == -1){
			num[se] = 1;
			for (int j=se*2;j<=300000;j+=se)num[j] = 0;
		}
	}
	
	for (int i=6;i<=300000;i++){
		if (num[i] == 1){
			vec.push_back(i);
		}
	}
	vec.push_back(999989);
	vec.push_back(999999);
	while(scanf("%d", &a)){
		if (a==1)return 0;
		printf("%d:", a);
		for (int i=0;vec[i]<=a;i++){
			if (!(a%vec[i])) printf(" %d", vec[i]);
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 14584
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
bool suf(ld a, ld b, ld c, ld d) {
	if (b <= c || d <= a) return 0;
	return 1;
}//[a,b),[c,d)
ll fact(ll i, ll z) {
	ll sum = 1;
	for (ll j = max(z, 2LL); j <= i; j++)
		sum = (sum* j) % Mod;
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%Mod;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}
#define int long long
const long long inf = 4523372036854775807;
const int iinf = 1500000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
int n, m;
vector<B>e[100001];
int a[100001];
int pa[100001];
int root(int x) {
	if (pa[x] == x) {
		return x;
	}
	return pa[x] = root(pa[x]);
}
void unite(int x, int y) {
	x = root(x), y = root(y);
	pa[x] = y;
}
bool b[100001];
signed main() {
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		pa[i] = i;
	}
	for (int i = 1; i <= n; i++)
		a[i] = inf;
	for (int i = 0; i < m; i++) {
		int l, r, d;
		cin >> l >> r >> d;
		e[l].push_back(B{ r,d });
		e[r].push_back(B{ l,-d });
		unite(l, r);
	}
	for (int i = 1; i <= n; i++) {
		root(i);
	}
	queue<int>q;
	for (int i = 1; i <= n; i++) {
		if (!b[pa[i]]) {
			q.push(pa[i]);
			b[pa[i]] = 1;
			a[pa[i]] = 0;
		}
	}
	while (!q.empty()) {
		int t = q.front(); q.pop();
		for (int i = 0; i < e[t].size(); i++) {
			if (a[e[t][i].to] == inf) {
				a[e[t][i].to] = a[t] + e[t][i].cost;
				q.push(e[t][i].to);
			}
			else {
				if (a[e[t][i].to] != a[t] + e[t][i].cost) {
					cout << "No\n";
					return 0;
				}
			}
		}
	}
	cout << "Yes\n";
	getchar(); getchar();
}

Measured memory_bytes: 14952
S = input()
count = 0
smae = ""

for i in range(len(S)) :
    if i == 0 :
        smae = S[i]
    elif smae == S[i] :
        smae = ("1" if S[i] == "0" else "0")
        count += 1
        continue
    smae = S[i]
    
print(count)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  string s;
  cin>>n>>k>>s;
  k-=1;
  if(s[k]=='A'){
    s[k]='a';
  }else if(s[k]=='B'){
    s[k]='b';
  }else{
    s[k]='c';
  }
  cout<<s<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
using namespace std;


int main() {
	long long n, c = 0, turn = 0;
	cin >> n;
	while(n != 0){
		c += pow(2, turn);
		n /= 2;
		turn++; 
	}
	cout << c;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
long long n,ans,m;
inline long long cal(long long x,long long y)
{	
	if(x>y)
	swap(x,y);
	if(y%x==0)
	return (2*(y/x)-1)*x;
	return 2*(y/x)*x+cal(y%x,x);
}
int main()
{
	scanf("%lld%lld",&n,&m);
	printf("%lld\n",n+cal(n-m,m));
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<stack>
#include<sstream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=10000+10;
int main()
{
    int n;
    while(~scanf("%d",&n)){
        printf("%d\n",48-n);
    }


    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        int x[] = new int[5];
        for(int i = 0; i < 5; i++){
            x[i] = stdIn.nextInt();
        }
        
        //int a = stdIn.nextInt();
        //int b = stdIn.nextInt();
        //int n = stdIn.nextInt();
        int k = stdIn.nextInt();
        
        if(x[4] - x[0] <= k){
            System.out.println("Yay!");
        }else{
            System.out.println(":(");
        }
        
        //System.out.println();
        //System.out.print();
    }
}


Measured memory_bytes: 23252
# せいぜいひとつ繰り上がって10*Nになる程度なので
# 全探索で構わんという罠

n, k = gets.chomp.split.map(&:to_i)
arr = gets.chomp.split
n.upto(10*n) do |i|
  flag = true
  i.to_s.chars.each do |c|
    if arr.include?(c)
      flag = false
      break
    end
  end
  if flag
    puts i
    exit
  end
end

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

int main(){
    int N;
    cin >> N;
    vector<int> vec(N);

    rep(i, N){
        cin >> vec.at(i);

    }
    int light = 1;
    int count = 0;
    bool goal = false;
    rep(i, N)
    {
        light = vec.at(light - 1);
        count += 1;
        if (light == 2)
        {
            goal = true;
            break;
        }
    }

    if (goal)
    {
        cout << count << endl;
    }
    else
    {
        cout << "-1" << endl;
    }
    
    
}

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

int main(void) 
{
  int i = 1, a, b;
  while(1) {
      cin >> a >> b;
      if(a == 0 && b == 0) break;
      if(a > b) {
          cout << b << " " << a << endl;
      } else { 
          cout << a << " " << b << endl;
      }
      i++;
    }
}




Measured memory_bytes: 3092
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#include <bitset>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  long N, M;
  cin >> N >> M;
  unordered_set<long> st;
  st.insert(1);
  unordered_map<long, long> mp;
  for (long i = 1; i <= N; i++) mp[i] = 1;
  rep (i, M) {
    long x, y;
    cin >> x >> y;
    if (st.count(x) > 0) st.insert(y);
    mp[y]++;
    mp[x]--;
    if (mp[x] == 0) st.erase(x);
  }
  cout << st.size() << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


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

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	ll N,Q;
    string S;
	cin>>N;
    cin>>S;
    cin>>Q;
    ll t,a,b;
    char c;
    map<char,set<ll>> s_mp;
    rep(i,26){
        char a = (char)(int('a')+i);
        s_mp[a] = {};
    }

    rep(i,N){
        s_mp[S[i]].insert(i);
    }
    ll ans = 0;
    
    rep(i,Q){
        cin>>t;
        if(t==1){
            cin>>a>>c;
            s_mp[S[a-1]].erase(a-1);
            S[a-1] = c;
            s_mp[S[a-1]].insert(a-1);
        }else{
            cin>>a>>b;
            ans = 0;
            rep(i,26){
                char c = (char)(int('a')+i);
            
                auto x = s_mp[c].lower_bound(a-1);
                auto y = s_mp[c].upper_bound(b-1);
                if(x!= y){
                    ++ans;
                }
            }
            cout<<ans<<"\n";
        }

    }
	

	return 0;
}

Measured memory_bytes: 26268
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18) + 1;
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll n, m;
vector<ll> a;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n>>m;
    map<ll,ll>ma;
    ma[1]=2;
    ma[2]=5;
    ma[3]=5;
    ma[4]=4;
    ma[5]=5;
    ma[6]=6;
    ma[7]=3;
    ma[8]=7;
    ma[9]=6;
    for (int i = 0; i < m; i++)
    {
        ll temp;
        cin >> temp;
        a.push_back(temp);
    }
    vector<string> dp(n+10,"0");
    dp[0]="";
    rep(i,n+1){
        if(dp[i]=="0")continue;
        rep(j,m){
            if(dp[i+ma[a[j]]].size()==dp[i].size()+1){
                char temp=a[j]+'0';
                string temp1=dp[i]+temp;
                if(temp1>dp[i+ma[a[j]]]){
                    //cout<<temp1<<" "<<dp[i+ma[a[j]]]<<"\n";
                    dp[i+ma[a[j]]]=temp1;
                }
            }
            else{
                if(dp[i+ma[a[j]]].size()<dp[i].size()+1){
                    char temp=a[j]+'0';
                    dp[i+ma[a[j]]]=dp[i]+temp;
                }
            }
        }
        //debug(dp);
    }
    cout << dp[n] << "\n";
}


Measured memory_bytes: 43648
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;


using Graph = vector<vector<int>>; 
Graph g;

vector<int> dp;
vector<bool> flag;

int rec(int x) {
    if (flag[x]) return dp[x];
    flag[x] = true;
    
    int res = 0;
    for (auto e : g[x]) {
        res = max(res, rec(e)+1);
    }

    dp[x] = res;

    return res;
}


void solve() {
    int N, M; cin >> N >> M;
    
    g.resize(N);
    dp.resize(N);
    flag.resize(N);

    for (int i = 0; i < M; i++) {
        int x, y; cin >> x >> y;
        x--; y--;
        g[x].push_back(y);
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        ans = max(ans, rec(i));
    }

    cout << ans << endl;
}


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

Measured memory_bytes: 11096
#include <cstdio>

using namespace std;

int n, r;
int cards[2][51];

int main() {
  while (true) {
    scanf("%d %d", &n, &r);
    if (n == 0 && r == 0) break;
    for (int i=0;i<n;i++) cards[0][i] = n-i;
    for (int i=0;i<r;i++) {
      int p, c;
      scanf("%d %d", &p, &c);
      for (int j=0;j<c;j++) {
        cards[(i+1)&1][j] = cards[i&1][p-1+j];
      }
      for (int j=0;j<p-1;j++) {
        cards[(i+1)&1][c+j] = cards[i&1][j];
      }
      for (int j=p-1+c;j<n;j++) {
        cards[(i+1)&1][j] = cards[i&1][j];
      }
    }
    printf("%d\n", cards[r&1][0]);
  }
}

Measured memory_bytes: 2584
/* *>>>>>Anshit_Bhardwaj<<<<<* */
#include <bits/stdc++.h>
#define ll long long
#define f(i, x, n) for(int i = x; i < n; i++)
#define dbg(x) cout << x << endl
#define dbg2(x, y) cout << x << ' ' << y << endl
#define dbg3(x, y, z) cout << x << ' ' << y << ' ' << z << endl
#define mod 1000000007
using namespace std;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    cout << a*b << endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int power(int x, int n){
    int res = 1;

    if(n > 0){
        res = pow(x, n/2);
        if(n%2 == 0) res *= res;
        else res = res*res*x;
    }

    return res;
}

int main(){
    int N; cin >> N;
    int ans = power(3, N);

    int res = 1;
    for(int i=0; i<N; i++){
        int a; cin >> a;
        if(a%2 == 0) res *= 2;
    }

    cout << ans - res << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1003,INF = 0x3f3f3f3f;
int n,X[MaxN];
vector<int> e[MaxN];
int dp[MaxN];

bool dfs(int x) {
    vector<int> f;f.resize(X[x]+1,INF);f[0]=0;
    for (auto v:e[x]) {
        if (!dfs(v)) return false;
        vector<int> g;g.resize(X[x]+1,INF);
        for (int i=0;i<=X[x]-X[v];++i) g[i+X[v]]=min(g[i+X[v]],f[i]+dp[v]);
        for (int i=0;i<=X[x]-dp[v];++i) g[i+dp[v]]=min(g[i+dp[v]],f[i]+X[v]);
        f=g;
    }
    dp[x]=INF;
    for (auto i:f) dp[x]=min(dp[x],i);
    return dp[x]<INF;
}

int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    cin >> n;
    for (int i=2;i<=n;++i) {
        int x;cin >> x;
        e[x].push_back(i);
    }
    for (int i=1;i<=n;++i) cin >> X[i];
    if (dfs(1)) cout << "POSSIBLE\n";
    else cout << "IMPOSSIBLE\n";
    return 0;
}

Measured memory_bytes: 5756
S = gets.chomp
ans01 = 0
ans10 = 0
S.chars.each_with_index{|c,i|
  if i % 2 == 0
    if c == "0"
      ans10 += 1
    else
      ans01 += 1
    end
  else
    if c == "0"
      ans01 += 1
    else
      ans10 += 1
    end
  end
}

if ans01 < ans10
  puts ans01
else
  puts ans10
end

Measured memory_bytes: 9468
#include <bits/stdc++.h>
using namespace std;
#define sz(a) (int)(a).size()
#define all(a) (a).begin() , (a).end()
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define name(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int N=(int)1e6+7;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n , d, x;
    cin >>n >> d >> x;
    int ans=0;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        int t = d / a;
        if(t==0)ans++;
        else if(t * a + 1 <= d)ans += t + 1;
        else
        ans += t;
       // debug() << name(t);
    }
    cout << ans + x << '\n';
    return 0;
}



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

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

    vector<pair<int, int>> robot;
    for (auto i = 0; i < n; i++) {
        int x, l;
        cin >> x >> l;
        robot.emplace_back(x + l, x - l);
    }
    sort(robot.begin(), robot.end());

    int ans = 1, last = robot[0].first;
    for (auto i = 1; i < n; i++) {
        if(last > robot[i].second) continue;
        ans++;
        last = robot[i].first;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1400
def main():
    H, W = (int(_) for _ in input().split())
    S = [input() for _ in range(H)]
    yoko = [[0] * W for _ in range(H)]
    tate = [[0] * W for _ in range(H)]

    for i in range(H):
        right = 0
        cc = 0
        for left in range(W):
            if S[i][left] == '#':
                cc = 0
                right += 1
                continue
            while right < W and S[i][right] == '.':
                right += 1
            cc = right - left
            if left > 0 and S[i][left-1] == '.': yoko[i][left] = yoko[i][left-1]
            else: yoko[i][left] = cc
    for i in range(W):
        bottom = 0
        cc = 0
        for top in range(H):
            if S[top][i] == '#':
                cc = 0
                bottom += 1
                continue
            while bottom < H and S[bottom][i] == '.':
                bottom += 1
            cc = bottom - top
            if top > 0 and S[top-1][i] == '.': tate[top][i] = tate[top-1][i]
            else: tate[top][i] = cc
    output = 0
    for i in range(H):
        for j in range(W):
            output = max(output, yoko[i][j]+tate[i][j]-1)
    print(output)
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 137596
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#include <time.h>
#include <chrono>
#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a,b) for(ll i=a;i>b;i--)
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define repl(i,l,r) for(int i=(1);i<(r);i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = (1LL << 31) - 1;
const ll mod = 1e9 + 7;


set<ll> s, t;


ll cul(ll x,bool flag,bool judge) {
	//flag trueでshrineを探す
	ll right, left;

	if (flag) {
		auto ite = s.lower_bound(x);
		
			if (ite == s.end())right= 100000000000;
			else {
				right = abs(x - *ite);
				if (!judge) {
					right += cul(*ite,false,true);
				}
			}
		
			if (ite == s.begin())left= 100000000000;
			else {
				ite--;
				left = abs(x - *ite);
				if (!judge) {
					left += cul(*ite, false, true);
				}
			}

	}
	else {
		auto ite = t.lower_bound(x);

		if (ite == t.end())right = 100000000000;
		else {
			right = abs(x - *ite);
			if (!judge) {
				right += cul(*ite, true, true);
			}
		}

		if (ite == t.begin())left = 100000000000;
		else {
			ite--;
			left = abs(x - *ite);
			if (!judge) {
				left += cul(*ite, true, true);
			}
		}
	}
	//cout <<"  "<< min(right, left) << endl;
	return min(right, left);
}

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

	ll A, B; cin >> A >> B;
	ll Q; cin >> Q;

	FOR(i, 0, A){
		ll x; cin >> x;
		s.insert(x);
	}
	FOR(i, 0, B) {
		ll x; cin >> x;
		t.insert(x);
	}
	FOR(i, 0, Q) {
		ll x; cin >> x;

		cout <<min(cul(x,true,false),cul(x,false,false)) << endl;

	}



	return 0;
}

Measured memory_bytes: 13020
n,k = map(int,input().split())

li = []

for i in range(n):
    s,t = map(int,input().split())
    li.append([s,t])
    
li.sort()

cnt = 0
for i in range(n):
    cnt += li[i][1]
    if cnt >= k:
        print(li[i][0])
        exit()


Measured memory_bytes: 20104
using System;
using System.Collections.Generic;
using System.Linq;

public class Hello
{
	static void Main(string[] args)
    {
        var num1 = int.Parse(Console.ReadLine());
        long numSum = 0;

        for (int i = 1; i <= num1; i++)
        {
            for (int j = 1; j <= num1; j++)
            {
                for (int k = 1; k <= num1; k++)
                {
                    long tempNum = Gcd(i, j);
                    long tempNum2 = Gcd(tempNum, k);
                    numSum += tempNum2;
                }

            }

        }

        Console.Write(numSum);

    }

    static long Gcd(long m, long n)
    {
        if (n == 0) return m;
        return Gcd(n, m % n);
    }

}


Measured memory_bytes: 27328
#include<bits/stdc++.h>
using namespace std;
char ans[100005];
int main()
{
	string s;
	int n,j=0;
	cin >> s >> n;
	for(int i=0;i<s.size();i+=n){
		ans[j++]=s[i];
	}
	for(int i=0;i<j;i++)
		cout << ans[i];
	system("pause");
	return 0;
}


Measured memory_bytes: 504
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoders {
	class Program {
		static void Main(string[] args) {

			var inputArray = new string[3];
			inputArray = Console.ReadLine().Split(' ');

			// 不正な入力は処理しない
			if (inputArray.Length != 2) {
				Console.WriteLine("invalid input");
				return;
			}

			// 入力値セット
			var A = long.Parse(inputArray[0]);
			var B = long.Parse(inputArray[1]);

			// Aの消費税になる最大の税抜き金額=A+1円の消費税の金額になる最小の税抜き金額-1
			var MinA = CalcMinZeinuki(A, 0.08);
			var MaxA = CalcMinZeinuki(A + 1, 0.08) - 1;

			var MinB = CalcMinZeinuki(B,  0.1);
			var MaxB = CalcMinZeinuki(B + 1, 0.1) - 1;

			int ans;

			if(MinA <= MaxB & MinB <= MaxA) {
				ans = Math.Max(MinA, MinB);
			}
			else {
				ans = -1;
			}
			//Console.WriteLine($"8% {MinA},{MaxA}  10%{MinB},{MaxB}");
			Console.WriteLine(ans);

		}

		private static int CalcMinZeinuki(long A,double tax) {
			
			return (int)Math.Ceiling(A / tax);

		}
	}
}


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

int main(){
  int N;
  cin >> N;
  
  map<string, unsigned long long> m;
  unsigned long long ans = 0;
  
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());

    auto itr = m.find(s);
    
    if (itr == m.end())
      m[s] = 1;
    else
      m[s] += 1;
    
  }
  
  for(auto itr = m.begin(); itr != m.end(); ++itr) {
    if(itr->second > 1) ans += itr->second * (itr->second - 1) / 2;
  }
  
  cout << ans;
  
  return 0;
}




Measured memory_bytes: 11136
#include <bits/stdc++.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
//int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
//int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
//const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'


signed main() {
    fio();
    int a, b, h, m;
    cin >> a  >> b >> h >> m;
    double theta = (double)360 * m / 60.;
    double th2 = h * 30 + 30 * m / 60.;
    // DEBUG(theta);
    // DEBUG(th2);
    double x1 = b * cos(theta * pi / 180), y1 = b * sin(theta * pi / 180), x2 = a * cos(th2 * pi / 180), y2 = a * sin(th2 * pi / 180);
    DEBUG_VEC(vector<double>({x1, y1, x2, y2}));
    Sp(sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)));
}

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> a(n);
    for (auto &x: a) cin >> x;
    int w = 0;
    vector<int> c(32, 0);
    for (auto &x: a) {
        bool f = true;
        for (int i = 0; i < 32 && f; i++) {
            if (x & (1 << i)) {
                f = false, c[i]++;
            }
        }
        w ^= x;
    }
    int ans = 0;
    for (int i = 31; i >= 0; i--) {
        if (w & (1 << i)) {
            if (!c[i]) {
                cout << -1 << "\n";
                return 0;
            }
            w ^= (1 << (i+1)) - 1;
            ans++;
        }
    }
    if (w == 0) {
        cout << ans << "\n";
    } else {
        cout << -1 << "\n";
    }
    return 0;
}

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

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

int main() {
	ll a;
	double b;
	ll bb;
	ll ans;
	cin >> a >> b;
	bb = (ll)(b * 100+0.01);
	ans = (ll)((a * bb)/100);

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3740
#include <iostream>
#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
#define NIL -1
//#define INFTY 1000000000000000000

LL labs(LL x){
    if(x>0){
        return x;
    }else{
        return -1*x;
    }
}

int main(){
    LL h;
    LL w;
    LL d;
    LL q;
    cin >> h >> w >> d;
    LL a;
    vector<LL> x(h*w);
    vector<LL> y(h*w);
    for(LL i=0; i<h; i++){
        for(LL j=0; j<w; j++){
            cin >> a;
            a--;
            x[a]=i;
            y[a]=j;
        }
    }
    cin >> q;
    vector<LL> l(q);
    vector<LL> r(q);
    for(LL i=0; i<q; i++){
        cin >> l[i] >> r[i];
        l[i]--;
        r[i]--;
    }

    vector<LL> dp(h*w);
    for(LL i=0; i<d; i++){
        dp[i]=0;
    } 

    for(LL i=0; i<d; i++){
        LL tmp=i;
        while(tmp+d<h*w){
            dp[tmp+d]=dp[tmp]+labs(x[tmp+d]-x[tmp])+labs(y[tmp+d]-y[tmp]);
            tmp+=d;
        }
    }

    for(LL i=0; i<q; i++){
        cout << dp[r[i]]-dp[l[i]] << endl;
    }

    return 0;
}


Measured memory_bytes: 6952
#include<iostream>
using namespace std;
int main() {
  int tmp = 0;
  string S;
  cin >> S;
  for(int i = 0; i < 4; i++) {
    int tmp = 0;
    for(int j = 0; j < 4; j++) {
      if(S[i] == S[j]) {
        tmp++;
      }
    }
    if(tmp != 2) {
      printf("No");
      break;
    } else if (i == 3) {
      printf("Yes");
    }
  }
  return 0;
}

Measured memory_bytes: 764
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
// #include "prettyprint.hpp"

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  int ans = C - (A - B);
  cout << (ans > 0 ? ans : 0) << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        abc167_b solver = new abc167_b();
        solver.solve(1, in, out);
        out.close();
    }

    static class abc167_b {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int A = in.nextInt();
            int B = in.nextInt();
            int C = in.nextInt();
            int K = in.nextInt();

            int sum = 0;
            int diff = 0;
            if (A < K) {
                sum += A;
                diff = K - A;
            } else {
                out.println(K);
                return;
            }
            if (diff < B) {
                out.println(sum);
                return;
            } else {
                diff = diff - B;
            }
            sum -= diff;
            out.println(sum);


        }

    }
}



Measured memory_bytes: 35820
#include<stdio.h>
#define M 100000000
int MIN(int a,int b){return a<b?a:b;}
int zMIN(int a,int b){return a*b?MIN(a,b):a+b;}
int main(){
  int w,n,m,s,t,i,j,k,min;
  while(scanf("%d %d %d %d %d",&w,&n,&m,&s,&t),s){
    int d[110][110]={0};
    int c[20][110]={0};
    while(m--){
      scanf("%d %d %d",&i,&j,&k);
      d[i][j]=d[j][i]=k;
    }
    for(i=0;i<=w;i++){
      for(j=0;j<=n;j++)c[i][j]=M;
    }
    for(i=c[0][s]=0;i<=w;i++){
      int f[110]={0};
      for(j=0;j<n;j++){
	min=M;
	for(k=1;k<=n;k++){
	  if(f[k]==0&&min>c[i][k])min=c[i][s=k];
	}
	c[i+1][s]=MIN(c[i+1][s],c[i][s]);
	for(k=f[s]=1;k<=n;k++){
	  if(d[s][k]){
	    c[i  ][k]=MIN(c[i  ][k],c[i][s]+d[s][k]  );
	    c[i+1][k]=MIN(c[i+1][k],c[i][s]+d[s][k]/2);
	  }
	}
	//for(k=0;k<n;k++)printf("%d ",c[i][k+1]);printf("\n");
      }//printf("\n");
      //for(j=0;j<n;j++)printf("%d ",c[i][j+1]);printf("\n");
    }
    printf("%d\n",c[w][t]);
  }
  return 0;
}

Measured memory_bytes: 664
#!/usr/bin/perl

my ($n) = map { $_ - 0 } split(/\s+/,<STDIN>);
my $s = scalar(<STDIN>);

my @c = split(//o,$s);
my @p = ();
$#p = $n - 1;

my %cnt = ();


my $l = $c[0];
$cnt{$l} ++;

for(my $i=0;$i<$n-1;$i++){
  my $n = $c[$i+1];
  if( $l eq 'W' and $n eq 'R' ){
    $p[$i] = 1;
    $cnt{'WW'} ++;
  }
  $l = $n;
  $cnt{$l} ++;
}

if( $cnt{'W'} == 0 or $cnt{'R'} == 0 or $cnt{'WW'} == 0 ){
  print "0\n";exit(0);
}

my $mr_r = -1;
my $ml_w = $n;
for(my $i=0;$i<$n;$i++){
  $mr_r = $i if $c[$i] eq 'R';
  $ml_w = $n-1-$i if $c[$n-1-$i] eq 'W';
}

#print "mr_r = $mr_r , ml_w = $ml_w \n";
#exit(0);

my $op = 0;

while( $mr_r >= 0 and $ml_w < $n and $mr_r >= $ml_w and $cnt{'WW'}>0 ){
  # $mr_r を白 $ml_w を赤にする
  $c[$mr_r] = 'W';
  if( $mr_r > 0 and $c[$mr_r - 1] eq 'W' ){
    $cnt{'WW'} --;
  }
  while( $mr_r >= 0 and $c[$mr_r] eq 'W' ){
    $mr_r --;
  }
  $c[$ml_w] = 'R';
  if( $ml_w < $n-1 and $c[$ml_w + 1] eq 'R' ){
    $cnt{'WW'} --;
  }
  while( $ml_w < $n and $c[$ml_w] eq 'R' ){
    $ml_w ++;
  }
  $op++;
}

print "$op\n";



Measured memory_bytes: 23144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF 2 << 29
#define MOD 1000000007
#define Yes(f) puts((f)? "Yes" : "No")
#define YES(f) puts((f)? "YES" : "NO")
int gcd(int a, int b) {
	if (b != 0)return gcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}

using Graph = vector<vector<int>>;

int main(){
	int a, b, c; cin >> a >> b >> c;
	bool f = true;
	if((a != b && b != c && a != c) || (a == b && b == c)) f = false;
	Yes(f);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define loop(n, i) for(int i=0;i<n;i++)
#define loop1(n, i) for(int i=1;i<=n;i++)
#define rloop(n, i) for(int i=n;i;i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;
using P = pair<int, int>;

struct Edge {
    int u;
    int v;
    int cost;
};

const int INF = 1<<29;

int main() {
    int n, m, p; cin >> n >> m >> p;
    V<Edge> E(m);
    loop (m, i) {
        int a, b, c; cin >> a >> b >> c;
        a--, b--;
        E[i] = { a, b, p - c };
    }

    V<int> dist(n, INF);
    dist[0] = 0;
    loop (n - 1, i) {
        loop (E.size(), j) {
            auto e = E[j];
            if (dist[e.v] > dist[e.u] + e.cost) {
                dist[e.v] = dist[e.u] + e.cost;
            }
        }
    }

    V<int> dist2 = dist;
    loop (n, i) {
        loop (E.size(), j) {
            auto e = E[j];
            if (dist2[e.v] > dist2[e.u] + e.cost) {
                dist2[e.v] = dist2[e.u] + e.cost;
            }
        }
    }
    if (dist2[n - 1] != dist[n - 1]) {
        cout << - 1 << endl;
    } else {
        cout << max(0, -dist[n - 1]) << endl;
    }
    return 0;
}



Measured memory_bytes: 384