akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define PI  3.14159265358979323846

ll gcd(ll a,ll b)
{
    if(a==0)
        return b;
    else
        return gcd(b%a,a);
}
ll fast(ll n,ll a,ll m)
{
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
    {
        ll res=fast(n/2,a,m)%m;
        if(n%2==0)
            return (((res%m)*(res%m))%m);
        else
            return (((((res%m)*a)%m)*res)%m);
    }
}
ll lcm(ll x,ll y)
{
    ll P=x*y;
    P/=gcd(x,y);
    return P;
}
int main()
{
    ll n,i;
    cin>>n;
    ll fac[n+1];
    fac[0]=1;
    for(i=1;i<=n;i++)
    {
        fac[i]=fac[i-1]*i;
    }
    ll P[n],Q[n];
    for(i=0;i<n;i++)
    {
        cin>>P[i];
    }
    for(i=0;i<n;i++)
    {
        cin>>Q[i];
    }
    ll b[n+1]={0},c[n+1]={0};
    ll a1=0,a2=0;
    for(i=0;i<n;i++)
    {
        ll f=0;
        for(ll j=1;j<=P[i]-1;j++)
        {
            if(b[j]==1)
            {
                f++;
            }
        }
        ll K=P[i]-1;
        K-=f;
        a1+=K*fac[n-i-1];
        b[P[i]]=1;
    }

    for(i=0;i<n;i++)
    {
        ll f=0;
        for(ll j=1;j<=Q[i]-1;j++)
        {
            if(c[j]==1)
            {
                f++;
            }
        }
        ll K=Q[i]-1;
        K-=f;
        a2+=K*fac[n-i-1];
        c[Q[i]]=1;
    }
    cout<<abs(a1-a2);

}




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


