akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<climits>
using namespace std;

typedef long long ll;

struct Edge{int from, to; ll cost;};

const ll INF = 1ll<<50;

int main(){
    int n, m, a, b;
    ll c;
    cin >> n >> m;

    Edge es[m];

    for(int i = 0; i < m; i++){
        cin >> a >> b >> c;
        a--, b--;
        es[i].from = a, es[i].to = b, es[i].cost = -c;
    }

    ll score[n];
    for(int i = 0; i < n; i++)  score[i] = 0;

    bool neg = false;
    for(int i = 0; i < 2*n; i++){
        for(int j = 0; j < m; j++){
            Edge e = es[j];
            if(score[e.from] + e.cost < score[e.to]){
                score[e.to] = score[e.from] + e.cost;
                if(i >= n-1 && e.to == n-1)    neg = true;
            }
        }
    }

    if(neg){
        cout << "inf" << endl;
        return 0;
    }

    for(int i = 0; i < n; i++)  score[i] = INF;
    score[0] = 0;

    for(int i = 0; i < n-1; i++){    
        for(int j = 0; j < m; j++){
            Edge e = es[j];
            if(score[e.from] == INF)  continue;
            if(score[e.from] + e.cost < score[e.to]){
                score[e.to] = score[e.from] + e.cost;
            }
        }
    }

    cout << -score[n-1] << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var result = Console.ReadLine()
                .Split(' ')
                .Select(x => int.Parse(x))
                .Aggregate((mults, value) => mults * value);

            if (result % 2 == 0)
            {
                Console.WriteLine("Even");
            }
            else
            {
                Console.WriteLine("Odd");
            }
        }
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
typedef long long ll;
typedef long double ld;
char str[200005];
int dp[200005][4];
int main() {
	scanf("%s", str);
	int n = strlen(str);
	const int INF = 1e9;
	fill(dp[0], dp[0] + 4, -INF);
	dp[0][0] = 0;
	for (int i = 0; i < n; ++i) {
		string s;
		fill(dp[i + 1], dp[i + 1] + 4, -INF);
		for (int l = 1; l <= 3; ++l) {
			if (l > i + 1) continue;
			s += str[i - l + 1];
			string t;
			for (int j = 0; j <= 3; ++j) {
				if (j + l > i + 1) continue;
				if (j) t += str[i - l - j + 1];
				if (s == t) continue;
				dp[i + 1][l] = max(dp[i + 1][l], dp[i + 1 - l][j] + 1);
			}
		}
	}
	printf("%d\n", *max_element(dp[n], dp[n] + 4));
}


Measured memory_bytes: 3584
/*

                                  In the name of Allah, Most Gracious, Most Merciful


*/
#include<bits/stdc++.h>
#include<numeric>
using namespace std;

//*** constant value ***
const long double PI = 3.141592653589793238;
const double EPS = 1e-6 ;
//*** constant value ***

//****** define ********
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define dd double
#define vll vector<ll>
#define vs vector<string>
#define fn(i,n) for(ll i = 0; i<n; i++)
#define f(i,a,b) for(i=a;i<b;i++)
#define f1(i,a,b) for(i=b-1;i>=a;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pls pair<ll,string>
#define vpl vector<pll>
#define pb push_back
#define mk make_pair
#define x first
#define y second
#define tt cout<<"Came here"<<endl;
//****** define ********
void solve()
{
   ll k,n;
   cin>>k>>n;
   vll v(n);
   fn(i,n)
   cin>>v[i];
   sort(v.begin(),v.end());
   ll ans = v[n-1] - v[0];
   fn(i,n)
   {
       if(i==0)
        continue;
       ans = min(ans, k -(v[i]-v[i-1]));
   }

   cout<<ans<<endl;

}

int main()
{
    IOS;
    ll tc = 1;
    while(tc--)
    {
        solve();
    }


return 0;
}



Measured memory_bytes: 4752
import numpy as np
import pdb

def main():
    mystring = np.array(list(raw_input()))
    oddstr = oddstring(mystring)
    oddstr = ''.join(oddstr)
    print oddstr

def oddstring(mystring):
    stringsize = len(mystring)
    oddindices = range(0,stringsize, 2)
    oddstr = mystring[oddindices]
    return oddstr

if __name__ == '__main__':
    main()


Measured memory_bytes: 19420
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<int> L(M), R(M);
    vector<int> p(Q), q(Q);
    vector<vector<int>> train(N + 1, vector<int>(N + 1, 0));
    for (int i = 0; i < M; i++)
    {
        cin >> L[i] >> R[i];
        L[i]--;
        R[i]--; //0-indexed
        train[L[i]][R[i]]++;
    }

    for (int i = 0; i < Q; i++)
    {
        cin >> p[i] >> q[i];
    }
    // rui[s][g]でs~gまでに完全に含まれる列車の本数をO(1)で取り出したい
    vector<vector<int>> rui(N + 1, vector<int>(N + 1, 0));
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            rui[i + 1][j + 1] = rui[i][j + 1] + rui[i + 1][j] - rui[i][j] + train[i][j];
        }
    }

    for (int i = 0; i < Q; i++)
    {
        cout << rui[q[i]][q[i]] - rui[q[i]][p[i] - 1] - rui[p[i] - 1][q[i]] + rui[p[i] - 1][p[i] - 1] << endl;
    }
}

Measured memory_bytes: 5248
if __name__ == "__main__":
    n, x = map(int, input().split())
    a = list(map(int, input().split()))

    total = sum(a)

    if a[0] > x:
        a[0] = x

    for i in range(0, n-1):
        if a[i] + a[i+1] > x:
            a[i+1] = x - a[i]

    print(total-sum(a))


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

