akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

typedef long long ll; //64bit型
using namespace std;
const ll INF = 1LL << 20;

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

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

        cin >> N >> Q;
        cin >> S;

        vector<int> l(Q), r(Q);
        for (int i = 0; i < Q; i++)
        {
                cin >> l[i] >> r[i];
        }

        vector<int> sum(N + 1, 0);
        for (int i = 1; i < N; i++)
        {
                sum[i + 1] = sum[i];
                if (S[i - 1] == 'A' && S[i] == 'C')
                {
                        sum[i + 1]++;
                }
        }
        //0 1 2 3 4 5 6
        // A C A C A C
        // 1 2 3 4 5 6
        for (int i = 0; i < Q; i++)
        {
                int ans = sum[r[i]] - sum[l[i]];
                cout << ans << endl;
        }

        return 0;
}


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

typedef long long ll;

vector<pair<int, int>> g[100005];
int r[100005], c[100005], n, k, a, mx, b;

void dfs(int p, int pr)
{
    int ci = 1;
    for (auto i : g[p])
        if (i.first != pr)
        {
            int a = i.first,
                b = i.second;
            if (ci == c[p])
                ++ci;
            mx = max(mx, ci);
            r[b] = c[a] = ci++;
            dfs(a, p);
        }
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cin >> n;
    for (int i = 0; i < n - 1; ++i)
    {
        cin >> a >> b;
        g[a].push_back({b, i});
        g[b].push_back({a, i});
    }
    dfs(1, -1);
    cout << mx << endl;
    for (int i = 0; i < n - 1; ++i)
        cout << r[i] << endl;
    return 0;
}

Measured memory_bytes: 8704
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, a[300005] = {}, b[3] = {}, c[3] = {};
    string s;
    cin >> n >> s;
    ll z = 1, u = n, v = 0, w = 0;
    for (int i = 0; i < n + n + n; i++) {
        int x, y, z;
        if (s[i] == 'R') x = 0, y = 1, z = 2;
        else if (s[i] == 'G') x = 1, y = 2, z = 0;
        else x = 2, y = 0, z = 1;
        if (c[x]) c[x]--, a[i] = -1;
        else if (b[y]) b[y]--, c[z]++, a[i] = 0;
        else if (b[z]) b[z]--, c[y]++, a[i] = 0;
        else b[x]++, a[i] = 1;
    }
    //for (int i = 0; i < n + n + n; i++) cout << a[i] << ' ';
    for (int i = 0; i < n + n + n; i++) {
        if (a[i] == 1) z = z * u % 998244353, u--, v++;
        else if (a[i] == 0) z = z * v % 998244353, v--, w++;
        else z = z * w % 998244353, w--;
    }
    cout << z;
    //BBRGRRGRGGRBBGB
    //((.).()(..()).)
    //5 20 40 40 40 120 120 240 480 480 480 960 960 960 960
}


Measured memory_bytes: 1872
import std.stdio;

void main() {
  int width, height;
  while(readf("%d %d\n", &width, &height), (width + height) != 0) {
    int[][] route = new int[][](width, height);
    bool[][] zones = new bool[][](width, height);
    int number;
    readf("%d\n", &number);
    for(int i, j, n = 0; n < number; n++) {
      readf("%d %d\n", &i, &j);
      zones[i - 1][j - 1] = true;
    }
    
    route[0][0] = 1;

    for(int i = 1; i < width; i++)
      if (!zones[i][0])
        route[i][0] = route[i - 1][0];
    for(int j = 1; j < height; j++)
      if (!zones[0][j])
        route[0][j] = route[0][j - 1];
  
    for(int i = 1; i < width; i++) {
      for(int j = 1; j < height; j++) {
        if (zones[i][j]) continue;        
        if (zones[i - 1][j] && zones[i][j - 1]) route[i][j] = 0;
        else if (zones[i - 1][j]) route[i][j] = route[i][j - 1];
        else if (zones[i][j - 1]) route[i][j] = route[i - 1][j];
        else {
          route[i][j] = route[i - 1][j] + route[i][j - 1];
        }
      }
    }
    writeln(route[width - 1][height - 1]);
  }
}

Measured memory_bytes: 1068
#include <bits/stdc++.h>
using namespace std;
#define endl '\n';
#define ll long long
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back

int main() {

   // IOS;
   int n,k;
   cin>>n>>k;
   int a[n];
   rep(i,0,n)cin>>a[i];
   sort(a,a+n);
   ll sum=0;
   rep(i,0,k)sum+=a[i];
   cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3636
def main():
    S = input()

    acgt = []
    flag = False
    count = 0
    for s in S:
        if s == "A" or s == "C" or s == "G" or s == "T":
            if flag:
                count += 1
            else:
                flag = True
                count = 1
        else:
            acgt.append(count)
            flag = False
            count = 0

    if count > 0:
        acgt.append(count)
        
    print(max(acgt))


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string a[n], b[m];
  for(int i=0; i<n; i++)
    cin >> a[i];
  for(int i=0; i<n; i++)
    cin >> b[i];
  for(int i=0; i<n-m+1; i++)
    for(int j=0; j<n-m+1; j++){
      bool flag=0;
      for(int k=0; k<m; k++)
        for(int l=0; l<m; l++)
          if(a[i+k][j+l]!=b[k][l])
            flag = 1;
      if(flag==0){
        cout << "Yes";
        return 0;
      }
    }

  cout << "No";
  return 0;
}

