akhauriyash/Code-Regression huggingface dataset:
# 上位ノードほど @rank が大きい数字となる
class Node
  attr_accessor :parent, :rank

  # 親は自分自身、ランクは 0 として初期化する
  def initialize(n)
    @parent = n
    @rank = 0
  end
end

class UnionFind
  # 0 から n - 1 までのノードを初期化する
  def initialize(n)
    @nodes = (0...n).map { |i| Node.new(i) }
  end

  # 再帰で最も上位の親を探して更新し、その値を返す
  def root(x)
    return x if @nodes[x].parent == x
    root(@nodes[x].parent)
  end

  # a と b を仲間にする
  def unite(a, b)
    a_root = root(a)
    b_root = root(b)
    # a 及び b の親が同じ場合は何もしない
    return if a_root == b_root

    # a親ランク < b親ランク の場合は、b親をa親の親とする
    # なお、ランクをいじる必要はなし
    if @nodes[a_root].rank < @nodes[b_root].rank
      @nodes[a_root].parent = b_root
    # その他の場合は、a親をb親の親とする
    else
      @nodes[b_root].parent = a_root
    # a親、及びb親のランクが同じ場合は、a親のランクを +1 する
      @nodes[a_root].rank += 1 if @nodes[a_root].rank == @nodes[b_root].rank
    end
  end

  # a と b の最も上位の親が同じかどうかを返す
  def same?(a, b)
    root(a) == root(b)
  end

  # 各ノードの親を全て出力する確認用
  def parents
    @nodes.map(&:parent)
  end
  
  # 各ノードの最も上位の親を全て出力する確認用
  def roots
    @nodes.size.times.map { |i| root(i) }
  end
end

n, m = gets.split.map(&:to_i)
edges = []
m.times { edges << gets.split.map(&:to_i).map(&:pred) }

tree = UnionFind.new(n)

edges.each { |x, y| tree.unite(x, y) }

puts tree.roots.uniq.size


Measured memory_bytes: 19960
a, b = map(int, input().split())
snow = b - a
h = []
tmp = 0
for i in range(1,1000):
    tmp += i
    h.append(tmp)
x =[h[j+1] - h[j] for j in range(998)]
y = x.index(snow)
print(h[y] - a)

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

#define int long long
#define ll long long
#define f1(i,a,b) for(i=a;i<b;i++)
#define f2(i,a,b) for(i=a;i>=b;i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod=1000000007;
ll temp;
int n;
vector<pair<int,int>> a;

int checker(int p,int q)
{
	map<pair<int,int>, int> ap;
	int i;
	f1(i,0,n)
	{
		ap.insert(mp(a[i],1));
	}
	int ans=0;
	f1(i,0,n)
	{
		if(ap.find(mp(a[i].ff-p,a[i].ss-q))!=ap.end())
		{
			ans++;
		}
		//cout<<ans<<endl;
	}
	return n-ans;

}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // #ifndef ONLINE_JUDGE
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/in.txt","r",stdin);
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/out.txt","w",stdout);
    // #endif
    cin>>n;
    int i,j;
    f1(i,0,n)
    {
    	cin>>j>>temp;
    	a.pb(mp(j,temp));
    }
    int maxans=mod;
    f1(i,0,n)
    {
    	f1(j,0,n)
    	{
    		if(i!=j)
    		{
    			int p=a[i].ff-a[j].ff;
    			int q=a[i].ss-a[j].ss;
    			maxans=min(maxans,checker(p,q));
    		}
    	}
    }
    if(n==1)
    {
    	cout<<1;
    	return 0;
    }
    cout<<maxans;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace  std;
int main ()
{
	int n;
	int a[111];
	cin>>n;
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(i%2==0)continue;
		if(a[i]%2==1)ans++;
	}
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 3624
z[4000],*a=z,*b=z+2000,m,i,j;main(n){for(;scanf("%d",&n),i=n;printf("%d\n",m))for(memset(a,m=0,8e3);i--;j=a,a=b,b=j)for(j=n+1;j--;)m=fmax(m,b[j]=getchar()-46?0:1+fmin(fmin(b[j+1],a[j+1]),a[j]));}

Measured memory_bytes: 0
# AtCoder Beginner Contest 131
# C - Anti-Division
import math

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

A,B,C,D=map(int,input().split())
bc=B//C
ac=(A-1)//C
cnum=bc-ac

bd=B//D
ad=(A-1)//D
dnum=bd-ad


lcmcd=lcm(C,D)
blcmcd=B//lcmcd
alcmcd=(A-1)//lcmcd
lcmcdnum=blcmcd-alcmcd


print(B-A-cnum-dnum+lcmcdnum+1)


Measured memory_bytes: 9020
#include <iostream>

int main()
{
    using namespace std;
    int32_t W, a, b;
    cin >> W;
    cin >> a;
    cin >> b;
    
    int32_t diff;
    
    if (a > b && b+W-a < 0) {
        diff = abs(b+W-a);
    } else if (a < b && a+W-b < 0) {
        diff = abs(a+W-b);
    } else {
        diff = 0;
    }
    
    cout << diff << endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList<>();
		int num = scanner.nextInt();
		for (int i = 0; i < num; i++) {
			list.add(scanner.nextInt());
		}
		scanner.close();

		Collections.sort(list);
		int stock = 0;
		int count = 0;
		int stockNum = 0;
		for (int i : list) {
			if (stock != i) {
				stock = i;
				count = i;
			}
			count--;
			if (count == 0) {
				stockNum += stock;
			}
		}
		System.out.println(list.size() - stockNum);
	}
}


Measured memory_bytes: 50712
from collections import deque
def isMahojin(jin):
  sigma = sum(jin[0])
  for i in range(3):
    if sum(jin[i]) != sigma:
      return False
    if sum([jin[k][i] for k in range(3)]) != sigma:
      return False
  if sum([jin[i][i] for i in range(3)]) != sigma:
    return False
  if sum([jin[2-i][i] for i in range(3)]) != sigma:
    return False
  return True