def main():
    n = int(input().strip())
    S = input().strip()
    query_table = [0] * (n+1)
    for i, s in enumerate(S):
        if s == "#":
            query_table[i + 1] = query_table[i] + 1
        else:
            query_table[i + 1] = query_table[i]
    ans = float("inf")

    for ptr in range(n+1):
        # left side
        left_black = query_table[ptr]
        left_white = ptr - left_black

        # right side
        right_black = query_table[n] - left_black
        right_white = n - ptr - right_black
        ans = min(ans, left_black+right_white)

    print(ans)

    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 75208
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void)
{
    int N;
    cin >> N;
    vector<int> a;
    int tmp;
    for (int i = 0; i < N; i++)
    {
        cin >> tmp;
        a.push_back(tmp);
    }
    bool f = true;
    int count = 0;
    for (int i = 0; i < N; i++)
    {
        if (a[i] % 2 == 1)
        {
            f = false;
        }
    }
    if (f == true)
    {
        while (f == true)
        {
            for (int i = 0; i < N; i++)
            {
                a[i] /= 2;
                if (a[i] % 2 == 1)
                {
                    f = false;
                }
            }
            count++;
        }
        cout << count << endl;
    }
    else
    {
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define lli long long int
int main(){
  lli a,b,k;
  cin>>a>>b>>k;
  if(k<=a)
    cout<<a-k<<" "<<b;
  else if(k<=a+b)
    cout<<"0"<<" "<<b-(k-a);
  else
    cout<<"0"<<" "<<"0";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include<algorithm>
using namespace std;
int a[810];
int main()
{
    int n,iwa=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin >>a[i];
    }
    sort(a,a+n);
    for(int i=0;i<n;i++){
        if((n-1-i)%2==0){iwa+=a[i];}
        else{iwa-=a[i];}
    }
    cout<<iwa<<endl;
}



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

int main(){
    int N, M;
    cin >> N >> M;
    int x, y, z;
    vector<int> edge[N+1];
    rep(i, M){
        cin >> x >> y >> z;
        edge[x].push_back(y);
        edge[y].push_back(x);
    }
    bool a[N+1], check[N+1];
    fill_n(a, N+1, true);
    fill_n(check, N+1, true);
    int count = 0;
    queue<int> que;
    rep2(i, 1, N+1){
        if(a[i]){
            count++;
            que.push(i);
            while(!que.empty()){
                int j = que.front();
                check[j] = false;
                que.pop();
                rep(k, edge[j].size()){
                    int l = edge[j][k];
                    if(check[l]){
                        que.push(l);
                        a[l] = false;
                    }
                }
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 6776
#include <bits/stdc++.h>
#define X first
#define Y second

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;

const ll INF = 2e18;
const int inf = 1e9+10;
const int maxN = 2e5+10;
const int maxD = 15;
const int maxH = 100; 
const int MOD = 998244353;


int main()
{
	char x;
	scanf(" %c",&x);
	if(x>='a' && x<='z')
	{
		puts("a");
	}
	else
	{
		puts("A");
	}
	return 0;
}

Measured memory_bytes: 3656
N,K,Q=gets.split.map(&:to_i)
qs=Q.times.map{gets.to_i}
ps=Array.new(N+1,0)
for i in 0..Q-1
    ps[qs[i]]+=1
end
ps.map!{|e|K-Q+e}
for i in 1..N
    puts ps[i]<=0 ? "No" : "Yes"
end


Measured memory_bytes: 4988
#include<stdio.h>

int main() {
	int a, b,m = 0;
	char n;

	scanf("%d %c %d", &a, &n, &b);

	if (n=='+') {
		printf("%d",a+b);
	}
	if(n=='-') {
		printf("%d", a - b);
	}


	return 0;
}

Measured memory_bytes: 128
n=list(map(int,input().split()))
Y=list(map(int,input().split()))
P=[i for i in Y if i>=0]
M=[i*-1 for i in Y if i<0]
#P,M==[]時のerror処理として大きな数を追加
if P==[]:
    P.append(max(M)*1000)
if M==[]:
    M.append(max(P)*1000)
p=sorted(P)
m=sorted(M)
L1=[]
L2=[]
#Index　out of range はあらかじめifで範囲を超えないようにしておく
for i in range(n[1]):
    if n[1]-i-2<len(m) and i<len(p):
        L1.append(p[i]+m[n[1]-i-2]*2)
        L2.append(p[i]*2+m[n[1]-i-2])
if len(p)>=n[1]:
    L1.append(p[n[1]-1])
if len(m)>=n[1]:
    L2.append(m[n[1]-1])
print(min(min(L1),min(L2)))

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

int main () {
  vector<char> line(19) ;
  
  for ( int i = 0 ; i < 19 ; i++ ){
    cin >> line.at(i) ;
  }
  
  line.at(5) = ' ' ;
  line.at(13) = ' ' ;
  
  for (int  i = 0 ; i < 19 ; i++ ) {
    cout << line.at(i) ;
  }
}

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

int main(){
	int N, i;
	string S;
	scanf("%d", &N);
	cin >> S;
	if(N % 2 == 1){
		printf("No\n");
		return 0;
	}
	for(i = 0; i < N / 2; i++){
		if(S[i] != S[i + N / 2]){
			printf("No\n");
			return 0;
		}
	}printf("Yes\n");
	return 0;
}

Measured memory_bytes: 384
N= int(input())
A= list(map(int,input().split()))

A = sorted(A)

if A[0] == 0:
  print(0)
else:
  S = 1
  for n in range(N):
    S *= A[N-1-n]
    if S > 10**18:
      S = -1
      break
  print(S)


Measured memory_bytes: 21708
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

	in := func() int {
		sc.Scan()
		i, _ := strconv.Atoi(sc.Text())
		return i
	}

	n, x, t := in(), in(), in()

	q := n / x
	r := n % x

	time := q * t

	if r != 0 {
		time += t
	}

	fmt.Println(time)
}


Measured memory_bytes: 1808
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = Long.parseLong(sc.next());
		long b = Long.parseLong(sc.next());
		long c = Long.parseLong(sc.next());
		long d = Long.parseLong(sc.next());
		long cBaisuIndex = a / c;
		if (a % c != 0) {
			cBaisuIndex++;
		}
		long cMaxIndex = b / c + 1;

		long dBaisuIndex = a / d;
		if (a % d != 0) {
			dBaisuIndex++;
		}
		long dMaxIndex = b / d + 1;
		long koyakusu = 0;
		koyakusu = getMaxKoyakusu(c, d);
		long cdBaisuIndex = a / koyakusu;
		if (a % koyakusu != 0) {
			cdBaisuIndex++;
		}
		long cdMaxIndex = b / koyakusu + 1;
		long ab = b - a + 1;
		long ret = ab - (cMaxIndex - cBaisuIndex) - (dMaxIndex - dBaisuIndex) + (cdMaxIndex - cdBaisuIndex);
		System.out.print(ret);
	}

	public static long getMaxKoyakusu(long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while ((temp = (long) a % b) != 0) {
			a = b;
			b = (long) temp;
		}
		return (long) (c / b);
	}
}


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

int main(){
  int N;
  cin >> N;
  vector<int> tako(N);
  for(int i=0;i<N;i++){
    cin >> tako.at(i);
  }
  
  vector<int> kaifuku(N*(N-1)/2);
  int count = 0;
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      kaifuku.at(count) = tako.at(i) * tako.at(j);
      count += 1;
    }
  }
  
  int sum = 0;
  for(int i=0;i<kaifuku.size();i++){
    sum += kaifuku.at(i);
  }
  
  cout << sum << endl;
  
}

Measured memory_bytes: 256
# UnionFind

# 配列で、子のID番目:(親のID), 親のID番目:(その塊の-サイズ)
# Union Findを使う
class UnionFind:
    def __init__(self, size):
        self.parent_indexes = [-1] * size
        
    def find_parent(self, n):
#         print(self.parent_indexes[n])
        if self.parent_indexes[n] < 0:
            return n
#         print('hewe')
        # 探しているnodeが指し示しているのが現在の親ではない場合、
        # 現在の親に書き換え(memo化)た上で返す
        self.parent_indexes[n] = self.find_parent(self.parent_indexes[n])
        return self.parent_indexes[n] 
    
    def union(self, n1, n2):
        if self.same_group(n1, n2):
            return False
        
        # サイズの大きい方の親が親であり続ける
        if self.size(n1) >= self.size(n2):
            tmp = self.size(n2)
            self.parent_indexes[self.find_parent(n2)] = self.find_parent(n1)
            self.parent_indexes[self.find_parent(n1)] -= tmp
            return True
        
        tmp = self.size(n1)
        self.parent_indexes[self.find_parent(n1)] = self.find_parent(n2)
        self.parent_indexes[self.find_parent(n2)] -= tmp
        return True
        
    
    def size(self, n):
        return -self.parent_indexes[self.find_parent(n)]
    
    def same_group(self, n1, n2):
        return self.find_parent(n1) == self.find_parent(n2)



n, m = map(lambda x: int(x), input().split())
uf = UnionFind(n)

for _ in range(m):
    a, b = map(lambda x: int(x), input().split())
    uf.union(a-1, b-1)
    
print(-min(uf.parent_indexes))

Measured memory_bytes: 14872
unittest
{
	assert( [ "2 3 1 2" ].solve == "3.000000000 0" );
	assert( [ "2 2 1 1" ].solve == "2.000000000 1" );
}



import std.conv;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto w = 0L;
	auto h = 0L;
	auto x = 0L;
	auto y = 0L;
	input.front.formattedRead!"%s %s %s %s"( w, h, x, y );
	
	// 二等分になるように切るのが一番大きくなる
	// 点が中心にないなら切り方は一通り、中心にあるならどう切っても二等分になる
	return format( "%0.9f %d", w * h / 2.0L, ( x == w / 2.0L ) && ( y == h / 2.0L ) );
}