Measured memory_bytes: 3576
#include "bits/stdc++.h"
using namespace std;

#define eb emplace_back
#define all(x) begin(x), end(x)
#define log(x) cout << (x) << endl
#define rep(i, n) for(int i=0;i<(int)(n);++i)

using pi = pair<int,int>;
using vpi = vector<pi>;
using ll = long long;

int main() {
	int n,a,b;
	cin >> n;
	vpi tasks;
	rep (i, n) {
		cin>>a>>b;
		tasks.emplace_back(b,a);
	}
	sort(all(tasks));

	ll t=0;
	for (auto p: tasks) {
		t += p.second;
		if (t > p.first) {
			return log("No"),0;
		}
	}
	log("Yes");
}


Measured memory_bytes: 2420
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map>
#include <map>
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
using namespace std;
typedef long long LL;

int main()
{
    long long n, mi = 10000000000, ma = 0;
    cin >> n;

    vector<long long> a(n);

    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        ma = max(ma, a[i]);
        mi = min(mi, a[i]);
    }

    cout << abs(ma - mi) << endl;

    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
array = Array.new(n).map { Array.new(n, 0) }
n.times do
  input = gets.split(' ').map(&:to_i)
  unless input[1].zero?
    input[2..-1].each do |value|
      array[input[0] - 1][value - 1] = 1
    end
  end
end
puts array.map { |arr| arr.join ' ' }


Measured memory_bytes: 6984
#include<iostream>
using namespace std;
int main(){
  int A,B,C,D,x,y;
  cin>>A>>B>>C>>D;
  x= A + B ;
  y= C + D ;
  if(x>y){
  cout<<"Left"<<endl;
  }
  else if(x==y){
  cout<<"Balanced"<<endl;
  }
  else{
  cout<<"Right"<<endl;
  }
return 0;
}

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

#define rep(i,s,e) for(int i = (s);i <= (e);i++)

typedef long long ll;
int n;
ll a;
ll b;
vector<ll> h;

bool able(int k)
{
	ll damage = b * k;

	ll cou = 0;
	for(ll hp : h)
	{
		hp = max(hp - damage , 0LL);

		cou += hp / a + min(hp % a , 1LL);
	}

	return cou <= k;
}

ll binary()
{
	ll ng = 0;
	ll ok = 1e9 + 1;

	while(abs(ok - ng) > 1)
	{
		ll mid = (ok + ng) / 2;
		if(able(mid))
		{
			ok = mid;
		}
		else
		{
			ng = mid;
		}
	}
	return ok;
}

int main()
{
	cin >> n >> a >> b;
	a -= b;
	h.resize(n);

	rep(i,0,n - 1)
	{
		cin >> h[i];
	}

	sort(h.rbegin(),h.rend());

	cout << binary() << endl;
	return 0;
}



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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

ll pow(ll x, ll y, ll mod) {
    if (y == 0) {
        return 1;
    }
    if (y % 2 == 0) {
        return pow(x * x % mod, y / 2, mod) % mod;
    } else {
        return x * pow(x, y - 1, mod) % mod;
    }
}


void solve() {
    ll N;
    string X;
    cin >> N >> X;
    ll pop_count = 0;
    rep(i, N) {
        if (X[i] == '1') pop_count++;
    }
    if (pop_count == 0) {
        rep(i, N) {
            cout << 1 << '\n';
        }
        return;
    }
    // +1
    ll v1 = 0;
    // -1
    ll v2 = 0;
    rep(i, N) {
        if (X[i] == '1') {
            v1 += pow(2, N - 1 - i, pop_count + 1);
            if (pop_count > 1) {
                v2 += pow(2, N - 1 - i, pop_count - 1);
            }
        }
    }
    vector<ll> B(1e5 * 3 + 1, 0);
    rep2(i, 1, 1e5 * 2 + 1) {
        ll c = __builtin_popcount(i);
        ll r = i % c;
        if (r == 0) {
            B[i] = 1;
        } else {
            B[i] = B[r] + 1;
        }
    }
    rep(i, N) {
        ll x = 0;
        if (X[i] == '1') {
            ll mod = pop_count - 1;
            if (mod == 0) {
                cout << 0 << '\n';
                continue;
            } else {
                x = v2 - pow(2, N - 1 - i, mod);
                if (x < 0) x += mod;
                x %= mod;
            }
        } else {
            ll mod = pop_count + 1;
            x = v1 + pow(2, N - 1 - i, mod);
            x %= mod;
        }
        cout << B[x] + 1 << '\n';
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 5960
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double a = sc.nextFloat();
		double b = sc.nextFloat();
		double h = sc.nextFloat();
		double m = sc.nextFloat();

		double tanshin = h *5 + (m/12);
		double kakudo = 0;
		if(m > tanshin) {
			kakudo = (m-tanshin) *6;
		}else {
			kakudo = (tanshin -m) *6;
		}
		if(kakudo == 0) {
			System.out.println(Math.abs(a-b));
			return;
		}
		if(kakudo >180) {
			kakudo = 360 - kakudo;
		}
		double answer = Math.sqrt((a* a) + (b* b) -2* a*b * Math.cos(Math.toRadians(kakudo)));
		System.out.println(answer);


	}
}

