akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const int MAX = 1005;

bool seen[MAX];
int minw = INF;
vector<pair<int, int>> w;

ll solve(int x) {
  int idx = x, minr = INF, sumr = 0;
  vector<int> r;
  while (1) {
    r.push_back(w[idx].first);
    minr = min(minr, w[idx].first);
    sumr += w[idx].first;
    seen[idx] = true;
    if (x == w[idx].second) break;
    idx = w[idx].second;
  }
  if (r.empty()) return 0;

  int n = r.size();
  ll sum1, sum2;
  sum1 = sumr + (n-2) * minr;
  sum2 = sumr + minr + (n+1) * minw;

  return min(sum1, sum2);
  

}

int main() {
  int n;
  cin >> n;
  pair<int, int> p;
  rep(i, n) {
    cin >> p.first;
    minw = min(minw, p.first);
    p.second = i;
    w.push_back(p);
    seen[i] = false;
  }

  sort(w.begin(), w.end());

  ll ans = 0;
  rep(i, n) {
    if (!seen[i]) {
      ans += solve(i);
    }
  }

  cout << ans << endl;

  
  return 0;
}


Measured memory_bytes: 3136
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, L: "List[int]"):
    L.sort()
    return YES if sum(L[:-1]) > L[-1] else NO


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(solve(N, L))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,a,b) for(ll i=a;i <= b;i++)
#define fast_io ios_base::sync_with_stdio(false)
#define pb push_back
#define fir first
#define sec second
#define tr(it,x) for(it = x.begin();it != x.end();it++)
#define mp make_pair
#define sz(x) (ll)x.size()
#define rep(i,n) for(ll i=0;i<n;i++)
#define double long double
#define accuracy ll precision = numeric_limits<double>::digits10
#define pll pair<ll,ll>
#define N 100005

ll n,k,dp[N],h[N];

int main() {
	// freopen("input.txt", "r", stdin); 
	// freopen("output.txt", "w", stdout);
	fast_io;	 
	accuracy;
	cin >> n;
	k = 2;
	fr(i,1,n) cin >> h[i];
	fr(i,0,N-1) dp[i] = LLONG_MAX;
	dp[1] = 0;
	fr(i,2,n) {
		fr(j,max(1ll,i-k),i-1) {
			dp[i] = min(dp[i],dp[j] + abs(h[i] - h[j]));
		}
	}
	cout << dp[n] << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string.h>
#include <cstdio>
using namespace std;

char MAP[8][9];//}bvîñ

void rotate(){//}bvð90xñ]
  char bM[8][9];
  memcpy(bM,MAP,72);
  for(int i = 0 ; i < 8 ; i++){
    for(int j = 0 ; j < 8 ; j++){
      MAP[i][j] = bM[7-j][i];
    }
  }
}
void showmap() {//}bvðoÍ
  for(int i = 0 ; i < 8 ; i++){
    printf("%s\n",MAP[i]);
  }
}
int main(){
  for(int i = 0 ; i < 8 ; i++){
    scanf("%s",MAP[i]);
  }
  for(int i = 1 ; i <= 3 ; i++) {
    printf("%d\n", 90*i);
    rotate();
    showmap();
  }
  return 0;
}

Measured memory_bytes: 0
// Problem : C - A x B + C
// Contest : AtCoder - AtCoder Beginner Contest 179
// URL : https://atcoder.jp/contests/abc179/tasks/abc179_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

// Macros

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int, int>
#define mii map<pii, int>
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(x) (int) x.size()
#define mod 1000000007
#define EPS 1e-9
#define inf 1e10
#define PI acos(-1.0)
#define int long long
#define N 100005

// Solution

void solve() {
  int n;
  cin >> n;
  int ans = 0;
  for (int a = 1; a < n; a++) {
    for (int b = 1; b < n; b++) {
      if (a * b >= n) break;
      ans++;
    }
  }
  cout << ans;
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

  int tests;
  tests = 1;
  // cin>>tests;

  for (int test = 1; test <= tests; test++) {
    // cout<<"Case #"<<test<<": ";
    solve();
  }

  return 0;
}

Measured memory_bytes: 3652
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        int r = 0;
        int b = 0;
        for (int i = 0; i < n; i++) {
            if (s.charAt(i) == 'R') {
                r++;
            } else {
                b++;
            }
        }
        if (r > b) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }    
}


Measured memory_bytes: 23252
a = input()
n = len(a)

s = 0 # s[0]の余り
c = [0] * 2019 # c[i] = 余り i の個数
c[s] += 1
d = 1 # 10**i mod 2019

for i in range(n):
    s = (s + d * int(a[n-i-1])) % 2019 # s[i+1]の余り
    d = d * 10 % 2019 #10**(i+1) mod 2019
    c[s] += 1

print(int(sum([i*(i-1)/2 for i in c])))

Measured memory_bytes: 9216
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
using namespace std;