Measured memory_bytes: 3016
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int64_t N, sum = 0, ans = 1000000000000000;
    cin >> N;
    vector<int64_t> A(N);
    for (int i = 0; i < N; i++) {
        if (i == 0) {
            cin >> A.at(i);
            sum += A.at(i);
            continue;
        }
        int a;
        cin >> a;
        sum += a;
        A.at(i) = A.at(i - 1) + a;
    }
    for (int i = 0; i < N - 1; i++) {
        ans = min(ans, abs(sum - 2 * A.at(i)));
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<cstdlib>
#include<iostream>
#include<complex>
#include<math.h>
#include<string>
#include<sstream>

using namespace std;

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

    int v[N];

    for (int i = 0; i < N; i++){
        cin >> v[i];
        if(i>0){
            for(int j = 1; j < i+1; j++){
                if(v[i-j] > v[i-j+1]){
                    int a,b;
                    a=v[i-j];
                    b=v[i-j+1];
                    v[i-j]=b;
                    v[i-j+1]=a;
                }
                else{
                    break;
                }
            }
        }
    }
    

    double ans = v[0]*pow(0.5,N-1);
    for (int i = 0; i < N-1; i++){
        ans += v[i+1]*pow(0.5,N-i-1);
    }
    cout << ans <<endl;
    
    return 0;

}

Measured memory_bytes: 256
n = int(input())
D = [list(map(int, input().split())) for _ in range(n)]
for i in range(n-2):
    if D[i][0] == D[i][1] and D[i+1][0] == D[i+1][1] and D[i+2][0] == D[i+2][1]:
        print("Yes")
        exit()
print("No")