int height[100010],dp[100010];

int main()
{
    int n; cin>>n;
    dp[0]=0;
    for(int i=0;i<n;i++)
        cin>>height[i];
    for(int i=1;i<n;i++)
    {
        dp[i]=dp[i-1]+abs(height[i-1]-height[i]);
        if(i-2>=0)
            dp[i]=min(dp[i],dp[i-2]+abs(height[i-2]-height[i]));
    }
    cout<<dp[n-1];
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define maxn 305
#define inf 0x3f3f3f3f
#define LL long long
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define mm(a,b) memset(a,b,sizeof(a))
#define mp(a,b) make_pair(a,b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
const double eps = 1e-6;
const LL mod=1e9+7;
const LL INF=(LL)1e18;
using namespace std;
LL gcd(LL a,LL b){return b==0?a:gcd(b,a%b);}
LL qpow(LL x,LL y){LL re=1,base=x%mod;while(y){if(y&1)re=(re*base)%mod;base=(base*base)%mod;y>>=1;}return re;}
int n,m;
queue<int>q[maxn];
int vis[maxn],num[maxn];
int Max,ans,wh0;
int main(){
//	freopen("input.txt","r",stdin);
//	freopen("ouput.txt","w",sdout);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			int x;
			cin>>x;
			q[i].push(x);
		}
	}
	mm(vis,0),ans=inf;
	for(int i=1;i<=m;i++){
		mm(num,0);
		Max=0;
		int who=q[1].front();
		for(int j=1;j<=n;j++){
			int x=q[j].front();
			while(vis[x]){
				q[j].pop();
				x=q[j].front();
			}
			num[x]++;
			if(num[x]>Max){
				Max=num[x];
				who=x;
			}
		}
		vis[who]=1;
		ans=min(ans,Max);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 768
N,M = map(int,input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
#ans = False
for dx in range(N-M+1):
    for dy in range(N-M+1):
        flg = True
        for i in range(M):
            for j in range(M):
                if A[i+dx][j+dy] != B[i][j]:
                    flg = False
        if flg:
            print("Yes")
            exit()
print("No")

Measured memory_bytes: 3064
use std::io;
use std::str::FromStr;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn input_vec() -> Vec<u64> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

fn main() {
    let n: u64 = input();
    let mut a_vec = input_vec();
    a_vec.sort_by(|x, y| y.cmp(&x));
    let mut ans = a_vec[0];
    let mut i = 1;
    let mut count = 1;
    while count < n - 1 {
        // print!("{} ", a_vec[i as usize]);
        ans += a_vec[i as usize];
        count += 1;
        if count < n - 1 {
            // print!("{} ", a_vec[i as usize]);
            ans += a_vec[i as usize];
            count += 1;
            i += 1;
        } else {
            break;
        }
    }
    // println!();
    println!("{}", ans);
}


Measured memory_bytes: 5824
//minamoto
#include<bits/stdc++.h>
#define R register
#define ll long long
#define inf 0x3f3f3f3f3f3f3f3f
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
ll read(){
    R ll res,f=1;R char ch;
    while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
    for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
    return res*f;
}
inline char getop(){R char ch;while((ch=getc())>'Z'||ch<'A');return ch;}
const int N=505;
struct eg{int v,nx,w;ll c;}e[N*N];int head[N],tot;
inline void add(R int u,R int v,R ll c){
	e[++tot]={v,head[u],1,c},head[u]=tot,
	e[++tot]={u,head[v],0,-c},head[v]=tot;
}
int x[N],y[N],a[N],b[N],t[N],LL[N],RR[N],DD[N],UU[N],vis[N],pe[N],n,m,S,T;
ll v[N],dis[N],res,ans;queue<int>q;
bool spfa(){
	memset(dis,0x3f,sizeof(dis));
	dis[S]=0,q.push(S);
	while(!q.empty()){
		int u=q.front();q.pop(),vis[u]=0;
		go(u)if(e[i].w&&(cmin(dis[v],dis[u]+e[i].c)?pe[v]=i,1:0)&&!vis[v])q.push(v),vis[v]=1;
	}
	if(dis[T]==inf)return false;
	res+=dis[T];
	for(R int i=T;i!=S;i=e[pe[i]^1].v)--e[pe[i]].w,++e[pe[i]^1].w;
	return true;
}
ll calc(int k){
	fp(i,1,k)LL[i]=DD[i]=0,RR[i]=UU[i]=19260817;
	fp(i,1,m)if(b[i]<k){
		switch(t[i]){
			case 'L':LL[b[i]+1]=a[i]+1;break;
			case 'R':RR[k-b[i]]=a[i]-1;break;
			case 'D':DD[b[i]+1]=a[i]+1;break;
			case 'U':UU[k-b[i]]=a[i]-1;break;
		}
	}
	fp(i,2,k)cmax(LL[i],LL[i-1]),cmax(DD[i],DD[i-1]);
	fd(i,k-1,1)cmin(RR[i],RR[i+1]),cmin(UU[i],UU[i+1]);
	memset(head,0,sizeof(head)),tot=1;
	S=0,T=(n+k)<<1|1;
	fp(i,1,n)add(i,n+i,-v[i]-1000000000000000ll);
	fp(i,1,k){
		add(S,n+n+i,0),add(n+n+k+i,T,0);
		fp(j,1,n){
			if(x[j]>=LL[i]&&x[j]<=RR[i])add(n+n+i,j,0);
			if(y[j]>=DD[i]&&y[j]<=UU[i])add(n+j,n+n+k+i,0);
		}
	}
	res=0;while(spfa());
	return -res-k*1000000000000000ll;
}
int main(){
//	freopen("testdata.in","r",stdin);
	n=read();
	fp(i,1,n)x[i]=read(),y[i]=read(),v[i]=read();
	m=read();
	fp(i,1,m)t[i]=getop(),a[i]=read(),b[i]=read();
	fp(i,1,n)cmax(ans,calc(i));
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2816
# # Make IO faster
# import sys
# input = sys.stdin.readline

# # get single (or) multiple str
# X = input()

# # get single int
# N = int(input())
# # get multiple int (e.g., 2)
# X, Y = map(int, input().split())
# # get multiple int (e.g., 2) for N lines
# XY = [list(map(int, input().split())) for _ in range(N)]

# from IPython import embed; embed(); exit();

# 全部入り
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

from collections import Counter
N = INT()
S = input().split(" ")
# print()
if len(Counter(S)) == 3:
    print("Three")
else:
    print("Four")


Measured memory_bytes: 27068
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const long long MOD = 998244353;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll = long long;
using pLL = std::pair<ll, ll>;
#define SORT(v) std::sort(v.begin(), v.end())
#define RSORT(v) std::sort(v.rbegin(), v.rend())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string n,x;
    cin >> n >> x;
    
    cout << x << n << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
    const int oo = 1e9;
    using namespace std;
    void fast(){
    	std::ios_base::sync_with_stdio(0);
    	cin.tie(NULL); cout.tie(NULL);
    }
     
     
    int main(){
    	fast();
    int n , m;cin>>n>>m;
--n,--m;
    cout<<(n * m )<<endl;
    	return 0;
    }
    //mosta7il_

Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define ll long long int
#define vec vector
#define forn(a) for(ll a=0; a<n; a++)
#define all(x) x.begin(), x.end()
#define deb(x) cerr<<#x<<" = "<<x<<endl

using namespace std;

int main() {
    IOS;

    int k, x; cin>>k>>x;
    for(int i=x-(k-1); i<=x+(k-1); i++){
        cout<<i<<" ";
    }cout<<endl;

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("sse,sse2")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

template<class T>
using ordered_set = tree <T, null_type ,  less<T> ,  rb_tree_tag ,  tree_order_statistics_node_update>;

template<class T>
using ordered_multiset = tree <T, null_type ,  less_equal<T> ,  rb_tree_tag ,  tree_order_statistics_node_update>;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;
using vvi = vector<vi>;
using vvii = vector<vii>;

#define all(x) x.begin(), x.end()
#define all_r(x) x.rbegin(), x.rend()
#define pb push_back
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define REP(i, n) for(int i = n; i >= 0; --i)
#define f first
#define s second
int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string S;
	int k;
	cin >> k >> S;
	if((int)S.size() <= k) cout << S << '\n';
	else cout << S.substr(0, k) + "..." << '\n';
 	return 0;
}

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

using namespace std;

#define debug(x) '[' << #x << " is: " << x << "] "
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int nax = 333;

ld dp[nax][nax][nax],ev[nax][nax][nax];
int n;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.precision(10);
	cout << fixed;
	#ifndef ONLINE_JUDGE
	//	freopen("input.txt","r",stdin);
	#endif
	cin>>n;
	vector<int> a(4);
	int sum = 0;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		a[x]++;
		sum+=x;
	}
	dp[a[1]][a[2]][a[3]]=1;
	for(int c=n;c>=0;c--){
		for(int b=n;b>=0;b--){
			for(int a=n;a>=0;a--){
				if(!dp[a][b][c])continue;
				if(!a && !b && !c || a+b+c>n)continue;

				ld waste = (n - (a + b + c))/(n+0.0);
				ev[a][b][c] += (waste / (1-waste)) * dp[a][b][c];

				if(a){
					dp[a-1][b][c] += dp[a][b][c] * a / (a+b+c);
					ev[a-1][b][c] += ev[a][b][c] * a / (a+b+c);
				}
				if(b){
					dp[a+1][b-1][c] += dp[a][b][c] * b / (a+b+c);
					ev[a+1][b-1][c] += ev[a][b][c] * b / (a+b+c);
				}
				if(c){
					dp[a][b+1][c-1] += dp[a][b][c] * c / (a+b+c);
					ev[a][b+1][c-1] += ev[a][b][c] * c / (a+b+c);
				}
			}
		}
	}
	cout << ev[0][0][0] + sum << endl;
}

Measured memory_bytes: 948096
H, W = gets.chomp.split.map(&:to_i)

ll = []

H.times do |i|
  a = gets.chomp.chars

  next if a.count('.') == W
  ll << a
end


cols = []
W.times do |j|
  flag = false
  ll.length.times do |i|
    flag = true if ll[i][j] == '#'
  end

  cols << j if flag
end

ans = []
ll.length.times do |i|
  row = []
  cols.each do |j|
    row << ll[i][j]
  end
  ans << row
end

ans.each do |row|
  puts row.join
end


Measured memory_bytes: 2556
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int ans = 0;
    string S;
    cin >> S;
    rep(i, 4) {
        if (S[i] == '+') ++ans;
        else --ans;
    }
    cout << ans << endl;
    return 0;
}


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

