akhauriyash/Code-Regression huggingface dataset:
from collections import Counter, deque, OrderedDict, defaultdict
# from copy import copy, deepcopy # pythonのみ．copyは1次元，deepcopyは多次元．
# from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
# from functools import reduce
# from heapq import heapify, heappop, heappush
from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():

    N, W = map(int, input().split())
    d = defaultdict(list)
    for _ in range(N):
        w, v = map(int, input().split())
        d[w].append(v)

    for i in d.values():
        i.sort(reverse=True)

    # dict型をvalueでsort(keyでsortならkey変数削除）
    from collections import OrderedDict
    d = OrderedDict(sorted(d.items()))

    # for i in range(4-len(d)):
    # d[0].append(0)

    dlength = []
    for k, v in d.items():
        dlength.append((range(len(v)+1), k, v))

    for i in range(4-len(dlength)):
        dlength.append((range(1), 0, [0]))
    Mans = 0
    for i in dlength[0][0]:
        for j in dlength[1][0]:
            for k in dlength[2][0]:
                for l in dlength[3][0]:
                    if i*dlength[0][1]+j*dlength[1][1]+k*dlength[2][1]+l*dlength[3][1] <= W:
                        Mans = max(Mans, sum(
                            dlength[0][2][:i])+sum(dlength[1][2][:j])+sum(dlength[2][2][:k])+sum(dlength[3][2][:l]))

    print(Mans)


resolve()

Measured memory_bytes: 76180
import copy

h, w, k = map(int, input().split())
grd = [list(i for i in input()) for _ in range(h)]
ans = 0
for i in range(2**h):
    grd1 = copy.deepcopy(grd)
    for i1 in range(h):
        if i >> i1 & 1:
            grd1[i1] = ['r'] * w
    for j in range(2**w):
        grd2 = copy.deepcopy(grd1)
        for j1 in range(w):
            if j >> j1 & 1:
                for n in range(h):
                    grd2[n][j1] = 'r'

        if sum(grd2,[]).count('#') == k:
            ans += 1
print(ans)

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