Measured memory_bytes: 9192
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int N,K,x;
  int64_t sum=0;
  cin>>N>>K;
  priority_queue<int> H(N,0);
  for(int i=0;i<N;i++)
  {
    cin>>x;
    H.push(x);
    sum+=x;
  }
  for(int j=0;j<K;j++)
  {
    sum-=H.top();
    H.pop();
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 1792
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    Int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;

    Int resSugarWater = 0, resSugar = 0;
    double maxDensity = 0.0;

    for(Int a = 0; 100*A*a <= F; ++a) {
        for(Int b = 0; 100*A*a+100*B*b <= F; ++b) {
            for(Int c = 0; 100*A*a+100*B*b+C*c <= F; ++c) {
                for(Int d = 0; 100*A*a+100*B*b+C*c+D*d <= F; ++d) {
                    Int mWater = 100*A*a + 100*B*b;
                    Int mSugar = C*c + D*d;
                    if (mSugar > E*mWater/100 or (mWater+mSugar) == 0) continue;

                    double density = (double)mSugar/(double)(mWater+mSugar);
                    if (density >= maxDensity) {
                        maxDensity = density;
                        resSugarWater = mWater+mSugar;
                        resSugar = C*c+D*d;
                    }
                }
            }
        }
    }

    cout << resSugarWater << " " << resSugar << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>

using namespace std;

struct Comp
{
	bool operator()(const pair<int, int>& a, const pair<int, int>& b) const
	{
		if (a.first - a.second <= 0 && b.first - b.second <= 0) {
			return a.first < b.first;
		}
		else if (a.first - a.second > 0 && b.first - b.second > 0) {
			return a.second > b.second;
		}
		return a.first - a.second <= 0;
	}
};

int main()
{
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	int left = 0, right = 0;
	vector<pair<int, int>> mid;
	for (int i = 0; i < n; i++) {
		string t;
		cin >> t;
		int a = 0;
		int c = 0;
		for (int j = 0; j < t.size(); j++) {
			if (t[j] == '(') {
				c++;
			}
			else {
				c--;
				if (c < 0) {
					a++;
					c = 0;
				}
			}
		}
		if (a == 0) {
			left += c;
		}
		else if (c == 0) {
			right += a;
		}
		else {
			mid.push_back({ a, c });
		}
	}

	sort(mid.begin(), mid.end(), Comp());

	int cur = left;
	for (int i = 0; i < mid.size(); i++) {
		cur -= mid[i].first;
		if (cur < 0) {
			cout << "No" << endl;
			return 0;
		}
		cur += mid[i].second;
	}

	if (cur != right) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	return 0;
}



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

n = int(input())
li = [list(map(int,input().split())) for _ in range(n)]

li.sort(key = lambda x: x[1])

time = 0

for i,j in li:
    time += i
    if time > j:
        print('No')
        exit()

print('Yes')


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

int n;
vector<int> h;
vector<int> DP;

int main()
{
	cin >> n;
	h.resize(n + 1);
	for (int i = 1; i < n+1; i++)
		cin >> h[i];

	DP.resize(n + 1);

	// can reach n, n+1; DP[n] = 0
	DP[n] = 0;
	DP[n - 1] = abs(h[n] - h[n - 1]);
	for (int i = n - 2; i >= 1; i--)
	{
		DP[i] = min(DP[i + 2] + abs(h[i + 2] - h[i]), DP[i + 1] + abs(h[i + 1] - h[i]));
	}
	cout << DP[1] << endl;
}

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

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

  int n;
  cin >> n;
  vector<int> b(n - 1);
  rep(i, 0, n - 1) cin >> b[i];

  ll ans = b[0] + b[b.size() - 1];
  rep(i, 1, n - 1) ans += min(b[i], b[i - 1]);

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define pi 3.14159265358979323846264338
using namespace std;

int main() {
	int n;
	cin >> n;
	set<int> a;
	int j;
	for (int i = 0; i < n; i++) {
		cin >> j;
		a.insert(j);
	}
	if ((n - a.size()) % 2 != 0) {
		cout << a.size() - 1 << endl;
	}
	else {
		cout << a.size() << endl;
	}
	return 0;
}

Measured memory_bytes: 4864
#include <iostream>
#include <cstring>
#include <cmath> 
#include <algorithm>

using namespace std;

const int maxn=1e5+10;
int n,m,va;
unsigned long long w[maxn],v[maxn],f[maxn];

int main()
{
	memset(f,0x3f,sizeof(f));
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>w[i]>>v[i];
		va+=v[i];
	}
	f[0]=0;
	for(int j=n;j>=1;j--)
    {
	    for(int i=va;i>=v[j];i--)
	    {
		    if(i-v[j]>=0)
		    {
		    	f[i]=min(f[i],f[i-v[j]]+w[j]);
			}
	    }
    }
//    for(int i=1;i<=m;i++)
//    {
//    	cout<<f[i]<<" ";
//	}
//	cout<<endl; 
	for(int i=va;i>=0;i--)
	{
		if(f[i]<=m)
		{
			cout<<i<<endl;
			return 0;
		}
	}
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long ll;

inline void up(int &x, int y) { x < y ? x = y : 0; }
inline void down(int &x, int y) { x > y ? x = y : 0; }

int main() {
	int a, l, r;
	std::cin >> a >> l >> r;
	if ((r / a) == ((l - 1) / a)) puts("NG");
	else puts("OK");
	return 0;
}










Measured memory_bytes: 3648
#include<cstdio>
#include<cstring>
#include<algorithm>

struct Node
{
	int key;
	Node *next, *prev;
};

Node *nil;

Node* listSearch(int key)
{
	Node *cur = nil->next;
	while (cur != nil && cur->key != key)
	{
		cur = cur->next;
	}
	return cur;
}

void init()
{
	nil = new Node;
	nil->next = nil;
	nil->prev = nil;
}

void printList()
{
	Node *cur = nil->next;
	int isf = 0;
	while (true)
	{
		if (cur == nil)
		{
			break;
		}
		if (isf++ > 0)
		{
			printf(" ");
		}
		printf("%d", cur->key);
		cur = cur->next;
	}
	printf("\n");
}

void deleteNode(Node *t)
{
	if (t == nil) return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	delete t;
}

void deleteFirst()
{
	deleteNode(nil->next);
}

void deleteLast()
{
	deleteNode(nil->prev);
}

void deleteKey(int key)
{
	deleteNode(listSearch(key));
}

void insert(int key)
{
	Node *x = new Node;
	x->key = key;
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}

int main()
{
	int key, n;
	int size = 0;
	char com[20];
	int np = 0, nd = 0;
	scanf("%d", &n);
	init();
	for (int i = 0; i < n; i++)
	{
		scanf("%s%d", com, &key);
		if (com[0] == 'i')
		{
			insert(key);
			np++;
			size++;
		}
		else if (com[0] == 'd')
		{
			if (strlen(com) > 6)
			{
				if (com[6] == 'F')
				{
					deleteFirst();
				}
				else if (com[6] == 'L')
				{
					deleteLast();
				}
			}
			else
			{
				deleteKey(key);
				nd++;
			}
			size--;
		}
	}
	printList();
}

Measured memory_bytes: 33812
#include<bits/stdc++.h>
using namespace std;
long long n,m,k,ans;
int main()
{
	scanf("%lld%lld%lld",&n,&m,&k);
	if(!m)
	{
		printf("0");
		return 0;
	}
	ans+=(n/(m+k))*m;
	ans+=min(n-(ans/m)*(m+k),m);
	printf("%lld",ans);
	return 0;
}

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

#define FOR(i,a,b)  for(ll (i)=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll (i)=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      (v).begin(),(v).end()
#define BIT(n)      (1LL<<(n))
#define IN(x,l,r)   ((l)<=(x)&&(x)<=(r))
#define SHOW(x)     cout<<#x<<" = "<<x<<endl
#define SORT(v)     sort(ALL(v))
#define SZ(v)       (ll)(v).size()
#define UNIQ(v)     SORT(v);(v).erase(unique(ALL(v)),(v).end())
#define PERM(v)     for(bool p=1;p;p=next_permutation(ALL(v)))
#define PQ(T)       priority_queue<T,vector<T>,greater<T>>

template<typename T>string join(const vector<T>& v, string d=" ")
{stringstream s;REP(i,SZ(v))s<<d<<v[i];return s.str().substr(d.length());}

template<typename T> ostream& operator<<(ostream& s, const vector<T>& v)
{if(SZ(v))s<<join(v,", ");return s;}

const ll INF = 1e15;
const ll MOD = 1e9+7;
const double EPS = 1e-10;

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

int main() {
    ll Q, H, S, D; cin >> Q >> H >> S >> D;
    ll N; cin >> N;
    
    ll ans = 0;
    if (N % 2 == 1) {
        ans += min({4 * Q, 2 * H, S});
        N--;
    }
    ans += (N / 2) * min({8 * Q, 4 * H, 2 * S, D});
    cout << ans << endl;
    
    return 0;
}


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

int main()
{
	int32_t N;
	char S[100000];
	scanf("%d %s", &N, S);

	int32_t res = 0;
	char prev = ' ';
	for (int32_t i = 0; i < N; i++) {
		if (prev != S[i])
			res++;
		prev = S[i];
	}

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

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<ll>>;
using P = pair<int,int>;
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; }

/*
有向閉路を持たないグラフなので
トポロジカルソートができる
それの最長経路をDPで求めるような問題
*/

int dp[100100];
ll N,M;
Graph G;

int rec(int v)
{
  //dp[v]:=ノードvを始点とした時のGの有効パスの長さの最大値
  if (dp[v]!=-1) return dp[v]; //すでに更新済
  
  int res=0;
  for (auto nv : G[v])
  {
    chmax(res, rec(nv)+1); 
  }
  return dp[v]=res;
}

int main()
{
  cin>>N>>M;
  G.assign(N,vector<ll>());
  for (int i=0;i<M;i++)
  {
    int x,y;cin>>x>>y;
    x--;y--;
    G[x].push_back(y);
  }
  
  //初期化
  for (int v=0;v<N;v++) dp[v]=-1;
  
  //全ノードを一通り更新しながら答えを求める
  int res=0;
  //v起点の最長経路の長さを求める
  for (int v=0;v<N;v++)
    chmax(res,rec(v));
  cout<<res<<endl;
}


Measured memory_bytes: 8192
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main (){
ll dp[105][100009]={0},wt[105],val[105];
ll n,w;
cin>>n>>w;
for(int i=1;i<=n;i++)
cin>>wt[i]>>val[i];

for(int i=1;i<=n;i++){
 for(int j=1;j<=w;j++){
 	if(j<wt[i])dp[i][j]=dp[i-1][j];
 	else dp[i][j]=max(dp[i-1][j-wt[i]]+val[i],dp[i-1][j]); 
 }	
}

cout<<dp[n][w]<<endl;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var swr = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(swr);
            var line = Console.ReadLine().Trim().Split(' ').Select(s => int.Parse(s)).ToArray();
            var line2 = Console.ReadLine().Trim().Split(' ').Select(s => int.Parse(s)).ToArray();
            int M1 = line[0];
            int D1 = line[1];
            int M2 = line2[0];
            int D2 = line2[1];
            int ans = 0;
            if (M1 + 1 == M2)
            {
                ans = 1;
            }
            Console.WriteLine(ans);
            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 13396
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * 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;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int[] a = in.nextIntArray(3);
            Arrays.sort(a);
            out.println(a[0] + a[1] + 10 * a[2]);
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

        public String nextString() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public int[] nextIntArray(int n) {
            int[] res = new int[n];
            for (int i = 0; i < n; i++) {
                res[i] = nextInt();
            }
            return res;
        }

    }
}



