akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.C_Challenge
{
    class ABC_080
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            var fs = new bool[n, 10];
            for (int i = 0; i < n; i++)
            {
                int[] fi = ReadInts();
                for(int j = 0; j < 10; j++)
                {
                    fs[i, j] = fi[j] == 1;
                }
            }
            var ps = new long[n, 11];
            for(int i = 0; i < n; i++)
            {
                long[] pi = ReadLongs();
                for(int j = 0; j <= 10; j++)
                {
                    ps[i, j] = pi[j];
                }
            }
            //bit全探索
            int allPat = (int)Math.Pow(2, 10);
            long surplus = long.MinValue;
            for(int i = 1; i < allPat; i++)
            {
                long surplusTemp = 0;
                for(int j = 0; j < n; j++)
                {
                    int bothCnt = 0;
                    for (int k = 0; k < 10; k++)
                    {
                        if (((i >> k) & 1) == 1 && fs[j, k])
                        {
                            bothCnt++;
                        }
                    }
                    surplusTemp += ps[j, bothCnt];
                }
                surplus = Math.Max(surplus, surplusTemp);
            }
            Console.WriteLine(surplus);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

int main() {
  cin>>x;
  long long currB=100;
  long long days=0;
  while(currB<x) {
  	long long currI=currB/100;
  	currB+=currI;
  	days++;
  }
  cout<<days;
  return 0;
}

Measured memory_bytes: 3624
def main():
    N, X = map(int, input().split())
    L = list(map(int, input().split()))
 
    ans = 1
    D = 0
    for i in range(N):
      D = D + L[i]
      if D <= X:
        ans+=1
        
    return ans
    
if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3060
from sys import stdin, stdout
import sys
INF=1e11
import bisect
def get_int(): return int(stdin.readline().strip())
def get_ints(): return map(int,stdin.readline().strip().split()) 
def get_array(): return list(map(int,stdin.readline().strip().split()))
def get_string(): return stdin.readline().strip()
def op(c): return stdout.write(c)
from collections import defaultdict 
import math
#for _ in range(int(stdin.readline())):
n=get_int()
if n%1000==0:
    print(0)
else:
    print(1000-n%1000)
    




Measured memory_bytes: 9392
import java.util.Scanner;

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

			for(int i=0;i<line.length();i++){
				char ch = line.charAt(i);
				if(Character.isLowerCase(ch)) answer = answer + Character.toUpperCase(ch);
				else answer = answer + Character.toLowerCase(ch);
			}
			System.out.println(answer);
		}
	}
}


Measured memory_bytes: 31476
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    a,b,x=parseMap(split(readline()))
    println(ifelse(0<=x-a<=b,"YES","NO"))
end
main()

Measured memory_bytes: 166788
import java.util.*;

public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int sx = sc.nextInt();
        int sy = sc.nextInt();
        int tx = sc.nextInt();
        int ty = sc.nextInt();
        sc.close();

        for(int i = 0; i < tx-sx; i++){
            System.out.print("R");
        }
        for(int i = 0; i < ty-sy; i++){
            System.out.print("U");
        }
        
        for(int i = 0; i < tx-sx; i++){
            System.out.print("L");
        }
        for(int i = 0; i < ty-sy; i++){
            System.out.print("D");
        }

        System.out.print("D");
        for(int i = 0; i < tx-sx+1; i++){
            System.out.print("R");
        }
        for(int i = 0; i < ty-sy+1; i++){
            System.out.print("U");
        }
        System.out.print("L");

        System.out.print("U");
        for(int i = 0; i < tx-sx+1; i++){
            System.out.print("L");
        }
        for(int i = 0; i < ty-sy+1; i++){
            System.out.print("D");
        }
        System.out.print("R");
    }
}

Measured memory_bytes: 22724
#include <iostream>
using namespace std;
int n,m,s[1000],a[1000],b[1000],ans,dp[1000][1001];
int main(void){
    while(1){
    cin>>n>>m;
    if(n==0&&m==0)return 0;
    ans=1e9;
    for(int i=0;i<n;i++)for(int j=0;j<=n;j++)dp[i][j]=1e9;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)cin>>b[i];
    for(int i=0;i<n;i++){
        if(a[i]<b[i])s[i]=b[i]-a[i];
        else if(a[i]>b[i])s[i]=m+b[i]-a[i];
        else s[i]=0;
    }
    dp[0][0]=s[0];
    for(int i=1;i<n;i++){
        for(int j=i;j>=0;j--){
            if(s[i]<=s[i-1]){
                dp[i][j]=min(dp[i][j],dp[i-1][j]);
                if(j>0)dp[i][j]=min(dp[i][j],dp[i-1][j-1]+m-s[i-1]+s[i]);
            }
            else{
                dp[i][j]=min(dp[i][j],dp[i-1][j]+s[i]-s[i-1]);
                dp[i][j]=min(dp[i][j],dp[i-1][j+1]);
            }
            //cout<<dp[i][j]<<endl;
        }
    }
    for(int i=0;i<=n;i++){
        ans=min(ans,dp[n-1][i]);
    }
    cout<<ans<<endl;
    }
}



Measured memory_bytes: 6996
import sys

sys.setrecursionlimit(10 ** 9)

H, W = map(int, input().split())
inputs = [input() for _ in range(H)]

visited = [[False for _ in range(W)] for _ in range(H)]
vectors = [[0, -1], [-1, 0], [0, 1], [1, 0]]
ans = 0