int main(void){
	int input;
	int h,m,s;
	
	cin >> input;
	
	s = input % 60;
	m = ((input - s) / 60) % 60;
	h = (input - m*60 - s) / 3600;
	
	cout << h <<":"<< m <<":"<< s << endl;
	return(0);
}

Measured memory_bytes: 1164
class UnionFind:
  def __init__(self, n):
    self.tree = [-1] * n
    self.rank = [0] * n
    self.diff_weight = [0] * n
  
  def unite(self, a, b, w):
    w += self.weight(a)
    w -= self.weight(b)
    a = self.root(a)
    b = self.root(b)
    if a == b:
      return
    if self.rank[a] < self.rank[b]:
      a, b = b, a
      w *= -1
    if self.rank[a] == self.rank[b]:
      self.rank[a] += 1
    self.tree[b] = a
    self.diff_weight[b] = w
    
  def root(self, a):
    if(self.tree[a] < 0):
      return a
    else:
      res = self.root(self.tree[a])
      self.diff_weight[a] += self.diff_weight[self.tree[a]]
      self.tree[a] = res
      return self.tree[a]

  def same(self, a, b):
    return self.root(a) == self.root(b)

  def weight(self, a):
    self.root(a)
    return self.diff_weight[a]

  def diff(self, a, b):
    return self.weight(b) - self.weight(a)

