akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
#define mod 998244353
#define maxn 200010
#define LL long long
using namespace std;
LL fact[maxn],inv[maxn],ans,t[maxn],p;
int n,m,k,nm;
LL quick_pow(LL a,LL b){
	LL ans=1;
	while(b){
		if(b&1)ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans%mod;
}
void init(){
	int i;
	scanf("%d%d%d",&n,&m,&k);
	nm=n,nm=max(nm,m),fact[0]=1;
	for(i=1;i<=nm;i++)fact[i]=fact[i-1]*i%mod;
	inv[nm]=quick_pow(fact[nm],mod-2);
	for(i=nm-1;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;
}
LL C(LL a,LL b){
	return fact[a]*inv[a-b]%mod*inv[b]%mod;
}
int main(){
	int i;
	init();
	ans=0,p=quick_pow(m-1,n-k-1);
	for(i=n-k;i<=n;i++){
		ans=(ans+m*p%mod*C(n-1,i-1)%mod)%mod;
		p=p*(m-1)%mod;
	}
	printf("%lld\n",ans);
	return 0;
}

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

void a(){
    ll a,b,c;
    cin >> a >>b >>c;
    cout << (a==b&&b==c?"No":
             a==b?"Yes":
             a==c?"Yes":
             b==c?"Yes":"No");
}
void b(){
    ll n; cin >> n;
    auto a = vector<ll>(n,0);
    bool f=true;
    rep(i,n) {
        cin >> a[i];
        if(a[i]%2==0){
            if(a[i]%5==0||a[i]%3==0) continue;
        }else continue;
        f = false;
        break;
    }
    cout << (f?"APPROVED":"DENIED");
}

void c(){
    ll n; cin >> n;
    map<string,ll> s;
    rep(i,n) {
        string t; cin >> t;
        s[t]++;
    }
    auto ans = vector<string>();
    ll _max = 0;
    for(auto i: s) _max = max(_max,i.second);
    for(auto i: s){
        if(i.second == _max) ans.push_back(i.first);
    }
    copy(ans.begin(),ans.end(),ostream_iterator<string>(cout,"\n"));
}

int main(){
    c();
    return 0;
}

Measured memory_bytes: 26868
@A=glob<>;@l=<>;printf sort{$a-$b}map{$x=@v=$T=$_;$v[$T&3]+=$_,$x+=$T&3&&10,$T/=4for@l;$x+=abs$A[$_]-($v[$_]||1e9)for 1..3;$x-31}1..1e5

Measured memory_bytes: 8704
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int[][] dist = new int[n][n];
        long sum = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                dist[i][j] = scanner.nextInt();
                sum += dist[i][j];
            }
        }
        sum /= 2;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                for (int k = 0; k < n; k++) {
                    if (dist[j][k] > dist[j][i] + dist[i][k]) {
                        System.out.println(-1);
                        return;
                    }
                }
            }
        }
        for (int i = 1; i < n; i++) {
            for (int j = 0; j < i; j++) {
                for (int k = 0; k < n; k++) {
                    if (i != k && j != k && dist[i][j] == dist[i][k] + dist[k][j]) {
                        sum -= dist[i][j];
                        break;
                    }
                }
            }
        }
        System.out.println(sum);
    }
}

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

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

	if (s.at(0) == s.at(1) && s.at(1) != s.at(2) && s.at(2) == s.at(3)) cout << "Yes" << endl;
	else if (s.at(0) == s.at(2) && s.at(1) != s.at(2) && s.at(1) == s.at(3)) cout << "Yes" << endl;
	else if (s.at(0) == s.at(3) && s.at(1) != s.at(3) && s.at(1) == s.at(2)) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
n=int(input())
a,b=map(int, input().split())
h = list(map(int, input().split())) 

k=[]
minsa=10000000
for i in range(n):
  sa= abs(a-h[i]*0.006-b)
  minsa=(min(sa,minsa))
  k.append(sa)
print(k.index(minsa)+1)

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

int main(void)
{
    int n,m,i,val;
    cin>>n>>m;
    long long sum = 0;
    for(i = 0; i < m; i++)
    {
        cin>>val;
        sum = sum + val;
    }
    if(sum > n)
        cout<<-1<<endl;
    else
        cout<<n-sum<<endl;

    return 0;
}


Measured memory_bytes: 3636
/* C - Multiplication 3 */

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

int ten_times(int n){
  if(n == 0){
    return 1;
  }else{
    return 10 * ten_times(n - 1);
  }
}

int main(){
  long long A;
  string B, str;
  int num = 0;
  cin >> A >> B;
  for(int i = 0; i < B.size(); i++){
    if(B.at(i) != '.'){
      str += B.at(i);
    }
  }
  int len = str.size();
  for(int i = 0; i < len; i++){
    num += (str.at(i) - '0') * ten_times(len - 1 - i);
  }
  cout << A * num / 100 << endl;
}


Measured memory_bytes: 3640
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
  vector<ll>to[1000005];
int main(){
  ll a;cin>>a;
  cout<<a+a*a+a*a*a;
}


Measured memory_bytes: 27068
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    X = I()
    c = 100
    cnt = 0
    while c < X:
        c *= 1.01
        c = int(c)
        cnt += 1
    print(cnt)

