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

long long solve(long long N){
    //cout << "aaa"<<endl;
    long long sum = 0;
    long long target = N;
    
    while(target>=1){
        sum+=target%10;
        target /=10;
    }
    return sum;
}


int main(void){
    long long N;
    cin >> N;
    long long Ndummy = N;
    long long keta = 1;
    long long  cont = 0;

    
    string check = to_string(N);
    
    if(check.size()==1){
        cout << N << endl;
        return 0;
        
    }
    
    
    bool flag = true;
    for(int i = 1; i < check.size();i++){
        //cout << check[i]<<endl;
        if(check[i]!= '9')flag = false;
    }
    //cout <<"flag"<<endl;
    if(flag==true){
        //cout <<"flag"<<endl;
        cout << solve(N)<<endl;
        return 0;
    }
    

    //cout <<"flag"<<endl;
    
    while(Ndummy>=1){
        keta *= 10;
        Ndummy /=10;
        cont++;
    }

    long long moto;
    //cout << N <<" "<< keta <<" "<< N/keta <<endl;
    if(N*10/keta>=1&&N*10/keta!=9){
        
        moto = N*10/keta-1;
        //cout << cont <<endl;
        for(int i = 0; i < cont-1;i++){
            moto += 9;
        }

        
    }else if(N*10/keta==9){
        
        moto = N*10/keta;
        //cout << moto <<endl;
        for(int i = 0; i < cont-2;i++){
            moto += 9;
        }
        moto += 8;
        
    }else{
        moto =9;
        for(int i = 0; i < cont-1;i++){
            moto += 9;
        }
    }
    
    cout << moto << endl;
    
}



Measured memory_bytes: 256
import java.util.*;
import java.lang.Math;
import java.math.BigDecimal;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = gcd(A, B);
        System.out.println((long)A * (long)B / C);
    }
    
    public static int gcd(int A, int B){
        int tmp = 0;
        if(A < B){
            tmp = A;
            A = B;
            B = tmp;
        }
        int C = A % B;
        while(C != 0){
            A = B;
            B = C;
            C = A % B;
        }
        return B;
    }
}


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

#define INF 1001001001
#define MAX 1e18

int op(int a, int b) { return max(a,b); }
int e() { return -1; }
int target;
bool f(int x) { return target > x; }

int main() {
  int n, q;
  cin >> n >> q;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  vector<int> ans;
  segtree<int, op, e> st(a);
  while (q--) {
    int t; cin >> t;
    if (t==1) {
      int x, v; cin >> x >> v;
      st.set(--x,v);
    } else if (t==2) {
      int l, r; cin >> l >> r;
      ans.push_back(st.prod(--l,r));
    } else {
      int x; cin >> x >> target;
      ans.push_back(st.max_right<f>(--x)+1);
    }
  }
  for (auto a : ans) cout << a << endl;

  return 0;
}


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

using namespace std;
using p = pair<long long, int>;
#define INF 100000000

int main(){
	string s;
	cin >> s;
	
	if(s == "ABC")
	 cout << "ARC" << endl;
	 else cout << "ABC" << endl;
	
}

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



int main()
{
	int n, q, num, sum, i, j, max = 0, min = 0;
	int *p = NULL;

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

	p = (int *)malloc((n + 1)*sizeof(int));

	if (p)
	{
		for (i = 1; i < n + 1; i++)
		{
			*(p + i) = 0;
		}

		for (i = 0; i < q; i++)
		{
			scanf("%d %d", &num, &sum);

			p[num] += sum;

			if (p[num] > max || p[num] == max && num < min)
			{
				max = p[num];
				min = num;
			}
			else if (num==min && p[num] < max )
			{
				max = min = 0;
				for (j = 1; j < n + 1; j++)
				{
					if (p[j]!=0 && p[j] > max)
					{
						max = p[j];
						min = j;
					}
				}
			}

		
				
			printf("%d %d\n", min, p[min]);
		}
	}



	return 0;
}


Measured memory_bytes: 4504
#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;

#define TRACE
#ifdef TRACE
#define tr(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << 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) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define tr(...)
#endif

#define ll long long
#define ld long double 
#define endl "\n"
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (ll)(a.size())
#define all(a) a.begin(), a.end() 
#define fr(i,n) for(i=1;i<=n;i++)
#define rp(i,n) for(i=0;i<n;i++)
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the iterator to kth largest element.(0-based)
typedef pair<ll, ll> ii;
typedef vector<ll> vl;
const ll N = 200010;
ll mod=1e9+7;

ll ffmod(ll x, ll y, ll mod)
{
    ll rt=1;
    while(y)
    {
        if(y&1ll) rt=(rt*x)%mod;
        x=(x*x)%mod, y/=2ll;
    }
    return rt;
}

ll dp[410][410], a[410], pre[410];