Measured memory_bytes: 21460
#include <stdio.h>

int d[9],c[9];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++)scanf("%d%d",d+i,c+i);
	int l,r;
	if(n==1)l=0,r=10;
	if(n==2)l=10,r=100;
	if(n==3)l=100,r=1000;
	
	for(int x=l;x<r;x++){
		char s[9];
		sprintf(s,"%d",x);
		int flag=1;
		for(int i=0;i<m;i++)flag&=s[d[i]-1]-'0'==c[i];
		if(flag){
			printf("%d",x);
			return 0;
		}
	}
	puts("-1");
}

Measured memory_bytes: 1736
# C
n = int(input())
h = list(map(int,input().split()))
flg = True

for i in range(n-2,-1,-1):
    if h[i] > h[i+1]:
        h[i] -= 1
        
        if h[i] > h[i+1]:
            flg = False
            break
    
if flg:
    print('Yes')
    
else:
    print('No')

Measured memory_bytes: 14396
import copy

n = int(input())
a = list(map(int, input().split()))

max_a = max(a)


def gcd(n, m):
    if m == 0:
        return n
    
    return gcd(m, n % m)


# 事前処理
# あらかじめ、左端からi個でgcdを計算しておく
# 同様に右からも
l = [0] * n
r = [0] * n

l[0] = a[0]
r[-1] = a[-1]

for i in range(0, n-1):
    l[i+1] = gcd(l[i], a[i+1])

for i in range(n-1, 0, -1):
    r[i-1] = gcd(r[i], a[i-1])


tmp = 0
ans = 0

for i in range(n):
    if i == 0:
        tmp = r[i+1]
    elif i == n-1:
        tmp = l[i-1]
    else:
        tmp = gcd(l[i-1], r[i+1])
    
    ans = max(ans, tmp)

print(ans)

Measured memory_bytes: 14848
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
#define pi acos(-1.0)

int main()
{
    ll i, j, n, m, cnt = 0;
    string s;
    cin >> s;
    for(i = 0, j = s.size() - 1; i < j; )
    {
        if(s[i] != s[j]){
            cnt++;
        }
        i++;
        j--;
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int N;
	cin >> N;
	int min_num = INF32;
	vector<int> data(N);

	for (int i = 0; i < N; i++)
	{
		cin >> data[i];
	}
	for (int i = 0; i <= 100; i++)
	{

		int sum = 0;
		for (int j = 0; j < N; j++)
		{
			sum += (data[j] - i) * (data[j] - i);
		}
		min_num = min(min_num, sum);
	}

	cout << min_num << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#define MAX 100000
#define NIL -1

struct Node
{
	int p, left, right;
};

Node T[MAX];
int  D[MAX];

// 節点uの子をカンマ区切りで出力(2, 3, 0)
void printChildren(int u)
{
	int c = T[u].left;
	int isf = 0;
	while (c != NIL)
	{
		if (isf++ > 0) std::cout << ", ";
		std::cout << c;
		c = T[c].right;
	}
}

void print(int u)
{
	std::cout << "node " << u << ": ";
	std::cout << "parent = " << T[u].p << ", ";
	std::cout << "depth = " << D[u] << ", ";

	if (T[u].p == NIL)std::cout << "root, ";
	else if (T[u].left == NIL)std::cout << "leaf, ";
	else std::cout << "internal node, ";

	std::cout << "[";
	printChildren(u);
	std::cout << "]" << std::endl;
}

void setDepth(int u, int d)
{
	D[u] = d;
	if (T[u].left  != NIL) setDepth(T[u].left, d + 1);
	if (T[u].right != NIL) setDepth(T[u].right, d);
}

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

	for (int i = 0; i < n; i++)
	{
		T[i].p = NIL;
		T[i].left = NIL;
		T[i].right = NIL;
	}

	int p, k, c, l;
	for (int i = 0; i < n; i++)
	{
		std::cin >> p >> k;
		for (int j = 0; j < k; j++)
		{
			std::cin >> c;
			if (j == 0)
			{
				T[p].left = c;
			}
			else
			{
				T[l].right = c;
			}
			T[c].p = p;
			l = c;
		}
	}

	int root;
	for (int i = 0; i < n; i++)
	{
		if (T[i].p == NIL)root = i;
	}
	setDepth(root, 0);

	for (int i = 0; i < n; i++)
	{
		print(i);
	}
}


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n - 1);
  for (int i = 0; i < n; i++) { cin >> b[i]; }
  a[0] = b[0];
  a[n - 1] = b[n - 2];
  for (int i = 1; i < n - 1; i++) {
    a[i] = min(b[i - 1], b[i]);
  }
  cout << accumulate(a.begin(), a.end(), 0) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
const ll INF = 1LL<<60;
typedef pair<ll, ll> P;