import sys

stdin = sys.stdin
na = lambda: map(int, stdin.readline().split())
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())

def main():
  n, m = na()
  uf = UnionFind(n)
  for _ in range(m):
    t = list(na())
    a, b, c = t[0], t[1], t[2]
    if a == 0:
      d = t[3]
      uf.unite(b, c, d)
    else:
      if uf.same(b, c):
        print(uf.diff(b, c))
      else:
        print("?")

main()


Measured memory_bytes: 11468
#include <iostream>

using namespace std;

int main() {
    int r, g, b;
    cin >> r >> g >> b;
    int value = r * 100 + g * 10 + b;
    if (value % 4 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

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

int main (){
  int n;
  cin>>n;
  vector<int> v(n);
  rep(i,n){
    cin>>v.at(i);
  }
  int sum=0;
  rep(i,n){
    sum+= v.at(i);
  }
  cout << sum - n << endl;
}

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

int main(){
  int n, m;
  std::cin >> n >> m;
  vector<string> a(n), b(m);
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    std::cin >> b[i];
  }
  for (int i = 0; i < n - m + 1; i++) {
    for (int j = 0; j < n - m + 1; j++) {
      for (int y = i; y < i + m; y++) {
        for (int x = j; x < j + m; x++) {
          if(a[y][x] != b[y - i][x - j])x = y = 1e9;
        }
        if(y == i + m - 1){
          std::cout << "Yes" << std::endl;
          return 0;
        }
      }
    }
  }
  std::cout << "No" << std::endl;
  return 0;
}


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

int main() {
    while (1) {
        int H, W;
        cin >> H >> W;
        if (H == 0 && W == 0) break;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if ((i + j) % 2 == 0) cout << "#";
                else cout << ".";
            }
            cout << endl;
        }
        cout << endl;
    }
}


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

