akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
       
using namespace std;
       
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30
 
// #define MAX 100010
 
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES

int a[1234567];
vector<int> g[1234567];
bool poss;  

int dfs(int u,int v)
{
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    for(int i=0;i<g[u].size();i++)
    {
        int zolo = g[u][i];
        if(zolo==v)
            continue;
        cnt++;
        int temp = dfs(zolo,u);
        sum+=temp;
        mx = max(mx,temp);
    }
    if(cnt == 0)
        return a[u];
    if(a[u]>sum||a[u]<mx||(2*a[u])<sum)
    {
        poss = true;
        return 0;
    }
    return 2*a[u]-sum;
}

int 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
    long long int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    if(n==2)
    {
        if(a[0]==a[1])
            cout<<"YES";
        else
            cout<<"NO";
        cout<<endl;
        return 0;
    }
    for(int i=0;i<n-1;i++)
    {
        int x,y;
        cin>>x>>y;
        x--;y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    poss = false;
    int temp=1;
    for(int i=0;i<n;i++)
    {
        if(g[i].size()>1)
        {
            temp = dfs(i,-1);
            break;
        }
    }
    if(temp==0&&!poss)
        cout<<"YES";
    else
        cout<<"NO";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 39424
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,vl>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
const ll INF=1LL<<60;
const ll MOD=1000000007;




int main(){
    string S;
    cin >> S;
    ll N=S.size();

    //dp[i][j]について、iは未満フラグ　j桁目までみたとき
    vector<vector<ll>> dp(2, vector<ll>(N, 0));

    dp[0][0]=2;
    dp[1][0]=1;

    for(ll i=1;i<N;i++){
        if(S[i]=='0'){
            dp[0][i]=dp[0][i-1]%MOD;
            dp[1][i]=(dp[1][i-1]*3)%MOD;
        }
        else{
            dp[0][i]=(dp[0][i-1]*2)%MOD;
            dp[1][i]=(dp[1][i-1]*3+dp[0][i-1])%MOD;
        }
    ;}
    
    cout<<(dp[0][N-1]+dp[1][N-1])%MOD<<endl;


    return 0;
}


Measured memory_bytes: 2816
//Utkarsh.25dec
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
using namespace std;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
bool vis[N];
vector <int> adj[N];
void solve()
{
    ll n;
    cin>>n;
    vl v;
    ll cnt[n+1]={0};
    rep(i,n)
    {
        ll c;
        cin>>c;
        v.pb(c);
        cnt[c]++;
    }
    ll overall=0;
    for(int i=1;i<=n;i++)
    {
        ll t=cnt[i];
        t=((t*(t-1))/2);
        overall+=t;
    }
    for(int i=0;i<n;i++)
    {
        ll t=cnt[v[i]];
        ll ans=overall;
        ans-=((t*(t-1))/2);
        t--;
        ans+=((t*(t-1))/2);
        cout<<ans<<'\n';
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 17520
#include<bits/stdc++.h>
typedef long long ll;
int n;
ll a[200000];
using namespace std;
int main()
{
    int flag=0;
    int i;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    for(i=0;i<n;i++)
    {
        if(a[i]==a[i+1])
            {

                flag=1;
                break;
            }
    }
    if(flag)
    {
        cout<<"NO"<<endl;
    }
    else
        cout<<"YES"<<endl;
    return 0;
}

Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(150000)

n, m = map(int, input().split())
bad = [int(input()) for _ in range(m)]
MOD = int(1e9+7)

memo = {0:1, 1:1}
for i in bad:
    memo[i] = 0

def fib(n, mod):
    if n not in memo:
        memo[n] = (fib(n-1, mod) + fib(n-2, mod)) % mod
    return memo[n]

print(fib(n, MOD))

Measured memory_bytes: 98280
#include <stdio.h>
#include <stdlib.h>
int main() {
int *a,n,v,j,i,k;
scanf("%d",&n);
a=(int *)malloc(sizeof(int)*n);
for(i=0;i<n;i++){
    scanf("%d",&a[i]);
}
for(k=0;k<n;k++){
  if (k!=n-1) printf("%d ",a[k]);
  else printf("%d",a[k]);
}
printf("\n");
for(i=1;i<n;i++){
      v=a[i];
      j=i-1;
      while(j>=0 && a[j]>v){
        a[j+1]=a[j];
        j--;
        a[j+1]=v;
        }
        for(k=0;k<n;k++){
        if (k!=n-1) printf("%d ",a[k]);
        else printf("%d",a[k]);
                  }
              printf("\n");
    }
      return 0;
}



Measured memory_bytes: 2060
#![allow(unused_imports)]
use std::io::{ self, Write };
use std::str::FromStr;
use std::cmp::{ min, max };
use std::collections::{ BinaryHeap, VecDeque };

#[allow(unused_macros)]
macro_rules! trace {
    ($var:expr) => {
        let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($var), $var);
    };
    ($($args:expr),*) => { trace!(($($args),*)) }
}

#[allow(unused_macros)]
macro_rules! put {
    ($var:expr) => {
        let _ = writeln!(&mut std::io::stdout(), "{}", $var);
    };
    ($var:expr, $($args:expr),*) => {
        let _ = write!(&mut std::io::stdout(), "{} ", $var);
        put!($($args),*);
    };
}

fn sum(i0: usize, j0: usize, i1: usize, j1: usize, ac: &Vec<Vec<usize>>) -> usize {
    if i0 == 0 && j0 == 0 {
        ac[i1][j1]
    } else if i0 == 0 {
        ac[i1][j1] - ac[i1][j0-1]
    } else if j0 == 0 {
        ac[i1][j1] - ac[i0-1][j1]
    } else {
        ac[i1][j1] + ac[i0-1][j0-1] - ac[i0-1][j1] - ac[i1][j0-1]
    }
}

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let k: usize = sc.cin();
    let k2 = 2 * k;
    let k3 = 3 * k;

    let mut bs = vec![vec![0; k3]; k3];

    for _ in 0..n {
        let mut x: usize = sc.cin();
        let mut y: usize = sc.cin();
        let c: char = sc.cin::<String>().chars().next().unwrap();
        if c == 'W' {
            x = (x + k) % k2;
            y = y % k2;
        } else {
            x %= k2;
            y %= k2;
        }
        bs[x][y] += 1;
        if y+k2 < k3 { bs[x][y+k2] += 1; }
        if x+k2 < k3 { bs[x+k2][y] += 1; }
        if y+k2 < k3 && x+k2 < k3 { bs[x+k2][y+k2] += 1; }
    }
    // for i in 0..k3 { trace!(bs[i]); }
    // put!("===");

    for i in 0..k3 {
        for j in 1..k3 {
            bs[i][j] += bs[i][j-1];
        }
    }
    for j in 0..k3 {
        for i in 1..k3 {
            bs[i][j] += bs[i-1][j];
        }
    }
    // for i in 0..k3 { trace!(bs[i]); }
    // put!("===");

    let mut mx = 0;
    let mut mn = n;
    for i in 0..k {
        for j in 0..k {
            let count = sum(i+0, j+0, i+k-1, j+k-1, &bs)
                      + sum(i+k, j+k, i+k2-1, j+k2-1, &bs);
            mx = max(mx, count);
            mn = min(mn, count);
        }
    }
    trace!(mx, mn);
    put!(max(mx, n-mn));
}

#[allow(dead_code)]
struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn reserve(&mut self) {
        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));
            }
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        self.reserve();
        match self.buffer.pop_front().unwrap().parse::<T>() {
            Ok(a) => a,
            Err(_) => panic!("parse err")
        }
    }
}


