akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<complex>
#include<map>

#define f first
#define s second

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define EPS (1e-10)
using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

int memo[1010];
int w,n;
int wei[1000];
int val[1000];

void search(int p){
  if(p == n) return;
  int ww = wei[p];
  int vv = val[p];
  for(int i=w-ww; i>=0; i--) if(memo[i] != -1) {
      memo[ww+i] = max(memo[ww+i], memo[i] + vv); 
  }
  search(p+1);
}

int main(){
  int cc = 1;
  while(scanf("%d",&w),w){
    scanf("%d",&n);
    REP(i,n) scanf("%d,%d",val+i,wei+i);
    memset(memo,-1,sizeof(memo));
    memo[0] = 0;
    search(0);
    int vv = 0, ww = 0;
    REP(i,w+1){
      if(memo[i] > vv){
	vv = memo[i];
	ww = i;
      }
    }
    printf("Case %d:\n",cc++);
    printf("%d\n",vv);
    printf("%d\n",ww);
  }
  return 0;
}

Measured memory_bytes: 0
N=int(input())
S=input()
r = S.count("R")
g = S.count("G")
b = S.count("B")
out =r*g*b

for i in range(0,N):
    w = 1
    while i+w*2<N:
        if S[i]!=S[i+w] and S[i]!=S[i+2*w] and S[i+w]!=S[i+2*w]:
            out = out -1
        w = w+1
        
print(out)

Measured memory_bytes: 9208
import collections

N = int(input())

a = []
b = []
for i in range(N):
    s = input()
    a.append(s)

M = int(input())
for i in range(M):
    t = input()
    b.append(t)

a1 = collections.Counter(a)
a2 = a1.most_common()

ans = 0
for i in range(len(a1)):
    total = a2[i][1] - b.count(a2[i][0])
    if total > ans:
        ans = total
    else:
        continue
print(ans)

Measured memory_bytes: 9320
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

	int n;
	string s[100];
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> s[i];
	}
	for(int i=1; i<n; i++){
		int m=s[i-1].size();
		if(s[i-1][m-1]!=s[i][0]){
			cout << "No" << endl;
			return 0;
		}
	}
	sort(s, s+n);
	for(int i=0; i<n-1; i++){
		if(s[i]==s[i+1]){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;

	return 0;
}


Measured memory_bytes: 256
def main():
    from sys import setrecursionlimit, stdin
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**9+10


    N = II()
    A = LMIIS()


    max_nodes = [0]*(N+1)
    max_nodes[N] = A[N]
    for i in range(N-1,-1,-1):
        max_nodes[i] = max_nodes[i+1] + A[i]


    if N == 0:
        if A[0] != 1:
            print(-1)
        else:
            print(1)

        return
    if A[0] != 0:
        if sum(A[1:]) == 0:
            print(1)
        else:
            print(-1)
        return


    sum_top = 1

    tmp = 1
    
    for i in range(1,N+1):
        max_l = tmp*2
        if max_l >= max_nodes[i]:
            print(sum_top+sum(max_nodes[i:]))
            return
        sum_top += max_l
        tmp = max_l - A[i]
        if tmp < 0:
            print(-1)
            return

    dbg(sum_top)
    print(-1)


main()

Measured memory_bytes: 82652
#include <stdio.h>



int main(void)
{
	//変数の宣言
	int n;
	int a;
	int i;
	int maru=0;
	int sankaku=0;
	int batu=0;
	
	
	//データの読み込み
	scanf("%d",&n);
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	for(i=0;i<n;i++){
		scanf("%d",&a);
		if(a%4==0){
			maru++;
		}else if(a%2==0){
			sankaku++;
		}else{
			batu++;
		}
	}
	
	if(sankaku>0){
		batu++;
	}
	
	
	
	
//	printf("計算部分終了\n");
	
	//出力
	
	if(maru+1<batu){
		printf("No");
	}else{
		printf("Yes");
	}
	
//	printf("結果の出力終了\n");
	
	return 0;
}



Measured memory_bytes: 128
N = int(input())
P = [[int(_) for _ in input().split()] for i in range(N)]

ans = 0
for i in range(N):
    ix, iy = P[i]
    for j in range(i, N):
        jx, jy = P[j]
        ans += ((ix - jx) ** 2 + (iy - jy) ** 2) ** 0.5

print(ans / (N * (N-1) // 2) * (N-1))


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

int main()
{
    int N;cin>>N;
    string S;cin>> S;
    vector<int> R;
    vector<int> G;
    vector<int> B;
    for (int i=0;i<N;i++)
    {
        if (S[i]=='R') R.push_back(i);
        if (S[i]=='G') G.push_back(i);
        if (S[i]=='B') B.push_back(i);
    }
    
    int minus=0;
    int index1,index2;
    for (int j=0;j<R.size();j++)
        for (int a=1;a<N;a++)
        {
            index1=R[j]+a;
            index2=R[j]-a;
            if (binary_search(G.begin(),G.end(),index1) && binary_search(B.begin(),B.end(),index2)) minus++;
            if (binary_search(G.begin(),G.end(),index2) && binary_search(B.begin(),B.end(),index1)) minus++;
        }
    for (int j=0;j<G.size();j++)
        for (int a=1;a<N;a++)
        {
            index1=G[j]+a;
            index2=G[j]-a;
            if (binary_search(R.begin(),R.end(),index1) && binary_search(B.begin(),B.end(),index2)) minus++;
            if (binary_search(R.begin(),R.end(),index2) && binary_search(B.begin(),B.end(),index1)) minus++;
        }
    for (int j=0;j<B.size();j++)
        for (int a=1;a<N;a++)
        {
            index1=B[j]+a;
            index2=B[j]-a;
            if (binary_search(G.begin(),G.end(),index1) && binary_search(R.begin(),R.end(),index2)) minus++;
            if (binary_search(G.begin(),G.end(),index2) && binary_search(R.begin(),R.end(),index1)) minus++;
        }
    cout << B.size()*R.size()*G.size()-minus << endl;
return 0;
}

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

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> C(N);
  vector<vector<int>> A(N, vector<int>(M));
  vector<int> sum(M, 0);
  int cant = 0;
  long cash = 0;
  for(int i = 0; i < N; i++) {
    cin >> C.at(i);
    cash += C.at(i);
    for (int j = 0; j < M; j++) {
      cin >> A.at(i).at(j);
      sum.at(j) += A.at(i).at(j);
    }
  }
  for (int i = 0; i < M; i++) {
    if (sum.at(i) < X) {
      cant = 1;
    }
  }

  if (cant == 1) {
    cout << -1 << endl;
  } else {
    long m = cash;
    for (int bit = 0; bit < (1<<N); ++bit) {
      vector<int> tak(M,0);
      long submin = 0;
      cant = 0;
      for (int i = 0; i < N; i++) {
        if (bit & (1<<i)) {
          for(int j = 0; j < M; j++) {
            tak.at(j) += A.at(i).at(j);
          }
          submin += C.at(i);
        }
      }
      for (int i = 0; i < M; i++) {
        if (tak.at(i) < X) {
          cant = 1;
        }
      }
      if (cant == 0) {
        m = min(m, submin);
      }
    }
    cout << m << endl;
  }
}


Measured memory_bytes: 3632
n=int(input())
a=list(map(int,input().split()))

def maxHeapify(A, i):
	l = i*2
	r = i*2+1
	if l <= n and A[l-1] > A[i-1]:
		largest = l
	else: 
		largest = i
	if r <= n and A[r-1] > A[largest-1]:
		largest = r

	if largest != i:
		A[i-1],A[largest-1]=A[largest-1],A[i-1]
		maxHeapify(A, largest)
for i in range(n//2,0,-1):
	maxHeapify(a,i)
print(" ",end="")
print(*a)


Measured memory_bytes: 63700
#include<stdio.h>
#include<stdlib.h>

#define WHITE 0
#define BLACK 1
#define inf 2000

int main(){
  int n, mincost, sum=0;
  int A[101][101]={}, color[101], d[101], pi[101];
  int i, j, r, u, v;

  scanf("%d", &n);
  if(n < 0 || 100 < n)
    exit(1);

  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      scanf("%d", &A[i][j]);
      if(A[i][j] != -1 && (A[i][j] < 0 || 2000 < A[i][j]))
	exit(2);
    }
  }

  for(u = 0; u < n; u++){
    d[u] = inf;
    pi[u] = -1;
    color[u] = WHITE;
  }
  d[0] = 0;

  while(1){
    mincost = inf;
    for(i = 0; i < n; i++){
      if((color[i] != BLACK) && (d[i] < mincost)){
	  mincost = d[i];
	  u = i;
      }
    }
    if(mincost == inf)
      break;
    color[u] = BLACK;
    for(v = 0; v < n; v++){
      if((color[v] != BLACK) && (A[u][v] != -1) && (A[u][v] < d[v])){
	pi[v] = u;
	d[v] = A[u][v];
      }
    }
  }

  for(i = 0; i < n; i++)
    sum += d[i];
  
  printf("%d\n", sum);

  return 0;
}

Measured memory_bytes: 648
using System;

class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        int ans = 0;
        int count = 1;
        for (int i = 0; i < a.Length; i++)
        {
            if (a[i] == count)
                count++;
            else
                ans++;
        }
        Console.WriteLine(count == 1 || ans == a.Length ? -1 : ans);
    }
}