int main()
{
    FIO;
    ll n,i,j,tp,k;
    cin>>n;
    fr(i,n) cin>>a[i], pre[i]=a[i]+pre[i-1];
    for(i=2;i<=n;i++)
        for(j=1;j+i-1<=n;j++)
        {
            tp=j+i-1;
            dp[j][tp]=1e18;
            for(k=j;k<tp;k++)
                dp[j][tp]=min(dp[j][tp], dp[j][k]+dp[k+1][tp]);
            dp[j][tp]+=(pre[tp]-pre[j-1]);
//            tr(j,tp,dp[j][tp]);
        }
    cout<<dp[1][n]<<endl;
    return 0;
}


Measured memory_bytes: 1536
/*
for (int i = 0; i < N; ++i){}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<int,int> point;
#define rep(i,n) for(i,0,n)

// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
 

int main() {
	// 入力
	ll n;
	cin >> n;
	ll v[n];
	for (ll i = 0; i < n; ++i) cin >> v[i];
	
 
	// 解法
	ll a1[100000+10]={0};
	ll a2[100000+10]={0};
	for (ll i = 0; i < n/2; ++i){
		a1[v[i*2]] += 1;
		a2[v[i*2+1]] += 1;
	}
	// cout << "a1[0] " << a1[0] << endl;
	// cout << "a2[0] " << a2[0] << endl;
	
	ll max1 = 0;
	ll max2 = 0;
	ll max_idx1 = 0;
	ll max_idx2 = 0;
	
	for (ll i = 0; i < 100000; ++i){
		if (a1[i]>max1){
			max1 = a1[i];
			max_idx1 = i;
		}
		if (a2[i]>max2){
			max2 = a2[i];
			max_idx2 = i;
		}
	}
	
	sort(a1, a1 + 100000, greater<ll>());
	sort(a2, a2 + 100000, greater<ll>());
	// cout << "max_idx1 " << max_idx1 << endl;
	// cout << "max_idx2 " << max_idx2 << endl;
	if (max_idx1==max_idx2){
		if(a1[0]+a2[1]>a1[1]+a2[0]) cout << n - a1[0] - a2[1] << endl;
		else cout << n - a1[1] - a2[0] << endl;
	}
	else cout << n - a1[0] - a2[0]<< endl;
}
 


Measured memory_bytes: 2560
import java.util.Scanner;
public class Main {
     public static void main(String[] args) {
       Scanner ob=new Scanner(System.in);
       int n=ob.nextInt();
       char[] s=ob.next().toCharArray();
       int count=0;
       int  i=0,j=s.length-1;
while(i<j)
     {
        while(i<j&&s[i]=='R'){i++;}
        while(i<j&&s[j]=='W'){j--;}
       if(i<j){s[i]='R';s[j]='W';count++;}
     }
         System.out.println(count);
     } 
}

Measured memory_bytes: 31896
// Created by AboAbdoMC
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long

using namespace std;
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

const int OO = 1e9+7;
const int MOD = 1e9+7;
const int N = 1e3+7;

vector<int> v[N];
int vs[N];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n;
    cin >> n;
    rep(i,n)
    {
        rep(j,n-1)
        {
            int a;
            cin >> a;
            v[i].pb(a-1);
        }
        reverse(v[i].begin(), v[i].end());
        vs[i] = v[i].back();
    }
    int ans = 0;
    while(1)
    {
        bool ok = 0;
        int cnt = 0;
        vector<pair<int,int> > vec;
        rep(i,n)
        {
            if (vs[i] != -1 && vs[vs[i]] == i && i < vs[i])
            {
                ok = 1;
                vec.pb({i,vs[i]});
            }
            else if (vs[i] == -1) cnt++;
        }
        if (cnt == n) break;
        else if (!ok) {cout << "-1\n";return 0;}

        for(auto p:vec)
        {
            int i = p.f;
            int j = p.s;
            v[i].pop_back();
            if (v[i].size()) vs[i] = v[i].back();
            else vs[i] = -1;
            v[j].pop_back();
            if (v[j].size()) vs[j] = v[j].back();
            else vs[j] = -1;
        }
        ans++;
    }    
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 4352
#include <iostream>
using namespace std;
int main() {
    int a, b, k;
    cin >> a >> b >> k;
    int x, n = 0;
    for (int i = 100; k != 0; --i) {
        if (a % i == 0 && b % i == 0) {
            x = i;
            k--;
        }
    }
    cout << x << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int cnt = 0;

void selectionSort( int *A, int N )
{
    int minj;
    int tmp;
    
    for ( int i = 0; i < N; i++ ) {
        minj = i;
        for ( int j = i + 1; j < N; j++ ) {
            if ( A[j] < A[minj] ) {
                minj = j;
            }
        }
        if ( i != minj ) {
            tmp = A[i];
            A[i] = A[minj];
            A[minj] = tmp;
            cnt++;
        }
    }
}


int main(void)
{
    int N;
    int A[100] = {0};
    
    scanf("%d", &N);
    
    for ( int i = 0; i < N; i++ ) {
        scanf("%d", &A[i]);
    }
    
    selectionSort( A, N );
    
    for ( int i = 0; i < N; i++ ) {
        printf("%d", A[i]);
        if ( i != N - 1 ) {
            printf(" ");
        } else {
            printf("\n");
        }
    }
    
    printf("%d\n", cnt);
    
    return 0;
}


Measured memory_bytes: 2108
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define IOS std::cin.tie(0),std::ios::sync_with_stdio(false)

namespace idaten {

	using namespace std;
	using ll = int_fast64_t;
	using ull = uint_fast64_t;
	using P = std::pair<int64_t, int64_t>;
	template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
	template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
	template<class Type>struct is_vector : std::false_type {};
	template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
	template <typename T> inline std::ostream& operator << (std::ostream& out, const std::vector<T>& v) {
		if (v.empty())return out;
		constexpr bool is_vector_v = is_vector<T>::value;
		if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
		else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
		return out;
	}
	inline void put() {}
	template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
	template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
	inline void putn() {}
	template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

	void dfs(int now, vector<vector<int>>& path, vector<int>& visit, vector<ll>& cnt, ll scr, vector<ll>& res) {
		visit[now] = 1;
		scr += cnt[now];
		res[now] = scr;
		REP(i, path[now].size()) {
			int t = path[now][i];
			if (visit[t] < 0) {
				dfs(t, path, visit, cnt, scr, res);
			}
		}
		scr -= cnt[now];
	}

	void solve() {
		IOS;
		int n, q;
		cin >> n >> q;
		vector<int> a(n - 1), b(n - 1);
		vector<vector<int>> path(n);
		vector<int> p(q), x(q);
		REP(i, n - 1) {
			cin >> a[i] >> b[i];
			a[i]--;
			b[i]--;
			path[a[i]].push_back(b[i]);
			path[b[i]].push_back(a[i]);
		}
		vector<ll> cnt(n, 0);
		REP(i, q) {
			cin >> p[i] >> x[i];
			p[i]--;
			cnt[p[i]] += x[i];
		}
		vector<ll> res(n, 0);
		vector<int> visit(n, -1);
		dfs(0, path, visit, cnt, 0, res);
		put(res);
	}
} // namespace idaten

int main() {
	idaten::solve();
	return 0;
}


Measured memory_bytes: 35968
package main

import (
	"fmt"
	"math"
	"sort"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	k--
	tree := make([]int, n)
	for i := 0; i < n; i++ {
		var tmp int
		fmt.Scan(&tmp)
		tree[i] = tmp
	}
	sort.Sort(sort.IntSlice(tree))
	min := math.MaxInt32
	for i := 0; i < n - k; i++ {
		if min > tree[i + k] - tree[i] {
			min = tree[i + k] - tree[i]
		}
	}
	fmt.Println(min)
}

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

#define $(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl '\n'
#define x first
#define y second
//#define int long long
#define double long double
#define pii pair<int, int>
#define pb push_back
#define vec vector
#define beg begin
#define dbg(x) cerr << #x << " = " << x << endl;

template<class T> ostream& operator<<(ostream &str, vector<T> &a) {
    for (auto &i : a) {
        str << i << " ";
    }
    return str;
}

template<class T> istream& operator>>(istream &str, vector<T> &a) {
    for (auto &i : a) {
        str >> i;
    }
    return str;
}

template<class T> ostream& operator<<(ostream &str, pair<T, T> &a) {
    str << a.first << " " << a.second;
    return str;
}

template<class T> istream& operator>>(istream &str, pair<T, T> &a) {
    str >> a.first >> a.second;
    return str;
}

void solve(); signed main() {
#ifdef LOCAL
    freopen("C:\\Users\\artma\\CLionProjects\\problems\\input.txt", "r", stdin);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(6);
    solve();
    return 0;
}

const int MOD = 1e9 + 7, MAXN = 5e5 + 10, INF = 1e18 + 10, BASE = 37;

struct bit {
    vec<int> t;
    bit() {
        t.resize(MAXN);
    }
    void upd(int i, int x) {
        while (i < MAXN) {
            t[i] += x;
            i = i | (i + 1);
        }
    }
    int sum(int i) {
        int cur = 0;
        while (i >= 0) {
            cur += t[i];
            i = (i & (i + 1)) - 1;
        }
        return cur;
    }
};

void solve() {
    int n, q;
    cin >> n >> q;
    vec<int> c(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> c[i];
    }
    vec<pii> qs(q);
    for (int i = 0; i < q; ++i) {
        int l, r;
        cin >> l >> r;
        qs[i] = {l, r};
    }

    vec<int> nxt(n + 1);
    map<int, int> id;
    for (auto it : c) {
        id[it] = n + 1;
    }
    for (int i = n; i >= 1; --i) {
        nxt[i] = id[c[i]];
        id[c[i]] = i;
    }

    bit t;
    map<pii, int> ans;
    vec<vec<int>> R(MAXN), L(MAXN);
    set<pii> se;
    for (auto it : qs) {
        se.insert(it);
    }
    for (auto it : se) {
        R[it.y].pb(it.x);
        L[it.x].pb(it.y);
    }


    for (int i = 1; i <= n; ++i) {
        for (auto r : L[i]) {
            ans[{i, r}] -= (t.sum(n + 1) - t.sum(r));
        }
        t.upd(nxt[i], 1);
        for (auto l : R[i]) {
            ans[{l, i}] += (t.sum(n + 1) - t.sum(i));
        }
    }
    for (auto it : qs) {
        cout << ans[it] << endl;
    }
}

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

using namespace std;

#define ll long long
#define pb push_back
#define vi vector<int>
#define bn(n) (n).begin(), (n).end()
#define FOR(n) for(int i = 0; i < (int)n; i++)


void solve() {
    int n;
    cin >> n;
    cout << (n+1)*n/2 << "\n";
}

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

    int t = 1, i = 1;
    //cin >> t;
    while(t--) {
        //cout << "Case #" << i << ": ";
        solve();
        //i++;
    }
    return 0;
}


Measured memory_bytes: 3520
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<cstring>
#include<utility>
#include<set>
#include<stack>
#include<complex>
#include<bitset>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int>PA;
using namespace std;
#define MAX  999999
int main(){
    vi v(5,0);
    vb flag(4,true);
    vvi u(4,vi(4,0));
    u[1][2]=1;u[2][3]=1;u[3][1]=1;
    while(cin>>v[0],v[0]){
        rep(i,4)flag[i]=true;
        rep(i,4)cin>>v[i+1];
        int cnt=0;
        rep(i,5)if(flag[v[i]]){flag[v[i]]=false; cnt++;}
        if(cnt==1||cnt==3){rep(i,5)cout<<3<<endl;goto L;}
        rep(i,5){
            rep(j,5){
                if(i==j||v[i]==v[j])continue;
                if(u[v[i]][v[j]]){cout<<"1"<<endl; break;}
                else {cout<<"2"<<endl;break;}
            }
        }
    L:;
    }
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
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;
}

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;
using namespace atcoder;


void solve(){
	int n,m;
	cin>>n>>m;
	vector<string>S(n);
	rep(i,n)cin>>S[i];
	mf_graph<int>f(n*m+2);
	int s=n*m,t=n*m+1;
	rep(i,n){
		rep(j,m){
			int id=i*m+j;
			if(S[i][j]=='#')continue;
			if((i+j)%2==0){
				f.add_edge(s,id,1);
			}
			else{
				f.add_edge(id,t,1);
			}
		}
	}
	rep(i,n){
		rep(j,m){
			if((i+j)%2||S[i][j]=='#')continue;
			int id=i*m+j;
			if(i-1>=0&&S[i-1][j]!='#'){
				f.add_edge(id,(i-1)*m+j,1);
			}
			if(j-1>=0&&S[i][j-1]!='#'){
				f.add_edge(id,i*m+(j-1),1);
			}
			if(i+1<n&&S[i+1][j]!='#'){
				f.add_edge(id,(i+1)*m+j,1);
			}
			if(j+1<m&&S[i][j+1]!='#'){
				f.add_edge(id,i*m+(j+1),1);
			}
		}
	}
	cout<<f.flow(s,t)<<"\n";
	vector<vector<char>>ans(n,vector<char>(m,'.'));
	for(auto e:f.edges()){
		int x=e.from,y=e.to;
		if(x>y)swap(x,y);
		if(x==s||x==t||y==s||y==t)continue;
		if(e.flow==0)continue;
		if(ans[x/m][x%m]!='.'||ans[y/m][y%m]!='.')continue;
		if(y%m-x%m==1){
			ans[x/m][x%m]='>';
			ans[y/m][y%m]='<';
		}
		else{
			ans[x/m][x%m]='v';
			ans[y/m][y%m]='^';
		}
	}
	rep(i,n){
		rep(j,m){
			if(S[i][j]=='#')cout<<'#';
			else cout<<ans[i][j];
		}
		cout<<"\n";
	}
}


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


Measured memory_bytes: 5668
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

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

signed main() {
  init();
  ll N;
  cin >> N;
  ll even = N / 2;
  ll odd = N - N / 2;
  COUT(even * odd);
  return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
s = str(input())
if s[k-1] == 'A':
    ans = s[:k-1] + 'a' + s[k:]
elif s[k-1] == 'B':
    ans = s[:k-1] + 'b' + s[k:]
else:
    ans = s[:k-1] + 'c' + s[k:]
print(ans)

Measured memory_bytes: 9140
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;

char op[2]={'+','-'};
int a[4]={0};

int per(int x,int y, int i){
    if(op[i]=='+')return x+y;
    else return x-y;
}

int main(void){
    string s;
    cin>>s;
    for(int i=0;i<4;i++)a[i]=s[i]-'0';
    for(int i=0;i<2;i++){
        for(int j=0;j<2;j++){
            for(int k=0;k<2;k++){
                int now = 0;
                now = per(a[0],a[1],i);
                now = per(now,a[2],j);
                now = per(now,a[3],k);
                if(now==7){
                    cout<<a[0]<<op[i]<<a[1]<<op[j]<<a[2]<<op[k]<<a[3]<<"="<<7<<endl;
                    return 0;
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

main(){
  int max=-1e9;
  int min=1e9;
  int t;
  int n;
  scanf("%d",&n);
  int i;
  for(i=0;i<n;i++){
    scanf("%d",&t);
    if(max<t)
      max=t;
    if(min>t)
      min=t;
  }
  printf("%d\n",max-min);
}

Measured memory_bytes: 128
import static java.lang.Math.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt(), m = in.nextInt();
			int[] c = in.nextIntArray(m);
			int[] dp = new int[n+1];
			Arrays.fill(dp, INF);
			dp[0] = 0;

			for (int i = 0; i <= n; i++) {
				for (int j = 0; j < m; j++) {
					if (i-c[j] >= 0) {
						dp[i] = min(dp[i-c[j]] + 1, dp[i]);
					}
				}
			}

			out.println(dp[n]);

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}



Measured memory_bytes: 25248
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <deque>
#include <map>
#include <iomanip>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstdint>
#include <cstring>
//#pragma warning(disable:4996)
 
using namespace std;
 
 
/** Type Define **/
typedef long long int           ll;
typedef pair<int, int>          pii;
typedef pair<ll, ll>            pll;
typedef vector<string>          vs;
typedef vector<bool>            vb;
typedef vector<int>             vi;
typedef vector<long long>		vl;
typedef vector<vi>              vvi;
typedef vector<vl>				vvl;
typedef vector<char>            vch;
#define		it(x)  x.begin() 
#define		all(x)  x.begin(), x.end()
#define		pb(x)   push_back(x)
constexpr int           inf = 0x3f3f3f3f;
constexpr long long 	INF = 9123456789123456789;
constexpr long long     MOD = 1000000007LL;
/*************************************************/
int N, R;
 
