akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;


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

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve() {
	ll n, a, b;
	cin >> n >> a >> b;
	
	ll ans = n / (a + b) * a;
	ans += min(n % (a + b), a);
	cout << ans << en;
}

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

	solve();
	//int t; cin >> t; REP(i, t) solve();

	return 0;
}

Measured memory_bytes: 256
object Main extends App {
  import scala.io.StdIn._

  val n = readInt
  val scores = Array.tabulate(n){_ ⇒
    val Array(x, y) = readLine.trim.split(' ')
    (x, y)
  }
  println(
    (scores.collect{
      case (x, "BTC") ⇒ x.toDouble * 380000
    }.sum) + (scores.collect{
      case (x, "JPY") ⇒ x.toInt
    }.sum)
  )
}

Measured memory_bytes: 27076
using System;
using System.Numerics;

namespace ConsoleApp2
{
	class Program
	{
		static void Main(string[] args)
		{
			var n = int.Parse(Console.ReadLine());
			var accum = new BigInteger();


			for (int i = 1; i <= n; i++)
			{
				if (!(i % 3 == 0 || i % 5 == 0)) accum += i;
			}

			Console.WriteLine(accum);
		}
	}
}


Measured memory_bytes: 40772
import java.util.Scanner;

public class Main {
    public static void main(String[] atrgs){
        new Main().run();
    }

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] A = new int[N+1];
        int[] B = new int[N];
        for(int i = 0; i < N+1; i++) {
            A[i] = scanner.nextInt();
        }
        for(int i = 0; i < N; i++) {
            B[i] = scanner.nextInt();
        }

        long count= 0;
        for(int i = 0; i < N; i++) {
            int left = Math.min(A[i], B[i]);
            count += left;
            A[i] -= left;
            B[i] -= left;

            int right = Math.min(A[i + 1], B[i]);
            count += right;
            A[i + 1] -= right;
            B[i] -= right;
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 63684
from collections import defaultdict
N, K = map(int, input().split())
d = defaultdict(int)
for _ in range(N):
  a, b = map(int, input().split())
  d[a] += b
d = sorted(d.items(), key=lambda x:x[0])
s = 0
for i in range(len(d)):
  s += d[i][1]
  if K <= s:
    print(d[i][0])
    exit()

Measured memory_bytes: 15324
N = int(input())
X = list(map(int, input().split()))
Y = sorted(X)
m1 = Y[N//2 - 1] #小さい方の中央値候補
m2 = Y[N//2] #大きい方の中央値候補
for i in range(N):
  if X[i] <= m1:
    print(m2)
  else:
    print(m1)

Measured memory_bytes: 26772
h, w = map(int, input().split())

a = [""] * h
for i in range(h):
    a[i] = list(input())

row = [False] * w
col = [False] * h

for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            row[j] = True
            col[i] = True

for i in range(h):
    if col[i] == True:
        for j in range(w):
            if row[j] == True:
                print(a[i][j], end = "")

        print() 


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


int main() {

 
    string t;
    cin>>t;


    for(int i=0;i<t.size();i++){
        if(t.at(i)=='?')
            t.at(i)='D';
    }


    cout<<t<<endl;

    return 0;
}

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 5LL << 60;
const ll mod = 1e9 + 7;

int main() {
	int N;
	cin >> N;
	int A[N + 2];
	A[0] = 0;
	for(int i = 0; i < N; i++) cin >> A[i + 1];
	A[N + 1] = 0;
	int sum = 0;
	for(int i = 1; i < N + 2; i++) sum += abs(A[i - 1] - A[i]);
	for(int i = 1; i < N + 1; i++) {
		cout << sum - abs(A[i - 1] - A[i]) - abs(A[i] - A[i + 1]) + abs(A[i - 1] - A[i + 1]) << "\n";
	}
	return 0;
}


Measured memory_bytes: 4004
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef pair<long, int> sushi;

int main(){
  int N, K; cin >> N >> K;
  vector<sushi> a(N);
  int cnt[N];
  for(int i=0; i<N; i++){
    int t; long d; cin >> t >> d;
    a[i] = sushi(d, t-1);
    cnt[i] = 0;
  }
  sort(a.begin(),
       a.end(),
       [](const sushi& x, const sushi& y){ return x.first > y.first; });
  priority_queue<sushi, vector<sushi>, greater<sushi>> pque;
  long val = 0;
  for(int i=0; i<K; i++){
    pque.push(a[i]);
    val += a[i].first;
    cnt[a[i].second]++;
  }
  long v = 0;
  for(int i=0; i<N; i++){
    if(cnt[i] > 0) v++;
  }
  val += v * v;
  long ans = val;
  for(int i=K; i<N; i++){
    if(cnt[a[i].second]!=0) continue;
    if(pque.empty()) break;
    sushi s = pque.top(); pque.pop();
    while(!pque.empty() && cnt[s.second]==1){
      s = pque.top(); pque.pop();
    }
    if(cnt[s.second] >= 2){
      v++;
      val = val - s.first - (v-1)*(v-1) + a[i].first + v*v;
      ans = max(ans, val);
      cnt[s.second]--;
      cnt[a[i].second]++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4340
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,i,j,c,d,a,b;
    scanf("%lld%lld",&n,&d);
    double x,y;
    c=0;
    for(i=0;i<n;i++){
        scanf("%lld%lld",&a,&b);
        j=a*a+b*b;
        x=sqrt(j);
        if(x<=d)
          c++;
    }
    printf("%lld\n",c);
    return 0;
}


Measured memory_bytes: 3784
#include<bits/stdc++.h>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace  std ;
typedef long l ;
typedef long long ll ;
typedef vector<int>vi ;
typedef vector<l>vl ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ;
typedef pair<int,int> pii ;
typedef pair<ll,ll> pll ;
long long power(long long k , long long n , long long m=1e9+7)
{
    long long res = 1;
    while(n)
    {
        if(n%2!=0)
        {
            res = (res*k)%m ;
        }
        k = (k*k)%m ;
        n = n/2 ;
    }
    return(res) ;
}
ll nck(ll n , ll k ,ll m=1e9+7)
{
    ll i , j,b=1,c=1 ;
    if(n-k<k)
    {
        k = n-k ;
    }
    while(k)
    {
        b*=n ;
        c*=k ;
        ll g = __gcd(b,c) ;
        b/=g ;
        c/=g ;
        n--;
        k-- ;
    }
    return(b) ;
}
long long fact(long long n , long long m = 1e9+7)
{
    long long a = 1 ;
    if(n==0 || n==1)
    {
        return(1) ;
    }
    while(n>0)
    {
        a = (a%m * n%m)%m ;
        n-- ;
    }
    return(a) ;
}
void READ(vll &v, ll n)
{
    ll a ;
    for(ll i=0 ; i<n ; i=i+1)
    {
        cin>>a ;
        v.pb(a) ;
    }
}
void PRINT(vll &v, ll n)
{
    ll a ;
    for(ll i=0 ; i<n ; i=i+1)
    {
        cout<<v[i]<<" " ;
    }
    cout<<"\n" ;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    std::cout.unsetf ( std::ios::floatfield );//this and next line for floating precision upto 6
    std::cout.precision(10);
    ll a,b,c,d,e,x,i,j,n,t,m,k,y,s;
    double p,q,r,w,u ;
    string str = "",str1 = "" ;
    char ch,chr ;
    ll a1,a2,b1,b2 ;
    cin>>n ;
    vll v;
    READ(v,n) ;
    sort(all(v));
    a = accumulate(all(v),(ll)0);
    if(a-v[n-1]>v[n-1])
    {
    	cout<<"Yes\n" ;
	}
	else
	{
		cout<<"No\n" ;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <math.h>
using namespace std;
int main(){
    int a,b;
    float t;
    cin >> a >> b >> t;
    int t2=t+0.5;
    int ans = t2/a;
    ans *= b;
    cout << ans << endl;
    return 0;
}

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

int main(){
  int n;
  cin >>n;
  int x;
  int ans=0;
  rep(i,n){
     cin>>x;
     if(x%2==0) {if(x%5!=0&&x%3!=0)ans=1;} 
  }
  if(ans) cout<<"DENIED"<<endl;
  else cout<<"APPROVED"<<endl;
}

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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

int main(void){
    int N;
    scanf("%d",&N);

    int* H;
    NEW(H,N+1); //Hi→H[i]とする、添字範囲0~N
    for(int i=1;i<=N;i++){
        scanf("%d",&H[i]);
    }

    int count=0;
    int ans=0;

    for(int i=1;i<N;i++){
        if(H[i]>=H[i+1]){ //右隣に移動できる時
            count+=1;
        }
        else{
            if(ans<count){
                ans=count;
            }
            count=0;
        }
    }
    if(ans<count){
        ans=count;
    }

    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 512
import queue
K = int(input())
q = queue.Queue()
for i in range(1,10):
    q.put(i)
for i in range(K):
    x = q.get()
    if x%10 != 0:
        q.put(10*x + (x%10) -1)
    q.put(10*x + (x%10))
    if x%10 != 9:
        q.put(10*x + (x%10) +1)
print(x)

Measured memory_bytes: 12452
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(){
    long long int n, j, i, step;
    scanf("%lld", &n);
    for (i = sqrt(n); i > 0; i--){
        j = n / i;
        if (n % i == 0){
            break;
        }
    }
    step = (j - 1) + (i - 1);
    printf("%lld", step);
    return 0;
}


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

int main() {
    int A,B,K;
    cin >> A >> B >> K;
    if(B-A+1 <= K*2) {
        for(int i = A; i <= B; i++) {
            cout << i << endl;
        }
        return 0;
    }
    for(int i = A; i < A+K; i++) {
        cout << i << endl;
    }
    for(int j = B-K+1; j <= B; j++) {
        cout << j << endl;
    }
}

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

typedef long long ll;

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,l,n) for(int i=(l);i<=(n);i++)

template<class T>
using vt = vector<T>;
template<class T>
using vvt = vector<vector<T>>;

int main(){
    char a,b;
    cin >> a >> b;
    if(a=='H'){
        if(b=='H') cout << 'H' << endl;
        else cout << 'D' << endl;
    }
    else {
        if(b=='H') cout << 'D' << endl;
        else cout << 'H' << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import sys
 
X, Y=map(int,input().split())
 
if X==2 or Y==2:
  print('No')
  sys.exit()
elif X==4 or X==6 or X==9 or X==11:
  if Y==6 or Y==9 or Y==11:
    print('Yes')
    sys.exit()
  else:
    print('No')
    sys.exit()
else:
  if Y==3 or Y==5 or Y==7 or Y==8 or Y==10 or Y==12:
    print('Yes')
    sys.exit()
  else:
    print('No')
    sys.exit()  

Measured memory_bytes: 3064
<?php
    
    fscanf(STDIN,"%d%d",$N,$X);
    
    $L = array_map('intval',explode(" ",trim(fgets(STDIN))));
    
    array_unshift($L,0);
    
    $sum=0;
    $count=0;
    for($i=0;$i<=$N;$i++){
        $sum += $L[$i];
        if($sum>$X)break;
        $count++;
    }
    echo $count;

?>

Measured memory_bytes: 16272
#!/usr/bin/env python3
import sys, math, fractions, itertools, collections, copy, heapq


def solve(A: int, B: int, C: int):
    if A % 2 == 0 or B % 2 == 0 or C % 2 == 0:
        print(0)
    else:
        print(min([A*B, B*C, C*A]))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    solve(A, B, C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5180
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
using namespace std;

set<int, greater<int> > rank;
map<int, int> points;
int main(){
    int a, b;
    while(scanf("%d,%d", &a, &b), a){
	rank.insert(b);
	points[a] = b;
    }
    while(~scanf("%d", &a)){
	cout << distance(rank.begin(), rank.lower_bound(points[a])) + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
#define M_PI 3.14159265358979323846
#define MOD 1000000007
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> ipair;
typedef pair<ll, ll> llpair;
    
/*
    Author: Koushik Sahu
    Created: 11 Sep 2020 20:40:55
*/

ll h, w, dp[1001][1001];
char a[1001][1001];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    cin>>h>>w;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin>>a[i][j];
        }
    }
    fill_n(dp[0], 1001*1001, 0);
    dp[0][0] = 1;
    bool flag = false;
    for(int i=0; i<h; i++){
        if(!flag){
            if(a[i][0]=='.'){
                dp[i][0] = 1;
            }else{
                break;
            }
        }
    }
    for(int j=0; j<w; j++){
        if(!flag){
            if(a[0][j]=='.'){
                dp[0][j] = 1;
            }else{
                break;
            }
        }
    }
    for(int i=1; i<h; i++){
        for(int j=1; j<w; j++){
            if(a[i][j]=='.') dp[i][j] = (dp[i-1][j] + dp[i][j-1])%MOD;
        }
    }
    cout<<dp[h-1][w-1]<<"\n";
    return 0;
}

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

int main(){
	string s;
	cin>>s;
	if(s[2]==s[3] and s[4]==s[5])cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 3620
import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;
import std.container;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

const real eps = 1e-10;

void calc(int[][] m, int x, int y,int[][] cost, int c) {
	if(cost[x][y] <= c) {
		return;
	}
	cost[x][y] = c;
	if(m[2*x][y] == 0) {
		calc(m, x-1, y, cost, c+1);
	}
	if(m[2*x+2][y] == 0) {
		calc(m, x+1, y, cost, c+1);
	}
	if(m[2*x+1][y] == 0) {
		calc(m, x, y-1, cost, c+1);
	}
	if(m[2*x+1][y+1] == 0) {
		calc(m, x, y+1, cost, c+1);
	}
}

void main(){
	while(true) {
		auto wh = readInts();
		auto w = wh[0];
		auto h = wh[1];
		if((w|h) == 0) return;

		int[][] m;
		m ~= new int[](w+1).map!(a => 1).array;
		for(int i; i < 2*h-1; ++i) {
			auto l = readInts();
			if(i%2 == 0) {
				l = 1 ~ l ~ 1;
			}
			m ~= l;
		}
		m ~= new int[](w+1).map!(a => 1).array;
		auto cost = new int[][](h,w);
		for(int i; i < h; ++i) {
			for(int j; j < w; ++j) {
				cost[i][j] = int.max;
			}
		}
		calc(m, 0, 0, cost, 1);
		writeln(cost[h-1][w-1] == int.max ? 0: cost[h-1][w-1]);
	}
}

Measured memory_bytes: 3476
#include <stdio.h>

int main(void){

  char s[10];

  scanf("%s",s );

if(s[0]=='S'){
  printf("Cloudy\n");


}else if(s[0]=='C'){

  printf("Rainy\n");

}else if(s[0]=='R'){
  printf("Sunny\n");

}


  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

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

  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &x: a) cin >> x;

  for (auto &x: a) {
    if (x % 2 == 0) {
      if (x % 3 == 0 || x % 5 == 0) continue;
      else {
        cout << "DENIED" << endl;
        return 0;
      }
    }
  }

  cout << "APPROVED" << endl;

  return 0;
}


Measured memory_bytes: 256
mod = 1000000007

n, m = map(int, input().split())
xs = list(map(int, input().split()))
ys = list(map(int, input().split()))

xres, yres = 0, 0
for i in range(n):
    xres += i*xs[i] - (n-i-1)*xs[i]
    xres %= mod

for i in range(m):
    yres += i*ys[i] - (m-i-1)*ys[i]
    yres %= mod

ans = (xres * yres) % mod
print(ans)


Measured memory_bytes: 18624
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5+100)

def dfs(v):
    l = []
    
    for nv in G[v]:
        l.append(dfs(nv))
    
    l.sort(reverse=True)
    res = 0
    
    for i in range(len(l)):
        res = max(res, l[i]+i+1)
    
    return res

N = int(input())
G = [[] for _ in range(N)]

for i in range(1, N):
    a = int(input())
    G[a-1].append(i)

print(dfs(0))

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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)

using namespace std;



bool chk(ll a, ll b, vector<string>& s){
    ll n = s.size();
    rep(hx, n){
        rep(wx, n){
            //t[i][j] = s[(i+a)%n][(j+b)%n]
            //t[j][i] = s[(j+a)%n][(i+b)%n]
            ll i0 = (hx+a)%n;
            ll j0 = (wx+b)%n;
            ll i1 = (hx+b)%n;
            ll j1 = (wx+a)%n;
            if(s[i0][j0] != s[j1][i1]){
                return false;
            }
        }
    }
    return true;
}

ll solve(vector<string>& s){
    ll n = s.size();
    ll cnt = 0;
    rep(a, n){
        if(chk(a, 0, s)) cnt += n;
    }
    return cnt;
}

int main(){
    ll n;
    cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s[i];


    cout << solve(s) << endl;


    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int a,b;
int main()
{
	string s;
	cin>>s;
	if(s.length()<=1)
	{
		cout<<"No\n";
		return 0;
	}
	for(int i=0;i<s.length();i++)
	{
		if(s[i]=='C')a++;
		if(s[i]=='F'&&a)b++;
	}
	if(b)cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/python3
# -*- coding:utf-8 -*-

import sys
sys.setrecursionlimit(10**9)

def main():
  n = int(input())
  inode2scores = [0] * (n+1)
  tree = [[] for _ in range(n+1)]
  weights = dict()
  for _ in range(n-1):
    a, b, c = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)
    weights[(a, b)] = weights[(b, a)] = c
    
  q, k = map(int, input().split())  
  visited = [False] * (n+1)
  iroot = k
  def dfs(inode, score=0):
    visited[inode] = True
    for ichild in tree[inode]:
      if visited[ichild]:
        continue
      inode2scores[ichild] = weights[(inode, ichild)] + score
      dfs(ichild, inode2scores[ichild])
  dfs(iroot)
  for _ in range(q):
    x, y = map(int, input().split())
    print(inode2scores[x] + inode2scores[y])

if __name__=='__main__':
  main()



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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)

const char sp = ' ';
const char cmm = ',';
const int MOD = 1000000007;

using ll = long long;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}

vector<ll> prime;
void eratos(size_t max){
    vector<bool> isprime(max+1, true);
    isprime[0] = false;
    isprime[1] = false;

    for(size_t i=2; i * i <= max; ++i){
        if(isprime[i]){
            for(size_t j=2; i*j <= max; ++j){
                isprime[i*j] = false;
            }
        }
    }

    for(size_t i=0; i <= max; ++i){
        if(isprime[i])
            prime.push_back(i);
    }
}

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    eratos(55555);
    int i = 0;
    int cnt = 0;
    while(cnt < n){
        if(prime[i]%5 == 1){
            cout << prime[i] << sp;
            ++cnt;
        }
        ++i;
    }
    cout << endl;



    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int PERMUTATION[24][4] = {
	{0,1,2,3}, {0,1,3,2}, {0,2,1,3}, {0,2,3,1}, {0,3,1,2}, {0,3,2,1},
	{1,0,2,3}, {1,0,3,2}, {1,2,0,3}, {1,2,3,0}, {1,3,0,2}, {1,3,2,0},
	{2,1,0,3}, {2,1,3,0}, {2,0,1,3}, {2,0,3,1}, {2,3,1,0}, {2,3,0,1},
	{3,1,2,0}, {3,1,0,2}, {3,2,1,0}, {3,2,0,1}, {3,0,1,2}, {3,0,2,1}
};

void init_operators(char ops[27][3]) {
	int i, j, k, n = 0;
	for (i = 0; i < 3; i++) {
		for (j = 0; j < 3; j++) {
			for (k = 0; k < 3; k++) {
				ops[n][0] = "+-*"[i];
				ops[n][1] = "+-*"[j];
				ops[n][2] = "+-*"[k];
				n++;
			}
		}
	}
}

int calc(int a, int b, char op) {
	if (op == '+')
		return a + b;
	if (op == '-')
		return a - b;
	return a * b;
}

void solve(int data[4], char op[27][3]) {
	int i, j;
	int a, b ,c, d;
	char x, y, z;
	const char *fmt;

	for (i = 0; i < 24; i++) {
		a = data[PERMUTATION[i][0]];
		b = data[PERMUTATION[i][1]];
		c = data[PERMUTATION[i][2]];
		d = data[PERMUTATION[i][3]];
		for (j = 0; j < 27; j++) {
			x = op[j][0];
			y = op[j][1];
			z = op[j][2];
			if (calc(a, calc(b, calc(c, d, z), y), x) == 10) {
				//abcd... (a x (b y (c z d)))
				fmt = "(%d %c (%d %c (%d %c %d)))\n";
				printf(fmt, a, x, b, y, c, z, d);
				return;
			}
			if (calc(a, calc(calc(b, c, y), d, z), x) == 10) {
				//abc.d.. (a x ((b y c) z d))
				fmt = "(%d %c ((%d %c %d) %c %d))\n";
				printf(fmt, a, x, b, y, c, z, d);
				return;
			}
			if (calc(a, calc(calc(b, c, y), d, z), x) == 10) {
				//abc..d. (a x ((b y c) z d))
				fmt = "(%d %c ((%d %c %d) %c %d))\n";
				printf(fmt, a, x, b, y, c, z, d);
				return;
			}
			if (calc(calc(a, b, x), calc(c, d, z), y) == 10) {
				//ab.cd.. ((a x b) y (c z d))
				fmt = "((%d %c %d) %c (%d %c %d))\n";
				printf(fmt, a, x, b, y, c, z, d);
				return;
			}
			if (calc(calc(calc(a, b, x), c, y), d, z) == 10) {
				//ab.c.d. ((a x b) y c) z d)
				fmt = "(((%d %c %d) %c %d) %c %d)\n";
				printf(fmt, a, x, b, y, c, z, d);
				return;
			}
		}
	}
	puts("0");
}

int main() {
	int d[4];
	char ops[27][3];

	init_operators(ops);
	while (1) {
		scanf("%d %d %d %d ", d, d+1, d+2, d+3);
		if (!d[0] && !d[1] && !d[2] && !d[3])
			break;
		solve(d, ops);
	}
	return 0;
}

Measured memory_bytes: 616
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i, MAT.size()){
    REP(j, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(void){
      return;
    };
    HOGE(CLASS1 key, CLASS2 value){
      this->key = key;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  cin >> N;

  // k(k-1) = 2N
  // k*k > 2N > (k-1)*(k-1)
  ll k = (ll)sqrt(2*N)+1;
  if(k*(k-1)!=2*N){
    cout << "No\n";
    return 0;
  }

  printf("Yes\n");

  vvll S(k, vll(k-1, -1));
  ll tmp = 1;
  REP(i, k){
    REP(j, i){
      S[i][j] = S[j][i-1];
    }
    FOR(j, i, k-1){
      S[i][j] = tmp;
      tmp++;
    }
  }

  printf("%d\n", k);
  REP(i, k){
    printf("%d", k-1);
    REP(j, k-1){
      printf(" %d", S[i][j]);
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 2944
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define int long long
#define MP make_pair
#define PB push_back
#define FI first
#define SE second
typedef pair<int, pair<int, int> > PPII;
typedef pair<int, int> PII;
static const int INF = 1ll<<60;
static const int dx[] = { 1, -1, 0, 0, };
static const int dy[] = { 0, 0, 1, -1 };

int H,W,N;
int fld[1005][1005];
int dp[1005][1005];

signed main(){
    while(1){
        cin>>H>>W>>N;
        if(H==0&&W==0&&N==0)break;
        N--;
        dp[0][0]=N;
        for(int i=0;i<H;++i)
            for(int j=0;j<W;++j)cin>>fld[i][j];

        for(int i=0;i<H;++i){
            for(int j=0;j<W;++j){
                int a=dp[i][j]/2;
                int b=dp[i][j]-a;
                if(fld[i][j]==1){
                    dp[i+1][j]+=a;
                    dp[i][j+1]+=b;
                }
                else{
                    dp[i+1][j]+=b;
                    dp[i][j+1]+=a;
                }
            }
        }
        int x=1,y=1;
        while(1){
            if(x>W||y>H)break;
            if(dp[y-1][x-1]%2==0){
                if(fld[y-1][x-1]==0)y++;
                else x++;
            }
            else {
                if(fld[y-1][x-1]==0)x++;
                else y++;
            }
        }
        cout<<y<<" "<<x<<endl;
        memset(dp,0,sizeof(dp));
        memset(fld,0,sizeof(fld));
    }
}

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

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<string,int>Psi;

vector <int> v;
int dfs(int a,int b){
  int min=INF;
  int min_i;
  if(b-a<=0){
    return v[a];
  }
  for(int i=a;i<b;i++){
    if(v[i]<min){
      min=v[i];
      min_i=i;
    }
  }
  for(int i=a;i<b;i++){
    v[i]-=min;
  }
  return min+dfs(a,min_i)+dfs(min_i+1,b);
}
void all(){
  v[0]++;
}

int main(){
  int n;
  cin>>n;
  int ans=0;
  REP(i,n){
    int tmp;
    cin>>tmp;
    v.push_back(tmp);
  }


  cout<<dfs(0,n)<<endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cstring>

// ref : http://kyopro.hateblo.jp/entry/2018/12/25/174720

using ll = long long;
/*
dp[d][smaller][leadingZero][num]
numは3, 5, 7を少なくとも1回選んだかどうかのフラグとする
具体的には3bit(つまり0 ~ 7)のうち各bitで管理する
leadingZero = 0 はまだ0が続いている状態
*/
ll dp[11][2][2][8];

int main(){
    std::string S;
    std::cin >> S;

    memset(dp, 0, sizeof dp);
    dp[0][0][0][0] = 1;
    for(int d = 0; d < S.size(); d++){
        for(int smaller = 0; smaller < 2; smaller++){
            for(int leadingZero = 0; leadingZero < 2; leadingZero++){
                for(int num = 0; num < 8; num++){
                    if(dp[d][smaller][leadingZero][num] == 0) continue; // 足す意味なし

                    int val; // 次に入れられる数字の最大値
                    if(smaller == 1){
                        val = 9;
                    }else{
                        val = S[d] - '0';
                    }

                    if(leadingZero == 0){
                        // まだ0が続いている状態で後々のために1を入れておく
                        dp[d + 1][1][leadingZero][0] = 1;
                    }

                    // valの値に応じてsmallerを切り替えて計算
                    if(val == 3) dp[d + 1][0][1][num | 1] += dp[d][smaller][leadingZero][num];
                    if(val > 3) dp[d + 1][1][1][num | 1] += dp[d][smaller][leadingZero][num];
                    if(val == 5) dp[d + 1][0][1][num | 2] += dp[d][smaller][leadingZero][num];
                    if(val > 5) dp[d + 1][1][1][num | 2] += dp[d][smaller][leadingZero][num];;
                    if(val == 7) dp[d + 1][0][1][num | 4] += dp[d][smaller][leadingZero][num];;
                    if(val > 7) dp[d + 1][1][1][num | 4] += dp[d][smaller][leadingZero][num];
                }
            }
        }
    }

    std::cout << dp[S.size()][0][1][7] + dp[S.size()][1][1][7] << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
 
int main(void){
    int N, K, max, tmp;
    int* p;
 
    scanf("%d %d",&N, &K);
 
    p=(int*)malloc(N*sizeof(int));
 
    for(int i=0; i<N; i++){
        scanf("%d",p+i);
    }
 
    for(int i=1; i<N; i++){
        p[i]=p[i]+p[i-1];
    }
    max=p[K-1];
    for(int i=1; i<N-K+1; i++){
        tmp=p[i+K-1]-p[i-1];
        if(max<tmp)
            max=tmp;
    }
    printf("%f",(max+K)/2.);
 
 
    return 0;
}

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

int main(){
    string s; cin >> s;
    int len = s.length(), l = 2;
    int ans = 0;
    int i;
    for(i = 0; i < len; i++){
        if(l == 2){
            l = 1; ans++;
        }else{
            if(s[i-1] == s[i]){
                if(i < len-1){l++; i++; ans++;}
            }else{
                ans++; l = 1;
           }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
w,h,n = gets.split.map!(&:to_i)
s,t = 0,0

n.times do
    x,y,a = gets.split.map!(&:to_i)

    if a == 1 then
        s = x if s < x
    elsif a == 2
        w = x if w > x
    elsif a == 3
        t = y if t < y
    else
        h = y if h > y
    end
end

if w - s < 0 || h - t < 0 then
    puts 0
else
    puts (w - s) * (h - t)
end

Measured memory_bytes: 1788
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

fn abbaisu(A: i64, B: i64, n: i64) -> i64 {
    if n > B {
        return 0;
    }
    let mut start = A - (A % n);
    if start < A {
        start += n;
    }
    let end = B - (B % n);
    (end - start) / n + 1
}

fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

fn main() {
    let (A, B, C, D) = get!(i64, i64, i64, i64);
    let koubaisu = C * D / gcd(C, D);
    println!("{}", (B-A+1) - abbaisu(A, B, C) - abbaisu(A, B, D) + abbaisu(A, B, koubaisu));
}


Measured memory_bytes: 4352
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  int num = (n + 999) / 1000;
  cout << num * 1000 - n << endl;
  return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)

int main(void) {
    int a, b, ans = 0;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a >> b;
    FOR(i, a, b + 1) {
        if ((i / 10000) % 10 == i % 10
            && (i / 1000) % 10 == (i / 10) % 10) {
            ans++;
        }
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#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;
     
    void debug_out() { cerr << endl; }
    template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
    template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
    template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
    template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
    template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
    template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}
     
    #define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
    #define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
    #define dbg_ok cerr<<"OK!\n"
    #define  st first
    #define  nd second
    #define int long long  
     
    template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
    typedef cc_hash_table<int, int, hash<int > > ht;
     
    const int  M    = 998244353;
    const int  MAXN = 10005 ;
    const int   INF  = 0x3F3F3F3F  ; // long long inf
    const long double eps = 1.084202e-19;
 
    int32_t main(){
         ios_base::sync_with_stdio(false);
         cin.tie(NULL);
         string s ;  
         cin >> s ; 
         int n = s.size() ; 
         int p= 2019;
         map<int, int> mp;
         int ans = 0 ;
		++mp[0];
		int t=0, p2=1;
		for(int i=n-1; ~i; --i) {
			t=(t+(s[i]-'0')*p2)%p;
			ans+=mp[t];
			mp[t]++;
			p2=p2*10%p;
		}
        cout<<ans;
        
       
    }

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, M, K;
    cin >> N >> M >> K;

    for(ll i=0; i<=N; i++){
        for(ll j=0; j<=M; j++){
            if(i*(M-j) + j*(N-i) == K){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define forr(i, a, b) for(ll i = (a); i < (ll) (b); i++)
#define forn(i, n) forr(i, 0, n)
#define forall(it, v) for(auto it = v.begin(); it != v.end(); ++it)
#define dforn(i, n) for(ll i = ((ll) n) - 1; i >= 0; i--)
#define db(v) cerr << #v << " = " << v << endl
#define pb push_back
typedef long long ll;
const int MAXN = 55;

ll n, A[MAXN], K[MAXN], ans;

void decrease(){
  ll s = 0;
  forn(i, n){
    K[i] = A[i] / n;
    s += K[i];
  }
  forn(i, n){
    A[i] -= K[i] * n;
    A[i] += (s - K[i]);
  }
  ans += s;
  bool ok = true;
  forn(i, n){
    if(A[i] >= n){
      ok = false;
      break;
    }
  }
  if(ok){
    printf("%lld\n", ans);
    return;
  }
  else {
    decrease();
  }
}

int main() {
  scanf("%lld", &n);
  forn(i, n){
    scanf("%lld", &A[i]);
  }
  
  decrease();
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		scan.close();
		int cnt=0;
		while(cnt<c) {
			if(b-a*(cnt+1)<0)break;
			cnt++;
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  string s; cin >> s;
  if(s[s.size()-1] == 's') s += "es";
  else s += "s";
  cout << s;
  return 0;
}


Measured memory_bytes: 3672
s = input()
K = int(input())

rlt = ''

for i in range(len(s)-1):
  c = (26-ord(s[i])+ord('a'))%26
  if K >= c:
    rlt += 'a'
    K -= c
  else:
    rlt += s[i]
    
rlt += chr((K + ord(s[-1]) - ord('a'))%26 + ord('a'))
print(rlt)

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

const int num = 100005;
int field[num];

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

  for (int i = 0; i < num; i++)
  {
    field[i] = 0;
  }

  int a;
  for (int i = 0; i < n; i++)
  {
    cin >> a;
    a++;
    field[a]++;
    field[a - 1]++;
    field[a + 1]++;
  }

  int res = 0;
  for (int i = 0; i < num; i++)
  {
    if (field[i] > res)
    {
      res = field[i];
    }
  }

  cout << res << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;

using ll = long long;
using Bint = mp::cpp_int;
ll mod = 1000000007;

bool next_5(vector<int> &v, ll num) {
    num++;
    return v[num] < 5;

    while (num < v.size()) {
        if (v[num] != 5) {
            if (v[num] < 5) {
                return true;
            } else {
                return false;
            }
        }
        num++;
    }

    return false;
}

int main() {
source:
    string n;
    cin >> n;
    vector<int> n_array(n.length() + 1, 0);

    rep(i, n.length()) {
        ll index = n.length() - i - 1;
        int temp = n[index] - '0';
        n_array[i] = temp;
    }

    ll ans = 0;

    bool flag = false;
    rep(i, n.length() + 1) {
        int num = n_array[i];
        if (flag && (num == 9)) {
            flag = true;
        } else {
            if (flag) {
                flag = false;
                num++;
            }
            if (num <= 4 | (num == 5 && next_5(n_array, i))) {
                ans += num;
                flag = false;
            } else {
                ans += 10 - num;
                flag = true;
            }
        }
    }

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



Measured memory_bytes: 5252
import Control.Applicative
import Control.Monad

main :: IO ()
main = do
  solve <$> readLn <*> f >>= prt
  loop
  where
    f = map read <$> words <$> getLine
    loop = do
      n <- readLn
      unless (n == 0) $ do
        putStrLn ""
        solve n <$> f >>= prt
        loop

solve :: Int -> [Int] -> [Int]
solve n [x, l, c, d] = let sm = 10 * x + 50 * l + 100 * c + 500 * d
                           cg = sm - n
                           (cd, r1) = divMod cg 500
                           (cc, r2) = divMod r1 100
                           (cl, r3) = divMod r2 50
                           cx = r3 `div` 10
                       in [ max 0 (x - cx),
                            max 0 (l - cl),
                            max 0 (c - cc),
                            max 0 (d - cd) ]
                         
prt :: [Int] -> IO ()
prt [a, b, c, d] = do
  when (a > 0) $ putStrLn $ "10 " ++ show a
  when (b > 0) $ putStrLn $ "50 " ++ show b
  when (c > 0) $ putStrLn $ "100 " ++ show c
  when (d > 0) $ putStrLn $ "500 " ++ show d



Measured memory_bytes: 3960
#include<iostream>
#include<map>
using namespace std;
long h,w,a,b,c,d,D[10]={0,1,-1,0,-1,-1,1,1},cnt[10],i,j;
map<pair<long,long>,long>m;
main()
{
	cin>>h>>w>>a;
	for(*cnt=(h-2)*(w-2);cin>>a>>b;i++)
		for(j=0;j<9;)
			if((c=a+D[j])>1&(d=b+D[++j])>1&c<h&d<w)cnt[c=m[make_pair(c,d)]++]--,cnt[c+1]++;
	for(i=0;i<10;i++)cout<<cnt[i]<<endl;
}

Measured memory_bytes: 56448
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

ll A[MAXN];
pii B[MAXN];
int dp[110][110];
char S[MAXN];

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1,idy = -1;
    int tc;
    ll curv;
    bool judge = true;

    k = 10;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n;

    for(int i=0;i<n;i++)
    {
        cin>>S;

        idx = -1;

        A[i] = 0;

        m = strlen(S);

        judge = false;

        cnt = 0;

        for(int j=0;j<m;j++){
            if(S[j]=='.'){
                judge = true;
                continue;
            }
            A[i] = 10*A[i]+(ll)(S[j]-'0');
            if(judge)cnt++;
        }

        a = -cnt;
        b = -cnt;

        curv = A[i];

        while(!(curv&1)){
            curv>>=1;
            a++;
        }

        while(!(curv%5)){
            curv/=5;
            b++;
        }

        dp[a+k][b+k]++;

        B[i] = pii(a,b);
    }


    for(int i=70;i>=0;i--){
        for(int j=70;j>=0;j--){
            dp[i][j] += dp[i+1][j];
            dp[i][j] += dp[i][j+1];
            dp[i][j] -= dp[i+1][j+1];
        }
    }

    ll res = 0;

    for(int i=0;i<n;i++){
        a = B[i].f;
        b = B[i].s;

        x = max(0,k-a);
        y = max(0,k-b);

        res += (ll)dp[x][y];

        if(a>=0&&b>=0)res--;
    }

    res>>=1;

    cout<<res<<"\n";

    return 0;
}


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

int	main(void)
{
  	int	N;
  	int	*H;
  	int	i;
  	int	num;
  	int	count;
  	int	tmp;
  	int max;
  
  	num = scanf("%d\n", &N);
  	if (num != 1)
      	return (0);
  
  	H = (int *)malloc(sizeof(int) * N);
  	for (i=0; i<N; i++)
    {
      	num = scanf("%d", &H[i]);
      	if (num != 1)
          	return (0);
    }
  
  	tmp = 0;
  	count = 0;
  	max = 0;
  	for (i=N-2; i>=0; i--)
    {
      	if (H[i] >= H[i + 1])
        {
          	count++;
          	if (max < count)
            {
              	max = count;
          		tmp = i;
            }
        }
      	else
        {
          	count = 0;
        }
    }
  	printf("%d", max);
  	return (0);
}

Measured memory_bytes: 512
p = 10**9+7
N = int(input())
S = input().strip()
C = {chr(i):[] for i in range(97,123)}
for i in range(N):
    C[S[i]].append(i)
cnt = 1
for j in range(97,123):
    cnt = (cnt*(1+len(C[chr(j)])))%p
print((cnt-1)%p)

Measured memory_bytes: 45168
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <cstdint>
#include <chrono>
#include "atcoder/all"
using namespace std;
using namespace atcoder;
#define     loop(n,i,a)     for(ll i=a;i<n;i++)
#define     loopR(n,i,a)    for(ll i=a-1;i>=n;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pii>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
template<typename T>void max_self(T &a,T b){a=max(a,b);}
template<typename T>void min_self(T &a,T b){a=min(a,b);}
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
int KnightI[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int KnightJ[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=3e5+10,oo=0x3f3f3f3f,MOD=998244353;
const long double PI = acos(-1),eps=1.0e-14;

void solve(){
    int n,q;
    cin>>n>>q;
    fenwick_tree<ll>ft(n);
    loop(n,i,0){
        ll x;
        cin>>x;
        ft.add(i,x);
    }
    while(q--){
        ll t,a,b;
        cin>>t>>a>>b;
        if(t)
            cout<<ft.sum(a,b)<<endl;
        else
            ft.add(a,b);
    }
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();

}


Measured memory_bytes: 8252