int main ()
{
	int n; cin >> n;
	vector<int> a(n);

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

	int ans = 0;
	int count = 0;
	int value = 0;
	for (int i=0; i<n; ++i)
	{
		if (value == a[i])
		{
			++count;
		}
		else
		{
			ans += count / 2;
			value = a[i];
			count = 1;
		}
	}
	ans += count / 2;

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

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

int main() {
  int64_t b;

  while (cin >> b, b) {
    for (int64_t d = sqrt(2 * b); d > 0; --d) {
      int64_t a = (2 * b + d - d * d) / (2 * d);
      if (a <= 0) continue;
      if ((a + d) * (a + d - 1) - a * (a - 1) == 2 * b) {
        cout << a << " " << d << endl;
        break;
      }
    }
  }
}



Measured memory_bytes: 3096
N, M = map(int, input().split())
c = [tuple(map(int, input().split())) for _ in range(M)]
right = N
left = 1
for i in range(0, M):
    left = max(left, c[i][0])
    right = min(right, c[i][1])
print(len(range(left, right+1)))

Measured memory_bytes: 16632
#include<stdio.h>
#include<string.h>
//言語は「C++14(GCC 5.4.1)」
//AtCoder Beginner Contest 43-A

int main(void)
{
	int i, S=0, N;
	scanf("%d", &N);
	for(i=0; i<=N; i++)
	{
		S = S + i;
	}
	printf("%d", S);
	return 0;
}

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

int n;
vector<int> s(1000000);

int binarySearch(int key){
  int left = 0;
  int right = n;

  while(left < right){
    int mid = (left + right) / 2;

    if(key == s[mid]) return 1;

    else if(key < s[mid]) right = mid;

    else left = mid + 1;

  }

    return 0;

}

int main()
{
  int q, k, sum = 0;

  cin >> n;
  for(int i = 0; i < n; i++) cin >> s[i];

  cin >> q;
  for(int i = 0; i < q; i++){
    cin >> k;
    if(binarySearch(k)) sum++;
  }

  cout << sum << endl;

  return 0;

}



Measured memory_bytes: 6600
#include <iostream>
#include <array>
#include <algorithm>

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

int main(){
    array<ll, 3> a;
    REP(i, 3){
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    REP(i, 3){
        cout << a.at(i);
        if(i < 2){
            cout << ' ';
        }
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3144
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <map>

using namespace std;

void solve()
{
	string s;
	cin >> s;
	reverse(s.begin(), s.end());
	for (int i = 0; i < s.size(); ++i)
	{
		if (i + 4 < s.size() && s[i] == 'm' && s[i + 1] == 'a' && s[i + 2] == 'e' && s[i + 3] == 'r' && s[i + 4] == 'd')
		{
			i += 4;
		}
		else if (i + 6 < s.size() && s[i] == 'r' && s[i + 1] == 'e' && s[i + 2] == 'm' && s[i + 3] == 'a' && s[i + 4] == 'e' && s[i + 5] == 'r' && s[i + 6] == 'd')
		{
			i += 6;
		}
		else if (i + 4 < s.size() && s[i] == 'e' && s[i + 1] == 's' && s[i + 2] == 'a' && s[i + 3] == 'r' && s[i + 4] == 'e')
		{
			i += 4;
		}
		else if (i + 5 < s.size() && s[i] == 'r' && s[i + 1] == 'e' && s[i + 2] == 's' && s[i + 3] == 'a' && s[i + 4] == 'r' && s[i + 5] == 'e')
		{
			i += 5;
		}
		else
		{
			cout << "NO" << endl;
			return;
		}
	}
	cout << "YES" << endl;
}

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

Measured memory_bytes: 512
#include <string>
#include <time.h>
#include <vector>
#include <map>
#include <set>
#include <sstream>
#include <algorithm>
#include <bitset>
#include <utility>
#include <iostream>
#include <cmath>
#include <deque>

#define MOD 1000000007
#define pii pair<ll,ll>
#define X first
#define Y second
#define mp make_pair

typedef int ll;
using namespace std;
#define MAXN 1488228
ll x, y, n;
ll a[250005], b[150005], dp[200500][4];

int main() {
    string s;
    cin >> s;
    n = s.size();
    for (int i = 0; i < n; i++) {
        a[i] = s[i] - 'a';
    }
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j < 2; j++) {
            dp[i][j] = -MOD;
        }
    }
    dp[1][1] = dp[2][2] = 1;
    for (int i = 1; i < n; i++) {
        for (int k = 1; k <= 2; k++) {
            for (int j = 1; j <= 2 && i + j <= n; j++) {
                if (j != k) {
                    dp[i + j][j] = max(dp[i+j][j], dp[i][k] + 1);
                } else {
                    bool flag = false;
                    for (int l = 0; l < j; l++) {
                        if (a[i + l] != a[i-j+l]) {
                            flag = true;
                        }
                    }
                    if (flag) {
                        dp[i + j][j] = max(dp[i+j][j], dp[i][k] + 1);
                    }
                }
            }
        }
    }
    cout << max(dp[n][1], dp[n][2]) << endl;
    return 0;
}

Measured memory_bytes: 5632
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<vector>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define FOR(i,s,e) for (int i=s;i<e;i++)
#define FOE(i,s,e) for (int i=s;i<=e;i++)
#define FOD(i,s,e) for (int i=s;i>=e;i--)
#define SET(a,e) memset(a,e,sizeof(a))
#define LL long long
#define LD long double
#define pb push_back
#define x first
#define y second
#define PII pair<int,int>
#define PLI pair<LL,int>
#define PIL pair<int,LL>
#define PLL pair<LL,LL>
#define eps 1e-9
#define mp make_pair

int n,m,ans,tmp,c[100005];

int main () {
	scanf("%d",&n);
	FOE(i,1,n) {
		scanf("%d",&tmp);
		++c[tmp];	
	}
	FOE(i,1,100002) {
		ans=max(ans,c[i-1]+c[i]+c[i+1]);	
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 512
from operator import itemgetter

n = int(input())
r = []
b = []
c = 0
for i in range(n):
  r.append(list(map(int,input().split())))
for i in range(n):
  b.append(list(map(int,input().split())))
r.sort(key = itemgetter(1),reverse = True)
b.sort(key = itemgetter(0))
for i in range(n):
  for j in range(n):
    if b[i][0] > r[j][0] and b[i][1] > r[j][1]:
      r[j] = [10**6,10**6]
      c += 1
      break
print(c)
    


Measured memory_bytes: 3064
include Math

d, n, bounce_max = gets.split.map(&:to_i)
all_obs = (1..n).map { gets.split.map(&:to_i) }
min = Float::INFINITY

EPS = 0.00001

(0..bounce_max).each do |bounce|
    bounce_point = (0..bounce+1).map {|k| k * d.to_f / (bounce + 1)}
    next if bounce_point.any? {|x| all_obs.map(&:first).any?{|u| (x - u).abs < EPS}}

    candidates = [sqrt(d.to_f / (2 * (bounce + 1)))]

    bounce_point.each_cons(2) do |x1, x2|
        obs = all_obs.select {|x, y| x1 < x && x < x2}
        obs.each do |u, v|
            a = v.to_f / ((u - x1) * (x2 - u))
            candidates << sqrt(1 / (2 * a))
        end
    end

    candidates.select! do |vx|
        bounce_point.each_cons(2).all? do |x1, x2|
            obs = all_obs.select {|x, y| x1 < x && x < x2}
            if obs.empty?
                true
            else
                obs.all? do |u, v|
                    a = 1 / (2 * vx ** 2)
                    obs.all? {|u, v| v <= a * (u - x1) * (x2 - u) + EPS} 
                end
            end
        end
    end

    next if candidates.empty?

    m = candidates.map {|vx|
        a = 1 / (2 * vx ** 2)
        vy = vx * a * d / (bounce + 1)
        hypot(vx, vy)
    }.min

    min = m if m < min
end

p min

Measured memory_bytes: 8860
#include<bits/stdc++.h>
#define LL long long
#define Max 100005
const LL mod=1e9+7;
const LL LL_MAX=9223372036854775807;
using namespace std;
int n,a,b,c,d;
char s[200005];
int main()
{
    scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);
    scanf("%s",s+1);
    int en=max(c,d);
    for(int i=a; i<=en; i++)
    {
        if(s[i]=='#' && s[i-1]=='#')
        {
            printf("No\n");
            return 0;
        }
    }
    if(s[c]=='#' || s[d]=='#')
    {
        printf("No\n");
        return 0;
    }
    int flag=0;
    for(int i=b; i<=min(c,d); i++)
    {
        if(s[i]=='.' && s[i-1]=='.')
        {
            if(s[i+1]=='.')
                flag=1;
        }
    }
    if(c>d)
    {
        if(flag)
            printf("Yes\n");
        else
            printf("No\n");
    }
    else
        printf("Yes\n");
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
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(){

  while(1){
      int a,b ;
      cin>>a>>b ;
  if(a==0&&b==0) break ;
  int c= a*a+ b*b ;int d= b ;
  bool flag = 0;
  for(int i = a+1 ;i*i<c;i++){
      d= b ;
     while(i*i+d*d>=c){
         if(i>=d) break ;
         if(i*i+d*d==c){
             cout<<i<<" "<<d<<endl ;
             flag= 1 ;
             break ;
         }
         else d-- ;
     }
     if(flag) break ;
  }
  if(flag) continue ;

  while(!flag){
      c++ ;
   for(int i=1 ;i*i<c;i++){
       if(flag) break ;
      int res= c- i*i ;
      rep2(j,i+1,res){
          if(j*j>res) break ;
          if(j*j==res){
              cout<<i<<" "<<j<<endl ;
              flag=1 ;
              break ;
          }
      }
    
   }
  } 

  }
  return 0 ; 
}




Measured memory_bytes: 3004
#include<stdio.h>

int main(void)

{

int a,b,c ;

int count = 0 ;

int i ;

scanf("%d %d %d",&a,&b,&c);

for(i=a ;i<=b ;i++){

if(c%i==0) count++ ;

}

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

return 0 ;

}
 

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define inf (ll)1e9
#define mod (ll)(1e9+7)
#define d(x) cerr<<#x<<"="<<x<<endl;
#define p(x) cout<<(x)<<endl
#define ps(x) cout<<(x);
#define pk(x) cout<<(x)<<" ";
#define pfix(d,x) cout << fixed << setprecision(d) << x << endl;
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define minel(v) *min_element(all(v))
#define minind(v) distance((v).begin(), min_element(all(v)))
#define maxel(v) *max_element(all(v))
#define maxind(v) distance((v).begin(), max_element(all(v)))
#define fi first
#define se second
ll a[51],b[51],c,d,n,m,x,y,z,h,w,k,sum,mi=inf,ma=-inf,ans,s,t,l,r,res,tmp,itr,p,q;
bool flag;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int dx8[8]={1,1,0,-1,-1,-1,0,1},dy8[8]={0,1,1,1,0,-1,-1,-1};
char cha;
string st;
typedef map<ll, ll> imap;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<pair<ll,ll> > VP;


ll burger(ll x, ll l){
   //d(x)d(l)
   if(l==0)return 1;
   if(x<=1)return 0;
   else if(x<2+b[l-1])return burger(x-1, l-1);
   else if(x==2+b[l-1])return a[l-1]+1;
   else if(x<b[l])return a[l-1]+1+burger(x-2-b[l-1], l-1);
   else return a[l];
}

int main(void){
    cin>>n>>x;
    a[0]=1;
    b[0]=1;
    rep(i,1,51)a[i]=2*a[i-1]+1;
    rep(i,1,51)b[i]=2*b[i-1]+3;
    p(burger(x,n));
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double db;
#define pb(x) push_back(x)
#define mkp(x,y) make_pair(x,y)
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
//char buf[1<<21],*p1=buf,*p2=buf;
#define int long long
inline int read() {
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)) {if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch))x=x*10+(ch^48),ch=getchar();
	return x*f;
}
int n,tot,ans,a[100];
void exgcd(int a,int b,int &x,int &y){
	if(!b){x=1;y=0;return;}
	exgcd(b,a%b,y,x);
	y-=a/b*x;
}
int solve(int a,int b){
	int x,y;
	exgcd(a,b,x,y);
	x=(x%b+b)%b;
	if(!x)x=b;
	y=(1-a*x)/b;
	y=-y;
	if(y<=0) return n;
//	cout << a <<" "<< b <<" "<< x <<" "<< y <<" "<< a * x<< endl;
	return a*x;
}
bool isp(int x){
	for(int i=2;i*i<=x;++i)if(x%i==0)return 0;
	return 1;
}
signed main(){
	cin>>n, ans = 2 * n;
	if(n==1) puts("1"),exit(0);
	n=n*2;
	int tmp=n;
	for(int i=2;i*i<=tmp;++i){
		if(tmp%i==0){
			++tot,a[tot]=1;
			while(tmp%i==0)tmp/=i,a[tot]*=i;
		}
	}
	if(tmp)a[++tot]=tmp;
	for(int msk=0;msk<(1<<tot)-1;++msk){
		int x=1,y=1;
		for(int j=0;j<tot;++j)
			if(msk>>j&1)x*=a[j+1];
			else y*=a[j+1];
		ans=min(ans,min(solve(x,y),solve(y,x)));
	}
	cout<<ans-1<<endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	int N, C;
	cin >> N >> C;
	int D[C][C], c[N][N];
	rep(i, 0, C) rep(j, 0, C) cin >> D[i][j];
	rep(i, 0, N) rep(j, 0, N) cin >> c[i][j], c[i][j]--;

	int cost[3][C];
	memset(cost, 0, sizeof(cost));
	rep(ci, 0, C) rep(i, 0, N) rep(j, 0, N) {
		cost[(i + j) % 3][ci] += D[c[i][j]][ci];
	}

	int c_array[3];
	int rsl = 1 << 30;
	for(c_array[0] = 0; c_array[0] < C; c_array[0]++) {
		for(c_array[1] = 0; c_array[1] < C; c_array[1]++) {
			if(c_array[0] == c_array[1]) continue;
			for(c_array[2] = 0; c_array[2] < C; c_array[2]++) {
				if(c_array[0] == c_array[2] or c_array[1] == c_array[2]) continue;
				int tmp = 0;
				rep(i, 0, 3) tmp += cost[i][c_array[i]];
				rsl = min(rsl, tmp);
			}
		}
	}

	cout << rsl << endl;

	
}


Measured memory_bytes: 1280
#[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)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      m: usize,
      dcs: [(usize, usize); m],
    }

    let mut ans: usize = 0;
    let mut rems = vec![];
    for (mut d, mut c) in dcs {
        while c>0 {
            if c%2 == 1 {
                rems.push(d)
            }
            ans += c/2;
            if d >= 5 {
                ans += c/2;
            }
            d *= 2;
            d = d/10 + d%10;
            c /= 2;
        }
    }

    if rems.len() > 0 {
        let mut cur = rems[0];
        for i in 1..rems.len() {
            cur += rems[i];
            ans += 1;
            if cur >= 10 {
                cur = cur/10 + cur%10;
                ans += 1;
            }
        }
    }
    puts!("{}\n", ans);
}