Measured memory_bytes: 28892
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	ll ans=INFLL;
	cin >>n;
	V a(n);
	ll sum=0LL;
	rep(i,n){
		cin>>a[i];
		sum += a[i];
		if(i!=0){
			a[i]+=a[i-1];
		}
	//	clog<<a[i]<<endl;

	}
	for(int i=0;i<n-1;i++){
		chmin(ans,abs(2*a[i]-sum));
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main() {
   int N;
   cin >> N;
   vector<int64_t> L(87);

   L.at(0) = 2LL;
   L.at(1) = 1LL;
   for (size_t i = 2; i < N+1; i++) {
     L.at(i) = L.at(i-1)+L.at(i-2);
   }
   cout << L.at(N) << endl;
}


Measured memory_bytes: 256
import java.io.*;

class Main{
	public static void main(String[]args)throws IOException{
		
		BufferedReader br=
			new BufferedReader(new InputStreamReader(System.in));
		
		String str=br.readLine();

		String[] num=str.split(" ");

		int W=Integer.parseInt(num[0]);
		int H=Integer.parseInt(num[1]);
		int x=Integer.parseInt(num[2]);
		int y=Integer.parseInt(num[3]);
		int r=Integer.parseInt(num[4]);
		
		if((x+r)>W || (x-r)<0 || (y+r)>H || (y-r)<0){
			System.out.println("No");
		}
		else{
			System.out.println("Yes");
		}
	}
}

Measured memory_bytes: 24496
// atcoder/abc134/B/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, d;
  while (cin >> n >> d) {
    cout << (n + 2 * d) / (2 * d + 1) << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}


macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let a: usize = sc.cin();
    let b: usize = sc.cin();
    let c: usize = sc.cin();

    let mut ans = "No";
    if a == b && b != c { ans = "Yes" }
    if a == c && b != c { ans = "Yes" }
    if b == c && a != c { ans = "Yes" }
    put!(ans);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


Measured memory_bytes: 4352
var
  a:array[1..10000]of longint;
  i,j,k,n,m,p,q,w:longint;
  s:string;
procedure qsort(l,r:longint);
var
  i,j,mid,p:longint;
begin
  i:=l;j:=r;
  mid:=a[(l+r) div 2];
  repeat
    while a[i]<mid do inc(i);
    while a[j]>mid do dec(j);
    if i<=j then
      begin
        p:=a[i];a[i]:=a[j];a[j]:=p;
        inc(i);
        dec(j);
      end;
  until i>j;
  if l<j then qsort(l,j);
  if i<r then qsort(i,r);
end;
begin
  readln(k);
  readln(n,m);
  for i:=1 to k do read(a[i]);
  qsort(1,k);
  p:=0;
  q:=0;
  w:=0;
  for i:=1 to k do
  begin
    if a[i]>n then break;
    inc(p);
  end;
  for j:=i to k do
  begin
    if a[j]>m then break;
    inc(q);
  end;
  for i:=j to k do
  begin
    if a[i]>m then inc(w);
  end;
  if p>q then p:=q;
  if p>w then p:=w;
  writeln(p);
end.

Measured memory_bytes: 128
#include<cstdio>//输入输出要用的文件。 
#include<cmath>//sqrt要用的文件。 
using namespace std;
long long n,ans;//10的10次方超int。 
int s;
int main(){
    scanf("%lld",&n);//long long的scanf要用lld。 
    for(int i=sqrt(n);i>0;--i) //从平方根开始搜索，用n除以搜到的第一个数，计算出它的位数就是答案。 
        if(n%i==0){
            ans=n/i;
            break;
        }
    while(ans>0){//计算位数。 
        ++s;
        ans/=10;
    }
    printf("%d\n",s);//s为int型变量。 
    return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

inline int f(int n){
	int ret = 0;
	while(n){
		ret += n % 10;
		n/=10;
	}
	return ret;
}

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

	if(n % f(n) == 0)
		puts("Yes");
	else
		puts("No");

	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N,M,C = map(int,input().split())
B = list(map(int,input().split()))
A = [list(map(int,input().split())) for i in range(N)]
ans=0
for i in range(N):
    sum=0
    for j in range(M):
        sum+=A[i][j]*B[j]
    if sum+C>0:
        ans+=1
    
print(ans)


Measured memory_bytes: 38384
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
#include <stack>
#include <map> // pair
#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
typedef std::stack<int> IntStack;
typedef std::stack<char> charStack;

using namespace std;
using ll = long long;
typedef pair <ll, ll > pll;

int main()
{
	ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	ll n, m, K;
	ll memo[1003][1003] = { {} };
	ll memox[1003] = {};
	ll memoy[1003] = {};
	ll x[1000006] = {};
	ll y[200005] = {};
	ll z[200005] = {};
	string s;
	string s1, s2;
	//IntStack yStack;
	//charStack Stack;
	//vector<pair<int, int> > pairs(a);
	cin >> a;
	cin >> b;
	e = a;
	f = b;
	cin >> c;
	cin >> d;
	while (e !=c)
	{
		e++;
		cout << "R";
	}
	while (f != d+1)
	{
		f++;
		cout << "U";
	}
	while (e != a-1)
	{
		e--;
		cout << "L";
	}
	while (f != b)
	{
		f--;
		cout << "D";
	}
	e++;
	cout << "R";
	f--;
	cout << "D";
	while (e != c+1)
	{
		e++;
		cout << "R";
	}
	while (f != d)
	{
		f++;
		cout << "U";
	}
	while (e != a)
	{
		e--;
		cout << "L";
	}
	while (f != b)
	{
		f--;
		cout << "D";
	}
	cout << endl;
	//cout << ans << endl;


	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	//cout << "" << endl;

	return 0;
}
//char型の文字数字は、-'0'で数値に変換できる
//accumulate(x, x + a, 0);//int型までの配列の合計
//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;
//cout << char(z - 'a');
//log10(i) + 1 //10進数の桁数を取得

//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}

//最小公倍数
//ll x = a * b;
//ll tmp;
///* 自然数 a > b を確認・入替 */
//if (a<b) {
//	tmp = a;
//	a = b;
//	b = tmp;
//}
///* ユークリッドの互除法 */
//ll r = a % b;
//while (r != 0) {
//	a = b;
//	b = r;
//	r = a % b;
//}
//a = x / b;//答え

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

int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	for(int i=0; i<n; i++) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	int m = n/2;
	cout << v[m] - v[m-1];
	return 0;
}


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

int main(void){
    int n;
    cin >> n;
    vector<int> vec(n);
    rep(i,n) cin >> vec.at(i);

    sort(vec.begin(),vec.end());
    reverse(vec.begin(),vec.end());
    int ans = 0;
    for(int i=0;i<n;i++){
        if(i%2==0){
            ans -= vec.at(i);
        }else{
            ans += vec.at(i);
        }
    }
    cout << abs(ans) << endl;
}

Measured memory_bytes: 256
import sys
import math
from collections import deque
input = sys.stdin.readline
H = int(input())
n = 0
for i in range(10**3):
    if H == 1:
        break
    H //= 2
    n += 1
ans = 1
for i in range(n):
    ans *= 2
    ans += 1
print(ans)

Measured memory_bytes: 3316
#include<iostream>
#include<algorithm>
#include<cmath>

typedef struct _pair{
long long int B;
long long int C;
}pair;

bool comC(pair &a,pair &b){
  return a.C<b.C;
}


int main(){
  long long int N,M,A[100000],newA[100000],result=0;
  pair data[100000];
  std::cin>>N>>M;
  for(int i=0;i<N;i++)
    std::cin>>A[i];
  for(int i=0;i<M;i++)
    std::cin>>data[i].B>>data[i].C;

  std::sort(A,A+N,std::greater<int>());
  std::sort(data,data+M,comC);

  int index=N-1;
  for(int i=M-1;i>=0;i--){
    for(int j=data[i].B;j>0;j--){
      newA[index--]=data[i].C;
      if(index<0)  break;
    }
    if(index<0) break;
  }
  for(int i=0;i<N;i++){
    result+=std::max(A[i],newA[i]);
  }
  std::cout<<result<<std::endl;
  return 0;
}


Measured memory_bytes: 3328
package main

import (
  "fmt"
  "bufio"
  "os"
  "strconv"

  // "math"
)

func foo(s, t string, a, b int, u string) (int, int) {
  if u == s {
    a -= 1
  } else if u == t {
    b -= 1
  }
  return a, b
}


var sc = bufio.NewScanner(os.Stdin)
func nextInt() int {
    sc.Scan()
    i, e := strconv.Atoi(sc.Text())
    if e != nil {
        panic(e)
    }
    return i
}

func nextText() string {
    sc.Scan()
    return sc.Text()
}

func main() {
  // input
  sc.Split(bufio.ScanWords)
  s := nextText()
  t := nextText()
  a := nextInt()
  b := nextInt()
  u := nextText()

  // output
  newa, newb := foo(s, t, a, b, u)
  fmt.Printf("%d %d\n", newa, newb)
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC058B
{
    class Program
    {
        static void Main(string[] args)
        {
            string O, E;
            O = Console.ReadLine();
            E = Console.ReadLine();

            string ans="";
            int flgOE;

            if (O.Length - E.Length == 1)
                flgOE = 1;
            else
                flgOE = 0;

            for (int i = 0; i < O.Length; i++)
            {
                if (flgOE == 0 || (flgOE == 1 && i < O.Length - 1))
                    ans += O[i].ToString() + E[i].ToString();
                else
                    ans += O[i].ToString() ;
            }
            Console.WriteLine(ans);
        }

    }
    
}


Measured memory_bytes: 13140
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18) + 1;
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll a,b,q;
vector<ll> s,t,x;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a>>b>>q;
    s.resize(a);
    t.resize(b);
    x.resize(q);
    rep(i,a){
        cin>>s[i];
    }
    rep(i,b){
        cin>>t[i];
    }
    rep(i,q){
        cin>>x[i];
    }
    vector<ll> c(q),d(q),ans(q);
    rep(i,q){
        c[i]=lower_bound(ALL(s),x[i])-s.begin();
        d[i]=lower_bound(ALL(t),x[i])-t.begin();
    }
    rep(i,q){
        ll score=LINF;
        if(c[i]!=a&&d[i]!=b){
            ll temp=max(abs(s[c[i]]-x[i]),abs(t[d[i]]-x[i]));
            chmin(score,temp);
        }
        if(c[i]!=0&&d[i]!=0){
            ll temp=max(abs(s[c[i]-1]-x[i]),abs(t[d[i]-1]-x[i]));
            chmin(score,temp);
        }
        if(c[i]!=0&&d[i]!=b){
            ll temp=max(abs(s[c[i]-1]-x[i]),abs(t[d[i]]-x[i]));
            ll temp1=min(abs(s[c[i]-1]-x[i]),abs(t[d[i]]-x[i]));
            chmin(score,temp1*2+temp);
        }
        if(c[i]!=a&&d[i]!=0){
            ll temp=max(abs(s[c[i]]-x[i]),abs(t[d[i]-1]-x[i]));
            ll temp1=min(abs(s[c[i]]-x[i]),abs(t[d[i]-1]-x[i]));
            chmin(score,temp1*2+temp);
        }
        ans[i]=score;
    }
    rep(i,q)
    cout << ans[i] << "\n";
}