Measured memory_bytes: 34780
class Treasure
  def initialize(value, weight)
    @value = value;
    @weight = weight;
  end
  def getValue
    return @value;
  end
  def getWeight
    return @weight;
  end
end

MAX_BAG_WEIGHT = 1000;
MAX_NUM_TREASURES = 1000;
MAX_VALUE = 10000;
WEIGHT = 0;
VALUE = 1;

#DP
def getMaxValue(bagWeight, treasureArray)
  table = Array.new(bagWeight + 1, 0);
  treasureArray.each{ |t|
    tWeight = t.getWeight;
    tValue = t.getValue;
    bagWeight.step(tWeight, -1) { |w| #bagWeight書き換わってまずくない？
      break if table[w- tWeight] < 0;
      tmp = table[w]
      table[w] = table[w - tWeight] + tValue if tmp < table[w - tWeight] + tValue
    }
  }
  #p table
  return table;
end

def getMinWeightWhenMaxValue(bagWeight, valueTable)
  minWeight = bagWeight;
  maxValue = valueTable.max
  bagWeight.step(1, -1) { |w|
    break if maxValue > valueTable[w];
    minWeight = w;
  }
  return minWeight;
end

#main
caseNumber = 0;
while true
  bagWeight = gets.to_i;
  break if bagWeight == 0;
  numTreasures = gets.to_i;
  treasure = Array.new;
  numTreasures.step(1, -1) {
    input = gets.chomp.split(/\s*,\s*/);
    treasure << Treasure.new(input[0].to_i, input[1].to_i);
  }
  valueTable = getMaxValue(bagWeight, treasure);
  caseNumber += 1
  puts "Case " + caseNumber.to_s + ":";
  puts valueTable.max; #速度落ちる？
  puts getMinWeightWhenMaxValue(bagWeight, valueTable);
end