int main() {
    cin>>N;
    long double pi = 3.1415926;
    cout<<fixed<<setprecision(10)<<pi * N * 2<<endl;
}


Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int a, b;
  cin >> a >> b;

  if (a >= 13) {
    cout << b << endl;
  } else if (a >= 6) {
    cout << b / 2 << endl;
  } else {
    cout << 0 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
	string s;
	cin>>s;
	int ans=0,sz=2;
	for(int i=0;i<s.size();i++){
		if(sz==2){
			ans++;
			sz=1;
		}
		else{
			if(s[i]==s[i-1]){
				i++;
				if(i>=s.size()){
					break;
				}
				ans++;
				sz=2;
			}
			else{
				ans++;
				sz=1;
			}
		}
	}
	cout<<ans<<endl;
	return(0);
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, M, L;
cin >> N >> M >> L;  
long long int A[N][M] = {0};
long long int B[M][L] = {0}; 
long long int C[N][L] = {0}; 

for (int i = 0; i < N; i++){
  for (int j = 0; j < M; j++){
cin >> A[i][j]; 
}
}
for (int i = 0; i < M; i++){
  for (int j = 0; j < L; j++){
cin >> B[i][j]; 
}
}
for(int i = 0; i < N; i++){
  for(int j = 0; j < L; j++){
      long long int S = 0; 
   for(int k = 0; k < M; k++){
    S += A[i][k] * B[k][j]; 
}
  C[i][j] = S; 
}
}
for(int i = 0; i < N; i++){
  for(int j = 0; j < L; j++){
  if(j == 0) cout << C[i][0]; 
  else cout << " " << C[i][j];    
}
cout << endl; 
}
}


Measured memory_bytes: 3268
#include<stdio.h>
#include<algorithm>
using namespace std;
int s[110000];
int t[110000];
int p[110000];
pair<int,int>ev[210000];
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)scanf("%d%d",s+i,t+i);
	for(int i=0;i<b;i++)scanf("%d",p+i);
	p[b++]=0;
	p[b++]=1000000001;
	std::sort(p,p+b);
	int sz=0;
	long long ret=0;
	for(int i=0;i<a;i++){
		if(s[i]<t[i]){
			if(upper_bound(p,p+b,s[i])==upper_bound(p,p+b,t[i])){
				ret+=t[i]-s[i];
				continue;
			}
			int color=(upper_bound(p,p+b,s[i])-p)%2;
			ev[sz++]=make_pair(s[i],color+1);
			ev[sz++]=make_pair(t[i],-color-1);
		}
		if(t[i]<s[i]){
			if(upper_bound(p,p+b,s[i])==upper_bound(p,p+b,t[i])){
				ret+=s[i]-t[i];
				continue;
			}
			int color=(upper_bound(p,p+b,s[i])-p)%2;
			ev[sz++]=make_pair(t[i],color+1);
			ev[sz++]=make_pair(s[i],-color-1);
		}
	}
	std::sort(ev,ev+sz);
	int at=0;
	int v1=0;
	int v0=0;
	for(int i=0;i<sz;i++){
		//printf("%d %d\n",ev[i].first,ev[i].second);
		while(at<b&&ev[i].first>p[at]){
			if(at>0){
				if(at%2)ret+=(long long)v1*(p[at]-p[at-1]);
				else ret+=(long long)v0*(p[at]-p[at-1]);
			}
			at++;
		}
		int ind=at;
		if(ev[i].second>0){
			if(ev[i].second==2){
				v1++;
				if(ind%2==1)ret-=ev[i].first-p[ind-1];
			}else{
				v0++;
				if(ind%2==0)ret-=ev[i].first-p[ind-1];
			}
	//		ret+=(*upper_bound(p,p+b,ev[i].first))-ev[i].first;
		}else{
			if(ev[i].second==-2){
				v1--;
				if(ind%2==1)ret+=ev[i].first-p[ind-1];
			}else{
				v0--;
				if(ind%2==0)ret+=ev[i].first-p[ind-1];
			}
	//		ret+=ev[i].first-(*(upper_bound(p,p+b,ev[i].first)-1));
		}
	}
	printf("%lld\n",ret);
}

Measured memory_bytes: 3860
#include <bits/stdc++.h>
#include <iostream>
typedef long long ll;
#define rep(i,a,b) for(ll i =a ;i <= b;i++)
#define per(i,a,b) for(ll i =a ;i >= b;i--)
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
 


int main()
{
	//ifstream cin("input.txt");
	int n;
	int sum = 0;
	int mx = 0;
	rep(i,0,4){
		cin>>n;
		if(n%10 != 0){
			sum += n + (10 - n%10);
			mx = max(10 - n%10, mx);
		}
		else
			sum +=n;
		
	}
	cout<< sum - mx;
	
	

}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int ms =41;
int dp[41][1000][1000];
int vet[41][3];
int n;
double ma,mb;

int solve(int id, int A, int B){
	
	if(A and B and (A*mb == B*ma))
		return 0;
	if(id == n)
		return inf;
		
	int &ans = dp[id][A][B];
	if(ans!=-1)
		return ans;
	ans = min(solve(id+1,A,B), vet[id][2] + solve(id+1,A+vet[id][0
	],B+vet[id][1]));
	
	return ans;

}


int main(){
	cin >> n >> ma >> mb;
	for(int i = 0;i<n;i++)
		cin >> vet[i][0]>>vet[i][1] >> vet[i][2];
	memset(dp, -1, sizeof(dp));
	
	int ans = solve(0,0,0);
	if(ans == inf)
		cout<<"-1";
	else
		cout<<ans;
}

Measured memory_bytes: 160384
import sys
input = sys.stdin.readline
p=int(input())
A=[int(i) for i in input().split()]
B=[0]*p
for i in range(p):
  a,c=A[i],1
  B[0]-=a
  for j in range(1,p):
    c=c*i%p
    B[j]-=a*c
    if j==p-1:
      B[j]+=a
B=B[::-1]
for i in range(p):
  B[i]=B[i]%p
print(*B)