Measured memory_bytes: 40184
#include <cstdio>
#include <algorithm>
static int MAX_N = 10;
int K, X;
int MIN = -1000000;
int MAX = 1000000;
void solve();

int main(){

  scanf("%d %d", &K, &X);
  solve();
}

void solve(){
  int first, last;
  first = X-K+1;
  last = X+K-1;
  if(first<MIN){
    for(int i = MIN; i<MIN+K; i++){
      printf("%d ", i);
    }
    printf("\n");
  }else if(last >MAX){
    for(int i = MAX-K+1; i<MAX+1; i++){
      printf("%d ", i);
    }
    printf("\n");
  }else{
    for(int i = first; i<last+1; i++){
      printf("%d ", i);
    }
    printf("\n");
  }
}


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

public class Hello
{
    public static int MOD = 1000000007;
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        getAns(n);
    }
    static void getAns(int n)
    {
        var a1 = BigInteger.ModPow(10, n, MOD);
        var a2 = BigInteger.ModPow(9, n, MOD);
        var a3 = BigInteger.ModPow(8, n, MOD);
        var ans = (a1 + a3) % MOD;
        var t = (a2 * 2) % MOD;
        ans -= t;
        if (ans < 0) ans += MOD;
        ans %= MOD;
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 27640
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>

#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順

signed main(){
    int n,k;
    cin >> n >> k;
    int r,s,p;
    cin >> r >> s >> p;
    string t;
    cin >> t;
    int r1 = 0;
    int s1 = 0;
    int p1 = 0;
    REP(i,n){
        if(t[i]=='r'){
            if(i>=k && t[i-k]=='r') t[i] = '#';
            else p1 ++;
        }
        if(t[i]=='s'){
            if(i>=k && t[i-k]=='s') t[i] = '#';
            else r1 ++;
        }
        if(t[i]=='p'){
            if(i>=k && t[i-k]=='p') t[i] = '#';
            else s1 ++;
        }
    }
    cout << r*r1 + s*s1 + p*p1 << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, x, y) for (ll i = x; i <= y; i++)
#define BIT(t) (1ll << t)
#define PER(i, y, x) for (ll i = y; i >= x; i--)
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define pll pair<ll, ll>
#define SIZE(v) ll(v.size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
//        ios::sync_with_stdio(false);
//        cin.tie(nullptr);

int main(){
  ll n;
  cin >>n;
  vll a(n);
  bool flag = false;
  REP(i,0,n-1){
    cin >> a[i];
    if(a[i] == 0){
      flag = true;
    }
  }
  if(flag){
    cout << 0 << endl;
    return 0;
  }
  long double tmp = log10l(1e18);
  ll ans = 1;
  REP(i,0,n-1){
    tmp -= log10l(a[i]);
    if(tmp < 0){
      cout << -1 << endl; return 0;
    }
    ans *= a[i];
  }
  if(ans > ll(1e18)){
    cout << -1 << endl;
  }else{
    cout << ans << endl;

  }
}

Measured memory_bytes: 4040
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    while(true) {
      char[] number = in.next().toCharArray();
      if (number[0] == '0') break;
      int sum = 0;
      for (int i = 0; i < number.length; i++) {
        sum += Character.getNumericValue(number[i]);
      }
      System.out.println(sum);
    }
  }
}

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