def dfs(h, w):
    # 入力された値はindex out of rangeにならないvalidationが掛けられている
    if visited[h][w]:
        return (0, 0)
    
    visited[h][w] = True

    if inputs[h][w] == '#':
        black, white = 1, 0 
    else:
        black, white = 0, 1

    for vector in vectors:
        next_h = h + vector[0]
        next_w = w + vector[1]
        if not (0 <= next_h < H and 0 <= next_w < W):
            continue
        next_color = inputs[next_h][next_w]
        if inputs[h][w] != next_color:
            p_black, p_white = dfs(next_h, next_w)
            black += p_black
            white += p_white

    return (black, white)

for h in range(H):
    for w in range(W):
        black, white = dfs(h, w)
        ans += black * white  

print(ans)


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

#define M 1046527
#define NIL -1
#define L 14

char H[M][L];

// 文字から数値に変換
int Char2int(char ch){
    if(ch == 'A'){
        return 1;
    }
    else if(ch == 'C'){
        return 2;
    }
    else if(ch == 'G'){
        return 3;
    }
    else if(ch == 'T'){
        return 4;
    }
    else{
        return 0;
    }
}

// 文字列から数値へ変換してキーを作成
long long getKey(char str[]){
    long long sum = 0, p = 1, i;
    for(i = 0; i < strlen(str); i++){
        // いわば5進数
        sum += p*(Char2int(str[i]));
        p *= 5;
    }
    return sum;
}

// ハッシュ関数
int h1(int key){ return key % M; }

int h2(int key){ return 1 + key % (M-1); }

int find(char str[]){
    long long key, i, h;
    key = getKey(str); // 文字列を数値に変換
    for(i=0;;i++){
        h = (h1(key) + i * h2(key)) % M;
        if(strcmp(H[h], str) == 0) return 1;
        else if(strlen(H[h]) == 0) return 0;
    }
    return 0;
}

int insert(char str[]){
    long long key, i, h;
    key = getKey(str); // 文字列を数値に変換
    for(i=0;;i++){
        h = (h1(key) + i*h2(key)) % M;
        if(strcmp(H[h], str) == 0) return 1;
        else if(strlen(H[h]) == 0){
            strcpy(H[h], str);
            return 0;
        }
    }
    return 0;
}

int main(){
    int i, n;
    char str[L], com[9];
    for(i=0;i<M;i++){
        H[i][0] = '\0';
    }
    scanf("%d", &n);
    for(i=0;i<n;i++){
        scanf("%s %s", com, str);

        if(com[0] == 'i'){
            insert(str);
        }
        else{
            if(find(str)){
                printf("yes\n");
            }
            else{
                printf("no\n");
            }
        }
    }
    return 0;
}


Measured memory_bytes: 17076
#include <iostream>
#include <vector>

using namespace std;

struct potential_union_find{
    vector<int> par, sz, diff_w;

    potential_union_find(int n) {
        par.resize(n);
        sz.resize(n);
        diff_w.resize(n);
        for (int i = 0; i < n; i++) {
            par[i] = i;
            sz[i] = 0; 
            diff_w[i] = 0;
        }
    }

    int find(int x) {
        if (par[x] == x)
            return x;
        else {
            int r = find(par[x]);
            diff_w[x] += diff_w[par[x]];
            return par[x] = r;
        }
    }

    int weight(int x) {
        find(x);
        return diff_w[x];
    }

    bool unite(int x, int y, int w) {
        w += weight(x); w -= weight(y);

        x = find(x), y = find(y);

        if (x == y)
            return false;
    
        if (sz[x] < sz[y]) {
            swap(x, y);
            w = -w;
        }

        if (sz[x] ==  sz[y])
            sz[x]++;
        par[y] = x;
        diff_w[y] = w;
        return true;
    }

    int diff(int x, int y) {
        return weight(y) - weight(x);
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }
};