void sol() {
 
}
 
int main() {
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cin.tie(nullptr);
  	cin >> N >> R;
  	if(N >= 10) cout << R << endl;
  	else{
		R += 100 * (10 - N);
      	cout << R << endl;
    }
 
 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <climits>
#include <sstream>
#include <iterator>
#include <sstream>
#include <iomanip>
#include <istream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;

int main()
{
    int H, W;
    cin >> H >> W;
    cin.ignore();

    char pic[H+2][W+2];
    memset(pic, '#', sizeof(pic));

    for(int i = 1; i <= H; i++) {
        for(int j = 1; j <= W; j++) {
            char c = getchar();
            pic[i][j] = c;
        }
        char t = getchar();
    }

    for(int i = 0; i < H+2; i++) {
        for(int j = 0; j < W+2; j++) {
            cout << pic[i][j];
        }
        cout << "\n";
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e16
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


int main() {

	string s;
	cin >> s;
	int ans = 0, c = 0;

	for (int i = 0; i < s.size(); i++) {
		c++;
		if (s[i] != 'A'&&s[i] != 'T'&&s[i] != 'C'&&s[i] != 'G') {
			ans = max(ans, c-1);
			c = 0;
		}
	}
	
	ans = max(ans, c);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
/**
 *     author: qodjf
 *     created: 04.21.2020 23:13:45
 */
#include <bits/stdc++.h>
using namespace std;

string to_string(string s) { return '"' + s + '"'; }

string to_string(const char *s) { return to_string((string)s); }

string to_string(bool b) { return (b ? "true" : "false"); }

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifndef ONLINE_JUDGE
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define dbg(...) 42
#endif

#define mst(x, a) memset(x, a, sizeof(x))

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const ll MOD = 1e9 + 7;

ll N, K;
vector<ll> negative, positive;
ll zeroCnt, negCnt, posCnt;

ll cntOfProductLessThan(const vector<ll> &A, ll x) {
  ll cnt = 0;
  int rb = 0;
  for (int i = A.size() - 1; i >= 0; i--) {
    rb = min(rb, i);
    while (A[rb] * A[i] <= x && rb < i) rb++;
    cnt += rb;
  }
  return cnt;
}

ll test(ll x) {
  if (x == 0) {
    return zeroCnt * (posCnt + negCnt) + zeroCnt * (zeroCnt - 1) / 2 +
           posCnt * negCnt;
  }
  if (x > 0) {
    return cntOfProductLessThan(positive, x) +
           cntOfProductLessThan(negative, x) + test(0);
  }

  ll cnt = 0;
  int lb = negCnt - 1;
  for (int i = 0; i < posCnt; i++) {
    while (lb >= 0 && positive[i] * negative[lb] <= x) lb--;
    cnt += negCnt - 1 - lb;
  }
  return cnt;
}

void solve() {
  sort(positive.begin(), positive.end());
  sort(negative.rbegin(), negative.rend());

  ll lo = -1e18 - 10, hi = 1e18 + 10;
  while (lo + 1 < hi) {
    ll mi = lo + (hi - lo) / 2;
    // product <= x is >= K
    if (test(mi) >= K) {
      hi = mi;
    } else {
      lo = mi;
    }
  }
  cout << hi << endl;
}

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

  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    if (a > 0) {
      positive.push_back(a);
    } else if (a < 0) {
      negative.push_back(a);
    }
  }
  posCnt = positive.size();
  negCnt = negative.size();
  zeroCnt = N - posCnt - negCnt;
  solve();
}


Measured memory_bytes: 2420
import java.util.*;
import java.io.*;

class UnionFind{
    int size;
    int[] parent;
    int[] height;

    int[] partSize;

    public UnionFind(int size){
        this.size = size;
        parent = new int[size];
        height = new int[size];
        partSize = new int[size];
        for(int i=0;i<size;i++){
            parent[i]=i;
            height[i]=0;
            partSize[i]=1;
        }
    }
    private boolean isRoot(int node){
        return node==parent[node];
    }
    private int getRoot(int node){
        if(isRoot(node)) return node;
        else{
            parent[node] = getRoot(parent[node]);
            return parent[node];
        }
    }
    public void union(int node1, int node2){
        if(find(node1,node2)) return;
        if(height[node1]>height[node2]){
            partSize[getRoot(node1)] = partSize[getRoot(node1)]+partSize[getRoot(node2)];
            parent[getRoot(node2)] = getRoot(node1);
        }else{
            partSize[getRoot(node2)] = partSize[getRoot(node1)]+partSize[getRoot(node2)];
            parent[getRoot(node1)] = getRoot(node2);
        }
    }
    public boolean find(int node1, int node2){
        return getRoot(node1)==getRoot(node2);
    }
    public int countGroup(){
        int ans = 0;
        for(int i=0;i<size;i++) if(isRoot(i)) ans++;
        return ans;
    }
    public int getPartSize(int node){
        return partSize[getRoot(node)];
    }
}
public class Main {
    static long countPair(long N){
        return N * (N-1) / 2;
    }
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();

        int[] A = new int[M];
        int[] B = new int[M];
        for(int m=0; m<M; m++){
            A[m]=sc.nextInt()-1;
            B[m]=sc.nextInt()-1;
        }

        UnionFind bridge = new UnionFind(N);
        LinkedList<Long> convenient = new LinkedList<>();
        convenient.add(0L);

        for(int m=M-1; m>0; m--){
            if(bridge.find(A[m],B[m])) convenient.addFirst(convenient.getFirst());
            else{
                long x = convenient.getFirst() - countPair(bridge.getPartSize(A[m])) - countPair(bridge.getPartSize(B[m]));
                bridge.union(A[m], B[m]);
                x += countPair(bridge.getPartSize(A[m]));
                convenient.addFirst(x);
            }
        }
        //for(long a : convenient) System.out.println(a);
        for(long a : convenient) System.out.println(countPair(N) - a);
    }
}

Measured memory_bytes: 98604
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

struct edge {
	int to, cost;
};

typedef pair<int, int> P;

int V;
int E;

vector<edge> G[100001];
int d[100001];

void dijkstra(int s) {
	priority_queue<P, vector<P>, greater<P>>que;

	fill(d, d+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));
			}
		}
	}
}