Measured memory_bytes: 6136
/// 11:57 AM 02/05/20
/// Author: t_bone_289 (An Immature Programmer.... I'm still developing !!)
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define M 1000000007
#define error(x) cout << #x << " = " << x << endl;
#define pi 3.14159265358979323846
typedef long long ll;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

template<typename T>
void ContainerError(T &v);

ll powmod(ll base, ll exp, ll MOD);

ll mpow(ll base, ll exp);

ll gcd(ll a, ll b);

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll n;
    cin >> n;
    ll nn = n;
    n=100;
    ll ans = 0;
    for(ll i=1;i<=100000;i++) {
        n = (n) * 1.01;
        if(n>=nn) {
            ans = i;
            break;
        }
    }
    cout<<ans;
    return 0;
}

template<typename T>
void ContainerError(T &v) {
    cout << "{";
    for (auto &x:v) { cout << x << ','; }
    cout << "}" << endl;
    return;
}

ll powmod(ll base, ll exp, ll MOD) {
    ll res = 1;
    while (exp > 0) {
        if (exp % 2 == 1) res = (res * base) % MOD;
        base = (base * base) % MOD;
        exp /= 2;
    }
    return (res % MOD);
}

ll mpow(ll base, ll exp) {
    ll res = 1;
    while (exp > 0) {
        if (exp % 2 == 1) res = (res * base);
        base = (base * base);
        exp /= 2;
    }
    return (res);
}

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



Measured memory_bytes: 3652
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner scanner = new Scanner(System.in);
		String str = scanner.nextLine();
		
 		int y = Integer.parseInt(str);
		
		System.out.println(y*y*y);
	}
}

Measured memory_bytes: 26252
import math as m
from functools import reduce
n,T= int(input()),[]
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
for i in range(n):
    T.append(int(input()))
tmp = max(T)
for i in range(n):
    if tmp % T[i] != 0:
        tmp = T[i]//gcd(tmp, T[i])*tmp

print(tmp)



Measured memory_bytes: 3700
package main

import "fmt"

func main() {
	var N, M int
	// コンソールで入力を要求
	fmt.Scan(&N, &M)

	t := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&t[i])
	}

	s := 0
	for _, x := range t {
		s += x
	}

	ans := 0
	for j := 0; j < N; j++ {
		if t[j]*4*M < s {
			ans++
		}
	}

	if ans+M <= N {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
	
	int N;
	vecs(A)
	pb(A,"3")pb(A,"5")pb(A,"7")
map<string,int> S;
map<char,int> T;
int ans=0;
	cin>>N;
	fx(A.size()){

		ll g=atol(A.at(x).c_str());
		if(S[A.at(x)]==0&&g<=N){
S[A.at(x)]++;
			T['3']=0;T['5']=0;T['7']=0;
			fy(A.at(x).size()){
				T[A.at(x).at(y)]++;
			}
			if(T['3']>0&&T['5']>0&&T['7']>0){
				ans++;
			}
			if(g<MOD){pb(A,A.at(x)+"3")pb(A,A.at(x)+"5")pb(A,A.at(x)+"7")
			pb(A,"3"+A.at(x))pb(A,"5"+A.at(x))pb(A,"7"+A.at(x))}
		}
		
	}
	
	ce(ans)
}

Measured memory_bytes: 18032
#include <iostream>
#include <vector>
using namespace std;
using ull = unsigned long long;

int main(){
  int n, p;
  bool all_even = true;
  cin >> n >> p;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
    if(a[i]%2) all_even = false;
  }

  ull ans = 1;
  if(all_even){
    if(p) ans = 0;
    else ans <<= 1;
  }
  for(int i = 0; i < n-1; i++)
    ans <<= 1;

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


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <ctime>
#include <climits>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <utility>
#include <cstdlib>

using namespace std;
long int pow107 = (int)pow(10, 9) + 7;
long int limit = LONG_MAX;

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

long int jou(long int x, long int y){
    long int f = 1;
    for(int i = 0; i < y; ++i){
        f = f * x % pow107;
    }
    return f;
}

bool pn(long int x){
    if(x != 2 && x % 2 == 0)
        return false;
    for(int i = 3; i < x; ++i){
        if(x != i && x % i == 0)
            return false;
    }
    return true;
}

long int factorial(long int n){
    long int f = 1;
    for(long int i = 1; i <= n; ++i){
        f = f * i % pow107;
    }
    return f;
}

//最大limit
//10^9+7    pow107
//素数pn
//n乗jou
//コンビネーションfactorial
//

int main(){
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); ++i){
        for(int j = i + 1; j < s.size(); ++j){
            if(s[i] == s[j]){
                cout << "no" << endl;
                return 0;
            }
        }
    }
    cout << "yes" << endl;
}

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