int main() {
    int n, m;   cin >> n >> m;
    potential_union_find u(n);
    bool can = true;
    for (int i = 0; i < m; i++) {
        int r, l, d;    cin >> r >> l >> d;
        l--, r--;

        if (!u.same(r, l)) {
            u.unite(r, l, d);
        }
        else {
            if (u.diff(r, l) != d) {
                can = false;
            }
        }
    }
    if (can)
        cout << "Yes" << endl;
    else 
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;

ll ans=0;
ll keta[35];
ll k[10];

ll solve1(ll i,ll k){
    if(i<=10) return max(0ll,9*(ll)pow(10,i-1)-k+1);

    else {
        ll kk=9;
        i--;
        for(ll j=0;j<35;j++){
            if(i>>j&1){
                kk*=keta[j];
                kk%=Mod;
            }
        }
        return (kk-k+1+Mod)%Mod;
    }
}

ll gcd(ll a,ll b){
    if(a<b) swap(a,b);
    if(a%b==0) return b;
    else return gcd(b,a%b);
}

ll solve2(ll i,ll j,ll s){
    ll g=gcd(i,j);
    if(s%g!=0) return 0;
    s=s/g;
    ll i1=i/g;
    ll j1=j/g;

    ll p=0;
    while(s%j1!=0&&p<=j1){
        s-=i1;
        p++;
    }

    
    ll q=s/j1;

    ll ans=0;
    while(p<=k[i]){
        if(p>0&&q<=k[j]&&q>0) ans+=1;
        p+=j1;
        q-=i1;
    }

    return ans;
}

int main(){
    ll i,j,l;
    ll s;
    cin>>s;
    if(s==1) {
        cout<<9<<endl;
        return 0;
    }

    
    k[1]=9;
    for(i=2;i<10;i++) k[i]=10*k[i-1];

    keta[0]=10;
    for(i=1;i<35;i++) keta[i]=(keta[i-1]*keta[i-1])%Mod;

    for(i=1;i*i<=s;i++){
        if(s%i==0){
            if(i*i==s) ans+=solve1(i,s/i);
            else ans+=solve1(i,s/i)+solve1(s/i,i);
            ans%=Mod;
        }
    }

    for(i=9;i<s;i++){
        ll rr=ans;
        ll ss=s;
        ll p=ss%i;
        if(p==0) p=i;
        ss-=p*(i+1);
        if(ss>0) ans+=1+ ss/(i*(i+1));
        if(ss>0&&ss%(i*(i+1))==0) ans--;
        ans%=Mod;
    }

    for(i=1;i<=8;i++){
        for(j=i+1;j<=9;j++){
            ll ss=s;
            for(l=i+1;l<j;l++){
                ss-=k[l]*l;
            }
            if(ss>0){
                ans+=solve2(i,j,ss);
                ans%=Mod;
                
            } 
        }
    }

    cout<<(ans+Mod)%Mod<<endl;

    return 0;
    
   
}

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

int main(){
  int n;cin>>n;
  vector<long long> m(n+1);
  for(int i=0;i<n+1;++i)cin>>m[i];
  vector<long long> h(n);
  for(int i=0;i<n;++i)cin>>h[i];
  
  long long result = 0;
  
  for(int i=n-1;i>=0;--i){
    if(h[i]>=m[i+1]){
      result += m[i+1];
      h[i] -= m[i+1];
      m[i+1] = 0;
      if(h[i]>=m[i]){
        result += m[i];
        h[i] -= m[i];
        m[i] = 0;
      }else{
        result += h[i];
        m[i] -= h[i];
        h[i] = 0;
      }
    }else{
      result += h[i];
      m[i+1] -= h[i];
      h[i] = 0;
    }
  }
  
  cout<<result<<endl;
  
  return 0;
}

Measured memory_bytes: 1792
import sys
input = sys.stdin.readline
from heapq import heappop, heappush

t = int(input())
for i in range(t):
    n = int(input())
    C = [list(map(int,input().split())) for i in range(n)]
    L = []
    R = []

    ans = 0
    for i in range(n):
        k = C[i][0]-1
        l = C[i][1]
        r = C[i][2]
        ans += min(l,r)
        if l > r:
            L.append([r-l, k])
        elif l < r:
            R.append([l-r, k+1])

    L.sort(key=lambda x:x[1], reverse=True)
    R.sort(key=lambda x:x[1])

    LQ = []
    ind = 0
    for i in range(n-1,-1,-1):
        while ind < len(L) and L[ind][1] == i:
            heappush(LQ, L[ind])
            ind += 1
        if len(LQ) > 0:
            LL = heappop(LQ)
            ans += -LL[0]

    RQ = []
    ind = 0
    for i in range(n):
        while ind < len(R) and R[ind][1] == i:
            heappush(RQ, R[ind])
            ind += 1
        if len(RQ) > 0:
            RR = heappop(RQ)
            ans += -RR[0]
    # print(LQ,RQ)
    print(ans)

Measured memory_bytes: 130944
#include<iostream>
#include<math.h>
#include<vector>
#include <algorithm>
#include <string>
#include <unordered_map>

using namespace std;

int main(){
  unordered_map<char,char> mp;
  mp['A'] = 'T';
  mp['T'] = 'A';
  mp['C'] = 'G';
  mp['G'] = 'C';
  
  char ch;
  cin >> ch;
  cout << mp[ch];
  return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

// 最大公約数 : 3,4 ->  1
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

void solve()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; ++i)
  {
    cin >> a[i];
  }

  vector<int> L(n, 0), R(n, 0);
  for(int i = 0; i < n - 1; ++i)
  {
    L[i + 1] = gcd(L[i], a[i]);
  }
  for(int i = n - 1; i >= 1; --i)
  {
    R[i - 1] = gcd(R[i], a[i]);
  }

  /*
  for(const auto& l : L)
  {
    cout << l << " ";
  }
  cout << endl;
  for(const auto& l : R)
  {
    cout << l << " ";
  }
  cout << endl;
  //*/

  int ans = 0;
  for(int i = 0; i < n; ++i)
  {
    ans = max(ans, (int)gcd(L[i], R[i]));
  }
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

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

int main() {
  int k,s; cin>>k>>s;
  int ans=0;
  if(s%3==0)ans++;
  int ans2=0;
  if(s<=k){ans2+=s/2+1;}
  else if(s/2<=k){ans2+=s/2-(s-k+1)/2+1;}
  else{ans2+=k-(s-k+1)/2+1;}
  if(s%3==0)ans2--;
  ans2*=3;
  int ans3=0;
  for(int i=k; i>=0; i--){
    for(int j=i-1; j>=0; j--){
      if(s-i-j<j && 0<=s-i-j){ans3++;}
    }
  }
  ans3*=6;
  ans+=ans2+ans3;
  cout<<ans;
}



Measured memory_bytes: 3564
using System;

public class Hello
{
    public static void Main()
    {
        var a1 = "maerd";
        var a2 = "esare";
        var a3 = "resare";
        var a4 = "remaerd";
        var s2 = Console.ReadLine().Trim();
        var w = s2.ToCharArray();
        Array.Reverse(w);
        var s = new string(w);
        var sL = s.Length;
        var p = 0; var w5 = "";
        while (p < s.Length)
        {
            if (p + 5 > sL) { Console.WriteLine("NO"); break; }
            w5 = s.Substring(p, 5);
            if (p + 5 == sL && (w5 == a1 | w5 == a2)) { Console.WriteLine("YES"); break; }
            if (p + 6 == sL && s.Substring(p, 6) == a3) { Console.WriteLine("YES"); break; }
            if (p + 7 == sL && s.Substring(p, 7) == a4) { Console.WriteLine("YES"); break; }
            if (w5 == a1 | w5 == a2) { p += 5;  goto next; }
            if (p + 6 < sL && s.Substring(p, 6) == a3) { p += 6; goto next; }
            if (p + 7 < sL && s.Substring(p, 7) == a4) { p += 7; goto next; }
            { Console.WriteLine("NO"); break; }
            next:;
        }
    }
}


Measured memory_bytes: 13140
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int x = sc.nextInt();
    int[] a = new int[N];
    for (int i = 0; i < N; i++) {
      a[i] = sc.nextInt();
    }
    Arrays.sort(a);
    int ans = 0;
    for (int i = 0; i < N - 1; i++) {
      if (a[i] <= x) {
        x -= a[i];
        ans++;
      }
    }
    if (a[N - 1] == x) {
      ans++;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
int r,c,n,x,y,ans[200][200];
int main(void)
{
    scanf("%d%d%d",&r,&c,&n);
    x=1,y=1;
    for(int i=1,cnt;i<=n;i++){
        scanf("%d",&cnt);
        while(cnt--){
            ans[x][y]=i;
            if(y==c&&x%2==1)
                y=c,x++;
            else if(y==1&&x%2==0)
                y=1,x++;
            else if(x&1)
                y++;
            else
                y--;
        }
    }
    for(int i=1;i<=r;i++)
    for(int j=1;j<=c;j++)
        printf("%d%c",ans[i][j],j==c?'\n':' ');
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
using namespace std;
  
int a[20000];

int main(){
	int n,m;
	while(cin>>n>>m&&(n||m)){
		int ans=0;
		for(int i=0;i<n+m;i++)cin>>a[i];
		sort(a,a+n+m);
		int prev=0;
		for(int i=0;i<n+m;i++){
			ans=max(ans,a[i]-prev);
			prev=a[i];
		}
		cout<<ans<<endl;
	}
    return 0;
}

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

int main() {
	int k,a,b;
	cin>>k>>a>>b;
	if(b%k==0 || a%k==0)
		cout<<"OK"; 
	else if(((b/k)-(a/k))>=1)
      cout<<"OK";
  else cout<<"NG";
	return 0;
}


Measured memory_bytes: 3620
from sys import stdin

s = stdin.readline().rstrip()

mae = s[:2]
ato = s[2:]

def syoukyo(i):
    if i[0] == 0:
        i = i[1]
    return int(i)

mae = syoukyo(mae)
ato = syoukyo(ato)

if (mae > 12 or mae == 0) and 0 <ato < 13:
    print("YYMM")
elif 0 <mae < 13 and( ato > 12 or ato == 0):
    print("MMYY")
elif 0 <mae < 13 and 0 <ato < 13:
    print("AMBIGUOUS")
else:
    print("NA")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define INF 1e18
#define MOD 1000000007
#define PI M_PI
#define ll long long
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define REP(i, n) for (int i=0; i<n; i++)
#define REPD(i, n) for (int i=n-1; i>=0; i--)
#define print(x) cout << x << endl;
#define debug(x) cout << #x << " = " << endl;

using namespace std;

void solve()
{
    int r;
    cin >> r;
    print(r*r);
}

int main()
{
    solve();

    return 0;
}

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

#define check(i) \
  do{ \
    cout << i << endl; cin >> S; \
    if(S == "Vacant") return 0; \
  } while(0)

int N;
string S;
string T;

int main() {
  cin >> N;
  check(0); T = S; check(N - 1);
  int l = 0, r = N;
  while(true) {
    int m = (l + r) / 2;
    check(m);
    if(((m - l) % 2 == 1) == (S == T)) r = m;
    else { l = m; T = S; }
  }
}


Measured memory_bytes: 852
n = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = gets.chomp.to_i
puts "#{n[k-1]}"


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);

typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef long long int lli;
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,pair<int,int>> ddp;
typedef pair<long long,pll> ldp;

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(v) v.begin(), v.end()
#define fi(n) for(int i=0;i<(n);i++)
#define fj(n) for(int j=0;j<(n);j++)
#define fk(n) for(int k=0;k<(n);k++)
#define mod 1000000007
#define MAX 100000+5;

int main()
    {
        fastio
        lli n ,l;
        cin >> n >> l;
        lli x,min=1000000007,sum=0;
        fi(n)
        {
            x = i+1 + l -1;
            sum+=x;
            if(abs(x)<min)
            min=abs(x);
        }
if(sum<0)
        cout << sum+min;
        else
        cout << sum-min;
        return 0;
    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb          push_back
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define endl        "\n"
#define fast        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int         long long int
#define mod         1000000007
#define test        int t;cin>>t;while(t--)
#define REP(i,a,b)  for(int i=a,i<=b;i++)
#define MAXN        200001

int dp[3001][3001];
int solve(string &str1,string &str2,int n,int m)
{
    if(n==0 || m==0)
        return 0;
    else if(dp[n][m]!=-1)
        return dp[n][m];
    else
    {
        if(str1[n-1]==str2[m-1]){
            return dp[n][m]=1+ solve(str1,str2,n-1,m-1);
        }
        else
            return dp[n][m]=max(solve(str1,str2,n,m-1),
                solve(str1,str2,n-1,m));
    }
}
int32_t main()
{
    fast;
    string str1,str2;
    cin>>str1>>str2;

    int n=str1.length(),m=str2.length();
    memset(dp,-1,sizeof(dp));
    solve(str1,str2,str1.length(),str2.length());

    string ans="";
    while(n> 0 && m>0){

        // cout<<"Im in loop"<<endl;
        if(str1[n-1]==str2[m-1]){
            ans.pb(str1[n-1]);
            n=n-1;m=m-1;
        }
        else{
            if(dp[n][m]==dp[n-1][m])
                n=n-1;
            else
                m=m-1;
        }
    }

    reverse(all(ans));
    cout<<ans<<endl;
    return 0;
}

// 1 1 2 2 2 3 3 4 5 6 

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

int main() {
    int r,g,b;
    cin >> r >> g >> b;
    int total;
    total = r*100 + g*10 + b;
    if(total % 4 == 0){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/tenka1-2019-beginner/tasks/tenka1_2019_b

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  ll N, K;
  string S;
  cin >> N >> S >> K;

  char masked = S[K - 1];

  string res = S;

  for (auto& c : res) {
    if (c != masked) c = '*';
  }

  cout << res << "\n";
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int n, k; cin >> n >> k;
    if (k > (n-2)*(n-1)/2) {
        cout << -1 << endl;
        return 0;
    }
    vector<vector<int>> g(n, vector<int>(n,1));
    int cnt = 0;
    rep(i,n-1) repf(j,i+1,n-1) {
        if (cnt >= k) {
            break;
        }
        cnt++;
        g[i][j] = g[j][i] = 0;
    }

    cout << n*(n-1)/2-cnt << endl;
    rep(i,n) repf(j,i+1,n) {
        if (g[i][j]) {
            cout << i+1 << " " << j+1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
h,w=map(int,input().split())
l=list()
l.append('#'*(w+2))
for i in range(h):
    l.append("#"+input()+"#")
l.append('#'*(w+2))
si=[[0 for i in j] for j in l]
sj=[[0 for i in j] for j in l]
for i in range(h+2):
    k=0
    for j in range(w+2):
        if l[i][j]==".":
            k+=1
        else:
            for f in range(j-k,j):
                si[i][f]=k
            k=0
for j in range(w+2):
    k=0
    for i in range(h+2):
        if l[i][j]==".":
            k+=1
        else:
            for f in range(i-k,i):
                sj[f][j]=k
            k=0
ans=0
for i in range(h+2):
    for j in range(w+2):
        ans=max(ans,sj[i][j]+si[i][j])
print(ans-1)

Measured memory_bytes: 144928
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pa;
typedef unsigned int uint;
typedef unsigned long long ull;
int main() {
	ll a, b, c, d, ans[10];
	cin >> a >> b >> c >> d;
	ans[0] = a * c;
	ans[1] = b * c;
	ans[2] = a * d;
	ans[3] = b * d;
	sort(ans, ans + 4);
	cout << ans[3] << endl;


	return 0;
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
using namespace std;

using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define N  200005

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        vi adj[N];
        ll n;
        cin>>n;
        rep(i,2,n+1)
        {
            ll x;
            cin>>x;
            adj[x].pb(i);
            adj[i].pb(x);
        }   
        adj[1].pb(1);     
        rep(i,1,n+1)
        {
            cout<<adj[i].size()-1<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 16176
#pragma GCC optimize("Ofast")
#include <set>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <bitset>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy 2333333
#define bql 2147483647
#define ll long long
using namespace std;
int n;
double a[55];
double sum;
int main()
{
	//fast;
	cin>>n;
	for (int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	sum=(a[1]+a[2])/2;
	for (int i=3;i<=n;i++)
	{
		sum=(sum+a[i])/2;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main()
{
    int A, B;
    cin >> A >> B;
    cout << A * B << endl;

    return 0;
}


Measured memory_bytes: 3188
n = int(input())

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

A = []
ans = int(0)

for i in range(n):
    am = a[i] % 2
    if am == 0:
        A.append(a[i])
        continue

for i in range(len(A)):
    x = A[i] % 3
    y = A[i] % 5
    if x != 0 and y != 0:
        ans += 1
        continue


if ans == 0:
    print("APPROVED")
else:
    print("DENIED")


Measured memory_bytes: 3064
#include <stdio.h>

int	main(void)
{
  unsigned long long	N;
  unsigned long long	A;
  unsigned long long	B;
  int	num;
  unsigned long long	set;
  unsigned long long	turn;
  unsigned long long	amari;
  unsigned long long	ans;
  
  num = scanf("%llu %llu %llu", &N, &A, &B);
  if (num != 3)
    return (0);
  
  set = A + B;
  turn = N / set;
  amari = N % set;
  if (A < amari)
    amari = A;
  
  ans = A * turn + amari;
  printf("%llu", ans);
  return (0);
}
  

Measured memory_bytes: 128
#include <stdio.h>
main(){
  int i, j, c = 0, f, k;
  int r[100];

  scanf("%d", &k);
  
  for(i = 0;i < k;i++){
    scanf("%d", &r[i]);
  }

  f = 1;
  while(f){
    f = 0;
      for(j=k-1;j>=1;j--){
        if(r[j] < r[j-1]){
          i = r[j-1];
          r[j-1] = r[j];
          r[j] = i;
          f = 1;
          c++;
        }
      }

  }
  for(i = 0;i < k-1;i++){
    printf("%d ", r[i]);
  }
  printf("%d\n", r[i]);
  printf("%d\n", c);
  return 0;
}

Measured memory_bytes: 600
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

uint32_t nextpint(void){ char c=getchar_unlocked(); while(c<'0'||'9'<c) c=getchar_unlocked(); uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return x; }

int main(void){
	char c, C;
	while((C=getchar())!=10){
		c=C;
	}
	if(c=='3'){
		putchar_unlocked('b');
	}else if(c=='0'||c=='1'||c=='6'||c=='8'){
		putchar_unlocked('p');
	}else{
		putchar_unlocked('h');
	}
	putchar_unlocked('o');
	putchar_unlocked('n');
	putchar_unlocked(10);
}


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

bool is_square(int n)
{
    for (int i = 0; i <= n; i++)
    {
        if (i * i == n)
        {
            return true;
        }
    }
    return false;
}

int main()
{
    int n;
    cin >> n;
    int ans = 0;
    int cur = 0;
    for (size_t i = 1; i <= n; i++)
    {
        int a;
        cin >> a;
        if (a == cur + 1)
        {
            cur++;
        }
        else
        {
            ans++;
        }
    }
    if (cur == 0)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
#define PI pair<int,int>
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
	write(a); puts("");
}
inline int rnd(int x){
	return rand()%x;
}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=100005;
int n,a[N];
bool solve(){
	int sum=0,sss=0,flag=0;
	for(int i=1;i<=n;i++)if(a[i]%2==0)sum++; else sss++;
	for(int i=1;i<=n;i++)if(a[i]==1)flag=1; if(flag)return sum&1;
	if(sum&1)return 1; else if(sss>=2)return 0;
	for(int i=1;i<=n;i++)if(a[i]&1)a[i]--;
	int t=0;
	for(int i=1;i<=n;i++)t=__gcd(t,a[i]);
	for(int i=1;i<=n;i++)a[i]/=t;
	return solve()^1;
}
int main(){
	//freopen("std.in","r",stdin); freopen("my.out","w",stdout);
	n=read(); 
	for(int i=1;i<=n;i++)a[i]=read();
	if(n==1){
		if(a[1]==1)puts("Second"); else puts("First"); return 0;
	}
	puts(solve()?"First":"Second");
}
/*
2 1
2 6
3 4
3 5

(2,3) (1,6) (1,4) (1,5) (
(1,2)-(1连出的点，2连出的点）
*/

Measured memory_bytes: 640
#include <stdio.h>

int gcd(int a,int b){
    /* 自然数 a > b を確認・入替 */
    int tmp,r;
    if(a<b){
      tmp = a;
      a = b;
      b = tmp;
    }

    /* ユークリッドの互除法 */
    r = a % b;
    while(r!=0){
      a = b;
      b = r;
      r = a % b;
    }
    return b;
}

int main(void){

    int k;
    scanf("%d",&k);
    int sum=0,a,b,c;

    for(a=1;a<k+1;a++){
        for(b=1;b<k+1;b++){
            for(c=1;c<k+1;c++){
                sum+=gcd(gcd(a,b),c);
            }
        }
    }
    printf("%d\n",sum);



    return 0;
}


Measured memory_bytes: 1736
#include <iostream>
using namespace std;
#define MAX 100005
#define NIL -1
 
struct Node { int p, l, r;};
 
Node T[MAX];
int n, D[MAX];
 
void print(int u) {
  int i,c;
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].p << ", ";
  cout << "depth = " << D[u] << ", ";
 
  if( T[u].p == NIL ) cout << "root, ";
  else if( T[u].l == NIL ) cout << "leaf, ";
  else cout << "internal node, ";
 
  cout << "[";
 
  for(i=0, c=T[u].l; c!=NIL; i++,c=T[c].r) {
    if(i) cout <<", ";
    cout << c;
  }
  cout << "]" << endl;
}
 
void rec(int u, int p) {
  D[u] = p;
  if(T[u].r != NIL) rec(T[u].r,p);
  if(T[u].l != NIL) rec(T[u].l,p+1);
}
 
int main(void) {
  int i,j,d,v,c,l,r;
  cin >> n;
  for(i=0;i<n;i++) T[i].p = T[i].l = T[i].r = NIL;
  for(i=0;i<n;i++) {
    cin >> v >> d;
    for(j=0;j<d;j++) {
      cin >> c;
      if(j==0) T[v].l=c;
      else T[l].r =c;
      l = c;
      T[c].p = v;
    }
  }
  for(i=0;i<n;i++) {
    if(T[i].p == NIL) r = i;
  }
   
  rec(r,0);
   
  for(i=0;i<n;i++) print(i);
   
  return 0;
}



Measured memory_bytes: 7668
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
int main()
{
	// ABC075-C, 1068, 
	int n, m; cin >> n >> m;
	vector<vector<int>> g(n);
	vector<P> p(m);
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		p[i] = make_pair(a, b);
		g[a].push_back(b);
		g[b].push_back(a);
	}
	int ans = 0;
	for (int i = 0; i < m; ++i) {
		vector<vector<int>> gg = g;
		gg[p[i].first].erase(find(gg[p[i].first].begin(), gg[p[i].first].end(), p[i].second));
		gg[p[i].second].erase(find(gg[p[i].second].begin(), gg[p[i].second].end(), p[i].first));

		vector<int> dist(n, -1);
		queue<int> que;

		dist[0] = 0;
		que.push(0);

		while (!que.empty()) {
			int v = que.front();
			que.pop();

			for (int nv : gg[v]) {
				if (dist[nv] != -1) continue;

				dist[nv] = dist[v] + 1;
				que.push(nv);
			}
		}

		bool ok = true;
		rep(j, n) {
			if (dist[j] == -1) ok = false;
		}
		if (!ok) ans++;
	}
	cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3620
main :: IO()
main = do
    [x,a,b] <- map read . words <$> getLine
    putStrLn $ getsolve x a b
    
getsolve :: Int -> Int -> Int -> String
getsolve x a b
    | a+x < b		= "dangerous"
    | a < b			= "safe"
    | otherwise		= "delicious"

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;
struct Cake {
    ll data[3];
};

ll solve(Cake *cake,int n,int m,const int sign[3]){
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            ll a=0,b=0;
            REP(k,3)a+=cake[i].data[k]*sign[k],b+=cake[j].data[k]*sign[k];
            if(a>b)swap(cake[i],cake[j]);
        }
    }

    ll sum=0;
    REP(i,m){
        REP(j,3){
            sum+=cake[n-1-i].data[j]*sign[j];
        }
    }

    return sum;
}

int main(){
    ios::sync_with_stdio(false);
    ll n,m;
    const int sign[8][3]={{1,1,1},{1,1,-1},{1,-1,1},{1,-1,-1},
        {-1,1,1},{-1,1,-1},{-1,-1,1},{-1,-1,-1}};
    Cake cake[1001];
    int dp[1001];
    cin >> n >> m;
    REP(i,n){
        ll a,b,c;
        cin >> a >> b >> c;
        cake[i].data[0]=a;
        cake[i].data[1]=b;
        cake[i].data[2]=c;
    }
    ll res = 0;
    REP(i,8){
        ll t = solve(cake,n,m,sign[i]);
        res = max(t,res);
    }
    cout << res << endl;

}


Measured memory_bytes: 256
N = int(input())
dp=list(range(N+1))

i = 6
while i <= N:
    for j in range(i,N+1):
        dp[j] = min(dp[j],1+dp[j-i])
    i = i*6
i = 9
while i <= N:
    for j in range(i,N+1):
        dp[j] = min(dp[j],1+dp[j-i])
    i = i*9

print(dp[N])

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

    typedef long long int ll;

    #define MOD (ll)(1e9+7)
    #define endl "\n"
    #define pb push_back
    #define TEST_CASES  ll t;cin >> t;while(t--)
    #define forn(i,a,n) for (int i = a; i < n; ++i)
    #define f first
    #define s second
    #define all(x) x.begin(), x.end()
    
    ll powD(ll x,ll y){
      ll res = 1;
      while(y > 0){
        if(y & 1)
          res = (res*x)%MOD;
        x = (x*x)%MOD;
        y = y>>1;
      }
      return res;
    }

    int n,m,q;
    vector<vector<int>> Q(50,vector<int>(4));
    vector<int> freq(11,0);
    int score(){
      vector<int> arr;
      forn(i,1,m+1){
        forn(j,0,freq[i])
          arr.push_back(i);
      }
      int sum = 0;
      forn(i,0,q){
        int a = Q[i][0]-1;
        int b = Q[i][1]-1;
        int c = Q[i][2];
        int d = Q[i][3];
        if(arr[b] - arr[a] == c)
          sum += d;
      }
      /*cout<<sum<<endl;
      forn(i,0,n){
        cout<<arr[i]<<" ";
      }
      cout<<endl;*/
      return sum;
    }
    int maxscore = -1;
    void f(int I,int n){
      if(I == m){
        freq[I] = n;
        maxscore = max(maxscore,score());
        return;
      }
      forn(i,0,n+1){
        freq[I] = i;
        f(I+1,n-i);
      }
    }


  
    int main()
    {
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      cin>>n>>m>>q;
      forn(i,0,q){
        forn(j,0,4){
          cin>>Q[i][j];
        }
      }
      f(1,n);
      cout<<maxscore<<endl;
      


    }
    //read the question correctly (ll vs int)


Measured memory_bytes: 3664
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#define MOD 1000000007
#define INF (1ll<<60)
typedef long long ll;
using namespace std;

ll x[100000];
ll index_zero;
ll n, k;

ll cnt(ll l){
    ll a = 0, b = 0;
    ll r = l + k - 1;
    if (x[r] > 0)a = x[r];
    else a = 0;
    if (x[l] < 0) b = -x[l];
    else b = 0;
    if (a > b){
        return a + 2*b;
    } else {
        return 2*a + b;
    }
}

int main(){
    cin >> n >> k;
    for (int i = 0; i < n; i++){
        cin >> x[i];
    }

    index_zero = lower_bound(x, x+n, 0) - x - 1;
    //cout << index_zero-1 << endl;
    ll l = 0, r = 0;
    for (; l + k <= index_zero; l++);
    long long res = INF;
    for (ll i = l; i + k <= n; i++){
        //cout << "cnt(" << i << ") = " << cnt(i) << endl;
        res = min(res, cnt(i));
    }
    cout << res << endl;
}


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

int main(){

    string s;
    cin >> s;
    int n = s.length();
    rep(i,n/2){
        
        if(s[i] != s[n-1 - i]){
            cout << "No" << endl;
            return 0;
        }

    }

    rep(i,s.substr(0,(n-1)/2).length()/2){

        if(s.substr(0,(n-1)/2)[i] != s.substr(0,(n-1)/2)[s.substr(0,(n-1)/2).length()-1 - i]){
            cout << "No" << endl;
            return 0;
        }

    }

    rep(i,s.substr((n+3)/2-1).length()/2){
        if(s.substr((n+3)/2-1)[i] != s.substr((n+3)/2-1)[s.substr((n+3)/2-1).length()-1 - i]){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}




Measured memory_bytes: 256
import java.util.Scanner;
public class Main
{
	public static void main(String arg[])
	{
		Scanner in = new Scanner(System.in);
		while(in.hasNext())
		{
			int n=in.nextInt();
			if(n==0)
				return;
			int max=0;
			int min=500;
			while(n-->0)
			{
				int s=0;
				for(int i=0;i<5;i++)
					s+=in.nextInt();
				if(max<=s)
					max=s;
				if(min>=s)
					min=s;
			}
			System.out.println(max+" "+min);
		}
	}
}

Measured memory_bytes: 12000
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var firstLine = Console.ReadLine().Split(' ').Select(value => int.Parse(value)).ToList();
			var one = firstLine[0] * firstLine[1];
			var two = firstLine[2] * firstLine[3];

			Console.WriteLine(Math.Max(one, two));
		}
	}
}


Measured memory_bytes: 13268
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    ls = [0] * n
    ls[0] = sum(a) - sum(a[1::2]) * 2
    for i in range(1, n):
        ls[i] = (a[i-1] - ls[i-1] // 2) * 2
    print(*ls)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 63856
import sys

n = input()
events = []
for line in sys.stdin:
    events.append(line.strip())

out = 0
score = 0
runner = 0
for event in events:
    if event == 'OUT':
        out += 1
        if out == 3:
            print score
            out = 0
            score = 0
            runner = 0
    elif event == 'HIT':
        if runner == 3:
            score += 1
        else:
            runner += 1
    elif event == 'HOMERUN':
        score += runner+1
        runner = 0

Measured memory_bytes: 6376
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<queue>
#define ll long long
#define maxn 200010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static int buf[20],len; len=0;
	if(x<0)x=-x,putchar('-');
	for(;x;x/=10)buf[len++]=x%10;
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]+'0');
}
inline void writeln(ll x){write(x); putchar('\n');}
inline void writesp(ll x){write(x); putchar(' ');}
struct Data{
	ll id,dis;
	friend bool operator < (Data a,Data b){return a.dis>b.dis;}
};
std::priority_queue<Data>q;
struct edge{
	int to,nxt,d;
}e[2*maxn];
int fir[maxn],mark[maxn];
ll dist[maxn];
int n,m,tot;
inline void add_edge(int x,int y,int z){e[tot].to=y; e[tot].d=z; e[tot].nxt=fir[x]; fir[x]=tot++;}
void dijkstra(int S)
{
	for(int i=1;i<=n;i++)
		mark[i]=0,dist[i]=1ll<<60;
	dist[S]=0;
	q.push((Data){S,dist[S]});
	while(!q.empty()){
		Data now=q.top(); q.pop();
		if(mark[now.id])continue;
		mark[now.id]=1;
		for(int i=fir[now.id];~i;i=e[i].nxt)
			if(dist[e[i].to]>dist[now.id]+e[i].d){
				dist[e[i].to]=dist[now.id]+e[i].d;
				q.push((Data){e[i].to,dist[e[i].to]});
			}
	}
}
int main()
{
	n=read(); m=read();
	memset(fir,255,sizeof(fir)); tot=0;
	for(int i=1;i<=m;i++){
		int l=read(),r=read(),k=read();
		add_edge(l,r,k);
	}
	for(int i=1;i<n;i++)
		add_edge(i+1,i,0);
	dijkstra(1);
	if(dist[n]<1ll<<60)writeln(dist[n]);
	else puts("-1");
	return 0;
}

Measured memory_bytes: 6648
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)


int main(){
    int n,a,b;
    cin >> n >> a >> b;
    cout << min(a,b) << " "<< max(0,a+b-n)  << endl;
    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <cstdlib> //abs(int x)
using namespace std;

int n;

int solve(int* H){
  int C[n];
  C[0] = 0;
  C[1] = abs(H[1]-H[0]);
  for (int i=2; i<n; i++){
    C[i] = min(C[i-1]+abs(H[i]-H[i-1]), C[i-2]+abs(H[i]-H[i-2]));
  }
  return C[n-1];
}

// 
int main(){
  cin >> n;
  int H[n];
  for (int i=0; i<n; i++){
    cin >> H[i];
  }
  cout << solve(H) << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<cmath>

using std::cout;
using std::cin;
using std::endl;
using std::pow;
using std::string;

int main(){
    long long int a,out,c;
    double b;
    cin >> a >> b;
    c = b*100 + 1e-1;
    out = a*c/100;
    cout << out;
}

Measured memory_bytes: 3732