Measured memory_bytes: 6016
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#define rep(index,num) for(int index=0;index<num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
typedef long long ll;
using namespace std;
typedef pair<int,int> pint;
int main(){
	int N,W;
	int value[100],weight[100];
	int dp[101][10001];
	scan(N);scan(W);
	rep(i,N){
		scan(value[i]);scan(weight[i]);
	}
	rep(w,W+1){
		dp[0][w]=0;
	}
	rep(i,N){
		rep(w,W+1){
			if(w>=weight[i]) dp[i+1][w]=max(max(dp[i][w-weight[i]]+value[i],dp[i+1][w-weight[i]]+value[i]),dp[i][w]);
			else dp[i+1][w]=dp[i][w];
		}
	}
	prin(dp[N][W]);
	return 0;
}



Measured memory_bytes: 6972
inp = []
tmp = 10
ans = 0
temp = 0
for _ in range(5):
    inp.append(input())
for i in range(5):
    if tmp > int(inp[i][-1]) and int(inp[i][-1]) != 0:
        tmp = int(inp[i][-1])
        temp = i
last = inp.pop(temp)
for j in inp:
    if j[-1] == "0":
        ans += int(j)
    else:
        ans += int(j[:-1]+ "0") + 10
ans += int(last)
print(ans)


Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.StringTokenizer;
class InputReader {
    BufferedReader buf;
    StringTokenizer tok;
 
