akhauriyash/Code-Regression huggingface dataset:
# frozen_string_literal: true

input = gets.chomp.split
a = input[0].to_i
b = input[1].to_i
c = input[2].to_i
k = input[3].to_i

point = 0
ka = k - a
if ka <= 0
    point = k
else
    point = a
    kb = ka - b
    if kb > 0
        # kc = kb - c
        # if kc <= 0
        #     point = a - c
        # else
            point = a - kb
        # end
    end
end

puts point


Measured memory_bytes: 14328
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<map>
#include<bitset>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,int> pint;
typedef pair<long long,pint> p3;
typedef long long ll;
const int inf   = 1e9+7;
const ll  longinf = 1LL<<60;
const int mod=1e9+7;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};



int main(){
  int n,c,k;
  cin>>n>>c>>k;
  int a[n];
  rep(i,n)cin>>a[i];
  sort(a,a+n);
  int cnt=1,t=a[0]+k,ans=1;
  rep(i,n-1){
    if(cnt==c||a[i+1]>t){
      ans++;
      t=a[i+1]+k;
      cnt=1;
      }
    else cnt++;
    }
  cout<<ans<<endl;
  return 0;
  }

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

const int N = 2005, mod = 1000000007;

int dp[N][N], sum[N][N], n, k;
void up(int &x, int y) { x += y - mod, x += x >> 31 & mod; }

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n >> k;
	dp[0][n + 1] = 1; for (int i = 1; i <= n + 1; ++i) sum[0][i] = 1;
	for (int i = 1; i < k; ++i) {
		for (int j = 1; j <= n - i + 1; ++j)
			up(dp[i][j] = dp[i - 1][j], sum[i - 1][j + 1]);
		for (int j = n; j >= 1; --j) up(sum[i][j] = sum[i][j + 1], dp[i][j]);
	}
	int ans = sum[k - 1][2];
	for (int i = 0; i < n - k - 1; ++i) up(ans, ans);
	std::cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 31360
"""
N= 4
K = [2, 2, 1, 3]
"""

N = int(input())
K = list(map(int,input().split()))