Measured memory_bytes: 90364
from collections import defaultdict
N = int(input())

A = [int(x) for x in input().split(" ")]
Q = int(input())
d = defaultdict(int)

ans_sum = 0
for a in A:
    d[a] += 1
    ans_sum += a

for q in range(Q):
    B, C = map(int, input().split())
    num = d[B]
    ans_sum -= num * B
    ans_sum += num * C
    d[B] = 0
    d[C] += num
    print(ans_sum)


Measured memory_bytes: 24120
#include<bits/stdc++.h>
#define MAX_LOG_V 20
#define MAX_V 100005
using namespace std;
typedef long long ll;
vector<int> G[MAX_V],G2[MAX_V];
int root;
int parent[MAX_LOG_V][MAX_V];
int depth[MAX_V];

void dfs(int v,int p,int d){
  parent[0][v]=p;
  depth[v]=d;
  for(int i=0;i<G[v].size();i++)
    if(G[v][i]!=p)dfs(G[v][i],v,d+1);
}

void init(int V){
  dfs(root,-1,0);
  for(int k=0;k+1<MAX_LOG_V;k++)
    for(int v=0;v<V;v++)
      if(parent[k][v]<0)parent[k+1][v]=-1;
      else parent[k+1][v]=parent[k][parent[k][v]];
}

int lca(int u,int v){
  if(depth[u]>depth[v])swap(u,v);
  for(int k=0;k<MAX_LOG_V;k++){
    if((depth[v]-depth[u])>>k&1)v=parent[k][v];
  }
  if(u==v)return u;
  for(int k=MAX_LOG_V-1;k>=0;k--){
    if(parent[k][u]!=parent[k][v]){
      u=parent[k][u];
      v=parent[k][v];
    }
  }
  return parent[0][u];
}

queue<int> q;