int main() {
	int s;

	cin >> V >> E >> s;
	for (int i = 0; i < E; i++) {
		int a, b, c; cin >> a >> b >> c;
		edge e;
		e.to = b;
		e.cost = c;

		G[a].push_back(e);
	}

	dijkstra(s);

	for (int i = 0; i < V; i++) {
		if (d[i] == INF) {
			cout << "INF";
		}
		else {
			cout << d[i];
		}
		cout << endl;
	}

}


Measured memory_bytes: 13052
package main

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

func NextInt(sc *bufio.Scanner) int {
	sc.Scan()
	n, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return n
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)

	n := NextInt(sc)
	var a int
	for i := 0; i < n; i++ {
		b := NextInt(sc)
		if i == 0 || a != b {
			if 0 < i {
				fmt.Fprint(w, " ")
			}
			fmt.Fprint(w, b)
			a = b
		}
	}
	fmt.Fprint(w, "\n")

	w.Flush()
}



Measured memory_bytes: 3420
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<int, int>;
 
#define INF 1e18
#define MAX 200005

using mint = modint998244353;

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mint::mod());
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main() {
  int n;
  cin >> n;
  combination comb(n*2);
  vector<int> a;
  {
    map<int,int> mp;
    rep(i,n*2) {
      int h; cin >> h;
      mp[h]++;
    }
    for (auto m : mp) a.push_back(m.second);
  }
  auto twofact = [&](int n) { // nは奇数であること
    int nn = (n+1)/2;
    return comb.fact[n+1]/(comb.fact[nn]*mint(2).pow(nn));
  };
  int as = a.size();
  vector< vector<mint> > d(as);
  rep(i,as) {
    d[i].push_back(1);
    for (int rem=a[i]-2; rem>=0; rem-=2) {
      d[i].push_back(comb(a[i],rem)*twofact(a[i]-rem-1));
    }
  }
  while (d.size()>1) {
    vector< vector<mint> > nd;
    int ds = d.size();
    if (ds%2==1) nd.push_back(d[ds-1]);
    rep(i,ds/2) nd.push_back(convolution(d[i*2],d[i*2+1]));
    swap(d,nd);
  }
  mint ans = 0;
  rep(i,d[0].size()) {
    mint now = d[0][i]*twofact(n*2-i*2-1);
    ans += now*(i%2?-1:1);
  }
  cout << ans.val() << endl;

  return 0;
}