int main() {
  int n, c, k; cin >> n >> c >> k;
  vector<int> t(n);
  int ans = 0;
  rep(i,n) cin >> t[i];
  sort(t.begin(), t.end());
  t.push_back(0);
  int train = 0, limit = t[0] + k;
  rep(i,n) {
    if (limit < t[i]) {
      ans++;
      train = 0;
      limit = t[i] + k;
    }
    train++;
    if (train >= c) {
      ans++;
      train = 0;
      limit = t[i+1] + k;
    }
  }
  if (train) ans++;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4044
ami = Array.new(gets.to_i)
ami.size.times{|i|
	ami[i] = i+1
}
gets.to_i.times{
	n,m = gets.split(",").map(&:to_i)
	tmp = ami[n-1]
	ami[n-1] = ami[m-1]
	ami[m-1] = tmp
}
puts ami

Measured memory_bytes: 8688
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>
#include <bitset>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

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


Measured memory_bytes: 3620
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define seg_size 262144
#define REP(i,n) for(long long i = 0;i < n;++i)
int main(){
	int h, w;
	cin >> h >> w;
	vector<pair<int,int>> geko;
	REP(i, h) {
		string s;
		cin >> s;
		REP(q, w) {
			if (s[q] == 'B') {
				geko.push_back(make_pair(i, q));
			}
		}
	}
	int ans = 0;
	REP(i, geko.size()) {
		REP(q, geko.size()) {
			ans = max(ans, abs(geko[i].first - geko[q].first) + abs(geko[i].second - geko[q].second));
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(0);

    int w,a,b;
    cin >> w >> a >> b;

    if(b>a+w) cout << b-a-w;
    else if(a>b+w) cout << a-b-w;
    else cout << 0;

    return 0;
}

Measured memory_bytes: 256
//#define NDEBUG
 
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <cassert>
#include <unistd.h>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <random>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
const int MN = 50500; 
const int MD = 1000003;

int n, m;
P g[MN];
vector<P> edge;
int calc(int l, int r) {
    ll res = 1;
    while (l <= r) {
        P p = g[l];
        l = p.first+1;
        res *= p.second; res %= MD;
    }
    return res;
}
int solve() {
    if (n % 2) return 0;
    edge.clear();
    for (int i = 0; i < n-1; i++) {
        g[i] = P(i+1, 1);
    }
    vector<T> buf;
    buf.push_back(T(n-1, 0, n-1));
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b; a--; b--;
        if (a > b) swap(a, b);
        if ((b-a) % 2 == 0) continue;
        buf.push_back(T(b-a, a, b));
    }
    sort(buf.begin(), buf.end());
    for (T &t: buf) {
        int a, b, c;
        tie(c, a, b) = t;
        int res = calc(a, b) + calc(a+1, b-1);
        res %= MD;
        g[a] = P(b, res);
    }
    return g[0].second;
}

int main() {
    while (true) {
        cin >> n >> m;
        if (!n) break;
        cout << solve() << endl;
    }
}

Measured memory_bytes: 2072
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            var abp = new List<Tuple<long, long, long>>();
            for (var i = 0; i < N; ++i) 
            {
                var ab = Sarray();
                abp.Add(Tuple.Create(ab[0] + ab[1], ab[0], ab[1]));
            }
            abp = abp.OrderByDescending(a => a.Item1).ToList();
            var tkhs = 0L;
            var aoki = 0L;
            for(var i=0;i<N;++i)
            {
                if (0 == (i % 2))
                    tkhs += abp[i].Item2;
                else
                    aoki += abp[i].Item3;
            }
            WriteLine(tkhs - aoki);
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 28976
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
//#pragma comment(linker, "/STACK:1024000000,1024000000")

using namespace std;

#define ll long long
#define SZ(x) ((int)(x).size()) 
#define ALL(v) (v).begin(), (v).end()
#define foreach(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define reveach(i, v) for (__typeof((v).rbegin()) i = (v).rbegin(); i != (v).rend(); ++ i) 
#define REP(i,a,n) for ( int i=a; i<int(n); i++ )
#define FOR(i,a,n) for ( int i=n-1; i>= int(a);i-- )
#define lson rt<<1, L, m
#define rson rt<<1|1, m, R
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define fi first
#define se second
#define CLR(a, b) memset(a, b, sizeof(a))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
const int N = 1e5 + 7;
int n, k;
int a[N];
vector<int> G[N];
int res;
int dfs(int u, int f, int d){
    int maxD = d;
    for(auto v : G[u]){
        if(v == f) continue;;
        Max(maxD, dfs(v, u, d + 1));
    }
    //printf("u = %d, d = %d, maxD = %d\n", u, d, maxD);
    if(u != 1 && f != 1 && maxD - d >= k - 1){
        //cout << u << endl;
        res ++;
        return d - 1;
    }
    return maxD;
}
int main(){
#ifdef ac
	freopen("in.txt","r",stdin);
#endif
	//freopen("out.txt","w",stdout);
    scanf("%d%d", &n, &k);
    REP(i, 0, n){
        scanf("%d", &a[i]);
        if(i) G[a[i]].pb(i + 1);
    }
    if(a[0] != 1) res ++;
    dfs(1, 0, 1);
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 13952
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


def li_input():
    return [int(_) for _ in input().split()]

"""
1  insertionSort(A, n, g)
2      for i = g to n-1
3          v = A[i]
4          j = i - g
5          while j >= 0 && A[j] > v
6              A[j+g] = A[j]
7              j = j - g
8              cnt++
9          A[j+g] = v
10
11 shellSort(A, n)
12     cnt = 0
13     m = ?
14     G[] = {?, ?,..., ?}
15     for i = 0 to m-1
16         insertionSort(A, n, G[i])
"""

cnt = 0

def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j + g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v

def shellSort(A, n):
    m = 1

    G = [1]
    for i in range(1, 10000):
        if 3 * G[i - 1] + 1 > len(A):
            break
        G.append(3 * G[i - 1] + 1)
    G = G[::-1]
    m = len(G)

    print(m)
    print(" ".join(list(map(str, G))))

    for i in range(m):
        insertionSort(A, n, G[i])
    
    print(cnt)

    for a in A:
        print(a)

def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    
    shellSort(A, N)



main()



Measured memory_bytes: 47616
import itertools
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
S = int(input())
digit = S //3
sum = 0
for i in range(1,digit +1):
    if i == 1:
        sum += 1
        continue
    left_num = S - i* 3
    pause = i-1
    sum += combinations_count(left_num + pause,pause)
print(sum % (10 ** 9 + 7))

Measured memory_bytes: 9184
open System

// prelude
let readStr () = stdin.ReadLine()

let read f () = readStr() |> f
let reads f () = readStr().Split() |> Array.map f

let pair = function
| [|a; b|] -> (a, b)
| _ -> failwith "owatta"

let triple = function
| [|a; b; c|] -> (a, b, c)
| _ -> failwith "owatta"

let readPair f g () =
  let (a,b) = readStr().Split() |> pair
  (f a, g b)

let readTriple f g h () =
  let (a,b,c) = readStr().Split() |> triple
  (f a, g b, h c)

let inc n = n + 1
let dec n = n - 1

let inline flip f a b = f b a
let rec fix f = fun x -> (f (fix f)) x

module Option =
  let getOr defaultValue = function
  | Some x -> x
  | None -> defaultValue

module Array =
  let modify (arr: _ []) i f =
    arr.[i] <- f arr.[i]

module Array2D =
  let modify (arr: _ [,]) i j f =
    arr.[i, j] <- f arr.[i, j]

// start
let (S,W) = readPair int int ()

if W>=S then "unsafe" else "safe"
|> printfn "%s"

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

// int/long:		-2147483648 - 2147483648 (-2^31 <= int < 2^31)
// long/long long:	-9223372036854775808 - 9223372036854775807 (-2^63 <= long < 2^63)
#define	INF (1<<29)
//536870912

#define	MOD 1000000007

int	main() {
	long N, M;
	cin >>N >>M;
	long S=0;
	if (N>M)
		swap(N, M);
	if (N==1) {
		if (1==M)
			S=1;
		else 
			S=M-2;
	} else if (2==N) {
		S=0;
	} else {
		S=(N-2)*(M-2);
	}
	cout <<S <<endl;
	return 0;
}



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

int main() {
  int N, K;
  cin >> N;
  
  int sum = 1;
  for(int i = 0; i < N; i++){
      cin >> K;
      if(2 * sum <= sum + K){
          sum *= 2;
      }else{
          sum += K;
      }
  
  }
  cout << sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 114514810;
const int MOD = 1000000007;
const double EPS = 1e-8;
const double PI = acos(-1.0);
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///
int n, m;
double a[25], b[25], l[25];
double ans = 0;

double calc(vi v)
{
	double t = 0;
	REP(i, v.size())
	{
		FOR(j, i + 1, v.size())
		{
			t += pow((a[v[i]] - a[v[j]]), 2) + pow((b[v[i]] - b[v[j]]), 2) + pow((l[v[i]] - l[v[j]]), 2);
		}
	}
	return t;
}

void solve(int i, vi v)
{
	if (v.size() == m) ans = max(ans, calc(v));
	else if (i != n)
	{
		solve(i + 1, v);
		v.push_back(i);
		solve(i + 1, v);
	}
}

int main()
{
	cin >> n >> m;
	REP(i, n)
	{
		cin >> l[i] >> a[i] >> b[i];
	}
	vi v;
	solve(0, v);
	cout << D10 << ans << endl;
	return 0;
}

Measured memory_bytes: 1312
#include <bits/stdc++.h>
#define fastio() ios_base::sync_with_stdio(false);
using namespace std;
typedef long long ll;
typedef long double ld;


int main(){
	int n, k; cin >> n >> k;
	vector<pair<int, int>> edges;
	for(int i = 1; i<=n; i++){
		for(int j = i+1; j<=n; j++) edges.push_back({i, j});
	}
	int cnt = 0;
	while(cnt<k && edges.back().first != 1) edges.pop_back(), cnt++;
	if (cnt == k){
		printf("%d\n", int(edges.size()));
		for(auto e: edges) printf("%d %d\n", e.first, e.second);
	}
	else puts("-1");
	return 0;
}


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

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		bool flag = false;
		int prev;
		int in[10];
		int used[10];
		for (int j = 0; j < 10; j++)
		{
			cin >> in[j];
		}
		prev = in[0];
		vector<int> B;
		vector<int> C;
		for (int j = 0; j < 10; j++)
		{
			if (prev > in[j])
			{
				C.push_back(in[j]);
				used[j] = false;
				continue;
			}
			else
			{
				prev = in[j];
				B.push_back(in[j]);
				used[j] = true;
			}
		}
		prev = C[0];
		for (int j = 0; j < C.size(); j++)
		{
			if (prev > C[j])
			{
				flag = true;
				break;
			}
			else
			{
				prev = C[j];
			}
		}
		if (flag) cout << "NO" << endl;
		else cout << "YES" << endl;
	}
	return 0;
}

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

#define ll long long int
#define endl '\n'
#define inf 1e18

void testCase()
{
    
   // ll t; cin>>t; while(t--)
    {
        string s;
        cin>>s;
        ll n=s.length();
        ll ans=0;
        for(int i=0;i<n;i++)
        {
            if(s[i]=='R')
            {
                ll j=i;
                ll cnt=0;
                while(s[j]=='R')
                cnt++,j++;
                ans=max(ans,cnt);
            }
        }
        cout<<ans;
    }       
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    testCase();
    return 0;
}

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

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

    vector<int> v(N);
    for (int i = 0; i < N; i++) {
        if (S[i] == 'A' && S[i + 1] == 'C') {
            v[i + 1] = 1;
        }
    }

    vector<int> sum(v.size() + 1, 0);
    partial_sum(v.begin(), v.end(), sum.begin() + 1);

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

Measured memory_bytes: 1792
n, a, b, c = map(int, input().split())
d = {"A": a, "B": b, "C": c}
res = []
s_l = [input() for _ in range(n)]

for i, s in enumerate(s_l): 
    s0 = s[0]
    s1 = s[1]
    if d[s0] == d[s1] == 0:
        print("No")
        exit()
    elif d[s0] == 0:
        d[s0] += 1
        d[s1] -= 1
        res.append(s0)
    elif d[s1] == 0:
        d[s0] -= 1
        d[s1] += 1
        res.append(s1)
    elif i == n-1:
        res.append(s0)
    elif s0 in s_l[i+1]:
        d[s0] += 1
        d[s1] -= 1
        res.append(s0)
    else:
        d[s0] -= 1
        d[s1] += 1
        res.append(s1)
print("Yes")
for r in res:
    print(r)




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

ans = 0
for i in reversed(range(N)):
    m1 = min(B[i], A[i + 1])
    ans += m1
    m0 = min(B[i] - m1, A[i])
    A[i] -= m0
    ans += m0
print(ans)

Measured memory_bytes: 18476
#include <stdio.h>
#include <string.h>

int main(){

  int i,j,m,n;
  char regi[256][11],try_id[256][11];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    int count=0;
    scanf("%s",regi[i]);
  }
  scanf("%d",&m);
  for(i=0;i<m;i++){
    int count=0;
    scanf("%s",try_id[i]);
  }

  int door=0;

  for(i=0;i<m;i++){
    for(j=0;j<n;j++){
      if(strcmp(try_id[i],regi[j])==0){
        if(door==0){
          printf("Opened by %s\n",try_id[i]);
          door=1;
          break;
        }else{
          printf("Closed by %s\n",try_id[i]);
          door=0;
          break;
        }
      }
      if(j==n-1)printf("Unknown %s\n",try_id[i]);
    }
  }


  return 0;

}

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


int main(){
	int N;cin>>N;
	map<long long,int> m;
	m[0] = 1;
	long long total = 0,ans = 0;
	for(int i=0;i<N;i++){
		int x;cin>>x;
		total += x;
		ans += m[total];
		m[total] += 1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 12800
import sys
k,a,b = map(int, input().split())

if b-a<=2 or a+1>k:
    print(1+k)
    sys.exit()


k -= a-1
ans = a
if k%2==0:
    ans += k//2*(b-a)
else:
    ans += (k-1)//2*(b-a)+1

print(ans)

Measured memory_bytes: 3064
import sys

input = sys.stdin.readline

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

if (b-a)%2 ==0:
    print((b-a)//2)

else:
    min_sabun = min(a-1,n-b)
    kyori = (b-a-1)//2
    print(min_sabun+kyori+1)

Measured memory_bytes: 8980
#include <iostream>
using namespace std;
typedef long long ll;
string s;

void solve() {
  cin >> s;
  ll sum, ans = 0;
  for (ll mask = 0; mask < (1 << (s.size() - 1)); mask++) {
    ll sum = ll(s[0] - '0');
    for (int i = 0; i < (s.size() - 1); i++) {
      if ((1 << i) & mask) {
        ans += sum;
        sum = 0;
      }
      sum = sum * 10 + (ll)(s[i + 1] - '0');
    }
    ans += sum;
  }

  cout << ans << endl;
}

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

Measured memory_bytes: 256
#include<iostream>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main(){
    char a[3];
    int count=0;
    cin>>a;
    rep(i,3){
        if(a[i]=='R'){
            count++;
        }
    }
    if(count==0){
        cout<<0;
        return 0;
    }else if(count==1){
        cout<<1;
        return 0;
    }else if(count==3){
        cout<<3;
        return 0;
    }else if(a[1]=='R'){
        cout<<2;
    }else{
        cout<<1;
    }
}

Measured memory_bytes: 3632
def vecprod(x1,y1,x2,y2) 
    return x1*y2-x2*y1
end

n = gets.to_i
x,y = 2.times.map{Array.new(n,0)}
n.times do |i|
    x[i],y[i] = gets.split.map(&:to_i)
end

l = [0]
for i in 1..n-1
    if x[i] < x[l[0]]
        l = [i]
    elsif x[i] == x[l[0]] && y[i] < y[l[0]]
        l = [i]
    end
end

while
    l.push(0)
    for i in 0..n-1
        p = vecprod(x[l[-1]]-x[l[-2]],y[l[-1]]-y[l[-2]],x[i]-x[l[-2]],y[i]-y[l[-2]])
        if p > 0 || (p == 0 && (x[l[-1]]-x[l[-2]])**2+(y[l[-1]]-y[l[-2]])**2 < (x[i]-x[l[-2]])**2+(y[i]-y[l[-2]])**2)
            l[-1] = i
        end
    end
    break if l[0] == l[-1]
end
ans = Array.new(n,0.0)
l.pop
m = l.size
for i in 0..m-1
    a = Math.atan(-(x[l[i]]-x[l[i-1]])/(y[l[i]]-y[l[i-1]]).to_f)
    b = Math.atan(-(x[l[i]]-x[l[(i+1)%m]])/(y[l[i]]-y[l[(i+1)%m]]).to_f)
    a += Math::PI if a <= b
    ans[l[i]] = (a-b)/2/Math::PI
end
puts ans

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

int main(){
#ifndef ONLINE_JUDGE
    freopen("ip.txt", "r", stdin);
    freopen("op.txt", "w", stdout);
#endif
	int n;
	cin >> n;
	vector<int> a(n), b(n), c(n);
	for(int i = 0; i < n; ++i){
		cin >> a[i] >> b[i] >> c[i];

	}

	int dp[n +1][3] = {0};
	dp[0][0] = a[0]; dp[0][1] = b[0]; dp[0][2] = c[0];

	for(int i = 1; i < n; ++i){
		dp[i][0] = max(dp[i -1][1] + a[i], dp[i -1][2] + a[i]);
		dp[i][1] = max(dp[i -1][0] + b[i], dp[i -1][2] + b[i]);
		dp[i][2] = max(dp[i -1][1] + c[i], dp[i -1][0] + c[i]);
	}

	cout << max({dp[n -1][0], dp[n -1][1], dp[n -1][2]}) << endl;

}

Measured memory_bytes: 5580
//Dragon_warrior7(IITK)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define maxin(v) *max_element(v.begin(), v.end())
#define minin(v) *min_element(v.begin(), v.end())
#define sumall(vect) accumulate(vect.begin(), vect.end(), 0)
#define count(x, vect) count(vect.begin(), vect.end(), x)
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 100000000000000000
#define deb(x) cout << #x << " " << x << "\n"
#define pll pair<ll, ll> 
#define vll vector<ll> 
#define rub cout << "------------------------------------\n"
//#define min(a, b, c) min(a, min(b, c))
//#define max(a, b, c) max(a, max(b, c))
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}

void print(vector<ll> v)
{
	for (int i = 0; i < v.size(); i++)
		cout << v[i] << " ";
}
ll n,m,a,b,temp;
string str;
set<ll> s;
vll v;
ll color[3][31];
ll cost[31][31];
ll repaint[3][31];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	ll c;
	cin>>c;
	for(int i=1;i<=c;i++)
	for(int j=1;j<=c;j++)
	cin>>cost[i][j];
	ll a[n+1][n+1];
	ll count[3]={0};
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++)
	{
	    cin>>a[i][j];
	    color[(i+j)%3][a[i][j]]++;
	    count[(i+j)%3]++;
	}
	ll mi=llmax;
	for(int k=0;k<=2;k++)
	{
	for(int i=1;i<=c;i++)
	{
	 ll sum=0;
	 for(int j=1;j<=c;j++)
	 {
	     sum+=cost[j][i]*color[k][j];
	 }
	 repaint[k][i]=sum;
	}
	}
	for(int i=1;i<=c;i++)
	{
	    for(int j=1;j<=c;j++)
	    {
	        if(j==i)
	        continue;
	        for(int k=1;k<=c;k++)
	        {
	           if(k==i || k==j)
	           continue;
	           mi=min(repaint[0][i]+repaint[1][j]+repaint[2][k],mi);
	        }
	    }
	}
	cout<<mi;
}