// Macros
#define F      first
#define S      second
#define PB     push_back
#define MP     make_pair
#define ALL(c) c.begin(),c.end()

// Rename Datatypes
using ll  = long long;
using ld  = long double;
using pii = std::pair <int,int>;

// Random
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
/* [a,b] */ template<class T> T rnd_IntType(T a, T b){ return uniform_int_distribution<T>(a, b)(rng); }
/* [a,b) */ template<class T> T rnd_RealType(T a, T b){ return uniform_real_distribution<T>(a,b)(rng); }

// Common Functions
ll fastpow(ll a, ll ex){ ll res = 1; while(ex){ if(ex & 1) res *= a; a *= a; ex >>= 1; } return res; }
ll fastpow(ll a, ll ex, ll m){ a %= m; ll res = 1; while(ex){ if(ex & 1) res = (a*res) % m; a = (a*a) % m; ex >>= 1; } return res; }
ll modinverse(ll a, ll m){ ll m0 = m; ll y = 0, x = 1; while (a > 1){ ll q = a / m; a %= m; swap(a,m); x -= q*y; swap(x,y); } if(x < 0) x += m0; return x; }

// Output, Common Containers
template <typename T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <typename T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <typename T> ostream& operator << (ostream &os, const deque<T> &v) { for (T i : v) os << i << ' '; return os; }
template <typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << "(" << v.F << "=>" << v.S << ") "; return os; }
template <typename T, typename S> ostream& operator << (ostream &os, const map<T, S> &v) { for (auto i : v) os << i << ' '; return os; }