Measured memory_bytes: 12436
/*#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")*/
//#include<bits/stdc++.h>
#include<iostream>
#include<vector>
using namespace std;
#define ll long long

ll D,C[26],S[365][26],T[365],Tans[365],V[365],Vorigin[365];
ll last[365][26],last_sim[365][26],last2[26];
ll vmax;
ll steps=0,dadd_best;

void greedy(){
    ll dadd,i,j,k,l,i_calc,tbest,score,vbest;
    for(dadd=0;dadd<=26;++dadd){
        //リセット
        for(i=0;i<D;i++){
            if(i<26)last2[i]=0;
            for(j=0;j<26;j++){
                last[i][j]=0;
            }
        }

        for(i=0;i<D;i++){
            i_calc=min(i+dadd+1,D);
            //cout<<i_calc<<endl;
            for(j=0;j<26;j++){
                //得点の初期化
                //cout<<i<<endl;
                if(i==0){
                    V[i]=0;
                }else{
                    V[i]=V[i-1];
                }
                
                //lastの初期化
                if(i==0)for(k=0;k<26;k++)last[i][k]=0;
                else for(k=0;k<26;k++)last[i][k]=last[i-1][k];

                last[i][j]=i;
                V[i]+=S[i][j];

                for(k=0;k<26;k++)
                    for(l=i;l<i_calc;l++)V[i]-=C[k]*(l-last[i][k]);

                if(j==0||V[i]>=vmax){
                    vmax=V[i];
                    tbest=j;
                }
            }
            if(i==0)for(j=0;j<26;j++)last[i][j]=0;
            else for(j=0;j<26;j++)last[i][j]=last[i-1][j];
            T[i]=tbest;
            last[i][tbest]=i;
        }

        //得点の再計算
        score=0;
        for(i=0;i<26;i++)last2[i]=0;
        for(i=0;i<D;i++){
            score+=S[i][T[i]];
            last2[T[i]]=i;
            for(j=0;j<26;j++)score-=C[j]*(i-last2[j]);
        }

        if(dadd==0||score>vbest){
            dadd_best=dadd;
            vbest=score;
            for(i=0;i<D;i++){
                if(i<26)Tans[i]=T[i];
                for(j=0;j<26;j++)last_sim[i][j]=last[i][j];
            }
        }
    }

    vmax=vbest;
    for(i=0;i<D;i++){
        if(i<26)T[i]=Tans[i];
        for(j=0;j<26;j++)last[i][j]=last_sim[i][j];
    }
}

