akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int n,k; cin >> n >> k;
  vi a(n);
  rep(i,n) cin >> a[i];
  rep(i,k) {
    vi b(n+1);
    rep(i,n) {
      int l = max(0, i-a[i]);
      int r = min(n-1, i+a[i]);
      int rc = r+1;
      b[l]++;
      if (rc < n) b[rc]--;
    }
    rep(i, n) b[i+1] += b[i];
    b.pop_back();
    if (a == b) break;
    a = b;
  }
  rep(i,n) printf("%d%c", a[i], i==n-1?'\n':' ');
  return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define loop for(;;)
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;
#define inf (1e9)
#define eps (1e-9)

template<class S, class T> inline
ostream& operator<<(ostream&os, pair<S,T> p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template<class S, class T, class U> inline
ostream& operator<<(ostream&os, tuple<S,T,U> t) {
  return os << '('
    << get<0>(t) << ", "
    << get<1>(t) << ", "
    << get<2>(t) << ')';
}

template<class T> inline
ostream& operator<<(ostream&os, vector<T> v) {
  if (v.size() == 0) { return os << "(empty)"; }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

template<class T> inline
istream& operator>>(istream&is, vector<T>&v) {
  rep (i, v.size()) is >> v[i];
  return is;
}

//           ^   >  v   <
int dx[] = { -1, 0, 1,  0 };
int dy[] = {  0, 1, 0, -1 };

typedef vector<int> vi;
typedef vector<vi> vvi;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout.setf(ios::fixed);
  cout.precision(10);
  random_device dev;
  mt19937 rand(dev());

  int m; cin >> m;
  rep (_, m) {
    int n, k; cin >> n >> k;
    vi xs(n); cin >> xs;
    if (n<=k) { cout << 0 << endl; continue; }
    vi ds(n-1);
    rep (i, n-1) ds[i] = xs[i+1] - xs[i];
    int sum = xs[n-1] - xs[0];
    sort(begin(ds), end(ds));
    rep (i, k-1) sum -= ds[n-2-i];
    cout << sum << endl;
  }

  return 0;
}

Measured memory_bytes: 1900
def greenandredapples():
    X, Y, A, B, C = list(map(int, input().split()))
    RedD = sorted(list(map(int, input().split())))
    GreenD = sorted(list(map(int, input().split())))
    Colorl = sorted(list(map(int, input().split())))

    considered = RedD[-X:] + GreenD[-Y:]
    Colorl.extend(considered)
    return sum(sorted(Colorl,reverse=True)[:X+Y])

print(greenandredapples())

Measured memory_bytes: 23988
#include <stdio.h>

int main(){
    int i,x,y,tmp;
    for (i =1; ;){
        scanf("%d %d", &x, &y);
        if (x==0 && y==0){
            break;
        }
        if (x > y){
            tmp = x;
            x = y;
            y = tmp;
        }
        printf("%d %d\n", x, y);
    }
    return(0);
}

Measured memory_bytes: 600
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N;
string S;

int main() {
  INCANT;
  cin >> S;
  int N = S.size();
  bool flag = false;
  rep(i, N-1) {
    if (S[i]=='A' && S[i+1]=='C') flag = true;
  }
  string ans = flag?"Yes":"No";
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
def main():
  N = int(input())
  H = list(map(int,input().split()))

  ma = H[-1]
  ans = "Yes"
  for i, h in enumerate(H[::-1]):
    if i == 0:
      continue
    if ma > h:
      ma = h
      continue
    if ma < h:
      if ma + 1 == h:
        continue
      ans = "No"
    if ma == h:
      continue
  print(ans)

if __name__ == "__main__":
  main()

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

using namespace std;

#define FOR(i,a,b)  for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n)    FOR(i,0,n)
#define ALL(a)      a.begin(),a.end()
#define vi          vector<int>
#define vvi         vector<vi>
#define P           pair<int,int>
#define vP          vector<P>
#define vvP         vector<vP>

int main(){
    int n;cin>>n;
    if(n<105)cout<<0<<endl;
    else if(n==105)cout<<1<<endl;
    else{
        int res=1;
        for(int i=107;i<n+1;i+=2){
            int div=0;
            FOR(j,1,i+1){
                if(i%j==0)div++;
            }
            if(div==8){
                cerr<<"Found! :"<<i<<endl;
                res++;
            }
        }
        cout<<res<<endl;
    }
    return 0;
}


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


class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        int ans = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).Distinct().Count();
        Console.WriteLine(ans);



    }





    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"


3 3 33


";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
const int N = 10;

double a[N][N];
int x[N],y[N];
int n;

void init()
{
    for(int i = 0;i < n;++i){
        for(int j = 0;j < n;++j){
            a[i][j] = a[j][i] = sqrt(1.0*(x[i]-x[j]) * (x[i]-x[j]) + (y[i]-y[j]) * (y[i] - y[j]));
        }
    }
}

int main()
{
    cin>>n;
    for(int i = 0;i < n;++i){
        cin>>x[i]>>y[i];
    }
    init();
    double res = 0.0;
    int t = 1;
    for(int i = 2;i <= n;++i) t *= i;
    for(int i = 0;i < n;++i){
        for(int j = i+1;j < n;++j){
            res += a[i][j] * (t/n)*2;
        }
    }
    res = res / t;
    printf("%.10lf\n",res); 
    return 0;
}

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