// Debugging
#ifdef LOCAL
	#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); d__f(_it, args); }
	void d__f(istream_iterator<string> it) {}
	template<typename Head, typename... Tail> void d__f(istream_iterator<string> it, Head H, Tail... T) { cerr << *it << " <=> [" << H << "]\n"; d__f(++it, T...); }
#else
	#define trace(args...)
#endif


// CODE STARTS HERE

const int modulo1 = 1e9+7;
const int modulo2 = 998244353;

const int mod = 1e9+7;

ll add(ll a, ll b) { return (a + b) % mod; }
ll sub(ll a, ll b) { return (a - b) % mod; }
ll mul(ll a, ll b) { return (a * b) % mod; }

signed main() {
	std::ios::sync_with_stdio(false); //Warning: Do NOT use C I/O now.
	std::cin.tie(nullptr); //Note: Comment out this line for interactive questions.
	// std::cout.setf(std::ios::fixed); std::cout.precision(20); //Note: To output decimals correctly.

	// int t; cin>>t;
	// for(int test_no = 1; test_no <= t; ++test_no){}

	int n, k;
	cin>>n>>k;

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

	vector<bool> dp(k+1, false);

	for(int i=0; i<=k; ++i)
		for(auto no: a)
			if(no <= i)
				dp[i] = dp[i] || !dp[i-no];
	
	cout<<(dp[k] ? "First\n" : "Second\n");
}

Measured memory_bytes: 256
#include <stdio.h>
int n, m, x, a, b;
int h[100000];
int e[100000];
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++) {
		scanf("%d", h + i);
	}
	for (int i = 0; i < m; i++) {
		scanf("%d%d", &a, &b);
		a--; b--;
		if (h[a] <= h[b]) {
			e[a]++;
		}
		if (h[b] <= h[a]) {
			e[b]++;
		}
	}
	for (int i = 0; i < n; i++) {
		if (!e[i])x++;
	}
	printf("%d\n", x);
}

Measured memory_bytes: 2508
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
#define int long long
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

int n[4];
bool ta[4] = {};