Measured memory_bytes: 2176
/*
  Vivek Rathi
  CSE 3rd Year
  MNNIT
*/
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
#define ll long long int
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define present(c,x) ((c).find(x) != (c).end())
#define null NULL
#define mp make_pair
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define inf 1e18
#define flush fflush(stdout);
//unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
//shuffle (foo.begin(), foo.end(), std::default_random_engine(seed));
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
ll modpower(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b>>=1;
	}
	return res;
}
//-------------------------------Template--Above-----------------------------------------------

int main()
{
	boost
	ll n;
	cin>>n;
	ll co=0;
	ll a[n],b[n],c[n];
	for(ll i=0;i<n;i++)
		cin>>a[i];
	for(ll i=0;i<n;i++)
	{
			cin>>b[i];
			co+=b[i];
	}
	for(ll i=0;i<n-1;i++)
		cin>>c[i];
	
	for(ll i=0;i<n-1;i++)
	{
		if(a[i]+1==a[i+1])
		{
			co+=c[a[i]-1];
		}
	}
	cout<<co<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
#define ll long long
const int maxi=2000000000;
const int maxq=1000000000;
const ll mod=1000000007LL;
#define f(i,a,b) for(int  i=(a); i<(b);++i)
/*
unsigned int countSetBits(unsigned int n)
{
    unsigned int count = 0;
    while (n) {
        count += n & 1;
        n >>= 1;
    }
    return count;
}
*/

/*
const int maxx=9000000;
void SieveOfEratosthenes(vector<int> &primes){
    bool IsPrime[maxx+1];
    memset(IsPrime, true, sizeof(IsPrime));
    for(int p=2;p*p<=maxx ;p++){
        if(IsPrime[p]){
            for(int i=p*p;i<maxx ;i+=p) IsPrime[i]=false;
        }
    }
    f(p,2,maxx +1){
        if(IsPrime[p]) primes.push_back(p);
    }
    }
*/
//int b[100];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k,sum=0;
    cin>>n>>k;
    int a[n];
    f(i,0,n) cin>>a[i];
    sort(a,a+n);
    f(i,0,k) sum+=a[i];
    cout<<sum<<endl;
    return 0;
}




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