jin = [[0]*3 for _ in range(3)]
jin[0][0] = int(raw_input())
jin[0][1] = int(raw_input())
jin[1][1] = int(raw_input())
s = 1
while True:
  jin[0][2] = s - jin[0][0]-jin[0][1]
  jin[2][2] = s - jin[0][0]-jin[1][1]
  jin[2][1] = s - jin[0][1]-jin[1][1]
  jin[1][2] = s - jin[0][2]-jin[2][2]
  jin[2][0] = s - jin[2][1]-jin[2][2]
  jin[1][0] = s - jin[0][0]-jin[2][0]
  if isMahojin(jin):
    break
  s += 1
for i in range(3):
    print jin[i][0],jin[i][1],jin[i][2]




Measured memory_bytes: 2936
#include <bits/stdc++.h>
#define len(x) (int) (x.size())
using namespace std;
typedef long long ll;

int main() {
    ll h, w, ans;
    cin >> h >> w;


    if (h == 1 || w == 1) {
        ans = 1;
    }
    else if (h % 2 == 1 && w % 2 == 1) {
        ans = (h*w) / 2 + 1;
    }
    else {
        ans = (h*w) / 2;
    }

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

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> ostream & operator<<(ostream & os, vector<T> const &);
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream & os, tuple<T...> const & t){ _ot<0>(os, t); return os; }
template<class T, class U> ostream & operator<<(ostream & os, pair<T,U> const & p){ return os << "(" << p.first << ", " << p.second << ") "; }
template<class T> ostream & operator<<(ostream & os, vector<T> const & v){ rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os; }
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<mt(__VA_ARGS__)<<" ["<<__LINE__<<"]"<<endl)
#else
#define dump(...)
#endif

int const inf = (1LL<<31)-1;
int const B = 1000;
struct RMQ {
    int n;
    vector<int> Bmin;
    vector<vector<int>> dat;
    RMQ(int n_){
        n = n_;
        if(n%B) n += B-n%B;
        dat.assign(n/B,vector<int>(B,inf));
        Bmin.assign(n/B,inf);
    }
    void set(int idx, int x){
        get(idx) = x;
        Bmin[idx/B] = inf;
        for(int i=0;i<B;i++) Bmin[idx/B] = min(Bmin[idx/B], get(idx/B*B+i));
    }
    int & get(int idx){
        return dat[idx/B][idx%B];
    }
    int rmq(int l, int r){
        int res = inf;
        if(l/B != r/B){
            while(l%B){
                res = min(res, get(l));
                l++;
            }
            while(r%B){
                r--;
                res = min(res, get(r));
            }
            while(l<r){
                res = min(res, Bmin[l/B]);
                l+=B;
            }
        } else {
            while(l<r){
                res = min(res, get(l));
                l++;
            }
        }
        return res;
    }
};

int main(){
    int n,q;
    cin >> n >> q;
    RMQ rmq(n);
    rep(i,q){
        int c, x, y;
        cin >> c >> x >> y;
        if(c) cout << rmq.rmq(x,y+1) << endl;
        else rmq.set(x,y);
    }
}

Measured memory_bytes: 1524
#include<stdio.h>

int a[101][101];
int d[101];
int pi[101];
char color[101];
int n,mincost,sumcost=0;

void prim(void);

int main(){
  int i,j;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&a[i][j]);
    }
  }

  prim();
 
  printf("%d\n",sumcost);

  return 0;
}

void prim(void){
  int i,j,u;
  for(i=0;i<n;i++){
    d[i]=2001;
    pi[i] = -1;
    color[i]='W';
  }
  d[0]=0;
  while(1){
    mincost = 2000000;
    for(i=0;i<n;i++){
      if(color[i]!='B' && d[i] < mincost){
	mincost = d[i];
        u = i;
      }
    }

    if(mincost==2000000) break;
    color[u]='B';
  
  for(i=0;i<n;i++){
    if(color[i]!='B' && a[u][i]!=-1 && a[u][i]<d[i]){
      pi[i] = u;
      d[i]=a[u][i];
     }
   }
  }
  for(i=1;i<n;i++){
    sumcost+=d[i];
  }
}

