akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<stdio.h>
#include<time.h>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(void) {
	int n;
	cin>>n;
	for(int i = 1; i <= n; ++i) { // CHECK_NUM
		int x = i;
		if(x % 3 == 0) {
			cout<<" "<<i;
		} else {
			while(true) {	// INCLUDE3
				if(x % 10 == 3) {
					cout<<" "<<i;
					break;
				}
				x /= 10;
				if(x == 0) break;
			}
		}
		// END_CHECK_NUM
	}
	cout<<endl;
}

Measured memory_bytes: 3080
#include<stdio.h>
int main(){
	int N,K;
	scanf("%d %d", &N, &K);
	int total[N];
	int i;
	for( i=0;i<N;i++){
		scanf("%d", &total[i]);
	}
	for( i=K;i<N;i++){
		if(total[i-K] < total[i]){
			printf("Yes\n");
		}else {
			printf("No\n");
		}
	}
	
	
	
	return 0;
}


Measured memory_bytes: 2420
# import sys
# input = sys.stdin.readline

def mp(): return map(int, input().split())
def lmp(): return list(map(int, input().split()))

n,k = mp()
a = lmp()
l = 0
r = int(1e9+5)
while r - l != 1:
    m = (l+r)//2
    cnt = 0
    for i in range(n):
        cnt += (a[i]-1) // m
    if cnt <= k:
        r = m
    else:
        l = m
print(r)


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

 using namespace std;

 int main() {
   int D, N;

   cin >> D >> N;

   if (D == 0) {
     if (N == 100) cout << 101 << endl;
     else cout << N << endl;
   }
   else if (D == 1) {
     if (N == 100) cout << 10100 << endl;
     else cout << N * 100 << endl;
   }
   else {
     if (N == 100) cout << 1010000 << endl;
     else cout << N * 10000 << endl;
   }
}


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    V< V<int> > edges(n);
    for (int i = 1; i < n; i++) {
        int p; cin >> p; p--;
        edges[p].emplace_back(i);
    }
    V<int> x(n);
    for (int i = 0; i < n; i++) cin >> x[i];

    auto dfs = [&](auto && self, int i) -> P<int, P<int, int> > {
        V< V<bool> > dp(2, V<bool>(x[i] + 1, false));
        dp[0][0] = true;
        int subx = 0;
        for (int j: edges[i]) {
            dp[1] = V<bool>(x[i] + 1, false);
            P<int, P<int, int> > ch = self(self, j);
            subx += ch.first;
            for (int k = 0; k <= x[i]; k++) {
                if (!dp[0][k]) continue;
                if (k + ch.second.first <= x[i]) dp[1][k + ch.second.first] = true;
                if (k + ch.second.second <= x[i]) dp[1][k + ch.second.second] = true;
            }
            swap(dp[0], dp[1]);
        }
        int chm = INF;
        for (int j = x[i]; j >= 0; j--) {
            if (dp[0][j]) {
                chm = j;
                break;
            }
        }
        if (chm != INF) return make_pair(subx + x[i] - chm, make_pair(x[i], subx - chm));
        else return make_pair(0, make_pair(INF, INF));
    };
    P<int, P<int, int> > ans = dfs(dfs, 0);
    if (ans.second.first <= x[0] || ans.second.second <= x[0]) cout << "POSSIBLE\n";
    else cout << "IMPOSSIBLE\n";
    return 0;
}


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

using namespace std;
using ll = long long;

