akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include <time.h>
typedef long long llint;
int compare(const void *a, const void *b){return *(llint *)a - *(llint *)b;}


int main(void){
    llint n,m,i,sum=0;
    scanf("%lld%lld",&n,&m);
    llint x[m],sa[m-1];
    for(i=0;i<m;i++){
        scanf("%lld",&x[i]);
    }
    if(n>=m){
        printf("0\n");
        return 0;
    }
    qsort(x,m,sizeof(llint),compare);
    for(i=0;i<m-1;i++){
        sa[i]=x[i+1]-x[i];
    }
    qsort(sa,m-1,sizeof(llint),compare);
    for(i=0;i<m-1-n+1;i++){
        sum+=sa[i];
    }
    printf("%lld\n",sum);
    return 0;
}


Measured memory_bytes: 2540
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp;

fn main() {
    input!{
        n: usize,
        m: usize,
        xc: i32,
        yc: i32,
        xs: [i32; n],
        ys: [i32; m],
    }

    let mut war = true;
    for z in (xc+1)..(yc+1) {
        let mut ok = true;
        for i in 0..n {
            if xs[i] >= z {
                ok = false;
                break;
            }
        }
        if ok == false { continue; }

        for i in 0..m {
            if ys[i] < z {
                ok = false;
                break;
            }
        }

        if ok {
            println!("{}", "No War");
            war = false;
            break;
        }
    }
    if war {
        println!("{}", "War")
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <vector>
#include <climits>

using namespace std;

int main() {
	int row,col;
	cin >> row >> col;
	
	vector<int> rsum(col+1,0);
	vector<int> rcsum(col+1,0);

	for(int i=0;i<row;i++) {
		for(int j=0;j<col;j++) {
			cin >> rsum[j];
			rsum[col] += rsum[j];
			rcsum[j]  += rsum[j];
			cout << rsum[j] << " ";
		}
		rcsum[col] += rsum[col];
		cout << rsum[col] << endl;
		rsum[col] = 0;
	}	

	for(int i=0;i<col;i++)
		cout << rcsum[i] << " ";
	cout << rcsum[col]<< endl;

	return 0;
}




Measured memory_bytes: 3104
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=1e9+7;
ll m,n,l,yy[305][305],ans[305][305]; 
 
int main()
{
    std::ios::sync_with_stdio(0); std::cin.tie(0);
    cin>>m>>n>>l;
    ll a,b,c;
    for(int i=1;i<=m;++i)
     for(int j=1;j<=m;++j)
     yy[i][j]=1e15,ans[i][j]=1e15;
    for(int i=0;i<n;++i)
    {
    	cin>>a>>b>>c;
    	if(c>l) c=1e15;
    	yy[a][b]=yy[b][a]=c;
	}
	for(int i=1;i<=m;++i)
	 for(int j=1;j<=m;++j)
	  for(int k=1;k<=m;++k)
	  yy[j][k]=min(yy[j][k],yy[j][i]+yy[i][k]);
	  for(int i=1;i<=m;++i)
	 for(int j=1;j<=m;++j)
	  if(yy[i][j]<=l) ans[i][j]=1;
	  for(int i=1;i<=m;++i)
	 for(int j=1;j<=m;++j)
	  for(int k=1;k<=m;++k)
	  ans[j][k]=min(ans[j][k],ans[j][i]+ans[i][k]);
	ll q;
	cin>>q;
	while(q--)
	{
		cin>>a>>b;
		if(ans[a][b]<1e15) cout<<ans[a][b]-1<<'\n';
		else cout<<-1<<'\n';
	}
	return 0;
}

Measured memory_bytes: 5048
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int inf=1000000000;

int map[10][10],vis[10],dis[10],m,n,sit[10],s[10],ans;

void Dijkstra(int a)
{
    for(int i=0;i<=9;i++) dis[i]=map[a][i];
    vis[a]=1;
    for(int i=0;i<9;i++)
    {
        int minn=inf,v=1;
        for(int j=0;j<=9;j++)
        if(!vis[j]&&dis[j]<minn) {minn=dis[j];v=j;}
        vis[v]=1;
        for(int j=0;j<=9;j++)
            dis[j]=min(dis[j],dis[v]+map[v][j]);
    }
}

int main()
{
    while(cin>>m>>n)
    {
        ans=0;
        int a;
        for(int i=0;i<=9;i++) {sit[i]=0;s[i]=0;}

        for(int i=0;i<=9;i++)
        for(int j=0;j<=9;j++)
        scanf("%d",&map[i][j]);

        for(int i=1;i<=m;i++)
        for(int j=1;j<=n;j++)
        {
            scanf("%d",&a);
            if(a!=-1) sit[a]++;
        }
        for(int i=0;i<=9;i++){
        for(int j=0;j<=9;j++) vis[j]=0;
        if(sit[i]!=0) Dijkstra(i);
        s[i]=dis[1];}
        for(int i=0;i<=9;i++)
            ans += s[i]*sit[i];
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrep(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define fore(i,a) for(auto &i:a)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define isin(i,a,b) ((a) <= (i) && (i) < (b))
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll  = long long;
using unit= unsigned;
using ull = unsigned long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vvi = vector<vi>;
using vp  = vector<P>;
void _main(); int main(){ cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T>void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T>void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T>void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T>void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T>bool chmax(T &a, const T &b){ if (a<b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if (b<a){ a = b; return 1; } return 0; }
template<class T>T gcd(T a, T b){ if (b==0){ return a; }else{ return gcd(b, a%b); }}
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
constexpr double eps = 1e-10;
constexpr int inf = INT_MAX / 2;
constexpr ll infl = 1LL << 60;

void _main() {
  ll A, B, C, D;
  cin >> A >> B >> C >> D;
  ll CD = lcm(C, D);

  ll divisible_c = B/C - (A-1)/C;
  ll divisible_d = B/D - (A-1)/D;
  ll divisible_cd = B/CD - (A-1)/CD;
  
  ll ans = (B-A+1) - divisible_c - divisible_d + divisible_cd;
  cout << ans << endl;
}

Measured memory_bytes: 256
S = input()


def f():
    if S == "keyence":
        print("YES")
    else:
        n = len(S)
        for i in range(n):
            for j in range(i, n):
                T = ""
                for k in range(n):
                    if i <= k <= j:
                        continue
                    else:
                        T += S[k]
                if T == "keyence":
                    print("YES")
                    return
        else:
            print("NO")


f()


Measured memory_bytes: 3060
def check(x1, y1, x2, y2, xp, yp):
    return ((y1 > yp) != (y2 > yp)) and (xp - x1 < (x2 - x1) * (yp - y1) / (y2 - y1))


while True:
    try:
        x1, y1, x2, y2, x3, y3, xp, yp = map(float, input().split())
    except:
        break
    print('YES' if (check(x1, y1, x2, y2, xp, yp) +
                    check(x2, y2, x3, y3, xp, yp) +
                    check(x3, y3, x1, y1, xp, yp)) & 1 else 'NO')

Measured memory_bytes: 7396
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main() {
    int N;
    cin >> N;
    
    int L[2 * N];
    for (int i =0; i < 2 * N;++i) cin >> L[i];
    sort(L, L + 2 * N);
    
    int res = 0;
    for (int i = 0; i < N; ++i) {
        res += L[2 * i];
    }
    
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
bool check[102];
int main() {
    int x, n;
    cin >> x >> n;
    for (int i = 0; i <= 101; i++) {
        check[i] = true;
    }
    for (int i = 0; i < n; i++) {
        int p;
        cin >> p;
        check[p] = false;
    }
    int difference = 0;
    int ret;
    while(true) {
        if (check[x - difference]) {
            ret = x - difference;
            break;
        }
        else if (check[x + difference]) {
            ret = x + difference;
            break;
        }
        difference++;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a,b;
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>a>>b;
    if(abs(a-b)%2==0) cout<<abs(a-b)/2<<endl;
    else if(a==b) cout<<"0"<<endl;
    else
    {
        ll t1,t2,temp;
        if(a>b)
        {
            t1=b+(a-b-1)/2,t2=n-a+1+(a-b-1)/2;
        }
        else
            t1=a+(b-a-1)/2,t2=n-b+1+(b-a-1)/2;
            cout<<min(t1,t2)<<endl;
    }
}


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

int main(){
    string s;
    int k;
    cin>>s>>k;
    int ans;
    for (char i : s) {
        if(i =='1')--k;
        else {ans=i-'0';break;}
        if(k<=0)break;
    }
    if(k>0)cout<<ans<<endl;
    else cout<<"1"<<endl;
    return 0;
}

Measured memory_bytes: 256
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin>>a>>b;
    int c=b-a;
    int sum=0;
    rep(i,c-1){
        sum+=i+1;
    }
    cout<<sum-a<<"\n";
}


Measured memory_bytes: 3528
#pragma GCC optimize("O2")

#include <bits/stdc++.h>
#ifdef DEBUG
	#include "debug.hpp"
#endif

using namespace std;

#define all(c) (c).begin(), (c).end()
#define traverse(c, it) for(auto it = (c).begin(); it != (c).end(); it++)
#define rep(i, N) for(int i = 0; i < (N); i++)
#define rep1(i, N) for(int i = 1; i <= (N); i++)
#define rep2(i, s, e) for(int i = (s); i <= (e); i++)
#define rep3(i, s, e, d) for(int i = (s); (d) >= 0 ? i <= (e) : i >= (e); i += (d))
#define pb push_back


#ifdef DEBUG
	#define debug(x...) {dbg::depth++; string dbg_vals = dbg::to_string(x); dbg::depth--; dbg::fprint(__func__, __LINE__, #x, dbg_vals);}
	#define light_debug(x) {dbg::light = 1; dbg::dout << __func__ << ":" << __LINE__ << "  " << #x << " = " << x << endl; dbg::light = 0;}
#else
	#define debug(x...)
	#define light_debug(x) 
#endif


using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;


signed main(){

	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	#ifdef DEBUG
		freopen("debug", "w", stderr);
	#endif

	string s, t;
	cin >> s >> t;
	int ans = 0;
	rep(i, (int)s.size())
		ans += s[i] != t[i];
	cout << ans << '\n';
	

	#ifdef DEBUG
		dbg::dout << "\nExecution time: " << clock() << "ms\n";
	#endif

	return 0;
}


Measured memory_bytes: 3752
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <map>
#include <cmath>
#include <algorithm>
#include <stack>
using namespace std;
char mins[5][5005];
string str;
int fun(int a,int b){
    int tt= 0;
    for(int i = 0;i < 5;++i){
        int tag1 = 0;
        int len = strlen(mins[i]);
        if(len == 0) tag1 = 1;
        if(len == b-a+1){
            int t = 0;
            for(int j = 0;j < len;++j){
                if(str[a+j] != mins[i][j]) t = 1;
            }
            if(t == 0){
                tt = 1;
                break;
            }
        }
        for(int j = 0;j < len;++j){
            if(tag1 == 1) break;
            if(a + j > b){
                tag1 = 1;
                break;
            }
            else if(str[a+j] < mins[i][j]){
                tag1 = 1;
                break;
            }
            else if(str[a+j] == mins[i][j]) continue;
            else if(str[a+j] > mins[i][j]){
                tag1 = -1;
                break;
            }
        }
        if(tag1 == 0 || tag1 == -1){
            continue;
        }
        else{
            for(int j = 3;j >= i;--j){
                int len = strlen(mins[j]);
                for(int k = 0;k < len;++k){
                    mins[j+1][k] = mins[j][k];
                }
                mins[j+1][len] = '\0';
            }
            for(int j = a;j <= b;++j){
                mins[i][j-a] = str[j];
            }
            mins[i][b-a+1] = '\0';
            return 1;
        }
    }
    if(tt) return 1;
    return 0;
}
int main()
{
    
    cin >> str;
    int k;
    cin >> k;
    int len = str.length();
    mins[0][0] = mins[0][1] = mins[0][2] = mins[0][3] = mins[0][4] = '\0';
    for(int i = 0;i < len;++i){
        for(int j = i;j < len;++j){
            if(!fun(i,j)) break;
        }
    }
    cout << mins[k-1] << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);

		int R = sc.nextInt();
		int G = sc.nextInt();
		int B = sc.nextInt();
		int N = sc.nextInt();

		int count=0;

		for(int i=0;(R*i)<=N;i++) {
			for(int j=0;(R*i)+(G*j)<=N;j++) {
				int rest = N - (R*i) - (G*j);

				if(rest % B == 0){
					count++;
				}
			}
		}

		System.out.println(count);
	}

}


Measured memory_bytes: 23252
using System;
using System.Collections.Generic;

namespace abc121_c
{
    class Program
    {
        static void Main()
        {
            var tmpNm = Console.ReadLine().Split();
            var n = int.Parse(tmpNm[0]);
            var shopList = new SortedDictionary<long,long>();
            for (var i = 0; i < n; i++)
            {
                var tmpAb = Console.ReadLine().Split();
                var a = int.Parse(tmpAb[0]);
                var b = int.Parse(tmpAb[1]);
                if (shopList.ContainsKey(a))
                {
                    shopList[a] += b;
                }
                else
                {
                    shopList[a] = b;
                }
            }
            var m = int.Parse(tmpNm[1]);
            long needMoney = 0;
            foreach (var shop in shopList)
            {
                if (shop.Value < m)
                {
                    needMoney += shop.Key * shop.Value;
                    m -= (int)shop.Value;
                    continue;
                }

                needMoney += shop.Key * m;
                break;
            }

            Console.WriteLine(needMoney);

        }
    }
}


Measured memory_bytes: 25132
n=gets.to_i
ary=gets.split(' ').map(&:to_i)
r=0
ary.each.with_index do |a, i|
  next if i < 1
  aa = ary[i-1] - a
  if aa > 0
    r += aa
    ary[i] += aa
  else
    next
  end
end
print r

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n,m;
    cin >> n >> m;
    vector<vector<int32>> dp(m+1, vector<int32>(1<<n, INF));
    dp[0][0] = 0;
    REP(i,m){
        int32 a,b;
        cin >> a >> b;
        int32 cbit = 0;
        REP(j,b){
            int32 c;
            cin >> c;
            c--;
            cbit |= (1 << c);
        }
        // cout << bitset<10>(cbit) << endl;
        REP(mask,1<<n){
            dp[i+1][mask] = min(dp[i+1][mask], dp[i][mask]);
            dp[i+1][mask | cbit] = min(dp[i+1][mask | cbit], dp[i][mask] + a);
        }
    }
    // REP(i,1<<n)cout << dp[m][i] << endl;
    if(dp[m][(1<<n) - 1] == INF)dp[m][(1<<n) - 1] = -1;
    ANS(dp[m][(1<<n) - 1]);
    return 0;
}

Measured memory_bytes: 32384
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<algorithm>
#include<map>
#pragma warning(disable: 4996)
#define rep(i,n) for(int i = 1; i < (n); i++)
using namespace std;
using ll = long long;


int main() {
	
	int N;
	cin >> N;
	vector<int> a(N);
	vector<int> cnt(N);
	rep(i, N) {
		cin >> a[i];
		cnt[a[i]-1]++;
	}
	for (int i = 0; i < N; ++i) {
		cout << cnt[i] << endl; 
	}
	return 0;
}

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



int main(){
	cin.tie(0)->sync_with_stdio(0);
	long long n;
	cin >> n, -- n;
	int t = 1;
	long long s = 26;
	while(s <= n){
		n -= s;
		s *= 26;
		++ t;
	}
	string res;
	for(auto i = 0; i < t; ++ i){
		res.push_back(n % 26 + 'a');
		n /= 26;
	}
	reverse(res.begin(), res.end());
	cout << res << "\n";
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<int> c(n - 1), s(n - 1), f(n - 1);
  rep(i, n - 1) cin >> c[i] >> s[i] >> f[i];

  rep(i, n) {
    int ans = 0;
    REP(j, i, n - 1) {
      if (ans < s[j])
        ans = s[j];
      else if ((ans - s[j]) % f[j])
        ans = ans + f[j] - (ans - s[j]) % f[j];
      ans += c[j];
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
### subroutines

def backtrace(max, n, edges, start)
  visited = (n + 2).times.map{false}

  q = [start]
  visited[start] = true

  while ! q.empty?
    pos = q.shift
    next if pos == 0

    for pos0 in (0..n)
      if edges[pos0][pos] && ! visited[pos0]
        visited[pos0] = true
        q << pos0
      end
    end
  end

  visited
end

### main

while true
  max = gets.strip.to_i
  break if max == 0

  n = gets.strip.to_i

  masu = [0] + n.times.map{gets.strip.to_i}

  edges = (n + 2).times.map{(n + 2).times.map{false}}

  for pos in (0..n)
    for k in (1..max)
      pos0 = pos + k
      pos0 += masu[pos0] if pos0 <= n
      pos0 = 0 if pos0 < 0
      pos0 = n + 1 if pos0 > n

      edges[pos][pos0] = true
    end
  end

  visited = backtrace(max, n, edges, n + 1)

  if ! visited[0]
    puts 'NG'
    next
  end

  ans = 'OK'
  for i in (1..n)
    if ! visited[i]
      visited0 = backtrace(max, n, edges, i)
      if visited0[0]
        ans = 'NG'
        break
      end
    end
  end

  puts ans
end

Measured memory_bytes: 9268
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)
function root(uf::Array{Int,1},x);s=x;while uf[s]>0;s=uf[s];end;s;end
function same(uf::Array{Int,1},x,y);root(uf,x)==root(uf,y)?true:false;end
function unite(uf::Array{Int,1},x,y);l=root(uf,x);r=root(uf,y);if l<r;uf[l]+=uf[r];uf[r]=l;elseif l>r;uf[r]+=uf[l];uf[l]=r;end;end

function main()
	n = readline() |> parseInt
	a = Array{Int}(3,n)
	for i in 1:n
		x,y = readline() |> split |> parseMap
		a[:,i] = [i,x,y]
	end
	a = sortcols(a,by=x->x[2])
	e = Tuple{Int,Int,Int}[]
	for i in 2:n
		push!(e,(a[1,i-1],a[1,i],a[2,i]-a[2,i-1]))
	end
	a = sortcols(a,by=x->x[3])
	for i in 2:n
		push!(e,(a[1,i-1],a[1,i],a[3,i]-a[3,i-1]))
	end
	m = 1
	e = sort(e, by=x->x[3])
	uf = -ones(Int,n)
	w = 0
	while m < n
		g = shift!(e)
		if !same(uf,g[1],g[2])
			unite(uf,g[1],g[2])
			m = max(m,-uf[root(uf,g[1])],-uf[root(uf,g[2])])
			w += g[3]
		end
	end
	println(w)
end

main()

Measured memory_bytes: 216788
#include <bits/stdc++.h>
int main() {
    int n;
    scanf("%d", &n);
    int h[n];
    for (int i = 0; i < n; i++) { scanf("%d", &h[i]); }
    
    int max = h[0];
    int count = 1;
    for (int i = 1; i < n; i++) { 
        if (h[i] >= max) { 
            max = h[i];
            count++;
        }
    }
    printf("%d", count);
    return 0;
}

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

int h, in, c, n;
int main(void){
    while(cin >> h) {
        if(h==0) break;
        int ans = 0;
        vector<vector<int> > b;
        rep(i, 0, h) {
            vector<int> r;
            rep(i, 0, 5) {
                cin >> in;
                r.push_back(in);
            }
            b.push_back(r);
        }
        bool combo;
        do {
            combo = false;
            rep(i, 0, h) {
                c = 0;
                n = 0;
                rep(j, 0, 3) {
                    if(b[i][j]!=0 && b[i][j]==b[i][j+1] && b[i][j+1]==b[i][j+2]) {
                        c = b[i][j];
                        n = 3;
                        b[i][j] = b[i][j+1] = b[i][j+2] = 0;
                        rep(k, j+3, 5) {
                            if(b[i][k]==c) {
                                n++;
                                b[i][k] = 0;
                            } else break;
                        }
                    } 
                }
                ans += n * c;
                if(c>0) combo = true;
            }
            if(combo) {
                rep(i, 0, 5) {
                    vector<int> nz;
                    rrep(j, h-1, 0) {
                        if(b[j][i]!=0) nz.push_back(b[j][i]);
                    }
                    int nzs = nz.size();
                    rrep(j, h-1, 0) {
                        if(nzs>0) {
                            b[j][i] = nz[h-1-j];
                            nzs--;
                        } else b[j][i] = 0;
                    }
                }
            }
        } while(combo);
        cout << ans << endl;
    }
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ll n;
  cin >> n;
  for (ll i = n; i < 1000; i++) {
    string s = to_string(i);
    if (s.at(0)==s.at(1) && s.at(1)==s.at(2)) {
      cout << i << endl;
      break;
    }
  }
}

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

#define lp(i,n) for(int i=0;i<n;i++)
#define lpin(a,i,n) for(int i=0;i<n;i++){cin>>a[i];}
using namespace std;

int main(){
  int a,b;
  cin>>a>>b;
  int ans=a+b+2,max=1;
  for(int i=2;i<min(a,b)+1;i++){
    if(a%i==0 && b%i==0){
      max=i;
    }
  }
  ans-=max+1;
  cout<<ans<<endl;
  return 0;
}



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

typedef int value_type; /* ソートするキーの型 */

/* x, y, z の中間値を返す */
value_type med3(value_type x, value_type y, value_type z) {
    if (x < y) {
        if (y < z) return y; else if (z < x) return x; else return z;
    } else {
        if (z < y) return y; else if (x < z) return x; else return z;
    }
}

/* クイックソート
 * a     : ソートする配列
 * left  : ソートするデータの開始位置
 * right : ソートするデータの終了位置
 */
void quicksort(value_type a[], int left, int right) {
    if (left < right) {
        int i = left, j = right;
        value_type tmp, pivot = med3(a[i], a[i + (j - i) / 2], a[j]); /* (i+j)/2 ではオーバーフローしてしまう */
        while (1) { /* a[] を pivot 以上と以下の集まりに分割する */
            while (a[i] < pivot) i++; /* a[i] >= pivot となる位置を検索 */
            while (pivot < a[j]) j--; /* a[j] <= pivot となる位置を検索 */
            if (i >= j) break;
            tmp = a[i]; a[i] = a[j]; a[j] = tmp; /* a[i], a[j] を交換 */
            i++; j--;
        }
        quicksort(a, left, i - 1);  /* 分割した左を再帰的にソート */
        quicksort(a, j + 1, right); /* 分割した右を再帰的にソート */
    }
}

int main(void){

  int N;
  scanf("%d\n", &N);

  int *A;
  A = (int*)malloc(N*sizeof(int));
  for(int i=0; i<N; i++){
    scanf("%d", &A[i]);
  }

  for(int i=0; i<N; i++){
    A[i] -= i+1;
  }

  quicksort(A,0,N-1);

  int mid = A[N/2];
  long long ans=0;

  for(int i=0; i<N/2; i++){
    ans += mid - A[i];
  }
  for(int i=N/2; i<N; i++){
    ans += A[i] - mid;
  }

  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <iterator>
#include <climits>
#include <unordered_map>
#include <functional>
#include <queue>

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

inline int ctoi(char c) {
    return (int)(c -'0');
}

// ----------------------------------------------------------

struct Info {
    ll c;
    ll s;
    ll f;
};

Info inputs[511];

int main() {
    ll n;
    cin >> n;
    rep(i, n - 1) {
        cin >> inputs[i].c >> inputs[i].s >> inputs[i].f;
    }

    rep(i, n) {
        ll time = 0;
        for(auto j = i; j < n - 1; ++j) {
            const Info& t_info = inputs[j];
            if (time <= t_info.s) {
                time = t_info.s;
            } else {
                ll sub = (time - t_info.s) % t_info.f;
                if (sub != 0) {
                    time += t_info.f - sub;
                }
                //cout << sub << ", " << time << endl;
            }
            time += t_info.c;
            //cout << t_info.c  << ", " << time << endl;
        }
        cout << time << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;

typedef long long Int;

Int gcd(Int a,Int b){
	if(a<b) return gcd(b,a);
	if(b==0) return a;
	return gcd(b,a%b);
}

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

int M,N,A,B,C,D;

Int calc(Int x,Int y){
	if(x==0) return 1;
	if(x%y==0) return 1;
	Int d=gcd(x,y);
	return y/d;
}

bool exi[100100];
Int getminS(Int a,Int c,Int m){
	for(int i=0;i<m;i++) exi[i]=false;
	int cur=0;
	while(true){
		if(exi[cur]) break;
		exi[cur]=true;
		cur+=a;
		cur%=m;
	}
	for(Int i=1;;i++){
		Int cur=(i*c)%m;
		if(exi[cur]) return i;
	}
	return -1;
}

Int getminL(Int a,Int c,Int m){
	c%=m;
	for(int i=1;;i++){
		Int cur=(a*i)%m;
		if(cur==c) return i;
	}
	return -1;
}

Int solve(){
	if(M==1&&N==1) return 0;
	Int s1=getminS(A,C,M);
	Int s2=getminS(B,D,N);
	Int s=lcm(s1,s2);
	Int l1=getminL(A,s*C,M);
	Int l2=getminL(B,s*D,N);
	Int dl1=calc(A,M);
	Int dl2=calc(B,N);
	Int d=gcd(dl1,dl2);
	Int coe=l1-l2;
	if(coe<0) coe*=-1;
	Int k=calc(coe,d);
	
	Int t=lcm(dl1,dl2);
	
	return t*k*s-1;
}

int main(){
	cin>>M>>N>>A>>B>>C>>D;
	Int ans=solve();
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 1256
n=int(input())
l=input().rstrip().split()
m=int(input())
ans=[]
A=0
for i in range(m):
    p,x=[int(i) for i in input().rstrip().split()]
    for j in range(len(l)):
        if p-1==j:
            A+=x
        else:
            A+=int(l[j])
    print(A)
    A=0

Measured memory_bytes: 3060
N = int(input())
S = input()

cum_sum_w = [0] * (N + 1)
cum_sum_e = [0] * (N + 1)


for i in range(N):

    if (S[i] == "W"):
        cum_sum_w[i+1] = cum_sum_w[i] + 1
        cum_sum_e[i+1] = cum_sum_e[i] + 0
    else:
        cum_sum_w[i+1] = cum_sum_w[i] + 0
        cum_sum_e[i+1] = cum_sum_e[i] + 1

ans = 10**100  

for i in range(N):
    tmp_ans = cum_sum_w[i] + (cum_sum_e[N] - cum_sum_e[i + 1])
    ans = min(ans,tmp_ans)
    
print((ans))

Measured memory_bytes: 32824
using System;
using System.Linq;

namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
      string S=Console.ReadLine();
      string T=Console.ReadLine();
      int ans=0;
      for(int i=0;i<3;i++){
        if(S.Substring(i,1)==T.Substring(i,1)){
          ans++;
        }
           }
           Console.WriteLine(ans);
    }    
  }

}



Measured memory_bytes: 25792
#include <iostream>
 
using namespace std;
 
int main(){
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	int points = 0;
	int n;
	cin >> n;
	int a[n],b[n],c[n-1];
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n; i++) cin >> b[i];
	for (int i = 0; i < n - 1; i++) cin >> c[i];
	for (int i = 0; i < n; i++) {
		points += b[a[i]-1];
		if ((i > 0) && (a[i] - a[i-1] == 1)) points += c[a[i-1]-1];
	}
	cout << points;
	return 0;
}

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

// 💖 Hi, thanks for using ICIE! 💖
// 🔧 To use a custom code template, set it in Settings(Ctrl+,) in "Icie Template List" entry 🔧
// 📝 If you spot any bugs or miss any features, create an issue at https://github.com/pustaczek/icie 📝

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int a, b;
    cin>>a>>b;
    if(a<b){
        cout<<"0\n";
    }
    else
        cout<<"10\n";
}


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

#define INF 1e9
#define MAX 100005
#define xx first
#define yy second
#define pb push_back
#define mp make_pair
#define ull long long
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define nl '\n'
#define zai <<' '<<
#define all(a) a.begin(),a.end()
#define pc __builtin_popcount
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int a,p;
	cin >> a >> p;
	cout << (a*3+p)/2;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
int a[100100];

void solve() {
    int sum = 0;
    for (int i = 1; i <= n+1; i++) sum += abs(a[i] - a[i-1]);

    for (int i = 1; i <= n; i++) {
        cout << sum - abs(a[i]-a[i-1]) - abs(a[i] - a[i+1]) + abs(a[i-1] - a[i+1]) << endl;
    }
}

void input() {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
}

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

    input();
    solve();
}


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

map<pair<long long, long long>, int> freq;

long long findGCD(long long Ai, long long Bi)
{
    if(Ai == 0)
        return Bi;
        
    if(Bi == 0)
        return Ai;
        
    return findGCD(Bi % Ai, Ai);
}

long long precomp[200005];
const long long modConst = 1000000007;

pair<long long, long long> Negate(pair<long long, long long> old)
{
    if(old == make_pair(0ll, 1ll))
        return make_pair(1ll, 0ll);
        
    else if(old == make_pair(1ll, 0ll))
        return make_pair(0ll, 1ll);
        
    pair<long long, long long> ans = make_pair(-old.second, old.first);
    if(ans.second < 0)
    {
        ans.second *= -1;
        ans.first *= -1;
    }
    
    return ans;
}

int main()
{
    precomp[0] = 1;
    for(int i = 1; i < 200005; i++)
        precomp[i] = (precomp[i - 1] * 2) % modConst;
        
    int N;
    scanf("%d", &N);
    
    long long numWays = 1, numWays00 = 0;
    for(int i = 1; i <= N; i++)
    {
        long long Ai, Bi;
        scanf("%lld%lld", &Ai, &Bi);
        
        if(Ai == 0 && Bi == 0)
        {
            numWays00++;
            continue;
        }
        
        else if(Ai == 0)
            freq[make_pair(0, 1)]++;
        
        else if(Bi == 0)
            freq[make_pair(1, 0)]++;
            
        else
        {
            long long GCD = findGCD(abs(Ai), abs(Bi));
            if(Bi > 0)
            {
                Ai /= GCD;
                Bi /= GCD;
            }
            
            else
            {
                Ai = (-Ai) / GCD;
                Bi = (-Bi) / GCD;
            }
            
            freq[make_pair(Ai, Bi)]++;
        }
    }

    while(!freq.empty())
    {
        map<pair<long long, long long>, int>::iterator itr = freq.begin();
        long long numWays1 = (precomp[itr -> second] - 1 + modConst) % modConst, numWays2;
        
        pair<long long, long long> negated = Negate(itr -> first);
        map<pair<long long, long long>, int>::iterator itr2 = freq.find(negated);
        
        if(itr2 == freq.end())
            numWays2 = (precomp[0] - 1 + modConst) % modConst;
            
        else
        {
            numWays2 = (precomp[itr2 -> second] - 1 + modConst) % modConst;
            freq.erase(itr2);
        }
        
        numWays *= (numWays1 + numWays2 + 1 + modConst) % modConst;
        numWays = (numWays + modConst) % modConst;
        
        freq.erase(itr);
    }
    
    printf("%lld", (numWays - 1 + modConst + numWays00) % modConst);
}

Measured memory_bytes: 17632
#include <iostream>
#include <vector>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <regex>
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pl4 = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using vvs = vector<vs>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vpii = vector<pii>;
using vvpii = vector<vpii>;
using vpl4 = vector<pl4>;
using vvpl4 = vector<vpl4>;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define rFOR(i,a,b) for(int i=(b);i>=(a);i--)
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) sort((a).rbegin(),(a).rend())
#define UNIQUE(a) (a).erase(unique((a).begin(),(a).end()),(a).end())
#define PREVP(a) prev_permutation((a).begin(),(a).end())
#define NEXTP(a) next_permutation((a).begin(),(a).end())
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Say(a) cout <<(a);
#define Sal(a) cout <<(a)<<endl;
#define dbg(a) cout <<(#a)<<": "<<(a)<<endl;
#define a2l(a) ((ll)(a-97))
#define A2l(a) ((ll)(a-65))
#define l2a(a) ((char)(a+97))
#define l2A(a) ((char)(a+65))

#define int ll

const ll MOD = 1e9+7;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll min(ll a, ll b){if(a>=b) return b;if(a<b) return a;}
ll max(ll a, ll b){if(a>=b) return a;if(a<b) return b;}

ll isP(ll n){
    if(n<=1) return 0;
    FOR(i,2,(ll)sqrt(n)){
        if(n%i==0) return 0;
    }
    return 1;
}

ll BinS(vll a,ll b){
    ll min=0,max=a.size()-1,mid=0;;
    while(1){
        mid=(min+max)/2;
        if(a[min]==b) return min;
        if(a[mid]==b) return mid;
        if(a[max]==b) return max;
        if(max-min<=2) return -1;
        if(a[mid]<b) min=mid;
        if(a[mid]>b) max=mid;
    }
}

//seiki
//#include <regex>
/*bubun*/
//regex_search("u32", regex("[0-9]"));      // true
/*kanzen*/
//regex_match("u32", regex("(i|u)\\d+"));   // true

signed main() {
    
    ll N,M=0;
    cin >>N;
    FOR(i,0,10){
        M+=(ll)((N%(ll)pow(10,i+1))/(ll)pow(10,i));
    }
    Yn(N%M==0);
    
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){

  int X, Y;
  int XX, YY, a, b;

  cin >> X >> Y;

  XX = X * 2;
  YY = Y / 2;

  a = XX - YY;
  b = YY - X;
  //cout << a << " " << b << endl;


  if(a>=0 && b>=0 && X==a+b && Y==2*a+4*b) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=(k);i++)
#define INF ((int)1<<28)
#define mk(i,j) make_pair(i,j)

#define N 200
#define M 10000
#define R 1000
int sdst[N][N];
int ldst[N][N];
int dp[R+1][N];

using namespace std;
int main(){
	int n,m;
	while(cin >> n >> m){
		if(!n)break;
		rep(i,n)rep(j,n){
			sdst[i][j] = ldst[i][j] = i==j?0:INF;
		}
		rep(i,m){
			int x,y,t;
			string s;
			cin >> x >> y >> t;
			x--;y--;
			cin >> s;
			if(s[0]=='L'){
				ldst[x][y] = ldst[y][x] = min(ldst[x][y],t);
			}else{
				sdst[x][y] = sdst[y][x] = min(sdst[x][y],t);
			}
		}
		rep(k,n)rep(i,n)rep(j,n){
			ldst[i][j] = min(ldst[i][j],ldst[i][k] + ldst[k][j]);
			sdst[i][j] = min(sdst[i][j],sdst[i][k] + sdst[k][j]);
		}
		int r,zp;
		cin >> r;
		rep(i,r)rep(j,n)dp[i][j]=INF;
		cin >> zp;
		zp--;
		dp[0][zp]=0;
		rep(i,r-1){
			int z;
			cin >> z;
			z--;
			rep(j,n)rep(k,n){
				dp[i+1][k] = min(dp[i+1][k],
				 dp[i][j] + (j==k?ldst[zp][z]:ldst[zp][j] + sdst[j][k] + ldst[k][z]));
			}
			zp = z;
		}
		int ans = INF;
		rep(i,n)ans = min(dp[r-1][i],ans);
		cout << ans << endl;
	}
}

Measured memory_bytes: 2296
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define String std::string
#define fir first
#define sec second
#define mp std::make_pair
#define Pair std::pair<int, int>
#define Map std::map< int, int >
#define Vector std::vector<int>

typedef long long ll;
typedef unsigned long long ull;

const int N = 100000 + 5;
const int M = 3000 + 5;
const int MOD = 1e9 + 7;
const int inv2 = 500000004;
const int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
const int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

template<class T>
inline T readT() {
    T res = 0, f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) res = (res << 1) + (res << 3) + ch - '0';
    return res * f;
}
#define read readT<int>

int n, k;
int buc[N * 2];

int main() {
    std::cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        buc[i % k]++;
    }
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        int tmp = (k - i % k) % k;
        if ((tmp + tmp) % k == 0) ans += (ll)buc[tmp] * buc[tmp];
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <unordered_set>

#define ll long long int
#define mod 1000000007

using namespace std;


int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll m, n;
    cin >> m >> n;
    
    vector<vector<int>> vec(m,vector<int>(n, 0));
    for(int i= 0; i<m;i++){
        for(int j = 0;j<n;j++){
            char x;
            cin >> x;
            vec[i][j] = x;
        }
    }
    
    vector<vector<int>> dp(m,vector<int>(n, 0));
    
    dp[0][0] = (vec[0][0] == '#');
    
    // for(int i = 1;i<dp.size();i++){
    //     dp[0][i] = 1e5;
    //     dp[0][j] = min(dp[0][j], dp[i][j - 1] + (vec[i][j - 1] == '.' && vec[i][j] == '#'));
    // }
    
    // for(int i = 1;i<dp.size();i++){
    //     dp[i][0] = dp[i-1][0] + (vec[i-1][0] == '.' && vec[i][0] == '#');
    // }
    
    // for(int i= 1; i<m;i++){
    //     for(int j = 1;j<n;j++){
    //         dp[i][j] = 1e5;
    //         dp[i][j] = min(dp[i][j], dp[i - 1][j] + (vec[i - 1][j] == '.' && vec[i][j] == '#'));
    //         dp[i][j] = min(dp[i][j], dp[i][j - 1] + (vec[i][j - 1] == '.' && vec[i][j] == '#'));
    //         // dp[i][j] = min(dp[i-1][j] + (vec[i-1][j] == '.' && vec[i][j] == '#')
    //         //               ,dp[i][j-1] + (vec[i][j-1] == '.' && vec[i][j] == '#'));
            
    //     }
    
    // }
    
    vector<vector<int>> f(m, vector<int>(n));
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      if (i + j == 0) {
        f[0][0] = (vec[0][0] == '#');
        
      } else {
        f[i][j] = (int) 1e9;
        if (i > 0) f[i][j] = min(f[i][j], f[i - 1][j] + (vec[i - 1][j] == '.' && vec[i][j] == '#'));
        if (j > 0) f[i][j] = min(f[i][j], f[i][j - 1] + (vec[i][j - 1] == '.' && vec[i][j] == '#'));
      }
    //   cout << f[i][j] << " ";
     
    }
    // cout << '\n';
  }
    
    cout << f[m-1][n-1];
}