int main(){
    string s,t;
    cin>>s>>t;
    sort(s.begin(),s.end());

    sort(t.begin(),t.end());
    reverse(t.begin(),t.end());
    if(s<t)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 3616
# 与えられた N 以下の素数を列挙して、その N 以下の素数の素因数分解を高速に与えるアルゴリズム。
#
# 計算量:
#     構築: O(N)　
#     素因数分解: n <= N なる n に対し O(log n)、N < n <= N**2 なる n に対し、O(N / log N)
#
#
# 参考: https://cp-algorithms.com/algebra/prime-sieve-linear.html (n <= N に対して O(log n) の部分)

from collections import defaultdict

n = int(input())
N = n + 10  # 10 ** 7 以下だとよさそう。10 ** 7 でPyPy3で構築に500ms程度。
lp = [0] * (N+1)
pr = []  # N 以下の素数のリスト
for i in range(2, N+1):
    if lp[i] == 0:
        lp[i] = i
        pr.append(i)
    for j, p in enumerate(pr):
        if p > lp[i] or i * p > N:
            break
        lp[i * p] = p


def fac_small(n):
    """
    引数 n の素因数分解をして、素因数を昇順に格納したリストを返す。
    ex. fac_small(60) == [2, 2, 3, 5]
    与えられた n について 1 <= n <= N を仮定する。n == 1 では空リストを返す。
    計算量は O(log n) 
    """
    # assert 1 <= n <= N
    ret = defaultdict(int)
    while n > 1:
        ret[lp[n]] += 1
        n //= lp[n]
    return ret


ans = 0
for c in range(1, n):
    tmp = 1
    for f in (fac_small(n - c)).values():
        tmp *= (f + 1)
    ans += tmp

print(ans)

Measured memory_bytes: 80068
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll MOD=1e9+7;
const int INF=1<<30;

map<ll,ll> pfmp; //各素因数の冪指数の総和を格納
vector<ll> pfv(0); //異なる素因数を昇順に格納

void PF(ll N){
  ll n=N;
  if(n<=0) return;
  if(n%2==0){
    if(pfmp[2]==0) pfv.push_back(2);
    while(n%2==0){
      n/=2;
      pfmp[2]++;
    }
  }
  if(n==1) return;
  for(ll i=3;i<=sqrt(N);i+=2){
    if(n%i==0){
      if(pfmp[i]==0) pfv.push_back(i);
      while(n%i==0){
        n/=i;
        pfmp[i]++;
      }
    }
  }
  if(n!=1){
    if(pfmp[n]==0) pfv.push_back(n);
    pfmp[n]++;
  } 
  sort(all(pfv));
}

const int MAX=200001; //nCrのnのMAX+1
ll fac[MAX],finv[MAX],inv[MAX];

void COMinit(){
  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;
  }
}
ll COM(int n,int k){
  if (n<k) return 0;
  if (n<0||k<0) return 0;
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
//Add COMinit(); in main function.

int main(){
  COMinit();
  int N,M; cin >> N >> M;
  PF(M);
  ll ans=1;
  for(auto c:pfmp){
    ans*=COM(N-1+c.second,N-1);
    ans%=MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

template <typename T>
map<pair<int, int>, T> dijkstra(int s, map<pair<int, int>, vector<pair<pair<int, int>, int>>> &G) {
    // const T inf = numeric_limits<T>::max();
    using P = pair<T, pair<int, int>>;
    // int n       = G.size();
    map<pair<int, int>, T> d;
    priority_queue<P, vector<P>, greater<P>> q;
    d[{s, -1}] = 0;
    q.push({d[{s, -1}], {s, -1}});
    while (!q.empty()) {
        P p = q.top();
        q.pop();
        auto v = p.second;
        if (d.count(v) != 0 && d[v] < p.first)
            continue;
        for (auto &e : G[v]) {
            auto u = e.first;
            T c    = e.second;
            if (d.count(u) == 0 || d[u] > d[v] + c) {
                d[u] = d[v] + c;
                q.push({d[u], u});
                // cout << u.first << " " << u.second << " " << d[u] << "\n";
            }
        }
    }
    return d;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    map<pair<int, int>, vector<pair<pair<int, int>, int>>> edges;
    for (int i = 0; i < m; ++i) {
        int u, v;
        int w;
        cin >> u >> v >> w;
        u--, v--, w--;
        edges[{u, w}].push_back({{v, w}, 0});
        edges[{v, w}].push_back({{u, w}, 0});
        edges[{u, -1}].push_back({{u, w}, 1});
        edges[{v, -1}].push_back({{v, w}, 1});
        edges[{u, w}].push_back({{u, -1}, 0});
        edges[{v, w}].push_back({{v, -1}, 0});
    }
    map<pair<int, int>, int> ret = dijkstra<int>(0, edges);
    if (ret.count({n - 1, -1}) == 0)
        cout << -1 << "\n";
    else
        cout << ret[{n - 1, -1}] << "\n";
    return 0;
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

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

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl;
#define int ll

const ll mod = 1e9 + 7;
const ll inf = (1LL << 50);

void solve(long long N, std::vector<long long> P, std::vector<long long> Q){
    queue<int> que;
    rep(i, N) que.push(i + 1);

    while(to_string(que.front()).size() < N) {
        string t = to_string(que.front());
        que.pop();
        for(int i = 1; i <= N; i++) {
            char c = (char)(i + '0');
            // debug(t)
            // debug(c)
            if (t.find(c) == string::npos) {
                que.push(stoi(t + c));
            }
        }
    }

    vector<int> v;
    while(!que.empty()) {
        v.emplace_back(que.front());
        que.pop();
    }
    sort(all(v));

    int p = 0, q = 0;    
    rep(i, N) {
        p *= 10, q *= 10;
        p += P[i];
        q += Q[i];
    }
    // debug(p);
    // debug(q);
    // rep(i, N) debug(v[i]);
    cout << abs(lower_bound(all(v), q) - lower_bound(all(v), p)) << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    long long N;
    scanf("%lld",&N);
    std::vector<long long> P(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&P[i]);
    }
    std::vector<long long> Q(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&Q[i]);
    }
    solve(N, std::move(P), std::move(Q));
    return 0;
}


Measured memory_bytes: 1284
//Zory-2020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define db double
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define mem(x,val) memset(x,val,sizeof x)
#define Swap(a,b,n) for(int I=0;I<=n;I++) swap(a[I],b[I])
#define PC __builtin_popcountll
#ifdef DEBUG
	#define debug(A,args...) fprintf(stderr,A,##args)
#else
	#define debug(A,args...) printf("")
#endif
#define deb debug("line %d\n",__LINE__)
namespace mine
{
	ll qread()
	{
		ll ans=0,f=1;char c=getchar();
		while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);putchar('\n');}
	template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
	template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
	ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
	bool IN(ll x,ll l,ll r){return l<=x and x<=r;}
	void GG(){puts("-1");exit(0);}

	const db eps=1e-8;
	const int INF=0x3f3f3f3f;
	const int MOD=998244353;
	int mm(const int x){return x>=MOD?x-MOD:x;}
	template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
	ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
	ll invm(ll x){return qpower(x,MOD-2);}
	const int MM=5e6+10;
	ll fac[MM],facinv[MM],Inv[MM];ll Comb(int n,int m){return n<0 or n<m?0:fac[n]*facinv[m]%MOD*facinv[n-m]%MOD;}
	void PRE()
	{
		fac[0]=1;fo(i,1,MM-1) fac[i]=fac[i-1]*i%MOD;
		facinv[MM-1]=invm(fac[MM-1]);fd(i,MM-1,1) facinv[i-1]=facinv[i]*i%MOD;
		Inv[1]=1;fo(i,2,MM-1) Inv[i]=(MOD-MOD/i)*Inv[MOD%i]%MOD;
	}
	const int N=1e6+10;
	//随机数
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ll rd(ll l,ll r){return l+rng()%(r-l+1);}
	//------------------FIXED------------------
	char str[N];
	void main()
	{
		scanf("%s",str+1);
		puts(str[3]==str[4] and str[5]==str[6]?"Yes":"No");
	}
};//变量重名！
signed main()
{
	#ifdef DEBUG
	//freopen("a.in","r",stdin);
	//freopen("z.txt","r",stdin);
	//freopen("a.out","w",stdout);
	#endif
	srand(time(0));
	mine::main();
	//debug("\n------------------------------------------\nTime: %.2lf s\n",1.0*clock()/CLOCKS_PER_SEC);
}

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

int gcd(int, int);

int main() {
    int x(0), y(0);
    cin >> x >> y;
    cout << gcd(x, y) << "\n";
    return 0;
}

int gcd(int x, int y) {
    if(x % y == 0) {
        return y;
    }
    return gcd(y, x % y);
}


Measured memory_bytes: 3096
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
  ll n;
  cin>>n;
  vector<ll> v;
  rep(i,0,n){
    ll a;
    cin>>a;
    v.pb(a);
  }
  map<ll,ll> ma;
  rep(i,0,v.sz){
    ma[v[i]]++;
  }
  vector<pair<ll,ll> > v1;
  map<ll,ll>::iterator itr = ma.begin();
  while(itr!=ma.end()){
    ll a = (*itr).fi;
    ll b = (*itr).se;
    v1.pb(mp(a,b));
    itr++;
  }
  sort(all(v1));
  ll flag = 0;
  if(v1.sz==1){
    if(v1[0].fi==0){
      flag = 1;
    }
  }
  else if(v1.sz==2){
    if(v1[0].fi==0&&v1[0].se*2==v1[1].se){
      flag = 1;
    }
  }
  else if(v1.sz==3){
    if((v1[0].fi^v1[1].fi)==v1[2].fi){
      if(v1[0].se==v1[1].se&&v1[1].se==v1[2].se){
        flag = 1;
      }
    }
  }
  if(flag==1){
      cout << "Yes" << endl;
  }
  else{
      cout << "No" << endl;
  }
  return 0;
}

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