int main() {
    int N = 0;
    cin >> N;
    vector<int> A(N,0);
    for(int i = 0; i < N; i++) {
        cin >> A.at(i);
    }

    int ans = 0;
    int now = 0;

    for(int i = 0; i < N - 1; i++) {
        if(A.at(i) >= A.at(i + 1)) {
            now++;
            ans = max(ans, now);
        } else {
            now = 0;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3736
from collections import Counter
S = input()
S = S + '0'
mod = 2019
p = [0] * mod
r = 0
d = 1
for s in S[::-1]:
  t = int(s)%mod
  r += t*d
  r %= mod
  d = d*10%mod
  p[r] += 1

#p.append(0)
#ans = 0
#c = Counter(p)
#for k,n in c.most_common():
#  if n > 1:
#    ans += 1
#  else:break
  
print(sum([i*(i-1)//2 for i in p]))

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

using namespace std;
typedef long long ll;
const int MAXN = 110;

int H, W;
char board[MAXN][MAXN];
int dp[MAXN][MAXN];

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

    cin >> H >> W;
    for (int i = 0; i < H; i++)
        for (int j = 0; j < W; j++)
            cin >> board[i][j];

    dp[0][0] = 0;
    if (board[0][0] == '#')
        dp[0][0] = 1;
    for (int i = 0; i < H; i++)
        for (int j = 0; j < W; j++)
        {
            if (i + j == 0) continue;
            dp[i][j] = 1e9;
            if (i)
            {
                if (board[i][j] == board[i-1][j])
                    dp[i][j] = min (dp[i][j], dp[i-1][j]);
                else
                    dp[i][j] = min (dp[i][j], dp[i-1][j] + 1);
            }
            if (j)
            {
                if (board[i][j] == board[i][j-1])
                    dp[i][j] = min (dp[i][j], dp[i][j-1]);
                else
                    dp[i][j] = min (dp[i][j], dp[i][j-1] + 1);
            }
        }

    cout << (dp[H-1][W-1] + 1) / 2 << "\n";
}

Measured memory_bytes: 384
program test
implicit none
  integer,allocatable::a(:)
  integer :: N,i,ans,k
  read*,N
  allocate(a(N))
  read(*,*)(a(i),i=1,N)
  k=0
  ans=0
  do i=1,N-1
  	if(a(i)>=a(i+1))then
    	k=k+1
        ans=max(k,ans)
    else 
    	k=0
        ans=max(k,ans)
    end if
 end do
 print*,ans
end program test

Measured memory_bytes: 1152
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		StringTokenizer st = new StringTokenizer(br.readLine());
		
		String S = st.nextToken();
		String T = st.nextToken();
		
		st = new StringTokenizer(br.readLine());
		
		int A = Integer.parseInt(st.nextToken());
		int B = Integer.parseInt(st.nextToken());
		
		String U = br.readLine();
		
		if(S.equals(U))
			A--;
		else
			B--;
		
		System.out.println(A+ " " +B);
	}

}

Measured memory_bytes: 36816
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(){
  int x, a, b;
  char s[100];

  int stack[200];
  int current = 0;

  while(scanf("%s", &s) != EOF) {
    if ( s[0] == '+' ){
      a = stack[--current];
      b = stack[--current];
      stack[current++] = a + b;
    } else if ( s[0] == '-' ){
      a = stack[--current];
      b = stack[--current];
      stack[current++] = b - a;
    } else if ( s[0] == '*' ){
      a = stack[--current];
      b = stack[--current];
      stack[current++] = a * b;
    } else {
      x = atoi(s);
      stack[current++] = x;
    }
    //printf("current top of stack is %d\n", stack[current - 1]);
  }

  printf("%d\n", stack[0]);
}



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

int main(){
    int w, a, b;
    cin >> w >> a >> b;
    if(b+w < a)      cout << a - (b+w) << endl;
    else if(a+w < b) cout << b - (a+w) << endl;
    else             cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void extended_euclid(ll x,ll y,ll *c,ll *a,ll *b){
  ll a0,a1,a2,b0,b1,b2,r0,r1,r2,q;r0=x;r1=y;a0=1;a1=0;b0=0;b1=1;
  while(r1>0){q=r0/r1;r2=r0%r1;a2=a0-q*a1;b2=b0-q*b1;r0=r1;r1=r2;a0=a1;a1=a2;b0=b1;b1=b2;}
  *c=r0;*a=a0;*b=b0;
}
 
ll get_inv(ll n, ll p){
  ll a,b,c;
  extended_euclid(n,p,&c,&a,&b);
  if(a<p) a+=p;
  return a%p;
}
 
ll fact[2000100],fact_inv[2000100];
 
void init() {
  fact[0]=1;
  for(int i=1; i<2000100; i++) fact[i]=fact[i-1]*i%MAX;
  fact_inv[2000050]=get_inv(fact[2000050],MAX);
  for(int i=2000049; i>=0; i--)fact_inv[i]=fact_inv[i+1]*(i+1)%MAX;
}
 
ll nCr(int N,int K){
  if(K<0||K>N)return 0;
  return fact[N]*fact_inv[K]%MAX*fact_inv[N-K]%MAX;
}

vector<P> calc(ll n) {
  vector<P> v;
  for(ll i=2; i*i<=n; i++) {
    if(n%i==0) {
      P p=P(i,0);
      while(n%i==0) {
        n/=i;
        p.S++;
      }
      v.push_back(p);
    }
  }
  if(n!=1) v.push_back(P(n,1));
  return v;
}

void Main() {
  init();
  ll n,m;
  cin >> m >> n;
  vector<P> v=calc(n);
  ll ans=1;
  for(int i=0; i<v.size(); i++) {
    ans*=nCr(v[i].S+m-1,m-1);
    ans%=MAX;
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

using namespace std;

int main() {

    int n;
    cin >> n;
    
    int sum = 0, maxi = 0;
    for(int i = 0; i < n; i++) {
        int l;
        cin >> l;
        
        if(l > maxi)
            maxi = l;
        
        sum += l;
    }
    
    if(maxi < sum - maxi)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

using Weight = int;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int s, int d, Weight w)
    : src(s), dst(d), weight(w) {
  }
};

using Edges  = vector<Edge>;
using Graph  = vector<Edges>;
using Array  = vector<Weight>;
using Matrix = vector<Array>;

void addArc(Graph &g, const int &a, const int &b, const Weight &w = 1) {
  g[a].emplace_back(a, b, w);
}

void addEdge(Graph &g, const int &a, const int &b, const Weight &w = 1) {
  addArc(g, a, b, w);
  addArc(g, b, a, w);
}

template<typename V>
constexpr string join(const V &v, const string &sep) {
  stringstream ss;
  if (v.size()) ss << v[0];
  loop(i, 1, v.size()) ss << sep << v[i];
  return ss.str();
}

void solve() {
  int n, m;
  cin >> n >> m;
  Graph g(n);
  while (m--) {
    int a, b;
    cin >> a >> b;
    addEdge(g, --a, --b);
  }
  deque<int> q;
  q.pb(0);
  vi done(n);
  done[0] = true;
  for (;;) {
    int p  = q.back();
    bool b = true;
    for (Edge e : g[p]) {
      if (done[e.dst]) continue;
      done[e.dst] = true;
      q.push_back(e.dst);
      b = false;
      break;
    }
    if (b) break;
  }
  for (;;) {
    int p  = q.front();
    bool b = true;
    for (Edge e : g[p]) {
      if (done[e.dst]) continue;
      done[e.dst] = true;
      q.push_front(e.dst);
      b = false;
      break;
    }
    if (b) break;
  }
  cout << q.size() << endl;
  vi v;
  while (q.size()) v.pb(q.front() + 1), q.pop_front();
  cout << join(v, " ") << endl;
}


Measured memory_bytes: 12656
#![allow(unused_mut, non_snake_case,unused_imports)]
use std::iter;
use std::cmp::{max, min, Ordering};
use std::mem::{swap};
use std::collections::{HashMap,BTreeMap,HashSet,BTreeSet,BinaryHeap,VecDeque};
use std::iter::FromIterator;

//　高速 EOF要
//macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();input_inner!{iter, $($r)*}};($($r:tt)*) => {let mut s = {use std::io::Read;let mut s = String::new();std::io::stdin().read_to_string(&mut s).unwrap();s};let mut iter = s.split_whitespace();input_inner!{iter, $($r)*}};}
//macro_rules! input_inner {($iter:expr) => {};($iter:expr, ) => {};($iter:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($iter, $t);input_inner!{$iter $($r)*}};}
//macro_rules! read_value {($iter:expr, ( $($t:tt),* )) => {( $(read_value!($iter, $t)),* )};($iter:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()};($iter:expr, chars) => {read_value!($iter, String).chars().collect::<Vec<char>>()};($iter:expr, usize1) => {read_value!($iter, usize) - 1};($iter:expr, $t:ty) => {$iter.next().unwrap().parse::<$t>().expect("Parse error")};}
// 低速 EOF不要
macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
fn main(){
    input!(N:i32,M:usize,X:i32,Y:i32,x:[i32;N],y:[i32;M]);
    let x:Vec<i32> = x;
    let y:Vec<i32> = y;
    let &maxx = x.iter().max().unwrap();
    let &miny = y.iter().min().unwrap();

    let L = max(maxx,X);
    let R = min(miny,Y);
    println!("{}",if L < R {"No War"}else{"War"});
}

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

int main(){
  string s;cin>>s;
  bool flag = true;
  if(s[0]!='A')flag=false;
  int n = s.size();
  int cnt = 0;
  fol(i,n){
    if(((int)s[i]&32)==0){
      if(!(s[i]!='A'^s[i]!='C'))flag=false;
    }
  }
  for(int i=2;i<n-1;i++){
    if(s[i]=='C')cnt++;
  }
  if(cnt!=1)flag=false;
  if(flag)cout << "AC"<<endl;
  else cout << "WA"<<endl;
  return 0;
}


Measured memory_bytes: 256
#[allow(unused)]
use proconio::marker::*;
use proconio::{fastout, input};
#[allow(unused)]
use std::cmp::{max, min, Reverse};
#[allow(unused)]
use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque};

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        p: [Usize1; n],
        xy: [(Usize1, Usize1); m],
    }

    let mut uf = UnionFind::new(n);
    for &(x, y) in xy.iter() {
        uf.unite(x, y);
    }

    let ans: usize = (0..n).filter(|&i| uf.same(i, p[i])).map(|i| 1).sum();
    println!("{}", ans);
}

struct UnionFind {
    parents: Vec<usize>,
    rank: Vec<usize>,
}

impl UnionFind {
    fn new(n: usize) -> UnionFind {
        let mut vec = vec![0; n];
        for i in 0..n {
            vec[i] = i;
        }
        UnionFind {
            parents: vec,
            rank: vec![0; n],
        }
    }

    fn find(&self, x: usize) -> usize {
        if x == self.parents[x] {
            x
        } else {
            self.find(self.parents[x])
        }
    }

    fn unite(&mut self, x: usize, y: usize) {
        let px = self.find(x);
        let py = self.find(y);
        if px == py {
            return;
        }

        if self.rank[px] < self.rank[py] {
            self.parents[px] = py;
        } else {
            self.parents[py] = px;
            if self.rank[px] == self.rank[py] {
                self.rank[px] += 1;
            }
        }
    }

    fn same(&self, x: usize, y: usize) -> bool {
        self.find(x) == self.find(y)
    }
}


Measured memory_bytes: 7588
k,a,b = map(int, input().split())

tap_x2 = a + 1
have = 0
if b - a >= 2 and a < k:
    turns_left = k - tap_x2
    if turns_left % 2 == 0:
        have = b + (b-a)*(turns_left//2)
    else:
        have = b + (b-a)*(turns_left//2) + 1
    print(have)
else:
    print(k+1)

Measured memory_bytes: 3060
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

a, b = rm()
print(max(a+b, a-b, a*b))
















Measured memory_bytes: 26976
n = int(input())
r = [[int(i) for i in input().split()] for i in range(n)]
b = [[int(i) for i in input().split()] for i in range(n)]
for i in r:
	i[0],i[1] = i[1],i[0]
r,b = sorted(r)[::-1],sorted(b)
answer = 0
for i in b:
	for j in r:
		if i[0]>j[1] and i[1]>j[0]:
			answer += 1
			r.remove(j)
			break
print(answer)


Measured memory_bytes: 3064
#include <string>
#include <bits/stdc++.h>
#include <stdio.h>
#include<math.h>
#include <ctype.h>
#include <algorithm> // sort
#include <map> // pair
using namespace std;

int main() {
 int n,m,t;
  cin >> n >> m;
  vector<int> vec(n);
  vector<int> f(m);
  for(int i=0;i<n;i++){
    cin >> vec.at(i);
    for(int j=0;j<vec.at(i);j++){
      cin >> t;
      f.at(t-1)++;
    }
  }  
  int ans=0;
  for(int i=0;i<m;i++){
      if(f.at(i)==n){
        ans++;
      }
     
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int m[100],f[100],r[100],Count=0,i,point[100];
	
	while(1){
		scanf("%d %d %d",&m[Count],&f[Count],&r[Count]);
		if(m[Count]==-1 && f[Count]==-1 && r[Count]==-1){
			break;
		}
		Count++;
	}
	
	//A=1,B=2,C=3,D=4,E=5,F=6
	for(i=0;i<Count;i++){
		if(m[i]==-1 || f[i]==-1){
			printf("F\n");
		}
		else if(m[i]+f[i]>=80){
			printf("A\n");
		}
		else if(m[i]+f[i]>=65 && m[i]+f[i]<80){
			printf("B\n");
		}
		else if(m[i]+f[i]>=50 && m[i]+f[i]<65){
			printf("C\n");
		}
		else if(m[i]+f[i]>=30 && m[i]+f[i]<50 && r[i]>=50){
			printf("C\n");
		}
		else if(m[i]+f[i]>=30 && m[i]+f[i]<50 && r[i]<50){
			printf("D\n");
		}
		else if(m[i]+f[i]<30){
			printf("F\n");
		}
	}
	return 0;
}

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

template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}


int toint(string s)
{
  int ans=0;
  for(int i=0;i<s.size();)
    {
      int tmp=1;
      if(s[i]>'1'&&s[i]<='9')
	{
	  tmp=(s[i]-'0');
	  i++;
	}
      if(s[i]=='m')
	ans+=tmp*1000;
      if(s[i]=='c')
	ans+=tmp*100;
      if(s[i]=='x')
	ans+=tmp*10;
      if(s[i]=='i')
	ans+=tmp*1;
      i++;
    }
  
  return ans;
}

string tostr(int x)
{ 
  string s;
  string ds="ixcm";
  for(int i=0;i<4;i++)
    {
      if(x%10>0)
	{
	  s=ds[i]+s;
	  if(x%10>1)
	      s=(char)((x%10)+'0')+s;
	}
      x/=10;
    }
  return s;

}

int main()
{
  int n;
  cin>>n;
  for(;n--;)
    {
      string s1,s2;
      cin>>s1>>s2;
      cout<<tostr(toint(s1)+toint(s2))<<endl;
    }
}

Measured memory_bytes: 1208
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int k = scan.nextInt();
		int n = scan.nextInt();
		int[] array = new int[200000];

		for(int i=0;i<n;i++) {
			array[i] = scan.nextInt();

		}

		int distance = 0;
		int max = array[0] + (k-array[n-1]);
		for(int i=0;i<n-1;i++) {

			distance = array[i+1] - array[i];
			if(distance >= max) {
				max = distance;
			}
	}
		System.out.println(k-max);

		scan.close();

	}

}


Measured memory_bytes: 78820
N = int(input())
li = [list(map(int, input().split())) for i in range(N - 1)]

for n in range(N):
  if n == N - 1:
    print(0)
    break
  
  ans = 0
  for index, i in enumerate(li):
    if index < n:
      continue

    if ans < i[1]:
      ans = i[1]
    else:
      if (ans - i[1]) % i[2] != 0:
        ans += i[2] - (ans % i[2])

    ans += i[0]
  print(ans)

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

const int N = 1e5; 

int n; 
vector<int> g[N + 2]; 
int SG[N + 2];
void dfs (int foo, int p) {
  SG[foo] = 0; 
  for (int bar : g[foo]) {
    if (bar == p) continue; 
    dfs(bar, foo); 
    SG[foo] ^= SG[bar] + 1; 
  }
} 
int main() {
  //freopen("in.inp", "r", stdin); freopen("in.out", "w", stdout); 
  
  scanf("%d", &n); 
  for (int ie = 1; ie < n; ie++) {
    int foo, bar; 
    scanf("%d %d", &foo, &bar); 
    g[foo].push_back(bar); 
    g[bar].push_back(foo); 
  }
  dfs(1, 0);
  if (SG[1] != 0) {
    printf("Alice\n"); 
  } else {
    printf("Bob\n"); 
  } 
}

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

int main(){
  int N; cin >> N;
  int A[N]; rep(i,N) cin >> A[i];

  rep(i,N){
      cout << A[i];
      if (i!=N-1) cout << " ";
    }
  cout << endl;

  int tmp;
  for (int i=1; i<N; i++){
    tmp = A[i];
    int j = i-1;
    while (j>=0 && A[j]>tmp) {
      A[j+1] = A[j];
      --j;
    } 
    A[j+1] = tmp;

    rep(i,N){
      cout << A[i];
      if (i!=N-1) cout << " ";
    }
    cout << endl;
  }

  return 0;
}

 


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define endl '\n'
#define inf (ll)(1e18+5)
#define maxn 3000001
#define mod (ll)(1e9+7)
#define int ll
 
using namespace std;
 
void io(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
}

int n,m,l,r,x,y,z,a,b,c,mn=inf,mx=-inf,w,sum=0;
int ar[maxn];
string s,t;
int dp[3005][3005];

int32_t main(){
io();
IOS;    
		cin>>s>>t;
		int n=s.size();
		int m=t.size();


		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
				if(s[i-1]==t[j-1])dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
			}
		}

		int i=n,j=m;
		string ans;
		
		while(i>0 && j>0){
			if(s[i-1]==t[j-1]){
				ans=s[i-1]+ans;
				i--;
				j--;
			}else{
				if(dp[i-1][j]>=dp[i][j-1]){
					i--;
				}else{
					j--;
				}
			}

		}

		cout<<ans<<endl;





        

        


        
    
        
        
                


 
        
 
 
 
        
 
 
 
 
        
        
 
        
        
 
    
    
    
    
 
 
       
 
 
 
 
      
   
 
 
 
 
}

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