signed main() {
	cin >> n[0] >> n[1] >> n[2] >> n[3];
	for (int i = 0; i < 4; i++) {
		if (n[i] == 1)ta[0] = true;
		else if (n[i] == 4)ta[1] = true;
		else if (n[i] == 7)ta[2] = true;
		else if (n[i] == 9)ta[3] = true;
	}
	for (int i = 0; i < 4; i++) {
		if (ta[i] == false) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	getchar(); getchar();
	return 0;
}

Measured memory_bytes: 256
#include"iostream"
using namespace std;
int main()
{
	int x, a, b, c;
	cin >> x;
	a = x % 60;
	b = x / 60 % 60;
	c = x / 60 / 60;
	cout << c << ":" << b << ":" << a << endl;
	return 0;
}


Measured memory_bytes: 3104
#include <functional>
#include <iostream>
#include <vector>

using namespace std;

class UFTree {
private:
  const int N;           // 要素数
  std::vector<int> par;  // 各ノードの親のID（根ノードは自分を参照）
  std::vector<int> sizes;  // 各ノードを根とする木のサイズ（根でないノードには無関係）

public:
  UFTree(int n) : par(n), sizes(n, 1), N(n) {
    for (int i = 0; i < n; i++) par[i] = i;
  }

  // 要素xが属するグループの根ノードのIDを見つける
  int find(int x) {
    if (par[x] == x)
      return x;
    else
      return par[x] = find(par[x]);
  }

  // 要素x, yが属するグループ同士を統合する
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    if (sizes[x] < sizes[y]) {
      par[x] = y;
      sizes[y] += sizes[x];
    } else {
      par[y] = x;
      sizes[x] += sizes[y];
    }
  }

  // グループのリストを表示する
  // (IDが小さい順に表示される, O(n^2)なので最速の実装ではない)
  void show() {
    std::cout << "Groups : " << std::endl;
    std::function<void(int)> f = [&](int x) {
      std::cout << x << ',';
      for (int y = 0; y < N; y++) {
        if (par[y] == x && y != x) f(y);
      }
    };
    for (int i = 0; i < N; i++) {
      if (par[i] == i) {
        f(i);
        std::cout << std::endl;
      }
    }
  }

  // 要素x, yが同じグループに属するかどうか
  bool same(int x, int y) { return find(x) == find(y); }

  // 要素xが所属するグループに含まれる要素の数
  int size(int x) { return sizes[find(x)]; }
};

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

  UFTree uf(N);
  std::vector<std::vector<int> > fried(N);
  std::vector<std::vector<int> > block(N);

  for (int _ = 0; _ < M; _++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    uf.unite(a, b);
    fried[a].push_back(b);
    fried[b].push_back(a);
  }
  for (int _ = 0; _ < K; _++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    block[a].push_back(b);
    block[b].push_back(a);
  }

  for (int i = 0; i < N; i++) {
    int cnt = uf.size(i) - 1;
    for (int j = 0; j < fried[i].size(); j++) {
      if (uf.same(i, fried[i][j])) cnt--;
    }
    for (int j = 0; j < block[i].size(); j++) {
      if (uf.same(i, block[i][j])) cnt--;
    }
    cout << cnt << " ";
  }
  cout << endl;
}


Measured memory_bytes: 12664
X,Y=map(int,input().split())
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 10 ** 6
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

if (X+Y)%3:
    ans=0
else:
    N=(X+Y)//3
    if N<=X<=2*N and N<=Y<=2*N:
        ans=cmb(N,X-N,p)
    else:
        ans=0

print(ans)