Measured memory_bytes: 43996
#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
    string s;
    cin >> s;
    
    if(s == "RRS" || s == "SRR"){
        cout << 2 << endl;
    }

    else if(s == "RRR"){
        cout << 3 << endl;
    }

    
    else if(s == "SSS"){
        cout << 0 << endl;
    }

    else cout << 1 << endl;
}

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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

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

  LL x,a;
  cin >> x >> a;
  if(x<a){
    cout << 0 << endl;
  }else{
    cout << 10 << endl;
  }
}


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

using namespace std;
enum Status{
  NotExplore = 0,
  Exploring,
  Explored,
};

vector<vector<int> > tree(100000);
vector<Status> nodeStatus(100000);
vector<pair<int, int> > ans;

/// deep first search
int dfs (int currentNode, int parentNode)
{
  int isOdd = 0;
  nodeStatus[currentNode] = Status::Exploring;
  
  for (auto childNode : tree[currentNode]) {
    if (parentNode == childNode) continue;
    if (nodeStatus[childNode] == Status::Explored) continue;
    if (nodeStatus[childNode] == Status::Exploring) {
      isOdd ^= 1;
      ans.push_back({currentNode, childNode});
    }
    if (nodeStatus[childNode] == Status::NotExplore) {
      if (dfs(childNode, currentNode)) {
        ans.push_back({childNode, currentNode});
      } else {
        isOdd ^= 1;
        ans.push_back({currentNode, childNode});
      }
    }
  }

  nodeStatus[currentNode] = Status::Explored;
  return isOdd;
}

int main()
{
  int N, M; cin >> N >> M;
  
  for (int i=0; i<M; i++) {
    int a, b; cin >> a >> b;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  
  if (dfs(1, 0)) {
    cout << -1 << endl;
  } else {
    for (auto p : ans) {
      cout << p.first << " " << p.second << endl;
    }
  }

}


Measured memory_bytes: 17524
#include <iostream>

int main()
{
	int n;
	std::cin >> n;
	
	int prev_a = 0;
	int a;
	long long step = 0;
	for (int i = 0; i < n; i++) {
		std::cin >> a;
		if (a < prev_a) {
			step += prev_a - a;
		}
		else {
			prev_a = a;
		}
	}
	
	std::cout << step << std::endl;
	
	return 0;
}


Measured memory_bytes: 3188
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
#define ll long long

const int maxn=1e5+10;
const ll mod=1e9+7;
const double eps=1e-8;

ll f[110][maxn],add[maxn],cnt[maxn];

int main()
{
    ll n,siz,mid,mmid,l,r,i,j,g=0,sum=0;
    scanf("%lld%lld",&siz,&n);
    mmid=sqrt(siz+eps);
    mid=siz/(mmid+1);
    g=0;
    for (l=1;l<=siz;l=r+1)
    {
        ///[l,r]
        r=siz/(siz/l);
//        printf("%lld %lld %lld\n",l,r,siz/l);
        if (siz/l<=mid)
            cnt[siz/l]=r-l+1;
    }

    for (j=1;j<=mmid;j++)
        f[1][j]=1;
    for (i=2;i<=n;i++)
    {
        g=0;
        for (j=1;j<=mmid;j++)
            (g+=f[i-1][j])%=mod;
        for (j=1;j<=mmid;j++)
            f[i][j]=g;

        for (l=1;l<=mid;l++)
            add[l]=(add[l-1]+f[i-2][l])%mod;

        g=0;
        for (l=mid;l>=1;l--)
        {
            (g+=add[l]*cnt[l])%mod;
            (f[i][l]+=g)%=mod;
        }
    }


    for (j=1;j<=mmid;j++)
        (sum+=f[n][j])%mod;
    for (l=1;l<=mid;l++)
    {
        add[l]=(add[l-1]+f[n-1][l])%mod;
        (sum+=add[l]*cnt[l])%=mod;
    }

    ///
    memset(f,0,sizeof(f));
    g=0;
    for (l=mid;l>=1;l--)
    {
        (g+=cnt[l])%mod;
        f[1][l]=g;
    }
    n--;
    for (i=2;i<=n;i++)
    {
        g=0;
        for (j=1;j<=mmid;j++)
            (g+=f[i-1][j])%=mod;
        for (j=1;j<=mmid;j++)
            f[i][j]=g;

        for (l=1;l<=mid;l++)
            add[l]=(add[l-1]+f[i-2][l])%mod;

        g=0;
        for (l=mid;l>=1;l--)
        {
            (g+=add[l]*cnt[l])%mod;
            (f[i][l]+=g)%=mod;
        }
    }


    for (j=1;j<=mmid;j++)
        (sum+=f[n][j])%mod;
    for (l=1;l<=mid;l++)
    {
        add[l]=(add[l-1]+f[n-1][l])%mod;
        (sum+=add[l]*cnt[l])%=mod;
    }


    printf("%lld",sum);
    return 0;
}
/*
special
100=10*10

100 3
1 1 100
2 2 50
3 3 33
4 4 25
5 5 20
6 6 16
7 7 14
8 8 12
9 9 11
10 10 10
///
11 11 9
12 12 8
13 14 7
15 16 6
17 20 5
21 25 4
26 33 3
34 50 2
51 100 1


23 3
1 1 23
2 2 11
3 3 7
4 4 5
///
5 5 4
6 7 3
8 11 2
12 23 1


31622*log(n) *100

10 5
1 1 10
2 2 5
3 3 3

4 5 2
6 10 1

*/


Measured memory_bytes: 86656
x,k,d=map(int,input().split())
if x==0:
    if k%2==0:
        ans=0
    else:
        ans=d
else:
    if x<0:
        x=-x

    if x-k*d>=x%d:
        ans=x-k*d
    else:
        y=x//d
        if (k-y)%2==0:
            ans=x-d*y
        else:
            ans=abs(x-d*(y+1))


print(ans)

Measured memory_bytes: 9188
n,k = map(int,input().split())
mod = 10**9+7
ans = 0

kosu = [0 for i in range(k+1)]

for i in range(k, 0, -1):
    kin = 1  ## kosuに入れる数
    nn = k//i    ## iの倍数が何個あるかを計算する
    ii = n
    kini = nn
    while ii > 0:
        if ii%2 == 1:
            kin = (kin*kini)%mod
        kini = (kini**2)%mod
        ii //= 2
    for j in range(2,nn+1):
        kin = (kin-kosu[j*i])%mod
    kosu[i] = kin

for i in range(1,k+1):
    ans = (ans+(kosu[i]*i)%mod)%mod

print(ans)


Measured memory_bytes: 11400
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int hate[10];

bool check(int n) {
	while (n > 0) {
		if (hate[n % 10]) {
			return false;
		}
		n /= 10;
	}

	return true;
}

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

	for (int i = 0; i < n; i++) {
		int buf; cin >> buf;

		hate[buf] = 1;
	}

	for (int i = n; n < 99999; i++) {
		
		if (check(i)) {
			cout << i << endl;
			return 0;
		}
	}

	return 0;
}

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