K = sorted(K,reverse=True)
"""
#print(K)
before_data = 0
before_data_before = 0
ans = 0 
for i in K :
    ans += before_data
    before_data_before = before_data
    before_data = i
"""
ans = 0 
for i,l in enumerate(K) :
    if (i == 0 ):
        ans += 0
    
    else :
        ans += K[i // 2]

    


print(ans)

Measured memory_bytes: 31000
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
def init_dp1(init, N): return [init for _ in range(N)]
def init_dp2(init, N, M): return [[init for _ in range(M)] for _ in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def main():
    N, M = read_values()

    L = [set() for _ in range(N)]
    C = [0] * N
    S = {i for i in range(N)}
    for _ in range(N + M - 1):
        u, v = read_index()
        L[u].add(v)
        C[v] += 1
        if v in S:
            S.remove(v)

    Q = queue.Queue()
    for s in S:
        Q.put(s)

    P = ["0"] * N    
    while not Q.empty():
        s = Q.get()
        for w in L[s]:
            P[w] = str(s + 1)
            C[w] -= 1
            if C[w] == 0:
                Q.put(w)

    print("\n".join(P))


if __name__ == "__main__":
    main()


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

int main()
{
    int n;
    cin>>n;
    long long int k=1,a[n+1];
    int e=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(a[i]==0)
        e=1;
        if(a[i]>1000000000000000000)
        e=2;
    }
    if(e==1)
    {
        cout<<0;
        return 0;
    }
    if(e==2)
    {
        cout<<-1;
        return 0;
    }
    //sort(a,a+n)
    for(int i=1;i<=n;i++)
    {
        string s=to_string(a[i]);
        string s1=to_string(k);
        int d=s.length()-1;
        int e1=s1.length()-1;
        int f=d+e1;
        int g=(s[0]-'0')*(s1[0]-'0');
        string s2=to_string(g);
        f+=s2.length()-1;
        int d1=s2[0]-'0';
        if(f>18)
        {
            e=1;
            break;
        }
        if(f==18 && d1>1)
        {
            e=1;
            break;
        }
        k=k*a[i];
        
        
        if(k>1000000000000000000)
        break;
    }
    if(k>1000000000000000000 || e==1)
    cout<<-1;
    else
    cout<<k;
}

Measured memory_bytes: 4444
#!/usr/bin/env python3
import sys
from math import ceil

def solve(N: int, D: int):
    print(ceil(N/(2*D+1)))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(N, D)

if __name__ == '__main__':
    main()


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

int n,t,m[1000],l[1000],k[1000];

bool check(int x){
  int c[1001]={},used[1000]={},cnt=n;
  for(int i=0;i<t;i++){
    x+=c[i];
    for(int j=0;j<n&&x;j++){
      if(used[j])continue;
      if(i+m[j]>t)return 0;
      if(i%(l[j]+k[j])<=l[j])c[i+m[j]]++,cnt--,used[j]=1,x--;
    }
  }
  return !cnt;
}

int main(){
  while(scanf("%d%d",&n,&t),n){
    for(int i=0;i<n;i++)scanf("%d%d%d",&m[i],&l[i],&k[i]);
    int ans=0;
    for(int i=1;i<=n&&!ans;i++)if(check(i))ans=i;
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3136
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let nm: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nm[0];
    let mut a: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let m = a.len();
    let b = vec![2,5,5,4,5,6,3,7,6];
    a.sort();

    let mut memo = vec![vec![vec![-1; m]; n+1]; 2];
    memo[0][0].copy_from_slice(&vec![0i32; m]);

    for i in 0..m {
        if a[i] == 0 || a[i] >= 10 {
            println!("error");
            return;
        }
        let num = b[a[i]-1];
        for j in 0..cmp::min(num, n+1) {
            let tmp = memo[i%2][j].clone();
            memo[(i+1)%2][j].copy_from_slice(&tmp);
        }
        for j in num..n+1 {
            let sum1 = memo[i%2][j].iter().fold(0i32, |acc, x| acc + x);
            let sum2 = memo[i%2][j-num].iter().fold(0i32, |acc, x| acc + x);
            let sum3 = memo[(i+1)%2][j-num].iter().fold(0i32, |acc, x| acc + x);
            if sum3 >= 0 && sum3 + 1 >= sum1 {
                let tmp = memo[(i+1)%2][j-num].clone();
                memo[(i+1)%2][j].copy_from_slice(&tmp);
                memo[(i+1)%2][j][i] += 1;
            } else if sum2 >= 0 && sum2 + 1 >= sum1 {
                let tmp = memo[i%2][j-num].clone();
                memo[(i+1)%2][j].copy_from_slice(&tmp);
                memo[(i+1)%2][j][i] += 1;
            } else {
                let tmp = memo[i%2][j].clone();
                memo[(i+1)%2][j].copy_from_slice(&tmp);
            }
        }
    }
    for i in (0..m).rev() {
        for _j in 0..memo[m%2][n][i] {
            print!("{}", a[i]);
        }
    }
    println!();
    
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
int sx,sy,tx,ty;
cin >> sx >> sy >> tx >> ty;
const int dx=tx-sx,dy=ty-sy;
cout << string(dy,'U') << string(dx,'R');
cout << string(dy,'D') << string(dx,'L');
cout << 'L' << string(dy+1,'U') << string(dx+1,'R') << 'D';
cout << 'R' << string(dy+1,'D') << string(dx+1,'L') << 'U';
cout << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

int x[10][10];

int main(int argc, char* argv[])
{
    int n,d;
    scanf("%d%d", &n,&d);

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

    int cnt=0;
    int k;
    for(i=0; i<n; i++) {
        for(j=i+1; j<n; j++) {
            ll sum=0;
            for(k=0; k<d; k++) {
                sum += (ll)(x[i][k]-x[j][k])*(ll)(x[i][k]-x[j][k]);
            }
            ll tmp = sqrt((double)sum+0.001);
            if(sum==tmp*tmp) {
                cnt++;
            }
        }
    }
    printf("%d\n", cnt);

    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<utility>
#include<functional>

using namespace std;

typedef pair<int,int> P;

struct edge{
  int to,cap,cost,rev;
};

const int MAX_V=3003;
int V;
vector<edge> G[MAX_V];
int h[MAX_V];
int dist[MAX_V];
int prevv[MAX_V],preve[MAX_V];

void add_edge(int from,int to,int cap,int cost){
  G[from].push_back({to,cap,cost,(int)G[to].size()});
  G[to].push_back({from,0,-cost,(int)G[from].size()-1});
}

int min_cost_flow(int s,int t){
  int res=0;
  const int INF=1<<29;
  fill(h,h+V,INF);
  h[s]=0;
  for(;;){
    bool u=false;
    for(int i=0;i<V;i++){
      for(auto f:G[i]){
	if(f.cap){
	  int nd=h[i]+f.cost;
	  if(nd<h[f.to]){
	    h[f.to]=nd;
	    u=true;
	  }
	}
      }
    }
    if(!u)break;
  }
  while(h[t]<0){
    priority_queue<P,vector<P>,greater<P> > que;
    fill(dist,dist+V,INF);
    dist[s]=0;
    que.push({0,s});
    while(!que.empty()){
      P p=que.top();
      que.pop();
      int v=p.second;
      if(dist[v]<p.first)continue;
      for(int i=0;i<G[v].size();i++){
	edge &e=G[v][i];
	if(e.cap>0&&dist[e.to]>dist[v]+e.cost+h[v]-h[e.to]){
	  dist[e.to]=dist[v]+e.cost+h[v]-h[e.to];
	  prevv[e.to]=v;
	  preve[e.to]=i;
	  que.push({dist[e.to],e.to});
	}
      }
    }
    if(dist[t]==INF)return res;
    for(int v=0;v<V;v++){
      h[v]+=dist[v];
    }
    int d=INF;
    for(int v=t;v!=s;v=prevv[v]){
      d=min(d,G[prevv[v]][preve[v]].cap);
    }
    res+=d*h[t];
    for(int v=t;v!=s;v=prevv[v]){
      edge &e=G[prevv[v]][preve[v]];
      e.cap-=d;
      G[v][e.rev].cap+=d;
    }
  }
  return res;
}
	

int main(){
  int N;
  cin>>N;
  int A[1000],B[1000];
  set<int> s;
  for(int i=0;i<N;i++){
    cin>>A[i]>>B[i];
    s.insert({A[i],B[i]});
  }
  map<int,int> m;
  for(auto e:s){
    int n=m.size();
    m[e]=n;
  }
  V=N+s.size()+3;
  for(int i=0;i<N;i++){
    add_edge(0,i+1,1,0);
    add_edge(i+1,m[A[i]]+N+1,1,-B[i]);
    add_edge(i+1,m[B[i]]+N+1,1,-A[i]);
    add_edge(i+1,s.size()+N+1,1,0);
  }
  for(int i=0;i<s.size();i++){
    add_edge(1+N+i,N+s.size()+2,1,0);
  }
  add_edge(s.size()+N+1,s.size()+N+2,99999,0);
  cout<<-min_cost_flow(0,s.size()+N+2)<<endl;
}

Measured memory_bytes: 1848
#include<iostream>
#include<string>
#include<map>
#include <vector>
#include <iomanip>
#include <cmath>
#include <cctype>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define out(x) cout << x << endl;
// for (int i = 0; i < N; ++i) cin >> A[i];
typedef vector<int> vint;
typedef vector<long> vl;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef map<string, int> mapstri;
typedef map<string, int> mapii;

int main () {
    long long n;
    cin >> n;
    long long ans = 0;
    while (n >= 500) {
        n -= 500;
        ans += 1000;
    }
    while (n >= 5) {
        n -= 5;
        ans += 5;
    }
    out(ans)
    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

ld p, q, a, n;

int solve(int i, int cnt, int mul, ld sum)
{
	if (abs(sum - p / q) < EPS) return 1;
	if (sum - p / q > EPS || cnt == n || mul*i > a) return 0;
	if (p / q - (sum + 1.0 / i * (n - cnt)) > EPS) return 0;
	return solve(i + 1, cnt, mul, sum) + solve(i, cnt + 1, mul*i, sum + 1.0 / i);
}

int main()
{
	cin.sync_with_stdio(false);
	while (cin >> p >> q >> a >> n, p || q || a || n)
	{
		cout << solve(0, 0, 1, 0) << endl;
	}
	return 0;
}

Measured memory_bytes: 3668
#include <stdio.h>
typedef long long ll;
#define abs(x) ((x) > 0 ? (x) : -(x))

int
main(int argc, char *argv[])
{
  int n, a[100000] = {}, cost[100000];

  scanf("%d", &n);
  scanf("%d", &a[0]);
  cost[0] = abs(a[0]);
  for(int i = 1; i < n; i++){
    scanf("%d", &a[i]);
    cost[i] = cost[i - 1] + abs(a[i] - a[i - 1]);
  }
  
  printf("%d\n", abs(a[n - 1]) + cost[n - 1] - cost[1] + abs(a[1]));
  for(int i = 1; i < n - 1; i++){
    printf("%d\n", abs(a[n - 1]) + cost[n - 1] - cost[i + 1] + cost[i - 1] + abs(a[i + 1] - a[i - 1]));
  }
  printf("%d\n", cost[n - 2] + abs(a[n - 2]));

  return 0;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a==1)
    {
        if(b==1)cout<<"Draw"<<endl;
        else cout<<"Alice"<<endl;
    }
    else if(b==1)
    {
        if(a==1)cout<<"Draw"<<endl;
        else cout<<"Bob"<<endl;
    }
    else
    {
        if(a>b)cout<<"Alice"<<endl;
        else if(a==b)cout<<"Draw"<<endl;
        else cout<<"Bob"<<endl;
    }
}


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

using namespace std;

int main() 
{ 
    long int K;
    cin>>K;
  string S;
  cin>>S;
  
  if(K>=S.length())
  {
      cout<<S<<endl;
  }
  else
  {
      for(int i=0;i<K;++i)
      {
          cout<<S[i];
      }
      cout<<"..."<<endl;
  }
    
    
}

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

void chmin(int64_t& a, int64_t b){
    a = min(a, b);
}

int main(){
    int N;
    int64_t A[500][500] = {0}, Spos[501][501] = {0}, Sneg[501][501] = {0};
    cin >> N;
    for(int i=0; i<N; i++) for(int j=0; j<N; j++) if(i!=j){
        cin >> A[i][j];
        (i < j ? Sneg[i+1][j+1] : Spos[i+1][j+1]) = A[i][j];
    }

    for(int i=0; i<N; i++) for(int j=0; j<N; j++){
        Spos[i+1][j+1] += Spos[i+1][j] + Spos[i][j+1] - Spos[i][j];
        Sneg[i+1][j+1] += Sneg[i+1][j] + Sneg[i][j+1] - Sneg[i][j];
    }

    const int64_t INF = 1e18;
    int64_t dp[501][501];
    for(int i=0; i<=N; i++) for(int j=0; j<=N; j++) dp[i][j] = INF;
    dp[N][N] = 0;
    for(int i=N; i>=0; i--) for(int j=N; j>=i; j--) for(int k=i-1; k>=0; k--){
        int64_t res = dp[i][j];
        res += Sneg[i][i] - Sneg[i][k] - Sneg[k][i] + Sneg[k][k];
        res += Spos[N][i] - Spos[N][k] - Spos[j][i] + Spos[j][k];
        chmin(dp[k][i], res);
    }

    int64_t ans = INF;
    for(int j=0; j<=N; j++) chmin(ans, dp[0][j]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8064
import sys
input = sys.stdin.readline
S = list(input())[: -1]
n = S.count("N") > 0
e = S.count("E") > 0
s = S.count("S") > 0
w = S.count("W") > 0
if n and s or (n == 0 and (s == 0)):
  if e and w or (e == 0 and (w == 0)):
    print("Yes")
    exit(0)
print("No")

Measured memory_bytes: 28396
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    int N; cin>>N;
    vector<int> v(N);
    for(int i=0;i<N;i++) cin>>v[i];
    sort(v.begin(),v.end());
    double sum=v[0];
    for(int i=1;i<N;i++){
        sum+=pow(2,i-1)*v[i];
    }
    cout<<fixed<<setprecision(10)<<sum/pow(2,N-1)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repX(i, n ,x) for (int i = x; i < (int)(n); ++i)
#define repBack(i, n) for (int i = n; i >= 0; --i)
#define dup(x,y) (((x)+(y)-1)/(y))

int main() {
    string S;
    cin >> S;
    if(S == "SUN")
        cout << 7 << endl;
    if (S == "MON")
        cout << 6 << endl;
    if (S == "TUE")
        cout << 5 << endl;
    if (S == "WED")
        cout << 4 << endl;
    if (S == "THU")
        cout << 3 << endl;
    if (S == "FRI")
        cout << 2 << endl;
    if (S == "SAT")
        cout << 1 << endl;

    return 0;
}

Measured memory_bytes: 256
#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 lli long long int
#define all(x) x.begin(),x.end()
#define siz(x) x.size()
#define prs(x,y) x.find(y)!=x.end()
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res;}
inline int level(int n){int ans=0;while(n%2==0){n/=2;ans++;}return ans;}
int main()
{
		lli a,b,c,k;
		cin>>a>>b>>c>>k;
		if(k<=a)
			cout<<k;
		else if(k<=a+b)
			cout<<a;
		else
			cout<<a-(k-(a+b));

}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll r, d, x[11];
  cin >> r >> d >> x[0];
  rep(i, 10) {x[i+1]=r*x[i]-d; cout << x[i+1] << newl;}
  return 0;
}

Measured memory_bytes: 256
H,W = map(int,input().split())
src = [list(map(int,input().split())) for i in range(H)]

dp = [[[0 for ex in range(W)] for sx in range(W)] for xy in range(H+W-1)]
dp[0][0][0] = src[0][0]
for xy in range(H+W-2):
    n = min(xy+1,H,W,H+W-xy-1)
    sx0 = max(0,xy-H+1)
    for sx in range(sx0, sx0+n):
        for ex in range(sx, sx0+n):
            sy,ey = xy-sx, xy-ex
            if sx < W-1 and ex < W-1:
                gain = src[sy][sx+1]
                if sx+1 != ex+1: gain += src[ey][ex+1]
                if dp[xy+1][sx+1][ex+1] < dp[xy][sx][ex] + gain:
                    dp[xy+1][sx+1][ex+1] = dp[xy][sx][ex] + gain
            if sx < W-1 and ey < H-1:
                gain = src[sy][sx+1]
                if sx+1 != ex: gain += src[ey+1][ex]
                if dp[xy+1][sx+1][ex] < dp[xy][sx][ex] + gain:
                    dp[xy+1][sx+1][ex] = dp[xy][sx][ex] + gain
            if sy < H-1 and ex < W-1:
                gain = src[sy+1][sx]
                if sx != ex+1: gain += src[ey][ex+1]
                if dp[xy+1][sx][ex+1] < dp[xy][sx][ex] + gain:
                    dp[xy+1][sx][ex+1] = dp[xy][sx][ex] + gain
            if sy < H-1 and ey < H-1:
                gain = src[sy+1][sx]
                if sx != ex: gain += src[ey+1][ex]
                if dp[xy+1][sx][ex] < dp[xy][sx][ex] + gain:
                    dp[xy+1][sx][ex] = dp[xy][sx][ex] + gain

print(dp[-1][-1][-1])

Measured memory_bytes: 169352
#include<bits/stdc++.h>
int n,a,mi=99;
int f(int v){
int M[]={0,1,28,2,29,14,24,3,30,22,20,15,25,17,4,8,31,27,13,23,21,19,16,7,26,12,18,6,11,5,10,9};
return M[(((v&-v)*0x077CB531U))>>27];
}
int main(){
	scanf("%d",&n);
	while(n--){
		scanf("%d",&a);
		mi=std::min(mi,f(a));
	}
	printf("%d\n",mi);
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        string[] str = Console.ReadLine().Split(' ');
        int N = int.Parse(str[0]);
        int K = int.Parse(str[1]);
        long[] A = new long[N];
        str = Console.ReadLine().Split(' ');
        for(int i=0;i<N;i++){
            A[i] = int.Parse(str[i]);
        }
        long[] s1 = new long[N];
        long[] s2 = new long[N];
        long sum = 0;
        for(int i=0;i<N;i++){
            sum += A[i] >= 0 ? A[i] : 0;
            s1[i] = (i == 0 ? 0 : s1[i-1]) + (A[i] > 0 ? -A[i] : 0);
            s2[i] = (i == 0 ? 0 : s2[i-1]) + (A[i] < 0 ? A[i] : 0);
        }
        long max = 0;
        for(int i=0;i+K-1<N;i++){
            max = Math.Max(max,sum+s1[i+K-1]-(i != 0 ? s1[i-1] : 0));
        }
        for(int i=0;i+K-1<N;i++){
            max = Math.Max(max,sum+s2[i+K-1]-(i != 0 ? s2[i-1] : 0));
        }
        sb.Append(max+"\n");
    }
}

Measured memory_bytes: 19160
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
int main()
{
    int n;
    cin>>n;
    if(n%2==1){
        double num=n/2+1;
        cout<<num/n<<endl;
    }
    else{
        cout<<0.5<<endl;
    }
}

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

#define pb push_back
signed main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  int a[300009]={};
  int b[300009]={};
  rep(i,s.size()){
    int d=0;
    if(s[i]=='W')d++;
    a[i+1]=a[i]+d;
  }
  for(int i=s.size()-1;i>=0;i--){
    int d=0;
    if(s[i]=='E')d++;
    b[i-1]=b[i]+d;
  }
  int ans=1e9;
  rep(i,s.size()){
    //cout<<a[i]<<' '<<b[i]<<endl;
    if(i==0)ans=min(ans,b[i]);
    else if(i==s.size()-1)ans=min(ans,a[i]);
    else ans=min(ans,a[i]+b[i]);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 5380
using System;
using System.Linq;

namespace agc012_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Array.Sort(x);
            long ret = 0;
            for (int i = 0; i < n; i++)
            {
                ret += x[n * 3 - (i + 1) * 2];
            }
            Console.WriteLine(ret);
        }
    }
}

Measured memory_bytes: 40908
#include <stdio.h>
#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    int N;
    scanf("%d", &N);
    int A[N], B[N], C[N];
    int i=0;
    for(i=0;i<N;i++) {
        scanf("%d", &A[i]);
    }
    for(i=0;i<N;i++) {
        scanf("%d", &B[i]);
    }
    for(i=0;i<N-1;i++) {
        scanf("%d", &C[i]);
    }
    
    int prev = N;
    int sum = 0;
    for(i=0;i<N;i++) {
        sum += B[A[i] - 1];
        if (A[i] - prev == 1) {
            sum += C[prev - 1];
        }
        prev = A[i];
    }
    printf("%d", sum);
    return 0;
}

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