int main(){
    int i,j;
    cin>>D;
    for(i=0;i<26;i++)cin>>C[i];
    for(i=0;i<D;i++)for(j=0;j<26;j++)cin>>S[i][j];
    greedy();
    //cout<<dadd_best<<endl;
    for(i=0;i<D;i++)cout<<T[i]+1<<"\n";
    return 0;
}

Measured memory_bytes: 3432
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int inf=1e9+7;//0x3f
//
int cnts[26],cntt[26];
int main(){
	string S,T;
	cin>>S>>T;
	if(S==T){
		Yes(1);
		return 0;
	}
	for(int i=0;i<S.size();i++){
		cnts[S[i]-'a']++;
		cntt[T[i]-'a']++;
	}
	sort(cnts,cnts+26);
	sort(cntt,cntt+26);
	for(int i=0;i<26;i++){
		if(cnts[i]!=cntt[i]){
			Yes(0);
			return 0;
		}
	}
	Yes(1);
	return 0;
}

Measured memory_bytes: 776
import numpy as np

a = list(map(int, input().split()))
if a[1] == 0:
    print(a[0])
else: 
    b = list(map(int, input().split()))
    c = list(set([i for i in range(200)]) - set(b))
    idx = np.abs(np.asarray(c) - a[0]).argmin()
    print(c[idx])

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