int main(){
    int antena[5];
    int k;
    bool flag = true;
    for (int i = 0; i < 5; i++){
        cin >> antena[i];
    }
    cin >> k;
    if (antena[4] - antena[0] > k){
        cout << ":(" << endl;
    }
    else cout << "Yay!" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstring>
#include <set>

using namespace std;

const int maxn = 1e5 + 5;

struct Node {
    int x, y, id;
}node[maxn];

struct Edge {
    int u, v, val;
    bool operator <(const Edge& rhs) const {
        return val < rhs.val;
    }
}e[maxn << 1];

int par[maxn];
int n;

bool cmp1(const Node &a, const Node &b) {
    return a.x < b.x;
}

bool cmp2(const Node &a, const Node &b) {
    return a.y < b.y;
}

void init() {
    for (int i = 0; i <= n; i ++)
        par[i] = i;
}

int findpar(int x) {
    return par[x] = (par[x] == x ? x : findpar(par[x]));
}

void unite(int x, int y) {
    x = findpar(x), y = findpar(y);
    if (x == y) return;
    par[x] = y;
}

int main(int argc, char const *argv[]) {
    
    cin >> n;

    init();

    for (int i = 1; i <= n; i ++) {
        scanf("%d%d", &node[i].x, &node[i].y);
        node[i].id = i;
    }

    sort(node + 1, node + n + 1, cmp1);

    int cnt = 0;
    for (int i = 2; i <= n; i ++)
        e[cnt ++] = (Edge){node[i - 1].id, node[i].id, node[i].x - node[i - 1].x};
    
    sort(node + 1, node + n + 1, cmp2);
    for (int i = 2; i <= n; i ++)
        e[cnt ++] = (Edge){node[i - 1].id, node[i].id, node[i].y - node[i - 1].y};

    sort(e, e + cnt);

    long long ans = 0;
    for (int i = 0; i < cnt; i ++) {
        int u = e[i].u, v = e[i].v, val = e[i].val;
        if (findpar(u) == findpar(v)) continue;
        unite(u, v);
        ans += val;
    }

    cout << ans << endl;

    return 0;
}

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

int main(void) {
  string s;
  cin >> s;
  int i = 0, tmp;
  bool key = false;

  while(1) {
    tmp = i;
    if(0 == s.compare(i,11,"dreameraser")) {
      i += 11;
    } else if (0 == s.compare(i,10,"dreamerase")) {
      i += 10;
    } else if (0 == s.compare(i,7,"dreamer")) {
      i += 7;
   } else if(0 == s.compare(i,5,"dream")) {
      i += 5;
    } else if (0 == s.compare(i,6,"eraser")) {
      i += 6;
    }else if (0 == s.compare(i,5,"erase")) {
      i += 5;
    }
   
    //cout << i << endl;
    if (tmp == i) {
      key = false; break;
    } else if (i == s.size()) {
      key = true; break;
    } 
  }

  if(key) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 2e5+10 , M = 5e5+10, OO = 0x3f3f3f3f ,  MOD = 1e9+7;
const double EPS = 1e-3;
#define M_PI 3.14159265358979323846
#define clr(arr,val) memset(arr , val , sizeof (arr))
#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n)-1;i >= 0;i--)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define pb push_back
#define F first
#define S second
#define all(v) ((v).begin()) , ((v).end())
#define sz(v)  ((int)((v).size()))
typedef pair <int,int> pii ;
typedef vector < pii > vii ;
typedef vector < int > vi;
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);

char s[1005][1005];
ll dp[1005][1005];
int n, m;

ll solve(int i , int j){
    if(i >= n || j>= m) return 0;
    if(s[i][j] == '#') return 0;
    if(i == n-1 && j == m-1) return 1;

    ll& ret = dp[i][j];
    if(~ret) return ret;

    ret = (solve(i , j+1) + solve(i+1 , j))%MOD;
    return ret;

}





int main(){


    //ios_base::sync_with_stdio(0);
    //cin.tie(0);cout.tie(0);


    scanf("%d %d",&n,&m);
    for(int i = 0 ; i < n ; ++i)
        scanf("%s", s[i]);


    memset(dp , -1 , sizeof dp);
    ll ans = solve(0,0);
    printf("%lld\n",ans);



    return 0;
}


Measured memory_bytes: 9216
let rec pow a n = if n <= 0 then 1 else a * pow a (n-1)
let mod_mul a b = (a * b) mod 1000000007
let rec for_iter a b f = if a >= b then [] else let x = f a in x :: for_iter (a+1) b f
let is_prime x = 
  if x <= 1 then false
  else
    for_iter 2 x (fun i -> x mod i)
    |> List.for_all ((<>) 0)

let n = Scanf.scanf "%d" (fun x -> x)
let () =
  for_iter 2 (n+1) (fun d ->
    if not (is_prime d) then
      1
    else
      let v = for_iter 1 15 (fun p -> n / pow d p)
        |> List.fold_left (+) 0
      in v+1
  ) |> List.fold_left mod_mul 1
  |> Printf.printf "%d\n"

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

int z(int i) {
  if (i >= 0) {
    return i;
  }
  if (i < 0) {
    return 0 - i;
  }
}
 
int main() {
  int N;
  cin >> N;
  vector<int> w(N);
  int sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> w.at(i);
    sum += w.at(i);
  }
  int m = 0;
  for (int i = 0; i < N; i++) {
    m += w.at(i);
    int M = sum - m;
    w.at(i) = M - m;
    if (i > 1 && w.at(i) <= 0) {
      cout << min(z(w.at(i)), z(w.at(i - 1))) << endl;
      break;
    }
    else if (i == N - 1) {
      cout << z(w.at(i)) <<endl;
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1000003 ;

int main(){
  int n;
  cin >> n;
  pint p[n];
  int ans=0;
  rep(i,n)cin >> p[i].first >> p[i].second;
  rep(i,n){
    rep(j,n){
      if(i==j)continue;
      int x=p[i].first-p[j].first;
      int y=p[i].second-p[j].second;
      int cnt=0;
      rep(k,n){
        rep(l,n){
          if(p[k].first-p[l].first==x && p[k].second-p[l].second==y)cnt++;
        }
      }
      ans=max(ans,cnt);
    }
  }
  cout << n-ans << endl;
return 0;}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int H;
		int W;

		while (true) {
			do {
				H = sc.nextInt();
				W = sc.nextInt();
			} while (H >= 300 && W >= 300);

			if (H == 0 && W == 0) {
				break;
			}
			for (int j = 0; j < H; j++) {
				for (int i = 0; i < W; i++){
					System.out.print("#");
				}
				System.out.print("\n");
			}

			System.out.print("\n");
		}
	}

}

Measured memory_bytes: 37300
N,x = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
for i in range(N-1):
    if a[i] > x:
        ans +=  a[i]-x
        a[i] = x
    if a[i] + a[i+1] > x:
        ans += a[i]+a[i+1]-x
        a[i+1] -= a[i]+a[i+1]-x
print(ans)
        

Measured memory_bytes: 63984
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    N = I()

    lucas = [0] * (N + 1)
    lucas[0] = 2
    lucas[1] = 1
    for i in range(N - 1):
        lucas[i+2] = lucas[i] + lucas[i+1]

    print(lucas[-1])

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9164
import math
n = int(input())
ans = 0
t_1, a_1 = map(int, input().split())
pret = t_1
prea = a_1
for x in range(n - 1):
    t, a = map(int, input().split())
    m = -min(-pret//t,-prea//a)
    pret = m * t
    prea = m * a
print(pret + prea)

Measured memory_bytes: 3064
btn = [None, ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"]
for t in range(input()):
    state = 0
    cnt = -1
    ans = ""
    for c in map(int, raw_input()):
        if c:
            cnt += 1
            state = c
        else:
            if state:
                tgt = btn[state]
                ans += tgt[cnt % len(tgt)]
            state = 0
            cnt = -1
    print ans

Measured memory_bytes: 6336
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
#define repi(i,a,b) for (int i=a;i<(b);i++)
#define SIZE_OF_ARRAY(a) (sizeof(a)/sizeof(a[0]))
using namespace std;
typedef long long ll;
  
  int main(void){
    cin.tie(0); //cin高速化
    ios::sync_with_stdio(false); //cin高速化
	int a,b,c,d;
    cin >> a >> b >> c >> d;
    int l = a+b;
    int r = c+d;
	if(l==r){
      cout << "Balanced"<<endl;
    }else if(l>r){
      cout << "Left" <<endl;
    }else{
      cout << "Right" <<endl;
    }
    return 0;
  } 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define x first
#define y second
#define pb push_back
#define pf push_front

using ll = long long;
using namespace std;

ll M = 1000000007;
typedef pair<int, int> P;
long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main()
{
    int n;
    cin >> n;
    vector<int> d(n);
    bool ok = true;
    rep(i, n)
    {
        cin >> d[i];
    }
    ok=d[0]==0;
    sort(all(d));
    int now = 0;
    int cnt = 0;
    deque<ll> len;
    ll ans = 1;
    int zero = 0;
    rep(i, n)
    {
        if (d[i] == 0)
        {
            zero++;
        }
        if (d[i] == now)
        {
            cnt++;
            if(i==n-1){
                len.push_back(cnt);
            }
        }
        else if (d[i] == now + 1)
        {
            len.push_back(cnt);
            cnt = 1;
            now = d[i];
            if(i==n-1){
                len.push_back(cnt);
            }
        }
        else
        {
            ok = false;
        }
    }
    ll mod = 998244353;
    
    if (zero != 1)
    {
        ok = false;
    }
    FOR(i, 1, len.size())
    {
        ans = ans * modpow(len[i - 1], len[i], mod);
        // cout<<modpow(len[i-1],len[i],mod)<<endl;
        ans %= mod;
        // cout<<ans<<endl;
    }
    if (ok)
    {
        cout << ans << endl;
    }
    else
    {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 1408
//by azidoazideazide(c2n14)
//D
#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
using ll=long long;
#define pb push_back

vector<int> adj[200005];
ll cnt[200005];
bool vis[200005];

int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n,t;
	cin>>n>>t;
	for(int i=1,a,b;i<=n-1;i++){
		cin>>a>>b;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	while(t--){
		int p,x;
		cin>>p>>x;
		cnt[p]+=x;
	}
	queue<int> q;
	q.emplace(1);
	while(!q.empty()){
		int from=q.front();
		q.pop();
		if(vis[from]) continue;
		vis[from]=1;
		
		for(int to:adj[from]){
			if(!vis[to]){
				cnt[to]+=cnt[from];
				q.emplace(to);
			}
		}
	}
	for(int i=1;i<=n;i++) cout<<cnt[i]<<' '; cout<<endl;
}


Measured memory_bytes: 16500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;

void solve(long long N, vector<long long> x, vector<long long> y){
	ll res = 1000;
	rep(i,N) {
		rep(j,N) {
			long long cx = x[i]-x[j], cy = y[i]-y[j];
			// cout << i << " " << j << " " << cx << " " << cy << endl;
			long long c = 0;
			rep(k,N) {
				rep(l,N) {
					if (k != l && x[k]-x[l] == cx && y[k]-y[l] == cy) c++;
				}
			}
			res = min(res, N-c);
		}
	}	
	cout << res << endl;
}

int main(){	
	long long N;
	scanf("%lld",&N);
	vector<long long> y(N-1+1);
	vector<long long> x(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&x[i]);
		scanf("%lld",&y[i]);
	}
	solve(N, x, y);
	return 0;
}



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

int main(){
  int n,m;
  cin >> n >> m;
  vector<vector<int>> jobs(m);
  for(int i = 0; i < n ; i++)
  {
    int a, b;
    cin >> a >> b;
    if(a > m) continue;
    jobs[m-a].push_back(b);//M-a日目までに行えば報酬をもらえる
  }

  long long ans = 0;
  priority_queue<int> q;
  for(int i = m-1;i >= 0; i--){
    for(auto& p : jobs[i]){
      q.push(p);
    }
    if(!q.empty()){
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
  return 0;
}

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


N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input().rstrip()

dp = [[0, 0, 0] for _ in range(N)]

for i in range(K):
    Q = T[i]
    if Q == "s":
        dp[i][0] = R
    elif Q == "p":
        dp[i][1] = S
    else:
        dp[i][2] = P

for i in range(K, N):
    Q = T[i]
    if Q == "s":
        dp[i][0] = max(dp[i-K][1], dp[i-K][2]) + R
        dp[i][1] = max(dp[i-K][0], dp[i-K][2])
        dp[i][2] = max(dp[i-K][0], dp[i-K][1])
    elif Q == "p":
        dp[i][0] = max(dp[i-K][1], dp[i-K][2])
        dp[i][1] = max(dp[i-K][0], dp[i-K][2]) + S
        dp[i][2] = max(dp[i-K][0], dp[i-K][1])
    else:
        dp[i][0] = max(dp[i-K][1], dp[i-K][2])
        dp[i][1] = max(dp[i-K][0], dp[i-K][2])
        dp[i][2] = max(dp[i-K][0], dp[i-K][1]) + P

ans = 0
for i in range(K):
    ans += max(dp[-1-i])
print(ans)

Measured memory_bytes: 60208
#include <bits/stdc++.h>
using namespace std;
//for(int i = 0; i < n; i++)
 
int main() {
  int a, b, ans = 0;
  double pi = 3.141592653589793238462, x, haba;
  long long n;
  string s;
  cin >> a >> b >> x;
  //vector<int> v(n), c(n);
  if(x >= a * a * b / 2.00000000) {
    haba = (a * b * a - x) / a / a * 2;
    printf("%.10f\n", 90.0000 - atan(a / haba) * 180.000 / pi);
  }
  else {
    haba = x / a / b * 2;
    printf("%.10f\n", atan(b / haba) * 180.000 / pi);
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int a, b, c, tmt;

    scanf ("%d %d %d", &a, &b, &c);

    if (a > b) {
        tmt = a;
        a = b;
        b = tmt;
    }
    if (b > c) {
        tmt = b;
        b = c;
        c = tmt;
    }
    if (a > b) {
        tmt = a;
        a = b;
        b = tmt;
    }

    printf ("%d %d %d\n", a, b, c);
        

    return 0;
}


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

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) (a).begin(),(a).end()

template<typename T1, typename T2> inline void chkmin(T1 & x, const T2 & y) {if (y < x) x = y;}
template<typename T1, typename T2> inline void chkmax(T1 & x, const T2 & y) {if (x < y) x = y;}

const int MOD = 1e9 + 7;

void add(int &a, int b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

int n;

void read() {
    cin >> n;
}

const int N = 2010;
int dp[N];

void run() {
    dp[0] = 1;
    for (int sum = 1; sum <= n; ++sum) {
        for (int val = 3; val <= sum; ++val) {
            add(dp[sum], dp[sum - val]);
        }
    }
}

void write() {
    cout << dp[n] << endl;
}

signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(20), cout.setf(ios::fixed);
    read();
    run();
    write();
    return 0;
}

Measured memory_bytes: 3652