int main()
{
	int N;
	scanf("%d", &N);
	std::vector<int64_t> X(N), Y(N);
	for (int i{}; i < N; i++)
		scanf("%lld%lld", &X[i], &Y[i]);
	std::map<std::pair<int64_t, int64_t>, int> m;
	for (int i{}; i < N; i++)
		for (int j{i + 1}; j < N; j++)
			if (i != j)
			{
				if (X[i] == X[j] || Y[i] == Y[j])
					m[{std::abs(X[i] - X[j]), std::abs(Y[i] - Y[j])}]++;
				else if (X[i] >= X[j])
					m[{X[i] - X[j], Y[i] - Y[j]}]++;
				else
					m[{X[j] - X[i], Y[j] - Y[i]}]++;
			}
	
	int max{};
	for (auto& e: m)
		max = std::max(max, e.second);
	printf("%d\n", N - max);

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6+ 5;
const int M = 1e7 + 5;
const int INF=1e9+7;
const int mod=1e9+7;
const double eps=1e-9;
typedef long long ll;
typedef pair<int,int>pi;
int T,n,m;
int a[N],b[N],c[N];
vector<int>G;
int main() {
    string s;
    cin >> s;
    cout << s[0] << s[1] << s[2];
}

Measured memory_bytes: 3552
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <deque>

int parent[200005];
int length[200005];

void init(){
  for (int i=0; i<200005; i++){
    parent[i]=i;
    length[i]=1;
  }
  return;
}

int getroot(int n){
  if (parent[n]==n){
    return n;
  } else {
    return getroot(parent[n]);
  }
}

bool samegroup(int n, int m){
  int nroot = getroot(n);
  int mroot = getroot(m);
  //printf("checking samegroup(%d, %d) -> (%d, %d)\n",n,m,nroot,mroot);
  if (nroot==mroot){
    return true;
  } else {
    return false;
  }
}

bool unite(int n, int m){
  if (samegroup(n, m)){
    return false; 
  } else {
    int nroot = getroot(n);
    int mroot = getroot(m);
    if (length[nroot]==length[mroot]){
      parent[nroot] = mroot;
      length[mroot]++;
    } else if (length[nroot]>length[mroot]){
      parent[mroot] = nroot;
    } else {
      parent[nroot] = mroot;
    }
    return true;
  }
}

int main(){
  int N, M;
  scanf("%d", &N);
  scanf("%d", &M);
  std::vector<int> p(N);
  for (int i=0; i<N; i++){
    scanf("%d", &p[i]);
  }
  std::vector<int > x(M), y(M);
  for (int i=0; i<M; i++){
    scanf("%d", &x[i]);
    scanf("%d", &y[i]);
  }
  init();
  for (int i=0; i<M; i++){
    unite(x[i], y[i]);
  }
  int ans = 0;
  for (int i=0; i<N; i++){
    if (samegroup(p[i],i+1)){
      //printf("same %d %d\n", p[i],i+1);
      ans++;
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 2944
N = int(input())
s = input().strip()
t = input().strip()
ind = -1
for i in range(N):
    x = s[i:]
    y = t[:N-i]
    if x==y:
        ind = i
        break
if ind>=0:
    print(N+i)
else:
    print(2*N)

Measured memory_bytes: 61920
package main

import "fmt"

func main() {
	var x, y, z, ans int
	fmt.Scan(&x,&y,&z)
	x -= z

	for {
		if x >= (y + z){
			x -= (y + z)
			ans++
		} else {
			break
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
bool judge(const char& a)
{
    bool ans;
    if (a == '.') {
        ans = true;
    } else {
        ans = false;
    }
    return ans;
}


int main()
{
    int h, w;
    std::cin >> h >> w;
    std::array<std::string, 55> S;
    std::array<std::array<int, 55>, 55> N = {};
    for (int i = 0; i < h; ++i) {
        std::cin >> S.at(i);
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (!judge(S[i][j])) {
                if (i > 0) {
                    N[i - 1][j] += 1;
                }
                if (i < h) {
                    N[i + 1][j] += 1;
                }
                if (j > 0) {
                    N[i][j - 1] += 1;
                }
                if (j < w) {
                    N[i][j + 1] += 1;
                }
                if (i > 0 && j > 0) {
                    N[i - 1][j - 1] += 1;
                }
                if (i > 0 && j < w) {
                    N[i - 1][j + 1] += 1;
                }
                if (i < h && j > 0) {
                    N[i + 1][j - 1] += 1;
                }
                if (i < h && j < w) {
                    N[i + 1][j + 1] += 1;
                }
            }
        }
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (judge(S[i][j])) {
                S[i].replace(j, 1, std::to_string(N[i][j]));  //= static_cast<char>(N[i][j]);
            }
        }
    }
    for (int i = 0; i < h; ++i) {
        std::cout << S.at(i) << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define endl '\n'
#define int long long
int32_t main()
{
    int n,k;
    cin>>n>>k;
    vector<int> v(n);
    for(int i=0;i<n;i++)
    	cin>>v[i];
    sort(v.begin(),v.end());
    int ans=0;
    for(int i=0;i<max((int)0,n-k);i++)
    	ans+=v[i];
    cout<<ans;
}

Measured memory_bytes: 1792
#include <iomanip>
#include <iostream>
using namespace std;
int a[105];
int main() {
  int n, m, x;
  int under = 0, up = 0;
  cin >> n >> m >> x;
  for (int i = 0; i < m; i++) {
    cin >> a[i];
    if (x > a[i])
      under++;
    else
      up++;
  }
  cout << min(under, up);
  return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <deque>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define reppe(i,a,b) for(int i = (int)(a) ; i <= (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repme(i,a,b) for(int i = (int)(a) ; i >= (int)(b) ; --i)

typedef long long ll;

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

int charN(char c) {
    return static_cast<int>(c) - static_cast<int>('a');
}
int main() {
    int N; cin >> N;
    vector<pair<ll,ll>> xy;
    repp(i, 0, N) {
        ll x, y; cin >> x >> y;
        xy.emplace_back(x, y);
    }
    sort(xy.begin(), xy.end());
    
    map<pair<ll,ll>, int> counter;
    int count = 0;
    repp(i, 0, N) {
        repp(j, i + 1, N) {
            ++counter[make_pair(xy[j].first - xy[i].first, xy[j].second - xy[i].second)];
            count = max(count, counter[make_pair(xy[j].first - xy[i].first, xy[j].second - xy[i].second)]);
        }
    }
    cout << (N - count) << endl;
}



Measured memory_bytes: 384
h,w = map(int,input().split())
c,d = map(int,input().split())
e,f = map(int,input().split())
s = []
t = []
m = h*w
for i in range(h):
    s.append(input())
    t.append([m]*w)
c -= 1
d -= 1
t[c][d] = 0
cnt = 0
stc1 = [[c,d]]
stc2 = []
a = 0
while(1):
    if(c > 0):
        if(s[c-1][d] == '.' and t[c-1][d] > cnt):
            t[c-1][d] = cnt
            stc1.append([c-1,d])
    if(d > 0):
        if(s[c][d-1] == '.' and t[c][d-1] > cnt):
            t[c][d-1] = cnt
            stc1.append([c,d-1])
    if(c < h-1):
        if(s[c+1][d] == '.' and t[c+1][d] > cnt):
            t[c+1][d] = cnt
            stc1.append([c+1,d])
    if(d < w-1):
        if(s[c][d+1] == '.' and t[c][d+1] > cnt):
            t[c][d+1] = cnt
            stc1.append([c,d+1])
    for j in range(-2,3):
        for k in range(-2,3):
            if(abs(j)+abs(k) > 1):
                if(c+j >= 0 and c+j < h and d+k >= 0 and d+k < w):
                    if(s[c+j][d+k] == '.' and t[c+j][d+k] > cnt+1):
                        t[c+j][d+k] = min(t[c+j][d+k],cnt+1)
                        stc2.append([c+j,d+k])
    if(len(stc1) > a+1):
        a += 1
        c = stc1[a][0]
        d = stc1[a][1]
    else:
        if(len(stc2) > 0):
            stc1 = stc2
            stc2 = []
            a = 0
            c = stc1[0][0]
            d = stc1[0][1]
            cnt += 1
        else:
            break
if(t[e-1][f-1] == m):
    print(-1)
else:
    print(t[e-1][f-1])

Measured memory_bytes: 143988
#include <bits/stdc++.h>
using std::cout;
using std::endl;
using std::cin;

int main(){
	int n; cin >> n;
	std::string s; cin >> s;
	std::vector<int> A(s.size()), B(s.size());
	for(int i = 0; i < s.size(); i++){
		if(s[i] == 'W') A[i + 1]++;
		if(s[i] == 'E') B[i + 1]++;
	}
	for(int i = 0; i < s.size(); i++){
		A[i + 1] += A[i];
		B[i + 1] += B[i];
	}
	
	int mi = 1e9;
	for(int i = 0; i < s.size(); i++){
		mi = std::min(mi, A[i] + B[s.size()] - B[i + 1]);
	}
	
	cout << mi << endl;
	return 0;
}


Measured memory_bytes: 3076
#include<stdio.h>

int main() {
     int n, a[21], b[51], c[51], sum=0;
     scanf("%d", &n);
     for (int i = 0; i < n; i++) {
          scanf("%d", &a[i]);
     }
     for (int i = 0; i < n; i++) {
          scanf("%d", &b[i]);
          sum+=b[i];
     }
     for (int i = 0; i < n-1; i++) {
          scanf("%d", &c[i]);
     }
     for (int i = 1; i < n; i++) {

          if (a[i] == a[i-1]+1) {
               sum+=c[a[i-1]-1];
          }
     }
     printf("%d\n", sum);

     return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

void dfs(void);
void visit(int);

int G[N][N];//Graph
int color[N];
int S[N];//Stack
int d[N];//discover
int f[N];//finish
int t = 0;//time
int n = 0;

int main(){

  int u = 0, k = 0, v = 0;
  int i = 0, j = 0;
 
  //initialize
  for(i = 0; i < N; i++){
    
    for(j = 0; j < N; j++){
      G[i][j] = 0;
    }
    
  }

  //scan
  scanf("%d",&n);
  
  for(i = 0; i < n; i++){
    scanf("%d%d",&u,&k);
    
    for(j = 0; j < k; j++){
      scanf("%d",&v);
      G[u-1][v-1] = 1;
    }
    
  }

  dfs();
  
  //print
  for(i = 0; i < n; i++){

    printf("%d %d %d\n",i+1,d[i],f[i]);
    
  }
  
  return 0;

}

void dfs(void){
  
  int u = 0;
  
  for(u = 0; u < n; u++){
    
    color[u] = WHITE;
    
  }
  
  for(u = 0; u < n; u++){

    if(color[u] == WHITE)visit(u);
    
  }
  
}

void visit(int u){

  int v = 0;
  
  color[u] = GRAY;
  d[u] = ++t;
  for(v = 0; v < n; v++){

    if(G[u][v] == 0)continue;
    
    if(color[v] == WHITE){
      
      visit(v);
      
    }
    
  }
  color[u] = BLACK;
    f[u] = ++t;
}



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

int n, m;
string s;

int main()
{
  while (cin >> n, n){
    cin >> m >> s;

    char expected = 'I';
    int len = 0, ans = 0;
    for (int i = 0; i < m; i++){
      if (s[i] == expected){
        len++;
        expected = (expected == 'I' ? 'O' : 'I');
        if (len == 2 * n + 1) {
          ans++;
          len -= 2;
        }
      }
      else {
        if (expected == 'I'){
          len = 0;
        } else {
          len = 1;
        }
      }
    }

    cout << ans << endl;
  }
}

Measured memory_bytes: 3892
l,r=map(int,input().split())
L=l%2019
R=r%2019
ans=2019
if l+2019<=r:
        print(0)
elif L>R:
        print(0)
else:
        for i in range(L,R+1):
              for j in range(i+1,R+1):
                        ans=min(ans,(i*j)%2019)
        print(ans)

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

using namespace std;
typedef long long ll;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> x(n);
    for(int i=0;i<n;i++) cin >> x[i];
    int ans = 0;
    for(int i=0;i<n;i++) {
        ans += 2* min(abs(x[i]),  abs(k-x[i]));
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
H, W = map(int, input().split())

tmp_list = [list(map(int, input().split())) for i in range(H)]
ans_list = [[None for i in range(W)] for j in range(H)]



# j: 横方向(0 ~ W-1)
# i: 縦方向(0 ~ H-1)
def search_func(i, j):
    
    if not (not ans_list[i][j]):
        return ans_list[i][j]
    
    # print("i =", i, ",j =", j)
    # ４方向に探索する。
    add_list = set()
    if j != 0 and tmp_list[i][j] > tmp_list[i][j-1]:
        add_list = add_list.union(search_func(i, j-1))
    if j != (W-1) and tmp_list[i][j] > tmp_list[i][j+1]:
        add_list = add_list.union(search_func(i, j+1))
    if i != 0 and tmp_list[i][j] > tmp_list[i-1][j]:
        add_list = add_list.union(search_func(i-1, j))
    if i != (H-1) and tmp_list[i][j] > tmp_list[i+1][j]:
        add_list = add_list.union(search_func(i+1, j))
        
    # ４方向は囲まれていた
    if not add_list:
        ans_list[i][j] = set({tmp_list[i][j]})
    else:
        ans_list[i][j] = add_list
    return ans_list[i][j]
    

sort_list = []
for i in range(H):
    for j in range(W):
        sort_list.append([tmp_list[i][j], i, j])

# キーにしたがってソートする。
sort2_list = sorted(sort_list, key=lambda x: x[0])

final_ans = 0
for item in sort2_list:
    if len(search_func(item[1], item[2])) > 1:
        final_ans += 1
print(final_ans)


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

int main(){
    int ans=0;
    string s;
    cin>>s;
    stack<char> st;
    for(int i = 0; i < s.size(); i++)
    {
        if(st.size()==0 || st.top()==s[i])
        {
            st.push(s[i]);
        }
        else
        {
            ans+=2;
            st.pop();
        }
        
    }
    

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i, n) cin >> h[i];

  sort(all(h));
  LL ans = 0;
  for (int i = 0; i < max(0, n - k); i ++) ans += h[i];

  cout << ans << endl;
}


Measured memory_bytes: 1024
from math import sqrt, cos, pi

a, b, h, m = map(int, input().split())

rot_a = h*30 + m*0.5
rot_b = m*6
rot = rot_a-rot_b if rot_a>rot_b else rot_b-rot_a
if rot > 180:
  rot = min(rot_a, rot_b) + 360 - max(rot_a, rot_b)

ans = sqrt(a**2 + b**2 - 2*a*b*cos(rot*pi/180))
print(ans)

Measured memory_bytes: 9360
/**
 * Created by hiramekun at 23:05 on 2019-10-29.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll n, k;
    cin >> n >> k;
    vl a(n), f(n);
    cin >> a >> f;
    sort(all(a), greater<>()), sort(all(f));
    ll s = -1;
    ll e = *max_element(all(a)) * *max_element(all(f));
    while (e - s > 1) {
        ll m = (s + e) / 2;
        ll k_now = k;
        bool satis = true;
        rep(i, n) {
            ll res = max(0LL, a[i] - m / f[i]);
            if (k_now < res) {
                satis = false;
                break;
            }
            k_now -= res;
        }
        if (satis) e = m;
        else s = m;
    }
    cout << e << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

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

int N;

bool can_calc(int N) {
	for (int i=1; i<=9; i++) {
		for (int j=1; j<=9; j++) {
			if (i * j == N) {
				return true;
			}
		}
	}

	return false;
}

int main(){

	cin >> N;

	string ans;
	if (can_calc(N)) {
		ans = "Yes";
	} else {
		ans = "No";
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():
    W,a,b=map(int,input().split())
    if a+W<b:
        print(b-a-W)
    elif b+W<a:
        print(a-b-W)
    else:
        print(0)



resolve()

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

int main(){
  string S;
  int A,B;
  cin >> A >> B;
  cin >> S;
  bool ret = true;
  for(int i = 0; i < A; ++i){
    ret *= (S[i] != '-');
  }
  ret *= (S[A] == '-');
  for(int i = 0; i < B; ++i){
    ret *=(S[A+1+i] != '-');
  }
  if(ret) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn=2123;
long long mod=1e9+7;
int n,a[maxn],K;
long long res;
int main()
{
    scanf("%d%d",&n,&K);
    for (int i=1;i<=n;++i) scanf("%d",&a[i]);
    for (int i=1;i<=n;++i) {
        for (int j=1;j<=i;++j) if (a[j]>a[i]) res=(res+K)%mod;
        for (int j=1;j<=n;++j) if (a[j]>a[i]) res=(res+1ll*K*(K-1)/2)%mod;
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin>>s;
  for (int i = 0; i < s.size(); ++i)
  {
    if(s.at(i)>='A'&&s.at(i)<='Z') s.at(i)+=32;
  }
  int ans=0;
  while(cin>>t,t!="END_OF_TEXT")
  {
    for (int i = 0; i < t.size(); ++i)
    {
      if(t.at(i)>='A'&&t.at(i)<='Z') t.at(i)+=32;
    }
    if(s==t) ++ans;
  }
  cout<<ans<<endl;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  int ans = 0;
  int right = 0;
  int cn = 0;
  if (s[0] == '0') cn++;
  for (int left = 0; left < n; ++left){
    while (cn <= k && right < n){
      if(right + 1 < n && s[right] == '1' && s[right +1] == '0')cn++;
      ++right;
    }
    /* break した状態で right は条件を満たす最大なので、何かする */
    ans = max(ans,right - left);

    if (left + 1 < n && s[left] == '0' && s[left + 1] == '1') cn--;
  }
  cout << ans << endl;
}

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

int key[7];
int key_2[7];

void N(){
	int change = key[1];
	key[1] = key[2];
	key[2] = key[6];
	key[6] = key[5];
	key[5] = change;
}

void S(){
	int change = key[1];
	key[1] = key[5];
	key[5] = key[6];
	key[6] = key[2];
	key[2] = change;
}

void W(){
	int change = key[1];
	key[1] = key[3];
	key[3] = key[6];
	key[6] = key[4];
	key[4] = change;
}

void E(){
	int change = key[1];
	key[1] = key[4];
	key[4] = key[6];
	key[6] = key[3];
	key[3] = change;
}

int equal(){
	int i;
	for(i=0;i<6;i++){
		if(key[i+1] != key_2[i+1]){
			return 0;
		}
	}
	return 1;
}

int main(void){
	int i,j;
	int check = 0;
	
	for(i=0;i<6;i++){
		scanf("%d", &key[i+1]);
	}
	
	for(i=0;i<6;i++){
		scanf("%d", &key_2[i+1]);
	}
	
	for(i=0;i<4;i++){
		for(j=0;j<4;j++){
			N();
			E();
			S();
			if(equal() == 1){
				check = 1;
			}
		}
		E();
	}
	for(i=0;i<4;i++){
		for(j=0;j<4;j++){
			N();
			E();
			S();
			if(equal() == 1){
				check = 1;
			}
		}
		N();
	}
	
	if(check == 1){
		printf("Yes\n");
	}else if(check == 0){
		printf("No\n");
	}
	
	return 0;
	
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define rFORe(i, a, n) for(int (i) = (int)(n); (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 1, (n))
#define REPo(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rREPe(i, n) rFORe((i), 1, (n))
#define rREPo(i, n) rFORe((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define dup(x, y) (((x)+(y)-1)/(y))
#define vc(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using vp = vector<P>;
using vt = vector<T>;

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

int main() {
  int k,a,b;
  cin >> k >> a >> b;
  bool ok = false;
  if (a%k==0) ok = true;
  if (b%k==0) ok = true;
  if (a/k != b/k) ok = true;
  cout << (ok?"OK":"NG") << endl; 

  return 0;
}

Measured memory_bytes: 3632
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        String s = sc.next();
        
        int res = 0;
        
        for(int i = 0; i < 6; i++){
            res = s.charAt(i) == '1' ? res + 1 : res;
        }
        
        System.out.println(res);
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <set>
#include <string>
#include <algorithm>

using namespace std;
int a[26];
int main()
{
    string s;
    int k, id(0);
    cin >> s >> k;
    int n = s.length();
    set <string> ans;
    for(int i = 0; i < n; i++)
    {
        string cur = "";
        for(int j = i; j < min(i + k, n); j++)
        {
            cur += s[j];
            ans.insert(cur);
        }
    }
    int cnt(0);
    for(auto it : ans)
    {
        cnt++;
        if(cnt == k)
            return cout << it, 0;
    }
}


Measured memory_bytes: 1664