int main(){
  long long n,a,b,c,d,e;
  cin>>n>>a>>b>>c>>d>>e;
  long long f=min({a,b,c,d,e});
  if(f==1) cout<<n/f+4<<endl;
  else cout<<n/f+5<<endl;
}

Measured memory_bytes: 256
N, u, v = map(int, input().split())
u, v = u-1, v-1

ABs = [list(map(lambda x:int(x)-1, input().split())) for _ in range(N-1)]

#%%
roots = [[] for _ in range(N)]

for AB in ABs:
    roots[AB[0]].append(AB[1])
    roots[AB[1]].append(AB[0])

#BFS
def BFS(roots, start):
    from collections import deque
    seen = [-1 for _ in range(N)]
    seen[start] = 0
    todo = deque([start])
    while len(todo) > 0:
        checking = todo.pop()
        for root in roots[checking]:
            if seen[root] == -1:
                seen[root] = seen[checking] +1
                todo.append(root)
    return seen

from_u = BFS(roots, u)
from_v = BFS(roots, v)

from collections import deque
todo = deque([u])
max_distance = from_v[u]
position = u
seen = [False for _ in range(N)]
seen[u] = True
while len(todo) > 0:
    checking = todo.pop()
    for root in roots[checking]:
        if from_u[root] < from_v[root] and seen[root] == False:
            seen[root] = True
            todo.append(root)

            if max_distance < from_v[root]:
                max_distance = from_v[root]
                position = root
            