int main() {
  int k;
  cin >> k;
  vector<int> vec={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << vec[k-1] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    int n;
    cin>>n;
    int cnt=0;

    for(int i=a;i<=b;i++)
    {
        if(i%n==0)
            cnt++;
    }

    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>

using namespace std;


int main()
{
	int N;
	vector<long long> As;
	vector<long long> Bs;
	
	cin >> N;

	long long a,b;
	for (int ni = 0; ni < N + 1; ni++){
		cin >> a;
		As.push_back(a);
	}
	for (int ni = 0; ni < N; ni++){
		cin >> b;
		Bs.push_back(b);
	}

	long long ans = 0;

	long long cnt;
	for (int ni = N-1; ni >= 0; ni--){
		cnt = min(As[ni+1], Bs[ni]);
		Bs[ni] -= cnt;
		ans += cnt;

		cnt = min(As[ni], Bs[ni]);
		As[ni] -= cnt;
		ans += cnt;
	}
	//ans += min(As[0], Bs[0]);

	printf("%lld",ans);


	//printf("No");


	return 0;
}



Measured memory_bytes: 2548
#include "bits/stdc++.h"
using namespace std;

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

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

	vector<int> vec(n);
	for (auto& e : vec) {
		cin >> e;
	}

	sort(vec.begin(), vec.end());
	int d;
	if (n > 1) {
		d = gcd(abs(vec.at(0) - x), abs(vec.at(1) - x));
		for (int i = 2; i < n; i++) {
			d = gcd(abs(vec.at(i) - x), d);
		}
	}
	else {
		d = abs(vec.at(0) - x);
	}
	cout << d << endl;
}


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

int main() {
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  
  int ans = 0;
  rep(i,a) {
    rep(j,b) {
      rep(k,c) {
        if (500*i+100*j+50*k==x) ans++;
      }
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;;

class Main {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        try {
            String[] data;
            String res;
            int m, f, r;

            while (true) {
                data = br.readLine().split(" ");
                m = Integer.parseInt(data[0]);
                f = Integer.parseInt(data[1]);
                r = Integer.parseInt(data[2]);

                if (m == -1 && f == -1 && r == -1)
                    return;
                if (m == -1 || f == -1)
                    res = "F";
                else if (m + f >= 80)
                    res = "A";
                else if (65 <= m + f && m + f < 80)
                    res = "B";
                else if (50 <= m + f && m + f < 65)
                    res = "C";
                else if (30 <= m + f && m + f < 50) {
                    res = "D";
                    if (r >= 50)
                        res = "C";
                } else if (m + f < 30)
                    res = "F";
                else
                    return;

                System.out.println(res);

            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}


Measured memory_bytes: 24252
n, a, b = map(int, input().split())
ans = 0
for i in range(int(n) + 1):
  ins = []
  sums = 0
  ins.append(i // 10000)
  ins.append((i % 10000) // 1000)
  ins.append((i % 1000) // 100)
  ins.append((i % 100) // 10)
  ins.append(i % 10)
  if sum(ins) >= a and sum(ins) <= b:
    ans += i
print(ans)

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

int main()
{
	string m, n;
	cin >> m >> n;
	
	if (m.length() > n.length())
		cout << "GREATER";
	else if (n.length() > m.length())
		cout << "LESS";
	else
	{
		if (m > n)
			cout << "GREATER";
		else if (m < n)
			cout << "LESS";
		else
			cout << "EQUAL";
	}
	
	return 0;
}

Measured memory_bytes: 256
using System;

namespace ConsoleApp_ITP1_8_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            string output = "";

            foreach (char s in input)
            {
                if (Char.IsUpper(s))
                    output += Char.ToLower(s);
                else
                    output += Char.ToUpper(s);
            }
            Console.WriteLine(output);
        }
    }
}



Measured memory_bytes: 9140
#include<iostream>
#include<cstring>
#include<cstdio>
#define MN 200000
using namespace std;
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;
}
int n,num[26];
long long ans=0;
char st[MN+5];
int main()
{
	scanf("%s",st+1);n=strlen(st+1);
	for(int i=1;i<=n;++i) ++num[st[i]-'a'];
	for(int i=0;i<26;++i) for(int j=i+1;j<26;++j) ans+=1LL*num[i]*num[j];
	printf("%lld\n",ans+1);
	return 0;
}



Measured memory_bytes: 384
///cREATED bY BERNARB.01
#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;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef priority_queue<int,vector<int>,greater<int>> pqil;
typedef priority_queue<int> pqig;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef priority_queue<pii> pqiig;
typedef vector<pii> vii;
typedef vector<piii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef map<int, int> mii;
#define mid ((l+r)/2)
#define PB push_back
#define PP pop_back
#define PF push_front
#define DF pop_front
#define F first
#define S second
#define MP make_pair
#define C continue
#define B break
#define R return
#define sz(v) (int)(v).size()
#define len(s) (int)(s).length()
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define clr(arr, x) memset((arr), (x), sizeof (arr))
#define loop(n) for(int i=0; i<(n); i++)
#define jloop(n) for(ll j=0; j<(n); j++)
#define rloop(n) for(ll i=(n)-1; i>=0; i--)
#define sgm(y) (((y)*((y)+1))/2)
const ll INF = 2e17+423;
const ll mod = 1e9+7; //998244353;
const ld pi = acos(-1.0);
const ld cmpf = 1e-9;
//__int128_t
//      -ASCII-
//a -> z | A -> Z | 0 -> 9
//97 122 | 65  90 | 48  57
#define endl '\n'
ll po(ll,ll);
















const int N = 1e4+9;
int h, n, a[N], b[N];
ll dp[N];
ll sol(int rem){
  if(rem<=0) R 0;
  ll &ret = dp[rem];
  if(ret!=-1) R ret;
  ret = sol(rem-a[0])+b[0];
  for(int i=1; i<n; i++){
    ret = min(ret, sol(rem-a[i])+b[i]);
  }
  R ret ;
}
int main() {
  /*#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  #endif // ONLINE_JUDGE*/
  ios::sync_with_stdio(0);
  cin.tie(0);
  clr(dp, -1);
  cin >> h >> n;
  loop(n) cin >> a[i] >> b[i];
  cout << sol(h) << '\n';
  R 0;
}
/*

*/




























































ll po(ll x, ll n){
  if(n==0) R 1;
  ll y = po(x, n/2);
  y = ((y)*(y));
  if(n%2) y = (y*(x));
  R y;
}


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

int main(){
    int a,b,c;
    int j=0;
    cin>>a>>b>>c;
    for(int i=a;i<=b;i++){
        if(c%i==0){
            j++;
        }
    }
		cout<<j<<endl;
	return 0;
}

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

int main(){
  int n , m;
  cin >> n >> m;
  
  int count[n] = {0};
  vector<int> a(n);
  for(int i = 0; i < m; i++){
      int a, b;
      cin >> a >> b;
      count[a-1]++;
      count[b-1]++;
  }

  
  for(int i = 0; i < n; i++){
	cout << count[i] << endl;
  }
}

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

int main() {
	int n; cin>>n;
	vector<int> letters(27,-1);

	while (n--) {
		vector<int> l(27,-1);
		string s; cin>>s;
		for (char c : s) {
			if (l[c-'a']==-1) l[c-'a']=1;
			else l[c-'a']++;
		}
		for (int i=0; i<27; i++) {
			if (l[i]==-1) letters[i]=0;
			else if (letters[i]==-1) letters[i]=l[i];
			else letters[i] = min(letters[i],l[i]);
		}
	}

	for (int i=0; i<27; i++) {
		for (int j=0; j<letters[i]; j++) {
			cout << (char)(i+'a');
		}
	}

	cout << endl;
	return 0;
}

Measured memory_bytes: 256
/*
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,fma")
*/
#include <bits/stdc++.h>
#define LL              long long
#define ll              long long
#define SL(n)           scanf("%lld",&n)
#define LF              double
#define SF(n)           scanf("%lf",&n)
 
#define pb              push_back
#define mp              make_pair
 
#define ON(n,i)         (n|(1LL<<i))
#define OFF(n,i)        (n&(~(1LL<<i)))
#define CHK(n,i)        (n&(1LL<<i))
 
#define ff              first
#define ss              second
 
#define SET(arr)        memset( arr , -1 , sizeof arr)
#define RESET(arr)      memset( arr,0,sizeof arr)
 
#define srt(v)          sort(v.begin(),v.end())
#define uniq(v)			v.resize(distance(v.begin(),unique(v.begin(),v.end())))
#define found( s,d )    (s.find(d) != s.end())
 
#define FOR(i,s,e)      for( LL i = s ; i<=e ; i++ )
#define RFOR(i,e,s)     for( LL i = e ; i>=s ; i-- )
         
 
#define FILEIN          freopen("in.txt","r",stdin)
#define FILEOUT         freopen("WA.txt","w",stdout)
 
#define DEBUG(x)        cerr<<#x<<" = "<<x<<endl
#define PRINTALL(v)     {cerr<<endl<<"Printing: "<<#v<<endl;for(LL i = 0 ; i<v.size(); i++) DEBUG(v[i]); cerr<<endl;}
 
using namespace std;
const LL inf = 1e9;

const LL lim = 1010;
LL dp[lim][lim];
LL c[lim], t[lim];
LL N,T;

LL F( LL pos, LL rem ){
    if(rem<0) return inf;
    if(pos == 0){
        if( rem == T ) return inf;
        else return 0;
    }
    LL &ret = dp[pos][rem];
    if(ret!=-1) return ret;
    ret = min( F(pos-1, rem) , c[pos] + F(pos-1,rem-t[pos]) );
    return ret;
}


int main(){
    SET(dp);
    
    SL(N); SL(T);
    FOR(i,1,N) SL(c[i]), SL(t[i]);
    LL ans = F(N,T);
    if(ans>=inf) cout<<"TLE"<<endl;
    else cout<<ans<<endl; 
return 0;}

Measured memory_bytes: 11580
#include<stdio.h>
int main(){
	int n,m,l;
	int Avector[100][100];
	int Bvector[100][100];
	scanf("%d%d%d",&n,&m,&l);
	for(int i=0;i<n;i++)for(int j=0;j<m;j++)scanf("%d",&Avector[i][j]);
	for(int i=0;i<m;i++)for(int j=0;j<l;j++)scanf("%d",&Bvector[i][j]);
	long int sum=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<l;j++){
			for(int k=0;k<m;k++){
				sum += Avector[i][k]*Bvector[k][j];
			}
			printf("%ld",sum);
			if(j!=l-1)printf(" ");
			sum = 0;
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2108
use std::cmp;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();

    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let b: Vec<u32> = (0..n - 1).map(|_| read()).collect();

    let mut a: u32 = b[0];

    for i in 1..b.len() {
        a += cmp::min(b[i - 1], b[i])
    }
    a += *b.last().unwrap();
    println!("{}", a);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#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(){
	vector<int> a(3);
	rep(i, 3) cin >> a.at(i);
	sort(a.begin(), a.end());
	int ans = 1;
	rep(i, 2) if(a.at(i) != a.at(i+1)) ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>

using namespace std;

typedef long long ll;

mt19937 rnd(228);

const int N = 700 + 7;

bool g[N][N];
bool u[N];
int a[N];

int x = 0, y = 0;

int n;

void dfs(int v, int col)
{
    if (u[v])
    {
        if (a[v] != col)
        {
            cout << -1 << '\n';
            exit(0);
        }
        return;
    }
    u[v] = true;
    a[v] = col;
    if (col == 0) x++;
    else y++;
    for (int i = 0; i < n; i++)
    {
        if (g[v][i])
        {
            dfs(i, col ^ 1);
        }
    }
}

bitset <N> dp;

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    int m;
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (i != j)
            {
                g[i][j] = 1;
            }
        }
    }
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a][b] = g[b][a] = 0;
    }
    dp[0] = 1;
    for (int i = 0; i < n; i++)
    {
        if (!u[i])
        {
            x = 0, y = 0;
            dfs(i, 0);
            dp = dp << x | dp << y;
        }
    }
    int ans = 1e9;
    for (int i = 0; i <= n; i++)
    {
        if (dp[i])
        {
            ans = min(ans, i * (i - 1) / 2 + (n - i) * (n - i - 1) / 2);
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 768
/*input
30
*/
 
 
#include <bits/stdc++.h>
 
using namespace std;
 
#define ld long double
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vpll vector < pair<long long,long long> >
#define fill(a,val)  memset(a,val, sizeof (a))
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define mp make_pair
#define pb push_back
#define f first
#define se second
#define all(cont) cont.begin(), cont.end()
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MAX   1e9
#define MIN  -1e9
typedef map<long long int, long long int> mpi;
typedef set<long long int> seti;
typedef multiset<long long int> mseti;
typedef priority_queue<long long int> pq;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i, n)    for(long long int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define repn(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define PI 3.14159265
#define dbg(x) cerr << "\n" << (#x) << " = " << (x) << endl ;
//#define cerr if(false)cerr
 
#define mod 998244353
 
struct node{
    ll val;
};
struct Interval {int start, end;};
bool compare(struct node n1, struct node n2) {
    return (n1.val < n2.val);
}
 
 
 ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 





 
int main() 
{
    ll x; cin>>x;
    if(x>=30)
    	cout<<"Yes"<<endl;
    else
    	cout<<"No"<<endl;
    return 0;  
}
 

Measured memory_bytes: 3636
from itertools import accumulate

*S, = map(lambda x: 1 if x == 'A' else 2, input())
*T, = map(lambda x: 1 if x == 'A' else 2, input())
# A=1,B=2

acc_s = (0,) + tuple(accumulate(S))
acc_t = (0,) + tuple(accumulate(T))

Q = int(input())
for _ in range(Q):
    sl, sr, tl, tr = map(int, input().split())
    sl -= 1
    tl -= 1
    diff = (acc_t[tr] - acc_t[tl]) - (acc_s[sr] - acc_s[sl])
    print('YES' if diff % 3 == 0 else 'NO')


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

int main(){
	int q,a,b;
	string str,odr,p,pri;
	cin >> str >> q;

	for(int i=0; i<q; i++){

		cin >> odr;
        
        if( odr == "print"){
        	cin >> a >> b;
        	cout << str.substr(a,b-a+1) << endl; //no problem
        	//pri = str.substr(a-1,b-a+1);
        	//cout << pri;
        }
        
        else if( odr == "reverse"){
        	cin >> a >> b;
        	string rev=str.substr(b,1);
        	for(int i=0; i<b-a; i++){
        	    rev += str.substr(b-i-1,1);
        	}
        	str = str.replace(a,b-a+1,rev);

        } else {
            cin >> a >> b >> p;
            str = str.replace(a,b-a+1,p);     	
        }
	}

	return 0;
}

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

int main() {
    double a, b, x; cin >> a >> b >> x;
    if (a * a * b / 2 > x) {
        double v = x * 2 / b / a;
        printf("%.12f\n", atan2(b, v) * 180 / acos(-1));
    } else {
        double u = x * 2 / a / a;
        u = 2 * b - u;
        printf("%.12f\n", atan2(u, a) * 180 / acos(-1));
    }
    return 0;
}

Measured memory_bytes: 256
import math 
import sys
N=int(input())
A=[int(i) for i in input().split()]
for i in range(N):
    A[i]=A[i]-i-1
A.sort()
ans =0
a=A[N//2]
for i in range(N):
    ans+=abs(A[i]-a)
print(ans)

Measured memory_bytes: 26832
//test submit
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using LayoutKind = System.Runtime.InteropServices.LayoutKind;

public static class P
{
    public static void Main()
    {
        Console.WriteLine(7 - Array.IndexOf(new string[] { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" }, Console.ReadLine()));
    }
}


Measured memory_bytes: 13024
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll H, W;
  cin >> H >> W;
  vector<string> MAP(H);
  for (int i = 0; i < H; i++) {
    cin >> MAP[i];
  }
  vector<string> new_MAP(H);
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (MAP[i][j] == '#') {
        cout << '#';
        continue;
      }
      ll cnt = 0;
      if (i - 1 >= 0 && MAP[i - 1][j] == '#') cnt++;
      if (j - 1 >= 0 && i - 1 >= 0 && MAP[i - 1][j - 1] == '#') cnt++;
      if (j + 1 < W && i - 1 >= 0 && MAP[i - 1][j + 1] == '#') cnt++;
      if (j - 1 >= 0 && MAP[i][j - 1] == '#') cnt++;
      if (j + 1 < W && MAP[i][j + 1] == '#') cnt++;
      if (i + 1 < H && MAP[i + 1][j] == '#') cnt++;
      if (i + 1 < H && j - 1 >= 0 && MAP[i + 1][j - 1] == '#') cnt++;
      if (i + 1 < H && j + 1 < W && MAP[i + 1][j + 1] == '#') cnt++;
      cout << cnt;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int num1,num2;
	cin>>num1>>num2;
	if(num1>=1 && num1<=9)
	{
		if(num2>=1 && num2<=9)
		 cout<<num1*num2;
		else
		 cout<<"-1";
	}
	else
	 cout<<"-1";
	return 0;
}

Measured memory_bytes: 3624
n = int(input())
xl = [list(map(int, input().split())) for _ in range(n)]
ran = [[xl[i][0]-xl[i][1], xl[i][0]+xl[i][1]] for i in range(n)]
ran = sorted(ran, key=lambda x:x[1])
ans = 1
right = ran[0][1]
for i in range(n):
  l, r = ran[i]
  if l >= right:
    ans += 1 
    right = r 

print(ans)

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

int main(){
  string s;
  cin >> s;
  if(s[0] == '7' || s[1] == '7' || s[2] == '7'){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }

}

Measured memory_bytes: 3596
import collections

N = int(input())
lst = list(map(int, input().split()))
c = dict(collections.Counter(lst))
ans = 2 ** (N // 2)
if (N % 2 != 0):
  for i in range(0, N, 2):
    if (i not in c.keys()):
      ans = 0
      break
    else:
      if (i == 0):
        if (c[i] != 1):
          ans = 0
          break
      else:
        if (c[i] != 2):
          ans = 0
          break
else:
  for i in range(1, N, 2):
    if (i not in c.keys()):
      ans = 0
      break
    else:
      if (c[i] != 2):
        ans = 0
        break
      
print(ans % ((10 ** 9) + 7))

Measured memory_bytes: 16352
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var stdin = bufio.NewScanner(os.Stdin)

func main() {
	arr := scanArrayInt()
	a, b, c, d := arr[0], arr[1], arr[2], arr[3]
	if b < c || d < a {
		fmt.Println("0")
		return
	}
	var start, end = map[bool]int{true: a, false: c}[a > c], map[bool]int{true: b, false: d}[d > b]
	fmt.Println(end - start)
}
func scanArrayInt() []int {
	var ret = []int{}
	stdin.Scan()
	for _, s := range strings.Split(stdin.Text(), " ") {
		i, _ := strconv.Atoi(s)
		ret = append(ret, i)
	}
	return ret
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

int main(){
    string s;
  	cin >> s;
  int n = s.size() - 1;
  if ( s.at(n) != 's' ) cout << s + 's' << endl;
  if ( s.at(n) == 's' ) cout << s + "es" << endl;
  
}



Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	long N,A[200000],B[200000],l,r,m,ans=0,L,R;
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>A[i];
		B[i]=i-A[i];
		A[i]=i+A[i];
	}
	sort(B,B+N);
	for(int i=0;i<N;i++){
		
		l=-1;r=N;
		while(r-l>1){
			m=(r+l)/2;
			if(A[i]>B[m])l=m;
			else r=m;
		}L=l;
		
		l=-1;r=N;
		while(r-l>1){
			m=(r+l)/2;
			if(A[i]<B[m])r=m;
			else l=m;
		}R=r;
		
		if(R-L>1)ans+=R-L-1;
	}
	cout<<ans;
	return 0;
}

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

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

long long MOD = 1000000000 + 7;

int N;
string ALPHA = "abcdefghijklmn";

void solve(string s, int max_val, int n){
  if(n < N){
    for(int i = 0; i <= min(n,max_val+1); i++){
      solve(s + ALPHA[i], max(max_val, i), n+1);
    }
  } else { 
    cout << s << endl;
  }
}

int main(){
  cout << setprecision(10);
  cin >> N;
  string s = "";
  solve(s, 0,0);

}


Measured memory_bytes: 1536
n=gets.to_i
a=gets.split.map(&:to_i).sort
cnt=0
n=a.size
for i in 0...n-2
  for j in i+1...n-1
    for k in j+1...n
      if a[i]+a[j]>a[k]&&(!(a[i]==a[j]||a[j]==a[k]))
        cnt+=1
      end
    end
  end
end
puts cnt


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

int main() {
    int a, b;
    cin >> a >> b;

    string s;
    cin >> s;

    int cnt = 0;
    bool c = false;

    for (int i = 0, n = a + b + 1; i < n; i++)
        if (s.at(i) == '-') {
            cnt++;

            if (i == a)
                c = true;
        }

    cout << ((cnt == 1 && c) ? "Yes" : "No") << endl; 
}

Measured memory_bytes: 3644
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# Set 2 dimension list
def dim2input(N):
    li = []
    for _ in range(N):
        li.append(list(map(int, input())))
    return li

# --------------------------------------------

dp = None

def main():
    X, Y = input().split()

    if X > Y:
        print(">")
    elif X < Y:
        print("<")
    else:
        print("=")

main()


Measured memory_bytes: 4800
#include <iostream>
#include <queue>
#include <stack>
using namespace std;
const int maxn=1e6+5;
char str[maxn];
int main()
{
    cin>>str;
    stack <int>ans;
    for(int i=0;str[i]!='\0';i++)
    {
        if(str[i]=='0')
        {
            ans.push(0);
        }
        else if(str[i]=='1')
        {
            ans.push(1);
        }
        else if(str[i]=='B')
        {
            if(ans.size())ans.pop();
        }
    }
    int a[maxn];
    int cnt=0;
    while(ans.size()>=1)
    {
        a[cnt++]=ans.top();
        ans.pop();
    }
    for(int i=cnt-1;i>=0;i--)
        cout<<a[i];
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<b;i++)
inline constexpr int intpow(ll a,ll b){
    if(b==0) return 1;
    ll ans=intpow(a,b/2);
    return ans*ans*(b&1?a:1);
}
int main(){
    int n,y;
    cin>>n>>y;
    rep(i,0,n+1){
        rep(j,0,n+1-i){
            if(10000*i+5000*j+1000*(n-i-j)==y){
                cout<<i<<" "<<j<<" "<<n-i-j;
                return 0;
            }
        }
    }
    cout<<"-1 -1 -1";
}

Measured memory_bytes: 256
M=10**9+7;H,W,A,B=map(int,input().split());Z=C=1
for I in range(H-1):Z=C=C*(W+H-B-2-I)*pow(I+1,M-2,M)%M
for I in range(1,H-A):C=C*(B-1+I)*(H-I)*pow(I*(W+H-B-1-I),M-2,M)%M;Z+=C
print(Z%M)

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;

vec<vii> dp;
/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    cout << fixed << setprecision(15);

    string s; cin >> s;
    int n = s.size();
    int K; cin >> K;
    dp.resize(101, vii(4, vi(2)));
    // i桁までで, 非ゼロをj個使って作れるs以下の数の個数
    dp[0][0][0] = 1;
    rep(i,n)rep(j,4)rep(k,2) {
        // nd : 次に見る桁の数字
        int nd = s[i]-'0';
        // 0~9のどれに遷移するか
        rep(d,10) {
            int ni = i +1, nj = j, nk = k;
            if(d != 0) nj++;  // 非ゼロを使った
            if(nj > K) continue;  // 非ゼロはK回までしか使えない
            if(k == 0) {  // そこまでの桁はsと一致(これ以降の桁の数字はsのものを超えない)
                if(d > nd) continue;
                if(d < nd) nk = 1;
            }  // else -> そこまでの桁はsより小さい。(これ以降の桁は自由に選べる)
            dp[ni][nj][nk] += dp[i][j][k];
        }
    }
    int ans = dp[n][K][0] + dp[n][K][1];
    cout << ans << '\n';
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");
		long n = Long.parseLong(str[0]);
		long a = Long.parseLong(str[1]);
		long b = Long.parseLong(str[2]);

		long x = n / (a + b);
		long min = Math.min(n % (a + b), a);
		System.out.println(x * a + min);
	}
}


Measured memory_bytes: 23252
n=int(input())
dict={}
for i in range(0,n):
  temp=str(input())
  if temp in dict:
    dict[temp]=dict[temp]+1
  else:
    dict[temp]=1
temp=max(dict.values())
max_list=[dict[0] for dict in dict.items() if dict[1]==temp] 
max_list.sort()
for i in range(0,len(max_list)):
  print(max_list[i])

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

int main() {
  long A, B, K;
  cin >> A >> B >> K;
  long a = max(0L, A - K);
  long b = max(0L, B - (K - (A - a)));
  cout << a << "\n";
  cout << b << "\n";
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string ans = "No";
  while (n != 0) {
    int temp = n % 10;
    if (temp==7) ans = "Yes";
    n = n / 10;
  }
  cout << ans;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

#define MAX_V 100001
struct edge {
	int to;
	int cost;
};
vector<edge> G[MAX_V];
int d[MAX_V];

void dijkstra(int s) {
	priority_queue<P, vector<P>, greater<P> > que;
	fill(d, d + MAX_V, INF);
	d[s] = 0;
	que.push(P(0, s));

	while (!que.empty()) {
		P p = que.top();
		que.pop();
		int v = p.second;
		if (d[v] < p.first) continue;

		for (int i = 0; i < G[v].size(); ++i) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

void solve_abc_d() {
	ll n;

	cin >> n;

	ll a, b;
	edge e;
	rep(i, n - 1) {
		cin >> a >> b;
		e.to = a;
		e.cost = 1;
		G[b].push_back(e);
		e.to = b;
		e.cost = 1;
		G[a].push_back(e);
	}

	int d1[MAX_V], dn[MAX_V];
	dijkstra(1);
	rep1(i, n) {
		d1[i] = d[i];
	}
	dijkstra(n);
	rep1(i, n) {
		dn[i] = d[i];
	}

	ll f = 0;
	ll s = 0;
	rep1(i, n) {
		if (d1[i] <= dn[i]) {
			f++;
		}
		else {
			s++;
		}
	}

	if (f > s) {
		cout << "Fennec\n";
	}
	else {
		cout << "Snuke\n";
	}
}

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

	solve_abc_d();

	return 0;
}


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

int main() {
	int n, x, y;
	cin >> n >> x >> y;
	map<int, int> mp;
	for (int i = 1; i <= n - 1; i++) {
		for (int j = i + 1; j <= n; j++) {
			int ansi;
			if (i < x) {
				if (j <= x) ansi = j - i;
				else if (j <= y) ansi = x - i + min(j - x, y - j + 1);
				else ansi = x - i + 1 + j - y;
			}
			else if (i < y) {
				if (j <= y) ansi = min(j - i, i - x + 1 + y - j);
				else ansi=min(j - i, i - x + 1 + j - y);
			}
			else ansi = j - i;
			mp[ansi]++;
		}
	}
	for(int i=1;i<=n-1;i++) cout << mp[i] << endl;
}

Measured memory_bytes: 384
A, B, K = map(int, input().split())
#A, B, K = 12, 8, 2


if A > B:
	tmp = B
	B = A
	A = tmp
	#print(A,B)

d = []

for i in range(1,A+1):
	if A % i == 0 and B % i == 0:
		d.append(i)

d.reverse()
print(d[K-1])

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


#define  SZ(items) (int)items.size()
#define  CLR(a)  memset(a,0,sizeof(a))
#define  SET(a)  memset(a,-1,sizeof(a))

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



template <class T> inline T biton(T n, T pos)
{
    return n | ((T)1 << pos);
}
template <class T> inline T bitoff(T n, T pos)
{
    return n & ~((T)1 << pos);
}
template <class T> inline T ison(T n, T pos)
{
    return (bool)(n & ((T)1 << pos));
}
template <class T> inline T gcd(T a, T b)
{
    while (b)
    {
        a = a % b;
        swap(a, b);
    }
    return a;
}
template <class T> inline T bigmod(T p, T e, T m)
{
    T ret = 1;
    for (; e > 0; e >>= 1)
    {
        if (e & 1)
            ret = (ret * p) % m;
        p = (p * p) % m;
    }
    return (T)ret;
};

#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1)
{
    cerr << name << " is " << arg1 << std::endl;
}
template < typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " is " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define debug(...)
#endif


void solve()
{
    double n;
    cin>>n;

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

        long long d=i*1.08;

        if(d==n){
            cout<<i<<endl;
            return;
        }
    }

    cout<<":("<<endl;

}

int main()
{
    ios_base::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    cout.tie(nullptr);
    cin.tie(nullptr);


    int t = 1;

    while (t--)
    {
        solve();
    }

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
int main(){
	int a,b,c,d;
	scanf("%d %d %d",&a,&b,&c);
	if (a>c){
		d=c;
		c=a;
		a=d;
	}
	if (b>c){
		d=c;
		c=b;
		b=d;
	}
	if (a>b){
		d=a;
		a=b;
		b=d;
	}
	printf("%d %d %d\n",a,b,c);
	return 0;
}


Measured memory_bytes: 2760
use std::env;
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn main() {
    // main の引数
    /*
        引数なしのときargs.len() = 1;
    */
    let args: Vec<String> = env::args().collect();

    let a = read::<i32>();
    let b = read::<i32>();

    let av = (a + b + 1) / 2;

    println!("{}", av);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long i = 0; i < n; i++)
#define erep(i, n) for(long i = 1; i <= n; i++)
const long MOD = 1000000007;
#define all(a) a.begin(), a.end()
#define eall(a) a.begin()+1, a.end()
#define show(ans)  cout << ans << endl;

unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){
long N;
cin >> N;
vector<long> A(N+1);
erep(i, N) cin >> A[i];
vector<long> gcdleft(N+2);
gcdleft[0]=1;
gcdleft[1]=A[1];
vector<long> gcdright(N+2);
gcdright[N]=A[N];
gcdright[N+1]=1;
long ans = 0;
long tmp;
if(N != 2){
    for(long i = 2; i<=N;i++){
        gcdleft[i] = euclidean_gcd(gcdleft[i-1], A[i]);
    }
    for(long i = N-1; i>=1;i--){
        gcdright[i] = euclidean_gcd(gcdright[i+1], A[i]);
    }
ans = max(ans, gcdleft[N-1]);
ans = max(ans, gcdright[2]);

    for(long i = 2; i<=N-1;i++){
        tmp = euclidean_gcd(gcdleft[i-1], gcdright[i+1]);
        ans = max(ans, tmp);
    }
}
else{
    ans = max(A[1], A[2]);
}
show(ans);

return 0;
}

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


using namespace std;

using ll   = long long;
using ii   = pair   < int , int >;
using i3   = pair   < int , ii  >;
using li   = pair   < ll  , int >;
using lii  = pair   < ll  , ii  >;
using pll  = pair   < ll  , ll  >;
using vi   = vector < int       >;
using vl   = vector < ll        >;
using vii  = vector < ii        >;
using vli  = vector < li        >;
using vpll = vector < pll       >;
using vi3  = vector < i3        >;
using vlii = vector < lii       >;


const int N = 2e5 + 5;
const ll INF = 1e17 + 7;
const double eps = 1e-9 , PI = acos(-1);


int n , m;

int dis[N];
int in[N];
bool vis[N];
vi adj[N];
int ans = 0;

void dfs(int u){
    vis[u] = 1;
    ans = max(ans , dis[u]);
    for(int v : adj[u]){
            dis[v] = max(dis[v] , dis[u] + 1);
            in[v] --;
            if(in[v] == 0)dfs(v);
    }
}


void solve(int testCase){

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

    for(int i = 0 ; i < m ; i ++){
            int u , v; scanf("%d %d" , &u , &v);

            adj[u].push_back(v);
            in[v] ++;
    }

    for(int i = 1 ; i <= n ; i ++){
            if((!vis[i]) && (in[i] == 0))dfs(i);
    }

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

}

main(){

    int t = 1;
    // scanf("%d" , &t);

    for(int testCase = 1 ; testCase <= t ; testCase ++){
            solve(testCase);
    }

    return 0;
}


Measured memory_bytes: 12672
#include <stdio.h>
int main(void)
{
	long x;
	int a,b,ans;
	scanf("%ld",&x);
	a = x / 500;
	x = x - 500*a;
	b = x / 5;
	ans = 1000*a + 5*b;
	printf("%d",ans);
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> sum(N);
  long ans = 0;
  for (int i = 0, a; i < N && cin >> a; i++) {
    if (i + a < N) sum.at(i + a)++;
    if (i - a >= 0) ans += sum.at(i - a);
  }
  cout << ans << "\n";
}

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

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

  int maxval = 0;
  int cnt = 0;
  for (int i=0; i<N; i++) {
    if (S[i] == 'I')
      cnt++;
    else
      cnt--;
    maxval = max(cnt, maxval);
  }

  cout << maxval << endl;

  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

t = A[0]
indices = [0]
seq = [t]
for i in range(1,N):
  if A[i] > t:
    t = A[i]
    indices.append(i)
    seq.append(t)

M = len(seq)
delta = [seq[0]]+[seq[i+1]-seq[i] for i in range(M-1)]

temp = [0]*M
count = [0]*M


from bisect import bisect_left
for a in A:
  p = bisect_left(seq, a)
  count[p] += a - seq[p]
  temp[p] += 1

t = 0
for i in reversed(range(M)):
  t += temp[i]
  temp[i] = t

for i in range(M):
  count[i] += temp[i]*delta[i]

result = [0]*N
for i,c in zip(indices,count):
  result[i] = c

for r in result:
  print(r)

Measured memory_bytes: 24216
#include<stdio.h>
#include<math.h>
#include<iostream>
using namespace std;
int main()
{
	int n;
	int i;
	int ans = 0;
	scanf("%d", &n);
	for(i = 1; i <= n; i++)
	ans = ans + i;
	printf("%d\n", ans);

}

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

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i=0; i<n; i++) cin >> v[i];
    sort(v.rbegin(), v.rend());
    int ans = 0;
    for(int i=0; i<n; i++){
        if(i%2 == 0) ans += v[i];
        else ans -= v[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#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 fst first
#define scd second
#define PB push_back
#define MP make_pair
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define rep(i,x) for(int i=0;i<(x);++i)
#define rep1(i,x) for(int i=1;i<=(x);++i)
#define rrep(i,x) for(int i=(x)-1;i>=0;--i)
#define rrep1(i,x) for(int i=(x);i>=1;--i)
#define FOR(i,a,x) for(int i=(a);i<(x);++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
 
template<typename T>T&get(){T a;cin >> a;return a;}
template<typename T>T&rev(T&a){reverse(all(a));return a;}
template<typename T>istream&operator>>(istream&is,vector<T>&vec){rep(i,vec.size())is>>vec[i];return is;}
template<typename T>vector<T>&sort(vector<T>a){sort(all(a));return a;}
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
 
const int inf = 1e9;
const ll linf = 3e18;
 
struct edge {
    int to, cost, time;
    edge(int to0,int cost0,int time0) {
        to = to0; cost = cost0; time = time0;
    };
};
 
int N, M;
 
vector<edge> G[100];
int d[100];
 
void dijkstra(int s, int mode)
{
    priority_queue<pii, vector<pii>, greater<pii> > q;
 
    fill(d, d + M, inf);
    d[s] = 0;
 
    q.push(MP(0, s));
 
    while (q.size()) {
        pii p = q.top(); q.pop();
        int v = p.scd;
        if (p.fst > d[v]) continue;
        rep(u, G[v].size()) {
            edge e = G[v][u];
            int a = mode == 0 ? e.cost : e.time;
            if (d[e.to] > d[v] + a) {
                d[e.to] = d[v] + a;
                q.push(MP(d[e.to], e.to));
            }
        }
    }
}
 
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
 
    while (cin >> N >> M, N || M) {
        rep(i, M) G[i].clear();
 
        rep(i, N) {
            int a, b, cost, time; cin >> a >> b >> cost >> time; a--; b--;
            G[a].PB(edge(b, cost, time));
            G[b].PB(edge(a, cost, time));
        }
 
        int K; cin >> K;
 
        rep(i, K) {
            int p, q, r; cin >> p >> q >> r; p--; q--;
            dijkstra(p, r);
            cout << d[q] << endl;
        }
    }
}

Measured memory_bytes: 1304
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string S; cin >> S;
    int ans = 777;
    if(S == "RRR") ans = 3;
    if(S == "RRS" || S == "SRR") ans = 2;
    if(S == "SSS") ans = 0;
    if(ans == 777) ans = 1;
    cout << ans << endl;
}

Measured memory_bytes: 3592
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const int N=1e5+10;
int gcd(int a,int b){return !b?a:gcd(b,a%b);}
int n,a[N];
int pre[N],suf[N];
int main(){
	scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	pre[1]=a[1];for(int i=2;i<=n;i++)pre[i]=gcd(pre[i-1],a[i]);
	suf[n]=a[n];for(int i=n-1;i;i--)suf[i]=gcd(suf[i+1],a[i]);
	int ans=max(pre[n-1],suf[2]);
	for(int i=2;i<=n-1;i++)ans=max(ans,gcd(pre[i-1],suf[i+1]));
	cout<<ans;
}

Measured memory_bytes: 1408
var
	N,T:int64;
begin
	read(N);
	T:=1;
	while N>=T do begin
		dec(N,T);
		T:=T*26;
	end;
	while T>1 do begin
		T:=T div 26;
		write(Chr(N div T+97));
		N:=N mod T;
	end;
end.

Measured memory_bytes: 1388
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    ll n,k,ans=0;
    cin>>n>>k;
    rep(i,n){
        ll a=i+1;
        if(a<=k) continue;
        else ans+=n/a*(a-k)+(n%a-k+1)*(n%a-k+1>0);
    }
    cout<<ans*(k>0)+n*n*(!k);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define vll vector<ll>
#define pll pair<ll,ll>
#define vp vector<pll>
#define test int tcase; cin>>tcase; for(int tc = 1; tc <= tcase; tc++)
#define inp(a,n,f) ll a[n+f];for(ll hh=f;hh<n+f;hh++)cin>>a[hh];
#define printdecimal(k) cout<<fixed<<setprecision(k);
#define ub upper_bound
#define lb lower_bound
#define mapp map<ll,ll>
#define mem(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(),v.end()
#define qll queue<ll>
#define sll set<ll>
#define inf LLONG_MAX
#define fileio freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout)
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}


signed main()
{
    fastio;
    //fileio;
	ll n,i;
	cin>>n;
	ll a[n],b[n],c[n],dp[n][3];
	for(i=0;i<n;i++)
		cin>>a[i]>>b[i]>>c[i];		
	dp[0][0]=a[0];
	dp[0][1]=b[0];
	dp[0][2]=c[0];
	for(i=1;i<n;i++)
	{
		dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
		dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
		dp[i][2]=max(dp[i-1][1],dp[i-1][0])+c[i];
	}
	cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
	int A,B,C;
	cin>>A>>B>>C;
	int ans=A%B;
	int i=1;
	while(true){
		if((A*i)%B==C){
			ce("YES")
			return 0;
		}else{
			if(i!=1&&(A*i)%B==ans){
				ce("NO")
				return 0;
			}
		}
		i++;
	}
	
}

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

using namespace std;
typedef long long ll;

int main() {
    int n, h; cin >> n >> h;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    int max_a = *max_element(a.begin(), a.end());
    sort(b.begin(), b.end());
    int tot_b = 0;
    int ans = 1001001010;
    for (int i = 1; i <= n; i++) {
        int num = i;
        tot_b += b[n-i];
        int tmp_h = h - tot_b;
        if (tmp_h > 0)
            num += ceil((double)tmp_h / (double)max_a);
        ans = min(ans, num);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1152
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

int main(void)
{
    int N;
    cin >> N;

    string S;
    cin >> S;

    string s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    string ss = s + s;
    for (int i = 0; i < (int)S.size(); i++)
        cout << ss[S[i] - 'A' + N];
    cout << endl;

    return 0;
}


Measured memory_bytes: 256