    public InputReader() {
        buf = new BufferedReader(new InputStreamReader(System.in));
//        try {
//            Path currentRelativePath = Paths.get("");
//            String s = currentRelativePath.toAbsolutePath().toString();
//            String curDir = System.getProperty("user.dir");
//            System.out.println("current dir: " + s);
//            buf = new BufferedReader(new FileReader("/Users/wangdong/Dropbox/LC_Java/src/test/resources/testA.txt"));
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        }
    }
 
    public boolean hasNext() {
        while (tok == null || !tok.hasMoreElements()) {
            try {
                tok = new StringTokenizer(buf.readLine());
            } catch (Exception e) {
                return false;
            }
        }
        return true;
    }
 
    public String next() {
        if (hasNext()) return tok.nextToken();
        return null;
    }
 
    public int nextInt() {
        return Integer.parseInt(next());
    }
 
    public long nextLong() {
        return Long.parseLong(next());
    }
 
    public  Double nextDouble() {
        return Double.parseDouble(next());
    }
 
    public BigInteger nextBigInteger() {
        return new BigInteger(next());
    }
 
    public BigDecimal nextBigDecimal() {
        return new BigDecimal(next());
    }
}
 
 
public class Main {
  public static void main(String[] args) {
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt();
     	int[] p = new int[n+1];
    	p[1] = -1;
    	int[] cnt = new int[n+1];
    	for (int i = 2; i <=n; i++) {
          p[i] = in.nextInt();
          cnt[p[i]] += 1;
        }
		
    	for (int i = 1; i <= n; i++) {
          out.println(cnt[i]);
        }
        out.close();
    }
  
}

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