using namespace std;

int main()
{
    int n;
    scanf("%d", &n);

    double taxRate = 1.08;

    int div = ceil(n / taxRate);
    int match = floor(div * taxRate);
    if(match == n)
    {
        printf("%d\n", div);
    }
    else
        printf(":(\n");
    return 0;
}


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

int main() {

  long long int n, p;

  while( true ) {

    cin >> n >> p;

    if ( n == 0 ) break;

    long long int num[50] = {0};

    long long int cnt = 0;

    long long int m = p;

    while( true ) {

      if ( m > 0 ) {
	m--;
	num[cnt]++;
	if ( num[cnt] == p ) break;
      }else {
	m = num[cnt];
	num[cnt] = 0;
      }
      cnt = ( cnt + 1 ) % n;

    }

    cout << cnt << endl;

  }

  return 0;

}

Measured memory_bytes: 1156
import sys
import numpy as np
input = sys.stdin.readline

def main():
    N, M, X = map(int, input().split())
    CA = np.array([np.array([int(v) for v in input().split()]) for _ in range(N)])

    def dp(i, a):
        if np.all(a>=X):
            return 0
        if i >= N:
            return -1
        purchased = dp(i + 1, a+CA[i][1:])
        unpurchased = dp(i + 1, a[:])
        if purchased != -1:
            purchased += CA[i][0]
            if unpurchased != -1:
                return min(purchased, unpurchased)
            else:
                return purchased
        else:
            return unpurchased
    
    print(dp(0, np.zeros(M, dtype=np.int32)))


if __name__ == '__main__':
    main()

Measured memory_bytes: 27380
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
using namespace std;

ll a,b,c,d,x,y;

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> a >> b >> c >> d;
    x = c/b;
    if( c%b!=0 ) x++;
    y = a/d;
    if( a%d!=0 ) y++;

    if( x <= y ){
        cout << "Yes";
    }else{
        cout << "No";
    }

    return 0;
}


Measured memory_bytes: 3612
from itertools import accumulate

N, C, *XV = map(int, open(0).read().split())

X = XV[::2] + [C]
A = [0] + list(accumulate(XV[1::2]))

ans = L = R = 0
for b in range(N + 1):
    T = A[N] - A[b]
    d = C - X[b]

    L = max(L, A[b] - X[b - 1])
    R = max(R, A[b] - 2 * X[b - 1])

    ans = max(ans, L + T - 2 * d, R + T - d)

print(ans)


Measured memory_bytes: 25588
#include <iostream>

using namespace std;

int main() {
    int N;
    cin >> N;
    int value[N];
    int cost[N];
    for (int i = 0; i < N; ++i) {
        cin >> value[i];
    }
    for (int i = 0; i < N; ++i) {
        cin >> cost[i];
    }
    int ans = 0;
    for (int j = 0; j < N; ++j) {
        if (value[j] - cost[j] > 0) {
            ans += value[j] - cost[j];
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
x, y = map(int, input().split())
ans = 0
if x == 1:
    ans += 300000
elif x == 2:
    ans += 200000
elif x == 3:
    ans += 100000
if y == 1:
    ans += 300000
elif y == 2:
    ans += 200000
elif y == 3:
    ans += 100000
if x == 1 and y == 1:
    ans += 400000
print(ans)


Measured memory_bytes: 38384
#include <iostream>
#include <fstream>
#include <set>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>
using namespace std;

bool is_palindrome(int x) {
    vector<int> digit;
    bool flag = true;
    while (x > 0) {
        digit.push_back(x % 10);
        x /= 10;
    }
    for (int i = 0; i < digit.size() / 2; i++) {
        if (digit.at(i) != digit.at(digit.size() - 1 - i)) {
            flag = false;
            break;
        }
    }
    return flag;
}

int main(int argc, const char * argv[]) {
    
    int A, B;
    cin >> A >> B;
    
    int cnt = 0;
    for (int i = A; i <= B; i++) {
        if (is_palindrome(i)) cnt++;
    }
    
    cout << cnt << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

int main()
{
	int N,Q;
	string S;

	cin >> N >> Q;
	cin >> S;

	int sum[100010]={};
	S="_"+S;
	for(int i=N;i>0;i--)
	{
		if(S[i-1]=='A' && S[i]=='C')
			sum[i]++;
	}
	for(int i=1;i<=N+1;i++)
	{
		sum[i]+=sum[i-1];
	}
	for(int i=0;i<Q;i++)
	{
		int l,r;
		cin >> l >> r;
		cout << sum[r]-sum[l] << endl;
	}
	return 0;
}



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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);

    int i;
    for (i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    
    sort(a.begin(),a.end(),greater<int>());

    int alice = 0,bob = 0;
    for (i = 0; i < n; i++)
    {
        if(i % 2 == 0)alice+=a[i];
        else bob += a[i];
    }
    
    cout << alice - bob << endl;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
A=['.' for _ in range(N)]
B=['.' for _ in range(M)]
for i in range(N):
    A[i]=list(input())
for i in range(M):
    B[i]=list(input())
Ans=False
for i in range(N-M+1):
    for j in range(N-M+1):
        tmp=True
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l]!=B[k][l]:
                    tmp=False
        if tmp==True:
            Ans=True
if Ans==True:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064