int main(){
  int n,p;
  cin>>n;
  for(int i=1;i<n;i++){
    cin>>p; p--;
    G[i].push_back(p);
    G[p].push_back(i);
    G2[p].push_back(i);
  }
  init(n);
  for(int i=0;i<n;i++)
    sort(G2[i].begin(),G2[i].end());
  for(int i=0;i<G2[0].size();i++)
    q.push(G2[0][i]);
  int pv=0;
  ll ans=0;
  while(!q.empty()){
    int v=q.front(); q.pop();
    ans+=depth[v]+depth[pv]-depth[lca(pv,v)]*2;
    for(int i=0;i<G2[v].size();i++)
      q.push(G2[v][i]);
    pv=v;
  }
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

#define MAX_V 252
#define INF (1<<29)

struct Edge {
    int to, cap, rev;
    Edge(int to, int cap, int rev) :
        to(to), cap(cap), rev(rev) {}
};

vector<Edge> G[MAX_V];
int level[MAX_V], iter[MAX_V];

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

void bfs(int s)
{
    memset(level, -1, sizeof(level));
    queue<int> Q;
    level[s] = 0;
    Q.push(s);
    while (!Q.empty()) {
	int v = Q.front(); Q.pop();
	for (int i = 0; i < (int)G[v].size(); i++) {
	    Edge &e = G[v][i];
	    if (e.cap > 0 && level[e.to] < 0) {
		level[e.to] = level[v] + 1;
		Q.push(e.to);
	    }
	}
    }
}

int dfs(int v, int t, int f)
{
    if (v == t) return f;
    for (int &i = iter[v]; i < (int)G[v].size(); i++) {
	Edge &e = G[v][i];
	if (e.cap > 0 && level[v] < level[e.to]) {
	    int d = dfs(e.to, t, min(f, e.cap));
	    if (d > 0) {
		e.cap -= d;
		G[e.to][e.rev].cap += d;
		return d;
	    }
	}
    }
    return 0;
}

int max_flow(int s, int t)
{
    int flow = 0;
    for (;;) {
	bfs(s);
	if (level[t] < 0) return flow;
	memset(iter, 0, sizeof(iter));
	int f;
	while ((f = dfs(s, t, INF)) > 0) {
	    flow += f;
	}
    }
}

void init()
{
    for (int i = 0; i < MAX_V; i++) {
        G[i].clear();
    }
}  

int main()
{
    int N, M, L;
    while (cin >> N >> M >> L) {
        int d[N][N];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                d[i][j] = INF;
            }
            d[i][i] = 0;
        }

        init();
        
        int a, b, c;
        for (int i = 0; i < M; i++) {
            cin >> a >> b >> c; a--; b--;
            d[a][b] = d[b][a] = c;
        }

        for (int k = 0; k < N; k++) {
            for (int i = 0; i < N; i++) {
                for (int j = 0; j < N; j++) {
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
                }
            }
        }
        
        vector<int> P(N), K(N);
        for (int i = 0; i < N; i++) {
            cin >> P[i];
        }
        for (int i = 0; i < N; i++) {
            cin >> K[i];
        }
        
        int S = 2*N, T = S + 1;
        for (int i = 0; i < N; i++) {
            add_edge(S, i, P[i]);
            for (int j = 0; j < N; j++) {
                if (d[i][j] < L) {
                    add_edge(i, j + N, INF);
                }
            }
            add_edge(i + N, T, K[i]);
        }
        cout << max_flow(S, T) << endl;
    }
    return 0;
}

Measured memory_bytes: 3232
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod=1000000007;
/* 4 方向への隣接頂点への移動を表すベクトル */
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
int main(){
ll N; cin>>N;
ll field[N][N]={};
vector<vector<ll> > dist(N, vector<ll>(N, -1)); 
for(ll i=0; i<N;i++){
for(ll j=0; j<N;j++){
field[i][j]=1;
dist[i][j]=min(i,j);
dist[i][j]=min(dist[i][j],N-1-i);
dist[i][j]=min(dist[i][j],N-1-j);}}
ll p,a,b;
ll counter=0;
ll ca=0;
ll cb=100000;
for(ll i=0; i<N*N;i++){
cin>>p; p--;
a=p/N; 
b=p%N;
field[a][b]=0;
cb=100000;
ca+=dist[a][b];
    deque<pair<ll,ll> > que; 
    que.push_front(make_pair(a, b)); 
  
    while (!que.empty()) {
        pair<ll, ll> current_pos = que.front(); // キューの先頭を見る (C++ ではこれをしても pop しない)
        ll x = current_pos.first;
        ll y = current_pos.second;
        que.pop_front(); // キューから pop を忘れずに
        if(field[x][y]==1){
        for (ll direction = 0; direction < 4; ++direction) {
            ll next_x = x + dx[direction];
            ll next_y = y + dy[direction];
            if (next_x < 0 || next_x > N-1|| next_y < 0 || next_y > N-1) {
              continue;}
            if(dist[next_x][next_y]>dist[x][y]+1){
              dist[next_x][next_y]=dist[x][y]+1;
              que.push_front(make_pair(next_x, next_y));}}}
          
        if(field[x][y]==0){
        for (ll direction = 0; direction < 4; ++direction) {
            ll next_x = x + dx[direction];
            ll next_y = y + dy[direction];
            if (next_x < 0 || next_x > N-1|| next_y < 0 || next_y > N-1) {
              continue;}
            if(dist[next_x][next_y]>dist[x][y]){
              dist[next_x][next_y]=dist[x][y];
              que.push_front(make_pair(next_x, next_y));}}}
    }}
   cout << ca << endl;}


Measured memory_bytes: 9404
n = int(input())
strings = [input() for _ in range(3)]
count = 0
for i in range(n):
    tmp = list(set([strings[0][i], strings[1][i], strings[2][i]]))
    if len(tmp) == 3:
        count += 2
    elif len(tmp) == 2:
        count += 1
print(count)


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;