Measured memory_bytes: 384
module IntMap = Map.Make (struct
  type t = int
  let compare = compare
end)

let () = Scanf.scanf "%d %d\n" @@ fun n m ->
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  let (acc, _, _) = Array.fold_left (fun (acc, offset, map) a ->
    let offset = (offset + a) mod m in
    let map = IntMap.add ((a + m - offset) mod m) (1 + try IntMap.find ((a + m - offset) mod m) map with Not_found -> 0) map in
    acc + (try IntMap.find ((m - offset) mod m) map with Not_found -> 0), offset, map) (0, 0, IntMap.empty) as_ in
  Printf.printf "%d\n" acc


Measured memory_bytes: 9344
#include <iostream>
using namespace std;
int main(void) {
	int a,b;
	cin >> a >> b;
	if (a == 1)a = 14;
	if (b == 1)b = 14;
	if (a > b) {
		cout << "Alice" << std::endl;
	}
	else if (a < b)
	{
		cout << "Bob" << std::endl;
	}
	else
	{
		cout << "Draw" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 384
import java.util.*;
public class Main {
	
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		Integer[] A = new Integer[M];
		for(int i=0;i<M;i++) {
			A[i] = sc.nextInt();
		}
		StringBuilder ret = new StringBuilder();
		int[] dp = new int[N+1];
		int[] cost = new int[] {0,2,5,5,4,5,6,3,7,6};
		dp_num_order(dp,A,cost);
		Arrays.sort(A,Collections.reverseOrder());
		int match = N;
		while (match > 0) {
			for(int a : A) {
				if(match-cost[a]>=0 && dp[match] == 1+dp[match-cost[a]]) {
					ret.append(a);
					match -= cost[a];
					break;
				}
			}
		}
		System.out.println(new String(ret));
	}
	
	public static void dp_num_order(int[] dp, Integer[] A, int[] cost) {
		dp[0] = 0;
		for(int i=1;i<dp.length;i++) {
			int maxval = Integer.MIN_VALUE;
			for(int j : A) {
				if (i-cost[j] < 0) continue;
				if(dp[i-cost[j]]+1 > maxval) maxval = dp[i-cost[j]]+1;
			}
			dp[i] = maxval;
		}
	}
}


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

public class Main {
    public static void main(String[] args) throws IOException {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        final int N = sc.nextInt();
        boolean flg = true;
        for (int i = 0; i < N; i++) {
            int Ai = sc.nextInt();
            if (Ai % 2 == 0) {
                if ((Ai % 3 != 0) && (Ai % 5 != 0)) {
                    flg = false;
                    break;
                }
            }
        }
        out.println(flg ? "APPROVED" : "DENIED");
        out.flush();
    }
}

// FastScanner start
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}
// FastScanner end

Measured memory_bytes: 21204