typedef struct box{
	int has;
	int pos;
	int num;
}box;

int main(){
	int i;
	int n,m;
	int *x,*y;
	box *b;
	int res = 0;

	scanf("%d %d",&n,&m);

	x = calloc(sizeof(int),m);
	y = calloc(sizeof(int),m);
	b = calloc(sizeof(box),n);
	for(i = 0;i < m;i++){
		scanf("%d %d",&x[i],&y[i]);
		x[i]--;
		y[i]--;
	}
	b[0].has = 1;
	for(i = 0;i < n;i++){
		b[i].num = 1;
	}
	for(i = 0;i < m;i++){
		b[x[i]].num -= 1;
		b[y[i]].num += 1;
		if(b[x[i]].has){
			b[y[i]].has = 1;
		}
		if(b[x[i]].num == 0){
			b[x[i]].has = 0;
		}
	}
	for(i = 0;i < n;i++){
		res += b[i].has;
	}
	printf("%d\n", res);



	return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
const int lim = 600;

//2次元累積和
int s[lim][lim];

int main(){
    int N, M, Q;
    cin >> N >> M >> Q;

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

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

    for(int i=0; i<Q; i++){
        int p, q;
        cin >> p >> q;
        int ans = s[q][q] - s[q][p-1] - s[p-1][q] + s[p-1][p-1];
        cout << ans << endl;
    }
}

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

typedef long long ll;
typedef long double ld;
typedef string str;

#define f(i, begin, end) for (__typeof(i) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define trav(v) for (auto &x : v)
#define dis(v) trav(v) cout << x << " ";
#define deb(x) cerr << #x << ":" << x << "\n"
#define debv(v) trav(v) cerr << x << " ";
#define all(v) v.begin(), v.end()
#define nl cout << "\n"

int main()
{

    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t = 1;
    // cin >> t;
    while (t--)
    {
        ll i, j, k;
        ll n, m;
        cin >> n >> m;
        ll score = 0, penalty = 0;
        set<ll> ac;
        map<ll, ll> s;
        string str;
        f(i, 0, m)
        {
            cin >> j >> str;
            if (str == "AC" && (ac.find(j) == ac.end()))
            {
                ac.insert(j);
                if (s.find(j) != s.end())
                {
                    penalty += s[j];
                    s.erase(j);
                }
            }
            else if (str == "WA")
                s[j]++;
        }
        cout
            << ac.size() << " " << penalty << "\n";
    }
    return 0;
}

Measured memory_bytes: 4992
import Control.Monad
import Data.List

main :: IO ()
main = do
  [n, m] <- map (read :: String -> Int) . words <$> getLine
  strs <- replicateM m getLine
  let es = sort $ concatMap strToEdge strs
  let nodes = createNodeList es
  print $ solve nodes n

type Edge = (Int, Int)
type Path = [Int]

strToEdge :: String -> [Edge]
strToEdge str = [(from, to), (to, from)]
  where
    [from, to] = map read $ words str

createNodeList :: [Edge] -> [[Int]]
createNodeList es = map (map snd) $ groupBy (\a b -> fst a ==  fst b)  $ sort es

solve :: [[Int]] -> Int  -> Int
solve nodes n = dfs 1 1 [1]
  where
    dfs :: Int -> Int -> [Int] -> Int
    dfs i depth visited
      | depth == n = 1
      | null candidate = 0
      | otherwise = sum $ map (\w -> dfs w (depth+1) (w:visited)) candidate
          where candidate = filter (`notElem` visited)(nodes !! (i - 1))


Measured memory_bytes: 1020
#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(i = 0; i < n; i++)
//#define DEBUG
using namespace std;

int main(){
	int n, m, a;
	while(cin>>n>>m>>a, n||m||a){
		int yoko[101][1001];
		rep(i, 101)rep(j, 1001)yoko[i][j] = 0;
		rep(i, m){
			int h, l, r;
			cin>>h>>l>>r;
			yoko[l][h] = 1, yoko[r][h] = -1;
		}
		for(int h = 1001; h > 0;){
			h--;
			a += yoko[a][h];
			#ifdef DEBUG
			cout<<"h: "<<h<<"; a: "<<a<<endl;
			#endif
		}
		cout<<a<<endl;
	}
	return 0;
}

Measured memory_bytes: 1260
console.log((args=>{
  const [[N],A] = args.trim().split`\n`.map(r=>r.split` `.map(v=>v|0));
  let t = 0, c = 1000, s = 0, max = 1000;
  for ( let i = 1; i < N; i++ ) {
    t = A[i] - A[i-1];
    if ( t > 0 ) {
      s += Math.floor( c / A[i-1] );
      c = c % A[i-1];
    } else if ( t < 0 ) {
      c += s * A[i-1];
      s = 0;
      if ( max < c ) max = c;
    }
  }
  return Math.max(max,c+s*A[N-1]);
})(require('fs').readFileSync('/dev/stdin', 'utf8')));


Measured memory_bytes: 29696
#include <iostream>

using namespace std;

int main()
{

int a,b;

cin>>a>>b;

if(a==b){

    cout<<"Draw"<<endl;
}
else if((a>b||a==1)&&b!=1){

cout<<"Alice"<<endl;
}
else if(b>a||b==1){
    cout<<"Bob"<<endl;
}

    return 0;
}

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

int main() {
    int n;  cin >> n;
    vector<int> P(n); 
    for (int i = 0; i < n; i++) {
        cin >> P[i];
    }
    int m = 200000;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (P[i] <= m) ans++;
        m = min(m, P[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String tmp = scan.next() + "d";
        int tmpCount = 0, count = 0;
        String ACGTString[] = tmp.split("");
        for (String nuc : ACGTString) {
            if (nuc.equals("A") || nuc.equals("G") || nuc.equals("C") || nuc.equals("T")) {
                tmpCount += 1;
            } else {
                if (count < tmpCount) {
                    count = tmpCount;
                }
                tmpCount = 0;
            }
        }
        System.out.println(count);

    }
}


Measured memory_bytes: 21844
#include <iostream>

using namespace std;

int tabmin(int* numarr, int num);
int tabmax(int* numarr, int num);
long tabsum(int* numarr, int num);

int main(void){
  int numofnums;
  cin >> numofnums;
  int numarr[numofnums];
  for(int time = 0; time < numofnums; time++){
    cin >> numarr[time];
  }
  int min = tabmin(numarr, numofnums);
  int max = tabmax(numarr, numofnums);
  long sum = tabsum(numarr, numofnums);
  cout << min << " " << max << " " << sum << endl;
  return 0;
}

int tabmin(int* numarr, int num){
  int min=1000000;
  for(int id=0; id<num; id++){
    if(numarr[id] <= min) min = numarr[id];
  }
  return min;
}

int tabmax(int* numarr, int num){
  int max=-1000000;
  for(int id=0; id<num; id++){
    if(numarr[id] >= max) max = numarr[id];
  }
  return max;
}

long tabsum(int* numarr, int num){
  long sum=0;
  for(int id=0; id<num; id++){
    sum+=numarr[id];
  }
  return sum;
}



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

def main():
    K = int(input())

    t = 7
    t %= K
    for i in range(K+1):
        if t == 0:
            print(i+1)
            break
        t = (t * 10 + 7) % K
    else:
        print(-1)
    

main()

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



int main(){
  int a,b,c,d,e,f;
  cin >> a >> b >> c >> d >> e >> f;
  int i,j,k,l;
  int water = 0;
  int sugar = 0;
  double maxx = 0.0;
  int maxTotal=100*a;
  int maxSugar=0;
  for(i=0;i<=30;i++){
    water = i*a*100;
    if(water>f)break;
    else for(j=0;j<=30;j++){
      water =i*a*100 + j*b*100;
      if(water>f)break;
      else if(water==0)continue;
      else for(k=0;k<=3000;k++){
          sugar = k*c;
          if(sugar*100>water*e)break;
          else if(sugar+water>f)break;
          for(l=0;l<=2000;l++){
            sugar = k*c + l*d;
            if(sugar*100>water*e)break;
            else if(sugar+water>f)break;
            else{
              if((double)sugar/(double)(sugar+water)>=maxx){
                maxx = (double)sugar/(double)(sugar+water);
                maxTotal = sugar + water;
                maxSugar = sugar;
              }
          }
        }
      }
    }
  }
  cout << maxTotal << " " << maxSugar<< endl;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int digit_sum(int n)
{
  int res = 0;
  while (0 < n)
  {
    res += n % 10;
    n /= 10;
  }
  return res;
}

int main()
{
  int N;
  cin >> N;
  int ans = 1e9 + 7;
  for (int i = 1; i < N; ++i)
  {
    int A = i, B = N - i;
    int tmp = digit_sum(A) + digit_sum(B);
    ans = min(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}

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

//#include <atcoder/all>

using namespace std;
// using namespace atcoder;
using ll = long long;

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

  if (n & 1) {
    cout << n / 2 << endl;
  } else {
    cout << n / 2 - 1 << endl;
  }
}

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

using ll=long long;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, q; cin >> n >> q;
  string s; cin >> s;
  vector<int> num(n);
  rep(i,n-1){
    if(s[i]=='A'&&s[i+1]=='C') num[i]++;
  }
  rep(i,n) num[i+1] += num[i];
  rep(i,q){
    int l, r;
    cin >> l >> r;
    l--; r--;
    cout << num[r-1] - num[l-1] << endl;
  }  
}

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

int main() {
  int H, W;

  while (true) {
    cin >> H >> W;
    if (H == 0 && W == 0)
      break;

    for (int h = 0; h < H; h++) {
      for (int w = 0; w < W; w++) {
        // (0,0)からの移動距離
        int step = h + w;
        // step が奇数であれば "." を出力
        if (step - (step / 2) * 2 == 1)
          cout << ".";
        else
          cout << "#";
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}



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


int main(void) {
  int N;  // 店舗数
  int M;  // 購入したい本数
  cin >> N >> M;
  // 各店舗の栄養ドリンクの値段
  // 各店舗の購入できる最大本数
  vector<P>   ab(N);
  rep(i, N) {
    cin >> ab[i].first >> ab[i].second;
  }


  // M本の栄養ドリンクを買うのに必要な最小の金額
  ll ans = 0;
  sort(ab.begin(), ab.end());
  int count = 0;
  int i = 0;
  while (count < M) {
    int num = min(M - count, ab[i].second);
    ans += (ll)num * ab[i].first;
    count += num;
    i++;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1024
import sys
import math
import functools
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n, k = na()
a = na()
cl = 0
cr = 0
for i in range(n-1):
    for j in range(i+1,n):
        if a[i] < a[j]:
            cl += 1
        if a[i] > a[j]:
            cr += 1
ans = (cr*k %mod + (cl+cr) * k*(k-1)//2) % mod
print(ans)

Measured memory_bytes: 3700
def hoge() gets.split.map(&:to_i) end
n, m, x, y = hoge; xx = hoge; yy = hoge

yyy, xxx = yy.sort[0], xx.sort.reverse[0]
flag = false
if xxx <= yyy
    (xxx.succ..yyy).to_a.each do |i| 
        if i > x && i <= y then flag = true; break end
    end
end

puts flag ? "No War" : "War"

Measured memory_bytes: 1788
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,m,c,b[20],a,cnt,i,j,sum;
	scanf("%d %d %d",&n,&m,&c);
	for(i=0;i<m;i++)	scanf("%d",&b[i]);
	cnt=0;
	for(i=0;i<n;i++)	{
		sum=c;
		for(j=0;j<m;j++)	{
			scanf("%d",&a);
			sum+=a*b[j];
		}
		if(sum>0)	cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 128
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000
#define MAXN 1000000

typedef long long ll;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

int dp[MAXN+1];
int dp2[MAXN+1];

int main(void) {
    for (int j = 0; j <= MAXN; j++) {
        dp[j] = INF;
        dp2[j] = INF;
    }
    dp[0] = 0; dp[1] = 1;
    dp2[0] = 0; dp2[1] = 1;
    // DP
    for (int i = 1; i < 200; i++) {
        int plus = i * (i+1) * (i+2) / 6;
        for (int j = 1; j <= MAXN; j++) {
            if (j - plus >= 0) dp[j] = min(dp[j], dp[j-plus] + 1);
            else dp[j] = dp[j];
        }
        if (plus % 2 == 1) {
            for (int j = 1; j <= MAXN; j++) {
                if (j - plus >= 0) dp2[j] = min(dp2[j], dp2[j-plus] + 1);
                else dp2[j] = dp2[j];
            }
        } else {
            for (int j = 1; j <= MAXN; j++) {
                dp2[j] = dp2[j];
            }
        }
    }
//    for (int i = 1; i < 5; i++) {
//        for (int j = 1; j <= 10; j++) {
//            cout << dp2[i][j] << " ";
//        }
//        cout << endl;
//    }
    int n;
    while (1) {
        cin >> n;
        if (n == 0) break;
        cout << dp[n] << " " << dp2[n] << endl;
    }
    return 0;
}

Measured memory_bytes: 8972
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define rrep(i,n) for (ll i = (n)-1; i >=0; --i)
#define ALL(a) a.begin(),a.end()
#define pb push_back
#define dame { puts("-1"); return 0;}
#define show(x) cerr<<#x<<" = "<<x<<endl;

using namespace std;
using ll = long long;
using ld = long double;
using pl = pair<ll, ll>;

typedef vector<ll> vl;
typedef vector<pl> vp;
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; }


// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const ll mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  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) 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 a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} c(200005);


int main() {
  ll n,x;
  cin >> n>>x;

  vector<ll> a(n);
  rep(i,n) cin >> a[i];

  vector<ll> s(n+1);
  ll ans = 0;
  rep(i, n-1) {
    s[i] = a[i+1] + a[i];
    if(i==0) continue;
    if(s[i]>x &&s[i-1]>x) {
      ll tmp = min(a[i], min(s[i]-x, s[i-1]-x));
      ans += tmp;
      s[i] -= tmp;
      s[i-1] -= tmp;
    }
  }
  rep(i, n-1) {
    if(s[i]>x) ans += s[i] - x;
  }  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4992
#include<cstdio>
#include<algorithm>
using namespace std;
int n, m, X[101000];
int w[101000], L[101000], Mod = 1000000007, G[32][3][3] = {{{0,1,0},{0,0,1},{1,Mod-2,4}}};
int R[3] = {0,1,5}, TP[3];
void Up(int x){
    int i, j, t = 0;
    while(x){
        if(x&1){
            for(i=0;i<3;i++)TP[i]=0;
            for(i=0;i<3;i++)for(j=0;j<3;j++)TP[i] = (TP[i]+1ll*G[t][i][j]*R[j])%Mod;
            for(i=0;i<3;i++)R[i]=TP[i];
        }
        t++;x>>=1;
    }
}
int main(){
    int i, j, k, l;
    for(i=1;i<32;i++){
        for(j=0;j<3;j++)for(k=0;k<3;k++)for(l=0;l<3;l++)G[i][j][k] = (G[i][j][k] + 1ll*G[i-1][j][l]*G[i-1][l][k])%Mod;
    }
    scanf("%d%d",&n,&m);
    for(i=1;i<=m+1;i++){
        if(i<=m)scanf("%d",&X[i]);
        else X[i] = n;
        Up(X[i]-X[i-1]);
        int d = R[0];
        R[1] = (R[1]-d+Mod)%Mod;
        R[2] = (R[2]-d*5ll%Mod+Mod)%Mod;
    }
    printf("%d\n",R[0]);
}

Measured memory_bytes: 512
def ascan; gets.split.map(&:to_i);end

a,b,c = ascan.sort

if a==b&&b==c
    p 0;exit 0
end

cnt = 0
while a <= c-2
    a += 2
    cnt += 1
end

while b <= c-2
    b += 2
    cnt += 1
end


if a==b&&b==c
    p cnt;exit 0
end

if a+1==c&&b+1==c
    p cnt+1;exit 0
end

p cnt+2


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

#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RREP(i, a, b) for (int i = (int)(a)-1; i >= (int)(b); --i)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, n, 0)
#define ALL(r) (r).begin(), (r).end()

int64_t f(int64_t n) {
    return (n % 2 == 0) ? n / 2 : 3 * n + 1;
}

void Main() {
    int64_t s, m = 1; cin >> s;
    set<int64_t> x;
    while (x.find(s) == x.end()) {
        x.insert(s);
        s = f(s);
        m++;
    }
    cout << m << endl;
}

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


Measured memory_bytes: 3672
#include<iostream>

using namespace std;

int main() {
    char b, c[128];
    c['A'] = 'T';
    c['T'] = 'A';
    c['C'] = 'G';
    c['G'] = 'C';

    cin >> b;

    cout << c[(int)b] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>  
#include <cstring>  
  
using namespace std;  
  
const int maxn = 3001;  
  
int length[maxn][maxn], word[maxn][maxn];  
string s1, s2;  
  
void print_LCS(int i, int j)  
{  
    if(i==0 || j==0) return;  
  
    if(word[i][j] == 0)  
    {  
        print_LCS(i-1, j-1);  
        cout << s1[i-1];  
    }  
    else if(word[i][j] == 1)  
    {  
        print_LCS(i, j-1);  
    }  
    else if(word[i][j] == 2)  
    {  
        print_LCS(i-1, j);  
    }  
}  
  
int main()  
{  
    ios_base::sync_with_stdio(false);  
    cin.tie(0);  
  
    cin >> s1 >> s2;
      
    int n1 = s1.length(), n2 = s2.length();
    memset(word, -1, sizeof(word));  
  
    for(int i=1 ; i<=n1 ; i++)  
    {  
      for(int j=1 ; j<=n2 ; j++)  
      {  
        if(s1[i-1] == s2[j-1])  
        {  
          length[i][j] = length[i-1][j-1] + 1;  
          word[i][j] = 0; //左上  
        }  
        else if(length[i-1][j] < length[i][j-1])  
        {  
          length[i][j] = length[i][j-1];  
          word[i][j] = 1; //左  
        }  
        else  
        {  
          length[i][j] = length[i-1][j];  
          word[i][j] = 2; //右  
        }  
      }
    }
    print_LCS(n1, n2); cout << '\n';
      
    return 0 ;  
}

Measured memory_bytes: 70784
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;
// using dfs or inorder traverse and savee them then iterate over them to ckeck they are sorted

// Complete the breakingRecords function below.
void minn(int a, int b)
{
    a > b ? cout << b : cout << a;
}

void solve(string s)
{
    
}

int main()
{
    int n, m , k;
    cin >> n >> k;
    vector <ll> v(n,0);
    vector <bool> b(150001,0);
    ll sum = 0;
    for (int i = 0; i < n; i++){
        cin >> v[i];
    }
    sort(v.begin(),v.end());
    for (int i = 0; i < n - k; i++){
        sum += v[i];
    }
    cout << sum;
    

}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
  string s;
  cin >> s;
  ll n=s.size();
  string ans="";
  for(ll i=0;i<n;i++){
    ans.push_back('x');
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
n,m=map(int,input().split())
ab=[[0,0] for i in range(m)]
for i in range(m):
    ab[i][0],ab[i][1]=map(int,input().split())

import sys
sys.setrecursionlimit(10**9) #再帰の上限をあげる

root=[-1 for i in range(n+1)] #自分が親なら自身の番号を、そうでないなら（元）親の番号を示す
def r(x):   #親は誰？
    if root[x]<0:
        return x
    else:
        root[x]=r(root[x])
        return root[x]


ans=n*(n-1)//2
d=[n*(n-1)//2]
for i in range(1,m+1):
    a,b=ab[-i][0],ab[-i][1]
    a=r(a)
    b=r(b)
    a,b=min(a,b),max(a,b)
    if a!=b:
        ans-=root[a]*root[b]
        root[a]+=root[b]
        root[b]=a
    d.append(ans)

for i in range(m):
    print(d[-2-i])


Measured memory_bytes: 28804
//AOJ0005
#include<iostream>
using namespace std;

long long gcd(int n,int m){
	if(m==0)return n;
	gcd(m,n%m);
}
int main(){
	long long  n,m;
	while(cin>>n>>m){
		cout<<gcd(n,m)<<" "<<n*m/gcd(n,m)<<endl;
	}
	return 0;
}

Measured memory_bytes: 2992