using namespace std;

int main()
{
 float prob,imp;
 int n;
 cin>>n;
 if(n%2==0){
    imp=n/2;
 }
 else{
    imp=n/2+1;
     }
 prob=imp/n;
 cout<<setprecision(10)<<prob;
    return 0;

}


Measured memory_bytes: 256
import java.util.*;
import java.math.BigInteger;
 
public class Main{
  public static void main(String args[]){
  	Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int d = sc.nextInt();
    int x, y, p=0;
    BigInteger p1 = BigInteger.valueOf(d);
    p1 = p1.multiply(p1);
    for(int i = 0; i < n ; i++){
    	x = sc.nextInt();
      	y = sc.nextInt();
      	BigInteger r = BigInteger.valueOf(x);
      	r = r.multiply(r);
      	BigInteger s = BigInteger.valueOf(y);
      	s = s.multiply(s);
      	r = r.add(s);
      	if(r.compareTo(p1) <= 0)
        	p++;
    }
    System.out.println(p);
  }
}

Measured memory_bytes: 60244
expression = gets.split( " " )
stack = []
expression.each { |exp|
	if "+" == exp
		b = stack.pop
		a = stack.pop
		stack.push( a + b )
	elsif "-" == exp
		b = stack.pop
		a = stack.pop
		stack.push( a - b	 )
	elsif "*" == exp
		b = stack.pop
		a = stack.pop
		stack.push( a * b )
	else
		stack.push( exp.to_i )
	end
}
puts( stack.pop )