int main()
{
  int N,a,sum0=0,sum1=0,sum3=0,sum2=0;
  vector<int> V,V0;

  cin>>N;
  for(int i=0;i<N;i++){
    cin>>a;
    V.push_back(a);
    if(a==2)sum2++;
    if(a==3)sum3++;
  }
  sort(V.begin(),V.end());
  if(V[0]==0){
    for(int i=0;i<N;i++){
      sum0++;
      V.erase(V.begin());
      if(V[0]!=0 || V.empty())break;
    }
  }
  for(int i=0;i<sum0;i++)V0.push_back(0);
  for(int i=0;i<N;i++){
    if(V[0]!=1 || V.empty())break;
    sum1++;
    V.erase(V.begin());
  }
  for(int i=0;i<sum1;i++)V0.push_back(1);
  if(V0.size()>=2 || sum0!=0){
    if(sum0%2==1){
      if(sum1==0 && !V.empty()){
	V0.insert(V0.end()-1,V[0]);
	if(V[0]==2)sum2--;
	V.erase(V.begin());
      }
      else if(sum1!=0){
	for(int i=0;i<V0.size();i++){
	  if(V0[i]!=V0[i+1]){
	    swap(V0[i],V0[i+1]);
	    break;
	  }
	}
      }
    }
  }
  if(sum3==1 && sum2!=0)swap(V[sum2-1],V[sum2]);
 
  for(int i=0;i<V.size();i++)cout<<V[i]<<endl;
  for(int i=0;i<V0.size();i++)cout<<V0[i]<<endl;
  return 0;
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define Fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MOD 1000000007

vector<ll> aa[100005];
ll vi[100005];

ll depth(ll xx)
{
    ll i;
    vi[xx]=1;
    for(i=0;i<aa[xx].size();i++)
    {
        if(vi[aa[xx][i]]==0)
        {
            depth(aa[xx][i]);
        }
    }
}

int main()
{
    Fast;

    ll n,x,y,z,i,m,c;
    cin>>n>>m;
    c=0;
    for(i=0;i<m;i++)
    {
        cin>>x>>y>>z;
        aa[x].push_back(y);
        aa[y].push_back(x);
    }
    for(i=1;i<=n;i++)
    {
        if(vi[i]==0)
        {
            depth(i);
            c++;
        }
    }
    cout<<c;
}


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

int main(){
  int a;
  unsigned long u = 2, v = 1, w = 0;
  cin >> a;
  if(a == 0){
    cout << 2 << endl;
    return 0;
  }
  if(a == 1){
    cout << 1 << endl;
    return 0;
  }
  for(int i = 2; i <= a; i++){
    w = u + v; 
    u = v;
    v = w;
  }
  cout << w << endl;
}

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

int main() {
  int x;
  cin >> x;
  
  int ans = 1;
  for (int i = 2; i < 32; i++) {
    for (int j = 2; j < 10; j++) {
      int a = pow(i,j);
      if (a <= x) {
        ans = max(ans, a);
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main{
	public static void main(String[] args)  throws IOException,NumberFormatException{
		try {
		FastScanner sc=new FastScanner();
		int x=sc.nextInt(),a=sc.nextInt(),b=sc.nextInt();
		if(b-a>x) {
			System.out.println("dangerous");
		}
		else if(b-a<=0) {
			System.out.println("delicious");
		}
		else {
			System.out.println("safe");
		}
		}
		catch(Exception e) {
			return ;
		}
		
	}
	static final Random random=new Random();
	
	static void ruffleSort(int[] a) {
		int n=a.length;
		for(int i=0;i<n;i++) {
			int oi=random.nextInt(n),temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}
	
	public static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try { 
                                      st=new StringTokenizer(br.readLine());				               
                              } catch (IOException e) {}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		
		long[] readLongArray(int n) {
			long[] a=new long[n];
			for(int i=0; i<n ; i++) a[i]=nextLong();
			return a;
		}
		
		String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
	}

}


Measured memory_bytes: 32540
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define fi first
#define se second
#define FF first
#define SS second
#define mp make_pair
#define ll long long
#define pii pair<int,int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define endl '\n'
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define sz(x) (int)x.size()
typedef long double f80;
#define all(x) x.begin(), x.end()

const int mod = 1e9 + 7;
const int N = 1e5 + 5;
vector<int> g[N];
bool vis[N];

void dfs(int u) {
    vis[u] = 1;
    for(int v : g[u]) {
        if(!vis[v])
            dfs(v);
    }
}

signed main()
{
    #ifdef LOCAL
        freopen("inp.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, m;
    cin >> n >> m;
    fr(i, 1, m) {
        int x, y, z;
        cin >> x >> y >> z;
        g[x].pb(y);
        g[y].pb(x);
    }
    int ans = 0;
    fr(i, 1, n) {
        if(!vis[i]) {
            dfs(i);
            ans++;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 8960
import sys
sys.setrecursionlimit(3000)
h,w=map(int,input().split())
s=['#'*(w+2)]+['#'+input()+'#' for _ in [0]*h]+['#'*(w+2)]
l=[[0]*(w+2) for _ in [0]*(h+2)]
for i in range(h+2):
    for j in range(w+2):
        if s[i][j]=='#':
            l[i][j]=-1
def sol(m,n):
    global l
    if l[m][n]>=0:
        for i,j in [(m-1,n),(m+1,n),(m,n-1),(m,n+1)]:
            if l[i][j]==0 and [i,j]!=[1,1]:
                l[i][j]=l[m][n]+1
                sol(i,j)
            elif l[i][j]>l[m][n]+1:
                l[i][j]=l[m][n]+1
                sol(i,j)
sol(1,1)
if l[h][w]==0:print(-1)
else:print(h*w-l[h][w]-(sum(x.count('#') for x in s)-2*h-2*w-4)-1)

Measured memory_bytes: 65500
/* 2018-01-15-15.31.11 */

#include<bits/stdc++.h>
#define ll long long int

using namespace std;

int main()
{
    int N,A,B;
    cin >> N >> A >> B;
    if((B-A-1)%2==0) printf("Borys\n");
    else printf("Alice\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC return 0;
using namespace std;
const int N(3005);
char a[N], b[N];
short dp[N][N];
char last[N][N];
int n, m;
string res;
int main() {
    DAU
    cin >> (a + 1) >> (b + 1);
    n = static_cast<int>(strlen(a + 1));
    m = static_cast<int>(strlen(b + 1));
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
            if (a[i] == b[j])
                dp[i][j] = dp[i-1][j-1] + 1, last[i][j] = a[i];
            else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
    while (n > 0 && m > 0) {
        if (last[n][m])
            res += last[n][m], --n, --m;
        if (dp[n][m] == dp[n-1][m])
            --n;
        if (dp[n][m] == dp[n][m-1])
            --m;
    }
    reverse(res.begin(), res.end());
    cout << res;
    PLEC
}


Measured memory_bytes: 26752
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int H, W; cin >> H >> W;
  vector<vector<int>> c(H, vector<int>(W));
  int N; cin >> N;

  int pos = 0;
  for(int i=1; i<=N; i++) {
    int a; cin >> a;
    for (int j = pos; j<pos+a; j++) {
      int pos_h, pos_w;
      pos_h = j / W;
      if (pos_h%2==0) pos_w = j%W;
      else pos_w = (W-1) - j%W;
      c[pos_h][pos_w] = i;
    }
    pos += a;
  }

  for(auto x: c) {
    for(int y=0; y<x.size(); y++) {
      if (y!=0) cout << " "; 
      cout << x[y];
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 384
use std::cmp::*;
use std::collections::*;
use std::io::*;
use std::str::*;
use std::string::*;
use std::f64::consts::PI;

struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        IO(r, std::io::BufWriter::new(w))
    }

    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }

    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let s: String = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();

        return s.parse::<T>().ok().unwrap();
    }

    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

fn prime_factorization(n: i64) -> HashMap<i64, i64> {
    let mut n = n;
    let mut res = HashMap::new();
    let mut i = 2;
    while i * i <= n {
        while n % i == 0 {
            n /= i;
            let count = res.entry(i).or_insert(0);
            *count += 1;
        }
        i += 1;
    }

    if n > 1 {
        res.insert(n, 1);
    }

    return res;
}

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: i64 = sc.read();

    for i in 0..50001 {
        if (i as f64 * 1.08) as i64 == n {
            println!("{}", i);
            return;
        }
    }
    println!(":(");
}


Measured memory_bytes: 4352
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;

void main()
{
	while (1) {
		auto a = readln.split.map!(to!int);
		auto h = a[0];
		auto w = a[1];
		if (!h) break;
		auto field = new string[](h);
		auto f = new bool[][](h, w);

		foreach (i; 0..h) {
			field[i] = readln.chomp;
		}

		uint x, y;
		while (1) {
			if (f[y][x]) {
				writeln("LOOP");
				break;
			}
			f[y][x] = 1;
			if (field[y][x] == '.') {
				writeln(x, " ", y);
				break;
			} else if (field[y][x] == '>') {
				x++;	
			} else if (field[y][x] == '<') {
				x--;	
			} else if (field[y][x] == 'v') {
				y++;	
			} else if (field[y][x] == '^') {
				y--;	
			}
		}
	}
}

Measured memory_bytes: 1080
#include <algorithm>
#include <iostream>
#include <vector>

using std::cin;
using std::cout;
using std::max;
using std::size_t;
using std::vector;

int calc_satisfaction(const vector<int> &last, const vector<int> &c,
                      const int d, const size_t held) {
    int satisfaction = 0;
    for (size_t i = 0uL; i < 26uL; ++i) {
        if (i == held) continue;
        satisfaction += c.at(i) * (d - last.at(i));
    }
    return satisfaction;
}

int main() {
    // input
    int D;  // 365
    cin >> D;
    vector<int> c(26);  // 満足度の減衰 / day
    for (int &ci : c) cin >> ci;
    vector<vector<int>> s(D, c);  // 満足度の上昇
    for (auto &si : s) {
        for (int &sij : si) cin >> sij;
    }

    // solve
    vector<int> last(26, 0);
    vector<int> t(D, -1);
    // とりあえず各日で最大になるように貪欲
    for (int d = 0; d < D; ++d) {
        int max_satisfaction = -1000000009;
        for (int i = 0; i < 26; ++i) {
            int satisfaction = calc_satisfaction(last, c, d + 1, i);
            if (max_satisfaction < max(s.at(d).at(i), satisfaction)) {
                max_satisfaction = max(s.at(d).at(i), satisfaction);
                t.at(d)          = i + 1;
                continue;
            }
            if (max_satisfaction == max(s.at(d).at(i), satisfaction)) {
                if (c.at(i) > c.at(t.at(d) - 1)) {
                    t.at(d) = i + 1;
                }
            }
        }
        last.at(t.at(d) - 1) = d + 1;
    }

    // output
    for (const int ti : t) cout << ti << '\n';

    return 0;
}

Measured memory_bytes: 3676
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main(void) {
  string s;
  cin >> s;
  
  if (s.size() == 1)
  {
    cout << 0 << endl;
  }
  else
  {
    int ans = 0;
    string tmp{s[0]};
    for (int i = 1;i < s.size();)
    {
      if (tmp[0] != s[i])
      {
        s = s.erase(i-1, 2);
        i = i > 2?i-1:1;
        tmp[0] = s[i > 2?i - 2:0];
        ans+=2;
      }
      else
      {
        tmp[0] = s[i];
        i++;
      }
    }
    cout << ans << endl;
  }
  

  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <climits>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <stack>
#include <algorithm>
#include <map>
#include <numeric>
#include <set>
using namespace std;

#define ll long long
#define ld long double
#define pi 3.14159265359;

// v:vector  type:型  order:greater or less
#define _sort(v,type,order) do { sort(v.begin(),v.end(),order<type>()); } while(0)
// vector 要素の総和算出
// v:vector  default_value:初期値
#define _sum(v,default_value) accumulate(v.begin(),v.end(),default_value )
// vector 最大値( return ite )
#define _max_element(v) max_element(v.begin(),v.end())
// vector 最大値が格納されている要素値
#define _max_element_number(v) distance(v.begin(),max_element(v.begin(),v.end()))
// 特定コンテナの中から特定の値をカウントする
#define _count(v,value) count(v.begin(),v.end(),value)

//set<uint32_t> member;	// 重複するデータを保持する事はできない member.insert(2) member.insert(2) ⇒ member.count(2)は1
//                                                              member.emplace(2)とかも同じ
//multiset<uint32_t> v;	// 重複するデータも保持する事はできる   member.insert(2) member.insert(2) ⇒ member.count(2)は2

// 丸め
#define _round(v) round(v)
// 2乗 / 3乗
#define _square(v) pow(v,2)
#define _cube(v)   pow(v,3)
// 大小判定
#define _max(x,y) max(x,y)
#define _min(x,y) min(x,y)
// string ⇒ int
#define _stringtoi(s) stoi(s)
// double 平方根
#define _sqrt(x) sqrt(x)
// double 引数 x 以上で最小の整数値 ex) 3.30303 ⇒ 4
#define _ceil(x) ceil(x)
// 指定された要素以上の値が現れる最初の位置のイテレータを取得する
#define _lower_bound(v,min) lower_bound(v.begin(), v.end(), min)
// 指定された要素より大きい値が現れる最初の位置のイテレータを取得する
#define _upper_bound(v,min) upper_bound(v.begin(), v.end(), min)

// 順列 n個の数が与えられる
// 0,1,2,...,n-1
// 全ての並べ方を1行ごとに出力する
// ex 0 1 2 / 0 2 1 / 1 0 2 / 1 2 0 / 2 0 1 / 2 1 0
#define _next_permutation(v) do {   \
	for (auto num : v) {            \
		printf("%d ", num);         \
	}                               \
	printf("\n");                   \
} while (next_permutation(v.begin(), v.end()))

// 絶対値
static int32_t _abs(const int32_t x) { return  (x > 0 ? x : -x); }
// 最大公約数
static int gcd(int a, int b)
{
	if (a < b) {
		a ^= b;
		b ^= a;
		a ^= b;
	}
	return b ? gcd(b, a % b) : a;
}
// 最小公倍数
static int lcm(int a, int b) { return a * b / gcd(a, b); }
// 多次元 std::vector 生成
template<class T>
vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); }
// ex) auto dp = make_vec<uint64_t>(SIZE + 1, 2, 2);

// UINT32_MAX
// 4294967295 ≒ 4 * 1e9 


/*

*/
// ABC 162 C
// https://atcoder.jp/contests/abc162/tasks/abc162_c
int main()
{
	uint32_t n;
	cin >> n;

	uint64_t result = 0;
	uint32_t temp;
	for (uint32_t i = 1; i <= n; i++) {
		for (uint32_t j = 1; j <= n; j++) {
			temp = gcd(i, j);
			for (uint32_t k = 1; k <= n; k++) {
				result += gcd(temp, k);
			}
		}
	}
	printf("%llu\n", result);
	return 0;
}

Measured memory_bytes: 3728
import java.util.*;
public class Main {
	
	public static void main(String... args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		
		long[] map = new long[N];
		for (int i = 0; i < N; i++) {
			map[i] = sc.nextLong();
		}
		
		long ans1 = calcAns(map, 1);
		long ans2 = calcAns(map, -1);

		
		System.out.println(Math.min(ans1, ans2));
	}
	
	static long calcAns(long[] map, int type) {
		long ans = 0;
		long sum = 0;
		for (int i = 0; i < map.length; i++) {
			long a = map[i];
			sum += a;
			if (type == -1) {
				if (sum <= type) {
					type = 1;
					continue;
				} else {
					ans += sum + 1;
					type = 1;
					sum = -1;
				}
			} else {
				if (sum >= type) {
					type = -1;
					continue;
				} else {
					ans += Math.abs(sum) + 1;
					type = -1;
					sum = 1;
				}
			}
		}
		
		
		return ans;
	}
}


Measured memory_bytes: 51304
#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;
const ll mod = 1e9+7;
#define all(x) (x).begin(),(x).end()

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    int N,R;
    cin >> N >> R;
    if(N >= 10){
        cout <<R<< "\n";
    }else{
        cout <<R+100*(10-N)<< "\n";
    }
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main {
  public static void main(String[] args)throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      char[] a=br.readLine().toCharArray();
      long count=0;
      for(int i=0;i<a.length;i++){
        if(a[i]=='+')
         count++;
        else
        count--;
      }
      System.out.println(count);
    }
  }


Measured memory_bytes: 21076
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define INF 1e9
#define PI acos(-1)
typedef long long ll;
typedef pair<int, int> p_ii;


int d[110][110];

int main() {
	
	int n, m;
	int a[1010], b[1010], c[1010];
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i] >> c[i];
		a[i]--; b[i]--;
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i == j)d[i][j] = 0;
			else d[i][j] = 1000000;
		}
	}
	
	for (int i = 0; i < m; i++) {
		d[a[i]][b[i]] = min(d[a[i]][b[i]], c[i]);//辺の情報
		d[b[i]][a[i]] = min(d[b[i]][a[i]], c[i]);
	}

	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
	
	int ans = m;
	for (int i = 0; i < m; i++) {
		bool check = false;
		for (int j = 0; j < n; j++) {
			if (d[j][a[i]] + c[i] == d[j][b[i]])check = true;
		}
		if (check)ans--;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

X=gets.to_i
ans=[-1,-1]
-120.upto(120) do|a|
  -120.upto(120) do|b|
    if a**5-b**5==X
        ans=[a,b]
        break
    end
  end
end
puts ans.join(" ")

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

int main() {
    
    int n;
    cin>>n;
    int a=0,b=0;
    for(int i=0;i<n;i++){
        string A,B;
        cin>>A>>B;
        if(A<B) b+=3;
        if(A>B) a+=3;
        if(A==B) {
            a++;
            b++;
        }
    }
    cout<<a<<" "<<b<<endl;
}



Measured memory_bytes: 3156
def sol(_inp=input):
    n,k=map(int,_inp().split())
    ds=list(map(int,_inp().split()))
    res=0
    for l in range(k+1):
        for r in range(k-l+1):
            if l+r<n:
                cur=sum(ds[:l])+sum(ds[n-r:])
                negs=[i for i in ds[:l]+ds[n-r:] if i<0]
            else:
                cur=sum(ds)
                negs=[i for i in ds if i<0]
            rem=min(max(k-l-r,0),len(negs))
            cur-=sum(sorted(negs)[:rem])
            res=max(res,cur)
    return str(res)
print(sol())

Measured memory_bytes: 44908
#include <bits/stdc++.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string.h>
using namespace std;
#define pb push_back
#define all(v) v. begin(),v. end()
#define  rep(i,n,v) for(i=n;i<v;i++)
#define per(i,n,v) for(i=n;i>v;i--)
#define ff first 
#define ss second 
#define pp pair<ll,ll>
#define ll  long long
#define endl '\n'
void solve()
{
  ll n, a,m=1,b=1, c,k=0, i, j,l=1e9+7;
  string s, r, y;
  cin>>n;
  vector<string>v;
  map<string,int>hash;
  rep(i,0,n) {cin>>s;hash[s]++;}
  for(auto x:hash)
  {
    if(x.ss>k)k=x.ss;
  }
  for(auto it=hash.begin();it!=hash.end();it++)
  {
    if(it->ss==k) cout<<it->ff<<endl;
  }
  /*rep(i,0,v.size()) hash[v[i]]++;
  int max_count = 0, res = -1; 

    for (auto i : hash) { 

        if (max_count < i.second) { 

            //res = i.first; 

            max_count = i.second; 

        } 

    }
    vector<string>vec;
    for (auto i : hash) { 

        if (max_count == i.second) { */
/*r=i.first;
sort(r.begin(),r. end());
            cout<<r<<endl;*/
            /*  vec. pb(i.first);

            max_count = i.second; 

        } }
        rep(i,0,vec.size()) cout<<vec[i]<<endl;*/
    
  /*sort(all(v));
  rep(i,0,v.size())
  {
    if(v[i]==v[i+1] && i+1<v.size()) {k++;continue;}
    if(k>m) {m=k;k=0;}
  }
  k=0;
  rep(i,0,v.size())
  {
    if(v[i]==v[i+1] && i+1<v.size()) {k++;continue;}
    if(k==m) {sort(v[i].begin(),v[i].end());cout<<v[i]<<endl;}
    k=0;
  }*/
  
  /*sort(r.begin(),r. end());
  cout<<r;*/
}
int main()
{
 ios_base::sync_with_stdio(false);
  cin. tie(0);cout. tie(0);
    ll t=1;
   //cin>>t;
    while(t--)
    {
      solve();
    }
    return 0;
}

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

using namespace std;

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

    int n, m, x;
    cin >> n >> m >> x;
    int y = max(n, m);
    cout << ceil((double)x / (double)y) << "\n";
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var h, w, ans int
	fmt.Scan(&h, &w)
	if w == 1 || h == 1 {
		ans = 1
	} else {
		ans = ((w+1)/2)*((h+1)/2) + (w/2)*(h/2)
	}
	fmt.Println(ans)
}


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

using namespace std;

#define INF 210000000
#define int long long

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

int lcm(int a, int b) { return a * b / gcd(a, b); }

signed main() {
		int a,b;
		char s;
		cin >> a >> s >> b;
		if(s == '+') cout << a + b << endl;
		else cout << a - b << endl;
}



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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  bool flag = false;
  if(a == b){
    if(b != c){
      flag = true;
    }
  }
  else if(a == c || b == c){
    flag = true;
  }
  if (flag){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
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 (a > b){ a = b; return 1;}return 0;}
template <class T>
void printv(vector<T> v) {for (T t : v) {cout << t << " ";}cout << '\n';}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" <<endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;


int kazu[100001];
const ll mod = 998244353;

int main() {
	int n;
    cin >> n;
    ll a[100005];
    ll b[100005];

    REP(i,n){
        scanf("%lld",&a[i]);
        b[i]=0;
    }

    if(a[0]!=0) cout << 0 << endl;
    else
    {
        ll ans = 1;
        REP(i,n) b[a[i]]++;
        if(b[0]>1) cout << "0" << endl; 
        else{
            REP(i,n)
            {
                if (i == 0) continue;
                ans *= b[a[i]-1];
                ans %= 998244353;
            }
                
            cout << ans << endl;;
        }
    }
    return 0;
}


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

using namespace std;

int main(){
	while(1){
		int face[3]={1,2,3};
		int n,result=1;
		cin>>n;
		if(n==0) break;
		for(int i=0;i<n;i++){
			string str;
			cin>>str;
			int tmp=face[0];
			if(str=="North"){
				face[0]=face[1];
				face[1]=7-tmp;
			} else if(str=="East"){
				face[0]=7-face[2];
				face[2]=tmp;
			} else if(str=="West"){
				face[0]=face[2];
				face[2]=7-tmp;
			} else if(str=="South"){
				face[0]=7-face[1];
				face[1]=tmp;
			} else if(str=="Right"){
				tmp=face[1];
				face[1]=face[2];
				face[2]=7-tmp;
			} else if(str=="Left"){
				tmp=face[1];
				face[1]=7-face[2];
				face[2]=tmp;
			}
			result+=face[0];
		}
		cout<<result<<endl;
	}
	return 0;
}

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

typedef long long ll;
typedef long double ld;

void generisi(string s, int i, int n, int kolko){
    string s1 = s;
    if(i == n+1){
        cout << s << "\n";
        return;
    }
    for(int j=1; j<=kolko; j++){
        s1 += (j-1+'a');
        generisi(s1, i+1, n, kolko);
        s1.pop_back();
    }
    s1 += kolko+'a';
    generisi(s1, i+1, n, kolko+1);
}

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;

	int n;
	cin >> n;
	generisi("", 1, n, 0);
    return 0;
}


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

Measured memory_bytes: 3164
from itertools import permutations as perm
n = int(input())
p = list(map(int,input().split()))
q = list(map(int,input().split()))

a,b = 0,0

for i,tmp in enumerate(sorted(perm(range(1,n+1)))):
    if tmp[0] != p[0] and  tmp[0] != q[0]:
        continue
    for s,t in zip(tmp, p):
        if s != t:
            break
    else:
        a = i+1
    for s,t in zip(tmp, q):
        if s != t:
            break
    else:
        b = i+1
print(abs(a-b)) 
# print(a,b)


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

int main() {
    int s = 0;
    string str;
    cin >> str;
    for(int i=0;i<str.length();i++) {
        s += (int)(str[i]-'0');
    }
    if(s==0) {
        cout << "Yes" << endl;
    } else  if(s%9==0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3744
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
  a[i]-=i+1
b=a[:]
b.sort()
mid1=0
mid2=0
if n%2==1:
  ans=0
  mid1=b[n//2]
  for bb in b:
    ans+=abs(bb-mid1)
  print(ans)
else:
  mid1=b[n//2]
  mid2=b[n//2-1]
  ans1,ans2=0,0
  for bb in b:
    ans1+=abs(bb-mid1)
    ans2+=abs(bb-mid2)
  print(min(ans1,ans2))


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

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

    int digitNum = 0;
    int m = n;
    while (m > 0) {
        m /= 10;
        digitNum++;
    }

    if (digitNum == 1) cout << n << endl;
    else if (digitNum == 2) cout << 9 << endl;
    else if (digitNum == 3) cout << n - 90 << endl;
    else if (digitNum == 4) cout << 909 << endl;
    else if (digitNum == 5) cout << n - 10000 + 910 << endl;
    else cout << 90909 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

const int MAX = 1e5 + 10;
int N, K;
VI G[MAX];

LL dfs(int cur, int prev, int kind) {
    LL ret = kind;

    int nxt_kind = K - 1 - (prev != -1);
    FORE(e, G[cur]) if (e != prev) {
        (ret *= dfs(e, cur, nxt_kind)) %= MOD;
        nxt_kind--;
    }

    return ret;
}

int main(void) {
    scanf("%d%d", &N, &K);
    REP(i, N - 1) {
        int a, b;
        scanf("%d%d", &a, &b);
        a--; b--;
        G[a].EB(b);
        G[b].EB(a);
    }

    REP(i, N) {
        if (K - 1 < (int)G[i].size()) {
            cout << 0 << endl;
            return 0;
        }
    }

    cout << dfs(0, -1, K) << endl;
}


Measured memory_bytes: 11520
#include<stdio.h>
#define N 100
int selectionSort(int*,int);

int main()
{
  int i,n,a[N],count;

  scanf("%d",&n);
  for(i=0; i<n; i++) scanf("%d",&a[i]);
  
  count = selectionSort(a,n);
  
  for(i=0; i<n; i++) {
    printf("%d",a[i]);
    if(i<n-1) printf(" ");
  }
  printf("\n%d\n",count);
  
  return 0;
}

int selectionSort(int a[],int n)
{
  int i,j,minj,tmp,count=0;

  for(i=0; i<n-1; i++) {
    minj = i;
    for(j=i; j<n; j++)
      if(a[j]<a[minj]) minj = j;
    if(minj!=i){
      tmp = a[i];
      a[i] = a[minj];
      a[minj] = tmp;
      count++;
    }
  }
  return count;
}
  

Measured memory_bytes: 604
def judge(L,i,j):
    a=0
    if L[i][j]=="#":
        a= (L[i-1][j]!="#" and L[i+1][j]!="#"
        and L[i][j-1]!="#" and L[i][j+1]!="#")
    return a

def judge_ed(L,i,j):
    a=0
    if L[i][j]=="#":
        if i == 0:
            a= (L[i+1][j]!="#" and L[i][j-1]!="#" and L[i][j+1]!="#")
        elif i == h-1:
            a= (L[i-1][j]!="#" and L[i][j-1]!="#" and L[i][j+1]!="#")
        elif j == 0:
            a= (L[i-1][j]!="#" and L[i+1][j]!="#" and L[i][j+1]!="#")
        else:
            a= (L[i-1][j]!="#" and L[i+1][j]!="#" and L[i][j-1]!="#")
    return a

h,w=map(int,input().split())
A=[input() for _ in range(h)]
ans=0

for i in range(h):
    for j in range(w):
        a=0
        if i in (0,h-1) and j in (0,w-1):a=0
        elif i in (0,h-1) or j in (0,w-1):
            a = judge_ed(A,i,j)
        else:a = judge(A,i,j)
        if a==1:
            ans=1

print("Yes" if ans==0 else "No")



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define arrprint(v,n) rep(i,0,n-1)cout << v[i] << " ";cout << endl;
#define matprint(v,n,m) rep(i,0,n-1){rep(j,0,m-1){cout << v[i][j] << " ";}cout << endl;}
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
typedef long long ll;
typedef pair<int,int> P;
/*---fast pow---*/
ll mod_pow(ll x,ll n){
  ll res = 1;
  while(n > 0){
    if(n & 1) res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}



//*---mint---*/
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint operator~() const { return mint(1) / *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint& operator/=(const mint& a){ (x*=a.pow(mod-2).x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  mint operator/(const mint& a)const{ return mint(*this) /= a;}
  mint pow(ll t) const {
    if(!t) return 1;
    mint res = pow(t/2);
    res *= res;
    return (t&1)?res*x:res;
  }
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
mint ex(mint x, ll t) { return x.pow(t);}
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
typedef vector<mint> vm;
struct comb {
  vm f, g;
  comb(){}
  comb(int mx):f(mx+1),g(mx+1) {
    f[0] = 1;
    rep(i,1,mx) f[i] = f[i-1]*i;
    g[mx] = f[mx].pow(mod-2);
    for(int i=mx;i>0;i--) g[i-1] = g[i]*i;
  }
  mint c(int a, int b) {
    if (a < b) return 0;
    return f[a]*g[b]*g[a-b];
  }
} c(3e6);
//c.c(a,b)=>aCb mod

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

    mint ans = 0;
    
    rep(i,0,k){
        ans += c.c(n-1,i) * c.c(n,i);
    }

    cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 47104
#!/usr/bin/ruby
#encoding: utf-8

# 「前から調べる場合、できるだけ1下げるほうが、構成しやすい」
# (貪欲法)

n = gets.to_i
h = gets.split.map(&:to_i)

ans = false

if n == 1
  puts "Yes"
  exit
end

# できるだけ1下げる
(0..n-1).each do |i|
  if i == 0
    h[i] -= 1
  else
    if h[i-1] <= h[i]-1
      h[i] -= 1
    end
  end
end

(0..n-2).each do |i|
  if h[i] > h[i+1]
    puts "No"
    exit
  end
end

puts "Yes"

Measured memory_bytes: 8580
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n, a, b = map(int, input().split())
    blue = (n // (a+b)) * a
    r = n % (a+b)
    if r <= a:
        print(blue+r)
    else:
        print(blue+a)

if __name__ == '__main__':
    main()

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

using namespace std;
using ll = long long;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()

ll ts = 1000000007;

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

  long double a, b, c;
  cin >> a >> b;
  c = a * b;
  cout << (long long int)c;
}


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

int main () {
  int N,M;
  cin >> N >> M ;
  int A[N];
  int SUM=0;
  for (int i=0;i< N;i++){
    cin >> A[i];
    SUM+=A[i];
  }

  string ans="No";
  int count=0;
  double perA= (double)SUM / (4 * M) ;
  for (int a : A) {
    if (perA <= a){count++;}
    if(count >= M) {ans="Yes"; break;}
  }

  cout << ans;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<climits>
#include<algorithm>
#include<vector>
#include<valarray>
#include<string>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iostream>
#include<iomanip>
using namespace std;
   
   
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;i>=0;i--)
#define DREP(i,n) for(int i=n;i>0;i--)
#define Rep(i,m,n) for(int i=m;i<n;i++)
#define ReP(i,m,n) for(int i=m;i<=n;i++)
#define scani(a) scanf("%d",&a)
#define scand(a) scanf("%lf",&a)
#define scans(s) scanf("%s",s)
#define readi(a) int a;scanf("%d",&a)
#define printi(a) printf("%d",a)
#define prints(s) printf("%s",s)
#define even(n) (((n)+1)%2)
#define odd(n) ((n)%2)
#define sg(x) ((x)?1:0)
#define LF printf("\n")
#define SPACE printf(" ")
#define pb push_back
#define mp make_pair
#define bs binary_search
#define all(a) (a).begin(),(a).end()
#define forall(itr,a) for(auto itr=(a).begin();itr!=(a).end();++itr)
   
typedef long long LL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<double,double> pdd;
typedef pair<int,int> pii;
   
const double pi = acos(-1.0);
double rad(double t){return t*pi/180.0;}
double deg(double d){return d*180.0/pi;}
template<typename T>T GCD(T x,T y){return y?GCD(y,x%y):x;}
template<typename T>T LCM(T x,T y){return x/GCD(x,y)*y;}
template<class T>ostream& operator<<(ostream& os,const set<T>& s){os<<"{";for(auto itr=s.begin();s.end() != itr;++itr){if(itr!=s.begin())os<<',';os<<*itr;}os<<"}";return os;}
template<class S,class T>ostream& operator<<(ostream& os,const pair<S,T>& p){os<<'('<<p.first<<','<<p.second<<')';return os;}
const int MOD = (int)pow(10,9) +7;


//begin global variable
LL dp[51][51][2600]={};// dp[1~i][choose j(<=i)][sum]
//end   global variable

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


  int N,A,x[51];
  cin >> N >> A;
  REP(i,N) cin >> x[i];
  
  dp[0][0][0]=1;
  REP(i,N){
    rep(j,N+1){
      rep(sum,2500+1){
        dp[i][j][sum] += dp[i-1][j][sum];
        if(j-1>=0 && sum-x[i]>=0)
          dp[i][j][sum] += dp[i-1][j-1][sum-x[i]];
      }
    }
  }
  LL ans = 0;
  REP(i,N){
    ans += dp[N][i][i*A];
  }

  cout << ans << endl;
  //end   main()
  return 0;
}


Measured memory_bytes: 52096
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

int32_t main(){
	int n;
	cin >> n;
	int a[n];
	int sumi = 0;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		sumi += a[i];
	}
	int ans = sumi;
	int cur = 0;
	for(int i = 0; i < n; i++){
		cur += a[i];
		ans = min(ans,abs(sumi-cur-cur));
	}
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']
require 'prime'

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

n,k = inp
a = inp

imos = na(n+1,0)
rand_v = rand(n)
f = false
k.times do |c|
  min = n
  imos.fill(0)
  a.each.with_index do |d,i|
    imos[small(n,i+d+1)] -= 1
    imos[big(0,i-d)] += 1
  end
  now = 0
  n.times do |i|
    now += imos[i]
    a[i] = now
  end
  if(a[0]==n)
    if(f)
      break
    end
    f=true
  end
end
puts a.join(" ")

Measured memory_bytes: 37120
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    string s;
    cin >> s;
    int n = s.size();
    vector<int> ans(n, 0);
    int cnt = 0, last = -1;
    bool f = true;
    rep(i, n)
    {
        if (f)
        {
            if (s[i] == 'R')
            {
                cnt++;
                continue;
            }
            f = false;
            ans[i] += cnt / 2;
            ans[i - 1] += cnt - cnt / 2;
            i--;
            cnt = 0;
            last = i;
        }
        else
        {
            if (s[i] == 'L')
            {
                int d = i - last;
                if (d % 2)
                    ans[last + 1]++;
                else
                    ans[last]++;
                continue;
            }
            i--;
            f = true;
        }
    }
    rep(i, n) cout << ans[i] << " ";
    cout << endl;
}

Measured memory_bytes: 1488
S=input()
T=["dream","dreamer","erase","eraser"]
S=S.replace(T[3],"0000000").replace(T[2],"00000").replace(T[1],"0000000").replace(T[0],"00000")
U=""
for k in range(len(S)):
    U+="0"
if S==U:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3316
N = int(input())
Ai = [int(i) for i in input().split(" ")]
Bi = [int(i) for i in input().split(" ")]
Ci = [int(i) for i in input().split(" ")]

res = 0
pre_i = None
for i in Ai:
  res += Bi[i-1]
  if pre_i and i == pre_i+1:
    res += Ci[i-2]
  pre_i = i

print(res)

Measured memory_bytes: 3064