int main() {
  int n;
  cin >> n;
  vi p(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  int cnt = 0;
  for (int i = 1; i < n - 1; i++) {
    if (p[i - 1] < p[i] && p[i] < p[i + 1]) cnt++;
    if (p[i - 1] > p[i] && p[i] > p[i + 1]) cnt++;
  }

  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>

#define INF 2000000000

using namespace std;

int main() {
	long long h, w;
	cin >> h >> w;
	long long u = h / 2 * w;
	long long d = (h - h / 2) * w;
	long long o = 0;
	long long ans = INF;
	for (int i = 0; i < w; i++) {
		ans = min(ans, max(max(u, d), o) - min(min(u, d), o));
		ans = min(ans, max(max((w - i) / 2 * h, (w - i - (w - i) / 2) * h), o) - 
			min(min((w - i) / 2 * h, (w - i - (w - i) / 2) * h), o));
		u -= h / 2;
		d -= h - h / 2;
		o += h;
	}
	swap(w, h);
	u = h / 2 * w;
	d = (h - h / 2) * w;
	o = 0;
	for (int i = 0; i < w; i++) {
		ans = min(ans, max(max(u, d), o) - min(min(u, d), o));
		ans = min(ans, max(max((w - i) / 2 * h, (w - i - (w - i) / 2) * h), o) - 
			min(min((w - i) / 2 * h, (w - i - (w - i) / 2) * h), o));
		u -= h / 2;
		d -= h - h / 2;
		o += h;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
# Fall 7, Stand 8...
# !/ankit_SM/bin/env python

from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

def main():
    tinn=1; #tinn=int(input())
    for tin in range(tinn):
        h1,m1,h2,m2,k=map(int,input().split())
        x=(h2-h1)*60;
        y=m2-m1
        print(x+y-k)


# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()
if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
    main()

Measured memory_bytes: 63016
#include <iostream>
#include <string>
#include <cmath>
#include <ctime>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;

int main(){
    string s;
    cin >> s;

    int sta, fin;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'A') {
            sta = i;
            break;
        }
    }

    for(int i = s.size() - 1; i > 0; i--){
        if(s[i] == 'Z') {
            fin = i;
            break;
        }
    }

    cout << fin - sta + 1 << endl;

}


Measured memory_bytes: 640
import java.io.*;

public class Main {

    public static void main(String a[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] input = br.readLine().split(" ");
        int[]  stack = new int[input.length];
        int top = -1;
        int op1, op2;
        for (String i : input) {
            switch (i) {
                case "-":
                    op1 = stack[top];
                    stack[top--] = 0;
                    op2 = stack[top];
                    stack[top--] = 0;
                    stack[++top] = op2 - op1 ;
                    break;
                case "+":
                    op1 = stack[top];
                    stack[top--] = 0;
                    op2 = stack[top];
                    stack[top--] = 0;
                    stack[++top] = op2 + op1;
                    break;
                case "/":
                    op1 = stack[top];
                    stack[top--] = 0;
                    op2 = stack[top];
                    stack[top--] = 0;
                    stack[++top] = op2 / op1;
                    break;
                case "*":
                    op1 = stack[top];
                    stack[top--] = 0;
                    op2 = stack[top];
                    stack[top--] = 0;
                    stack[++top] = op2 * op1;
                    break;
                default:
                    stack[++top] = Integer.parseInt(i);
                    break;
            }
        }
        bw.append(stack[0] + "\n");
        bw.flush();
    }

}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> d(N);
  rep(i,N)cin >>d.at(i);
  
  int ans = 0;
  for(int i=0;i<N;i++)
  {
  	for(int j=i+1;j<N;j++)
    {
    	ans +=d.at(i)*d.at(j);
    }
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef pair<int, int> P;
//typedef pair<int, pair<int, int> > PP;
const int MAX=2e5+10;
const ll INF=9e18;

int main(){
	int N;
	ll X;
	cin>>N>>X;
	ll x[MAX];
	rep1(i,N)cin>>x[i];
	ll sum[MAX];
	sum[0]=0;
	rep1(i,N)sum[i]=sum[i-1]+x[i];
	ll ans=INF;
	rep1(k,N){
		bool ed=false;
		ll tmp=sum[N]*5+X*(N+k);
		for(int p=N-2*k; p>=1; p-=k){
			tmp+=2*sum[p];
			if(ans<=tmp){
				ed=true;
				break;
			}
		}
      	if(!ed)ans=min(ans, tmp);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3328
import java.util.Scanner;
public class Main{
    
    public void solve(){
        Scanner sc = new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        int c=sc.nextInt();
        if(a<b&&b<c){
            System.out.print("Yes");
        }else{
            System.out.print("No");
        }
   
        System.out.println();
    }
    
    public static void main(String[] args){
        Main obj = new Main();
        obj.solve();
    }
}

Measured memory_bytes: 17160
fun main(args: Array<String>) {
    abc094c()
}

private data class ValueIndexed(val value: Long, val index: Int)

fun abc094c() {
    val n = readLine()!!.toInt()
    val xList = readLine()!!.split(" ").map { it.toLong() }
        .mapIndexed { index, l -> ValueIndexed(l, index) }.sortedBy { it.value }

    val centerLeft = xList[xList.size / 2 - 1].value
    val centerRight = xList[xList.size / 2].value

    val answer = xList.sortedBy { it.index }
        .map { if (it.value < centerRight) centerRight else centerLeft }

    println(answer.joinToString(separator = System.lineSeparator()))
}


Measured memory_bytes: 131388
#include <bits/stdc++.h> 
    #include<ext/pb_ds/assoc_container.hpp> 
    #include<ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    using namespace std;
    template <typename T>
    using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
    #define int long long  
    typedef long double ld;
    #define pb push_back
    #define f(i,a,b) for(int i=a;i<b;i++)
    #define fd(i,a,b) for(int i=a-1;i>=b;i--)
    #define pf push_front
    #define fi first
    #define se second
     int mn=1e9+7;
    int cnt=0;
    vector<pair<int ,int >> v1,v2;  
    signed main() {
    ios_base::sync_with_stdio(false);
     cin.tie(NULL);  
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("INPUT.txt", "r", stdin);
    // for writing output to output.txt
    freopen("OUTPUT.txt", "w", stdout);
    #endif
 
    // -------------------------------------Code starts here--------------------------------------------------------------------- 

   int r;
   cin>>r;
   float a=3.14*2*r;
   cout<<fixed<<setprecision(2)<<a<<endl;
}

Measured memory_bytes: 3804
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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; }

typedef long long ll;

using namespace std;
int mod=1e9+7;
long long modpow(long long x,long long n,long long mod)
{
  if(n==0)return 1;
  long long res=modpow(x*x%mod,n/2,mod);
  if(n&1)res=res*x%mod;
  return res;
}
long long modinv(long long a,long long mod)//extgcdの方がいいらしい
{
  return modpow(a,mod-2,mod);
}


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int b,w;
  cin>>b>>w;
  vector<int>kai(b+w+1),inv(b+w+1);
  kai[0]=1;
  rep(i,b+w)kai[i+1]=(ll)kai[i]*(i+1)%mod;
  inv[b+w]=modinv(kai[b+w],mod);
  for(int i=b+w;i>0;i--)inv[i-1]=(ll)inv[i]*i%mod;
  auto c=[&](int a,int b){return (ll)kai[a]*inv[b]%mod*inv[a-b]%mod;};
  vector<int>inv2(b+w+1);
  inv2[0]=1;
  inv2[1]=modinv(2,mod);
  rep(i,b+w-1)
  {
    inv2[i+1]=(ll)inv2[i]*inv2[1]%mod;
  }
  vector<int>fullb(w),fullw(b);
  fullw[0]=inv2[w];
  fullb[0]=inv2[b];
  rep(i,b-1)
  {
    fullw[i+1]=(fullw[i]+(ll)c(w+i,i+1)*inv2[w+i+1])%mod;
  }
  rep(i,w-1)
  {
    fullb[i+1]=(fullb[i]+(ll)c(b+i,i+1)*inv2[b+i+1])%mod;
  }
  rep(i,b+w)
  {
    int pb=0,pw=0;
    int res=0;
    if(i>=b)pb=fullb[i-b];
    if(i>=w)pw=fullw[i-w];
    res+=(1LL+2*mod-pb-pw)*inv2[1]%mod;
    res+=pw;
    cout<<res%mod<<"\n";
  }
  cout<<flush;


  return 0;

}


Measured memory_bytes: 5376
N = int(input())
As = [int(input()) for _ in range(N)]

As.sort(reverse=True)

if N % 2:
    ans = 2 * sum(As[:N//2 - 1]) - 2 * sum(As[N//2 + 2:])
    A1, A2, A3 = As[N//2 - 1:N//2 + 2]
    ans += max(A1 + A2 - 2*A3, 2*A1 - A2 - A3)
else:
    ans = 2 * sum(As[:N//2 - 1]) + As[N//2 - 1] - As[N//2] - 2 * sum(As[N//2 + 1:])

print(ans)


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

using namespace std;

#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(t) for(ll i =0;i<t;i++)
#define bs(a,x) binary_search(a.begin(),a.end(),x)
#define ll long long int
#define ul unsigned long int
#define ld long double
#define umpi unordered_map<int,int> 
#define umpl unordered_map<ll,ll> 
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define mod 1000000007 
#define N 10000000
#define all(a) a.begin(),a.end()
#define point pair<ll,ll>

const int inf = 1000000007;
const ll linf = 1ll * inf * inf;
const ll MAXIMUM =1000005;

inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }
inline ll max(ll a, ll b){return a>b?a:b;}
inline ll min(ll a, ll b){return a<b?a:b;}

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};

int main()
{
	fio;
	ll n;cin>>n;
	vl h(n);
	f(n)cin>>h[i];
	vl dp(n+1,inf);
	dp[0]=0;
	f(n)
	{
		for(int j:{i+1,i+2})
		{
			if(j<n)
			{
				dp[j]=min(dp[j],dp[i]+abs(h[j]-h[i]));
			}
		}
	}
	cout<<dp[n-1]<<"\n";
}

Measured memory_bytes: 1792
# coding: utf-8
# Your code here!
n=int(input())
a=input().split()
l=[]
ans=100000000
for i in range(n):
    l.append(int(a[i]))
for i in range(n):
    #print(l[:i],l[i:])
    t=abs(sum(l[:i])-sum(l[i:]))
    if(t<ans):
        ans=t
print(ans)

Measured memory_bytes: 3064
#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
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
bool initialized = false;

/**
 * @fn
 * This function must be called at first.
 */
void combination_init() {
    initialized = true;
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

/**
 * @fn
 * Calculates the combination  ( nCK % p: N choose K mod p).
 *
 * @brief constraint: 1 ≤ k ≤ n ≤ 10^7
 * @return nCK % MOD
 */
long long combination(int n, int k) {
    assert(initialized);
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

/**
 * @fn
 * Calculates the factorial of the number.
 *
 * @brief constraint: 1 ≤ k ≤ 10^7 and 1 ≤ n ≤ 10^9
 * @return N! % MOD
 */
long long factorial(int n) {
    assert(initialized);
    if (n < 0) return 0;
    return fac[n] % MOD;
}

/**
 * @fn
 * Calculates the combination ( nCK % p: N choose K mod p).
 *
 * @brief
 * @return nCK % MOD
 */
long long combination2(int n, int k) {
    assert(initialized);
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    ll res = 1;
    k = min(k, n - k);
    for (long long x = 1; x <= k; x++) {
        res *= (n - x + 1);
        res %= MOD;
        res *= inv[x];
        res %= MOD;
    }
    return res;
}

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 Main() {
    ll n, a, b;
    cin >> n >> a >> b;
    combination_init();
    ll ans = pow(2, n, MOD) - 1;
    ans %= MOD;
    if (ans < 0) ans += MOD;
    ans -= combination2(n, a);
    ans %= MOD;
    if (ans < 0) ans += MOD;
    ans -= combination2(n, b);
    ans %= MOD;
    if (ans < 0) ans += MOD;
    cout << ans << '\n';
}

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


Measured memory_bytes: 12160
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, M = mapint()
As = [0]+list(mapint())
from itertools import accumulate
cAs = list(accumulate(As))

for i in range(N+1):
    cAs[i] = cAs[i]%M

from collections import Counter
c = Counter(cAs)
ans = 0
for num, cnt in c.most_common():
    if cnt<2:
        break
    ans += cnt*(cnt-1)//2

print(ans)

Measured memory_bytes: 102216
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    int a[n];
    rep(i, n) {
        cin >> a[i];
    }

    if(n == 1) {
        cout << a[0] << endl;
        return 0;
    }
    else {
        if(n % 2 == 1) {
            for(int i = n-1; 0 <= i; i -= 2) {
                cout << a[i] << " ";
            }
            for(int i = 1; i <= n-4; i += 2) {
                cout << a[i] << " ";
            }
            cout << a[n-2] << endl;
            return 0;
        }
        else {
            for(int i = n-1; 1 <= i; i -= 2) {
                cout << a[i] << " ";
            }
            for(int i = 0; i <= n-4; i += 2) {
                cout << a[i] << " ";
            }
            cout << a[n-2] << endl;
            return 0;
        }
    }
    
}

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

int main() {
   long long x, k, d;
   cin >> x >> k >> d;
   
   if(abs(x) > d) {
   		if(x < 0) {
   			long long val = ceil((1.0*(abs(x)-d))/d);
   			val = min(val, k);
   			x += val*d;
   			k -= val;
   		} else {
   			long long val = ceil((1.0*(x-d))/d);
   			val = min(val, k);
   			x -= val*d;
   			k -= val;
   		}
   }
   // cout << "x after while loop: " << x << endl;
   //     cout << "k after while loop: " << k << endl;
   ////while(k > 0 && abs(x) > d) {
   //   k--;
   //   if(x < 0) {
   //      x+=d;
   //   } else {
   //      x-=d;
   //   }
   //}
   
   

   long long ans;
   if(x < 0) {
      if(k%2 == 0) {
         cout << abs(x);
      } else {
         cout << min(abs(x + d), abs(x - d));
      }
   } else {
      if(k%2 == 0) {
         cout << abs(x);
      } else {
         cout << min(abs(x + d), abs(x - d));
      }
   }

	return 0;
}

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

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

vector<pair<ll, ll>> primeFactorize(ll n) {
  vector<pair<ll, ll>> r;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0) {
      continue;
    }
    ll ex = 0;
    while (n % i == 0) {
      ex++;
      n /= i;
    }
    r.push_back({i, ex});
  }
  if (n != 1) {
    r.push_back({n, 1});
  }
  return r;
}

int main() {
  int N;
  ll P;
  cin >> N >> P;
  const auto& res = primeFactorize(P);
  ll v = 1;
  for (auto r : res) {
    for (int i = 0; i < r.second / N; i++) {
      v *= r.first;
    }
  }
  cout << v << endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define f(i, n) for(int i = 0; i < n; ++i)
#define pb push_back
#define T int t = 0; cin >> t; while(t--)
#define b_e(a) a.begin(), a.end()
typedef long long ll;
typedef  long double lld;
const ll mod = 1e9 + 7;
const ll mx = 2e3 + 1;

void input(){
    int n, m;
    cin >> n >> m;
    cout << ((n == m) ? "Yes" : "No") << endl;
}
int main(){
    input();
    return 0;
}


Measured memory_bytes: 256
if __name__ == '__main__':

    n,k = map(int,input().split())
    h = list(map(int,input().split()))

    #TLE pypy
    INF = 10**9
    dp = [INF] * (n+1)
    dp[0] = 0
    k = min(k,n)
    for i in range(1,n):
        for j in range(1,k+1):
            dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
    print(dp[n-1])



Measured memory_bytes: 84924
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <ctime>

#define inf 0x3f3f3f3f
#define Inf 0x3FFFFFFFFFFFFFFFLL
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Rep(i, n) for (int i = 1; i <= (n); ++i)
#define clr(x, a) memset(x, (a), sizeof x)
using namespace std;
typedef long long ll;
int const N = 55;
ll x[N], y[N];
int main() {
  int n; cin >> n;
  rep(i, n) cin >> x[i] >> y[i];
  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }
  int ans = inf, p, q;
  rep(i, n) rep(j, n) if (i != j) {
    ll u = x[i] - x[j], v = y[i] - y[j];
    int t = 0;
    rep(i2, n) {
      bool ok = 0;
      rep(j2, n) if (i2 != j2) {
        if (x[i2] - x[j2] == u && y[i2] - y[j2] == v) ok = 1;
        if (ok) break;
      }
      if (ok) ++t;
    }
    ans = min(ans, n - t);
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
# import sys
# input = sys.stdin.readline
import itertools
import collections
from decimal import Decimal


# 持っているビスケットを叩き、1枚増やす
# ビスケット A枚を 1円に交換する
# 1円をビスケット B枚に交換する
def main():
    n = int(input())
    ans = ''
    for i in range(1, 99):
        if n <= 26 ** i:
            n -= 1
            for j in range(i):
                ans += chr(ord('a') + n % 26)
                n //= 26
            break
        else:
            n -= 26 ** i

    print(ans[::-1])

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def bfs(H, W, black_cells, dist):
    d = 0
    while black_cells:
        h, w = black_cells.popleft()
        d = dist[h][w]
        for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
            new_h = h + dy
            new_w = w + dx
            if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w:
                continue
            if dist[new_h][new_w] == -1:
                dist[new_h][new_w] = d + 1
                black_cells.append((new_h, new_w))
    return d


def input_list():
    return list(map(Decimal, input().split()))


def input_list_str():
    return list(map(str, input().split()))


if __name__ == "__main__":
    main()


Measured memory_bytes: 77272
import java.util.*;
import java.io.*;
public class Main
{   
    static int arr[][]=new int[100008][3];
    static int dp[][]=new int[100008][4];
    public static int getAns(int day,int lastday,int n)
    {
        if(day>=n)return 0;
        if(dp[day][lastday]!=-1)return dp[day][lastday];
        int ans=Integer.MIN_VALUE;
        if(lastday!=0)
        {
            ans=Math.max(ans,arr[day][0]+getAns(day+1,0,n));
        }
        if(lastday!=1)
        {
            ans=Math.max(ans,arr[day][1]+getAns(day+1,1,n));
        }
        if(lastday!=2)
        {
            ans=Math.max(ans,arr[day][2]+getAns(day+1,2,n));
        }
        return dp[day][lastday]=ans;
    }
	public static void main(String[] args)throws IOException {
		FastReader kb=new FastReader();
        int n=kb.nextInt();
        for(int i=0;i<dp.length;i++)Arrays.fill(dp[i],-1);
        for(int i=0;i<n;i++)
        {arr[i][0]=kb.nextInt();arr[i][1]=kb.nextInt();arr[i][2]=kb.nextInt();}
        System.out.println(getAns(0,3,n));
	}
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
  
}













Measured memory_bytes: 61756
#include<iostream>
#include<algorithm>
#include<cmath>
#include<typeinfo>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){ 
    string c[2];
    rep(i,2){
        cin >> c[i] ;
    }

    string a = c[0];
    string b = c[1];

    reverse(a.begin(),a.end());
    if(a == b) puts("YES");
    else puts("NO");
}   

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fi first
#define se second
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9+7;
int main(){
	fastio;
	ll a,b;
	cin>>a>>b;
	ll g = __gcd(a,b);
	cout<<(a*b)/g<<"\n";
}

Measured memory_bytes: 256
#20131121

while true
	n=gets.to_i
	break if n == 0
	count = 0
	1.upto(500){|e1|
		break if e1 >= n
		sum = 0
		e1.upto(500){|e2|
			sum+=e2
			if sum > n
				break
			elsif sum == n
				count+=1
				break
			end
		}
	}
	p count
end

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

int main() {
  int a, b,c,d,e;
  int list[100];
  int n;
  int x;
  while(cin >>x &&x){
  int i;
  for(i=0;i<x;i++) {
    cin>>a>>b>>c>>d>>e;
    list[i] = a+b+c+d+e;
  }
  n=i;
  sort(list, list+n);
  cout << list[n-1] << ' ' << list[0]<<endl;}
  return 0;
}

Measured memory_bytes: 1176
n, m = map(int, input().split())
cl = [1 for _ in range(n)]
rl = [1]+[0 for _ in range(n-1)]

for i in range(m):
    x_n, y_n = map(int, input().split())
    cl[x_n-1] -= 1
    cl[y_n-1] += 1
    if rl[x_n-1] == 1 and cl[x_n-1]>0:
        rl[y_n-1] = 1
    elif rl[x_n-1] == 1 and cl[x_n-1] == 0:
        rl[x_n-1] = 0
        rl[y_n-1] = 1
    elif rl[x_n-1] == 0:
        pass
print(sum(rl))


Measured memory_bytes: 5552
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=j; i<=k; i++)
#define FFOR(i, j, k) for(int i=j; i<k; i++)
#define DFOR(i, j, k) for(int i=j; i>=k; i--)
#define bug(x) cerr<<#x<<" = "<<x<<'\n'
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
template <typename T> inline void read(T &x){
    char c;
    bool nega=0;
    while((!isdigit(c=getchar()))&&(c!='-'));
    if(c=='-'){
        nega=1;
        c=getchar();
    }
    x=c-48;
    while(isdigit(c=getchar())) x=x*10+c-48;
    if(nega) x=-x;
}
template <typename T> inline void writep(T x){
    if(x>9) writep(x/10);
    putchar(x%10+48);
}
template <typename T> inline void write(T x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    writep(x);
}
template <typename T> inline void writeln(T x){
    write(x);
    putchar('\n');
}
#define taskname "E"
const ll base=1000000007;
int a[401];
int b[401];
ll f[401][401];
ll s[401][401];
int c, n;
inline ll sum(int c, int a, int b){
    return (s[b][c]-s[a-1][c])%base;
}
int main(){
    #ifdef Megumin
        if(fopen(taskname".inp", "r"))
            freopen(taskname".inp", "r", stdin);
    #endif // Megumin
    FOR(i, 1, 400){
        s[i][0]=1;
        FOR(j, 1, 400) s[i][j]=(s[i][j-1]*i)%base;
    }
    FOR(i, 1, 400) FOR(j, 0, 400) s[i][j]=(s[i][j]+s[i-1][j])%base;
    read(n);
    read(c);
    FOR(i, 1, n) read(a[i]);
    FOR(i, 1, n) read(b[i]);
    f[0][c]=1;
    FFOR(i, 0, n) FOR(j, 0, c) if(f[i][j]){
        FOR(k, 0, j) f[i+1][j-k]=(f[i+1][j-k]+f[i][j]*sum(k, a[i+1], b[i+1]))%base;
    }
    writeln((f[n][0]+base)%base);
}


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

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

    int loop, sum1 = 0, sum2 = 0;
    cin >> loop;
    vector<int> s1(loop);

    for (int i = 0; i < loop; i++) {
        cin >> s1[i];
        sum1 += s1[i];
    }

    sum1 -= s1[0];
    sum2 += s1[0];
    int min = abs(sum1 - sum2);
    for (int i = 1; i < loop - 1; i++) {
        sum1 -= s1[i];
        sum2 += s1[i];
        if (abs(sum1 - sum2) < min)
            min = abs(sum1 - sum2);
    }

    cout << min << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int zero(int);
int main(){
	int n;
	int a,b;
	cin>>n;
	cin>>a>>b;
	cout<<min(a,b)<<" "<<zero(a+b-n)<<endl;
}
int zero(int a){
	if(a<=0){
		return 0;
	}
	else return a;
}


Measured memory_bytes: 256
cup = [1,0,0]
while act  = gets
  case act.chomp
  when "A,B" then cup[0], cup[1] = cup[1], cup[0]
  when "B,A" then cup[0], cup[1] = cup[1], cup[0]
  when "A,C" then cup[0], cup[2] = cup[2], cup[0]
  when "C,A" then cup[0], cup[2] = cup[2], cup[0]
  when "B,C" then cup[1], cup[2] = cup[2], cup[1]
  when "C,B" then cup[1], cup[2] = cup[2], cup[1]
  end
end

case cup.index(1)
  when 0 then puts "A"
  when 1 then puts "B"
  when 2 then puts "C"
end

Measured memory_bytes: 8592
n, x = map(int, input().split())
a, p = [1], [1]
for i in range(n):
    a.append(a[i] * 2 + 3)
    p.append(p[i] * 2 + 1)

def f(n, x):
    if n == 0:
        return 0 if x <= 0 else 1
    elif x <= 1 + a[n - 1]:
        return f(n - 1, x - 1)
    else:
        return p[n - 1] + 1 + f(n - 1, x - 2 - a[n - 1])
print(f(n, x))

Measured memory_bytes: 3064
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define show(n) cerr<<#n<<" = "<<n<<endl
#define showp(n) cerr<<n.fs<<", "<<n.sc<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showsp(n) for(auto z:n){cerr<<z.fs<<" "<<z.sc<<", "}cerr<<endl

#define yes puts("Yes")
#define no puts("No")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

inline void io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}
template<typename T> inline void in(T &e){cin>>e;}
template<typename T> inline void out(T e){cout<<e<<endl;}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

int n;

signed main(){
    io();
    in(n);

    for(int c=0;;c+=4){
        if(c>100) break;
        for(int d=0;;d+=7){
            if(c+d > 100) break;
            if(c+d==n){
                yes;
                return 0;
            }
        }
    }
    no;

    return 0;
}


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

typedef long long ll;


int main() {
    int i, j, k, n, m, h=0, v=0;
    int x, y;
    int ans=0;
    cin>>x>>y;
    if(x==0) {
        if(y>=0)    cout<<y;
        else    cout<<1-y;
        return 0;
    }
    if(y==0) {
        if(x>0) {
            cout<<1+x;
        }
        else    cout<<abs(x);
        return 0;
    }

    if(x>y) {
        if(x<0 && y<0) {
            ans=2+abs(y)-abs(x);
        }
        if(x>0 && y>0) {
            ans=2+x-y;
        }
        if(x>0 && y<0) {
            if(abs(y)<=x) {
                ans=1+x-abs(y);
            }
            else {
                ans=1+abs(y)-x;
            }
        }
    }
    else if(x<y) {
        if(x<0 && y<0) {
            ans=y-x;
        }
        if(x>0 && y>0) {
            ans=y-x;
        }
        if(x<0 && y>0) {
            ans=1+abs(y-abs(x));
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 384