int main()
{
	long long n, m, k;
	cin >> n >> m >> k;

	vector<long long> av(n);
	for (auto& a : av) {
		cin >> a;
	}
	vector<long long> bv(m);
	for (auto& b : bv) {
		cin >> b;
	}

	long long ret = 0;
	{
		long long ai = 0;
		long long bi = 0;
		long long c = 0;

		while (c <= k) {
			if (ai < n) {
				c += av[ai++];
			}
			else {
				break;
			}
		}

		while (c <= k) {
			if (bi < m) {
				c += bv[bi++];
			}
			else {
				break;
			}
		}

		if (c <= k) {
			cout << n + m << endl;
			return 0;
		}

		while (0 < ai) {
			c -= av[--ai];
			if (k < c) {
				continue;
			}

			while (c <= k) {
				if (bi < m) {
					c += bv[bi++];
				}
				else {
					break;
				}
			}

			if (c <= k) {
				ret = max(ai + bi, ret);
			}
			else {
				ret = max(ai + bi - 1, ret);
			}
		}
	}

	swap(n, m);
	av.swap(bv);

	{
		long long ai = 0;
		long long bi = 0;
		long long c = 0;

		while (c <= k) {
			if (ai < n) {
				c += av[ai++];
			}
			else {
				break;
			}
		}

		while (c <= k) {
			if (bi < m) {
				c += bv[bi++];
			}
			else {
				break;
			}
		}

		if (c <= k) {
			cout << n + m << endl;
			return 0;
		}

		while (0 < ai) {
			c -= av[--ai];
			if (k < c) {
				continue;
			}

			while (c <= k) {
				if (bi < m) {
					c += bv[bi++];
				}
				else {
					break;
				}
			}

			if (c <= k) {
				ret = max(ai + bi, ret);
			}
			else {
				ret = max(ai + bi - 1, ret);
			}
		}
	}


	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 6344
N = int(input())
a = list(map(int, input().split()))
b = [1] * N
c = min(a)

while max(b) != 0:
    for i in range(N):
        b[i] = a[i] % c
    for i in range(N):
        if b[i] != 0:
            c = min(c, b[i])
print(c)

Measured memory_bytes: 14224
N, L = map(int, input().split())
A = list(map(int, input().split()))
k = -1
for i in range(N-1):
    if A[i]+A[i+1]>=L:
        k=i+1
if k==-1:
    print("Impossible")
else:
    print("Possible")
    res = []
    for i in reversed(range(1,k+1)):
        res.append(i)
    for i in range(k+1,N):
        res.append(i)
    for i in reversed(res):
        print(i)

Measured memory_bytes: 91772
#include<bits/stdc++.h>
using namespace std;
int read(){
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9')  f=(c=='-')?-1:1,c=getchar();
    while(c>='0'&&c<='9')  x=x*10+c-'0',c=getchar();
    return x*f;
}
int a[100001];
int main(){
	int n=read(),ans=0;
	for(int i=1;i<=n;i++)
		a[i]=read(),ans+=a[i];
	int m=read();
	for(int i=1;i<=m;i++)
		printf("%d\n",ans-a[read()]+read());
}


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

int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    ll x=0;
    cin >> a[0];
    rep2(i,n){
        cin >> x;
        a[i]=x+a[i-1];
    }
    vector<ll> b(n-1);
    ll l=a[n-1];
    rep(i,n-1){
        b[i]=abs(l-a[i]*2);
    }
    sort(b.begin(),b.end());
    cout << b[0] << endl;
}

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

int S;
const ULL M = 1000000007;

const int z=10000;
ULL F[z+1], I[z+1], iF[z+1];

ULL C(int n,int r){ return F[n]*iF[r]%M*iF[n-r]%M; }

int main(){
 cin>>S;

 F[0]=I[1]=iF[0]=1;
 for(int i=1; i<=z; i++) F[i]=F[i-1]*i%M;
 for(int i=2; i<=z; i++) I[i]=M-M/i*I[M%i]%M;
 for(int i=1; i<=z; i++) iF[i]=iF[i-1]*I[i]%M;

 ULL ans=0;
 for(int i=1; i*3<=S; i++){
  int Rem = S-i*3;
  ans += C(Rem+i-1,i-1);
 }

 ans %= M;
 cout<<ans<<endl;

 return 0;
}




Measured memory_bytes: 3884
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
    int a, b, c, d;
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> d;
    string win;
    while (1)
    {
        c -= b;
        if (c <= 0)
        {
            win = "Yes";
            break;
        }
        a -= d;
        if (a <= 0)
        {
            win = "No";
            break;
        }
    }
    cout << win << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int x;
    cin>>x;
    if(x%7==2){
        cout<<"sat"<<endl;
    }
    else if(x%7==3){
        cout<<"sun"<<endl;
    }
    else if(x%7==4){
        cout<<"mon"<<endl;
    }
    else if(x%7==5){
        cout<<"tue"<<endl;
    }
    else if(x%7==6){
        cout<<"wed"<<endl;
    }
    else if(x%7==0){
        cout<<"thu"<<endl;
    }
    else if(x%7==1){
        cout<<"fri"<<endl;
    }
    
} 