print(max_distance-1)

Measured memory_bytes: 111040
#include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
int gs[101],n,tot,ans; 
int main()
{
	cin>>n>>tot;
	ans=n;
	for(int i=1;i<=n;i++)
	{
		cin>>gs[i];
		tot-=gs[i];
	}
	for(int i=1;i<=n;i++)
	{
		//cout<<ans<<endl;
		ans=max(ans,n+tot/gs[i]);
	}
	cout<<ans;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
ab.sort()
ans=0
for i in range(n):
    if m>ab[i][1]:
        ans+=ab[i][0]*ab[i][1]
        m-=ab[i][1]
    else:
        ans+=ab[i][0]*m
        print(ans)
        break


Measured memory_bytes: 27756
#include <stdio.h>
#include <math.h>

int main() {

  double d1,d2,d3,d4;
  int i,j,k,l,n;
  double x[1020] = {0};
  double y[1020] = {0};
  double z[1020] = {0};
  double o,p,q,max;
  max = -1;
  o=0;
  p=0;
  q=0;
  d1 = 0;
  d2 = 0;
  d3 = 0;
  d4 = 0;

  scanf("%d",&n);

  for(i=0; i<n; i++) {
    scanf("%lf",&x[i]);
  }

  for(i=0; i<n; i++) {
    scanf("%lf",&y[i]);
  }

  for(i=0; i<n;i++) {

    o = (x[i] - y[i]) * (x[i] - y[i]);
    p = (x[i] - y[i]) * (x[i] - y[i]) * (x[i] - y[i]);
    p = p*p;
    p = sqrt(p);
  
    d3 = d3 + p;
    d2 = d2+o;
    d1 = d1 + sqrt(o); 

    if(max < sqrt(o)) {
      max = sqrt(o);
    }

   
  }

  d2 = pow(d2,1.0/2);
  d3 = pow(d3,1.0/3);
  d4 = max;

  printf("%.11lf\n%.11lf\n%.11lf\n%.11lf\n" ,d1,d2,d3,d4);

  return 0;

}



Measured memory_bytes: 2048
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <bitset>
#include<vector>
#include<utility>
#include<fstream>
#include<queue>
#include <iomanip>
#include<numeric>
#include<set>
#include<map>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i,n) for(int i=0;i<n;i++)
char ca;
const int MOD = 1000000007;
ll  c = 0, d = 0, e = 0, f = 0,g=0, n, i, j, k, h, w, o, a[100005], b[10000] = {};
queue<ll> q;
string s;
pair<ll, ll> p[20][20];
vector<vector<ll>> v;
const int MAX = 2005;
long long fac[MAX], finv[MAX], inv[MAX];

int main() {
	cin >> n>>k;
	cin >> c >> d >> e;
	cin >> s;

	rep(i, n) {
		if (s[i] == 'r') f = e;
		if (s[i] == 's') f = c;
		if (s[i] == 'p') f = d;
		if (i >= k && s[i - k] == s[i]) {
			f = 0;
			s[i] = '0';
		}
		g += f;

		//cout << f << "\n";
	}

	cout << g;

	return 0;

}


Measured memory_bytes: 512
from collections import defaultdict
n=int(input())
a=[int(i) for i in input().split()]

dic={}
for idx, j in enumerate(a,1):
    dic[j]=idx


dic = sorted(dic.items() , key=lambda x:x[0])

li=[]
for i,j in dic:
    li.append(j)
print(*li)

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

typedef long long int ll;

vector <ll> h;
vector <ll> dp(100005);

bool isPrime(ll n) 
{ 
    // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
  
    // This is checked so that we can skip 
    // middle five numbers in below loop 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
}

int main()
{
    ios::sync_with_stdio(false);

    ll i,j,k,l,m,n;

    cin >> n;

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

        h.push_back(k);
    }

    if(n==2)
    {
        cout << abs(h[0]-h[1]) << '\n';
        return 0;
    }

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

    // cout << dp[0] << '\n';
    // cout << dp[1] << '\n';

    for(i=2;i<n;i++)
    {
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));

        // cout << dp[i] << '\n';
    }

    cout << dp[n-1] << '\n';





}