main()



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

int main() {
  int N;
  cin >> N;
  string ans="No";
  for (int i=1; i<10; i++) {
    if (N%i!=0) {continue;}
    if ((N/i)/10==0) {
      ans = "Yes";
      break;
    }
  }
  cout << ans << endl;
}

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

class Program
{
    static void Main(string[] args)
    {
        int[] arrMoto = Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
        int n = arrMoto[0];
        int x = arrMoto[1];
        int y = arrMoto[2];
        int[] ansArr = new int[n - 1];
        int number = 0;
        int start = 1;
        while(start < n)
        {
            int end = start + 1;
            while(end <= n)
            {
                //if (start <= x && y <= end) number = x - start + end - y + 1;
                //else if ((start > x && y > end) || end <= x || start >= y) number = end - start;
                //else number = Math.Min(end - start, Math.Abs(x - start) + Math.Abs(y - end) + 1);    
                number = Math.Min(end - start, Math.Abs(x - start) + Math.Abs(y - end) + 1);
                ansArr[number - 1]++;
                end++;
            }
            start++;
        }
        foreach (int i in ansArr) Console.WriteLine(i);

    }


  

}



Measured memory_bytes: 13396
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

bool isTriangle(ll a,ll b,ll c){
  if(c<a+b)return true;
  else return false;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N;
  cin>>N;
  vi L(N);
  REP(i,N) cin >> L[i];
  sort(ALL(L));
  vll num(N);
  num[0]=0;
  num[1]=0;
  if(isTriangle(L[0],L[1],L[2]))num[2]=1;
  else num[2] = 0;
  REP2(i,3,N){
    ll count = 0;
    REP2(j,1,i)REP(k,j){
      if(isTriangle(L[k],L[j],L[i]))count++;
    }
    num[i]=num[i-1]+count;
  }
  cout<<num[N-1];
  return 0;
}

Measured memory_bytes: 256
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];
ll x[10];
ll y[10];