Measured memory_bytes: 640
#include <bits/stdc++.h> 
#define FOR(i,a,b) for(int i=(a);i<=(b);++i) 
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) 
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end() 
#define asn ans
using namespace std;
template <typename T> istream& operator >> (istream& is, vector<T>& vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;

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

int n;

vector<int> ans;

int gcd(int m, int n)
{
	if ((0 == m) || (0 == n))
		return 0;
	while (m != n)
	{
		if (m > n) m = m - n;
		else         n = n - m;
	}
	return m;
}

int main() {
	int a, x; CI a >> x;
	vector<int> n(a); CI n;
	int m = 1999999999;

	if (!(a == 1)) {
		int sa = abs(x - n[0]);
		REP(i, a - 1) {
			int tmp=gcd(sa, abs(n[i] - n[i + 1]));
			m = min(m, tmp);
		}
	}
	else m = min(m, abs(n[0] - x));

	CO m EN;

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <vector>
#include <sstream>
#include <unordered_map>

using namespace std;
typedef long long ll;


ll ans, mx, mn, flag, sum, cnt,cntr,cntg;

ll b[10000],g[10000],r[10000];
int main(){
	ll n;
	cin>>n;
	string s;
	cin>>s;
	for(ll i=n-1; i>=0; i--){
		if(s[i]=='B') cnt++;
		else if(s[i]=='R') cntr++;
		else cntg++;
		b[i]=cnt;
		r[i]=cntr;
		g[i]=cntg;
	}
	
	for(ll i=0; i<n; i++){
		for(ll j=i+1; j<n; j++){
			if(s[i]=='R'&&s[j]=='G'){
				ll flag=j+(j-i);
				if(flag<n && s[flag]=='B') ans+=b[j]-1;
				else ans+=b[j];
			}
			//RBG
			else if(s[i]=='R'&&s[j]=='B'){
				ll flag=j+(j-i);
				if(flag<n && s[flag]=='G') ans+=g[j]-1;
				else ans+=g[j];
			}
			//BRG
			else if(s[i]=='B'&&s[j]=='R'){
				ll flag=j+(j-i);
				if(flag<n && s[flag]=='G') ans+=g[j]-1;
				else ans+=g[j];
			}
			//BGR
			else if(s[i]=='B'&&s[j]=='G'){
				ll flag=j+(j-i);
				if(flag<n && s[flag]=='R') ans+=r[j]-1;
				else ans+=r[j];
			}
			//GBR
			else if(s[i]=='G'&&s[j]=='B'){
				ll flag=j+(j-i);
				if(flag<n && s[flag]=='R') ans+=r[j]-1;
				else ans+=r[j];
			}
			//GRB
			else if(s[i]=='G'&&s[j]=='R'){
				ll flag=j+(j-i);
				if(flag<n && s[flag]=='B') ans+=b[j]-1;
				else ans+=b[j];
			}
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3708
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

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

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

//-----------------------ここから-----------


int main(void){
    int n, k;

    cin >> n >> k;
    

    if(n >= k && n % k == 0){
        cout << 0 << endl;
    } else {
        cout << 1 << endl;
    }

}



Measured memory_bytes: 256
n,m = map(int, input().split())

#memorize current start and end
s_c,e_c = 1,n
for i in range(m):
    l,r = map(int,input().split())
    if l<s_c:
        if s_c<=r<e_c:
            e_c = r
        elif r<s_c:
            print(0)
            exit()
    elif s_c<=l<=e_c:
        s_c = l
        if r<e_c:
            e_c = r
    elif l>e_c:
        print(0)
        exit()
print(e_c-s_c+1)

Measured memory_bytes: 3064
PROGRAM ATCODER

implicit none
integer(8) :: k, a, b, c, k_zanki, all, i

read(*,*) k, a, b

if(b-a <= 2) then 
	write(*,'(i0)') k+1
    stop
end if

k_zanki = k - (a-1)

all = a
do i = 1, k_zanki/2
	all = all + b - a
end do

if(mod(k_zanki,2) == 1)then
	all = all +1
end if

write(*,'(i0)') all

END PROGRAM ATCODER


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <string>
#include <vector>
 
using namespace std;
typedef long long ll;
using gra = vector<vector<ll>>;
using gram = vector<unordered_map<ll,ll>>;
 
typedef unsigned long long ull;
 
template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
 
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> T dup(T a, T b) { return (a + b - 1) / b; }
template <class T> T modpow(T x, T p, T m) { T a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
// template <class T> void prim(T a) { for(ll i=0;i<a.size();++i) { cout << a[i]; } cout << "\n"; }
 
#define mod 1000000007LL
#define INF 10000000000000000LL
 
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define rrep1(i, n) for (int i = n; i > 0; --i)
 
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
//#define modpow(x, p, m) { ll a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
 
#define m0(h) memset(h, 0, sizeof(h))
#define m1(h) memset(h, 1, sizeof(h))
#define m(h, n) memset(h, (n), sizeof(h))
#define all(n) (n).begin(),(n).end()
#define bit(n) (1LL << (n))
#define pb push_back
 
//#ifdef LOCAL
//
//#define dpri(...) fprintf(stderr, __VA_ARGS__)
//#define pria(g) rep(i,g.size()){ cout << i << "{"; rep(j,g[i].size()) cout << g[i][j] << " "; cout << "}" << "\n"; }
//#else
//#define dpri(...) 42
//#define pria(g) 42
//#endif
 
 
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ---------------------
  // コーディング開始
  // ---------------------
  ll x,y;
  cin >> x >> y;
  ll ans =0;
  if(x==1) ans+=300000;
  if(x==2) ans+=200000;
  if(x==3) ans+=100000;
  if(y==1) ans+=300000;
  if(y==2) ans+=200000;
  if(y==3) ans+=100000;
  if(x==1&&y==1) ans+=400000;
  pri(ans);
  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
import random
getr = random.randint

def linput(ty=int, cvt=list):
	return cvt(map(ty,input().split()))

def gcd(a: int, b: int):
	while b: a, b = b, a%b
	return a

def lcm(a: int, b: int):
	return a * b // gcd(a, b)

def main():
	D = int(input())  # days
	vC = [0,]+linput()     # decrine rate
	
	#sumC = sum(vC)
	
	# satis (d,i)
	mS = [[0,]+linput() for _ in [0,]*D]
	
	
	vL = [-1,]*(26+1)   # last day of Type
	
	#day = -1
	res = 0      # manzoku
	vR = []
	vT = []
	rapp = vR.append
	tapp = vT.append
	
	#day = -1
	res = 0      # manzoku
	vR = []
	rapp = vR.append

	def get_scoreA(vT):
		res = 0
		for d in range(D): #[0,364] day
			t = vT[d] ## sample output
			vS = mS[d]
			Sdt = vS[t]
			res += Sdt
		
			vL[t] = d
			C = sum(c*(d-l) for c,l in zip(vC,vL))
			res -= C
		
			#rapp(res) ##
		return res

	## sample output
	#vT = [int(input()) for _ in [0,]*D] ## for p.C
	MR = 5000
	
	for m in range(MR):
		vTtmp = []
		for d in range(D):
			vTtmp.append(getr(1,26))
		resTmp = get_scoreA(vTtmp)
		if resTmp>res:
			res = resTmp
			rapp(res)
			vT = [t for t in vTtmp]

	"""
	for d in range(D): #[0,364] day
		#t = vT[d] ## sample output
		bestT = 1
		candiR = []
		vS = mS[d]
		for t in range(1,27):  # [1,26] type
			candir = 0
			Sdt = vS[t]
			candir += Sdt
			
			vltmp = vL[t]
			vL[t] = d
			C = sum(c*(d-l) for c,l in zip(vC,vL))
			candir -= C
			candiR.append(candir)
			
			vL[t] = vltmp
		
		bestR = max(candiR)
		bestT = candiR.index(bestR) + 1
		res += bestR
		rapp(res)
		tapp(bestT)
	"""
	
	
	
	#sT = "No Yes".split()
	#print(sT[res])
	#print(res)
	print(*vT, sep='\n')
	print(*vR, file=sys.stderr)
	#print(sum(vR), file=sys.stderr)

if __name__ == "__main__":
	main()


Measured memory_bytes: 82216
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n), b(n), c(n);
	rep(i,n){
		cin >> a[i];
		--a[i];
	}
	rep(i,n) cin >> b[i];
	rep(i,n-1) cin >> c[i];
	int ans = 0;
	rep(i,n){
		ans += b[a[i]];
		if(i+1 < n && a[i+1] == a[i]+1) ans += c[a[i]];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int a,b,c,x;
    cin >> a >> b >>c >>x;
    int cnt=0;
    for(int i=0; i<=a; i++){
        for(int j=0; j<=b; j++){
            for(int k=0; k<=c; k++){
                if(x == i*500 + j*100 + k * 50) cnt++;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int A,B,C,K;
main()
{
  cin>>A>>B>>C>>K;
  int ans=0;
  if(A<K)ans+=A,K-=A;
  else ans+=K,K=0;
  if(B<K)K-=B;
  else K=0;
  ans-=K;
  cout<<ans<<endl;
}

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

int main(){
	int N,K;
	cin>>N>>K;
	int index;
	int tmp;
	for(int i=0;i<N;++i){
		cin>>tmp;
		if(tmp==1){
			index=i;
			break;
		}
	}
	if((N-1)%(K-1)==0)cout<<(N-1)/(K-1)<<endl;
	else cout<<(N-1)/(K-1)+1<<endl;
}


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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt","r",stdin));
	TEST(freopen("output.txt","w",stdout));
	TEST(freopen("debug.txt","w",stderr));
	int N, K;
	cin>>N>>K;
	cout<<N-K+1<<'\n';
	return 0;
}

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
char chlit(char c){return c+32;}
char chbig(char c){return c-32;}

int main(){
  int x;cin >> x;
  if(x >= 1200)cout << "ARC" << endl;
  else cout << "ABC" << endl;
  return 0;
}


Measured memory_bytes: 256
n, q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n-1)]
px = [list(map(int, input().split())) for _ in range(q)]

l = [[] for i in range(n)]
for a, b in ab:
    a, b = a - 1, b - 1
    l[a].append(b)
    l[b].append(a)

value = [0 for i in range(n)]
for p, x in px:
    p -= 1
    value[p] += x

s = [0]
flag = [False]*(n)
while s:
    v = s.pop()
    flag[v] = True
    for e in l[v]:
        if flag[e]:
            continue
        
        value[e] += value[v]
        s.append(e)

print(*value)


Measured memory_bytes: 124036
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import lru_cache, reduce
from math import gcd
from operator import add, itemgetter, mul, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N = int(sys.stdin.buffer.readline())
A = list(map(int, sys.stdin.buffer.readline().split()))

counter = Counter(A)
A.sort()

dp = [True] * (max(A) + 10)
ans = 0
for a in A:
    if not dp[a]:
        continue
    if counter[a] == 1:
        ans += dp[a]
    j = a
    while j < len(dp):
        dp[j] = False
        j += a
print(ans)


Measured memory_bytes: 55508
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))

L = [0]
R = [0]
gcd_l = a[0]
gcd_r = a[-1]
for i in range(n):
    gcd_l = gcd(a[i],gcd_l)
    L.append(gcd_l)
    gcd_r = gcd(a[n-i-1],gcd_r)
    R.append(gcd_r)
#R.append(0)
#print(n)
#print(*L)
#print(*R)
ans = 0

for i in range(n):
    ans = max(ans,gcd(L[i],R[n-i-1]))

print(ans)

Measured memory_bytes: 94824
#if 0
date +%Y.%m.%d

题解先咕着。
#endif
#include <cstdio>
#define debug(...) fprintf(stderr, __VA_ARGS__)

inline int input() { int x; scanf("%d", &x); return x; }

int main() {
	int n = input();
	if(n == 1) puts("No");
	else if(n & 1) {
		puts("Yes");
		for(int i = 2; i + 1 <= n; i += 2) {
			printf("%d %d\n", i, i + 1);
			printf("%d %d\n", i + 1, 1);
			printf("%d %d\n", 1, i + n);
			printf("%d %d\n", i + n, i + n + 1);
		}
		printf("%d %d\n", n + 1, 2);
	} else {
		bool ok = false;
		for(int i = 2; i < n and not ok; i ++)
			if((i ^ n ^ 1) < n) {
				puts("Yes");
				if(i & 1)
					printf("%d %d\n", n, i);
				else
					printf("%d %d\n", n, i + n);
				if((i ^ n ^ 1) & 1)
					printf("%d %d\n", n + n, i ^ n ^ 1);
				else
					printf("%d %d\n", n + n, (i ^ n ^ 1) + n);
				ok = true;
			}
		if(ok) {
			for(int i = 2; i + 1 <= n; i += 2) {
				printf("%d %d\n", i, i + 1);
				printf("%d %d\n", i + 1, 1);
				printf("%d %d\n", 1, i + n);
				printf("%d %d\n", i + n, i + n + 1);
			}
			printf("%d %d\n", n + 1, 2);
		} else
			puts("No");
	}
}

Measured memory_bytes: 2304
n = int(input())
s = input()

max_cnt = s.count('R')*s.count('G')*s.count('B')

tmp = 0
for i in range(0, n-2):
  for j in range(i+1, n-1):
    if j+j-i < n:
      if s[i] != s[j] and s[i] != s[j+j-i] and s[j] != s[j+j-i]:
        tmp += 1

print(max_cnt-tmp)

Measured memory_bytes: 68168
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

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

  int a, b;
  cin >> a >> b;
  cout << a*b << '\n';
}


Measured memory_bytes: 3640
import bisect
def prime(n):
    max_=int(n**0.5)
    li=[i for i in range(2,n+1)]
    primes=[]
    while li[0]<=max_:
        primes.append(li[0])
        tmp=li[0]
        li=[i for i in li if i%tmp!=0]
    primes.extend(li)
    return primes
Q=int(input())
arr=prime(100000)
likenum=[]
n=len(arr)
for i in range(n):
    lik=(arr[i]+1)//2
    x=bisect.bisect_left(arr,lik)
    if(x<n and arr[x]==(lik)):
        likenum.append(arr[i])
for i in range(Q):
    L,R=map(int,input().split())
    r=bisect.bisect_left(likenum,R)
    l=bisect.bisect_left(likenum,L)
    if(r<len(likenum) and likenum[r]==R):
        r+=1
    print(r-l)

Measured memory_bytes: 7472
def hoge(m):
    if m % 10 == 0:
        return 0
    else:
        return (m//10+1)*10-m

P = [int(input()) for i in range(5)]
# 次の注文までの時間を計算する
P_tmp = [hoge(p) for p in P]
m = max(P_tmp)
m_idx = P_tmp.index(m)
m = P.pop(m_idx)

minites = 0

for p in P:
    minites += p
    minites += hoge(minites)
minites += m
print(minites)


Measured memory_bytes: 3060
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define String std::string
#define fir first
#define sec second
#define mp std::make_pair
#define Pair std::pair<int, int>
#define Map std::map< int, int >
#define Vector std::vector<int>

typedef long long ll;
typedef unsigned long long ull;

const int N = 2e5 + 5;
const int MOD = 1e9 + 7;
const int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
const int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

ll n, k;

int main() {
    std::cin >> n >> k;
    if (500 * n >= k) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
s=input()
for i in range(int(input())):
    l=list(input().split())
    l[1]=int(l[1])
    l[2]=int(l[2])+1
    if l[0]=="print":
        print(s[l[1]:l[2]])
    elif l[0]=="reverse":
        s=s[:l[1]]+s[l[1]:l[2]][::-1]+s[l[2]:]
    elif l[0]=="replace":
        s=s[:l[1]]+l[3]+s[l[2]:]

Measured memory_bytes: 7648
#include<bits/stdc++.h>
#define REP(i,n) for(long long i=0;i<n;++i)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
using namespace std;
int main(){
    int n;
    scanf("%d",&n);
    int A[n];
    REP(i,n) scanf("%d",&A[i]);
    int v,j;
    REP(i,n){
        if(i) printf(" ");
        printf("%d",A[i]);
    }
    puts("");
    FOR(i,1,n){
        v=A[i];
        j=i-1;
        while(j>=0&&A[j]>v){
            A[j+1]=A[j];
            j--;
            A[j+1]=v;
        }
        REP(k,n){
            if(k) printf(" ");
            printf("%d",A[k]);
        }
        puts("");
    }
    return 0;
}




Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F(i,s,e) for(ll i=s;i<e;++i)

int main()
{
    ll x;
    cin >> x;
    F(i,-200,200){
        F(j,-200,200){
            if(i*i*i*i*i-j*j*j*j*j==x){
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3640
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;
#include <cstring>

int main() {
  int h, w, sx, sy, gx, gy, dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
  string s[1000];
  deque<pair<int, int> > q;
  cin >> h >> w >> sx >> sy >> gx >> gy;
  sx--;
  sy--;
  gx--;
  gy--;
  vector<vector<int> > dis(h), visited(h);
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < h; i++) {
    dis[i].resize(w);
    visited[i].resize(w);
    for (int j = 0; j < w; j++) {
      dis[i][j] = 10000000;
    }
  }
  dis[sx][sy] = 0;
  q.push_front({sx, sy});
  while (!q.empty()) {
    int x, y;
    x = q.front().first;
    y = q.front().second;
    q.pop_front();
    if (visited[x][y] == 0) {
      visited[x][y] = 1;
      for (int i = 0; i < 4; i++) {
        if (x + dx[i] >= 0 && x + dx[i] < h && y + dy[i] >= 0 &&
            y + dy[i] < w && dis[x + dx[i]][y + dy[i]] > dis[x][y] &&
            s[x + dx[i]][y + dy[i]] == '.') {
          dis[x + dx[i]][y + dy[i]] = dis[x][y];
          q.push_front({x + dx[i], y + dy[i]});
        }
      }
      for (int i = max(0, x - 2); i < min(h, x + 3); i++) {
        for (int j = max(0, y - 2); j < min(w, y + 3); j++) {
          if (dis[i][j] > dis[x][y] + 1 && s[i][j] == '.') {
            dis[i][j] = dis[x][y] + 1;
            q.push_back({i, j});
          }
        }
      }
    }
  }
  cout << (dis[gx][gy] == 10000000 ? -1 : dis[gx][gy]) << endl;
}

Measured memory_bytes: 13380
#include <iostream>
#include <vector>
#include <tuple>
#include <numeric>

using T = std::tuple<long long int, long long int, long long int>;
const int MAX_N = 1000;
const int MAX_M = 1000;

T operator+(const T& a, const T& b) {
  return std::make_tuple(
    std::get<0>(a) + std::get<0>(b),
    std::get<1>(a) + std::get<1>(b),
    std::get<2>(a) + std::get<2>(b)
  );
}

long long int evaluate(T t) {
  return std::abs(std::get<0>(t)) + std::abs(std::get<1>(t)) + std::abs(std::get<2>(t));
}

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

  std::vector<T> inputs;

  for (int i = 0; i < N; i++) {
    long long int x, y, z;
    std::cin >> x >> y >> z;

    inputs.push_back(std::make_tuple(x, y, z));
  }

  long long int answer = 0;

  for (int i = -1; i <= 1; i += 2) {
    for (int j = -1; j <= 1; j += 2) {
      for (int k = -1; k <= 1; k += 2) {
        sort(inputs.begin(), inputs.end(), [&](const T&a, const T& b) {
          long long int va = i * std::get<0>(a) + j * std::get<1>(a) + k * std::get<2>(a);
          long long int vb = i * std::get<0>(b) + j * std::get<1>(b) + k * std::get<2>(b);

          return va < vb;
        });

        T c = accumulate(inputs.begin(), inputs.begin() + M, T(), [](const T& prev, const T& current) {
          return std::make_tuple(
            std::get<0>(prev) + std::get<0>(current),
            std::get<1>(prev) + std::get<1>(current),
            std::get<2>(prev) + std::get<2>(current)
          );
        });

        answer = std::max(answer, evaluate(c));
      }
    }
  }

  std::cout << answer << std::endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def YesNo(x): return 'Yes' if x else 'No'
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from collections import defaultdict

def main():
    N = II()
    xy = []
    for _ in range(N):
        xy.append(LI())
    xy2g = defaultdict(int)
    g2xy = defaultdict(set)
    for x, y in xy:
        y = -y
        gx = xy2g[x]
        gy = xy2g[y]
        if gx == gy != 0:
            continue
        elif gx != 0 != gy:  # merge
            if len(g2xy[gx]) < len(g2xy[gy]):
                gx, gy = gy, gx
            for xy in g2xy[gy]:
                xy2g[xy] = gx
            g2xy[gx] |= g2xy[gy]
            g2xy[gy].clear()
        else:
            g = gx or gy or x
            xy2g[x] = xy2g[y] = g
            g2xy[g] |= {x, y}
    ans = -N
    for xys in g2xy.values():
        nx = sum(xy > 0 for xy in xys)
        ny = len(xys) - nx
        ans += nx * ny
    return ans

print(main())

Measured memory_bytes: 114524
#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
    int d = 0;
    int c[26];
    int s[365][26];
    int t[365];
    int last[26] = {0};
    int score = 0;

    cin >> d;

    for(int i = 0; i < 26; i++)
    {
        cin >> c[i];
    }

    for(int i = 0; i < d; i++)
    {
        for(int j = 0; j < 26; j++)
        {
            cin >> s[i][j];
        }
    }

    for(int i = 0; i < d; i++)
    {
        cout << ((i + 1) % 26 + 1) << endl;
    }

}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define rep(i,s,n) for (int i = s; i < n; i++)
#define revrep(i,n,g) for (int i = n-1; i >= g; i--)
using namespace std;
using ll = long long;

ll solve(string s, int p) {
  map<int, ll> d;
  d[0] = 1;
  int c,t;
  c = 0; t = 1;
  ll ans = 0;
  revrep(i, s.size(), 0) {
    int a = atoi(s.substr(i,1).c_str());
    c += a * t;
    c %= p;
    ans += d[c];
    d[c] += 1;
    t *= 10;
    t %= p;
  }
  return ans;
}

int main() {
  string s;
  cin >> s;
  ll a = solve(s, 2019);
  cout << a << endl;
  return 0;
}


Measured memory_bytes: 3800
#include <iostream>
#include <vector>
using namespace std ;
bool is_war ( const vector <int >& x , const vector <int >& y ) {
for ( int Z = -100; Z <= 100; ++ Z ) {
bool is_ok = true ;
for ( int i = 0; i < x . size (); ++ i ) {
if ( x [ i ] >= Z ) is_ok = false ;
}
for ( int i = 0; i < y . size (); ++ i ) {
if ( y [ i ] < Z ) is_ok = false ;
}
if ( is_ok ) return false ;
}
return true ;
}
int main () {
int N , M ; cin >> N >> M ;
vector <int > x ( N +1) , y ( M +1);
cin >> x [0] >> y [0];
for ( int i = 0; i < N ; ++ i ) {
cin >> x [ i +1];
}
for ( int i = 0; i < M ; ++ i ) {
cin >> y [ i +1];
}
if ( is_war (x , y )) {
cout << " War " << endl ;
}
else {
cout << "No War " << endl ;
}
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		String s = sc.next();

		int b = 0;
		long ans = 0;

		for (char c : s.toCharArray()) {
			if (c == 'B')
				b++;
			else
				ans+=b;
		}

		System.out.println(ans);

	}

}


Measured memory_bytes: 26380
H,W=map(int,input().split())
N=int(input())
a=list(map(int,input().split()))

c=[[0 for i in range(W)] for i in range(H)]
k=0
for i in range(H):
    if i%2==0:
        for j in range(W):
            c[i][j]=k+1
            a[k]-=1
            if a[k]==0:
                k+=1
    else:
        for j in range(W-1,-1,-1):
            c[i][j]=k+1
            a[k]-=1
            if a[k]==0:
                k+=1
for i in range(H):
    for j in range(W):
        print(c[i][j],end=' ')
    print()


Measured memory_bytes: 9644
n,k = map(int,input().split())
lst = [[int(i) for i in input().split()] for i in range(n)]
nlst = sorted(lst,key= lambda x:x[0])
cnt = 0

for i in range(n):
    cnt += nlst[i][1]
    if cnt >= k:
        ans = nlst[i][0]
        break
    
print(ans)


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

const int inf=0x3f;
int h[100005],dp[100005];

signed main()
{
	int n,k;
	while(cin>>n>>k){
		for(int i=1;i<=n;i++)cin>>h[i];
		memset(dp,inf,sizeof dp);
		
		dp[1]=0,dp[2]=abs(h[2]-h[1]);
		for(int i=2;i<=n;i++){
			for(int j=1;j<=k;j++){
				if(i-j<=0)break;
				dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
			}
		}
		cout<<dp[n]<<endl;
	}
	return 0;
}

Measured memory_bytes: 4388
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

ll lcm (ll x, ll y)
{
    return x*(y/__gcd(x,y));
}

main()
{
    fast;
    int n,i;
    cin>>n;
    ll t;
    cin>>t;
    ll ans=t;
    for (i=0;i<n-1;i++)
    {
        cin>>t;
        ans=lcm(ans,t);
    }
    cout<<ans<<endl;
}

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

int main(){
    int N;
    cin >> N;
    vector<string> W;
    for(int i=0; i<N; i++){
        string s;
        cin >> s;
        W.push_back(s);
    }

    for(int i=0; i<N; i++){
        for(int j=i+1; j<N; j++){
            if(W[i] == W[j]){
                cout << "No";
                return 0;
            }
        }
    }

    for(int i =0; i<N-1; i++){
        if(W[i][W[i].length()-1] != W[i+1][0]){
            cout << "No";
            return 0;
        }
    }

    cout << "Yes";
}

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

int main() {
  int n;
  cin>>n;
  vector<int> V(n);
  for (int i=0; i<n; i++){
    cin>>V[i];
  }
  int k=0;
  for (int j=0;(V[j]%2==0 && j<n); j++){
    V[j]=V[j]/2;
    if(j==n-1){
      k++;
      j=-1;
    }
  }
  cout << k <<endl;
}

Measured memory_bytes: 256
toInt :: String -> Int
toInt = read :: String -> Int

getKthNumber :: String -> Int -> Int
getKthNumber s k
  | k == 1 = n
  | n == 1 = getKthNumber (tail s) (k - 1)
  | otherwise = n
      where
        n = toInt $ take 1 s

main = do
  s <- getLine
  k <- toInt <$> getLine
  putStrLn $ show $ getKthNumber s k


Measured memory_bytes: 636
#include <cstdio>
int n,s;
int dfs(int x,int y,int sum) {
	if(x==10) {
		return y==n&&sum==s;
	}
	return dfs(x+1,y,sum)+dfs(x+1,y+1,sum+x);
}
int main() {
	while(scanf("%d %d",&n,&s),n) {
		printf("%d\n",dfs(0,0,0));
	}
}

Measured memory_bytes: 1028
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

con = 10 ** 9 + 7
#入力受け取り
def getlist():
	return list(map(int, input().split()))


#処理内容
def main():
	N, K = getlist()
	ans = 0
	L = [0] * (K + 1)
	for i in range(K):
		x = K - i
		val = pow(int(K // x), N, con)
		for j in range(2, int(K // x) + 1):
			val -= L[x * j]
		L[x] = (val % con)

	for i in range(1, K + 1):
		ans += L[i] * i
		ans %= con

	print(ans)

if __name__ == '__main__':
	main()

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

#define fio                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ull unsigned long long
#define ld long double
#define endl "\n"
#define ff first
#define ss second
#define pi pair<ll, ll>
#define PI 3.141592653589793238462643383279502884L
#define mp make_pair
#define pb push_back
#define fall(i, a, b) for (int i = a; i < b; i++)
#define sz(x) (ll) x.size()
#define all(x) x.begin(), x.end()
#define ed cout << "ed";
ll MOD = 1e9 + 7;
ll MOD1 = 1e9 + 123;
ll MOD2 = 1e9 + 321;

int main()
{
    fio;
ll n,i,j,k,m,c;
   cin>>n;
    string a;
    cin>>a;
    int pre[n+1];
    int post[n+1];
c=0;
pre[0]=0;
    for(i=0;i<n;i++)
    {
        if(a[i]=='W')
            c++;
        if(a[i]=='R')
            pre[i+1]=0;
        else pre[i+1]=1;

      pre[i+1]+= pre[i];
 
    }

    int ans=min(c,n-c);
    int temp=0;

    for(i=0;i<n;i++)
    {
        temp= (n-i)-(c-pre[i]);
          // cout<<temp<<" "<<pre[i];

        if(pre[i]>temp)
        {
            ans=min(ans,pre[i]);
        }
        else 
        {
             ans=min(ans,temp);
        }


    }

    cout<<ans;

    return 0;
}


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

#define MAX 3002

int n;
int m;

#define MOD 1000000007

long long int dp[MAX][MAX][2];
bool use[MAX][MAX][2];

inline long long int dfs(int a, int b, int c){
	if (b == 0){
		c = 1;
	}
	if (a == m){
		if (c == 1){
			return 1;
		}
		return 0;
	}
	if (use[a][b][c]){
		return dp[a][b][c];
	}
	use[a][b][c] = true;
	//up
	if (b != n){
		dp[a][b][c] += dfs(a + 1, b, c);
		dp[a][b][c] += dfs(a + 1, b + 1, c);
		dp[a][b][c] %= MOD;
	}
	if (b != 0){
		dp[a][b][c] += dfs(a + 1, b, c|(b==1));
		dp[a][b][c] += dfs(a + 1, b - 1, c|(b==1));
		dp[a][b][c] %= MOD;
	}
	return dp[a][b][c];
}
int main(){
	cin >> n >> m;
	long long int ans = 0;
	for (int i = 0; i <= n; i++){
		ans += dfs(0, i, 0);
		ans %= MOD;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 158720
X, K, D = map(int, input().split())

division, mod = divmod(abs(X), D)

if division > K:
    ans = abs(X) - (D * K)
else:
    if (K - division) % 2 == 0:
        ans = mod
    else:
        ans = abs(mod - D)

print(ans)

Measured memory_bytes: 9200
#include<bits/stdc++.h>
using namespace std;
typedef long long int lld;
#define X first
#define Y second
//#define INF 1e12
 
int main() {
	int n,m;cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int x;cin>>x;
		n-=x;
	}
	if(n<0)cout<<-1<<endl;
	else cout<<n<<endl;
	return 0;
}

Measured memory_bytes: 3624
/*
  author:@Prashant Singh
  created on : 30/11/2019 00:39 AM


*/

#include<bits/stdc++.h>
using namespace std;


typedef long long int ll;

vector<ll> adj[1000001]; 

ll i;
#define mod 747474747
#define pb push_back
#define endl cout<<"\n";
#define prt1(a) cout<<a<<" "
#define prt2(a,b) cout<<a<<" "<<b<<" "
#define prt3(a,b,c) cout<<a<<" "<<b<<" "<<c<<" "
#define rep(i,st,end) for( i=st;i<end;i++)
#define repv(i,st,end) for( i=st;i>=end;i--)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

// to find root  call using root(arr,element)





int main()
{
  fio;
  ll n;
  cin>>n;
  double ans=n/1.08;
  ll x=ans;

  if(ll(x*1.08)==n)
  {
    prt1(x);
  }
  else
  {
    ll a=ans+1;
    if(ll(a*1.08)==n)
      prt1(a);
    else if (ll((ans-1)*1.08)==n)
      prt1(ans-1);
    else
      prt1(":(");
  }
  return 0;
}

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

#define ff first
#define ss second
using namespace std;
#define maxn 2000006
#define pb push_back
#define ll long long
#define lll __int128
#define vll vector<ll>
#define mll map<ll,ll>
#define MOD 1000000007
#define pll pair<ll,ll>
#define ull unsigned long long
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
inline void fastio() {ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);}

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

ll n, m;
ll a[maxn], b, M[maxn];
ll memo[1003][5000];

ll func(ll i, ll mask) {
	if (i == m) {
		if (mask == (pow(2, n) - 1)) return 0;
		else return INT_MAX;
	}

	if (mask == (pow(2, n) - 1)) return 0;

	if (memo[i][mask] != -1) return memo[i][mask];

	ll q1 = func(i + 1, mask);
	ll q2 = func(i + 1, mask | M[i]) + a[i];

	return memo[i][mask] = min(q1, q2);
}

int main() {
	fastio();

	cin >> n >> m;

	f(i, 0, 1002) {
		f(j, 0, 4999) memo[i][j] = -1;
	}

	f(i, 0, m - 1) {
		cin >> a[i] >> b;

		f(j, 0, b - 1) {
			ll c; cin >> c;
			M[i] += pow(2, c - 1);
		}

		// cout<<M[i]<<endl;
	}



	ll ans = func(0, 0);

	if (ans == INT_MAX) cout << "-1";
	else cout << ans;


	return 0;
}

Measured memory_bytes: 43264
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
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 powmod(ll a,ll b,ll MOD){ll ans=1ll;while(b){if(b&1)ans=ans*a%MOD;a=a*a%MOD;b>>=1;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int d[500][500];
int n,m;
int a[maxn];
int b[maxn];
int c[maxn];
int main()
{
	//    freopen("C:\\Users\\DH_M\\Desktop\\code_io\\in.txt.txt","r",stdin);
	//    freopen("C:\\Users\\DH_M\\Desktop\\code_io\\out.txt.txt","w",stdout);
	gbtb;
	cin>>n>>m;
	repd(i,1,m)
	{
		cin>>a[i]>>b[i]>>c[i];
	}
	repd(i,1,n)
	{
		repd(j,1,n)
		{
			d[i][j] = d[j][i] = i==j?0:inf;
		}
	}
	repd(k,1,m)
	{
		repd(i,1,n)
		{
			repd(j,1,n)
			{
				d[i][j]=d[j][i]=min(d[j][i],d[i][a[k]]+d[b[k]][j]+c[k]);
			}
		}
	}
	int ans=0;
	repd(k,1,m)
	{
		if(d[a[k]][b[k]]!=c[k])
		{
			ans++;
		}
	}
	cout<<ans<<endl;



    return 0;
}

inline void getInt(int* p) {char ch;do {ch = getchar();}
while (ch == ' ' || ch == '\n');if (ch == '-') {*p = -(getchar() - '0');
while ((ch = getchar()) >= '0' && ch <= '9') {*p = *p * 10 - ch + '0';}}
else {*p = ch - '0';while ((ch = getchar()) >= '0' && ch <= '9')
{*p = *p * 10 + ch - '0';}}}


Measured memory_bytes: 4608
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;

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

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}
int main()
{
    int A, B;
    cin >> A >> B;

    if (A + B < 10) { cout << A + B << endl; }
    else { cout << "error" << endl; }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
 int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    double ans;
    cin>>n;
    ans=(double)n-floor(n/2);
    ans/=(double)n;
    cout<<setprecision(8)<<ans<<endl;

	return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

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

    for (int i = -120; i <= 120; ++i) {
        for (int j = -120; j < 120; ++j) {
            if (pow(i, 5) - pow(j, 5) == x) {
                cout << i << " " << j << endl;
                return 0;
            }
        }
    } 
    return 0;
}

Measured memory_bytes: 4012
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[]$) {
        Scanner sc = new Scanner(in);
        long a=sc.nextLong();
        long b=sc.nextLong();
        long c=sc.nextLong();
        if(a%2*b%2*c%2==0){
            out.println(0);
        }else{
            long x=a*b;
            long y=c*b;
            long z=a*c;
            out.println(min(x,min(y,z)));
        }
    }
}

Measured memory_bytes: 21716