Measured memory_bytes: 3104
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        a: i64,
        v: i64,
        b: i64,
        w: i64,
        t: i64,
    }

    let a_b = (a - b).abs();
    let v_w = v - w;
    let t_v_w = t * v_w;
    if a_b <= t_v_w {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 2168
import sys

def solve():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    X = [int(x) for x in input().split()]
    left = [0]
    right = [0]
    for x in X:
        if x < 0: left.append(-x)
        else: right.append(x)
    left.sort()
    lenl = len(left)
    lenr = len(right)
    Ans = 100000000000000
    for l in range(min(lenl, K + 1)):
        r = K - l
        if r < lenr:
            Ans = min(min(left[l], right[r]) + left[l] + right[r], Ans)
    #print(left, right)
    print(Ans)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 14940
/*
Date : 14/8/20
*/
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define pb push_back
#define int long long int
#define tc int t; cin>>t; while(t--)
using namespace std;
const int N=1e5+3;

int32_t main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
//tc
{
 string s;
 cin>>s;
 int cnt=0,mx=0;
 for(int i=0;i<s.size();i++)
 {
 	if(s[i]=='R')cnt++;
 	else {
 		mx=max(cnt,mx);
 		cnt=0;
 	}
 }
 mx=max(mx,cnt);
 cout<<mx;
}
return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  string S;
  cin>>N>>S;
  int s=S.size();
  int p=0;
  int count=0;
  for(int i=0; i<s; i++){
if(S.at(i)=='A'){
p=1;
}
else if(p==1&&S.at(i)=='B'){
p=2;
}
else if(p==2&&S.at(i)=='C'){
p=0;
count++;
}
else{p=0;
}
 }
 cout<<count<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    char ch(getchar());
    while(ch<'a'||ch>'z')ch=getchar();
    while((ch>='a'&&ch<='z')||ch==',')
    {
        if(ch==',')cout<<" "<<endl;
        else cout<<ch;
        ch=getchar();
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll n;
int main(){
    int sx,sy,ty,tx;
    cin>>sx>>sy>>tx>>ty;
    //cout<<sy<<" "<<ty<<endl;
    //return 0;
    for(int i = sy; i<ty;i++) cout<<"U";
    //return 0;
    for(int i = sx; i<tx;i++) cout<<"R";
    for(int i = ty; i>sy;i--) cout<<"D";
    for(int i = tx; i>sx;i--) cout<<"L";
    cout<<"L";
    for(int i= sy; i < ty+1; i++) cout<<"U";
    for(int i = sx-1;i<tx;i++) cout<<"R";
    cout<<"D"<<"R";
    for(int i = ty; i > sy-1;i--) cout<<"D";
    for(int i = tx+1;i>sx;i--) cout<<"L";
    cout<<"U"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

int main() {
  string s, t;
  cin >> s >> t;
  int ans = 0;
  rep(i, 3) {
    if(s[i] == t[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3564
#include<iostream>
#include<vector>
using namespace std;
using ll=long long ;
int main()
{
    int n;
    cin>>n;
    vector<ll> arr(n);
    for(int i=0;i<n;i++)
    cin>>arr[i];
    ll dp[n][n];
    for(int i=n-1;i>=0;i--)
    {
        for(int j=i;j<n;j++)
        {
            if(i==j)
            {
                dp[i][j]=arr[i];
            }
            else 
            {
                dp[i][j]=max(arr[i]-dp[i+1][j],arr[j]-dp[i][j-1]);
            }
        }
    }
    cout<<dp[0][n-1];
}

Measured memory_bytes: 49264
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int n,l;
    cin>>n>>l;
    string s[n];
    for(int i=0;i<n;i++) {
        cin>>s[i];
    }
    sort(s,s+n);
    for(int i=0;i<n;i++) {
        cout<<s[i];
    }
    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

  int n, k; cin >> n >> k;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];

  vector<int> imos(n+1, 0);
  for(int i = 0; i < n; i++){
    imos[i+1] = imos[i] + a[i];
  }
  for(int i = 0; i < n; i++){
    imos[i+1] = (imos[i+1] - (i+1)) % k;
  }

  int ans = 0;
  map<int, int> mp;
  for(int i = 0; i <= n; i++){
    if(i - k >= 0) mp[imos[i - k]]--;
    ans += mp[imos[i]];
    mp[imos[i]]++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 15872
#include <iostream>
#define MAX 1000
#define MODO 1000000007
using namespace std;


long long solve(char a[][MAX], int h, int w){
    long long dp[h+1][w+1];

    for(int i=0;i<=h;i++){
        for(int j=0;j<=w;j++){
            if(i==0 || j==0){
                dp[i][j] = 0;
                if(i==0 && j==1){
                   dp[i][j]=1;
                }
            }
            else{
                if(a[i-1][j-1]=='#'){
                    dp[i][j] = 0;
                }
                else{
                    dp[i][j] = (dp[i][j-1] + dp[i-1][j])%MODO;
                }
            }
        }
    }
    return dp[h][w];
}

int main(){
    int h, w;
    cin >> h >> w;
    char a[h][MAX];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> a[i][j];
        }
    }
    cout << solve(a, h, w) << endl;
}

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

using namespace std;

typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

int main()
{
    while(true)
    {
        int N, M;
        scanf("%d", &N);
        scanf("%d", &M);

        if((N == 0) && (M == 0))
            break;
        vector<vector<int>> vv(N);
        int a,b;
        REP(i, M)
        {
            scanf("%d %d", &a, &b);
            vv[a - 1].push_back(b - 1);
            vv[b - 1].push_back(a - 1);
        }
        set<int> ans;
        REP(i, vv[0].size())
        {
            int f= vv[0][i];
            if(f != 0) ans.insert(f);
            REP(h, vv[f].size())
            {
                int f2= vv[f][h];
                if(f2 != 0) ans.insert(f2);
            }
        }
        printf("%d\n", (int)ans.size());
    }
    return 0;
}




Measured memory_bytes: 3252
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
void go();
int main() {
#ifdef tokitsukaze
    freopen("TEST.txt", "r", stdin);
#endif
    go();
    return 0;
}

/*********************************  head  *********************************/


LL n,a,b,m;

LL ans;
void go() {
    cin>>n;
    m=sqrt(n);
    a=1,b=1;
    while(m>=2){
        if(n%m==0)break;
        --m;
    }
    LL ans=n/m;
    printf("%lld\n",m+ans-2);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) begin(v), end(v)
#define allg(v) begin(v), end(v), greater<int>()



int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  int n, d, x;
  cin >> n >> d >> x;
  
  int ans = x;
  
  vector<int> a(n);  
  rep(i, 0, n) {
    cin >> a.at(i);
    int j = 0;
    while(a.at(i) *j +1 <= d) {
      j++;
    }
    ans += j;
  }
      
  cout << ans << "\n";
  
  //cout << fixed << setprecision(10) << n << "\n";

}


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

ll mino(ll &x){
    if(x<=2)return 0;
    ll tmp = (x-1)/2*2;
    x -= tmp;
    return tmp;
}

int main(){

    ll I, O, T, J, L, S, Z;
    cin >> I >> O >> T >> J >> L >> S >> Z;
    ll ans = O + mino(I) + mino(J) + mino(L);
    if(I > J)swap(I, J);
    if(J > L)swap(J, L);
    if(I > J)swap(I, J);
    if(I == 2)ans += 6;
    else if(J == 2)ans += 4;
    else if(I == 1)ans += 3;
    else if(L == 2)ans += 2;
    cout << ans << endl;

    return 0;
}

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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) ;
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;

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

bool to[330][330];

int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll N, M; cin >> N >> M;
	vector<queue<ll>> A(N);
	vector<bool> is_game(M, true);
	REP(i, N)
	{
		REP(j, M)
		{
			ll a; cin >> a;
			--a;
			A[i].push(a);
		}
	}

	
	ll res{INF};
	while (true)
	{
		vector<ll> join(M, 0);
		REP(i, N)
		{
			while (true)
			{
				ll a = A[i].front();
				if (!is_game[a])
				{
					A[i].pop();
				}
				else
				{
					join[a]++;
					break;
				}

				if (A[i].size() == 0)
					goto exit;
			}
		}

		ll game_i = -1;
		ll ma = 0;
		for (ll i = 0; i < M; ++i)
		{
			if (ma < join[i])
			{
				ma = join[i];
				game_i = i;
			}
		}

		res = min(res, ma);
		is_game[game_i] = false;
	}

 exit:
	std::cout << res << std::endl;	
	
	return 0;
}


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

int main() {
  string n;
  std::cin >> n;
  if((n[0] == n[1] && n[1] == n[2]) || (n[1] == n[2] && n[2] == n[3])) {
    std::cout << "Yes" << '\n';
  } else {
    std::cout << "No" << '\n';
  }
}

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

int main() {
 int r,D,x0;
  cin >> r >> D >> x0;
  vector<int> x(11);
  x[0]=x0;
  for(int i=1;i<11;i++){
  x[i]=x[i-1]*r-D;
  }
  
  for(int i=1;i<11;i++){
  cout << x[i] << endl;
  }
    
}

Measured memory_bytes: 256
R = lambda: map(int, input().split())
n, q = R()
s = input()
a = [0] * n
c = 0
for i in range(1, n):
    if s[i-1: i+1] == 'AC': c += 1
    a[i] = c
for _ in range(q):
    l, r = R()
    print(a[r - 1] - a[l - 1])


Measured memory_bytes: 6164
#include <stdio.h>
#include <limits.h>
#define WHITE 0
#define BLACK 1
#define NILL -1
#define N 1000

int d[N], w[N][N], color[N], v;

int main(){
    int n, i, j, u, k, s = 0, mincost;
    
    scanf("%d",&n);
    
    for(i = 0;i < n; i++){
        for(j = 0;j < n; j++){
            w[i][j] = INT_MAX;
        }
    }
    
    for(i = 0; i < n; i++){
        d[i] = INT_MAX;
        color[i] = 0;
        scanf("%d %d", &u, &k);
        for(j = 0;j < k; j++){
            scanf("%d", &v);
            scanf("%d", &w[u][v]);
        }
    }
    d[s] = 0;
    
    while(1){
        mincost = INT_MAX;
        for(i = 0;i < n; i++){
            if(d[i] < mincost && color[i] == WHITE){
                mincost = d[i];
                u = i;
            }
        }
        
        if(mincost == INT_MAX){
            break;
        }
        color[u] = BLACK;
        
        for(v = 0;v <= n; v++){
            if(w[u][v] == INT_MAX){
                continue;
            }
            if(d[v] > d[u] + w[u][v]){
                d[v] = d[u] + w[u][v];
            }
        }
    }
    for(i = 0;i < n; i++){
        printf("%d %d\n", i, d[i]);
    }
    return 0;
}

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

int main() { 
  int a,b;
  cin>>a>>b;
  bool ok=false;
  if(2*a<=b &&b <=4*a && (b-2*a)%2==0){
    ok=true;
  }
  
  if(ok)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
}

Measured memory_bytes: 3636
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
                
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pretime float(clock()-clk)/CLOCKS_PER_SEC
#define max2(a,b) ((a)>(b) ? (a) : (b))   
#define min2(a,b) ((a)<(b) ? (a) : (b)) 
#define rep(i,a,b) for(i=a;i<=b;++i)
#define rev(i,a,b) for(i=a;i>=b;--i) 
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define lli long long int 
#define ins insert
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define PI 3.14159265
#define mod 1000000007
#define inf 1000000000000000

using namespace std;
typedef vector<lli>   vll;
typedef vector<int>   vi;
typedef set<lli>      sll;
typedef set<int>      si;
typedef pair<lli,lli> pll;
typedef pair<int,int> pii;
clock_t clk=clock();       

lli i,j;
void solve(void);

int main()
{
  speedio;
   int t=1;  
  // cin>>t;
   while(t--)
     solve();

  return 0;
}
//
void solve()
{
	int a,p; cin>>a>>p;
	cout<<(a*3+p)/2<<'\n';
}

Measured memory_bytes: 256