Measured memory_bytes: 2168
// I can't tell you what it really is,
// I can only tell you what it feels like.
#include "bits/stdc++.h"
using namespace std;
#define int long long
const int N = 10000 + 2;
const int mod = 1e9 + 7;

char s[N];
int dp[N][100][2], d, n;


int go(int id, int md, int cur, bool f = false) {
  if (id == n) {    
    return !md;
  }
  if (~dp[id][md][f]) return dp[id][md][f];
  long long ans = 0, dig = s[id] - '0';
  for (int i = 0; i < 10; ++i) {
    if (f == false && i > dig) break;
    ans += go(id+1, (md+i)%d, cur*10+i, f|(i<dig));
  }
  while (ans >= mod) ans -= mod;
  return dp[id][md][f] = ans;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> s >> d;
  memset(dp, -1, sizeof dp);  
  n = strlen(s);  
  int ans =  go(0,0,0) - 1;
  if (ans < 0) ans += mod;
  cout << ans;  
  return 0;
}
// 1). Try forming/rearranging the equations if any
// 2). If problem asks to count, try counting in reverse(it can be easier sometimes)

Measured memory_bytes: 16896
#include <iostream>
#include <string>

using namespace std;

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

  int A, B, C;
  cin >> A >> B >> C;

  // nA % B == C ?
  for(int i=1; i<B; i++){
	if(i*A % B == C){
	  cout << "YES" << endl;
	  return 0;
	}
  }
  cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256