int main()
{
    char ch;cin>>ch;
    if(ch=='A')cout<<"T"<<endl;
    else if(ch=='C')cout<<"G"<<endl;
    else if(ch=='G')cout<<"C"<<endl;
    else cout<<"A"<<endl;
return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second

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

signed main(){
	int a,b,c,n,sum=0;
	cin>>a>>b>>c>>n;
	r(i,3001){
		r(j,3001){
			int k=n-i*a-j*b;
			if(k<0)continue;
			if(k%c==0)sum++;
		}
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
ll countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}


int main() {
	IOS;
	bool used[26];
	MEM(used, false);
	string s;
	cin >> s;
	bool ans = true;
	REP(i, s.size()) {
		int x = s[i] - 'a';
		if (used[x]) {
			ans = false;
			break;
		}
		used[x] = true;
	}

	cout << (ans ? "yes" : "no") << endl;
}



Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <cfenv>
#include <cinttypes>
#include <cstdint>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <forward_list>
#include <initializer_list>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#if __cplusplus >= 201402L
#include <shared_mutex>
#endif

#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;

const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};

int main(){
    int l,r,d;
    cin >> l >> r >> d;
    int sum = 0;
    sum += r/d;
    sum -= (l-1)/d;
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 3184
H=int(input())+1
A=[0]+list(map(int,input().split()))
def h(i):
 l=2*i;r=l+1
 g=i
 if l<H and A[i]<A[l]:g=l
 if r<H and A[g]<A[r]:g=r
 if g>i:A[i],A[g]=A[g],A[i];h(g)
for i in range(H//2,0,-1):h(i)
print(' '+' '.join(map(str,A[1:])))


Measured memory_bytes: 64176
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
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
#import numpy as np
#from decimal import *

N, x = MAP()
a = LIST()
ans = max(0, a[0]-x)
a[0] = min(a[0], x)

for i in range(1, N):
	ans += max(0, a[i]+a[i-1]-x)
	a[i] = min(a[i], x - a[i-1])

print(ans)

Measured memory_bytes: 16228
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Int int32_t
#define all(c) c.begin(), c.end()
#define FAST ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define bitcnt(n) __builtin_popcountll(n)
#define setpre(n) cout << fixed << setprecision(n)
#define tr(c) for(const auto& x : c )cout << x << " "; cout << "\n";
#define ol(c, s, e) for(int pos=s; pos<e; pos++)cout << c[pos] << " ";cout <<"\n";
#define PI acos(-1LL)

const int M = 1000000007;
const int N = 2e5 + 5;
const long long INF = 1e9 + 12;

int H, W;
int dp[1001][1001];
char s[1001][1001];

int fun(int i, int j){
    if(i > H || j > W)
        return 0;
    if(i==H && j == W)
        return 1;
    if(dp[i][j]!=-1)
        return dp[i][j];
    if(s[i][j] == '#')
        return 0;
    return dp[i][j] = (fun(i+1,j) + fun(i, j+1))%M;
}
void solve(){
    cin >> H >> W;
    memset(dp, -1, sizeof dp);
    for(int i=1;i<=H; i++){
        for(int j=1; j<=W; j++){
            cin >> s[i][j];
        }
    }
    cout << fun(1,1)%M;
}

signed main(){
    FAST
    int tc = 1;
//    TODO: check for tc
//    cin >> tc;
    for (int t = 1; t <= tc; t++) {
        solve();
    }
}


Measured memory_bytes: 12536
#abc089c

n=int(raw_input())
m=a=r=c=h=0
for i in xrange(n):
 temp=raw_input()
 if temp[0]=='M':
  m+=1
 elif temp[0]=='A':
  a+=1
 elif temp[0]=='R':
  r+=1
 elif temp[0]=='C':
  c+=1
 elif temp[0]=='H':
  h+=1
s=[m,a,r,c,h]
res=0
for i in xrange(5):
 for j in xrange(i):
  for k in xrange(j):
   res+=s[i]*s[j]*s[k]
print res


Measured memory_bytes: 2568
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define ll long long
#define pi 3.1415926535897
using namespace std;
void put(int x){
	if(x<0) {
		putchar('-');
		x*=-1;
	}
	if(x==0) {
		putchar('0');
	}
	int num=0;
	char c[15];
	while(x) {
		c[++num]=(x%10)+48;
		x/=10;
	}
	while(num) {
		putchar(c[num--]);
	}
	putchar('\n');
}
inline void in(int &x){
	char ch=getchar();
	int flag=1;
	while(!(ch>='0'&&ch<='9')) {
		if(ch=='-')
			flag*=-1;
		ch=getchar();
	}
	x=ch-'0';
	ch=getchar();
	while(ch>='0'&&ch<='9') {
		x=((x<<3)+(x<<1))+ch-'0';
		ch=getchar();
	}
	x*=flag;
}
int a,b,h,m;double k,km,kh,ans,kk;
int main(){
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	in(a);in(b);in(h);in(m);
	kh=30.0*h;km=6.0*m;kh+=m/60.0*30;
	if(kh<km){
		int t=km;km=kh;kh=t;
	}
	k=kh-km;kk=360.0-k;
	if(k>kk)k=kk;
	k=k/180.0*pi;
//	printf("%.2lf %.2lf %.2lf %.2lf\n",k,km,kh,cos (k));
	ans=sqrt(a*a+b*b-2*a*b*cos(k));
	printf("%.10lf\n",ans);
	return 0;
}

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

int main() {
	int x, y, s;
	while(cin >> x >> y >> s && (x || y || s)){
		int ans = 0;
		for(int i = 1; i <= s; ++i){
			for(int j = 1; j <= s; ++j){
				if(i * (100 + x) / 100 + j * (100 + x) / 100 == s)
					ans = max(ans, i * (100 + y) / 100 + j * (100 + y) / 100);
				if(i * (100 + x) / 100 + j * (100 + x) / 100 > s)
					break;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

using namespace std;

//#define MD 10

int main(){
    string s;
    cin>>s;
    int ans=0;
    char flag='B';
    if(s[0]=='W'){
        flag='W';
    }
    
    for(int i=1;i<s.length();i++){
        if(flag!=s[i]){
            ans++;
            flag=s[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int H, W;
    string t;
    vector<string> M;
    cin >> H >> W;
    for (int i=0; i<H; ++i) {
        cin >> t;
        M.emplace_back(t);
    }
    
    for (int y=0; y<H; ++y) {
        string s;
        for (int x=0; x<W; ++x) {
            if (M[y][x] == '#') {
                s += "#";
                continue;
            }
            int b = 0;
            for (int py = max(y-1, 0); py < min(y+2, H); ++py) {
                for (int px = max(x-1, 0); px < min(x+2, W); ++px) {
                    if (M[py][px] == '#') { b += 1; }
                }
            }
            s += to_string(b);
        }
        cout << s << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define debug(x) cerr << #x << ':' << x << endl
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> A(n+1,0LL), B(n,0LL);
    REP(i,n+1) cin >> A[i];
    REP(i,n) cin >> B[i];

    ll cnt = 0LL;
    for(int i=0; i<=n-1; i++){
        // cout << "B[i]" << B[i] << endl;
        if(B[i]>=A[i]){
            cnt+=A[i];
            B[i]-=A[i];
            A[i]=0;
            if(B[i]>=A[i+1]){
                cnt+=A[i+1];
                B[i]-=A[i+1];
                A[i+1] = 0;
            }
            else{
                cnt+=B[i];
                A[i+1] -= B[i];
                B[i]=0;
            }
        }
        else{
            cnt+=B[i];
            A[i]-=B[i];
            B[i]=0;
        }
        // cout << cnt << endl;
    }
    // REP(i,n+1) cout << A[i] << " ";
    // cout << endl;
    // REP(i,n) cout << B[i] << " ";
    // cout << endl;
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1792
// practice with kaiboy
import java.io.*;
import java.util.*;

public class Main extends PrintWriter {
	Main() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	}

	static final int MD = 1000000007;
	void main() {
		int n = sc.nextInt();
		int k = sc.nextInt();
		if (n == 1) {
			println(k);
			return;
		}
		int[] dd = new int[n];
		long ans = (long) k * (k - 1) % MD;
		while (--n > 0) {
			int i = sc.nextInt() - 1;
			int j = sc.nextInt() - 1;
			if (++dd[i] >= 2)
				ans = ans * (k - dd[i]) % MD;
			if (++dd[j] >= 2)
				ans = ans * (k - dd[j]) % MD;
		}
		println(ans);
	}
}


Measured memory_bytes: 59692
from fractions import gcd
a,b,c,d=map(int,input().split())
lcm=int(c*d/gcd(c,d))
A=a-1
x1=A-A//c-A//d+A//lcm
x2=b-b//c-b//d+b//lcm
print(x2-x1)

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

typedef long long ll;

const ll mod = 1000000007;

int main() {
    int H, W;
    int A;
    cin >> H >> W;
    int c[10][10];
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> c[i][j];
        }
    }

    for (int k = 0; k < 10; k++) {
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                c[i][j] = min(c[i][j], c[i][k]+c[k][j]);
            }
        }
    }
    
    int ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> A;
            if (A >= 0) {
                ans += c[A][1];
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,a,k,ans;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>k;
	for (int i=1;i<=n;++i)
	{
		cin>>a;
		if (a>=k) ++ans;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
////////////////package Educ_DP;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int a=s.nextInt();
        s.nextLine();
        int[][] dp=new int[a][3];
        for (int i=0;i<a;i++){
            String[] l=s.nextLine().split(" ");
            int[] list=new int[3];
            for (int j=0;j<3;j++){
                list[j]=Integer.parseInt(l[j]);

            }
            if (i==0){
                for (int j=0;j<3;j++){
                    dp[i][j]=list[j];
                }
            }
            else{
                for (int j=0;j<3;j++){
                    for (int k=0;k<3;k++){
                        if (j!=k){
                            dp[i][j]=Math.max(dp[i][j],dp[i-1][k]+list[j]);
                        }
                    }
                }
            }
        }
        int x=dp[dp.length-1][0];
        int y=Math.max(dp[dp.length-1][1],dp[dp.length-1][2]);
        System.out.println(Math.max(x,y));
    }
}


Measured memory_bytes: 69936
#include<bits/stdc++.h>
#include<climits>
 
using namespace std;
 
#define debug(x,y) cout<<(#x)<<" " <<(#y)<<" is " << (x) <<" "<< (y) << endl
#define watch(x) cout<<(#x)<<" is " << (x) << endl
#define fast ios_base::sync_with_stdio(false)
#define fie(i,a,b) for(i=a;i<b;i++)
#define MOD 1000000007
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define ll long long
#define lld long long int
#define ALL(x) (x).begin(),(x).end()
 
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<pair<int,int>> vpi;
typedef long long LL;
 
const long long OO = 2e18;
const double pi=2*acos(0.0);
 
bool isprime(long long int a){
    if(a==1){
        return false;
    }
    for(int i=2;i*i<=a;i++){
        if(a%i==0){
            return false;
        }
    }
    return true;
} 
 
bool iscoprime(int a,int b){
    int i;
    for(i=2;i<=min(a,b);i++){
        if(a%i==0 && b%i==0){
            return false;
        }
    }
    return true;
}
 
ll gcd(ll a,ll b){
    if(b==0){
        return a;
    }
    else{
        return gcd(b,a%b);
    }
}
 
int maxA(vi a){
    int m=0;
    for(int i=0;i<a.size();i++){
        m=max(m,a[i]);
    }
    return m;
}
 
int minA(vi a){
    int m=100000;
    for(int i=0;i<a.size();i++){
        m=min(m,a[i]);
    }
    return m;
}
 
vi freqN(vi a, int n){
    vi f(n);
    f={0};
    for(int i=0;i<a.size();i++){
        f[a[i]]++;
    }
    return f;
}
 
vi freqA(vi a){
    vi f(26);
    f={0};
    for(int i=0;i<a.size();i++){
        f[a[i]-'0']++;
    }
    return f;
}
 
bool mycomp(const pair<long int,long int>&p1 , const pair<long int,long int>&p2){
    if(p1.second < p2.second) return true;
    else if(p1.second==p2.second) return p1.first<p2.first;
    else return false;
}
 
unsigned int rightmostsetbit(unsigned int n){
    return n & -n;
}
 
bool cmp(pair<lld,lld>&p1 , pair<lld,lld>&p2){
    if((p1.first*p1.second)==(p2.first*p2.second)) return p1.second>p2.second;
    return (p1.first*p1.second)>(p2.first*p2.second);
}
 
int main(){
fast;
cin.tie(0);
lld n,k,i;
cin>>n>>k;
double a[n];
for(lld i=0;i<n;i++){
    cin>>a[i];
    a[i]=(double)((a[i]+1)/2);
}
double sum=0;
double ans=INT_MIN;
for(i=0;i<k;i++){
    sum+=a[i];
}
ans=sum;
lld z=0;
for(i=k;i<n;i++){
    sum+=(a[i]-a[z]);
    z++;
    ans=max(ans,sum);
}
printf("%.12lf\n",ans);
}

Measured memory_bytes: 1920
class Point
  attr_accessor :t, :x, :y
  def initialize(t, x, y)
    @t = t
    @x = x
    @y = y
  end

  def traveling?(p)
    time = p.t - self.t
    mdist = self.mdist(p)
    mdist <= time && (time - mdist).even?
  end

  def mdist(p)
    (self.x - p.x).abs + (self.y - p.y).abs
  end

  def to_s
    "(#{@t},#{@x},#{@y})"
  end
end

N = gets.to_i
plan = [Point.new(0,0,0)]
N.times do
  plan.push(Point.new(*gets.split(' ').map(&:to_i)))
end


plan.each_cons(2) do |a,b|
  unless a.traveling?(b)
    puts 'No'
    exit
  end
end
puts 'Yes'

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

using namespace std;
#define ll long long
const int mod=998244353;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n,k,cnt=0;
    cin>>n>>k;
    while(n) n/=k,cnt++;
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
using lint=long long;
using ld=long double;
template<class T>using numr=std::numeric_limits<T>;
struct input_t{template<class T>operator T(){T t;std::cin>>t;return t;}}input;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint x,y;std::cin>>x>>y;
    std::cout<<(x>y?"safe":"unsafe")<<'\n';
}


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

using namespace std;

#define rip(i,n,s) for (int i=(s);i<(int)(n);i++)
#define all(a) (a).begin(),(a).end()
typedef long long ll;

int main(){
    //cout << "Hello, World!" << endl;
    int n;
    cin >> n;
    vector<int> da(n);
    rip(i,n,0){
        cin >> da[i];
        //cout << i << endl;
    }
    int x=*--da.end();
    int k=-1;
    rip(j,n-1,0){
        //cout << j << endl;
        if(da[j]<=x){
            k++;
            swap(da[k],da[j]);
        }
    }
    swap(da[k+1],da[n-1]);
    int ans=k+1;
    rip(i,n,0){
        if(i==ans){
            cout << '[' << da[i] << ']';
        }else{
            cout << da[i];
        }
        if(i==n-1){
            cout << endl;
        }else{
            cout << ' ';
        }
    }
}


Measured memory_bytes: 3136
#include<stdio.h>
int main(void){
    int n;
    scanf("%d",&n);
    int a[n],i,j=0;
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    int cnt1=0,cnt2=0,cnt3=0;
    for(i=0;i<n;i++){
        if(a[i]%2 == 0 && (a[i]%3 != 0 && a[i]%5 != 0)){
            cnt1++;
        }
    }
        if(cnt1)
        puts("DENIED");
        else
        puts("APPROVED");
        return 0;
    }

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define puts(x) cout << x << "\n"
constexpr int mod = 1000000007;
using namespace std;
int d, c[30], l[30], s[400][30];
signed main() {
	cin >> d;
	for1(i, 26)cin >> c[i];
	for1(i, d)for1(j, 26)cin >> s[i][j];
	for1(i, d) {
		int p = 0, k = -mod;
		for1(j, 26) {
			int kj = s[i][j] + c[j] * (i - l[j]) * 1.20;
			if (kj > k) { p = j; k = kj; }
			else if (kj == k && c[j] > c[p])p = j;
		}
		puts(p); l[p] = i;
	}
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

int main(){
  ll N;
  cin >> N;
  vvll A(N, vll(N));
  ll sum = 0;
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      cin >> A.at(i).at(j);
      sum += A.at(i).at(j);
    }
  }
  sum /= 2;
  bool flag = true;
  ll extra = 0;
  vector<vector<bool>> extraflag(N, vector<bool>(N, true));
  for(int k = 0; k < N; k++){
    for(int i = 0; i < N; i++){
      for(int j = 0; j < N; j++){
        if(k == i || k == j) continue;
        if(extraflag.at(i).at(j) && A.at(i).at(j) == A.at(i).at(k) + A.at(k).at(j)){
          extra += A.at(i).at(j);
          extraflag.at(i).at(j) = false;
        }
        if(A.at(i).at(j) > A.at(i).at(k) + A.at(k).at(j)) flag = false;
      }
    }
  }
  if(!flag) cout << -1 << endl;
  else cout << sum - extra/2 << endl;
}

Measured memory_bytes: 1024
Scanf.scanf "%d" @@ fun n ->
  let a = Array.init n (fun _ -> Scanf.scanf " %d" ((+) 0)) in
  Array.fold_left (fun (z, (y, s)) x ->
    if s = 0 then if x = y then z, (x, 0) else z, (x, (x-y))
    else if s * (x-y) < 0 then z+1, (x, 0) else z, (x, s)) (1, (a.(0), 0)) a
  |> fst |> Printf.printf "%d\n"

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {

    int a, b, c, x, y; cin >> a >> b >> c >> x >> y;

    int ans = 0;
    if (a + b <= 2 * c) {
        ans = x * a + y * b;
    }
    else { // 2 * c < a + b
        
        if (x <= y) {
            ans += 2 * c * x;
            y -= x;
            ans += y * min(b, 2 * c);
        }
        else {
            ans += 2 * c * y;
            x -= y;
            ans += x * min(a, 2 * c);
        }

    }

    cout << ans << endl;
    return 0;
}

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

int main()
{
	string S;
	int a=0;
	int total = 0;
	cin >> S;
	if (S[0] == 'o') ++a;
	if (S[1] == 'o') ++a;
	if (S[2] == 'o') ++a;
	total = 700 + a * 100;
	
	cout << total;
}

Measured memory_bytes: 256
import heapq
x, y, z, K = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse = True)
b = sorted(list(map(int, input().split())), reverse = True)
c = sorted(list(map(int, input().split())), reverse = True)
heap = []
for i in range(min(x, K)):
    for j in range(min(y, K//(i+1) + 1)):
        for k in range(min(z, K//((i+1)*(j+1)) + 1)):
            heapq.heappush(heap, - a[i] - b[j] - c[k])
for a in heapq.nsmallest(K, heap):
    print(-a)

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

int main() {
    string S; cin >> S;
    int a; cin >> a;

    rep(i, a){
        string q; cin >> q;
        if (q == "print"){
            int x, y; cin >> x >> y;
            string ou = S.substr(x, y - x + 1);
            cout << ou << endl;
        }

        if (q == "replace"){
            int x, y; cin >> x >> y;
            string z; cin >> z;
            S.replace(x, y - x + 1, z);
        }

        if (q == "reverse"){
            int x, y; cin >> x >> y;
            string copy = S.substr(x, y - x + 1);
            reverse(copy.begin(), copy.end());
            S.replace(x, y - x + 1, copy);
        }
    }
    return 0;
}


Measured memory_bytes: 3216
#include <cmath>
#include <iostream>
#include <string>

using namespace std;

typedef long long ll;

int sum(int x)
{
    ll sum = x % 10;
    while (true) {
        x /= 10;
        sum += x % 10;
        if (x < 10) {
            break;
        }
    }
    return sum;
}

int main()
{
    ll N;
    cin >> N;
    if (N % sum(N) == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N (100009)
#define LL long long
using namespace std;

LL n,a[N],f[N][3];
char opt[N][2];

int main()
{
	cin>>n;
	for (int i=1; i<n; ++i)
		cin>>a[i]>>opt[i];
	cin>>a[n];
	f[1][0]=a[1]; f[1][1]=f[1][2]=-1e18;
	for (int i=2; i<=n; ++i)
		if (opt[i-1][0]=='+')
		{
			f[i][0]=max(f[i-1][0],f[i-1][1])+a[i];
			f[i][1]=f[i-1][1]-a[i];
			f[i][2]=f[i-1][2]+a[i];
		}
		else
		{
			f[i][0]=-1e18;
			f[i][1]=max(f[i-1][0],f[i-1][1])-a[i];
			f[i][2]=max(f[i-1][1],f[i-1][2])+a[i];
		}
	cout<<max(f[n][0],max(f[n][1],f[n][2]))<<endl;
}


Measured memory_bytes: 3584
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		sc.close();

		for (int i = 0; i < s.length(); i++) {
			char ch = s.charAt(i);
			int x = ch - 'A';
			x += n;
			x %= 26;
			ch = (char) ('A' + x);
			System.out.print(ch);
		}
		System.out.println();
	}
}


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

#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;
typedef long long ll;

int main(){

    double r;
    cin >> r;

    cout << 2.0 * r * PI << endl;
    
    return 0;
}


Measured memory_bytes: 3788
use proconio::input;

fn main() {
    input! {
        a: [u64]
    }
    let ans = a.iter().fold(1u64, |x, y| x.saturating_mul(*y));
    if ans <= 1_000_000_000_000_000_000 {
        println!("{}", ans);
    } else {
        println!("-1");
    }
}

Measured memory_bytes: 4560
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int N, K;
	cin >> N >> K;

	long long ans = 0;
	for (int b = 1; b <= N; ++b) {
		int q = N / b;
		int r = N % b;
		if (b > K) {
			ans += q * (b - K);
		}
		if (r >= K) {
			ans += r - K + 1;
		}
	}
	if (K == 0) {
		ans -= N;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <bitset>
#include <string>
#include <array>
#include <random>
#include <chrono>
#include <algorithm>
#include <unordered_map>

int main(void){
	int n;
	std::cin >> n;
	std::vector<int> d(n);
	for(int i=0;i<n;i++)std::cin >> d[i];
	std::sort(d.begin(), d.end());
	std::cout << d[n / 2] - d[n / 2 - 1] << std::endl;
}

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

int main(){
    char suit[4] = {'S','H','C','D'};  //char型は1文字のみ格納可能
    vector<vector<bool> > m(4,vector<bool>(13,true));   //初期値がtrue
    int n;
    cin >> n;
    for(int i=0; i<n; i++){
        char c;
        int j;
        cin >> c >> j;
        switch(c){
            case 'S': m[0][j-1] = false; break; //cがSと一致すれば0行目のj-1列目相当のカードは手札にあるということでfalse
            case 'H': m[1][j-1] = false; break;
            case 'C': m[2][j-1] = false; break;
            case 'D': m[3][j-1] = false; break;
        }
    }

    for(int i=0; i<4; i++){
        for(int j=0; j<13; j++){
            if(m[i][j]) cout << suit[i] << " " << j+1 << endl;
        }
    }
    
    return 0;
}


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

using namespace std;

int N;

int main() {
	cin >> N;
	vector<int> d(N);
	for (int i = 0; i < N; i++) { cin >> d[i]; }
	sort(d.begin(), d.end());

	int right = d[N / 2];
	int left = d[N / 2 - 1];

	if (right == left) { cout << 0 << endl; }
	else { cout << right - left << endl; }

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
using vvll = vector<vector<long long>>;
using pii = pair<int, int>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define reps(i,n) for(int i = 1; i <= (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define rreps(i,n) for(int i = (int)(n); i > 0; i--)
#define FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define RFOR(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define call(x) (x).cbegin(), (x).cend()
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
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 (b<a) {a=b; return 1;} return 0;}
const int INF = INT_MAX;
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};

double dp[310][310][310];
int N;

double func(int i, int j, int k) {
    if (dp[i][j][k] >= 0) return dp[i][j][k];
    if (i==0 && j==0 && k==0) return 0.0;
    double res = 0.0;
    if (i > 0) res += func(i-1, j, k) * i;
    if (j > 0) res += func(i+1, j-1, k) * j;
    if (k > 0) res += func(i, j+1, k-1) * k;
    res += N;
    res *= 1.0/(i+j+k);
    return dp[i][j][k] = res;

}

void solve(int N, int one, int two, int three){
    memset(dp, -1, sizeof(dp));
    cout << fixed << setprecision(10) << func(one, two, three) << endl;
}

int main(){
    cin >> N;
    int one = 0, two = 0, three = 0;
    for(int i = 0 ; i < N ; i++){
        int a;
        cin >> a;
        if (a == 1) one++;
        if (a == 2) two++;
        if (a == 3) three++;
    }
    solve(N, one, two, three);
    return 0;
}



// // 入力
// int N;

// // DP テーブル
// double dp[310][310][310];
// double rec(int i, int j, int k) {
//     if (dp[i][j][k] >= 0) return dp[i][j][k];
//     if (i == 0 && j == 0 && k == 0) return 0.0;

//     double res = 0.0;
//     if (i > 0) res += rec(i-1, j, k) * i;
//     if (j > 0) res += rec(i+1, j-1, k) * j;
//     if (k > 0) res += rec(i, j+1, k-1) * k;
//     res += N;
//     res *= 1.0 / (i + j + k);

//     return dp[i][j][k] = res;
// }

// int main() {
//     cin >> N;
//     int one = 0, two = 0, three = 0;
//     for (int i = 0; i < N; ++i) {
//         int a; cin >> a;
//         if (a == 1) ++one;
//         else if (a == 2) ++two;
//         else ++three;
//     }

//     // 初期化
//     memset(dp, -1, sizeof(dp));

//     // 答え
//     cout << fixed << setprecision(10) << rec(one, two, three) << endl;
// }

Measured memory_bytes: 233088
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond, yes, no) \
    { cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond&& mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())
    is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a) n = a;
    if (n > b) n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

std::vector<int> enum_div(int n) {
    std::vector<int> ret;
    for (int i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i != 1 && i * i != n) { ret.push_back(n / i); }
        }
    }
    return ret;
}

template <typename T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

struct ToUpper {
    char operator()(char c) {
        return toupper(c);
    }
};

struct ToLower {
    char operator()(char c) {
        return tolower(c);
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> A(N);
    cin >> A;

    SORT(A);
    ll ans = 0;
    int i = 0;
    while (M > 0) {
        int c = A[i].second;
        chmin(c, M);
        M -= c;
        ans += (ll)c * A[i].first;
        i++;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define LL long long
#define clr(x,i) memset(x,i,sizeof(x))
using namespace std;
const int N=200005;
const LL mo=1e9+7;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
struct Edge{
	int to,nex; LL w;
}e[N*4];
int n,m,s,t,head[N],vis[N],tot,id[N];
LL ds[N],dt[N],fs[N],ft[N],g[N];
inline void ade(int u,int v,LL w)
{e[++tot]=(Edge){v,head[u],w};head[u]=tot;}
inline void add(int &x,int y)
{
	x+=y; if(x>mo) x-=mo;
}
inline LL sqr(LL x)
{
	return x*x%mo;
}
int cmp(int x,int y)
{
	return g[x]<g[y];
}
void spfa(int s,LL *dist,LL *f)
{
	queue<int> q; q.push(s);
	for(int i=0;i<=n;i++) dist[i]=1e15,id[i]=i;
	clr(vis,0); dist[s]=0; vis[s]=f[s]=1;
	//for(int i=1;i<=n;i++) cout<<dist[i]<<' '; cout<<endl;
	while(!q.empty()){
		int u=q.front(); q.pop(); vis[u]=0;
		for(int i=head[u];i;i=e[i].nex){
			int v=e[i].to; LL w=e[i].w;
			if(dist[v]>dist[u]+w){
				dist[v]=dist[u]+w;
				if(!vis[v])
				  vis[v]=1,q.push(v);
			}
		}
	}
	for(int i=1;i<=n;i++) g[i]=dist[i];
	sort(id+1,id+n+1,cmp);
//	for(int i=1;i<=n;i++) cout<<dist[i]<<' '; cout<<endl;
//	for(int i=1;i<=n;i++) cout<<id[i]<<' '; cout<<endl<<endl;
	for(int i=1;i<=n;i++){
		int u=id[i];
		for(int j=head[u];j;j=e[j].nex){
			int v=e[j].to; LL w=e[j].w;
			if(dist[v]==dist[u]+w)
			  (f[v]+=f[u])%=mo;
		}
	}
}
int main()
{
	n=read();m=read();s=read();t=read();
	for(int i=1;i<=m;i++){
		int u=read(),v=read(),w=read();
		ade(u,v,w); ade(v,u,w);
	}
	spfa(s,ds,fs); spfa(t,dt,ft);
//	cout<<"S: ";for(int i=1;i<=n;i++) cout<<fs[i]<<' '; cout<<endl;
//	cout<<"T: ";for(int i=1;i<=n;i++) cout<<ft[i]<<' '; cout<<endl;
	LL ans=sqr(fs[t]),len=ds[t];
	if(len%2==0)
	for(int u=1;u<=n;u++){
		if(ds[u]==(len/2))
		  ans=(ans-sqr(fs[u])*sqr(ft[u])%mo+mo)%mo;
	}
	int k1=len&1;
	//cout<<ans<<' '<<k1<<endl;
	for(int u=1;u<=n;u++){
		for(int i=head[u];i;i=e[i].nex){
			int v=e[i].to; LL w=e[i].w;
			if(ds[u]<(len/2)+k1 && dt[v]<(len/2)+k1 && ds[u]+w+dt[v]==len){
				ans=(ans-sqr(fs[u])*sqr(ft[v])%mo+mo)%mo;
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 18272
def main():
    H, W = map(int, input().split())
    field = [list(input()) for _ in range(H)]
    dd = ((1, 0), (-1, 0), (0, 1), (0, -1))

    q = []
    for i in range(H):
        for j in range(W):
            if field[i][j] == "#":
                q.append((i, j))
                field[i][j] = 0
    moves = 0

    while q:
        qn = []
        moves += 1
        for x, y in q:
            for dx, dy in dd:
                nx, ny = int(x + dx), int(y + dy)
                if 0 <= nx < H and 0 <= ny < W:
                    if field[nx][ny] == ".":
                        field[nx][ny] = moves
                        qn.append((nx, ny))

        q = qn

    m = []
    for i in range(H):
        m.append(max(field[i]))
    print(max(m))


main()


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

int main(){
    int n;
    cin >> n;
    int x[n];
    for(int i = 0;i < n;i++){
      cin >> x[i];
      }
    cout << x[n - 1];
    for(int j = 1;j < n;j++){
      cout << " " << x[n - 1 - j];
      }
     cout << endl;
     return 0;
    }

Measured memory_bytes: 1160
import java.util.Scanner;
import java.math.BigDecimal;

public class Main{
	public Main(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int tmp;
		
		for(int i = 1; i <= n; i++){
			String st = sc.next();
			BigDecimal bd = new BigDecimal(st);
			
			System.out.println("Case "+i+":");
			for(int j = 0; j < 10; j++){
				bd = bd.multiply(bd);
				st = bd.toString();
				if(st.length() < 8){
					tmp = 8 - st.length();
					String s = "";
					for(int k = 0; k < tmp; k++){
						s += "0";
					}
					st = s + st;
				}
				st = st.substring(2, 6);
				bd = new BigDecimal(st);
				System.out.println(bd);
			}
		}
	}
	
	public static void main(String[] args){
		new Main();
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  int a = 0, b = 0;
  for (int i = 0; i < S.size(); i++) {
    if(S.at(i) == 'A' || S.at(i) == 'C' || S.at(i) == 'G' || S.at(i) == 'T'){
      a++;
      b = max(a, b);
    }
    else a = 0;
  }
  cout << b << endl;
}

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

int main(){
    int N;
    cin >> N;
    
    vector<int> numbers;
    for(int i = 0; i < N; i++){
        vector<int>::iterator it;
        it = numbers.begin();
        int addNum;
        cin >> addNum;
        numbers.insert(it, addNum);
    }

    int count = 0;
    bool flag = true;
    while(true){
        for(int i = 0; i < N; i++){
        if (numbers[i] % 2) flag = false;
        numbers[i] /= 2;
        }
        if(!flag) break;
        count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    unused_imports,
    dead_code
)]
//use permutohedron::LexicalPermutation as _;
use proconio::input;
//use proconio::marker::*;
//use std::collections::*;
use std::cmp::*;
// use std::num;
fn main() {
    input! {N:usize, A:[i64;N]}
    let inf = std::i64::MIN / 4;
    let mut ans = inf;
    let mut dp = vec![vec![inf; 3]; N + 1];
    // dp[i][j] i個まで進めた時、スキップ消費済みの数をjとする。
    // Nが奇数なら、最終的にスキップを1個または2個消費する
    // Nが偶数なら、最終的にスキップを0個または1個消費する
    // スキップを3個以上消費することはできない。
    let k = N % 2 + 1;
    dp[0][0] = 0;
    for i in 0..N {
        if i % 2 == 0 {
            // 偶数個 なら、奇数番目は…。
            dp[i + 1][0] = dp[i][0] + A[i];
            dp[i + 1][1] = max(dp[i][0], dp[i][1]);
            dp[i + 1][2] = dp[i][2] + A[i];
        } else {
            dp[i + 1][0] = dp[i][0];
            dp[i + 1][1] = dp[i][1] + A[i];
            dp[i + 1][2] = max(dp[i][1], dp[i][2]);
        }
    }
    //println!("{:?}", dp);
    let ans = max(dp[N][k - 1], dp[N][k]);
    println!("{}", ans);
}


Measured memory_bytes: 16816