Measured memory_bytes: 6104
#coding: utf-8
n = int(input())
takoyaki_list = list(map(int,input().split()))
# strings = list(map(str, [input() for i in range(amount)]))
sum = 0

for i in range(len(takoyaki_list)-1):
    for j in range(i+1,len(takoyaki_list)):
        # print(str(i)+str(',')+str(j))
        sum += takoyaki_list[i]*takoyaki_list[j]
        
print(sum)


Measured memory_bytes: 2940
from fractions import gcd
from functools import reduce

n = int(input())
t = list(int(input()) for _ in range(n))

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

print(lcm_list(t))

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

int main() {
  int sum = 1;
  int N, K;
  cin >> N >> K;
  
  for (int i = N; i > 0; i--){
    if (sum > K){
      sum += K;
    }
    else{
      sum *= 2;
    }
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
/*  
    Talkin' to myself and feelin' old
    Sometimes I'd like to quit, nothin' ever seems to fit
    Hangin' around, nothin' to do but frown
    Rainy days and Mondays always get me down
    _________________________
    _________________________
    936 Hours of Solitude
    Quarantine_Day : 39
*/

#include<bits/stdc++.h>

using namespace std;

typedef long long int       ll;
typedef vector<int>         vi;
typedef vector<ll>          vl;
typedef pair<int, int>      pii;
typedef pair<ll, ll>		pll;

#define pb(n)           push_back(n)
#define GSORT(v)        sort(v.begin(), v.end(), greater<int>())
#define SORT(v)         sort(v.begin(), v.end());
#define REV(v)          reverse(v.begin(), v.end());
#define db(a)           cout<<#a<<" = "<<a<<endl;
#define FIN             freopen("in.txt","r",stdin);
#define FOUT            freopen("out.txt","w",stdout);
#define REP(i,n)        for(int i = (int)(0); i < (int)(n); i++)
#define FOR(i, a, b)    for(int i = (int)a; i <= (int)b; i++)    

#define MAX 90

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

    int a, b; cin>>a>>b;
    string s; cin>>s;
    bool flag = true;
    if(s[a] != '-') flag = false;
    else if(s.size() != a + b + 1) flag = false;
    else{
        REP(i, s.size()){
            if(i == a) continue;
            if(!isdigit(s[i])){
                flag = false;
                break;
            }
        }
    }
    cout<<(flag?"Yes\n":"No\n");

    return 0;
}


Measured memory_bytes: 256
def main():
    N, A, B = map(int, input().split())

    if (B - A) % 2 == 0:
        print((B - A) // 2)
    else:
        ret = min(
            A + (B - A - 1) // 2,
            (N - B + 1) + (N - (A + N - B + 1)) // 2
        )
        print(ret)


if __name__ == '__main__':
    main()


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

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


int main() {
  int n, q;
  cin >> n >> q;
  queue <string> name;
  queue <int> time;
  rep(i, n) {
    string s;
    int t;
    cin >> s >> t;
    name.push(s);
    time.push(t);
  }
  int sum = 0;
  while (!time.empty()) {
    if (q < time.front()) {
      name.push(name.front());
      time.push(time.front()-q);
      sum += q;
      name.pop();
      time.pop();
    } else {
      sum += time.front();
      cout << name.front() << ' ' << sum << endl;
      name.pop();
      time.pop();
    }
  }
}


Measured memory_bytes: 5720
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		
		while(true) {
			int m = scan.nextInt();
			int f = scan.nextInt();
			int r = scan.nextInt();
			
			if(m == -1 && f == -1) {
				break;
			}
			
			if(m == -1 || f == -1) System.out.println("F");
			else if(m + f >= 80) System.out.println("A");
			else if(m + f >= 65) System.out.println("B");
			else if(m + f >= 50) System.out.println("C");
			else if(m + f >= 30) {
				if(r >= 50) System.out.println("C");
				else System.out.println("D");
			}
			else System.out.println("F");
			
		}
		
	}

}



Measured memory_bytes: 26352