Measured memory_bytes: 127936
#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define td(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define int long long
using namespace std;
typedef vector<int> vi;
#define y1 abacaba
#define left sefude
#define db(x) cerr << #x <<" == "<<x << endl;
#define db2(x,y) cerr<<#x <<" == "<<x<<", "<<#y<<" == "<<y<<endl;
#define db3(x,y,z) cerr << #x<<" == "<<x<<", "<<#y<<" == "<<y<<", "<<#z<<" == "<<z<<endl; 
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
inline ll mod(ll n, ll m ){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
ll exp(ll a,ll b,ll m){
    if(b==0LL) return 1LL;
    if(b==1LL) return mod(a,m);
    ll k = mod(exp(a,b/2,m),m);
    if(b&1LL){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}


int32_t main(){
  fastio;
  ll x,k,d;
  cin >> x >> k >> d;
  x = abs(x);
  ll tira = min(x/d,k);
  x-=tira*d;
  k-=tira;
  if(k == 0){
    cout << abs(x) << endl;
    return 0;
  }else if(k&1){
    cout << abs(x - d) << endl;
  }else cout << abs(x) << endl;
  // math -> gcd it all
  // Did u check N=1? Did you switch N,M?
}

Measured memory_bytes: 3620
program multiplication2
  implicit none
  integer(16), parameter :: u = 10_16**18
  integer :: n, i
  integer(16) :: a(100000) = 0, x = 1
  read(*,*) n
  read(*,*) a(1:n)
  if (minval(a(1:n)) == 0) then
    write(*,'(i0)') 0
    stop
  end if
  do i = 1, n
    x = x*a(i)
    if (x > u) then
      write(*,'(i0)') -1
      stop
    end if
  end do
  write(*,'(i0)') x
end program multiplication2

Measured memory_bytes: 4528
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  vector<int> vec(3);
  cin>>vec[0]>>vec[1]>>vec[2];
  
  sort(vec.begin(),vec.end());
  
  if(vec[0]==vec[1]&&vec[1]==vec[2]){
    cout<<1<<endl;
  }
  else if(vec[0]==vec[1]&&vec[1]!=vec[2]){
    cout<<2<<endl;
  }
  else if(vec[0]!=vec[1]&&vec[1]==vec[2]){
    cout<<2<<endl;
  }
  else{
    cout<<3<<endl;
  }
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int a[16][16];
int main() {
	rep(i,16)rep(j,16) a[i][j] = -1;
	int n; cin >> n;
	rep(i,n) {
		int aa; cin >> aa;
		while(aa--) {
			int x, y; cin >> x >> y;
			--x;
			a[i][x] = y;
		}
	}
	int ans = 0;
	for(int i = 0; i < (1 << n); ++i) {
		bool flg = true;
		for(int j = 0; j < n; ++j) {
			if((i >> j) & 1) {
				for(int k = 0; k < n; ++k) {
					if(a[j][k] != -1) {
						if(a[j][k] != ((i >> k) & 1)) flg = false;
					}
				}
			}
		}
		if(flg) {
			ans = max(ans, __builtin_popcount(i));
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include <random>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define bn(x) ((1<<x)-1)
#define newline puts("")
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,const vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,const pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;



int main() {
  int n,c,k;
  scanf("%d%d%d",&n,&c,&k);
  vl t(n);
  rep(i,n) cin>>t[i];
  sort(rng(t));
  int l = 0, ans = 0;
  t.pb(LINF);
  rep(i,n+1) {
    if (t[l]+k < t[i]) {
      l = i;
      ans++;
    }
    if (i-l >= c) l += c, ans++;
  }
  cout<<ans<<endl;
  return 0;
}






















Measured memory_bytes: 1792
function main(input){
  input = input.split('\n');
  const [N, M] = input[0].split(' ').map(Number);
  const H = input[1].split(' ').map(Number);

  const map = {};
  for(let i=0; i<M; i++){
    const [a, b] = input[2 + i].split(' ').map(Number);
    if(!map[a]) map[a] = []
    if(!map[b]) map[b] = []
    map[a].push(b);
    map[b].push(a);
  }

  let count = 0;
  for(let i=1; i<=N; i++){
    const tonari = map[i];
    if(tonari && tonari.some(x => H[i-1] <= H[x-1])) continue;
    count++;
  }

  console.log(count);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim());


Measured memory_bytes: 98460
n = int(input())
from collections import defaultdict
import sys
sys.setrecursionlimit(10**7)
graph = defaultdict(list)
edge = []
for i in range(n-1):
  a, b = list(map(int, input().split()))
  edge.append((a, b))
  graph[a].append(b)
  graph[b].append(a)
c = list(map(int, input().split()))
c.sort(reverse=True)
visited = [0 for i in range(n+1)]
ans = [0 for i in range(n+1)]
score = 0

def dfs(x):
  visited[x] = 1
  for next_ in graph[x]:
    if visited[next_]:
      continue
    dfs(next_)
  if all(visited[i] for i in graph[x]):
    ans[x] = c.pop()
    return
  visited[x] = 0

dfs(1)
for a, b in edge:
  score += min(ans[a], ans[b])
print(score)
print(*ans[1:])

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

int main(void)
{
  int n;
  cin >> n ;
  int me=100000;
  for(int i =0;i < n;i++){
    me *= 1.05;

    if(me % 1000 != 0){
      me += 1000 - (me % 1000);
    }
  }
  cout << me << endl;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define REP(i, a, n) for(int i = (a); i < (n); i++)
using namespace std;
typedef pair<double, int> pdi;

struct point { int x, y; };
struct line { point p, q; };

int T, N, O[110], L[110];
line A, S[110];

bool intersect(line l1, line l2) {
  double ax = l1.p.x, ay = l1.p.y;
  double bx = l1.q.x, by = l1.q.y;
  double cx = l2.p.x, cy = l2.p.y;
  double dx = l2.q.x, dy = l2.q.y;
  double ta = (cx - dx) * (ay - cy) + (cy - dy) * (cx - ax);
  double tb = (cx - dx) * (by - cy) + (cy - dy) * (cx - bx);
  double tc = (ax - bx) * (cy - ay) + (ay - by) * (ax - cx);
  double td = (ax - bx) * (dy - ay) + (ay - by) * (ax - dx);
  return tc * td < 0 && ta * tb < 0;
}

double distance(line l, point p) {
  double ux = l.q.x - l.p.x;
  double uy = l.q.y - l.p.y;
  double vx = p.x - l.p.x;
  double vy = p.y - l.p.y;
  double cross = abs(ux * vy - uy * vx);
  double ul = sqrt(ux * ux + uy * uy);
  return cross / ul;
}

int main(void) {
  cin >> T;
  while(T--) {
    cin >> A.p.x >> A.p.y >> A.q.x >> A.q.y;
    cin >> N;
    REP(i, 0, N) cin >> S[i].p.x >> S[i].p.y >> S[i].q.x >> S[i].q.y >> O[i] >> L[i];

    vector<pdi> E;
    REP(i, 0, N) if(intersect(A, S[i])) {
      double da = distance(S[i], A.p);
      double db = distance(S[i], A.q);
      double d = da / (da + db);
      E.push_back(pdi(d, i));
    }

    sort(E.begin(), E.end());

    vector<int> g;
    REP(i, 0, E.size()) {
      int k = E[i].second;
      g.push_back(O[k] == 1 ? L[k] : (L[k] ^ 1));
    }

    int ans = 0;
    REP(i, 1, (g.size())) if(g[i - 1] != g[i]) ans++;
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define all(A) A.begin(),A.end()
typedef long long ll;

vector<vector<int>> par(100100,vector<int>(0));
vector<bool> seen(100100,0);
vector<int> dp(100100,-1);

int f(int x){
  if(seen[x]) return dp[x];
  seen[x] = 1;
  int ans = 0;
  for(int p : par[x]){
    ans = max(ans, f(p)+1);
  }
  dp[x] = ans;
  return ans;
}

int main(){
  int n,m;
  cin >> n >> m;
  rep(i,m){
    int x,y;
    cin >> x >> y;
    par[y].push_back(x);
  }
  rep1(i,n) f(i);
  int ans = 0;
  rep1(i,n) ans = max(ans, dp[i]);
  cout << ans << endl;
}

Measured memory_bytes: 13372
# E Red and Green Apples
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

p = p[:x]
q = q[:y]

ans = p + q + r

ans.sort(reverse=True)

ans = ans[:x+y]

print(sum(ans))

Measured memory_bytes: 23328
#include<iostream>
#include<cstdlib>
using namespace std;
int main() 
{
	int a,b,c,d,pd=0;
	cin>>a;
	d=a%10;
	a=a/10;
	c=a%10;
	a=a/10;
	b=a%10;
	a=a/10;
    if(a+b+c+d==7){pd++;cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7";return 0;}
    if(a+b+c-d==7){pd++;cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7";return 0;}
    if(a+b-c+d==7){pd++;cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7";return 0;}
   	if(a+b-c-d==7){pd++;cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7";return 0;}
  	if(a-b+c+d==7){pd++;cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7";return 0;}
  	if(a-b+c-d==7){pd++;cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7";return 0;}
   	if(a-b-c+d==7){pd++;cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7";return 0;}
  	if(a-b-c-d==7){pd++;cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7";return 0;}
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int tarou_point = 0;
        int hanako_point = 0;
        int n = sc.nextInt();
        while(true){
            for(int i = 0;i < n;i++) {
            	String tarou = sc.next();
                String hanako = sc.next();
            	if(tarou.compareTo(hanako) < 0){
                    hanako_point = hanako_point + 3;
                }else if(tarou.compareTo(hanako) > 0){
                    tarou_point = tarou_point + 3;
                }else if(tarou.compareTo(hanako) == 0){
                    tarou_point++;
                    hanako_point++;
                }
            }
            System.out.println(tarou_point + " " + hanako_point);
            break;
        }
    }
}


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

signed main(void)
{
	string s;
	vector<int> cnt(3, 0);

	cin >> s;
	rep(i, s.size()) cnt[s[i] - 'a']++;
	sort(cnt.begin(), cnt.end());
	if (cnt[2] - cnt[0] <= 1)
		cout << "YES" << endl;
	else 
		cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 512
package main

/*
連鎖行列積
*/

import (
	"bufio"
	"bytes"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
	"strings"
)

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

type mem *[][]int

func main() {
	scanner := makeScanner(1024)
	n := eGetInt(scanner)
	p := make([]int, n+1)
	for i := 0; i < n; i++ {
		rowcol := eGetInts(scanner)
		p[i] = rowcol[0]
		p[i+1] = rowcol[1]
	}
	m := make([][]int, n)
	for i := 0; i < n; i++ {
		m[i] = make([]int, n)
	}
	// 初期値の格納
	for i := 0; i < n; i++ {
		for j := i; j < n; j++ {
			if i == j {
				m[i][j] = 0 //  同じ行列へのコストは当然0
			} else {
				m[i][j] = math.MaxInt64
			}
		}
	}

	// num : 行列の数. num == 1の場合は初期値0を格納ずみ
	for num := 2; num <= n; num++ {
		// s : スタート行列番号
		for s := 0; s+num <= n; s++ {
			// t : 終了行列番号
			t := s + num - 1
			// k : 仕切
			for k := s; k < t; k++ {
				m[s][t] = min(m[s][t], m[s][k]+m[k+1][t]+p[s]*p[k+1]*p[t+1])
			}
		}
	}
	fmt.Println(m[0][n-1])
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}

type ints []int

func (s ints) String() string {
	var buf bytes.Buffer
	buf.WriteString("[")
	sep := ""
	for _, v := range s {
		buf.WriteString(fmt.Sprintf("%s%d", sep, v))
		sep = ", "
	}
	buf.WriteString("]")
	return buf.String()
}

func reverse(a ints) ints {
	r := make(ints, len(a))
	for i := 0; i < len(a); i++ {
		r[i] = a[len(a)-1-i]
	}
	return r
}
func max(a ints) (int, bool) {
	if len(a) == 0 {
		return 0, false
	}
	m := a[0]
	for _, e := range a {
		if e > m {
			m = e
		}
	}
	return m, true
}

// func min(a []int) int {
// 	m := a[0]
// 	for _, v := range a {
// 		if v < m {
// 			m = v
// 		}
// 	}
// 	return m
// }

func sum(a ints) int {
	if len(a) == 0 {
		return 0
	}
	sum := 0
	for _, e := range a {
		sum += e
	}
	return sum
}
func find(n int, a ints) int {
	for i, v := range a {
		if n == v {
			return i
		}
	}
	return -1
}



Measured memory_bytes: 1228